Documentation

Examples.Language.TraversalComposition

Sequential calls on disjoint borrowed buffers #

The source function calls the existing traversal twice on the same shared heap. Its native proof uses only the supplied function contracts: the first call's frame preserves the second input, and the second call's frame preserves the first result. Views disjoint from both buffers keep their initial contents. No traversal body or second implementation is unfolded here.

theorem Complexity.Language.Examples.Traversal.boundedMapPair_spec (xs ys : Buffer CellTy.nat) (limit : ℕ) (leftContents rightContents : Array ℕ) (initial : Heap) (separated : xs.Disjoint ys) :
⦃fun (heap : Heap) => ⌜heap = initial ∧ xs.Contents heap leftContents ∧ ys.Contents heap rightContents⌝⦄ Implementation.boundedMapPair xs ys limit ⦃Std.Do.PostCond.noThrow fun (x : Unit) (finish : Heap) => ⌜xs.Contents finish (Array.map (fun (x : CellValue CellTy.nat) => min (x + 1) limit) leftContents) ∧ ys.Contents finish (Array.map (fun (x : CellValue CellTy.nat) => min (x + 1) limit) rightContents) ∧ ∀ {kind : CellTy} (other : Buffer kind) (contents : Array (CellValue kind)), xs.Disjoint other → ys.Disjoint other → other.Contents initial contents → other.Contents finish contents⌝⦄

Two ordinary calls compose their array results and heap frames, including when the disjoint buffers are borrowed slices of one shared object.

theorem Complexity.Language.Examples.Traversal.boundedMapPair_eval (xs ys : Buffer CellTy.nat) (limit : ℕ) {leftContents rightContents : Array ℕ} {heap : Heap} (observedLeft : xs.Contents heap leftContents) (observedRight : ys.Contents heap rightContents) (separated : xs.Disjoint ys) :
∃ (finish : Heap), Implementation.boundedMapPair xs ys limit heap = Part.some (Except.ok (), finish) ∧ xs.Contents finish (Array.map (fun (x : CellValue CellTy.nat) => min (x + 1) limit) leftContents) ∧ ys.Contents finish (Array.map (fun (x : CellValue CellTy.nat) => min (x + 1) limit) rightContents) ∧ ∀ {kind : CellTy} (other : Buffer kind) (contents : Array (CellValue kind)), xs.Disjoint other → ys.Disjoint other → other.Contents heap contents → other.Contents finish contents

The same two calls terminate with both mapped arrays in their actual final heap, preserving every initial observation outside both borrowed views.

theorem Complexity.Language.Examples.Traversal.boundedMapPair_total (leftContents rightContents : Array ℕ) :
Implementation.boundedMapPair_contract (fun (xs ys : Buffer CellTy.nat) (x : ℕ) (heap : Heap) => xs.Contents heap leftContents ∧ ys.Contents heap rightContents ∧ xs.Disjoint ys) fun (xs ys : Buffer CellTy.nat) (limit : ℕ) (initial : Heap) (x : Unit) (finish : Heap) => xs.Contents finish (Array.map (fun (x : CellValue CellTy.nat) => min (x + 1) limit) leftContents) ∧ ys.Contents finish (Array.map (fun (x : CellValue CellTy.nat) => min (x + 1) limit) rightContents) ∧ ∀ {kind : CellTy} (other : Buffer kind) (contents : Array (CellValue kind)), xs.Disjoint other → ys.Disjoint other → other.Contents initial contents → other.Contents finish contents

The composed function exposes the same ordinary two-array result and outside-both frame through its generated named argument interface.