ParserSlowFinalEncoding

Lean checked

Statement

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

Lemma · Final slow-path rounding and binary64 encoding

For every x:\mathtt{DecimalLexeme}, B\in\mathbb R, \mathrm{tr}:\mathtt{num.imp.dec2flt.Dec2FltAssemblyTrace}(\mathtt{F64}), five records d,d_0,d_1,d_2,d_3:\mathtt{DecimalSeq}, and four checked signed 32-bit scalars E_0,E_1,E_s,E_2:\mathtt{I32}, the following implication holds. Here \mathtt{DecimalSeq} denotes \mathtt{num.imp.dec2flt.decimal\_seq.DecimalSeq}, and e_0,e_1,e_s,e_2\in\mathbb Z are the respective scalar values of the four E's.
Use the following local notation. For a list L of natural numbers, set
N(L)=\operatorname{foldl}((a,b)\mapsto10a+b,0,L).
Let F_x be x.\mathtt{fractionDigits} when present and the empty list otherwise. If x.\mathtt{exponent} is absent, put a_x=0. If it is present as (u,\sigma,L), fold L from zero, replacing the accumulator a by 10a+b on the next entry b when a<65536, and leaving a unchanged otherwise. Give the resulting natural accumulator a minus sign exactly when \sigma=\operatorname{some}(\mathtt{true}), to obtain the integer a_x; the Boolean u does not affect this value. Put
A=\operatorname{accumulatedMagnitude}(x) =N(x.\mathtt{integerDigits}\mathbin{++}F_x) 10^{a_x-|F_x|}.
For any decimal record s, define
\begin{aligned} n(s)&=s.\mathtt{num\_digits}.\mathtt{val}\in\mathbb N,& q(s)&=s.\mathtt{decimal\_point}.\mathtt{val}\in\mathbb Z,\\ \tau(s)&=s.\mathtt{truncated},& D(s)&=\operatorname{take}_{n(s)}(s.\mathtt{digits}.\mathtt{val}),\\ L(s)&=\operatorname{map}(\mathtt{val},D(s)),& V(s)&=N(L(s))10^{q(s)-n(s)}\in\mathbb R. \end{aligned}
The map retains list order and takes each unsigned byte's natural value. Write n_i=n(d_i), q_i=q(d_i), \tau_i=\tau(d_i), D_i=D(d_i), L_i=L(d_i), and V_i=V(d_i). The notation \operatorname{last}(L) means the last entry of a nonempty list. Decimal values and scaled magnitude inequalities use real powers with integer exponents and embed natural coefficients in \mathbb R. Word arithmetic and scalar or digit-count bounds use natural or integer arithmetic as indicated.
For call notation let \mathcal P stand for the name prefix num.imp.dec2flt, and fix the binary64 trait instance F64.Insts.Dec2flt_modelNumImpTraitsFloatU64. The symbols \mathsf{parse}, \mathsf{slow}, and \mathsf{Loop}_i denote respectively the model operations \mathcal P.\mathtt{decimal\_seq.parse\_decimal\_seq}, \mathcal P.\mathtt{slow.parse\_long\_mantissa}, and \mathcal P.\mathtt{slow.parse\_long\_mantissa\_loop}i for i=0,1,2. Each \mathsf{slow} or \mathsf{Loop}_i call includes the fixed trait instance as its first argument. Write \mathsf{left} and \mathsf{right} for \mathcal P.\mathtt{decimal\_seq.DecimalSeq.left\_shift} and \mathcal P.\mathtt{decimal\_seq.DecimalSeq.right\_shift}. In calls, Q(s) abbreviates the four consecutive arguments
s.\mathtt{num\_digits},\quad s.\mathtt{decimal\_point},\quad s.\mathtt{truncated},\quad s.\mathtt{digits};
in a returned tuple, (Q(s),E,\mathtt{none}) abbreviates the six-tuple of those four fields followed by E and \mathtt{none}. The notation k_T denotes the scalar constant k of type T, and \operatorname{ok}(v) denotes successful return of exactly v. Set the two biased-pair constants
Z=\{\mathtt{m}=0_{\mathtt{U64}}, \mathtt{p\_biased}=0_{\mathtt{I32}}\},\qquad J=\{\mathtt{m}=0_{\mathtt{U64}}, \mathtt{p\_biased}=2047_{\mathtt{I32}}\}.
Define the natural unit U=2^{52}, the infinity word T=2047U, and the real threshold H=2^{1024}-2^{970}. With m=\mathrm{tr}.\mathtt{selected\_pair}.\mathtt{m}.\mathtt{val}\in\mathbb N and b=\mathrm{tr}.\mathtt{selected\_pair}.\mathtt{p\_biased}.\mathtt{val}\in\mathbb Z, define the natural raw word
r=m\mathbin{\operatorname{OR}} \bigl((\operatorname{emod}_{2^{64}}(b)\,U)\bmod2^{64}\bigr).
Here \operatorname{OR} is bitwise OR on natural numbers, and \operatorname{emod}_{2^{64}}(b) is the unique integer in [0,2^{64}) congruent to b modulo 2^{64}, viewed as a natural number. Thus the exponent-field shift is reduced modulo 2^{64}.
Assume the exact successful calls and numerical premises
\begin{gathered} \mathsf{parse}(\mathrm{tr}.\mathtt{body})=\operatorname{ok}(d),\qquad n(d)\ne0,\qquad -324\leq q(d)<310,\\ \mathsf{slow}(\mathrm{tr}.\mathtt{body}) =\operatorname{ok}(\mathrm{tr}.\mathtt{selected\_pair}),\qquad \mathrm{tr}.\mathtt{assembly\_result}.\mathtt{val}=r,\\ \mathsf{Loop}_0(Z,Q(d),0_{\mathtt{I32}},\mathtt{none}) =\operatorname{ok}((Q(d_0),E_0,\mathtt{none})),\\ \mathsf{Loop}_1(J,Q(d_0),E_0,\mathtt{none}) =\operatorname{ok}((Q(d_1),E_1,\mathtt{none})),\\ \mathsf{Loop}_2(d_1,E_s)=\operatorname{ok}((d_2,E_2)),\\ \operatorname{sub}_{\mathtt{I32}}(E_1,1_{\mathtt{I32}}) =\operatorname{ok}(E_s),\qquad e_s=e_1-1,\\ q_1=0,\qquad n_1\ne0,\qquad 5\leq d_1.\mathtt{digits}.\mathtt{val}[0].\mathtt{val},\\ -1079\leq e_1,\qquad B/2^{e_1}\leq1,\qquad e_2=\max(e_s,-1022),\qquad \max(e_2-e_s,0)\leq58. \end{gathered}
Here \operatorname{sub}_{\mathtt{I32}} is checked signed 32-bit subtraction, so its equation includes successful evaluation without overflow; the last bound uses the nonnegative part of the integer difference.
Assume the following d_2 certificate:
\begin{gathered} n_2\leq768,\qquad \forall z\in D_2,\quad z.\mathtt{val}<10,\\ \exists z\in\mathbb N\ \exists L\in\operatorname{List}(\mathbb N),\quad L_2=z::L\ \land\ 1\leq z<10\ \land\ |L_2|=n_2,\\ \exists\eta_2,u_2\in\mathbb R:\quad \begin{aligned} &A/2^{e_2+1}=V_2+\eta_2\ \land\ B/2^{e_2+1}=V_2+u_2\\ &{}\land\ 0\leq\eta_2<u_2 \ \land\ (\tau_2=\mathtt{true}\ \Longleftrightarrow\ 0<\eta_2). \end{aligned} \end{gathered}
This requires a positive leading digit, but imposes no nonzero-last-digit condition on d_2.
Assume \mathsf{left}(d_2,53_{\mathtt{Usize}})=\operatorname{ok}(d_3) and all of the following d_3 certificate:
\begin{gathered} n_3\leq768,\qquad \forall z\in D_3,\quad z.\mathtt{val}<10,\\ \exists z\in\mathbb N\ \exists L\in\operatorname{List}(\mathbb N),\quad L_3=z::L\ \land\ 1\leq z<10\ \land\ |L_3|=n_3 \ \land\ \operatorname{last}(L_3)\ne0,\\ \exists\eta_3,u_3\in\mathbb R:\quad \begin{aligned} &A/2^{e_2-52}=V_3+\eta_3\ \land\ B/2^{e_2-52}=V_3+u_3\\ &{}\land\ 0\leq\eta_3<u_3 \ \land\ (\tau_3=\mathtt{true}\ \Longleftrightarrow\ 0<\eta_3), \end{aligned}\\ q_3<19,\qquad 0\leq A/2^{e_2-52},\qquad A/2^{e_2-52}<2^{64}-\tfrac12,\\ \forall n\in\mathbb N,\quad n+\tfrac12\leq V_3\ \lor\ B/2^{e_2-52}\leq n+\tfrac12. \end{gathered}
Finally assume that for every record d_4:\mathtt{DecimalSeq}, if
\mathsf{right}(d_3,1_{\mathtt{Usize}})=\operatorname{ok}(d_4) \quad\hbox{and}\quad n(d_4)\ne0,
then, using n_4,q_4,\tau_4,D_4,L_4,V_4 as defined above for d_4, all of the following hold:
\begin{gathered} n_4\leq768,\qquad \forall z\in D_4,\quad z.\mathtt{val}<10,\\ \exists z\in\mathbb N\ \exists L\in\operatorname{List}(\mathbb N),\quad L_4=z::L\ \land\ 1\leq z<10\ \land\ |L_4|=n_4 \ \land\ \operatorname{last}(L_4)\ne0,\\ \exists\eta_4,u_4\in\mathbb R:\quad \begin{aligned} &A/2^{e_2-51}=V_4+\eta_4\ \land\ B/2^{e_2-51}=V_4+u_4\\ &{}\land\ 0\leq\eta_4<u_4 \ \land\ (\tau_4=\mathtt{true}\ \Longleftrightarrow\ 0<\eta_4), \end{aligned}\\ q_4<19,\qquad 0\leq A/2^{e_2-51},\qquad A/2^{e_2-51}<2^{64}-\tfrac12,\\ \forall n\in\mathbb N,\quad n+\tfrac12\leq V_4\ \lor\ B/2^{e_2-51}\leq n+\tfrac12. \end{gathered}
This is conditional on both successful shifting and a nonempty result; it does not assume that such a d_4 exists.
Then at least one of the following three alternatives holds.
  1. Infinity: r=T and H\leq A.
  2. Low grid: there exists j\in\mathbb N such that
    \begin{gathered} j\leq2^{53},\qquad r=j,\qquad A\leq2^{53}2^{-1074},\\ A\leq j2^{-1074}+2^{-1075},\qquad j2^{-1074}\leq A+2^{-1075},\\ \bigl(A=(j+\tfrac12)2^{-1074}\ \lor A=(j-\tfrac12)2^{-1074}\bigr) \ \Longrightarrow\ j\bmod2=0. \end{gathered}
  3. Normal grid: there exist p,j\in\mathbb N such that, with the real spacing \Delta=2^{p-1075} (where p-1075 is an integer difference),
    \begin{gathered} 2\leq p\leq2046,\qquad U\leq j\leq2^{53},\qquad p<2046\ \lor\ j<2^{53},\\ r=pU+(j-U),\qquad U\Delta\leq A\leq2^{53}\Delta,\qquad A<H,\\ A\leq j\Delta+\Delta/2,\qquad j\Delta\leq A+\Delta/2,\\ \bigl(A=(j+\tfrac12)\Delta\ \lor\ A=(j-\tfrac12)\Delta\bigr) \ \Longrightarrow\ j\bmod2=0. \end{gathered}
    The difference j-U in the raw word is natural subtraction; the stated lower bound on j makes it the ordinary nonnegative difference.

Lean statement

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

import Tablet.DecimalSeqRoundArbitraryEndpoint
import Tablet.ParserSlowFirstRoundSeparation
import Tablet.ParserSlowCarryRoundSeparation
import Tablet.ParserExponentConstants
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.ModelU64Shl
import Tablet.P804_T1_DecimalValueBounds
import Tablet.DecimalRightShiftLoop0Execution
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 100000
set_option maxHeartbeats 800000

namespace dec2flt_model

-- [TABLET NODE: ParserSlowFinalEncoding]
theorem ParserSlowFinalEncoding :
    forall (x : DecimalLexeme) (B : Real)
      (tr : num.imp.dec2flt.Dec2FltAssemblyTrace F64)
      (d d0 d1 d2 d3 : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (exp0 exp1 expStart exp2 : Std.I32),
      num.imp.dec2flt.decimal_seq.parse_decimal_seq tr.body = ok d ->
      d.num_digits.val != 0 ->
      -324 <= d.decimal_point.val -> d.decimal_point.val < 310 ->
      num.imp.dec2flt.slow.parse_long_mantissa
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 tr.body =
          ok tr.selected_pair ->
      DecimalGoalVocabularyDefault.assembledWord
        tr.selected_pair tr.assembly_result ->
      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) ->
      num.imp.dec2flt.slow.parse_long_mantissa_loop1
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 2047#i32 }
        d0.num_digits d0.decimal_point d0.truncated d0.digits exp0 none =
          ok (d1.num_digits, d1.decimal_point, d1.truncated, d1.digits,
            exp1, none) ->
      num.imp.dec2flt.slow.parse_long_mantissa_loop2
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
          ok (d2, exp2) ->
      exp1 - 1#i32 = ok expStart -> expStart.val = exp1.val - 1 ->
      d1.decimal_point.val = 0 -> d1.num_digits.val != 0 ->
      5 <= d1.digits.val[0].val ->
      -1079 <= exp1.val ->
      B / (2 : Real) ^ exp1.val <= 1 ->
      exp2.val = max expStart.val (-1022) ->
      (exp2.val - expStart.val).toNat <= 58 ->
      let A := DecimalGoalVocabularyDefault.accumulatedMagnitude x
      let digits2 :=
        (d2.digits.val.take d2.num_digits.val).map (fun z => z.val)
      let integer2 : Nat := digits2.foldl (fun n digit => 10 * n + digit) 0
      let value2 : Real := integer2 * (10 : Real) ^
        (d2.decimal_point.val - (d2.num_digits.val : Int))
      d2.num_digits.val <= 768 /\
      (forall z, z ∈ d2.digits.val.take d2.num_digits.val -> z.val < 10) /\
      (exists z zs, digits2 = z :: zs /\ 1 <= z /\ z < 10 /\
        digits2.length = d2.num_digits.val) /\
      (exists eta2 u2 : Real,
        A / (2 : Real) ^ (exp2.val + 1) = value2 + eta2 /\
        B / (2 : Real) ^ (exp2.val + 1) = value2 + u2 /\
        0 <= eta2 /\ eta2 < u2 /\
        (d2.truncated = true <-> 0 < eta2)) ->
      num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d2 53#usize = ok d3 ->
      let digits3 :=
        (d3.digits.val.take d3.num_digits.val).map (fun z => z.val)
      let integer3 : Nat := digits3.foldl (fun n digit => 10 * n + digit) 0
      let value3 : Real := integer3 * (10 : Real) ^
        (d3.decimal_point.val - (d3.num_digits.val : Int))
      d3.num_digits.val <= 768 /\
      (forall z, z ∈ d3.digits.val.take d3.num_digits.val -> z.val < 10) /\
      (exists z zs, digits3 = z :: zs /\ 1 <= z /\ z < 10 /\
        digits3.length = d3.num_digits.val /\ digits3.getLast? != some 0) /\
      (exists eta3 u3 : Real,
        A / (2 : Real) ^ (exp2.val - 52) = value3 + eta3 /\
        B / (2 : Real) ^ (exp2.val - 52) = value3 + u3 /\
        0 <= eta3 /\ eta3 < u3 /\
        (d3.truncated = true <-> 0 < eta3)) /\
      d3.decimal_point.val < 19 /\
      0 <= A / (2 : Real) ^ (exp2.val - 52) /\
      A / (2 : Real) ^ (exp2.val - 52) <
        (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) /\
      (forall n : Nat,
        (n : Real) + (1 / 2 : Real) <= value3 \/
          B / (2 : Real) ^ (exp2.val - 52) <=
            (n : Real) + (1 / 2 : Real)) ->
      (forall d4 : num.imp.dec2flt.decimal_seq.DecimalSeq,
        num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d3 1#usize = ok d4 ->
        d4.num_digits.val != 0 ->
        let digits4 :=
          (d4.digits.val.take d4.num_digits.val).map (fun z => z.val)
        let integer4 : Nat := digits4.foldl (fun n digit => 10 * n + digit) 0
        let value4 : Real := integer4 * (10 : Real) ^
          (d4.decimal_point.val - (d4.num_digits.val : Int))
        d4.num_digits.val <= 768 /\
        (forall z, z ∈ d4.digits.val.take d4.num_digits.val -> z.val < 10) /\
        (exists z zs, digits4 = z :: zs /\ 1 <= z /\ z < 10 /\
          digits4.length = d4.num_digits.val /\ digits4.getLast? != some 0) /\
        (exists eta4 u4 : Real,
          A / (2 : Real) ^ (exp2.val - 51) = value4 + eta4 /\
          B / (2 : Real) ^ (exp2.val - 51) = value4 + u4 /\
          0 <= eta4 /\ eta4 < u4 /\
          (d4.truncated = true <-> 0 < eta4)) /\
        d4.decimal_point.val < 19 /\
        0 <= A / (2 : Real) ^ (exp2.val - 51) /\
        A / (2 : Real) ^ (exp2.val - 51) <
          (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) /\
        forall n : Nat,
          (n : Real) + (1 / 2 : Real) <= value4 \/
            B / (2 : Real) ^ (exp2.val - 51) <=
              (n : Real) + (1 / 2 : Real)) ->
      let unit : Nat := 2 ^ 52
      let infinityBits : Nat := 2047 * unit
      let threshold : Real := (2 : Real) ^ (1024 : Nat) -
        (2 : Real) ^ (970 : Nat)
      let raw : Nat := Nat.lor tr.selected_pair.m.val
        (((tr.selected_pair.p_biased.val.emod (2 ^ 64)).toNat * unit) %
          (2 ^ 64))
      (raw = infinityBits /\ threshold <= A) \/
      (exists j : Nat,
        j <= 2 ^ 53 /\ raw = j /\
        A <= (2 ^ 53 : Nat) * (2 : Real) ^ (-(1074 : Int)) /\
        A <= (j : Real) * (2 : Real) ^ (-(1074 : Int)) +
          (2 : Real) ^ (-(1075 : Int)) /\
        (j : Real) * (2 : Real) ^ (-(1074 : Int)) <= A +
          (2 : Real) ^ (-(1075 : Int)) /\
        (A = ((j : Real) + (1 / 2 : Real)) *
              (2 : Real) ^ (-(1074 : Int)) \/
            A = ((j : Real) - (1 / 2 : Real)) *
              (2 : Real) ^ (-(1074 : Int)) -> j % 2 = 0)) \/
      (exists p j : Nat,
        2 <= p /\ p <= 2046 /\
        2 ^ 52 <= j /\ j <= 2 ^ 53 /\
        (p < 2046 \/ j < 2 ^ 53) /\
        raw = p * unit + (j - unit) /\
        let delta : Real := (2 : Real) ^ ((p : Int) - 1075)
        (unit : Real) * delta <= A /\
        A <= (2 ^ 53 : Nat) * delta /\
        A < threshold /\
        A <= (j : Real) * delta + delta / 2 /\
        (j : Real) * delta <= A + delta / 2 /\
        (A = ((j : Real) + (1 / 2 : Real)) * delta \/
            A = ((j : Real) - (1 / 2 : Real)) * delta -> j % 2 = 0)) := 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.

