Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Constructed regular slow execution and raw-word certificate
- r=J and H\le X;
- for some natural j\le T, r=j, X\le T2^{-1074}, X\le j2^{-1074}+2^{-1075}, j2^{-1074}\le X+2^{-1075}, and (X=(j+1/2)2^{-1074}\ \lor\ X=(j-1/2)2^{-1074}) \Longrightarrow j\bmod2=0;
- for some natural p,j with 2\le p\le2046, U\le j\le T, and p<2046 or j<T, put \Delta=2^{p-1075}. Then r=pU+(j-U), U\Delta\le X\le T\Delta, X<H, X\le j\Delta+\Delta/2, j\Delta\le X+\Delta/2, and (X=(j+1/2)\Delta\ \lor\ X=(j-1/2)\Delta) \Longrightarrow j\bmod2=0.
Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.P495_T1_SlowLoop0Execution
import Tablet.P529_T1_Loop1Execution
import Tablet.P529_T1_NormalizationBounds
import Tablet.P529_T1_Loop2Execution
import Tablet.P529_T1_FinalShiftCertificate
import Tablet.P529_T1_SeparationPackage
import Tablet.P529_T1_RoundArbitraryEndpoint
import Tablet.P529_T1_CarryRoundExecution
import Tablet.P529_T1_EncodingArithmetic
import Tablet.ParserExponentConstants
import Tablet.Binary64NearestEvenAssembly
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.ModelU64Shl
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P529_T1_RegularSlowExecution]
theorem P529_T1_RegularSlowExecution (s : Slice Std.U8) (X Y : Real)
(d : num.imp.dec2flt.decimal_seq.DecimalSeq)
(hparse : num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d)
(hpointLo : -324 <= d.decimal_point.val)
(hpointHi : d.decimal_point.val < 310)
(hinput : d.num_digits.val <= 768 /\
(forall b, b ∈ d.digits.val.take d.num_digits.val -> b.val < 10) /\
(exists h tail,
(d.digits.val.take d.num_digits.val).map (fun b => b.val) = h :: tail /\
1 <= h /\ h < 10 /\ (h :: tail).length = d.num_digits.val)) :
let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
(fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
Y = V d + (10 : Real) ^ (d.decimal_point.val - 768) ->
(exists eta : Real, X = V d + eta /\ 0 <= eta /\
eta < (10 : Real) ^ (d.decimal_point.val - 768) /\
(d.truncated = true <-> 0 < eta)) ->
exists fp : num.imp.dec2flt.common.BiasedFp,
P9_T1_ActualDispatchOperations.slow s = ok fp /\
(let raw : Nat := Nat.lor fp.m.val
(((fp.p_biased.val.emod (2 ^ 64)).toNat * (2 ^ 52)) % (2 ^ 64))
0 <= X /\ ((raw = 2047 * (2 ^ 52) /\
(2 : Real) ^ (1024 : Nat) - (2 : Real) ^ (970 : Nat) <= X) \/
(exists j : Nat,
j <= 2 ^ 53 /\ raw = j /\
X <= (2 ^ 53 : Nat) * (2 : Real) ^ (-1074 : Int) /\
X <= (j : Real) * (2 : Real) ^ (-1074 : Int) + (2 : Real) ^ (-1075 : Int) /\
(j : Real) * (2 : Real) ^ (-1074 : Int) <= X + (2 : Real) ^ (-1075 : Int) /\
(X = ((j : Real) + 1 / 2) * (2 : Real) ^ (-1074 : Int) \/
X = ((j : Real) - 1 / 2) * (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 * (2 ^ 52) + (j - 2 ^ 52) /\
let delta : Real := (2 : Real) ^ ((p : Int) - 1075)
(2 ^ 52 : Nat) * delta <= X /\ X <= (2 ^ 53 : Nat) * delta /\
X < (2 : Real) ^ (1024 : Nat) - (2 : Real) ^ (970 : Nat) /\
X <= (j : Real) * delta + delta / 2 /\
(j : Real) * delta <= X + delta / 2 /\
(X = ((j : Real) + 1 / 2) * delta \/
X = ((j : Real) - 1 / 2) * delta -> j % 2 = 0)))) /\
(exists magnitude : F64,
DecimalGoalVocabularyDefault.assembledWord fp magnitude /\
DecimalGoalVocabularyDefault.roundsMagnitude X magnitude) := by
Proof
Natural-language proof
The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.
Explanatory prose status
Prose retained as authored. The explanatory prose is preserved as it stood when captured.
Proof
Lean proof
exact (set_option maxHeartbeats 2000000 in by
let pack (e : Std.I32) (m : Std.U64) : Result num.imp.dec2flt.common.BiasedFp := do
let b ← e - (-1022)#i32
let p ← b + 1#i32
let u ← 1#u64 <<< 52#u32
let p' ← if m < u then p - 1#i32 else ok p
let u' ← 1#u64 <<< 52#u32
let mask ← u' - 1#u64
let a ← lift (m &&& mask)
ok { m := a, p_biased := p' }
let suffix (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (e : Std.I32) :
Result num.imp.dec2flt.common.BiasedFp := do
let b ← e - (-1022)#i32
let p ← b + 1#i32
if p >= 2047#i32 then ok { m := 0#u64, p_biased := 2047#i32 }
else
let d3 ← num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d 53#usize
let m ← num.imp.dec2flt.decimal_seq.DecimalSeq.round d3
if m >= 9007199254740992#u64 then
let d4 ← num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d3 1#usize
let e' ← e + 1#i32
let m4 ← num.imp.dec2flt.decimal_seq.DecimalSeq.round d4
let b' ← e' - (-1022)#i32
let p' ← b' + 1#i32
if p' >= 2047#i32 then ok { m := 0#u64, p_biased := 2047#i32 }
else pack e' m4
else pack e m
let rawOf (fp : num.imp.dec2flt.common.BiasedFp) : Nat :=
Nat.lor fp.m.val (((fp.p_biased.val.emod (2^64)).toNat * 2^52) % 2^64)
have biasOps (e : Std.I32) (hlo : -1022 <= e.val) (hhi : e.val <= 1261) :
∃ b p : Std.I32, e - (-1022)#i32 = ok b ∧ b + 1#i32 = ok p ∧
p.val = e.val + 1023 := by
obtain ⟨b, hb, hbval⟩ := WP.spec_imp_exists
(IScalar.sub_spec (x := e) (y := (-1022)#i32)
(by rw [IScalar.min_I32_eq]; norm_num; omega)
(by rw [IScalar.max_I32_eq]; norm_num; omega))
obtain ⟨p, hp, hpval⟩ := WP.spec_imp_exists
(IScalar.add_spec (x := b) (y := 1#i32)
(by rw [IScalar.min_I32_eq]; norm_num at hbval ⊢; omega)
(by rw [IScalar.max_I32_eq]; norm_num at hbval ⊢; omega))
exact ⟨b,p,hb,hp,by norm_num at hbval hpval; omega⟩
have mask52 (z : Std.U64) : (z &&& 4503599627370495#u64).val = z.val % 2^52 := by
change (z.bv &&& 4503599627370495#64).toNat = z.bv.toNat % 2^52
rw [show 4503599627370495#64 = 2#64^52 - 1#64 by decide,
BitVec.and_two_pow_sub_one_eq_mod]
simp
have fieldOr (a ef : Nat) (ha : a < 2^52)
(hef : ef * 2^52 < 2^64) : a ||| (ef * 2^52) = a + ef * 2^52 := by
have hland : a &&& (ef * 2^52) = 0 := by
apply Nat.eq_of_testBit_eq
intro j
rw [Nat.testBit_land, Nat.testBit_mul_two_pow]
by_cases hj : j < 52
· simp [hj]
· have haj : a.testBit j = false := by
apply Nat.testBit_eq_false_of_lt
exact lt_of_lt_of_le ha (Nat.pow_le_pow_right (by omega) (by omega))
simp [haj]
let av : BitVec 64 := BitVec.ofNat 64 a
let ev : BitVec 64 := BitVec.ofNat 64 (ef * 2^52)
have hlandBV : av &&& ev = 0#64 := by
apply BitVec.eq_of_toNat_eq
simp only [av, ev, BitVec.toNat_and, BitVec.toNat_ofNat]
rw [Nat.mod_eq_of_lt (ha.trans (by norm_num)), Nat.mod_eq_of_lt hef, hland]
calc
a ||| (ef * 2^52) = (av ||| ev).toNat := by
simp only [av, ev, BitVec.toNat_or, BitVec.toNat_ofNat]
rw [Nat.mod_eq_of_lt (ha.trans (by norm_num)), Nat.mod_eq_of_lt hef]
_ = (av + ev).toNat := by rw [BitVec.add_eq_or_of_and_eq_zero av ev hlandBV]
_ = a + ef * 2^52 := by
rw [BitVec.toNat_add_of_and_eq_zero hlandBV]
simp only [av, ev, BitVec.toNat_ofNat]
rw [Nat.mod_eq_of_lt (ha.trans (by norm_num)), Nat.mod_eq_of_lt hef]
have packExec (e : Std.I32) (m : Std.U64)
(hlo : -1022 <= e.val) (hhi : e.val <= 1023) :
∃ fp : num.imp.dec2flt.common.BiasedFp, pack e m = ok fp ∧
rawOf fp = (e.val + 1023 - (if m.val < 2^52 then 1 else 0)).toNat * 2^52 +
m.val % 2^52 := by
obtain ⟨b,p,hb,hp,hpval⟩ := biasOps e hlo (by omega)
have hpbound : 1 <= p.val ∧ p.val <= 2046 := by omega
have hpower : ∃ p' : Std.I32,
(if m < 4503599627370496#u64 then p - 1#i32 else ok p) = ok p' ∧
p'.val = e.val + 1023 - (if m.val < 2^52 then 1 else 0) ∧
0 <= p'.val ∧ p'.val <= 2046 := by
by_cases hm : m.val < 2^52
· have hm' : m < 4503599627370496#u64 := by
change m.val < 4503599627370496
norm_num at hm
exact hm
obtain ⟨p',hp',hv⟩ := WP.spec_imp_exists
(IScalar.sub_spec (x := p) (y := 1#i32)
(by rw [IScalar.min_I32_eq]; norm_num; omega)
(by rw [IScalar.max_I32_eq]; norm_num; omega))
refine ⟨p', by rw [if_pos hm']; exact hp', ?_, ?_, ?_⟩
all_goals norm_num at hv; try simp only [if_pos hm]
all_goals omega
· have hm' : ¬m < 4503599627370496#u64 := by
change ¬m.val < 4503599627370496
norm_num at hm
omega
refine ⟨p, by rw [if_neg hm'], ?_, by omega, by omega⟩
simp only [if_neg hm, Int.sub_zero]
exact hpval
obtain ⟨p',hp',hp'val,hp'lo,hp'hi⟩ := hpower
let fp : num.imp.dec2flt.common.BiasedFp :=
{ m := m &&& 4503599627370495#u64, p_biased := p' }
refine ⟨fp, ?_, ?_⟩
· unfold pack
simp only [hb, hp, bind_tc_ok,
show (1#u64 <<< 52#u32) = ok 4503599627370496#u64 by rfl,
hp', show (4503599627370496#u64 - 1#u64) = ok 4503599627370495#u64 by rfl]
rfl
· have hef : p'.val.toNat * 2^52 < 2^64 := by
have : p'.val.toNat <= 2046 := by omega
norm_num
omega
unfold rawOf
change Nat.lor (m &&& 4503599627370495#u64).val
(((p'.val.emod (2^64)).toNat * 2^52) % 2^64) = _
rw [mask52]
have hmod : p'.val.emod (2^64) = p'.val := by
exact Int.emod_eq_of_lt hp'lo (by norm_num; omega)
rw [hmod, Nat.mod_eq_of_lt hef]
change (m.val % 2^52) ||| (p'.val.toNat * 2^52) = _
rw [fieldOr (m.val % 2^52) p'.val.toNat (Nat.mod_lt _ (by positivity)) hef, hp'val]
omega
intro Vfun hY hX
classical
have h0pkg := P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi hinput
(by simpa [Vfun] using hY) (by simpa [Vfun] using hX)
rcases h0pkg with ⟨d0, e0, steps, h0, hsteps, he0lo, he0hi, hXlo,
hp0lo, hp0hi, hn0, hd0, hshape0, htrim0, hends0⟩
-- The source call starts from exactly the parsed record and the certified loop zero.
have hinput0 : d0.num_digits.val <= 768 /\
(forall b, b ∈ d0.digits.val.take d0.num_digits.val -> b.val < 10) /\
(exists h tail,
(d0.digits.val.take d0.num_digits.val).map (fun b => b.val) = h :: tail /\
1 <= h /\ h < 10 /\ (h :: tail).length = d0.num_digits.val) :=
⟨hn0, hd0, hshape0⟩
have h1pkg := P529_T1_Loop1Execution X Y d0 e0 hp0lo hp0hi he0lo
hinput0 (by simpa [Vfun] using hends0)
rcases h1pkg with ⟨d1, e1, bound, h1, hbound, hboundlo, hboundhi,
hp1, hn1, hheadlo, hheadhi, hn1cap, hd1, hshape1, hends1⟩
have hnorm := P529_T1_NormalizationBounds X Y d d0 d1 e0 e1
hpointLo hpointHi hinput h0 h1 (by simpa [Vfun] using hY)
(by simpa [Vfun] using hX)
rcases hnorm with ⟨_, hXY, hYbound, he1lo, he1hi⟩
have h2pkg := P529_T1_Loop2Execution X Y d1 e1 he1lo hp1
⟨hn1cap, hd1, hshape1⟩ (by simpa [Vfun] using hends1)
rcases h2pkg with ⟨es, e2, d2, sh, hdec, hesval, heslo, h2, he2val,
hshval, hshle, h2case, hp2lo, hp2hi, hn2, hd2, hshape2, htrim2, hends2⟩
have he2range : -1022 <= e2.val /\ e2.val <= 1260 := by
rw [he2val]
omega
have he1le : e1.val <= e2.val + 1 := by rw [he2val, hesval]; omega
have hYbound2 : Y / (2 : Real) ^ (e2.val + 1) <= 1 := by
have hYle : Y <= (2 : Real) ^ e1.val :=
(div_le_one (by positivity)).mp hYbound
have hpow : (2 : Real) ^ e1.val <= (2 : Real) ^ (e2.val + 1) :=
zpow_le_zpow_right₀ (by norm_num) he1le
exact (div_le_one (by positivity)).2 (hYle.trans hpow)
have h3pkg := P529_T1_FinalShiftCertificate X Y d2 e2 hp2lo hp2hi
⟨hn2, hd2, hshape2⟩ hYbound2 (by simpa using hends2)
rcases h3pkg with ⟨d3, h3, hp3lo, hp3hi, hn3, hd3, hshape3, htrim3,
hXpos3, hXhi3, hends3⟩
have hsepPkg := P529_T1_SeparationPackage X Y d d0 d1 d2 d3 e0 e1 es e2
hpointLo hpointHi hinput h0 h1 hdec h2 h3
(by simpa [Vfun] using hY) (by simpa [Vfun] using hX)
rcases hsepPkg with ⟨hhalfSep, hoddSep⟩
have hroundPkg := P529_T1_RoundArbitraryEndpoint d3
(X / (2 : Real) ^ (e2.val - 52)) (Y / (2 : Real) ^ (e2.val - 52))
hn3 hd3 (Or.inr ⟨hshape3, htrim3⟩) (by omega) (by positivity)
(by
have hbig : (2 : Real) ^ (53 : Nat) < (2 : Real) ^ (64 : Nat) - 1 / 2 := by norm_num
exact lt_trans hXhi3 hbig)
(by simpa using hends3)
(by
intro n
simpa using hhalfSep n)
rcases hroundPkg with ⟨m, hround, hmUpper, hmLower, hmTie⟩
have hnumNe : d.num_digits ≠ 0#usize := by
rcases hinput.2.2 with ⟨head, tail, hmap, hhead, hheadHi, hlen⟩
intro heq
have hv := congrArg (fun n : Std.Usize => n.val) heq
simp at hv
rw [← hlen] at hv
simp at hv
have hsmall : ¬ d.decimal_point < (-324)#i32 := by
intro hs
have hs' : d.decimal_point.val < -324 := by
simpa only [IScalar.lt_equiv] using hs
omega
have hlarge : ¬ d.decimal_point >= 310#i32 := by
intro hl
have hl' : (310 : Int) <= d.decimal_point.val := by
simpa only [IScalar.le_equiv] using hl
omega
have hsource : P9_T1_ActualDispatchOperations.slow s = suffix d2 e2 := by
have h0bind {R : Type}
(k : Std.Usize → Std.I32 → Bool → Array Std.U8 768#usize → Std.I32 →
Option num.imp.dec2flt.common.BiasedFp → Result R) :
(do
let (n,p,tr,a,e,r) ← 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
k n p tr a e r) = k d0.num_digits d0.decimal_point d0.truncated
d0.digits e0 none := by
simp only [h0, bind_tc_ok]
rfl
have h1bind {R : Type}
(k : Std.Usize → Std.I32 → Bool → Array Std.U8 768#usize → Std.I32 →
Option num.imp.dec2flt.common.BiasedFp → Result R) :
(do
let (n,p,tr,a,e,r) ← 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 e0 none
k n p tr a e r) = k d1.num_digits d1.decimal_point d1.truncated
d1.digits e1 none := by
simp only [h1, bind_tc_ok]
rfl
have h2bind {R : Type}
(k : num.imp.dec2flt.decimal_seq.DecimalSeq → Std.I32 → Result R) :
(do
let (a,e) ← num.imp.dec2flt.slow.parse_long_mantissa_loop2
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 es
k a e) = k d2 e2 := by
simp only [h2, bind_tc_ok]
rfl
change num.imp.dec2flt.slow.parse_long_mantissa
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s = _
unfold num.imp.dec2flt.slow.parse_long_mantissa
rcases ParserExponentConstants with ⟨_, _, hsig, _, _, hinf, _, hmin, _⟩
change (do
let i ← F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS
i - 1#u32) = ok 52#u32 at hsig
change (do
let i ← (do
let i ← (do
let i ← (do
let i1 ← (do
let i ← F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS
i - 1#u32)
let i2 ← F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.BITS - i1
i2 - 1#u32)
let i1 ← 1#u32 <<< i
i1 - 1#u32)
i >>> 1#i32)
let i1 ← lift (UScalar.hcast .I32 i)
let i2 ← i1 - 1#i32
-.i2) = ok (-1022)#i32 at hmin
rw [hinf]
simp only [num.imp.dec2flt.common.BiasedFp.zero_pow2, bind_tc_ok]
rw [hparse]
simp only [bind_tc_ok, if_neg hnumNe, if_neg hsmall, if_neg hlarge]
rw [h0bind]
rw [h1bind]
rw [hdec]
simp only [bind_tc_ok]
rw [h2bind]
rw [hmin]
simp only [bind_tc_ok]
rw [hsig]
simp only [bind_tc_ok]
have hcast : lift (UScalar.cast .Usize 52#u32) = ok 52#usize := by
apply congrArg ok
apply UScalar.eq_of_val_eq
simp
have hadd : (52#usize + 1#usize) = ok 53#usize := by
obtain ⟨w, hw, hv⟩ := WP.spec_imp_exists
(UScalar.add_spec (x := 52#usize) (y := 1#usize) (by scalar_tac))
have heq : w = 53#usize := UScalar.eq_of_val_eq (by simpa using hv)
simpa only [heq] using hw
simp only [hcast, hadd, show (52#u32 + 1#u32) = ok 53#u32 by rfl,
show (1#u64 <<< 53#u32) = ok 9007199254740992#u64 by rfl, bind_tc_ok]
rfl
have hnormal : -1022 < e2.val -> (2 ^ 52 : Nat) <=
X / (2 : Real) ^ (e2.val - 52) := by
intro hnormalExp
have hd2eq : d2 = d1 := by
rcases h2case with hno | hyes
· exact hno.2.2.1
· have : e2.val = -1022 := hyes.2.2.2
omega
rcases hshape1 with ⟨head, tail, hmap, hheadlo, hheadhi, hlen⟩
have hval := P472_T1_DecimalValueBounds
((d1.digits.val.take d1.num_digits.val).map (fun b => b.val))
head tail hmap (by omega)
(by
intro q hq
rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩
exact hd1 b hb)
d1.decimal_point.val
have hlen1 : ((d1.digits.val.take d1.num_digits.val).map
(fun b => b.val)).length = d1.num_digits.val := by
rw [hmap]
simpa using hlen
have hVlower : (1 / 2 : Real) <=
((((d1.digits.val.take d1.num_digits.val).map
(fun b => b.val)).foldl (fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (d1.decimal_point.val - (d1.num_digits.val : Int)) := by
have hfirst := hval.1
rw [hlen1, hp1] at hfirst
norm_num at hfirst
have hfirst' : (head : Real) / 10 <=
((((d1.digits.val.take d1.num_digits.val).map
(fun b => b.val)).foldl (fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (d1.decimal_point.val - (d1.num_digits.val : Int)) := by
rw [hp1, show (0 : Int) - (d1.num_digits.val : Int) =
-(d1.num_digits.val : Int) by omega, zpow_neg, zpow_natCast]
simpa using hfirst
have hh : (5 : Real) <= head := by exact_mod_cast hheadlo
have hhalf : (1 / 2 : Real) <= (head : Real) / 10 := by nlinarith
exact hhalf.trans hfirst'
have hXbase : (1 / 2 : Real) <=
X / (2 : Real) ^ (e2.val + 1) := by
rcases hends2 with ⟨eta, u, hXeq, hYeq, heta, hlt, htr⟩
rw [hXeq, hd2eq]
have hlower' : (1 / 2 : Real) <=
(fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
(fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))) d1 := by
simpa [Vfun] using hVlower
linarith
have hscale : (2 : Real) ^ (53 : Nat) *
(X / (2 : Real) ^ (e2.val + 1)) =
X / (2 : Real) ^ (e2.val - 52) := by
rw [div_eq_mul_inv, div_eq_mul_inv, ← zpow_neg, ← zpow_neg]
calc
(2 : Real) ^ (53 : Nat) * (X * (2 : Real) ^ (-(e2.val + 1))) =
((2 : Real) ^ (53 : Nat) * (2 : Real) ^ (-(e2.val + 1))) * X := by ring
_ = (2 : Real) ^ (-(e2.val - 52)) * X := by
rw [← zpow_natCast (2 : Real) 53, ← zpow_add₀
(by norm_num : (2 : Real) ≠ 0)]
congr 1
norm_num
omega
_ = X * (2 : Real) ^ (-(e2.val - 52)) := by ring
have hmul := mul_le_mul_of_nonneg_left hXbase (by positivity : (0 : Real) <= 2 ^ (53 : Nat))
rw [hscale] at hmul
have hcast : (2 ^ 52 : Nat) = ((2 : Real) ^ (52 : Nat) : Real) := by norm_num
rw [hcast]
set_option maxHeartbeats 800000 in nlinarith
have hcarryWitness : ∃ (d4 : num.imp.dec2flt.decimal_seq.DecimalSeq) (m4 : Std.U64),
(2^53 <= m.val ->
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d3 1#usize = ok d4 ∧
num.imp.dec2flt.decimal_seq.DecimalSeq.round d4 = ok m4) ∧
(2^53 <= m.val ->
(X / (2 : Real) ^ (e2.val - 52)) / 2 <= (m4.val : Real) + 1/2 ∧
(m4.val : Real) <= (X / (2 : Real) ^ (e2.val - 52)) / 2 + 1/2 ∧
((X / (2 : Real) ^ (e2.val - 52)) / 2 = (m4.val : Real) + 1/2 ∨
(X / (2 : Real) ^ (e2.val - 52)) / 2 = (m4.val : Real) - 1/2 ->
m4.val % 2 = 0)) := by
by_cases hc : 2^53 <= m.val
· obtain ⟨d4, m4, hs4, _, _, _, _, _, _, _, _, hr4, hu4, hl4, ht4⟩ :=
P529_T1_CarryRoundExecution
(X / (2 : Real) ^ (e2.val - 52))
(Y / (2 : Real) ^ (e2.val - 52)) d3 m hn3 hd3 hshape3 htrim3
(by omega) (le_of_lt hXpos3) hXhi3 hround hc hends3 hoddSep
exact ⟨d4, m4, fun _ => ⟨hs4,hr4⟩, fun _ => ⟨hu4,hl4,ht4⟩⟩
· exact ⟨d3, 0#u64, fun h => (hc h).elim, fun h => (hc h).elim⟩
obtain ⟨d4,m4,hcarryCall,hcarryNear⟩ := hcarryWitness
let raw : Nat :=
if 1024 <= e2.val then 2047 * 2^52
else if 2^53 <= m.val then
if 1023 <= e2.val then 2047 * 2^52
else (e2.val + 1024 - (if m4.val < 2^52 then 1 else 0)).toNat * 2^52 +
m4.val % 2^52
else (e2.val + 1023 - (if m.val < 2^52 then 1 else 0)).toNat * 2^52 +
m.val % 2^52
let Cert (r : Nat) : Prop :=
0 <= X ∧ ((r = 2047 * 2^52 ∧
(2 : Real) ^ (1024 : Nat) - (2 : Real) ^ (970 : Nat) <= X) ∨
(∃ j : Nat, j <= 2^53 ∧ r = j ∧
X <= (2^53 : Nat) * (2 : Real) ^ (-1074 : Int) ∧
X <= (j : Real) * (2 : Real) ^ (-1074 : Int) + (2 : Real) ^ (-1075 : Int) ∧
(j : Real) * (2 : Real) ^ (-1074 : Int) <= X + (2 : Real) ^ (-1075 : Int) ∧
(X = ((j : Real) + 1/2) * (2 : Real) ^ (-1074 : Int) ∨
X = ((j : Real) - 1/2) * (2 : Real) ^ (-1074 : Int) -> j % 2 = 0)) ∨
(∃ p j : Nat, 2 <= p ∧ p <= 2046 ∧ 2^52 <= j ∧ j <= 2^53 ∧
(p < 2046 ∨ j < 2^53) ∧ r = p * 2^52 + (j - 2^52) ∧
let delta : Real := (2 : Real) ^ ((p : Int) - 1075)
(2^52 : Nat) * delta <= X ∧ X <= (2^53 : Nat) * delta ∧
X < (2 : Real) ^ (1024 : Nat) - (2 : Real) ^ (970 : Nat) ∧
X <= (j : Real) * delta + delta/2 ∧ (j : Real) * delta <= X + delta/2 ∧
(X = ((j : Real) + 1/2) * delta ∨ X = ((j : Real) - 1/2) * delta ->
j % 2 = 0)))
have henc : Cert raw := P529_T1_EncodingArithmetic X e2.val m.val m4.val
he2range.1 he2range.2 hXpos3 hXhi3 hnormal hmUpper hmLower hmTie hcarryNear
have hrun : ∃ fp : num.imp.dec2flt.common.BiasedFp,
P9_T1_ActualDispatchOperations.slow s = ok fp ∧ rawOf fp = raw := by
obtain ⟨b,p,hb,hp,hpval⟩ := biasOps e2 he2range.1 (by omega)
have hfirst : (p >= 2047#i32) ↔ 1024 <= e2.val := by
change (2047 : Int) <= p.val ↔ 1024 <= e2.val
omega
by_cases he : 1024 <= e2.val
· refine ⟨{m := 0#u64,p_biased := 2047#i32}, ?_, ?_⟩
· rw [hsource]
dsimp only [suffix]
rw [hb]
simp only [bind_tc_ok, hp, if_pos (hfirst.mpr he)]
· simp only [raw, if_pos he]
change Nat.lor 0 (((2047 : Int).emod (2^64)).toNat * 2^52 % 2^64) = _
norm_num [Nat.lor_eq]
rfl
· have hpf : ¬p >= 2047#i32 := fun h => he (hfirst.mp h)
have hcguard : (m >= 9007199254740992#u64) ↔ 2^53 <= m.val := by
change 9007199254740992 <= m.val ↔ 2^53 <= m.val
norm_num
have hresume : P9_T1_ActualDispatchOperations.slow s =
(if m >= 9007199254740992#u64 then do
let d4 ← num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d3 1#usize
let e' ← e2 + 1#i32
let m4 ← num.imp.dec2flt.decimal_seq.DecimalSeq.round d4
let b' ← e' - (-1022)#i32
let p' ← b' + 1#i32
if p' >= 2047#i32 then ok {m := 0#u64,p_biased := 2047#i32}
else pack e' m4
else pack e2 m) := by
rw [hsource]
dsimp only [suffix]
rw [hb]
simp only [bind_tc_ok, hp, if_neg hpf, h3, hround]
by_cases hc : 2^53 <= m.val
· obtain ⟨hs4,hr4⟩ := hcarryCall hc
obtain ⟨e',he',he'val⟩ := WP.spec_imp_exists
(IScalar.add_spec (x := e2) (y := 1#i32)
(by rw [IScalar.min_I32_eq]; norm_num; omega)
(by rw [IScalar.max_I32_eq]; norm_num; omega))
have hev : e'.val = e2.val + 1 := by simpa using he'val
obtain ⟨b',p',hb',hp',hp'val⟩ := biasOps e' (by omega) (by omega)
have hsecond : (p' >= 2047#i32) ↔ 1023 <= e2.val := by
change (2047 : Int) <= p'.val ↔ 1023 <= e2.val
omega
have hresume4 : P9_T1_ActualDispatchOperations.slow s =
(if p' >= 2047#i32 then ok {m := 0#u64,p_biased := 2047#i32}
else pack e' m4) := by
rw [hresume, if_pos (hcguard.mpr hc), hs4]
simp only [bind_tc_ok, he', hr4, hb', hp']
by_cases hec : 1023 <= e2.val
· refine ⟨{m := 0#u64,p_biased := 2047#i32}, ?_, ?_⟩
· rw [hresume4, if_pos (hsecond.mpr hec)]
· simp only [raw, if_neg he, if_pos hc, if_pos hec]
change Nat.lor 0 (((2047 : Int).emod (2^64)).toNat * 2^52 % 2^64) = _
norm_num [Nat.lor_eq]
rfl
· obtain ⟨fp,hpack,hraw⟩ := packExec e' m4 (by omega) (by omega)
refine ⟨fp, ?_, ?_⟩
· rw [hresume4, if_neg (fun h => hec (hsecond.mp h)), hpack]
· simp only [raw, if_neg he, if_pos hc, if_neg hec]
rw [hraw, hev]
congr 3 <;> omega
· obtain ⟨fp,hpack,hraw⟩ := packExec e2 m he2range.1 (by omega)
refine ⟨fp, ?_, ?_⟩
· rw [hresume, if_neg (fun h => hc (hcguard.mp h)), hpack]
· simpa only [raw, if_neg he, if_neg hc] using hraw
obtain ⟨fp,hcall,hraw⟩ := hrun
have hcert : Cert (rawOf fp) := by rw [hraw]; exact henc
refine ⟨fp,hcall,hcert,?_⟩
have hbound : rawOf fp <= 2047 * 2^52 := by
rcases hcert.2 with htop | hlow | hnormal
· omega
· obtain ⟨j,hj,hr,_⟩ := hlow
rw [hr]
norm_num at hj ⊢
omega
· obtain ⟨p,j,_,hp,_,hj,_,hr,_⟩ := hnormal
rw [hr]
norm_num at hp hj ⊢
omega
have hrawlt : rawOf fp < 2^64 := lt_of_le_of_lt hbound (by norm_num)
let magnitude : F64 := U64.ofNatCore (rawOf fp) hrawlt
have hasm : DecimalGoalVocabularyDefault.assembledWord fp magnitude := by
change magnitude.val = rawOf fp
exact U64.ofNatCore_val_eq hrawlt
exact ⟨magnitude,hasm,Binary64NearestEvenAssembly X fp magnitude hcert hasm⟩
)
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.P495_T1_SlowLoop0Execution
import Tablet.P529_T1_Loop1Execution
import Tablet.P529_T1_NormalizationBounds
import Tablet.P529_T1_Loop2Execution
import Tablet.P529_T1_FinalShiftCertificate
import Tablet.P529_T1_SeparationPackage
import Tablet.P529_T1_RoundArbitraryEndpoint
import Tablet.P529_T1_CarryRoundExecution
import Tablet.P529_T1_EncodingArithmetic
import Tablet.ParserExponentConstants
import Tablet.Binary64NearestEvenAssembly
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.ModelU64Shl
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P529_T1_RegularSlowExecution]
theorem P529_T1_RegularSlowExecution (s : Slice Std.U8) (X Y : Real)
(d : num.imp.dec2flt.decimal_seq.DecimalSeq)
(hparse : num.imp.dec2flt.decimal_seq.parse_decimal_seq s = ok d)
(hpointLo : -324 <= d.decimal_point.val)
(hpointHi : d.decimal_point.val < 310)
(hinput : d.num_digits.val <= 768 /\
(forall b, b ∈ d.digits.val.take d.num_digits.val -> b.val < 10) /\
(exists h tail,
(d.digits.val.take d.num_digits.val).map (fun b => b.val) = h :: tail /\
1 <= h /\ h < 10 /\ (h :: tail).length = d.num_digits.val)) :
let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
(fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
Y = V d + (10 : Real) ^ (d.decimal_point.val - 768) ->
(exists eta : Real, X = V d + eta /\ 0 <= eta /\
eta < (10 : Real) ^ (d.decimal_point.val - 768) /\
(d.truncated = true <-> 0 < eta)) ->
exists fp : num.imp.dec2flt.common.BiasedFp,
P9_T1_ActualDispatchOperations.slow s = ok fp /\
(let raw : Nat := Nat.lor fp.m.val
(((fp.p_biased.val.emod (2 ^ 64)).toNat * (2 ^ 52)) % (2 ^ 64))
0 <= X /\ ((raw = 2047 * (2 ^ 52) /\
(2 : Real) ^ (1024 : Nat) - (2 : Real) ^ (970 : Nat) <= X) \/
(exists j : Nat,
j <= 2 ^ 53 /\ raw = j /\
X <= (2 ^ 53 : Nat) * (2 : Real) ^ (-1074 : Int) /\
X <= (j : Real) * (2 : Real) ^ (-1074 : Int) + (2 : Real) ^ (-1075 : Int) /\
(j : Real) * (2 : Real) ^ (-1074 : Int) <= X + (2 : Real) ^ (-1075 : Int) /\
(X = ((j : Real) + 1 / 2) * (2 : Real) ^ (-1074 : Int) \/
X = ((j : Real) - 1 / 2) * (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 * (2 ^ 52) + (j - 2 ^ 52) /\
let delta : Real := (2 : Real) ^ ((p : Int) - 1075)
(2 ^ 52 : Nat) * delta <= X /\ X <= (2 ^ 53 : Nat) * delta /\
X < (2 : Real) ^ (1024 : Nat) - (2 : Real) ^ (970 : Nat) /\
X <= (j : Real) * delta + delta / 2 /\
(j : Real) * delta <= X + delta / 2 /\
(X = ((j : Real) + 1 / 2) * delta \/
X = ((j : Real) - 1 / 2) * delta -> j % 2 = 0)))) /\
(exists magnitude : F64,
DecimalGoalVocabularyDefault.assembledWord fp magnitude /\
DecimalGoalVocabularyDefault.roundsMagnitude X magnitude) := by
-- BODY
exact (set_option maxHeartbeats 2000000 in by
let pack (e : Std.I32) (m : Std.U64) : Result num.imp.dec2flt.common.BiasedFp := do
let b ← e - (-1022)#i32
let p ← b + 1#i32
let u ← 1#u64 <<< 52#u32
let p' ← if m < u then p - 1#i32 else ok p
let u' ← 1#u64 <<< 52#u32
let mask ← u' - 1#u64
let a ← lift (m &&& mask)
ok { m := a, p_biased := p' }
let suffix (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (e : Std.I32) :
Result num.imp.dec2flt.common.BiasedFp := do
let b ← e - (-1022)#i32
let p ← b + 1#i32
if p >= 2047#i32 then ok { m := 0#u64, p_biased := 2047#i32 }
else
let d3 ← num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d 53#usize
let m ← num.imp.dec2flt.decimal_seq.DecimalSeq.round d3
if m >= 9007199254740992#u64 then
let d4 ← num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d3 1#usize
let e' ← e + 1#i32
let m4 ← num.imp.dec2flt.decimal_seq.DecimalSeq.round d4
let b' ← e' - (-1022)#i32
let p' ← b' + 1#i32
if p' >= 2047#i32 then ok { m := 0#u64, p_biased := 2047#i32 }
else pack e' m4
else pack e m
let rawOf (fp : num.imp.dec2flt.common.BiasedFp) : Nat :=
Nat.lor fp.m.val (((fp.p_biased.val.emod (2^64)).toNat * 2^52) % 2^64)
have biasOps (e : Std.I32) (hlo : -1022 <= e.val) (hhi : e.val <= 1261) :
∃ b p : Std.I32, e - (-1022)#i32 = ok b ∧ b + 1#i32 = ok p ∧
p.val = e.val + 1023 := by
obtain ⟨b, hb, hbval⟩ := WP.spec_imp_exists
(IScalar.sub_spec (x := e) (y := (-1022)#i32)
(by rw [IScalar.min_I32_eq]; norm_num; omega)
(by rw [IScalar.max_I32_eq]; norm_num; omega))
obtain ⟨p, hp, hpval⟩ := WP.spec_imp_exists
(IScalar.add_spec (x := b) (y := 1#i32)
(by rw [IScalar.min_I32_eq]; norm_num at hbval ⊢; omega)
(by rw [IScalar.max_I32_eq]; norm_num at hbval ⊢; omega))
exact ⟨b,p,hb,hp,by norm_num at hbval hpval; omega⟩
have mask52 (z : Std.U64) : (z &&& 4503599627370495#u64).val = z.val % 2^52 := by
change (z.bv &&& 4503599627370495#64).toNat = z.bv.toNat % 2^52
rw [show 4503599627370495#64 = 2#64^52 - 1#64 by decide,
BitVec.and_two_pow_sub_one_eq_mod]
simp
have fieldOr (a ef : Nat) (ha : a < 2^52)
(hef : ef * 2^52 < 2^64) : a ||| (ef * 2^52) = a + ef * 2^52 := by
have hland : a &&& (ef * 2^52) = 0 := by
apply Nat.eq_of_testBit_eq
intro j
rw [Nat.testBit_land, Nat.testBit_mul_two_pow]
by_cases hj : j < 52
· simp [hj]
· have haj : a.testBit j = false := by
apply Nat.testBit_eq_false_of_lt
exact lt_of_lt_of_le ha (Nat.pow_le_pow_right (by omega) (by omega))
simp [haj]
let av : BitVec 64 := BitVec.ofNat 64 a
let ev : BitVec 64 := BitVec.ofNat 64 (ef * 2^52)
have hlandBV : av &&& ev = 0#64 := by
apply BitVec.eq_of_toNat_eq
simp only [av, ev, BitVec.toNat_and, BitVec.toNat_ofNat]
rw [Nat.mod_eq_of_lt (ha.trans (by norm_num)), Nat.mod_eq_of_lt hef, hland]
calc
a ||| (ef * 2^52) = (av ||| ev).toNat := by
simp only [av, ev, BitVec.toNat_or, BitVec.toNat_ofNat]
rw [Nat.mod_eq_of_lt (ha.trans (by norm_num)), Nat.mod_eq_of_lt hef]
_ = (av + ev).toNat := by rw [BitVec.add_eq_or_of_and_eq_zero av ev hlandBV]
_ = a + ef * 2^52 := by
rw [BitVec.toNat_add_of_and_eq_zero hlandBV]
simp only [av, ev, BitVec.toNat_ofNat]
rw [Nat.mod_eq_of_lt (ha.trans (by norm_num)), Nat.mod_eq_of_lt hef]
have packExec (e : Std.I32) (m : Std.U64)
(hlo : -1022 <= e.val) (hhi : e.val <= 1023) :
∃ fp : num.imp.dec2flt.common.BiasedFp, pack e m = ok fp ∧
rawOf fp = (e.val + 1023 - (if m.val < 2^52 then 1 else 0)).toNat * 2^52 +
m.val % 2^52 := by
obtain ⟨b,p,hb,hp,hpval⟩ := biasOps e hlo (by omega)
have hpbound : 1 <= p.val ∧ p.val <= 2046 := by omega
have hpower : ∃ p' : Std.I32,
(if m < 4503599627370496#u64 then p - 1#i32 else ok p) = ok p' ∧
p'.val = e.val + 1023 - (if m.val < 2^52 then 1 else 0) ∧
0 <= p'.val ∧ p'.val <= 2046 := by
by_cases hm : m.val < 2^52
· have hm' : m < 4503599627370496#u64 := by
change m.val < 4503599627370496
norm_num at hm
exact hm
obtain ⟨p',hp',hv⟩ := WP.spec_imp_exists
(IScalar.sub_spec (x := p) (y := 1#i32)
(by rw [IScalar.min_I32_eq]; norm_num; omega)
(by rw [IScalar.max_I32_eq]; norm_num; omega))
refine ⟨p', by rw [if_pos hm']; exact hp', ?_, ?_, ?_⟩
all_goals norm_num at hv; try simp only [if_pos hm]
all_goals omega
· have hm' : ¬m < 4503599627370496#u64 := by
change ¬m.val < 4503599627370496
norm_num at hm
omega
refine ⟨p, by rw [if_neg hm'], ?_, by omega, by omega⟩
simp only [if_neg hm, Int.sub_zero]
exact hpval
obtain ⟨p',hp',hp'val,hp'lo,hp'hi⟩ := hpower
let fp : num.imp.dec2flt.common.BiasedFp :=
{ m := m &&& 4503599627370495#u64, p_biased := p' }
refine ⟨fp, ?_, ?_⟩
· unfold pack
simp only [hb, hp, bind_tc_ok,
show (1#u64 <<< 52#u32) = ok 4503599627370496#u64 by rfl,
hp', show (4503599627370496#u64 - 1#u64) = ok 4503599627370495#u64 by rfl]
rfl
· have hef : p'.val.toNat * 2^52 < 2^64 := by
have : p'.val.toNat <= 2046 := by omega
norm_num
omega
unfold rawOf
change Nat.lor (m &&& 4503599627370495#u64).val
(((p'.val.emod (2^64)).toNat * 2^52) % 2^64) = _
rw [mask52]
have hmod : p'.val.emod (2^64) = p'.val := by
exact Int.emod_eq_of_lt hp'lo (by norm_num; omega)
rw [hmod, Nat.mod_eq_of_lt hef]
change (m.val % 2^52) ||| (p'.val.toNat * 2^52) = _
rw [fieldOr (m.val % 2^52) p'.val.toNat (Nat.mod_lt _ (by positivity)) hef, hp'val]
omega
intro Vfun hY hX
classical
have h0pkg := P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi hinput
(by simpa [Vfun] using hY) (by simpa [Vfun] using hX)
rcases h0pkg with ⟨d0, e0, steps, h0, hsteps, he0lo, he0hi, hXlo,
hp0lo, hp0hi, hn0, hd0, hshape0, htrim0, hends0⟩
-- The source call starts from exactly the parsed record and the certified loop zero.
have hinput0 : d0.num_digits.val <= 768 /\
(forall b, b ∈ d0.digits.val.take d0.num_digits.val -> b.val < 10) /\
(exists h tail,
(d0.digits.val.take d0.num_digits.val).map (fun b => b.val) = h :: tail /\
1 <= h /\ h < 10 /\ (h :: tail).length = d0.num_digits.val) :=
⟨hn0, hd0, hshape0⟩
have h1pkg := P529_T1_Loop1Execution X Y d0 e0 hp0lo hp0hi he0lo
hinput0 (by simpa [Vfun] using hends0)
rcases h1pkg with ⟨d1, e1, bound, h1, hbound, hboundlo, hboundhi,
hp1, hn1, hheadlo, hheadhi, hn1cap, hd1, hshape1, hends1⟩
have hnorm := P529_T1_NormalizationBounds X Y d d0 d1 e0 e1
hpointLo hpointHi hinput h0 h1 (by simpa [Vfun] using hY)
(by simpa [Vfun] using hX)
rcases hnorm with ⟨_, hXY, hYbound, he1lo, he1hi⟩
have h2pkg := P529_T1_Loop2Execution X Y d1 e1 he1lo hp1
⟨hn1cap, hd1, hshape1⟩ (by simpa [Vfun] using hends1)
rcases h2pkg with ⟨es, e2, d2, sh, hdec, hesval, heslo, h2, he2val,
hshval, hshle, h2case, hp2lo, hp2hi, hn2, hd2, hshape2, htrim2, hends2⟩
have he2range : -1022 <= e2.val /\ e2.val <= 1260 := by
rw [he2val]
omega
have he1le : e1.val <= e2.val + 1 := by rw [he2val, hesval]; omega
have hYbound2 : Y / (2 : Real) ^ (e2.val + 1) <= 1 := by
have hYle : Y <= (2 : Real) ^ e1.val :=
(div_le_one (by positivity)).mp hYbound
have hpow : (2 : Real) ^ e1.val <= (2 : Real) ^ (e2.val + 1) :=
zpow_le_zpow_right₀ (by norm_num) he1le
exact (div_le_one (by positivity)).2 (hYle.trans hpow)
have h3pkg := P529_T1_FinalShiftCertificate X Y d2 e2 hp2lo hp2hi
⟨hn2, hd2, hshape2⟩ hYbound2 (by simpa using hends2)
rcases h3pkg with ⟨d3, h3, hp3lo, hp3hi, hn3, hd3, hshape3, htrim3,
hXpos3, hXhi3, hends3⟩
have hsepPkg := P529_T1_SeparationPackage X Y d d0 d1 d2 d3 e0 e1 es e2
hpointLo hpointHi hinput h0 h1 hdec h2 h3
(by simpa [Vfun] using hY) (by simpa [Vfun] using hX)
rcases hsepPkg with ⟨hhalfSep, hoddSep⟩
have hroundPkg := P529_T1_RoundArbitraryEndpoint d3
(X / (2 : Real) ^ (e2.val - 52)) (Y / (2 : Real) ^ (e2.val - 52))
hn3 hd3 (Or.inr ⟨hshape3, htrim3⟩) (by omega) (by positivity)
(by
have hbig : (2 : Real) ^ (53 : Nat) < (2 : Real) ^ (64 : Nat) - 1 / 2 := by norm_num
exact lt_trans hXhi3 hbig)
(by simpa using hends3)
(by
intro n
simpa using hhalfSep n)
rcases hroundPkg with ⟨m, hround, hmUpper, hmLower, hmTie⟩
have hnumNe : d.num_digits ≠ 0#usize := by
rcases hinput.2.2 with ⟨head, tail, hmap, hhead, hheadHi, hlen⟩
intro heq
have hv := congrArg (fun n : Std.Usize => n.val) heq
simp at hv
rw [← hlen] at hv
simp at hv
have hsmall : ¬ d.decimal_point < (-324)#i32 := by
intro hs
have hs' : d.decimal_point.val < -324 := by
simpa only [IScalar.lt_equiv] using hs
omega
have hlarge : ¬ d.decimal_point >= 310#i32 := by
intro hl
have hl' : (310 : Int) <= d.decimal_point.val := by
simpa only [IScalar.le_equiv] using hl
omega
have hsource : P9_T1_ActualDispatchOperations.slow s = suffix d2 e2 := by
have h0bind {R : Type}
(k : Std.Usize → Std.I32 → Bool → Array Std.U8 768#usize → Std.I32 →
Option num.imp.dec2flt.common.BiasedFp → Result R) :
(do
let (n,p,tr,a,e,r) ← 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
k n p tr a e r) = k d0.num_digits d0.decimal_point d0.truncated
d0.digits e0 none := by
simp only [h0, bind_tc_ok]
rfl
have h1bind {R : Type}
(k : Std.Usize → Std.I32 → Bool → Array Std.U8 768#usize → Std.I32 →
Option num.imp.dec2flt.common.BiasedFp → Result R) :
(do
let (n,p,tr,a,e,r) ← 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 e0 none
k n p tr a e r) = k d1.num_digits d1.decimal_point d1.truncated
d1.digits e1 none := by
simp only [h1, bind_tc_ok]
rfl
have h2bind {R : Type}
(k : num.imp.dec2flt.decimal_seq.DecimalSeq → Std.I32 → Result R) :
(do
let (a,e) ← num.imp.dec2flt.slow.parse_long_mantissa_loop2
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 es
k a e) = k d2 e2 := by
simp only [h2, bind_tc_ok]
rfl
change num.imp.dec2flt.slow.parse_long_mantissa
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 s = _
unfold num.imp.dec2flt.slow.parse_long_mantissa
rcases ParserExponentConstants with ⟨_, _, hsig, _, _, hinf, _, hmin, _⟩
change (do
let i ← F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS
i - 1#u32) = ok 52#u32 at hsig
change (do
let i ← (do
let i ← (do
let i ← (do
let i1 ← (do
let i ← F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS
i - 1#u32)
let i2 ← F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.BITS - i1
i2 - 1#u32)
let i1 ← 1#u32 <<< i
i1 - 1#u32)
i >>> 1#i32)
let i1 ← lift (UScalar.hcast .I32 i)
let i2 ← i1 - 1#i32
-.i2) = ok (-1022)#i32 at hmin
rw [hinf]
simp only [num.imp.dec2flt.common.BiasedFp.zero_pow2, bind_tc_ok]
rw [hparse]
simp only [bind_tc_ok, if_neg hnumNe, if_neg hsmall, if_neg hlarge]
rw [h0bind]
rw [h1bind]
rw [hdec]
simp only [bind_tc_ok]
rw [h2bind]
rw [hmin]
simp only [bind_tc_ok]
rw [hsig]
simp only [bind_tc_ok]
have hcast : lift (UScalar.cast .Usize 52#u32) = ok 52#usize := by
apply congrArg ok
apply UScalar.eq_of_val_eq
simp
have hadd : (52#usize + 1#usize) = ok 53#usize := by
obtain ⟨w, hw, hv⟩ := WP.spec_imp_exists
(UScalar.add_spec (x := 52#usize) (y := 1#usize) (by scalar_tac))
have heq : w = 53#usize := UScalar.eq_of_val_eq (by simpa using hv)
simpa only [heq] using hw
simp only [hcast, hadd, show (52#u32 + 1#u32) = ok 53#u32 by rfl,
show (1#u64 <<< 53#u32) = ok 9007199254740992#u64 by rfl, bind_tc_ok]
rfl
have hnormal : -1022 < e2.val -> (2 ^ 52 : Nat) <=
X / (2 : Real) ^ (e2.val - 52) := by
intro hnormalExp
have hd2eq : d2 = d1 := by
rcases h2case with hno | hyes
· exact hno.2.2.1
· have : e2.val = -1022 := hyes.2.2.2
omega
rcases hshape1 with ⟨head, tail, hmap, hheadlo, hheadhi, hlen⟩
have hval := P472_T1_DecimalValueBounds
((d1.digits.val.take d1.num_digits.val).map (fun b => b.val))
head tail hmap (by omega)
(by
intro q hq
rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩
exact hd1 b hb)
d1.decimal_point.val
have hlen1 : ((d1.digits.val.take d1.num_digits.val).map
(fun b => b.val)).length = d1.num_digits.val := by
rw [hmap]
simpa using hlen
have hVlower : (1 / 2 : Real) <=
((((d1.digits.val.take d1.num_digits.val).map
(fun b => b.val)).foldl (fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (d1.decimal_point.val - (d1.num_digits.val : Int)) := by
have hfirst := hval.1
rw [hlen1, hp1] at hfirst
norm_num at hfirst
have hfirst' : (head : Real) / 10 <=
((((d1.digits.val.take d1.num_digits.val).map
(fun b => b.val)).foldl (fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (d1.decimal_point.val - (d1.num_digits.val : Int)) := by
rw [hp1, show (0 : Int) - (d1.num_digits.val : Int) =
-(d1.num_digits.val : Int) by omega, zpow_neg, zpow_natCast]
simpa using hfirst
have hh : (5 : Real) <= head := by exact_mod_cast hheadlo
have hhalf : (1 / 2 : Real) <= (head : Real) / 10 := by nlinarith
exact hhalf.trans hfirst'
have hXbase : (1 / 2 : Real) <=
X / (2 : Real) ^ (e2.val + 1) := by
rcases hends2 with ⟨eta, u, hXeq, hYeq, heta, hlt, htr⟩
rw [hXeq, hd2eq]
have hlower' : (1 / 2 : Real) <=
(fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
(fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))) d1 := by
simpa [Vfun] using hVlower
linarith
have hscale : (2 : Real) ^ (53 : Nat) *
(X / (2 : Real) ^ (e2.val + 1)) =
X / (2 : Real) ^ (e2.val - 52) := by
rw [div_eq_mul_inv, div_eq_mul_inv, ← zpow_neg, ← zpow_neg]
calc
(2 : Real) ^ (53 : Nat) * (X * (2 : Real) ^ (-(e2.val + 1))) =
((2 : Real) ^ (53 : Nat) * (2 : Real) ^ (-(e2.val + 1))) * X := by ring
_ = (2 : Real) ^ (-(e2.val - 52)) * X := by
rw [← zpow_natCast (2 : Real) 53, ← zpow_add₀
(by norm_num : (2 : Real) ≠ 0)]
congr 1
norm_num
omega
_ = X * (2 : Real) ^ (-(e2.val - 52)) := by ring
have hmul := mul_le_mul_of_nonneg_left hXbase (by positivity : (0 : Real) <= 2 ^ (53 : Nat))
rw [hscale] at hmul
have hcast : (2 ^ 52 : Nat) = ((2 : Real) ^ (52 : Nat) : Real) := by norm_num
rw [hcast]
set_option maxHeartbeats 800000 in nlinarith
have hcarryWitness : ∃ (d4 : num.imp.dec2flt.decimal_seq.DecimalSeq) (m4 : Std.U64),
(2^53 <= m.val ->
num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d3 1#usize = ok d4 ∧
num.imp.dec2flt.decimal_seq.DecimalSeq.round d4 = ok m4) ∧
(2^53 <= m.val ->
(X / (2 : Real) ^ (e2.val - 52)) / 2 <= (m4.val : Real) + 1/2 ∧
(m4.val : Real) <= (X / (2 : Real) ^ (e2.val - 52)) / 2 + 1/2 ∧
((X / (2 : Real) ^ (e2.val - 52)) / 2 = (m4.val : Real) + 1/2 ∨
(X / (2 : Real) ^ (e2.val - 52)) / 2 = (m4.val : Real) - 1/2 ->
m4.val % 2 = 0)) := by
by_cases hc : 2^53 <= m.val
· obtain ⟨d4, m4, hs4, _, _, _, _, _, _, _, _, hr4, hu4, hl4, ht4⟩ :=
P529_T1_CarryRoundExecution
(X / (2 : Real) ^ (e2.val - 52))
(Y / (2 : Real) ^ (e2.val - 52)) d3 m hn3 hd3 hshape3 htrim3
(by omega) (le_of_lt hXpos3) hXhi3 hround hc hends3 hoddSep
exact ⟨d4, m4, fun _ => ⟨hs4,hr4⟩, fun _ => ⟨hu4,hl4,ht4⟩⟩
· exact ⟨d3, 0#u64, fun h => (hc h).elim, fun h => (hc h).elim⟩
obtain ⟨d4,m4,hcarryCall,hcarryNear⟩ := hcarryWitness
let raw : Nat :=
if 1024 <= e2.val then 2047 * 2^52
else if 2^53 <= m.val then
if 1023 <= e2.val then 2047 * 2^52
else (e2.val + 1024 - (if m4.val < 2^52 then 1 else 0)).toNat * 2^52 +
m4.val % 2^52
else (e2.val + 1023 - (if m.val < 2^52 then 1 else 0)).toNat * 2^52 +
m.val % 2^52
let Cert (r : Nat) : Prop :=
0 <= X ∧ ((r = 2047 * 2^52 ∧
(2 : Real) ^ (1024 : Nat) - (2 : Real) ^ (970 : Nat) <= X) ∨
(∃ j : Nat, j <= 2^53 ∧ r = j ∧
X <= (2^53 : Nat) * (2 : Real) ^ (-1074 : Int) ∧
X <= (j : Real) * (2 : Real) ^ (-1074 : Int) + (2 : Real) ^ (-1075 : Int) ∧
(j : Real) * (2 : Real) ^ (-1074 : Int) <= X + (2 : Real) ^ (-1075 : Int) ∧
(X = ((j : Real) + 1/2) * (2 : Real) ^ (-1074 : Int) ∨
X = ((j : Real) - 1/2) * (2 : Real) ^ (-1074 : Int) -> j % 2 = 0)) ∨
(∃ p j : Nat, 2 <= p ∧ p <= 2046 ∧ 2^52 <= j ∧ j <= 2^53 ∧
(p < 2046 ∨ j < 2^53) ∧ r = p * 2^52 + (j - 2^52) ∧
let delta : Real := (2 : Real) ^ ((p : Int) - 1075)
(2^52 : Nat) * delta <= X ∧ X <= (2^53 : Nat) * delta ∧
X < (2 : Real) ^ (1024 : Nat) - (2 : Real) ^ (970 : Nat) ∧
X <= (j : Real) * delta + delta/2 ∧ (j : Real) * delta <= X + delta/2 ∧
(X = ((j : Real) + 1/2) * delta ∨ X = ((j : Real) - 1/2) * delta ->
j % 2 = 0)))
have henc : Cert raw := P529_T1_EncodingArithmetic X e2.val m.val m4.val
he2range.1 he2range.2 hXpos3 hXhi3 hnormal hmUpper hmLower hmTie hcarryNear
have hrun : ∃ fp : num.imp.dec2flt.common.BiasedFp,
P9_T1_ActualDispatchOperations.slow s = ok fp ∧ rawOf fp = raw := by
obtain ⟨b,p,hb,hp,hpval⟩ := biasOps e2 he2range.1 (by omega)
have hfirst : (p >= 2047#i32) ↔ 1024 <= e2.val := by
change (2047 : Int) <= p.val ↔ 1024 <= e2.val
omega
by_cases he : 1024 <= e2.val
· refine ⟨{m := 0#u64,p_biased := 2047#i32}, ?_, ?_⟩
· rw [hsource]
dsimp only [suffix]
rw [hb]
simp only [bind_tc_ok, hp, if_pos (hfirst.mpr he)]
· simp only [raw, if_pos he]
change Nat.lor 0 (((2047 : Int).emod (2^64)).toNat * 2^52 % 2^64) = _
norm_num [Nat.lor_eq]
rfl
· have hpf : ¬p >= 2047#i32 := fun h => he (hfirst.mp h)
have hcguard : (m >= 9007199254740992#u64) ↔ 2^53 <= m.val := by
change 9007199254740992 <= m.val ↔ 2^53 <= m.val
norm_num
have hresume : P9_T1_ActualDispatchOperations.slow s =
(if m >= 9007199254740992#u64 then do
let d4 ← num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d3 1#usize
let e' ← e2 + 1#i32
let m4 ← num.imp.dec2flt.decimal_seq.DecimalSeq.round d4
let b' ← e' - (-1022)#i32
let p' ← b' + 1#i32
if p' >= 2047#i32 then ok {m := 0#u64,p_biased := 2047#i32}
else pack e' m4
else pack e2 m) := by
rw [hsource]
dsimp only [suffix]
rw [hb]
simp only [bind_tc_ok, hp, if_neg hpf, h3, hround]
by_cases hc : 2^53 <= m.val
· obtain ⟨hs4,hr4⟩ := hcarryCall hc
obtain ⟨e',he',he'val⟩ := WP.spec_imp_exists
(IScalar.add_spec (x := e2) (y := 1#i32)
(by rw [IScalar.min_I32_eq]; norm_num; omega)
(by rw [IScalar.max_I32_eq]; norm_num; omega))
have hev : e'.val = e2.val + 1 := by simpa using he'val
obtain ⟨b',p',hb',hp',hp'val⟩ := biasOps e' (by omega) (by omega)
have hsecond : (p' >= 2047#i32) ↔ 1023 <= e2.val := by
change (2047 : Int) <= p'.val ↔ 1023 <= e2.val
omega
have hresume4 : P9_T1_ActualDispatchOperations.slow s =
(if p' >= 2047#i32 then ok {m := 0#u64,p_biased := 2047#i32}
else pack e' m4) := by
rw [hresume, if_pos (hcguard.mpr hc), hs4]
simp only [bind_tc_ok, he', hr4, hb', hp']
by_cases hec : 1023 <= e2.val
· refine ⟨{m := 0#u64,p_biased := 2047#i32}, ?_, ?_⟩
· rw [hresume4, if_pos (hsecond.mpr hec)]
· simp only [raw, if_neg he, if_pos hc, if_pos hec]
change Nat.lor 0 (((2047 : Int).emod (2^64)).toNat * 2^52 % 2^64) = _
norm_num [Nat.lor_eq]
rfl
· obtain ⟨fp,hpack,hraw⟩ := packExec e' m4 (by omega) (by omega)
refine ⟨fp, ?_, ?_⟩
· rw [hresume4, if_neg (fun h => hec (hsecond.mp h)), hpack]
· simp only [raw, if_neg he, if_pos hc, if_neg hec]
rw [hraw, hev]
congr 3 <;> omega
· obtain ⟨fp,hpack,hraw⟩ := packExec e2 m he2range.1 (by omega)
refine ⟨fp, ?_, ?_⟩
· rw [hresume, if_neg (fun h => hc (hcguard.mp h)), hpack]
· simpa only [raw, if_neg he, if_neg hc] using hraw
obtain ⟨fp,hcall,hraw⟩ := hrun
have hcert : Cert (rawOf fp) := by rw [hraw]; exact henc
refine ⟨fp,hcall,hcert,?_⟩
have hbound : rawOf fp <= 2047 * 2^52 := by
rcases hcert.2 with htop | hlow | hnormal
· omega
· obtain ⟨j,hj,hr,_⟩ := hlow
rw [hr]
norm_num at hj ⊢
omega
· obtain ⟨p,j,_,hp,_,hj,_,hr,_⟩ := hnormal
rw [hr]
norm_num at hp hj ⊢
omega
have hrawlt : rawOf fp < 2^64 := lt_of_le_of_lt hbound (by norm_num)
let magnitude : F64 := U64.ofNatCore (rawOf fp) hrawlt
have hasm : DecimalGoalVocabularyDefault.assembledWord fp magnitude := by
change magnitude.val = rawOf fp
exact U64.ofNatCore_val_eq hrawlt
exact ⟨magnitude,hasm,Binary64NearestEvenAssembly X fp magnitude hcert hasm⟩
)
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
- Binary64NearestEvenAssembly
- ModelU64BitAnd
- ModelU64BitOr
- ModelU64Shl
- SlowLoop0Execution
- CarryRoundExecution
All 16 entries
- Binary64NearestEvenAssembly
- ModelU64BitAnd
- ModelU64BitOr
- ModelU64Shl
- SlowLoop0Execution
- CarryRoundExecution
- EncodingArithmetic
- FinalShiftCertificate
- Loop1Execution
- Loop2Execution
- NormalizationBounds
- RoundArbitraryEndpoint
- SeparationPackage
- ActualDispatchOperations
- ParserExponentConstants
- num imp dec2flt decimal seq parse decimal seq
Inspect related source (198)
- parse_decimal_seq · dec2flt/decimal_seq.rs:288 Program Rust
- parse_decimal_seq_loop0 · dec2flt/decimal_seq.rs:296 Program Rust
- body · dec2flt/decimal_seq.rs:296 Program Rust
More program dependencies (156)
- parse_decimal_seq_loop1 · dec2flt/decimal_seq.rs:368 Program Rust
- body · dec2flt/decimal_seq.rs:368 Program Rust
- parse_decimal_seq_loop2 · dec2flt/decimal_seq.rs:309 Program Rust
- body · dec2flt/decimal_seq.rs:309 Program Rust
- parse_decimal_seq_loop3 · dec2flt/decimal_seq.rs:313 Program Rust
- body · dec2flt/decimal_seq.rs:313 Program Rust
- parse_decimal_seq_loop4 · dec2flt/decimal_seq.rs:368 Program Rust
- body · dec2flt/decimal_seq.rs:368 Program Rust
- parse_decimal_seq_loop5 · dec2flt/decimal_seq.rs:313 Program Rust
- body · dec2flt/decimal_seq.rs:313 Program Rust
- parse_decimal_seq_loop6 · dec2flt/decimal_seq.rs:368 Program Rust
- body · dec2flt/decimal_seq.rs:368 Program Rust
- parse_decimal_seq_loop7 · dec2flt/decimal_seq.rs:368 Program Rust
- body · dec2flt/decimal_seq.rs:368 Program Rust
- Dec2flt_modelNumImpDec2fltLemireU64 · dec2flt/mod.rs:217 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
- read_u64 · dec2flt/common.rs:22 Program Rust
- write_u64 · dec2flt/common.rs:29 Program Rust
- BiasedFp · dec2flt/common.rs:56 Program Rust
- is_8digits · dec2flt/common.rs:44 Program Rust
- dec2flt_with_trace · dec2flt/mod.rs:355 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:22 Program Rust
- default · dec2flt/decimal_seq.rs:34 Program Rust
- MAX_DIGITS · dec2flt/decimal_seq.rs:64 Program Rust
- MAX_DIGITS_WITHOUT_OVERFLOW · dec2flt/decimal_seq.rs:67 Program Rust
- round · dec2flt/decimal_seq.rs:97 Program Rust
- round_loop · dec2flt/decimal_seq.rs:107 Program Rust
- body · dec2flt/decimal_seq.rs:107 Program Rust
- count_trailing_zeros · dec2flt/decimal_seq.rs:236 Program Rust
- count_trailing_zeros_loop · dec2flt/decimal_seq.rs:240 Program Rust
- body · dec2flt/decimal_seq.rs:240 Program Rust
- final_decimal_point · dec2flt/decimal_seq.rs:269 Program Rust
- parse_digits_into_seq · dec2flt/decimal_seq.rs:257 Program Rust
- parse_digits_into_seq_loop · dec2flt/decimal_seq.rs:259 Program Rust
- body · dec2flt/decimal_seq.rs:259 Program Rust
- parse_scientific · dec2flt/parse.rs:121 Program Rust
- parse_scientific_loop · dec2flt/parse.rs:145 Program Rust
- body · dec2flt/parse.rs:145 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
- MAX_EXPONENT_DISGUISED_FAST_PATH · dec2flt/mod.rs:220 Program Rust
- MAX_EXPONENT_FAST_PATH · dec2flt/mod.rs:219 Program Rust
- from_u64 · dec2flt/mod.rs:263 Program Rust
- pow10_fast_path · dec2flt/mod.rs:222 Program Rust
- Dec2flt_modelNumImpTraitsFloatExtU64 · traits.rs:339 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
- 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
- default · dec2flt/mod.rs:128 Program Rust
- default · dec2flt/mod.rs:121 Program Rust
- biased_fp_to_float · dec2flt/mod.rs:282 Program Rust
- eq · dec2flt/common.rs:55 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- try_fast_path · dec2flt/decimal.rs:59 Program Rust
- DECIMAL_POINT_RANGE · dec2flt/decimal_seq.rs:68 Program Rust
- right_shift · dec2flt/decimal_seq.rs:176 Program Rust
- right_shift_loop0 · dec2flt/decimal_seq.rs:181 Program Rust
- body · dec2flt/decimal_seq.rs:181 Program Rust
- right_shift_loop0_loop0 · dec2flt/decimal_seq.rs:191 Program Rust
- body · dec2flt/decimal_seq.rs:191 Program Rust
- right_shift_loop1 · dec2flt/decimal_seq.rs:210 Program Rust
- body · dec2flt/decimal_seq.rs:210 Program Rust
- right_shift_loop2 · dec2flt/decimal_seq.rs:217 Program Rust
- body · dec2flt/decimal_seq.rs:217 Program Rust
- try_add_digit · dec2flt/decimal_seq.rs:74 Program Rust
- compute_float · dec2flt/lemire.rs:26 Program Rust
- parse_inf_nan · dec2flt/parse.rs:244 Program Rust
- parse_number · dec2flt/parse.rs:234 Program Rust
- pfe_empty · dec2flt/mod.rs:270 Program Rust
- pfe_invalid · dec2flt/mod.rs:277 Program Rust
- 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
- 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
- CastInto · traits.rs:18 Program Rust
- Float · traits.rs:74 Program Rust
- FloatExt · traits.rs:170 Program Rust
- Int · traits.rs:27 Program Rust
- from_u64_bits · traits.rs:341 Program Rust
- integer_decode · traits.rs:348 Program Rust
- Dec2flt_modelNumImpTraitsCastIntoI16 · traits.rs:45 Program Rust
- ONE · traits.rs:53 Program Rust
- ZERO · traits.rs:52 Program Rust
- zero_pow2 · dec2flt/common.rs:66 Program Rust
- can_use_fast_path · dec2flt/decimal.rs:42 Program Rust
- INT_POW10 · dec2flt/decimal.rs:8 Program Rust
- left_shift · dec2flt/decimal_seq.rs:130 Program Rust
- left_shift_loop0 · dec2flt/decimal_seq.rs:139 Program Rust
- body · dec2flt/decimal_seq.rs:139 Program Rust
- left_shift_loop1 · dec2flt/decimal_seq.rs:153 Program Rust
- body · dec2flt/decimal_seq.rs:153 Program Rust
- trim · dec2flt/decimal_seq.rs:83 Program Rust
- trim_loop · dec2flt/decimal_seq.rs:92 Program Rust
- body · dec2flt/decimal_seq.rs:92 Program Rust
- number_of_digits_decimal_left_shift · dec2flt/decimal_seq.rs:375 Program Rust
- TABLE · dec2flt/decimal_seq.rs:377 Program Rust
- TABLE_POW5 · dec2flt/decimal_seq.rs:386 Program Rust
- number_of_digits_decimal_left_shift_loop · dec2flt/decimal_seq.rs:441 Program Rust
- body · dec2flt/decimal_seq.rs:441 Program Rust
- set_precision · dec2flt/fpu.rs:99 Program Rust
- compute_product_approx · dec2flt/lemire.rs:134 Program Rust
- power · dec2flt/lemire.rs:121 Program Rust
- parse_partial_number · dec2flt/parse.rs:164 Program Rust
- MAX_SHIFT · dec2flt/slow.rs:28 Program Rust
- NUM_POWERS · dec2flt/slow.rs:29 Program Rust
- POWERS · dec2flt/slow.rs:30 Program Rust
- call · dec2flt/slow.rs:33 Program Rust
- offset_from · dec2flt/common.rs:34 Program Rust
- cast · traits.rs:46 Program Rust
- full_multiplication · dec2flt/lemire.rs:126 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
- 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
- closure · dec2flt/slow.rs:33 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
- MIN_19DIGIT_INT · dec2flt/parse.rs:8 Program Rust
- parse_8digits · dec2flt/parse.rs:18 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
- MASK · dec2flt/parse.rs:19 Program Rust
- MUL1 · dec2flt/parse.rs:20 Program Rust
- MUL2 · dec2flt/parse.rs:21 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
- 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
- CoreMarkerCopy · core/src/marker.rs:57 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.P340_T1_selected_target_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
- Binary64AdjacentNormalValues
- Binary64FiniteMagnitudeStrictMono
- Binary64Model
- Binary64ModelDefault
- Binary64NearestEvenAssembly
- DecimalDigitLexScale
All 208 entries
- Binary64AdjacentNormalValues
- Binary64FiniteMagnitudeStrictMono
- Binary64Model
- Binary64ModelDefault
- Binary64NearestEvenAssembly
- DecimalDigitLexScale
- DecimalGoalVocabulary
- DecimalGoalVocabularyDefault
- DecimalLeftShiftDigitGrowth
- DecimalLeftShiftFirstLoopSemantics
- DecimalLeftShiftLoop1Execution
- DecimalLeftShiftLoopLex
- DecimalLeftShiftSecondLoopSemantics
- DecimalLeftShiftTableCertificate
- DecimalLexeme
- DecimalRightShiftU64DyadicBridge
- DecimalSeqFractionalDigitInterval
- DecimalSeqLeftShiftRecordSemantics
- DecimalSeqRoundLoopPrefixCore
- DecimalSeqRoundLoopValue
- DecimalSeqTrimSemantics
- F64
- F64 Insts CoreCloneClone
- F64 Insts CoreMarkerCopy
- F64 Insts CoreOpsArithDivF64F64
- F64 Insts CoreOpsArithMulF64F64
- F64 Insts CoreOpsArithNegF64
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64 MAX EXPONENT DISGUISED FAST PATH
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64 MAX EXPONENT FAST PATH
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64 pow10 fast path
- F64 Insts Dec2flt modelNumImpTraitsFloatExtU64
- F64 Insts Dec2flt modelNumImpTraitsFloatExtU64 from u64 bits
- F64 Insts Dec2flt modelNumImpTraitsFloatExtU64 integer decode
- 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
- NearestEvenOrderedGrid
- NumberHelperDecimalPrefixInterval
- DecimalRightShiftFinalLoopSemantics
- DecimalRightShiftLoop0Execution
- DecimalRightShiftMainLoopSemantics
- DecimalRightShiftPrefixLoopSemantics
- DecimalSeqDyadicShiftSemantics
- DecimalSeqRightShiftRecordSemantics
- DecimalValueBounds
- LoopZeroRightShiftTransport
- RightLoopStep
- RightPrefixLengthBounds
- RightShiftCanonical
- SlowLoop0Execution
- CarryRoundExecution
- EncodingArithmetic
- FinalShiftCertificate
- LeftHistoryBoundary
- LeftLeadingProgress
- LeftLoopStep
- LeftShiftCertificate
- Loop1Execution
- Loop2Execution
- NormalizationBounds
- ReachableCapacity
- RegularSlowExecution
- RightBoundaryTransport
- RightHistoryBoundary
- RoundArbitraryEndpoint
- SeparationPackage
- GridAlignment
- GridBoundaryRetained
- LeftBoundaryTransport
- DecimalFoldBounds
- LeftShiftPointGrowth
- PointZeroGrowth
- SelectedLeftGrowth
- ExponentLowerBound
- PowerGridAlignment
- ResultLoopBackward
- LeftCoefficientTransport
- LeftHistoryInvariant
- LeftStepPotential
- CoefficientGridAlignment
- DecimalBinaryExponentBound
- LeftLoopBudgetTransition
- ActualDispatchOperations
- DispatchOperations
- ParserExponentConstants
- PositiveScaleErrorTransport
- Preamble
- ResultLoopPartial
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice write u64
- SlowShiftSelectorCertificate
- 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 Lemire
- num imp dec2flt Lemire MAX MANTISSA FAST PATH default
- num imp dec2flt biased fp to float
- 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 Decimal can use fast path
- num imp dec2flt decimal Decimal try fast path
- num imp dec2flt decimal INT POW10
- 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 final decimal point
- 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 seq
- num imp dec2flt decimal seq parse digits into seq
- num imp dec2flt fpu fpu precision set precision
- num imp dec2flt lemire compute float
- num imp dec2flt lemire compute product approx
- num imp dec2flt lemire full multiplication
- num imp dec2flt lemire power
- num imp dec2flt parse MIN 19DIGIT INT
- num imp dec2flt parse adjust many digit count
- num imp dec2flt parse parse 8digits
- num imp dec2flt parse parse 8digits MASK
- num imp dec2flt parse parse 8digits MUL1
- num imp dec2flt parse parse 8digits MUL2
- num imp dec2flt parse parse inf nan
- num imp dec2flt parse parse many digits
- num imp dec2flt parse parse number
- num imp dec2flt parse parse partial number
- num imp dec2flt parse parse scientific
- num imp dec2flt parse try parse 19digits
- num imp dec2flt parse try parse digits
- 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 dec2flt table LARGEST POWER OF FIVE
- num imp dec2flt table POWER OF FIVE 128
- num imp dec2flt table SMALLEST POWER OF FIVE
- num imp traits CastInto
- num imp traits Float
- num imp traits FloatExt
- 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": "P529_T1_RegularSlowExecution",
"closure_version": "patch_c_v1",
"active_decl_hash": "ef3c493c67a53e10afa8396a9e55049c2ea144e8e7419bc9dcaeb412aac68682",
"active_statement_hash": "aca95b66de9a5d15f61f854865ff0090daf273031e4447fe5303f60fc478f2bc",
"kernel_axioms": [
"Classical.choice",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-200",
"boundary_theorems": {},
"strict_theorem_deps": {
"Binary64NearestEvenAssembly": "028531442bb8a66c",
"P472_T1_DecimalValueBounds": "4b5c924b5d52bc9d",
"P495_T1_SlowLoop0Execution": "5a1e49d921a1825a",
"P529_T1_CarryRoundExecution": "026983daf0ccba18",
"P529_T1_EncodingArithmetic": "f35d99c23b5ee50f",
"P529_T1_FinalShiftCertificate": "6a5bd46c366c9837",
"P529_T1_Loop1Execution": "da66766413255a0f",
"P529_T1_Loop2Execution": "e8eeb6e19acff10b",
"P529_T1_NormalizationBounds": "deb4bf7513f18e80",
"P529_T1_RoundArbitraryEndpoint": "c9f717a9d35879a8",
"P529_T1_SeparationPackage": "b45bf4832efd5912",
"ParserExponentConstants": "e2a30a7b0c5e9c91",
"num_imp_dec2flt_common_BiasedFp_zero_pow2": "0f3e5cc6a65d812e",
"num_imp_dec2flt_slow_parse_long_mantissa": "0eb6fb2627d0ff5c",
"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": "71a18a6c119a3cdc",
"F64": "ec4e25fbaf4e11d4",
"F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
"F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS": "d9fd91641cb78c5e",
"F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
"P9_T1_ActualDispatchOperations": "d8bf51ebbbf153ac",
"P9_T1_DispatchOperations": "9a657a317bca572b",
"num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
"num_imp_dec2flt_common_BiasedFp_zero_pow2": "0f99ae12c6707137",
"num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
"num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "fd298e37d5ae4f86",
"num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "1aaf1bb11c0b6a49",
"num_imp_dec2flt_decimal_seq_DecimalSeq_round": "8ea3c058fea09978",
"num_imp_dec2flt_decimal_seq_parse_decimal_seq": "f7442f2664cfd5f2",
"num_imp_dec2flt_slow_parse_long_mantissa": "f4b1825aa46c08b9",
"num_imp_traits_Float": "426bf608517697dc"
}
}Prose assessment
{
"label": "Recorded Sound: VerifierPass",
"assessment_status": "VerifierPass",
"fingerprint_relation": "matches current fingerprint",
"assessment_fingerprint": "sound-v2:cc8aa4c826df66e85d7530a87bed05135ee4b7fdc84ae7f07bfef775e479e6da",
"current_fingerprint": "sound-v2:cc8aa4c826df66e85d7530a87bed05135ee4b7fdc84ae7f07bfef775e479e6da",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}