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.
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
- Ram.LanguageCompiler.callCost program fn bodySteps = Ram.LocalCompiler.Function.callSteps 0 (Ram.LanguageCompiler.lowerFunc program fn) bodySteps
Instances For
A callee body bound transports through its compiler-derived call overhead.
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.
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.
- skip {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {depth : ℕ} (entry : Complexity.Language.State Γ) : ExecutionCost ⋯ 0
- assign {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {τ result : Complexity.Language.Ty} {depth : ℕ} (target : Complexity.Language.Var Γ τ) (value : Complexity.Language.Prim Γ τ) (entry : Complexity.Language.State Γ) {fits : PrimFits w entry.locals value} : ExecutionCost ⋯ (primCodeSize value)
- letPrim {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {τ result : Complexity.Language.Ty} {depth : ℕ} {value : Complexity.Language.Prim Γ τ} {continuation : Complexity.Language.Stmt signatures (τ :: Γ) result} {entry : Complexity.Language.State Γ} {finish : Complexity.Language.State (τ :: Γ)} {control : Complexity.Language.Control result} {fits : PrimFits w entry.locals value} {body : RealizedExec program w depth continuation (Complexity.Language.State.cons (value.eval entry.locals) entry) finish control} {steps : ℕ} (tail : ExecutionCost body steps) : ExecutionCost ⋯ (primCodeSize value + steps)
- read {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {kind : Complexity.Language.CellTy} {depth : ℕ} {buffer : Complexity.Language.Atom Γ (Complexity.Language.Ty.buffer kind)} {index : Complexity.Language.Atom Γ Complexity.Language.Ty.nat} {continuation : Complexity.Language.Stmt signatures (kind.toTy :: Γ) result} {entry : Complexity.Language.State Γ} {finish : Complexity.Language.State (kind.toTy :: Γ)} {control : Complexity.Language.Control result} {value : Complexity.Language.CellValue kind} {bufferFits : ValueFits w (buffer.eval entry.locals)} {indexFits : index.eval entry.locals < 2 ^ w} {loaded : entry.heap.read (buffer.eval entry.locals) (index.eval entry.locals) = Except.ok value} {valueFits : ValueFits w (kind.toValue value)} {body : RealizedExec program w depth continuation (Complexity.Language.State.cons (kind.toValue value) entry) finish control} {steps : ℕ} (tail : ExecutionCost body steps) : ExecutionCost ⋯ (readCodeSize + steps)
- readNode {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {kind : Complexity.Language.CellTy} {depth : ℕ} {ref : Complexity.Language.Atom Γ (Complexity.Language.Ty.node kind)} {continuation : Complexity.Language.Stmt signatures (kind.toTy.prod (Complexity.Language.Ty.node kind).option :: Γ) result} {entry : Complexity.Language.State Γ} {finish : Complexity.Language.State (kind.toTy.prod (Complexity.Language.Ty.node kind).option :: Γ)} {control : Complexity.Language.Control result} {head : Complexity.Language.CellValue kind} {tail : Option (Complexity.Language.NodeRef kind)} {found : entry.heap.node? kind (ref.eval entry.locals).object = some (head, tail)} {valueFits : ValueFits w (kind.toValue head, tail)} {body : RealizedExec program w depth continuation (Complexity.Language.State.cons (kind.toValue head, tail) entry) finish control} {steps : ℕ} (bodyCost : ExecutionCost body steps) : ExecutionCost ⋯ (readNodeCodeSize + steps)
- write {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {kind : Complexity.Language.CellTy} {depth : ℕ} {buffer : Complexity.Language.Atom Γ (Complexity.Language.Ty.buffer kind)} {index : Complexity.Language.Atom Γ Complexity.Language.Ty.nat} {value : Complexity.Language.Atom Γ kind.toTy} {entry : Complexity.Language.State Γ} {heap : Complexity.Language.Heap} {bufferFits : ValueFits w (buffer.eval entry.locals)} {indexFits : index.eval entry.locals < 2 ^ w} {valueFits : ValueFits w (value.eval entry.locals)} {written : entry.heap.write (buffer.eval entry.locals) (index.eval entry.locals) (kind.ofValue (value.eval entry.locals)) = Except.ok heap} : ExecutionCost ⋯ writeCodeSize
- slice {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {kind : Complexity.Language.CellTy} {depth : ℕ} {buffer : Complexity.Language.Atom Γ (Complexity.Language.Ty.buffer kind)} {offset length : Complexity.Language.Atom Γ Complexity.Language.Ty.nat} {continuation : Complexity.Language.Stmt signatures (Complexity.Language.Ty.buffer kind :: Γ) result} {entry : Complexity.Language.State Γ} {finish : Complexity.Language.State (Complexity.Language.Ty.buffer kind :: Γ)} {control : Complexity.Language.Control result} {view : Complexity.Language.Buffer kind} {bufferFits : ValueFits w (buffer.eval entry.locals)} {offsetFits : offset.eval entry.locals < 2 ^ w} {lengthFits : length.eval entry.locals < 2 ^ w} {sliced : Complexity.Language.Buffer.slice (buffer.eval entry.locals) (offset.eval entry.locals) (length.eval entry.locals) = Except.ok view} {viewFits : ValueFits w view} {body : RealizedExec program w depth continuation (Complexity.Language.State.cons view entry) finish control} {steps : ℕ} (tail : ExecutionCost body steps) : ExecutionCost ⋯ (sliceCodeSize + steps)
- seqNormal {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {depth : ℕ} {first second : Complexity.Language.Stmt signatures Γ result} {entry middle finish : Complexity.Language.State Γ} {control : Complexity.Language.Control result} {head : RealizedExec program w depth first entry middle Complexity.Language.Control.normal} {tail : RealizedExec program w depth second middle finish control} {firstSteps secondSteps : ℕ} (firstCost : ExecutionCost head firstSteps) (secondCost : ExecutionCost tail secondSteps) : ExecutionCost ⋯ (firstSteps + 2 + secondSteps)
- seqReturn {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {depth : ℕ} {first second : Complexity.Language.Stmt signatures Γ result} {entry finish : Complexity.Language.State Γ} {value : Complexity.Language.Value result} {head : RealizedExec program w depth first entry finish (Complexity.Language.Control.returned value)} {steps : ℕ} (cost : ExecutionCost head steps) : ExecutionCost ⋯ (steps + 3)
- iteTrue {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {depth : ℕ} {condition : Complexity.Language.Atom Γ Complexity.Language.Ty.bool} {yes no : Complexity.Language.Stmt signatures Γ result} {entry finish : Complexity.Language.State Γ} {control : Complexity.Language.Control result} {test : condition.eval entry.locals = true} {body : RealizedExec program w depth yes entry finish control} {steps : ℕ} (cost : ExecutionCost body steps) : ExecutionCost ⋯ (steps + 3)
- iteFalse {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {depth : ℕ} {condition : Complexity.Language.Atom Γ Complexity.Language.Ty.bool} {yes no : Complexity.Language.Stmt signatures Γ result} {entry finish : Complexity.Language.State Γ} {control : Complexity.Language.Control result} {test : condition.eval entry.locals = false} {body : RealizedExec program w depth no entry finish control} {steps : ℕ} (cost : ExecutionCost body steps) : ExecutionCost ⋯ (steps + 2)
- matchNone {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result τ : Complexity.Language.Ty} {depth : ℕ} {value : Complexity.Language.Atom Γ τ.option} {noneBranch : Complexity.Language.Stmt signatures Γ result} {someBranch : Complexity.Language.Stmt signatures (τ :: Γ) result} {entry finish : Complexity.Language.State Γ} {control : Complexity.Language.Control result} {selected : value.eval entry.locals = none} {body : RealizedExec program w depth noneBranch entry finish control} {steps : ℕ} (cost : ExecutionCost body steps) : ExecutionCost ⋯ (steps + 2)
- matchSome {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result τ : Complexity.Language.Ty} {depth : ℕ} {value : Complexity.Language.Atom Γ τ.option} {noneBranch : Complexity.Language.Stmt signatures Γ result} {someBranch : Complexity.Language.Stmt signatures (τ :: Γ) result} {entry : Complexity.Language.State Γ} {payload : Complexity.Language.Value τ} {finish : Complexity.Language.State (τ :: Γ)} {control : Complexity.Language.Control result} {selected : value.eval entry.locals = some payload} {payloadFits : ValueFits w payload} {body : RealizedExec program w depth someBranch (Complexity.Language.State.cons payload entry) finish control} {steps : ℕ} (cost : ExecutionCost body steps) : ExecutionCost ⋯ (2 * fieldCount τ + steps + 3)
- whileFalse {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {depth : ℕ} {guard : Complexity.Language.Stmt signatures Γ Complexity.Language.Ty.bool} {body : Complexity.Language.Stmt signatures Γ result} {entry finish : Complexity.Language.State Γ} {test : RealizedExec program w depth guard entry finish (Complexity.Language.Control.returned false)} {guardSteps : ℕ} (guardCost : ExecutionCost test guardSteps) : ExecutionCost ⋯ (guardSteps + 11)
- whileTrue {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {depth : ℕ} {guard : Complexity.Language.Stmt signatures Γ Complexity.Language.Ty.bool} {body : Complexity.Language.Stmt signatures Γ result} {entry afterGuard afterBody finish : Complexity.Language.State Γ} {control : Complexity.Language.Control result} {test : RealizedExec program w depth guard entry afterGuard (Complexity.Language.Control.returned true)} {iteration : RealizedExec program w depth body afterGuard afterBody Complexity.Language.Control.normal} {rest : RealizedExec program w depth (guard.while body) afterBody finish control} {guardSteps bodySteps restSteps : ℕ} (guardCost : ExecutionCost test guardSteps) (bodyCost : ExecutionCost iteration bodySteps) (restCost : ExecutionCost rest restSteps) : ExecutionCost ⋯ (guardSteps + bodySteps + restSteps + 10)
- whileReturn {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {depth : ℕ} {guard : Complexity.Language.Stmt signatures Γ Complexity.Language.Ty.bool} {body : Complexity.Language.Stmt signatures Γ result} {entry afterGuard finish : Complexity.Language.State Γ} {value : Complexity.Language.Value result} {test : RealizedExec program w depth guard entry afterGuard (Complexity.Language.Control.returned true)} {iteration : RealizedExec program w depth body afterGuard finish (Complexity.Language.Control.returned value)} {guardSteps bodySteps : ℕ} (guardCost : ExecutionCost test guardSteps) (bodyCost : ExecutionCost iteration bodySteps) : ExecutionCost ⋯ (guardSteps + bodySteps + 17)
- ret {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {depth : ℕ} (value : Complexity.Language.Atom Γ result) (entry : Complexity.Language.State Γ) {fits : ValueFits w (value.eval entry.locals)} : ExecutionCost ⋯ (2 * fieldCount result + 2)
- callReturn {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {w : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {depth : ℕ} {fn : Fin signatures.length} {args : Complexity.Language.Args Γ signatures[fn].params} {continuation : Complexity.Language.Stmt signatures (signatures[fn].result :: Γ) result} {entry : Complexity.Language.State Γ} {calleeFinish : Complexity.Language.State signatures[fn].params} {value : Complexity.Language.Value signatures[fn].result} {finish : Complexity.Language.State (signatures[fn].result :: Γ)} {control : Complexity.Language.Control result} {arguments : EnvFits w (args.eval entry.locals)} {callee : RealizedExec program w depth (program.body fn) (entry.enter (args.eval entry.locals)) calleeFinish (Complexity.Language.Control.returned value)} {body : RealizedExec program w (depth + 1) continuation (Complexity.Language.State.cons value (entry.restore calleeFinish)) finish control} {calleeSteps bodySteps : ℕ} (calleeCost : ExecutionCost callee calleeSteps) (bodyCost : ExecutionCost body bodySteps) : ExecutionCost ⋯ (callCost program fn (calleeSteps + 2) + bodySteps)
Instances For
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
Strengthening admissibility reuses the same function and numerical bound.
Weaken a mathematical bound without changing the observed computation.