Documentation

CslibFrontier.Algorithms.WordRAM.Refuter4n.PackedState

Packed state of the 4n - 9d refuter and its invariant #

A word-level representation of the gate-elimination states that the refuter refute visits (Cslib.Circuits.Boolean.AffineDisperser4n), and the relation Rep saying that packed words represent a state. This is the pure layer of the Word-RAM refuter of issue #4322 (Milestone 4); no program and no running time is claimed here.

Fix a bound N on the names of parameters, auxiliary variables and gates and a bound E on equation names. The layout of a circuit C uses N = nameBound C = n + C.size (names along the run, nameSet_iterate) and E = eqnBound C = 5 n + 7 C.size (equation names at the end of the run, eqns_refuterLoop). The packed state PackedState consists of:

Rep records only the words; the bounds that also follow from validity (terms, output and pairs named below N) are derived from State.Valid (Rep.terms_lt, Rep.out_lt, Rep.pairs_lt).

Word width. At w ≥ N + 2 and w ≥ 4, every stored word of a valid represented state fits (Rep.fits); with N = n + C.size this is the basis w ≥ n + C.size + 2, plus w ≥ 4 for a 4-bit truth table, which binds only when N < 2. This layer fixes no memory layout: addresses, counters, scratch cells and the separate instruction and workspace bounds come with the step programs. Equation words are rows at the fixed width N, while evaluateAux builds its dense rows at the width varBound S; the step layer relates the two.

Searches of the refuter run over sorted Finsets; on a mask they are the ascending bit scan over List.range N (find?_sort_eq_find?_range, findSome?_sort_eq_findSome?_range). The first client is the (D1) search: pFindD1 scans the gate mask and reads only packed rows, and equals findD1 on every represented state (Rep.pFindD1_eq). The second client is the initial state: initialPacked C represents initialState C (rep_initialPacked).

Main definitions #

Main results #

Bitmasks and sorted searches #

The bitmask of a finite set of names: bit i is set iff i ∈ s (the inverse of Finset.equivBitIndices).

@[simp]

Bit i of maskOf s is membership of i in s.

theorem Cslib.Algorithms.WordRAM.Refuter4n.maskOf_lt {s : Finset ℕ} {N : ℕ} (hs : ∀ i ∈ s, i < N) :
maskOf s < 2 ^ N

A set of names below N has a mask below 2 ^ N.

theorem Cslib.Algorithms.WordRAM.Refuter4n.sort_eq_filter_range {s : Finset ℕ} {N : ℕ} (hs : ∀ i ∈ s, i < N) :
(s.sort fun (x1 x2 : ℕ) => x1 ≤ x2) = List.filter (fun (i : ℕ) => decide (i ∈ s)) (List.range N)

The sorted list of a set of names below N is the ascending filter of List.range N.

theorem Cslib.Algorithms.WordRAM.Refuter4n.find?_sort_eq_find?_range {s : Finset ℕ} {N : ℕ} (hs : ∀ i ∈ s, i < N) (p : ℕ → Bool) :
List.find? p (s.sort fun (x1 x2 : ℕ) => x1 ≤ x2) = List.find? (fun (i : ℕ) => (maskOf s).testBit i && p i) (List.range N)

A search in a sorted set of names below N is the ascending scan of its mask.

theorem Cslib.Algorithms.WordRAM.Refuter4n.findSome?_sort_eq_findSome?_range {α : Type u_1} {s : Finset ℕ} {N : ℕ} (hs : ∀ i ∈ s, i < N) (g : ℕ → Option α) :
List.findSome? g (s.sort fun (x1 x2 : ℕ) => x1 ≤ x2) = List.findSome? (fun (i : ℕ) => if (maskOf s).testBit i = true then g i else none) (List.range N)

findSome? in a sorted set of names below N is the ascending scan of its mask.

Gate rows #

The word code of an argument: const b ↦ b, node i ↦ i + 2.

The bit index 2a + b of the input pair (a, b) in a truth table.

The 4-bit truth table of a binary operation: bit idx a b is op a b.

theorem Cslib.Algorithms.WordRAM.Refuter4n.testBit_ttOf (op : Bool → Bool → Bool) (a b : Bool) :
(ttOf op).testBit (idx a b) = op a b

The truth table records the operation.

A truth table is a 4-bit word.

The code of an argument that reads only names below N is below N + 2.

A gate row of three words.

  • tt : ℕ

    The truth table of the operation.

  • left : ℕ

    The code of the left argument.

  • right : ℕ

    The code of the right argument.

