Documentation

CslibFrontier.Computability.Circuit.Boolean.Tableau.Decoder.Circuit

The stages of the decoder circuit of the succinct tableau #

The decoder computes, from the bits of a clause number, the bits of the clause of the tableau formula on bit-field labels (Cslib.Circuits.Boolean.Tableau.clauseAt): for each of its three literals, the label in labelBits bits, least significant first, then the sign (litBits). It composes three stages:

The stages are assembled, with the correctness and the linear size of the whole circuit, in CslibFrontier/Computability/Circuit/Boolean/Tableau/Decoder/Assembly.lean.

Main definitions #

Main results #

References #

The formula of an output bit #

Input j of the formula of an output bit.

def Cslib.Circuits.Boolean.Tableau.Decoder.term (k : ℕ) (h : 3 * k + 3 < 28 := by omega) :

Term k of the formula of an output bit: a selector and the exclusive or of two bits.

The formula of an output bit: the input 0, or one of nine terms, each the conjunction of a selector with the exclusive or of two bits.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.eval_outTemplate (y : Fin 28 → Bool) :
outTemplate.eval interpretation y = (y 0 || y 1 && (y 2 ^^ y 3) || y 4 && (y 5 ^^ y 6) || y 7 && (y 8 ^^ y 9) || y 10 && (y 11 ^^ y 12) || y 13 && (y 14 ^^ y 15) || y 16 && (y 17 ^^ y 18) || y 19 && (y 20 ^^ y 21) || y 22 && (y 23 ^^ y 24) || y 25 && (y 26 ^^ y 27))
theorem Cslib.Circuits.Boolean.Tableau.Decoder.eval_outTemplate_nat (y : ℕ → Bool) :
(outTemplate.eval interpretation fun (j : Fin 28) => y ↑j) = (y 0 || y 1 && (y 2 ^^ y 3) || y 4 && (y 5 ^^ y 6) || y 7 && (y 8 ^^ y 9) || y 10 && (y 11 ^^ y 12) || y 13 && (y 14 ^^ y 15) || y 16 && (y 17 ^^ y 18) || y 19 && (y 20 ^^ y 21) || y 22 && (y 23 ^^ y 24) || y 25 && (y 26 ^^ y 27))

The formula of an output bit on the values of numbered wires.

The bits of a literal #

The bits of a literal: its label in w bits, least significant first, then its sign.

The constant stage #

The bit i of a bit string, or false.

The key of the input bits of the constant stage: the clause and tag bits, s slot bits, and the fourteen comparison chains.

noncomputable def Cslib.Circuits.Boolean.Tableau.Decoder.tableFn {k : ℕ} {State : Type} [Fintype State] [DecidableEq State] (tm : Turing.MultiTapeTM k Bool State) (b : BitString (4 + slotBits k State + 14)) (o : Fin (3 * (13 + slotBits k State))) :

The function of the constant stage: bit f of literal r (f < 13 + s) is a tag or slot bit or a selector of the shape of literal r of the key of the input bits.

noncomputable def Cslib.Circuits.Boolean.Tableau.Decoder.tableCircuit {k : ℕ} {State : Type} [Fintype State] [DecidableEq State] (tm : Turing.MultiTapeTM k Bool State) :
Circuit signature (4 + slotBits k State + 14) (3 * (13 + slotBits k State))

The constant stage: a circuit computing tableFn, one disjunctive normal form per output. Its size depends only on the machine.

The wires of the output stage #

The wire of the constant b, after N inputs.

The wire of bit q of the field of width w at offset off, or of false.

The wire of chain k after q bits, true for q = 0.

The first wire of the term kk of the payload bit q.

The second wire of the term kk of the payload bit q: a borrow or a carry.

The number of wires of the field stage.

The wire of the lookup of x.

The wire read at input j of the formula of output bit o of the output stage. Output o is bit o % (3 + P) of literal o / (3 + P), where P = s + cb + tb: two tag bits, P payload bits and the sign. The output r * (13 + s) + f of the constant stage is wire aWidth + r * (13 + s) + f.

The wire of input i of the constant stage: a clause, tag or slot bit, or the last gate of a comparison chain.

Wire bounds #

