Documentation

Examples.Ram.ArrayCount

Mathematical properties of a callable occurrence counter #

These proofs use the existing array-count function and standard list facts. They do not expand its traversal, registers or call frames. A decoded result is a mathematical observation of the actual function, not a new executable implementation. Each array is assumed to be present in memory already. The executable example passes the target as an ordinary additional argument; its complete count includes the actual function call and halt.

theorem Ram.Examples.ArrayCount.eval_eq_of_perm {w heapLimit : ℕ} {program : Program} {left right : ArrayRef w} {target : Word w} {xs ys : List (Word w)} {entry₁ entry₂ : Source.State w} (hw : 0 < w) (permutation : xs.Perm ys) (fit₁ : BitVec.toNat left.base + xs.length < 2 ^ w) (fit₂ : BitVec.toNat right.base + ys.length < 2 ^ w) (array₁ : left.Rep heapLimit xs entry₁) (array₂ : right.Rep heapLimit ys entry₂) :

Counting is insensitive to the order of the represented words. The heaps and pointers may differ: this equates only returned counts, not shared states or the work of constructing or permuting either array.

def Ram.Examples.ArrayCount.runCount (array : ArrayRef 32) (target : Word 32) (heapLimit : ℕ) (entry : Source.State 32) :

Execute the declared counter with a typed array and a scalar target. The runner returns a value separately from the untouched output stream.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Ram.Examples.ArrayCount.runCount_eq {heapLimit : ℕ} {array : ArrayRef 32} {target : Word 32} {xs : List (Word 32)} {entry : Source.State 32} (fit : BitVec.toNat array.base + xs.length < 2 ^ 32) (hstack : heapLimit + ABI.frameSize Source.Array.countFunctions.registers < 2 ^ 32) (represented : array.Rep heapLimit xs entry) :
    runCount array target heapLimit entry = some (List.count target xs, 20 * xs.length + 76, StopReason.halted)

    The real mixed-argument invocation returns the exact list count, with all call, iteration and halt instructions included. The represented length bounds the result, so the occurrence count cannot overflow a word.