Documentation

Complexity.Computability.Ram.Compiler.Language.Buffer.Copy.AppendCost

Allocation-aware linear cost of the existing buffer append #

The actual Copy.append allocates and initializes its fresh destination, copies the left input, copies the right input, then returns that destination. Its cost proof reuses the existing copy loop bound and source contracts at the real intermediate heaps. Inputs may overlap: only the freshly allocated destination needs to be disjoint. No readiness or finite-word assumption restricts this conditional cost contract; those belong to the independent launch proof.

The size envelopes count initialization, both calls, their sequence dispatch, and the actual return. The whole-invocation envelope additionally counts its outer call and final halt through the existing compiler cost function.

The compiler-derived core envelope includes real allocation initialization and both actual copying calls; it omits only the outer function initialization.

Equations
Instances For
    theorem Ram.LanguageCompiler.BufferCopy.append_stmt_costBound (leftValues rightValues : Array ℕ) (left right : Complexity.Language.Buffer Complexity.Language.CellTy.nat) (heap : Complexity.Language.Heap) (w heapLimit : ℕ) (observedLeft : left.Contents heap leftValues) (observedRight : right.Contents heap rightValues) :

    Bound the same allocating source statement from ordinary input contents. There are no cell ranges, word-width inequalities or proposed readiness premises.

    theorem Ram.LanguageCompiler.BufferCopy.appendCoreBound_eq (leftSize rightSize : ℕ) :
    appendCoreBound leftSize rightSize = (14 + ↑copyIntoGuardCost + ↑copyIntoBodyCost + 10) * (leftSize + rightSize) + appendCoreBound 0 0

    Each input element pays for one initializer iteration and one copy round. All remaining compiler-generated costs are fixed overhead.

    The complete lowered function-body envelope uses only total input size, and adds the existing two-instruction function initialization exactly once.

    Equations
    Instances For
      theorem Ram.LanguageCompiler.BufferCopy.appendBodyBound_sizes (leftSize rightSize : ℕ) :
      appendCoreBound leftSize rightSize + 2 = appendBodyBound (leftSize + rightSize)

      Splitting the same total size differently does not change the body envelope.

      The body envelope is affine in the sum of the two native array lengths.

      Add the actual outer invocation and final halt to the proved body budget.

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

        The invocation keeps exactly the body envelope's linear coefficient.

        theorem Ram.LanguageCompiler.BufferCopy.isBigO_appendBodyBound :
        (fun (size : ℕ) => ↑(appendBodyBound size)) =O[Filter.atTop] fun (size : ℕ) => ↑size

        The body cost is linear in total native input size.

        The complete invocation envelope is linear in total native input size.