Documentation

Examples.Ram.ArrayCopyFunction

Executable array copy with a reusable returned state #

copy executes the existing Unit-returning copy function and returns its actual shared state through applyState. Ordinary list equations describe the copied memory; the logical lists occur only in erased safety proofs, never as runtime arguments. The implementation does not allocate or load either array.

copyThenSum is a host-level composition of two genuine compiled calls: it passes copy's returned state directly to the existing executable sum function. It is not a new single compiled RAM program. Host-side preloading and state projection are not charged as RAM array-conversion instructions, and no whole-program cost is claimed for this composition. Each original operation retains its separate cost theorems. The existing raw-block copy example remains independent.

def Ram.Examples.ArrayCopyFunction.Safe (source destination length : Word 32) (heapLimit : ℕ) (entry : Source.State 32) :

The existing array assertions provide a safe non-overlapping copy of the runtime length. No contents or proposed result become executable inputs.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    Budget-free copy correctness establishes normal termination of this compiled call. No measured execution or proposed time bound is needed.

    def Ram.Examples.ArrayCopyFunction.copy (source destination length : Word 32) (heapLimit : ℕ) (entry : Source.State 32) (safe : Safe source destination length heapLimit entry) (hstack : heapLimit + ABI.frameSize Source.Array.copyFunctions.registers < 2 ^ 32) :

    Execute the existing compiled copy and return its source-visible state. The proof is erased, and the destination contents come from actual RAM stores.

    Equations
    Instances For
      theorem Ram.Examples.ArrayCopyFunction.copy_applyState_spec {source destination length : Word 32} {heapLimit : ℕ} {entry : Source.State 32} (safe : Safe source destination length heapLimit entry) (hstack : heapLimit + ABI.frameSize Source.Array.copyFunctions.registers < 2 ^ 32) {xs ys : List (Word 32)} (count : BitVec.toNat length = xs.length) (sameLength : ys.length = xs.length) (sourceArray : Source.ArrayAt heapLimit source xs entry) (destinationArray : Source.ArrayAt heapLimit destination ys entry) (disjoint : ArraysDisjoint source xs.length destination xs.length) :
      have result := Source.Array.copyFunctions.applyState.copy source destination length heapLimit entry ⋯; result.1 = () ∧ Source.ArrayAt heapLimit source xs result.2 ∧ Source.ArrayAt heapLimit destination xs result.2 ∧ ArrayFrame destination xs.length entry.mem result.2.mem ∧ result.2.input = entry.input ∧ result.2.outputRev = entry.outputRev

      Typed Unit application retains the actual copied shared state. The empty value does not replace execution: the destination contents, frame and streams come from the same compiled invocation.

      theorem Ram.Examples.ArrayCopyFunction.copy_spec {source destination length : Word 32} {heapLimit : ℕ} {entry : Source.State 32} (safe : Safe source destination length heapLimit entry) (hstack : heapLimit + ABI.frameSize Source.Array.copyFunctions.registers < 2 ^ 32) {xs ys : List (Word 32)} (count : BitVec.toNat length = xs.length) (sameLength : ys.length = xs.length) (sourceArray : Source.ArrayAt heapLimit source xs entry) (destinationArray : Source.ArrayAt heapLimit destination ys entry) (disjoint : ArraysDisjoint source xs.length destination xs.length) :
      have finish := copy source destination length heapLimit entry safe hstack; Source.ArrayAt heapLimit source xs finish ∧ Source.ArrayAt heapLimit destination xs finish ∧ ArrayFrame destination xs.length entry.mem finish.mem ∧ finish.input = entry.input ∧ finish.outputRev = entry.outputRev

      The actual returned state contains the copied list at both pointers, preserves memory outside the destination, and retains both I/O streams.

      theorem Ram.Examples.ArrayCopyFunction.copy_contents {source destination length : Word 32} {heapLimit : ℕ} {entry : Source.State 32} (safe : Safe source destination length heapLimit entry) (hstack : heapLimit + ABI.frameSize Source.Array.copyFunctions.registers < 2 ^ 32) {xs ys : List (Word 32)} (count : BitVec.toNat length = xs.length) (sameLength : ys.length = xs.length) (sourceArray : Source.ArrayAt heapLimit source xs entry) (destinationArray : Source.ArrayAt heapLimit destination ys entry) (disjoint : ArraysDisjoint source xs.length destination xs.length) :
      arrayContents (copy source destination length heapLimit entry safe hstack).mem destination xs.length = xs

      The ordinary list observation of the actual copied destination equals the source list. This reuses the existing representation-to-list theorem.

      theorem Ram.Examples.ArrayCopyFunction.runTotal_steps_le {source destination length : Word 32} {heapLimit : ℕ} {entry : Source.State 32} (safe : Safe source destination length heapLimit entry) (hstack : heapLimit + ABI.frameSize Source.Array.copyFunctions.registers < 2 ^ 32) {xs ys : List (Word 32)} (count : BitVec.toNat length = xs.length) (sameLength : ys.length = xs.length) (sourceArray : Source.ArrayAt heapLimit source xs entry) (destinationArray : Source.ArrayAt heapLimit destination ys entry) (disjoint : ArraysDisjoint source xs.length destination xs.length) :
      (Source.Array.copyFunctions.runTotal.copy source destination length heapLimit entry ⋯).steps ≤ 19 * xs.length + 39

      The existing independent body bound gives a bound for the actual copy call, including argument setup, return and halt. It is not used by copy_halts.

      def Ram.Examples.ArrayCopyFunction.copyThenSum (source destination length : Word 32) (heapLimit : ℕ) (entry : Source.State 32) (safe : Safe source destination length heapLimit entry) (hstack : heapLimit + ABI.frameSize Source.Array.sumFunctions.registers < 2 ^ 32) :

      Host-level sequencing of two actual compiled applications. Sum reads the destination from copy's returned state, not the input state or a logical list.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Ram.Examples.ArrayCopyFunction.copyThenSum_eq {source destination length : Word 32} {heapLimit : ℕ} {entry : Source.State 32} (safe : Safe source destination length heapLimit entry) (hstack : heapLimit + ABI.frameSize Source.Array.sumFunctions.registers < 2 ^ 32) {xs ys : List (Word 32)} (count : BitVec.toNat length = xs.length) (sameLength : ys.length = xs.length) (sourceArray : Source.ArrayAt heapLimit source xs entry) (destinationArray : Source.ArrayAt heapLimit destination ys entry) (disjoint : ArraysDisjoint source xs.length destination xs.length) :
        copyThenSum source destination length heapLimit entry safe hstack = (List.map BitVec.toNat xs).sum % 2 ^ 32

        Ordinary function composition preserves the source list's modular sum. No loop, RAM register or calling-convention proof is opened in this argument.