Documentation

CslibFrontier.Algorithms.WordRAM.Refuter4n.PackedOps

Packed primitive operations of the 4n - 9d refuter #

The refuter step applyStep (Cslib.Circuits.Boolean.AffineDisperser4n) is built from a few state operations: rerouting a name to a literal (inside State.deleteGate, State.restrict and State.deleteEqn), dropping equations, moving an affine gate into the affine system, the affine reparameterisation State.swap and pair creation State.addPair. This file gives each of them as a word-level operation on the packed state PackedState and proves that it represents the state operation (Rep). This is the pure layer of the step programs of issue #4322 (Milestone 4); no program and no running time is claimed here.

The operations read and write only words: names, argument codes argCode, negation bits and packed rows. A literal ℓ enters as its argument code argCode ℓ.arg and negation bit ℓ.neg.toNat.

Main definitions #

Main results #

Masks #

Clear bit i of the mask m.

Set bit i of the mask m.

Erasing a name clears its bit.

Inserting a name sets its bit.

Rerouting in gate rows and in the output #

The negation bit ln absorbed for the argument code c when v is rerouted.

The argument code c with v rerouted to the code la.

Reroute v to the literal with argument code la and negation bit ln in a gate row.

theorem Cslib.Algorithms.WordRAM.Refuter4n.rowLt_substRow {N v la ln : ℕ} {r : GateRow} (hr : RowLt N r) (hla : la < N + 2) :
RowLt N (substRow v la ln r)

Rerouting keeps a row within range.

Reroute v to the literal with argument code la and negation bit ln in the output code o = 2 · argCode + neg.

Rerouting in the output code is Lit.subst.

Rows of literals, equations and moved gates #

The row of an argument code: the constant a at bit N for a < 2, and the term a - 2 otherwise.

The row of the literal with argument code la and negation bit ln.

theorem Cslib.Algorithms.WordRAM.Refuter4n.argWord_lt {N a : ℕ} (ha : a < N + 2) :
argWord N a < 2 ^ (N + 1)

The row of an argument code below N + 2 fits in N + 1 bits.

theorem Cslib.Algorithms.WordRAM.Refuter4n.litWordOf_lt {N la ln : ℕ} (haN : la < N + 2) (hln : ln ≤ 1) :
litWordOf N la ln < 2 ^ (N + 1)

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

theorem Cslib.Algorithms.WordRAM.Refuter4n.litWordOf_eq {N : ℕ} {ℓ : Circuits.Boolean.SemiCircuit.Lit} (h : ∀ (y : ℕ), ℓ.Reads y → y < N) :
litWordOf N (argCode ℓ.arg) ℓ.neg.toNat = litWord N ℓ

litWordOf computes the row litWord of a literal from its codes.

The equation word of the affine gate with row r moved into the affine system as J (affEqn): the terms J, left (if the operation depends on it) and right (likewise), the constant op false false at bit N and the alive flag at bit N + 1.

affWord computes the word of the equation affEqn from the row of the gate.

theorem Cslib.Algorithms.WordRAM.Refuter4n.testBit_eqnWord (N : ℕ) (e : Circuits.Boolean.SemiCircuit.Equation) (alive : Bool) (i : ℕ) :
(eqnWord N e alive).testBit i = ((if i < N then decide (i ∈ e.terms) else decide (i = N) && e.rhs) || decide (i = N + 1) && alive)

The bits of an equation word: terms below N, the right-hand side at N and the alive flag at N + 1.

theorem Cslib.Algorithms.WordRAM.Refuter4n.substWord_eqnWord {N v : ℕ} (hv : v < N) {ℓ : Circuits.Boolean.SemiCircuit.Lit} (hℓ : ∀ (y : ℕ), ℓ.Reads y → y < N) {e : Circuits.Boolean.SemiCircuit.Equation} (he : ∀ j ∈ e.terms, j < N) (alive : Bool) :
substWord v (litWord N ℓ) (eqnWord N e alive) = eqnWord N (e.subst v ℓ) alive

Equation update. Rerouting v to ℓ in an equation (Equation.subst) is the row substitution substWord of the parameter map applied to its word, with the row of ℓ.

Packed operations #

The pair record c avoids the name x.

Reroute v to the literal with argument code la and negation bit ln in every gate row, every equation word and the output (SemiCircuit.subst).

theorem Cslib.Algorithms.WordRAM.Refuter4n.PackedState.getD_gateRows_subst (N v la ln J : ℕ) (P : PackedState) :
(subst N v la ln P).gateRows.getD J { tt := 0, left := 0, right := 0 } = substRow v la ln (P.gateRows.getD J { tt := 0, left := 0, right := 0 })

A gate row after substitution (the zero row is fixed).

An equation word after substitution (the zero word is fixed).

Delete the gate J, rerouting it to the literal (la, ln) (State.deleteGate).

Restrict the parameter x to the literal (la, ln), keeping the pairs avoiding x (State.restrict x ℓ (S.pairsAvoid x), hence State.fixConst).

Delete the equation e and the auxiliary variable v, rerouting v to the literal (la, ln) (State.deleteEqn).

Drop the equation e and the auxiliary variable v (State.dropEqn).

Move the gate J into the affine system with the equation name e (State.moveAffine).

Exchange the parameter x and the auxiliary variable Q, substituting the row u for x in the parameter map (State.swap).

Representation of the packed operations #

Bounded states #

The names read by the equations, the gates and the output of S are below N. A valid represented state is bounded (Rep.bounded). Gate deletion, restriction and equation deletion by a literal reading names below N, dropping an equation, swapping, adding a pair, and moving a gate below N preserve it (Bounded.deleteGate to Bounded.moveAffine).

  • terms (e : ℕ) : e ∈ S.eqns → ∀ j ∈ (S.eqn e).terms, j < N

    Terms of equations are below N.

  • reads (J : ℕ) : J ∈ S.gates → ∀ (i : ℕ), (S.gate J).Reads i → i < N

    Names read by gates are below N.

  • out (i : ℕ) : S.out.Reads i → i < N

    The name read by the output is below N.

Deleting a gate preserves boundedness.

Deleting an equation preserves boundedness.

The affine reparameterisation preserves boundedness.

Moving a gate named below N into the affine system preserves boundedness.

Deleting a gate. PackedState.deleteGate represents State.deleteGate J ℓ.

Fixing a parameter. PackedState.restrictAvoid N w b.toNat 0 represents State.fixConst w b.

Dropping an equation. PackedState.dropEqn represents State.dropEqn e v: the trivial drop of e, and v leaves the auxiliary variables.

theorem Cslib.Algorithms.WordRAM.Refuter4n.Rep.deleteEqn {n N E : ℕ} {P : PackedState} {S : Circuits.Boolean.AffineDisperser4n.State n} (h : Rep N E P S) (hB : Bounded N S) (e : ℕ) {v : ℕ} (hv : v < N) {ℓ : Circuits.Boolean.SemiCircuit.Lit} (hℓ : ∀ (y : ℕ), ℓ.Reads y → y < N) :

Deleting an equation. PackedState.deleteEqn represents State.deleteEqn e v ℓ: the rerouting of v to ℓ followed by the drop of e and v.

Moving an affine gate. PackedState.moveAffine represents State.moveAffine J e for a gate J and an equation name e < E.

Affine reparameterisation. PackedState.swap with the row of ∑ ((T \ {x}) ∆ {Q}) = c represents State.swap x Q c T.