Documentation

Examples.Ram.ArrayMap

In-place mapping with an imported helper #

The named source calls the already verified square function and writes each result back into the borrowed array. The shared map contract supplies the loop invariant, termination and outside-array frame; the client supplies only the helper contract and its ordinary mathematical transformation.

The executable contents equation uses List.map. Its independent full-run bound includes the helper calls, real loads and stores, both iteration cursors, the generated index, and the enclosing call and halt. No list loader or allocation is performed, and machine-word multiplication remains modular.

@[reducible, inline]
noncomputable abbrev Ram.Examples.ArrayMap.functions.eval.Scalar.addSquare {w✝ : ℕ} (accumulator x : Word w✝) :

The declared function's result and shared state, observed through its actual execution.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    @[reducible, inline]

    Execute the declared function's compiled call, retaining the complete machine result.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[reducible, inline]

      Execute the declared function with a normal-halt proof, retaining its state and count.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        @[reducible, inline]

        Project the declared word, array, or Unit result of the normally terminating call. Use runTotal or applyState to observe execution when the result is Unit.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[reducible, inline]

          Project the declared word, array, or Unit result of the normally terminating call. Use runTotal or applyState to observe execution when the result is Unit.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            @[reducible, inline]

            The declared function's result and shared state, observed through its actual execution.

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

              The declared parameters' actual by-value word fields.

              @[reducible, inline]
              noncomputable abbrev Ram.Examples.ArrayMap.functions.bodyTime.mapSquares {w✝ : ℕ} (xs : ArrayRef w✝) :
              ℕ → Source.State w✝ → Part ℕ

              The declared function's compiled body count, excluding its enclosing call overhead.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                @[reducible, inline]

                Execute the declared function and return its typed value and source shared state, excluding private stack cells and restoring caller registers while retaining actual stream effects.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  @[reducible, inline]

                  Project the declared word, array, or Unit result of the normally terminating call. Use runTotal or applyState to observe execution when the result is Unit.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    @[reducible, inline]

                    Execute the declared function with a normal-halt proof, retaining its state and count.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      @[reducible, inline]

                      Execute the declared function and return its typed value and source shared state, excluding private stack cells and restoring caller registers while retaining actual stream effects.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        theorem Ram.Examples.ArrayMap.functions.arguments_eq.Scalar.addSquare {w✝ : ℕ} (accumulator x : Word w✝) :
                        arguments.Scalar.addSquare accumulator x = [accumulator, x]

                        The declared parameters' actual by-value word fields.

                        The declared parameters' actual by-value word fields.

                        @[reducible, inline]

                        Execute the declared function's compiled call, retaining the complete machine result.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          @[reducible, inline]
                          noncomputable abbrev Ram.Examples.ArrayMap.functions.bodyTime.Scalar.addSquare {w✝ : ℕ} (accumulator x : Word w✝) :
                          ℕ → Source.State w✝ → Part ℕ

                          The declared function's compiled body count, excluding its enclosing call overhead.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            @[reducible, inline]

                            Execute the declared function's compiled call, retaining the complete machine result.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              @[reducible, inline]

                              Execute the declared function and return its typed value and source shared state, excluding private stack cells and restoring caller registers while retaining actual stream effects.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                @[reducible, inline]
                                noncomputable abbrev Ram.Examples.ArrayMap.functions.eval.Scalar.square {w✝ : ℕ} (x : Word w✝) :

                                The declared function's result and shared state, observed through its actual execution.

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

                                  Transform a borrowed array using a statically imported source function.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    @[reducible, inline]
                                    noncomputable abbrev Ram.Examples.ArrayMap.functions.eval.mapSquares {w✝ : ℕ} (xs : ArrayRef w✝) :

                                    The declared function's result and shared state, observed through its actual execution.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For
                                      @[reducible, inline]
                                      noncomputable abbrev Ram.Examples.ArrayMap.functions.bodyTime.Scalar.squaredNorm {w✝ : ℕ} (x y : Word w✝) :
                                      ℕ → Source.State w✝ → Part ℕ

                                      The declared function's compiled body count, excluding its enclosing call overhead.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        @[reducible, inline]
                                        abbrev Ram.Examples.ArrayMap.functions.arguments.Scalar.addSquare {w✝ : ℕ} (accumulator x : Word w✝) :
                                        List (Word w✝)
                                        Equations
                                        Instances For
                                          @[reducible, inline]

                                          The declared function's result and shared state, observed through its actual execution.

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

                                            The declared parameters' actual by-value word fields.

                                            @[reducible, inline]

                                            Execute the declared function and return its typed value and source shared state, excluding private stack cells and restoring caller registers while retaining actual stream effects.

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

                                              The declared parameters' actual by-value word fields.

                                              @[reducible, inline]

                                              Execute the declared function's compiled call, retaining the complete machine result.

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For
                                                @[reducible, inline]
                                                noncomputable abbrev Ram.Examples.ArrayMap.functions.bodyTime.Scalar.square {w✝ : ℕ} (x : Word w✝) :
                                                ℕ → Source.State w✝ → Part ℕ

                                                The declared function's compiled body count, excluding its enclosing call overhead.

                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For
                                                  @[reducible, inline]

                                                  Execute the declared function with a normal-halt proof, retaining its state and count.

                                                  Equations
                                                  • One or more equations did not get rendered due to their size.
                                                  Instances For
                                                    @[reducible, inline]
                                                    noncomputable abbrev Ram.Examples.ArrayMap.functions.bodyTime.Scalar.sumSquares {w✝ : ℕ} (xs : ArrayRef w✝) :
                                                    ℕ → Source.State w✝ → Part ℕ

                                                    The declared function's compiled body count, excluding its enclosing call overhead.

                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    Instances For
                                                      @[reducible, inline]
                                                      abbrev Ram.Examples.ArrayMap.functions.run.Scalar.addSquare {w✝ : ℕ} (accumulator x : Word w✝) :
                                                      ℕ → Source.State w✝ → Option (RunResult (State w✝))

                                                      Execute the declared function's compiled call, retaining the complete machine result.

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For
                                                        @[reducible, inline]
                                                        Equations
                                                        Instances For
                                                          @[reducible, inline]

                                                          Project the declared word, array, or Unit result of the normally terminating call. Use runTotal or applyState to observe execution when the result is Unit.

                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For
                                                            @[reducible, inline]

                                                            Execute the declared function with a normal-halt proof, retaining its state and count.

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For
                                                              @[reducible, inline]

                                                              Execute the declared function with a normal-halt proof, retaining its state and count.

                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For
                                                                @[reducible, inline]

                                                                Project the declared word, array, or Unit result of the normally terminating call. Use runTotal or applyState to observe execution when the result is Unit.

                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For
                                                                  @[reducible, inline]

                                                                  Execute the declared function and return its typed value and source shared state, excluding private stack cells and restoring caller registers while retaining actual stream effects.

                                                                  Equations
                                                                  • One or more equations did not get rendered due to their size.
                                                                  Instances For
                                                                    theorem Ram.Examples.ArrayMap.typed_contract {w heapLimit : ℕ} {xs : List (Word w)} (hw : 0 < w) :
                                                                    Source.TypedFunctionContract functions.program heapLimit 1 functions.function.mapSquares DSL.ValueKind.unit functions.arguments.mapSquares (fun (array : ArrayRef w) (entry : Source.State w) => array.Rep heapLimit xs entry) fun (array : ArrayRef w) (entry : Source.State w) (x : DSL.ValueKind.unit.Value w) (finish : Source.State w) => array.Rep heapLimit (List.map (fun (x : Word w) => x * x) xs) finish ∧ ArrayFrame array.base xs.length entry.mem finish.mem ∧ finish.input = entry.input ∧ finish.outputRev = entry.outputRev

                                                                    Ordinary list mapping describes the actual mutation. The helper's contract is reused without inspecting its body or exposing the traversal's local slots.

                                                                    theorem Ram.Examples.ArrayMap.function_timeBound {w control heapLimit : ℕ} (hw : 0 < w) (array : ArrayRef w) :
                                                                    Source.FunctionTimeBound control functions.program heapLimit 1 functions.function.mapSquares (fun (args : List (Word w)) (x : Source.State w) => args = functions.arguments.mapSquares array) fun (x : List (Word w)) (x_1 : Source.State w) => 46 * BitVec.toNat array.length + 8

                                                                    A separate uniform bound on the same function body. Squaring has an empty body and computes its result in the actual return expression, charged by its call.

                                                                    theorem Ram.Examples.ArrayMap.halts {heapLimit : ℕ} {array : ArrayRef 32} {xs : List (Word 32)} {entry : Source.State 32} (represented : array.Rep heapLimit xs entry) (hstack : heapLimit + 2 * ABI.frameSize functions.registers < 2 ^ 32) :

                                                                    Budget-free correctness proves normal termination of the actual compiled call, with the two required frames and no separately supplied time bound.

                                                                    theorem Ram.Examples.ArrayMap.applyState_contents {heapLimit : ℕ} {array : ArrayRef 32} {xs : List (Word 32)} {entry : Source.State 32} (represented : array.Rep heapLimit xs entry) (hstack : heapLimit + 2 * ABI.frameSize functions.registers < 2 ^ 32) :
                                                                    have finish := (functions.applyState.mapSquares array heapLimit entry ⋯).2; arrayContents finish.mem array.base xs.length = List.map (fun (x : Word 32) => x * x) xs

                                                                    The ordinary executable state projection contains exactly the mathematical mapped list. This is the compiled invocation, not a host call to List.map.

                                                                    theorem Ram.Examples.ArrayMap.runTotal_steps_le {heapLimit : ℕ} {array : ArrayRef 32} {xs : List (Word 32)} {entry : Source.State 32} (represented : array.Rep heapLimit xs entry) (hstack : heapLimit + 2 * ABI.frameSize functions.registers < 2 ^ 32) :
                                                                    (functions.runTotal.mapSquares array heapLimit entry ⋯).steps ≤ 46 * xs.length + 71

                                                                    Bound this same complete invocation, including its outer call and halt.