A real heap workload with amortized linear machine time #
The input is a command count followed by Boolean words. One means push a cell containing one; zero means clear, by visiting and zeroing every active cell. The final stack height is written to output. The source program is fixed and contains both loops: no command or heap operation is performed by the host.
The mathematical specification folds the commands over the stack height and describes every heap cell below the declared boundary. Potential is ten times the current height. It pays for expensive clear commands using credit retained by earlier pushes. Budgets count actual compiled word-RAM transitions.
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Pure specification only; execution consumes the actual input words.
Equations
- Ram.Examples.AmortizedClear.result commands top = List.foldl (fun (n : ℕ) (b : Bool) => Ram.Examples.AmortizedClear.advance b n) top commands
Instances For
Active cells contain one; all other allocated cells contain zero.
Equations
- Ram.Examples.AmortizedClear.Prefix H top mem = ∀ i < H, mem (BitVec.ofNat w i) = if i < top then 1 else 0
Instances For
Instances For
Equations
Instances For
- heap : Prefix H (BitVec.toNat (s.regs 1)) s.mem
Instances For
Clearing performs an actual store for each old cell, preserves the other live state, and costs at most ten transitions per cell plus its final guard.
- heap : Prefix H (BitVec.toNat (s.regs 1)) s.mem
Instances For
The branch budgets include the compiled conditional and its true-branch skip jump; the potentially expensive clear is not charged a constant price.
Equations
- One or more equations did not get rendered due to their size.
Instances For
- heap : Prefix H (BitVec.toNat (s.regs 1)) s.mem
Instances For
One command is read from the input stream, executed, and the actual remaining-count register is decremented. The expensive bound depends on the entry height, before it is converted into an amortized contract.
- heap : Prefix H (BitVec.toNat (s.regs 1)) s.mem
Instances For
Equations
- Ram.Examples.AmortizedClear.Invariant H expected s = ∃ (rest : List Bool), Ram.Examples.AmortizedClear.Snapshot H expected rest s
Instances For
Equations
- Ram.Examples.AmortizedClear.potential s = 10 * BitVec.toNat (s.regs 1)
Instances For
Expensive clear operations spend saved potential. The bound 25 is proved from the two real execution bounds, not used as an instruction price.
The outer invariant records the unconsumed input and its abstract fold. The rule retains final potential, allowing this workload to be composed with another workload instead of silently throwing its saved credit away.
For an existing stack, initial credit is charged explicitly. In particular this bound is linear in command count plus the initial stack height.
Instances For
Input, initialization and output are ordinary charged source statements. The initial heap is empty, so its potential is genuinely zero.
Full machine result, consumed input and functional heap correctness, with an actual linear transition budget including boundary read and halt. Width and capacity constrain the problem input, not an uncharged host computation.
The observable answer decodes to the natural fold, not just its residue. The heap-capacity precondition also bounds every possible final stack height.