Documentation

CslibFrontier.Algorithms.WordRAM.Refuter4n.Evaluator

Framed Word-RAM evaluators for the 4n - 9d refuter #

The refuter of issue #4322 (Milestone 4) evaluates the hard function f : BooleanFunction n on its candidate points. The Word-RAM has no oracle instruction, so f is given as code. This module states the contract such code must meet, in the library's Word-RAM cost model, and how a caller charges its calls. No running time is claimed for the refuter here, and no polynomial-time instantiation: adapting ComputableInPolyTime.exists_wordRAM (a flat program on bit-per-word inputs) to this calling convention is separate work.

Packed input. A point x : BitString n is passed as one word, pointWord x, its number in the existing BitString.equivFin n (an abbreviation naming the calling convention, so the equivFin lemmas such as testBit_equivFin apply to it directly). The word is below 2 ^ n, so it fits at every width w ≥ n (Fits.mono (equivFin n x).isLt).

Contract. A FramedEvaluator n f r is a fixed standard-basis program code on r registers, with an input register inp, a workspace base register base, a result register out (inp ≠ base), a workspace size space and a per-call instruction bound cost. The certificate exec holds at every word width w ≥ n + 1, for every point x and every data whose register inp holds pointWord x and whose register base holds an address b with Fits w (b + space); the other registers and all memory, including the workspace window [b, b + space), are arbitrary. From such data code runs within cost instructions to data satisfying EvalPost: (f x).toNat in out, registers inp and base unchanged, and every memory cell outside the window unchanged. Window cells and the other registers are left unspecified.

The admitted widths are fixed rather than chosen by the evaluator: every w ≥ n + 1, the widths at which the packed point fits and, even for n = 0, so does the constant 1. A caller may run at any larger width its own addresses need. The workspace is at most the cost (space_le_cost), the usual space-within-time bound (a call of cost instructions accesses at most cost cells, though not necessarily contiguous ones). An evaluator that could choose its widths could hide a 2 ^ n-bit truth table of f in one constant and answer within a constant cost; with these two conditions it must either work at width n + 1 or have a window that does not fit there, and then pay cost ≥ space ≥ 2 ^ (n + 1) per call. The code itself is not bounded in length, so for one n a branching program over the bits gives cost O(n) for every f; uniformity in n is the role of the polynomial-time instantiation, which stays open.

Since the certificate starts from arbitrary window contents and scratch registers, a call needs no reset before it, and any initialisation the code performs is part of cost: every call, with its setup, is charged by cost. Since memory outside the window is arbitrary and the result is fixed, the result cannot depend on it; since it is preserved, so is any refuter state stored there. This is a stateless calling convention: unlike SubroutineBase, which carries a representation invariant and whose dirty-memory initializer initClear zero-fills its block, an evaluator keeps no state between calls and starts from dirty memory without any reset pass. It also differs from Program.ComputesInTime, which certifies a flat program started from an input list at the admitted widths its statement names: an evaluator is a structured Code run inside a caller's registers and memory, so its certificate carries a frame and starts from arbitrary data.

Calls. A caller runs code in an injective register bank g of its own register file (Code.rename). The call postcondition CallPost is EvalPost read through the bank, plus every caller register outside the bank kept. FramedEvaluator.exec_loop runs a counting loop whose body is a charged preparation, one call and a charged continuation (ExecWithin.call): from index i₀ up to the limit N it costs (N - i₀) * (tPrep + cost + tCont + 2) + 2 instructions, overhead plus the number of calls times the cost of evaluation and setup.

Instances. Witnesses of the contract live in the tests (CslibFrontierTests.Refuter4nEvaluator): a parity evaluator with no workspace and an evaluator with a one-cell window.

Main definitions #

Main results #

Packed points #

@[reducible, inline]

The packed word of a point: its number in BitString.equivFin n, with x i at bit i (testBit_equivFin).

The evaluator contract #

structure Cslib.Algorithms.WordRAM.Refuter4n.EvalPost {n r : ℕ} (f : BooleanFunction n) (inp base out : Fin r) (space : ℕ) (x : BitString n) (s t : WordRAM.Data r) :

The postcondition of one evaluation of f on x, from data s to data t, for the input register inp, the base register base, the result register out and a window of space cells at the base held in base. The memory frame is Modifies on the window's Block.footprint (Modifies.block_iff gives it cell by cell).

A framed Word-RAM evaluator for f : BooleanFunction n: a fixed standard-basis program on r registers with its calling convention and per-call instruction bound. The certificate exec holds at every width w ≥ n + 1, from any data whose register inp holds the packed point and register base a workspace base b with Fits w (b + space), with all other registers and all memory arbitrary (the window [b, b + space) included). It computes (f x).toNat into out within cost instructions, keeps inp and base, and keeps every memory cell outside the window (EvalPost).

The postcondition of one call of E in the register bank g of a caller, from caller data s on the point x to caller data t: EvalPost read through the bank (the result in g E.out, g E.inp and g E.base kept, memory outside the window kept), and every caller register outside the bank kept.

theorem Cslib.Algorithms.WordRAM.Refuter4n.FramedEvaluator.exec_loop {n : ℕ} {f : BooleanFunction n} {r r' : ℕ} (E : FramedEvaluator n f r) {g : Fin r → Fin r'} (hg : Function.Injective g) {w N tPrep tCont : ℕ} (hw : n + 1 ≤ w) {index limit : Fin r'} {prep cont : WordRAM.Code WordRAM.Basis.standard r'} (P : ℕ → WordRAM.Data r' → Prop) (hlimit : ∀ (y : WordRAM.Data r'), P (y.regs index) y → y.regs limit = N) (hstep : ∀ (y : WordRAM.Data r'), P (y.regs index) y → y.regs index < N → ∃ (a : WordRAM.Data r') (x : BitString n), WordRAM.ExecWithin w prep y a tPrep ∧ WordRAM.Fits w (a.regs (g E.base) + E.space) ∧ a.regs (g E.inp) = pointWord x ∧ ∀ (t : WordRAM.Data r'), E.CallPost g x a t → ∃ (z : WordRAM.Data r'), WordRAM.ExecWithin w cont t z tCont ∧ P (y.regs index + 1) z ∧ z.regs index = y.regs index + 1) {s : WordRAM.Data r'} (hle : s.regs index ≤ N) (hs : P (s.regs index) s) :
∃ (y : WordRAM.Data r'), WordRAM.ExecWithin w (WordRAM.Code.loop (WordRAM.Cond.lt index limit) (prep.seq ((WordRAM.Code.rename g E.code).seq cont))) s y ((N - s.regs index) * (tPrep + E.cost + tCont + 2) + 2) ∧ P N y ∧ y.regs index = N

A counting loop with one call per iteration. The body is a charged preparation prep, one call of E in the bank g and a charged continuation cont, at a width w ≥ n + 1. At each iteration below N, the preparation reaches data at which the call is admitted on some point, and the continuation re-establishes the invariant at the next index from any data satisfying CallPost. Then the loop runs within (N - i₀) * (tPrep + E.cost + tCont + 2) + 2 instructions from index i₀: every call and its setup is charged.