Documentation

CslibFrontier.Algorithms.WordRAM.Refuter4n.PackedAffineRepCode

Word-RAM code for the children search and the affine representation of the 4n - 9d refuter #

Standard-basis Word-RAM routines for the children search pGetChildren, the evaluation oracle pEvaluateAux and the affine representation pFindAffineRep of the packed step pApplyStep on the memory image Stored of a packed state, each with an execution theorem in the library's Word-RAM cost model (Cslib.WordRAM.ExecWithin: every instruction is charged). This file continues PackedSearchCode (issue #4322, Milestone 4); it claims no running time for a step or for the refuter.

Main definitions #

Main results #

Supporting lemmas, not results: map_childCode_pGetChildren (the coded children are the hits of childTest below N + E), childCode_lt and childOfCode_childCode (child codes are below N + E and decode back to the child; the later step programs use them) and pEvaluateAux_eq_N (the constant assignment as the unit assignment of N). The scratch window of the oracle starts at top, the first address past the image (Layout.top), so Stored.of_eq_below of PackedCode keeps the image while it is written.

The children of p (pGetChildren) are coded as numbers below N + E: the gate J as J and the equation e as N + e (childCode). In this coding they are the hits of one scan over K < N + E with the test childTest (map_childCode_pGetChildren), so the first child is the first hit, and the second child is the first hit other than the first child.

The code of a child: the gate J is J, the equation e is N + e.

Whether the code K is a child of p: a gate reading p (rowReads), or an alive equation with the term p, the two tests of pGetChildren.

The children as one scan: their codes are the hits of childTest below N + E, in order.

theorem Cslib.Algorithms.WordRAM.Refuter4n.childCode_lt {N E p : ℕ} {P : PackedState} {c : ℕ ⊕ ℕ} (hc : c ∈ pGetChildren N E p P) :
childCode N c < N + E

The code of a child is below N + E.

Decoding a child code: below N a gate, otherwise the equation K - N.

Decoding recovers every child of p.

