Documentation

Complexity.Computability.Ram.Source.Function.Time

Compiler-derived function costs #

Ram.Source.FunctionMeasuredExec observes the same invocation as Ram.Source.FunctionExec, with the exact compiled count of its body. This count includes calls performed by the body, but not the enclosing caller's argument evaluation, frame setup or return sequence. Ram.Source.FunctionMeasuredExec.call adds those actual generated blocks when the function is invoked at a call site.

Ram.Source.FunctionTimeBound is a separate conditional bound on body execution. Combining it with Ram.Source.FunctionContract establishes termination, the functional postcondition and the bound for one and the same invocation. The count is independent of the proposed bound and safety capacities.

def Ram.Source.FunctionMeasuredExec {w : Nat} (control : Nat) (program : Program) (heapLimit depth : Nat) (f : Func) (args : List (Word w)) (bodySteps : Nat) (entry : State w) (value : List (Word w)) (finish : State w) :

Function invocation with its exact compiled body count. The returned fields and shared effects are those of the same body; enclosing call overhead is accounted for by FunctionMeasuredExec.call, not included in bodySteps.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Ram.Source.FunctionMeasuredExec.of_body {w control heapLimit depth bodySteps : Nat} {program : Program} {f : Func} {args : List (Word w)} {entry callee : State w} (arity : args.length = f.params) (frame : f.params ≤ f.locals) (body : LocalMeasuredExec control program heapLimit depth f.body bodySteps (entry.enter args) callee) (result : ∀ (expr : Expr), expr ∈ f.results → Expr.ReadsBelow heapLimit callee.regs callee.mem expr) :
    FunctionMeasuredExec control program heapLimit depth f args bodySteps entry (List.map callee.eval f.results) (entry.restore callee)

    Reuse the existing measured body without choosing a cost annotation.

    theorem Ram.Source.FunctionMeasuredExec.erase {w control heapLimit depth bodySteps : Nat} {program : Program} {f : Func} {args : List (Word w)} {entry finish : State w} {value : List (Word w)} (h : FunctionMeasuredExec control program heapLimit depth f args bodySteps entry value finish) :
    FunctionExec program heapLimit depth f args entry value finish

    Erasing the count retains the same safe invocation.

    theorem Ram.Source.FunctionMeasuredExec.length_eq {w control heapLimit depth bodySteps : Nat} {program : Program} {f : Func} {args : List (Word w)} {entry finish : State w} {value : List (Word w)} (h : FunctionMeasuredExec control program heapLimit depth f args bodySteps entry value finish) :

    Measuring the body does not change the number of returned fields.

    theorem Ram.Source.FunctionMeasuredExec.deterministic {w control heapLimit depth bodySteps : Nat} {program : Program} {f : Func} {args : List (Word w)} {entry finish : State w} {value : List (Word w)} {control' heapLimit' depth' bodySteps' : Nat} {value' : List (Word w)} {finish' : State w} (h : FunctionMeasuredExec control program heapLimit depth f args bodySteps entry value finish) (h' : FunctionMeasuredExec control' program heapLimit' depth' f args bodySteps' entry value' finish') :
    bodySteps = bodySteps' ∧ value = value' ∧ finish = finish'

    A body has one count and one result, independently of safety capacities and the compiler's reserved-register boundary.

    theorem Ram.Source.FunctionMeasuredExec.call {w control heapLimit depth bodySteps : Nat} {program : Program} {f : Func} {entry finish : State w} {value : List (Word w)} {fn : Nat} {dsts : List Reg} {exprs : List Expr} (h : FunctionMeasuredExec control program heapLimit depth f (List.map entry.eval exprs) bodySteps entry value finish) (lookup : program[fn]? = some f) (resultCount : dsts.length = f.results.length) (arguments : ∀ (expr : Expr), expr ∈ exprs → Expr.ReadsBelow heapLimit entry.regs entry.mem expr) :
    LocalMeasuredExec control program heapLimit (depth + 1) (Stmt.call dsts fn exprs) (List.length (ABI.callPrefixLocals control f.locals exprs 0) + 1 + bodySteps + List.length (ABI.returnCodeResultsLocals control f.locals f.results) + dsts.length) entry (finish.setRegs dsts value)

    Count an actual call, including argument evaluation, frame code, the entry jump, the callee body, return code and every result-field receipt.

    theorem Ram.Source.FunctionExec.exists_measured {w heapLimit depth : Nat} {program : Program} {f : Func} {args : List (Word w)} {entry finish : State w} {value : List (Word w)} (h : FunctionExec program heapLimit depth f args entry value finish) (control : Nat) :
    ∃ (bodySteps : Nat), FunctionMeasuredExec control program heapLimit depth f args bodySteps entry value finish

    Safe termination already determines an actual body count; a time bound is not needed to obtain the corresponding measured invocation.

    def Ram.Source.FunctionTimeBound {w : Nat} (control : Nat) (program : Program) (heapLimit depth : Nat) (f : Func) (P : List (Word w) → State w → Prop) (bound : List (Word w) → State w → Nat) :

    A conditional bound on the actual body count. This does not assert termination; use FunctionContract.with_timeBound for a total guarantee.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Ram.Source.FunctionTimeBound.of_body {w control heapLimit depth : Nat} {program : Program} {f : Func} {P : List (Word w) → State w → Prop} {bound : List (Word w) → State w → Nat} {R : State w → Prop} {bodyBound : State w → Nat} (body : TimeBound control program heapLimit depth f.body R bodyBound) (pre : ∀ (args : List (Word w)) (entry : State w), P args entry → R (entry.enter args)) (budget : ∀ (args : List (Word w)) (entry : State w), P args entry → bodyBound (entry.enter args) ≤ bound args entry) :
      FunctionTimeBound control program heapLimit depth f P bound

      Transfer an existing body-time proof through the argument representation. No functional specification or proposed result is used to define the count.

      theorem Ram.Source.FunctionTimeBound.mono_bound {w control heapLimit depth : Nat} {program : Program} {f : Func} {P : List (Word w) → State w → Prop} {bound bound' : List (Word w) → State w → Nat} (h : FunctionTimeBound control program heapLimit depth f P bound) (budget : ∀ (args : List (Word w)) (entry : State w), P args entry → bound args entry ≤ bound' args entry) :
      FunctionTimeBound control program heapLimit depth f P bound'
      theorem Ram.Source.FunctionContract.with_timeBound {w control heapLimit depth : Nat} {program : Program} {f : Func} {P : List (Word w) → State w → Prop} {Q : List (Word w) → State w → List (Word w) → State w → Prop} {bound : List (Word w) → State w → Nat} (h : FunctionContract program heapLimit depth f P Q) (time : FunctionTimeBound control program heapLimit depth f P bound) (args : List (Word w)) (entry : State w) :
      P args entry → ∃ (bodySteps : Nat), ∃ (value : List (Word w)), ∃ (finish : State w), FunctionMeasuredExec control program heapLimit depth f args bodySteps entry value finish ∧ Q args entry value finish ∧ bodySteps ≤ bound args entry

      Attach a separate bound to the very invocation supplied by correctness.