Documentation

Examples.Language.ImportsTraversalCompiled

Compiling effectful calls into an imported traversal library #

The existing import client calls the library traversal twice. Each selected library contract is transported through the generated source embedding. The first call's actual frame establishes the second call's input; neither loop, array-correctness argument nor register-level lowering is proved again.

The client has the same emitted call structure as the original two-buffer composition. Its bound reuses that existing numerical expression and the proved preservation of callee overhead under embedding. The final theorem concerns the client's actual invocation in the combined program, with two mapped buffers, the outside-both frame and one represented final heap. Code and three-frame stack capacity refer to this combined program, not the smaller library table.

theorem Complexity.Language.Examples.Imports.boundedMapPair_total (leftContents rightContents : Array ℕ) :
FunctionTotal Implementation.program Implementation.boundedMapPairId (fun (args : Env Implementation.signatures[Implementation.boundedMapPairId].params) (heap : Heap) => Buffer.Contents args.head heap leftContents ∧ Buffer.Contents args.tail.head heap rightContents ∧ Buffer.Disjoint args.head args.tail.head) fun (args : Env Implementation.signatures[Implementation.boundedMapPairId].params) (initial : Heap) (x : Value Implementation.signatures[Implementation.boundedMapPairId].result) (finish : Heap) => Buffer.Contents args.head finish (Array.map (fun (x : CellValue CellTy.nat) => min (x + 1) args.tail.tail.head) leftContents) ∧ Buffer.Contents args.tail.head finish (Array.map (fun (x : CellValue CellTy.nat) => min (x + 1) args.tail.tail.head) rightContents) ∧ ∀ {kind : CellTy} (other : Buffer kind) (contents : Array (CellValue kind)), Buffer.Disjoint args.head other → Buffer.Disjoint args.tail.head other → other.Contents initial contents → other.Contents finish contents

The existing source correctness proof supplies both array results and the outside-both frame, without reopening either imported traversal.

theorem Complexity.Language.Examples.Imports.boundedMapPair_realizable {w : ℕ} (hw : 0 < w) (leftContents rightContents : Array ℕ) (leftIncrementsFit : ∀ (j : ℕ) (hj : j < leftContents.size), leftContents[j] + 1 < 2 ^ w) (rightIncrementsFit : ∀ (j : ℕ) (hj : j < rightContents.size), rightContents[j] + 1 < 2 ^ w) :

The client, imported traversal and increment helper need two nested call levels. The original value ranges and actual intermediate-heap frame are retained.

The imported callees retain their actual instruction bounds and frame overhead. The client's unchanged call structure therefore admits the original pair bound, while the first call's frame supplies the second call's current input.