The children search on the image, for the name Reg.argB: the gate mask, the two table bases and the bound N + E; the scan of childTest, its first hit into Reg.argC; the scan of the hits other than it (exec_childrenCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_childrenCode {w b N E n p : ℕ} {P : PackedState} (x : WordRAM.Data 32) (hb : x.regs Reg.base = b) (hN : x.regs Reg.argN = N) (hE : x.regs Reg.numE = E) (hp : x.regs Reg.argB = p) (hpN : p < N) (hw : N + 2 ≤ w) (haddr : WordRAM.Fits w (b + 5 + 3 * N + E + 1)) (hI : Stored { base := b, N := N, E := E, n := n } P x.mem) (hgl : P.gateRows.length = N) (hel : P.eqnRows.length = E) (hgates : WordRAM.Fits w P.gates) (heq : ∀ e < E, WordRAM.Fits w (P.eqnRows.getD e 0)) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w childrenCode x y ((N + E) * 61 + 21) ∧ y.mem = x.mem ∧ y.regs Reg.argC = (List.map (childCode N) (pGetChildren N E p P)).head?.getD (N + E) ∧ y.regs Reg.wT = (List.map (childCode N) (pGetChildren N E p P)).tail.head?.getD (N + E) ∧ ∀ (i : Fin 32), 14 ≤ ↑i → i ≠ Reg.argA → i ≠ Reg.argC → i ≠ Reg.argD → i ≠ Reg.passBase → i ≠ Reg.passLen → y.regs i = x.regs i

The children search on the memory image. With the base address b, the name bound N, the number E of equation words and a name p < N in Reg.base, Reg.argN, Reg.numE and Reg.argB, for the image of P at b with N gate rows, a word-sized gate mask and E word-sized equation words, childrenCode leaves the code (childCode) of the first child of p in Reg.argC and that of the second child in Reg.wT, each N + E if there is no such child, within 61 (N + E) + 21 instructions, at every width w ≥ N + 2 at which b + 5 + 3 N + E + 1 fits. It keeps the memory and every register from 14 on except Reg.argA, Reg.argC, Reg.argD, Reg.passBase and Reg.passLen.

The evaluation oracle of the affine representation #

pEvaluateAux N E a P val runs the packed elimination XORSATDense.cols on the rows auxWords. For the unit assignments val = (· == y) (y = N: no parameter is set), these rows are one filter over the codes K < E + N (auxRow: the alive equation words below their alive flag, then the rows of the parameters) followed by the row of a. The code copies them into a scratch window at Z = top (Layout.top, b + 5 + 3 N + E + n + 2 N), after the pair records when there are at most N of them (as under Rep), and calls the elimination routine XORSATDense.elimCode on that window.

theorem Cslib.Algorithms.WordRAM.Refuter4n.pEvaluateAux_eq_N (N E a : ℕ) (P : PackedState) :
(pEvaluateAux N E a P fun (j : ℕ) => j == N) = pEvaluateAux N E a P fun (x : ℕ) => false

The constant of the oracle does not see the unit assignment of N.

pEvaluateAux for the auxiliary variable Reg.argQ and the unit assignment of Reg.argC (none when it is N), into Reg.result (exec_evalAuxCode).

The time bound of evalAuxCode in the library's Word-RAM cost model.

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_evalAuxCode {w b N E n y a : ℕ} {P : PackedState} (x : WordRAM.Data 32) (hb : x.regs Reg.base = b) (hN : x.regs Reg.argN = N) (hE : x.regs Reg.numE = E) (hn : x.regs Reg.numIn = n) (hy : x.regs Reg.argC = y) (ha : x.regs Reg.argQ = a) (haN : a < N) (hw : N + 2 ≤ w) (haddr : WordRAM.Fits w ({ base := b, N := N, E := E, n := n }.top + E + N + 1)) (hI : Stored { base := b, N := N, E := E, n := n } P x.mem) (hel : P.eqnRows.length = E) (hpar : WordRAM.Fits w P.params) (heq : ∀ e < E, WordRAM.Fits w (P.eqnRows.getD e 0)) :
∃ (z : WordRAM.Data 32), WordRAM.ExecWithin w evalAuxCode x z (evalAuxTime N E) ∧ z.regs Reg.result = (pEvaluateAux N E a P fun (j : ℕ) => j == y).toNat ∧ (∀ (i : Fin 32), 14 ≤ ↑i → z.regs i = x.regs i) ∧ ∀ (c : ℕ), c < { base := b, N := N, E := E, n := n }.top ∨ { base := b, N := N, E := E, n := n }.top + E + N + 1 ≤ c → z.mem c = x.mem c

The evaluation oracle on the memory image. With the base address b, the name bound N, the numbers E and n of equation words and parameter rows, a name y and an auxiliary name a < N in Reg.base, Reg.argN, Reg.numE, Reg.numIn, Reg.argC and Reg.argQ, for the image of P at b with a word-sized parameter mask and E word-sized equation words, evalAuxCode leaves (pEvaluateAux N E a P (· == y)).toNat in Reg.result within evalAuxTime N E instructions, at every width w ≥ N + 2 at which the end Z + E + N + 1 of the scratch window at Z = top (Layout.top, the first address past the image) fits. It keeps every register from 14 on and every memory cell outside [Z, Z + E + N + 1).

The affine representation #

pFindAffineRep N E a P is the constant c = pEvaluateAux N E a P (fun _ => false) and the sum of 2 ^ y over the parameters y < N whose unit assignment changes the value. The code queries the oracle once for y = N (the constant, by pEvaluateAux_eq_N) and once for every y < N, with the loop index in Reg.argC (where the oracle reads its assignment), the constant in Reg.tmp₁ and the partial sum in Reg.tmp₂.

pFindAffineRep for the auxiliary variable Reg.argQ: the constant into Reg.tmp₁, the mask into Reg.tmp₂ (exec_findAffineRepCode).

The time bound of findAffineRepCode in the library's Word-RAM cost model: N + 1 oracle queries and 11 N + 6 further instructions.

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_findAffineRepCode {w b N E n a : ℕ} {P : PackedState} (x : WordRAM.Data 32) (hb : x.regs Reg.base = b) (hN : x.regs Reg.argN = N) (hE : x.regs Reg.numE = E) (hn : x.regs Reg.numIn = n) (ha : x.regs Reg.argQ = a) (haN : a < N) (hw : N + 2 ≤ w) (haddr : WordRAM.Fits w ({ base := b, N := N, E := E, n := n }.top + E + N + 1)) (hI : Stored { base := b, N := N, E := E, n := n } P x.mem) (hgl : P.gateRows.length ≤ N) (hel : P.eqnRows.length = E) (hpl : P.phiRows.length ≤ n) (hk : P.pairs.length ≤ N) (hpar : WordRAM.Fits w P.params) (heq : ∀ e < E, WordRAM.Fits w (P.eqnRows.getD e 0)) :
∃ (z : WordRAM.Data 32), WordRAM.ExecWithin w findAffineRepCode x z (findAffineRepTime N E) ∧ z.regs Reg.tmp₁ = (pFindAffineRep N E a P).1.toNat ∧ z.regs Reg.tmp₂ = (pFindAffineRep N E a P).2 ∧ z.regs Reg.argC = N ∧ (∀ (i : Fin 32), 14 ≤ ↑i → i ≠ Reg.argC → i ≠ Reg.tmp₁ → i ≠ Reg.tmp₂ → z.regs i = x.regs i) ∧ Stored { base := b, N := N, E := E, n := n } P z.mem ∧ ∀ (c : ℕ), c < { base := b, N := N, E := E, n := n }.top ∨ { base := b, N := N, E := E, n := n }.top + E + N + 1 ≤ c → z.mem c = x.mem c

The affine representation on the memory image. With the base address b, the name bound N, the numbers E and n of equation words and parameter rows and an auxiliary name a < N in Reg.base, Reg.argN, Reg.numE, Reg.numIn and Reg.argQ, for the image of P at b with at most N gate rows, at most n parameter rows, at most N pair records, a word-sized parameter mask and E word-sized equation words, findAffineRepCode leaves the constant (pFindAffineRep N E a P).1 (as 0 or 1) in Reg.tmp₁ and the mask (pFindAffineRep N E a P).2 in Reg.tmp₂ within findAffineRepTime N E instructions, at every width w ≥ N + 2 at which the end Z + E + N + 1 of the scratch window at Z = top (Layout.top, the first address past the image) fits. It leaves N in Reg.argC, keeps every other register from 14 on and every memory cell outside [Z, Z + E + N + 1), so the image of P too.