Documentation

Examples.Language.ArrayIterationCompiled

Nonuniform costs for the existing array-record loop #

The unchanged ArrayRangeNative.repeatAppend copies a growing array on each iteration. Its generated mathematical guard/body contracts transport the current array observations through the actual heaps. The shared arena loop rule reuses these contracts with a finite-sum potential, without a second execution induction, a new termination argument or reconstruction of array handles.

The inferred body certificate uses the real allocating append cost, including the caller's record updates. Structural composition accounts for the enclosing function and its initialization once. The resulting all-input bound grows as 1 + count + count * initialSize + count² * chunkSize; its mathlib asymptotic corollary concerns this same envelope. These are conditional cost contracts, not readiness, capacity, space or complete launched-execution guarantees.

Infer the actual guard's uniform cost at the caller's depth.

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

    Infer one round's cost from the current mathematical input lengths and actual heap observations. Both append inputs may share storage.

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

      Sum the size-dependent round envelopes and the final false guard.

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

        The real append supplies the slope; caller bookkeeping is size-independent.

        theorem Complexity.Language.Examples.LinkedList.NativeRange.RepeatAppendCost.loopBound_succ (count size chunk : ℕ) :
        loopBound (count + 1) size chunk = ↑guardCost + ↑(bodyCost (size + chunk)) + loopBound count (size + chunk) chunk + 10

        One iteration increases the current array length and consumes its own charge.

        def Complexity.Language.Examples.LinkedList.NativeRange.RepeatAppendCost.functionCost (count size chunkSize : ℕ) :
        { bound : ℕ // ∀ (w heapLimit : ℕ) (chunkValues : Array ℕ) (initialValue : Payload) (chunk : Buffer CellTy.nat) (initial : Buffer CellTy.nat × ℕ) (heap : Heap), initialValue.values.size = size → chunkValues.size = chunkSize → chunk.Contents heap chunkValues → ArrayRangeNative.Source.repeatAppend_loop1.state_representation.Rel initialValue initial heap → Ram.LanguageCompiler.StmtArenaCostBound ArrayRangeNative.Source.program w heapLimit 2 (ArrayRangeNative.Source.program.body ArrayRangeNative.Source.repeatAppendId) { locals := ArrayRangeNative.Source.repeatAppend_args count chunk initial, heap := heap } bound }

        Infer the unchanged function's statement envelope using only count and input lengths, before introducing handles, payloads, word width or heap limit.

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

          The callable function adds its existing initialization charge exactly once.

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

            Bound the same callable function under its original array/record observations, without imposing disjointness, termination budgets or capacity assumptions.

            theorem Complexity.Language.Examples.LinkedList.NativeRange.RepeatAppendCost.functionBodyBound_eq (count size chunk : ℕ) :
            functionBodyBound count size chunk = functionBodyBound 0 0 0 + ∑ index ∈ Finset.range count, (↑guardCost + ↑(bodyCost (size + (index + 1) * chunk)) + 10)

            All iteration-dependent work is the finite sum; the remaining caller work is exactly its zero-iteration envelope.

            An all-input polynomial bound obtained by bounding each actual round's size by the final array size. Compiler-derived coefficients remain explicit.

            theorem Complexity.Language.Examples.LinkedList.NativeRange.RepeatAppendCost.isBigO_functionBodyBound :
            (fun (input : ℕ × ℕ × ℕ) => ↑(functionBodyBound input.1 input.2.1 input.2.2)) =O[Filter.atTop] fun (input : ℕ × ℕ × ℕ) => ↑(1 + input.1 * (1 + input.2.1 + input.1 * input.2.2))

            The same three-parameter envelope has mathlib's asymptotic growth bound. The proof uses an all-input inequality, not constraints on relative input sizes.