Documentation

Complexity.Language.Representation.List

Linked lists as mathematical source values #

The default list representation observes an optional typed node reference at the actual heap. Nil has no node; a cons node stores one head and the actual shared tail. Distinct roots and heap layouts may represent the same list, so this relation is deliberately not a pure encoding or an equivalence of types.

The operation rules reuse the existing heap operations and contents proofs. They do not introduce a second list implementation or an executable decoder. Representation.bufferList remains an explicit mathematical view of contiguous storage, separate from this linked representation.

Ordinary lists represented by real immutable nodes with shared tails.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    @[simp]
    theorem Complexity.Language.Representation.list_rel (kind : CellTy) (values : List (CellValue kind)) (root : Option (NodeRef kind)) (heap : Heap) :
    (list kind).Rel values root heap ↔ NodeRef.Contents heap root values
    theorem Complexity.Language.Representation.list_nil (kind : CellTy) (heap : Heap) :
    (list kind).Rel [] none heap

    The empty list needs no heap object.

    theorem Complexity.Language.Representation.list_rooted {kind : CellTy} {values : List (CellValue kind)} {root : Option (NodeRef kind)} {heap : Heap} (observed : (list kind).Rel values root heap) :
    ValueRooted heap root

    Every nonempty represented list has an existing root. This does not claim that every existing object identifier denotes a correctly typed list.

    theorem Complexity.Language.Representation.list_cons {kind : CellTy} {values : List (CellValue kind)} {tail : Option (NodeRef kind)} {heap : Heap} (head : CellValue kind) (observed : (list kind).Rel values tail heap) :
    (list kind).Rel (head :: values) (some (heap.cons head tail).1) (heap.cons head tail).2

    One actual allocation constructs the mathematical cons and shares its tail.

    theorem Complexity.Language.Representation.list_uncons {kind : CellTy} {values : List (CellValue kind)} {root : Option (NodeRef kind)} {heap : Heap} (observed : (list kind).Rel values root heap) :
    match values, observed with | [], observed => heap.uncons root = Except.ok none | head :: rest, observed => ∃ (tail : Option (NodeRef kind)), heap.uncons root = Except.ok (some (head, tail)) ∧ (list kind).Rel rest tail heap

    Actual uncons follows ordinary list cases and returns the identical shared tail, not a copied suffix or a mathematical value substituted for a runtime read.

    theorem Complexity.Language.Representation.list_mono {kind : CellTy} {values : List (CellValue kind)} {root : Option (NodeRef kind)} {initial finish : Heap} (observed : (list kind).Rel values root initial) (preserved : initial.ShapeExtends finish) :
    (list kind).Rel values root finish

    Preserving existing immutable nodes preserves every represented list, including shared tails, even when mutable buffers change.

    theorem Complexity.Language.Representation.list_take {kind : CellTy} {values : List (CellValue kind)} {root : Option (NodeRef kind)} {heap : Heap} {count : ℕ} (observed : (list kind).Rel values root heap) (backward : Heap.BackwardLinks Heap.nodeReferences heap) (retained : ∀ (ref : NodeRef kind), root = some ref → ref.object < count) :
    (list kind).Rel values root (heap.take count)

    Prefix reclamation keeps a represented list when its root survives and the actual node links point backwards. The whole tail chain is retained.