Concrete worklist invariant for the native Chan–He traversal #
The invariant connects the reserved native stack, existing finite recursion, retained arrays, output-pointer table and fresh heap. Remaining work pays for both future output cells and future allocations. In particular, allocation bounds decrease with the mathematical work measure rather than granting an unbounded heap to each kernel call.
Main definitions #
Arena: fixed caller parameters and disjoint stack/table/heap reservations.Cursor: represented pending entries and the already emitted native pointers and nodes.Cursor.Invariant: readback, frames, exact remaining output and concrete space reservations.
These proof invariants are original and do not add a machine model or operational oracle.
Fixed parameters and concrete memory reservations of a complete native root traversal.
- n : ℕ
Maximum column cardinality.
- m : ℕ
Candidate-prime bound.
- Λ : ℕ
Label-bit parameter.
- U : ℕ
Node input magnitude.
- N : ℕ
Common number of four-cell packed groups.
- fuel : ℕ
Root recursion fuel.
- primes : ℕ
Prime bitmap base.
- stack : ℕ
Reserved native word-stack base.
- capacity : ℕ
Reserved native word-stack capacity.
- table : ℕ
Unsigned output-pointer table base.
- outputCapacity : ℕ
Reserved output-pointer table capacity.
- floor : ℕ
First address permitted for allocated heavy and packed arrays.
- ceiling : ℕ
Final upper bound on the fresh heap pointer.
Protected original memory below the stack, including the complete frontend forest.
Instances For
Persistent caller registers, including actual zero and one used by native branches.
Instances For
Exact register preservation transfers all persistent caller parameters. The heap and accumulated count are deliberately absent from this fixed register set.
Concrete non-overlap and capacity obligations for the reserved native layout.
Instances For
A single signed envelope covers both actual native kernels at every worklist transition.
Instances For
Proof state of the actual stack loop; no part of this structure is evaluated by the program.
Top-first pending entries.
- emitted : List (ℕ × ThreeSum.ChanHe.Node)
Packed base pointers and their existing mathematical nodes in emitted order.
Instances For
Remaining transitions include empty entries and zero-fuel leaves.
Instances For
Full readback and allocation invariant at the actual native loop header.
- bounded : WordRAM.Data.Bounded (w + 2) x
All actual native words fit.
- controls : a.Controls x
Persistent caller parameters have not changed.
The actual bitmap still represents all candidate primes.
- stack : WordRAM.Stack.Rep (w + 2) a.stack a.capacity (List.flatMap Entry.words s.pending) (WordRAM.Data.comap registers x)
The actual word stack represents exactly the pending entries.
- depth : Math.Bounded a.fuel (List.map Entry.task s.pending)
The existing finite depth invariant bounds pending entries.
Every pending entry retains its duplicate-free existing admissibility promise.
Every pending array has exact signed-encoded native readback.
Pending arrays avoid the entire reserved stack and output-table gap.
Every pending array lies below the current fresh allocation.
The fresh heap never enters the reserved table or stack.
Remaining work reserves enough space for every later allocation.
The accumulated native count equals the actual emitted sequence length.
Remaining work reserves enough output-table cells.
Every emitted pointer and every packed cell has exact existing-node readback.
- outputBounds (i : Fin s.emitted.length) : a.floor ≤ s.emitted[↑i].1 ∧ s.emitted[↑i].1 + 4 * a.N ≤ x.regs heap
Retained packed arrays lie above the reserved output table and below the fresh heap.
- exactOutput : List.map Prod.snd s.emitted ++ Math.output a.m.primesLE a.Λ (List.map Entry.task s.pending) = target
The emitted prefix followed by the exact pending recursion is the target sequence.
Every original cell below the reserved stack remains available to subsequent roots.
Instances For
A live loop has at least one pending entry, since each entry occupies seven actual words.
A finished actual loop has emitted the complete target, with every array already read back.