Documentation

Complexity.Computability.Ram.Compiler.Language.List.Fold.Basic

Shared arguments and bounds for linked-list folding #

Callback domains, actual source arguments and accumulated envelopes are shared by readiness and cost proofs. These definitions do not choose a traversal or require a proposed instruction bound to establish successful execution. The guard's measured primitive proof retains its existing branch counts.

Mathematical charge accumulated along the ordinary fold trajectory. This is an envelope on supplied bounds, not a source execution or cost model.

Equations
Instances For
    theorem Ram.LanguageCompiler.List.Fold.accumulated_add_const {α : Type u} {kind : Complexity.Language.CellTy} (step : α → Complexity.Language.CellValue kind → α) (charge : α → Complexity.Language.CellValue kind → ℕ) (overhead : ℕ) (accumulator : α) (values : List (Complexity.Language.CellValue kind)) :
    accumulated step (fun (a : α) (head : Complexity.Language.CellValue kind) => charge a head + overhead) accumulator values = accumulated step charge accumulator values + values.length * overhead

    A fixed per-element overhead separates from the accumulator-dependent callback charges without changing which accumulator supplies each bound.

    Each index keeps the mathematical accumulator and its actual source value; heap representations need not choose a unique runtime encoding.

    Equations
    Instances For

      The callback domain and accumulator observation are checked at the actual entry heap, rather than turning the representation into a host-side decoder.

      Equations
      Instances For
        @[reducible, inline]
        abbrev Ram.LanguageCompiler.List.Fold.CalleeResources {α : Type u} {accTy : Complexity.Language.Ty} {kind : Complexity.Language.CellTy} {signatures : List Complexity.Language.Signature} (program : Complexity.Language.Program signatures) (fn : Fin signatures.length) (same : signatures[fn] = Complexity.Language.List.Fold.stepSignature accTy kind) (representation : Complexity.Language.Representation α accTy) (domain : α → Complexity.Language.CellValue kind → Prop) (w heapLimit depth : ℕ) (reserve : α → Complexity.Language.CellValue kind → ℕ) :

        Fold specializes the shared resource interface to the selected callback; the reservation depends on the mathematical accumulator and current head.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[reducible, inline]
          abbrev Ram.LanguageCompiler.List.Fold.CalleeCostBound {α : Type u} {accTy : Complexity.Language.Ty} {kind : Complexity.Language.CellTy} {signatures : List Complexity.Language.Signature} (program : Complexity.Language.Program signatures) (fn : Fin signatures.length) (same : signatures[fn] = Complexity.Language.List.Fold.stepSignature accTy kind) (representation : Complexity.Language.Representation α accTy) (domain : α → Complexity.Language.CellValue kind → Prop) (w heapLimit depth : ℕ) (bound : α → Complexity.Language.CellValue kind → ℕ) :

          Callback bounds retain the shared convention: actual core steps plus the two function-initialization instructions, before the caller adds its frame work.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            def Ram.LanguageCompiler.List.Fold.remainingCost {α : Type u} {kind : Complexity.Language.CellTy} {signatures : List Complexity.Language.Signature} (program : Complexity.Language.Program signatures) (fn : Fin signatures.length) (accTy : Complexity.Language.Ty) (step : α → Complexity.Language.CellValue kind → α) (bound : α → Complexity.Language.CellValue kind → ℕ) (accumulator : α) (values : List (Complexity.Language.CellValue kind)) :

            The emitted call overhead and one round of actual linked traversal are added to the callback's independently supplied bound at each accumulator.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem Ram.LanguageCompiler.List.Fold.remainingCost_eq_sum {α : Type u} {kind : Complexity.Language.CellTy} {signatures : List Complexity.Language.Signature} (program : Complexity.Language.Program signatures) (fn : Fin signatures.length) (accTy : Complexity.Language.Ty) (step : α → Complexity.Language.CellValue kind → α) (bound : α → Complexity.Language.CellValue kind → ℕ) (accumulator : α) (values : List (Complexity.Language.CellValue kind)) :
              remainingCost program fn accTy step bound accumulator values = accumulated step bound accumulator values + values.length * (callCost program fn 0 + 2 * fieldCount accTy + 45)

              Callback charges along the ordinary fold trajectory separate from the compiler's linear traversal and actual calling-convention overhead.

              theorem Ram.LanguageCompiler.List.Fold.contents_valueFits {kind : Complexity.Language.CellTy} {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {initial : Source.State w} {root : Option (Complexity.Language.NodeRef kind)} {values : List (Complexity.Language.CellValue kind)} (memory : HeapRep placement heapLimit heap initial) (observed : Complexity.Language.NodeRef.Contents heap root values) (head : Complexity.Language.CellValue kind) :
              head ∈ values → ValueFits w (kind.toValue head)

              Every represented list head already has its scalar range in the actual initial memory. Later callbacks retain these immutable stored heads.

              theorem Ram.LanguageCompiler.List.Fold.guard_measured {accTy : Complexity.Language.Ty} {kind : Complexity.Language.CellTy} {signatures : List Complexity.Language.Signature} (program : Complexity.Language.Program signatures) (accumulator : Complexity.Language.Value accTy) (root : Option (Complexity.Language.NodeRef kind)) (heap : Complexity.Language.Heap) {w heapLimit depth cursor : ℕ} (positive : 0 < w) :
              ∃ (execution : Complexity.Language.Exec program (Complexity.Language.List.Fold.guard accTy kind) (Complexity.Language.List.Fold.state accumulator root heap) (Complexity.Language.List.Fold.state accumulator root heap) (Complexity.Language.Control.returned root.isSome)) (ready : ArenaReady execution w heapLimit depth cursor cursor), ArenaExecutionCost ready (if root.isSome = true then 9 else 6)

              The actual guard tests only the optional root and preserves both locals and heap. Its two branches have their existing, distinct emitted counts.

              The source invocation receives the original represented accumulator and linked root. These are existing source arguments, not a host-side list loader.

              Equations
              Instances For
                def Ram.LanguageCompiler.List.Fold.invocationBound {α : Type u} {accTy : Complexity.Language.Ty} {kind : Complexity.Language.CellTy} {signatures : List Complexity.Language.Signature} (sourceProgram : Complexity.Language.Program signatures) (fn : Fin signatures.length) (same : signatures[fn] = Complexity.Language.List.Fold.stepSignature accTy kind) (step : α → Complexity.Language.CellValue kind → α) (bound : α → Complexity.Language.CellValue kind → ℕ) (mathematical : α) (values : List (Complexity.Language.CellValue kind)) :

                The complete invocation envelope includes the actual relocated callback frames, source-body initialization, outer invocation and final halt.

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