Earlier prose review

An earlier review questioned the prose argument. Lean subsequently checked the formal proof. Review of the statement’s intended meaning is a separate judgment.

Proof

Unfold num imp dec2flt slow parse long mantissa and rewrite its three loops by the exact call hypotheses. The checked decrement gives e_s=e_1-1, and the normalization equation gives e_2=\max(e_s,-1022). Hence
-1022\leq e_2,\qquad e_1\leq e_2+1. \tag{1}
Write V_2 for the positive decimal value represented by d_2. Positivity follows from its nonempty canonical leading digit and DecimalValueBounds. The two endpoint equations for d_2 have errors 0\leq\eta_2<u_2, so
\frac{A}{2^{e_2+1}}=V_2+\eta_2 <V_2+u_2=\frac{B}{2^{e_2+1}}. \tag{2}
In particular A<B and B>0. By (1), monotonicity of powers of two, and the explicit hypothesis B/2^{e_1}\leq1,
\frac{B}{2^{e_2+1}}\leq\frac{B}{2^{e_1}}\leq1, \qquad \frac{A}{2^{e_2+1}}<1. \tag{3}
This is the normalization bound needed below; it is not inferred merely from the leading digit.
Put X=A/2^{e_2-52} and B_3=B/2^{e_2-52}. The supplied d_3 certificate, whose construction is stated by ParserSlowFirstRoundSeparation, gives precisely the shape, endpoint, point, U64-range, and half-integer-separation premises of DecimalSeqRoundArbitraryEndpoint. Applying that theorem produces the same U64 M as the extracted first round and gives
X\leq M+\tfrac12,\qquad M\leq X+\tfrac12, \tag{4}
with M even if either inequality is an equality at a midpoint. Rewriting X=(A/2^{e_2+1})2^{53} in (3) gives X<2^{53}; since M is integral, (4) gives M\leq2^{53}.
The constants supplied by ParserExponentConstants reduce the first saturation test in num imp dec2flt slow parse long mantissa to e_2+1023\geq2047. If it succeeds, then e_2\geq1024. In this case e_2>-1022, so loop 2 performs no shift: its one-step body is already done, d_2=d_1, and e_2=e_s. The point-zero and leading-digit hypotheses and DecimalValueBounds give V_2\geq1/2, whence A/2^{e_2+1}\geq1/2. Therefore A\geq2^{1024}, which is at least the required threshold 2^{1024}-2^{970}. The extracted result is exactly the zero-mantissa, biased-exponent-2047 record, whose raw word is 2047\,2^{52}.
Suppose instead that the first test does not saturate. The checked cast and addition produce the shift count 53, the stipulated left-shift call identifies its result with d_3, the stipulated round call identifies its result with M, and the checked U32 addition and U64 shift produce the comparison word 2^{53}. Thus the extracted carry branch is taken exactly when M\geq2^{53}.
In the carry branch M=2^{53}. It is also necessary to justify, rather than assume, the nonempty successor required by the carry certificate. Since this round result is nonzero, unfolding the round guard rules out a negative decimal point for d_3. Its canonical positive-leading shape and point bound then satisfy DecimalRightShiftLoop0Execution with shift one. That theorem constructs a successful right shift with nonzero digit count; determinism of the result identifies it with the successor in the extracted call. The universal carry hypothesis, whose certificate is supplied by ParserSlowCarryRoundSeparation, now applies. A second application of DecimalSeqRoundArbitraryEndpoint gives the rerounded integer M_4. From (4), (3), and M=2^{53},
2^{52}-\tfrac14\leq A/2^{e_2-51}<2^{52}.
The two half-step inequalities for M_4 force M_4=2^{52}.
The checked exponent update in this branch is e_{24}=e_2+1 and its second biased test is e_2+1024\geq2047. If that test succeeds, the preceding nonsaturation forces e_2=1023. The lower inequality in (4) then gives
(2^{53}-\tfrac12)2^{971}\leq A.
Direct power arithmetic gives
(2^{53}-\tfrac12)2^{971}=2^{1024}-2^{970}. \tag{5}
Thus this extracted infinity result satisfies the exact threshold clause. If the second test does not succeed, e_2\leq1022. The reround is 2^{52}, its mask is zero, and the raw word is (e_2+1024)2^{52}. For e_2=-1022 this is the low-grid witness j=2^{53}. For e_2>-1022, choose the equivalent endpoint witness p=e_2+1023, j=2^{53}; then (e_2+1024)2^{52}=p2^{52}+(j-2^{52}). The inequalities and parity clause are exactly (4) scaled by 2^{e_2-52}.
It remains to treat the noncarry branch M<2^{53}. Its checked arithmetic first forms p_0=e_2+1023, subtracts one precisely when M<2^{52}, and masks the mantissa by 2^{52}-1. The mask identity is
(M\mathbin{\&}(2^{52}-1))=M\bmod2^{52}. \tag{6}
The masked value is below 2^{52}, while the exponent field is a multiple of 2^{52}; hence their bitwise OR is their sum. These are exactly the operations denoted by ModelU64Shl, ModelU64BitAnd, and ModelU64BitOr. If e_2=-1022, the two cases M<2^{52} and M\geq2^{52} reduce (6) respectively to exponent fields zero and one, and both give raw word M. Thus j=M is the low-grid witness.
If e_2>-1022, the no-shift argument used above gives A/2^{e_2+1}\geq1/2, hence X\geq2^{52}. The first inequality in (4) and integrality force M\geq2^{52}, so no exponent decrement occurs. With p=e_2+1023 and j=M, (6) gives
2\leq p\leq2046,\quad 2^{52}\leq j<2^{53},\quad r=p2^{52}+(j-2^{52}). \tag{7}
The lower and upper magnitude bounds follow from 2^{52}\leq X<2^{53} after multiplying by \Delta=2^{p-1075}=2^{e_2-52}, and (4) gives both half-step inequalities and the even-tie implication.
For every finite case with e_2\leq1022, (3) gives A<2^{e_2+1}\leq2^{1023}<2^{1024}-2^{970}. In the sole remaining case e_2=1023, noncarry gives M\leq2^{53}-1, and (4) gives X\leq2^{53}-1/2. Equality would force M=2^{53}-1, an odd midpoint result, contradicting the even-tie clause. Thus the inequality is strict; multiplying by 2^{971} and using (5) gives A<2^{1024}-2^{970}. The carry and noncarry cases are exhaustive, and the displayed calculations establish every raw-word, range, nearest, parity, and threshold conjunct in the three alternatives.

