Documentation

Complexity.Computability.Ram.Compiler.Language.Arena.CostBound.Range.Completion

Arena cost bounds for locally completing ranges #

A saved local result finishes the actual body normally, then leaves through the masked false guard. The represented mathematical phase distinguishes this path from a continuing round without adding a source variable or another loop. The completed guard retains its own cost certificate at the actual final heap.

This rule reuses StmtArenaCostBound.while_model. It neither proves termination again nor replaces a local result by an enclosing function return. Positive stride, word ranges and sufficient capacity are not needed to bound an already supplied ready execution.

theorem Ram.LanguageCompiler.StmtArenaCostBound.while_range_completion_rel {signatures : List Complexity.Language.Signature} {Γ : List Complexity.Language.Ty} {result τ : Complexity.Language.Ty} {Mutable Locals α : Type} {w heapLimit depth : ℕ} (view : Complexity.Language.Env Γ ≃ Locals) (program : Complexity.Language.Program signatures) (guard : Complexity.Language.Stmt signatures Γ Complexity.Language.Ty.bool) (body : Complexity.Language.Stmt signatures Γ result) (pending : Complexity.Language.Atom Γ τ.option) (stoppedGuard : ∀ (state : Complexity.Language.State Γ) (value : Complexity.Language.Value τ), pending.eval state.locals = some value → Complexity.Language.Exec program guard state state (Complexity.Language.Control.returned false)) (stop stride : ℕ) (stateRel : ℕ → Mutable → Locals → Complexity.Language.Heap → Prop) (resultRep : Complexity.Language.Representation α τ) (step : ℕ → Mutable → Option α × Mutable) (guardRel : ∀ (index : ℕ) (mutable : Mutable) (locals : Locals) (heap : Complexity.Language.Heap), stateRel index mutable locals heap → pending.eval (view.symm locals) = none → ∃ (after : Locals) (finish : Complexity.Language.Heap), Complexity.Language.Stmt.observe view guard program locals heap = Part.some ((Complexity.Language.Control.returned (decide (index < stop)), after), finish) ∧ stateRel index mutable after finish ∧ pending.eval (view.symm after) = none) (bodyRel : ∀ (index : ℕ) (mutable : Mutable) (locals : Locals) (heap : Complexity.Language.Heap), index < stop → stateRel index mutable locals heap → pending.eval (view.symm locals) = none → ∃ (after : Locals) (finish : Complexity.Language.Heap), Complexity.Language.Stmt.observe view body program locals heap = Part.some ((Complexity.Language.Control.normal, after), finish) ∧ stateRel (if (step index mutable).1.isSome = true then index else index + stride) (step index mutable).2 after finish ∧ resultRep.option.Rel (step index mutable).1 (pending.eval (view.symm after)) finish) (invariant : ℕ → Mutable → Prop) (guardBound bodyBound potential : ℕ → Mutable → ℕ) (completedGuardBound : ℕ → Mutable → α → ℕ) (guardCost : ∀ (index : ℕ) (mutable : Mutable) (locals : Locals) (heap : Complexity.Language.Heap), invariant index mutable → stateRel index mutable locals heap → pending.eval (view.symm locals) = none → StmtArenaCostBound program w heapLimit depth guard { locals := view.symm locals, heap := heap } (guardBound index mutable)) (bodyCost : ∀ (index : ℕ) (mutable : Mutable) (locals : Locals) (heap : Complexity.Language.Heap), invariant index mutable → index < stop → stateRel index mutable locals heap → pending.eval (view.symm locals) = none → StmtArenaCostBound program w heapLimit depth body { locals := view.symm locals, heap := heap } (bodyBound index mutable)) (completedGuardCost : ∀ (index : ℕ) (mutable : Mutable) (value : α) (locals : Locals) (heap : Complexity.Language.Heap), stateRel index mutable locals heap → resultRep.option.Rel (some value) (pending.eval (view.symm locals)) heap → StmtArenaCostBound program w heapLimit depth guard { locals := view.symm locals, heap := heap } (completedGuardBound index mutable value)) (falseExit : ∀ (index : ℕ) (mutable : Mutable), invariant index mutable → ¬index < stop → guardBound index mutable + 11 ≤ potential index mutable) (normalStep : ∀ (index : ℕ) (mutable : Mutable), invariant index mutable → index < stop → (step index mutable).1 = none → invariant (index + stride) (step index mutable).2 ∧ guardBound index mutable + bodyBound index mutable + potential (index + stride) (step index mutable).2 + 10 ≤ potential index mutable) (completedStep : ∀ (index : ℕ) (mutable : Mutable) (value : α), invariant index mutable → index < stop → (step index mutable).1 = some value → guardBound index mutable + bodyBound index mutable + completedGuardBound index (step index mutable).2 value + 21 ≤ potential index mutable) (start : ℕ) (mutable : Mutable) (locals : Locals) (heap : Complexity.Language.Heap) (represented : stateRel start mutable locals heap) (running : pending.eval (view.symm locals) = none) (initial : invariant start mutable) :
StmtArenaCostBound program w heapLimit depth (guard.while body) { locals := view.symm locals, heap := heap } (potential start mutable)

Bound the same local-completion range using its heap-indexed single-round observations. Continuing rounds preserve the mathematical invariant. Completing rounds retain the cursor and pay for the stopped guard as well as the normal round and false-exit overheads, namely 10 + 11. No invariant on the completed mathematical state is imposed, but its state and saved-result representations remain available to the completed guard's cost certificate.