Documentation

Complexity.Computability.Ram.Memory.Finmap.Contracts

Ordinary store blocks implementing finite-map updates #

These budget-free contracts connect fixed source statements to mathlib's Finmap.insert and Finmap.erase. The represented key is ghost data appearing only in the precondition and result, not in the program's syntax. Runtime addresses and values are already in the specified registers, as required by explicit preconditions; address calculation and table initialization are not provided for free.

Insertion writes the payload before a nonzero presence marker. Both stores read only registers, so changing memory cannot invalidate the second store's operands. Erasure stores the ordinary source constant zero into the marker; its compiled constant evaluation remains part of the existing machine cost. The exact final state and standard Set.EqOn frames retain all other memory.

theorem Ram.Source.Finmap.insert_contract {w : ℕ} {κ : Type u_1} [DecidableEq κ] {heapLimit depth : ℕ} {program : Program} {layout : κ × Bool → Word w} {map : Finmap fun (x : κ) => Word w} (key : κ) (value marker : Word w) (payloadReg valueReg flagReg markerReg : Reg) :
TotalRelContract program heapLimit depth ((Stmt.store (Expr.var payloadReg) (Expr.var valueReg)).seq (Stmt.store (Expr.var flagReg) (Expr.var markerReg))) (fun (s : State w) => FinmapAt heapLimit layout map s ∧ Function.Injective layout ∧ marker ≠ 0 ∧ s.regs payloadReg = layout (key, true) ∧ s.regs valueReg = value ∧ s.regs flagReg = layout (key, false) ∧ s.regs markerReg = marker) fun (entry finish : State w) => finish = (entry.setMem (layout (key, true)) value).setMem (layout (key, false)) marker ∧ FinmapAt heapLimit layout (Finmap.insert key value map) finish ∧ Set.EqOn finish.mem entry.mem {layout (key, true), layout (key, false)}ᶜ

Two ordinary register-addressed stores implement native finite-map insertion, with no dependence of the program text on the represented key.

theorem Ram.Source.Finmap.erase_contract {w : ℕ} {κ : Type u_1} [DecidableEq κ] {heapLimit depth : ℕ} {program : Program} {layout : κ × Bool → Word w} {map : Finmap fun (x : κ) => Word w} (key : κ) (flagReg : Reg) :
TotalRelContract program heapLimit depth (Stmt.store (Expr.var flagReg) (Expr.const 0)) (fun (s : State w) => FinmapAt heapLimit layout map s ∧ Function.Injective layout ∧ s.regs flagReg = layout (key, false)) fun (entry finish : State w) => finish = entry.setMem (layout (key, false)) 0 ∧ FinmapAt heapLimit layout (Finmap.erase key map) finish ∧ Set.EqOn finish.mem entry.mem {layout (key, false)}ᶜ

Clearing one marker implements native erasure and leaves its payload unchanged. The zero is an ordinary compiled constant, not an initialized register or a free whole-table initialization step.