Documentation

Examples.Language.LinkedListComposition

Traversing a newly allocated native list #

The existing NativeLists.reverseSum first allocates an actual reversed list, then traverses that returned list with the existing addition callback. Source correctness transports the mathematical List observation across the first call; the same observation selects the second call's length-dependent cost certificate. No decoder, second implementation or per-consumer register proof is introduced.

The final RAM theorem retains the same actual heap and allocation cursor. The original list remains observable. A final-sum range supplies all addition ranges; the additional arena allowance is three words per original element.

The shared fold envelope uses the original addition callback's proved cost. Call-frame and traversal coefficients belong to the library, not this consumer.

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

    Select the actual sum-fold certificate at its mathematical input length. The callback's ordinary range domain is retained, separately from correctness.

    def Complexity.Language.Examples.LinkedList.reverseSumCost (length : ℕ) :
    { bound : ℕ // ∀ (w heapLimit : ℕ) (values : List ℕ) (root : Option (NodeRef CellTy.nat)) (heap : Heap), values.length = length → (Representation.list CellTy.nat).Rel values root heap → values.sum < 2 ^ w → Ram.LanguageCompiler.StmtArenaCostBound NativeLists.Source.program w heapLimit 5 (NativeLists.Source.program.body NativeLists.Source.reverseSumId) { locals := NativeLists.Source.reverseSum_args root, heap := heap } bound }

    Infer both actual calls' costs, carrying the first call's source postcondition to the new list's cost proof. The source declaration itself and its mathematical correctness theorem remain unchanged.

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

      The inferred body envelope adds the actual outer invocation and final halt once. Both inner traversals and their callbacks are already included.

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

        The inferred complete invocation bound is affine in length. This identity states that fact without introducing another set of compiler coefficients.

        The proved whole-invocation envelope is linear in the input length, using mathlib's ordinary IsBigO, not a separate complexity predicate.

        Compose existing measured calls at their actual returned heap and cursor. The independent reverse specification supplies the List observed by the fold.

        theorem Complexity.Language.Examples.LinkedList.reverseSum_ready_cost {w heapLimit cursor : ℕ} (values : List ℕ) (root : Option (NodeRef CellTy.nat)) (heap : Heap) (positive : 0 < w) (observed : (Representation.list CellTy.nat).Rel values root heap) (fits : values.sum < 2 ^ w) (space : cursor + 3 * values.length ≤ heapLimit) :

        Compose the actual allocating reverse with the scalar fold at its actual returned heap and cursor. The second traversal reserves no additional words.

        theorem Complexity.Language.Examples.LinkedList.reverseSum_execute {w heapLimit cursor : ℕ} {placement : ℕ → Ram.Word w} (values : List ℕ) (root : Option (NodeRef CellTy.nat)) {heap : Heap} (observed : (Representation.list CellTy.nat).Rel values root heap) (fits : values.sum < 2 ^ w) {entry : Ram.Source.State w} (launch : Ram.LanguageCompiler.FunctionArenaLaunch NativeLists.Source.program NativeLists.Source.reverseSumId 5 heapLimit placement (NativeLists.Source.reverseSum_args root) heap cursor entry) (space : cursor + 3 * values.length ≤ heapLimit) :

        The native allocation-then-traversal program halts on RAM with values.sum. The original List remains observable in the same final heap. The instruction bound covers both traversals, initialization, calls, returns and halt; input loading is excluded. The cursor bound concerns cumulative fresh allocation, not exact peak live storage or reclamation.