Documentation

Examples.Ram.ArraySliceProperties

Mathematical properties of executable slice sums #

After proving the value equation for sumSlice, clients can use ordinary list identities to reason about the executable function. These results specialize it to empty and whole slices, and split a sum into two adjacent slices. The proofs use neither an execution relation nor the implementation of the summation loop.

All applications still require represented memory, legal slice ranges and enough stack space. The partition theorem compares returned values; it does not compile the two host-level applications into a single function or assign them a cost.

theorem Ram.Examples.ArraySlice.sumSlice_zero {heapLimit : ℕ} {array : ArrayRef 32} {xs : List (Word 32)} {entry : Source.State 32} (offset : Word 32) (fit : BitVec.toNat array.base + xs.length < 2 ^ 32) (within : BitVec.toNat offset ≤ BitVec.toNat array.length) (hstack : heapLimit + 2 * ABI.frameSize functions.registers < 2 ^ 32) (represented : array.Rep heapLimit xs entry) :
sumSlice array offset 0 heapLimit entry ⋯ ⋯ hstack = 0

The executable function returns zero on a zero-length slice at any legal offset, including the end of the represented array.

theorem Ram.Examples.ArraySlice.sumSlice_whole {heapLimit : ℕ} {array : ArrayRef 32} {xs : List (Word 32)} {entry : Source.State 32} (fit : BitVec.toNat array.base + xs.length < 2 ^ 32) (hstack : heapLimit + 2 * ABI.frameSize functions.registers < 2 ^ 32) (sumStack : heapLimit + ABI.frameSize Source.Array.sumFunctions.registers < 2 ^ 32) (represented : array.Rep heapLimit xs entry) :
sumSlice array 0 array.length heapLimit entry ⋯ ⋯ hstack = ArraySum.sum array heapLimit entry ⋯ sumStack

Slicing the whole array agrees with the existing executable sum function. Each implementation has its own sufficient stack-capacity premise.

theorem Ram.Examples.ArraySlice.sumSlice_partition {heapLimit : ℕ} {array : ArrayRef 32} {xs : List (Word 32)} {entry : Source.State 32} (left right : Word 32) (fit : BitVec.toNat array.base + xs.length < 2 ^ 32) (partition : BitVec.toNat left + BitVec.toNat right = BitVec.toNat array.length) (hstack : heapLimit + 2 * ABI.frameSize functions.registers < 2 ^ 32) (sumStack : heapLimit + ABI.frameSize Source.Array.sumFunctions.registers < 2 ^ 32) (represented : array.Rep heapLimit xs entry) :
(sumSlice array 0 left heapLimit entry ⋯ ⋯ hstack + sumSlice array left right heapLimit entry ⋯ ⋯ hstack) % 2 ^ 32 = ArraySum.sum array heapLimit entry ⋯ sumStack

Two adjacent slices covering the array reproduce its sum modulo the word range. This is a list decomposition theorem about the actual returned values.