Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Final slow-path rounding and binary64 encoding
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
- Infinity: r=T and H\leq A.
- 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}
- 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
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.
Uses
Inspect related source (201)
- parse_long_mantissa · dec2flt/slow.rs:27 Program Rust
- parse_long_mantissa_loop0 · dec2flt/slow.rs:51 Program Rust
- body · dec2flt/slow.rs:51 Program Rust
More program dependencies (159)
- parse_long_mantissa_loop1 · dec2flt/slow.rs:69 Program Rust
- body · dec2flt/slow.rs:69 Program Rust
- parse_long_mantissa_loop2 · dec2flt/slow.rs:94 Program Rust
- body · dec2flt/slow.rs:94 Program Rust
- Dec2flt_modelNumImpTraitsFloatU64 · traits.rs:309 Program Rust
- BITS · traits.rs:319 Program Rust
- LARGEST_POWER_OF_TEN · traits.rs:327 Program Rust
- MAX_EXPONENT_ROUND_TO_EVEN · traits.rs:325 Program Rust
- MIN_EXPONENT_ROUND_TO_EVEN · traits.rs:324 Program Rust
- SIG_TOTAL_BITS · traits.rs:320 Program Rust
- SMALLEST_POWER_OF_TEN · traits.rs:328 Program Rust
- BiasedFp · dec2flt/common.rs:52 Program Rust
- zero_pow2 · dec2flt/common.rs:62 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:21 Program Rust
- DECIMAL_POINT_RANGE · dec2flt/decimal_seq.rs:67 Program Rust
- left_shift · dec2flt/decimal_seq.rs:129 Program Rust
- left_shift_loop0 · dec2flt/decimal_seq.rs:138 Program Rust
- body · dec2flt/decimal_seq.rs:138 Program Rust
- left_shift_loop1 · dec2flt/decimal_seq.rs:152 Program Rust
- body · dec2flt/decimal_seq.rs:152 Program Rust
- right_shift · dec2flt/decimal_seq.rs:175 Program Rust
- right_shift_loop0 · dec2flt/decimal_seq.rs:180 Program Rust
- body · dec2flt/decimal_seq.rs:180 Program Rust
- right_shift_loop0_loop0 · dec2flt/decimal_seq.rs:190 Program Rust
- body · dec2flt/decimal_seq.rs:190 Program Rust
- right_shift_loop1 · dec2flt/decimal_seq.rs:209 Program Rust
- body · dec2flt/decimal_seq.rs:209 Program Rust
- right_shift_loop2 · dec2flt/decimal_seq.rs:216 Program Rust
- body · dec2flt/decimal_seq.rs:216 Program Rust
- round · dec2flt/decimal_seq.rs:96 Program Rust
- round_loop · dec2flt/decimal_seq.rs:106 Program Rust
- body · dec2flt/decimal_seq.rs:106 Program Rust
- parse_decimal_seq · dec2flt/decimal_seq.rs:283 Program Rust
- parse_decimal_seq_loop0 · dec2flt/decimal_seq.rs:290 Program Rust
- body · dec2flt/decimal_seq.rs:290 Program Rust
- parse_decimal_seq_loop1 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop2 · dec2flt/decimal_seq.rs:303 Program Rust
- body · dec2flt/decimal_seq.rs:303 Program Rust
- parse_decimal_seq_loop3 · dec2flt/decimal_seq.rs:307 Program Rust
- body · dec2flt/decimal_seq.rs:307 Program Rust
- parse_decimal_seq_loop4 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop5 · dec2flt/decimal_seq.rs:307 Program Rust
- body · dec2flt/decimal_seq.rs:307 Program Rust
- parse_decimal_seq_loop6 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop7 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- MAX_SHIFT · dec2flt/slow.rs:28 Program Rust
- call · dec2flt/slow.rs:33 Program Rust
- Float · traits.rs:74 Program Rust
- default · traits.rs:116 Program Rust
- default · traits.rs:104 Program Rust
- default · traits.rs:119 Program Rust
- default · traits.rs:110 Program Rust
- default · traits.rs:113 Program Rust
- default · traits.rs:101 Program Rust
- from_u64 · dec2flt/mod.rs:263 Program Rust
- EXP_MASK · traits.rs:321 Program Rust
- INFINITY · traits.rs:312 Program Rust
- NAN · traits.rs:314 Program Rust
- NEG_INFINITY · traits.rs:313 Program Rust
- NEG_NAN · traits.rs:317 Program Rust
- SIG_MASK · traits.rs:322 Program Rust
- classify · traits.rs:334 Program Rust
- to_bits · traits.rs:330 Program Rust
- read_u64 · dec2flt/common.rs:18 Program Rust
- write_u64 · dec2flt/common.rs:25 Program Rust
- Dec2flt_modelNumImpTraitsInt · traits.rs:51 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:329 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:295 Program Rust
- Lemire · dec2flt/mod.rs:115 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- is_8digits · dec2flt/common.rs:40 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- default · dec2flt/decimal_seq.rs:33 Program Rust
- MAX_DIGITS · dec2flt/decimal_seq.rs:63 Program Rust
- MAX_DIGITS_WITHOUT_OVERFLOW · dec2flt/decimal_seq.rs:66 Program Rust
- trim · dec2flt/decimal_seq.rs:82 Program Rust
- trim_loop · dec2flt/decimal_seq.rs:91 Program Rust
- body · dec2flt/decimal_seq.rs:91 Program Rust
- try_add_digit · dec2flt/decimal_seq.rs:73 Program Rust
- count_trailing_zeros · dec2flt/decimal_seq.rs:235 Program Rust
- count_trailing_zeros_loop · dec2flt/decimal_seq.rs:239 Program Rust
- body · dec2flt/decimal_seq.rs:239 Program Rust
- number_of_digits_decimal_left_shift · dec2flt/decimal_seq.rs:368 Program Rust
- number_of_digits_decimal_left_shift_loop · dec2flt/decimal_seq.rs:434 Program Rust
- body · dec2flt/decimal_seq.rs:434 Program Rust
- parse_decimal_exponent · dec2flt/decimal_seq.rs:269 Program Rust
- parse_decimal_exponent_loop · dec2flt/decimal_seq.rs:272 Program Rust
- body · dec2flt/decimal_seq.rs:272 Program Rust
- parse_digits_into_seq · dec2flt/decimal_seq.rs:256 Program Rust
- parse_digits_into_seq_loop · dec2flt/decimal_seq.rs:258 Program Rust
- body · dec2flt/decimal_seq.rs:258 Program Rust
- NUM_POWERS · dec2flt/slow.rs:29 Program Rust
- POWERS · dec2flt/slow.rs:30 Program Rust
- closure · dec2flt/slow.rs:33 Program Rust
- CastInto · traits.rs:18 Program Rust
- FloatExt · traits.rs:170 Program Rust
- Int · traits.rs:27 Program Rust
- Dec2flt_modelNumImpTraitsCastIntoI16 · traits.rs:45 Program Rust
- ONE · traits.rs:53 Program Rust
- ZERO · traits.rs:52 Program Rust
- TABLE · dec2flt/decimal_seq.rs:370 Program Rust
- TABLE_POW5 · dec2flt/decimal_seq.rs:379 Program Rust
- cast · traits.rs:46 Program Rust
- biased_fp_to_float · dec2flt/mod.rs:282 Program Rust
- dec2flt_with_trace · dec2flt/mod.rs:355 Program Rust
- compute_float · dec2flt/lemire.rs:26 Program Rust
- MIN_19DIGIT_INT · dec2flt/parse.rs:8 Program Rust
- adjust_many_digit_count · dec2flt/parse.rs:86 Program Rust
- adjust_many_digit_count_loop · dec2flt/parse.rs:89 Program Rust
- body · dec2flt/parse.rs:89 Program Rust
- parse_many_digits · dec2flt/parse.rs:104 Program Rust
- parse_number · dec2flt/parse.rs:231 Program Rust
- parse_partial_number · dec2flt/parse.rs:161 Program Rust
- parse_scientific · dec2flt/parse.rs:121 Program Rust
- parse_scientific_loop · dec2flt/parse.rs:142 Program Rust
- body · dec2flt/parse.rs:142 Program Rust
- try_parse_19digits · dec2flt/parse.rs:61 Program Rust
- try_parse_19digits_loop · dec2flt/parse.rs:64 Program Rust
- body · dec2flt/parse.rs:64 Program Rust
- try_parse_digits · dec2flt/parse.rs:30 Program Rust
- try_parse_digits_loop0 · dec2flt/parse.rs:33 Program Rust
- body · dec2flt/parse.rs:33 Program Rust
- try_parse_digits_loop1 · dec2flt/parse.rs:50 Program Rust
- body · dec2flt/parse.rs:50 Program Rust
- Dec2flt_modelNumImpDec2fltLemireU64 · dec2flt/mod.rs:217 Program Rust
- Dec2flt_modelNumImpTraitsFloatExtU64 · traits.rs:339 Program Rust
- from_u64_bits · traits.rs:341 Program Rust
- offset_from · dec2flt/common.rs:30 Program Rust
- eq · dec2flt/common.rs:51 Program Rust
- dec2flt · dec2flt/mod.rs:508 Program Rust
- try_fast_path · dec2flt/decimal.rs:59 Program Rust
- compute_product_approx · dec2flt/lemire.rs:134 Program Rust
- power · dec2flt/lemire.rs:121 Program Rust
- parse_8digits · dec2flt/parse.rs:18 Program Rust
- MASK · dec2flt/parse.rs:19 Program Rust
- MUL1 · dec2flt/parse.rs:20 Program Rust
- MUL2 · dec2flt/parse.rs:21 Program Rust
- parse_inf_nan · dec2flt/parse.rs:241 Program Rust
- pfe_empty · dec2flt/mod.rs:270 Program Rust
- pfe_invalid · dec2flt/mod.rs:277 Program Rust
- MAX_EXPONENT_DISGUISED_FAST_PATH · dec2flt/mod.rs:220 Program Rust
- MAX_EXPONENT_FAST_PATH · dec2flt/mod.rs:219 Program Rust
- pow10_fast_path · dec2flt/mod.rs:222 Program Rust
- integer_decode · traits.rs:348 Program Rust
- default · dec2flt/mod.rs:128 Program Rust
- default · dec2flt/mod.rs:121 Program Rust
- can_use_fast_path · dec2flt/decimal.rs:42 Program Rust
- INT_POW10 · dec2flt/decimal.rs:8 Program Rust
- set_precision · dec2flt/fpu.rs:99 Program Rust
- full_multiplication · dec2flt/lemire.rs:126 Program Rust
- LARGEST_POWER_OF_FIVE · dec2flt/table.rs:10 Program Rust
- POWER_OF_FIVE_128 · dec2flt/table.rs:19 Program Rust
- SMALLEST_POWER_OF_FIVE · dec2flt/table.rs:9 Program Rust
Standard-library dependencies (39)
- bitand · core/src/ops/bit.rs:178 Rust library
- bitor · core/src/ops/bit.rs:282 Rust library
- shl · core/src/ops/bit.rs:489 Rust library
- MANTISSA_DIGITS · core/src/num/f64.rs:412 Rust library
- clone · core/src/clone.rs:698 Rust library
- div · core/src/ops/arith.rs:515 Rust library
- mul · core/src/ops/arith.rs:350 Rust library
- neg · core/src/ops/arith.rs:719 Rust library
- shr · core/src/ops/bit.rs:612 Rust library
- EXPONENT_MASK · core/src/num/f64.rs:615 Rust library
- INFINITY · core/src/num/f64.rs:512 Rust library
- MANTISSA_MASK · core/src/num/f64.rs:637 Rust library
- NAN · core/src/num/f64.rs:509 Rust library
- NEG_INFINITY · core/src/num/f64.rs:515 Rust library
- classify · core/src/num/f64.rs:782 Rust library
- from_bits · core/src/num/f64.rs:1269 Rust library
- to_bits · core/src/num/f64.rs:1223 Rust library
- is_ascii_digit · core/src/num/mod.rs:958 Rust library
- from_residual · core/src/option.rs:2793 Rust library
- branch · core/src/option.rs:2779 Rust library
- first · core/src/slice/mod.rs:155 Rust library
- split_first · core/src/slice/mod.rs:198 Rust library
- as_bytes · core/src/str/mod.rs:498 Rust library
- CoreMarkerCopy · core/src/marker.rs:57 Rust library
- CoreOpsArithDivF64F64 · core/src/ops/arith.rs:511 Rust library
- CoreOpsArithMulF64F64 · core/src/ops/arith.rs:344 Rust library
- CoreOpsArithNegF64 · core/src/ops/arith.rs:713 Rust library
- FpCategory · core/src/num/mod.rs:1522 Rust library
- Div · core/src/ops/arith.rs:460 Rust library
- Mul · core/src/ops/arith.rs:322 Rust library
- Neg · core/src/ops/arith.rs:690 Rust library
- BitOr · core/src/ops/bit.rs:254 Rust library
- Shl · core/src/ops/bit.rs:461 Rust library
- Shr · core/src/ops/bit.rs:584 Rust library
- CoreCloneClone · core/src/clone.rs:696 Rust library
- CoreOpsBitBitAndU64U64 · core/src/ops/bit.rs:174 Rust library
- CoreOpsBitBitOrU64U64 · core/src/ops/bit.rs:278 Rust library
- CoreOpsBitShlU32U64 · core/src/ops/bit.rs:483 Rust library
- CoreOpsBitShrU32U64 · core/src/ops/bit.rs:606 Rust library
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
- Classical.choice
- Dec2Flt.configured_x86_64_numBits
- Quot.sound
- propext
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
- Binary64Model
- Binary64ModelDefault
- DecimalGoalVocabulary
- DecimalGoalVocabularyDefault
- DecimalLexeme
- DecimalRightShiftFinalLoopSemantics
All 122 entries
- Binary64Model
- Binary64ModelDefault
- DecimalGoalVocabulary
- DecimalGoalVocabularyDefault
- DecimalLexeme
- DecimalRightShiftFinalLoopSemantics
- DecimalRightShiftLoop0Execution
- DecimalRightShiftMainLoopSemantics
- DecimalRightShiftPrefixLoopSemantics
- DecimalRightShiftU64DyadicBridge
- DecimalSeqFractionalDigitInterval
- DecimalSeqPrimitiveSemantics
- DecimalSeqRoundArbitraryEndpoint
- DecimalSeqRoundLoopPrefixCore
- DecimalSeqRoundLoopValue
- DecimalSeqTrimSemantics
- F64
- F64 Insts CoreCloneClone
- F64 Insts CoreMarkerCopy
- F64 Insts CoreOpsArithDivF64F64
- F64 Insts CoreOpsArithMulF64F64
- F64 Insts CoreOpsArithNegF64
- F64 Insts Dec2flt modelNumImpTraitsFloatU64
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 BITS
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 EXP MASK
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 INFINITY
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 LARGEST POWER OF TEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 MAX EXPONENT ROUND TO EVEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 MIN EXPONENT ROUND TO EVEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 NAN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 NEG INFINITY
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 NEG NAN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 SIG MASK
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 SIG TOTAL BITS
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 SMALLEST POWER OF TEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 classify
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 to bits
- ModelF64Classify
- ModelF64Clone
- ModelF64Div
- ModelF64ExponentMask
- ModelF64FromBits
- ModelF64FromU64
- ModelF64Infinity
- ModelF64MantissaDigits
- ModelF64MantissaMask
- ModelF64Mul
- ModelF64Nan
- ModelF64Neg
- ModelF64NegInfinity
- ModelF64ToBits
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceFirst
- ModelSliceSplitFirst
- ModelStrAsBytes
- ModelU64BitAnd
- ModelU64BitOr
- ModelU64Shl
- ModelU64Shr
- ModelU8IsAsciiDigit
- NumberHelperDecimalPrefixInterval
- DecimalFoldBounds
- DecimalValueBounds
- ParserExponentConstants
- ParserSlowFinalEncoding
- Preamble
- ResultLoopPartial
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice write u64
- U64 Insts CoreOpsBitBitAndU64U64
- U64 Insts CoreOpsBitBitOrU64U64
- U64 Insts CoreOpsBitShlU32U64
- U64 Insts CoreOpsBitShrU32U64
- U64 Insts Dec2flt modelNumImpTraitsCastIntoI16
- U64 Insts Dec2flt modelNumImpTraitsCastIntoI16 cast
- U64 Insts Dec2flt modelNumImpTraitsInt
- U64 Insts Dec2flt modelNumImpTraitsInt ONE
- U64 Insts Dec2flt modelNumImpTraitsInt ZERO
- core num FpCategory
- core ops arith Div
- core ops arith Mul
- core ops arith Neg
- core ops bit BitOr
- core ops bit Shl
- core ops bit Shr
- num imp dec2flt Dec2FltAssemblyTrace
- num imp dec2flt common BiasedFp
- num imp dec2flt common BiasedFp zero pow2
- num imp dec2flt common is 8digits
- num imp dec2flt decimal Decimal
- num imp dec2flt decimal seq DecimalSeq
- num imp dec2flt decimal seq DecimalSeq DECIMAL POINT RANGE
- num imp dec2flt decimal seq DecimalSeq Insts CoreDefaultDefault default
- num imp dec2flt decimal seq DecimalSeq MAX DIGITS
- num imp dec2flt decimal seq DecimalSeq MAX DIGITS WITHOUT OVERFLOW
- num imp dec2flt decimal seq DecimalSeq left shift
- num imp dec2flt decimal seq DecimalSeq right shift
- num imp dec2flt decimal seq DecimalSeq round
- num imp dec2flt decimal seq DecimalSeq trim
- num imp dec2flt decimal seq DecimalSeq try add digit
- num imp dec2flt decimal seq count trailing zeros
- num imp dec2flt decimal seq number of digits decimal left shift
- num imp dec2flt decimal seq number of digits decimal left shift TABLE
- num imp dec2flt decimal seq number of digits decimal left shift TABLE POW5
- num imp dec2flt decimal seq parse decimal exponent
- num imp dec2flt decimal seq parse decimal seq
- num imp dec2flt decimal seq parse digits into seq
- num imp dec2flt slow parse long mantissa
- num imp dec2flt slow parse long mantissa MAX SHIFT
- num imp dec2flt slow parse long mantissa NUM POWERS
- num imp dec2flt slow parse long mantissa POWERS
- num imp dec2flt slow parse long mantissa closure
- num imp dec2flt slow parse long mantissa closure Insts CoreOpsFunctionFnTupleUsizeUsize call
- num imp traits CastInto
- num imp traits Float
- num imp traits Float EXP BIAS default
- num imp traits Float EXP BITS default
- num imp traits Float EXP MIN default
- num imp traits Float EXP SAT default
- num imp traits Float SIG BITS default
- num imp traits Int
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"
}