Documentation

Examples.Language.LinkedListAllocation

Executing a native linked-list constructor on RAM #

This is the actual generated NativeConstruction.Source.prepend wrapper, not the imported constructor considered in isolation. Its ordinary source refinement supplies head :: values; the shared constructor-call rule supplies readiness and the exact count for the same execution. The invocation includes both call levels, initialization, the wrapper return and the final halt.

The returned execution retains the actual extended heap and updated cursor. The original tail remains available in that same heap, including when it is shared by other roots. No disjointness or suffix copying is required.

Infer the straight-line wrapper's bound from its actual body and the constructor certificate. The measured theorem below establishes the exact count.

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

    Full instruction count for the generated wrapper, including its outer invocation, private-flag initialization and final halt exactly once.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Complexity.Language.Examples.LinkedList.prepend_ready_cost {w heapLimit cursor : ℕ} (head : ℕ) (tail : Option (NodeRef CellTy.nat)) (heap : Heap) (positive : 0 < w) (headFits : head < 2 ^ w) (space : cursor + 3 ≤ heapLimit) :

      The generated constructor body exposes its exact allocation and instruction count in ordinary arguments, so later callers reuse it at their current heap and cursor without opening the imported constructor again.

      theorem Complexity.Language.Examples.LinkedList.prepend_execute {w heapLimit cursor : ℕ} {placement : ℕ → Ram.Word w} (head : ℕ) (values : List ℕ) (tail : Option (NodeRef CellTy.nat)) {heap : Heap} (observed : (Representation.list CellTy.nat).Rel values tail heap) {entry : Ram.Source.State w} (launch : Ram.LanguageCompiler.FunctionArenaLaunch NativeConstruction.Source.program NativeConstruction.Source.prependId 1 heapLimit placement (NativeConstruction.Source.prepend_args head tail) heap cursor entry) (space : cursor + 3 ≤ heapLimit) :
      ∃ (outcome : Ram.LanguageCompiler.FunctionArenaExecution NativeConstruction.Source.program NativeConstruction.Source.prependId 1 heapLimit placement (NativeConstruction.Source.prepend_args head tail) heap entry), (Representation.list CellTy.nat).Rel (head :: values) outcome.value outcome.heap ∧ outcome.heap = (heap.cons head tail).2 ∧ outcome.value = some (heap.cons head tail).1 ∧ (Representation.list CellTy.nat).Rel values tail outcome.heap ∧ heap.ShapeExtends outcome.heap ∧ outcome.cursor = cursor + 3 ∧ outcome.bodySteps = prependBodySteps + 2 ∧ outcome.result.steps = prependSteps

      The ordinary native constructor halts in one real allocating RAM invocation. The source refinement is independent of resources; the launch supplies the existing finite-word, rootedness and code/stack conditions. Only three additional arena words are needed, regardless of the represented tail's length.

      Infer both actual wrapper calls and the final return from the generated body. The exact execution theorem below retains both calls at the same nesting depth.

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

        Two sequential calls to the same generated constructor reuse its exact body count. Each call pays its own frame work; the final return belongs to the caller.

        Equations
        Instances For

          The actual two-constructor wrapper's complete invocation count, including its own initialization, outer call and final halt.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem Complexity.Language.Examples.LinkedList.prependPair_execute {w heapLimit cursor : ℕ} {placement : ℕ → Ram.Word w} (first second : ℕ) (values : List ℕ) (tail : Option (NodeRef CellTy.nat)) {heap : Heap} (observed : (Representation.list CellTy.nat).Rel values tail heap) {entry : Ram.Source.State w} (launch : Ram.LanguageCompiler.FunctionArenaLaunch NativeConstruction.Source.program NativeConstruction.Source.prependPairId 2 heapLimit placement (NativeConstruction.Source.prependPair_args first second tail) heap cursor entry) (space : cursor + 6 ≤ heapLimit) :

            Two calls to the generated constructor run sequentially at depth two and retain both actual allocations. The ordinary result and shared-tail frame refer to the same halted invocation whose exact count includes both wrapper calls.

            Only the chosen branch allocates: three nodes on the true path and two on the false path, including the common continuation's final constructor call.

            Equations
            Instances For

              The actual branch and common continuation's core count. Initialize the optional result slot, then assign the selected value to it once. The common option match copies its payload once before the final call. Assignments, branches and sequencing use the existing compiler costs.

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

                The selected branch's complete invocation, including the wrapper's own initialization, outer call and halt. Untaken branch calls are not charged.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  theorem Complexity.Language.Examples.LinkedList.choosePrepend_execute {w heapLimit cursor : ℕ} {placement : ℕ → Ram.Word w} (flag : Bool) (head : ℕ) (leftValues rightValues : List ℕ) (left right : Option (NodeRef CellTy.nat)) {heap : Heap} (leftObserved : (Representation.list CellTy.nat).Rel leftValues left heap) (rightObserved : (Representation.list CellTy.nat).Rel rightValues right heap) {entry : Ram.Source.State w} (launch : Ram.LanguageCompiler.FunctionArenaLaunch NativeBranches.Source.program NativeBranches.Source.choosePrependId 2 heapLimit placement (NativeBranches.Source.choosePrepend_args flag head left right) heap cursor entry) (space : cursor + choosePrependReserve flag ≤ heapLimit) :
                  ∃ (outcome : Ram.LanguageCompiler.FunctionArenaExecution NativeBranches.Source.program NativeBranches.Source.choosePrependId 2 heapLimit placement (NativeBranches.Source.choosePrepend_args flag head left right) heap entry), (Representation.list CellTy.nat).Rel (head :: head :: if flag = true then head :: leftValues else rightValues) outcome.value outcome.heap ∧ (Representation.list CellTy.nat).Rel leftValues left outcome.heap ∧ (Representation.list CellTy.nat).Rel rightValues right outcome.heap ∧ heap.ShapeExtends outcome.heap ∧ outcome.cursor = cursor + choosePrependReserve flag ∧ outcome.bodySteps = choosePrependBodySteps flag + 2 ∧ outcome.result.steps = choosePrependSteps flag

                  A native list-valued conditional allocates along its actual selected branch, merges that list, then invokes the common continuation on the same real heap. The original roots remain observable even if they share nodes. The execution record retains complete physical memory and placement for a subsequent call.

                  Infer the wrapper's uniform structural bound from its actual body and the two callee certificates. No call-table index or field-copy formula is supplied.

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

                    Complete constant invocation bound, including the enclosing initialization, outer call and halt. Input loading is outside this preloaded-call boundary.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      theorem Complexity.Language.Examples.LinkedList.replaceHead_execute_le {w heapLimit cursor : ℕ} {placement : ℕ → Ram.Word w} (replacement : ℕ) (values : List ℕ) (root : Option (NodeRef CellTy.nat)) {heap : Heap} (observed : (Representation.list CellTy.nat).Rel values root heap) {entry : Ram.Source.State w} (launch : Ram.LanguageCompiler.FunctionArenaLaunch NativeViews.Source.program NativeViews.Source.replaceHeadId 2 heapLimit placement (NativeViews.Source.replaceHead_args replacement root) heap cursor entry) (space : cursor + 3 ≤ heapLimit) :

                      Ordinary List matching reads at most one actual node, shares its tail and allocates one new head. The same halted RAM execution satisfies the native mathematical equation, a length-independent instruction bound and three-word growth. Every old List observation remains valid, including shared tails.