Documentation

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

Field arithmetic for the decoder of the succinct tableau #

The first stage of the decoder of the tableau formula on bit-field labels (CslibFrontier/Computability/Circuit/Boolean/Tableau/Succinct.lean). Its inputs are the bits of a clause number: two bits of the clause, two bits of the tag, then a payload of P = s + cb + tb bits made of the slot (s bits), the column c (cb bits) and the block t (tb bits). It is an explicit De Morgan gate list (fieldGates) of

There are 2 + (4 + P) + 14 P + (2 ^ (m + 1) - 1) + x.length gates, linear in the field widths and in the length of x; in particular there is no carry-lookahead adder, whose size is not linear.

Correctness is proved wire by wire: the intended value of every wire (fieldVal) is consistent with its gate (allGates_consistentAt_fieldGates), so it is the value the list computes (getD_evalCode_of_allGates).

Main definitions #

Main results #

Gate lists checked gate by gate #

Every gate of gates, the first one at wire base, satisfies p at its wire.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.allGates_append {p : ℕ → Op × List ℕ → Prop} {b : ℕ} {l₁ l₂ : List (Op × List ℕ)} :
AllGates p b (l₁ ++ l₂) ↔ AllGates p b l₁ ∧ AllGates p (b + l₁.length) l₂
theorem Cslib.Circuits.Boolean.Tableau.Decoder.allGates_cons {p : ℕ → Op × List ℕ → Prop} {b : ℕ} {g : Op × List ℕ} {l : List (Op × List ℕ)} :
AllGates p b (g :: l) ↔ p b g ∧ AllGates p (b + 1) l
theorem Cslib.Circuits.Boolean.Tableau.Decoder.allGates_map_range {p : ℕ → Op × List ℕ → Prop} {b w : ℕ} {f : ℕ → Op × List ℕ} :
AllGates p b (List.map f (List.range w)) ↔ ∀ i < w, p (b + i) (f i)
theorem Cslib.Circuits.Boolean.Tableau.Decoder.allGates_flatMap_range {p : ℕ → Op × List ℕ → Prop} {b w : ℕ} {f : ℕ → List (Op × List ℕ)} :
AllGates p b (List.flatMap f (List.range w)) ↔ ∀ i < w, AllGates p (b + (List.map (fun (j : ℕ) => (f j).length) (List.range i)).sum) (f i)
theorem Cslib.Circuits.Boolean.Tableau.Decoder.sum_range_map_const {len : ℕ} {f : ℕ → List (Op × List ℕ)} (hf : ∀ (j : ℕ), (f j).length = len) (i : ℕ) :
(List.map (fun (j : ℕ) => (f j).length) (List.range i)).sum = i * len

Blocks of a common length len start at multiples of len.

Blocks of lengths 2 ^ j start at 2 ^ i - 1.

A gate reads only wires below its own, with the arity of its operation.

The wire of a gate carries, under σ, the value of the gate on the values of its arguments.

A list of well-formed gates is the code of a program.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.getD_evalCode_of_allGates {n : ℕ} {gates : List (Op × List ℕ)} (hwf : AllGates WellFormedAt n gates) (σ : ℕ → Bool) (hσ : AllGates (ConsistentAt σ) n gates) {w : ℕ} (hw : w < n + gates.length) :
(evalCode interpretation false (List.ofFn fun (i : Fin n) => σ ↑i) gates).getD w false = σ w

A valuation consistent with every gate is the evaluation of a well-formed gate list.

A conjunction (false) or a disjunction (true).

theorem Cslib.Circuits.Boolean.Tableau.Decoder.wellFormedAt_two {w a b : ℕ} {op : Op} (hop : signature.Arity op = 2) (ha : a < w) (hb : b < w) :
theorem Cslib.Circuits.Boolean.Tableau.Decoder.consistentAt_two {σ : ℕ → Bool} {w a b : ℕ} {op : Op} :
ConsistentAt σ w (op, [a, b]) ↔ σ w = op.value (σ a) (σ b)

Bit-serial comparison #

The comparison computed by a chain: a < b (for gt = false) or b < a (for gt = true), with ties decided by e.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.mod_two_pow_succ (v i : ℕ) :
v % 2 ^ (i + 1) = v % 2 ^ i + 2 ^ i * (v.testBit i).toNat

