Documentation

Examples.Language.ScalarCompiled

Transferring the scalar source proof through generic lowering #

The independent source program and its mathematical proofs are imported unchanged. The additional proofs here concern the actual intermediate natural values and sufficient call nesting. The helper's existing source contract identifies its actual returned value; its mathematical behavior is not reproved.

The shared lowering theorems produce both callable IR execution and a halted RAM runner with the same mathematical minimum. No register layout, receiver update or algorithm-specific source-to-IR adapter appears in this proof. Separate source-execution cost bounds apply to that same invocation, including its internal helper call, outer calling convention and final halt.

The source contracts preserve every initial heap. These pure backend consumers instantiate the shared heap relation with no source objects, so arbitrary RAM entry memory is admitted. Their read-only source bodies separately establish that the actual target invocation preserves this entry state.

The helper needs no nested call and its actual sum must fit the word width.

One call level suffices. The intermediate increment, not merely the final minimum, and the compared limit must both be representable.

theorem Complexity.Language.Examples.Scalar.increment_functionExec {w heapLimit : ℕ} (hw : 0 < w) (n : ℕ) (_sourceHeap : Heap) (fits : n + 1 < 2 ^ w) (entry : Ram.Source.State w) :

The automatically lowered helper returns the same mathematical increment. The entry state and heap boundary are arbitrary; no manual register proof is needed.

theorem Complexity.Language.Examples.Scalar.boundedIncrement_functionExec {w heapLimit : ℕ} (hw : 0 < w) (n limit : ℕ) (_sourceHeap : Heap) (sumFits : n + 1 < 2 ^ w) (limitFits : limit < 2 ^ w) (entry : Ram.Source.State w) :

The same source helper-call and branch program has an actual generated function execution returning the mathematical minimum. This uses the shared compiler theorem and the unchanged source correctness proof.

The actual compiled machine returns the source-level minimum and preserves the shared entry state. Its measured instruction count refers to this same execution, without assuming or claiming an instruction upper bound.

The helper body spends four transitions on addition, four on returning its value and setting the flag, and two on flag initialization.

The caller reuses the helper's complete call bound. Local initialization, comparison, assignment and return retain the actual branch selected by the helper's result. The false branch retains the initialized limit.

The caller reuses the helper's complete call bound. Local initialization, comparison, the selected assignment, dispatch and return add at most nineteen transitions.

theorem Complexity.Language.Examples.Scalar.boundedIncrement_runUntil_le {w heapLimit : ℕ} (hw : 0 < w) (n limit : ℕ) (_sourceHeap : Heap) (sumFits : n + 1 < 2 ^ w) (limitFits : limit < 2 ^ w) (entry : Ram.Source.State w) (codeCapacity : List.length (Ram.LanguageCompiler.lowerCode program 1) < 2 ^ w) (stackCapacity : heapLimit + 2 * Ram.ABI.frameSize (Ram.LanguageCompiler.programControl program) < 2 ^ w) :

The same halted machine invocation returns the mathematical minimum and satisfies the independent source cost bound, including the outer call and halt.

The structure wrapper reuses the actual imported scalar implementation. Its two stored fields and the intermediate increment are the only value ranges; two nested call levels include the imported helper's own call.

