Documentation

CslibFrontier.Algorithms.WordRAM.Refuter4n.PackedOpsCode

Word-RAM code for the state operations of the packed 4n - 9d refuter #

Standard-basis Word-RAM routines for the state operations of PackedOps on the memory image of a packed state (Stored of InputLayout), each with an execution theorem in the library's Word-RAM cost model (Cslib.WordRAM.ExecWithin: every instruction is charged). The execution theorems are stated for the image at a layout L, with the addresses of Layout; each routine reads the sizes it needs from Reg.base, Reg.argN, Reg.numE and Reg.numIn. This file continues PackedCode (issue #4322, Milestone 4); it claims no running time for a step or for the refuter.

Main definitions #

Main results #

@[reducible, inline]

The number n of parameter rows.

@[reducible, inline]

An equation name.

@[reducible, inline]

The auxiliary variable of a swap.

@[reducible, inline]

The first word of a pair record.

@[reducible, inline]

The second word of a pair record.

@[reducible, inline]

A temporary register of the state operations.

@[reducible, inline]

A temporary register of the state operations.

Updates of the stored state #

How Stored changes when a mask, an equation word, the parameter rows or the pair records change, at any layout L. Stored is over the full tables of the state, so a lemma that writes a table cell takes the lengths of the tables stored before that cell. The lemmas read the old state with Stored.gateRow, Stored.eqnRow, Stored.phiRow and Stored.pair, and build the new one with Stored.of_words.

Mask and equation-word routines #

Dropping and deleting equations, deleting gates, adding pairs #

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_dropTrivialEqnCode {w e : ℕ} {L : Layout} {P : PackedState} (x : WordRAM.Data 32) (hb : x.regs Reg.base = L.base) (hN : x.regs Reg.argN = L.N) (he : x.regs Reg.eqnIdx = e) (heE : e < L.E) (hgl : P.gateRows.length ≤ L.N) (haddr : WordRAM.Fits w (L.phiAddr 0)) (hI : Stored L P x.mem) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w dropTrivialEqnCode x y 8 ∧ Stored L (PackedState.dropTrivialEqn e P) y.mem ∧ (∀ (j : Fin 32), 14 ≤ ↑j → j ≠ Reg.passWord → y.regs j = x.regs j) ∧ ∀ (c : ℕ), c < L.eqnAddr 0 ∨ L.phiAddr 0 ≤ c → y.mem c = x.mem c

dropTrivialEqn on the memory image. With the equation name e < L.E in Reg.eqnIdx, dropTrivialEqnCode turns the image of P at the layout L, a state with at most L.N gate rows, into the image of P.dropTrivialEqn e within 8 instructions, at every width at which L.phiAddr 0 fits, changing no register from 14 on except Reg.passWord and no cell outside the equation table.

