Documentation

Complexity.Computability.Ram.Compiler.Local.Measured.Basic

Exact source counts for callee-sized frames #

LocalMeasuredExec retains the computations and safety premises of SafeExec. Its counts come from the instruction blocks generated by LocalCompiler and the concrete callee-sized ABI. A function's declared local bound determines its call overhead; the reserved-register boundary does not price the call.

The closed simulation below proves that these counts are actual machine transitions. Recursive bodies use the induction hypothesis at their own local bound; no unproved call-simulation assumption remains.

inductive Ram.Source.LocalMeasuredExec (control : Nat) (program : Program) (heapLimit : Nat) {w : Nat} :
Nat → Stmt → Nat → State w → State w → Prop

Safe execution with exact counts from the local-frame compiler. control locates reserved registers; depth separately bounds nested source calls.

Instances For
    theorem Ram.Source.LocalMeasuredExec.erase {w control heapLimit depth steps : Nat} {program : Program} {stmt : Stmt} {s t : State w} (h : LocalMeasuredExec control program heapLimit depth stmt steps s t) :
    SafeExec program heapLimit depth stmt s t

    Dropping the count preserves every source operation and safety premise.

    theorem Ram.Source.LocalMeasuredExec.depth_add {w control heapLimit depth steps : Nat} {program : Program} {stmt : Stmt} {s t : State w} (h : LocalMeasuredExec control program heapLimit depth stmt steps s t) (extra : Nat) :
    LocalMeasuredExec control program heapLimit (depth + extra) stmt steps s t

    Additional allowed call nesting does not alter the executed count.

    theorem Ram.Source.LocalMeasuredExec.mono {w control heapLimit depth depth' steps : Nat} {program : Program} {stmt : Stmt} {s t : State w} (h : LocalMeasuredExec control program heapLimit depth stmt steps s t) (hle : depth ≤ depth') :
    LocalMeasuredExec control program heapLimit depth' stmt steps s t
    theorem Ram.Source.LocalMeasuredExec.rebase {w control heapLimit depth steps : Nat} {program : Program} {stmt : Stmt} {s t : State w} (h : LocalMeasuredExec control program heapLimit depth stmt steps s t) (control' : Nat) :
    LocalMeasuredExec control' program heapLimit depth stmt steps s t

    Moving the reserved registers does not change a computation's instruction count. In particular, a larger global register boundary does not enlarge the frames of functions whose declared local bounds have stayed the same.

    theorem Ram.Source.SafeExec.assign_localMeasured {w : Nat} {program : Program} {heapLimit depth : Nat} {dst : Reg} {value : Expr} {s t : State w} (h : SafeExec program heapLimit depth (Stmt.assign dst value) s t) (control : Nat) :
    LocalMeasuredExec control program heapLimit depth (Stmt.assign dst value) (LocalCompiler.stmtSize control (LocalCompiler.calleeLocals program) (Stmt.assign dst value)) s t

    An existing safe assignment has exactly its emitted instruction length. The endpoint is retained, so clients can reuse a proved value correspondence without rebuilding the assignment or eliminating a fixed concrete state.

    theorem Ram.Source.SafeExec.exists_localMeasured {w : Nat} {program : Program} {heapLimit depth : Nat} {stmt : Stmt} {s t : State w} (h : SafeExec program heapLimit depth stmt s t) (control : Nat) :
    ∃ (steps : Nat), LocalMeasuredExec control program heapLimit depth stmt steps s t

    Every safe computation has a local-compiler-derived count, independently of whether the supplied register boundary is sufficient for its compilation. Compiler simulation separately requires well-formedness at that boundary.

    theorem Ram.Source.localMeasured_iff_safe {w control heapLimit depth : Nat} {program : Program} {stmt : Stmt} {s t : State w} :
    (∃ (steps : Nat), LocalMeasuredExec control program heapLimit depth stmt steps s t) ↔ SafeExec program heapLimit depth stmt s t
    theorem Ram.LocalCompiler.simulate_measured {w control locals heapLimit depth steps : Nat} {program : Program} {main stmt : Stmt} {s s' : Source.State w} (hvalid : Valid control program main) (hcodefit : List.length (rawLink control program main) < 2 ^ w) (hx : Source.LocalMeasuredExec control program heapLimit depth stmt steps s s') (hwf : stmt.WellFormed locals) :
    SimulationExact control locals heapLimit (rawLink control program main) (calleeLocals program) (entry control program main) depth stmt steps s s'

    Every measured source constructor executes for exactly its declared number of actual RAM transitions. In the recursive case the body runs at f.locals, which need not equal either the caller's local bound or control.

    theorem Ram.LocalCompiler.simulate_safe_measured {w control locals heapLimit depth : Nat} {program : Program} {main stmt : Stmt} {s s' : Source.State w} (hvalid : Valid control program main) (hcodefit : List.length (rawLink control program main) < 2 ^ w) (hx : Source.SafeExec program heapLimit depth stmt s s') (hwf : stmt.WellFormed locals) :
    ∃ (steps : Nat), Source.LocalMeasuredExec control program heapLimit depth stmt steps s s' ∧ SimulationExact control locals heapLimit (rawLink control program main) (calleeLocals program) (entry control program main) depth stmt steps s s'

    A safe source execution determines a single exact count uniformly for all matching target states, rather than a target-dependent count chosen afterward.