The low i + 1 bits of a number: its bit i above its low i bits.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.cmp_succ (gt : Bool) (v K i : ℕ) (e : Bool) :
cmp gt (v % 2 ^ (i + 1)) (K % 2 ^ (i + 1)) e = (andOr (K.testBit i ^^ gt)).value (if gt = true then v.testBit i else !v.testBit i) (cmp gt (v % 2 ^ i) (K % 2 ^ i) e)

One step of a comparison chain: comparing one more bit is a disjunction or a conjunction of the literal of the bit with the comparison of the lower bits, by the bit of the constant.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.cmp_mod_of_lt {gt : Bool} {v K w : ℕ} {e : Bool} (hv : v < 2 ^ w) (hK : K < 2 ^ w) :
cmp gt (v % 2 ^ w) (K % 2 ^ w) e = cmp gt v K e

A comparison of numbers below 2 ^ w on all w bits.

The layout #

A comparison chain: the offset and the width of the field it reads, its direction (gt: K < v rather than v < K), the constant K and the tie value init.

  • off : ℕ

    The input offset of the field.

  • width : ℕ

    The width of the field.

  • gt : Bool

    Whether the chain decides K < v rather than v < K.

  • K : ℕ

    The constant.

  • init : Bool

    The value on equal numbers.

The fourteen comparison chains, for slot, column and block widths s, cb and tb, an input bound n, a step bound T and a hardwired prefix of length X: the offset and the width of the field read, the direction, the constant and the tie value. Chains 0, 1 and 2 give the borrows of c - 1, the carries of c + 1 and the borrows of t - 1.

The start of the comparison chains, after the N inputs, the two constants and the N negations.

The start of the decoder tree, after the fourteen chains of P gates.

The start of the lookup chain, after the 2 ^ (m + 1) - 1 gates of the tree.

Gate i of chain k, comparing the field of width w at input offset off, padded with zeros to P bits, with the constant K: its literal is the bit of the field (gt) or its negation, and it combines it with the previous gate of the chain (or the tie value init).

Node q of level ℓ of the decoder tree: true at level 0, and otherwise the node q % 2 ^ ℓ of the level below together with bit ℓ of the payload, negated when bit ℓ of q is clear.

The decoder tree on the low m bits of the payload, level by level.

Gate i of the lookup chain: the disjunction of the previous gate with the indicator of the payload i when x[i] is true.

The field stage of the decoder, for slot, column and block widths s, cb and tb, a hardwired input prefix x, an input length n and a step bound T.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.length_fieldGates (s cb tb : ℕ) (x : List Bool) (n T : ℕ) :
(fieldGates s cb tb x n T).length = 2 + (4 + (s + cb + tb)) + 14 * (s + cb + tb) + (2 ^ (x.length.size + 1) - 1) + x.length

The number of gates of the field stage.

The intended values #

The comparison of chain spec after j bits, on the clause number idx.

The intended value of each wire of the field stage on the bits of the clause number idx: the inputs, the constants, the negations, the chains after each bit, the indicators of the low bits of the payload p = idx / 16, and the lookup of x at p.

Correctness #

