Documentation

CslibFrontier.Algorithms.WordRAM.Refuter4n.PackedScanCode

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

Standard-basis Word-RAM routines for scans over a range and for the searches built from them on the memory image Stored of a packed state (the fresh equation name, the term searches of the constraint deletion and the reader search), each with an execution theorem in the library's Word-RAM cost model (Cslib.WordRAM.ExecWithin: every instruction is charged). This file continues PackedOpsCode (issue #4322, Milestone 4); it claims no running time for a step or for the refuter.

Main definitions #

Main results #

@[reducible, inline]

The index of a scan (a register of the callee bank).

Scans over a range #

scanCode test runs the test test for K = 0, 1, … below the bound in Reg.passLen; the test leaves p K (as 0 or 1) in Reg.result. The scan leaves the first K with p K (or the bound if there is none, List.find?) in Reg.wT, and the last such K plus one (or 0, a List.foldl) in Reg.wQ. The searches of the packed step are scans.

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_scanCode {w N T : ℕ} (test : WordRAM.Code WordRAM.Basis.standard 32) (p : ℕ → Bool) (x : WordRAM.Data 32) (hN : x.regs Reg.passLen = N) (hfit : WordRAM.Fits w (N + 1)) (htest : ∀ (z : WordRAM.Data 32), z.mem = x.mem → (∀ (i : Fin 32), 14 ≤ ↑i → z.regs i = x.regs i) → z.regs Reg.scanIdx < N → z.regs Reg.wS = 1 → ∃ (z' : WordRAM.Data 32), WordRAM.ExecWithin w test z z' T ∧ z'.mem = z.mem ∧ z'.regs Reg.result = (p (z.regs Reg.scanIdx)).toNat ∧ ∀ (i : Fin 32), i = Reg.scanIdx ∨ i = Reg.wS ∨ i = Reg.wQ ∨ i = Reg.wT ∨ 14 ≤ ↑i → z'.regs i = z.regs i) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w (scanCode test) x y (N * (T + 8) + 6) ∧ y.mem = x.mem ∧ (∀ (i : Fin 32), 14 ≤ ↑i → y.regs i = x.regs i) ∧ y.regs Reg.wT = (List.find? p (List.range N)).getD N ∧ y.regs Reg.wQ = List.foldl (fun (a K : ℕ) => if p K = true then K + 1 else a) 0 (List.range N)

A scan over a range. Let the caller's state x hold the bound N in Reg.passLen, and let test be a routine that, from any state with the memory of x, the registers from 14 on of x, an index K < N in Reg.scanIdx and 1 in Reg.wS, leaves (p K).toNat in Reg.result within T instructions, keeps the memory and keeps Reg.scanIdx, Reg.wS, Reg.wQ, Reg.wT and every register from 14 on. At every width at which N + 1 fits, scanCode test leaves ((List.range N).find? p).getD N in Reg.wT and (List.range N).foldl (fun a K => if p K then K + 1 else a) 0 in Reg.wQ within N (T + 8) + 6 instructions, keeping the memory and every register from 14 on.

The fresh equation name #

pFreshEqn on the image: the equation table and its size, then the scan of the alive flags; the fresh name is left in Reg.wQ (exec_freshEqnCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_freshEqnCode {w b N E n : ℕ} {P : PackedState} (x : WordRAM.Data 32) (hb : x.regs Reg.base = b) (hN : x.regs Reg.argN = N) (hE : x.regs Reg.numE = E) (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) (hel : P.eqnRows.length = E) (heq : ∀ e < E, WordRAM.Fits w (P.eqnRows.getD e 0)) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w freshEqnCode x y (13 * E + 12) ∧ y.mem = x.mem ∧ y.regs Reg.wQ = pFreshEqn N E P ∧ ∀ (i : Fin 32), 14 ≤ ↑i → i ≠ Reg.passBase → i ≠ Reg.passLen → y.regs i = x.regs i

The fresh equation name on the memory image. With the base address b, the name bound N and the number E of equation words in Reg.base, Reg.argN and Reg.numE, for the image of P at b with E word-sized equation words, freshEqnCode leaves pFreshEqn N E P in Reg.wQ within 13 E + 12 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.passBase and Reg.passLen.

The term searches of the constraint deletion #

The least name below Reg.passLen that is a bit of both Reg.argA and Reg.argD, into Reg.wT (exec_bothBitsCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_bothBitsCode {w N W A : ℕ} (x : WordRAM.Data 32) (hW : x.regs Reg.argA = W) (hA : x.regs Reg.argD = A) (hN : x.regs Reg.passLen = N) (hfW : WordRAM.Fits w W) (hfA : WordRAM.Fits w A) (hfit : WordRAM.Fits w (N + 1)) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w bothBitsCode x y (13 * N + 6) ∧ y.mem = x.mem ∧ (∀ (i : Fin 32), 14 ≤ ↑i → y.regs i = x.regs i) ∧ y.regs Reg.wT = (List.find? (fun (i : ℕ) => W.testBit i && A.testBit i) (List.range N)).getD N

The least common bit. With words W and A in Reg.argA and Reg.argD and the bound N in Reg.passLen, bothBitsCode leaves ((List.range N).find? fun i => W.testBit i && A.testBit i).getD N in Reg.wT within 13 N + 6 instructions, at every width at which W, A and N + 1 fit, keeping the memory and every register from 14 on.

The least name below Reg.passLen other than Reg.argB that is a bit of Reg.argA, into Reg.wT (exec_otherBitCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_otherBitCode {w N W v : ℕ} (x : WordRAM.Data 32) (hW : x.regs Reg.argA = W) (hv : x.regs Reg.argB = v) (hN : x.regs Reg.passLen = N) (hfW : WordRAM.Fits w W) (hfit : WordRAM.Fits w (N + 1)) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w otherBitCode x y (15 * N + 6) ∧ y.mem = x.mem ∧ (∀ (i : Fin 32), 14 ≤ ↑i → y.regs i = x.regs i) ∧ y.regs Reg.wT = (List.find? (fun (i : ℕ) => W.testBit i && i != v) (List.range N)).getD N

The least other bit. With a word W in Reg.argA, a name v in Reg.argB and the bound N in Reg.passLen, otherBitCode leaves ((List.range N).find? fun i => W.testBit i && i != v).getD N in Reg.wT within 15 N + 6 instructions, at every width at which W and N + 1 fit, keeping the memory and every register from 14 on.

Whether the gate Reg.scanIdx is live (its bit of the gate mask in Reg.argA) and reads the name Reg.argB (rowReads of its row in the gate table at Reg.passBase), into Reg.result (exec_gateReadsCode). The reader search and the children search share it.

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_gateReadsCode {w G K p gates : ℕ} {r : GateRow} (z : WordRAM.Data 32) (hK : z.regs Reg.scanIdx = K) (ho : z.regs Reg.wS = 1) (hA : z.regs Reg.argA = gates) (hG : z.regs Reg.passBase = G) (hp : z.regs Reg.argB = p) (hrow : GateRowAt G K r z.mem) (hf : WordRAM.Fits w (G + 3 * K + 2)) (hfp : WordRAM.Fits w (p + 2)) (hgates : WordRAM.Fits w gates) :
∃ (z' : WordRAM.Data 32), WordRAM.ExecWithin w gateReadsCode z z' 18 ∧ z'.mem = z.mem ∧ z'.regs Reg.result = (gates.testBit K && rowReads r p).toNat ∧ ∀ (i : Fin 32), i = Reg.scanIdx ∨ i = Reg.wS ∨ i = Reg.wQ ∨ i = Reg.wT ∨ 14 ≤ ↑i → z'.regs i = z.regs i

The live-gate reader test. For the gate K in Reg.scanIdx, a gate mask in Reg.argA, a gate table at G in Reg.passBase with the row r of K, and a name p in Reg.argB, gateReadsCode leaves (gates.testBit K && rowReads r p).toNat in Reg.result within 18 instructions, at every width at which G + 3 K + 2, p + 2 and the mask fit. It keeps the memory and the registers Reg.scanIdx, Reg.wS, Reg.wQ, Reg.wT and every register from 14 on.

pFindReader on the image: the gate mask, the gate table, then the scan; the reader (or N) is left in Reg.wT (exec_readerCode).

theorem Cslib.Algorithms.WordRAM.Refuter4n.exec_readerCode {w b N E n G : ℕ} {P : PackedState} (x : WordRAM.Data 32) (hb : x.regs Reg.base = b) (hN : x.regs Reg.argN = N) (hG : x.regs Reg.argB = G) (hGN : G < N) (hw : N + 2 ≤ w) (haddr : WordRAM.Fits w (b + 5 + 3 * N)) (hI : Stored { base := b, N := N, E := E, n := n } P x.mem) (hgl : P.gateRows.length = N) (hgates : WordRAM.Fits w P.gates) :
∃ (y : WordRAM.Data 32), WordRAM.ExecWithin w readerCode x y (28 * N + 12) ∧ y.mem = x.mem ∧ y.regs Reg.wT = (pFindReader N G P).getD N ∧ ∀ (i : Fin 32), 14 ≤ ↑i → i ≠ Reg.argA → i ≠ Reg.passBase → i ≠ Reg.passLen → y.regs i = x.regs i

The reader search on the memory image. With the base address b, the name bound N and a gate name G < N in Reg.base, Reg.argN and Reg.argB, for the image of P at b with N gate rows and a word-sized gate mask, readerCode leaves (pFindReader N G P).getD N in Reg.wT within 28 N + 12 instructions, at every width w ≥ N + 2 at which b + 5 + 3 N fits. It keeps the memory and every register from 14 on except Reg.argA, Reg.passBase and Reg.passLen.