Documentation

Complexity.Computability.Ram.Compiler.Language.Linking.ExecutionCost

Exact execution costs through source program embeddings #

Typed call relocation preserves the existing compiler-derived count, including the actual callee frame and returning-body work. The forward proof follows ExecutionCost; reflection reuses realization reflection, existence of a cost observation and its determinism. It therefore covers every target realization, not only a chosen execution obtained by forwarding a source witness.

Statement bounds transfer in both directions with unchanged entry states and numerical bounds. They remain uniform over word widths and call capacities; neither transfer provides or assumes a budget-based termination argument.

theorem Ram.LanguageCompiler.ExecutionCost.callReturnOfEq {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {fn : Fin signatures.length} {signature : Complexity.Language.Signature} (same : signatures[fn] = signature) {w depth : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {args : Complexity.Language.Args Γ signature.params} {continuation : Complexity.Language.Stmt signatures (signature.result :: Γ) result} {entry : Complexity.Language.State Γ} {calleeFinish : Complexity.Language.State signature.params} {value : Complexity.Language.Value signature.result} {finish : Complexity.Language.State (signature.result :: Γ)} {control : Complexity.Language.Control result} {arguments : EnvFits w (args.eval entry.locals)} {callee : RealizedExec program w depth (cast ⋯ (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)

Transport the existing returning-call charge along an equality of complete signatures. The actual function and its compiler-derived call overhead are unchanged.

theorem Ram.LanguageCompiler.ExecutionCost.renameCalls {source target : List Complexity.Language.Signature} {sourceProgram : Complexity.Language.Program source} {targetProgram : Complexity.Language.Program target} {map : Complexity.Language.SignatureMap source target} (embedded : sourceProgram.Embeds map targetProgram) {w depth : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {statement : Complexity.Language.Stmt source Γ result} {entry finish : Complexity.Language.State Γ} {control : Complexity.Language.Control result} {execution : RealizedExec sourceProgram w depth statement entry finish control} {steps : ℕ} (cost : ExecutionCost execution steps) :
ExecutionCost ⋯ steps

Renaming calls through an actual program embedding preserves the exact compiled core count of the same realized execution.

theorem Ram.LanguageCompiler.ExecutionCost.of_renameCalls {source target : List Complexity.Language.Signature} {sourceProgram : Complexity.Language.Program source} {targetProgram : Complexity.Language.Program target} {map : Complexity.Language.SignatureMap source target} (embedded : sourceProgram.Embeds map targetProgram) {w depth : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {statement : Complexity.Language.Stmt source Γ result} {entry finish : Complexity.Language.State Γ} {control : Complexity.Language.Control result} {execution : RealizedExec targetProgram w depth (Complexity.Language.Stmt.renameCalls map statement) entry finish control} {steps : ℕ} (cost : ExecutionCost execution steps) :
ExecutionCost ⋯ steps

Every realized execution of a renamed statement has the original count. Reflection first recovers the source execution; cost determinism then identifies its count with the given target observation, without assuming source termination.

theorem Ram.LanguageCompiler.ExecutionCost.renameCalls_iff {source target : List Complexity.Language.Signature} {sourceProgram : Complexity.Language.Program source} {targetProgram : Complexity.Language.Program target} {map : Complexity.Language.SignatureMap source target} (embedded : sourceProgram.Embeds map targetProgram) {w depth : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {statement : Complexity.Language.Stmt source Γ result} {entry finish : Complexity.Language.State Γ} {control : Complexity.Language.Control result} {execution : RealizedExec sourceProgram w depth statement entry finish control} {steps : ℕ} :
ExecutionCost ⋯ steps ↔ ExecutionCost execution steps

Exact cost observations are invariant under typed source relocation.

theorem Ram.LanguageCompiler.StmtCostBound.renameCalls {source target : List Complexity.Language.Signature} {sourceProgram : Complexity.Language.Program source} {targetProgram : Complexity.Language.Program target} {map : Complexity.Language.SignatureMap source target} (embedded : sourceProgram.Embeds map targetProgram) {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {statement : Complexity.Language.Stmt source Γ result} {entry : Complexity.Language.State Γ} {bound : ℕ} (specification : StmtCostBound sourceProgram statement entry bound) :
StmtCostBound targetProgram (Complexity.Language.Stmt.renameCalls map statement) entry bound

A source bound applies to every realized target execution of the relocated statement, with the same mathematical entry and bound.

theorem Ram.LanguageCompiler.StmtCostBound.of_renameCalls {source target : List Complexity.Language.Signature} {sourceProgram : Complexity.Language.Program source} {targetProgram : Complexity.Language.Program target} {map : Complexity.Language.SignatureMap source target} (embedded : sourceProgram.Embeds map targetProgram) {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {statement : Complexity.Language.Stmt source Γ result} {entry : Complexity.Language.State Γ} {bound : ℕ} (specification : StmtCostBound targetProgram (Complexity.Language.Stmt.renameCalls map statement) entry bound) :
StmtCostBound sourceProgram statement entry bound

Reflect a uniform target statement bound to its original source statement.

theorem Ram.LanguageCompiler.StmtCostBound.renameCalls_iff {source target : List Complexity.Language.Signature} {sourceProgram : Complexity.Language.Program source} {targetProgram : Complexity.Language.Program target} {map : Complexity.Language.SignatureMap source target} (embedded : sourceProgram.Embeds map targetProgram) {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {statement : Complexity.Language.Stmt source Γ result} {entry : Complexity.Language.State Γ} {bound : ℕ} :
StmtCostBound targetProgram (Complexity.Language.Stmt.renameCalls map statement) entry bound ↔ StmtCostBound sourceProgram statement entry bound

Typed source embeddings preserve and reflect bounds over all realized executions, uniformly in word width and call capacity.