Documentation

Examples.Ram.ArrayArguments

Calling functions with array arguments #

The library's sumPair takes two array references and calls the same sum implementation twice. Its source calls pass one typed handle per array; the existing compiler evaluates the two word fields at each call site.

The list concatenation below is only a mathematical description of the returned sum. Neither concatenation, allocation nor data loading is claimed to occur in the implementation. Read-only references may overlap. The runnable example starts with four explicitly preloaded heap words and requires no I/O driver or instruction budget.

theorem Ram.Examples.ArrayArguments.eval_append {w heapLimit : ℕ} {left right : ArrayRef w} {xs ys : List (Word w)} {entry : Source.State w} (hw : 0 < w) (leftFit : BitVec.toNat left.base + xs.length < 2 ^ w) (rightFit : BitVec.toNat right.base + ys.length < 2 ^ w) (leftArray : left.Rep heapLimit xs entry) (rightArray : right.Rep heapLimit ys entry) :

Two real array calls compute the sum of the concatenated mathematical lists, without constructing that concatenation in machine memory.

def Ram.Examples.ArrayArguments.runSumPair (left right : ArrayRef 32) (heapLimit : ℕ) (entry : Source.State 32) :

Execute the typed two-array function on already represented 32-bit data. The returned count includes both inner calls, the outer call, return and halt.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Ram.Examples.ArrayArguments.runSumPair_eq {heapLimit : ℕ} {left right : ArrayRef 32} {xs ys : List (Word 32)} {entry : Source.State 32} (leftFit : BitVec.toNat left.base + xs.length < 2 ^ 32) (rightFit : BitVec.toNat right.base + ys.length < 2 ^ 32) (hstack : heapLimit + 2 * ABI.frameSize Source.Array.sumFunctions.registers < 2 ^ 32) (leftArray : left.Rep heapLimit xs entry) (rightArray : right.Rep heapLimit ys entry) :
    runSumPair left right heapLimit entry = some ((List.map BitVec.toNat (xs ++ ys)).sum % 2 ^ 32, 18 * (xs.length + ys.length) + 197, StopReason.halted)

    The executable call returns the mathematical concatenation sum and its actual full transition count. Stack capacity is a safety premise, not a supplied runtime limit. All calls and returns are counted; host-side preloading is not.