P529_T1_LeftHistoryBoundary

Lean checked

Statement

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

Lemma · Capacity and boundary order on the actual left history

Let d_0 have positive exact-length decimal shape and count at most 768, -324\le p_0\le0, and e_0\ge0. Assume ordered fixed endpoints X/2^{e_0}=V(d_0)+\eta, Y/2^{e_0}=V(d_0)+u, 0\le\eta<u, sticky iff \eta>0. Suppose the actual specialized loop-one call with sentinel (0,2047) and None returns (d_1,e_1,\mathsf{none}). Then
0\le e_1-e_0+768-p_0,\qquad 2^{e_1-e_0}\le V(d_0)\Longrightarrow1\le V(d_1).
Also for every natural coefficient c and integer R, if 0\le R-e_0+768-p_0, then
0\le R-e_1+768-p_1,\qquad V(d_1)<c2^{R-e_1}\Longrightarrow V(d_0)<c2^{R-e_0}.

Lean statement

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

import Tablet.P529_T1_Loop1Execution
import Tablet.P529_T1_LeftShiftCertificate
import Tablet.SlowShiftSelectorCertificate
import Tablet.P826_T1_ResultLoopBackward
import Tablet.P856_T1_CoefficientGridAlignment
import Tablet.P798_T1_LeftBoundaryTransport
import Tablet.P472_T1_DecimalValueBounds
import Tablet.P844_T1_LeftHistoryInvariant
import Tablet.P844_T1_LeftStepPotential
import Tablet.P844_T1_LeftCoefficientTransport
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_LeftHistoryBoundary]
theorem P529_T1_LeftHistoryBoundary (X Y : Real)
    (d0 d1 : num.imp.dec2flt.decimal_seq.DecimalSeq) (exp0 exp1 : Std.I32)
    (hpointLo : -324 <= d0.decimal_point.val)
    (hpointHi : d0.decimal_point.val <= 0) (hexpLo : 0 <= exp0.val)
    (hinput : d0.num_digits.val <= 768 /\
      (forall b, b ∈ d0.digits.val.take d0.num_digits.val -> b.val < 10) /\
      (exists h tail,
        (d0.digits.val.take d0.num_digits.val).map (fun b => b.val) = h :: tail /\
        1 <= h /\ h < 10 /\ (h :: tail).length = d0.num_digits.val))
    (hcall : num.imp.dec2flt.slow.parse_long_mantissa_loop1
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 2047#i32 }
      d0.num_digits d0.decimal_point d0.truncated d0.digits exp0 none =
        ok (d1.num_digits, d1.decimal_point, d1.truncated, d1.digits, exp1, none)) :
    let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      ((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
        (fun n z => 10 * n + z) 0 : Nat) : Real) *
        (10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
    (exists eta u : Real,
      X / (2 : Real) ^ exp0.val = V d0 + eta /\
      Y / (2 : Real) ^ exp0.val = V d0 + u /\
      0 <= eta /\ eta < u /\ (d0.truncated = true <-> 0 < eta)) ->
    0 <= exp1.val - exp0.val + 768 - d0.decimal_point.val /\
    ((2 : Real) ^ (exp1.val - exp0.val) <= V d0 -> 1 <= V d1) /\
    (forall (c : Nat) (R : Int),
      0 <= R - exp0.val + 768 - d0.decimal_point.val ->
      0 <= R - exp1.val + 768 - d1.decimal_point.val /\
      (V d1 < (c : Real) * (2 : Real) ^ (R - exp1.val) ->
        V d0 < (c : Real) * (2 : Real) ^ (R - exp0.val))) := 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

Construct the normal call by Loop1Execution and identify its final state with the hypothesized one by injectivity of ok. It supplies final point zero, positive decimal shape, and e_1\ge e_0-1260\ge-1260. We describe conditional transitions on the given normal history, so no unexported counter or termination count from that theorem is used. Unfold the body in num imp dec2flt slow parse long mantissa. For a positive-shaped state with -324\le p\le0, a continuing normal body uses the literal negative-point selector or point-zero match. SlowShiftSelectorCertificate, SelectedLeftGrowth, and PointZeroGrowth give its selected k\le60 and growth. Apply LeftShiftCertificate at that k. Injectivity identifies the constructed shift with the normal body's shift. The shape and endpoints persist and -324\le p'\le0. The None option remains None, since the infinity comparison is false. The cast of k is exact; the successful subtraction in the given body has value e'=e-k. Thus exponents never increase. The shape/point/None invariant is justified by the forward rule ResultLoopPartial; the normal history can equally be inductively unfolded using ResultLoopBackward. Every intermediate exponent is at least the terminal e_1, since each remaining update subtracts a nonnegative shift. Therefore it is at least -1260, and LeftLoopStep applies at every such state. Its principal supplies all correlated point/head transitions used below. A normal done state is unchanged, with point zero and head at least five.
For the first capacity use the head bonus
H(p,z)= \begin{cases} 36,&p=-1,\ z\ge7,\\ 27,&p=-1,\ z<7,\\ 36,&p=0,\ z\ge5,\\ 33,&p=0,\ 3\le z<5,\\ 27,&p=0,\ z<3,\\ 0,&\text{otherwise}. \end{cases}
Every continuation satisfies
H(p,z)+3k\le H(p',z')+10(p'-p),\qquad p'-p\le k. \tag{1}
Here is the full arithmetic verification from the literal selector. For p\le-19, k=60, growth is 18 or 19, and the input bonus is zero, so 180\le10(p'-p)+H(p',z') and growth is at most 60. For p=-1, k=3. A stall has input bonus 27 and output bonus 36; the recovery clause rules out an input head at least seven. A move to zero with input head at least seven has both bonuses 36, giving 36+9\le36+10. With a smaller head the input bonus is 27 and the output bonus is at least 27, which suffices. Its growth is zero or one, at most three. For p=0, growth is zero. A head at most two has input bonus 27, output bonus at least 33, and shift at most two; a head three or four has bonuses 33 and 36 and shift one. For -18\le p\le-2, put n=-p\in[2,18]. The input bonus is zero, output bonus at least 27, and growth is n-1 or n. The literal row k=6,9,13,16,19,23,26,29,33,36,39,43,46,49,53,56,59 gives 3k\le10n and n\le k in each corresponding case. Since 10n\le27+10(n-1), (1) follows for either growth. These regimes exhaust every continuation.
Put C=e_1-e+768-p. Apply backward induction along the exact history with simultaneous assertions
7(p+324)+H(p,z)\le3C,\qquad 2^{e_1-e}\le V(a)\Longrightarrow1\le V(d_1). \tag{2}
At the final done state, p=0, e=e_1 and H=36. Both sides of the capacity assertion equal 2304. The order implication is its own premise since 2^0=1. On a continuation e'=e-k, the successor capacity C' is nonnegative by its (2), because p'\ge-324 and H'\ge0. Substitute C=C'-k+(p'-p) into (2) at the successor; the first inequality in (1) gives (2) at the predecessor. For order, align 2^{e_1-e'} on the successor grid by CoefficientGridAlignment with coefficient one: p'\le0\le768 and C'\ge0 are precisely its hypotheses. The assumption 2^{e_1-e}\le V(a) multiplies by 2^k to put that successor boundary below 2^kV(a). Positive input value follows from DecimalValueBounds; output count and the actual call come from the step. LeftBoundaryTransport therefore puts the boundary below V(a'), and the successor implication proves order at the predecessor. The backward loop rule now proves (2) at d_0. Nonnegativity of its left side gives the first stated capacity and its order component gives the first stated implication.
For a general c,R, put C_R=R-e+768-p. The second inequality in (1) gives C_R'=C_R+k-(p'-p)\ge C_R, so input capacity propagates forward. At each successor CoefficientGridAlignment aligns c2^{R-e'} there. If c2^{R-e}\le V(a), the same left-boundary transport gives c2^{R-e'}\le V(a'). Iterating through the exact history gives c2^{R-e_0}\le V(d_0)\Longrightarrow c2^{R-e_1}\le V(d_1) and terminal capacity. Contraposition is the claimed strict-order implication. This proves all conclusions with grid premises at their actual application states.

Lean proof


  classical
  intro V hend0
  let State := Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
    Std.I32 × Option num.imp.dec2flt.common.BiasedFp
  let recOf := fun (s : State) =>
    ({ num_digits := s.1, decimal_point := s.2.1,
       truncated := s.2.2.1, digits := s.2.2.2.1 } :
      num.imp.dec2flt.decimal_seq.DecimalSeq)
  let P := fun (s : State) => s.2.1.val
  let E := fun (s : State) => s.2.2.2.2.1.val
  let headOf := fun (s : State) =>
    (((recOf s).digits.val.take (recOf s).num_digits.val).map
      (fun b => b.val)).headD 0
  let B := fun (p : Int) (z : Nat) =>
    (if p = -1 then if 7 <= z then 36 else 27
     else if p = 0 then if 5 <= z then 36 else if 3 <= z then 33 else 27
     else 0 : Int)
  let H := fun (s : State) => B (P s) (headOf s)
  let step : State -> Result (ControlFlow State State) := fun s =>
    num.imp.dec2flt.slow.parse_long_mantissa_loop1.body
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 2047#i32 }
      s.1 s.2.1 s.2.2.1 s.2.2.2.1 s.2.2.2.2.1 s.2.2.2.2.2
  let s0 : State := (d0.num_digits, d0.decimal_point, d0.truncated,
    d0.digits, exp0, none)
  let s1 : State := (d1.num_digits, d1.decimal_point, d1.truncated,
    d1.digits, exp1, none)
  obtain ⟨Inv, hstart, hsafe, hclosed⟩ := P844_T1_LeftHistoryInvariant
    X Y d0 exp0 hpointLo hpointHi hexpLo hinput hend0
  have hnonneg (s : State) : 0 <= H s := by
    dsimp only [H, B]
    split_ifs <;> omega
  have hstep (s : State) (hs : Inv s) :
      (step s = ok (done s) /\ P s = 0 /\ H s = 36) \/
      exists (t : State) (k : Std.Usize),
        step s = ok (cont t) /\ Inv t /\
        num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift (recOf s) k = ok (recOf t) /\
        k.val <= 60 /\ E t = E s - (k.val : Int) /\
        H s + 3 * (k.val : Int) <= H t + 10 * (P t - P s) /\
        P t - P s <= (k.val : Int) := by
    obtain ⟨hnone, hpLo, hpHi, heLo, hcap, hdigit, hshape, hend⟩ := hsafe s hs
    have hprincipal := P529_T1_LeftLoopStep
      (X / (2 : Real) ^ E s) (Y / (2 : Real) ^ E s)
      (recOf s) s.2.2.2.2.1 hpLo hpHi heLo ⟨hcap, hdigit, hshape⟩ hend
    rcases hprincipal with hdone | hcont
    · obtain ⟨hb, hp0, hz5⟩ := hdone
      have hbody : step s = ok (done s) := by
        have hsEta : (s.1, s.2.1, s.2.2.1, s.2.2.2.1, s.2.2.2.2.1, none) = s := by
          rw [← hnone]
        simpa only [step, recOf, hnone, hsEta] using hb
      obtain ⟨z, zs, hmap, hzlo, hzhi, hlen⟩ := hshape
      have hnpos : 0 < (recOf s).num_digits.val := by
        rw [← hlen]
        simp
      have hidx : 0 < (recOf s).digits.val.length := by
        have harray : (recOf s).digits.val.length = 768 := by
          simpa using (recOf s).digits.property
        omega
      have hread := congrArg (fun l : List Nat => l[0]?) hmap
      simp only [List.getElem?_cons_zero, List.getElem?_map] at hread
      rw [List.getElem?_take_of_lt hnpos] at hread
      rw [List.getElem?_eq_getElem hidx, Option.map_some] at hread
      have hz : 5 <= z := by
        have heq := Option.some.inj hread
        omega
      have hhead : headOf s = z := by dsimp only [headOf]; rw [hmap]; rfl
      refine Or.inl ⟨hbody, hp0, ?_⟩
      simp only [H, hhead, B, show P s = 0 from hp0]
      norm_num [hz]
    · obtain ⟨d', k, growth, e', z, z', zs, zs', hb, hleft, hgrowth,
        hk, hg, heq, hpEq, hmap, hmap', hz, hzhi, hz', hzhi', hsel,
        hlarge, hsmall, hstall, hrecover, hzero, hpLo', hpHi',
        hcap', hdigit', hlen', hlast', hend'⟩ := hcont
      let t : State := (d'.num_digits, d'.decimal_point, d'.truncated,
        d'.digits, e', none)
      have ht : recOf t = d' := by cases d'; rfl
      have hbody : step s = ok (cont t) := by
        simpa only [step, recOf, hnone, t] using hb
      have hInv : Inv t := hclosed s t hs (by simpa only [step] using hbody)
      have hbonus := P844_T1_LeftStepPotential (recOf s).decimal_point.val
        d'.decimal_point.val z z' k hpHi hpHi' hk hsel hlarge hsmall hstall hrecover hzero
      refine Or.inr ⟨t, k, hbody, hInv, ?_, hk, heq, ?_, ?_⟩
      · simpa only [ht] using hleft
      · have hhead : headOf s = z := by dsimp only [headOf]; rw [hmap]; rfl
        have hhead' : headOf t = z' := by dsimp only [headOf]; rw [ht, hmap']; rfl
        have hbonus' : B (P s) z + 3 * (k.val : Int) <=
            B (P t) z' + 10 * (P t - P s) := hbonus.1
        simpa only [H, hhead, hhead'] using hbonus'
      · simpa only [P, t, recOf] using hbonus.2.1
  have htransport (s t : State) (hs : Inv s) (ht : Inv t)
      (k : Std.Usize) (hk : k.val <= 60)
      (heq : E t = E s - (k.val : Int))
      (hleft : num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift (recOf s) k = ok (recOf t))
      (c : Nat) (R : Int) (hcap : 0 <= R - E t + 768 - P t) :
      (c : Real) * (2 : Real) ^ (R - E s) <= V (recOf s) ->
        (c : Real) * (2 : Real) ^ (R - E t) <= V (recOf t) := by
    obtain ⟨_, _, _, _, _, hdigit, hshape, _⟩ := hsafe s hs
    obtain ⟨_, _, hpHi, _, hcount, _, _, _⟩ := hsafe t ht
    change P t <= 0 at hpHi
    obtain ⟨z, zs, hmap, hz, _, hlen⟩ := hshape
    exact P844_T1_LeftCoefficientTransport (recOf s) (recOf t) k
      (E s) (E t) c R hk heq hdigit ⟨z, zs, hmap, hz, hlen⟩ hleft
      hcount (by change P t <= 768; omega) hcap
  let Rel := fun (s y : State) => Inv s ->
    7 * (P s + 324) + H s <= 3 * (E y - E s + 768 - P s) /\
    ((2 : Real) ^ (E y - E s) <= V (recOf s) -> 1 <= V (recOf y)) /\
    (forall (c : Nat) (R : Int),
      0 <= R - E s + 768 - P s ->
      0 <= R - E y + 768 - P y /\
      ((c : Real) * (2 : Real) ^ (R - E s) <= V (recOf s) ->
        (c : Real) * (2 : Real) ^ (R - E y) <= V (recOf y)))
  have hhistory : forall s y, Aeneas.Std.loop step s = ok y -> Rel s y := by
    apply P826_T1_ResultLoopBackward Rel step
    · intro s y hb
      dsimp only [Rel]
      intro hs
      rcases hstep s hs with ⟨hbody, hp0, hH⟩ | ⟨t, k, hbody, _⟩
      · have heq := Result.ok.inj (hbody.symm.trans hb)
        cases heq
        refine ⟨?_, ?_, ?_⟩
        · rw [hp0, hH]
          omega
        · simpa only [sub_self, zpow_zero] using (fun h : 1 <= V (recOf s) => h)
        · intro c R hc
          exact ⟨hc, fun h => h⟩
      · have heq := Result.ok.inj (hbody.symm.trans hb)
        cases heq
    · intro s t y hb ih
      dsimp only [Rel] at ih ⊢
      intro hs
      rcases hstep s hs with ⟨hbody, _, _⟩ |
        ⟨t', k, hbody, ht, hleft, hk, heq, hbonus, hgrowth⟩
      · have heq := Result.ok.inj (hbody.symm.trans hb)
        cases heq
      · have hstate := Result.ok.inj (hbody.symm.trans hb)
        cases hstate
        obtain ⟨hpotential, horder, hgeneral⟩ := ih ht
        have hpLo : -324 <= P t := (hsafe t ht).2.1
        have hHpos := hnonneg t
        have hcap : 0 <= E y - E t + 768 - P t := by omega
        refine ⟨?_, ?_, ?_⟩
        · omega
        · intro hboundary
          apply horder
          have hshifted := htransport s t hs ht k hk heq hleft 1 (E y) hcap
          simpa only [Nat.cast_one, one_mul] using hshifted (by simpa using hboundary)
        · intro c R hcapacity
          have hcapacity' : 0 <= R - E t + 768 - P t := by omega
          obtain ⟨hfinal, hpropagate⟩ := hgeneral c R hcapacity'
          refine ⟨hfinal, ?_⟩
          intro hboundary
          exact hpropagate (htransport s t hs ht k hk heq hleft c R hcapacity' hboundary)
  have hloop : Aeneas.Std.loop step s0 = ok s1 := by
    simpa only [step, s0, s1, num.imp.dec2flt.slow.parse_long_mantissa_loop1] using hcall
  obtain ⟨hpotential, horder, hgeneral⟩ := hhistory s0 s1 hloop hstart
  have hpLo : -324 <= P s0 := hpointLo
  have hHpos := hnonneg s0
  refine ⟨?_, horder, ?_⟩
  · change 0 <= E s1 - E s0 + 768 - P s0
    omega
  · intro c R hcapacity
    obtain ⟨hfinal, hpropagate⟩ := hgeneral c R hcapacity
    refine ⟨hfinal, ?_⟩
    intro hstrict
    by_contra hnot
    have hboundary : (c : Real) * (2 : Real) ^ (R - E s0) <= V (recOf s0) :=
      le_of_not_gt hnot
    exact (not_lt_of_ge (hpropagate hboundary)) hstrict

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P529_T1_Loop1Execution
import Tablet.P529_T1_LeftShiftCertificate
import Tablet.SlowShiftSelectorCertificate
import Tablet.P826_T1_ResultLoopBackward
import Tablet.P856_T1_CoefficientGridAlignment
import Tablet.P798_T1_LeftBoundaryTransport
import Tablet.P472_T1_DecimalValueBounds
import Tablet.P844_T1_LeftHistoryInvariant
import Tablet.P844_T1_LeftStepPotential
import Tablet.P844_T1_LeftCoefficientTransport
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_LeftHistoryBoundary]
theorem P529_T1_LeftHistoryBoundary (X Y : Real)
    (d0 d1 : num.imp.dec2flt.decimal_seq.DecimalSeq) (exp0 exp1 : Std.I32)
    (hpointLo : -324 <= d0.decimal_point.val)
    (hpointHi : d0.decimal_point.val <= 0) (hexpLo : 0 <= exp0.val)
    (hinput : d0.num_digits.val <= 768 /\
      (forall b, b ∈ d0.digits.val.take d0.num_digits.val -> b.val < 10) /\
      (exists h tail,
        (d0.digits.val.take d0.num_digits.val).map (fun b => b.val) = h :: tail /\
        1 <= h /\ h < 10 /\ (h :: tail).length = d0.num_digits.val))
    (hcall : num.imp.dec2flt.slow.parse_long_mantissa_loop1
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 2047#i32 }
      d0.num_digits d0.decimal_point d0.truncated d0.digits exp0 none =
        ok (d1.num_digits, d1.decimal_point, d1.truncated, d1.digits, exp1, none)) :
    let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      ((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
        (fun n z => 10 * n + z) 0 : Nat) : Real) *
        (10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
    (exists eta u : Real,
      X / (2 : Real) ^ exp0.val = V d0 + eta /\
      Y / (2 : Real) ^ exp0.val = V d0 + u /\
      0 <= eta /\ eta < u /\ (d0.truncated = true <-> 0 < eta)) ->
    0 <= exp1.val - exp0.val + 768 - d0.decimal_point.val /\
    ((2 : Real) ^ (exp1.val - exp0.val) <= V d0 -> 1 <= V d1) /\
    (forall (c : Nat) (R : Int),
      0 <= R - exp0.val + 768 - d0.decimal_point.val ->
      0 <= R - exp1.val + 768 - d1.decimal_point.val /\
      (V d1 < (c : Real) * (2 : Real) ^ (R - exp1.val) ->
        V d0 < (c : Real) * (2 : Real) ^ (R - exp0.val))) := by
-- BODY
  classical
  intro V hend0
  let State := Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
    Std.I32 × Option num.imp.dec2flt.common.BiasedFp
  let recOf := fun (s : State) =>
    ({ num_digits := s.1, decimal_point := s.2.1,
       truncated := s.2.2.1, digits := s.2.2.2.1 } :
      num.imp.dec2flt.decimal_seq.DecimalSeq)
  let P := fun (s : State) => s.2.1.val
  let E := fun (s : State) => s.2.2.2.2.1.val
  let headOf := fun (s : State) =>
    (((recOf s).digits.val.take (recOf s).num_digits.val).map
      (fun b => b.val)).headD 0
  let B := fun (p : Int) (z : Nat) =>
    (if p = -1 then if 7 <= z then 36 else 27
     else if p = 0 then if 5 <= z then 36 else if 3 <= z then 33 else 27
     else 0 : Int)
  let H := fun (s : State) => B (P s) (headOf s)
  let step : State -> Result (ControlFlow State State) := fun s =>
    num.imp.dec2flt.slow.parse_long_mantissa_loop1.body
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 2047#i32 }
      s.1 s.2.1 s.2.2.1 s.2.2.2.1 s.2.2.2.2.1 s.2.2.2.2.2
  let s0 : State := (d0.num_digits, d0.decimal_point, d0.truncated,
    d0.digits, exp0, none)
  let s1 : State := (d1.num_digits, d1.decimal_point, d1.truncated,
    d1.digits, exp1, none)
  obtain ⟨Inv, hstart, hsafe, hclosed⟩ := P844_T1_LeftHistoryInvariant
    X Y d0 exp0 hpointLo hpointHi hexpLo hinput hend0
  have hnonneg (s : State) : 0 <= H s := by
    dsimp only [H, B]
    split_ifs <;> omega
  have hstep (s : State) (hs : Inv s) :
      (step s = ok (done s) /\ P s = 0 /\ H s = 36) \/
      exists (t : State) (k : Std.Usize),
        step s = ok (cont t) /\ Inv t /\
        num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift (recOf s) k = ok (recOf t) /\
        k.val <= 60 /\ E t = E s - (k.val : Int) /\
        H s + 3 * (k.val : Int) <= H t + 10 * (P t - P s) /\
        P t - P s <= (k.val : Int) := by
    obtain ⟨hnone, hpLo, hpHi, heLo, hcap, hdigit, hshape, hend⟩ := hsafe s hs
    have hprincipal := P529_T1_LeftLoopStep
      (X / (2 : Real) ^ E s) (Y / (2 : Real) ^ E s)
      (recOf s) s.2.2.2.2.1 hpLo hpHi heLo ⟨hcap, hdigit, hshape⟩ hend
    rcases hprincipal with hdone | hcont
    · obtain ⟨hb, hp0, hz5⟩ := hdone
      have hbody : step s = ok (done s) := by
        have hsEta : (s.1, s.2.1, s.2.2.1, s.2.2.2.1, s.2.2.2.2.1, none) = s := by
          rw [← hnone]
        simpa only [step, recOf, hnone, hsEta] using hb
      obtain ⟨z, zs, hmap, hzlo, hzhi, hlen⟩ := hshape
      have hnpos : 0 < (recOf s).num_digits.val := by
        rw [← hlen]
        simp
      have hidx : 0 < (recOf s).digits.val.length := by
        have harray : (recOf s).digits.val.length = 768 := by
          simpa using (recOf s).digits.property
        omega
      have hread := congrArg (fun l : List Nat => l[0]?) hmap
      simp only [List.getElem?_cons_zero, List.getElem?_map] at hread
      rw [List.getElem?_take_of_lt hnpos] at hread
      rw [List.getElem?_eq_getElem hidx, Option.map_some] at hread
      have hz : 5 <= z := by
        have heq := Option.some.inj hread
        omega
      have hhead : headOf s = z := by dsimp only [headOf]; rw [hmap]; rfl
      refine Or.inl ⟨hbody, hp0, ?_⟩
      simp only [H, hhead, B, show P s = 0 from hp0]
      norm_num [hz]
    · obtain ⟨d', k, growth, e', z, z', zs, zs', hb, hleft, hgrowth,
        hk, hg, heq, hpEq, hmap, hmap', hz, hzhi, hz', hzhi', hsel,
        hlarge, hsmall, hstall, hrecover, hzero, hpLo', hpHi',
        hcap', hdigit', hlen', hlast', hend'⟩ := hcont
      let t : State := (d'.num_digits, d'.decimal_point, d'.truncated,
        d'.digits, e', none)
      have ht : recOf t = d' := by cases d'; rfl
      have hbody : step s = ok (cont t) := by
        simpa only [step, recOf, hnone, t] using hb
      have hInv : Inv t := hclosed s t hs (by simpa only [step] using hbody)
      have hbonus := P844_T1_LeftStepPotential (recOf s).decimal_point.val
        d'.decimal_point.val z z' k hpHi hpHi' hk hsel hlarge hsmall hstall hrecover hzero
      refine Or.inr ⟨t, k, hbody, hInv, ?_, hk, heq, ?_, ?_⟩
      · simpa only [ht] using hleft
      · have hhead : headOf s = z := by dsimp only [headOf]; rw [hmap]; rfl
        have hhead' : headOf t = z' := by dsimp only [headOf]; rw [ht, hmap']; rfl
        have hbonus' : B (P s) z + 3 * (k.val : Int) <=
            B (P t) z' + 10 * (P t - P s) := hbonus.1
        simpa only [H, hhead, hhead'] using hbonus'
      · simpa only [P, t, recOf] using hbonus.2.1
  have htransport (s t : State) (hs : Inv s) (ht : Inv t)
      (k : Std.Usize) (hk : k.val <= 60)
      (heq : E t = E s - (k.val : Int))
      (hleft : num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift (recOf s) k = ok (recOf t))
      (c : Nat) (R : Int) (hcap : 0 <= R - E t + 768 - P t) :
      (c : Real) * (2 : Real) ^ (R - E s) <= V (recOf s) ->
        (c : Real) * (2 : Real) ^ (R - E t) <= V (recOf t) := by
    obtain ⟨_, _, _, _, _, hdigit, hshape, _⟩ := hsafe s hs
    obtain ⟨_, _, hpHi, _, hcount, _, _, _⟩ := hsafe t ht
    change P t <= 0 at hpHi
    obtain ⟨z, zs, hmap, hz, _, hlen⟩ := hshape
    exact P844_T1_LeftCoefficientTransport (recOf s) (recOf t) k
      (E s) (E t) c R hk heq hdigit ⟨z, zs, hmap, hz, hlen⟩ hleft
      hcount (by change P t <= 768; omega) hcap
  let Rel := fun (s y : State) => Inv s ->
    7 * (P s + 324) + H s <= 3 * (E y - E s + 768 - P s) /\
    ((2 : Real) ^ (E y - E s) <= V (recOf s) -> 1 <= V (recOf y)) /\
    (forall (c : Nat) (R : Int),
      0 <= R - E s + 768 - P s ->
      0 <= R - E y + 768 - P y /\
      ((c : Real) * (2 : Real) ^ (R - E s) <= V (recOf s) ->
        (c : Real) * (2 : Real) ^ (R - E y) <= V (recOf y)))
  have hhistory : forall s y, Aeneas.Std.loop step s = ok y -> Rel s y := by
    apply P826_T1_ResultLoopBackward Rel step
    · intro s y hb
      dsimp only [Rel]
      intro hs
      rcases hstep s hs with ⟨hbody, hp0, hH⟩ | ⟨t, k, hbody, _⟩
      · have heq := Result.ok.inj (hbody.symm.trans hb)
        cases heq
        refine ⟨?_, ?_, ?_⟩
        · rw [hp0, hH]
          omega
        · simpa only [sub_self, zpow_zero] using (fun h : 1 <= V (recOf s) => h)
        · intro c R hc
          exact ⟨hc, fun h => h⟩
      · have heq := Result.ok.inj (hbody.symm.trans hb)
        cases heq
    · intro s t y hb ih
      dsimp only [Rel] at ih ⊢
      intro hs
      rcases hstep s hs with ⟨hbody, _, _⟩ |
        ⟨t', k, hbody, ht, hleft, hk, heq, hbonus, hgrowth⟩
      · have heq := Result.ok.inj (hbody.symm.trans hb)
        cases heq
      · have hstate := Result.ok.inj (hbody.symm.trans hb)
        cases hstate
        obtain ⟨hpotential, horder, hgeneral⟩ := ih ht
        have hpLo : -324 <= P t := (hsafe t ht).2.1
        have hHpos := hnonneg t
        have hcap : 0 <= E y - E t + 768 - P t := by omega
        refine ⟨?_, ?_, ?_⟩
        · omega
        · intro hboundary
          apply horder
          have hshifted := htransport s t hs ht k hk heq hleft 1 (E y) hcap
          simpa only [Nat.cast_one, one_mul] using hshifted (by simpa using hboundary)
        · intro c R hcapacity
          have hcapacity' : 0 <= R - E t + 768 - P t := by omega
          obtain ⟨hfinal, hpropagate⟩ := hgeneral c R hcapacity'
          refine ⟨hfinal, ?_⟩
          intro hboundary
          exact hpropagate (htransport s t hs ht k hk heq hleft c R hcapacity' hboundary)
  have hloop : Aeneas.Std.loop step s0 = ok s1 := by
    simpa only [step, s0, s1, num.imp.dec2flt.slow.parse_long_mantissa_loop1] using hcall
  obtain ⟨hpotential, horder, hgeneral⟩ := hhistory s0 s1 hloop hstart
  have hpLo : -324 <= P s0 := hpointLo
  have hHpos := hnonneg s0
  refine ⟨?_, horder, ?_⟩
  · change 0 <= E s1 - E s0 + 768 - P s0
    omega
  · intro c R hcapacity
    obtain ⟨hfinal, hpropagate⟩ := hgeneral c R hcapacity
    refine ⟨hfinal, ?_⟩
    intro hstrict
    by_contra hnot
    have hboundary : (c : Real) * (2 : Real) ^ (R - E s0) <= V (recOf s0) :=
      le_of_not_gt hnot
    exact (not_lt_of_ge (hpropagate hboundary)) hstrict

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (152)
More program dependencies (110)
Standard-library dependencies (39)

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
All 138 entries
Technical checking records
Local closure summary
{
  "node": "P529_T1_LeftHistoryBoundary",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "fe9efcf027ec9d9bf7bcc3e447ce18776365f97f8bbd4298d9619ee65d4978d1",
  "active_statement_hash": "6dc018ee3dfff8adbfa22b10584b3a42741a19bf32424506a755c4e2992a3c65",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-200",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "P529_T1_LeftLoopStep": "24fd9fefa4fce9ac",
    "P826_T1_ResultLoopBackward": "46222c89d1819e7b",
    "P844_T1_LeftCoefficientTransport": "9ea452683ab3c84d",
    "P844_T1_LeftHistoryInvariant": "7f7cb82b83ba305f",
    "P844_T1_LeftStepPotential": "438ed722040da64d"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "fd298e37d5ae4f86",
    "num_imp_dec2flt_decimal_seq_number_of_digits_decimal_left_shift": "b3efbd0e6b3fe061",
    "num_imp_dec2flt_slow_parse_long_mantissa": "62216a51d634059e",
    "num_imp_dec2flt_slow_parse_long_mantissa_closure_Insts_CoreOpsFunctionFnTupleUsizeUsize_call": "7df8a2c8e3717790"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:6014da1fb373c2c4975bfcfcceb5bd91017a9d0a64211c09dfed26c3c82752b5",
  "current_fingerprint": "sound-v2:6014da1fb373c2c4975bfcfcceb5bd91017a9d0a64211c09dfed26c3c82752b5",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}