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 #
Cslib.Algorithms.WordRAM.Refuter4n.pointWord: the packed word of a point.Cslib.Algorithms.WordRAM.Refuter4n.EvalPost: the postcondition of one evaluation.Cslib.Algorithms.WordRAM.Refuter4n.FramedEvaluator: a fixed Word-RAM program forfwith its calling convention, cost and execution certificate.Cslib.Algorithms.WordRAM.Refuter4n.FramedEvaluator.CallPost: the postcondition of one call in a caller's register bank.
Main results #
Cslib.Algorithms.WordRAM.Refuter4n.FramedEvaluator.exec_loop: a counting loop with one call per iteration, every call charged.
Packed points #
The packed word of a point: its number in BitString.equivFin n, with x i at bit i
(testBit_equivFin).
The evaluator contract #
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).
The result register holds
(f x).toNat.The input register is kept.
The base register is kept.
Every memory cell outside the window is kept.
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).
- code : WordRAM.Code WordRAM.Basis.standard r
The fixed program.
- inp : Fin r
The register holding the packed point
pointWord x. - base : Fin r
The register holding the base address
bof the workspace window. - out : Fin r
The register receiving
(f x).toNat. - space : ℕ
The size of the workspace window
[b, b + space). - cost : ℕ
The instruction bound of one call, setup and reset included.
The input and base registers are distinct, so a caller can set both.
The workspace is at most the cost, so a large window cannot raise the admitted widths for free.
- exec {w : ℕ} (x : BitString n) (s : WordRAM.Data r) : n + 1 ≤ w → WordRAM.Fits w (s.regs self.base + self.space) → s.regs self.inp = pointWord x → ∃ (t : WordRAM.Data r), WordRAM.ExecWithin w self.code s t self.cost ∧ EvalPost f self.inp self.base self.out self.space x s t
The execution certificate, for every width
w ≥ n + 1, point and data whose window at the base held inbasefits.
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.
- mem_eq : WordRAM.Modifies { base := (WordRAM.Data.comap g s).regs E.base, length := E.space }.footprint (WordRAM.Data.comap g s).mem (WordRAM.Data.comap g t).mem
Every caller register outside the bank is kept.
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.