Documentation

Examples.Language.Splay.Rotation

Actual field updates of the splay rotations #

These contracts describe the two real heap writes performed by a rotation. Ordinary array contents establish successful reads and writes; the resulting Array.set equations expose the precise field changes to a mathematical tree representation. The write witnesses also retain frames for unrelated objects, disjoint views of the same object and untouched cells of either child array.

The left/right buffers need disjoint storage, not distinct object identifiers. No assumption about a particular heap encoding, word width or time budget is needed for these source-correctness statements.

theorem Complexity.Language.Examples.Splay.rotateRight_eval_of_accesses (left right : Buffer CellTy.nat) (root child middle : ℕ) {initial between finish : Heap} (readChild : initial.read left root = Except.ok child) (readMiddle : initial.read right child = Except.ok middle) (writeLeft : initial.write left root middle = Except.ok between) (writeRight : between.write right child root = Except.ok finish) :
Implementation.rotateRight left right root initial = Part.some (Except.ok child, finish)

The declared right rotation performs the supplied current-heap accesses. The witnesses describe real writes in order, not a replacement array evaluator.

Swapping the two field arrays exchanges the source behaviors of the two rotations. This equation is not used to assign either implementation's cost.

theorem Complexity.Language.Examples.Splay.rotateLeft_eval_of_accesses (left right : Buffer CellTy.nat) (root child middle : ℕ) {initial between finish : Heap} (readChild : initial.read right root = Except.ok child) (readMiddle : initial.read left child = Except.ok middle) (writeRight : initial.write right root middle = Except.ok between) (writeLeft : between.write left child root = Except.ok finish) :
Implementation.rotateLeft left right root initial = Part.some (Except.ok child, finish)

The symmetric rotation retains the actual intermediate shared heap.

theorem Complexity.Language.Examples.Splay.rotateRight_eval (left right : Buffer CellTy.nat) (root child : ℕ) {initial : Heap} {leftValues rightValues : Array ℕ} (observedLeft : left.Contents initial leftValues) (observedRight : right.Contents initial rightValues) (separated : left.Disjoint right) (rootBound : root < leftValues.size) (childBound : child < rightValues.size) (childValue : leftValues[root] = child) :
∃ (between : Heap) (finish : Heap), Implementation.rotateRight left right root initial = Part.some (Except.ok child, finish) ∧ initial.write left root rightValues[child] = Except.ok between ∧ between.write right child root = Except.ok finish ∧ left.Contents finish (leftValues.set root rightValues[child] rootBound) ∧ right.Contents finish (rightValues.set child root childBound)

Valid ordinary array contents suffice for a right rotation. Its complete postcondition retains both precise array updates and the two heap-write facts, so later tree, alias and frame proofs do not have to reopen the implementation.

theorem Complexity.Language.Examples.Splay.rotateLeft_eval (left right : Buffer CellTy.nat) (root child : ℕ) {initial : Heap} {leftValues rightValues : Array ℕ} (observedLeft : left.Contents initial leftValues) (observedRight : right.Contents initial rightValues) (separated : left.Disjoint right) (rootBound : root < rightValues.size) (childBound : child < leftValues.size) (childValue : rightValues[root] = child) :
∃ (between : Heap) (finish : Heap), Implementation.rotateLeft left right root initial = Part.some (Except.ok child, finish) ∧ initial.write right root leftValues[child] = Except.ok between ∧ between.write left child root = Except.ok finish ∧ left.Contents finish (leftValues.set child root childBound) ∧ right.Contents finish (rightValues.set root leftValues[child] rootBound)

Valid ordinary array contents give the symmetric left-rotation contract, including both real writes and the current contents of both field arrays.

theorem Complexity.Language.Examples.Splay.contents_of_rotation_writes {first second : Buffer CellTy.nat} {firstIndex firstValue secondIndex secondValue : ℕ} {initial between finish : Heap} (writeFirst : initial.write first firstIndex firstValue = Except.ok between) (writeSecond : between.write second secondIndex secondValue = Except.ok finish) {kind : CellTy} {other : Buffer kind} {contents : Array (CellValue kind)} (observed : other.Contents initial contents) (outsideFirst : first.Disjoint other) (outsideSecond : second.Disjoint other) :
other.Contents finish contents

Two rotation writes preserve every unrelated borrowed view, including a keys array or disjoint slices of either underlying object. The two write facts are obtained directly from either rotation's operational contract.