P529_T1_RightHistoryBoundary

Lean checked

Statement

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

Lemma · Capacity and order backward on the actual right history

Let d have positive exact-length decimal shape, count at most 768, -324\le p<310, and original adjacent endpoints X=V(d)+\eta, Y=V(d)+10^{p-768}, 0\le\eta<10^{p-768}, with sticky iff \eta>0. Suppose actual specialized loop zero with zero sentinel, exponent zero and None returns (d_0,e_0,\mathsf{none}). If p_0<0, then e_0=0. For every natural c and integer R, terminal capacity 0\le R-e_0+768-p_0 implies
0\le R+768-p,\qquad V(d_0)<c2^{R-e_0}\Longrightarrow V(d)<c2^R .

Lean statement

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

import Tablet.P495_T1_SlowLoop0Execution
import Tablet.P495_T1_RightLoopStep
import Tablet.P529_T1_RightBoundaryTransport
import Tablet.P826_T1_ResultLoopBackward
import Tablet.ResultLoopPartial
import Tablet.P856_T1_CoefficientGridAlignment
import Tablet.P472_T1_DecimalValueBounds
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_RightHistoryBoundary]
theorem P529_T1_RightHistoryBoundary (X Y : Real)
    (d d0 : num.imp.dec2flt.decimal_seq.DecimalSeq) (exp0 : Std.I32)
    (hpointLo : -324 <= d.decimal_point.val)
    (hpointHi : d.decimal_point.val < 310)
    (hinput : d.num_digits.val <= 768 /\
      (forall b, b ∈ d.digits.val.take d.num_digits.val -> b.val < 10) /\
      (exists h tail,
        (d.digits.val.take d.num_digits.val).map (fun b => b.val) = h :: tail /\
        1 <= h /\ h < 10 /\ (h :: tail).length = d.num_digits.val))
    (hcall : num.imp.dec2flt.slow.parse_long_mantissa_loop0
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 0#i32 }
      d.num_digits d.decimal_point d.truncated d.digits 0#i32 none =
        ok (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits, exp0, 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))
    Y = V d + (10 : Real) ^ (d.decimal_point.val - 768) ->
    (exists eta : Real, X = V d + eta /\ 0 <= eta /\
      eta < (10 : Real) ^ (d.decimal_point.val - 768) /\
      (d.truncated = true <-> 0 < eta)) ->
    (d0.decimal_point.val < 0 -> exp0.val = 0) /\
    (forall (c : Nat) (R : Int),
      0 <= R - exp0.val + 768 - d0.decimal_point.val ->
      0 <= R + 768 - d.decimal_point.val /\
      (V d0 < (c : Real) * (2 : Real) ^ (R - exp0.val) ->
        V d < (c : Real) * (2 : Real) ^ R)) := 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 SlowLoop0Execution to the exact original package and identify its result with the supplied normal call. It gives 0\le e_0\le1260, the terminal positive decimal shape, point in [-324,0], and fixed endpoint equations. We now reason about conditional normal transitions in this same history. Initially the exponent is zero. At a positive-point normal continuation, unfold num imp dec2flt slow parse long mantissa: the cast of p\in[1,309] is exact under the ratified width in Assumptions, and SlowShiftSelectorCertificate gives its k\le60. The normal shift is identified with the one constructed by DecimalRightShiftLoop0Execution. RightShiftCanonical preserves positive decimal shape and the fixed endpoint errors. Write B=2^k. The execution principal gives B\le c<10B and p'=p-r+1, and RightPrefixLengthBounds gives 10^{r-1}\le c<10^r for this actual prefix call. If p\ge19, the selector gives 10^{18}<B<10^{19}. Then r\le18 contradicts c<10^r\le10^{18}<B, while r\ge21 contradicts c\ge10^{r-1}\ge10^{20}>10B. Hence r=19 or 20 and p'=p-18 or p-19. If 1\le p\le18, its bracket is B\le10^p<2B, so 10^{p-1}<B. The case r<p contradicts c<10^r\le10^{p-1}<B, and the case r\ge p+2 contradicts c\ge10^{r-1}\ge10^{p+1}\ge10B. Thus r=p or p+1 and p'=1 or zero. This derives the point alternatives before any exponent bound is used. They imply p'\ge0, p'<310 and exclusion of reset. The successful cast and addition in the body have exact value e'=e+k. Thus exponents never decrease. Every intermediate exponent is between zero and terminal e_0\le1260; the full implication RightLoopStep therefore applies at each such state. These invariants follow by ResultLoopPartial; backward arguments below use ResultLoopBackward. If any continuation occurs, all subsequent points are nonnegative. Consequently a negative terminal point requires that the initial guard was already false: no continuation occurred and the exponent stays zero.
