P495_T1_SlowLoop0Execution

Lean checked

Statement

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

Lemma · Normal first normalization loop with fixed endpoints

Let d have count at most 768, decimal retained cells, a positive leading digit, exact prefix length, and point -324\le p<310. Define V as retained decimal value and fix Y=V(d)+10^{p-768}. Suppose X=V(d)+\eta, 0\le\eta<10^{p-768}, and sticky is true iff \eta>0. The actual specialized slow loop 0, initialized with exponent zero and no early result, returns normally with (d_0,e_0,\mathsf{none}). There is an existential natural bound witness s\in\mathbb N satisfying s\le21 and 0\le e_0\le60s. Its point satisfies -324\le p_0\le0, its count is at most 768, and its retained list is decimal, positive-headed, and of exact count length. Either s=0 or its last retained cell is nonzero. The statement does not claim that s equals the number of executed shifts. Moreover 10^{-325}\le X, and there are \eta_0,u_0 satisfying X/2^{e_0}=V(d_0)+\eta_0, Y/2^{e_0}=V(d_0)+u_0, 0\le\eta_0<u_0, and exact output-sticky equivalence. No successful enclosing slow or public call is a hypothesis.

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_RightLoopStep

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P495_T1_SlowLoop0Execution]
theorem P495_T1_SlowLoop0Execution (X Y : Real)
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (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)) :
    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 : Int)) ->
    (exists eta : Real, X = V d + eta /\ 0 <= eta /\
      eta < (10 : Real) ^ (d.decimal_point.val - (768 : Int)) /\
      (d.truncated = true <-> 0 < eta)) ->
    exists (d0 : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (exp0 : Std.I32) (steps : Nat),
      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) /\
      steps <= 21 /\ 0 <= exp0.val /\ exp0.val <= (60 : Int) * steps /\
      (10 : Real) ^ (-325 : Int) <= X /\
      -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) /\
      (steps = 0 \/ d0.digits.val[d0.num_digits.val - 1]? ≠ some 0#u8) /\
      (exists 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
Proof

Natural-language proof

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

Explanatory prose status

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

Proof

Use loop 0 in num imp dec2flt slow parse long mantissa. For a current record a, point r, and exponent e, use a proof-local counter j\in\mathbb N for completed shifts, initially zero and incremented on each actual continuation. This counter is proof bookkeeping, separate from the exported existential bound witness s. Maintain: early result None; -324\le r<310; 0\le e\le60j; count at most 768, decimal retained cells and positive-head exact-length shape; and
X/2^e=V(a)+\alpha,\quad Y/2^e=V(a)+v,\quad 0\le\alpha<v,\quad a.\mathit{truncated}\iff\alpha>0. \tag{1}
Maintain also j=0 or a nonzero last retained cell, and the budgets
\begin{array}{ll} r\ge19&\Longrightarrow18j+r\le309,\\ 2\le r\le18&\Longrightarrow j\le17,\\ r=1,\ \text{head}=1&\Longrightarrow j\le19,\\ r=1,\ \text{head}\ne1&\Longrightarrow j\le18,\\ r\le0&\Longrightarrow j\le20. \end{array} \tag{2}
Initially e=j=0. The supplied \eta and the positive v=10^{p-768} prove (1); initial shape and point bounds are hypotheses. The integral bound p<310 gives p\le309, proving the first budget, and all other budgets hold with j=0. The terminal-cell disjunction holds because j=0, WITHOUT requiring the capped initial prefix to be trimmed.
For r\le0, the actual body returns this state unchanged. For r>0, (2) gives j\le20 and hence 0\le e\le1200\le1260. Apply RightLoopStep with endpoints X/2^e,Y/2^e and the current record. Its positive-point, upper-point, exponent, shape, and endpoint hypotheses follow from the invariant. It constructs the actual normal body continuation, shift k\le60, record a', and exact checked exponent update e'=e+k; no reset or early-result arm is taken. The update is checked-safe at that instant, and e'\le60(j+1). Its canonicality conclusions preserve shape and give the nonzero terminal cell for the new positive step count. Its endpoint conclusions give (1) at the successor by (X/2^e)/2^k=X/2^{e+k}, and the analogous identity for Y, using positivity of two and its integer-power addition law. Its quantitative point alternatives give r'\ge0 and r'<310, hence the point invariant.
Check every budget for j+1. If r\ge19, its successor is r-18 or r-19. If r'\ge19, then 18(j+1)+r'\le18j+r\le309. If r' enters a smaller regime, the old budget and r\ge19 give j\le16, so j+1\le17, sufficient for every smaller-regime budget. If 2\le r\le18, the successor is zero or one and j+1\le18. This gives both point-one budgets and the terminal budget. If r=1 and its head is one, the step principal forces r'=0 and j+1\le20. If r=1 and its head is not one, j+1\le19; a stall at one has new head exactly one, so its required budget is 19, while an exit at zero has budget 20. The non-head-one budget at a stalled successor is vacuous. These cover every continuation.
For termination use rank zero when r\le0, and when r>0 use 2r+\epsilon, where \epsilon=0 for head one and \epsilon=1 otherwise. It is a natural number because r>0 is integral. A large point decreases by at least 18, so the rank falls even if \epsilon increases. A point from two to eighteen moves to zero or one, whose rank is at most three, below the old rank at least four. At point one, a head-one state exits to rank zero; a non-head-one stall changes rank three to two because the new head is one. Thus every continuation has strictly smaller rank. Well-founded loop induction using the invariant and these actual normal body equations constructs a normal terminal result. None is preserved at every step, and termination requires r\le0. The last budget gives j\le20. Choose the exported natural bound witness s=j. Then s\le21 and 0\le e_0\le60s follow from the budget and exponent invariant, and s=0 or a nonzero last retained cell follows from the terminal-cell invariant. This choice establishes the existential clauses without asserting an execution-count identity in the statement. All other output and endpoint clauses are the invariant's terminal clauses, including the conditional terminal trimming.
Finally DecimalValueBounds on the INITIAL positive retained list gives V(d)\ge h10^{p-1}\ge10^{p-1}. Since p\ge-324, powers of ten are increasing and 10^{p-1}\ge10^{-325}. The initial X=V(d)+\eta with \eta\ge0 therefore gives X\ge10^{-325}. This establishes the remaining conjunct independently of the loop and completes the construction.

Lean proof


  exact (set_option maxHeartbeats 1600000 in by
    dsimp only
    intro hY hX
    classical
    rcases hinput with ⟨hnum, hdigit, hshape⟩
    rcases hshape with ⟨h, tail, hmap, hhle, hhh, hlen⟩
    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))
    let eta := X - V d
    let u := (10 : Real) ^ (d.decimal_point.val - (768 : Int))
    have hXeq : X = V d + eta := by dsimp [eta]; ring
    have heta0 : 0 <= eta := by
      rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
      rw [heq] at hXeq
      have : eta = eta' := by linarith
      simpa [this] using hlo
    have hetaU : eta < u := by
      rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
      have : eta = eta' := by linarith [hXeq, heq]
      simpa [u] using (by simpa [this] using hhi)
    have hsticky : d.truncated = true ↔ 0 < eta := by
      rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
      have : eta = eta' := by linarith [hXeq, heq]
      simpa [this] using htr
    have huPos : 0 < u := by
      dsimp [u]
      exact zpow_pos (by norm_num) _
    have hYeq : Y = V d + u := by simpa [u, V] using hY
    have hpupper : d.decimal_point.val ≤ 309 := by omega
    have hXlower : (10 : Real) ^ (-325 : Int) ≤ X := by
      have hv := P472_T1_DecimalValueBounds
        ((d.digits.val.take d.num_digits.val).map (fun b => b.val)) h tail
        (by simpa [hmap]) hhle
        (by intro q hq; rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩; exact hdigit b hb)
        d.decimal_point.val
      dsimp at hv
      have hlen' :
          ((d.digits.val.take d.num_digits.val).map (fun b => b.val)).length =
            d.num_digits.val := by
        rw [hmap]
        simpa using hlen
      have hnumNat : d.num_digits.val ≤ 768 := by exact_mod_cast hnum
      have hlenMap :
          (List.take d.num_digits.val (List.map (fun b => b.val) d.digits.val)).length =
            d.num_digits.val := by
        simp [List.length_take, Nat.min_eq_left hnumNat]
      have hpow : (10 : Real) ^ (-325 : Int) ≤
          (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
        have hh : (10 : Real) ^ (-325 : Int) ≤
            (10 : Real) ^ (d.decimal_point.val - 1) := by
          apply zpow_right_mono₀ (by norm_num : (1 : Real) ≤ 10)
          omega
        have h10pos : 0 < (10 : Real) ^ (d.decimal_point.val - 1) :=
          zpow_pos (by norm_num) _
        calc
          (10 : Real) ^ (-325 : Int) ≤ (10 : Real) ^ (d.decimal_point.val - 1) := hh
          _ ≤ (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
            have hhleR : (1 : Real) ≤ (h : Real) := by exact_mod_cast hhle
            nlinarith [h10pos, hhleR]
      have hVlo : (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) ≤ V d := by
        have htmp := hv.1
        change (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) ≤
          (((((d.digits.val.take d.num_digits.val).map (fun b => b.val)).foldl
            (fun n z => 10 * n + z) 0 : Nat) : Real) *
            (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)))
        rw [List.map_take] at htmp
        rw [hlenMap] at htmp
        rw [List.map_take]
        exact htmp
      rw [hXeq]
      linarith
    -- The loop invariant records a completed-shift counter separately from
    -- the exported existential bound witness.
    let recOf := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
        Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
      ({ 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 rank := fun (p : Int) (headOne : Bool) =>
      if p <= 0 then 0 else 2 * p.toNat + (if headOne then 0 else 1)
    let measure := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
        Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
      rank (recOf s).decimal_point.val
        (decide (((((recOf s).digits.val.take (recOf s).num_digits.val).map
          (fun b => b.val)).headD 0) = 1))
    have rank_step (p p' : Int) (headOne headOne' : Bool)
        (hp : 1 ≤ p) (hp' : 0 ≤ p')
        (hstep : (19 ≤ p ∧ (p' = p - 18 ∨ p' = p - 19)) ∨
          (2 ≤ p ∧ p ≤ 18 ∧ (p' = 0 ∨ p' = 1)) ∨
          (p = 1 ∧ headOne = true ∧ p' = 0) ∨
          (p = 1 ∧ headOne = false ∧
            (p' = 0 ∨ (p' = 1 ∧ headOne' = true)))) :
        rank p' headOne' < rank p headOne := by
      rcases hstep with h | h | h | h
      all_goals cases headOne <;> cases headOne'
      all_goals simp_all [rank]
      all_goals split_ifs <;> omega
    let Inv := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
        Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
      ∃ j : Nat,
        s.2.2.2.2.2 = none ∧
        -324 ≤ (recOf s).decimal_point.val ∧ (recOf s).decimal_point.val < 310 ∧
        0 ≤ s.2.2.2.2.1.val ∧
        s.2.2.2.2.1.val ≤ 60 * (j : Int) ∧
        (recOf s).num_digits.val ≤ 768 ∧
        (∀ b, b ∈ (recOf s).digits.val.take (recOf s).num_digits.val -> b.val < 10) ∧
        (∃ h tail,
          ((recOf s).digits.val.take (recOf s).num_digits.val).map
            (fun b => b.val) = h :: tail ∧ 1 ≤ h ∧ h < 10 ∧
            (h :: tail).length = (recOf s).num_digits.val) ∧
        (j = 0 ∨ (recOf s).digits.val[(recOf s).num_digits.val - 1]? ≠ some 0#u8) ∧
        (∃ alpha v : Real,
          X / (2 : Real) ^ s.2.2.2.2.1.val = V (recOf s) + alpha ∧
          Y / (2 : Real) ^ s.2.2.2.2.1.val = V (recOf s) + v ∧
          0 ≤ alpha ∧ alpha < v ∧
          ((recOf s).truncated = true ↔ 0 < alpha)) ∧
        ((19 ≤ (recOf s).decimal_point.val -> 18 * (j : Int) +
            (recOf s).decimal_point.val ≤ 309) ∧
         (2 ≤ (recOf s).decimal_point.val ->
            (recOf s).decimal_point.val ≤ 18 -> j ≤ 17) ∧
         ((recOf s).decimal_point.val = 1 ->
            (((((recOf s).digits.val.take (recOf s).num_digits.val).map
              (fun b => b.val)).headD 0) = 1 -> j ≤ 19)) ∧
         ((recOf s).decimal_point.val = 1 ->
            (((((recOf s).digits.val.take (recOf s).num_digits.val).map
              (fun b => b.val)).headD 0) ≠ 1 -> j ≤ 18)) ∧
         ((recOf s).decimal_point.val ≤ 0 -> j ≤ 20))
    let Post := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
        Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
      Inv s ∧ (recOf s).decimal_point.val ≤ 0
    let s0 := (d.num_digits, d.decimal_point, d.truncated, d.digits,
      (0#i32 : Std.I32), (none : Option num.imp.dec2flt.common.BiasedFp))
    have hstart : Inv s0 := by
      simp only [Inv, recOf, s0]
      refine ⟨0, trivial, ?_⟩
      constructor
      · exact hpointLo
      constructor
      · exact hpointHi
      constructor
      · norm_num
      constructor
      · norm_num
      constructor
      · exact hnum
      constructor
      · exact hdigit
      constructor
      · exact ⟨h, tail, hmap, hhle, hhh, hlen⟩
      constructor
      · exact Or.inl rfl
      constructor
      · refine ⟨eta, u, ?_⟩
        constructor
        · simpa [V] using hXeq
        constructor
        · simpa [V] using hYeq
        constructor
        · exact heta0
        constructor
        · exact hetaU
        · exact hsticky
      constructor
      · intro hp
        omega
      constructor
      · intro hp hp18
        omega
      constructor
      · intro hp
        omega
      constructor
      · intro hp
        omega
      · intro hp
        omega
    have hloop : Aeneas.Std.WP.spec
        (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) Post := by
      unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0
      apply Aeneas.Std.loop.spec_decr_nat measure Inv Post
        (fun s => 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)
        s0
      · intro s hs
        rcases s with ⟨n, p, tr, a, e, res⟩
        simp only [Prod.fst, Prod.snd] at hs ⊢
        have hsInv := hs
        rcases hs with ⟨j, hres, hpLo, hpHi, heLo, heHi, hn, hd, hshape,
          htrim, hends, hbudgets⟩
        let cur : num.imp.dec2flt.decimal_seq.DecimalSeq :=
          { num_digits := n, decimal_point := p, truncated := tr, digits := a }
        have hresNone : res = none := by simpa using hres
        have hshape' := hshape
        rcases hshape with ⟨head, tail, hmap', hheadLo, hheadHi, hlen'⟩
        have hbLarge : 19 ≤ p.val -> 18 * (j : Int) + p.val ≤ 309 := by
          intro hl
          have h := hbudgets.1 (by simpa [cur, recOf] using hl)
          simpa [cur, recOf] using h
        have hbMedium : 2 ≤ p.val -> p.val ≤ 18 -> j ≤ 17 := by
          intro hm hm18
          exact hbudgets.2.1 (by simpa [cur, recOf] using hm)
            (by simpa [cur, recOf] using hm18)
        have hbHeadOne : p.val = 1 -> head = 1 -> j ≤ 19 := by
          intro hp1 hh
          have hh' :
              (((a.val.take n.val).map (fun b => b.val)).headD 0) = 1 := by
            have hh'' := congrArg (fun xs : List Nat => xs.headD 0) hmap'
            have hhval :
                (((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
              simpa using hh''
            rw [hhval]
            exact hh
          exact hbudgets.2.2.1 (by simpa [cur, recOf] using hp1)
            (by simpa [cur, recOf, List.headD, hmap'] using hh')
        have hbHeadOther : p.val = 1 -> head ≠ 1 -> j ≤ 18 := by
          intro hp1 hh
          have hh' :
              (((a.val.take n.val).map (fun b => b.val)).headD 0) ≠ 1 := by
            have hh'' := congrArg (fun xs : List Nat => xs.headD 0) hmap'
            have hhval :
                (((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
              simpa using hh''
            rw [hhval]
            exact hh
          exact hbudgets.2.2.2.1 (by simpa [cur, recOf] using hp1)
            (by simpa [cur, recOf, List.headD, hmap'] using hh')
        have hbodySpec :
            num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
              F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
              { m := 0#u64, p_biased := 0#i32 }
              n p tr a e res
              ⦃ r => match r with
                | done y => Post y
                | cont y => Inv y ∧ measure y < measure (n, p, tr, a, e, res) ⦄ := by
          by_cases hp : p > 0#i32
          · have hpPos : 0 < p.val := by simpa using hp
            have hpInt : 1 ≤ p.val := by omega
            have hj : j ≤ 20 := by
              by_cases hl : 19 ≤ p.val
              · have hb := hbudgets.1 (by simpa [cur, recOf] using hl)
                have hjInt : (j : Int) ≤ 20 := by
                  have : 18 * (j : Int) + p.val ≤ 309 := hb
                  omega
                exact_mod_cast hjInt
              · by_cases hm : 2 ≤ p.val
                · have hb := hbudgets.2.1 (by simpa [cur, recOf] using hm)
                    (by have hm18 : p.val ≤ 18 := by omega
                        simpa [cur, recOf] using hm18)
                  omega
                · have hone : p.val = 1 := by omega
                  by_cases hheadone : head = 1
                  · have hheadVal :
                      (List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = head := by
                      rw [← List.map_take, hmap']
                      rfl
                    have hheadOne :
                        (List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = 1 := by
                      rw [hheadVal]
                      exact hheadone
                    have hb := hbudgets.2.2.1 (by simpa [cur, recOf] using hone)
                      (by simpa [cur, recOf, List.headD] using hheadOne)
                    omega
                  · have hheadVal :
                      (List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = head := by
                      rw [← List.map_take, hmap']
                      rfl
                    have hheadNotOne :
                        (List.take n.val (List.map (fun b => b.val) a.val)).headD 0 ≠ 1 := by
                      rw [hheadVal]
                      exact hheadone
                    have hb := hbudgets.2.2.2.1 (by simpa [cur, recOf] using hone)
                      (by simpa [cur, recOf, List.headD] using hheadNotOne)
                    omega
            have heHi1260 : e.val ≤ 1260 := by
              have hjInt : (j : Int) ≤ 20 := by exact_mod_cast hj
              have he1200 : e.val ≤ 60 * 20 := by
                calc
                  e.val ≤ 60 * (j : Int) := heHi
                  _ ≤ 60 * 20 := by nlinarith
              omega
            rcases hends with ⟨alpha, v, hXend, hYend, halpha, hlt, hsticky'⟩
            have hinputCur : n.val ≤ 768 ∧
                (∀ b, b ∈ a.val.take n.val -> b.val < 10) ∧
                (∃ hh tt, (a.val.take n.val).map (fun b => b.val) = hh :: tt ∧
                  1 ≤ hh ∧ hh < 10 ∧ (hh :: tt).length = n.val) := by
              simpa [cur, recOf] using And.intro hn (And.intro hd hshape')
            have hstep := P495_T1_RightLoopStep
              (X / (2 : Real) ^ e.val) (Y / (2 : Real) ^ e.val) cur e
              (by simpa [cur, recOf] using hpInt)
              (by simpa [cur] using hpHi)
              (by simpa using heLo) (by simpa using heHi1260) hinputCur
              (by simpa [cur, recOf, V] using
                (show ∃ alpha v : Real,
                  X / (2 : Real) ^ e.val = V cur + alpha ∧
                  Y / (2 : Real) ^ e.val = V cur + v ∧
                  0 ≤ alpha ∧ alpha < v ∧ (cur.truncated = true ↔ 0 < alpha) from
                  ⟨alpha, v, hXend, hYend, halpha, hlt, hsticky'⟩))
            rcases hstep with ⟨d', shift, exp', hbody, hcall, hshift, hexp',
              hpointStep, hpointSmall, hn', hd', hshapeNext, hlast, hendsNext,
              hstall, hheadExit⟩
            rcases hshapeNext with ⟨head', tail', hmapNext, hheadLo',
              hheadHi', hlenNext⟩
            have hpointLarge : 19 ≤ p.val ->
                d'.decimal_point.val = p.val - 18 ∨
                d'.decimal_point.val = p.val - 19 := by
              intro hl
              simpa [cur] using hpointStep (by simpa [cur] using hl)
            have hpointSmall' : p.val ≤ 18 ->
                d'.decimal_point.val = 0 ∨ d'.decimal_point.val = 1 := by
              intro hm
              simpa [cur] using hpointSmall (by simpa [cur] using hm)
            have hstallHead : p.val = 1 -> d'.decimal_point.val = 1 -> head' = 1 := by
              intro hp1 hp'1
              have hs := hstall (by simpa [cur] using hp1)
                (by simpa [cur] using hp'1)
              rcases hs with ⟨t, ht⟩
              have hh := congrArg (fun xs : List Nat => xs.headD 0) ht
              simpa [hmapNext] using hh
            have hheadExit0 : p.val = 1 -> head = 1 -> d'.decimal_point.val = 0 := by
              intro hp1 hh
              apply hheadExit (by simpa [cur] using hp1)
              have hmapCur :
                  (cur.digits.val.take cur.num_digits.val).map
                    (fun b => b.val) = head :: tail := by
                simpa [cur, recOf] using hmap'
              rw [hh] at hmapCur
              exact ⟨tail, hmapCur⟩
            let s' := (d'.num_digits, d'.decimal_point, d'.truncated,
              d'.digits, exp', (none : Option num.imp.dec2flt.common.BiasedFp))
            have hpNextLo : 0 ≤ d'.decimal_point.val := by
              by_cases hl : 19 ≤ p.val
              · rcases hpointLarge hl with hp' | hp' <;> omega
              · have hm : p.val ≤ 18 := by omega
                rcases hpointSmall' hm with hp' | hp' <;> omega
            have hpNextHi : d'.decimal_point.val < 310 := by
              have hpOldHi : p.val < 310 := by simpa [cur, recOf] using hpHi
              by_cases hl : 19 ≤ p.val
              · rcases hpointLarge hl with hp' | hp'
                · rw [hp']
                  have hsub : p.val - 18 ≤ p.val := by omega
                  exact lt_of_le_of_lt hsub hpOldHi
                · rw [hp']
                  have hsub : p.val - 19 ≤ p.val := by omega
                  exact lt_of_le_of_lt hsub hpOldHi
              · have hm : p.val ≤ 18 := by omega
                rcases hpointSmall' hm with hp' | hp' <;> rw [hp'] <;> omega
            have hshiftInt : (shift.val : Int) ≤ 60 := by exact_mod_cast hshift
            have heLo' : 0 ≤ exp'.val := by
              have heNonneg : 0 ≤ e.val := by simpa using heLo
              have hk : 0 ≤ (shift.val : Int) := by exact_mod_cast (Nat.zero_le shift.val)
              rw [hexp']
              exact add_nonneg heNonneg hk
            have heHi' : exp'.val ≤ 60 * ((j + 1 : Nat) : Int) := by
              rw [hexp']
              have heHiNorm : e.val ≤ 60 * (j : Int) := by simpa using heHi
              have hshiftBound : (shift.val : Int) ≤ 60 := hshiftInt
              push_cast
              nlinarith [heHiNorm, hshiftBound]
            have hendpoint' : ∃ alpha' v' : Real,
                X / (2 : Real) ^ exp'.val = V d' + alpha' ∧
                Y / (2 : Real) ^ exp'.val = V d' + v' ∧
                0 ≤ alpha' ∧ alpha' < v' ∧
                (d'.truncated = true ↔ 0 < alpha') := by
              rcases hendsNext with ⟨alpha', v', hXshift, hYshift,
                halpha', hlt', hsticky''⟩
              have hquotX : (X / (2 : Real) ^ e.val) /
                  (2 : Real) ^ shift.val = X / (2 : Real) ^ exp'.val := by
                rw [div_div]
                have hpow : (2 : Real) ^ exp'.val =
                    (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
                  calc
                    (2 : Real) ^ exp'.val = (2 : Real) ^ (e.val + (shift.val : Int)) := by rw [hexp']
                    _ = (2 : Real) ^ e.val * (2 : Real) ^ (shift.val : Int) :=
                      zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _
                    _ = (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
                      rw [zpow_natCast]
                rw [← hpow]
              have hquotY : (Y / (2 : Real) ^ e.val) /
                  (2 : Real) ^ shift.val = Y / (2 : Real) ^ exp'.val := by
                rw [div_div]
                have hpow : (2 : Real) ^ exp'.val =
                    (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
                  calc
                    (2 : Real) ^ exp'.val = (2 : Real) ^ (e.val + (shift.val : Int)) := by rw [hexp']
                    _ = (2 : Real) ^ e.val * (2 : Real) ^ (shift.val : Int) :=
                      zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _
                    _ = (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
                      rw [zpow_natCast]
                rw [← hpow]
              refine ⟨alpha', v', ?_, ?_, halpha', hlt', ?_⟩
              · calc
                  X / (2 : Real) ^ exp'.val =
                      (X / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val := hquotX.symm
                  _ = V d' + alpha' := hXshift
              · calc
                  Y / (2 : Real) ^ exp'.val =
                      (Y / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val := hquotY.symm
                  _ = V d' + v' := hYshift
              · exact hsticky''
            have hbudgetNext :
                (19 ≤ d'.decimal_point.val ->
                  18 * ((j + 1 : Nat) : Int) + d'.decimal_point.val ≤ 309) ∧
                (2 ≤ d'.decimal_point.val -> d'.decimal_point.val ≤ 18 -> j + 1 ≤ 17) ∧
                (d'.decimal_point.val = 1 -> head' = 1 -> j + 1 ≤ 19) ∧
                (d'.decimal_point.val = 1 -> head' ≠ 1 -> j + 1 ≤ 18) ∧
                (d'.decimal_point.val ≤ 0 -> j + 1 ≤ 20) := by
              constructor
              · intro hp'large
                by_cases hl : 19 ≤ p.val
                · have hb := hbLarge hl
                  rcases hpointLarge hl with hs | hs
                  · omega
                  · omega
                · have hm : p.val ≤ 18 := by omega
                  have hps := hpointSmall' hm
                  omega
              constructor
              · intro hp'lo hp'hi
                by_cases hl : 19 ≤ p.val
                · have hb := hbLarge hl
                  rcases hpointLarge hl with hs | hs
                  · omega
                  · omega
                · have hm : p.val ≤ 18 := by omega
                  have hps := hpointSmall' hm
                  omega
              constructor
              · intro hp'one hhead'one
                by_cases hl : 19 ≤ p.val
                · have hb := hbLarge hl
                  rcases hpointLarge hl with hs | hs
                  · omega
                  · omega
                · by_cases hm : 2 ≤ p.val
                  · have hm18 : p.val ≤ 18 := by omega
                    have hb := hbMedium hm hm18
                    have hps := hpointSmall' hm18
                    omega
                  · have hone : p.val = 1 := by omega
                    by_cases hheadone : head = 1
                    · have hb := hbHeadOne hone hheadone
                      have hexit := hheadExit0 hone hheadone
                      omega
                    · have hb := hbHeadOther hone hheadone
                      have hps := hpointSmall' (by omega)
                      omega
              constructor
              · intro hp'one hhead'not
                by_cases hl : 19 ≤ p.val
                · have hb := hbLarge hl
                  rcases hpointLarge hl with hs | hs
                  · omega
                  · omega
                · by_cases hm : 2 ≤ p.val
                  · have hm18 : p.val ≤ 18 := by omega
                    have hb := hbMedium hm hm18
                    have hps := hpointSmall' hm18
                    omega
                  · have hone : p.val = 1 := by omega
                    have hheadone : head ≠ 1 := by
                      intro h
                      subst head
                      have hexit := hheadExit0 hone rfl
                      omega
                    have hb := hbHeadOther hone hheadone
                    have hps := hpointSmall' (by omega)
                    have hstall' := hstallHead hone hp'one
                    omega
              · intro hp'nonpos
                by_cases hl : 19 ≤ p.val
                · have hb := hbLarge hl
                  rcases hpointLarge hl with hs | hs
                  · omega
                  · omega
                · by_cases hm : 2 ≤ p.val
                  · have hm18 : p.val ≤ 18 := by omega
                    have hb := hbMedium hm hm18
                    have hps := hpointSmall' hm18
                    omega
                  · have hone : p.val = 1 := by omega
                    by_cases hheadone : head = 1
                    · have hb := hbHeadOne hone hheadone
                      have hexit := hheadExit0 hone hheadone
                      omega
                    · have hb := hbHeadOther hone hheadone
                      have hps := hpointSmall' (by omega)
                      omega
            have hInvNext : Inv s' := by
              simp only [Inv, s', recOf]
              refine ⟨j + 1, ?_⟩
              constructor
              · trivial
              constructor
              · exact le_trans (by norm_num : (-324 : Int) ≤ 0) hpNextLo
              constructor
              · exact hpNextHi
              constructor
              · exact heLo'
              constructor
              · exact heHi'
              constructor
              · exact hn'
              constructor
              · exact hd'
              constructor
              · exact ⟨head', tail', hmapNext, hheadLo', hheadHi', hlenNext⟩
              constructor
              · exact Or.inr hlast
              constructor
              · simpa [s', recOf] using hendpoint'
              · simpa [hmapNext, List.headD] using hbudgetNext
            have hmeasureNext : measure s' < measure (n, p, tr, a, e, res) := by
              have hheadCur :
                  (((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
                have hh := congrArg (fun xs : List Nat => xs.headD 0) hmap'
                simpa using hh
              simp only [measure, recOf, s']
              rw [hheadCur, hmapNext]
              simp only [List.headD_cons]
              change rank d'.decimal_point.val (decide (head' = 1)) <
                rank p.val (decide (head = 1))
              have hrankStep :
                  (19 ≤ p.val ∧
                    (d'.decimal_point.val = p.val - 18 ∨
                     d'.decimal_point.val = p.val - 19)) ∨
                  (2 ≤ p.val ∧ p.val ≤ 18 ∧
                    (d'.decimal_point.val = 0 ∨ d'.decimal_point.val = 1)) ∨
                  (p.val = 1 ∧ decide (head = 1) = true ∧ d'.decimal_point.val = 0) ∨
                  (p.val = 1 ∧ decide (head = 1) = false ∧
                    (d'.decimal_point.val = 0 ∨
                     (d'.decimal_point.val = 1 ∧ decide (head' = 1) = true))) := by
                by_cases hl : 19 ≤ p.val
                · exact Or.inl ⟨hl, hpointLarge hl⟩
                · by_cases hm : 2 ≤ p.val
                  · exact Or.inr (Or.inl ⟨hm, by omega, hpointSmall' (by omega)⟩)
                  · have hone : p.val = 1 := by omega
                    by_cases hh : head = 1
                    · have hb : decide (head = 1) = true := by simp [hh]
                      exact Or.inr (Or.inr (Or.inl ⟨hone, hb,
                        hheadExit0 hone hh⟩))
                    · have hps := hpointSmall' (by omega)
                      have hb : decide (head = 1) = false := by simp [hh]
                      by_cases hp'one : d'.decimal_point.val = 1
                      · have hb' : decide (head' = 1) = true := by
                          simp [hstallHead hone hp'one]
                        exact Or.inr (Or.inr (Or.inr ⟨hone, hb,
                          Or.inr ⟨hp'one, hb'⟩⟩))
                      · exact Or.inr (Or.inr (Or.inr ⟨hone, hb,
                          Or.inl (by rcases hps with hzero | hone' <;> omega)⟩))
              exact rank_step p.val d'.decimal_point.val
                (decide (head = 1)) (decide (head' = 1))
                hpInt hpNextLo hrankStep
            have hbodyEq' :
                num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
                  F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
                  { m := 0#u64, p_biased := 0#i32 } n p tr a e res =
                  ok (cont (d'.num_digits, d'.decimal_point, d'.truncated,
                    d'.digits, exp', none)) := by
              simpa [cur, hresNone] using hbody
            rw [hbodyEq']
            simp only [WP.spec_ok]
            exact ⟨by simpa [s'] using hInvNext, hmeasureNext⟩
          · have hpval : p.val ≤ 0 := by
              have hp' : ¬ 0 < p.val := by simpa using hp
              exact not_lt.mp hp'
            have hdone :
                num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
                  F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
                  { m := 0#u64, p_biased := 0#i32 } n p tr a e res =
                  ok (done (n, p, tr, a, e, res)) := by
              simp [num.imp.dec2flt.slow.parse_long_mantissa_loop0.body, hp,
                hresNone]
            rw [hdone]
            simp only [WP.spec_ok]
            change Inv (n, p, tr, a, e, res) ∧ p.val ≤ 0
            exact ⟨hsInv, hpval⟩
        convert hbodySpec using 1
        funext r
        cases r <;> rfl
      · exact hstart
    obtain ⟨out, hout, hpost⟩ := Aeneas.Std.WP.spec_imp_exists hloop
    rcases hpost with ⟨hinv, hterminal⟩
    rcases out with ⟨n0, p0, b0, a0, e0, result0⟩
    rcases hinv with ⟨steps, hnone, hpLo, hpHi, heLo, heHi, hn0,
      hd0, hshape0, htrim0, hend0, hbudgets0⟩
    let d0 : num.imp.dec2flt.decimal_seq.DecimalSeq :=
      { num_digits := n0, decimal_point := p0, truncated := b0, digits := a0 }
    refine ⟨d0, e0, steps, ?_⟩
    constructor
    · have hresult : result0 = none := by simpa using hnone
      simpa [num.imp.dec2flt.slow.parse_long_mantissa_loop0, s0, d0, recOf, hresult] using hout
    constructor
    · omega
    constructor
    · simpa [d0] using heLo
    constructor
    · simpa [d0] using heHi
    constructor
    · simpa using hXlower
    constructor
    · simpa [d0] using hpLo
    constructor
    · simpa [d0] using hterminal
    constructor
    · simpa [d0] using hn0
    constructor
    · simpa [d0] using hd0
    constructor
    · simpa [d0] using hshape0
    constructor
    · simpa [d0] using htrim0
    · rcases hend0 with ⟨alpha0, v0, hX0, hY0, ha0, hav0, hstick0⟩
      exact ⟨alpha0, v0, by simpa [d0, V, recOf, List.map_take] using hX0,
        by simpa [d0, V, recOf, List.map_take] using hY0, ha0, hav0,
        by simpa [d0, recOf] using hstick0⟩
  )


end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P495_T1_RightLoopStep

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P495_T1_SlowLoop0Execution]
theorem P495_T1_SlowLoop0Execution (X Y : Real)
    (d : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (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)) :
    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 : Int)) ->
    (exists eta : Real, X = V d + eta /\ 0 <= eta /\
      eta < (10 : Real) ^ (d.decimal_point.val - (768 : Int)) /\
      (d.truncated = true <-> 0 < eta)) ->
    exists (d0 : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (exp0 : Std.I32) (steps : Nat),
      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) /\
      steps <= 21 /\ 0 <= exp0.val /\ exp0.val <= (60 : Int) * steps /\
      (10 : Real) ^ (-325 : Int) <= X /\
      -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) /\
      (steps = 0 \/ d0.digits.val[d0.num_digits.val - 1]? ≠ some 0#u8) /\
      (exists 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
-- BODY
  exact (set_option maxHeartbeats 1600000 in by
    dsimp only
    intro hY hX
    classical
    rcases hinput with ⟨hnum, hdigit, hshape⟩
    rcases hshape with ⟨h, tail, hmap, hhle, hhh, hlen⟩
    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))
    let eta := X - V d
    let u := (10 : Real) ^ (d.decimal_point.val - (768 : Int))
    have hXeq : X = V d + eta := by dsimp [eta]; ring
    have heta0 : 0 <= eta := by
      rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
      rw [heq] at hXeq
      have : eta = eta' := by linarith
      simpa [this] using hlo
    have hetaU : eta < u := by
      rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
      have : eta = eta' := by linarith [hXeq, heq]
      simpa [u] using (by simpa [this] using hhi)
    have hsticky : d.truncated = true ↔ 0 < eta := by
      rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
      have : eta = eta' := by linarith [hXeq, heq]
      simpa [this] using htr
    have huPos : 0 < u := by
      dsimp [u]
      exact zpow_pos (by norm_num) _
    have hYeq : Y = V d + u := by simpa [u, V] using hY
    have hpupper : d.decimal_point.val ≤ 309 := by omega
    have hXlower : (10 : Real) ^ (-325 : Int) ≤ X := by
      have hv := P472_T1_DecimalValueBounds
        ((d.digits.val.take d.num_digits.val).map (fun b => b.val)) h tail
        (by simpa [hmap]) hhle
        (by intro q hq; rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩; exact hdigit b hb)
        d.decimal_point.val
      dsimp at hv
      have hlen' :
          ((d.digits.val.take d.num_digits.val).map (fun b => b.val)).length =
            d.num_digits.val := by
        rw [hmap]
        simpa using hlen
      have hnumNat : d.num_digits.val ≤ 768 := by exact_mod_cast hnum
      have hlenMap :
          (List.take d.num_digits.val (List.map (fun b => b.val) d.digits.val)).length =
            d.num_digits.val := by
        simp [List.length_take, Nat.min_eq_left hnumNat]
      have hpow : (10 : Real) ^ (-325 : Int) ≤
          (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
        have hh : (10 : Real) ^ (-325 : Int) ≤
            (10 : Real) ^ (d.decimal_point.val - 1) := by
          apply zpow_right_mono₀ (by norm_num : (1 : Real) ≤ 10)
          omega
        have h10pos : 0 < (10 : Real) ^ (d.decimal_point.val - 1) :=
          zpow_pos (by norm_num) _
        calc
          (10 : Real) ^ (-325 : Int) ≤ (10 : Real) ^ (d.decimal_point.val - 1) := hh
          _ ≤ (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
            have hhleR : (1 : Real) ≤ (h : Real) := by exact_mod_cast hhle
            nlinarith [h10pos, hhleR]
      have hVlo : (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) ≤ V d := by
        have htmp := hv.1
        change (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) ≤
          (((((d.digits.val.take d.num_digits.val).map (fun b => b.val)).foldl
            (fun n z => 10 * n + z) 0 : Nat) : Real) *
            (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)))
        rw [List.map_take] at htmp
        rw [hlenMap] at htmp
        rw [List.map_take]
        exact htmp
      rw [hXeq]
      linarith
    -- The loop invariant records a completed-shift counter separately from
    -- the exported existential bound witness.
    let recOf := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
        Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
      ({ 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 rank := fun (p : Int) (headOne : Bool) =>
      if p <= 0 then 0 else 2 * p.toNat + (if headOne then 0 else 1)
    let measure := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
        Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
      rank (recOf s).decimal_point.val
        (decide (((((recOf s).digits.val.take (recOf s).num_digits.val).map
          (fun b => b.val)).headD 0) = 1))
    have rank_step (p p' : Int) (headOne headOne' : Bool)
        (hp : 1 ≤ p) (hp' : 0 ≤ p')
        (hstep : (19 ≤ p ∧ (p' = p - 18 ∨ p' = p - 19)) ∨
          (2 ≤ p ∧ p ≤ 18 ∧ (p' = 0 ∨ p' = 1)) ∨
          (p = 1 ∧ headOne = true ∧ p' = 0) ∨
          (p = 1 ∧ headOne = false ∧
            (p' = 0 ∨ (p' = 1 ∧ headOne' = true)))) :
        rank p' headOne' < rank p headOne := by
      rcases hstep with h | h | h | h
      all_goals cases headOne <;> cases headOne'
      all_goals simp_all [rank]
      all_goals split_ifs <;> omega
    let Inv := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
        Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
      ∃ j : Nat,
        s.2.2.2.2.2 = none ∧
        -324 ≤ (recOf s).decimal_point.val ∧ (recOf s).decimal_point.val < 310 ∧
        0 ≤ s.2.2.2.2.1.val ∧
        s.2.2.2.2.1.val ≤ 60 * (j : Int) ∧
        (recOf s).num_digits.val ≤ 768 ∧
        (∀ b, b ∈ (recOf s).digits.val.take (recOf s).num_digits.val -> b.val < 10) ∧
        (∃ h tail,
          ((recOf s).digits.val.take (recOf s).num_digits.val).map
            (fun b => b.val) = h :: tail ∧ 1 ≤ h ∧ h < 10 ∧
            (h :: tail).length = (recOf s).num_digits.val) ∧
        (j = 0 ∨ (recOf s).digits.val[(recOf s).num_digits.val - 1]? ≠ some 0#u8) ∧
        (∃ alpha v : Real,
          X / (2 : Real) ^ s.2.2.2.2.1.val = V (recOf s) + alpha ∧
          Y / (2 : Real) ^ s.2.2.2.2.1.val = V (recOf s) + v ∧
          0 ≤ alpha ∧ alpha < v ∧
          ((recOf s).truncated = true ↔ 0 < alpha)) ∧
        ((19 ≤ (recOf s).decimal_point.val -> 18 * (j : Int) +
            (recOf s).decimal_point.val ≤ 309) ∧
         (2 ≤ (recOf s).decimal_point.val ->
            (recOf s).decimal_point.val ≤ 18 -> j ≤ 17) ∧
         ((recOf s).decimal_point.val = 1 ->
            (((((recOf s).digits.val.take (recOf s).num_digits.val).map
              (fun b => b.val)).headD 0) = 1 -> j ≤ 19)) ∧
         ((recOf s).decimal_point.val = 1 ->
            (((((recOf s).digits.val.take (recOf s).num_digits.val).map
              (fun b => b.val)).headD 0) ≠ 1 -> j ≤ 18)) ∧
         ((recOf s).decimal_point.val ≤ 0 -> j ≤ 20))
    let Post := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
        Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
      Inv s ∧ (recOf s).decimal_point.val ≤ 0
    let s0 := (d.num_digits, d.decimal_point, d.truncated, d.digits,
      (0#i32 : Std.I32), (none : Option num.imp.dec2flt.common.BiasedFp))
    have hstart : Inv s0 := by
      simp only [Inv, recOf, s0]
      refine ⟨0, trivial, ?_⟩
      constructor
      · exact hpointLo
      constructor
      · exact hpointHi
      constructor
      · norm_num
      constructor
      · norm_num
      constructor
      · exact hnum
      constructor
      · exact hdigit
      constructor
      · exact ⟨h, tail, hmap, hhle, hhh, hlen⟩
      constructor
      · exact Or.inl rfl
      constructor
      · refine ⟨eta, u, ?_⟩
        constructor
        · simpa [V] using hXeq
        constructor
        · simpa [V] using hYeq
        constructor
        · exact heta0
        constructor
        · exact hetaU
        · exact hsticky
      constructor
      · intro hp
        omega
      constructor
      · intro hp hp18
        omega
      constructor
      · intro hp
        omega
      constructor
      · intro hp
        omega
      · intro hp
        omega
    have hloop : Aeneas.Std.WP.spec
        (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) Post := by
      unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0
      apply Aeneas.Std.loop.spec_decr_nat measure Inv Post
        (fun s => 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)
        s0
      · intro s hs
        rcases s with ⟨n, p, tr, a, e, res⟩
        simp only [Prod.fst, Prod.snd] at hs ⊢
        have hsInv := hs
        rcases hs with ⟨j, hres, hpLo, hpHi, heLo, heHi, hn, hd, hshape,
          htrim, hends, hbudgets⟩
        let cur : num.imp.dec2flt.decimal_seq.DecimalSeq :=
          { num_digits := n, decimal_point := p, truncated := tr, digits := a }
        have hresNone : res = none := by simpa using hres
        have hshape' := hshape
        rcases hshape with ⟨head, tail, hmap', hheadLo, hheadHi, hlen'⟩
        have hbLarge : 19 ≤ p.val -> 18 * (j : Int) + p.val ≤ 309 := by
          intro hl
          have h := hbudgets.1 (by simpa [cur, recOf] using hl)
          simpa [cur, recOf] using h
        have hbMedium : 2 ≤ p.val -> p.val ≤ 18 -> j ≤ 17 := by
          intro hm hm18
          exact hbudgets.2.1 (by simpa [cur, recOf] using hm)
            (by simpa [cur, recOf] using hm18)
        have hbHeadOne : p.val = 1 -> head = 1 -> j ≤ 19 := by
          intro hp1 hh
          have hh' :
              (((a.val.take n.val).map (fun b => b.val)).headD 0) = 1 := by
            have hh'' := congrArg (fun xs : List Nat => xs.headD 0) hmap'
            have hhval :
                (((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
              simpa using hh''
            rw [hhval]
            exact hh
          exact hbudgets.2.2.1 (by simpa [cur, recOf] using hp1)
            (by simpa [cur, recOf, List.headD, hmap'] using hh')
        have hbHeadOther : p.val = 1 -> head ≠ 1 -> j ≤ 18 := by
          intro hp1 hh
          have hh' :
              (((a.val.take n.val).map (fun b => b.val)).headD 0) ≠ 1 := by
            have hh'' := congrArg (fun xs : List Nat => xs.headD 0) hmap'
            have hhval :
                (((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
              simpa using hh''
            rw [hhval]
            exact hh
          exact hbudgets.2.2.2.1 (by simpa [cur, recOf] using hp1)
            (by simpa [cur, recOf, List.headD, hmap'] using hh')
        have hbodySpec :
            num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
              F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
              { m := 0#u64, p_biased := 0#i32 }
              n p tr a e res
              ⦃ r => match r with
                | done y => Post y
                | cont y => Inv y ∧ measure y < measure (n, p, tr, a, e, res) ⦄ := by
          by_cases hp : p > 0#i32
          · have hpPos : 0 < p.val := by simpa using hp
            have hpInt : 1 ≤ p.val := by omega
            have hj : j ≤ 20 := by
              by_cases hl : 19 ≤ p.val
              · have hb := hbudgets.1 (by simpa [cur, recOf] using hl)
                have hjInt : (j : Int) ≤ 20 := by
                  have : 18 * (j : Int) + p.val ≤ 309 := hb
                  omega
                exact_mod_cast hjInt
              · by_cases hm : 2 ≤ p.val
                · have hb := hbudgets.2.1 (by simpa [cur, recOf] using hm)
                    (by have hm18 : p.val ≤ 18 := by omega
                        simpa [cur, recOf] using hm18)
                  omega
                · have hone : p.val = 1 := by omega
                  by_cases hheadone : head = 1
                  · have hheadVal :
                      (List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = head := by
                      rw [← List.map_take, hmap']
                      rfl
                    have hheadOne :
                        (List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = 1 := by
                      rw [hheadVal]
                      exact hheadone
                    have hb := hbudgets.2.2.1 (by simpa [cur, recOf] using hone)
                      (by simpa [cur, recOf, List.headD] using hheadOne)
                    omega
                  · have hheadVal :
                      (List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = head := by
                      rw [← List.map_take, hmap']
                      rfl
                    have hheadNotOne :
                        (List.take n.val (List.map (fun b => b.val) a.val)).headD 0 ≠ 1 := by
                      rw [hheadVal]
                      exact hheadone
                    have hb := hbudgets.2.2.2.1 (by simpa [cur, recOf] using hone)
                      (by simpa [cur, recOf, List.headD] using hheadNotOne)
                    omega
            have heHi1260 : e.val ≤ 1260 := by
              have hjInt : (j : Int) ≤ 20 := by exact_mod_cast hj
              have he1200 : e.val ≤ 60 * 20 := by
                calc
                  e.val ≤ 60 * (j : Int) := heHi
                  _ ≤ 60 * 20 := by nlinarith
              omega
            rcases hends with ⟨alpha, v, hXend, hYend, halpha, hlt, hsticky'⟩
            have hinputCur : n.val ≤ 768 ∧
                (∀ b, b ∈ a.val.take n.val -> b.val < 10) ∧
                (∃ hh tt, (a.val.take n.val).map (fun b => b.val) = hh :: tt ∧
                  1 ≤ hh ∧ hh < 10 ∧ (hh :: tt).length = n.val) := by
              simpa [cur, recOf] using And.intro hn (And.intro hd hshape')
            have hstep := P495_T1_RightLoopStep
              (X / (2 : Real) ^ e.val) (Y / (2 : Real) ^ e.val) cur e
              (by simpa [cur, recOf] using hpInt)
              (by simpa [cur] using hpHi)
              (by simpa using heLo) (by simpa using heHi1260) hinputCur
              (by simpa [cur, recOf, V] using
                (show ∃ alpha v : Real,
                  X / (2 : Real) ^ e.val = V cur + alpha ∧
                  Y / (2 : Real) ^ e.val = V cur + v ∧
                  0 ≤ alpha ∧ alpha < v ∧ (cur.truncated = true ↔ 0 < alpha) from
                  ⟨alpha, v, hXend, hYend, halpha, hlt, hsticky'⟩))
            rcases hstep with ⟨d', shift, exp', hbody, hcall, hshift, hexp',
              hpointStep, hpointSmall, hn', hd', hshapeNext, hlast, hendsNext,
              hstall, hheadExit⟩
            rcases hshapeNext with ⟨head', tail', hmapNext, hheadLo',
              hheadHi', hlenNext⟩
            have hpointLarge : 19 ≤ p.val ->
                d'.decimal_point.val = p.val - 18 ∨
                d'.decimal_point.val = p.val - 19 := by
              intro hl
              simpa [cur] using hpointStep (by simpa [cur] using hl)
            have hpointSmall' : p.val ≤ 18 ->
                d'.decimal_point.val = 0 ∨ d'.decimal_point.val = 1 := by
              intro hm
              simpa [cur] using hpointSmall (by simpa [cur] using hm)
            have hstallHead : p.val = 1 -> d'.decimal_point.val = 1 -> head' = 1 := by
              intro hp1 hp'1
              have hs := hstall (by simpa [cur] using hp1)
                (by simpa [cur] using hp'1)
              rcases hs with ⟨t, ht⟩
              have hh := congrArg (fun xs : List Nat => xs.headD 0) ht
              simpa [hmapNext] using hh
            have hheadExit0 : p.val = 1 -> head = 1 -> d'.decimal_point.val = 0 := by
              intro hp1 hh
              apply hheadExit (by simpa [cur] using hp1)
              have hmapCur :
                  (cur.digits.val.take cur.num_digits.val).map
                    (fun b => b.val) = head :: tail := by
                simpa [cur, recOf] using hmap'
              rw [hh] at hmapCur
              exact ⟨tail, hmapCur⟩
            let s' := (d'.num_digits, d'.decimal_point, d'.truncated,
              d'.digits, exp', (none : Option num.imp.dec2flt.common.BiasedFp))
            have hpNextLo : 0 ≤ d'.decimal_point.val := by
              by_cases hl : 19 ≤ p.val
              · rcases hpointLarge hl with hp' | hp' <;> omega
              · have hm : p.val ≤ 18 := by omega
                rcases hpointSmall' hm with hp' | hp' <;> omega
            have hpNextHi : d'.decimal_point.val < 310 := by
              have hpOldHi : p.val < 310 := by simpa [cur, recOf] using hpHi
              by_cases hl : 19 ≤ p.val
              · rcases hpointLarge hl with hp' | hp'
                · rw [hp']
                  have hsub : p.val - 18 ≤ p.val := by omega
                  exact lt_of_le_of_lt hsub hpOldHi
                · rw [hp']
                  have hsub : p.val - 19 ≤ p.val := by omega
                  exact lt_of_le_of_lt hsub hpOldHi
              · have hm : p.val ≤ 18 := by omega
                rcases hpointSmall' hm with hp' | hp' <;> rw [hp'] <;> omega
            have hshiftInt : (shift.val : Int) ≤ 60 := by exact_mod_cast hshift
            have heLo' : 0 ≤ exp'.val := by
              have heNonneg : 0 ≤ e.val := by simpa using heLo
              have hk : 0 ≤ (shift.val : Int) := by exact_mod_cast (Nat.zero_le shift.val)
              rw [hexp']
              exact add_nonneg heNonneg hk
            have heHi' : exp'.val ≤ 60 * ((j + 1 : Nat) : Int) := by
              rw [hexp']
              have heHiNorm : e.val ≤ 60 * (j : Int) := by simpa using heHi
              have hshiftBound : (shift.val : Int) ≤ 60 := hshiftInt
              push_cast
              nlinarith [heHiNorm, hshiftBound]
            have hendpoint' : ∃ alpha' v' : Real,
                X / (2 : Real) ^ exp'.val = V d' + alpha' ∧
                Y / (2 : Real) ^ exp'.val = V d' + v' ∧
                0 ≤ alpha' ∧ alpha' < v' ∧
                (d'.truncated = true ↔ 0 < alpha') := by
              rcases hendsNext with ⟨alpha', v', hXshift, hYshift,
                halpha', hlt', hsticky''⟩
              have hquotX : (X / (2 : Real) ^ e.val) /
                  (2 : Real) ^ shift.val = X / (2 : Real) ^ exp'.val := by
                rw [div_div]
                have hpow : (2 : Real) ^ exp'.val =
                    (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
                  calc
                    (2 : Real) ^ exp'.val = (2 : Real) ^ (e.val + (shift.val : Int)) := by rw [hexp']
                    _ = (2 : Real) ^ e.val * (2 : Real) ^ (shift.val : Int) :=
                      zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _
                    _ = (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
                      rw [zpow_natCast]
                rw [← hpow]
              have hquotY : (Y / (2 : Real) ^ e.val) /
                  (2 : Real) ^ shift.val = Y / (2 : Real) ^ exp'.val := by
                rw [div_div]
                have hpow : (2 : Real) ^ exp'.val =
                    (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
                  calc
                    (2 : Real) ^ exp'.val = (2 : Real) ^ (e.val + (shift.val : Int)) := by rw [hexp']
                    _ = (2 : Real) ^ e.val * (2 : Real) ^ (shift.val : Int) :=
                      zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _
                    _ = (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
                      rw [zpow_natCast]
                rw [← hpow]
              refine ⟨alpha', v', ?_, ?_, halpha', hlt', ?_⟩
              · calc
                  X / (2 : Real) ^ exp'.val =
                      (X / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val := hquotX.symm
                  _ = V d' + alpha' := hXshift
              · calc
                  Y / (2 : Real) ^ exp'.val =
                      (Y / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val := hquotY.symm
                  _ = V d' + v' := hYshift
              · exact hsticky''
            have hbudgetNext :
                (19 ≤ d'.decimal_point.val ->
                  18 * ((j + 1 : Nat) : Int) + d'.decimal_point.val ≤ 309) ∧
                (2 ≤ d'.decimal_point.val -> d'.decimal_point.val ≤ 18 -> j + 1 ≤ 17) ∧
                (d'.decimal_point.val = 1 -> head' = 1 -> j + 1 ≤ 19) ∧
                (d'.decimal_point.val = 1 -> head' ≠ 1 -> j + 1 ≤ 18) ∧
                (d'.decimal_point.val ≤ 0 -> j + 1 ≤ 20) := by
              constructor
              · intro hp'large
                by_cases hl : 19 ≤ p.val
                · have hb := hbLarge hl
                  rcases hpointLarge hl with hs | hs
                  · omega
                  · omega
                · have hm : p.val ≤ 18 := by omega
                  have hps := hpointSmall' hm
                  omega
              constructor
              · intro hp'lo hp'hi
                by_cases hl : 19 ≤ p.val
                · have hb := hbLarge hl
                  rcases hpointLarge hl with hs | hs
                  · omega
                  · omega
                · have hm : p.val ≤ 18 := by omega
                  have hps := hpointSmall' hm
                  omega
              constructor
              · intro hp'one hhead'one
                by_cases hl : 19 ≤ p.val
                · have hb := hbLarge hl
                  rcases hpointLarge hl with hs | hs
                  · omega
                  · omega
                · by_cases hm : 2 ≤ p.val
                  · have hm18 : p.val ≤ 18 := by omega
                    have hb := hbMedium hm hm18
                    have hps := hpointSmall' hm18
                    omega
                  · have hone : p.val = 1 := by omega
                    by_cases hheadone : head = 1
                    · have hb := hbHeadOne hone hheadone
                      have hexit := hheadExit0 hone hheadone
                      omega
                    · have hb := hbHeadOther hone hheadone
                      have hps := hpointSmall' (by omega)
                      omega
              constructor
              · intro hp'one hhead'not
                by_cases hl : 19 ≤ p.val
                · have hb := hbLarge hl
                  rcases hpointLarge hl with hs | hs
                  · omega
                  · omega
                · by_cases hm : 2 ≤ p.val
                  · have hm18 : p.val ≤ 18 := by omega
                    have hb := hbMedium hm hm18
                    have hps := hpointSmall' hm18
                    omega
                  · have hone : p.val = 1 := by omega
                    have hheadone : head ≠ 1 := by
                      intro h
                      subst head
                      have hexit := hheadExit0 hone rfl
                      omega
                    have hb := hbHeadOther hone hheadone
                    have hps := hpointSmall' (by omega)
                    have hstall' := hstallHead hone hp'one
                    omega
              · intro hp'nonpos
                by_cases hl : 19 ≤ p.val
                · have hb := hbLarge hl
                  rcases hpointLarge hl with hs | hs
                  · omega
                  · omega
                · by_cases hm : 2 ≤ p.val
                  · have hm18 : p.val ≤ 18 := by omega
                    have hb := hbMedium hm hm18
                    have hps := hpointSmall' hm18
                    omega
                  · have hone : p.val = 1 := by omega
                    by_cases hheadone : head = 1
                    · have hb := hbHeadOne hone hheadone
                      have hexit := hheadExit0 hone hheadone
                      omega
                    · have hb := hbHeadOther hone hheadone
                      have hps := hpointSmall' (by omega)
                      omega
            have hInvNext : Inv s' := by
              simp only [Inv, s', recOf]
              refine ⟨j + 1, ?_⟩
              constructor
              · trivial
              constructor
              · exact le_trans (by norm_num : (-324 : Int) ≤ 0) hpNextLo
              constructor
              · exact hpNextHi
              constructor
              · exact heLo'
              constructor
              · exact heHi'
              constructor
              · exact hn'
              constructor
              · exact hd'
              constructor
              · exact ⟨head', tail', hmapNext, hheadLo', hheadHi', hlenNext⟩
              constructor
              · exact Or.inr hlast
              constructor
              · simpa [s', recOf] using hendpoint'
              · simpa [hmapNext, List.headD] using hbudgetNext
            have hmeasureNext : measure s' < measure (n, p, tr, a, e, res) := by
              have hheadCur :
                  (((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
                have hh := congrArg (fun xs : List Nat => xs.headD 0) hmap'
                simpa using hh
              simp only [measure, recOf, s']
              rw [hheadCur, hmapNext]
              simp only [List.headD_cons]
              change rank d'.decimal_point.val (decide (head' = 1)) <
                rank p.val (decide (head = 1))
              have hrankStep :
                  (19 ≤ p.val ∧
                    (d'.decimal_point.val = p.val - 18 ∨
                     d'.decimal_point.val = p.val - 19)) ∨
                  (2 ≤ p.val ∧ p.val ≤ 18 ∧
                    (d'.decimal_point.val = 0 ∨ d'.decimal_point.val = 1)) ∨
                  (p.val = 1 ∧ decide (head = 1) = true ∧ d'.decimal_point.val = 0) ∨
                  (p.val = 1 ∧ decide (head = 1) = false ∧
                    (d'.decimal_point.val = 0 ∨
                     (d'.decimal_point.val = 1 ∧ decide (head' = 1) = true))) := by
                by_cases hl : 19 ≤ p.val
                · exact Or.inl ⟨hl, hpointLarge hl⟩
                · by_cases hm : 2 ≤ p.val
                  · exact Or.inr (Or.inl ⟨hm, by omega, hpointSmall' (by omega)⟩)
                  · have hone : p.val = 1 := by omega
                    by_cases hh : head = 1
                    · have hb : decide (head = 1) = true := by simp [hh]
                      exact Or.inr (Or.inr (Or.inl ⟨hone, hb,
                        hheadExit0 hone hh⟩))
                    · have hps := hpointSmall' (by omega)
                      have hb : decide (head = 1) = false := by simp [hh]
                      by_cases hp'one : d'.decimal_point.val = 1
                      · have hb' : decide (head' = 1) = true := by
                          simp [hstallHead hone hp'one]
                        exact Or.inr (Or.inr (Or.inr ⟨hone, hb,
                          Or.inr ⟨hp'one, hb'⟩⟩))
                      · exact Or.inr (Or.inr (Or.inr ⟨hone, hb,
                          Or.inl (by rcases hps with hzero | hone' <;> omega)⟩))
              exact rank_step p.val d'.decimal_point.val
                (decide (head = 1)) (decide (head' = 1))
                hpInt hpNextLo hrankStep
            have hbodyEq' :
                num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
                  F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
                  { m := 0#u64, p_biased := 0#i32 } n p tr a e res =
                  ok (cont (d'.num_digits, d'.decimal_point, d'.truncated,
                    d'.digits, exp', none)) := by
              simpa [cur, hresNone] using hbody
            rw [hbodyEq']
            simp only [WP.spec_ok]
            exact ⟨by simpa [s'] using hInvNext, hmeasureNext⟩
          · have hpval : p.val ≤ 0 := by
              have hp' : ¬ 0 < p.val := by simpa using hp
              exact not_lt.mp hp'
            have hdone :
                num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
                  F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
                  { m := 0#u64, p_biased := 0#i32 } n p tr a e res =
                  ok (done (n, p, tr, a, e, res)) := by
              simp [num.imp.dec2flt.slow.parse_long_mantissa_loop0.body, hp,
                hresNone]
            rw [hdone]
            simp only [WP.spec_ok]
            change Inv (n, p, tr, a, e, res) ∧ p.val ≤ 0
            exact ⟨hsInv, hpval⟩
        convert hbodySpec using 1
        funext r
        cases r <;> rfl
      · exact hstart
    obtain ⟨out, hout, hpost⟩ := Aeneas.Std.WP.spec_imp_exists hloop
    rcases hpost with ⟨hinv, hterminal⟩
    rcases out with ⟨n0, p0, b0, a0, e0, result0⟩
    rcases hinv with ⟨steps, hnone, hpLo, hpHi, heLo, heHi, hn0,
      hd0, hshape0, htrim0, hend0, hbudgets0⟩
    let d0 : num.imp.dec2flt.decimal_seq.DecimalSeq :=
      { num_digits := n0, decimal_point := p0, truncated := b0, digits := a0 }
    refine ⟨d0, e0, steps, ?_⟩
    constructor
    · have hresult : result0 = none := by simpa using hnone
      simpa [num.imp.dec2flt.slow.parse_long_mantissa_loop0, s0, d0, recOf, hresult] using hout
    constructor
    · omega
    constructor
    · simpa [d0] using heLo
    constructor
    · simpa [d0] using heHi
    constructor
    · simpa using hXlower
    constructor
    · simpa [d0] using hpLo
    constructor
    · simpa [d0] using hterminal
    constructor
    · simpa [d0] using hn0
    constructor
    · simpa [d0] using hd0
    constructor
    · simpa [d0] using hshape0
    constructor
    · simpa [d0] using htrim0
    · rcases hend0 with ⟨alpha0, v0, hX0, hY0, ha0, hav0, hstick0⟩
      exact ⟨alpha0, v0, by simpa [d0, V, recOf, List.map_take] using hX0,
        by simpa [d0, V, recOf, List.map_take] using hY0, ha0, hav0,
        by simpa [d0, recOf] using hstick0⟩
  )


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 126 entries
Technical checking records
Local closure summary
{
  "node": "P495_T1_SlowLoop0Execution",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "fd3decd6a3a94372a7ca7319a9e643ebc9ad4c716253c02e8daafa84befafd28",
  "active_statement_hash": "7f259ed22561e71caa908498f059b54eb26a69b24237971891e44a81d88ff1e0",
  "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-181",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "P472_T1_DecimalValueBounds": "4b5c924b5d52bc9d",
    "P495_T1_RightLoopStep": "b873eecaa227a3e1",
    "num_imp_dec2flt_slow_parse_long_mantissa": "d2b4145772dccc04"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "59bf1ff9fe88fa8d",
    "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"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:dfb26d638e4893e772d88fc7d2d7eb333939d66e642be14f11096e9d5e1ffeef",
  "current_fingerprint": "sound-v2:dfb26d638e4893e772d88fc7d2d7eb333939d66e642be14f11096e9d5e1ffeef",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}