Documentation

Examples.Ram.LowerBound

Executable lower-bound search #

The ordinary lowerBound function executes the declared binary search on an existing array reference. Its result is the standard list insertion index, including the length sentinel when every element is below the key. Sortedness and the represented list occur only in erased correctness premises.

The separate time theorem bounds the actual complete invocation, including call setup, return and halt. No proposed result or time budget is supplied to the executable function. Memory is already represented: neither a host loader nor its work is included in this RAM count, and no extra strict endpoint condition is imposed on the array.

Sorted represented data and sufficient stack space make the actual call halt. This proof uses the budget-free typed contract, not a time estimate.

def Ram.Examples.LowerBound.lowerBound (array : ArrayRef 32) (key : Word 32) (heapLimit : ℕ) (entry : Source.State 32) (safe : ∃ (xs : List (Word 32)), array.Rep heapLimit xs entry ∧ List.Pairwise (fun (a b : Word 32) => BitVec.toNat a ≤ BitVec.toNat b) xs) (hstack : heapLimit + ABI.frameSize Source.Array.Search.functions.registers < 2 ^ 32) :

Execute binary search and decode its returned insertion index. Runtime inputs are the reference, key, heap boundary and preloaded state; all safety proofs are erased and the mathematical list is not an execution argument.

Equations
Instances For
    theorem Ram.Examples.LowerBound.lowerBound_eq {heapLimit : ℕ} {array : ArrayRef 32} (key : Word 32) {xs : List (Word 32)} {entry : Source.State 32} (sorted : List.Pairwise (fun (a b : Word 32) => BitVec.toNat a ≤ BitVec.toNat b) xs) (represented : array.Rep heapLimit xs entry) (hstack : heapLimit + ABI.frameSize Source.Array.Search.functions.registers < 2 ^ 32) :
    lowerBound array key heapLimit entry ⋯ hstack = List.findIdx (fun (x : Word 32) => decide (BitVec.toNat key ≤ BitVec.toNat x)) xs

    The actual executable value is the standard first index at least the key. No separate reference implementation or instruction bound enters the equation.

    theorem Ram.Examples.LowerBound.runTotal_steps_le {heapLimit : ℕ} {array : ArrayRef 32} (key : Word 32) {xs : List (Word 32)} {entry : Source.State 32} (sorted : List.Pairwise (fun (a b : Word 32) => BitVec.toNat a ≤ BitVec.toNat b) xs) (represented : array.Rep heapLimit xs entry) (hstack : heapLimit + ABI.frameSize Source.Array.Search.functions.registers < 2 ^ 32) :
    (Source.Array.Search.functions.runTotal.lowerBound array key heapLimit entry ⋯).steps ≤ 25 * Nat.clog 2 (xs.length + 1) + 69

    The same total call has a logarithmic full transition bound. Its outer overhead is normalized from the actual generated call and return code.