Documentation

Examples.Language.Scalar

A mathematical proof of an independent source program #

The program calls an increment function, compares its actual returned natural number with a supplied limit, and assigns the smaller value to a local before returning it. Both function bodies are typed source syntax. Their mathematical proof uses the generated native functions and ordinary natural-number facts. Shared evaluation adequacy supplies the source contracts used by the compiler, without another implementation proof.

This file establishes source behavior only. Realizing these unbounded natural operations on a word backend requires its separate range, compilation and cost theorems.

The named function's actual partial source action, with ordinary typed arguments and an explicitly supplied shared heap.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    Ordinary mathematical function generated from the same represented source block.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[reducible, inline]

      The source program's declared first-order signatures.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem Complexity.Language.Examples.Scalar.Implementation.boundedIncrement_action_rel_native (n limit : ℕ) (initialHeap✝ : Heap) :
        ∃ (returned : Value Ty.nat) (finish : Heap), boundedIncrement n limit initialHeap✝ = Part.some (Except.ok returned, finish) ∧ (Representation.ofEmbedding (Function.Embedding.refl ℕ)).Rel (boundedIncrement_model n limit) returned finish ∧ (fun (finish : Heap) => initialHeap✝.ShapeExtends finish) finish

        Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

        @[reducible, inline]

        Apply a predicate, postcondition or bound with ordinary source parameters to the actual argument environment. No new contract or execution is introduced.

        Equations
        Instances For
          theorem Complexity.Language.Examples.Scalar.Implementation.boundedIncrement_total_iff (pre✝ : ℕ → ℕ → Heap → Prop) (post✝ : ℕ → ℕ → Heap → ℕ → Heap → Prop) :
          boundedIncrement_contract pre✝ post✝ ↔ ∀ (n limit : ℕ) (initialHeap : Heap), pre✝ n limit initialHeap → ∃ (value : ℕ) (finalHeap : Heap), boundedIncrement n limit initialHeap = Part.some (Except.ok value, finalHeap) ∧ post✝ n limit initialHeap value finalHeap

          The source contract is equivalent to ordinary curried preconditions and successful result/heap postconditions, including termination and absence of faults.

          theorem Complexity.Language.Examples.Scalar.Implementation.increment_action_rel_native (n : ℕ) (initialHeap✝ : Heap) :
          ∃ (returned : Value Ty.nat) (finish : Heap), increment n initialHeap✝ = Part.some (Except.ok returned, finish) ∧ (Representation.ofEmbedding (Function.Embedding.refl ℕ)).Rel (increment_model n) returned finish ∧ (fun (finish : Heap) => initialHeap✝.ShapeExtends finish) finish

          Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

          The named function's actual partial source action, with ordinary typed arguments and an explicitly supplied shared heap.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            The same source execution returns the encoded mathematical result without changing its supplied heap, under the actual input representations.

            The named function's actual independently interpreted source body.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              @[reducible, inline]

              The actual declared argument environment, constructed from ordinary source parameters. This is proof-side parameter transport, not an additional runtime operation.

              Equations
              Instances For
                theorem Complexity.Language.Examples.Scalar.Implementation.increment_action_rel_native_preserving (n : ℕ) (initialHeap✝ : Heap) :
                ∃ (returned : Value Ty.nat) (finish : Heap), increment n initialHeap✝ = Part.some (Except.ok returned, finish) ∧ (Representation.ofEmbedding (Function.Embedding.refl ℕ)).Rel (increment_model n) returned finish ∧ (fun (finish : Heap) => initialHeap✝.ShapeExtends finish ∧ Buffer.PreservesContents initialHeap✝ finish) finish

                Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

                theorem Complexity.Language.Examples.Scalar.Implementation.increment_contract_iff_triple (pre✝ : ℕ → Heap → Prop) (post✝ : ℕ → Heap → ℕ → Heap → Prop) :
                increment_contract pre✝ post✝ ↔ ∀ (n : ℕ) (initialHeap : Heap), ⦃fun (currentHeap : Heap) => { down := currentHeap = initialHeap ∧ pre✝ n initialHeap }⦄ increment n ⦃(fun (value : ℕ) (finalHeap : Heap) => { down := post✝ n initialHeap value finalHeap }, fun (x : Fault) (x_1 : Heap) => { down := False }, PUnit.unit)⦄

                Prove the ordinary-parameter source contract with a total-correctness triple for the same action. The ghost initial heap equals the actual entry heap; successful results use the actual final heap, and faults are excluded.

                theorem Complexity.Language.Examples.Scalar.Implementation.boundedIncrement_eq (n limit : ℕ) :
                boundedIncrement n limit = have result := limit; do let next ← increment n have condition : Bool := decide (next ≤ limit) have __do_jp : ℕ → Unit → ExceptT Fault (StateT Heap Part) ℕ := fun (result : ℕ) (y : Unit) => pure result if condition = true then have result := next; do let y ← pure () __do_jp result y else do let y ← pure () __do_jp result y

                One source-body equation in ordinary monadic notation; named callees remain opaque.

                Automatic correspondence for the same generated source function, without a machine budget.

                theorem Complexity.Language.Examples.Scalar.Implementation.boundedIncrement_spec {pre✝ : Env [Ty.nat, Ty.nat] → Heap → Prop} {post✝ : Env [Ty.nat, Ty.nat] → Heap → ℕ → Heap → Prop} :
                FunctionTotal program boundedIncrementId pre✝ post✝ → ∀ (n limit : ℕ) (continuation : Std.Do.PostCond ℕ (Std.Do.PostShape.except Fault (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure))), ⦃fun (initialHeap : Heap) => { down := pre✝ (Env.cons n (Env.cons limit Env.empty)) initialHeap ∧ ∀ (value : ℕ) (finalHeap : Heap), post✝ (Env.cons n (Env.cons limit Env.empty)) initialHeap value finalHeap → (continuation.1 value finalHeap).down }⦄ boundedIncrement n limit ⦃continuation⦄

                Apply a supplied source contract with ordinary named arguments and its actual returned value and final heap. No callee body or new contract is inferred.

                theorem Complexity.Language.Examples.Scalar.Implementation.boundedIncrement_contract_iff_triple (pre✝ : ℕ → ℕ → Heap → Prop) (post✝ : ℕ → ℕ → Heap → ℕ → Heap → Prop) :
                boundedIncrement_contract pre✝ post✝ ↔ ∀ (n limit : ℕ) (initialHeap : Heap), ⦃fun (currentHeap : Heap) => { down := currentHeap = initialHeap ∧ pre✝ n limit initialHeap }⦄ boundedIncrement n limit ⦃(fun (value : ℕ) (finalHeap : Heap) => { down := post✝ n limit initialHeap value finalHeap }, fun (x : Fault) (x_1 : Heap) => { down := False }, PUnit.unit)⦄

                Prove the ordinary-parameter source contract with a total-correctness triple for the same action. The ghost initial heap equals the actual entry heap; successful results use the actual final heap, and faults are excluded.

                Ordinary arguments and the actual result observed in their real source heaps. This interface does not assert the existence of a total mathematical model.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  One source-body equation in ordinary monadic notation; named callees remain opaque.

                  @[reducible, inline]

                  Budget-free total correctness with ordinary source parameters and relational initial/final heap postconditions. This is the existing source function contract.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Automatic correspondence for the same generated source function, without a machine budget.

                    Fold an actual source invocation back to its named ordinary-argument observation.

                    theorem Complexity.Language.Examples.Scalar.Implementation.increment_total :
                    increment_contract (fun (n_source : Value Ty.nat) (initialHeap : Heap) => True) fun (n_source : Value Ty.nat) (initialHeap : Heap) (returned : Value Ty.nat) (finalHeap : Heap) => returned = increment_model ((fun (value : ℕ) => value) n_source) ∧ finalHeap = initialHeap

                    Exact total source contract derived from the checked encoded-result equation and the existing raw-input reconstruction, with the same final heap.

                    theorem Complexity.Language.Examples.Scalar.Implementation.boundedIncrement_action_rel_native_preserving (n limit : ℕ) (initialHeap✝ : Heap) :
                    ∃ (returned : Value Ty.nat) (finish : Heap), boundedIncrement n limit initialHeap✝ = Part.some (Except.ok returned, finish) ∧ (Representation.ofEmbedding (Function.Embedding.refl ℕ)).Rel (boundedIncrement_model n limit) returned finish ∧ (fun (finish : Heap) => initialHeap✝.ShapeExtends finish ∧ Buffer.PreservesContents initialHeap✝ finish) finish

                    Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

                    Ordinary arguments and the actual result observed in their real source heaps. This interface does not assert the existence of a total mathematical model.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      theorem Complexity.Language.Examples.Scalar.Implementation.boundedIncrement_total :
                      boundedIncrement_contract (fun (n_source limit_source : Value Ty.nat) (initialHeap : Heap) => True) fun (n_source limit_source : Value Ty.nat) (initialHeap : Heap) (returned : Value Ty.nat) (finalHeap : Heap) => returned = boundedIncrement_model ((fun (value : ℕ) => value) n_source) ((fun (value : ℕ) => value) limit_source) ∧ finalHeap = initialHeap

                      Exact total source contract derived from the checked encoded-result equation and the existing raw-input reconstruction, with the same final heap.

                      Fold an actual source invocation back to its named ordinary-argument observation.

                      @[reducible, inline]

                      Budget-free total correctness with ordinary source parameters and relational initial/final heap postconditions. This is the existing source function contract.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        The finite table of actual named source bodies.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem Complexity.Language.Examples.Scalar.Implementation.increment_total_iff (pre✝ : ℕ → Heap → Prop) (post✝ : ℕ → Heap → ℕ → Heap → Prop) :
                          increment_contract pre✝ post✝ ↔ ∀ (n : ℕ) (initialHeap : Heap), pre✝ n initialHeap → ∃ (value : ℕ) (finalHeap : Heap), increment n initialHeap = Part.some (Except.ok value, finalHeap) ∧ post✝ n initialHeap value finalHeap

                          The source contract is equivalent to ordinary curried preconditions and successful result/heap postconditions, including termination and absence of faults.

                          @[reducible, inline]

                          Apply a predicate, postcondition or bound with ordinary source parameters to the actual argument environment. No new contract or execution is introduced.

                          Equations
                          Instances For
                            @[reducible, inline]

                            The actual declared argument environment, constructed from ordinary source parameters. This is proof-side parameter transport, not an additional runtime operation.

                            Equations
                            Instances For
                              theorem Complexity.Language.Examples.Scalar.Implementation.increment_spec {pre✝ : Env [Ty.nat] → Heap → Prop} {post✝ : Env [Ty.nat] → Heap → ℕ → Heap → Prop} :
                              FunctionTotal program incrementId pre✝ post✝ → ∀ (n : ℕ) (continuation : Std.Do.PostCond ℕ (Std.Do.PostShape.except Fault (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure))), ⦃fun (initialHeap : Heap) => { down := pre✝ (Env.cons n Env.empty) initialHeap ∧ ∀ (value : ℕ) (finalHeap : Heap), post✝ (Env.cons n Env.empty) initialHeap value finalHeap → (continuation.1 value finalHeap).down }⦄ increment n ⦃continuation⦄

                              Apply a supplied source contract with ordinary named arguments and its actual returned value and final heap. No callee body or new contract is inferred.

                              Ordinary mathematical function generated from the same represented source block.

                              Equations
                              Instances For

                                The same source execution returns the encoded mathematical result without changing its supplied heap, under the actual input representations.

                                The named function's actual independently interpreted source body.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For

                                  Call the real helper, update a local in the selected branch, and observe that update after the branch. The original limit parameter is unchanged.

                                  Equations
                                  Instances For

                                    The actual named helper has the ordinary mathematical increment value.

                                    The named source function has an ordinary curried mathematical result, obtained from the same source correctness proof.

                                    theorem Complexity.Language.Examples.Scalar.increment_total :
                                    Implementation.increment_contract (fun (x : ℕ) (x_1 : Heap) => True) fun (n : ℕ) (heap : Heap) (value : ℕ) (finish : Heap) => value = n + 1 ∧ finish = heap

                                    Ordinary addition specifies the actual source helper.

                                    theorem Complexity.Language.Examples.Scalar.boundedIncrement_total :
                                    Implementation.boundedIncrement_contract (fun (x x_1 : ℕ) (x_2 : Heap) => True) fun (n limit : ℕ) (heap : Heap) (value : ℕ) (finish : Heap) => value = min (n + 1) limit ∧ finish = heap

                                    The caller's source proof composes the helper contract and the actual branch.

                                    theorem Complexity.Language.Examples.Scalar.boundedIncrement_returns (n limit : ℕ) (heap : Heap) :
                                    ∃ (finish : State signatures[1].params), Exec program (program.body 1) { locals := Env.cons n (Env.cons limit Env.empty), heap := heap } finish (Control.returned (min (n + 1) limit)) ∧ finish.heap = heap

                                    A successful invocation exists for every pair of natural inputs, and its actual returned value is the ordinary mathematical minimum.

                                    theorem Complexity.Language.Examples.Scalar.boundedIncrement_result (n limit value : ℕ) (heap : Heap) {finish : State [Ty.nat, Ty.nat]} (execution : Exec program (program.body 1) { locals := Env.cons n (Env.cons limit Env.empty), heap := heap } finish (Control.returned value)) :
                                    value = min (n + 1) limit

                                    Every actual return from the caller has the proved mathematical value.

                                    Ordinary mathematical inputs to the existing bounded increment operation.

                                    Instances For

                                      Ordinary mathematical function generated from the same represented source block.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For
                                        theorem Complexity.Language.Examples.Scalar.Structured.update_spec {pre✝ : Env [Ty.nat.prod Ty.nat] → Heap → Prop} {post✝ : Env [Ty.nat.prod Ty.nat] → Heap → ℕ × ℕ → Heap → Prop} :
                                        FunctionTotal program updateId pre✝ post✝ → ∀ (input : ℕ × ℕ) (continuation : Std.Do.PostCond (ℕ × ℕ) (Std.Do.PostShape.except Fault (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure))), ⦃fun (initialHeap : Heap) => { down := pre✝ (Env.cons input Env.empty) initialHeap ∧ ∀ (value : ℕ × ℕ) (finalHeap : Heap), post✝ (Env.cons input Env.empty) initialHeap value finalHeap → (continuation.1 value finalHeap).down }⦄ update input ⦃continuation⦄

                                        Apply a supplied source contract with ordinary named arguments and its actual returned value and final heap. No callee body or new contract is inferred.

                                        @[reducible, inline]

                                        Budget-free total correctness with ordinary source parameters and relational initial/final heap postconditions. This is the existing source function contract.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          theorem Complexity.Language.Examples.Scalar.Structured.update_total_iff (pre✝ : ℕ × ℕ → Heap → Prop) (post✝ : ℕ × ℕ → Heap → ℕ × ℕ → Heap → Prop) :
                                          update_contract pre✝ post✝ ↔ ∀ (input : ℕ × ℕ) (initialHeap : Heap), pre✝ input initialHeap → ∃ (value : ℕ × ℕ) (finalHeap : Heap), update input initialHeap = Part.some (Except.ok value, finalHeap) ∧ post✝ input initialHeap value finalHeap

                                          The source contract is equivalent to ordinary curried preconditions and successful result/heap postconditions, including termination and absence of faults.

                                          The named function's actual partial source action, with ordinary typed arguments and an explicitly supplied shared heap.

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For
                                            theorem Complexity.Language.Examples.Scalar.Structured.update_total :
                                            update_contract (fun (input_source : Value (Ty.nat.prod Ty.nat)) (initialHeap : Heap) => True) fun (input_source : Value (Ty.nat.prod Ty.nat)) (initialHeap : Heap) (returned : Value (Ty.nat.prod Ty.nat)) (finalHeap : Heap) => returned = (BoundedInput.programEmbedding.trans ((Function.Embedding.refl ℕ).prodMap (Function.Embedding.refl ℕ))) (update_model ((fun (raw : Value (Ty.nat.prod Ty.nat)) => { value := raw.1, limit := raw.2 }) input_source)) ∧ finalHeap = initialHeap

                                            Exact total source contract derived from the checked encoded-result equation and the existing raw-input reconstruction, with the same final heap.

                                            @[reducible, inline]

                                            The actual declared argument environment, constructed from ordinary source parameters. This is proof-side parameter transport, not an additional runtime operation.

                                            Equations
                                            Instances For
                                              theorem Complexity.Language.Examples.Scalar.Structured.run_spec {pre✝ : Env [Ty.nat, Ty.nat] → Heap → Prop} {post✝ : Env [Ty.nat, Ty.nat] → Heap → ℕ → Heap → Prop} :
                                              FunctionTotal program runId pre✝ post✝ → ∀ (n limit : ℕ) (continuation : Std.Do.PostCond ℕ (Std.Do.PostShape.except Fault (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure))), ⦃fun (initialHeap : Heap) => { down := pre✝ (Env.cons n (Env.cons limit Env.empty)) initialHeap ∧ ∀ (value : ℕ) (finalHeap : Heap), post✝ (Env.cons n (Env.cons limit Env.empty)) initialHeap value finalHeap → (continuation.1 value finalHeap).down }⦄ run n limit ⦃continuation⦄

                                              Apply a supplied source contract with ordinary named arguments and its actual returned value and final heap. No callee body or new contract is inferred.

                                              @[reducible, inline]

                                              The actual declared argument environment, constructed from ordinary source parameters. This is proof-side parameter transport, not an additional runtime operation.

                                              Equations
                                              Instances For
                                                @[reducible, inline]

                                                Apply a predicate, postcondition or bound with ordinary source parameters to the actual argument environment. No new contract or execution is introduced.

                                                Equations
                                                Instances For

                                                  The finite table of actual named source bodies.

                                                  Equations
                                                  • One or more equations did not get rendered due to their size.
                                                  Instances For
                                                    @[reducible, inline]

                                                    Signature-preserving positions of this imported source program.

                                                    Equations
                                                    • One or more equations did not get rendered due to their size.
                                                    Instances For
                                                      theorem Complexity.Language.Examples.Scalar.Structured.run_contract_iff_triple (pre✝ : ℕ → ℕ → Heap → Prop) (post✝ : ℕ → ℕ → Heap → ℕ → Heap → Prop) :
                                                      run_contract pre✝ post✝ ↔ ∀ (n limit : ℕ) (initialHeap : Heap), ⦃fun (currentHeap : Heap) => { down := currentHeap = initialHeap ∧ pre✝ n limit initialHeap }⦄ run n limit ⦃(fun (value : ℕ) (finalHeap : Heap) => { down := post✝ n limit initialHeap value finalHeap }, fun (x : Fault) (x_1 : Heap) => { down := False }, PUnit.unit)⦄

                                                      Prove the ordinary-parameter source contract with a total-correctness triple for the same action. The ghost initial heap equals the actual entry heap; successful results use the actual final heap, and faults are excluded.

                                                      theorem Complexity.Language.Examples.Scalar.Structured.run_action_rel_native (n limit : ℕ) (initialHeap✝ : Heap) :
                                                      ∃ (returned : Value Ty.nat) (finish : Heap), run n limit initialHeap✝ = Part.some (Except.ok returned, finish) ∧ (Representation.ofEmbedding (Function.Embedding.refl ℕ)).Rel (run_model n limit) returned finish ∧ (fun (finish : Heap) => initialHeap✝.ShapeExtends finish) finish

                                                      Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

                                                      @[reducible, inline]

                                                      Signatures of the functions added by this source declaration.

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For

                                                        Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

                                                        Automatic correspondence for the same generated source function, without a machine budget.

                                                        theorem Complexity.Language.Examples.Scalar.Structured.run_observe (arguments✝ : Env [Ty.nat, Ty.nat]) :
                                                        program.eval runId arguments✝ = run arguments✝.head arguments✝.tail.head

                                                        Fold an actual source invocation back to its named ordinary-argument observation.

                                                        theorem Complexity.Language.Examples.Scalar.Structured.run_action_eq_native (n limit : ℕ) (initialHeap✝ : Heap) :
                                                        run n limit initialHeap✝ = Part.some (Except.ok (run_model n limit), initialHeap✝)

                                                        The same source execution returns the encoded mathematical result without changing its supplied heap, under the actual input representations.

                                                        Added function bodies already typed against the complete linked table.

                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For

                                                          Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

                                                          theorem Complexity.Language.Examples.Scalar.Structured.run_eq (n limit : ℕ) :
                                                          run n limit = have result_join := none; have input := (n, limit); do let updated ← update input have result_join : Option ℕ := some updated.1 have __do_jp : Unit → ExceptT Fault (StateT Heap Part) ℕ := fun (y : Unit) => throw Fault.missingReturn match result_join with | none => do let y ← pure () __do_jp y | some payload => pure payload

                                                          One source-body equation in ordinary monadic notation; named callees remain opaque.

                                                          Ordinary arguments and the actual result observed in their real source heaps. This interface does not assert the existence of a total mathematical model.

                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For

                                                            Ordinary arguments and the actual result observed in their real source heaps. This interface does not assert the existence of a total mathematical model.

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For

                                                              The named function's actual independently interpreted source body.

                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For
                                                                theorem Complexity.Language.Examples.Scalar.Structured.update_eq (input : ℕ × ℕ) :
                                                                update input = have operand := input.1; have operand_1 := input.2; do let value ← Implementation.boundedIncrement operand operand_1 have operand : ℕ := input.2 pure (value, operand)

                                                                One source-body equation in ordinary monadic notation; named callees remain opaque.

                                                                theorem Complexity.Language.Examples.Scalar.Structured.run_total_iff (pre✝ : ℕ → ℕ → Heap → Prop) (post✝ : ℕ → ℕ → Heap → ℕ → Heap → Prop) :
                                                                run_contract pre✝ post✝ ↔ ∀ (n limit : ℕ) (initialHeap : Heap), pre✝ n limit initialHeap → ∃ (value : ℕ) (finalHeap : Heap), run n limit initialHeap = Part.some (Except.ok value, finalHeap) ∧ post✝ n limit initialHeap value finalHeap

                                                                The source contract is equivalent to ordinary curried preconditions and successful result/heap postconditions, including termination and absence of faults.

                                                                theorem Complexity.Language.Examples.Scalar.Structured.run_total :
                                                                run_contract (fun (n_source limit_source : Value Ty.nat) (initialHeap : Heap) => True) fun (n_source limit_source : Value Ty.nat) (initialHeap : Heap) (returned : Value Ty.nat) (finalHeap : Heap) => returned = run_model ((fun (value : ℕ) => value) n_source) ((fun (value : ℕ) => value) limit_source) ∧ finalHeap = initialHeap

                                                                Exact total source contract derived from the checked encoded-result equation and the existing raw-input reconstruction, with the same final heap.

                                                                theorem Complexity.Language.Examples.Scalar.Structured.update_contract_iff_triple (pre✝ : ℕ × ℕ → Heap → Prop) (post✝ : ℕ × ℕ → Heap → ℕ × ℕ → Heap → Prop) :
                                                                update_contract pre✝ post✝ ↔ ∀ (input : ℕ × ℕ) (initialHeap : Heap), ⦃fun (currentHeap : Heap) => { down := currentHeap = initialHeap ∧ pre✝ input initialHeap }⦄ update input ⦃(fun (value : ℕ × ℕ) (finalHeap : Heap) => { down := post✝ input initialHeap value finalHeap }, fun (x : Fault) (x_1 : Heap) => { down := False }, PUnit.unit)⦄

                                                                Prove the ordinary-parameter source contract with a total-correctness triple for the same action. The ghost initial heap equals the actual entry heap; successful results use the actual final heap, and faults are excluded.

                                                                The named function's actual independently interpreted source body.

                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For

                                                                  Fold an actual source invocation back to its named ordinary-argument observation.

                                                                  The same source execution returns the encoded mathematical result without changing its supplied heap, under the actual input representations.

                                                                  The named function's actual partial source action, with ordinary typed arguments and an explicitly supplied shared heap.

                                                                  Equations
                                                                  • One or more equations did not get rendered due to their size.
                                                                  Instances For

                                                                    Automatic correspondence for the same generated source function, without a machine budget.

                                                                    @[reducible, inline]
                                                                    abbrev Complexity.Language.Examples.Scalar.Structured.run_onArgs {α✝ : Sort u_1} :
                                                                    (ℕ → ℕ → α✝) → Env [Ty.nat, Ty.nat] → α✝

                                                                    Apply a predicate, postcondition or bound with ordinary source parameters to the actual argument environment. No new contract or execution is introduced.

                                                                    Equations
                                                                    Instances For
                                                                      theorem Complexity.Language.Examples.Scalar.Structured.run_action_rel_native_preserving (n limit : ℕ) (initialHeap✝ : Heap) :
                                                                      ∃ (returned : Value Ty.nat) (finish : Heap), run n limit initialHeap✝ = Part.some (Except.ok returned, finish) ∧ (Representation.ofEmbedding (Function.Embedding.refl ℕ)).Rel (run_model n limit) returned finish ∧ (fun (finish : Heap) => initialHeap✝.ShapeExtends finish ∧ Buffer.PreservesContents initialHeap✝ finish) finish

                                                                      Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

                                                                      Ordinary mathematical function generated from the same represented source block.

                                                                      Equations
                                                                      • One or more equations did not get rendered due to their size.
                                                                      Instances For
                                                                        @[reducible, inline]

                                                                        Budget-free total correctness with ordinary source parameters and relational initial/final heap postconditions. This is the existing source function contract.

                                                                        Equations
                                                                        • One or more equations did not get rendered due to their size.
                                                                        Instances For
                                                                          theorem Complexity.Language.Examples.Scalar.structured_update_eq (input : BoundedInput) :
                                                                          Structured.update_model input = { value := min (input.value + 1) input.limit, limit := input.limit }

                                                                          The native structure view reuses the unchanged scalar helper's mathematics.

                                                                          Constructing, passing and projecting an ordinary structure needs no second algorithm or representation-specific mathematical proof.

                                                                          The frontend's generated correspondence transfers the ordinary mathematical equation to this same represented source invocation.

                                                                          The actual source block observed with ordinary named local inputs.

                                                                          Equations
                                                                          • One or more equations did not get rendered due to their size.
                                                                          Instances For

                                                                            Executable total value function generated from the same buffer-free source block.

                                                                            Equations
                                                                            • One or more equations did not get rendered due to their size.
                                                                            Instances For
                                                                              theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.eq_pure (step✝ index✝ acc✝ start stop k : ℕ) (positiveStep✝ : 0 < step✝) :
                                                                              (∀ (index : ℕ) (mutable : ℕ × Unit), index < stop → body step✝ index mutable.1 start stop k = have outcome := (fun (index : ℕ) (mutable : ℕ × Unit) => (have index := index; have acc := mutable.1; have pattern := index; have index_1 := pattern; have acc := acc.add index_1; have index := index.add step✝; pure (none, acc, ())).run) index mutable; pure (match outcome.1 with | none => (Control.normal, step✝, index + step✝, outcome.2.1, start, stop, k, ()) | some value => (Control.returned value, step✝, index, outcome.2.1, start, stop, k, ()))) → sum_loop1 step✝ index✝ acc✝ start stop k = have outcome := have outcome := (forIn [index✝:stop:step✝] (none, index✝, acc✝, ()) fun (index : ℕ) (state : Option ℕ × ℕ × ℕ × Unit) => have outcome := (fun (index : ℕ) (mutable : ℕ × Unit) => (have index := index; have acc := mutable.1; have pattern := index; have index_1 := pattern; have acc := acc.add index_1; have index := index.add step✝; pure (none, acc, ())).run) index state.2.2; outcome.1.elim (pure (ForInStep.yield (none, index + step✝, outcome.2))) fun (value : ℕ) => pure (ForInStep.done (some value, index, outcome.2))).run; (outcome.1, step✝, outcome.2.1, outcome.2.2.1, start, stop, k, ()); pure (outcome.1.elim Control.normal Control.returned, outcome.2)

                                                                              Finite iteration correspondence, with its one-body obligation left in the enclosing function's callee and recursive-hypothesis scope.

                                                                              theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.body_preservesCaptures {entry✝ finish✝ : State [Ty.nat, Ty.nat, Ty.nat, Ty.nat, Ty.nat, Ty.nat]} {control✝ : Control Ty.nat} :
                                                                              Exec program Body entry✝ finish✝ control✝ → (CaptureView finish✝.locals).2 = (CaptureView entry✝.locals).2

                                                                              Source lexical immutability preserves these captures on every actual exit.

                                                                              theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.variant_spec (step✝ start stop k : ℕ) (invariant✝ : ℕ → ℕ → Heap → Prop) (variant✝ : ℕ → ℕ → Heap → ℕ) (normal✝ : ℕ → ℕ → Heap → Prop) (returned✝ : ℕ → ℕ → ℕ → Heap → Prop) :
                                                                              (∀ (index acc : ℕ) (startHeap : Heap), invariant✝ index acc startHeap → ⦃fun (currentHeap : Heap) => { down := currentHeap = startHeap }⦄ guard step✝ index acc start stop k ⦃(fun (guardOutcome : Control Ty.bool × Locals) (afterGuardHeap : Heap) => { down := have afterGuard_index := guardOutcome.2.2.1; have afterGuard_acc := guardOutcome.2.2.2.1; match guardOutcome.1 with | Control.returned again => if again = true then ⦃fun (currentHeap : Heap) => { down := currentHeap = afterGuardHeap }⦄ body step✝ afterGuard_index afterGuard_acc start stop k ⦃(fun (bodyOutcome : Control Ty.nat × Locals) (afterBodyHeap : Heap) => { down := have afterBody_index := bodyOutcome.2.2.1; have afterBody_acc := bodyOutcome.2.2.2.1; match bodyOutcome.1 with | Control.normal => invariant✝ afterBody_index afterBody_acc afterBodyHeap ∧ variant✝ afterBody_index afterBody_acc afterBodyHeap < variant✝ index acc startHeap | Control.returned value => returned✝ value afterBody_index afterBody_acc afterBodyHeap | Control.fault a => False }, PUnit.unit)⦄ else normal✝ afterGuard_index afterGuard_acc afterGuardHeap | Control.normal => False | Control.fault a => False }, PUnit.unit)⦄) → ∀ (index acc : ℕ), ⦃fun (heap : Heap) => { down := invariant✝ index acc heap }⦄ sum_loop1 step✝ index acc start stop k ⦃(fun (outcome : Control Ty.nat × Locals) (heap : Heap) => { down := have final_index := outcome.2.2.1; have final_acc := outcome.2.2.2.1; match outcome.1 with | Control.normal => normal✝ final_index final_acc heap | Control.returned value => returned✝ value final_index final_acc heap | Control.fault a => False }, PUnit.unit)⦄

                                                                              Prove this actual loop with fixed captures and well-founded progress on its mutable locals. Only normal body exits must decrease; guard effects, returns and faults retain their real heap.

                                                                              @[reducible, inline]

                                                                              The ordinary mutable locals of this source loop.

                                                                              Equations
                                                                              Instances For
                                                                                @[reducible, inline]

                                                                                The actual declared argument environment, constructed from ordinary source parameters. This is proof-side parameter transport, not an additional runtime operation.

                                                                                Equations
                                                                                • One or more equations did not get rendered due to their size.
                                                                                Instances For

                                                                                  The finite table of actual named source bodies.

                                                                                  Equations
                                                                                  • One or more equations did not get rendered due to their size.
                                                                                  Instances For

                                                                                    Source lexical immutability preserves these captures on every actual exit.

                                                                                    theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.variant_contract (step✝ start stop k : ℕ) (invariant✝ : ℕ → ℕ → Heap → Prop) (variant✝ : ℕ → ℕ → Heap → ℕ) (ready✝ : ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop) (normal✝ : ℕ → ℕ → Heap → Prop) (returned✝ : ℕ → ℕ → ℕ → Heap → Prop) :
                                                                                    (guard_contract step✝ start stop k invariant✝ (fun (x x_1 : ℕ) (x_2 : Heap) (after_index after_acc : ℕ) (finish : Heap) => False) fun (index acc : ℕ) (heap : Heap) (again : Bool) (after_index after_acc : ℕ) (finish : Heap) => if again = true then ready✝ index acc heap after_index after_acc finish else normal✝ after_index after_acc finish) → (∀ (index acc : ℕ) (heap : Heap), invariant✝ index acc heap → body_contract step✝ start stop k (ready✝ index acc heap) (fun (x x_1 : ℕ) (x_2 : Heap) (after_index after_acc : ℕ) (finish : Heap) => invariant✝ after_index after_acc finish ∧ variant✝ after_index after_acc finish < variant✝ index acc heap) fun (x x_1 : ℕ) (x_2 : Heap) (value after_index after_acc : ℕ) (finish : Heap) => returned✝ value after_index after_acc finish) → contract step✝ start stop k invariant✝ (fun (x x_1 : ℕ) (x_2 : Heap) (after_index after_acc : ℕ) (finish : Heap) => normal✝ after_index after_acc finish) fun (x x_1 : ℕ) (x_2 : Heap) (value after_index after_acc : ℕ) (finish : Heap) => returned✝ value after_index after_acc finish

                                                                                    Prove a named loop from independent mathematical guard and body contracts. Actual guard effects and early body returns are retained; only normal iterations decrease.

                                                                                    theorem Complexity.Language.Examples.Scalar.Strided.sum_total_iff (pre✝ : ℕ → ℕ → ℕ → Heap → Prop) (post✝ : ℕ → ℕ → ℕ → Heap → ℕ → Heap → Prop) :
                                                                                    sum_contract pre✝ post✝ ↔ ∀ (start stop k : ℕ) (initialHeap : Heap), pre✝ start stop k initialHeap → ∃ (value : ℕ) (finalHeap : Heap), sum_action start stop k initialHeap = Part.some (Except.ok value, finalHeap) ∧ post✝ start stop k initialHeap value finalHeap

                                                                                    The source contract is equivalent to ordinary curried preconditions and successful result/heap postconditions, including termination and absence of faults.

                                                                                    The actual value-producing guard, reevaluated on every iteration.

                                                                                    Equations
                                                                                    • One or more equations did not get rendered due to their size.
                                                                                    Instances For
                                                                                      theorem Complexity.Language.Examples.Scalar.Strided.sum_action_eq (start stop k : ℕ) :
                                                                                      sum_action start stop k = have acc := 0; have index := start; let step := k.add 1; have positiveStep := ⋯; do let __discr ← MonadLift.monadLift (sum_loop1 step index acc start stop k) match __discr with | (loopControl, loopLocals) => have index := loopLocals.2.1; have acc := loopLocals.2.2.1; have __do_jp := fun (y : Unit) => pure acc; match loopControl with | Control.normal => do let y ← pure () __do_jp y | Control.returned returned => pure returned | Control.fault error => do let y ← throw error __do_jp y

                                                                                      One source-body equation in ordinary monadic notation; named callees remain opaque.

                                                                                      The named function's actual independently interpreted source body.

                                                                                      Equations
                                                                                      • One or more equations did not get rendered due to their size.
                                                                                      Instances For

                                                                                        Observe lexical coordinates without unfolding the equivalence structure.

                                                                                        theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.body_contract_iff (step✝ start stop k : ℕ) (pre✝ : ℕ → ℕ → Heap → Prop) (normal✝ : ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop) (returned✝ : ℕ → ℕ → Heap → ℕ → ℕ → ℕ → Heap → Prop) :
                                                                                        body_contract step✝ start stop k pre✝ normal✝ returned✝ ↔ ∀ (index acc : ℕ) (heap : Heap), pre✝ index acc heap → ⦃fun (current : Heap) => { down := current = heap }⦄ body step✝ index acc start stop k ⦃(fun (outcome : Control Ty.nat × Locals) (finish : Heap) => { down := match outcome.1 with | Control.normal => have after := outcome.2; normal✝ index acc heap after.2.1 after.2.2.1 finish | Control.returned value => have after := outcome.2; returned✝ index acc heap value after.2.1 after.2.2.1 finish | Control.fault a => False }, PUnit.unit)⦄

                                                                                        Introduce named mutable variables directly, without unpacking internal coordinates.

                                                                                        @[reducible, inline]
                                                                                        abbrev Complexity.Language.Examples.Scalar.Strided.sum_loop1.body_contract :
                                                                                        ℕ → (start stop k : ℕ) → (ℕ → ℕ → Heap → Prop) → (ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop) → (ℕ → ℕ → Heap → ℕ → ℕ → ℕ → Heap → Prop) → Prop

                                                                                        Relational total correctness with ordinary mutable parameters and fixed captures. The existing block contract retains both actual heaps and excludes faults.

                                                                                        Equations
                                                                                        • One or more equations did not get rendered due to their size.
                                                                                        Instances For
                                                                                          theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.continue_eq (entry✝ : Env [Ty.nat, Ty.nat, Ty.nat, Ty.nat, Ty.nat, Ty.nat]) (next✝ : Env [Ty.nat, Ty.nat, Ty.nat, Ty.nat, Ty.nat, Ty.nat] → ExceptT Fault (StateT Heap Part) ℕ) :
                                                                                          Code.evalWith program entry✝ next✝ = do let __discr ← MonadLift.monadLift (sum_loop1 (View entry✝).1 (View entry✝).2.1 (View entry✝).2.2.1 (View entry✝).2.2.2.1 (View entry✝).2.2.2.2.1 (View entry✝).2.2.2.2.2.1) match __discr with | (control, locals) => match control with | Control.normal => next✝ (Env.cons (entry✝.get Var.here) (Env.cons locals.2.1 (Env.cons locals.2.2.1 (Env.cons (entry✝.get Var.here.there.there.there) (Env.cons (entry✝.get Var.here.there.there.there.there) (Env.cons (entry✝.get Var.here.there.there.there.there.there) Env.empty)))))) | Control.returned value => pure value | Control.fault error => throw error

                                                                                          Resume from actual mutable locals; immutable captures are preserved by the source frame.

                                                                                          theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.rel_contract (step✝ start stop k : ℕ) {Model✝ : Type} (stateRel✝ : Model✝ → ℕ → ℕ → Heap → Prop) (invariant✝ : Model✝ → Prop) {relation✝ : Model✝ → Model✝ → Prop} :
                                                                                          WellFounded relation✝ → ∀ (ready : Model✝ → ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop) (normal : ℕ → ℕ → Heap → Prop) (returned : ℕ → ℕ → ℕ → Heap → Prop), (∀ (model : Model✝), invariant✝ model → guard_contract step✝ start stop k (stateRel✝ model) (fun (x x_1 : ℕ) (x_2 : Heap) (after_index after_acc : ℕ) (finish : Heap) => False) fun (index acc : ℕ) (heap : Heap) (again : Bool) (after_index after_acc : ℕ) (finish : Heap) => if again = true then ready model index acc heap after_index after_acc finish else normal after_index after_acc finish) → (∀ (model : Model✝) (index acc : ℕ) (heap : Heap), invariant✝ model → stateRel✝ model index acc heap → body_contract step✝ start stop k (ready model index acc heap) (fun (x x_1 : ℕ) (x_2 : Heap) (after_index after_acc : ℕ) (finish : Heap) => ∃ (next : Model✝), invariant✝ next ∧ stateRel✝ next after_index after_acc finish ∧ relation✝ next model) fun (x x_1 : ℕ) (x_2 : Heap) (value after_index after_acc : ℕ) (finish : Heap) => returned value after_index after_acc finish) → ∀ (model : Model✝), invariant✝ model → contract step✝ start stop k (stateRel✝ model) (fun (x x_1 : ℕ) (x_2 : Heap) (after_index after_acc : ℕ) (finish : Heap) => normal after_index after_acc finish) fun (x x_1 : ℕ) (x_2 : Heap) (value after_index after_acc : ℕ) (finish : Heap) => returned value after_index after_acc finish

                                                                                          Prove this actual loop using a related mathematical state and well-founded progress. Fixed captures are retained by the generated execution frames.

                                                                                          @[reducible, inline]
                                                                                          abbrev Complexity.Language.Examples.Scalar.Strided.sum_loop1.contract :
                                                                                          ℕ → (start stop k : ℕ) → (ℕ → ℕ → Heap → Prop) → (ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop) → (ℕ → ℕ → Heap → ℕ → ℕ → ℕ → Heap → Prop) → Prop

                                                                                          Relational total correctness with ordinary mutable parameters and fixed captures. The existing block contract retains both actual heaps and excludes faults.

                                                                                          Equations
                                                                                          • One or more equations did not get rendered due to their size.
                                                                                          Instances For
                                                                                            theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.contract_iff (step✝ start stop k : ℕ) (pre✝ : ℕ → ℕ → Heap → Prop) (normal✝ : ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop) (returned✝ : ℕ → ℕ → Heap → ℕ → ℕ → ℕ → Heap → Prop) :
                                                                                            contract step✝ start stop k pre✝ normal✝ returned✝ ↔ ∀ (index acc : ℕ) (heap : Heap), pre✝ index acc heap → ⦃fun (current : Heap) => { down := current = heap }⦄ sum_loop1 step✝ index acc start stop k ⦃(fun (outcome : Control Ty.nat × Locals) (finish : Heap) => { down := match outcome.1 with | Control.normal => have after := outcome.2; normal✝ index acc heap after.2.1 after.2.2.1 finish | Control.returned value => have after := outcome.2; returned✝ index acc heap value after.2.1 after.2.2.1 finish | Control.fault a => False }, PUnit.unit)⦄

                                                                                            Introduce named mutable variables directly, without unpacking internal coordinates.

                                                                                            @[reducible, inline]

                                                                                            The source program's declared first-order signatures.

                                                                                            Equations
                                                                                            • One or more equations did not get rendered due to their size.
                                                                                            Instances For

                                                                                              The same complete environment, grouped by source mutability.

                                                                                              Equations
                                                                                              • One or more equations did not get rendered due to their size.
                                                                                              Instances For
                                                                                                theorem Complexity.Language.Examples.Scalar.Strided.sum_observe (arguments✝ : Env [Ty.nat, Ty.nat, Ty.nat]) :
                                                                                                program.eval sumId arguments✝ = sum_action arguments✝.head arguments✝.tail.head arguments✝.tail.tail.head

                                                                                                Fold an actual source invocation back to its named ordinary-argument observation.

                                                                                                theorem Complexity.Language.Examples.Scalar.Strided.sum_action_eq_pure (start stop k : ℕ) :
                                                                                                sum_action start stop k = pure (sum start stop k)

                                                                                                The actual source action terminates with the generated native result and preserves every initial heap. Lean's native recursion principle proves this once.

                                                                                                theorem Complexity.Language.Examples.Scalar.Strided.sum_contract_iff_triple (pre✝ : ℕ → ℕ → ℕ → Heap → Prop) (post✝ : ℕ → ℕ → ℕ → Heap → ℕ → Heap → Prop) :
                                                                                                sum_contract pre✝ post✝ ↔ ∀ (start stop k : ℕ) (initialHeap : Heap), ⦃fun (currentHeap : Heap) => { down := currentHeap = initialHeap ∧ pre✝ start stop k initialHeap }⦄ sum_action start stop k ⦃(fun (value : ℕ) (finalHeap : Heap) => { down := post✝ start stop k initialHeap value finalHeap }, fun (x : Fault) (x_1 : Heap) => { down := False }, PUnit.unit)⦄

                                                                                                Prove the ordinary-parameter source contract with a total-correctness triple for the same action. The ghost initial heap equals the actual entry heap; successful results use the actual final heap, and faults are excluded.

                                                                                                The actual source block observed with ordinary named local inputs.

                                                                                                Equations
                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                Instances For
                                                                                                  theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.guard_spec (step✝ start stop k : ℕ) {pre✝ : ℕ → ℕ → Heap → Prop} {normal✝ : ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop} {returned✝ : ℕ → ℕ → Heap → Bool → ℕ → ℕ → Heap → Prop} :
                                                                                                  guard_contract step✝ start stop k pre✝ normal✝ returned✝ → ∀ (index acc : ℕ) (post : Std.Do.PostCond (Control Ty.bool × Locals) (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure)), ⦃fun (heap : Heap) => { down := pre✝ index acc heap ∧ (∀ (after_index after_acc : ℕ) (finish : Heap), normal✝ index acc heap after_index after_acc finish → (post.1 (Control.normal, step✝, after_index, after_acc, start, stop, k, ()) finish).down) ∧ ∀ (value : Bool) (after_index after_acc : ℕ) (finish : Heap), returned✝ index acc heap value after_index after_acc finish → (post.1 (Control.returned value, step✝, after_index, after_acc, start, stop, k, ()) finish).down }⦄ guard step✝ index acc start stop k ⦃post⦄

                                                                                                  Apply a chosen mathematical contract to the native block action. Continuations see ordinary mutable outputs; proved frames restore the fixed captures.

                                                                                                  theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.regroup_apply (values✝ : Locals) :
                                                                                                  Regroup values✝ = ((values✝.2.1, values✝.2.2.1, ()), values✝.1, values✝.2.2.2.1, values✝.2.2.2.2.1, values✝.2.2.2.2.2.1, ())
                                                                                                  theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.count_frame_contract (step✝ start stop k : ℕ) (count✝ : ℕ → ℕ → ℕ) (limit✝ : ℕ) (invariant✝ : ℕ → ℕ → Heap → Prop) (frame✝ : Heap → Heap → Prop) :
                                                                                                  (∀ {a b c : Heap}, frame✝ a b → frame✝ b c → frame✝ a c) → ∀ (normal : Heap → Prop), (guard_contract step✝ start stop k invariant✝ (fun (x x_1 : ℕ) (x_2 : Heap) (after_index after_acc : ℕ) (x_3 : Heap) => False) fun (index acc : ℕ) (heap : Heap) (again : Bool) (after_index after_acc : ℕ) (finish : Heap) => count✝ after_index after_acc = count✝ index acc ∧ finish = heap ∧ invariant✝ after_index after_acc finish ∧ (again = true ↔ count✝ after_index after_acc < limit✝)) → (body_contract step✝ start stop k (fun (index acc : ℕ) (heap : Heap) => invariant✝ index acc heap ∧ count✝ index acc < limit✝) (fun (index acc : ℕ) (heap : Heap) (after_index after_acc : ℕ) (finish : Heap) => count✝ after_index after_acc = count✝ index acc + 1 ∧ invariant✝ after_index after_acc finish ∧ frame✝ heap finish) fun (x x_1 : ℕ) (x_2 : Heap) (x_3 after_index after_acc : ℕ) (x_4 : Heap) => False) → (∀ (index acc : ℕ) (heap : Heap), invariant✝ index acc heap → limit✝ ≤ count✝ index acc → normal heap) → ∀ (initial : Heap), contract step✝ start stop k (fun (index acc : ℕ) (heap : Heap) => invariant✝ index acc heap ∧ frame✝ initial heap) (fun (x x_1 : ℕ) (x_2 : Heap) (after_index after_acc : ℕ) (finish : Heap) => normal finish ∧ frame✝ initial finish) fun (x x_1 : ℕ) (x_2 : Heap) (x_3 after_index after_acc : ℕ) (x_4 : Heap) => False

                                                                                                  Compose an increasing count and a transitive heap frame from the actual guard and body contracts. The guard preserves the count and heap; normal body steps increase the count by one. Array effects and the exit consequence remain supplied mathematical facts, without a runtime budget.

                                                                                                  theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.regroup_symm_apply (grouped✝ : Mutable × Captured) :
                                                                                                  Regroup.symm grouped✝ = (grouped✝.2.1, grouped✝.1.1, grouped✝.1.2.1, grouped✝.2.2.1, grouped✝.2.2.2.1, grouped✝.2.2.2.2.1, ())
                                                                                                  theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.guard_observe (locals✝ : Locals) :
                                                                                                  Stmt.observe View Guard program locals✝ = guard locals✝.1 locals✝.2.1 locals✝.2.2.1 locals✝.2.2.2.1 locals✝.2.2.2.2.1 locals✝.2.2.2.2.2.1

                                                                                                  Coordinate conversion for composing this named observation.

                                                                                                  theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.preservesCaptures {entry✝ finish✝ : State [Ty.nat, Ty.nat, Ty.nat, Ty.nat, Ty.nat, Ty.nat]} {control✝ : Control Ty.nat} :
                                                                                                  Exec program Code entry✝ finish✝ control✝ → (CaptureView finish✝.locals).2 = (CaptureView entry✝.locals).2

                                                                                                  Source lexical immutability preserves these captures on every actual exit.

                                                                                                  theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.wellFounded_contract (step✝ start stop k : ℕ) (invariant✝ : ℕ → ℕ → Heap → Prop) (relation✝ : Mutable × Heap → Mutable × Heap → Prop) :
                                                                                                  WellFounded relation✝ → ∀ (ready : ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop) (normal : ℕ → ℕ → Heap → Prop) (returned : ℕ → ℕ → ℕ → Heap → Prop), (guard_contract step✝ start stop k invariant✝ (fun (x x_1 : ℕ) (x_2 : Heap) (after_index after_acc : ℕ) (finish : Heap) => False) fun (index acc : ℕ) (heap : Heap) (again : Bool) (after_index after_acc : ℕ) (finish : Heap) => if again = true then ready index acc heap after_index after_acc finish else normal after_index after_acc finish) → (∀ (index acc : ℕ) (heap : Heap), invariant✝ index acc heap → body_contract step✝ start stop k (ready index acc heap) (fun (x x_1 : ℕ) (x_2 : Heap) (after_index after_acc : ℕ) (finish : Heap) => invariant✝ after_index after_acc finish ∧ relation✝ ((after_index, after_acc, ()), finish) ((index, acc, ()), heap)) fun (x x_1 : ℕ) (x_2 : Heap) (value after_index after_acc : ℕ) (finish : Heap) => returned value after_index after_acc finish) → contract step✝ start stop k invariant✝ (fun (x x_1 : ℕ) (x_2 : Heap) (after_index after_acc : ℕ) (finish : Heap) => normal after_index after_acc finish) fun (x x_1 : ℕ) (x_2 : Heap) (value after_index after_acc : ℕ) (finish : Heap) => returned value after_index after_acc finish

                                                                                                  Prove a named loop from independent mathematical guard and body contracts. Actual guard effects and early body returns are retained; only normal iterations decrease.

                                                                                                  theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.body_observe (locals✝ : Locals) :
                                                                                                  Stmt.observe View Body program locals✝ = body locals✝.1 locals✝.2.1 locals✝.2.2.1 locals✝.2.2.2.1 locals✝.2.2.2.2.1 locals✝.2.2.2.2.2.1

                                                                                                  Coordinate conversion for composing this named observation.

                                                                                                  A lossless coordinate permutation; no source operation is executed.

                                                                                                  Equations
                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                  Instances For

                                                                                                    The named function's actual partial source action, with ordinary typed arguments and an explicitly supplied shared heap.

                                                                                                    Equations
                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                    Instances For
                                                                                                      @[reducible, inline]

                                                                                                      Fixed lexical captures, independent of the shared heap.

                                                                                                      Equations
                                                                                                      Instances For
                                                                                                        @[reducible, inline]
                                                                                                        abbrev Complexity.Language.Examples.Scalar.Strided.sum_loop1.guard_contract :
                                                                                                        ℕ → (start stop k : ℕ) → (ℕ → ℕ → Heap → Prop) → (ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop) → (ℕ → ℕ → Heap → Bool → ℕ → ℕ → Heap → Prop) → Prop

                                                                                                        Relational total correctness with ordinary mutable parameters and fixed captures. The existing block contract retains both actual heaps and excludes faults.

                                                                                                        Equations
                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                        Instances For
                                                                                                          theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.observe (locals✝ : Locals) :
                                                                                                          Stmt.observe View Code program locals✝ = sum_loop1 locals✝.1 locals✝.2.1 locals✝.2.2.1 locals✝.2.2.2.1 locals✝.2.2.2.2.1 locals✝.2.2.2.2.2.1

                                                                                                          Coordinate conversion for composing this named observation.

                                                                                                          The actual parsed lexical body, with its enclosing return type.

                                                                                                          Equations
                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                          Instances For
                                                                                                            theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.body_spec (step✝ start stop k : ℕ) {pre✝ : ℕ → ℕ → Heap → Prop} {normal✝ : ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop} {returned✝ : ℕ → ℕ → Heap → ℕ → ℕ → ℕ → Heap → Prop} :
                                                                                                            body_contract step✝ start stop k pre✝ normal✝ returned✝ → ∀ (index acc : ℕ) (post : Std.Do.PostCond (Control Ty.nat × Locals) (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure)), ⦃fun (heap : Heap) => { down := pre✝ index acc heap ∧ (∀ (after_index after_acc : ℕ) (finish : Heap), normal✝ index acc heap after_index after_acc finish → (post.1 (Control.normal, step✝, after_index, after_acc, start, stop, k, ()) finish).down) ∧ ∀ (value after_index after_acc : ℕ) (finish : Heap), returned✝ index acc heap value after_index after_acc finish → (post.1 (Control.returned value, step✝, after_index, after_acc, start, stop, k, ()) finish).down }⦄ body step✝ index acc start stop k ⦃post⦄

                                                                                                            Apply a chosen mathematical contract to the native block action. Continuations see ordinary mutable outputs; proved frames restore the fixed captures.

                                                                                                            @[reducible, inline]

                                                                                                            This named source function's index in its declared signature table.

                                                                                                            Equations
                                                                                                            Instances For
                                                                                                              theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.wellFounded_spec (step✝ start stop k : ℕ) (invariant✝ : ℕ → ℕ → Heap → Prop) (relation✝ : Mutable × Heap → Mutable × Heap → Prop) :
                                                                                                              WellFounded relation✝ → ∀ (normal : ℕ → ℕ → Heap → Prop) (returned : ℕ → ℕ → ℕ → Heap → Prop), (∀ (index acc : ℕ) (startHeap : Heap), invariant✝ index acc startHeap → ⦃fun (currentHeap : Heap) => { down := currentHeap = startHeap }⦄ guard step✝ index acc start stop k ⦃(fun (guardOutcome : Control Ty.bool × Locals) (afterGuardHeap : Heap) => { down := have afterGuard_index := guardOutcome.2.2.1; have afterGuard_acc := guardOutcome.2.2.2.1; match guardOutcome.1 with | Control.returned again => if again = true then ⦃fun (currentHeap : Heap) => { down := currentHeap = afterGuardHeap }⦄ body step✝ afterGuard_index afterGuard_acc start stop k ⦃(fun (bodyOutcome : Control Ty.nat × Locals) (afterBodyHeap : Heap) => { down := have afterBody_index := bodyOutcome.2.2.1; have afterBody_acc := bodyOutcome.2.2.2.1; match bodyOutcome.1 with | Control.normal => invariant✝ afterBody_index afterBody_acc afterBodyHeap ∧ relation✝ ((afterBody_index, afterBody_acc, ()), afterBodyHeap) ((index, acc, ()), startHeap) | Control.returned value => returned value afterBody_index afterBody_acc afterBodyHeap | Control.fault a => False }, PUnit.unit)⦄ else normal afterGuard_index afterGuard_acc afterGuardHeap | Control.normal => False | Control.fault a => False }, PUnit.unit)⦄) → ∀ (index acc : ℕ), ⦃fun (heap : Heap) => { down := invariant✝ index acc heap }⦄ sum_loop1 step✝ index acc start stop k ⦃(fun (outcome : Control Ty.nat × Locals) (heap : Heap) => { down := have final_index := outcome.2.2.1; have final_acc := outcome.2.2.2.1; match outcome.1 with | Control.normal => normal final_index final_acc heap | Control.returned value => returned value final_index final_acc heap | Control.fault a => False }, PUnit.unit)⦄

                                                                                                              Prove this actual loop with fixed captures and well-founded progress on its mutable locals. Only normal body exits must decrease; guard effects, returns and faults retain their real heap.

                                                                                                              theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.spec (step✝ start stop k : ℕ) {pre✝ : ℕ → ℕ → Heap → Prop} {normal✝ : ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop} {returned✝ : ℕ → ℕ → Heap → ℕ → ℕ → ℕ → Heap → Prop} :
                                                                                                              contract step✝ start stop k pre✝ normal✝ returned✝ → ∀ (index acc : ℕ) (post : Std.Do.PostCond (Control Ty.nat × Locals) (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure)), ⦃fun (heap : Heap) => { down := pre✝ index acc heap ∧ (∀ (after_index after_acc : ℕ) (finish : Heap), normal✝ index acc heap after_index after_acc finish → (post.1 (Control.normal, step✝, after_index, after_acc, start, stop, k, ()) finish).down) ∧ ∀ (value after_index after_acc : ℕ) (finish : Heap), returned✝ index acc heap value after_index after_acc finish → (post.1 (Control.returned value, step✝, after_index, after_acc, start, stop, k, ()) finish).down }⦄ sum_loop1 step✝ index acc start stop k ⦃post⦄

                                                                                                              Apply a chosen mathematical contract to the native block action. Continuations see ordinary mutable outputs; proved frames restore the fixed captures.

                                                                                                              theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.guard_contract_iff (step✝ start stop k : ℕ) (pre✝ : ℕ → ℕ → Heap → Prop) (normal✝ : ℕ → ℕ → Heap → ℕ → ℕ → Heap → Prop) (returned✝ : ℕ → ℕ → Heap → Bool → ℕ → ℕ → Heap → Prop) :
                                                                                                              guard_contract step✝ start stop k pre✝ normal✝ returned✝ ↔ ∀ (index acc : ℕ) (heap : Heap), pre✝ index acc heap → ⦃fun (current : Heap) => { down := current = heap }⦄ guard step✝ index acc start stop k ⦃(fun (outcome : Control Ty.bool × Locals) (finish : Heap) => { down := match outcome.1 with | Control.normal => have after := outcome.2; normal✝ index acc heap after.2.1 after.2.2.1 finish | Control.returned value => have after := outcome.2; returned✝ index acc heap value after.2.1 after.2.2.1 finish | Control.fault a => False }, PUnit.unit)⦄

                                                                                                              Introduce named mutable variables directly, without unpacking internal coordinates.

                                                                                                              @[reducible, inline]
                                                                                                              abbrev Complexity.Language.Examples.Scalar.Strided.sum_onArgs {α✝ : Sort u_1} :
                                                                                                              (ℕ → ℕ → ℕ → α✝) → Env [Ty.nat, Ty.nat, Ty.nat] → α✝

                                                                                                              Apply a predicate, postcondition or bound with ordinary source parameters to the actual argument environment. No new contract or execution is introduced.

                                                                                                              Equations
                                                                                                              Instances For
                                                                                                                @[reducible, inline]
                                                                                                                abbrev Complexity.Language.Examples.Scalar.Strided.sum_contract :
                                                                                                                (ℕ → ℕ → ℕ → Heap → Prop) → (ℕ → ℕ → ℕ → Heap → ℕ → Heap → Prop) → Prop

                                                                                                                Budget-free total correctness with ordinary source parameters and relational initial/final heap postconditions. This is the existing source function contract.

                                                                                                                Equations
                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                Instances For
                                                                                                                  @[reducible, inline]

                                                                                                                  Complete lexical coordinates for this source block.

                                                                                                                  Equations
                                                                                                                  Instances For
                                                                                                                    theorem Complexity.Language.Examples.Scalar.Strided.sum_spec {pre✝ : Env [Ty.nat, Ty.nat, Ty.nat] → Heap → Prop} {post✝ : Env [Ty.nat, Ty.nat, Ty.nat] → Heap → ℕ → Heap → Prop} :
                                                                                                                    FunctionTotal program sumId pre✝ post✝ → ∀ (start stop k : ℕ) (continuation : Std.Do.PostCond ℕ (Std.Do.PostShape.except Fault (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure))), ⦃fun (initialHeap : Heap) => { down := pre✝ (Env.cons start (Env.cons stop (Env.cons k Env.empty))) initialHeap ∧ ∀ (value : ℕ) (finalHeap : Heap), post✝ (Env.cons start (Env.cons stop (Env.cons k Env.empty))) initialHeap value finalHeap → (continuation.1 value finalHeap).down }⦄ sum_action start stop k ⦃continuation⦄

                                                                                                                    Apply a supplied source contract with ordinary named arguments and its actual returned value and final heap. No callee body or new contract is inferred.

                                                                                                                    theorem Complexity.Language.Examples.Scalar.Strided.sum_total :
                                                                                                                    FunctionTotal program sumId (fun (x : Env signatures[sumId].params) (x_1 : Heap) => True) fun (arguments : Env signatures[sumId].params) (initialHeap : Heap) (value : Value signatures[sumId].result) (finalHeap : Heap) => value = sum arguments.head arguments.tail.head arguments.tail.tail.head ∧ finalHeap = initialHeap

                                                                                                                    Exact total source contract inherited from the generated native function.

                                                                                                                    The actual source block observed with ordinary named local inputs.

                                                                                                                    Equations
                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                    Instances For
                                                                                                                      theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.captureView_symm_apply (grouped✝ : Mutable × Captured) :
                                                                                                                      CaptureView.symm grouped✝ = View.symm (grouped✝.2.1, grouped✝.1.1, grouped✝.1.2.1, grouped✝.2.2.1, grouped✝.2.2.2.1, grouped✝.2.2.2.2.1, ())

                                                                                                                      Restore grouped locals using the checked coordinate projection laws.

                                                                                                                      Lossless proof coordinates, including fixed and shadowed captures.

                                                                                                                      Equations
                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                      Instances For
                                                                                                                        theorem Complexity.Language.Examples.Scalar.Strided.sum_loop1.view_symm_apply (values✝ : Locals) :
                                                                                                                        View.symm values✝ = Env.cons values✝.1 (Env.cons values✝.2.1 (Env.cons values✝.2.2.1 (Env.cons values✝.2.2.2.1 (Env.cons values✝.2.2.2.2.1 (Env.cons values✝.2.2.2.2.2.1 Env.empty)))))

                                                                                                                        Restore complete lexical coordinates without unfolding proof fields.

                                                                                                                        theorem Complexity.Language.Examples.Scalar.strided_sum_eq (start stop k : ℕ) :
                                                                                                                        Strided.sum start stop k = (List.range' start ((stop - start + k) / (k + 1)) (k + 1)).sum

                                                                                                                        A dynamic positive stride enumerates the same ordinary arithmetic progression, including empty ranges and a last increment that passes the stop.

                                                                                                                        theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_total_iff (pre✝ : ℕ × ℕ → ℕ → ℕ → ℕ → Heap → Prop) (post✝ : ℕ × ℕ → ℕ → ℕ → ℕ → Heap → ℕ × ℕ → Heap → Prop) :
                                                                                                                        sum_contract pre✝ post✝ ↔ ∀ (initial : ℕ × ℕ) (start stop k : ℕ) (initialHeap : Heap), pre✝ initial start stop k initialHeap → ∃ (value : ℕ × ℕ) (finalHeap : Heap), sum_action initial start stop k initialHeap = Part.some (Except.ok value, finalHeap) ∧ post✝ initial start stop k initialHeap value finalHeap

                                                                                                                        The source contract is equivalent to ordinary curried preconditions and successful result/heap postconditions, including termination and absence of faults.

                                                                                                                        @[reducible, inline]

                                                                                                                        Immutable captures in their registered native types.

                                                                                                                        Equations
                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                        Instances For
                                                                                                                          theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.wellFounded_contract (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) (invariant✝ : ℕ → ℕ × ℕ → Heap → Prop) (relation✝ : Mutable × Heap → Mutable × Heap → Prop) :
                                                                                                                          WellFounded relation✝ → ∀ (ready : ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop) (normal : ℕ → ℕ × ℕ → Heap → Prop) (returned : ℕ × ℕ → ℕ → ℕ × ℕ → Heap → Prop), (guard_contract step✝ operand✝ first✝ operand✝¹ initial start stop k invariant✝ (fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => False) fun (index : ℕ) (acc : ℕ × ℕ) (heap : Heap) (again : Bool) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => if again = true then ready index acc heap after_index after_acc finish else normal after_index after_acc finish) → (∀ (index : ℕ) (acc : ℕ × ℕ) (heap : Heap), invariant✝ index acc heap → body_contract step✝ operand✝ first✝ operand✝¹ initial start stop k (ready index acc heap) (fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => invariant✝ after_index after_acc finish ∧ relation✝ ((after_index, after_acc, ()), finish) ((index, acc, ()), heap)) fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (value : ℕ × ℕ) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => returned value after_index after_acc finish) → contract step✝ operand✝ first✝ operand✝¹ initial start stop k invariant✝ (fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => normal after_index after_acc finish) fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (value : ℕ × ℕ) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => returned value after_index after_acc finish

                                                                                                                          Prove a named loop from independent mathematical guard and body contracts. Actual guard effects and early body returns are retained; only normal iterations decrease.

                                                                                                                          The named function's actual independently interpreted source body.

                                                                                                                          Equations
                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                          Instances For
                                                                                                                            theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.count_frame_contract (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) (count✝ : ℕ → ℕ × ℕ → ℕ) (limit✝ : ℕ) (invariant✝ : ℕ → ℕ × ℕ → Heap → Prop) (frame✝ : Heap → Heap → Prop) :
                                                                                                                            (∀ {a b c : Heap}, frame✝ a b → frame✝ b c → frame✝ a c) → ∀ (normal : Heap → Prop), (guard_contract step✝ operand✝ first✝ operand✝¹ initial start stop k invariant✝ (fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (x_3 : Heap) => False) fun (index : ℕ) (acc : ℕ × ℕ) (heap : Heap) (again : Bool) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => count✝ after_index after_acc = count✝ index acc ∧ finish = heap ∧ invariant✝ after_index after_acc finish ∧ (again = true ↔ count✝ after_index after_acc < limit✝)) → (body_contract step✝ operand✝ first✝ operand✝¹ initial start stop k (fun (index : ℕ) (acc : ℕ × ℕ) (heap : Heap) => invariant✝ index acc heap ∧ count✝ index acc < limit✝) (fun (index : ℕ) (acc : ℕ × ℕ) (heap : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => count✝ after_index after_acc = count✝ index acc + 1 ∧ invariant✝ after_index after_acc finish ∧ frame✝ heap finish) fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (x_3 : ℕ × ℕ) (after_index : ℕ) (after_acc : ℕ × ℕ) (x_4 : Heap) => False) → (∀ (index : ℕ) (acc : ℕ × ℕ) (heap : Heap), invariant✝ index acc heap → limit✝ ≤ count✝ index acc → normal heap) → ∀ (initial✝ : Heap), contract step✝ operand✝ first✝ operand✝¹ initial start stop k (fun (index : ℕ) (acc : ℕ × ℕ) (heap : Heap) => invariant✝ index acc heap ∧ frame✝ initial✝ heap) (fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => normal finish ∧ frame✝ initial✝ finish) fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (x_3 : ℕ × ℕ) (after_index : ℕ) (after_acc : ℕ × ℕ) (x_4 : Heap) => False

                                                                                                                            Compose an increasing count and a transitive heap frame from the actual guard and body contracts. The guard preserves the count and heap; normal body steps increase the count by one. Array effects and the exit consequence remain supplied mathematical facts, without a runtime budget.

                                                                                                                            theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.native_guard_eq (captures✝ : NativeCaptured) (index✝ : ℕ) (mutable✝ : BoundedInput × Unit) :
                                                                                                                            Stmt.observe NativeCaptureView Guard program ((index✝, mutable✝), captures✝) = pure (Control.returned (decide (index✝ < nativeRangeStop captures✝)), (index✝, mutable✝), captures✝)

                                                                                                                            The actual guard observed at native mutable locals and fixed captures.

                                                                                                                            theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_action_eq (initial : ℕ × ℕ) (start stop k : ℕ) :
                                                                                                                            sum_action initial start stop k = have operand := initial; do let first ← add_action operand 0 have acc : ℕ × ℕ := first have index : ℕ := start let operand_1 : ℕ := k let step : ℕ := operand_1.add 1 have positiveStep : 0 < step := ⋯ let __discr ← MonadLift.monadLift (sum_loop1 step operand_1 index acc first operand initial start stop k) match __discr with | (loopControl, loopLocals) => have index := loopLocals.2.2.1; have acc := loopLocals.2.2.2.1; have __do_jp := fun (y : Unit) => pure acc; match loopControl with | Control.normal => do let y ← pure () __do_jp y | Control.returned returned => pure returned | Control.fault error => do let y ← throw error __do_jp y

                                                                                                                            One source-body equation in ordinary monadic notation; named callees remain opaque.

                                                                                                                            theorem Complexity.Language.Examples.Scalar.StructuredRange.add_action_eq_pure_raw (input : ℕ × ℕ) (amount : ℕ) :
                                                                                                                            add_action input amount = pure (add ((fun (raw : ℕ × ℕ) => { value := raw.1, limit := raw.2 }) input) ((fun (raw : ℕ) => raw) amount)).sourceEncode

                                                                                                                            Observe any raw layout through its checked native reconstruction. Reconstruction is proof-side transport, not an additional source operation.

                                                                                                                            theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.variant_contract (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) (invariant✝ : ℕ → ℕ × ℕ → Heap → Prop) (variant✝ : ℕ → ℕ × ℕ → Heap → ℕ) (ready✝ : ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop) (normal✝ : ℕ → ℕ × ℕ → Heap → Prop) (returned✝ : ℕ × ℕ → ℕ → ℕ × ℕ → Heap → Prop) :
                                                                                                                            (guard_contract step✝ operand✝ first✝ operand✝¹ initial start stop k invariant✝ (fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => False) fun (index : ℕ) (acc : ℕ × ℕ) (heap : Heap) (again : Bool) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => if again = true then ready✝ index acc heap after_index after_acc finish else normal✝ after_index after_acc finish) → (∀ (index : ℕ) (acc : ℕ × ℕ) (heap : Heap), invariant✝ index acc heap → body_contract step✝ operand✝ first✝ operand✝¹ initial start stop k (ready✝ index acc heap) (fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => invariant✝ after_index after_acc finish ∧ variant✝ after_index after_acc finish < variant✝ index acc heap) fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (value : ℕ × ℕ) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => returned✝ value after_index after_acc finish) → contract step✝ operand✝ first✝ operand✝¹ initial start stop k invariant✝ (fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => normal✝ after_index after_acc finish) fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (value : ℕ × ℕ) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => returned✝ value after_index after_acc finish

                                                                                                                            Prove a named loop from independent mathematical guard and body contracts. Actual guard effects and early body returns are retained; only normal iterations decrease.

                                                                                                                            Fold an actual source invocation back to its named ordinary-argument observation.

                                                                                                                            theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.contract_iff (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) (pre✝ : ℕ → ℕ × ℕ → Heap → Prop) (normal✝ : ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop) (returned✝ : ℕ → ℕ × ℕ → Heap → ℕ × ℕ → ℕ → ℕ × ℕ → Heap → Prop) :
                                                                                                                            contract step✝ operand✝ first✝ operand✝¹ initial start stop k pre✝ normal✝ returned✝ ↔ ∀ (index : ℕ) (acc : ℕ × ℕ) (heap : Heap), pre✝ index acc heap → ⦃fun (current : Heap) => { down := current = heap }⦄ sum_loop1 step✝ operand✝ index acc first✝ operand✝¹ initial start stop k ⦃(fun (outcome : Control (Ty.nat.prod Ty.nat) × Locals) (finish : Heap) => { down := match outcome.1 with | Control.normal => have after := outcome.2; normal✝ index acc heap after.2.2.1 after.2.2.2.1 finish | Control.returned value => have after := outcome.2; returned✝ index acc heap value after.2.2.1 after.2.2.2.1 finish | Control.fault a => False }, PUnit.unit)⦄

                                                                                                                            Introduce named mutable variables directly, without unpacking internal coordinates.

                                                                                                                            theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.eq_pure_native (step✝ operand✝ index✝ : ℕ) (acc✝ first✝ operand✝¹ initial : BoundedInput) (start stop k : ℕ) (positiveStep✝ : 0 < step✝) :
                                                                                                                            (∀ (index : ℕ) (mutable : BoundedInput × Unit), index < stop → body step✝ ((Equiv.refl ℕ) operand✝) index (BoundedInput.sourceEquiv mutable.1) (BoundedInput.sourceEquiv first✝) (BoundedInput.sourceEquiv operand✝¹) (BoundedInput.sourceEquiv initial) ((Equiv.refl ℕ) start) ((Equiv.refl ℕ) stop) ((Equiv.refl ℕ) k) = have outcome := (fun (index : ℕ) (mutable : BoundedInput × Unit) => (have index := index; have acc := mutable.1; have pattern := index; have index_1 := pattern; have operand := acc; have operand_1 := index_1; do let next ← add operand operand_1 have acc : BoundedInput := next have index : ℕ := index.add step✝ pure (none, acc, ())).run) index mutable; pure (match outcome.1 with | none => (Control.normal, step✝, (Equiv.refl ℕ) operand✝, index + step✝, BoundedInput.sourceEquiv outcome.2.1, BoundedInput.sourceEquiv first✝, BoundedInput.sourceEquiv operand✝¹, BoundedInput.sourceEquiv initial, (Equiv.refl ℕ) start, (Equiv.refl ℕ) stop, (Equiv.refl ℕ) k, ()) | some value => (Control.returned (BoundedInput.sourceEquiv.toFun value), step✝, (Equiv.refl ℕ) operand✝, index, BoundedInput.sourceEquiv outcome.2.1, BoundedInput.sourceEquiv first✝, BoundedInput.sourceEquiv operand✝¹, BoundedInput.sourceEquiv initial, (Equiv.refl ℕ) start, (Equiv.refl ℕ) stop, (Equiv.refl ℕ) k, ()))) → sum_loop1 step✝ ((Equiv.refl ℕ) operand✝) ((Equiv.refl ℕ) index✝) (BoundedInput.sourceEquiv acc✝) (BoundedInput.sourceEquiv first✝) (BoundedInput.sourceEquiv operand✝¹) (BoundedInput.sourceEquiv initial) ((Equiv.refl ℕ) start) ((Equiv.refl ℕ) stop) ((Equiv.refl ℕ) k) = have outcome := have outcome := (forIn [index✝:stop:step✝] (none, index✝, acc✝, ()) fun (index : ℕ) (state : Option BoundedInput × ℕ × BoundedInput × Unit) => have outcome := (fun (index : ℕ) (mutable : BoundedInput × Unit) => (have index := index; have acc := mutable.1; have pattern := index; have index_1 := pattern; have operand := acc; have operand_1 := index_1; do let next ← add operand operand_1 have acc : BoundedInput := next have index : ℕ := index.add step✝ pure (none, acc, ())).run) index state.2.2; outcome.1.elim (pure (ForInStep.yield (none, index + step✝, outcome.2))) fun (value : BoundedInput) => pure (ForInStep.done (some value, index, outcome.2))).run; (outcome.1, step✝, operand✝, outcome.2.1, outcome.2.2.1, first✝, operand✝¹, initial, start, stop, k, ()); pure (outcome.1.elim Control.normal fun (value : BoundedInput) => Control.returned (BoundedInput.sourceEquiv.toFun value), outcome.2.1, (Equiv.refl ℕ) outcome.2.2.1, (Equiv.refl ℕ) outcome.2.2.2.1, BoundedInput.sourceEquiv outcome.2.2.2.2.1, BoundedInput.sourceEquiv outcome.2.2.2.2.2.1, BoundedInput.sourceEquiv outcome.2.2.2.2.2.2.1, BoundedInput.sourceEquiv outcome.2.2.2.2.2.2.2.1, (Equiv.refl ℕ) outcome.2.2.2.2.2.2.2.2.1, (Equiv.refl ℕ) outcome.2.2.2.2.2.2.2.2.2.1, (Equiv.refl ℕ) outcome.2.2.2.2.2.2.2.2.2.2.1, ())

                                                                                                                            The existing source range in checked native local coordinates. Encoding changes neither its iterations, early exits, heap nor source operation costs.

                                                                                                                            The same actual exit preserves its native immutable captures.

                                                                                                                            theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.eq_pure (step✝ operand✝ index✝ : ℕ) (acc✝ first✝ operand✝¹ initial✝ : ℕ × ℕ) (start✝ stop✝ k✝ : ℕ) :
                                                                                                                            have step := step✝; have operand := (Equiv.refl ℕ).symm operand✝; have index := (Equiv.refl ℕ).symm index✝; have acc := BoundedInput.sourceEquiv.symm acc✝; have first := BoundedInput.sourceEquiv.symm first✝; have operand_1 := BoundedInput.sourceEquiv.symm operand✝¹; have initial := BoundedInput.sourceEquiv.symm initial✝; have start := (Equiv.refl ℕ).symm start✝; have stop := (Equiv.refl ℕ).symm stop✝; have k := (Equiv.refl ℕ).symm k✝; ∀ (positiveStep : 0 < step), (∀ (index : ℕ) (mutable : BoundedInput × Unit), index < stop → body step ((Equiv.refl ℕ) operand) index (BoundedInput.sourceEquiv mutable.1) (BoundedInput.sourceEquiv first) (BoundedInput.sourceEquiv operand_1) (BoundedInput.sourceEquiv initial) ((Equiv.refl ℕ) start) ((Equiv.refl ℕ) stop) ((Equiv.refl ℕ) k) = have outcome := (fun (index : ℕ) (mutable : BoundedInput × Unit) => (have index := index; have acc := mutable.1; have pattern := index; have index_1 := pattern; have operand := acc; have operand_2 := index_1; do let next ← add operand operand_2 have acc : BoundedInput := next have index : ℕ := index.add step pure (none, acc, ())).run) index mutable; pure (match outcome.1 with | none => (Control.normal, step, (Equiv.refl ℕ) operand, index + step, BoundedInput.sourceEquiv outcome.2.1, BoundedInput.sourceEquiv first, BoundedInput.sourceEquiv operand_1, BoundedInput.sourceEquiv initial, (Equiv.refl ℕ) start, (Equiv.refl ℕ) stop, (Equiv.refl ℕ) k, ()) | some value => (Control.returned (BoundedInput.sourceEquiv.toFun value), step, (Equiv.refl ℕ) operand, index, BoundedInput.sourceEquiv outcome.2.1, BoundedInput.sourceEquiv first, BoundedInput.sourceEquiv operand_1, BoundedInput.sourceEquiv initial, (Equiv.refl ℕ) start, (Equiv.refl ℕ) stop, (Equiv.refl ℕ) k, ()))) → sum_loop1 step✝ operand✝ index✝ acc✝ first✝ operand✝¹ initial✝ start✝ stop✝ k✝ = have outcome := have outcome := (forIn [index:stop:step] (none, index, acc, ()) fun (index : ℕ) (state : Option BoundedInput × ℕ × BoundedInput × Unit) => have outcome := (fun (index : ℕ) (mutable : BoundedInput × Unit) => (have index := index; have acc := mutable.1; have pattern := index; have index_1 := pattern; have operand := acc; have operand_2 := index_1; do let next ← add operand operand_2 have acc : BoundedInput := next have index : ℕ := index.add step pure (none, acc, ())).run) index state.2.2; outcome.1.elim (pure (ForInStep.yield (none, index + step, outcome.2))) fun (value : BoundedInput) => pure (ForInStep.done (some value, index, outcome.2))).run; (outcome.1, step, operand, outcome.2.1, outcome.2.2.1, first, operand_1, initial, start, stop, k, ()); pure (outcome.1.elim Control.normal fun (value : BoundedInput) => Control.returned (BoundedInput.sourceEquiv.toFun value), outcome.2.1, (Equiv.refl ℕ) outcome.2.2.1, (Equiv.refl ℕ) outcome.2.2.2.1, BoundedInput.sourceEquiv outcome.2.2.2.2.1, BoundedInput.sourceEquiv outcome.2.2.2.2.2.1, BoundedInput.sourceEquiv outcome.2.2.2.2.2.2.1, BoundedInput.sourceEquiv outcome.2.2.2.2.2.2.2.1, (Equiv.refl ℕ) outcome.2.2.2.2.2.2.2.2.1, (Equiv.refl ℕ) outcome.2.2.2.2.2.2.2.2.2.1, (Equiv.refl ℕ) outcome.2.2.2.2.2.2.2.2.2.2.1, ())

                                                                                                                            The same range correspondence at arbitrary raw locals, reconstructed through the registered lossless native coordinates for theorem composition.

                                                                                                                            theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.continue_eq (entry✝ : Env [Ty.nat, Ty.nat, Ty.nat, Ty.nat.prod Ty.nat, Ty.nat.prod Ty.nat, Ty.nat.prod Ty.nat, Ty.nat.prod Ty.nat, Ty.nat, Ty.nat, Ty.nat]) (next✝ : Env [Ty.nat, Ty.nat, Ty.nat, Ty.nat.prod Ty.nat, Ty.nat.prod Ty.nat, Ty.nat.prod Ty.nat, Ty.nat.prod Ty.nat, Ty.nat, Ty.nat, Ty.nat] → ExceptT Fault (StateT Heap Part) (ℕ × ℕ)) :
                                                                                                                            Code.evalWith program entry✝ next✝ = do let __discr ← MonadLift.monadLift (sum_loop1 (View entry✝).1 (View entry✝).2.1 (View entry✝).2.2.1 (View entry✝).2.2.2.1 (View entry✝).2.2.2.2.1 (View entry✝).2.2.2.2.2.1 (View entry✝).2.2.2.2.2.2.1 (View entry✝).2.2.2.2.2.2.2.1 (View entry✝).2.2.2.2.2.2.2.2.1 (View entry✝).2.2.2.2.2.2.2.2.2.1) match __discr with | (control, locals) => match control with | Control.normal => next✝ (Env.cons (entry✝.get Var.here) (Env.cons (entry✝.get Var.here.there) (Env.cons locals.2.2.1 (Env.cons locals.2.2.2.1 (Env.cons (entry✝.get Var.here.there.there.there.there) (Env.cons (entry✝.get Var.here.there.there.there.there.there) (Env.cons (entry✝.get Var.here.there.there.there.there.there.there) (Env.cons (entry✝.get Var.here.there.there.there.there.there.there.there) (Env.cons (entry✝.get Var.here.there.there.there.there.there.there.there.there) (Env.cons (entry✝.get Var.here.there.there.there.there.there.there.there.there.there) Env.empty)))))))))) | Control.returned value => pure value | Control.fault error => throw error

                                                                                                                            Resume from actual mutable locals; immutable captures are preserved by the source frame.

                                                                                                                            Native mathematical arguments and results of this actual source function.

                                                                                                                            Equations
                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                            Instances For

                                                                                                                              The actual fixed stride selected from this loop's native captures.

                                                                                                                              Equations
                                                                                                                              Instances For
                                                                                                                                theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.native_captureView_symm_apply (grouped✝ : NativeMutable × NativeCaptured) :
                                                                                                                                NativeCaptureView.symm grouped✝ = Env.cons grouped✝.2.1 (Env.cons ((Equiv.refl ℕ) grouped✝.2.2.1) (Env.cons ((Equiv.refl ℕ) grouped✝.1.1) (Env.cons (BoundedInput.sourceEquiv grouped✝.1.2.1) (Env.cons (BoundedInput.sourceEquiv grouped✝.2.2.2.1) (Env.cons (BoundedInput.sourceEquiv grouped✝.2.2.2.2.1) (Env.cons (BoundedInput.sourceEquiv grouped✝.2.2.2.2.2.1) (Env.cons ((Equiv.refl ℕ) grouped✝.2.2.2.2.2.2.1) (Env.cons ((Equiv.refl ℕ) grouped✝.2.2.2.2.2.2.2.1) (Env.cons ((Equiv.refl ℕ) grouped✝.2.2.2.2.2.2.2.2.1) Env.empty)))))))))

                                                                                                                                Restore native loop coordinates without unfolding equivalence proofs.

                                                                                                                                theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_total :
                                                                                                                                FunctionTotal program sumId (fun (x : Env signatures[sumId].params) (x_1 : Heap) => True) fun (arguments : Env signatures[sumId].params) (initialHeap : Heap) (value : Value signatures[sumId].result) (finalHeap : Heap) => value = (sum ((fun (raw : ℕ × ℕ) => { value := raw.1, limit := raw.2 }) arguments.head) ((fun (raw : ℕ) => raw) arguments.tail.head) ((fun (raw : ℕ) => raw) arguments.tail.tail.head) ((fun (raw : ℕ) => raw) arguments.tail.tail.tail.head)).sourceEncode ∧ finalHeap = initialHeap

                                                                                                                                Exact total source contract inherited from the generated native function.

                                                                                                                                theorem Complexity.Language.Examples.Scalar.StructuredRange.add_total_iff (pre✝ : ℕ × ℕ → ℕ → Heap → Prop) (post✝ : ℕ × ℕ → ℕ → Heap → ℕ × ℕ → Heap → Prop) :
                                                                                                                                add_contract pre✝ post✝ ↔ ∀ (input : ℕ × ℕ) (amount : ℕ) (initialHeap : Heap), pre✝ input amount initialHeap → ∃ (value : ℕ × ℕ) (finalHeap : Heap), add_action input amount initialHeap = Part.some (Except.ok value, finalHeap) ∧ post✝ input amount initialHeap value finalHeap

                                                                                                                                The source contract is equivalent to ordinary curried preconditions and successful result/heap postconditions, including termination and absence of faults.

                                                                                                                                This actual source block, retaining its loop or allocation-scope semantics.

                                                                                                                                Equations
                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                Instances For

                                                                                                                                  Executable total value function generated from the same buffer-free source block.

                                                                                                                                  Equations
                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                  Instances For
                                                                                                                                    theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.regroup_apply (values✝ : Locals) :
                                                                                                                                    Regroup values✝ = ((values✝.2.2.1, values✝.2.2.2.1, ()), values✝.1, values✝.2.1, values✝.2.2.2.2.1, values✝.2.2.2.2.2.1, values✝.2.2.2.2.2.2.1, values✝.2.2.2.2.2.2.2.1, values✝.2.2.2.2.2.2.2.2.1, values✝.2.2.2.2.2.2.2.2.2.1, ())
                                                                                                                                    theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_action_eq_pure_raw (initial : ℕ × ℕ) (start stop k : ℕ) :
                                                                                                                                    sum_action initial start stop k = pure (sum ((fun (raw : ℕ × ℕ) => { value := raw.1, limit := raw.2 }) initial) ((fun (raw : ℕ) => raw) start) ((fun (raw : ℕ) => raw) stop) ((fun (raw : ℕ) => raw) k)).sourceEncode

                                                                                                                                    Observe any raw layout through its checked native reconstruction. Reconstruction is proof-side transport, not an additional source operation.

                                                                                                                                    Fold an actual source invocation back to its named ordinary-argument observation.

                                                                                                                                    The same complete environment, grouped by source mutability.

                                                                                                                                    Equations
                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                    Instances For
                                                                                                                                      theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.rel_contract (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) {Model✝ : Type} (stateRel✝ : Model✝ → ℕ → ℕ × ℕ → Heap → Prop) (invariant✝ : Model✝ → Prop) {relation✝ : Model✝ → Model✝ → Prop} :
                                                                                                                                      WellFounded relation✝ → ∀ (ready : Model✝ → ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop) (normal : ℕ → ℕ × ℕ → Heap → Prop) (returned : ℕ × ℕ → ℕ → ℕ × ℕ → Heap → Prop), (∀ (model : Model✝), invariant✝ model → guard_contract step✝ operand✝ first✝ operand✝¹ initial start stop k (stateRel✝ model) (fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => False) fun (index : ℕ) (acc : ℕ × ℕ) (heap : Heap) (again : Bool) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => if again = true then ready model index acc heap after_index after_acc finish else normal after_index after_acc finish) → (∀ (model : Model✝) (index : ℕ) (acc : ℕ × ℕ) (heap : Heap), invariant✝ model → stateRel✝ model index acc heap → body_contract step✝ operand✝ first✝ operand✝¹ initial start stop k (ready model index acc heap) (fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => ∃ (next : Model✝), invariant✝ next ∧ stateRel✝ next after_index after_acc finish ∧ relation✝ next model) fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (value : ℕ × ℕ) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => returned value after_index after_acc finish) → ∀ (model : Model✝), invariant✝ model → contract step✝ operand✝ first✝ operand✝¹ initial start stop k (stateRel✝ model) (fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => normal after_index after_acc finish) fun (x : ℕ) (x_1 : ℕ × ℕ) (x_2 : Heap) (value : ℕ × ℕ) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap) => returned value after_index after_acc finish

                                                                                                                                      Prove this actual loop using a related mathematical state and well-founded progress. Fixed captures are retained by the generated execution frames.

                                                                                                                                      noncomputable def Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.body :
                                                                                                                                      ℕ → ℕ → ℕ → ℕ × ℕ → ℕ × ℕ → ℕ × ℕ → (initial : ℕ × ℕ) → (start stop k : ℕ) → StateT Heap Part (Control (Ty.nat.prod Ty.nat) × Locals)

                                                                                                                                      The actual source block observed with ordinary named local inputs.

                                                                                                                                      Equations
                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                      Instances For
                                                                                                                                        @[reducible, inline]

                                                                                                                                        Budget-free total correctness with ordinary source parameters and relational initial/final heap postconditions. This is the existing source function contract.

                                                                                                                                        Equations
                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                        Instances For

                                                                                                                                          A native view of the same environment, with no runtime conversion.

                                                                                                                                          Equations
                                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                                          Instances For

                                                                                                                                            Canonical proof-side encoding of this function's native arguments. It does not insert an uncharged runtime conversion.

                                                                                                                                            Equations
                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                            Instances For

                                                                                                                                              The same actual exit preserves its native immutable captures.

                                                                                                                                              A lossless coordinate permutation; no source operation is executed.

                                                                                                                                              Equations
                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                              Instances For

                                                                                                                                                Lossless proof coordinates, including fixed and shadowed captures.

                                                                                                                                                Equations
                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                Instances For
                                                                                                                                                  theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.variant_spec (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) (invariant✝ : ℕ → ℕ × ℕ → Heap → Prop) (variant✝ : ℕ → ℕ × ℕ → Heap → ℕ) (normal✝ : ℕ → ℕ × ℕ → Heap → Prop) (returned✝ : ℕ × ℕ → ℕ → ℕ × ℕ → Heap → Prop) :
                                                                                                                                                  (∀ (index : ℕ) (acc : ℕ × ℕ) (startHeap : Heap), invariant✝ index acc startHeap → ⦃fun (currentHeap : Heap) => { down := currentHeap = startHeap }⦄ guard step✝ operand✝ index acc first✝ operand✝¹ initial start stop k ⦃(fun (guardOutcome : Control Ty.bool × Locals) (afterGuardHeap : Heap) => { down := have afterGuard_index := guardOutcome.2.2.2.1; have afterGuard_acc := guardOutcome.2.2.2.2.1; match guardOutcome.1 with | Control.returned again => if again = true then ⦃fun (currentHeap : Heap) => { down := currentHeap = afterGuardHeap }⦄ body step✝ operand✝ afterGuard_index afterGuard_acc first✝ operand✝¹ initial start stop k ⦃(fun (bodyOutcome : Control (Ty.nat.prod Ty.nat) × Locals) (afterBodyHeap : Heap) => { down := have afterBody_index := bodyOutcome.2.2.2.1; have afterBody_acc := bodyOutcome.2.2.2.2.1; match bodyOutcome.1 with | Control.normal => invariant✝ afterBody_index afterBody_acc afterBodyHeap ∧ variant✝ afterBody_index afterBody_acc afterBodyHeap < variant✝ index acc startHeap | Control.returned value => returned✝ value afterBody_index afterBody_acc afterBodyHeap | Control.fault a => False }, PUnit.unit)⦄ else normal✝ afterGuard_index afterGuard_acc afterGuardHeap | Control.normal => False | Control.fault a => False }, PUnit.unit)⦄) → ∀ (index : ℕ) (acc : ℕ × ℕ), ⦃fun (heap : Heap) => { down := invariant✝ index acc heap }⦄ sum_loop1 step✝ operand✝ index acc first✝ operand✝¹ initial start stop k ⦃(fun (outcome : Control (Ty.nat.prod Ty.nat) × Locals) (heap : Heap) => { down := have final_index := outcome.2.2.2.1; have final_acc := outcome.2.2.2.2.1; match outcome.1 with | Control.normal => normal✝ final_index final_acc heap | Control.returned value => returned✝ value final_index final_acc heap | Control.fault a => False }, PUnit.unit)⦄

                                                                                                                                                  Prove this actual loop with fixed captures and well-founded progress on its mutable locals. Only normal body exits must decrease; guard effects, returns and faults retain their real heap.

                                                                                                                                                  @[reducible, inline]
                                                                                                                                                  abbrev Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.guard_contract :
                                                                                                                                                  ℕ → ℕ → ℕ × ℕ → ℕ × ℕ → (initial : ℕ × ℕ) → (start stop k : ℕ) → (ℕ → ℕ × ℕ → Heap → Prop) → (ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop) → (ℕ → ℕ × ℕ → Heap → Bool → ℕ → ℕ × ℕ → Heap → Prop) → Prop

                                                                                                                                                  Relational total correctness with ordinary mutable parameters and fixed captures. The existing block contract retains both actual heaps and excludes faults.

                                                                                                                                                  Equations
                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                  Instances For

                                                                                                                                                    The actual value-producing guard, reevaluated on every iteration.

                                                                                                                                                    Equations
                                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                                    Instances For
                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_contract_iff_triple (pre✝ : ℕ × ℕ → ℕ → ℕ → ℕ → Heap → Prop) (post✝ : ℕ × ℕ → ℕ → ℕ → ℕ → Heap → ℕ × ℕ → Heap → Prop) :
                                                                                                                                                      sum_contract pre✝ post✝ ↔ ∀ (initial : ℕ × ℕ) (start stop k : ℕ) (initialHeap : Heap), ⦃fun (currentHeap : Heap) => { down := currentHeap = initialHeap ∧ pre✝ initial start stop k initialHeap }⦄ sum_action initial start stop k ⦃(fun (value : ℕ × ℕ) (finalHeap : Heap) => { down := post✝ initial start stop k initialHeap value finalHeap }, fun (x : Fault) (x_1 : Heap) => { down := False }, PUnit.unit)⦄

                                                                                                                                                      Prove the ordinary-parameter source contract with a total-correctness triple for the same action. The ghost initial heap equals the actual entry heap; successful results use the actual final heap, and faults are excluded.

                                                                                                                                                      Canonical proof-side encoding of this function's native arguments. It does not insert an uncharged runtime conversion.

                                                                                                                                                      Equations
                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                      Instances For

                                                                                                                                                        Executable total value function generated from the same buffer-free source block.

                                                                                                                                                        Equations
                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                        Instances For
                                                                                                                                                          theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.native_body_eq_of_eq (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : BoundedInput) (start stop k : ℕ) :
                                                                                                                                                          (∀ (index : ℕ) (mutable : BoundedInput × Unit), index < stop → body step✝ ((Equiv.refl ℕ) operand✝) index (BoundedInput.sourceEquiv mutable.1) (BoundedInput.sourceEquiv first✝) (BoundedInput.sourceEquiv operand✝¹) (BoundedInput.sourceEquiv initial) ((Equiv.refl ℕ) start) ((Equiv.refl ℕ) stop) ((Equiv.refl ℕ) k) = have outcome := (fun (index : ℕ) (mutable : BoundedInput × Unit) => (have index := index; have acc := mutable.1; have pattern := index; have index_1 := pattern; have operand := acc; have operand_1 := index_1; do let next ← add operand operand_1 have acc : BoundedInput := next have index : ℕ := index.add step✝ pure (none, acc, ())).run) index mutable; pure (match outcome.1 with | none => (Control.normal, step✝, (Equiv.refl ℕ) operand✝, index + step✝, BoundedInput.sourceEquiv outcome.2.1, BoundedInput.sourceEquiv first✝, BoundedInput.sourceEquiv operand✝¹, BoundedInput.sourceEquiv initial, (Equiv.refl ℕ) start, (Equiv.refl ℕ) stop, (Equiv.refl ℕ) k, ()) | some value => (Control.returned (BoundedInput.sourceEquiv.toFun value), step✝, (Equiv.refl ℕ) operand✝, index, BoundedInput.sourceEquiv outcome.2.1, BoundedInput.sourceEquiv first✝, BoundedInput.sourceEquiv operand✝¹, BoundedInput.sourceEquiv initial, (Equiv.refl ℕ) start, (Equiv.refl ℕ) stop, (Equiv.refl ℕ) k, ()))) → ∀ (index : ℕ) (mutable : BoundedInput × Unit), index < stop → Stmt.observe NativeCaptureView Body program ((index, mutable), step✝, operand✝, first✝, operand✝¹, initial, start, stop, k, ()) = pure (match (fun (index : ℕ) (mutable : BoundedInput × Unit) => (have index := index; have acc := mutable.1; have pattern := index; have index_1 := pattern; have operand := acc; have operand_1 := index_1; do let next ← add operand operand_1 have acc : BoundedInput := next have index : ℕ := index.add step✝ pure (none, acc, ())).run) index mutable with | (none, nextMutable) => (Control.normal, (index + step✝, nextMutable), step✝, operand✝, first✝, operand✝¹, initial, start, stop, k, ()) | (some value, nextMutable) => (Control.returned (BoundedInput.sourceEquiv.toFun value), (index, nextMutable), step✝, operand✝, first✝, operand✝¹, initial, start, stop, k, ()))

                                                                                                                                                          Transport the same body equation into native locals, retaining actual early returns.

                                                                                                                                                          theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.native_body_eq (captures✝ : NativeCaptured) (index✝ : ℕ) (mutable✝ : BoundedInput × Unit) :
                                                                                                                                                          index✝ < nativeRangeStop captures✝ → Stmt.observe NativeCaptureView Body program ((index✝, mutable✝), captures✝) = pure (match nativeBodyStep captures✝ index✝ mutable✝ with | (none, nextMutable) => (Control.normal, (index✝ + nativeRangeStep captures✝, nextMutable), captures✝) | (some value, nextMutable) => (Control.returned (BoundedInput.sourceEquiv.toFun value), (index✝, nextMutable), captures✝))

                                                                                                                                                          The same source body in native locals, using the already proved callee correspondences. Its result keeps normal continuation and early return distinct and preserves the heap.

                                                                                                                                                          The generated ordinary native function describes this same source body.

                                                                                                                                                          Source lexical immutability preserves these captures on every actual exit.

                                                                                                                                                          @[reducible, inline]

                                                                                                                                                          Apply a predicate, postcondition or bound with ordinary source parameters to the actual argument environment. No new contract or execution is introduced.

                                                                                                                                                          Equations
                                                                                                                                                          Instances For

                                                                                                                                                            The generated pure single-step view, with native mutable values and possible early return. Naming this view adds neither a source operation nor a separate user-written implementation.

                                                                                                                                                            Equations
                                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                                            Instances For
                                                                                                                                                              theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_spec {pre✝ : Env [Ty.nat.prod Ty.nat, Ty.nat, Ty.nat, Ty.nat] → Heap → Prop} {post✝ : Env [Ty.nat.prod Ty.nat, Ty.nat, Ty.nat, Ty.nat] → Heap → ℕ × ℕ → Heap → Prop} :
                                                                                                                                                              FunctionTotal program sumId pre✝ post✝ → ∀ (initial : ℕ × ℕ) (start stop k : ℕ) (continuation : Std.Do.PostCond (ℕ × ℕ) (Std.Do.PostShape.except Fault (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure))), ⦃fun (initialHeap : Heap) => { down := pre✝ (Env.cons initial (Env.cons start (Env.cons stop (Env.cons k Env.empty)))) initialHeap ∧ ∀ (value : ℕ × ℕ) (finalHeap : Heap), post✝ (Env.cons initial (Env.cons start (Env.cons stop (Env.cons k Env.empty)))) initialHeap value finalHeap → (continuation.1 value finalHeap).down }⦄ sum_action initial start stop k ⦃continuation⦄

                                                                                                                                                              Apply a supplied source contract with ordinary named arguments and its actual returned value and final heap. No callee body or new contract is inferred.

                                                                                                                                                              The same actual exit preserves its native immutable captures.

                                                                                                                                                              @[reducible, inline]

                                                                                                                                                              The actual declared argument environment, constructed from ordinary source parameters. This is proof-side parameter transport, not an additional runtime operation.

                                                                                                                                                              Equations
                                                                                                                                                              Instances For
                                                                                                                                                                theorem Complexity.Language.Examples.Scalar.StructuredRange.add_spec {pre✝ : Env [Ty.nat.prod Ty.nat, Ty.nat] → Heap → Prop} {post✝ : Env [Ty.nat.prod Ty.nat, Ty.nat] → Heap → ℕ × ℕ → Heap → Prop} :
                                                                                                                                                                FunctionTotal program addId pre✝ post✝ → ∀ (input : ℕ × ℕ) (amount : ℕ) (continuation : Std.Do.PostCond (ℕ × ℕ) (Std.Do.PostShape.except Fault (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure))), ⦃fun (initialHeap : Heap) => { down := pre✝ (Env.cons input (Env.cons amount Env.empty)) initialHeap ∧ ∀ (value : ℕ × ℕ) (finalHeap : Heap), post✝ (Env.cons input (Env.cons amount Env.empty)) initialHeap value finalHeap → (continuation.1 value finalHeap).down }⦄ add_action input amount ⦃continuation⦄

                                                                                                                                                                Apply a supplied source contract with ordinary named arguments and its actual returned value and final heap. No callee body or new contract is inferred.

                                                                                                                                                                The generated ordinary native function describes this same source body.

                                                                                                                                                                theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.view_symm_apply (values✝ : Locals) :
                                                                                                                                                                View.symm values✝ = Env.cons values✝.1 (Env.cons values✝.2.1 (Env.cons values✝.2.2.1 (Env.cons values✝.2.2.2.1 (Env.cons values✝.2.2.2.2.1 (Env.cons values✝.2.2.2.2.2.1 (Env.cons values✝.2.2.2.2.2.2.1 (Env.cons values✝.2.2.2.2.2.2.2.1 (Env.cons values✝.2.2.2.2.2.2.2.2.1 (Env.cons values✝.2.2.2.2.2.2.2.2.2.1 Env.empty)))))))))

                                                                                                                                                                Restore complete lexical coordinates without unfolding proof fields.

                                                                                                                                                                theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.body_spec (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) {pre✝ : ℕ → ℕ × ℕ → Heap → Prop} {normal✝ : ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop} {returned✝ : ℕ → ℕ × ℕ → Heap → ℕ × ℕ → ℕ → ℕ × ℕ → Heap → Prop} :
                                                                                                                                                                body_contract step✝ operand✝ first✝ operand✝¹ initial start stop k pre✝ normal✝ returned✝ → ∀ (index : ℕ) (acc : ℕ × ℕ) (post : Std.Do.PostCond (Control (Ty.nat.prod Ty.nat) × Locals) (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure)), ⦃fun (heap : Heap) => { down := pre✝ index acc heap ∧ (∀ (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap), normal✝ index acc heap after_index after_acc finish → (post.1 (Control.normal, step✝, operand✝, after_index, after_acc, first✝, operand✝¹, initial, start, stop, k, ()) finish).down) ∧ ∀ (value : ℕ × ℕ) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap), returned✝ index acc heap value after_index after_acc finish → (post.1 (Control.returned value, step✝, operand✝, after_index, after_acc, first✝, operand✝¹, initial, start, stop, k, ()) finish).down }⦄ body step✝ operand✝ index acc first✝ operand✝¹ initial start stop k ⦃post⦄

                                                                                                                                                                Apply a chosen mathematical contract to the native block action. Continuations see ordinary mutable outputs; proved frames restore the fixed captures.

                                                                                                                                                                @[reducible, inline]

                                                                                                                                                                The source program's declared first-order signatures.

                                                                                                                                                                Equations
                                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                                Instances For
                                                                                                                                                                  @[reducible, inline]
                                                                                                                                                                  abbrev Complexity.Language.Examples.Scalar.StructuredRange.sum_contract :
                                                                                                                                                                  (ℕ × ℕ → ℕ → ℕ → ℕ → Heap → Prop) → (ℕ × ℕ → ℕ → ℕ → ℕ → Heap → ℕ × ℕ → Heap → Prop) → Prop

                                                                                                                                                                  Budget-free total correctness with ordinary source parameters and relational initial/final heap postconditions. This is the existing source function contract.

                                                                                                                                                                  Equations
                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                  Instances For
                                                                                                                                                                    @[reducible, inline]
                                                                                                                                                                    abbrev Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.native_contract :
                                                                                                                                                                    ℕ → ℕ → BoundedInput → BoundedInput → (initial : BoundedInput) → (start stop k : ℕ) → (ℕ → BoundedInput → Heap → Prop) → (ℕ → BoundedInput → Heap → ℕ → BoundedInput → Heap → Prop) → (ℕ → BoundedInput → Heap → BoundedInput → ℕ → BoundedInput → Heap → Prop) → Prop

                                                                                                                                                                    The actual block contract with native mutable parameters and fixed captures. Only the returned predicate decodes the source value; control and both heaps stay unchanged.

                                                                                                                                                                    Equations
                                                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                                                    Instances For
                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.StructuredRange.add_contract_iff_triple (pre✝ : ℕ × ℕ → ℕ → Heap → Prop) (post✝ : ℕ × ℕ → ℕ → Heap → ℕ × ℕ → Heap → Prop) :
                                                                                                                                                                      add_contract pre✝ post✝ ↔ ∀ (input : ℕ × ℕ) (amount : ℕ) (initialHeap : Heap), ⦃fun (currentHeap : Heap) => { down := currentHeap = initialHeap ∧ pre✝ input amount initialHeap }⦄ add_action input amount ⦃(fun (value : ℕ × ℕ) (finalHeap : Heap) => { down := post✝ input amount initialHeap value finalHeap }, fun (x : Fault) (x_1 : Heap) => { down := False }, PUnit.unit)⦄

                                                                                                                                                                      Prove the ordinary-parameter source contract with a total-correctness triple for the same action. The ghost initial heap equals the actual entry heap; successful results use the actual final heap, and faults are excluded.

                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.captureView_symm_apply (grouped✝ : Mutable × Captured) :
                                                                                                                                                                      CaptureView.symm grouped✝ = View.symm (grouped✝.2.1, grouped✝.2.2.1, grouped✝.1.1, grouped✝.1.2.1, grouped✝.2.2.2.1, grouped✝.2.2.2.2.1, grouped✝.2.2.2.2.2.1, grouped✝.2.2.2.2.2.2.1, grouped✝.2.2.2.2.2.2.2.1, grouped✝.2.2.2.2.2.2.2.2.1, ())

                                                                                                                                                                      Restore grouped locals using the checked coordinate projection laws.

                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.body_observe (locals✝ : Locals) :
                                                                                                                                                                      Stmt.observe View Body program locals✝ = body locals✝.1 locals✝.2.1 locals✝.2.2.1 locals✝.2.2.2.1 locals✝.2.2.2.2.1 locals✝.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.2.2.2.1

                                                                                                                                                                      Coordinate conversion for composing this named observation.

                                                                                                                                                                      The actual source action terminates with the generated native result and preserves every initial heap. Lean's native recursion principle proves this once.

                                                                                                                                                                      Native mathematical arguments and results of this actual source function.

                                                                                                                                                                      Equations
                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                      Instances For

                                                                                                                                                                        The actual fixed range endpoint selected from this loop's native captures.

                                                                                                                                                                        Equations
                                                                                                                                                                        Instances For
                                                                                                                                                                          noncomputable def Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1 :
                                                                                                                                                                          ℕ → ℕ → ℕ → ℕ × ℕ → ℕ × ℕ → ℕ × ℕ → (initial : ℕ × ℕ) → (start stop k : ℕ) → StateT Heap Part (Control (Ty.nat.prod Ty.nat) × sum_loop1.Locals)

                                                                                                                                                                          The actual source block observed with ordinary named local inputs.

                                                                                                                                                                          Equations
                                                                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                                                                          Instances For

                                                                                                                                                                            The named function's actual partial source action, with ordinary typed arguments and an explicitly supplied shared heap.

                                                                                                                                                                            Equations
                                                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                                                            Instances For
                                                                                                                                                                              theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.guard_observe (locals✝ : Locals) :
                                                                                                                                                                              Stmt.observe View Guard program locals✝ = guard locals✝.1 locals✝.2.1 locals✝.2.2.1 locals✝.2.2.2.1 locals✝.2.2.2.2.1 locals✝.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.2.2.2.1

                                                                                                                                                                              Coordinate conversion for composing this named observation.

                                                                                                                                                                              Source lexical immutability preserves these captures on every actual exit.

                                                                                                                                                                              @[reducible, inline]

                                                                                                                                                                              The actual declared argument environment, constructed from ordinary source parameters. This is proof-side parameter transport, not an additional runtime operation.

                                                                                                                                                                              Equations
                                                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                                                              Instances For
                                                                                                                                                                                @[reducible, inline]

                                                                                                                                                                                Apply a predicate, postcondition or bound with ordinary source parameters to the actual argument environment. No new contract or execution is introduced.

                                                                                                                                                                                Equations
                                                                                                                                                                                Instances For
                                                                                                                                                                                  @[reducible, inline]
                                                                                                                                                                                  abbrev Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.native_body_contract :
                                                                                                                                                                                  ℕ → ℕ → BoundedInput → BoundedInput → (initial : BoundedInput) → (start stop k : ℕ) → (ℕ → BoundedInput → Heap → Prop) → (ℕ → BoundedInput → Heap → ℕ → BoundedInput → Heap → Prop) → (ℕ → BoundedInput → Heap → BoundedInput → ℕ → BoundedInput → Heap → Prop) → Prop

                                                                                                                                                                                  The actual block contract with native mutable parameters and fixed captures. Only the returned predicate decodes the source value; control and both heaps stay unchanged.

                                                                                                                                                                                  Equations
                                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                                  Instances For
                                                                                                                                                                                    theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.body_contract_iff (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) (pre✝ : ℕ → ℕ × ℕ → Heap → Prop) (normal✝ : ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop) (returned✝ : ℕ → ℕ × ℕ → Heap → ℕ × ℕ → ℕ → ℕ × ℕ → Heap → Prop) :
                                                                                                                                                                                    body_contract step✝ operand✝ first✝ operand✝¹ initial start stop k pre✝ normal✝ returned✝ ↔ ∀ (index : ℕ) (acc : ℕ × ℕ) (heap : Heap), pre✝ index acc heap → ⦃fun (current : Heap) => { down := current = heap }⦄ body step✝ operand✝ index acc first✝ operand✝¹ initial start stop k ⦃(fun (outcome : Control (Ty.nat.prod Ty.nat) × Locals) (finish : Heap) => { down := match outcome.1 with | Control.normal => have after := outcome.2; normal✝ index acc heap after.2.2.1 after.2.2.2.1 finish | Control.returned value => have after := outcome.2; returned✝ index acc heap value after.2.2.1 after.2.2.2.1 finish | Control.fault a => False }, PUnit.unit)⦄

                                                                                                                                                                                    Introduce named mutable variables directly, without unpacking internal coordinates.

                                                                                                                                                                                    theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.regroup_symm_apply (grouped✝ : Mutable × Captured) :
                                                                                                                                                                                    Regroup.symm grouped✝ = (grouped✝.2.1, grouped✝.2.2.1, grouped✝.1.1, grouped✝.1.2.1, grouped✝.2.2.2.1, grouped✝.2.2.2.2.1, grouped✝.2.2.2.2.2.1, grouped✝.2.2.2.2.2.2.1, grouped✝.2.2.2.2.2.2.2.1, grouped✝.2.2.2.2.2.2.2.2.1, ())

                                                                                                                                                                                    The actual source action terminates with the generated native result and preserves every initial heap. Lean's native recursion principle proves this once.

                                                                                                                                                                                    The named function's actual partial source action, with ordinary typed arguments and an explicitly supplied shared heap.

                                                                                                                                                                                    Equations
                                                                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                                                                    Instances For
                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.guard_spec (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) {pre✝ : ℕ → ℕ × ℕ → Heap → Prop} {normal✝ : ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop} {returned✝ : ℕ → ℕ × ℕ → Heap → Bool → ℕ → ℕ × ℕ → Heap → Prop} :
                                                                                                                                                                                      guard_contract step✝ operand✝ first✝ operand✝¹ initial start stop k pre✝ normal✝ returned✝ → ∀ (index : ℕ) (acc : ℕ × ℕ) (post : Std.Do.PostCond (Control Ty.bool × Locals) (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure)), ⦃fun (heap : Heap) => { down := pre✝ index acc heap ∧ (∀ (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap), normal✝ index acc heap after_index after_acc finish → (post.1 (Control.normal, step✝, operand✝, after_index, after_acc, first✝, operand✝¹, initial, start, stop, k, ()) finish).down) ∧ ∀ (value : Bool) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap), returned✝ index acc heap value after_index after_acc finish → (post.1 (Control.returned value, step✝, operand✝, after_index, after_acc, first✝, operand✝¹, initial, start, stop, k, ()) finish).down }⦄ guard step✝ operand✝ index acc first✝ operand✝¹ initial start stop k ⦃post⦄

                                                                                                                                                                                      Apply a chosen mathematical contract to the native block action. Continuations see ordinary mutable outputs; proved frames restore the fixed captures.

                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.observe (locals✝ : Locals) :
                                                                                                                                                                                      Stmt.observe View Code program locals✝ = sum_loop1 locals✝.1 locals✝.2.1 locals✝.2.2.1 locals✝.2.2.2.1 locals✝.2.2.2.2.1 locals✝.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.2.2.1 locals✝.2.2.2.2.2.2.2.2.2.1

                                                                                                                                                                                      Coordinate conversion for composing this named observation.

                                                                                                                                                                                      The finite table of actual named source bodies.

                                                                                                                                                                                      Equations
                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                      Instances For
                                                                                                                                                                                        theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.guard_contract_iff (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) (pre✝ : ℕ → ℕ × ℕ → Heap → Prop) (normal✝ : ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop) (returned✝ : ℕ → ℕ × ℕ → Heap → Bool → ℕ → ℕ × ℕ → Heap → Prop) :
                                                                                                                                                                                        guard_contract step✝ operand✝ first✝ operand✝¹ initial start stop k pre✝ normal✝ returned✝ ↔ ∀ (index : ℕ) (acc : ℕ × ℕ) (heap : Heap), pre✝ index acc heap → ⦃fun (current : Heap) => { down := current = heap }⦄ guard step✝ operand✝ index acc first✝ operand✝¹ initial start stop k ⦃(fun (outcome : Control Ty.bool × Locals) (finish : Heap) => { down := match outcome.1 with | Control.normal => have after := outcome.2; normal✝ index acc heap after.2.2.1 after.2.2.2.1 finish | Control.returned value => have after := outcome.2; returned✝ index acc heap value after.2.2.1 after.2.2.2.1 finish | Control.fault a => False }, PUnit.unit)⦄

                                                                                                                                                                                        Introduce named mutable variables directly, without unpacking internal coordinates.

                                                                                                                                                                                        @[reducible, inline]
                                                                                                                                                                                        abbrev Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.body_contract :
                                                                                                                                                                                        ℕ → ℕ → ℕ × ℕ → ℕ × ℕ → (initial : ℕ × ℕ) → (start stop k : ℕ) → (ℕ → ℕ × ℕ → Heap → Prop) → (ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop) → (ℕ → ℕ × ℕ → Heap → ℕ × ℕ → ℕ → ℕ × ℕ → Heap → Prop) → Prop

                                                                                                                                                                                        Relational total correctness with ordinary mutable parameters and fixed captures. The existing block contract retains both actual heaps and excludes faults.

                                                                                                                                                                                        Equations
                                                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                                                        Instances For
                                                                                                                                                                                          @[reducible, inline]

                                                                                                                                                                                          The ordinary mutable locals of this source loop.

                                                                                                                                                                                          Equations
                                                                                                                                                                                          Instances For
                                                                                                                                                                                            theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.wellFounded_spec (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) (invariant✝ : ℕ → ℕ × ℕ → Heap → Prop) (relation✝ : Mutable × Heap → Mutable × Heap → Prop) :
                                                                                                                                                                                            WellFounded relation✝ → ∀ (normal : ℕ → ℕ × ℕ → Heap → Prop) (returned : ℕ × ℕ → ℕ → ℕ × ℕ → Heap → Prop), (∀ (index : ℕ) (acc : ℕ × ℕ) (startHeap : Heap), invariant✝ index acc startHeap → ⦃fun (currentHeap : Heap) => { down := currentHeap = startHeap }⦄ guard step✝ operand✝ index acc first✝ operand✝¹ initial start stop k ⦃(fun (guardOutcome : Control Ty.bool × Locals) (afterGuardHeap : Heap) => { down := have afterGuard_index := guardOutcome.2.2.2.1; have afterGuard_acc := guardOutcome.2.2.2.2.1; match guardOutcome.1 with | Control.returned again => if again = true then ⦃fun (currentHeap : Heap) => { down := currentHeap = afterGuardHeap }⦄ body step✝ operand✝ afterGuard_index afterGuard_acc first✝ operand✝¹ initial start stop k ⦃(fun (bodyOutcome : Control (Ty.nat.prod Ty.nat) × Locals) (afterBodyHeap : Heap) => { down := have afterBody_index := bodyOutcome.2.2.2.1; have afterBody_acc := bodyOutcome.2.2.2.2.1; match bodyOutcome.1 with | Control.normal => invariant✝ afterBody_index afterBody_acc afterBodyHeap ∧ relation✝ ((afterBody_index, afterBody_acc, ()), afterBodyHeap) ((index, acc, ()), startHeap) | Control.returned value => returned value afterBody_index afterBody_acc afterBodyHeap | Control.fault a => False }, PUnit.unit)⦄ else normal afterGuard_index afterGuard_acc afterGuardHeap | Control.normal => False | Control.fault a => False }, PUnit.unit)⦄) → ∀ (index : ℕ) (acc : ℕ × ℕ), ⦃fun (heap : Heap) => { down := invariant✝ index acc heap }⦄ sum_loop1 step✝ operand✝ index acc first✝ operand✝¹ initial start stop k ⦃(fun (outcome : Control (Ty.nat.prod Ty.nat) × Locals) (heap : Heap) => { down := have final_index := outcome.2.2.2.1; have final_acc := outcome.2.2.2.2.1; match outcome.1 with | Control.normal => normal final_index final_acc heap | Control.returned value => returned value final_index final_acc heap | Control.fault a => False }, PUnit.unit)⦄

                                                                                                                                                                                            Prove this actual loop with fixed captures and well-founded progress on its mutable locals. Only normal body exits must decrease; guard effects, returns and faults retain their real heap.

                                                                                                                                                                                            Source lexical immutability preserves these captures on every actual exit.

                                                                                                                                                                                            noncomputable def Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.guard :
                                                                                                                                                                                            ℕ → ℕ → ℕ → ℕ × ℕ → ℕ × ℕ → ℕ × ℕ → (initial : ℕ × ℕ) → (start stop k : ℕ) → StateT Heap Part (Control Ty.bool × Locals)

                                                                                                                                                                                            The actual source block observed with ordinary named local inputs.

                                                                                                                                                                                            Equations
                                                                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                                                                            Instances For
                                                                                                                                                                                              theorem Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.spec (step✝ operand✝ : ℕ) (first✝ operand✝¹ initial : ℕ × ℕ) (start stop k : ℕ) {pre✝ : ℕ → ℕ × ℕ → Heap → Prop} {normal✝ : ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop} {returned✝ : ℕ → ℕ × ℕ → Heap → ℕ × ℕ → ℕ → ℕ × ℕ → Heap → Prop} :
                                                                                                                                                                                              contract step✝ operand✝ first✝ operand✝¹ initial start stop k pre✝ normal✝ returned✝ → ∀ (index : ℕ) (acc : ℕ × ℕ) (post : Std.Do.PostCond (Control (Ty.nat.prod Ty.nat) × Locals) (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure)), ⦃fun (heap : Heap) => { down := pre✝ index acc heap ∧ (∀ (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap), normal✝ index acc heap after_index after_acc finish → (post.1 (Control.normal, step✝, operand✝, after_index, after_acc, first✝, operand✝¹, initial, start, stop, k, ()) finish).down) ∧ ∀ (value : ℕ × ℕ) (after_index : ℕ) (after_acc : ℕ × ℕ) (finish : Heap), returned✝ index acc heap value after_index after_acc finish → (post.1 (Control.returned value, step✝, operand✝, after_index, after_acc, first✝, operand✝¹, initial, start, stop, k, ()) finish).down }⦄ sum_loop1 step✝ operand✝ index acc first✝ operand✝¹ initial start stop k ⦃post⦄

                                                                                                                                                                                              Apply a chosen mathematical contract to the native block action. Continuations see ordinary mutable outputs; proved frames restore the fixed captures.

                                                                                                                                                                                              theorem Complexity.Language.Examples.Scalar.StructuredRange.add_total :
                                                                                                                                                                                              FunctionTotal program addId (fun (x : Env signatures[addId].params) (x_1 : Heap) => True) fun (arguments : Env signatures[addId].params) (initialHeap : Heap) (value : Value signatures[addId].result) (finalHeap : Heap) => value = (add ((fun (raw : ℕ × ℕ) => { value := raw.1, limit := raw.2 }) arguments.head) ((fun (raw : ℕ) => raw) arguments.tail.head)).sourceEncode ∧ finalHeap = initialHeap

                                                                                                                                                                                              Exact total source contract inherited from the generated native function.

                                                                                                                                                                                              @[reducible, inline]
                                                                                                                                                                                              abbrev Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.native_guard_contract :
                                                                                                                                                                                              ℕ → ℕ → BoundedInput → BoundedInput → (initial : BoundedInput) → (start stop k : ℕ) → (ℕ → BoundedInput → Heap → Prop) → (ℕ → BoundedInput → Heap → ℕ → BoundedInput → Heap → Prop) → (ℕ → BoundedInput → Heap → Bool → ℕ → BoundedInput → Heap → Prop) → Prop

                                                                                                                                                                                              The actual block contract with native mutable parameters and fixed captures. Only the returned predicate decodes the source value; control and both heaps stay unchanged.

                                                                                                                                                                                              Equations
                                                                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                                                                              Instances For

                                                                                                                                                                                                The actual parsed lexical body, with its enclosing return type.

                                                                                                                                                                                                Equations
                                                                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                Instances For
                                                                                                                                                                                                  @[reducible, inline]
                                                                                                                                                                                                  abbrev Complexity.Language.Examples.Scalar.StructuredRange.sum_loop1.contract :
                                                                                                                                                                                                  ℕ → ℕ → ℕ × ℕ → ℕ × ℕ → (initial : ℕ × ℕ) → (start stop k : ℕ) → (ℕ → ℕ × ℕ → Heap → Prop) → (ℕ → ℕ × ℕ → Heap → ℕ → ℕ × ℕ → Heap → Prop) → (ℕ → ℕ × ℕ → Heap → ℕ × ℕ → ℕ → ℕ × ℕ → Heap → Prop) → Prop

                                                                                                                                                                                                  Relational total correctness with ordinary mutable parameters and fixed captures. The existing block contract retains both actual heaps and excludes faults.

                                                                                                                                                                                                  Equations
                                                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                  Instances For

                                                                                                                                                                                                    The named function's actual independently interpreted source body.

                                                                                                                                                                                                    Equations
                                                                                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.StructuredRange.add_action_eq (input : ℕ × ℕ) (amount : ℕ) :
                                                                                                                                                                                                      add_action input amount = have operand := input; have operand := operand.1; have operand_1 := amount; have nativeOperand := operand.add operand_1; have operand := input; have nativeOperand_1 := operand.2; have operand := nativeOperand; have operand_2 := nativeOperand_1; pure (operand, operand_2)

                                                                                                                                                                                                      One source-body equation in ordinary monadic notation; named callees remain opaque.

                                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.structured_range_add_eq (input : BoundedInput) (amount : ℕ) :
                                                                                                                                                                                                      StructuredRange.add input amount = { value := input.value + amount, limit := input.limit }

                                                                                                                                                                                                      The structure-valued helper retains the original limit and adds one amount.

                                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.structured_range_sum_eq (initial : BoundedInput) (start stop k : ℕ) :
                                                                                                                                                                                                      StructuredRange.sum initial start stop k = { value := initial.value + (List.range' start ((stop - start + k) / (k + 1)) (k + 1)).sum, limit := initial.limit }

                                                                                                                                                                                                      A native structure remains the loop accumulator across actual source calls. Ordinary fold transport proves its mathematical sum and unchanged second field.

                                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.structured_range_sum_total :
                                                                                                                                                                                                      RepresentedFunction.Total StructuredRange.program StructuredRange.sumId StructuredRange.sum_representation (fun (x : BoundedInput × ℕ × ℕ × ℕ) => True) fun (input : BoundedInput × ℕ × ℕ × ℕ) (value : BoundedInput) => value = { value := input.1.value + (List.range' input.2.1 ((input.2.2.1 - input.2.1 + input.2.2.2) / (input.2.2.2 + 1)) (input.2.2.2 + 1)).sum, limit := input.1.limit }

                                                                                                                                                                                                      The mathematical structure equation transfers to the same terminating source function through generated correspondence, without a second loop proof.

                                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.Signed.squaredDistance_action_rel_native_preserving (left right : ℤ) (left_source✝ right_source✝ : Value (Ty.bool.prod Ty.nat)) (initialHeap✝ : Heap) :
                                                                                                                                                                                                      Representation.int.Rel left left_source✝ initialHeap✝ → Representation.int.Rel right right_source✝ initialHeap✝ → ∃ (returned : Value (Ty.bool.prod Ty.nat)) (finish : Heap), squaredDistance left_source✝ right_source✝ initialHeap✝ = Part.some (Except.ok returned, finish) ∧ Representation.int.Rel (squaredDistance_model left right) returned finish ∧ (fun (finish : Heap) => initialHeap✝.ShapeExtends finish ∧ Buffer.PreservesContents initialHeap✝ finish) finish

                                                                                                                                                                                                      Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

                                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.Signed.distance_eq (left right : Bool × ℕ) :
                                                                                                                                                                                                      distance left right = do let sourceValue ← Scalar.Int.Implementation.negate_action right let delta ← Scalar.Int.Implementation.add_action left sourceValue have operand : Bool × ℕ := (false, 0) let sourceValue ← Scalar.Int.Implementation.less_action operand delta have boolean : Bool := false have __do_jp : Bool → Unit → ExceptT Fault (StateT Heap Part) (Bool × ℕ) := fun (boolean : Bool) (y : Unit) => if boolean = true then do let sourceResult ← Scalar.Int.Implementation.negate_action delta pure sourceResult else pure delta if sourceValue = true then have boolean := false; do let y ← pure () __do_jp boolean y else have boolean := true; do let y ← pure () __do_jp boolean y

                                                                                                                                                                                                      One source-body equation in ordinary monadic notation; named callees remain opaque.

                                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.Signed.distance_total_iff (pre✝ : Bool × ℕ → Bool × ℕ → Heap → Prop) (post✝ : Bool × ℕ → Bool × ℕ → Heap → Bool × ℕ → Heap → Prop) :
                                                                                                                                                                                                      distance_contract pre✝ post✝ ↔ ∀ (left right : Bool × ℕ) (initialHeap : Heap), pre✝ left right initialHeap → ∃ (value : Bool × ℕ) (finalHeap : Heap), distance left right initialHeap = Part.some (Except.ok value, finalHeap) ∧ post✝ left right initialHeap value finalHeap

                                                                                                                                                                                                      The source contract is equivalent to ordinary curried preconditions and successful result/heap postconditions, including termination and absence of faults.

                                                                                                                                                                                                      @[reducible, inline]

                                                                                                                                                                                                      Apply a predicate, postcondition or bound with ordinary source parameters to the actual argument environment. No new contract or execution is introduced.

                                                                                                                                                                                                      Equations
                                                                                                                                                                                                      Instances For

                                                                                                                                                                                                        Fold an actual source invocation back to its named ordinary-argument observation.

                                                                                                                                                                                                        Ordinary arguments and the actual result observed in their real source heaps. This interface does not assert the existence of a total mathematical model.

                                                                                                                                                                                                        Equations
                                                                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                          @[reducible, inline]

                                                                                                                                                                                                          Signatures of the functions added by this source declaration.

                                                                                                                                                                                                          Equations
                                                                                                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                            @[reducible, inline]

                                                                                                                                                                                                            Budget-free total correctness with ordinary source parameters and relational initial/final heap postconditions. This is the existing source function contract.

                                                                                                                                                                                                            Equations
                                                                                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                            Instances For

                                                                                                                                                                                                              The named function's actual partial source action, with ordinary typed arguments and an explicitly supplied shared heap.

                                                                                                                                                                                                              Equations
                                                                                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                              Instances For

                                                                                                                                                                                                                The finite table of actual named source bodies.

                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                  theorem Complexity.Language.Examples.Scalar.Signed.distance_contract_iff_triple (pre✝ : Bool × ℕ → Bool × ℕ → Heap → Prop) (post✝ : Bool × ℕ → Bool × ℕ → Heap → Bool × ℕ → Heap → Prop) :
                                                                                                                                                                                                                  distance_contract pre✝ post✝ ↔ ∀ (left right : Bool × ℕ) (initialHeap : Heap), ⦃fun (currentHeap : Heap) => { down := currentHeap = initialHeap ∧ pre✝ left right initialHeap }⦄ distance left right ⦃(fun (value : Bool × ℕ) (finalHeap : Heap) => { down := post✝ left right initialHeap value finalHeap }, fun (x : Fault) (x_1 : Heap) => { down := False }, PUnit.unit)⦄

                                                                                                                                                                                                                  Prove the ordinary-parameter source contract with a total-correctness triple for the same action. The ghost initial heap equals the actual entry heap; successful results use the actual final heap, and faults are excluded.

                                                                                                                                                                                                                  theorem Complexity.Language.Examples.Scalar.Signed.squaredDistance_action_rel_native (left right : ℤ) (left_source✝ right_source✝ : Value (Ty.bool.prod Ty.nat)) (initialHeap✝ : Heap) :
                                                                                                                                                                                                                  Representation.int.Rel left left_source✝ initialHeap✝ → Representation.int.Rel right right_source✝ initialHeap✝ → ∃ (returned : Value (Ty.bool.prod Ty.nat)) (finish : Heap), squaredDistance left_source✝ right_source✝ initialHeap✝ = Part.some (Except.ok returned, finish) ∧ Representation.int.Rel (squaredDistance_model left right) returned finish ∧ (fun (finish : Heap) => initialHeap✝.ShapeExtends finish) finish

                                                                                                                                                                                                                  Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

                                                                                                                                                                                                                  theorem Complexity.Language.Examples.Scalar.Signed.distance_action_rel_native_preserving (left right : ℤ) (left_source✝ right_source✝ : Value (Ty.bool.prod Ty.nat)) (initialHeap✝ : Heap) :
                                                                                                                                                                                                                  Representation.int.Rel left left_source✝ initialHeap✝ → Representation.int.Rel right right_source✝ initialHeap✝ → ∃ (returned : Value (Ty.bool.prod Ty.nat)) (finish : Heap), distance left_source✝ right_source✝ initialHeap✝ = Part.some (Except.ok returned, finish) ∧ Representation.int.Rel (distance_model left right) returned finish ∧ (fun (finish : Heap) => initialHeap✝.ShapeExtends finish ∧ Buffer.PreservesContents initialHeap✝ finish) finish

                                                                                                                                                                                                                  Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

                                                                                                                                                                                                                  The named function's actual independently interpreted source body.

                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                  Instances For

                                                                                                                                                                                                                    Ordinary arguments and the actual result observed in their real source heaps. This interface does not assert the existence of a total mathematical model.

                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.Signed.squaredDistance_total_iff (pre✝ : Bool × ℕ → Bool × ℕ → Heap → Prop) (post✝ : Bool × ℕ → Bool × ℕ → Heap → Bool × ℕ → Heap → Prop) :
                                                                                                                                                                                                                      squaredDistance_contract pre✝ post✝ ↔ ∀ (left right : Bool × ℕ) (initialHeap : Heap), pre✝ left right initialHeap → ∃ (value : Bool × ℕ) (finalHeap : Heap), squaredDistance left right initialHeap = Part.some (Except.ok value, finalHeap) ∧ post✝ left right initialHeap value finalHeap

                                                                                                                                                                                                                      The source contract is equivalent to ordinary curried preconditions and successful result/heap postconditions, including termination and absence of faults.

                                                                                                                                                                                                                      Ordinary mathematical function generated from the same represented source block.

                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                        @[reducible, inline]

                                                                                                                                                                                                                        Budget-free total correctness with ordinary source parameters and relational initial/final heap postconditions. This is the existing source function contract.

                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                          @[reducible, inline]

                                                                                                                                                                                                                          The actual declared argument environment, constructed from ordinary source parameters. This is proof-side parameter transport, not an additional runtime operation.

                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                          Instances For

                                                                                                                                                                                                                            The named function's actual independently interpreted source body.

                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                            Instances For

                                                                                                                                                                                                                              Added function bodies already typed against the complete linked table.

                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                              Instances For

                                                                                                                                                                                                                                The named function's actual partial source action, with ordinary typed arguments and an explicitly supplied shared heap.

                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                  theorem Complexity.Language.Examples.Scalar.Signed.squaredDistance_spec {pre✝ : Env [Ty.bool.prod Ty.nat, Ty.bool.prod Ty.nat] → Heap → Prop} {post✝ : Env [Ty.bool.prod Ty.nat, Ty.bool.prod Ty.nat] → Heap → Bool × ℕ → Heap → Prop} :
                                                                                                                                                                                                                                  FunctionTotal program squaredDistanceId pre✝ post✝ → ∀ (left right : Bool × ℕ) (continuation : Std.Do.PostCond (Bool × ℕ) (Std.Do.PostShape.except Fault (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure))), ⦃fun (initialHeap : Heap) => { down := pre✝ (Env.cons left (Env.cons right Env.empty)) initialHeap ∧ ∀ (value : Bool × ℕ) (finalHeap : Heap), post✝ (Env.cons left (Env.cons right Env.empty)) initialHeap value finalHeap → (continuation.1 value finalHeap).down }⦄ squaredDistance left right ⦃continuation⦄

                                                                                                                                                                                                                                  Apply a supplied source contract with ordinary named arguments and its actual returned value and final heap. No callee body or new contract is inferred.

                                                                                                                                                                                                                                  @[reducible, inline]

                                                                                                                                                                                                                                  The actual declared argument environment, constructed from ordinary source parameters. This is proof-side parameter transport, not an additional runtime operation.

                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                    theorem Complexity.Language.Examples.Scalar.Signed.distance_spec {pre✝ : Env [Ty.bool.prod Ty.nat, Ty.bool.prod Ty.nat] → Heap → Prop} {post✝ : Env [Ty.bool.prod Ty.nat, Ty.bool.prod Ty.nat] → Heap → Bool × ℕ → Heap → Prop} :
                                                                                                                                                                                                                                    FunctionTotal program distanceId pre✝ post✝ → ∀ (left right : Bool × ℕ) (continuation : Std.Do.PostCond (Bool × ℕ) (Std.Do.PostShape.except Fault (Std.Do.PostShape.arg Heap Std.Do.PostShape.pure))), ⦃fun (initialHeap : Heap) => { down := pre✝ (Env.cons left (Env.cons right Env.empty)) initialHeap ∧ ∀ (value : Bool × ℕ) (finalHeap : Heap), post✝ (Env.cons left (Env.cons right Env.empty)) initialHeap value finalHeap → (continuation.1 value finalHeap).down }⦄ distance left right ⦃continuation⦄

                                                                                                                                                                                                                                    Apply a supplied source contract with ordinary named arguments and its actual returned value and final heap. No callee body or new contract is inferred.

                                                                                                                                                                                                                                    theorem Complexity.Language.Examples.Scalar.Signed.squaredDistance_action_eq_native (left right : ℤ) (left_source✝ right_source✝ : Value (Ty.bool.prod Ty.nat)) (initialHeap✝ : Heap) :
                                                                                                                                                                                                                                    Representation.int.Rel left left_source✝ initialHeap✝ → Representation.int.Rel right right_source✝ initialHeap✝ → squaredDistance left_source✝ right_source✝ initialHeap✝ = Part.some (Except.ok (Representation.intEquiv.toEmbedding (squaredDistance_model left right)), initialHeap✝)

                                                                                                                                                                                                                                    The same source execution returns the encoded mathematical result without changing its supplied heap, under the actual input representations.

                                                                                                                                                                                                                                    Ordinary mathematical function generated from the same represented source block.

                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                    • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                    Instances For

                                                                                                                                                                                                                                      Fold an actual source invocation back to its named ordinary-argument observation.

                                                                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.Signed.squaredDistance_contract_iff_triple (pre✝ : Bool × ℕ → Bool × ℕ → Heap → Prop) (post✝ : Bool × ℕ → Bool × ℕ → Heap → Bool × ℕ → Heap → Prop) :
                                                                                                                                                                                                                                      squaredDistance_contract pre✝ post✝ ↔ ∀ (left right : Bool × ℕ) (initialHeap : Heap), ⦃fun (currentHeap : Heap) => { down := currentHeap = initialHeap ∧ pre✝ left right initialHeap }⦄ squaredDistance left right ⦃(fun (value : Bool × ℕ) (finalHeap : Heap) => { down := post✝ left right initialHeap value finalHeap }, fun (x : Fault) (x_1 : Heap) => { down := False }, PUnit.unit)⦄

                                                                                                                                                                                                                                      Prove the ordinary-parameter source contract with a total-correctness triple for the same action. The ghost initial heap equals the actual entry heap; successful results use the actual final heap, and faults are excluded.

                                                                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.Signed.squaredDistance_eq (left right : Bool × ℕ) :
                                                                                                                                                                                                                                      squaredDistance left right = do let sourceValue ← Scalar.Int.Implementation.negate_action right let delta ← Scalar.Int.Implementation.add_action left sourceValue let sourceResult ← Scalar.Int.Implementation.mul_action delta delta pure sourceResult

                                                                                                                                                                                                                                      One source-body equation in ordinary monadic notation; named callees remain opaque.

                                                                                                                                                                                                                                      theorem Complexity.Language.Examples.Scalar.Signed.distance_action_eq_native (left right : ℤ) (left_source✝ right_source✝ : Value (Ty.bool.prod Ty.nat)) (initialHeap✝ : Heap) :
                                                                                                                                                                                                                                      Representation.int.Rel left left_source✝ initialHeap✝ → Representation.int.Rel right right_source✝ initialHeap✝ → distance left_source✝ right_source✝ initialHeap✝ = Part.some (Except.ok (Representation.intEquiv.toEmbedding (distance_model left right)), initialHeap✝)

                                                                                                                                                                                                                                      The same source execution returns the encoded mathematical result without changing its supplied heap, under the actual input representations.

                                                                                                                                                                                                                                      Automatic correspondence for the same generated source function, without a machine budget.

                                                                                                                                                                                                                                      Automatic correspondence for the same generated source function, without a machine budget.

                                                                                                                                                                                                                                      @[reducible, inline]

                                                                                                                                                                                                                                      Signature-preserving positions of this imported source program.

                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                        @[reducible, inline]

                                                                                                                                                                                                                                        Apply a predicate, postcondition or bound with ordinary source parameters to the actual argument environment. No new contract or execution is introduced.

                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                          theorem Complexity.Language.Examples.Scalar.Signed.distance_action_rel_native (left right : ℤ) (left_source✝ right_source✝ : Value (Ty.bool.prod Ty.nat)) (initialHeap✝ : Heap) :
                                                                                                                                                                                                                                          Representation.int.Rel left left_source✝ initialHeap✝ → Representation.int.Rel right right_source✝ initialHeap✝ → ∃ (returned : Value (Ty.bool.prod Ty.nat)) (finish : Heap), distance left_source✝ right_source✝ initialHeap✝ = Part.some (Except.ok returned, finish) ∧ Representation.int.Rel (distance_model left right) returned finish ∧ (fun (finish : Heap) => initialHeap✝.ShapeExtends finish) finish

                                                                                                                                                                                                                                          Successful execution observes the native result in its actual final heap and retains every previously represented immutable list.

                                                                                                                                                                                                                                          Ordinary integer subtraction and absolute value describe the actual signed source calls. The algorithm proof does not mention their sign/magnitude fields.

                                                                                                                                                                                                                                          Generated correspondence transfers the mathematical equation to the same source function, independently of word bounds or an instruction budget.

                                                                                                                                                                                                                                          Multiplication reuses the ordinary integer square, not a proof about the two natural fields used by its implementation.