For each continuation, the literal selector gives
p-p'\le k. \tag{1}
If p\ge19, its left side is 18 or 19 and k=60. If 1\le p\le18, p'\ge0 and the eighteen literal values 3,6,9,13,16,19,23,26,29,33,36,39,43,46,49,53,56,59 each exceed or equal their respective input p. This proves (1) in all cases.
Fix c,R and carry terminal capacity backward. With C_R=R-e+768-p,
C_R=C_R'+k-(p-p')\ge C_R'.
At each successor, nonnegative capacity and p'\le309<768 permit CoefficientGridAlignment to write c2^{R-e'}=b10^{p'-768} for a natural b. If contrary to strict predecessor order one had c2^{R-e}\le V(a), divide by 2^k and use e'=e+k to place this aligned successor boundary below V(a)/2^k. The positive leading digit gives V(a)>0 by DecimalValueBounds, and the successor has nonzero count and is not the reset record. All call, digit and count premises of RightBoundaryTransport hold, so it gives c2^{R-e'}\le V(a'). This contradicts strict successor order. A done state is unchanged, so capacity and strict order are unchanged there. Backward loop induction with these two assertions reaches the initial exponent zero and proves both advertised conclusions. The endpoint errors persist by (X/2^e)/2^k=X/2^{e+k} and the same identity for Y; no new cutoff is substituted.

Lean proof


  dsimp only
  intro hY hX
  classical
  rcases hX with ⟨eta, hxeq, hetaLo, hetaHi, hsticky⟩
  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))
  rcases hinput with ⟨hcap, hdigit, hlead⟩
  have hrun := P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi
    ⟨hcap, hdigit, hlead⟩ hY ⟨eta, hxeq, hetaLo, hetaHi, hsticky⟩
  rcases hrun with ⟨dF, eF, steps, hrun, hsteps, heFLo, heFHi,
    hXlower, hpFLo, hpFHi, hcapF, hdigitF, hleadF, hlastF, hendF⟩
  have hfinalEq := Result.ok.inj (hrun.symm.trans hcall)
  have hn : dF.num_digits = d0.num_digits := congrArg (fun z => z.1) hfinalEq
  have hp : dF.decimal_point = d0.decimal_point :=
    congrArg (fun z => z.2.1) hfinalEq
  have ht : dF.truncated = d0.truncated := congrArg (fun z => z.2.2.1) hfinalEq
  have ha : dF.digits = d0.digits := congrArg (fun z => z.2.2.2.1) hfinalEq
  have he : eF = exp0 := congrArg (fun z => z.2.2.2.2.1) hfinalEq
  have hterminal : -324 <= d0.decimal_point.val ∧ d0.decimal_point.val <= 0 ∧
      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) := by
    exact ⟨by simpa [hp] using hpFLo, by simpa [hp] using hpFHi,
      by simpa [hn] using hcapF, by simpa [hn, ha] using hdigitF,
      by simpa [hn, ha] using hleadF⟩
  have hendpoints : ∃ eta0 u0 : Real,
      X / (2 : Real) ^ exp0.val = V d0 + eta0 ∧
      Y / (2 : Real) ^ exp0.val = V d0 + u0 ∧
      0 <= eta0 ∧ eta0 < u0 ∧ (d0.truncated = true ↔ 0 < eta0) := by
    simpa [V, he, hn, hp, ht, ha] using hendF
  have hterminalExp : 0 <= exp0.val ∧ exp0.val <= 1260 := by
    constructor
    · simpa [he] using heFLo
    · calc
        exp0.val <= 60 * steps := by simpa [he] using heFHi
        _ <= 60 * 21 := by omega
        _ = 1260 := by norm_num
  have bodyMono (a a' : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (e e' : Std.I32)
      (hb : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 0#i32 }
        a.num_digits a.decimal_point a.truncated a.digits e none =
        ok (cont (a'.num_digits, a'.decimal_point, a'.truncated,
          a'.digits, e', none))) :
      ∃ k : Std.Usize,
        k.val <= 60 ∧ e'.val = e.val + (k.val : Int) ∧
        (19 <= a.decimal_point.val -> k.val = 60) ∧
        (a.decimal_point.val <= 18 ->
          a.decimal_point.val <= (k.val : Int)) := by
    unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hb
    by_cases houter : a.decimal_point > 0#i32
    · simp only [if_pos houter, core.option.Option.is_none] at hb
      split at hb
      · obtain ⟨n, hncast, hnval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.hcast_inBounds_spec .Usize a.decimal_point (by scalar_tac))
        let traits := F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        let shift : Std.Usize := match n.val with
          | 0 => 0#usize | 1 => 3#usize | 2 => 6#usize | 3 => 9#usize
          | 4 => 13#usize | 5 => 16#usize | 6 => 19#usize | 7 => 23#usize
          | 8 => 26#usize | 9 => 29#usize | 10 => 33#usize | 11 => 36#usize
          | 12 => 39#usize | 13 => 43#usize | 14 => 46#usize | 15 => 49#usize
          | 16 => 53#usize | 17 => 56#usize | 18 => 59#usize | _ => 60#usize
        have hcert := SlowShiftSelectorCertificate traits n
        dsimp only at hcert
        rcases hcert with ⟨hselector, hshift, _, hsmall, hlarge⟩
        have hs : num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok shift := by
          simpa [traits, shift] using hselector
        have hneg : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE =
            ok (-2047)#i32 := by
          unfold num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
          change IScalar.neg (2047#i32 : Std.I32) = _
          unfold IScalar.neg IScalar.tryMk IScalar.tryMkOpt
          norm_num [IScalar.check_bounds, IScalarTy.numBits]
        simp only [Bind.bind, Aeneas.Std.bind, hncast, hs, hneg] at hb
        cases hr : num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift
            { num_digits := a.num_digits, decimal_point := a.decimal_point,
              truncated := a.truncated, digits := a.digits } shift <;>
          simp [hr] at hb
        split at hb
        · simp at hb
        · cases hc : lift (UScalar.hcast .I32 shift) with
          | fail err => simp [hc] at hb
          | div => simp [hc] at hb
          | ok i3 =>
            simp [hc] at hb
            cases ha : e + i3 with
            | fail err => simp [ha] at hb
            | div => simp [ha] at hb
            | ok out =>
              simp [ha] at hb
              have haddval := IScalar.add_equiv e i3
              rw [ha] at haddval
              obtain ⟨_, houtval, _⟩ := haddval
              have hshiftI : (i3.val : Int) = (shift.val : Int) := by
                obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
                  (UScalar.hcast_inBounds_spec .I32 shift (by
                    have hi : (shift.val : Int) <= 60 := by exact_mod_cast hshift
                    rw [IScalar.max_I32_eq]
                    norm_num [IScalarTy.numBits]
                    omega))
                have hz' : lift (UScalar.hcast .I32 shift) = ok z := by
                  simpa [lift] using hz
                have hiz : i3 = z := Result.ok.inj (hc.symm.trans hz')
                subst z
                simpa [WP.spec_ok] using hzval
              have hout : out.val = e.val + (shift.val : Int) := by
                simpa [hshiftI] using houtval
              rcases hb with ⟨_, hpointEq, _, _, houtEq⟩
              have hlargeK : 19 <= a.decimal_point.val -> shift.val = 60 := by
                intro hp
                have hnlarge : 19 <= n.val := by
                  have hn : (n.val : Int) = a.decimal_point.val := by
                    simpa using hnval
                  exact_mod_cast (by omega : (19 : Int) <= (n.val : Int))
                exact (hlarge hnlarge).1
              have hsmallK : a.decimal_point.val <= 18 ->
                  a.decimal_point.val <= (shift.val : Int) := by
                intro hp
                have hn : (n.val : Int) = a.decimal_point.val := by
                  simpa using hnval
                have hnpos : 1 <= n.val := by
                  have hpPos : (0 : Int) < a.decimal_point.val := by
                    simpa only [gt_iff_lt, IScalar.lt_equiv] using houter
                  have hnp : (1 : Int) <= a.decimal_point.val := by omega
                  rw [← hn] at hnp
                  exact_mod_cast hnp
                have hnsmall : n.val <= 18 := by
                  have hnp : (n.val : Int) <= 18 := by rw [hn]; exact hp
                  exact_mod_cast hnp
                have hkSmall : n.val <= shift.val := by
                  have hpow := (hsmall (by omega) hnsmall).2
                  have h2 : 2 ^ n.val <= 10 ^ n.val :=
                    Nat.pow_le_pow_left (by norm_num) _
                  have hpow2 : 2 ^ n.val < 2 ^ (shift.val + 1) :=
                    lt_of_le_of_lt h2 hpow
                  have hexp : n.val < shift.val + 1 :=
                    (Nat.pow_lt_pow_iff_right (by norm_num : 1 < (2 : Nat))).mp hpow2
                  omega
                have hkSmallI : (n.val : Int) <= (shift.val : Int) := by
                  exact_mod_cast (show n.val <= shift.val from hkSmall)
                omega
              refine ⟨shift, hshift, ?_, hlargeK, hsmallK⟩
              have hout' : e'.val = out.val := congrArg IScalar.val houtEq.symm
              omega
      · simp at hb
    · simp [houter] at hb
  let State := Std.Usize × Std.I32 × Bool × (Array Std.U8 768#usize) ×
    Std.I32 × Option num.imp.dec2flt.common.BiasedFp
  let stateDec := fun s : State =>
    num.imp.dec2flt.decimal_seq.DecimalSeq.mk s.1 s.2.1
      s.2.2.1 s.2.2.2.1
  let stateExp := fun s : State => s.2.2.2.2.1
  let stateBody := fun s : State =>
    num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 0#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 sStart : State := (d.num_digits, d.decimal_point, d.truncated,
    d.digits, 0#i32, none)
  let sFinal : State := (d0.num_digits, d0.decimal_point, d0.truncated,
    d0.digits, exp0, none)
  have hloop : Aeneas.Std.loop stateBody sStart = ok sFinal := by
    simpa [stateBody, sStart, sFinal,
      num.imp.dec2flt.slow.parse_long_mantissa_loop0] using hcall
  let stateInv := fun s : State =>
    let a := stateDec s;
    -324 <= a.decimal_point.val ∧ a.decimal_point.val < 310 ∧
    a.num_digits.val <= 768 ∧
    (forall b, b ∈ a.digits.val.take a.num_digits.val -> b.val < 10) ∧
    (exists h tail,
      (a.digits.val.take a.num_digits.val).map (fun b => b.val) = h :: tail ∧
      1 <= h ∧ h < 10 ∧ (h :: tail).length = a.num_digits.val) ∧
    0 <= (stateExp s).val ∧ (stateExp s).val <= 1260 ∧
    s.2.2.2.2.2 = none ∧
    (exists etaS uS : Real,
      X / (2 : Real) ^ (stateExp s).val = V a + etaS ∧
      Y / (2 : Real) ^ (stateExp s).val = V a + uS ∧
      0 <= etaS ∧ etaS < uS ∧ (a.truncated = true ↔ 0 < etaS))
  have hstartInv : stateInv sStart := by
    dsimp [stateInv, stateDec, stateExp, sStart]
    refine ⟨hpointLo, hpointHi, hcap, hdigit, hlead, by norm_num,
      by norm_num, rfl, ?_⟩
    refine ⟨eta, 10 ^ (d.decimal_point.val - 768), ?_, ?_, hetaLo, ?_, hsticky⟩
    · simpa [V, List.map_take, zpow_zero, div_one] using hxeq
    · simpa [V, List.map_take] using hY
    · dsimp
      exact hetaHi
  have hfinalInv : stateInv sFinal := by
    dsimp [stateInv, stateDec, stateExp, sFinal]
    refine ⟨hterminal.1, ?_, hterminal.2.2.1,
      hterminal.2.2.2.1, hterminal.2.2.2.2,
      hterminalExp.1, hterminalExp.2, rfl, ?_⟩
    · exact lt_of_le_of_lt hterminal.2.1 (by norm_num)
    · exact hendpoints
  have doneIdentity (s t : State)
      (hb : stateBody s = ok (done t)) : s = t := by
    by_cases hp : 0 < s.2.1.val
    · by_cases hn : s.2.2.2.2.2 = none
      · simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
          hp, hn] at hb
        cases hfirst : lift (IScalar.hcast .Usize s.2.1) with
        | fail err => simp [hfirst] at hb
        | div => simp [hfirst] at hb
        | ok n =>
          simp only [Bind.bind, Aeneas.Std.bind, hfirst] at hb
          cases hs : num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
              F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n with
          | fail err => simp [hs] at hb
          | div => simp [hs] at hb
          | ok shift =>
            cases hr : num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift
                { num_digits := s.1, decimal_point := s.2.1,
                  truncated := s.2.2.1, digits := s.2.2.2.1 } shift with
            | fail err => simp [hs, hr] at hb
            | div => simp [hs, hr] at hb
            | ok a =>
              have hneg : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE =
                  ok (-2047)#i32 := by
                unfold num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
                change IScalar.neg (2047#i32 : Std.I32) = _
                unfold IScalar.neg IScalar.tryMk IScalar.tryMkOpt
                norm_num [IScalar.check_bounds, IScalarTy.numBits]
              simp only [hs, hr, hneg] at hb
              split at hb
              · simp at hb
              · cases hc : lift (UScalar.hcast .I32 shift) with
                | fail err => simp [hc] at hb
                | div => simp [hc] at hb
                | ok i3 =>
                  cases ha : s.2.2.2.2.1 + i3 with
                  | fail err => simp [hc, ha] at hb
                  | div => simp [hc, ha] at hb
                  | ok out => simp [hc, ha] at hb
      · simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
          hp, hn] at hb
        exact hb
    · simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
        hp] at hb
      exact hb
  have hExpOrder : ∀ s t, Aeneas.Std.loop stateBody s = ok t →
      t.2.2.2.2.2 = none ->
        s.2.2.2.2.2 = none ∧ (stateExp s).val ≤ (stateExp t).val := by
    apply P826_T1_ResultLoopBackward (fun s t =>
      t.2.2.2.2.2 = none ->
        s.2.2.2.2.2 = none ∧ (stateExp s).val ≤ (stateExp t).val) stateBody
    · intro s t hb
      intro htNone
      have hs := doneIdentity s t hb
      subst t
      exact ⟨htNone, le_rfl⟩
    · intro s s' t hb ih
      intro htNone
      rcases ih htNone with ⟨hnextNone, horder⟩
      have hcurNone : s.2.2.2.2.2 = none := by
        by_contra hn
        simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
          hn] at hb
      have hnextTuple :
          (s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
            s'.2.2.2.2.1, none) = s' := by
        cases s' with
        | mk n rest =>
          cases rest with
          | mk p rest =>
            cases rest with
            | mk b rest =>
              cases rest with
              | mk arr rest =>
                cases rest with
                | mk e opt => simp_all
      have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
            { m := 0#u64, p_biased := 0#i32 }
            (stateDec s).num_digits (stateDec s).decimal_point
            (stateDec s).truncated (stateDec s).digits (stateExp s) none =
            ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
              (stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
        have hb0 := hb
        rw [← hnextTuple] at hb0
        simpa [stateBody, stateDec, stateExp, hcurNone] using hb0
      obtain ⟨k, _, hupdate, _, _⟩ := bodyMono (stateDec s) (stateDec s')
        (stateExp s) (stateExp s') hb'
      have hmono : (stateExp s).val <= (stateExp s').val := by
        have hk : (0 : Int) <= (k.val : Int) := Int.natCast_nonneg _
        omega
      exact ⟨hcurNone, le_trans hmono horder⟩
  let stateCapRel := fun s t : State =>
    ∀ (c : Nat) (R : Int),
      0 <= R - (stateExp t).val + 768 - (stateDec t).decimal_point.val ->
      0 <= R - (stateExp s).val + 768 - (stateDec s).decimal_point.val ∧
      (V (stateDec t) < (c : Real) * (2 : Real) ^ (R - (stateExp t).val) ->
        V (stateDec s) < (c : Real) * (2 : Real) ^ (R - (stateExp s).val))
  let historyRel := fun s t : State =>
    (t.2.2.2.2.2 = none ->
      s.2.2.2.2.2 = none ∧ (stateExp s).val <= (stateExp t).val) ∧
    (stateInv t -> stateInv s ->
      ((stateDec s).decimal_point.val >= 0 ->
        (stateDec t).decimal_point.val >= 0) ∧
      ((stateDec t).decimal_point.val < 0 ->
        (stateExp s).val = (stateExp t).val) ∧
      stateCapRel s t)
  have hhistory : ∀ s t, Aeneas.Std.loop stateBody s = ok t ->
      historyRel s t := (set_option maxHeartbeats 1600000 in by
    apply P826_T1_ResultLoopBackward historyRel stateBody
    · intro s t hb
      have hst := doneIdentity s t hb
      subst t
      constructor
      · intro hnone
        exact ⟨hnone, le_rfl⟩
      · intro htInv hsInv
        refine ⟨fun h => h, fun _ => rfl, ?_⟩
        intro c R hcap
        exact ⟨hcap, fun hlt => hlt⟩
    · intro s s' t hb ih
      constructor
      · intro htNone
        rcases ih.1 htNone with ⟨hnextNone, hexpOrder⟩
        have hcurNone : s.2.2.2.2.2 = none := by
          by_contra hn
          simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
            hn] at hb
        have hnextTuple :
            (s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
              s'.2.2.2.2.1, none) = s' := by
          cases s' with
          | mk n rest =>
            cases rest with
            | mk p rest =>
              cases rest with
              | mk b rest =>
                cases rest with
                | mk arr rest =>
                  cases rest with
                  | mk e opt => simp_all
        have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
              F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
              { m := 0#u64, p_biased := 0#i32 }
              (stateDec s).num_digits (stateDec s).decimal_point
              (stateDec s).truncated (stateDec s).digits (stateExp s) none =
              ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
                (stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
          have hb0 := hb
          rw [← hnextTuple] at hb0
          simpa [stateBody, stateDec, stateExp, hcurNone] using hb0
        obtain ⟨k, _, hupdate, _, _⟩ := bodyMono (stateDec s) (stateDec s')
          (stateExp s) (stateExp s') hb'
        have hkNonneg : (0 : Int) <= (↑↑k : Int) := Int.natCast_nonneg _
        have hmono : (stateExp s).val <= (stateExp s').val := by omega
        exact ⟨hcurNone, le_trans hmono hexpOrder⟩
      · intro htInv hsInv
        have htInvSaved := htInv
        dsimp only [stateInv, stateDec, stateExp] at htInv hsInv
        rcases htInv with ⟨hpLoT, hpHiT, hcountT, hdigitT, hshapeT,
          hexpLoT, hexpHiT, hsentT, hendT⟩
        rcases hsInv with ⟨hpLoS, hpHiS, hcountS, hdigitS, hshapeS,
          hexpLoS, hexpHiS, hsentS, hendS⟩
        rcases hshapeS with ⟨headS, tailS, hshapeS, hheadS, hhead10S, hlenS⟩
        have hnextBound := ih.1 hsentT
        rcases hnextBound with ⟨hsentNext, hexpNextT⟩
        have hpointPos : 1 <= (stateDec s).decimal_point.val := by
          change 1 <= s.2.1.val
          by_contra hn
          have hp : ¬ 0 < s.2.1.val := by omega
          simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
            hp] at hb
        rcases hendS with ⟨etaS, uS, hXS, hYS, hetaS, hetauS, hstickyS⟩
        have hstep := P495_T1_RightLoopStep (X / (2 : Real) ^ (stateExp s).val)
          (Y / (2 : Real) ^ (stateExp s).val) (stateDec s) (stateExp s)
          hpointPos hpHiS hexpLoS hexpHiS
          ⟨hcountS, hdigitS,
            ⟨headS, tailS, hshapeS, hheadS, hhead10S, hlenS⟩⟩
          ⟨etaS, uS, hXS, hYS, hetaS, hetauS, hstickyS⟩
        rcases hstep with ⟨dn, shift, en, hbStep, hright, hshift, hexpStep,
          hpLarge, hpSmall, hcountN, hdigitN, hshapeN, htrimN,
          hendN, hstall, hrecover⟩
        have hpLargeS : 19 <= s.2.1.val ->
            dn.decimal_point.val = s.2.1.val - 18 ∨
              dn.decimal_point.val = s.2.1.val - 19 := by
          simpa [stateDec] using hpLarge
        have hpSmallS : s.2.1.val <= 18 ->
            dn.decimal_point.val = 0 ∨ dn.decimal_point.val = 1 := by
          simpa [stateDec] using hpSmall
        have hnextTuple :
            (dn.num_digits, dn.decimal_point, dn.truncated, dn.digits,
              en, none) = s' := by
          have hb0 := hb
          have hnextTuple0 :
              (s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
                s'.2.2.2.2.1, none) = s' := by
            cases s' with
            | mk n rest =>
              cases rest with
              | mk p rest =>
                cases rest with
                | mk b rest =>
                  cases rest with
                  | mk arr rest =>
                    cases rest with
                    | mk e opt => simp_all
          rw [← hnextTuple0] at hb0
          have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
              F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
              { m := 0#u64, p_biased := 0#i32 }
              (stateDec s).num_digits (stateDec s).decimal_point
              (stateDec s).truncated (stateDec s).digits (stateExp s) none =
              ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
                (stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
            simpa [stateBody, stateDec, stateExp, hsentS] using hb0
          have hEq := Result.ok.inj (hbStep.symm.trans hb')
          injection hEq with htup
          rw [← hnextTuple0]
          simpa [stateDec, stateExp] using htup
        have hpointNLo : -324 <= dn.decimal_point.val := by
          by_cases hlarge : 19 <= s.2.1.val
          · rcases hpLargeS hlarge with hp | hp <;> omega
          · rcases hpSmallS (by omega) with hp | hp <;> omega
        have hpointNHi : dn.decimal_point.val < 310 := by
          by_cases hlarge : 19 <= s.2.1.val
          · rcases hpLargeS hlarge with hp | hp <;> omega
          · rcases hpSmallS (by omega) with hp | hp <;> omega
        have henEq : en = stateExp s' := by
          have hh := congrArg (fun z : State => z.2.2.2.2.1) hnextTuple
          simpa [stateExp] using hh
        rcases hendN with ⟨etaN, uN, hXN, hYN, hetaN, hetauN, hstickyN⟩
        have hscaleX : X / (2 : Real) ^
            ((stateExp s).val + (shift.val : Int)) =
            (X / (2 : Real) ^ (stateExp s).val) /
              (2 : Real) ^ (shift.val : Int) := by
          rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _]
          ring
        have hscaleY : Y / (2 : Real) ^
            ((stateExp s).val + (shift.val : Int)) =
            (Y / (2 : Real) ^ (stateExp s).val) /
              (2 : Real) ^ (shift.val : Int) := by
          rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _]
          ring
        have hXNext : X / (2 : Real) ^ en.val = V dn + etaN := by
          rw [hexpStep, hscaleX]
          exact hXN
        have hYNext : Y / (2 : Real) ^ en.val = V dn + uN := by
          rw [hexpStep, hscaleY]
          exact hYN
        have hnextInv : stateInv s' := by
          rw [← hnextTuple]
          dsimp only [stateInv, stateDec, stateExp]
          refine ⟨hpointNLo, hpointNHi, hcountN, hdigitN, hshapeN,
            ?_, ?_, rfl, ?_⟩
          · rw [hexpStep]
            have hshiftNonneg : (0 : Int) <= (↑↑shift : Int) := by
              exact Int.natCast_nonneg _
            exact add_nonneg hexpLoS hshiftNonneg
          · have hupper : (stateExp s').val <= 1260 :=
              le_trans hexpNextT hexpHiT
            simpa [henEq] using hupper
          · exact ⟨etaN, uN, hXNext, hYNext, hetaN, hetauN, hstickyN⟩
        have hback := ih.2 htInvSaved hnextInv
        rcases hback with ⟨hpointBack, hnegativeBack, hcapBack⟩
        have hpNextNonneg : 0 <= dn.decimal_point.val := by
          by_cases hlarge : 19 <= s.2.1.val
          · rcases hpLargeS hlarge with hp | hp <;> omega
          · rcases hpSmallS (by omega) with hp | hp <;> omega
        have hpNextState : 0 <= (stateDec s').decimal_point.val := by
          have hpointEq : dn.decimal_point = s'.2.1 := by
            have hh := congrArg (fun z : State => z.2.1) hnextTuple
            simpa using hh
          simpa [stateDec, hpointEq] using hpNextNonneg
        refine ⟨?_, ?_, ?_⟩
        · intro _
          exact hpointBack hpNextState
        · intro hpT
          have hpT' : 0 <= (stateDec t).decimal_point.val := hpointBack hpNextState
          omega
        · intro c R hcapT
          rcases hcapBack c R hcapT with ⟨hcapNext, hstrictNext⟩
          have hbodyMono : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
              F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
              { m := 0#u64, p_biased := 0#i32 }
              (stateDec s).num_digits (stateDec s).decimal_point
              (stateDec s).truncated (stateDec s).digits (stateExp s) none =
              ok (cont (dn.num_digits, dn.decimal_point, dn.truncated,
                dn.digits, en, none)) := by
            have hb0 := hb
            rw [← hnextTuple] at hb0
            simpa [stateBody, stateDec, stateExp, hsentS] using hb0
          obtain ⟨k, hkBound, hkUpdate, hkLarge, hkSmall⟩ :=
            bodyMono (stateDec s) dn (stateExp s) en hbodyMono
          have hkEq : (k.val : Int) = (shift.val : Int) := by
            omega
          have hpointDiff : s.2.1.val - dn.decimal_point.val <=
              (shift.val : Int) := by
            by_cases hlarge : 19 <= s.2.1.val
            · have hp := hpLargeS hlarge
              rcases hp with hp | hp
              · rw [hp]
                have h60 : (shift.val : Int) = 60 := by
                  have hkNat : k.val = 60 := hkLarge (by simpa [stateDec] using hlarge)
                  omega
                omega
              · rw [hp]
                have h60 : (shift.val : Int) = 60 := by
                  have hkNat : k.val = 60 := hkLarge (by simpa [stateDec] using hlarge)
                  omega
                omega
            · have hpSmallS' : s.2.1.val <= 18 := by omega
              have hp := hpSmallS hpSmallS'
              rcases hp with hp | hp
              · rw [hp]
                have hkP := hkSmall (by simpa [stateDec] using hpSmallS')
                change s.2.1.val <= (k.val : Int) at hkP
                omega
              · rw [hp]
                have hkP := hkSmall (by simpa [stateDec] using hpSmallS')
                change s.2.1.val <= (k.val : Int) at hkP
                omega
          have hcapSource : 0 <= R - (stateExp s).val + 768 -
              (stateDec s).decimal_point.val := by
            have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
              have hh := congrArg (fun z : State => z.2.1) hnextTuple
              simpa [stateDec] using hh
            have hcapNext' : 0 <= R - en.val + 768 - dn.decimal_point.val := by
              have heVal := congrArg IScalar.val henEq
              have hpVal : dn.decimal_point.val =
                  (stateDec s').decimal_point.val := by simpa using congrArg IScalar.val hpEq
              rw [heVal, hpVal]
              exact hcapNext
            change 0 <= R - (stateExp s).val + 768 - s.2.1.val
            omega
          have hstrictSource :
              V (stateDec t) < (c : Real) *
                (2 : Real) ^ (R - (stateExp t).val) ->
              V (stateDec s) < (c : Real) *
                (2 : Real) ^ (R - (stateExp s).val) :=
              (set_option maxHeartbeats 1600000 in by
            intro hstrictTerminal
            by_contra hnot
            have hle : (c : Real) * (2 : Real) ^
                (R - (stateExp s).val) <= V (stateDec s) := le_of_not_gt hnot
            have hgrid := P856_T1_CoefficientGridAlignment c
              (R - en.val) dn.decimal_point.val (by omega) (by
                have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
                  have hh := congrArg (fun z : State => z.2.1) hnextTuple
                  simpa [stateDec] using hh
                have heVal := congrArg IScalar.val henEq
                have hpVal : dn.decimal_point.val =
                    (stateDec s').decimal_point.val := by simpa using congrArg IScalar.val hpEq
                rw [heVal, hpVal]
                exact hcapNext)
            rcases hgrid with ⟨b, hbgrid⟩
            have hpowRel : (2 : Real) ^ (R - (stateExp s).val) =
                (2 : Real) ^ (R - en.val) * (2 : Real) ^ shift.val := by
              rw [show R - (stateExp s).val = (R - en.val) +
                (shift.val : Int) by omega]
              rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
              norm_num [zpow_natCast]
            have hmulBound : (c : Real) *
                (2 : Real) ^ (R - en.val) * (2 : Real) ^ shift.val <=
                V (stateDec s) := by
              calc
                (c : Real) * (2 : Real) ^ (R - en.val) *
                    (2 : Real) ^ shift.val =
                    (c : Real) * ((2 : Real) ^ (R - en.val) *
                      (2 : Real) ^ shift.val) := by ring
                _ = (c : Real) * (2 : Real) ^
                    (R - (stateExp s).val) := by rw [← hpowRel]
                _ <= V (stateDec s) := hle
            have hshiftPos : (0 : Real) < (2 : Real) ^ shift.val := by
              positivity
            have hnatpow : (2 : Real) ^ shift.val =
                (2 : Real) ^ (shift.val : Int) := by
              norm_num [zpow_natCast]
            have hboundary : (b : Real) *
                (10 : Real) ^ (dn.decimal_point.val - 768) <=
                V (stateDec s) / (2 : Real) ^ shift.val := by
              rw [← hbgrid, hnatpow]
              exact (le_div_iff₀ hshiftPos).2 (by simpa [mul_assoc] using hmulBound)
            have hnonreset : ¬ (dn.num_digits.val = 0 ∧
                dn.decimal_point.val = 0 ∧ dn.truncated = false) := by
              intro hreset
              rcases hshapeN with ⟨headN, tailN, _, hheadN, _, hlenN⟩
              have hposN : 1 <= dn.num_digits.val := by
                rw [← hlenN]
                simp
              omega
            have hxs := hdigitS
            have hvbounds := P472_T1_DecimalValueBounds
              ((stateDec s).digits.val.take (stateDec s).num_digits.val |>.map
                (fun z => z.val)) headS tailS hshapeS hheadS
              (fun q hq => by
                rcases List.mem_map.mp hq with ⟨z, hz, hzq⟩
                have hzd := hdigitS z hz
                simpa [hzq] using hzd)
              (stateDec s).decimal_point.val
            have hVpositive : 0 < V (stateDec s) := by
              have hlow := hvbounds.1
              have hpowpos : (0 : Real) < (10 : Real) ^
                  ((stateDec s).decimal_point.val - 1) := by
                exact zpow_pos (by norm_num) _
              have hheadReal : (1 : Real) <= (headS : Real) := by
                exact_mod_cast hheadS
              have hprod : 0 < (headS : Real) * (10 : Real) ^
                  ((stateDec s).decimal_point.val - 1) :=
                mul_pos (by linarith) hpowpos
              have hlow' : (headS : Real) * (10 : Real) ^
                    ((stateDec s).decimal_point.val - 1) <=
                  V (stateDec s) := by
                rw [hshapeS, hlenS] at hlow
                dsimp only [V]
                rw [hshapeS]
                simpa [V, List.map_take, List.foldl_cons] using hlow
              exact lt_of_lt_of_le hprod hlow'
            have htransport := P529_T1_RightBoundaryTransport
              (stateDec s) dn shift hshift hdigitS hright hnonreset hcountN
              hVpositive b hboundary
            have hstrictNext' : V dn <
                (c : Real) * (2 : Real) ^ (R - en.val) := by
              have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
                have hh := congrArg (fun z : State => z.2.1) hnextTuple
                simpa [stateDec] using hh
              have hnEq : dn.num_digits = (stateDec s').num_digits := by
                have hh := congrArg (fun z : State => z.1) hnextTuple
                simpa [stateDec] using hh
              have hdEq : dn.digits = (stateDec s').digits := by
                have hh := congrArg (fun z : State => z.2.2.2.1) hnextTuple
                simpa [stateDec] using hh
              have hstrictNextInput := hstrictNext hstrictTerminal
              simpa [V, stateDec, hpEq, hnEq, hdEq, henEq] using hstrictNextInput
            have hstrictGrid : V dn < (b : Real) *
                (10 : Real) ^ (dn.decimal_point.val - 768) := by
              rw [← hbgrid]
              exact hstrictNext'
            exact (not_lt_of_ge htransport) hstrictGrid
              )
          exact ⟨hcapSource, hstrictSource⟩
  )
  have hhist := hhistory sStart sFinal hloop
  rcases hhist with ⟨hfinalNone, hhistoryProp⟩
  have hnegResult : d0.decimal_point.val < 0 -> exp0.val = 0 := by
    intro hneg
    have hsame := (hhistoryProp hfinalInv hstartInv).2.1 hneg
    simpa [sStart, sFinal, stateExp] using hsame.symm
  have hcapacityResult : ∀ (c : Nat) (R : Int),
      0 <= R - exp0.val + 768 - d0.decimal_point.val ->
      0 <= R + 768 - d.decimal_point.val ∧
      (V d0 < (c : Real) * (2 : Real) ^ (R - exp0.val) ->
        V d < (c : Real) * (2 : Real) ^ R) := by
    intro c R hcap0
    have hcap := (hhistoryProp hfinalInv hstartInv).2.2 c R (by
      simpa [sFinal, stateDec, stateExp] using hcap0)
    simpa [sStart, sFinal, stateDec, stateExp] using hcap
  exact ⟨hnegResult, hcapacityResult⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P495_T1_SlowLoop0Execution
import Tablet.P495_T1_RightLoopStep
import Tablet.P529_T1_RightBoundaryTransport
import Tablet.P826_T1_ResultLoopBackward
import Tablet.ResultLoopPartial
import Tablet.P856_T1_CoefficientGridAlignment
import Tablet.P472_T1_DecimalValueBounds
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_RightHistoryBoundary]
theorem P529_T1_RightHistoryBoundary (X Y : Real)
    (d d0 : num.imp.dec2flt.decimal_seq.DecimalSeq) (exp0 : Std.I32)
    (hpointLo : -324 <= d.decimal_point.val)
    (hpointHi : d.decimal_point.val < 310)
    (hinput : d.num_digits.val <= 768 /\
      (forall b, b ∈ d.digits.val.take d.num_digits.val -> b.val < 10) /\
      (exists h tail,
        (d.digits.val.take d.num_digits.val).map (fun b => b.val) = h :: tail /\
        1 <= h /\ h < 10 /\ (h :: tail).length = d.num_digits.val))
    (hcall : num.imp.dec2flt.slow.parse_long_mantissa_loop0
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 0#i32 }
      d.num_digits d.decimal_point d.truncated d.digits 0#i32 none =
        ok (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits, exp0, 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))
    Y = V d + (10 : Real) ^ (d.decimal_point.val - 768) ->
    (exists eta : Real, X = V d + eta /\ 0 <= eta /\
      eta < (10 : Real) ^ (d.decimal_point.val - 768) /\
      (d.truncated = true <-> 0 < eta)) ->
    (d0.decimal_point.val < 0 -> exp0.val = 0) /\
    (forall (c : Nat) (R : Int),
      0 <= R - exp0.val + 768 - d0.decimal_point.val ->
      0 <= R + 768 - d.decimal_point.val /\
      (V d0 < (c : Real) * (2 : Real) ^ (R - exp0.val) ->
        V d < (c : Real) * (2 : Real) ^ R)) := by
-- BODY
  dsimp only
  intro hY hX
  classical
  rcases hX with ⟨eta, hxeq, hetaLo, hetaHi, hsticky⟩
  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))
  rcases hinput with ⟨hcap, hdigit, hlead⟩
  have hrun := P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi
    ⟨hcap, hdigit, hlead⟩ hY ⟨eta, hxeq, hetaLo, hetaHi, hsticky⟩
  rcases hrun with ⟨dF, eF, steps, hrun, hsteps, heFLo, heFHi,
    hXlower, hpFLo, hpFHi, hcapF, hdigitF, hleadF, hlastF, hendF⟩
  have hfinalEq := Result.ok.inj (hrun.symm.trans hcall)
  have hn : dF.num_digits = d0.num_digits := congrArg (fun z => z.1) hfinalEq
  have hp : dF.decimal_point = d0.decimal_point :=
    congrArg (fun z => z.2.1) hfinalEq
  have ht : dF.truncated = d0.truncated := congrArg (fun z => z.2.2.1) hfinalEq
  have ha : dF.digits = d0.digits := congrArg (fun z => z.2.2.2.1) hfinalEq
  have he : eF = exp0 := congrArg (fun z => z.2.2.2.2.1) hfinalEq
  have hterminal : -324 <= d0.decimal_point.val ∧ d0.decimal_point.val <= 0 ∧
      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) := by
    exact ⟨by simpa [hp] using hpFLo, by simpa [hp] using hpFHi,
      by simpa [hn] using hcapF, by simpa [hn, ha] using hdigitF,
      by simpa [hn, ha] using hleadF⟩
  have hendpoints : ∃ eta0 u0 : Real,
      X / (2 : Real) ^ exp0.val = V d0 + eta0 ∧
      Y / (2 : Real) ^ exp0.val = V d0 + u0 ∧
      0 <= eta0 ∧ eta0 < u0 ∧ (d0.truncated = true ↔ 0 < eta0) := by
    simpa [V, he, hn, hp, ht, ha] using hendF
  have hterminalExp : 0 <= exp0.val ∧ exp0.val <= 1260 := by
    constructor
    · simpa [he] using heFLo
    · calc
        exp0.val <= 60 * steps := by simpa [he] using heFHi
        _ <= 60 * 21 := by omega
        _ = 1260 := by norm_num
  have bodyMono (a a' : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (e e' : Std.I32)
      (hb : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 0#i32 }
        a.num_digits a.decimal_point a.truncated a.digits e none =
        ok (cont (a'.num_digits, a'.decimal_point, a'.truncated,
          a'.digits, e', none))) :
      ∃ k : Std.Usize,
        k.val <= 60 ∧ e'.val = e.val + (k.val : Int) ∧
        (19 <= a.decimal_point.val -> k.val = 60) ∧
        (a.decimal_point.val <= 18 ->
          a.decimal_point.val <= (k.val : Int)) := by
    unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hb
    by_cases houter : a.decimal_point > 0#i32
    · simp only [if_pos houter, core.option.Option.is_none] at hb
      split at hb
      · obtain ⟨n, hncast, hnval⟩ := Aeneas.Std.WP.spec_imp_exists
          (IScalar.hcast_inBounds_spec .Usize a.decimal_point (by scalar_tac))
        let traits := F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        let shift : Std.Usize := match n.val with
          | 0 => 0#usize | 1 => 3#usize | 2 => 6#usize | 3 => 9#usize
          | 4 => 13#usize | 5 => 16#usize | 6 => 19#usize | 7 => 23#usize
          | 8 => 26#usize | 9 => 29#usize | 10 => 33#usize | 11 => 36#usize
          | 12 => 39#usize | 13 => 43#usize | 14 => 46#usize | 15 => 49#usize
          | 16 => 53#usize | 17 => 56#usize | 18 => 59#usize | _ => 60#usize
        have hcert := SlowShiftSelectorCertificate traits n
        dsimp only at hcert
        rcases hcert with ⟨hselector, hshift, _, hsmall, hlarge⟩
        have hs : num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok shift := by
          simpa [traits, shift] using hselector
        have hneg : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE =
            ok (-2047)#i32 := by
          unfold num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
          change IScalar.neg (2047#i32 : Std.I32) = _
          unfold IScalar.neg IScalar.tryMk IScalar.tryMkOpt
          norm_num [IScalar.check_bounds, IScalarTy.numBits]
        simp only [Bind.bind, Aeneas.Std.bind, hncast, hs, hneg] at hb
        cases hr : num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift
            { num_digits := a.num_digits, decimal_point := a.decimal_point,
              truncated := a.truncated, digits := a.digits } shift <;>
          simp [hr] at hb
        split at hb
        · simp at hb
        · cases hc : lift (UScalar.hcast .I32 shift) with
          | fail err => simp [hc] at hb
          | div => simp [hc] at hb
          | ok i3 =>
            simp [hc] at hb
            cases ha : e + i3 with
            | fail err => simp [ha] at hb
            | div => simp [ha] at hb
            | ok out =>
              simp [ha] at hb
              have haddval := IScalar.add_equiv e i3
              rw [ha] at haddval
              obtain ⟨_, houtval, _⟩ := haddval
              have hshiftI : (i3.val : Int) = (shift.val : Int) := by
                obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
                  (UScalar.hcast_inBounds_spec .I32 shift (by
                    have hi : (shift.val : Int) <= 60 := by exact_mod_cast hshift
                    rw [IScalar.max_I32_eq]
                    norm_num [IScalarTy.numBits]
                    omega))
                have hz' : lift (UScalar.hcast .I32 shift) = ok z := by
                  simpa [lift] using hz
                have hiz : i3 = z := Result.ok.inj (hc.symm.trans hz')
                subst z
                simpa [WP.spec_ok] using hzval
              have hout : out.val = e.val + (shift.val : Int) := by
                simpa [hshiftI] using houtval
              rcases hb with ⟨_, hpointEq, _, _, houtEq⟩
              have hlargeK : 19 <= a.decimal_point.val -> shift.val = 60 := by
                intro hp
                have hnlarge : 19 <= n.val := by
                  have hn : (n.val : Int) = a.decimal_point.val := by
                    simpa using hnval
                  exact_mod_cast (by omega : (19 : Int) <= (n.val : Int))
                exact (hlarge hnlarge).1
              have hsmallK : a.decimal_point.val <= 18 ->
                  a.decimal_point.val <= (shift.val : Int) := by
                intro hp
                have hn : (n.val : Int) = a.decimal_point.val := by
                  simpa using hnval
                have hnpos : 1 <= n.val := by
                  have hpPos : (0 : Int) < a.decimal_point.val := by
                    simpa only [gt_iff_lt, IScalar.lt_equiv] using houter
                  have hnp : (1 : Int) <= a.decimal_point.val := by omega
                  rw [← hn] at hnp
                  exact_mod_cast hnp
                have hnsmall : n.val <= 18 := by
                  have hnp : (n.val : Int) <= 18 := by rw [hn]; exact hp
                  exact_mod_cast hnp
                have hkSmall : n.val <= shift.val := by
                  have hpow := (hsmall (by omega) hnsmall).2
                  have h2 : 2 ^ n.val <= 10 ^ n.val :=
                    Nat.pow_le_pow_left (by norm_num) _
                  have hpow2 : 2 ^ n.val < 2 ^ (shift.val + 1) :=
                    lt_of_le_of_lt h2 hpow
                  have hexp : n.val < shift.val + 1 :=
                    (Nat.pow_lt_pow_iff_right (by norm_num : 1 < (2 : Nat))).mp hpow2
                  omega
                have hkSmallI : (n.val : Int) <= (shift.val : Int) := by
                  exact_mod_cast (show n.val <= shift.val from hkSmall)
                omega
              refine ⟨shift, hshift, ?_, hlargeK, hsmallK⟩
              have hout' : e'.val = out.val := congrArg IScalar.val houtEq.symm
              omega
      · simp at hb
    · simp [houter] at hb
  let State := Std.Usize × Std.I32 × Bool × (Array Std.U8 768#usize) ×
    Std.I32 × Option num.imp.dec2flt.common.BiasedFp
  let stateDec := fun s : State =>
    num.imp.dec2flt.decimal_seq.DecimalSeq.mk s.1 s.2.1
      s.2.2.1 s.2.2.2.1
  let stateExp := fun s : State => s.2.2.2.2.1
  let stateBody := fun s : State =>
    num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
      { m := 0#u64, p_biased := 0#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 sStart : State := (d.num_digits, d.decimal_point, d.truncated,
    d.digits, 0#i32, none)
  let sFinal : State := (d0.num_digits, d0.decimal_point, d0.truncated,
    d0.digits, exp0, none)
  have hloop : Aeneas.Std.loop stateBody sStart = ok sFinal := by
    simpa [stateBody, sStart, sFinal,
      num.imp.dec2flt.slow.parse_long_mantissa_loop0] using hcall
  let stateInv := fun s : State =>
    let a := stateDec s;
    -324 <= a.decimal_point.val ∧ a.decimal_point.val < 310 ∧
    a.num_digits.val <= 768 ∧
    (forall b, b ∈ a.digits.val.take a.num_digits.val -> b.val < 10) ∧
    (exists h tail,
      (a.digits.val.take a.num_digits.val).map (fun b => b.val) = h :: tail ∧
      1 <= h ∧ h < 10 ∧ (h :: tail).length = a.num_digits.val) ∧
    0 <= (stateExp s).val ∧ (stateExp s).val <= 1260 ∧
    s.2.2.2.2.2 = none ∧
    (exists etaS uS : Real,
      X / (2 : Real) ^ (stateExp s).val = V a + etaS ∧
      Y / (2 : Real) ^ (stateExp s).val = V a + uS ∧
      0 <= etaS ∧ etaS < uS ∧ (a.truncated = true ↔ 0 < etaS))
  have hstartInv : stateInv sStart := by
    dsimp [stateInv, stateDec, stateExp, sStart]
    refine ⟨hpointLo, hpointHi, hcap, hdigit, hlead, by norm_num,
      by norm_num, rfl, ?_⟩
    refine ⟨eta, 10 ^ (d.decimal_point.val - 768), ?_, ?_, hetaLo, ?_, hsticky⟩
    · simpa [V, List.map_take, zpow_zero, div_one] using hxeq
    · simpa [V, List.map_take] using hY
    · dsimp
      exact hetaHi
  have hfinalInv : stateInv sFinal := by
    dsimp [stateInv, stateDec, stateExp, sFinal]
    refine ⟨hterminal.1, ?_, hterminal.2.2.1,
      hterminal.2.2.2.1, hterminal.2.2.2.2,
      hterminalExp.1, hterminalExp.2, rfl, ?_⟩
    · exact lt_of_le_of_lt hterminal.2.1 (by norm_num)
    · exact hendpoints
  have doneIdentity (s t : State)
      (hb : stateBody s = ok (done t)) : s = t := by
    by_cases hp : 0 < s.2.1.val
    · by_cases hn : s.2.2.2.2.2 = none
      · simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
          hp, hn] at hb
        cases hfirst : lift (IScalar.hcast .Usize s.2.1) with
        | fail err => simp [hfirst] at hb
        | div => simp [hfirst] at hb
        | ok n =>
          simp only [Bind.bind, Aeneas.Std.bind, hfirst] at hb
          cases hs : num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
              F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n with
          | fail err => simp [hs] at hb
          | div => simp [hs] at hb
          | ok shift =>
            cases hr : num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift
                { num_digits := s.1, decimal_point := s.2.1,
                  truncated := s.2.2.1, digits := s.2.2.2.1 } shift with
            | fail err => simp [hs, hr] at hb
            | div => simp [hs, hr] at hb
            | ok a =>
              have hneg : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE =
                  ok (-2047)#i32 := by
                unfold num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
                change IScalar.neg (2047#i32 : Std.I32) = _
                unfold IScalar.neg IScalar.tryMk IScalar.tryMkOpt
                norm_num [IScalar.check_bounds, IScalarTy.numBits]
              simp only [hs, hr, hneg] at hb
              split at hb
              · simp at hb
              · cases hc : lift (UScalar.hcast .I32 shift) with
                | fail err => simp [hc] at hb
                | div => simp [hc] at hb
                | ok i3 =>
                  cases ha : s.2.2.2.2.1 + i3 with
                  | fail err => simp [hc, ha] at hb
                  | div => simp [hc, ha] at hb
                  | ok out => simp [hc, ha] at hb
      · simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
          hp, hn] at hb
        exact hb
    · simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
        hp] at hb
      exact hb
  have hExpOrder : ∀ s t, Aeneas.Std.loop stateBody s = ok t →
      t.2.2.2.2.2 = none ->
        s.2.2.2.2.2 = none ∧ (stateExp s).val ≤ (stateExp t).val := by
    apply P826_T1_ResultLoopBackward (fun s t =>
      t.2.2.2.2.2 = none ->
        s.2.2.2.2.2 = none ∧ (stateExp s).val ≤ (stateExp t).val) stateBody
    · intro s t hb
      intro htNone
      have hs := doneIdentity s t hb
      subst t
      exact ⟨htNone, le_rfl⟩
    · intro s s' t hb ih
      intro htNone
      rcases ih htNone with ⟨hnextNone, horder⟩
      have hcurNone : s.2.2.2.2.2 = none := by
        by_contra hn
        simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
          hn] at hb
      have hnextTuple :
          (s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
            s'.2.2.2.2.1, none) = s' := by
        cases s' with
        | mk n rest =>
          cases rest with
          | mk p rest =>
            cases rest with
            | mk b rest =>
              cases rest with
              | mk arr rest =>
                cases rest with
                | mk e opt => simp_all
      have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
            { m := 0#u64, p_biased := 0#i32 }
            (stateDec s).num_digits (stateDec s).decimal_point
            (stateDec s).truncated (stateDec s).digits (stateExp s) none =
            ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
              (stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
        have hb0 := hb
        rw [← hnextTuple] at hb0
        simpa [stateBody, stateDec, stateExp, hcurNone] using hb0
      obtain ⟨k, _, hupdate, _, _⟩ := bodyMono (stateDec s) (stateDec s')
        (stateExp s) (stateExp s') hb'
      have hmono : (stateExp s).val <= (stateExp s').val := by
        have hk : (0 : Int) <= (k.val : Int) := Int.natCast_nonneg _
        omega
      exact ⟨hcurNone, le_trans hmono horder⟩
  let stateCapRel := fun s t : State =>
    ∀ (c : Nat) (R : Int),
      0 <= R - (stateExp t).val + 768 - (stateDec t).decimal_point.val ->
      0 <= R - (stateExp s).val + 768 - (stateDec s).decimal_point.val ∧
      (V (stateDec t) < (c : Real) * (2 : Real) ^ (R - (stateExp t).val) ->
        V (stateDec s) < (c : Real) * (2 : Real) ^ (R - (stateExp s).val))
  let historyRel := fun s t : State =>
    (t.2.2.2.2.2 = none ->
      s.2.2.2.2.2 = none ∧ (stateExp s).val <= (stateExp t).val) ∧
    (stateInv t -> stateInv s ->
      ((stateDec s).decimal_point.val >= 0 ->
        (stateDec t).decimal_point.val >= 0) ∧
      ((stateDec t).decimal_point.val < 0 ->
        (stateExp s).val = (stateExp t).val) ∧
      stateCapRel s t)
  have hhistory : ∀ s t, Aeneas.Std.loop stateBody s = ok t ->
      historyRel s t := (set_option maxHeartbeats 1600000 in by
    apply P826_T1_ResultLoopBackward historyRel stateBody
    · intro s t hb
      have hst := doneIdentity s t hb
      subst t
      constructor
      · intro hnone
        exact ⟨hnone, le_rfl⟩
      · intro htInv hsInv
        refine ⟨fun h => h, fun _ => rfl, ?_⟩
        intro c R hcap
        exact ⟨hcap, fun hlt => hlt⟩
    · intro s s' t hb ih
      constructor
      · intro htNone
        rcases ih.1 htNone with ⟨hnextNone, hexpOrder⟩
        have hcurNone : s.2.2.2.2.2 = none := by
          by_contra hn
          simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
            hn] at hb
        have hnextTuple :
            (s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
              s'.2.2.2.2.1, none) = s' := by
          cases s' with
          | mk n rest =>
            cases rest with
            | mk p rest =>
              cases rest with
              | mk b rest =>
                cases rest with
                | mk arr rest =>
                  cases rest with
                  | mk e opt => simp_all
        have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
              F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
              { m := 0#u64, p_biased := 0#i32 }
              (stateDec s).num_digits (stateDec s).decimal_point
              (stateDec s).truncated (stateDec s).digits (stateExp s) none =
              ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
                (stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
          have hb0 := hb
          rw [← hnextTuple] at hb0
          simpa [stateBody, stateDec, stateExp, hcurNone] using hb0
        obtain ⟨k, _, hupdate, _, _⟩ := bodyMono (stateDec s) (stateDec s')
          (stateExp s) (stateExp s') hb'
        have hkNonneg : (0 : Int) <= (↑↑k : Int) := Int.natCast_nonneg _
        have hmono : (stateExp s).val <= (stateExp s').val := by omega
        exact ⟨hcurNone, le_trans hmono hexpOrder⟩
      · intro htInv hsInv
        have htInvSaved := htInv
        dsimp only [stateInv, stateDec, stateExp] at htInv hsInv
        rcases htInv with ⟨hpLoT, hpHiT, hcountT, hdigitT, hshapeT,
          hexpLoT, hexpHiT, hsentT, hendT⟩
        rcases hsInv with ⟨hpLoS, hpHiS, hcountS, hdigitS, hshapeS,
          hexpLoS, hexpHiS, hsentS, hendS⟩
        rcases hshapeS with ⟨headS, tailS, hshapeS, hheadS, hhead10S, hlenS⟩
        have hnextBound := ih.1 hsentT
        rcases hnextBound with ⟨hsentNext, hexpNextT⟩
        have hpointPos : 1 <= (stateDec s).decimal_point.val := by
          change 1 <= s.2.1.val
          by_contra hn
          have hp : ¬ 0 < s.2.1.val := by omega
          simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
            hp] at hb
        rcases hendS with ⟨etaS, uS, hXS, hYS, hetaS, hetauS, hstickyS⟩
        have hstep := P495_T1_RightLoopStep (X / (2 : Real) ^ (stateExp s).val)
          (Y / (2 : Real) ^ (stateExp s).val) (stateDec s) (stateExp s)
          hpointPos hpHiS hexpLoS hexpHiS
          ⟨hcountS, hdigitS,
            ⟨headS, tailS, hshapeS, hheadS, hhead10S, hlenS⟩⟩
          ⟨etaS, uS, hXS, hYS, hetaS, hetauS, hstickyS⟩
        rcases hstep with ⟨dn, shift, en, hbStep, hright, hshift, hexpStep,
          hpLarge, hpSmall, hcountN, hdigitN, hshapeN, htrimN,
          hendN, hstall, hrecover⟩
        have hpLargeS : 19 <= s.2.1.val ->
            dn.decimal_point.val = s.2.1.val - 18 ∨
              dn.decimal_point.val = s.2.1.val - 19 := by
          simpa [stateDec] using hpLarge
        have hpSmallS : s.2.1.val <= 18 ->
            dn.decimal_point.val = 0 ∨ dn.decimal_point.val = 1 := by
          simpa [stateDec] using hpSmall
        have hnextTuple :
            (dn.num_digits, dn.decimal_point, dn.truncated, dn.digits,
              en, none) = s' := by
          have hb0 := hb
          have hnextTuple0 :
              (s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
                s'.2.2.2.2.1, none) = s' := by
            cases s' with
            | mk n rest =>
              cases rest with
              | mk p rest =>
                cases rest with
                | mk b rest =>
                  cases rest with
                  | mk arr rest =>
                    cases rest with
                    | mk e opt => simp_all
          rw [← hnextTuple0] at hb0
          have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
              F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
              { m := 0#u64, p_biased := 0#i32 }
              (stateDec s).num_digits (stateDec s).decimal_point
              (stateDec s).truncated (stateDec s).digits (stateExp s) none =
              ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
                (stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
            simpa [stateBody, stateDec, stateExp, hsentS] using hb0
          have hEq := Result.ok.inj (hbStep.symm.trans hb')
          injection hEq with htup
          rw [← hnextTuple0]
          simpa [stateDec, stateExp] using htup
        have hpointNLo : -324 <= dn.decimal_point.val := by
          by_cases hlarge : 19 <= s.2.1.val
          · rcases hpLargeS hlarge with hp | hp <;> omega
          · rcases hpSmallS (by omega) with hp | hp <;> omega
        have hpointNHi : dn.decimal_point.val < 310 := by
          by_cases hlarge : 19 <= s.2.1.val
          · rcases hpLargeS hlarge with hp | hp <;> omega
          · rcases hpSmallS (by omega) with hp | hp <;> omega
        have henEq : en = stateExp s' := by
          have hh := congrArg (fun z : State => z.2.2.2.2.1) hnextTuple
          simpa [stateExp] using hh
        rcases hendN with ⟨etaN, uN, hXN, hYN, hetaN, hetauN, hstickyN⟩
        have hscaleX : X / (2 : Real) ^
            ((stateExp s).val + (shift.val : Int)) =
            (X / (2 : Real) ^ (stateExp s).val) /
              (2 : Real) ^ (shift.val : Int) := by
          rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _]
          ring
        have hscaleY : Y / (2 : Real) ^
            ((stateExp s).val + (shift.val : Int)) =
            (Y / (2 : Real) ^ (stateExp s).val) /
              (2 : Real) ^ (shift.val : Int) := by
          rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _]
          ring
        have hXNext : X / (2 : Real) ^ en.val = V dn + etaN := by
          rw [hexpStep, hscaleX]
          exact hXN
        have hYNext : Y / (2 : Real) ^ en.val = V dn + uN := by
          rw [hexpStep, hscaleY]
          exact hYN
        have hnextInv : stateInv s' := by
          rw [← hnextTuple]
          dsimp only [stateInv, stateDec, stateExp]
          refine ⟨hpointNLo, hpointNHi, hcountN, hdigitN, hshapeN,
            ?_, ?_, rfl, ?_⟩
          · rw [hexpStep]
            have hshiftNonneg : (0 : Int) <= (↑↑shift : Int) := by
              exact Int.natCast_nonneg _
            exact add_nonneg hexpLoS hshiftNonneg
          · have hupper : (stateExp s').val <= 1260 :=
              le_trans hexpNextT hexpHiT
            simpa [henEq] using hupper
          · exact ⟨etaN, uN, hXNext, hYNext, hetaN, hetauN, hstickyN⟩
        have hback := ih.2 htInvSaved hnextInv
        rcases hback with ⟨hpointBack, hnegativeBack, hcapBack⟩
        have hpNextNonneg : 0 <= dn.decimal_point.val := by
          by_cases hlarge : 19 <= s.2.1.val
          · rcases hpLargeS hlarge with hp | hp <;> omega
          · rcases hpSmallS (by omega) with hp | hp <;> omega
        have hpNextState : 0 <= (stateDec s').decimal_point.val := by
          have hpointEq : dn.decimal_point = s'.2.1 := by
            have hh := congrArg (fun z : State => z.2.1) hnextTuple
            simpa using hh
          simpa [stateDec, hpointEq] using hpNextNonneg
        refine ⟨?_, ?_, ?_⟩
        · intro _
          exact hpointBack hpNextState
        · intro hpT
          have hpT' : 0 <= (stateDec t).decimal_point.val := hpointBack hpNextState
          omega
        · intro c R hcapT
          rcases hcapBack c R hcapT with ⟨hcapNext, hstrictNext⟩
          have hbodyMono : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
              F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
              { m := 0#u64, p_biased := 0#i32 }
              (stateDec s).num_digits (stateDec s).decimal_point
              (stateDec s).truncated (stateDec s).digits (stateExp s) none =
              ok (cont (dn.num_digits, dn.decimal_point, dn.truncated,
                dn.digits, en, none)) := by
            have hb0 := hb
            rw [← hnextTuple] at hb0
            simpa [stateBody, stateDec, stateExp, hsentS] using hb0
          obtain ⟨k, hkBound, hkUpdate, hkLarge, hkSmall⟩ :=
            bodyMono (stateDec s) dn (stateExp s) en hbodyMono
          have hkEq : (k.val : Int) = (shift.val : Int) := by
            omega
          have hpointDiff : s.2.1.val - dn.decimal_point.val <=
              (shift.val : Int) := by
            by_cases hlarge : 19 <= s.2.1.val
            · have hp := hpLargeS hlarge
              rcases hp with hp | hp
              · rw [hp]
                have h60 : (shift.val : Int) = 60 := by
                  have hkNat : k.val = 60 := hkLarge (by simpa [stateDec] using hlarge)
                  omega
                omega
              · rw [hp]
                have h60 : (shift.val : Int) = 60 := by
                  have hkNat : k.val = 60 := hkLarge (by simpa [stateDec] using hlarge)
                  omega
                omega
            · have hpSmallS' : s.2.1.val <= 18 := by omega
              have hp := hpSmallS hpSmallS'
              rcases hp with hp | hp
              · rw [hp]
                have hkP := hkSmall (by simpa [stateDec] using hpSmallS')
                change s.2.1.val <= (k.val : Int) at hkP
                omega
              · rw [hp]
                have hkP := hkSmall (by simpa [stateDec] using hpSmallS')
                change s.2.1.val <= (k.val : Int) at hkP
                omega
          have hcapSource : 0 <= R - (stateExp s).val + 768 -
              (stateDec s).decimal_point.val := by
            have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
              have hh := congrArg (fun z : State => z.2.1) hnextTuple
              simpa [stateDec] using hh
            have hcapNext' : 0 <= R - en.val + 768 - dn.decimal_point.val := by
              have heVal := congrArg IScalar.val henEq
              have hpVal : dn.decimal_point.val =
                  (stateDec s').decimal_point.val := by simpa using congrArg IScalar.val hpEq
              rw [heVal, hpVal]
              exact hcapNext
            change 0 <= R - (stateExp s).val + 768 - s.2.1.val
            omega
          have hstrictSource :
              V (stateDec t) < (c : Real) *
                (2 : Real) ^ (R - (stateExp t).val) ->
              V (stateDec s) < (c : Real) *
                (2 : Real) ^ (R - (stateExp s).val) :=
              (set_option maxHeartbeats 1600000 in by
            intro hstrictTerminal
            by_contra hnot
            have hle : (c : Real) * (2 : Real) ^
                (R - (stateExp s).val) <= V (stateDec s) := le_of_not_gt hnot
            have hgrid := P856_T1_CoefficientGridAlignment c
              (R - en.val) dn.decimal_point.val (by omega) (by
                have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
                  have hh := congrArg (fun z : State => z.2.1) hnextTuple
                  simpa [stateDec] using hh
                have heVal := congrArg IScalar.val henEq
                have hpVal : dn.decimal_point.val =
                    (stateDec s').decimal_point.val := by simpa using congrArg IScalar.val hpEq
                rw [heVal, hpVal]
                exact hcapNext)
            rcases hgrid with ⟨b, hbgrid⟩
            have hpowRel : (2 : Real) ^ (R - (stateExp s).val) =
                (2 : Real) ^ (R - en.val) * (2 : Real) ^ shift.val := by
              rw [show R - (stateExp s).val = (R - en.val) +
                (shift.val : Int) by omega]
              rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
              norm_num [zpow_natCast]
            have hmulBound : (c : Real) *
                (2 : Real) ^ (R - en.val) * (2 : Real) ^ shift.val <=
                V (stateDec s) := by
              calc
                (c : Real) * (2 : Real) ^ (R - en.val) *
                    (2 : Real) ^ shift.val =
                    (c : Real) * ((2 : Real) ^ (R - en.val) *
                      (2 : Real) ^ shift.val) := by ring
                _ = (c : Real) * (2 : Real) ^
                    (R - (stateExp s).val) := by rw [← hpowRel]
                _ <= V (stateDec s) := hle
            have hshiftPos : (0 : Real) < (2 : Real) ^ shift.val := by
              positivity
            have hnatpow : (2 : Real) ^ shift.val =
                (2 : Real) ^ (shift.val : Int) := by
              norm_num [zpow_natCast]
            have hboundary : (b : Real) *
                (10 : Real) ^ (dn.decimal_point.val - 768) <=
                V (stateDec s) / (2 : Real) ^ shift.val := by
              rw [← hbgrid, hnatpow]
              exact (le_div_iff₀ hshiftPos).2 (by simpa [mul_assoc] using hmulBound)
            have hnonreset : ¬ (dn.num_digits.val = 0 ∧
                dn.decimal_point.val = 0 ∧ dn.truncated = false) := by
              intro hreset
              rcases hshapeN with ⟨headN, tailN, _, hheadN, _, hlenN⟩
              have hposN : 1 <= dn.num_digits.val := by
                rw [← hlenN]
                simp
              omega
            have hxs := hdigitS
            have hvbounds := P472_T1_DecimalValueBounds
              ((stateDec s).digits.val.take (stateDec s).num_digits.val |>.map
                (fun z => z.val)) headS tailS hshapeS hheadS
              (fun q hq => by
                rcases List.mem_map.mp hq with ⟨z, hz, hzq⟩
                have hzd := hdigitS z hz
                simpa [hzq] using hzd)
              (stateDec s).decimal_point.val
            have hVpositive : 0 < V (stateDec s) := by
              have hlow := hvbounds.1
              have hpowpos : (0 : Real) < (10 : Real) ^
                  ((stateDec s).decimal_point.val - 1) := by
                exact zpow_pos (by norm_num) _
              have hheadReal : (1 : Real) <= (headS : Real) := by
                exact_mod_cast hheadS
              have hprod : 0 < (headS : Real) * (10 : Real) ^
                  ((stateDec s).decimal_point.val - 1) :=
                mul_pos (by linarith) hpowpos
              have hlow' : (headS : Real) * (10 : Real) ^
                    ((stateDec s).decimal_point.val - 1) <=
                  V (stateDec s) := by
                rw [hshapeS, hlenS] at hlow
                dsimp only [V]
                rw [hshapeS]
                simpa [V, List.map_take, List.foldl_cons] using hlow
              exact lt_of_lt_of_le hprod hlow'
            have htransport := P529_T1_RightBoundaryTransport
              (stateDec s) dn shift hshift hdigitS hright hnonreset hcountN
              hVpositive b hboundary
            have hstrictNext' : V dn <
                (c : Real) * (2 : Real) ^ (R - en.val) := by
              have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
                have hh := congrArg (fun z : State => z.2.1) hnextTuple
                simpa [stateDec] using hh
              have hnEq : dn.num_digits = (stateDec s').num_digits := by
                have hh := congrArg (fun z : State => z.1) hnextTuple
                simpa [stateDec] using hh
              have hdEq : dn.digits = (stateDec s').digits := by
                have hh := congrArg (fun z : State => z.2.2.2.1) hnextTuple
                simpa [stateDec] using hh
              have hstrictNextInput := hstrictNext hstrictTerminal
              simpa [V, stateDec, hpEq, hnEq, hdEq, henEq] using hstrictNextInput
            have hstrictGrid : V dn < (b : Real) *
                (10 : Real) ^ (dn.decimal_point.val - 768) := by
              rw [← hbgrid]
              exact hstrictNext'
            exact (not_lt_of_ge htransport) hstrictGrid
              )
          exact ⟨hcapSource, hstrictSource⟩
  )
  have hhist := hhistory sStart sFinal hloop
  rcases hhist with ⟨hfinalNone, hhistoryProp⟩
  have hnegResult : d0.decimal_point.val < 0 -> exp0.val = 0 := by
    intro hneg
    have hsame := (hhistoryProp hfinalInv hstartInv).2.1 hneg
    simpa [sStart, sFinal, stateExp] using hsame.symm
  have hcapacityResult : ∀ (c : Nat) (R : Int),
      0 <= R - exp0.val + 768 - d0.decimal_point.val ->
      0 <= R + 768 - d.decimal_point.val ∧
      (V d0 < (c : Real) * (2 : Real) ^ (R - exp0.val) ->
        V d < (c : Real) * (2 : Real) ^ R) := by
    intro c R hcap0
    have hcap := (hhistoryProp hfinalInv hstartInv).2.2 c R (by
      simpa [sFinal, stateDec, stateExp] using hcap0)
    simpa [sStart, sFinal, stateDec, stateExp] using hcap
  exact ⟨hnegResult, hcapacityResult⟩

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 133 entries
Technical checking records
Local closure summary
{
  "node": "P529_T1_RightHistoryBoundary",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "1db27f176bffd8fe67e4ce2cdb351d999d2e0c6a3b269b6fe33798333e613560",
  "active_statement_hash": "d6933e70ddfd44043a39018b3ec7c2ed57851cd8991efa87bdce47fa72efb865",
  "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-188",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "P472_T1_DecimalValueBounds": "4b5c924b5d52bc9d",
    "P495_T1_RightLoopStep": "b873eecaa227a3e1",
    "P495_T1_SlowLoop0Execution": "5a1e49d921a1825a",
    "P529_T1_RightBoundaryTransport": "bb615631f8d7363c",
    "P826_T1_ResultLoopBackward": "46222c89d1819e7b",
    "P856_T1_CoefficientGridAlignment": "811bf9ec1aa2ffd7",
    "SlowShiftSelectorCertificate": "963b7a2e670856e8",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE": "01b84a7a35e5bcf4",
    "num_imp_dec2flt_slow_parse_long_mantissa": "0eb6fb2627d0ff5c"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "SlowShiftSelectorCertificate": "7ebc2b39d69850c4",
    "num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE": "0cc5155758bc976a",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "1aaf1bb11c0b6a49",
    "num_imp_dec2flt_slow_parse_long_mantissa": "0ce7bdcf55d68c29",
    "num_imp_dec2flt_slow_parse_long_mantissa_closure_Insts_CoreOpsFunctionFnTupleUsizeUsize_call": "7df8a2c8e3717790",
    "num_imp_traits_Float": "94ab5f784cdf5db8"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:0efb1dad0a913512bc6c20f52075b24fecbbd4a32872959070652e2b282ea4f0",
  "current_fingerprint": "sound-v2:0efb1dad0a913512bc6c20f52075b24fecbbd4a32872959070652e2b282ea4f0",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}