Lean proof


  dsimp only
  intro x B tr d d0 d1 d2 d3 exp0 exp1 expStart exp2
    hparse hdne hdpLower hdpUpper hslow hassembled hloop0 hloop1 hloop2
    hsub hstart hd1Point hd1ne hd1Lead hexp1Lower hBUpper hexp2
    hshiftBound hstate2 hleft53 hstate3 hcarry
  classical
  let A := DecimalGoalVocabularyDefault.accumulatedMagnitude x
  let digits2 :=
    (d2.digits.val.take d2.num_digits.val).map (fun z => z.val)
  let integer2 : Nat := digits2.foldl (fun n digit => 10 * n + digit) 0
  let value2 : Real := integer2 * (10 : Real) ^
    (d2.decimal_point.val - (d2.num_digits.val : Int))
  let digits3 :=
    (d3.digits.val.take d3.num_digits.val).map (fun z => z.val)
  let integer3 : Nat := digits3.foldl (fun n digit => 10 * n + digit) 0
  let value3 : Real := integer3 * (10 : Real) ^
    (d3.decimal_point.val - (d3.num_digits.val : Int))
  rcases hstate2 with
    ⟨hcap2, hdigit2, hshape2, hend2⟩
  rcases hshape2 with ⟨z2, zs2, hshape2, hz2lo, hz2hi, hlen2⟩
  rcases hend2 with ⟨eta2, u2, hA2, hB2, heta2, hetau2, hsticky2⟩
  rcases hstate3 with
    ⟨hcap3, hdigit3, hshape3, hend3, hpoint3, hA3nonneg, hA3bound,
      hsep3⟩
  rcases hshape3 with
    ⟨z3, zs3, hshape3, hz3lo, hz3hi, hlen3, hlast3⟩
  rcases hend3 with ⟨eta3, u3, hA3, hB3, heta3, hetau3, hsticky3⟩
  have hround3 := DecimalSeqRoundArbitraryEndpoint d3
    (A / (2 : Real) ^ (exp2.val - 52))
    (B / (2 : Real) ^ (exp2.val - 52))
    ⟨hcap3, hdigit3,
      Or.inr ⟨z3, zs3, hshape3, hz3lo, hz3hi, hlen3, hlast3⟩,
      ⟨eta3, u3, hA3, hB3, heta3, hetau3, hsticky3⟩⟩
    hpoint3 hA3nonneg hA3bound hsep3
  obtain ⟨mantissa, hround3Call, hround3Upper, hround3Lower,
    hround3Even⟩ := hround3
  have hinteger2 : 0 < integer2 := by
    dsimp only [integer2, digits2]
    rw [hshape2]
    simp only [List.foldl_cons]
    have hrest (ys : List Nat) (a : Nat) :
        a <= ys.foldl (fun n digit => 10 * n + digit) a := by
      induction ys generalizing a with
      | nil => simp
      | cons q qs ih =>
        simp only [List.foldl_cons]
        exact le_trans (by omega) (ih (10 * a + q))
    have := hrest zs2 (10 * 0 + z2)
    omega
  have hvalue2pos : 0 < value2 := by
    exact mul_pos (by exact_mod_cast hinteger2) (zpow_pos (by norm_num) _)
  have hpow2pos : 0 < (2 : Real) ^ (exp2.val + 1) :=
    zpow_pos (by norm_num) _
  have hAB : A < B := by
    apply (div_lt_div_iff_of_pos_right hpow2pos).mp
    rw [hA2, hB2]
    linarith
  have hBpos : 0 < B := by
    have hquot : 0 < B / (2 : Real) ^ (exp2.val + 1) := by
      rw [hB2]
      linarith
    rcases div_pos_iff.mp hquot with h | h
    · exact h.1
    · exact (not_lt_of_ge hpow2pos.le h.2).elim
  have hexpOrder : exp1.val <= exp2.val + 1 := by
    rw [hexp2, hstart]
    omega
  have hpowOrder : (2 : Real) ^ exp1.val <=
      (2 : Real) ^ (exp2.val + 1) :=
    zpow_le_zpow_right₀ (by norm_num) hexpOrder
  have hB2Upper : B / (2 : Real) ^ (exp2.val + 1) <= 1 := by
    exact (div_le_div_of_nonneg_left hBpos.le
      (zpow_pos (by norm_num) _) hpowOrder).trans hBUpper
  have hA2Upper : A / (2 : Real) ^ (exp2.val + 1) < 1 := by
    have hlt : A / (2 : Real) ^ (exp2.val + 1) <
        B / (2 : Real) ^ (exp2.val + 1) :=
      (div_lt_div_iff_of_pos_right hpow2pos).2 hAB
    exact hlt.trans_le hB2Upper
  have hscale53 (C : Real) :
      C / (2 : Real) ^ (exp2.val - 52) =
        (C / (2 : Real) ^ (exp2.val + 1)) * (2 : Real) ^ (53 : Nat) := by
    rw [show exp2.val + 1 = (exp2.val - 52) + 53 by omega]
    rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
    norm_num only [zpow_natCast]
    field_simp
  have hA3Upper53 : A / (2 : Real) ^ (exp2.val - 52) <
      (2 : Real) ^ (53 : Nat) := by
    rw [hscale53]
    have hp53 : 0 < (2 : Real) ^ (53 : Nat) := by positivity
    nlinarith
  have hmantissaLe : mantissa.val <= 2 ^ 53 := by
    have hreal : (mantissa.val : Real) < ((2 ^ 53 : Nat) : Real) + 1 :=
      calc
        (mantissa.val : Real) <=
            A / (2 : Real) ^ (exp2.val - 52) + 1 / 2 := hround3Lower
        _ < ((2 ^ 53 : Nat) : Real) + 1 := by
          norm_num at hA3Upper53 ⊢
          linarith
    have hnat : mantissa.val < (2 ^ 53 : Nat) + 1 := by
      exact_mod_cast hreal
    omega
  have hexp2Lower : -1022 <= exp2.val := by
    rw [hexp2]
    exact le_max_right _ _
  rcases ParserExponentConstants with
    ⟨hbits, htotal, hsig, hexpbits, hexpsat, hinf, hbias, hmin,
      hsmall, hlarge, hroundmin, hroundmax⟩
  have hzero : num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
      ok { m := 0#u64, p_biased := 0#i32 } := by rfl
  have hinfFp : num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
      ok { m := 0#u64, p_biased := 2047#i32 } := by rfl
  have hdword : d.num_digits ≠ 0#usize := by
    intro h
    have := congrArg UScalar.val h
    simp at this
    have hdne' : d.num_digits.val ≠ 0 := by
      simpa [bne_iff_ne] using hdne
    exact hdne' this
  have hdpNotLow : ¬ d.decimal_point < (-324)#i32 := by
    change ¬ d.decimal_point.val < -324
    omega
  have hdpNotHigh : ¬ d.decimal_point >= 310#i32 := by
    change ¬ 310 <= d.decimal_point.val
    omega
  have hnormalizedLower (he : -1022 < exp2.val) :
      (1 / 2 : Real) <= A / (2 : Real) ^ (exp2.val + 1) := by
    have hstartHigh : -1022 <= expStart.val := by
      rw [hexp2] at he
      omega
    have hbody :
        num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
            ok (done (d1, expStart)) := by
      unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
      rw [hmin]
      simp only [bind_tc_ok]
      have hnot : ¬ ((-1022)#i32 : Std.I32) > expStart := by
        change ¬ (-1022 : Int) > expStart.val
        omega
      simp only [hnot, if_false]
    have hloopIdentity :
        num.imp.dec2flt.slow.parse_long_mantissa_loop2
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
            ok (d1, expStart) := by
      unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2
      rw [Aeneas.Std.loop.eq_1]
      simpa only [hbody]
    have hpair := Result.ok.inj (hloopIdentity.symm.trans hloop2)
    have hd2eq : d2 = d1 := (congrArg Prod.fst hpair).symm
    have he2eq : exp2 = expStart := (congrArg Prod.snd hpair).symm
    subst d2
    have hpoint2 : d1.decimal_point.val = 0 := by
      exact hd1Point
    have hnum2pos : 0 < d1.num_digits.val := by
      rw [← hlen2, hshape2]
      simp
    have hindexBound : (0 : Nat) < d1.digits.val.length := by
      rw [d1.digits.property]
      norm_num
    have htake : (d1.digits.val.take d1.num_digits.val)[0]? =
        some d1.digits.val[0] := by
      rw [List.getElem?_take, if_pos hnum2pos]
      exact List.getElem?_eq_getElem hindexBound
    have hhead := congrArg List.head? hshape2
    rw [List.head?_eq_getElem?] at hhead
    simp only [List.getElem?_map, htake] at hhead
    have hz2eq : z2 = d1.digits.val[0].val := by
      exact (Option.some.inj hhead).symm
    have hz2five : 5 <= z2 := by
      rw [hz2eq]
      exact hd1Lead
    have hdigits2 : forall q, q ∈ digits2 -> q < 10 := by
      intro q hq
      simp only [digits2, List.mem_map] at hq
      rcases hq with ⟨q8, hq8, rfl⟩
      exact hdigit2 q8 hq8
    have hv := P804_T1_DecimalValueBounds digits2 z2 zs2 hshape2 hz2lo
      hdigits2 d1.decimal_point.val
    dsimp only at hv
    rw [hlen2] at hv
    have hhalfValue : (1 / 2 : Real) <= value2 := by
      calc
        (1 / 2 : Real) <= (z2 : Real) * (10 : Real) ^ (-1 : Int) := by
          have hzR : (5 : Real) <= (z2 : Real) := by exact_mod_cast hz2five
          rw [zpow_neg]
          norm_num
          linarith
        _ <= value2 := by
          simpa [value2, integer2, hpoint2] using hv.1
    rw [hA2]
    exact hhalfValue.trans (by linarith)
  let infPower :=
    F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITE_POWER
  have hinf' : infPower = ok 2047#i32 := hinf
  let expMin := F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.EXP_MIN
  have hmin' : expMin = ok (-1022)#i32 := hmin
  have bind_ok_inv : ∀ {α β : Type} (r : Result α) (f : α → Result β) y,
      Bind.bind r f = ok y → ∃ x, r = ok x ∧ f x = ok y := by
    intro α β r f y hr
    cases r with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hr
    | div => simp [Bind.bind, Aeneas.Std.bind] at hr
    | ok q => exact ⟨q, rfl, hr⟩
  have hflow := hslow
  unfold num.imp.dec2flt.slow.parse_long_mantissa at hflow
  rw [hzero] at hflow
  simp only [bind_tc_ok] at hflow
  change (do let i ← infPower; _) = _ at hflow
  rw [hinf'] at hflow
  simp only [bind_tc_ok] at hflow
  rw [hinfFp, hparse] at hflow
  simp only [bind_tc_ok, hdword, if_false, hdpNotLow, hdpNotHigh,
    hloop0] at hflow
  change (do
    let (i3, i4, b1, a1, exp21, loop_result1) ←
      num.imp.dec2flt.slow.parse_long_mantissa_loop1
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 2047#i32 }
        d0.num_digits d0.decimal_point d0.truncated d0.digits exp0 none
    match loop_result1 with
    | none => _
    | some result => ok result) = _ at hflow
  rw [hloop1] at hflow
  simp only [bind_tc_ok] at hflow
  change (do
    let exp22 ← exp1 - 1#i32
    let (q2, exp23) ←
      num.imp.dec2flt.slow.parse_long_mantissa_loop2
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 exp22
    _) = _ at hflow
  rw [hsub] at hflow
  simp only [bind_tc_ok] at hflow
  change (do
    let (q2, exp23) ←
      num.imp.dec2flt.slow.parse_long_mantissa_loop2
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart
    _) = _ at hflow
  rw [hloop2] at hflow
  simp only [bind_tc_ok] at hflow
  change (do let i5 ← expMin; _) = _ at hflow
  rw [hmin'] at hflow
  simp only [bind_tc_ok] at hflow
  obtain ⟨expDiff, hdiff, hflow⟩ := bind_ok_inv _ _ _ hflow
  obtain ⟨biased, hbiased, hflow⟩ := bind_ok_inv _ _ _ hflow
  have hdiffVal : expDiff.val = exp2.val - (-1022) := by
    have hs := IScalar.sub_equiv exp2 (-1022)#i32
    rw [hdiff] at hs
    simpa using hs.2.1
  have hbiasedVal : biased.val = exp2.val + 1023 := by
    have hs := IScalar.add_equiv expDiff 1#i32
    rw [hbiased] at hs
    have hv := hs.2.1
    rw [hdiffVal] at hv
    norm_num at hv
    omega
  by_cases hsat : biased >= 2047#i32
  · simp only [hsat, if_true] at hflow
    have hselected : tr.selected_pair =
        ({ m := 0#u64, p_biased := 2047#i32 } :
          num.imp.dec2flt.common.BiasedFp) :=
      (Result.ok.inj hflow).symm
    rw [hselected]
    left
    constructor
    · norm_num
      rw [Nat.mod_eq_of_lt (by decide)]
      rfl
    · have he : 1024 <= exp2.val := by
        change biased.val >= 2047 at hsat
        omega
      have hnorm := hnormalizedLower (by omega)
      have hmag : (1 / 2 : Real) * (2 : Real) ^ (exp2.val + 1) <= A :=
        (le_div_iff₀ hpow2pos).mp hnorm
      have hpow : (2 : Real) ^ (1025 : Int) <=
          (2 : Real) ^ (exp2.val + 1) :=
        zpow_le_zpow_right₀ (by norm_num) (by omega)
      calc
        (2 : Real) ^ (1024 : Nat) - (2 : Real) ^ (970 : Nat) <=
            (2 : Real) ^ (1024 : Nat) := by
          exact sub_le_self _ (by positivity)
        _ = (1 / 2 : Real) * (2 : Real) ^ (1025 : Int) := by
          rw [show (2 : Real) ^ (1025 : Int) =
            (2 : Real) ^ (1024 : Nat) * 2 by
              rw [show (1025 : Int) = (1024 : Int) + 1 by omega,
                zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
              norm_num
              rfl]
          ring
        _ <= (1 / 2 : Real) * (2 : Real) ^ (exp2.val + 1) := by
          nlinarith
        _ <= A := hmag
  · simp only [hsat, if_false] at hflow
    let sigBits := F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_BITS
    have hsig' : sigBits = ok 52#u32 := hsig
    change (do let i8 ← sigBits; _) = _ at hflow
    rw [hsig'] at hflow
    simp only [bind_tc_ok] at hflow
    obtain ⟨shiftWidth, hcastWidth, hflow⟩ := bind_ok_inv _ _ _ hflow
    obtain ⟨shiftCount, haddCount, hflow⟩ := bind_ok_inv _ _ _ hflow
    have hwidthVal : shiftWidth.val = 52 := by
      simp only [lift] at hcastWidth
      have heq := Result.ok.inj hcastWidth
      have hv := congrArg UScalar.val heq
      simpa [UScalar.cast_val_eq] using hv.symm
    have hcountVal : shiftCount.val = 53 := by
      have hs := UScalar.add_equiv shiftWidth 1#usize
      rw [haddCount] at hs
      have hv := hs.2.1
      rw [hwidthVal] at hv
      norm_num at hv ⊢
      exact hv
    have hcount : shiftCount = 53#usize :=
      UScalar.eq_of_val_eq (by simpa using hcountVal)
    obtain ⟨shifted, hleft, hflow⟩ := bind_ok_inv _ _ _ hflow
    have hshifted : shifted = d3 := by
      rw [hcount] at hleft
      exact Result.ok.inj (hleft.symm.trans hleft53)
    subst shifted
    obtain ⟨rounded, hround, hflow⟩ := bind_ok_inv _ _ _ hflow
    have hrounded : rounded = mantissa :=
      Result.ok.inj (hround.symm.trans hround3Call)
    subst rounded
    obtain ⟨sigCount, haddSig, hflow⟩ := bind_ok_inv _ _ _ hflow
    have hsigCountVal : sigCount.val = 53 := by
      have hs := UScalar.add_equiv (52#u32 : Std.U32) 1#u32
      rw [haddSig] at hs
      simpa using hs.2.1
    have hsigCount : sigCount = 53#u32 :=
      UScalar.eq_of_val_eq (by simpa using hsigCountVal)
    obtain ⟨carryLimit, hshiftLimit, hflow⟩ := bind_ok_inv _ _ _ hflow
    have hcarryLimitVal : carryLimit.val = 2 ^ 53 := by
      have hs := UScalar.ShiftLeft_spec (1#u64) sigCount (2 ^ 64)
        (by rw [hsigCount]; norm_num [U64.numBits])
        (by norm_num [U64.size_eq])
      rw [hshiftLimit] at hs
      have hv := hs.1
      simp only [WP.spec_ok] at hv
      rw [hsigCount, Nat.shiftLeft_eq] at hv
      norm_num at hv ⊢
      exact hv
    have hcarryLimit : carryLimit = 9007199254740992#u64 :=
      UScalar.eq_of_val_eq (by norm_num; exact hcarryLimitVal)
    rw [hcarryLimit] at hflow
    have hdeltaPos : 0 < (2 : Real) ^ (exp2.val - 52) :=
      zpow_pos (by norm_num) _
    have hnearestUpper : A <= (mantissa.val : Real) *
          (2 : Real) ^ (exp2.val - 52) +
        (2 : Real) ^ (exp2.val - 52) / 2 := by
      calc
        A = (A / (2 : Real) ^ (exp2.val - 52)) *
            (2 : Real) ^ (exp2.val - 52) := by field_simp
        _ <= ((mantissa.val : Real) + 1 / 2) *
            (2 : Real) ^ (exp2.val - 52) := by gcongr
        _ = _ := by ring
    have hnearestLower : (mantissa.val : Real) *
          (2 : Real) ^ (exp2.val - 52) <= A +
        (2 : Real) ^ (exp2.val - 52) / 2 := by
      have hq : (mantissa.val : Real) - 1 / 2 <=
          A / (2 : Real) ^ (exp2.val - 52) := by linarith
      calc
        (mantissa.val : Real) * (2 : Real) ^ (exp2.val - 52) =
            ((mantissa.val : Real) - 1 / 2) *
                (2 : Real) ^ (exp2.val - 52) +
              (2 : Real) ^ (exp2.val - 52) / 2 := by ring
        _ <= (A / (2 : Real) ^ (exp2.val - 52)) *
              (2 : Real) ^ (exp2.val - 52) +
            (2 : Real) ^ (exp2.val - 52) / 2 := by gcongr
        _ = _ := by field_simp
    have hnearestEven :
        (A = ((mantissa.val : Real) + 1 / 2) *
              (2 : Real) ^ (exp2.val - 52) ∨
          A = ((mantissa.val : Real) - 1 / 2) *
              (2 : Real) ^ (exp2.val - 52) -> mantissa.val % 2 = 0) := by
      intro htie
      apply hround3Even
      rcases htie with htie | htie
      · left
        apply (div_eq_iff (ne_of_gt hdeltaPos)).2
        simpa [mul_comm] using htie
      · right
        apply (div_eq_iff (ne_of_gt hdeltaPos)).2
        simpa [mul_comm] using htie
    by_cases hfirstCarry : mantissa >= 9007199254740992#u64
    · simp only [hfirstCarry, if_true] at hflow
      have hmantissaCarry : mantissa.val = 2 ^ 53 := by
        change mantissa.val >= 9007199254740992 at hfirstCarry
        norm_num at hfirstCarry ⊢
        omega
      have hnum3ne : d3.num_digits ≠ 0#usize := by
        intro heq
        have hv := congrArg UScalar.val heq
        norm_num at hv
        rw [← hlen3, hshape3] at hv
        simp at hv
      have hpoint3nonneg : 0 <= d3.decimal_point.val := by
        by_contra hn
        have hpword : d3.decimal_point < 0#i32 := by
          change d3.decimal_point.val < 0
          omega
        unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round at hround3Call
        simp only [hnum3ne, if_false, hpword, if_true] at hround3Call
        have hz := congrArg UScalar.val (Result.ok.inj hround3Call.symm)
        rw [hmantissaCarry] at hz
        norm_num at hz
      obtain ⟨read4, acc4, d4good, _hprefix4, _hread4lo, _hread4hi,
          _hacc4lo, _hacc4hi, _hpros4lo, _hpros4hi, hrightGood,
          _hpoint4, hnonzeroGood⟩ :=
        DecimalRightShiftLoop0Execution d3 1#usize (by norm_num)
          hpoint3nonneg (by omega)
          ⟨hcap3, hdigit3, z3, zs3, hshape3, hz3lo, hz3hi,
            by rw [← hshape3]; exact hlen3⟩
      obtain ⟨d4, hright4, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hd4 : d4 = d4good := Result.ok.inj (hright4.symm.trans hrightGood)
      have hnonzero4 : d4.num_digits.val != 0 := by
        rw [hd4]
        exact hnonzeroGood
      have hstate4 := hcarry d4 hright4 hnonzero4
      rcases hstate4 with
        ⟨hcap4, hdigit4, hshape4, hend4, hpoint4, hA4nonneg,
          hA4bound, hsep4⟩
      rcases hshape4 with
        ⟨z4, zs4, hshape4, hz4lo, hz4hi, hlen4, hlast4⟩
      rcases hend4 with
        ⟨eta4, u4, hA4, hB4, heta4, hetau4, hsticky4⟩
      have hround4 := DecimalSeqRoundArbitraryEndpoint d4
        (A / (2 : Real) ^ (exp2.val - 51))
        (B / (2 : Real) ^ (exp2.val - 51))
        ⟨hcap4, hdigit4,
          Or.inr ⟨z4, zs4, hshape4, hz4lo, hz4hi, hlen4, hlast4⟩,
          ⟨eta4, u4, hA4, hB4, heta4, hetau4, hsticky4⟩⟩
        hpoint4 hA4nonneg hA4bound hsep4
      obtain ⟨mantissa4, hround4Call, hround4Upper, hround4Lower,
        hround4Even⟩ := hround4
      obtain ⟨exp24, haddExp24, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hexp24Val : exp24.val = exp2.val + 1 := by
        have hs := IScalar.add_equiv exp2 1#i32
        rw [haddExp24] at hs
        exact hs.2.1
      obtain ⟨rounded4, hround4', hflow⟩ := bind_ok_inv _ _ _ hflow
      have hrounded4 : rounded4 = mantissa4 :=
        Result.ok.inj (hround4'.symm.trans hround4Call)
      subst rounded4
      obtain ⟨expDiff4, hdiff4, hflow⟩ := bind_ok_inv _ _ _ hflow
      obtain ⟨biased4, hbiased4, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hdiff4Val : expDiff4.val = exp24.val - (-1022) := by
        have hs := IScalar.sub_equiv exp24 (-1022)#i32
        rw [hdiff4] at hs
        simpa using hs.2.1
      have hbiased4Val : biased4.val = exp2.val + 1024 := by
        have hs := IScalar.add_equiv expDiff4 1#i32
        rw [hbiased4] at hs
        have hv := hs.2.1
        rw [hdiff4Val, hexp24Val] at hv
        norm_num at hv
        omega
      have hscaleHalf : A / (2 : Real) ^ (exp2.val - 51) =
          (A / (2 : Real) ^ (exp2.val - 52)) / 2 := by
        rw [show exp2.val - 51 = (exp2.val - 52) + 1 by omega,
          zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
        rw [div_eq_mul_inv]
        ring
      have hX4Lower : ((2 ^ 52 : Nat) : Real) - 1 / 4 <=
          A / (2 : Real) ^ (exp2.val - 51) := by
        rw [hscaleHalf]
        have hmreal : (mantissa.val : Real) = (2 ^ 53 : Nat) := by
          exact_mod_cast hmantissaCarry
        rw [hmreal] at hround3Lower
        norm_num at hround3Lower ⊢
        linarith
      have hX4Upper : A / (2 : Real) ^ (exp2.val - 51) <
          ((2 ^ 52 : Nat) : Real) := by
        rw [hscaleHalf]
        norm_num at hA3Upper53 ⊢
        linarith
      have hmantissa4Le : mantissa4.val <= 2 ^ 52 := by
        have hr : (mantissa4.val : Real) < ((2 ^ 52 : Nat) : Real) + 1 :=
          hround4Lower.trans_lt (by linarith)
        have hrn : mantissa4.val < (2 ^ 52 : Nat) + 1 := by
          exact_mod_cast hr
        omega
      have hmantissa4Ge : 2 ^ 52 <= mantissa4.val := by
        by_contra hn
        have hle : mantissa4.val <= 2 ^ 52 - 1 := by omega
        have hleR : (mantissa4.val : Real) <=
            ((2 ^ 52 - 1 : Nat) : Real) := by exact_mod_cast hle
        have hround4Upper' : A / (2 : Real) ^ (exp2.val - 51) <=
            ((2 ^ 52 - 1 : Nat) : Real) + 1 / 2 := by
          calc
            _ <= (mantissa4.val : Real) + 1 / 2 := hround4Upper
            _ <= ((2 ^ 52 - 1 : Nat) : Real) + 1 / 2 := by gcongr
        norm_num at hround4Upper' hX4Lower
        linarith
      have hmantissa4Val : mantissa4.val = 2 ^ 52 := by omega
      by_cases hsecondSat : biased4 >= 2047#i32
      · simp only [hsecondSat, if_true] at hflow
        have he1023 : exp2.val = 1023 := by
          change 2047 <= biased4.val at hsecondSat
          change ¬ 2047 <= biased.val at hsat
          omega
        have hselected : tr.selected_pair =
            ({ m := 0#u64, p_biased := 2047#i32 } :
              num.imp.dec2flt.common.BiasedFp) :=
          (Result.ok.inj hflow).symm
        rw [hselected]
        left
        constructor
        · norm_num
          rw [Nat.mod_eq_of_lt (by decide)]
          rfl
        · have hden : 0 < (2 : Real) ^ (971 : Int) :=
            zpow_pos (by norm_num) _
          have hscaled : ((2 ^ 53 : Nat) : Real) - 1 / 2 <=
              A / (2 : Real) ^ (971 : Int) := by
            have hmreal : (mantissa.val : Real) = (2 ^ 53 : Nat) := by
              exact_mod_cast hmantissaCarry
            rw [hmreal, he1023] at hround3Lower
            norm_num at hround3Lower ⊢
            linarith
          have hthresholdEq :
              (((2 ^ 53 : Nat) : Real) - 1 / 2) *
                  (2 : Real) ^ (971 : Nat) =
                (2 : Real) ^ (1024 : Nat) -
                  (2 : Real) ^ (970 : Nat) := by
            have hprod : (2 : Real) ^ (53 : Nat) * 2 ^ (971 : Nat) =
                (2 : Real) ^ (1024 : Nat) := by
              rw [← pow_add]
            have hhalf : (1 / 2 : Real) * 2 ^ (971 : Nat) =
                (2 : Real) ^ (970 : Nat) := by
              rw [show (2 : Real) ^ (971 : Nat) =
                2 * (2 : Real) ^ (970 : Nat) by
                  rw [show (971 : Nat) = 970 + 1 by omega, pow_succ]
                  ring]
              ring
            have hcast53 : (((2 ^ 53 : Nat) : Real)) =
                (2 : Real) ^ (53 : Nat) := by norm_num
            rw [hcast53]
            rw [sub_mul, hprod, hhalf]
          rw [← hthresholdEq]
          exact (le_div_iff₀ hden).mp (by simpa using hscaled)
      · simp only [hsecondSat, if_false] at hflow
        obtain ⟨expDiff5, hdiff5, hflow⟩ := bind_ok_inv _ _ _ hflow
        obtain ⟨power2, hpower2, hflow⟩ := bind_ok_inv _ _ _ hflow
        have hdiff5Val : expDiff5.val = exp24.val - (-1022) := by
          have hs := IScalar.sub_equiv exp24 (-1022)#i32
          rw [hdiff5] at hs
          simpa using hs.2.1
        have hpower2Val : power2.val = exp2.val + 1024 := by
          have hs := IScalar.add_equiv expDiff5 1#i32
          rw [hpower2] at hs
          have hv := hs.2.1
          rw [hdiff5Val, hexp24Val] at hv
          norm_num at hv
          omega
        obtain ⟨unit4a, hunit4a, hflow⟩ := bind_ok_inv _ _ _ hflow
        have hunit4aVal : unit4a.val = 2 ^ 52 := by
          have hs := UScalar.ShiftLeft_spec (1#u64) (52#u32) (2 ^ 64)
            (by norm_num [U64.numBits]) (by norm_num [U64.size_eq])
          rw [hunit4a] at hs
          have hv := hs.1
          simp only [WP.spec_ok, Nat.shiftLeft_eq] at hv
          norm_num at hv ⊢
          exact hv
        have hnotSmall4 : ¬ mantissa4 < unit4a := by
          change ¬ mantissa4.val < unit4a.val
          omega
        simp only [hnotSmall4, if_false, bind_tc_ok] at hflow
        obtain ⟨unit4b, hunit4b, hflow⟩ := bind_ok_inv _ _ _ hflow
        obtain ⟨mask4, hmask4, hflow⟩ := bind_ok_inv _ _ _ hflow
        obtain ⟨masked4, hmasked4, hflow⟩ := bind_ok_inv _ _ _ hflow
        have hunit4bVal : unit4b.val = 2 ^ 52 := by
          have hs := UScalar.ShiftLeft_spec (1#u64) (52#u32) (2 ^ 64)
            (by norm_num [U64.numBits]) (by norm_num [U64.size_eq])
          rw [hunit4b] at hs
          have hv := hs.1
          simp only [WP.spec_ok, Nat.shiftLeft_eq] at hv
          norm_num at hv ⊢
          exact hv
        have hmask4Val : mask4.val = 2 ^ 52 - 1 := by
          have hs := UScalar.sub_equiv unit4b 1#u64
          rw [hmask4] at hs
          have hv := hs.2.1
          rw [hunit4bVal] at hv
          norm_num at hv ⊢
          omega
        have hmasked4Val : masked4.val = 0 := by
          simp only [lift] at hmasked4
          have heq := Result.ok.inj hmasked4
          have hv := congrArg UScalar.val heq
          rw [UScalar.val_and, hmantissa4Val, hmask4Val,
            Nat.and_two_pow_sub_one_eq_mod] at hv
          simpa using hv.symm
        have hselected : tr.selected_pair =
            ({ m := masked4, p_biased := power2 } :
              num.imp.dec2flt.common.BiasedFp) :=
          (Result.ok.inj hflow).symm
        have hpower2Nonneg : 0 <= power2.val := by omega
        have hpower2Upper : power2.val <= 2046 := by
          change ¬ 2047 <= biased4.val at hsecondSat
          omega
        have hraw : Nat.lor masked4.val
              (((power2.val.emod (2 ^ 64)).toNat * (2 ^ 52)) %
                (2 ^ 64)) =
            (power2.val.toNat * (2 ^ 52)) := by
          have hzeroLor (n : Nat) : Nat.lor 0 n = n := by
            apply Nat.eq_of_testBit_eq
            intro k
            simp [Nat.testBit_lor]
          have hpower2Lt : power2.val < (2 ^ 64 : Int) := by
            norm_num
            omega
          have hem : power2.val.emod (2 ^ 64) = power2.val :=
            Int.emod_eq_of_lt hpower2Nonneg hpower2Lt
          rw [hmasked4Val, hzeroLor, hem]
          have hpNat : power2.val.toNat <= 2046 := by
            rw [Int.toNat_le]
            omega
          apply Nat.mod_eq_of_lt
          calc
            power2.val.toNat * 2 ^ 52 <= 2046 * 2 ^ 52 := by gcongr
            _ < 2 ^ 64 := by norm_num
        rw [hselected]
        simp only [hraw]
        by_cases hminimum : exp2.val = -1022
        · right
          left
          have hpowerNat : power2.val.toNat = 2 := by
            rw [hpower2Val, hminimum]
            rfl
          have hmreal : (mantissa.val : Real) = (2 ^ 53 : Nat) := by
            exact_mod_cast hmantissaCarry
          have hhalfMin : (2 : Real) ^ (-(1074 : Int)) / 2 =
              (2 : Real) ^ (-(1075 : Int)) := by
            rw [show (-(1074 : Int)) = -(1075 : Int) + 1 by omega,
              zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
            norm_num
          have hlowMagnitude : A <= ((2 ^ 53 : Nat) : Real) *
              (2 : Real) ^ (-(1074 : Int)) := by
            have hd : 0 < (2 : Real) ^ (-(1074 : Int)) :=
              zpow_pos (by norm_num) _
            have hx := hA3Upper53
            rw [hminimum] at hx
            have hm := (div_lt_iff₀ hd).mp hx
            norm_num only [Nat.cast_pow, Nat.cast_ofNat] at hm ⊢
            exact hm.le
          refine ⟨2 ^ 53, le_rfl, ?_, hlowMagnitude, ?_, ?_, ?_⟩
          · rw [hpowerNat]
            norm_num [pow_succ]
          · rw [← hhalfMin]
            simpa [hminimum, hmreal] using hnearestUpper
          · rw [← hhalfMin]
            simpa [hminimum, hmreal] using hnearestLower
          · simpa [hminimum, hmreal] using hnearestEven
        · right
          right
          let p : Nat := (exp2.val + 1023).toNat
          have heLower : -1022 < exp2.val := by omega
          have heUpper : exp2.val <= 1022 := by
            change ¬ 2047 <= biased4.val at hsecondSat
            omega
          have hpNonneg : 0 <= exp2.val + 1023 := by omega
          have hpCast : (p : Int) = exp2.val + 1023 := by
            dsimp only [p]
            exact Int.toNat_of_nonneg hpNonneg
          have hpowerNat : power2.val.toNat = p + 1 := by
            have hpowerNatCast : (power2.val.toNat : Int) = power2.val :=
              Int.toNat_of_nonneg hpower2Nonneg
            have heq : (power2.val.toNat : Int) = (p + 1 : Nat) := by
              push_cast
              rw [hpowerNatCast, hpCast, hpower2Val]
              omega
            exact_mod_cast heq
          have hmreal : (mantissa.val : Real) = (2 ^ 53 : Nat) := by
            exact_mod_cast hmantissaCarry
          have hpExp : (p : Int) - 1075 = exp2.val - 52 := by omega
          have hnormalMagnitude : ((2 ^ 52 : Nat) : Real) *
              (2 : Real) ^ ((p : Int) - 1075) <= A := by
            have hnorm := hnormalizedLower heLower
            have hx : ((2 ^ 52 : Nat) : Real) <=
                A / (2 : Real) ^ (exp2.val - 52) := by
              rw [hscale53]
              norm_num at hnorm ⊢
              nlinarith
            rw [hpExp]
            exact (le_div_iff₀ hdeltaPos).mp hx
          have hnormalUpper : A <= ((2 ^ 53 : Nat) : Real) *
              (2 : Real) ^ ((p : Int) - 1075) := by
            rw [hpExp]
            simpa only [Nat.cast_pow, Nat.cast_ofNat] using
              ((div_lt_iff₀ hdeltaPos).mp hA3Upper53).le
          have hbelowThreshold : A < (2 : Real) ^ (1024 : Nat) -
              (2 : Real) ^ (970 : Nat) := by
            have hAupper : A < (2 : Real) ^ (exp2.val + 1) :=
              (div_lt_one hpow2pos).mp hA2Upper
            have hp : (2 : Real) ^ (exp2.val + 1) <=
                (2 : Real) ^ (1023 : Int) :=
              zpow_le_zpow_right₀ (by norm_num) (by omega)
            have hgap : (2 : Real) ^ (1023 : Nat) <
                (2 : Real) ^ (1024 : Nat) -
                  (2 : Real) ^ (970 : Nat) := by
              have hsmallPow : (2 : Real) ^ (970 : Nat) <
                  (2 : Real) ^ (1023 : Nat) :=
                pow_lt_pow_right₀ (by norm_num) (by omega)
              rw [show (2 : Real) ^ (1024 : Nat) =
                2 * (2 : Real) ^ (1023 : Nat) by
                  rw [show (1024 : Nat) = 1023 + 1 by omega, pow_succ]
                  ring]
              rw [lt_sub_iff_add_lt]
              calc
                (2 : Real) ^ (1023 : Nat) + 2 ^ (970 : Nat) <
                    (2 : Real) ^ (1023 : Nat) + 2 ^ (1023 : Nat) :=
                  by simpa [add_comm] using
                    add_lt_add_left hsmallPow ((2 : Real) ^ (1023 : Nat))
                _ = 2 * (2 : Real) ^ (1023 : Nat) := by ring
            exact hAupper.trans_le hp |>.trans hgap
          refine ⟨p, 2 ^ 53, by omega, by omega, by omega, le_rfl,
            Or.inl (by omega), ?_, hnormalMagnitude, hnormalUpper,
            hbelowThreshold, ?_, ?_, ?_⟩
          · rw [hpowerNat]
            norm_num [pow_succ]
            omega
          · rw [hpExp]
            simpa [hmreal] using hnearestUpper
          · rw [hpExp]
            simpa [hmreal] using hnearestLower
          · rw [hpExp]
            simpa [hmreal] using hnearestEven
    · simp only [hfirstCarry, if_false] at hflow
      have hmantissaLt : mantissa.val < 2 ^ 53 := by
        change ¬ mantissa.val >= 9007199254740992 at hfirstCarry
        norm_num at hfirstCarry ⊢
        omega
      obtain ⟨expDiff5, hdiff5, hflow⟩ := bind_ok_inv _ _ _ hflow
      obtain ⟨power2, hpower2, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hdiff5Val : expDiff5.val = exp2.val - (-1022) := by
        have hs := IScalar.sub_equiv exp2 (-1022)#i32
        rw [hdiff5] at hs
        simpa using hs.2.1
      have hpower2Val : power2.val = exp2.val + 1023 := by
        have hs := IScalar.add_equiv expDiff5 1#i32
        rw [hpower2] at hs
        have hv := hs.2.1
        rw [hdiff5Val] at hv
        norm_num at hv
        omega
      obtain ⟨unit3a, hunit3a, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hunit3aVal : unit3a.val = 2 ^ 52 := by
        have hs := UScalar.ShiftLeft_spec (1#u64) (52#u32) (2 ^ 64)
          (by norm_num [U64.numBits]) (by norm_num [U64.size_eq])
        rw [hunit3a] at hs
        have hv := hs.1
        simp only [WP.spec_ok, Nat.shiftLeft_eq] at hv
        norm_num at hv ⊢
        exact hv
      obtain ⟨power21, hpower21, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hpower21Val : power21.val =
          if mantissa < unit3a then exp2.val + 1022
          else exp2.val + 1023 := by
        by_cases hsmall : mantissa < unit3a
        · simp only [hsmall, if_true] at hpower21 ⊢
          have hs := IScalar.sub_equiv power2 1#i32
          rw [hpower21] at hs
          have hv := hs.2.1
          calc
            power21.val = power2.val - 1 := hv
            _ = exp2.val + 1022 := by rw [hpower2Val]; omega
        · simp only [hsmall, if_false] at hpower21 ⊢
          have heq := Result.ok.inj hpower21
          have hv := congrArg IScalar.val heq
          calc
            power21.val = power2.val := hv.symm
            _ = exp2.val + 1023 := hpower2Val
      obtain ⟨unit3b, hunit3b, hflow⟩ := bind_ok_inv _ _ _ hflow
      obtain ⟨mask3, hmask3, hflow⟩ := bind_ok_inv _ _ _ hflow
      obtain ⟨masked3, hmasked3, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hunit3bVal : unit3b.val = 2 ^ 52 := by
        have hs := UScalar.ShiftLeft_spec (1#u64) (52#u32) (2 ^ 64)
          (by norm_num [U64.numBits]) (by norm_num [U64.size_eq])
        rw [hunit3b] at hs
        have hv := hs.1
        simp only [WP.spec_ok, Nat.shiftLeft_eq] at hv
        norm_num at hv ⊢
        exact hv
      have hmask3Val : mask3.val = 2 ^ 52 - 1 := by
        have hs := UScalar.sub_equiv unit3b 1#u64
        rw [hmask3] at hs
        have hv := hs.2.1
        rw [hunit3bVal] at hv
        norm_num at hv ⊢
        omega
      have hmasked3Val : masked3.val = mantissa.val % 2 ^ 52 := by
        simp only [lift] at hmasked3
        have heq := Result.ok.inj hmasked3
        have hv := congrArg UScalar.val heq
        rw [UScalar.val_and, hmask3Val,
          Nat.and_two_pow_sub_one_eq_mod] at hv
        exact hv.symm
      have hselected : tr.selected_pair =
          ({ m := masked3, p_biased := power21 } :
            num.imp.dec2flt.common.BiasedFp) :=
        (Result.ok.inj hflow).symm
      have hpower21Nonneg : 0 <= power21.val := by
        split at hpower21Val <;> omega
      have hpower21Upper : power21.val <= 2046 := by
        change ¬ 2047 <= biased.val at hsat
        split at hpower21Val <;> omega
      have hraw : Nat.lor masked3.val
            (((power21.val.emod (2 ^ 64)).toNat * (2 ^ 52)) %
              (2 ^ 64)) =
          power21.val.toNat * 2 ^ 52 + masked3.val := by
        have hpLt : power21.val < (2 ^ 64 : Int) := by
          norm_num
          omega
        have hem : power21.val.emod (2 ^ 64) = power21.val :=
          Int.emod_eq_of_lt hpower21Nonneg hpLt
        rw [hem, Nat.mod_eq_of_lt]
        · have hmaskedLt : masked3.val < 2 ^ 52 := by
            rw [hmasked3Val]
            exact Nat.mod_lt _ (by positivity)
          calc
            Nat.lor masked3.val (power21.val.toNat * 2 ^ 52) =
                Nat.lor (2 ^ 52 * power21.val.toNat) masked3.val := by
              rw [Nat.mul_comm]
              exact Nat.lor_comm _ _
            _ = 2 ^ 52 * power21.val.toNat + masked3.val :=
              (Nat.two_pow_add_eq_or_of_lt hmaskedLt _).symm
            _ = power21.val.toNat * 2 ^ 52 + masked3.val := by omega
        · have hpNat : power21.val.toNat <= 2046 := by
            rw [Int.toNat_le]
            omega
          calc
            power21.val.toNat * 2 ^ 52 <= 2046 * 2 ^ 52 := by gcongr
            _ < 2 ^ 64 := by norm_num
      rw [hselected]
      simp only [hraw]
      by_cases hminimum : exp2.val = -1022
      · have hrawMin : power21.val.toNat * 2 ^ 52 + masked3.val =
            mantissa.val := by
          by_cases hsmall : mantissa < unit3a
          · have hsmallVal : mantissa.val < 2 ^ 52 := by
              change mantissa.val < unit3a.val at hsmall
              simpa only [hunit3aVal] using hsmall
            have hpVal : power21.val = 0 := by
              simp only [hsmall, if_true, hminimum] at hpower21Val
              omega
            have hpNat : power21.val.toNat = 0 := by rw [hpVal]; rfl
            rw [hpNat, zero_mul, zero_add, hmasked3Val,
              Nat.mod_eq_of_lt hsmallVal]
          · have hlargeVal : 2 ^ 52 <= mantissa.val := by
              change ¬ mantissa.val < unit3a.val at hsmall
              rw [hunit3aVal] at hsmall
              omega
            have hpVal : power21.val = 1 := by
              simp only [hsmall, if_false, hminimum] at hpower21Val
              omega
            have hpNat : power21.val.toNat = 1 := by rw [hpVal]; rfl
            rw [hpNat, one_mul, hmasked3Val,
              Nat.mod_eq_sub_mod hlargeVal,
              Nat.mod_eq_of_lt (by omega)]
            omega
        have hhalfMin : (2 : Real) ^ (-(1074 : Int)) / 2 =
            (2 : Real) ^ (-(1075 : Int)) := by
          rw [show (-(1074 : Int)) = -(1075 : Int) + 1 by omega,
            zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
          norm_num
        have hlowMagnitude : A <= ((2 ^ 53 : Nat) : Real) *
            (2 : Real) ^ (-(1074 : Int)) := by
          have hd : 0 < (2 : Real) ^ (-(1074 : Int)) :=
            zpow_pos (by norm_num) _
          have hx := hA3Upper53
          rw [hminimum] at hx
          have hm := (div_lt_iff₀ hd).mp hx
          norm_num only [Nat.cast_pow, Nat.cast_ofNat] at hm ⊢
          exact hm.le
        right
        left
        refine ⟨mantissa.val, hmantissaLt.le, hrawMin, hlowMagnitude,
          ?_, ?_, ?_⟩
        · rw [← hhalfMin]
          simpa [hminimum] using hnearestUpper
        · rw [← hhalfMin]
          simpa [hminimum] using hnearestLower
        · simpa [hminimum] using hnearestEven
      · have heLower : -1022 < exp2.val := by omega
        have heUpper : exp2.val <= 1023 := by
          change ¬ 2047 <= biased.val at hsat
          omega
        have hnorm := hnormalizedLower heLower
        have hXLower : ((2 ^ 52 : Nat) : Real) <=
            A / (2 : Real) ^ (exp2.val - 52) := by
          rw [hscale53]
          norm_num at hnorm ⊢
          nlinarith
        have hmantissaGe : 2 ^ 52 <= mantissa.val := by
          by_contra hn
          have hmLe : mantissa.val <= 2 ^ 52 - 1 := by omega
          have hmLeR : (mantissa.val : Real) <=
              ((2 ^ 52 - 1 : Nat) : Real) := by exact_mod_cast hmLe
          have hupper : A / (2 : Real) ^ (exp2.val - 52) <=
              ((2 ^ 52 - 1 : Nat) : Real) + 1 / 2 := by
            calc
              _ <= (mantissa.val : Real) + 1 / 2 := hround3Upper
              _ <= ((2 ^ 52 - 1 : Nat) : Real) + 1 / 2 := by gcongr
          norm_num at hupper hXLower
          linarith
        have hnotSmall : ¬ mantissa < unit3a := by
          change ¬ mantissa.val < unit3a.val
          rw [hunit3aVal]
          omega
        have hpower21Exact : power21.val = exp2.val + 1023 := by
          simpa only [hnotSmall, if_false] using hpower21Val
        let p : Nat := (exp2.val + 1023).toNat
        have hpNonneg : 0 <= exp2.val + 1023 := by omega
        have hpCast : (p : Int) = exp2.val + 1023 := by
          dsimp only [p]
          exact Int.toNat_of_nonneg hpNonneg
        have hpower21Nat : power21.val.toNat = p := by
          apply Nat.cast_injective (R := Int)
          rw [Int.toNat_of_nonneg hpower21Nonneg, hpCast, hpower21Exact]
        have hmaskedSub : masked3.val = mantissa.val - 2 ^ 52 := by
          rw [hmasked3Val, Nat.mod_eq_sub_mod hmantissaGe,
            Nat.mod_eq_of_lt (by omega)]
        have hrawNormal : power21.val.toNat * 2 ^ 52 + masked3.val =
            p * 2 ^ 52 + (mantissa.val - 2 ^ 52) := by
          rw [hpower21Nat, hmaskedSub]
        have hpExp : (p : Int) - 1075 = exp2.val - 52 := by omega
        have hnormalMagnitude : ((2 ^ 52 : Nat) : Real) *
            (2 : Real) ^ ((p : Int) - 1075) <= A := by
          rw [hpExp]
          exact (le_div_iff₀ hdeltaPos).mp hXLower
        have hnormalUpper : A <= ((2 ^ 53 : Nat) : Real) *
            (2 : Real) ^ ((p : Int) - 1075) := by
          rw [hpExp]
          simpa only [Nat.cast_pow, Nat.cast_ofNat] using
            ((div_lt_iff₀ hdeltaPos).mp hA3Upper53).le
        have hthresholdEq :
            (((2 ^ 53 : Nat) : Real) - 1 / 2) *
                (2 : Real) ^ (971 : Nat) =
              (2 : Real) ^ (1024 : Nat) -
                (2 : Real) ^ (970 : Nat) := by
          have hprod : (2 : Real) ^ (53 : Nat) * 2 ^ (971 : Nat) =
              (2 : Real) ^ (1024 : Nat) := by
            rw [← pow_add]
          have hhalf : (1 / 2 : Real) * 2 ^ (971 : Nat) =
              (2 : Real) ^ (970 : Nat) := by
            rw [show (2 : Real) ^ (971 : Nat) =
              2 * (2 : Real) ^ (970 : Nat) by
                rw [show (971 : Nat) = 970 + 1 by omega, pow_succ]
                ring]
            ring
          have hcast53 : (((2 ^ 53 : Nat) : Real)) =
              (2 : Real) ^ (53 : Nat) := by norm_num
          rw [hcast53, sub_mul, hprod, hhalf]
        have hbelowThreshold : A < (2 : Real) ^ (1024 : Nat) -
            (2 : Real) ^ (970 : Nat) := by
          by_cases htopExp : exp2.val = 1023
          · have hXle : A / (2 : Real) ^ (exp2.val - 52) <=
                ((2 ^ 53 : Nat) : Real) - 1 / 2 := by
              have hmLe : mantissa.val <= 2 ^ 53 - 1 := by omega
              have hmLeR : (mantissa.val : Real) <=
                  ((2 ^ 53 - 1 : Nat) : Real) := by exact_mod_cast hmLe
              calc
                _ <= (mantissa.val : Real) + 1 / 2 := hround3Upper
                _ <= ((2 ^ 53 - 1 : Nat) : Real) + 1 / 2 := by gcongr
                _ = ((2 ^ 53 : Nat) : Real) - 1 / 2 := by norm_num
            have hXne : A / (2 : Real) ^ (exp2.val - 52) ≠
                ((2 ^ 53 : Nat) : Real) - 1 / 2 := by
              intro heq
              have hmGeR : (9007199254740991 : Real) <=
                  (mantissa.val : Real) := by
                calc
                  (9007199254740991 : Real) =
                      (((2 ^ 53 : Nat) : Real) - 1 / 2) - 1 / 2 := by
                    rw [show (2 ^ 53 : Nat) = 9007199254740992 by
                      norm_num]
                    norm_num
                  _ = A / (2 : Real) ^ (exp2.val - 52) - 1 / 2 := by
                    rw [heq]
                  _ <= (mantissa.val : Real) :=
                    (sub_le_iff_le_add).2 hround3Upper
              have hmGe : 9007199254740991 <= mantissa.val := by
                exact_mod_cast hmGeR
              have hmEq : mantissa.val = 2 ^ 53 - 1 := by
                norm_num at hmantissaLt ⊢
                omega
              have htie : A / (2 : Real) ^ (exp2.val - 52) =
                  (mantissa.val : Real) + 1 / 2 := by
                rw [hmEq]
                norm_num at heq ⊢
                exact heq
              have heven := hround3Even (Or.inl htie)
              rw [hmEq] at heven
              norm_num at heven
            have hXlt : A / (2 : Real) ^ (exp2.val - 52) <
                ((2 ^ 53 : Nat) : Real) - 1 / 2 :=
              lt_of_le_of_ne hXle hXne
            have hd971 : 0 < (2 : Real) ^ (971 : Int) :=
              zpow_pos (by norm_num) _
            have hm := (div_lt_iff₀ hd971).mp (by
              rw [htopExp] at hXlt
              simpa using hXlt)
            rw [← hthresholdEq]
            simpa using hm
          · have heSmall : exp2.val <= 1022 := by omega
            have hAupper : A < (2 : Real) ^ (exp2.val + 1) :=
              (div_lt_one hpow2pos).mp hA2Upper
            have hp : (2 : Real) ^ (exp2.val + 1) <=
                (2 : Real) ^ (1023 : Int) :=
              zpow_le_zpow_right₀ (by norm_num) (by omega)
            have hsmallPow : (2 : Real) ^ (970 : Nat) <
                (2 : Real) ^ (1023 : Nat) :=
              pow_lt_pow_right₀ (by norm_num) (by omega)
            have hgap : (2 : Real) ^ (1023 : Nat) <
                (2 : Real) ^ (1024 : Nat) -
                  (2 : Real) ^ (970 : Nat) := by
              rw [show (2 : Real) ^ (1024 : Nat) =
                2 * (2 : Real) ^ (1023 : Nat) by
                  rw [show (1024 : Nat) = 1023 + 1 by omega, pow_succ]
                  ring, lt_sub_iff_add_lt]
              calc
                (2 : Real) ^ (1023 : Nat) + 2 ^ (970 : Nat) <
                    (2 : Real) ^ (1023 : Nat) + 2 ^ (1023 : Nat) :=
                  by simpa [add_comm] using
                    add_lt_add_left hsmallPow ((2 : Real) ^ (1023 : Nat))
                _ = 2 * (2 : Real) ^ (1023 : Nat) := by ring
            exact hAupper.trans_le hp |>.trans hgap
        right
        right
        refine ⟨p, mantissa.val, by omega, by omega, hmantissaGe,
          hmantissaLt.le, Or.inr hmantissaLt, hrawNormal,
          hnormalMagnitude, hnormalUpper, hbelowThreshold, ?_, ?_, ?_⟩
        · rw [hpExp]
          exact hnearestUpper
        · rw [hpExp]
          exact hnearestLower
        · rw [hpExp]
          exact hnearestEven

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalSeqRoundArbitraryEndpoint
import Tablet.ParserSlowFirstRoundSeparation
import Tablet.ParserSlowCarryRoundSeparation
import Tablet.ParserExponentConstants
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.ModelU64Shl
import Tablet.P804_T1_DecimalValueBounds
import Tablet.DecimalRightShiftLoop0Execution
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxRecDepth 100000
set_option maxHeartbeats 800000

namespace dec2flt_model

-- [TABLET NODE: ParserSlowFinalEncoding]
theorem ParserSlowFinalEncoding :
    forall (x : DecimalLexeme) (B : Real)
      (tr : num.imp.dec2flt.Dec2FltAssemblyTrace F64)
      (d d0 d1 d2 d3 : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (exp0 exp1 expStart exp2 : Std.I32),
      num.imp.dec2flt.decimal_seq.parse_decimal_seq tr.body = ok d ->
      d.num_digits.val != 0 ->
      -324 <= d.decimal_point.val -> d.decimal_point.val < 310 ->
      num.imp.dec2flt.slow.parse_long_mantissa
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 tr.body =
          ok tr.selected_pair ->
      DecimalGoalVocabularyDefault.assembledWord
        tr.selected_pair tr.assembly_result ->
      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) ->
      num.imp.dec2flt.slow.parse_long_mantissa_loop1
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 2047#i32 }
        d0.num_digits d0.decimal_point d0.truncated d0.digits exp0 none =
          ok (d1.num_digits, d1.decimal_point, d1.truncated, d1.digits,
            exp1, none) ->
      num.imp.dec2flt.slow.parse_long_mantissa_loop2
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
          ok (d2, exp2) ->
      exp1 - 1#i32 = ok expStart -> expStart.val = exp1.val - 1 ->
      d1.decimal_point.val = 0 -> d1.num_digits.val != 0 ->
      5 <= d1.digits.val[0].val ->
      -1079 <= exp1.val ->
      B / (2 : Real) ^ exp1.val <= 1 ->
      exp2.val = max expStart.val (-1022) ->
      (exp2.val - expStart.val).toNat <= 58 ->
      let A := DecimalGoalVocabularyDefault.accumulatedMagnitude x
      let digits2 :=
        (d2.digits.val.take d2.num_digits.val).map (fun z => z.val)
      let integer2 : Nat := digits2.foldl (fun n digit => 10 * n + digit) 0
      let value2 : Real := integer2 * (10 : Real) ^
        (d2.decimal_point.val - (d2.num_digits.val : Int))
      d2.num_digits.val <= 768 /\
      (forall z, z ∈ d2.digits.val.take d2.num_digits.val -> z.val < 10) /\
      (exists z zs, digits2 = z :: zs /\ 1 <= z /\ z < 10 /\
        digits2.length = d2.num_digits.val) /\
      (exists eta2 u2 : Real,
        A / (2 : Real) ^ (exp2.val + 1) = value2 + eta2 /\
        B / (2 : Real) ^ (exp2.val + 1) = value2 + u2 /\
        0 <= eta2 /\ eta2 < u2 /\
        (d2.truncated = true <-> 0 < eta2)) ->
      num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d2 53#usize = ok d3 ->
      let digits3 :=
        (d3.digits.val.take d3.num_digits.val).map (fun z => z.val)
      let integer3 : Nat := digits3.foldl (fun n digit => 10 * n + digit) 0
      let value3 : Real := integer3 * (10 : Real) ^
        (d3.decimal_point.val - (d3.num_digits.val : Int))
      d3.num_digits.val <= 768 /\
      (forall z, z ∈ d3.digits.val.take d3.num_digits.val -> z.val < 10) /\
      (exists z zs, digits3 = z :: zs /\ 1 <= z /\ z < 10 /\
        digits3.length = d3.num_digits.val /\ digits3.getLast? != some 0) /\
      (exists eta3 u3 : Real,
        A / (2 : Real) ^ (exp2.val - 52) = value3 + eta3 /\
        B / (2 : Real) ^ (exp2.val - 52) = value3 + u3 /\
        0 <= eta3 /\ eta3 < u3 /\
        (d3.truncated = true <-> 0 < eta3)) /\
      d3.decimal_point.val < 19 /\
      0 <= A / (2 : Real) ^ (exp2.val - 52) /\
      A / (2 : Real) ^ (exp2.val - 52) <
        (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) /\
      (forall n : Nat,
        (n : Real) + (1 / 2 : Real) <= value3 \/
          B / (2 : Real) ^ (exp2.val - 52) <=
            (n : Real) + (1 / 2 : Real)) ->
      (forall d4 : num.imp.dec2flt.decimal_seq.DecimalSeq,
        num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d3 1#usize = ok d4 ->
        d4.num_digits.val != 0 ->
        let digits4 :=
          (d4.digits.val.take d4.num_digits.val).map (fun z => z.val)
        let integer4 : Nat := digits4.foldl (fun n digit => 10 * n + digit) 0
        let value4 : Real := integer4 * (10 : Real) ^
          (d4.decimal_point.val - (d4.num_digits.val : Int))
        d4.num_digits.val <= 768 /\
        (forall z, z ∈ d4.digits.val.take d4.num_digits.val -> z.val < 10) /\
        (exists z zs, digits4 = z :: zs /\ 1 <= z /\ z < 10 /\
          digits4.length = d4.num_digits.val /\ digits4.getLast? != some 0) /\
        (exists eta4 u4 : Real,
          A / (2 : Real) ^ (exp2.val - 51) = value4 + eta4 /\
          B / (2 : Real) ^ (exp2.val - 51) = value4 + u4 /\
          0 <= eta4 /\ eta4 < u4 /\
          (d4.truncated = true <-> 0 < eta4)) /\
        d4.decimal_point.val < 19 /\
        0 <= A / (2 : Real) ^ (exp2.val - 51) /\
        A / (2 : Real) ^ (exp2.val - 51) <
          (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) /\
        forall n : Nat,
          (n : Real) + (1 / 2 : Real) <= value4 \/
            B / (2 : Real) ^ (exp2.val - 51) <=
              (n : Real) + (1 / 2 : Real)) ->
      let unit : Nat := 2 ^ 52
      let infinityBits : Nat := 2047 * unit
      let threshold : Real := (2 : Real) ^ (1024 : Nat) -
        (2 : Real) ^ (970 : Nat)
      let raw : Nat := Nat.lor tr.selected_pair.m.val
        (((tr.selected_pair.p_biased.val.emod (2 ^ 64)).toNat * unit) %
          (2 ^ 64))
      (raw = infinityBits /\ threshold <= A) \/
      (exists j : Nat,
        j <= 2 ^ 53 /\ raw = j /\
        A <= (2 ^ 53 : Nat) * (2 : Real) ^ (-(1074 : Int)) /\
        A <= (j : Real) * (2 : Real) ^ (-(1074 : Int)) +
          (2 : Real) ^ (-(1075 : Int)) /\
        (j : Real) * (2 : Real) ^ (-(1074 : Int)) <= A +
          (2 : Real) ^ (-(1075 : Int)) /\
        (A = ((j : Real) + (1 / 2 : Real)) *
              (2 : Real) ^ (-(1074 : Int)) \/
            A = ((j : Real) - (1 / 2 : Real)) *
              (2 : Real) ^ (-(1074 : Int)) -> j % 2 = 0)) \/
      (exists p j : Nat,
        2 <= p /\ p <= 2046 /\
        2 ^ 52 <= j /\ j <= 2 ^ 53 /\
        (p < 2046 \/ j < 2 ^ 53) /\
        raw = p * unit + (j - unit) /\
        let delta : Real := (2 : Real) ^ ((p : Int) - 1075)
        (unit : Real) * delta <= A /\
        A <= (2 ^ 53 : Nat) * delta /\
        A < threshold /\
        A <= (j : Real) * delta + delta / 2 /\
        (j : Real) * delta <= A + delta / 2 /\
        (A = ((j : Real) + (1 / 2 : Real)) * delta \/
            A = ((j : Real) - (1 / 2 : Real)) * delta -> j % 2 = 0)) := by
-- BODY
  dsimp only
  intro x B tr d d0 d1 d2 d3 exp0 exp1 expStart exp2
    hparse hdne hdpLower hdpUpper hslow hassembled hloop0 hloop1 hloop2
    hsub hstart hd1Point hd1ne hd1Lead hexp1Lower hBUpper hexp2
    hshiftBound hstate2 hleft53 hstate3 hcarry
  classical
  let A := DecimalGoalVocabularyDefault.accumulatedMagnitude x
  let digits2 :=
    (d2.digits.val.take d2.num_digits.val).map (fun z => z.val)
  let integer2 : Nat := digits2.foldl (fun n digit => 10 * n + digit) 0
  let value2 : Real := integer2 * (10 : Real) ^
    (d2.decimal_point.val - (d2.num_digits.val : Int))
  let digits3 :=
    (d3.digits.val.take d3.num_digits.val).map (fun z => z.val)
  let integer3 : Nat := digits3.foldl (fun n digit => 10 * n + digit) 0
  let value3 : Real := integer3 * (10 : Real) ^
    (d3.decimal_point.val - (d3.num_digits.val : Int))
  rcases hstate2 with
    ⟨hcap2, hdigit2, hshape2, hend2⟩
  rcases hshape2 with ⟨z2, zs2, hshape2, hz2lo, hz2hi, hlen2⟩
  rcases hend2 with ⟨eta2, u2, hA2, hB2, heta2, hetau2, hsticky2⟩
  rcases hstate3 with
    ⟨hcap3, hdigit3, hshape3, hend3, hpoint3, hA3nonneg, hA3bound,
      hsep3⟩
  rcases hshape3 with
    ⟨z3, zs3, hshape3, hz3lo, hz3hi, hlen3, hlast3⟩
  rcases hend3 with ⟨eta3, u3, hA3, hB3, heta3, hetau3, hsticky3⟩
  have hround3 := DecimalSeqRoundArbitraryEndpoint d3
    (A / (2 : Real) ^ (exp2.val - 52))
    (B / (2 : Real) ^ (exp2.val - 52))
    ⟨hcap3, hdigit3,
      Or.inr ⟨z3, zs3, hshape3, hz3lo, hz3hi, hlen3, hlast3⟩,
      ⟨eta3, u3, hA3, hB3, heta3, hetau3, hsticky3⟩⟩
    hpoint3 hA3nonneg hA3bound hsep3
  obtain ⟨mantissa, hround3Call, hround3Upper, hround3Lower,
    hround3Even⟩ := hround3
  have hinteger2 : 0 < integer2 := by
    dsimp only [integer2, digits2]
    rw [hshape2]
    simp only [List.foldl_cons]
    have hrest (ys : List Nat) (a : Nat) :
        a <= ys.foldl (fun n digit => 10 * n + digit) a := by
      induction ys generalizing a with
      | nil => simp
      | cons q qs ih =>
        simp only [List.foldl_cons]
        exact le_trans (by omega) (ih (10 * a + q))
    have := hrest zs2 (10 * 0 + z2)
    omega
  have hvalue2pos : 0 < value2 := by
    exact mul_pos (by exact_mod_cast hinteger2) (zpow_pos (by norm_num) _)
  have hpow2pos : 0 < (2 : Real) ^ (exp2.val + 1) :=
    zpow_pos (by norm_num) _
  have hAB : A < B := by
    apply (div_lt_div_iff_of_pos_right hpow2pos).mp
    rw [hA2, hB2]
    linarith
  have hBpos : 0 < B := by
    have hquot : 0 < B / (2 : Real) ^ (exp2.val + 1) := by
      rw [hB2]
      linarith
    rcases div_pos_iff.mp hquot with h | h
    · exact h.1
    · exact (not_lt_of_ge hpow2pos.le h.2).elim
  have hexpOrder : exp1.val <= exp2.val + 1 := by
    rw [hexp2, hstart]
    omega
  have hpowOrder : (2 : Real) ^ exp1.val <=
      (2 : Real) ^ (exp2.val + 1) :=
    zpow_le_zpow_right₀ (by norm_num) hexpOrder
  have hB2Upper : B / (2 : Real) ^ (exp2.val + 1) <= 1 := by
    exact (div_le_div_of_nonneg_left hBpos.le
      (zpow_pos (by norm_num) _) hpowOrder).trans hBUpper
  have hA2Upper : A / (2 : Real) ^ (exp2.val + 1) < 1 := by
    have hlt : A / (2 : Real) ^ (exp2.val + 1) <
        B / (2 : Real) ^ (exp2.val + 1) :=
      (div_lt_div_iff_of_pos_right hpow2pos).2 hAB
    exact hlt.trans_le hB2Upper
  have hscale53 (C : Real) :
      C / (2 : Real) ^ (exp2.val - 52) =
        (C / (2 : Real) ^ (exp2.val + 1)) * (2 : Real) ^ (53 : Nat) := by
    rw [show exp2.val + 1 = (exp2.val - 52) + 53 by omega]
    rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
    norm_num only [zpow_natCast]
    field_simp
  have hA3Upper53 : A / (2 : Real) ^ (exp2.val - 52) <
      (2 : Real) ^ (53 : Nat) := by
    rw [hscale53]
    have hp53 : 0 < (2 : Real) ^ (53 : Nat) := by positivity
    nlinarith
  have hmantissaLe : mantissa.val <= 2 ^ 53 := by
    have hreal : (mantissa.val : Real) < ((2 ^ 53 : Nat) : Real) + 1 :=
      calc
        (mantissa.val : Real) <=
            A / (2 : Real) ^ (exp2.val - 52) + 1 / 2 := hround3Lower
        _ < ((2 ^ 53 : Nat) : Real) + 1 := by
          norm_num at hA3Upper53 ⊢
          linarith
    have hnat : mantissa.val < (2 ^ 53 : Nat) + 1 := by
      exact_mod_cast hreal
    omega
  have hexp2Lower : -1022 <= exp2.val := by
    rw [hexp2]
    exact le_max_right _ _
  rcases ParserExponentConstants with
    ⟨hbits, htotal, hsig, hexpbits, hexpsat, hinf, hbias, hmin,
      hsmall, hlarge, hroundmin, hroundmax⟩
  have hzero : num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
      ok { m := 0#u64, p_biased := 0#i32 } := by rfl
  have hinfFp : num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
      ok { m := 0#u64, p_biased := 2047#i32 } := by rfl
  have hdword : d.num_digits ≠ 0#usize := by
    intro h
    have := congrArg UScalar.val h
    simp at this
    have hdne' : d.num_digits.val ≠ 0 := by
      simpa [bne_iff_ne] using hdne
    exact hdne' this
  have hdpNotLow : ¬ d.decimal_point < (-324)#i32 := by
    change ¬ d.decimal_point.val < -324
    omega
  have hdpNotHigh : ¬ d.decimal_point >= 310#i32 := by
    change ¬ 310 <= d.decimal_point.val
    omega
  have hnormalizedLower (he : -1022 < exp2.val) :
      (1 / 2 : Real) <= A / (2 : Real) ^ (exp2.val + 1) := by
    have hstartHigh : -1022 <= expStart.val := by
      rw [hexp2] at he
      omega
    have hbody :
        num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
            ok (done (d1, expStart)) := by
      unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
      rw [hmin]
      simp only [bind_tc_ok]
      have hnot : ¬ ((-1022)#i32 : Std.I32) > expStart := by
        change ¬ (-1022 : Int) > expStart.val
        omega
      simp only [hnot, if_false]
    have hloopIdentity :
        num.imp.dec2flt.slow.parse_long_mantissa_loop2
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
            ok (d1, expStart) := by
      unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2
      rw [Aeneas.Std.loop.eq_1]
      simpa only [hbody]
    have hpair := Result.ok.inj (hloopIdentity.symm.trans hloop2)
    have hd2eq : d2 = d1 := (congrArg Prod.fst hpair).symm
    have he2eq : exp2 = expStart := (congrArg Prod.snd hpair).symm
    subst d2
    have hpoint2 : d1.decimal_point.val = 0 := by
      exact hd1Point
    have hnum2pos : 0 < d1.num_digits.val := by
      rw [← hlen2, hshape2]
      simp
    have hindexBound : (0 : Nat) < d1.digits.val.length := by
      rw [d1.digits.property]
      norm_num
    have htake : (d1.digits.val.take d1.num_digits.val)[0]? =
        some d1.digits.val[0] := by
      rw [List.getElem?_take, if_pos hnum2pos]
      exact List.getElem?_eq_getElem hindexBound
    have hhead := congrArg List.head? hshape2
    rw [List.head?_eq_getElem?] at hhead
    simp only [List.getElem?_map, htake] at hhead
    have hz2eq : z2 = d1.digits.val[0].val := by
      exact (Option.some.inj hhead).symm
    have hz2five : 5 <= z2 := by
      rw [hz2eq]
      exact hd1Lead
    have hdigits2 : forall q, q ∈ digits2 -> q < 10 := by
      intro q hq
      simp only [digits2, List.mem_map] at hq
      rcases hq with ⟨q8, hq8, rfl⟩
      exact hdigit2 q8 hq8
    have hv := P804_T1_DecimalValueBounds digits2 z2 zs2 hshape2 hz2lo
      hdigits2 d1.decimal_point.val
    dsimp only at hv
    rw [hlen2] at hv
    have hhalfValue : (1 / 2 : Real) <= value2 := by
      calc
        (1 / 2 : Real) <= (z2 : Real) * (10 : Real) ^ (-1 : Int) := by
          have hzR : (5 : Real) <= (z2 : Real) := by exact_mod_cast hz2five
          rw [zpow_neg]
          norm_num
          linarith
        _ <= value2 := by
          simpa [value2, integer2, hpoint2] using hv.1
    rw [hA2]
    exact hhalfValue.trans (by linarith)
  let infPower :=
    F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.INFINITE_POWER
  have hinf' : infPower = ok 2047#i32 := hinf
  let expMin := F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.EXP_MIN
  have hmin' : expMin = ok (-1022)#i32 := hmin
  have bind_ok_inv : ∀ {α β : Type} (r : Result α) (f : α → Result β) y,
      Bind.bind r f = ok y → ∃ x, r = ok x ∧ f x = ok y := by
    intro α β r f y hr
    cases r with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hr
    | div => simp [Bind.bind, Aeneas.Std.bind] at hr
    | ok q => exact ⟨q, rfl, hr⟩
  have hflow := hslow
  unfold num.imp.dec2flt.slow.parse_long_mantissa at hflow
  rw [hzero] at hflow
  simp only [bind_tc_ok] at hflow
  change (do let i ← infPower; _) = _ at hflow
  rw [hinf'] at hflow
  simp only [bind_tc_ok] at hflow
  rw [hinfFp, hparse] at hflow
  simp only [bind_tc_ok, hdword, if_false, hdpNotLow, hdpNotHigh,
    hloop0] at hflow
  change (do
    let (i3, i4, b1, a1, exp21, loop_result1) ←
      num.imp.dec2flt.slow.parse_long_mantissa_loop1
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 2047#i32 }
        d0.num_digits d0.decimal_point d0.truncated d0.digits exp0 none
    match loop_result1 with
    | none => _
    | some result => ok result) = _ at hflow
  rw [hloop1] at hflow
  simp only [bind_tc_ok] at hflow
  change (do
    let exp22 ← exp1 - 1#i32
    let (q2, exp23) ←
      num.imp.dec2flt.slow.parse_long_mantissa_loop2
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 exp22
    _) = _ at hflow
  rw [hsub] at hflow
  simp only [bind_tc_ok] at hflow
  change (do
    let (q2, exp23) ←
      num.imp.dec2flt.slow.parse_long_mantissa_loop2
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart
    _) = _ at hflow
  rw [hloop2] at hflow
  simp only [bind_tc_ok] at hflow
  change (do let i5 ← expMin; _) = _ at hflow
  rw [hmin'] at hflow
  simp only [bind_tc_ok] at hflow
  obtain ⟨expDiff, hdiff, hflow⟩ := bind_ok_inv _ _ _ hflow
  obtain ⟨biased, hbiased, hflow⟩ := bind_ok_inv _ _ _ hflow
  have hdiffVal : expDiff.val = exp2.val - (-1022) := by
    have hs := IScalar.sub_equiv exp2 (-1022)#i32
    rw [hdiff] at hs
    simpa using hs.2.1
  have hbiasedVal : biased.val = exp2.val + 1023 := by
    have hs := IScalar.add_equiv expDiff 1#i32
    rw [hbiased] at hs
    have hv := hs.2.1
    rw [hdiffVal] at hv
    norm_num at hv
    omega
  by_cases hsat : biased >= 2047#i32
  · simp only [hsat, if_true] at hflow
    have hselected : tr.selected_pair =
        ({ m := 0#u64, p_biased := 2047#i32 } :
          num.imp.dec2flt.common.BiasedFp) :=
      (Result.ok.inj hflow).symm
    rw [hselected]
    left
    constructor
    · norm_num
      rw [Nat.mod_eq_of_lt (by decide)]
      rfl
    · have he : 1024 <= exp2.val := by
        change biased.val >= 2047 at hsat
        omega
      have hnorm := hnormalizedLower (by omega)
      have hmag : (1 / 2 : Real) * (2 : Real) ^ (exp2.val + 1) <= A :=
        (le_div_iff₀ hpow2pos).mp hnorm
      have hpow : (2 : Real) ^ (1025 : Int) <=
          (2 : Real) ^ (exp2.val + 1) :=
        zpow_le_zpow_right₀ (by norm_num) (by omega)
      calc
        (2 : Real) ^ (1024 : Nat) - (2 : Real) ^ (970 : Nat) <=
            (2 : Real) ^ (1024 : Nat) := by
          exact sub_le_self _ (by positivity)
        _ = (1 / 2 : Real) * (2 : Real) ^ (1025 : Int) := by
          rw [show (2 : Real) ^ (1025 : Int) =
            (2 : Real) ^ (1024 : Nat) * 2 by
              rw [show (1025 : Int) = (1024 : Int) + 1 by omega,
                zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
              norm_num
              rfl]
          ring
        _ <= (1 / 2 : Real) * (2 : Real) ^ (exp2.val + 1) := by
          nlinarith
        _ <= A := hmag
  · simp only [hsat, if_false] at hflow
    let sigBits := F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_BITS
    have hsig' : sigBits = ok 52#u32 := hsig
    change (do let i8 ← sigBits; _) = _ at hflow
    rw [hsig'] at hflow
    simp only [bind_tc_ok] at hflow
    obtain ⟨shiftWidth, hcastWidth, hflow⟩ := bind_ok_inv _ _ _ hflow
    obtain ⟨shiftCount, haddCount, hflow⟩ := bind_ok_inv _ _ _ hflow
    have hwidthVal : shiftWidth.val = 52 := by
      simp only [lift] at hcastWidth
      have heq := Result.ok.inj hcastWidth
      have hv := congrArg UScalar.val heq
      simpa [UScalar.cast_val_eq] using hv.symm
    have hcountVal : shiftCount.val = 53 := by
      have hs := UScalar.add_equiv shiftWidth 1#usize
      rw [haddCount] at hs
      have hv := hs.2.1
      rw [hwidthVal] at hv
      norm_num at hv ⊢
      exact hv
    have hcount : shiftCount = 53#usize :=
      UScalar.eq_of_val_eq (by simpa using hcountVal)
    obtain ⟨shifted, hleft, hflow⟩ := bind_ok_inv _ _ _ hflow
    have hshifted : shifted = d3 := by
      rw [hcount] at hleft
      exact Result.ok.inj (hleft.symm.trans hleft53)
    subst shifted
    obtain ⟨rounded, hround, hflow⟩ := bind_ok_inv _ _ _ hflow
    have hrounded : rounded = mantissa :=
      Result.ok.inj (hround.symm.trans hround3Call)
    subst rounded
    obtain ⟨sigCount, haddSig, hflow⟩ := bind_ok_inv _ _ _ hflow
    have hsigCountVal : sigCount.val = 53 := by
      have hs := UScalar.add_equiv (52#u32 : Std.U32) 1#u32
      rw [haddSig] at hs
      simpa using hs.2.1
    have hsigCount : sigCount = 53#u32 :=
      UScalar.eq_of_val_eq (by simpa using hsigCountVal)
    obtain ⟨carryLimit, hshiftLimit, hflow⟩ := bind_ok_inv _ _ _ hflow
    have hcarryLimitVal : carryLimit.val = 2 ^ 53 := by
      have hs := UScalar.ShiftLeft_spec (1#u64) sigCount (2 ^ 64)
        (by rw [hsigCount]; norm_num [U64.numBits])
        (by norm_num [U64.size_eq])
      rw [hshiftLimit] at hs
      have hv := hs.1
      simp only [WP.spec_ok] at hv
      rw [hsigCount, Nat.shiftLeft_eq] at hv
      norm_num at hv ⊢
      exact hv
    have hcarryLimit : carryLimit = 9007199254740992#u64 :=
      UScalar.eq_of_val_eq (by norm_num; exact hcarryLimitVal)
    rw [hcarryLimit] at hflow
    have hdeltaPos : 0 < (2 : Real) ^ (exp2.val - 52) :=
      zpow_pos (by norm_num) _
    have hnearestUpper : A <= (mantissa.val : Real) *
          (2 : Real) ^ (exp2.val - 52) +
        (2 : Real) ^ (exp2.val - 52) / 2 := by
      calc
        A = (A / (2 : Real) ^ (exp2.val - 52)) *
            (2 : Real) ^ (exp2.val - 52) := by field_simp
        _ <= ((mantissa.val : Real) + 1 / 2) *
            (2 : Real) ^ (exp2.val - 52) := by gcongr
        _ = _ := by ring
    have hnearestLower : (mantissa.val : Real) *
          (2 : Real) ^ (exp2.val - 52) <= A +
        (2 : Real) ^ (exp2.val - 52) / 2 := by
      have hq : (mantissa.val : Real) - 1 / 2 <=
          A / (2 : Real) ^ (exp2.val - 52) := by linarith
      calc
        (mantissa.val : Real) * (2 : Real) ^ (exp2.val - 52) =
            ((mantissa.val : Real) - 1 / 2) *
                (2 : Real) ^ (exp2.val - 52) +
              (2 : Real) ^ (exp2.val - 52) / 2 := by ring
        _ <= (A / (2 : Real) ^ (exp2.val - 52)) *
              (2 : Real) ^ (exp2.val - 52) +
            (2 : Real) ^ (exp2.val - 52) / 2 := by gcongr
        _ = _ := by field_simp
    have hnearestEven :
        (A = ((mantissa.val : Real) + 1 / 2) *
              (2 : Real) ^ (exp2.val - 52) ∨
          A = ((mantissa.val : Real) - 1 / 2) *
              (2 : Real) ^ (exp2.val - 52) -> mantissa.val % 2 = 0) := by
      intro htie
      apply hround3Even
      rcases htie with htie | htie
      · left
        apply (div_eq_iff (ne_of_gt hdeltaPos)).2
        simpa [mul_comm] using htie
      · right
        apply (div_eq_iff (ne_of_gt hdeltaPos)).2
        simpa [mul_comm] using htie
    by_cases hfirstCarry : mantissa >= 9007199254740992#u64
    · simp only [hfirstCarry, if_true] at hflow
      have hmantissaCarry : mantissa.val = 2 ^ 53 := by
        change mantissa.val >= 9007199254740992 at hfirstCarry
        norm_num at hfirstCarry ⊢
        omega
      have hnum3ne : d3.num_digits ≠ 0#usize := by
        intro heq
        have hv := congrArg UScalar.val heq
        norm_num at hv
        rw [← hlen3, hshape3] at hv
        simp at hv
      have hpoint3nonneg : 0 <= d3.decimal_point.val := by
        by_contra hn
        have hpword : d3.decimal_point < 0#i32 := by
          change d3.decimal_point.val < 0
          omega
        unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round at hround3Call
        simp only [hnum3ne, if_false, hpword, if_true] at hround3Call
        have hz := congrArg UScalar.val (Result.ok.inj hround3Call.symm)
        rw [hmantissaCarry] at hz
        norm_num at hz
      obtain ⟨read4, acc4, d4good, _hprefix4, _hread4lo, _hread4hi,
          _hacc4lo, _hacc4hi, _hpros4lo, _hpros4hi, hrightGood,
          _hpoint4, hnonzeroGood⟩ :=
        DecimalRightShiftLoop0Execution d3 1#usize (by norm_num)
          hpoint3nonneg (by omega)
          ⟨hcap3, hdigit3, z3, zs3, hshape3, hz3lo, hz3hi,
            by rw [← hshape3]; exact hlen3⟩
      obtain ⟨d4, hright4, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hd4 : d4 = d4good := Result.ok.inj (hright4.symm.trans hrightGood)
      have hnonzero4 : d4.num_digits.val != 0 := by
        rw [hd4]
        exact hnonzeroGood
      have hstate4 := hcarry d4 hright4 hnonzero4
      rcases hstate4 with
        ⟨hcap4, hdigit4, hshape4, hend4, hpoint4, hA4nonneg,
          hA4bound, hsep4⟩
      rcases hshape4 with
        ⟨z4, zs4, hshape4, hz4lo, hz4hi, hlen4, hlast4⟩
      rcases hend4 with
        ⟨eta4, u4, hA4, hB4, heta4, hetau4, hsticky4⟩
      have hround4 := DecimalSeqRoundArbitraryEndpoint d4
        (A / (2 : Real) ^ (exp2.val - 51))
        (B / (2 : Real) ^ (exp2.val - 51))
        ⟨hcap4, hdigit4,
          Or.inr ⟨z4, zs4, hshape4, hz4lo, hz4hi, hlen4, hlast4⟩,
          ⟨eta4, u4, hA4, hB4, heta4, hetau4, hsticky4⟩⟩
        hpoint4 hA4nonneg hA4bound hsep4
      obtain ⟨mantissa4, hround4Call, hround4Upper, hround4Lower,
        hround4Even⟩ := hround4
      obtain ⟨exp24, haddExp24, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hexp24Val : exp24.val = exp2.val + 1 := by
        have hs := IScalar.add_equiv exp2 1#i32
        rw [haddExp24] at hs
        exact hs.2.1
      obtain ⟨rounded4, hround4', hflow⟩ := bind_ok_inv _ _ _ hflow
      have hrounded4 : rounded4 = mantissa4 :=
        Result.ok.inj (hround4'.symm.trans hround4Call)
      subst rounded4
      obtain ⟨expDiff4, hdiff4, hflow⟩ := bind_ok_inv _ _ _ hflow
      obtain ⟨biased4, hbiased4, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hdiff4Val : expDiff4.val = exp24.val - (-1022) := by
        have hs := IScalar.sub_equiv exp24 (-1022)#i32
        rw [hdiff4] at hs
        simpa using hs.2.1
      have hbiased4Val : biased4.val = exp2.val + 1024 := by
        have hs := IScalar.add_equiv expDiff4 1#i32
        rw [hbiased4] at hs
        have hv := hs.2.1
        rw [hdiff4Val, hexp24Val] at hv
        norm_num at hv
        omega
      have hscaleHalf : A / (2 : Real) ^ (exp2.val - 51) =
          (A / (2 : Real) ^ (exp2.val - 52)) / 2 := by
        rw [show exp2.val - 51 = (exp2.val - 52) + 1 by omega,
          zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
        rw [div_eq_mul_inv]
        ring
      have hX4Lower : ((2 ^ 52 : Nat) : Real) - 1 / 4 <=
          A / (2 : Real) ^ (exp2.val - 51) := by
        rw [hscaleHalf]
        have hmreal : (mantissa.val : Real) = (2 ^ 53 : Nat) := by
          exact_mod_cast hmantissaCarry
        rw [hmreal] at hround3Lower
        norm_num at hround3Lower ⊢
        linarith
      have hX4Upper : A / (2 : Real) ^ (exp2.val - 51) <
          ((2 ^ 52 : Nat) : Real) := by
        rw [hscaleHalf]
        norm_num at hA3Upper53 ⊢
        linarith
      have hmantissa4Le : mantissa4.val <= 2 ^ 52 := by
        have hr : (mantissa4.val : Real) < ((2 ^ 52 : Nat) : Real) + 1 :=
          hround4Lower.trans_lt (by linarith)
        have hrn : mantissa4.val < (2 ^ 52 : Nat) + 1 := by
          exact_mod_cast hr
        omega
      have hmantissa4Ge : 2 ^ 52 <= mantissa4.val := by
        by_contra hn
        have hle : mantissa4.val <= 2 ^ 52 - 1 := by omega
        have hleR : (mantissa4.val : Real) <=
            ((2 ^ 52 - 1 : Nat) : Real) := by exact_mod_cast hle
        have hround4Upper' : A / (2 : Real) ^ (exp2.val - 51) <=
            ((2 ^ 52 - 1 : Nat) : Real) + 1 / 2 := by
          calc
            _ <= (mantissa4.val : Real) + 1 / 2 := hround4Upper
            _ <= ((2 ^ 52 - 1 : Nat) : Real) + 1 / 2 := by gcongr
        norm_num at hround4Upper' hX4Lower
        linarith
      have hmantissa4Val : mantissa4.val = 2 ^ 52 := by omega
      by_cases hsecondSat : biased4 >= 2047#i32
      · simp only [hsecondSat, if_true] at hflow
        have he1023 : exp2.val = 1023 := by
          change 2047 <= biased4.val at hsecondSat
          change ¬ 2047 <= biased.val at hsat
          omega
        have hselected : tr.selected_pair =
            ({ m := 0#u64, p_biased := 2047#i32 } :
              num.imp.dec2flt.common.BiasedFp) :=
          (Result.ok.inj hflow).symm
        rw [hselected]
        left
        constructor
        · norm_num
          rw [Nat.mod_eq_of_lt (by decide)]
          rfl
        · have hden : 0 < (2 : Real) ^ (971 : Int) :=
            zpow_pos (by norm_num) _
          have hscaled : ((2 ^ 53 : Nat) : Real) - 1 / 2 <=
              A / (2 : Real) ^ (971 : Int) := by
            have hmreal : (mantissa.val : Real) = (2 ^ 53 : Nat) := by
              exact_mod_cast hmantissaCarry
            rw [hmreal, he1023] at hround3Lower
            norm_num at hround3Lower ⊢
            linarith
          have hthresholdEq :
              (((2 ^ 53 : Nat) : Real) - 1 / 2) *
                  (2 : Real) ^ (971 : Nat) =
                (2 : Real) ^ (1024 : Nat) -
                  (2 : Real) ^ (970 : Nat) := by
            have hprod : (2 : Real) ^ (53 : Nat) * 2 ^ (971 : Nat) =
                (2 : Real) ^ (1024 : Nat) := by
              rw [← pow_add]
            have hhalf : (1 / 2 : Real) * 2 ^ (971 : Nat) =
                (2 : Real) ^ (970 : Nat) := by
              rw [show (2 : Real) ^ (971 : Nat) =
                2 * (2 : Real) ^ (970 : Nat) by
                  rw [show (971 : Nat) = 970 + 1 by omega, pow_succ]
                  ring]
              ring
            have hcast53 : (((2 ^ 53 : Nat) : Real)) =
                (2 : Real) ^ (53 : Nat) := by norm_num
            rw [hcast53]
            rw [sub_mul, hprod, hhalf]
          rw [← hthresholdEq]
          exact (le_div_iff₀ hden).mp (by simpa using hscaled)
      · simp only [hsecondSat, if_false] at hflow
        obtain ⟨expDiff5, hdiff5, hflow⟩ := bind_ok_inv _ _ _ hflow
        obtain ⟨power2, hpower2, hflow⟩ := bind_ok_inv _ _ _ hflow
        have hdiff5Val : expDiff5.val = exp24.val - (-1022) := by
          have hs := IScalar.sub_equiv exp24 (-1022)#i32
          rw [hdiff5] at hs
          simpa using hs.2.1
        have hpower2Val : power2.val = exp2.val + 1024 := by
          have hs := IScalar.add_equiv expDiff5 1#i32
          rw [hpower2] at hs
          have hv := hs.2.1
          rw [hdiff5Val, hexp24Val] at hv
          norm_num at hv
          omega
        obtain ⟨unit4a, hunit4a, hflow⟩ := bind_ok_inv _ _ _ hflow
        have hunit4aVal : unit4a.val = 2 ^ 52 := by
          have hs := UScalar.ShiftLeft_spec (1#u64) (52#u32) (2 ^ 64)
            (by norm_num [U64.numBits]) (by norm_num [U64.size_eq])
          rw [hunit4a] at hs
          have hv := hs.1
          simp only [WP.spec_ok, Nat.shiftLeft_eq] at hv
          norm_num at hv ⊢
          exact hv
        have hnotSmall4 : ¬ mantissa4 < unit4a := by
          change ¬ mantissa4.val < unit4a.val
          omega
        simp only [hnotSmall4, if_false, bind_tc_ok] at hflow
        obtain ⟨unit4b, hunit4b, hflow⟩ := bind_ok_inv _ _ _ hflow
        obtain ⟨mask4, hmask4, hflow⟩ := bind_ok_inv _ _ _ hflow
        obtain ⟨masked4, hmasked4, hflow⟩ := bind_ok_inv _ _ _ hflow
        have hunit4bVal : unit4b.val = 2 ^ 52 := by
          have hs := UScalar.ShiftLeft_spec (1#u64) (52#u32) (2 ^ 64)
            (by norm_num [U64.numBits]) (by norm_num [U64.size_eq])
          rw [hunit4b] at hs
          have hv := hs.1
          simp only [WP.spec_ok, Nat.shiftLeft_eq] at hv
          norm_num at hv ⊢
          exact hv
        have hmask4Val : mask4.val = 2 ^ 52 - 1 := by
          have hs := UScalar.sub_equiv unit4b 1#u64
          rw [hmask4] at hs
          have hv := hs.2.1
          rw [hunit4bVal] at hv
          norm_num at hv ⊢
          omega
        have hmasked4Val : masked4.val = 0 := by
          simp only [lift] at hmasked4
          have heq := Result.ok.inj hmasked4
          have hv := congrArg UScalar.val heq
          rw [UScalar.val_and, hmantissa4Val, hmask4Val,
            Nat.and_two_pow_sub_one_eq_mod] at hv
          simpa using hv.symm
        have hselected : tr.selected_pair =
            ({ m := masked4, p_biased := power2 } :
              num.imp.dec2flt.common.BiasedFp) :=
          (Result.ok.inj hflow).symm
        have hpower2Nonneg : 0 <= power2.val := by omega
        have hpower2Upper : power2.val <= 2046 := by
          change ¬ 2047 <= biased4.val at hsecondSat
          omega
        have hraw : Nat.lor masked4.val
              (((power2.val.emod (2 ^ 64)).toNat * (2 ^ 52)) %
                (2 ^ 64)) =
            (power2.val.toNat * (2 ^ 52)) := by
          have hzeroLor (n : Nat) : Nat.lor 0 n = n := by
            apply Nat.eq_of_testBit_eq
            intro k
            simp [Nat.testBit_lor]
          have hpower2Lt : power2.val < (2 ^ 64 : Int) := by
            norm_num
            omega
          have hem : power2.val.emod (2 ^ 64) = power2.val :=
            Int.emod_eq_of_lt hpower2Nonneg hpower2Lt
          rw [hmasked4Val, hzeroLor, hem]
          have hpNat : power2.val.toNat <= 2046 := by
            rw [Int.toNat_le]
            omega
          apply Nat.mod_eq_of_lt
          calc
            power2.val.toNat * 2 ^ 52 <= 2046 * 2 ^ 52 := by gcongr
            _ < 2 ^ 64 := by norm_num
        rw [hselected]
        simp only [hraw]
        by_cases hminimum : exp2.val = -1022
        · right
          left
          have hpowerNat : power2.val.toNat = 2 := by
            rw [hpower2Val, hminimum]
            rfl
          have hmreal : (mantissa.val : Real) = (2 ^ 53 : Nat) := by
            exact_mod_cast hmantissaCarry
          have hhalfMin : (2 : Real) ^ (-(1074 : Int)) / 2 =
              (2 : Real) ^ (-(1075 : Int)) := by
            rw [show (-(1074 : Int)) = -(1075 : Int) + 1 by omega,
              zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
            norm_num
          have hlowMagnitude : A <= ((2 ^ 53 : Nat) : Real) *
              (2 : Real) ^ (-(1074 : Int)) := by
            have hd : 0 < (2 : Real) ^ (-(1074 : Int)) :=
              zpow_pos (by norm_num) _
            have hx := hA3Upper53
            rw [hminimum] at hx
            have hm := (div_lt_iff₀ hd).mp hx
            norm_num only [Nat.cast_pow, Nat.cast_ofNat] at hm ⊢
            exact hm.le
          refine ⟨2 ^ 53, le_rfl, ?_, hlowMagnitude, ?_, ?_, ?_⟩
          · rw [hpowerNat]
            norm_num [pow_succ]
          · rw [← hhalfMin]
            simpa [hminimum, hmreal] using hnearestUpper
          · rw [← hhalfMin]
            simpa [hminimum, hmreal] using hnearestLower
          · simpa [hminimum, hmreal] using hnearestEven
        · right
          right
          let p : Nat := (exp2.val + 1023).toNat
          have heLower : -1022 < exp2.val := by omega
          have heUpper : exp2.val <= 1022 := by
            change ¬ 2047 <= biased4.val at hsecondSat
            omega
          have hpNonneg : 0 <= exp2.val + 1023 := by omega
          have hpCast : (p : Int) = exp2.val + 1023 := by
            dsimp only [p]
            exact Int.toNat_of_nonneg hpNonneg
          have hpowerNat : power2.val.toNat = p + 1 := by
            have hpowerNatCast : (power2.val.toNat : Int) = power2.val :=
              Int.toNat_of_nonneg hpower2Nonneg
            have heq : (power2.val.toNat : Int) = (p + 1 : Nat) := by
              push_cast
              rw [hpowerNatCast, hpCast, hpower2Val]
              omega
            exact_mod_cast heq
          have hmreal : (mantissa.val : Real) = (2 ^ 53 : Nat) := by
            exact_mod_cast hmantissaCarry
          have hpExp : (p : Int) - 1075 = exp2.val - 52 := by omega
          have hnormalMagnitude : ((2 ^ 52 : Nat) : Real) *
              (2 : Real) ^ ((p : Int) - 1075) <= A := by
            have hnorm := hnormalizedLower heLower
            have hx : ((2 ^ 52 : Nat) : Real) <=
                A / (2 : Real) ^ (exp2.val - 52) := by
              rw [hscale53]
              norm_num at hnorm ⊢
              nlinarith
            rw [hpExp]
            exact (le_div_iff₀ hdeltaPos).mp hx
          have hnormalUpper : A <= ((2 ^ 53 : Nat) : Real) *
              (2 : Real) ^ ((p : Int) - 1075) := by
            rw [hpExp]
            simpa only [Nat.cast_pow, Nat.cast_ofNat] using
              ((div_lt_iff₀ hdeltaPos).mp hA3Upper53).le
          have hbelowThreshold : A < (2 : Real) ^ (1024 : Nat) -
              (2 : Real) ^ (970 : Nat) := by
            have hAupper : A < (2 : Real) ^ (exp2.val + 1) :=
              (div_lt_one hpow2pos).mp hA2Upper
            have hp : (2 : Real) ^ (exp2.val + 1) <=
                (2 : Real) ^ (1023 : Int) :=
              zpow_le_zpow_right₀ (by norm_num) (by omega)
            have hgap : (2 : Real) ^ (1023 : Nat) <
                (2 : Real) ^ (1024 : Nat) -
                  (2 : Real) ^ (970 : Nat) := by
              have hsmallPow : (2 : Real) ^ (970 : Nat) <
                  (2 : Real) ^ (1023 : Nat) :=
                pow_lt_pow_right₀ (by norm_num) (by omega)
              rw [show (2 : Real) ^ (1024 : Nat) =
                2 * (2 : Real) ^ (1023 : Nat) by
                  rw [show (1024 : Nat) = 1023 + 1 by omega, pow_succ]
                  ring]
              rw [lt_sub_iff_add_lt]
              calc
                (2 : Real) ^ (1023 : Nat) + 2 ^ (970 : Nat) <
                    (2 : Real) ^ (1023 : Nat) + 2 ^ (1023 : Nat) :=
                  by simpa [add_comm] using
                    add_lt_add_left hsmallPow ((2 : Real) ^ (1023 : Nat))
                _ = 2 * (2 : Real) ^ (1023 : Nat) := by ring
            exact hAupper.trans_le hp |>.trans hgap
          refine ⟨p, 2 ^ 53, by omega, by omega, by omega, le_rfl,
            Or.inl (by omega), ?_, hnormalMagnitude, hnormalUpper,
            hbelowThreshold, ?_, ?_, ?_⟩
          · rw [hpowerNat]
            norm_num [pow_succ]
            omega
          · rw [hpExp]
            simpa [hmreal] using hnearestUpper
          · rw [hpExp]
            simpa [hmreal] using hnearestLower
          · rw [hpExp]
            simpa [hmreal] using hnearestEven
    · simp only [hfirstCarry, if_false] at hflow
      have hmantissaLt : mantissa.val < 2 ^ 53 := by
        change ¬ mantissa.val >= 9007199254740992 at hfirstCarry
        norm_num at hfirstCarry ⊢
        omega
      obtain ⟨expDiff5, hdiff5, hflow⟩ := bind_ok_inv _ _ _ hflow
      obtain ⟨power2, hpower2, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hdiff5Val : expDiff5.val = exp2.val - (-1022) := by
        have hs := IScalar.sub_equiv exp2 (-1022)#i32
        rw [hdiff5] at hs
        simpa using hs.2.1
      have hpower2Val : power2.val = exp2.val + 1023 := by
        have hs := IScalar.add_equiv expDiff5 1#i32
        rw [hpower2] at hs
        have hv := hs.2.1
        rw [hdiff5Val] at hv
        norm_num at hv
        omega
      obtain ⟨unit3a, hunit3a, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hunit3aVal : unit3a.val = 2 ^ 52 := by
        have hs := UScalar.ShiftLeft_spec (1#u64) (52#u32) (2 ^ 64)
          (by norm_num [U64.numBits]) (by norm_num [U64.size_eq])
        rw [hunit3a] at hs
        have hv := hs.1
        simp only [WP.spec_ok, Nat.shiftLeft_eq] at hv
        norm_num at hv ⊢
        exact hv
      obtain ⟨power21, hpower21, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hpower21Val : power21.val =
          if mantissa < unit3a then exp2.val + 1022
          else exp2.val + 1023 := by
        by_cases hsmall : mantissa < unit3a
        · simp only [hsmall, if_true] at hpower21 ⊢
          have hs := IScalar.sub_equiv power2 1#i32
          rw [hpower21] at hs
          have hv := hs.2.1
          calc
            power21.val = power2.val - 1 := hv
            _ = exp2.val + 1022 := by rw [hpower2Val]; omega
        · simp only [hsmall, if_false] at hpower21 ⊢
          have heq := Result.ok.inj hpower21
          have hv := congrArg IScalar.val heq
          calc
            power21.val = power2.val := hv.symm
            _ = exp2.val + 1023 := hpower2Val
      obtain ⟨unit3b, hunit3b, hflow⟩ := bind_ok_inv _ _ _ hflow
      obtain ⟨mask3, hmask3, hflow⟩ := bind_ok_inv _ _ _ hflow
      obtain ⟨masked3, hmasked3, hflow⟩ := bind_ok_inv _ _ _ hflow
      have hunit3bVal : unit3b.val = 2 ^ 52 := by
        have hs := UScalar.ShiftLeft_spec (1#u64) (52#u32) (2 ^ 64)
          (by norm_num [U64.numBits]) (by norm_num [U64.size_eq])
        rw [hunit3b] at hs
        have hv := hs.1
        simp only [WP.spec_ok, Nat.shiftLeft_eq] at hv
        norm_num at hv ⊢
        exact hv
      have hmask3Val : mask3.val = 2 ^ 52 - 1 := by
        have hs := UScalar.sub_equiv unit3b 1#u64
        rw [hmask3] at hs
        have hv := hs.2.1
        rw [hunit3bVal] at hv
        norm_num at hv ⊢
        omega
      have hmasked3Val : masked3.val = mantissa.val % 2 ^ 52 := by
        simp only [lift] at hmasked3
        have heq := Result.ok.inj hmasked3
        have hv := congrArg UScalar.val heq
        rw [UScalar.val_and, hmask3Val,
          Nat.and_two_pow_sub_one_eq_mod] at hv
        exact hv.symm
      have hselected : tr.selected_pair =
          ({ m := masked3, p_biased := power21 } :
            num.imp.dec2flt.common.BiasedFp) :=
        (Result.ok.inj hflow).symm
      have hpower21Nonneg : 0 <= power21.val := by
        split at hpower21Val <;> omega
      have hpower21Upper : power21.val <= 2046 := by
        change ¬ 2047 <= biased.val at hsat
        split at hpower21Val <;> omega
      have hraw : Nat.lor masked3.val
            (((power21.val.emod (2 ^ 64)).toNat * (2 ^ 52)) %
              (2 ^ 64)) =
          power21.val.toNat * 2 ^ 52 + masked3.val := by
        have hpLt : power21.val < (2 ^ 64 : Int) := by
          norm_num
          omega
        have hem : power21.val.emod (2 ^ 64) = power21.val :=
          Int.emod_eq_of_lt hpower21Nonneg hpLt
        rw [hem, Nat.mod_eq_of_lt]
        · have hmaskedLt : masked3.val < 2 ^ 52 := by
            rw [hmasked3Val]
            exact Nat.mod_lt _ (by positivity)
          calc
            Nat.lor masked3.val (power21.val.toNat * 2 ^ 52) =
                Nat.lor (2 ^ 52 * power21.val.toNat) masked3.val := by
              rw [Nat.mul_comm]
              exact Nat.lor_comm _ _
            _ = 2 ^ 52 * power21.val.toNat + masked3.val :=
              (Nat.two_pow_add_eq_or_of_lt hmaskedLt _).symm
            _ = power21.val.toNat * 2 ^ 52 + masked3.val := by omega
        · have hpNat : power21.val.toNat <= 2046 := by
            rw [Int.toNat_le]
            omega
          calc
            power21.val.toNat * 2 ^ 52 <= 2046 * 2 ^ 52 := by gcongr
            _ < 2 ^ 64 := by norm_num
      rw [hselected]
      simp only [hraw]
      by_cases hminimum : exp2.val = -1022
      · have hrawMin : power21.val.toNat * 2 ^ 52 + masked3.val =
            mantissa.val := by
          by_cases hsmall : mantissa < unit3a
          · have hsmallVal : mantissa.val < 2 ^ 52 := by
              change mantissa.val < unit3a.val at hsmall
              simpa only [hunit3aVal] using hsmall
            have hpVal : power21.val = 0 := by
              simp only [hsmall, if_true, hminimum] at hpower21Val
              omega
            have hpNat : power21.val.toNat = 0 := by rw [hpVal]; rfl
            rw [hpNat, zero_mul, zero_add, hmasked3Val,
              Nat.mod_eq_of_lt hsmallVal]
          · have hlargeVal : 2 ^ 52 <= mantissa.val := by
              change ¬ mantissa.val < unit3a.val at hsmall
              rw [hunit3aVal] at hsmall
              omega
            have hpVal : power21.val = 1 := by
              simp only [hsmall, if_false, hminimum] at hpower21Val
              omega
            have hpNat : power21.val.toNat = 1 := by rw [hpVal]; rfl
            rw [hpNat, one_mul, hmasked3Val,
              Nat.mod_eq_sub_mod hlargeVal,
              Nat.mod_eq_of_lt (by omega)]
            omega
        have hhalfMin : (2 : Real) ^ (-(1074 : Int)) / 2 =
            (2 : Real) ^ (-(1075 : Int)) := by
          rw [show (-(1074 : Int)) = -(1075 : Int) + 1 by omega,
            zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
          norm_num
        have hlowMagnitude : A <= ((2 ^ 53 : Nat) : Real) *
            (2 : Real) ^ (-(1074 : Int)) := by
          have hd : 0 < (2 : Real) ^ (-(1074 : Int)) :=
            zpow_pos (by norm_num) _
          have hx := hA3Upper53
          rw [hminimum] at hx
          have hm := (div_lt_iff₀ hd).mp hx
          norm_num only [Nat.cast_pow, Nat.cast_ofNat] at hm ⊢
          exact hm.le
        right
        left
        refine ⟨mantissa.val, hmantissaLt.le, hrawMin, hlowMagnitude,
          ?_, ?_, ?_⟩
        · rw [← hhalfMin]
          simpa [hminimum] using hnearestUpper
        · rw [← hhalfMin]
          simpa [hminimum] using hnearestLower
        · simpa [hminimum] using hnearestEven
      · have heLower : -1022 < exp2.val := by omega
        have heUpper : exp2.val <= 1023 := by
          change ¬ 2047 <= biased.val at hsat
          omega
        have hnorm := hnormalizedLower heLower
        have hXLower : ((2 ^ 52 : Nat) : Real) <=
            A / (2 : Real) ^ (exp2.val - 52) := by
          rw [hscale53]
          norm_num at hnorm ⊢
          nlinarith
        have hmantissaGe : 2 ^ 52 <= mantissa.val := by
          by_contra hn
          have hmLe : mantissa.val <= 2 ^ 52 - 1 := by omega
          have hmLeR : (mantissa.val : Real) <=
              ((2 ^ 52 - 1 : Nat) : Real) := by exact_mod_cast hmLe
          have hupper : A / (2 : Real) ^ (exp2.val - 52) <=
              ((2 ^ 52 - 1 : Nat) : Real) + 1 / 2 := by
            calc
              _ <= (mantissa.val : Real) + 1 / 2 := hround3Upper
              _ <= ((2 ^ 52 - 1 : Nat) : Real) + 1 / 2 := by gcongr
          norm_num at hupper hXLower
          linarith
        have hnotSmall : ¬ mantissa < unit3a := by
          change ¬ mantissa.val < unit3a.val
          rw [hunit3aVal]
          omega
        have hpower21Exact : power21.val = exp2.val + 1023 := by
          simpa only [hnotSmall, if_false] using hpower21Val
        let p : Nat := (exp2.val + 1023).toNat
        have hpNonneg : 0 <= exp2.val + 1023 := by omega
        have hpCast : (p : Int) = exp2.val + 1023 := by
          dsimp only [p]
          exact Int.toNat_of_nonneg hpNonneg
        have hpower21Nat : power21.val.toNat = p := by
          apply Nat.cast_injective (R := Int)
          rw [Int.toNat_of_nonneg hpower21Nonneg, hpCast, hpower21Exact]
        have hmaskedSub : masked3.val = mantissa.val - 2 ^ 52 := by
          rw [hmasked3Val, Nat.mod_eq_sub_mod hmantissaGe,
            Nat.mod_eq_of_lt (by omega)]
        have hrawNormal : power21.val.toNat * 2 ^ 52 + masked3.val =
            p * 2 ^ 52 + (mantissa.val - 2 ^ 52) := by
          rw [hpower21Nat, hmaskedSub]
        have hpExp : (p : Int) - 1075 = exp2.val - 52 := by omega
        have hnormalMagnitude : ((2 ^ 52 : Nat) : Real) *
            (2 : Real) ^ ((p : Int) - 1075) <= A := by
          rw [hpExp]
          exact (le_div_iff₀ hdeltaPos).mp hXLower
        have hnormalUpper : A <= ((2 ^ 53 : Nat) : Real) *
            (2 : Real) ^ ((p : Int) - 1075) := by
          rw [hpExp]
          simpa only [Nat.cast_pow, Nat.cast_ofNat] using
            ((div_lt_iff₀ hdeltaPos).mp hA3Upper53).le
        have hthresholdEq :
            (((2 ^ 53 : Nat) : Real) - 1 / 2) *
                (2 : Real) ^ (971 : Nat) =
              (2 : Real) ^ (1024 : Nat) -
                (2 : Real) ^ (970 : Nat) := by
          have hprod : (2 : Real) ^ (53 : Nat) * 2 ^ (971 : Nat) =
              (2 : Real) ^ (1024 : Nat) := by
            rw [← pow_add]
          have hhalf : (1 / 2 : Real) * 2 ^ (971 : Nat) =
              (2 : Real) ^ (970 : Nat) := by
            rw [show (2 : Real) ^ (971 : Nat) =
              2 * (2 : Real) ^ (970 : Nat) by
                rw [show (971 : Nat) = 970 + 1 by omega, pow_succ]
                ring]
            ring
          have hcast53 : (((2 ^ 53 : Nat) : Real)) =
              (2 : Real) ^ (53 : Nat) := by norm_num
          rw [hcast53, sub_mul, hprod, hhalf]
        have hbelowThreshold : A < (2 : Real) ^ (1024 : Nat) -
            (2 : Real) ^ (970 : Nat) := by
          by_cases htopExp : exp2.val = 1023
          · have hXle : A / (2 : Real) ^ (exp2.val - 52) <=
                ((2 ^ 53 : Nat) : Real) - 1 / 2 := by
              have hmLe : mantissa.val <= 2 ^ 53 - 1 := by omega
              have hmLeR : (mantissa.val : Real) <=
                  ((2 ^ 53 - 1 : Nat) : Real) := by exact_mod_cast hmLe
              calc
                _ <= (mantissa.val : Real) + 1 / 2 := hround3Upper
                _ <= ((2 ^ 53 - 1 : Nat) : Real) + 1 / 2 := by gcongr
                _ = ((2 ^ 53 : Nat) : Real) - 1 / 2 := by norm_num
            have hXne : A / (2 : Real) ^ (exp2.val - 52) ≠
                ((2 ^ 53 : Nat) : Real) - 1 / 2 := by
              intro heq
              have hmGeR : (9007199254740991 : Real) <=
                  (mantissa.val : Real) := by
                calc
                  (9007199254740991 : Real) =
                      (((2 ^ 53 : Nat) : Real) - 1 / 2) - 1 / 2 := by
                    rw [show (2 ^ 53 : Nat) = 9007199254740992 by
                      norm_num]
                    norm_num
                  _ = A / (2 : Real) ^ (exp2.val - 52) - 1 / 2 := by
                    rw [heq]
                  _ <= (mantissa.val : Real) :=
                    (sub_le_iff_le_add).2 hround3Upper
              have hmGe : 9007199254740991 <= mantissa.val := by
                exact_mod_cast hmGeR
              have hmEq : mantissa.val = 2 ^ 53 - 1 := by
                norm_num at hmantissaLt ⊢
                omega
              have htie : A / (2 : Real) ^ (exp2.val - 52) =
                  (mantissa.val : Real) + 1 / 2 := by
                rw [hmEq]
                norm_num at heq ⊢
                exact heq
              have heven := hround3Even (Or.inl htie)
              rw [hmEq] at heven
              norm_num at heven
            have hXlt : A / (2 : Real) ^ (exp2.val - 52) <
                ((2 ^ 53 : Nat) : Real) - 1 / 2 :=
              lt_of_le_of_ne hXle hXne
            have hd971 : 0 < (2 : Real) ^ (971 : Int) :=
              zpow_pos (by norm_num) _
            have hm := (div_lt_iff₀ hd971).mp (by
              rw [htopExp] at hXlt
              simpa using hXlt)
            rw [← hthresholdEq]
            simpa using hm
          · have heSmall : exp2.val <= 1022 := by omega
            have hAupper : A < (2 : Real) ^ (exp2.val + 1) :=
              (div_lt_one hpow2pos).mp hA2Upper
            have hp : (2 : Real) ^ (exp2.val + 1) <=
                (2 : Real) ^ (1023 : Int) :=
              zpow_le_zpow_right₀ (by norm_num) (by omega)
            have hsmallPow : (2 : Real) ^ (970 : Nat) <
                (2 : Real) ^ (1023 : Nat) :=
              pow_lt_pow_right₀ (by norm_num) (by omega)
            have hgap : (2 : Real) ^ (1023 : Nat) <
                (2 : Real) ^ (1024 : Nat) -
                  (2 : Real) ^ (970 : Nat) := by
              rw [show (2 : Real) ^ (1024 : Nat) =
                2 * (2 : Real) ^ (1023 : Nat) by
                  rw [show (1024 : Nat) = 1023 + 1 by omega, pow_succ]
                  ring, lt_sub_iff_add_lt]
              calc
                (2 : Real) ^ (1023 : Nat) + 2 ^ (970 : Nat) <
                    (2 : Real) ^ (1023 : Nat) + 2 ^ (1023 : Nat) :=
                  by simpa [add_comm] using
                    add_lt_add_left hsmallPow ((2 : Real) ^ (1023 : Nat))
                _ = 2 * (2 : Real) ^ (1023 : Nat) := by ring
            exact hAupper.trans_le hp |>.trans hgap
        right
        right
        refine ⟨p, mantissa.val, by omega, by omega, hmantissaGe,
          hmantissaLt.le, Or.inr hmantissaLt, hrawNormal,
          hnormalMagnitude, hnormalUpper, hbelowThreshold, ?_, ?_, ?_⟩
        · rw [hpExp]
          exact hnearestUpper
        · rw [hpExp]
          exact hnearestLower
        · rw [hpExp]
          exact hnearestEven

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (201)
More program dependencies (159)
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 122 entries
Technical checking records
Local closure summary
{
  "node": "ParserSlowFinalEncoding",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "d8df24cdae033d63adc73abf1cf88adae4387aa9ef9469ef8cf75d3b069edf2d",
  "active_statement_hash": "065f2b4acbbc8ace80780fc7a3e2701281c9ea260127b07dd2e7186696614c99",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-204",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalRightShiftLoop0Execution": "e27252660de78d95",
    "DecimalSeqRoundArbitraryEndpoint": "f8438d40995fe509",
    "P804_T1_DecimalValueBounds": "4b5c924b5d52bc9d",
    "ParserExponentConstants": "e2a30a7b0c5e9c91",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_round": "0eb6fb2627d0ff5c",
    "num_imp_dec2flt_slow_parse_long_mantissa": "d2b4145772dccc04",
    "num_imp_traits_Float_EXP_BIAS_default": "39417be39e20ce5d",
    "num_imp_traits_Float_EXP_BITS_default": "9ab622d85ef04d94",
    "num_imp_traits_Float_EXP_MIN_default": "39417be39e20ce5d",
    "num_imp_traits_Float_EXP_SAT_default": "9ab622d85ef04d94",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "d8d2f621d2f6aa27",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "DecimalLexeme": "c43614ff2149ecf2",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS": "d9fd91641cb78c5e",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "598dfa7d7b371110",
    "num_imp_dec2flt_common_BiasedFp": "5c88d5d7976c5e8f",
    "num_imp_dec2flt_common_BiasedFp_zero_pow2": "0f99ae12c6707137",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS_WITHOUT_OVERFLOW": "65634ac95536dcca",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "fd298e37d5ae4f86",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "4db7c37f5da1c6e0",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_round": "8ea3c058fea09978",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "244cf8318357caab",
    "num_imp_dec2flt_slow_parse_long_mantissa": "b1ccfebea6d0fad3",
    "num_imp_dec2flt_slow_parse_long_mantissa_MAX_SHIFT": "32f403f33bee78a7",
    "num_imp_traits_Float": "996e90a556298539"
  }
}
Prose assessment
{
  "label": "Sound flag superseded by recorded Lean closure",
  "assessment_status": "VerifierFail",
  "fingerprint_relation": "differs from current fingerprint",
  "assessment_fingerprint": "sound-v2:19eb9c3e2a501246bc34e87afe5d48d244a611e3cab295841bf56548971599ca",
  "current_fingerprint": "sound-v2:3caf741877ce532fcb54935b91c5504341599af18ae25862acf08a6fd2984687",
  "superseded_for_theorem_closure": true
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Fail",
  "substantiveness_status": "Pass"
}