Documentation

Complexity.Language.Heap.Allocation

Fresh initialized source objects #

Heap.alloc appends one typed native array and returns its complete view. Old object contents are unchanged, including observations through overlapping views. The fresh object has a new identity even when its array is empty.

These are independent mathematical heap operations and preservation rules. They do not add a source statement, a RAM allocator, a capacity check, or an initialization-cost claim. Such a lowering must initialize the actual target cells and connect its counted execution to this same source operation.

def Complexity.Language.Heap.alloc (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :

Append one fresh initialized object and return its full view and updated heap.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    @[simp]
    theorem Complexity.Language.Heap.alloc_object (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :
    (heap.alloc length initial).1.object = heap.objects.size
    @[simp]
    theorem Complexity.Language.Heap.alloc_offset (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :
    (heap.alloc length initial).1.offset = 0
    @[simp]
    theorem Complexity.Language.Heap.alloc_length (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :
    (heap.alloc length initial).1.length = length
    @[simp]
    theorem Complexity.Language.Heap.alloc_objects (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :
    (heap.alloc length initial).2.objects = heap.objects.push (HeapObject.buffer τ (Array.replicate length initial))
    @[simp]
    theorem Complexity.Language.Heap.alloc_size (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :
    (heap.alloc length initial).2.objects.size = heap.objects.size + 1

    Allocation increases the object domain by one, independently of the cell count.

    theorem Complexity.Language.Heap.getElem?_alloc_of_ne (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) {object : ℕ} (different : object ≠ heap.objects.size) :
    (heap.alloc length initial).2.objects[object]? = heap.objects[object]?

    Every object slot other than the newly appended slot is unchanged.

    theorem Complexity.Language.Heap.object?_alloc_of_ne (heap : Heap) {τ σ : CellTy} (length : ℕ) (initial : CellValue τ) {object : ℕ} (different : object ≠ heap.objects.size) :
    (heap.alloc length initial).2.object? σ object = heap.object? σ object

    Typed lookup away from the fresh identifier retains its exact outcome.

    theorem Complexity.Language.Heap.object?_alloc_of_lt (heap : Heap) {τ σ : CellTy} (length : ℕ) (initial : CellValue τ) {object : ℕ} (bound : object < heap.objects.size) :
    (heap.alloc length initial).2.object? σ object = heap.object? σ object

    In particular, allocation preserves every old object's complete typed contents.

    theorem Complexity.Language.Heap.node?_alloc_of_ne (heap : Heap) {τ σ : CellTy} (length : ℕ) (initial : CellValue τ) {object : ℕ} (different : object ≠ heap.objects.size) :
    (heap.alloc length initial).2.node? σ object = heap.node? σ object

    Appending a scalar array preserves every different immutable-node lookup.

    theorem Complexity.Language.Heap.node?_alloc_of_lt (heap : Heap) {τ σ : CellTy} (length : ℕ) (initial : CellValue τ) {object : ℕ} (bound : object < heap.objects.size) :
    (heap.alloc length initial).2.node? σ object = heap.node? σ object

    Every old immutable node retains its exact payload and shared tail.

    theorem Complexity.Language.Heap.object?_alloc_new (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :
    (heap.alloc length initial).2.object? τ (heap.alloc length initial).1.object = some (Array.replicate length initial)

    The newly returned view denotes precisely the initialized native array.

    theorem Complexity.Language.Heap.shapeExtends_alloc (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :
    heap.ShapeExtends (heap.alloc length initial).2

    Allocation extends object shape while preserving the stronger old-content facts above.

    theorem Complexity.Language.Heap.alloc_contents (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :
    (heap.alloc length initial).1.Contents (heap.alloc length initial).2 (Array.replicate length initial)

    The returned whole-object view has the requested ordinary mathematical contents.

    theorem Complexity.Language.Heap.alloc_valid (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :
    (heap.alloc length initial).1.Valid (heap.alloc length initial).2

    Every newly allocated view is valid, including an empty one.

    theorem Complexity.Language.Heap.alloc_rooted (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :
    (heap.alloc length initial).1.Rooted (heap.alloc length initial).2

    A fresh view is rooted in the extended heap.

    theorem Complexity.Language.Heap.alloc_not_rooted (heap : Heap) {τ : CellTy} (length : ℕ) (initial : CellValue τ) :
    ¬(heap.alloc length initial).1.Rooted heap

    Its identifier was not present before allocation, even for length zero.

    theorem Complexity.Language.Heap.read_alloc (heap : Heap) {τ : CellTy} {length index : ℕ} (initial : CellValue τ) (bound : index < length) :
    (heap.alloc length initial).2.read (heap.alloc length initial).1 index = Except.ok initial

    Reading any valid index of the new object returns its initialized scalar.

    theorem Complexity.Language.Heap.read_alloc_of_rooted (heap : Heap) {τ σ : CellTy} (length : ℕ) (initial : CellValue τ) {buffer : Buffer σ} (rooted : buffer.Rooted heap) (index : ℕ) :
    (heap.alloc length initial).2.read buffer index = heap.read buffer index

    Old rooted handles retain every read outcome, not only successful valid accesses.

    theorem Complexity.Language.Buffer.Rooted.alloc {heap : Heap} {τ σ : CellTy} {buffer : Buffer σ} (rooted : buffer.Rooted heap) (length : ℕ) (initial : CellValue τ) :
    buffer.Rooted (heap.alloc length initial).2

    Allocation preserves an old handle's rootedness without a validity or alias premise.

    theorem Complexity.Language.Buffer.Valid.alloc {heap : Heap} {τ σ : CellTy} {buffer : Buffer σ} (valid : buffer.Valid heap) (length : ℕ) (initial : CellValue τ) :
    buffer.Valid (heap.alloc length initial).2

    Old valid views remain valid after a fresh allocation.

    theorem Complexity.Language.Buffer.Contents.alloc {heap : Heap} {τ σ : CellTy} {buffer : Buffer σ} {contents : Array (CellValue σ)} (observed : buffer.Contents heap contents) (length : ℕ) (initial : CellValue τ) :
    buffer.Contents (heap.alloc length initial).2 contents

    Every old view keeps its exact current contents; old views may overlap each other.

    theorem Complexity.Language.Buffer.Rooted.disjoint_alloc {heap : Heap} {τ σ : CellTy} {buffer : Buffer σ} (rooted : buffer.Rooted heap) (length : ℕ) (initial : CellValue τ) :
    (heap.alloc length initial).1.Disjoint buffer

    Fresh identity separates the new view from every old rooted handle.