PackedState.dropEqn on the image: clear the auxiliary bit Reg.argB, then drop the equation word Reg.eqnIdx (exec_dropEqnCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_dropEqnCode {w e v : ℕ} {L : Layout} {P : PackedState} (x : WordRAM.Data 32) (hb : x.regs Reg.base = L.base) (hN : x.regs Reg.argN = L.N) (he : x.regs Reg.eqnIdx = e) (hv : x.regs Reg.argB = v) (heE : e < L.E) (hgl : P.gateRows.length ≤ L.N) (haddr : WordRAM.Fits w (L.phiAddr 0)) (hfv : WordRAM.Fits w (2 ^ v)) (haux : WordRAM.Fits w P.aux) (hI : Stored L P x.mem) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w dropEqnCode x y 18 ∧ Stored L (PackedState.dropEqn e v P) y.mem ∧ (∀ (j : Fin 32), 14 ≤ ↑j → j ≠ Reg.argA → j ≠ Reg.passWord → y.regs j = x.regs j) ∧ ∀ (c : ℕ), c < L.base ∨ L.phiAddr 0 ≤ c → y.mem c = x.mem c

dropEqn on the memory image. With the auxiliary name v in Reg.argB and the equation name e < L.E in Reg.eqnIdx, dropEqnCode turns the image of P at the layout L, a state with at most L.N gate rows and a word-sized auxiliary mask, into the image of P.dropEqn e v within 18 instructions, at every width at which L.phiAddr 0 and 2 ^ v fit, changing no register from 14 on except Reg.argA and Reg.passWord, and no cell below L.base or from L.phiAddr 0 on.

PackedState.deleteGate on the image: the substitution step with the gate name in Reg.passVar, then clear its bit in the gate mask (exec_deleteGateCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_deleteGateCode {w J la ln : ℕ} {L : Layout} {P : PackedState} (x : WordRAM.Data 32) (hb : x.regs Reg.base = L.base) (hN : x.regs Reg.argN = L.N) (hE : x.regs Reg.numE = L.E) (hv : x.regs Reg.passVar = J) (hla : x.regs Reg.argB = la) (hln : x.regs Reg.argC = ln) (hJN : J < L.N) (haN : la < L.N + 2) (hln1 : ln ≤ 1) (h4 : 4 ≤ w) (hw : L.N + 2 ≤ w) (haddr : WordRAM.Fits w (L.phiAddr 0)) (hI : Stored L P x.mem) (hgl : P.gateRows.length = L.N) (hel : P.eqnRows.length = L.E) (htt : ∀ r ∈ P.gateRows, WordRAM.Fits w r.tt) (heq : ∀ e ∈ P.eqnRows, e < 2 ^ (L.N + 2)) (hout : WordRAM.Fits w P.out) (hgates : WordRAM.Fits w P.gates) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w deleteGateCode x y (37 * L.N + 14 * L.E + 60) ∧ Stored L (PackedState.deleteGate L.N J la ln P) y.mem ∧ (∀ (i : Fin 32), 14 ≤ ↑i → i ≠ Reg.passBase → i ≠ Reg.passLen → i ≠ Reg.passWord → i ≠ Reg.argA → i ≠ Reg.argB → i ≠ Reg.argD → y.regs i = x.regs i) ∧ ∀ (c : ℕ), c < L.base ∨ L.phiAddr 0 ≤ c → y.mem c = x.mem c

deleteGate on the memory image. Under the hypotheses of exec_substStateCode with the gate name J as the rerouted name, and a word-sized gate mask, deleteGateCode turns the image of P at the layout L into the image of P.deleteGate L.N J la ln within 37 L.N + 14 L.E + 60 instructions, changing no register from 14 on except Reg.passBase, Reg.passLen, Reg.passWord, Reg.argA, Reg.argB and Reg.argD, and no cell below L.base or from L.phiAddr 0 on.

PackedState.deleteEqn on the image: the substitution step with the auxiliary name in Reg.passVar, then dropEqnCode (exec_deleteEqnCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_deleteEqnCode {w e v la ln : ℕ} {L : Layout} {P : PackedState} (x : WordRAM.Data 32) (hb : x.regs Reg.base = L.base) (hN : x.regs Reg.argN = L.N) (hE : x.regs Reg.numE = L.E) (hv : x.regs Reg.passVar = v) (hla : x.regs Reg.argB = la) (hln : x.regs Reg.argC = ln) (he : x.regs Reg.eqnIdx = e) (hvN : v < L.N) (heE : e < L.E) (haN : la < L.N + 2) (hln1 : ln ≤ 1) (h4 : 4 ≤ w) (hw : L.N + 2 ≤ w) (haddr : WordRAM.Fits w (L.phiAddr 0)) (hI : Stored L P x.mem) (hgl : P.gateRows.length = L.N) (hel : P.eqnRows.length = L.E) (htt : ∀ r ∈ P.gateRows, WordRAM.Fits w r.tt) (heq : ∀ e ∈ P.eqnRows, e < 2 ^ (L.N + 2)) (hout : WordRAM.Fits w P.out) (haux : WordRAM.Fits w P.aux) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w deleteEqnCode x y (37 * L.N + 14 * L.E + 68) ∧ Stored L (PackedState.deleteEqn L.N e v la ln P) y.mem ∧ (∀ (i : Fin 32), 14 ≤ ↑i → i ≠ Reg.passBase → i ≠ Reg.passLen → i ≠ Reg.passWord → i ≠ Reg.argA → i ≠ Reg.argB → i ≠ Reg.argD → y.regs i = x.regs i) ∧ ∀ (c : ℕ), c < L.base ∨ L.phiAddr 0 ≤ c → y.mem c = x.mem c

deleteEqn on the memory image. Under the hypotheses of exec_substStateCode with the auxiliary name v as the rerouted name, the equation name e < L.E in Reg.eqnIdx and a word-sized auxiliary mask, deleteEqnCode turns the image of P at the layout L into the image of P.deleteEqn L.N e v la ln within 37 L.N + 14 L.E + 68 instructions, changing no register from 14 on except Reg.passBase, Reg.passLen, Reg.passWord, Reg.argA, Reg.argB and Reg.argD, and no cell below L.base or from L.phiAddr 0 on.

PackedState.addPair on the image: after pairBase, write the record (Reg.pairFst, Reg.pairSnd) after the k records and store the count k + 1 (exec_addPairCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_addPairCode {w : ℕ} {L : Layout} {P : PackedState} {c : ℕ × ℕ} (x : WordRAM.Data 32) (hb : x.regs Reg.base = L.base) (hN : x.regs Reg.argN = L.N) (hE : x.regs Reg.numE = L.E) (hn : x.regs Reg.numIn = L.n) (h₁ : x.regs Reg.pairFst = c.1) (h₂ : x.regs Reg.pairSnd = c.2) (haddr : WordRAM.Fits w (L.pairAddr P.pairs.length 1)) (hI : Stored L P x.mem) (hgl : P.gateRows.length = L.N) (hel : P.eqnRows.length = L.E) (hpl : P.phiRows.length = L.n) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w addPairCode x y 18 ∧ Stored L (PackedState.addPair c P) y.mem ∧ (∀ (j : Fin 32), 14 ≤ ↑j → y.regs j = x.regs j) ∧ ∀ (a : ℕ), a ≠ L.base + 4 → a < L.pairAddr P.pairs.length 0 ∨ L.pairAddr P.pairs.length 1 < a → y.mem a = x.mem a

addPair on the memory image. With the record c in Reg.pairFst, Reg.pairSnd, addPairCode turns the image of P at the layout L, a state with L.N gate rows, L.E equation words and L.n parameter rows, into the image of P.addPair c within 18 instructions, changing no register from 14 on and no cell other than the count and the two new words, at every width at which the address L.pairAddr k 1 of the last new word fits, where k is the number of records.

Swapping a parameter and an auxiliary variable #

PackedState.swap on the image: the parameter Reg.passVar and the auxiliary variable Reg.argQ exchange their mask bits, and the row Reg.passWord is substituted for the parameter in every parameter row (exec_swapCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_swapCode {w x Q u : ℕ} {L : Layout} {P : PackedState} (y₀ : WordRAM.Data 32) (hb : y₀.regs Reg.base = L.base) (hN : y₀.regs Reg.argN = L.N) (hE : y₀.regs Reg.numE = L.E) (hn : y₀.regs Reg.numIn = L.n) (hx : y₀.regs Reg.passVar = x) (hQ : y₀.regs Reg.argQ = Q) (hu : y₀.regs Reg.passWord = u) (hxN : x < L.N) (hQN : Q < L.N) (huN : u < 2 ^ (L.N + 1)) (hw : L.N + 2 ≤ w) (haddr : WordRAM.Fits w (L.phiAddr L.n)) (hI : Stored L P y₀.mem) (hgl : P.gateRows.length = L.N) (hel : P.eqnRows.length = L.E) (hpl : P.phiRows.length = L.n) (hpar : WordRAM.Fits w P.params) (haux : WordRAM.Fits w P.aux) (hphi : ∀ r ∈ P.phiRows, r < 2 ^ (L.N + 1)) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w swapCode y₀ y (14 * L.n + 57) ∧ Stored L (PackedState.swap x Q u P) y.mem ∧ (∀ (i : Fin 32), 14 ≤ ↑i → i ≠ Reg.passBase → i ≠ Reg.passLen → i ≠ Reg.argA → i ≠ Reg.argB → y.regs i = y₀.regs i) ∧ ∀ (c : ℕ), c ≠ L.base → c ≠ L.base + 1 → c < L.phiAddr 0 ∨ L.phiAddr L.n ≤ c → y.mem c = y₀.mem c

swap on the memory image. With the parameter x < L.N in Reg.passVar, the auxiliary variable Q < L.N in Reg.argQ and a row u < 2 ^ (L.N + 1) in Reg.passWord, swapCode turns the image of P at the layout L into the image of P.swap x Q u within 14 L.n + 57 instructions, at every width w ≥ L.N + 2 at which the end L.phiAddr L.n of the parameter rows fits, for a word-sized parameter mask and auxiliary mask, L.N gate rows, L.E equation words and L.n parameter rows below 2 ^ (L.N + 1). It changes no register from 14 on except Reg.passBase, Reg.passLen, Reg.argA and Reg.argB, and no cell other than the two masks and the parameter rows.

Moving an affine gate into the system #

PackedState.moveAffine on the image: the equation word affWord of the gate Reg.argB becomes the equation Reg.eqnIdx, the gate bit is cleared and the auxiliary bit set (exec_moveAffineCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_moveAffineCode {w J e : ℕ} {L : Layout} {P : PackedState} (x : WordRAM.Data 32) (hb : x.regs Reg.base = L.base) (hN : x.regs Reg.argN = L.N) (hJ : x.regs Reg.argB = J) (he : x.regs Reg.eqnIdx = e) (hJN : J < L.N) (heE : e < L.E) (h4 : 4 ≤ w) (hw : L.N + 2 ≤ w) (haddr : WordRAM.Fits w (L.phiAddr 0)) (hI : Stored L P x.mem) (hgl : P.gateRows.length = L.N) (hrow : RowLt L.N (P.gateRows.getD J { tt := 0, left := 0, right := 0 })) (hgates : WordRAM.Fits w P.gates) (haux : WordRAM.Fits w P.aux) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w moveAffineCode x y 73 ∧ Stored L (PackedState.moveAffine L.N J e P) y.mem ∧ (∀ (i : Fin 32), 14 ≤ ↑i → i ≠ Reg.argA → i ≠ Reg.argD → i ≠ Reg.passWord → i ≠ Reg.tmp₁ → i ≠ Reg.tmp₂ → y.regs i = x.regs i) ∧ ∀ (c : ℕ), c < L.base ∨ L.phiAddr 0 ≤ c → y.mem c = x.mem c

moveAffine on the memory image. With the gate name J < L.N in Reg.argB and the equation name e < L.E in Reg.eqnIdx, for a gate row of J within range, a word-sized gate mask and auxiliary mask and L.N gate rows, moveAffineCode turns the image of P at the layout L into the image of P.moveAffine L.N J e within 73 instructions, at every width w ≥ max 4 (L.N + 2) at which L.phiAddr 0 fits. It changes no register from 14 on except Reg.argA, Reg.argD, Reg.passWord, Reg.tmp₁ and Reg.tmp₂, and no cell below L.base or from L.phiAddr 0 on.

Restriction: filtering the pair records #

PackedState.restrictAvoid on the image: the substitution step for the parameter Reg.passVar, the substitution pass on the parameter rows with the row of the literal that the substitution step leaves in Reg.passWord, the parameter bit, and the pair records avoiding the parameter (exec_restrictCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_restrictCode {w x la ln : ℕ} {L : Layout} {P : PackedState} (y₀ : WordRAM.Data 32) (hb : y₀.regs Reg.base = L.base) (hN : y₀.regs Reg.argN = L.N) (hE : y₀.regs Reg.numE = L.E) (hn : y₀.regs Reg.numIn = L.n) (hx : y₀.regs Reg.passVar = x) (hla : y₀.regs Reg.argB = la) (hln : y₀.regs Reg.argC = ln) (hxN : x < L.N) (haN : la < L.N + 2) (hln1 : ln ≤ 1) (h4 : 4 ≤ w) (hw : L.N + 2 ≤ w) (haddr : WordRAM.Fits w (L.pairAddr P.pairs.length 0)) (hI : Stored L P y₀.mem) (hgl : P.gateRows.length = L.N) (hel : P.eqnRows.length = L.E) (hpl : P.phiRows.length = L.n) (htt : ∀ r ∈ P.gateRows, WordRAM.Fits w r.tt) (heq : ∀ e ∈ P.eqnRows, e < 2 ^ (L.N + 2)) (hout : WordRAM.Fits w P.out) (hpar : WordRAM.Fits w P.params) (hphi : ∀ r ∈ P.phiRows, r < 2 ^ (L.N + 1)) (hpf : ∀ c ∈ P.pairs, WordRAM.Fits w c.1 ∧ WordRAM.Fits w c.2) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w restrictCode y₀ y (37 * L.N + 14 * L.E + 14 * L.n + 20 * P.pairs.length + 93) ∧ Stored L (PackedState.restrictAvoid L.N x la ln P) y.mem ∧ (∀ (i : Fin 32), 14 ≤ ↑i → i ≠ Reg.passBase → i ≠ Reg.passLen → i ≠ Reg.passWord → i ≠ Reg.argA → i ≠ Reg.argB → i ≠ Reg.argD → y.regs i = y₀.regs i) ∧ ∀ (c : ℕ), c < L.base ∨ L.pairAddr P.pairs.length 0 ≤ c → y.mem c = y₀.mem c

restrictAvoid on the memory image. Let the caller's state hold the base address L.base, the name bound L.N, the numbers L.E and L.n of equation words and parameter rows, a parameter x < L.N, an argument code la < L.N + 2 and a negation bit ln ≤ 1 in Reg.base, Reg.argN, Reg.numE, Reg.numIn, Reg.passVar, Reg.argB and Reg.argC, and let the memory hold the image of P at the layout L, with L.N gate rows, L.E equation words below 2 ^ (L.N + 2), L.n parameter rows below 2 ^ (L.N + 1), word-sized truth tables, output code, parameter mask and pair records. At every width w ≥ max 4 (L.N + 2) at which the end L.pairAddr m 0 of the pair records fits, where m is the number of pair records, restrictCode leaves the image of P.restrictAvoid L.N x la ln within 37 L.N + 14 L.E + 14 L.n + 20 m + 93 instructions. It changes no register from 14 on except Reg.passBase, Reg.passLen, Reg.passWord, Reg.argA, Reg.argB and Reg.argD, and no cell below L.base or from L.pairAddr m 0 on.