ResultLoopPartial

Lean checked

Statement

This explanation was written alongside the formalization to describe the statement and its reasoning.

Helper

Let a result-valued loop body either continue with another state or finish with an output. Suppose a predicate is preserved by every normally returning continuation, and every normally returning finish satisfies a postcondition. Then any normal return of the Aeneas loop from a state satisfying the predicate satisfies that postcondition.

Lean statement

Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.

import Tablet.num_imp_dec2flt_slow_parse_long_mantissa

open Aeneas Aeneas.Std Result ControlFlow Error
open Lean Order
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ResultLoopPartial]
theorem ResultLoopPartial {α β : Type}
    (inv : α → Prop) (post : β → Prop)
    (body : α → Result (ControlFlow α β))
    (hbody : ∀ x, inv x → ∀ r, body x = ok r →
      match r with
      | done y => post y
      | cont x' => inv x') :
    ∀ x y, inv x → Aeneas.Std.loop body x = ok y → post y := by
Proof

Natural-language proof

The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.

Explanatory prose status

Prose retained as authored. The explanatory prose is preserved as it stood when captured.

Proof

Use the least-fixpoint induction principle for the Aeneas result-valued loop. The asserted property of a loop approximation is: for every invariant state, if the approximation returns an output normally, that output satisfies the postcondition. This property is admissible because result values carry the flat order: an approximation below a normally returned value is that same returned value. For the induction step, evaluate the body. Failure or divergence cannot equal a normal return. A finished body result satisfies the postcondition by the body hypothesis. A continuation satisfies the invariant by that same hypothesis, so applying the induction hypothesis to the recursive loop call yields the postcondition. Fixpoint induction therefore gives the claim for the loop itself.

Lean proof


  refine Aeneas.Std.loop.fixpoint_induct body
    (fun f => ∀ x y, inv x → f x = ok y → post y) ?_ ?_
  · refine admissible_pi_apply
      (fun x r => ∀ y, inv x → r = ok y → post y) ?_
    intro x
    apply admissible_flatOrder
    intro y hx h
    cases h
  · intro f ih x y hx heq
    dsimp only at heq
    cases hb : body x with
    | fail e => simp [hb] at heq
    | div => simp [hb] at heq
    | ok r =>
      cases r with
      | done z =>
        simp only [hb] at heq
        cases heq
        exact hbody x hx (done y) hb
      | cont x' =>
        simp only [hb] at heq
        exact ih x' y (hbody x hx (cont x') hb) heq

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa

open Aeneas Aeneas.Std Result ControlFlow Error
open Lean Order
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ResultLoopPartial]
theorem ResultLoopPartial {α β : Type}
    (inv : α → Prop) (post : β → Prop)
    (body : α → Result (ControlFlow α β))
    (hbody : ∀ x, inv x → ∀ r, body x = ok r →
      match r with
      | done y => post y
      | cont x' => inv x') :
    ∀ x y, inv x → Aeneas.Std.loop body x = ok y → post y := by
-- BODY
  refine Aeneas.Std.loop.fixpoint_induct body
    (fun f => ∀ x y, inv x → f x = ok y → post y) ?_ ?_
  · refine admissible_pi_apply
      (fun x r => ∀ y, inv x → r = ok y → post y) ?_
    intro x
    apply admissible_flatOrder
    intro y hx h
    cases h
  · intro f ih x y hx heq
    dsimp only at heq
    cases hb : body x with
    | fail e => simp [hb] at heq
    | div => simp [hb] at heq
    | ok r =>
      cases r with
      | done z =>
        simp only [hb] at heq
        cases heq
        exact hbody x hx (done y) hb
      | cont x' =>
        simp only [hb] at heq
        exact ih x' y (hbody x hx (cont x') hb) heq

end dec2flt_model

Proof structure

Follow the declared dependencies to read the supporting statements and proofs.

Explore this dependency tree

Inspect related source (116)
More program dependencies (83)
Standard-library dependencies (30)

Related source and models come from the extraction records and declared dependencies.

Proof assumptions and review

Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.

Transitive assumptions

This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.

Helper theorems included
Technical checking records
Local closure summary
{
  "node": "ResultLoopPartial",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "8db16d5a9cf60da35105053ab4cc9e49279a400a6a246f1d6d00502e07d1eae7",
  "active_statement_hash": "4eb49d4b17ef2c144f7500c6643afdc66e60a5311fe8661ec4663b0a2f37e0cf",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-132",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {}
}
Prose assessment
{
  "label": "Lean proof closed; predictive prose review no longer required",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "sound-v2:f50483ed5eff837b24a3e8e0311e6391174f0bdf4a747f2372db1a79d06cfffc",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}