Documentation

Complexity.Computability.Ram.Compiler.Language.Realization.Range

Realizing pure native finite ranges #

Native guard and body observations expose the actual cursor, mutable values, fixed captures and heap. A high-level invariant supplies the word-range and callee-realization conditions of the same source blocks. Only normal body completion must preserve that invariant, after the actual cursor increment; an early return neither increments the cursor nor starts another round.

RealizationWP.while_range_encoded_of_total retains an existing source total specification and its postconditions. RealizationWP.while_range_encoded_invariant obtains finite source execution directly from the existing native range observation theorem and retains the invariant on normal exit. Its weaker RealizationWP.while_range_encoded corollary forgets that exit property. No rule introduces a second termination argument, block contract, execution semantics or instruction budget.

theorem Ram.LanguageCompiler.RealizationWP.while_range_encoded_of_total {signatures : List Complexity.Language.Signature} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {Mutable Captured α : Type} {w depth : ℕ} (view : Complexity.Language.Env Γ ≃ (ℕ × Mutable) × Captured) (program : Complexity.Language.Program signatures) (guard : Complexity.Language.Stmt signatures Γ Complexity.Language.Ty.bool) (body : Complexity.Language.Stmt signatures Γ result) (captures : Captured) (stop stride : ℕ) (encode : α → Complexity.Language.Value result) (step : ℕ → Mutable → Option α × Mutable) (guardEq : ∀ (index : ℕ) (mutable : Mutable), Complexity.Language.Stmt.observe view guard program ((index, mutable), captures) = pure (Complexity.Language.Control.returned (decide (index < stop)), (index, mutable), captures)) (bodyEq : ∀ (index : ℕ) (mutable : Mutable), index < stop → Complexity.Language.Stmt.observe view body program ((index, mutable), captures) = pure (match step index mutable with | (none, next) => (Complexity.Language.Control.normal, (index + stride, next), captures) | (some value, next) => (Complexity.Language.Control.returned (encode value), (index, next), captures))) (invariant : ℕ → Mutable → Complexity.Language.Heap → Prop) {normal : Complexity.Language.State Γ → Prop} {returned : Complexity.Language.Value result → Complexity.Language.State Γ → Prop} {start : ℕ} {mutable : Mutable} {heap : Complexity.Language.Heap} (total : Complexity.Language.TotalWP program (guard.while body) normal returned { locals := view.symm ((start, mutable), captures), heap := heap }) (guardRealizable : ∀ (index : ℕ) (state : Mutable) (heap : Complexity.Language.Heap), invariant index state heap → RealizationWP program w depth guard (fun (x : Complexity.Language.State Γ) => False) (fun (x : Complexity.Language.Value Complexity.Language.Ty.bool) (x_1 : Complexity.Language.State Γ) => True) { locals := view.symm ((index, state), captures), heap := heap }) (bodyRealizable : ∀ (index : ℕ) (state : Mutable) (heap : Complexity.Language.Heap), invariant index state heap → index < stop → RealizationWP program w depth body (fun (x : Complexity.Language.State Γ) => True) (fun (x : Complexity.Language.Value result) (x_1 : Complexity.Language.State Γ) => True) { locals := view.symm ((index, state), captures), heap := heap }) (preserve : ∀ (index : ℕ) (state next : Mutable) (heap : Complexity.Language.Heap), invariant index state heap → index < stop → step index state = (none, next) → invariant (index + stride) next heap) (initial : invariant start mutable heap) :
RealizationWP program w depth (guard.while body) normal returned { locals := view.symm ((start, mutable), captures), heap := heap }

Realize an already total source range while retaining its postconditions. The only preservation obligation concerns the native next value of a normal body step. Guard and body realization still check their actual operations, including the cursor increment on a normal path and encoded early returns.

