Documentation

Examples.Language.TraversalCompositionCompiled

Compiling two effectful traversal calls #

The same source declaration calls the existing traversal twice. Its first callee's proved frame preserves the second input in the actual intermediate heap. Realization and cost reuse the existing callee contracts; neither proof reopens the array loop or supplies a register-level adapter.

The final runner theorem retains both mapped arrays, observations outside both borrowed views, and their common represented final heap. The views may be disjoint slices of one object. Word ranges, preloaded memory and space for the three active call frames remain explicit, independently of the instruction bound.

theorem Complexity.Language.Examples.Traversal.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) :

Two nested call levels account for the pair calling a traversal which calls its increment helper. The first traversal's frame supplies the second input; all actual increment ranges are inherited from the existing callee proofs.

The inferred complete pair budget is shared by direct and imported callers, without reproducing either callee's body or manually adding call overhead.

Equations
Instances For

    The source frame is reused only to justify the second callee's input at the actual intermediate heap. Existing traversal bounds count both effectful calls; no array-correctness or loop-cost argument is repeated.

    The inferred pair budget with its actual outer-call and final-halt charges.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem Complexity.Language.Examples.Traversal.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

      Both mapped arrays and the outside-both frame describe one typed actual RAM result. The launch retains the original three-frame capacity and argument ranges; the separate instruction bound includes both calls and the final halt.

      theorem Complexity.Language.Examples.Traversal.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 ≤ 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) (boundedMapPairBodyBound leftContents.size rightContents.size) + 1

      The actual compiled pair invocation returns both mapped arrays and the outside-both frame in one represented final heap. Its independent instruction bound includes both calls, while stack capacity allows pair/traversal/helper.