Documentation

Examples.Ram.FunctionCompositionTime

Separate costs of a composition of imported functions #

The same FunctionComposition.functions declaration makes two real source calls. Their independently proved time bounds are transported through the generated imports and applied at the actual call sites. Copy's budget-free contract supplies the intermediate array representation needed by sum. Neither callee loop nor its frame implementation is reopened.

The body bound includes both inner calls and their generated ABI overhead. The final theorem additionally includes the enclosing call and halt of this single compiled invocation. No host-side preloading or array conversion is claimed as part of that execution.

theorem Ram.Examples.FunctionComposition.function_timeBound {w control heapLimit : ℕ} {source destination : ArrayRef w} {xs ys : List (Word w)} (hw : 0 < w) (sameLength : ys.length = xs.length) (fit : BitVec.toNat destination.base + xs.length < 2 ^ w) (disjoint : ArraysDisjoint source.base xs.length destination.base xs.length) :
Source.FunctionTimeBound control functions.program heapLimit 1 functions.function.copyThenSum (fun (args : List (Word w)) (entry : Source.State w) => args = functions.arguments.copyThenSum source destination ∧ source.Rep heapLimit xs entry ∧ destination.Rep heapLimit ys entry) fun (x : List (Word w)) (x_1 : Source.State w) => 37 * xs.length + 104

The actual body first copies and then sums the resulting destination. Previously proved callee bounds and real call blocks give its linear bound.

theorem Ram.Examples.FunctionComposition.runTotal_steps_le {source destination : ArrayRef 32} {heapLimit : ℕ} {entry : Source.State 32} (safe : Safe source destination heapLimit entry) (hstack : heapLimit + 2 * ABI.frameSize functions.registers < 2 ^ 32) {xs ys : List (Word 32)} (sameLength : ys.length = xs.length) (sourceArray : source.Rep heapLimit xs entry) (destinationArray : destination.Rep heapLimit ys entry) (disjoint : ArraysDisjoint source.base xs.length destination.base xs.length) :
(functions.runTotal.copyThenSum source destination heapLimit entry ⋯).steps ≤ 37 * xs.length + 160

The bound includes every inner and outer call block and the final halt of the same compiled invocation. Its termination proof remains budget-free.