Documentation

CslibFrontier.Computability.Circuit.Boolean.Oracle.Selection

Selecting an accepted candidate with oracle gates #

A selection round asks the oracle about N candidates side by side and keeps the word of the first accepted candidate, or a default word when none is accepted. Each query word and each candidate word is read from sources (Boolean.Source): input wires or constants. A word of sources is a substitution, so it reads the word Boolean.substitute ρ x from the input x. So a candidate can mix fixed bits, such as its own index, with input bits, such as a truth-table entry or the output of an earlier round. The default word is read from sources too, so it can be made correct for the inputs it reads.

Boolean.selectionRound src word dflt is this round as an oracle circuit that keeps its inputs and appends the selected word. Its queries have length q. It has N oracle gates, all at oracle depth one, and its other gates are a chain of multiplexers (Boolean.selectFirst). Rounds compose with Circuit.accumulate, where each round reads the inputs and the words of all earlier rounds; Boolean.eval_selectionRound has the shape that Circuit.eval_accumulate_block consumes.

The selected word is the first accepted candidate's, or the default when none is accepted (Boolean.selectedWord_spec). In particular, a property of words that every accepted candidate and the default satisfy holds for the selected word (Boolean.selectedWord_prop).

Main definitions #

Main results #

The first accepted candidate #

def Cslib.Circuits.Boolean.firstSel {w : ℕ} (d : BitString w) {N : ℕ} :
(Fin N → Bool) → (Fin N → BitString w) → BitString w

The word of the first candidate i with acc i, or the default d when there is none.

theorem Cslib.Circuits.Boolean.firstSel_spec {N w : ℕ} (d : BitString w) (acc : Fin N → Bool) (word : Fin N → BitString w) :
(∃ (i : Fin N), acc i = true ∧ (∀ j < i, acc j = false) ∧ firstSel d acc word = word i) ∨ (∀ (i : Fin N), acc i = false) ∧ firstSel d acc word = d

The first accepted candidate, or the default. Either some candidate is accepted and the selected word is that of the first accepted candidate, or none is and it is the default.

theorem Cslib.Circuits.Boolean.firstSel_prop {N w : ℕ} {P : BitString w → Prop} {d : BitString w} {acc : Fin N → Bool} {word : Fin N → BitString w} (hd : P d) (hacc : ∀ (i : Fin N), acc i = true → P (word i)) :
P (firstSel d acc word)

A property of words that the default and every accepted candidate's word have holds for the selected word.

def Cslib.Circuits.Boolean.selectFirst {K w : ℕ} (dflt : Fin w → Fin K) {N : ℕ} :
(Fin N → Fin K) → (Fin N → Fin w → Fin K) → Circuit signature K w

The De Morgan circuit selecting the first accepted candidate: candidate i is accepted when the input acc i is true, and its word is read from the inputs word i; the default word is read from the inputs dflt. A chain of N multiplexers.

@[simp]
theorem Cslib.Circuits.Boolean.eval_selectFirst {K N w : ℕ} (dflt : Fin w → Fin K) (acc : Fin N → Fin K) (word : Fin N → Fin w → Fin K) (x : BitString K) :
(selectFirst dflt acc word).eval interpretation x = firstSel (x ∘ dflt) (x ∘ acc) fun (i : Fin N) => x ∘ word i
@[simp]
theorem Cslib.Circuits.Boolean.size_selectFirst {K N w : ℕ} (dflt : Fin w → Fin K) (acc : Fin N → Fin K) (word : Fin N → Fin w → Fin K) :
(selectFirst dflt acc word).size = N * (3 * w + 1)

Sources, constants and oracle gates #

@[reducible, inline]

A source of one bit of a word: one of K input wires, or a constant. A word of sources ρ : Fin w → Source K is a substitution, and reads the word substitute ρ x from the input x.

The wire carrying a source after constLayer.

The inputs followed by the constants false and true. Two gates.

@[simp]

After constLayer, the wire of a source carries the bit that the source reads.

def Cslib.Circuits.Boolean.queryLayer {K N q : ℕ} (src : Fin N → Fin q → Source K) :

N oracle gates side by side, on the output of constLayer: gate i asks about the word read from the q sources src i.