theorem Cslib.Circuits.Boolean.Tableau.Decoder.chain_off_add_width_le {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (k : ℕ) :
(chain s cb tb x.length n T k).off + (chain s cb tb x.length n T k).width ≤ 4 + (s + cb + tb)

The fields read by the chains lie within the inputs.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_input {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) {w : ℕ} (hw : w < 4 + (s + cb + tb)) :
fieldVal s cb tb x n T idx w = idx.testBit w
theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_false {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) :
fieldVal s cb tb x n T idx (4 + (s + cb + tb)) = false
theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_true {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) :
fieldVal s cb tb x n T idx (4 + (s + cb + tb) + 1) = true
theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_not {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) {j : ℕ} (hj : j < 4 + (s + cb + tb)) :
fieldVal s cb tb x n T idx (4 + (s + cb + tb) + 2 + j) = !idx.testBit j
theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_chain {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) {k i : ℕ} (hk : k < 14) (hi : i < s + cb + tb) :
fieldVal s cb tb x n T idx (chainBase (4 + (s + cb + tb)) + k * (s + cb + tb) + i) = chainVal (chain s cb tb x.length n T k) idx (i + 1)
theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_tree {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx : ℕ) {ℓ q : ℕ} (hℓ : ℓ ≤ x.length.size) (hq : q < 2 ^ ℓ) :
fieldVal s cb tb x n T idx (treeBase (4 + (s + cb + tb)) (s + cb + tb) + (2 ^ ℓ - 1) + q) = decide (idx / 16 % 2 ^ ℓ = q)
theorem Cslib.Circuits.Boolean.Tableau.Decoder.fieldVal_or {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (idx i : ℕ) :
fieldVal s cb tb x n T idx (orBase (4 + (s + cb + tb)) (s + cb + tb) x.length.size + i) = (decide (idx / 16 % 2 ^ x.length.size ≤ i) && x.getD (idx / 16 % 2 ^ x.length.size) false)
theorem Cslib.Circuits.Boolean.Tableau.Decoder.allGates_fieldGates {s cb tb : ℕ} {x : List Bool} {n T : ℕ} {p : ℕ → Op × List ℕ → Prop} (hc₀ : p (4 + (s + cb + tb)) (Op.const false, [])) (hc₁ : p (4 + (s + cb + tb) + 1) (Op.const true, [])) (hnot : ∀ i < 4 + (s + cb + tb), p (4 + (s + cb + tb) + 2 + i) (Op.not, [i])) (hchain : ∀ k < 14, ∀ i < s + cb + tb, p (chainBase (4 + (s + cb + tb)) + k * (s + cb + tb) + i) (chainGate (4 + (s + cb + tb)) (s + cb + tb) k (chain s cb tb x.length n T k) i)) (htree : ∀ ℓ ≤ x.length.size, ∀ q < 2 ^ ℓ, p (treeBase (4 + (s + cb + tb)) (s + cb + tb) + (2 ^ ℓ - 1) + q) (treeGate (4 + (s + cb + tb)) (treeBase (4 + (s + cb + tb)) (s + cb + tb)) ℓ q)) (hor : ∀ i < x.length, p (orBase (4 + (s + cb + tb)) (s + cb + tb) x.length.size + i) (orGate (4 + (s + cb + tb)) (treeBase (4 + (s + cb + tb)) (s + cb + tb)) x.length.size (orBase (4 + (s + cb + tb)) (s + cb + tb) x.length.size) x i)) :
AllGates p (4 + (s + cb + tb)) (fieldGates s cb tb x n T)

The gates of the field stage, region by region.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.allGates_wellFormedAt_fieldGates {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (hm : x.length.size ≤ s + cb + tb) :
AllGates WellFormedAt (4 + (s + cb + tb)) (fieldGates s cb tb x n T)

The field stage is a well-formed gate list, when the decoder tree reads only payload bits.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.mod_two_pow_succ_eq_iff {p q ℓ : ℕ} (hq : q < 2 ^ (ℓ + 1)) :
p % 2 ^ (ℓ + 1) = q ↔ p % 2 ^ ℓ = q % 2 ^ ℓ ∧ p.testBit ℓ = q.testBit ℓ

The low ℓ + 1 bits of two numbers agree exactly when their low ℓ bits and their bits ℓ agree.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.allGates_consistentAt_fieldGates {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (hm : x.length.size ≤ s + cb + tb) (idx : ℕ) :
AllGates (ConsistentAt (fieldVal s cb tb x n T idx)) (4 + (s + cb + tb)) (fieldGates s cb tb x n T)

The intended values are consistent with the gates of the field stage.

theorem Cslib.Circuits.Boolean.Tableau.Decoder.getD_evalCode_fieldGates {s cb tb : ℕ} {x : List Bool} {n T : ℕ} (hm : x.length.size ≤ s + cb + tb) (idx : ℕ) {w : ℕ} (hw : w < 4 + (s + cb + tb) + (fieldGates s cb tb x n T).length) :
(evalCode interpretation false (List.ofFn fun (i : Fin (4 + (s + cb + tb))) => idx.testBit ↑i) (fieldGates s cb tb x n T)).getD w false = fieldVal s cb tb x n T idx w

The field stage computes the intended values of its wires on the bits of a clause number.