Documentation

CslibFrontier.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalStackFrame

Worklist facts that survive a stack-only native step #

Popping a pending entry changes memory only inside the reserved native stack and keeps the persistent caller registers 71–95. The worklist facts shared by the catalogue and visitor cursors therefore transfer to the popped state: the heap pointer and the floor below it, the output-count register, the caller controls, memory outside the reserved interval, the prime bitmap, and the readback and heap bounds of the pending entries. The lemma also records that the reserved stack fits in the gap below the floor. Callers still derive the other invariant fields, such as the output and its bounds, the heap budget and protected memory.

Both the native traversal and the fused decision visitor pop an entry before each transition, so they share this argument.

Main results #

These invariant proofs are original.

theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Traversal.Arena.stack_frame (a : Arena) {mem₁ mem₂ : ℕ → ℕ} (hframe : WordRAM.Modifies (WordStack.footprint a.stack a.capacity) mem₁ mem₂) (q : ℕ) (hq : q < a.stack ∨ a.stack + a.capacity ≤ q) :
mem₂ q = mem₁ q

A step that modifies only the reserved native stack leaves memory outside [a.stack, a.stack + a.capacity) unchanged.

theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Traversal.Entry.Stored.of_arena_frame {a : Arena} {e : Entry} {mem₁ mem₂ : ℕ → ℕ} (hs : e.Stored mem₁) (ha : a.Separated) (har : e.Around a.stack (a.floor - a.stack)) (hframe : WordRAM.Modifies (WordStack.footprint a.stack a.capacity) mem₁ mem₂) :
e.Stored mem₂

An entry whose arrays avoid [a.stack, a.floor) retains its readback across a stack-only memory modification.

theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Traversal.StoredNodes.of_arena_frame {a : Arena} {ns : List (ℕ × ThreeSum.ChanHe.Node)} {mem₁ mem₂ : ℕ → ℕ} (ho : StoredNodes a.U a.N a.table ns mem₁) (ha : a.Separated) (hb : ∀ (i : Fin ns.length), a.floor ≤ ns[↑i].1) (hframe : WordRAM.Modifies (WordStack.footprint a.stack a.capacity) mem₁ mem₂) :
StoredNodes a.U a.N a.table ns mem₂

Emitted pointer-table entries and packed node arrays above a.floor retain their readback across a stack-only memory modification.

theorem Cslib.Algorithms.WordRAM.ThreeSum.ChanHe.Traversal.Arena.preserved_of_stack_frame {a : Arena} {es : List Entry} (x y : WordRAM.Data 128) (ha : a.Separated) (hc : a.Controls x) (hb : a.Bitmap x.mem) (hs : ∀ d ∈ es, d.Stored x.mem) (har : ∀ d ∈ es, d.Around a.stack (a.floor - a.stack)) (hen : ∀ d ∈ es, ∀ (j : Fin 3), d.source j + (d.data j).length ≤ x.regs heap) (hfl : a.floor ≤ x.regs heap) (hframe : WordRAM.Modifies (WordStack.footprint a.stack a.capacity) x.mem y.mem) (hregs : ∀ (i : Fin 128), 71 ≤ ↑i → ↑i < 96 → y.regs i = x.regs i) :
y.regs heap = x.regs heap ∧ y.regs outputCount = x.regs outputCount ∧ a.Controls y ∧ (∀ (q : ℕ), q < a.stack ∨ a.stack + a.capacity ≤ q → y.mem q = x.mem q) ∧ a.capacity ≤ a.floor - a.stack ∧ (∀ d ∈ es, d.Stored y.mem) ∧ (∀ d ∈ es, ∀ (j : Fin 3), d.source j + (d.data j).length ≤ y.regs heap) ∧ a.Bitmap y.mem ∧ a.floor ≤ y.regs heap

A step that changes memory only inside the reserved native stack and keeps the persistent caller registers 71–95 preserves the worklist facts shared by the catalogue and visitor cursors. For the entries es, the conclusions are, in order:

  • the heap pointer and output count are unchanged;
  • the caller controls still hold;
  • memory below the stack and above its reserved interval is unchanged;
  • the reserved stack fits inside the gap below the heap floor;
  • each entry keeps its exact readback;
  • each entry still lies below the fresh heap;
  • the prime bitmap is still represented;
  • the heap pointer stays above the floor.