Documentation

Complexity.Computability.Ram.Array.Map.Basic

In-place mapping through a statically linked function #

The source operation takes a borrowed array in its first two parameter slots. It keeps an index, uses the ordinary forIn load and cursor updates, and calls the fixed source function fn before storing each returned word. The remaining slots are private locals, exactly as in the named DSL declaration with for i, x in xs { let y ← call helper(x); xs[i] := y; }.

The mathematical transformation below describes a verified callee; it is not an executable Lean callback or a second interpretation of the program.

One actual helper call, indexed store and explicit index increment. The iteration mechanism supplies the element in local 5.

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

    Initialize the public source index and traverse the borrowed array.

    Equations
    Instances For

      The ordinary source function underlying the reusable map operation. Its helper index is resolved statically, not passed in a runtime word.

      Equations
      Instances For
        def Ram.Source.Array.Map.bodyState {w : ℕ} (transform : Word w → Word w) (s : State w) :

        The shared effects and local assignments of the body after loading an element.

        Equations
        Instances For
          theorem Ram.Source.Array.Map.body_safe_at {w : ℕ} {program : Program} {helper : Func} {fn heapLimit depth : ℕ} {transform : Word w → Word w} (lookup : program[fn]? = some helper) (s : State w) (correct : FunctionContract program heapLimit depth helper (fun (args : List (Word w)) (x : State w) => args = [s.regs 5]) fun (x : List (Word w)) (entry : State w) (value : List (Word w)) (finish : State w) => value = [transform (s.regs 5)] ∧ finish = entry) (address : BitVec.toNat (s.regs 0 + s.regs 2) < heapLimit) :
          SafeExec program heapLimit (depth + 1) (body fn) s (bodyState transform s)

          A callee contract at the actual loaded word suffices for the body. The callee preserves shared state; the subsequent real store changes the array.

          theorem Ram.Source.Array.Map.body_remaining {w : ℕ} {program : Program} {fn heapLimit depth : ℕ} {s t : State w} (execution : SafeExec program heapLimit depth (body fn) s t) :
          t.regs 4 = s.regs 4

          Completed bodies preserve the private remaining count independently of the helper's behavior: the actual call restores caller locals before binding its result.