P826_T1_ResultLoopBackward

Lean checked

Statement

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

Helper · Backward induction for an extracted partial loop

Let a loop body on states of type \alpha return either a continuation state or a completed value of type \beta. Let R(x,y) be a relation between an input state and a completed value. Assume that every successful done step from x to y establishes R(x,y), and every successful continuation from x to x' transports R(x',y) backward to R(x,y). Then every successful evaluation of the extracted partial loop from x to y establishes R(x,y).

Lean statement

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

import Tablet.ResultLoopPartial

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

namespace dec2flt_model

-- [TABLET NODE: P826_T1_ResultLoopBackward]
theorem P826_T1_ResultLoopBackward {alpha beta : Type}
    (rel : alpha -> beta -> Prop)
    (body : alpha -> Result (ControlFlow alpha beta))
    (hdone : forall x y, body x = ok (done y) -> rel x y)
    (hcont : forall x x' y,
      body x = ok (cont x') -> rel x' y -> rel x y) :
    forall x y, Aeneas.Std.loop body x = ok y -> rel x 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

Apply fixed-point induction to the partial loop functional, with induction predicate saying that every successful result y of the current approximation from x satisfies R(x,y). The predicate is admissible in the flat result order: the only nontrivial approximant comparison is from divergence, and divergence cannot equal a successful result. For the fixed-point step, evaluate the body at x. Failure or divergence cannot produce the assumed successful loop result. A done result is handled by the done hypothesis. A continuation result x' reduces the loop evaluation to the recursive evaluation from x'; fixed-point induction gives R(x',y), and the continuation hypothesis gives R(x,y). This is the desired backward induction rule. It is the backward analogue of the forward invariant rule packaged by ResultLoopPartial.

Lean proof


  refine Aeneas.Std.loop.fixpoint_induct body
    (fun f => forall x y, f x = ok y -> rel x y) ?_ ?_
  · refine admissible_pi_apply
      (fun x r => forall y, r = ok y -> rel x y) ?_
    intro x
    apply admissible_flatOrder
    intro y h
    cases h
  · intro f ih x y 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 hdone x y hb
      | cont x' =>
        simp only [hb] at heq
        exact hcont x x' y hb (ih x' y heq)

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.ResultLoopPartial

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

namespace dec2flt_model

-- [TABLET NODE: P826_T1_ResultLoopBackward]
theorem P826_T1_ResultLoopBackward {alpha beta : Type}
    (rel : alpha -> beta -> Prop)
    (body : alpha -> Result (ControlFlow alpha beta))
    (hdone : forall x y, body x = ok (done y) -> rel x y)
    (hcont : forall x x' y,
      body x = ok (cont x') -> rel x' y -> rel x y) :
    forall x y, Aeneas.Std.loop body x = ok y -> rel x y := by
-- BODY
  refine Aeneas.Std.loop.fixpoint_induct body
    (fun f => forall x y, f x = ok y -> rel x y) ?_ ?_
  · refine admissible_pi_apply
      (fun x r => forall y, r = ok y -> rel x y) ?_
    intro x
    apply admissible_flatOrder
    intro y h
    cases h
  · intro f ih x y 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 hdone x y hb
      | cont x' =>
        simp only [hb] at heq
        exact hcont x x' y hb (ih x' y 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": "P826_T1_ResultLoopBackward",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "10d9776ccfaf5390ac3667a0f3c4b805d53d0e7b9a84af21aed423a85b3ecefe",
  "active_statement_hash": "6fd805c52775b6889fc51d68b989b4a00a7f5b1a73c57c769359b1ad963c3265",
  "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": "revalidate-cycle-194",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "ResultLoopPartial": "4dc847904b42b317"
  },
  "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:99772748057e707d0b3057012acc028e00e4d91e8710f7c522277a4e7aecf756",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}