Infer the cost of the real structure copies, projections and imported call. The witness is chosen before the arguments, so it is a uniform compiler-derived bound, not a price assigned to the mathematical structure operation.

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

    The caller's own construction and projection are charged around the actual structure-valued call, using the same shared structural rules.

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

      The caller reuses generated source totality for the structure-valued call. Only mathematical ranges remain after the shared projection/call rules.

      Add the actual outer call, return and final halt to the inferred body cost.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Complexity.Language.Examples.Scalar.structured_run_execute_le {w heapLimit : ℕ} {placement : ℕ → Ram.Word w} (n limit : ℕ) {heap : Heap} {entry : Ram.Source.State w} (launch : Ram.LanguageCompiler.FunctionLaunch Structured.program Structured.runId 3 heapLimit placement (Structured.run_args n limit) heap entry) (sumFits : n + 1 < 2 ^ w) :
        ∃ (outcome : Ram.LanguageCompiler.FunctionExecution Structured.program Structured.runId heapLimit placement (Structured.run_args n limit) heap entry), outcome.value = min (n + 1) limit ∧ outcome.result.steps ≤ structuredRunSteps

        The ordinary structure proof and independent compiler-derived cost describe one actual halted RAM invocation. The launch retains its input representation, word width and code/stack capacity; input loading is outside this boundary.

        The existing native increment's mathematical contract also protects every old buffer observation; mapping does not require another scalar proof.

        A real allocating traversal calling the original increment implementation.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem Complexity.Language.Examples.Scalar.mappedIncrement_execute {w heapLimit : ℕ} {placement : ℕ → Ram.Word w} (source : Buffer CellTy.nat) (input : Array ℕ) {heap : Heap} {cursor : ℕ} {entry : Ram.Source.State w} (launch : Ram.LanguageCompiler.FunctionArenaLaunch mappedIncrement (Buffer.Map.entry CellTy.nat CellTy.nat signatures) 1 heapLimit placement (Ram.LanguageCompiler.BufferMap.mapArgs source 0) heap cursor entry) (observed : source.Contents heap input) (fits : ∀ (i : ℕ) (hi : i < input.size), input[i] + 1 < 2 ^ w) (capacity : cursor + input.size ≤ heapLimit) :

          The existing scalar range and cost proofs suffice for the allocating map. The conclusion describes fresh output, every retained old view and the same halted RAM invocation. Only input ranges and sufficient storage remain.

          The same bound used by mappedIncrement_execute is linear in the array length. Word ranges and storage capacity remain in that execution theorem.

          Infer the actual structure-valued helper's uniform body cost once.

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

            The finite-range guard has a uniform bound at native loop coordinates.

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

              Structure copies, the real helper call and the cursor increment all occur in this compiler-derived bound; no mathematical mapper is charged as a primitive.

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

                The complete source body includes its pre-loop helper call, range setup, all iterations and final return, using the inferred compiler charges.

                Equations
                Instances For

                  The inferred budget is affine in the ordinary number of range elements. Both its per-round coefficient and fixed overhead come from the same compiler proof; the input structure, heap and step value do not change those constants.

                  The same full function has a bound in its ordinary numeric parameters; the initial structure and calling heap do not alter this uniform bound.

                  The actual structure helper uses no nested calls. Both its computed sum and the retained limit field must fit the selected word width.

                  Native coordinates expose the two actual guard operands; the other captured fields do not introduce extra word operations in this guard.

                  Realize the actual helper call, accumulator assignment and cursor increment. The generated source contract supplies the helper's returned structure.

                  theorem Complexity.Language.Examples.Scalar.structured_range_sum_realizable {w : ℕ} (hw : 0 < w) :
                  Ram.LanguageCompiler.FunctionRealizable StructuredRange.program w 1 StructuredRange.sumId (StructuredRange.sum_onArgs fun (initial : ℕ × ℕ) (start stop k : ℕ) (x : Heap) => initial.1 + (List.range' start ((stop - start + k) / (k + 1)) (k + 1)).sum < 2 ^ w ∧ start + (stop - start + k) / (k + 1) * (k + 1) < 2 ^ w ∧ k + 1 < 2 ^ w ∧ stop < 2 ^ w ∧ initial.2 < 2 ^ w)

                  One call level suffices for every iteration and the pre-loop helper call. The final sum bounds all intermediate additions. The last cursor may exceed stop, and its actual value and the eagerly computed stride remain explicit.

                  The same inferred source budget includes the outer call, return and halt.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem Complexity.Language.Examples.Scalar.structured_range_sum_execute_le {w heapLimit : ℕ} {placement : ℕ → Ram.Word w} (initial : BoundedInput) (start stop k : ℕ) {heap : Heap} {entry : Ram.Source.State w} (launch : Ram.LanguageCompiler.FunctionLaunch StructuredRange.program StructuredRange.sumId 1 heapLimit placement (StructuredRange.sum_inputEmbedding (initial, start, stop, k)) heap entry) (sumFits : initial.value + (List.range' start ((stop - start + k) / (k + 1)) (k + 1)).sum < 2 ^ w) (cursorFits : start + (stop - start + k) / (k + 1) * (k + 1) < 2 ^ w) (strideFits : k + 1 < 2 ^ w) :
                    ∃ (outcome : Ram.LanguageCompiler.FunctionExecution StructuredRange.program StructuredRange.sumId heapLimit placement (StructuredRange.sum_inputEmbedding (initial, start, stop, k)) heap entry), BoundedInput.sourceRepresentation.Rel { value := initial.value + (List.range' start ((stop - start + k) / (k + 1)) (k + 1)).sum, limit := initial.limit } outcome.value outcome.heap ∧ outcome.result.steps ≤ structuredRangeSumSteps start stop k

                    The ordinary structure/range theorem and its independently derived budget describe one actual halted RAM invocation. The launch retains the preloaded input representation and code/stack capacity, while the three extra conditions cover the actual sum, final cursor and computed stride, including empty ranges.

                    Infer a uniform bound for the same signed-distance caller from its actual integer callees. Sign branches, intermediate bindings and call overhead are counted by the existing compiler rules, not assigned mathematical prices.

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

                      The squared-distance caller pays for the actual subtraction and product implementations, with a bound inferred independently of their arguments.

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