Documentation

Complexity.Computability.Ram.Compiler.Language.ExecutionCost

Costs of realized source executions #

ExecutionCost observes the same source execution as RealizedExec. Its rules count the operations emitted by lowering, including actual buffer operations, the private return flag and actual callee-frame work. The observation does not supply termination, change source behavior, or ask a program author to assign instruction prices.

Counts here cover lowerStmtCore. A returning function body additionally runs its flag initialization, for two transitions. Its specialized exit needs no normal-continuation dispatch. The outer invocation's calling convention and final halt are accounted for separately. Internal calls already include their callee's complete body and call overhead.

The canonical reserved-register position in callSteps 0 only fixes a length expression; register placement does not change generated instruction counts. The measured lowering theorem connects these rules to actual RAM transitions.

def Ram.LanguageCompiler.callCost {signatures : List Complexity.Language.Signature} (program : Complexity.Language.Program signatures) (fn : Fin signatures.length) (bodySteps : ℕ) :

Complete internal-call charge for a source function and a bound on its lowered body. Argument fields, frame operations and return reception come from the actual compiler; clients do not supply register locations or ABI prices.

Equations
Instances For
    theorem Ram.LanguageCompiler.callCost_mono {signatures : List Complexity.Language.Signature} (program : Complexity.Language.Program signatures) (fn : Fin signatures.length) :
    Monotone (callCost program fn)

    A callee body bound transports through its compiler-derived call overhead.

    theorem Ram.LanguageCompiler.callCost_eq_add {signatures : List Complexity.Language.Signature} (program : Complexity.Language.Program signatures) (fn : Fin signatures.length) (bodySteps : ℕ) :
    callCost program fn bodySteps = bodySteps + callCost program fn 0

    Separate callee body work from its fixed, compiler-derived call overhead. This lets recursive bounds use ordinary arithmetic without unfolding argument, frame or return layouts in the algorithm proof.

    inductive Ram.LanguageCompiler.ExecutionCost {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w depth : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {stmt : Complexity.Language.Stmt signatures Γ result} {entry finish : Complexity.Language.State Γ} {control : Complexity.Language.Control result} :
    RealizedExec program w depth stmt entry finish control → ℕ → Prop

    The backend-derived core count of the given successful source execution. Range and call-nesting evidence belongs to that execution, not to a second correctness proof. Each constructor adds only its emitted runtime work.

    Instances For
      theorem Ram.LanguageCompiler.RealizedExec.exists_cost {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w depth : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {stmt : Complexity.Language.Stmt signatures Γ result} {entry finish : Complexity.Language.State Γ} {control : Complexity.Language.Control result} (execution : RealizedExec program w depth stmt entry finish control) :
      ∃ (steps : ℕ), ExecutionCost execution steps

      A successful source execution determines a cost observation without any proposed bound. This is a proposition about the existing execution, not an attempt to compute a natural number by inspecting a proof.

      A conditional bound on the complete lowered function body. Correctness and termination remain separate source contracts. The bound is uniform over word width and call capacity whenever the source execution is realizable.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Ram.LanguageCompiler.FunctionCostBound.consequence {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {fn : Fin signatures.length} {pre pre' : Complexity.Language.Env signatures[fn].params → Complexity.Language.Heap → Prop} {bound : Complexity.Language.Env signatures[fn].params → Complexity.Language.Heap → ℕ} (h : FunctionCostBound program fn pre bound) (input : ∀ (args : Complexity.Language.Env signatures[fn].params) (heap : Complexity.Language.Heap), pre' args heap → pre args heap) :
        FunctionCostBound program fn pre' bound

        Strengthening admissibility reuses the same function and numerical bound.

        theorem Ram.LanguageCompiler.FunctionCostBound.mono_bound {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {fn : Fin signatures.length} {pre : Complexity.Language.Env signatures[fn].params → Complexity.Language.Heap → Prop} {bound bound' : Complexity.Language.Env signatures[fn].params → Complexity.Language.Heap → ℕ} (h : FunctionCostBound program fn pre bound) (budget : ∀ (args : Complexity.Language.Env signatures[fn].params) (heap : Complexity.Language.Heap), pre args heap → bound args heap ≤ bound' args heap) :
        FunctionCostBound program fn pre bound'

        Weaken a mathematical bound without changing the observed computation.