Documentation

Complexity.Computability.Ram.Compiler.Language.List.Prepare

Preparing a current linked input in retained RAM memory #

A preparation consists of actual compiled List.Cons invocations, starting from the current memory and extending its heap. The supplied current values are proof-side external input, not a source callback or an already represented root. Each node is really allocated and its invocation steps are counted.

The original order is retained by preparing the tail before the head. An existing represented suffix can be shared. Exact old object contents and their placements survive, including mutable arrays and aliases. The final world can be used by a later preloaded invocation without bootstrapping its memory.

The cost bounds the allocating invocations, not external list traversal, transport, scalar loading, or a continuous driver. In particular, keeping an old rooted value's word encoding does not save its registers across the helper calls. Those physical driver operations remain a separate boundary.

A sequence of real allocating invocations for the current input prefix. Each continuation uses the preceding outcome's complete memory and placement. The empty prefix allocates nothing and preserves the supplied tail.

Instances For
    theorem Ram.LanguageCompiler.List.Prepare.Run.source {kind : Complexity.Language.CellTy} {w heapLimit : ℕ} {values : List (Complexity.Language.CellValue kind)} {tail root : Option (Complexity.Language.NodeRef kind)} {current finish : Session.State w heapLimit} {steps : ℕ} (run : Run kind values tail current root finish steps) :
    Complexity.Language.List.Prepare.Run kind values tail current.heap root finish.heap

    Erase machine evidence to the same actual source constructor invocations.

    theorem Ram.LanguageCompiler.List.Prepare.Run.observed {kind : Complexity.Language.CellTy} {w heapLimit : ℕ} {values suffix : List (Complexity.Language.CellValue kind)} {tail root : Option (Complexity.Language.NodeRef kind)} {current finish : Session.State w heapLimit} {steps : ℕ} (run : Run kind values tail current root finish steps) (observed : (Complexity.Language.Representation.list kind).Rel suffix tail current.heap) :
    (Complexity.Language.Representation.list kind).Rel (values ++ suffix) root finish.heap ∧ current.heap.objects.toList <+: finish.heap.objects.toList ∧ current.heap.ShapeExtends finish.heap ∧ Placement.Agrees current.heap current.placement finish.placement

    The prepared root observes the original mathematical list, while every old object and placement is retained. This also frames overlapping old arrays.

    theorem Ram.LanguageCompiler.List.Prepare.Run.retained_words {kind : Complexity.Language.CellTy} {w heapLimit : ℕ} {values suffix : List (Complexity.Language.CellValue kind)} {tail root : Option (Complexity.Language.NodeRef kind)} {current finish : Session.State w heapLimit} {steps : ℕ} (run : Run kind values tail current root finish steps) (observed : (Complexity.Language.Representation.list kind).Rel suffix tail current.heap) {τ : Complexity.Language.Ty} (value : Complexity.Language.Value τ) (rooted : Complexity.Language.ValueRooted current.heap value) :

    Existing state words survive preparation without reconstruction from a mathematical model. This is placement stability, not a register-save program.

    theorem Ram.LanguageCompiler.List.Prepare.exists_le {w heapLimit : ℕ} (kind : Complexity.Language.CellTy) (values suffix : List (Complexity.Language.CellValue kind)) (tail : Option (Complexity.Language.NodeRef kind)) (current : Session.State w heapLimit) (capacity : FunctionCapacity (Complexity.Language.List.Cons.program kind) (Complexity.Language.List.Cons.entry kind) w 0 heapLimit) (fits : ∀ value ∈ values, ValueFits w (kind.toValue value)) (space : current.cursor + 3 * values.length ≤ heapLimit) (observed : (Complexity.Language.Representation.list kind).Rel suffix tail current.heap) :
    ∃ (root : Option (Complexity.Language.NodeRef kind)) (finish : Session.State w heapLimit) (steps : ℕ), Run kind values tail current root finish steps ∧ (Complexity.Language.Representation.list kind).Rel (values ++ suffix) root finish.heap ∧ finish.cursor = current.cursor + 3 * values.length ∧ steps ≤ values.length * Cons.steps kind

    Every current finite input has a genuine preparation when its scalar words fit and the actual arena has three words per new node. The bound is derived from the compiled constructor's existing invocation theorem.