theorem Cslib.Circuits.Boolean.Tableau.Decoder.chainBase_add_lt_aWidth {s cb tb : ℕ} {x : List Bool} {n T k q : ℕ} (hk : k < 14) (hq : q < s + cb + tb) :
chainBase (4 + (s + cb + tb)) + k * (s + cb + tb) + q < aWidth s cb tb x n T
theorem Cslib.Circuits.Boolean.Tableau.Decoder.lt_aWidth_of_lt {s cb tb : ℕ} {x : List Bool} {n T w : ℕ} (hw : w < 2 * (4 + (s + cb + tb)) + 2) :
w < aWidth s cb tb x n T
theorem Cslib.Circuits.Boolean.Tableau.Decoder.constW_lt {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (b : Bool) :
constW (4 + (s + cb + tb)) b < aWidth s cb tb x n T
theorem Cslib.Circuits.Boolean.Tableau.Decoder.bitW_lt {s cb tb : ℕ} {x : List Bool} {n T off w q : ℕ} (h : off + w ≤ 4 + (s + cb + tb)) :
bitW (4 + (s + cb + tb)) off w q < aWidth s cb tb x n T
theorem Cslib.Circuits.Boolean.Tableau.Decoder.chainW_lt {s cb tb : ℕ} {x : List Bool} {n T k q : ℕ} (hk : k < 14) (hq : q ≤ s + cb + tb) :
chainW (4 + (s + cb + tb)) (s + cb + tb) k q < aWidth s cb tb x n T
theorem Cslib.Circuits.Boolean.Tableau.Decoder.uWire_lt {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (q kk : ℕ) (hq : q < s + cb + tb) :
uWire s cb tb T q kk < aWidth s cb tb x n T
theorem Cslib.Circuits.Boolean.Tableau.Decoder.vWire_lt {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (q kk : ℕ) (hq : q < s + cb + tb) :
vWire s cb tb q kk < aWidth s cb tb x n T
theorem Cslib.Circuits.Boolean.Tableau.Decoder.lookW_lt {s cb tb : ℕ} {x : List Bool} {n T : ℕ} :
lookW s cb tb x < aWidth s cb tb x n T
theorem Cslib.Circuits.Boolean.Tableau.Decoder.wireNat_lt {s cb tb : ℕ} {x : List Bool} {n T o j : ℕ} (ho : o < 3 * (2 + (s + cb + tb) + 1)) (hj : j < 28) :
wireNat s cb tb x n T o j < aWidth s cb tb x n T + 3 * (13 + s)

The wires of the output stage lie among the wires of the field and constant stages.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.keyWire_lt {s cb tb : ℕ} {x : List Bool} {n T i : ℕ} (hi : i < 4 + s + 14) :
keyWire s cb tb i < aWidth s cb tb x n T

The circuit #

theorem Cslib.Circuits.Boolean.Tableau.Decoder.isSome_fieldCode {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (hm : x.length.size ≤ s + cb + tb) :
(Circuit.ofCode (4 + (s + cb + tb)) (aWidth s cb tb x n T) (fieldGates s cb tb x n T, List.range (aWidth s cb tb x n T))).isSome = true
noncomputable def Cslib.Circuits.Boolean.Tableau.Decoder.fieldCircuit {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (hm : x.length.size ≤ s + cb + tb) :
Circuit signature (4 + (s + cb + tb)) (aWidth s cb tb x n T)

The field stage as a circuit whose outputs are all its wires.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.code_fieldCircuit {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (hm : x.length.size ≤ s + cb + tb) :
(fieldCircuit hm).code = (fieldGates s cb tb x n T, List.range (aWidth s cb tb x n T))
theorem Cslib.Circuits.Boolean.Tableau.Decoder.size_fieldCircuit {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (hm : x.length.size ≤ s + cb + tb) :
(fieldCircuit hm).size = (fieldGates s cb tb x n T).length
theorem Cslib.Circuits.Boolean.Tableau.Decoder.eval_fieldCircuit {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (hm : x.length.size ≤ s + cb + tb) (idx : ℕ) (w : Fin (aWidth s cb tb x n T)) :
(fieldCircuit hm).eval interpretation (fun (i : Fin (4 + (s + cb + tb))) => idx.testBit ↑i) w = fieldVal s cb tb x n T idx ↑w

Values of the wires read by the output stage #

theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_constW {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) (b : Bool) :
fieldVal s cb tb x n T idx (constW (4 + (s + cb + tb)) b) = b
theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_bitW {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) {off w q : ℕ} (h : off + w ≤ 4 + (s + cb + tb)) :
fieldVal s cb tb x n T idx (bitW (4 + (s + cb + tb)) off w q) = (idx / 2 ^ off % 2 ^ w).testBit q
theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_payload {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) {q : ℕ} (hq : q < s + cb + tb) :
fieldVal s cb tb x n T idx (4 + q) = (idx / 16).testBit q
theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_chainW {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) {k q : ℕ} (hk : k < 14) (hq : q ≤ s + cb + tb) (hinit : (chain s cb tb x.length n T k).init = true) :
fieldVal s cb tb x n T idx (chainW (4 + (s + cb + tb)) (s + cb + tb) k q) = chainVal (chain s cb tb x.length n T k) idx q

The value of chain k after q bits, through chainW.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.div_mod_eq_colOf {s cb : ℕ} (idx : ℕ) :
idx / 2 ^ (4 + s) % 2 ^ cb = colOf s cb (idx / 16)

The column of the payload, from the clause number.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.div_mod_eq_timeOf {s cb tb idx : ℕ} (hidx : idx < 2 ^ (4 + (s + cb + tb))) :
idx / 2 ^ (4 + s + cb) % 2 ^ tb = timeOf s cb (idx / 16)

The block of the payload, from a clause number of 4 + (s + cb + tb) bits.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_borrowC {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) {q : ℕ} (hq : q ≤ s + cb + tb) :
fieldVal s cb tb x n T idx (chainW (4 + (s + cb + tb)) (s + cb + tb) 0 q) = decide (colOf s cb (idx / 16) % 2 ^ q = 0)
theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_carryC {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) {q : ℕ} (hq : q ≤ s + cb + tb) :
fieldVal s cb tb x n T idx (chainW (4 + (s + cb + tb)) (s + cb + tb) 1 q) = decide (colOf s cb (idx / 16) % 2 ^ q = 2 ^ q - 1)
theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_borrowT {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) (hidx : idx < 2 ^ (4 + (s + cb + tb))) {q : ℕ} (hq : q ≤ s + cb + tb) :
fieldVal s cb tb x n T idx (chainW (4 + (s + cb + tb)) (s + cb + tb) 2 q) = decide (timeOf s cb (idx / 16) % 2 ^ q = 0)
theorem Cslib.Circuits.Boolean.Tableau.Decoder.eval_outTemplate_wireNat {s cb tb : ℕ} {x : List Bool} {n T : ℕ} {z : ℕ → Bool} {idx : ℕ} (hidx : idx < 2 ^ (4 + (s + cb + tb))) (hF : ∀ w < aWidth s cb tb x n T, z w = fieldVal s cb tb x n T idx w) (o : ℕ) :
(outTemplate.eval interpretation fun (j : Fin 28) => z (wireNat s cb tb x n T o ↑j)) = outBit s cb tb (fun (f : ℕ) => z (aWidth s cb tb x n T + o / (2 + (s + cb + tb) + 1) * (13 + s) + f)) (fun (q : ℕ) => z (aWidth s cb tb x n T + o / (2 + (s + cb + tb) + 1) * (13 + s) + (2 + s + q))) (idx / 16) (colOf s cb (idx / 16)) (timeOf s cb (idx / 16)) T (z (lookW s cb tb x)) (o % (2 + (s + cb + tb) + 1))

The formula of an output bit computes outBit on the values of its wires: the values of the field stage, and the outputs ts of the constant stage for its literal.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_keyWire_chain {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) {k : ℕ} (hk : k < 14) (hP : 1 ≤ s + cb + tb) :
fieldVal s cb tb x n T idx (keyWire s cb tb (4 + s + k)) = chainVal (chain s cb tb x.length n T k) idx (s + cb + tb)

The value of the last gate of chain k.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.ofBits_keyWire {s cb tb : ℕ} {x : List Bool} {n T idx : ℕ} (hidx : idx < 2 ^ (4 + (s + cb + tb))) (hs : 1 ≤ s) (h2T : 2 * T < 2 ^ cb) (hT : T < 2 ^ tb) (hn : n < 2 * T) (hx : x.length ≤ n) :
(Key.ofBits s fun (i : Fin (4 + s + 14)) => fieldVal s cb tb x n T idx (keyWire s cb tb ↑i)) = Key.ofFields s cb x.length n T (idx % 4) (idx / 4 % 4) (idx / 16)

The key read by the constant stage is the key of the fields of the clause number.