@[simp]
theorem Cslib.Circuits.Boolean.eval_queryLayer {K N q : ℕ} (src : Fin N → Fin q → Source K) (O : Language Bool) (x : BitString K) (i : Fin N) :
@[simp]
theorem Cslib.Circuits.Boolean.size_queryLayer {K N q : ℕ} (src : Fin N → Fin q → Source K) :
(queryLayer src).size = N

One round #

def Cslib.Circuits.Boolean.selectionRound {K N q w : ℕ} (src : Fin N → Fin q → Source K) (word : Fin N → Fin w → Source K) (dflt : Fin w → Source K) :

One selection round. Candidate i is accepted when the oracle accepts the word read from the sources src i. The round keeps its inputs and appends the word read from word i for the first accepted candidate i, or the word read from dflt when none is accepted.

noncomputable def Cslib.Circuits.Boolean.selectedWord {K N q w : ℕ} (O : Language Bool) (src : Fin N → Fin q → Source K) (word : Fin N → Fin w → Source K) (dflt : Fin w → Source K) (x : BitString K) :

The word that selectionRound src word dflt selects on the input x under the oracle O.

@[simp]
theorem Cslib.Circuits.Boolean.eval_selectionRound {K N q w : ℕ} (src : Fin N → Fin q → Source K) (word : Fin N → Fin w → Source K) (dflt : Fin w → Source K) (O : Language Bool) (x : BitString K) :
(selectionRound src word dflt).eval (oracleInterpretation O) x = Fin.append x (selectedWord O src word dflt x)

A round keeps its inputs and appends the selected word.

theorem Cslib.Circuits.Boolean.selectedWord_spec {K N q w : ℕ} (O : Language Bool) (src : Fin N → Fin q → Source K) (word : Fin N → Fin w → Source K) (dflt : Fin w → Source K) (x : BitString K) :
(∃ (i : Fin N), O.slice q (substitute (src i) x) = true ∧ (∀ j < i, O.slice q (substitute (src j) x) = false) ∧ selectedWord O src word dflt x = substitute (word i) x) ∨ (∀ (i : Fin N), O.slice q (substitute (src i) x) = false) ∧ selectedWord O src word dflt x = substitute dflt x

The word a round selects. Either the oracle accepts some candidate's query and the selected word is that of the first such candidate, or it accepts none and the selected word is the default.

theorem Cslib.Circuits.Boolean.selectedWord_prop {K N q w : ℕ} {P : BitString w → Prop} (O : Language Bool) (src : Fin N → Fin q → Source K) (word : Fin N → Fin w → Source K) (dflt : Fin w → Source K) (x : BitString K) (hd : P (substitute dflt x)) (hacc : ∀ (i : Fin N), O.slice q (substitute (src i) x) = true → P (substitute (word i) x)) :
P (selectedWord O src word dflt x)

A property of words that the default and every accepted candidate's word have holds for the word a round selects.

@[simp]
theorem Cslib.Circuits.Boolean.size_selectionRound {K N q w : ℕ} (src : Fin N → Fin q → Source K) (word : Fin N → Fin w → Source K) (dflt : Fin w → Source K) :
(selectionRound src word dflt).size = 2 + N + N * (3 * w + 1)

A round has 2 constant gates, N oracle gates and N multiplexers of width w.

@[simp]
theorem Cslib.Circuits.Boolean.cost_program_selectionRound {K N q w : ℕ} (src : Fin N → Fin q → Source K) (word : Fin N → Fin w → Source K) (dflt : Fin w → Source K) :

A round has N oracle gates.

theorem Cslib.Circuits.Boolean.depthWith_selectionRound_le {K N q w : ℕ} (src : Fin N → Fin q → Source K) (word : Fin N → Fin w → Source K) (dflt : Fin w → Source K) :

A round has at most one oracle gate on any path.

theorem Cslib.Circuits.Boolean.fanInAtMost_selectionRound {K N q w : ℕ} (src : Fin N → Fin q → Source K) (word : Fin N → Fin w → Source K) (dflt : Fin w → Source K) :
(selectionRound src word dflt).FanInAtMost (max q 2)

A round has fan-in at most max q 2.