Instances For

    The fields of a gate row are within their ranges for names below N.

    The row of a gate reading only names below N is within range.

    Output, pairs and equations #

    theorem Cslib.Algorithms.WordRAM.Refuter4n.litCode_lt {ℓ : Circuits.Boolean.SemiCircuit.Lit} {N : ℕ} (h : ∀ (i : ℕ), ℓ.Reads i → i < N) :
    litCode ℓ < 2 * N + 4

    The code of a literal that reads only names below N is below 2 N + 4.

    The two-word record of a pair: (2 fst + fstBias, 2 snd + sndBias).

    The word of an equation: terms below N at bits 0, …, N - 1, the right-hand side at bit N (the packed row rowWord of toDenseRow), and the alive flag at bit N + 1.

    The packed dense row of ∑ T = c at width N fits in N + 1 bits.

    Bits of the packed dense row of ∑ T = c at width N.

    @[simp]

    The alive flag of an equation word.

    Below the alive flag, an equation word is the dense XORSAT row of the equation, in the packed format of Cslib.Algorithms.WordRAM.XORSATDense.

    An equation word fits in N + 2 bits.

    Explicit rows of the parameter map #

    The value of the affine row stored in the word r: r_N + ∑_{j < N, r_j} val j.

    Substitute, in the row r, the name x by the row u: if x occurs, clear it and add u (terms and constant at once).

    theorem Cslib.Algorithms.WordRAM.Refuter4n.rowEval_two_pow {N i : ℕ} (hi : i < N) (val : ℕ → Bool) :
    rowEval N (2 ^ i) val = val i

    The row 2 ^ i is the coordinate val i.

    theorem Cslib.Algorithms.WordRAM.Refuter4n.rowEval_rowWord {N : ℕ} {T : Finset ℕ} (hT : ∀ j ∈ T, j < N) (c : Bool) (val : ℕ → Bool) :

    The packed dense row of ∑ T = c is the row c + ∑ T.

    theorem Cslib.Algorithms.WordRAM.Refuter4n.rowEval_substWord {N x : ℕ} (hx : x < N) (u r : ℕ) (val : ℕ → Bool) :
    rowEval N (substWord x u r) val = rowEval N r (Function.update val x (rowEval N u val))

    Row update. Substituting x by the row u in the row r evaluates r at the assignment giving x the value of u.

    theorem Cslib.Algorithms.WordRAM.Refuter4n.substWord_lt {N x u r : ℕ} (hx : x < N) (hu : u < 2 ^ (N + 1)) (hr : r < 2 ^ (N + 1)) :
    substWord x u r < 2 ^ (N + 1)

    Substitution keeps a row in N + 1 bits.

    The row of a literal: b ^^ neg for a constant b, val y ^^ neg for a node y.

    theorem Cslib.Algorithms.WordRAM.Refuter4n.rowEval_litWord {N : ℕ} {ℓ : Circuits.Boolean.SemiCircuit.Lit} (h : ∀ (y : ℕ), ℓ.Reads y → y < N) (val : ℕ → Bool) :
    rowEval N (litWord N ℓ) val = ℓ.eval val

    The row of a literal reading a name below N evaluates to the literal.

    The row of a literal fits in N + 1 bits.

    The words W are explicit affine rows of the parameter map of S: S.phi val i is the value of row i, and every row has its terms below N and its constant at bit N.

    • length : W.length = n

      One row per output bit.

    • lt (r : ℕ) : r ∈ W → r < 2 ^ (N + 1)

      Every row fits in N + 1 bits.

    • eval (val : ℕ → Bool) (i : Fin n) : S.phi val i = rowEval N (W.getD (↑i) 0) val

      Output bit i is the value of row i.

    Restriction x := ℓ (State.restrict, hence State.fixConst) updates every row by substituting the row of ℓ.

    Affine reparameterisation (State.swap x Q c T) updates every row by substituting x := c + val Q + ∑_{T \ {x}} val, the packed row of ∑ ((T \ {x}) ∆ {Q}) = c.

    Packed states #

    A packed refuter state (pure model of the Word-RAM memory image).

    • params : ℕ

      Bitmask of the parameters.

    • aux : ℕ

      Bitmask of the auxiliary variables.

    • gates : ℕ

      Bitmask of the gates.

    • gateRows : List GateRow

      The gate table, one row per name below N.

    • eqnRows : List ℕ

      The equation table, one word per equation name below E.

    • out : ℕ

      The code of the output literal.

    • pairs : List (ℕ × ℕ)

      The pair records.

    • phiRows : List ℕ

      The rows of the parameter map.

    Instances For

      Every word of P is below 2 ^ w.

      P represents the state S, with names below N and equation names below E.

      Every name of a represented state is below N.

      Every parameter of a represented state is below N.

      Every auxiliary variable of a represented state is below N.

      Every gate name of a represented state is below N.

      Terms of the equations of a valid represented state are named below N.

      The output of a valid represented state reads a name below N.

      The pairs of a valid represented state consist of names below N.

      There is one pair record per pair.

      For a valid state, there are at most N pair records.

      Word width. At w ≥ N + 2 and w ≥ 4, every word of a valid represented state fits.

      The table sizes of the layout #

      The name bound of the layout of C: the names along the run are below n + C.size (nameSet_iterate).

      The equation-name bound of the layout of C: the equation names at the end of the run are below 5 n + 7 C.size (eqns_refuterLoop).

      The equation table has at most 7 · nameBound C words.

      A gate row is degenerate: a constant argument (code below 2) or two equal arguments.

      (D1) on a packed state: the ascending scan of the gate mask for a degenerate row.

      The packed (D1) search returns the gate of findD1.

      Second client: the initial state #

      The packed initial state of C, with nameBound C gate rows and eqnBound C equation words.