theorem Ram.LanguageCompiler.RealizationWP.while_range_encoded_invariant {signatures : List Complexity.Language.Signature} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {Mutable Captured α : Type} {w depth : ℕ} (view : Complexity.Language.Env Γ ≃ (ℕ × Mutable) × Captured) (program : Complexity.Language.Program signatures) (guard : Complexity.Language.Stmt signatures Γ Complexity.Language.Ty.bool) (body : Complexity.Language.Stmt signatures Γ result) (captures : Captured) (stop stride : ℕ) (positive : 0 < stride) (encode : α → Complexity.Language.Value result) (step : ℕ → Mutable → Option α × Mutable) (guardEq : ∀ (index : ℕ) (mutable : Mutable), Complexity.Language.Stmt.observe view guard program ((index, mutable), captures) = pure (Complexity.Language.Control.returned (decide (index < stop)), (index, mutable), captures)) (bodyEq : ∀ (index : ℕ) (mutable : Mutable), index < stop → Complexity.Language.Stmt.observe view body program ((index, mutable), captures) = pure (match step index mutable with | (none, next) => (Complexity.Language.Control.normal, (index + stride, next), captures) | (some value, next) => (Complexity.Language.Control.returned (encode value), (index, next), captures))) (invariant : ℕ → Mutable → Complexity.Language.Heap → Prop) (guardRealizable : ∀ (index : ℕ) (state : Mutable) (heap : Complexity.Language.Heap), invariant index state heap → RealizationWP program w depth guard (fun (x : Complexity.Language.State Γ) => False) (fun (x : Complexity.Language.Value Complexity.Language.Ty.bool) (x_1 : Complexity.Language.State Γ) => True) { locals := view.symm ((index, state), captures), heap := heap }) (bodyRealizable : ∀ (index : ℕ) (state : Mutable) (heap : Complexity.Language.Heap), invariant index state heap → index < stop → RealizationWP program w depth body (fun (x : Complexity.Language.State Γ) => True) (fun (x : Complexity.Language.Value result) (x_1 : Complexity.Language.State Γ) => True) { locals := view.symm ((index, state), captures), heap := heap }) (preserve : ∀ (index : ℕ) (state next : Mutable) (heap : Complexity.Language.Heap), invariant index state heap → index < stop → step index state = (none, next) → invariant (index + stride) next heap) (start : ℕ) (mutable : Mutable) (heap : Complexity.Language.Heap) (initial : invariant start mutable heap) :
RealizationWP program w depth (guard.while body) (fun (finish : Complexity.Language.State Γ) => (view finish.locals).2 = captures ∧ invariant (view finish.locals).1.1 (view finish.locals).1.2 finish.heap) (fun (x : Complexity.Language.Value result) (x_1 : Complexity.Language.State Γ) => True) { locals := view.symm ((start, mutable), captures), heap := heap }

Realize a pure positive-step source range and retain its invariant and fixed captures on normal exit. Invariant preservation follows the already finite source execution; it requires no second termination proof. An early function return does not have to preserve the normal-round invariant.

theorem Ram.LanguageCompiler.RealizationWP.while_range_encoded {signatures : List Complexity.Language.Signature} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {Mutable Captured α : Type} {w depth : ℕ} (view : Complexity.Language.Env Γ ≃ (ℕ × Mutable) × Captured) (program : Complexity.Language.Program signatures) (guard : Complexity.Language.Stmt signatures Γ Complexity.Language.Ty.bool) (body : Complexity.Language.Stmt signatures Γ result) (captures : Captured) (stop stride : ℕ) (positive : 0 < stride) (encode : α → Complexity.Language.Value result) (step : ℕ → Mutable → Option α × Mutable) (guardEq : ∀ (index : ℕ) (mutable : Mutable), Complexity.Language.Stmt.observe view guard program ((index, mutable), captures) = pure (Complexity.Language.Control.returned (decide (index < stop)), (index, mutable), captures)) (bodyEq : ∀ (index : ℕ) (mutable : Mutable), index < stop → Complexity.Language.Stmt.observe view body program ((index, mutable), captures) = pure (match step index mutable with | (none, next) => (Complexity.Language.Control.normal, (index + stride, next), captures) | (some value, next) => (Complexity.Language.Control.returned (encode value), (index, next), captures))) (invariant : ℕ → Mutable → Complexity.Language.Heap → Prop) (guardRealizable : ∀ (index : ℕ) (state : Mutable) (heap : Complexity.Language.Heap), invariant index state heap → RealizationWP program w depth guard (fun (x : Complexity.Language.State Γ) => False) (fun (x : Complexity.Language.Value Complexity.Language.Ty.bool) (x_1 : Complexity.Language.State Γ) => True) { locals := view.symm ((index, state), captures), heap := heap }) (bodyRealizable : ∀ (index : ℕ) (state : Mutable) (heap : Complexity.Language.Heap), invariant index state heap → index < stop → RealizationWP program w depth body (fun (x : Complexity.Language.State Γ) => True) (fun (x : Complexity.Language.Value result) (x_1 : Complexity.Language.State Γ) => True) { locals := view.symm ((index, state), captures), heap := heap }) (preserve : ∀ (index : ℕ) (state next : Mutable) (heap : Complexity.Language.Heap), invariant index state heap → index < stop → step index state = (none, next) → invariant (index + stride) next heap) (start : ℕ) (mutable : Mutable) (heap : Complexity.Language.Heap) (initial : invariant start mutable heap) :
RealizationWP program w depth (guard.while body) (fun (x : Complexity.Language.State Γ) => True) (fun (x : Complexity.Language.Value result) (x_1 : Complexity.Language.State Γ) => True) { locals := view.symm ((start, mutable), captures), heap := heap }

Forget the normal-exit invariant after realizing the same pure finite range. Normal and early-return outcomes both remain possible.