The imported client's invocation budget includes its own outer call and final halt, reusing the library pair's inferred body budget.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem Complexity.Language.Examples.Imports.boundedMapPair_execute {w heapLimit : ℕ} {placement : ℕ → Ram.Word w} (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) (leftIncrementsFit : ∀ (j : ℕ) (hj : j < leftContents.size), leftContents[j] + 1 < 2 ^ w) (rightIncrementsFit : ∀ (j : ℕ) (hj : j < rightContents.size), rightContents[j] + 1 < 2 ^ w) {entry : Ram.Source.State w} (launch : Ram.LanguageCompiler.FunctionLaunch Implementation.program Implementation.boundedMapPairId 2 heapLimit placement (Implementation.boundedMapPair_args xs ys limit) heap entry) :
    ∃ (outcome : Ram.LanguageCompiler.FunctionExecution Implementation.program Implementation.boundedMapPairId heapLimit placement (Implementation.boundedMapPair_args xs ys limit) heap entry), xs.Contents outcome.heap (Array.map (fun (x : CellValue CellTy.nat) => min (x + 1) limit) leftContents) ∧ ys.Contents outcome.heap (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 outcome.heap contents) ∧ outcome.result.steps ≤ boundedMapPairInvocationBound leftContents.size rightContents.size

    The imported client returns both ordinary mapped arrays in one typed actual execution, preserving observations outside both borrowed views. The launch keeps the combined program's original code/stack capacities and argument ranges.

    theorem Complexity.Language.Examples.Imports.boundedMapPair_runUntil_le {w heapLimit : ℕ} (hw : 0 < w) (placement : ℕ → Ram.Word w) (xs ys : Buffer CellTy.nat) (limit : ℕ) (sourceHeap : Heap) (leftContents rightContents : Array ℕ) (observedLeft : xs.Contents sourceHeap leftContents) (observedRight : ys.Contents sourceHeap rightContents) (separated : xs.Disjoint ys) (leftLengthFits : xs.length < 2 ^ w) (rightLengthFits : ys.length < 2 ^ w) (limitFits : limit < 2 ^ w) (leftIncrementsFit : ∀ (j : ℕ) (hj : j < leftContents.size), leftContents[j] + 1 < 2 ^ w) (rightIncrementsFit : ∀ (j : ℕ) (hj : j < rightContents.size), rightContents[j] + 1 < 2 ^ w) (entry : Ram.Source.State w) (represented : Ram.LanguageCompiler.HeapRep placement heapLimit sourceHeap entry) (codeCapacity : List.length (Ram.LanguageCompiler.lowerCode Implementation.program Implementation.boundedMapPairId) < 2 ^ w) (stackCapacity : heapLimit + 3 * Ram.ABI.frameSize (Ram.LanguageCompiler.programControl Implementation.program) < 2 ^ w) :
    ∃ (finalHeap : Heap) (targetFinish : Ram.Source.State w) (bodySteps : ℕ) (target : Ram.State w), Implementation.boundedMapPair xs ys limit sourceHeap = Part.some (Except.ok (), finalHeap) ∧ xs.Contents finalHeap (Array.map (fun (x : CellValue CellTy.nat) => min (x + 1) limit) leftContents) ∧ ys.Contents finalHeap (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 sourceHeap contents → other.Contents finalHeap contents) ∧ Ram.Source.FunctionExec (Ram.LanguageCompiler.lowerProgram Implementation.program) heapLimit 2 (Ram.LanguageCompiler.lowerFunc Implementation.program Implementation.boundedMapPairId) (Ram.LanguageCompiler.envWords placement (Env.cons xs (Env.cons ys (Env.cons limit Env.empty)))) entry [] targetFinish ∧ Ram.LanguageCompiler.HeapRep placement heapLimit finalHeap targetFinish ∧ Ram.LocalCompiler.Function.runUntil (Ram.LanguageCompiler.programControl Implementation.program) (Ram.LanguageCompiler.lowerProgram Implementation.program) (↑Implementation.boundedMapPairId) 5 heapLimit (Ram.LanguageCompiler.envWords placement (Env.cons xs (Env.cons ys (Env.cons limit Env.empty)))) entry = some { state := target, steps := Ram.LocalCompiler.Function.callSteps (Ram.LanguageCompiler.programControl Implementation.program) (Ram.LanguageCompiler.lowerFunc Implementation.program Implementation.boundedMapPairId) bodySteps + 1, reason := Ram.StopReason.halted } ∧ Ram.LocalCompiler.Function.returnedValues 0 target = [] ∧ Ram.Source.State.Observes heapLimit 0 targetFinish target ∧ (Ram.LanguageCompiler.lowerFunc Implementation.program Implementation.boundedMapPairId).bodyTime (Ram.LanguageCompiler.lowerProgram Implementation.program) heapLimit (Ram.LanguageCompiler.envWords placement (Env.cons xs (Env.cons ys (Env.cons limit Env.empty)))) entry = Part.some bodySteps ∧ bodySteps ≤ Traversal.boundedMapPairBodyBound leftContents.size rightContents.size ∧ Ram.LocalCompiler.Function.callSteps (Ram.LanguageCompiler.programControl Implementation.program) (Ram.LanguageCompiler.lowerFunc Implementation.program Implementation.boundedMapPairId) bodySteps + 1 ≤ Ram.LocalCompiler.Function.callSteps (Ram.LanguageCompiler.programControl Implementation.program) (Ram.LanguageCompiler.lowerFunc Implementation.program Implementation.boundedMapPairId) (Traversal.boundedMapPairBodyBound leftContents.size rightContents.size) + 1

    The actual imported-traversal client halts with both mapped arrays and the outside-both frame in one represented final heap. The independent instruction bound covers both calls; capacity allows the client, traversal and helper frames.