Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Normal first normalization loop with fixed endpoints
Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.P495_T1_RightLoopStep
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P495_T1_SlowLoop0Execution]
theorem P495_T1_SlowLoop0Execution (X Y : Real)
(d : num.imp.dec2flt.decimal_seq.DecimalSeq)
(hpointLo : -324 <= d.decimal_point.val)
(hpointHi : d.decimal_point.val < 310)
(hinput : d.num_digits.val <= 768 /\
(forall b, b ∈ d.digits.val.take d.num_digits.val -> b.val < 10) /\
(exists h tail,
(d.digits.val.take d.num_digits.val).map (fun b => b.val) = h :: tail /\
1 <= h /\ h < 10 /\ (h :: tail).length = d.num_digits.val)) :
let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
(fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
Y = V d + (10 : Real) ^ (d.decimal_point.val - (768 : Int)) ->
(exists eta : Real, X = V d + eta /\ 0 <= eta /\
eta < (10 : Real) ^ (d.decimal_point.val - (768 : Int)) /\
(d.truncated = true <-> 0 < eta)) ->
exists (d0 : num.imp.dec2flt.decimal_seq.DecimalSeq)
(exp0 : Std.I32) (steps : Nat),
num.imp.dec2flt.slow.parse_long_mantissa_loop0
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
d.num_digits d.decimal_point d.truncated d.digits 0#i32 none =
ok (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits, exp0, none) /\
steps <= 21 /\ 0 <= exp0.val /\ exp0.val <= (60 : Int) * steps /\
(10 : Real) ^ (-325 : Int) <= X /\
-324 <= d0.decimal_point.val /\ d0.decimal_point.val <= 0 /\
d0.num_digits.val <= 768 /\
(forall b, b ∈ d0.digits.val.take d0.num_digits.val -> b.val < 10) /\
(exists h tail,
(d0.digits.val.take d0.num_digits.val).map (fun b => b.val) = h :: tail /\
1 <= h /\ h < 10 /\ (h :: tail).length = d0.num_digits.val) /\
(steps = 0 \/ d0.digits.val[d0.num_digits.val - 1]? ≠ some 0#u8) /\
(exists eta0 u0 : Real,
X / (2 : Real) ^ exp0.val = V d0 + eta0 /\
Y / (2 : Real) ^ exp0.val = V d0 + u0 /\
0 <= eta0 /\ eta0 < u0 /\ (d0.truncated = true <-> 0 < eta0)) := by
Proof
Natural-language proof
The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.
Explanatory prose status
Prose retained as authored. The explanatory prose is preserved as it stood when captured.
Proof
Lean proof
exact (set_option maxHeartbeats 1600000 in by
dsimp only
intro hY hX
classical
rcases hinput with ⟨hnum, hdigit, hshape⟩
rcases hshape with ⟨h, tail, hmap, hhle, hhh, hlen⟩
let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
(fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
let eta := X - V d
let u := (10 : Real) ^ (d.decimal_point.val - (768 : Int))
have hXeq : X = V d + eta := by dsimp [eta]; ring
have heta0 : 0 <= eta := by
rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
rw [heq] at hXeq
have : eta = eta' := by linarith
simpa [this] using hlo
have hetaU : eta < u := by
rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
have : eta = eta' := by linarith [hXeq, heq]
simpa [u] using (by simpa [this] using hhi)
have hsticky : d.truncated = true ↔ 0 < eta := by
rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
have : eta = eta' := by linarith [hXeq, heq]
simpa [this] using htr
have huPos : 0 < u := by
dsimp [u]
exact zpow_pos (by norm_num) _
have hYeq : Y = V d + u := by simpa [u, V] using hY
have hpupper : d.decimal_point.val ≤ 309 := by omega
have hXlower : (10 : Real) ^ (-325 : Int) ≤ X := by
have hv := P472_T1_DecimalValueBounds
((d.digits.val.take d.num_digits.val).map (fun b => b.val)) h tail
(by simpa [hmap]) hhle
(by intro q hq; rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩; exact hdigit b hb)
d.decimal_point.val
dsimp at hv
have hlen' :
((d.digits.val.take d.num_digits.val).map (fun b => b.val)).length =
d.num_digits.val := by
rw [hmap]
simpa using hlen
have hnumNat : d.num_digits.val ≤ 768 := by exact_mod_cast hnum
have hlenMap :
(List.take d.num_digits.val (List.map (fun b => b.val) d.digits.val)).length =
d.num_digits.val := by
simp [List.length_take, Nat.min_eq_left hnumNat]
have hpow : (10 : Real) ^ (-325 : Int) ≤
(h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
have hh : (10 : Real) ^ (-325 : Int) ≤
(10 : Real) ^ (d.decimal_point.val - 1) := by
apply zpow_right_mono₀ (by norm_num : (1 : Real) ≤ 10)
omega
have h10pos : 0 < (10 : Real) ^ (d.decimal_point.val - 1) :=
zpow_pos (by norm_num) _
calc
(10 : Real) ^ (-325 : Int) ≤ (10 : Real) ^ (d.decimal_point.val - 1) := hh
_ ≤ (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
have hhleR : (1 : Real) ≤ (h : Real) := by exact_mod_cast hhle
nlinarith [h10pos, hhleR]
have hVlo : (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) ≤ V d := by
have htmp := hv.1
change (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) ≤
(((((d.digits.val.take d.num_digits.val).map (fun b => b.val)).foldl
(fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)))
rw [List.map_take] at htmp
rw [hlenMap] at htmp
rw [List.map_take]
exact htmp
rw [hXeq]
linarith
-- The loop invariant records a completed-shift counter separately from
-- the exported existential bound witness.
let recOf := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
({ num_digits := s.1, decimal_point := s.2.1,
truncated := s.2.2.1, digits := s.2.2.2.1 } :
num.imp.dec2flt.decimal_seq.DecimalSeq)
let rank := fun (p : Int) (headOne : Bool) =>
if p <= 0 then 0 else 2 * p.toNat + (if headOne then 0 else 1)
let measure := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
rank (recOf s).decimal_point.val
(decide (((((recOf s).digits.val.take (recOf s).num_digits.val).map
(fun b => b.val)).headD 0) = 1))
have rank_step (p p' : Int) (headOne headOne' : Bool)
(hp : 1 ≤ p) (hp' : 0 ≤ p')
(hstep : (19 ≤ p ∧ (p' = p - 18 ∨ p' = p - 19)) ∨
(2 ≤ p ∧ p ≤ 18 ∧ (p' = 0 ∨ p' = 1)) ∨
(p = 1 ∧ headOne = true ∧ p' = 0) ∨
(p = 1 ∧ headOne = false ∧
(p' = 0 ∨ (p' = 1 ∧ headOne' = true)))) :
rank p' headOne' < rank p headOne := by
rcases hstep with h | h | h | h
all_goals cases headOne <;> cases headOne'
all_goals simp_all [rank]
all_goals split_ifs <;> omega
let Inv := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
∃ j : Nat,
s.2.2.2.2.2 = none ∧
-324 ≤ (recOf s).decimal_point.val ∧ (recOf s).decimal_point.val < 310 ∧
0 ≤ s.2.2.2.2.1.val ∧
s.2.2.2.2.1.val ≤ 60 * (j : Int) ∧
(recOf s).num_digits.val ≤ 768 ∧
(∀ b, b ∈ (recOf s).digits.val.take (recOf s).num_digits.val -> b.val < 10) ∧
(∃ h tail,
((recOf s).digits.val.take (recOf s).num_digits.val).map
(fun b => b.val) = h :: tail ∧ 1 ≤ h ∧ h < 10 ∧
(h :: tail).length = (recOf s).num_digits.val) ∧
(j = 0 ∨ (recOf s).digits.val[(recOf s).num_digits.val - 1]? ≠ some 0#u8) ∧
(∃ alpha v : Real,
X / (2 : Real) ^ s.2.2.2.2.1.val = V (recOf s) + alpha ∧
Y / (2 : Real) ^ s.2.2.2.2.1.val = V (recOf s) + v ∧
0 ≤ alpha ∧ alpha < v ∧
((recOf s).truncated = true ↔ 0 < alpha)) ∧
((19 ≤ (recOf s).decimal_point.val -> 18 * (j : Int) +
(recOf s).decimal_point.val ≤ 309) ∧
(2 ≤ (recOf s).decimal_point.val ->
(recOf s).decimal_point.val ≤ 18 -> j ≤ 17) ∧
((recOf s).decimal_point.val = 1 ->
(((((recOf s).digits.val.take (recOf s).num_digits.val).map
(fun b => b.val)).headD 0) = 1 -> j ≤ 19)) ∧
((recOf s).decimal_point.val = 1 ->
(((((recOf s).digits.val.take (recOf s).num_digits.val).map
(fun b => b.val)).headD 0) ≠ 1 -> j ≤ 18)) ∧
((recOf s).decimal_point.val ≤ 0 -> j ≤ 20))
let Post := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
Inv s ∧ (recOf s).decimal_point.val ≤ 0
let s0 := (d.num_digits, d.decimal_point, d.truncated, d.digits,
(0#i32 : Std.I32), (none : Option num.imp.dec2flt.common.BiasedFp))
have hstart : Inv s0 := by
simp only [Inv, recOf, s0]
refine ⟨0, trivial, ?_⟩
constructor
· exact hpointLo
constructor
· exact hpointHi
constructor
· norm_num
constructor
· norm_num
constructor
· exact hnum
constructor
· exact hdigit
constructor
· exact ⟨h, tail, hmap, hhle, hhh, hlen⟩
constructor
· exact Or.inl rfl
constructor
· refine ⟨eta, u, ?_⟩
constructor
· simpa [V] using hXeq
constructor
· simpa [V] using hYeq
constructor
· exact heta0
constructor
· exact hetaU
· exact hsticky
constructor
· intro hp
omega
constructor
· intro hp hp18
omega
constructor
· intro hp
omega
constructor
· intro hp
omega
· intro hp
omega
have hloop : Aeneas.Std.WP.spec
(num.imp.dec2flt.slow.parse_long_mantissa_loop0
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
d.num_digits d.decimal_point d.truncated d.digits 0#i32 none) Post := by
unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0
apply Aeneas.Std.loop.spec_decr_nat measure Inv Post
(fun s => num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
s.1 s.2.1 s.2.2.1 s.2.2.2.1 s.2.2.2.2.1 s.2.2.2.2.2)
s0
· intro s hs
rcases s with ⟨n, p, tr, a, e, res⟩
simp only [Prod.fst, Prod.snd] at hs ⊢
have hsInv := hs
rcases hs with ⟨j, hres, hpLo, hpHi, heLo, heHi, hn, hd, hshape,
htrim, hends, hbudgets⟩
let cur : num.imp.dec2flt.decimal_seq.DecimalSeq :=
{ num_digits := n, decimal_point := p, truncated := tr, digits := a }
have hresNone : res = none := by simpa using hres
have hshape' := hshape
rcases hshape with ⟨head, tail, hmap', hheadLo, hheadHi, hlen'⟩
have hbLarge : 19 ≤ p.val -> 18 * (j : Int) + p.val ≤ 309 := by
intro hl
have h := hbudgets.1 (by simpa [cur, recOf] using hl)
simpa [cur, recOf] using h
have hbMedium : 2 ≤ p.val -> p.val ≤ 18 -> j ≤ 17 := by
intro hm hm18
exact hbudgets.2.1 (by simpa [cur, recOf] using hm)
(by simpa [cur, recOf] using hm18)
have hbHeadOne : p.val = 1 -> head = 1 -> j ≤ 19 := by
intro hp1 hh
have hh' :
(((a.val.take n.val).map (fun b => b.val)).headD 0) = 1 := by
have hh'' := congrArg (fun xs : List Nat => xs.headD 0) hmap'
have hhval :
(((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
simpa using hh''
rw [hhval]
exact hh
exact hbudgets.2.2.1 (by simpa [cur, recOf] using hp1)
(by simpa [cur, recOf, List.headD, hmap'] using hh')
have hbHeadOther : p.val = 1 -> head ≠ 1 -> j ≤ 18 := by
intro hp1 hh
have hh' :
(((a.val.take n.val).map (fun b => b.val)).headD 0) ≠ 1 := by
have hh'' := congrArg (fun xs : List Nat => xs.headD 0) hmap'
have hhval :
(((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
simpa using hh''
rw [hhval]
exact hh
exact hbudgets.2.2.2.1 (by simpa [cur, recOf] using hp1)
(by simpa [cur, recOf, List.headD, hmap'] using hh')
have hbodySpec :
num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
n p tr a e res
⦃ r => match r with
| done y => Post y
| cont y => Inv y ∧ measure y < measure (n, p, tr, a, e, res) ⦄ := by
by_cases hp : p > 0#i32
· have hpPos : 0 < p.val := by simpa using hp
have hpInt : 1 ≤ p.val := by omega
have hj : j ≤ 20 := by
by_cases hl : 19 ≤ p.val
· have hb := hbudgets.1 (by simpa [cur, recOf] using hl)
have hjInt : (j : Int) ≤ 20 := by
have : 18 * (j : Int) + p.val ≤ 309 := hb
omega
exact_mod_cast hjInt
· by_cases hm : 2 ≤ p.val
· have hb := hbudgets.2.1 (by simpa [cur, recOf] using hm)
(by have hm18 : p.val ≤ 18 := by omega
simpa [cur, recOf] using hm18)
omega
· have hone : p.val = 1 := by omega
by_cases hheadone : head = 1
· have hheadVal :
(List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = head := by
rw [← List.map_take, hmap']
rfl
have hheadOne :
(List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = 1 := by
rw [hheadVal]
exact hheadone
have hb := hbudgets.2.2.1 (by simpa [cur, recOf] using hone)
(by simpa [cur, recOf, List.headD] using hheadOne)
omega
· have hheadVal :
(List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = head := by
rw [← List.map_take, hmap']
rfl
have hheadNotOne :
(List.take n.val (List.map (fun b => b.val) a.val)).headD 0 ≠ 1 := by
rw [hheadVal]
exact hheadone
have hb := hbudgets.2.2.2.1 (by simpa [cur, recOf] using hone)
(by simpa [cur, recOf, List.headD] using hheadNotOne)
omega
have heHi1260 : e.val ≤ 1260 := by
have hjInt : (j : Int) ≤ 20 := by exact_mod_cast hj
have he1200 : e.val ≤ 60 * 20 := by
calc
e.val ≤ 60 * (j : Int) := heHi
_ ≤ 60 * 20 := by nlinarith
omega
rcases hends with ⟨alpha, v, hXend, hYend, halpha, hlt, hsticky'⟩
have hinputCur : n.val ≤ 768 ∧
(∀ b, b ∈ a.val.take n.val -> b.val < 10) ∧
(∃ hh tt, (a.val.take n.val).map (fun b => b.val) = hh :: tt ∧
1 ≤ hh ∧ hh < 10 ∧ (hh :: tt).length = n.val) := by
simpa [cur, recOf] using And.intro hn (And.intro hd hshape')
have hstep := P495_T1_RightLoopStep
(X / (2 : Real) ^ e.val) (Y / (2 : Real) ^ e.val) cur e
(by simpa [cur, recOf] using hpInt)
(by simpa [cur] using hpHi)
(by simpa using heLo) (by simpa using heHi1260) hinputCur
(by simpa [cur, recOf, V] using
(show ∃ alpha v : Real,
X / (2 : Real) ^ e.val = V cur + alpha ∧
Y / (2 : Real) ^ e.val = V cur + v ∧
0 ≤ alpha ∧ alpha < v ∧ (cur.truncated = true ↔ 0 < alpha) from
⟨alpha, v, hXend, hYend, halpha, hlt, hsticky'⟩))
rcases hstep with ⟨d', shift, exp', hbody, hcall, hshift, hexp',
hpointStep, hpointSmall, hn', hd', hshapeNext, hlast, hendsNext,
hstall, hheadExit⟩
rcases hshapeNext with ⟨head', tail', hmapNext, hheadLo',
hheadHi', hlenNext⟩
have hpointLarge : 19 ≤ p.val ->
d'.decimal_point.val = p.val - 18 ∨
d'.decimal_point.val = p.val - 19 := by
intro hl
simpa [cur] using hpointStep (by simpa [cur] using hl)
have hpointSmall' : p.val ≤ 18 ->
d'.decimal_point.val = 0 ∨ d'.decimal_point.val = 1 := by
intro hm
simpa [cur] using hpointSmall (by simpa [cur] using hm)
have hstallHead : p.val = 1 -> d'.decimal_point.val = 1 -> head' = 1 := by
intro hp1 hp'1
have hs := hstall (by simpa [cur] using hp1)
(by simpa [cur] using hp'1)
rcases hs with ⟨t, ht⟩
have hh := congrArg (fun xs : List Nat => xs.headD 0) ht
simpa [hmapNext] using hh
have hheadExit0 : p.val = 1 -> head = 1 -> d'.decimal_point.val = 0 := by
intro hp1 hh
apply hheadExit (by simpa [cur] using hp1)
have hmapCur :
(cur.digits.val.take cur.num_digits.val).map
(fun b => b.val) = head :: tail := by
simpa [cur, recOf] using hmap'
rw [hh] at hmapCur
exact ⟨tail, hmapCur⟩
let s' := (d'.num_digits, d'.decimal_point, d'.truncated,
d'.digits, exp', (none : Option num.imp.dec2flt.common.BiasedFp))
have hpNextLo : 0 ≤ d'.decimal_point.val := by
by_cases hl : 19 ≤ p.val
· rcases hpointLarge hl with hp' | hp' <;> omega
· have hm : p.val ≤ 18 := by omega
rcases hpointSmall' hm with hp' | hp' <;> omega
have hpNextHi : d'.decimal_point.val < 310 := by
have hpOldHi : p.val < 310 := by simpa [cur, recOf] using hpHi
by_cases hl : 19 ≤ p.val
· rcases hpointLarge hl with hp' | hp'
· rw [hp']
have hsub : p.val - 18 ≤ p.val := by omega
exact lt_of_le_of_lt hsub hpOldHi
· rw [hp']
have hsub : p.val - 19 ≤ p.val := by omega
exact lt_of_le_of_lt hsub hpOldHi
· have hm : p.val ≤ 18 := by omega
rcases hpointSmall' hm with hp' | hp' <;> rw [hp'] <;> omega
have hshiftInt : (shift.val : Int) ≤ 60 := by exact_mod_cast hshift
have heLo' : 0 ≤ exp'.val := by
have heNonneg : 0 ≤ e.val := by simpa using heLo
have hk : 0 ≤ (shift.val : Int) := by exact_mod_cast (Nat.zero_le shift.val)
rw [hexp']
exact add_nonneg heNonneg hk
have heHi' : exp'.val ≤ 60 * ((j + 1 : Nat) : Int) := by
rw [hexp']
have heHiNorm : e.val ≤ 60 * (j : Int) := by simpa using heHi
have hshiftBound : (shift.val : Int) ≤ 60 := hshiftInt
push_cast
nlinarith [heHiNorm, hshiftBound]
have hendpoint' : ∃ alpha' v' : Real,
X / (2 : Real) ^ exp'.val = V d' + alpha' ∧
Y / (2 : Real) ^ exp'.val = V d' + v' ∧
0 ≤ alpha' ∧ alpha' < v' ∧
(d'.truncated = true ↔ 0 < alpha') := by
rcases hendsNext with ⟨alpha', v', hXshift, hYshift,
halpha', hlt', hsticky''⟩
have hquotX : (X / (2 : Real) ^ e.val) /
(2 : Real) ^ shift.val = X / (2 : Real) ^ exp'.val := by
rw [div_div]
have hpow : (2 : Real) ^ exp'.val =
(2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
calc
(2 : Real) ^ exp'.val = (2 : Real) ^ (e.val + (shift.val : Int)) := by rw [hexp']
_ = (2 : Real) ^ e.val * (2 : Real) ^ (shift.val : Int) :=
zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _
_ = (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
rw [zpow_natCast]
rw [← hpow]
have hquotY : (Y / (2 : Real) ^ e.val) /
(2 : Real) ^ shift.val = Y / (2 : Real) ^ exp'.val := by
rw [div_div]
have hpow : (2 : Real) ^ exp'.val =
(2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
calc
(2 : Real) ^ exp'.val = (2 : Real) ^ (e.val + (shift.val : Int)) := by rw [hexp']
_ = (2 : Real) ^ e.val * (2 : Real) ^ (shift.val : Int) :=
zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _
_ = (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
rw [zpow_natCast]
rw [← hpow]
refine ⟨alpha', v', ?_, ?_, halpha', hlt', ?_⟩
· calc
X / (2 : Real) ^ exp'.val =
(X / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val := hquotX.symm
_ = V d' + alpha' := hXshift
· calc
Y / (2 : Real) ^ exp'.val =
(Y / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val := hquotY.symm
_ = V d' + v' := hYshift
· exact hsticky''
have hbudgetNext :
(19 ≤ d'.decimal_point.val ->
18 * ((j + 1 : Nat) : Int) + d'.decimal_point.val ≤ 309) ∧
(2 ≤ d'.decimal_point.val -> d'.decimal_point.val ≤ 18 -> j + 1 ≤ 17) ∧
(d'.decimal_point.val = 1 -> head' = 1 -> j + 1 ≤ 19) ∧
(d'.decimal_point.val = 1 -> head' ≠ 1 -> j + 1 ≤ 18) ∧
(d'.decimal_point.val ≤ 0 -> j + 1 ≤ 20) := by
constructor
· intro hp'large
by_cases hl : 19 ≤ p.val
· have hb := hbLarge hl
rcases hpointLarge hl with hs | hs
· omega
· omega
· have hm : p.val ≤ 18 := by omega
have hps := hpointSmall' hm
omega
constructor
· intro hp'lo hp'hi
by_cases hl : 19 ≤ p.val
· have hb := hbLarge hl
rcases hpointLarge hl with hs | hs
· omega
· omega
· have hm : p.val ≤ 18 := by omega
have hps := hpointSmall' hm
omega
constructor
· intro hp'one hhead'one
by_cases hl : 19 ≤ p.val
· have hb := hbLarge hl
rcases hpointLarge hl with hs | hs
· omega
· omega
· by_cases hm : 2 ≤ p.val
· have hm18 : p.val ≤ 18 := by omega
have hb := hbMedium hm hm18
have hps := hpointSmall' hm18
omega
· have hone : p.val = 1 := by omega
by_cases hheadone : head = 1
· have hb := hbHeadOne hone hheadone
have hexit := hheadExit0 hone hheadone
omega
· have hb := hbHeadOther hone hheadone
have hps := hpointSmall' (by omega)
omega
constructor
· intro hp'one hhead'not
by_cases hl : 19 ≤ p.val
· have hb := hbLarge hl
rcases hpointLarge hl with hs | hs
· omega
· omega
· by_cases hm : 2 ≤ p.val
· have hm18 : p.val ≤ 18 := by omega
have hb := hbMedium hm hm18
have hps := hpointSmall' hm18
omega
· have hone : p.val = 1 := by omega
have hheadone : head ≠ 1 := by
intro h
subst head
have hexit := hheadExit0 hone rfl
omega
have hb := hbHeadOther hone hheadone
have hps := hpointSmall' (by omega)
have hstall' := hstallHead hone hp'one
omega
· intro hp'nonpos
by_cases hl : 19 ≤ p.val
· have hb := hbLarge hl
rcases hpointLarge hl with hs | hs
· omega
· omega
· by_cases hm : 2 ≤ p.val
· have hm18 : p.val ≤ 18 := by omega
have hb := hbMedium hm hm18
have hps := hpointSmall' hm18
omega
· have hone : p.val = 1 := by omega
by_cases hheadone : head = 1
· have hb := hbHeadOne hone hheadone
have hexit := hheadExit0 hone hheadone
omega
· have hb := hbHeadOther hone hheadone
have hps := hpointSmall' (by omega)
omega
have hInvNext : Inv s' := by
simp only [Inv, s', recOf]
refine ⟨j + 1, ?_⟩
constructor
· trivial
constructor
· exact le_trans (by norm_num : (-324 : Int) ≤ 0) hpNextLo
constructor
· exact hpNextHi
constructor
· exact heLo'
constructor
· exact heHi'
constructor
· exact hn'
constructor
· exact hd'
constructor
· exact ⟨head', tail', hmapNext, hheadLo', hheadHi', hlenNext⟩
constructor
· exact Or.inr hlast
constructor
· simpa [s', recOf] using hendpoint'
· simpa [hmapNext, List.headD] using hbudgetNext
have hmeasureNext : measure s' < measure (n, p, tr, a, e, res) := by
have hheadCur :
(((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
have hh := congrArg (fun xs : List Nat => xs.headD 0) hmap'
simpa using hh
simp only [measure, recOf, s']
rw [hheadCur, hmapNext]
simp only [List.headD_cons]
change rank d'.decimal_point.val (decide (head' = 1)) <
rank p.val (decide (head = 1))
have hrankStep :
(19 ≤ p.val ∧
(d'.decimal_point.val = p.val - 18 ∨
d'.decimal_point.val = p.val - 19)) ∨
(2 ≤ p.val ∧ p.val ≤ 18 ∧
(d'.decimal_point.val = 0 ∨ d'.decimal_point.val = 1)) ∨
(p.val = 1 ∧ decide (head = 1) = true ∧ d'.decimal_point.val = 0) ∨
(p.val = 1 ∧ decide (head = 1) = false ∧
(d'.decimal_point.val = 0 ∨
(d'.decimal_point.val = 1 ∧ decide (head' = 1) = true))) := by
by_cases hl : 19 ≤ p.val
· exact Or.inl ⟨hl, hpointLarge hl⟩
· by_cases hm : 2 ≤ p.val
· exact Or.inr (Or.inl ⟨hm, by omega, hpointSmall' (by omega)⟩)
· have hone : p.val = 1 := by omega
by_cases hh : head = 1
· have hb : decide (head = 1) = true := by simp [hh]
exact Or.inr (Or.inr (Or.inl ⟨hone, hb,
hheadExit0 hone hh⟩))
· have hps := hpointSmall' (by omega)
have hb : decide (head = 1) = false := by simp [hh]
by_cases hp'one : d'.decimal_point.val = 1
· have hb' : decide (head' = 1) = true := by
simp [hstallHead hone hp'one]
exact Or.inr (Or.inr (Or.inr ⟨hone, hb,
Or.inr ⟨hp'one, hb'⟩⟩))
· exact Or.inr (Or.inr (Or.inr ⟨hone, hb,
Or.inl (by rcases hps with hzero | hone' <;> omega)⟩))
exact rank_step p.val d'.decimal_point.val
(decide (head = 1)) (decide (head' = 1))
hpInt hpNextLo hrankStep
have hbodyEq' :
num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 } n p tr a e res =
ok (cont (d'.num_digits, d'.decimal_point, d'.truncated,
d'.digits, exp', none)) := by
simpa [cur, hresNone] using hbody
rw [hbodyEq']
simp only [WP.spec_ok]
exact ⟨by simpa [s'] using hInvNext, hmeasureNext⟩
· have hpval : p.val ≤ 0 := by
have hp' : ¬ 0 < p.val := by simpa using hp
exact not_lt.mp hp'
have hdone :
num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 } n p tr a e res =
ok (done (n, p, tr, a, e, res)) := by
simp [num.imp.dec2flt.slow.parse_long_mantissa_loop0.body, hp,
hresNone]
rw [hdone]
simp only [WP.spec_ok]
change Inv (n, p, tr, a, e, res) ∧ p.val ≤ 0
exact ⟨hsInv, hpval⟩
convert hbodySpec using 1
funext r
cases r <;> rfl
· exact hstart
obtain ⟨out, hout, hpost⟩ := Aeneas.Std.WP.spec_imp_exists hloop
rcases hpost with ⟨hinv, hterminal⟩
rcases out with ⟨n0, p0, b0, a0, e0, result0⟩
rcases hinv with ⟨steps, hnone, hpLo, hpHi, heLo, heHi, hn0,
hd0, hshape0, htrim0, hend0, hbudgets0⟩
let d0 : num.imp.dec2flt.decimal_seq.DecimalSeq :=
{ num_digits := n0, decimal_point := p0, truncated := b0, digits := a0 }
refine ⟨d0, e0, steps, ?_⟩
constructor
· have hresult : result0 = none := by simpa using hnone
simpa [num.imp.dec2flt.slow.parse_long_mantissa_loop0, s0, d0, recOf, hresult] using hout
constructor
· omega
constructor
· simpa [d0] using heLo
constructor
· simpa [d0] using heHi
constructor
· simpa using hXlower
constructor
· simpa [d0] using hpLo
constructor
· simpa [d0] using hterminal
constructor
· simpa [d0] using hn0
constructor
· simpa [d0] using hd0
constructor
· simpa [d0] using hshape0
constructor
· simpa [d0] using htrim0
· rcases hend0 with ⟨alpha0, v0, hX0, hY0, ha0, hav0, hstick0⟩
exact ⟨alpha0, v0, by simpa [d0, V, recOf, List.map_take] using hX0,
by simpa [d0, V, recOf, List.map_take] using hY0, ha0, hav0,
by simpa [d0, recOf] using hstick0⟩
)
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.P495_T1_RightLoopStep
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P495_T1_SlowLoop0Execution]
theorem P495_T1_SlowLoop0Execution (X Y : Real)
(d : num.imp.dec2flt.decimal_seq.DecimalSeq)
(hpointLo : -324 <= d.decimal_point.val)
(hpointHi : d.decimal_point.val < 310)
(hinput : d.num_digits.val <= 768 /\
(forall b, b ∈ d.digits.val.take d.num_digits.val -> b.val < 10) /\
(exists h tail,
(d.digits.val.take d.num_digits.val).map (fun b => b.val) = h :: tail /\
1 <= h /\ h < 10 /\ (h :: tail).length = d.num_digits.val)) :
let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
(fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
Y = V d + (10 : Real) ^ (d.decimal_point.val - (768 : Int)) ->
(exists eta : Real, X = V d + eta /\ 0 <= eta /\
eta < (10 : Real) ^ (d.decimal_point.val - (768 : Int)) /\
(d.truncated = true <-> 0 < eta)) ->
exists (d0 : num.imp.dec2flt.decimal_seq.DecimalSeq)
(exp0 : Std.I32) (steps : Nat),
num.imp.dec2flt.slow.parse_long_mantissa_loop0
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
d.num_digits d.decimal_point d.truncated d.digits 0#i32 none =
ok (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits, exp0, none) /\
steps <= 21 /\ 0 <= exp0.val /\ exp0.val <= (60 : Int) * steps /\
(10 : Real) ^ (-325 : Int) <= X /\
-324 <= d0.decimal_point.val /\ d0.decimal_point.val <= 0 /\
d0.num_digits.val <= 768 /\
(forall b, b ∈ d0.digits.val.take d0.num_digits.val -> b.val < 10) /\
(exists h tail,
(d0.digits.val.take d0.num_digits.val).map (fun b => b.val) = h :: tail /\
1 <= h /\ h < 10 /\ (h :: tail).length = d0.num_digits.val) /\
(steps = 0 \/ d0.digits.val[d0.num_digits.val - 1]? ≠ some 0#u8) /\
(exists eta0 u0 : Real,
X / (2 : Real) ^ exp0.val = V d0 + eta0 /\
Y / (2 : Real) ^ exp0.val = V d0 + u0 /\
0 <= eta0 /\ eta0 < u0 /\ (d0.truncated = true <-> 0 < eta0)) := by
-- BODY
exact (set_option maxHeartbeats 1600000 in by
dsimp only
intro hY hX
classical
rcases hinput with ⟨hnum, hdigit, hshape⟩
rcases hshape with ⟨h, tail, hmap, hhle, hhh, hlen⟩
let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
(fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
let eta := X - V d
let u := (10 : Real) ^ (d.decimal_point.val - (768 : Int))
have hXeq : X = V d + eta := by dsimp [eta]; ring
have heta0 : 0 <= eta := by
rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
rw [heq] at hXeq
have : eta = eta' := by linarith
simpa [this] using hlo
have hetaU : eta < u := by
rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
have : eta = eta' := by linarith [hXeq, heq]
simpa [u] using (by simpa [this] using hhi)
have hsticky : d.truncated = true ↔ 0 < eta := by
rcases hX with ⟨eta', heq, hlo, hhi, htr⟩
have : eta = eta' := by linarith [hXeq, heq]
simpa [this] using htr
have huPos : 0 < u := by
dsimp [u]
exact zpow_pos (by norm_num) _
have hYeq : Y = V d + u := by simpa [u, V] using hY
have hpupper : d.decimal_point.val ≤ 309 := by omega
have hXlower : (10 : Real) ^ (-325 : Int) ≤ X := by
have hv := P472_T1_DecimalValueBounds
((d.digits.val.take d.num_digits.val).map (fun b => b.val)) h tail
(by simpa [hmap]) hhle
(by intro q hq; rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩; exact hdigit b hb)
d.decimal_point.val
dsimp at hv
have hlen' :
((d.digits.val.take d.num_digits.val).map (fun b => b.val)).length =
d.num_digits.val := by
rw [hmap]
simpa using hlen
have hnumNat : d.num_digits.val ≤ 768 := by exact_mod_cast hnum
have hlenMap :
(List.take d.num_digits.val (List.map (fun b => b.val) d.digits.val)).length =
d.num_digits.val := by
simp [List.length_take, Nat.min_eq_left hnumNat]
have hpow : (10 : Real) ^ (-325 : Int) ≤
(h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
have hh : (10 : Real) ^ (-325 : Int) ≤
(10 : Real) ^ (d.decimal_point.val - 1) := by
apply zpow_right_mono₀ (by norm_num : (1 : Real) ≤ 10)
omega
have h10pos : 0 < (10 : Real) ^ (d.decimal_point.val - 1) :=
zpow_pos (by norm_num) _
calc
(10 : Real) ^ (-325 : Int) ≤ (10 : Real) ^ (d.decimal_point.val - 1) := hh
_ ≤ (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
have hhleR : (1 : Real) ≤ (h : Real) := by exact_mod_cast hhle
nlinarith [h10pos, hhleR]
have hVlo : (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) ≤ V d := by
have htmp := hv.1
change (h : Real) * (10 : Real) ^ (d.decimal_point.val - 1) ≤
(((((d.digits.val.take d.num_digits.val).map (fun b => b.val)).foldl
(fun n z => 10 * n + z) 0 : Nat) : Real) *
(10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)))
rw [List.map_take] at htmp
rw [hlenMap] at htmp
rw [List.map_take]
exact htmp
rw [hXeq]
linarith
-- The loop invariant records a completed-shift counter separately from
-- the exported existential bound witness.
let recOf := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
({ num_digits := s.1, decimal_point := s.2.1,
truncated := s.2.2.1, digits := s.2.2.2.1 } :
num.imp.dec2flt.decimal_seq.DecimalSeq)
let rank := fun (p : Int) (headOne : Bool) =>
if p <= 0 then 0 else 2 * p.toNat + (if headOne then 0 else 1)
let measure := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
rank (recOf s).decimal_point.val
(decide (((((recOf s).digits.val.take (recOf s).num_digits.val).map
(fun b => b.val)).headD 0) = 1))
have rank_step (p p' : Int) (headOne headOne' : Bool)
(hp : 1 ≤ p) (hp' : 0 ≤ p')
(hstep : (19 ≤ p ∧ (p' = p - 18 ∨ p' = p - 19)) ∨
(2 ≤ p ∧ p ≤ 18 ∧ (p' = 0 ∨ p' = 1)) ∨
(p = 1 ∧ headOne = true ∧ p' = 0) ∨
(p = 1 ∧ headOne = false ∧
(p' = 0 ∨ (p' = 1 ∧ headOne' = true)))) :
rank p' headOne' < rank p headOne := by
rcases hstep with h | h | h | h
all_goals cases headOne <;> cases headOne'
all_goals simp_all [rank]
all_goals split_ifs <;> omega
let Inv := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
∃ j : Nat,
s.2.2.2.2.2 = none ∧
-324 ≤ (recOf s).decimal_point.val ∧ (recOf s).decimal_point.val < 310 ∧
0 ≤ s.2.2.2.2.1.val ∧
s.2.2.2.2.1.val ≤ 60 * (j : Int) ∧
(recOf s).num_digits.val ≤ 768 ∧
(∀ b, b ∈ (recOf s).digits.val.take (recOf s).num_digits.val -> b.val < 10) ∧
(∃ h tail,
((recOf s).digits.val.take (recOf s).num_digits.val).map
(fun b => b.val) = h :: tail ∧ 1 ≤ h ∧ h < 10 ∧
(h :: tail).length = (recOf s).num_digits.val) ∧
(j = 0 ∨ (recOf s).digits.val[(recOf s).num_digits.val - 1]? ≠ some 0#u8) ∧
(∃ alpha v : Real,
X / (2 : Real) ^ s.2.2.2.2.1.val = V (recOf s) + alpha ∧
Y / (2 : Real) ^ s.2.2.2.2.1.val = V (recOf s) + v ∧
0 ≤ alpha ∧ alpha < v ∧
((recOf s).truncated = true ↔ 0 < alpha)) ∧
((19 ≤ (recOf s).decimal_point.val -> 18 * (j : Int) +
(recOf s).decimal_point.val ≤ 309) ∧
(2 ≤ (recOf s).decimal_point.val ->
(recOf s).decimal_point.val ≤ 18 -> j ≤ 17) ∧
((recOf s).decimal_point.val = 1 ->
(((((recOf s).digits.val.take (recOf s).num_digits.val).map
(fun b => b.val)).headD 0) = 1 -> j ≤ 19)) ∧
((recOf s).decimal_point.val = 1 ->
(((((recOf s).digits.val.take (recOf s).num_digits.val).map
(fun b => b.val)).headD 0) ≠ 1 -> j ≤ 18)) ∧
((recOf s).decimal_point.val ≤ 0 -> j ≤ 20))
let Post := fun (s : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
Std.I32 × Option num.imp.dec2flt.common.BiasedFp) =>
Inv s ∧ (recOf s).decimal_point.val ≤ 0
let s0 := (d.num_digits, d.decimal_point, d.truncated, d.digits,
(0#i32 : Std.I32), (none : Option num.imp.dec2flt.common.BiasedFp))
have hstart : Inv s0 := by
simp only [Inv, recOf, s0]
refine ⟨0, trivial, ?_⟩
constructor
· exact hpointLo
constructor
· exact hpointHi
constructor
· norm_num
constructor
· norm_num
constructor
· exact hnum
constructor
· exact hdigit
constructor
· exact ⟨h, tail, hmap, hhle, hhh, hlen⟩
constructor
· exact Or.inl rfl
constructor
· refine ⟨eta, u, ?_⟩
constructor
· simpa [V] using hXeq
constructor
· simpa [V] using hYeq
constructor
· exact heta0
constructor
· exact hetaU
· exact hsticky
constructor
· intro hp
omega
constructor
· intro hp hp18
omega
constructor
· intro hp
omega
constructor
· intro hp
omega
· intro hp
omega
have hloop : Aeneas.Std.WP.spec
(num.imp.dec2flt.slow.parse_long_mantissa_loop0
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
d.num_digits d.decimal_point d.truncated d.digits 0#i32 none) Post := by
unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0
apply Aeneas.Std.loop.spec_decr_nat measure Inv Post
(fun s => num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
s.1 s.2.1 s.2.2.1 s.2.2.2.1 s.2.2.2.2.1 s.2.2.2.2.2)
s0
· intro s hs
rcases s with ⟨n, p, tr, a, e, res⟩
simp only [Prod.fst, Prod.snd] at hs ⊢
have hsInv := hs
rcases hs with ⟨j, hres, hpLo, hpHi, heLo, heHi, hn, hd, hshape,
htrim, hends, hbudgets⟩
let cur : num.imp.dec2flt.decimal_seq.DecimalSeq :=
{ num_digits := n, decimal_point := p, truncated := tr, digits := a }
have hresNone : res = none := by simpa using hres
have hshape' := hshape
rcases hshape with ⟨head, tail, hmap', hheadLo, hheadHi, hlen'⟩
have hbLarge : 19 ≤ p.val -> 18 * (j : Int) + p.val ≤ 309 := by
intro hl
have h := hbudgets.1 (by simpa [cur, recOf] using hl)
simpa [cur, recOf] using h
have hbMedium : 2 ≤ p.val -> p.val ≤ 18 -> j ≤ 17 := by
intro hm hm18
exact hbudgets.2.1 (by simpa [cur, recOf] using hm)
(by simpa [cur, recOf] using hm18)
have hbHeadOne : p.val = 1 -> head = 1 -> j ≤ 19 := by
intro hp1 hh
have hh' :
(((a.val.take n.val).map (fun b => b.val)).headD 0) = 1 := by
have hh'' := congrArg (fun xs : List Nat => xs.headD 0) hmap'
have hhval :
(((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
simpa using hh''
rw [hhval]
exact hh
exact hbudgets.2.2.1 (by simpa [cur, recOf] using hp1)
(by simpa [cur, recOf, List.headD, hmap'] using hh')
have hbHeadOther : p.val = 1 -> head ≠ 1 -> j ≤ 18 := by
intro hp1 hh
have hh' :
(((a.val.take n.val).map (fun b => b.val)).headD 0) ≠ 1 := by
have hh'' := congrArg (fun xs : List Nat => xs.headD 0) hmap'
have hhval :
(((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
simpa using hh''
rw [hhval]
exact hh
exact hbudgets.2.2.2.1 (by simpa [cur, recOf] using hp1)
(by simpa [cur, recOf, List.headD, hmap'] using hh')
have hbodySpec :
num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
n p tr a e res
⦃ r => match r with
| done y => Post y
| cont y => Inv y ∧ measure y < measure (n, p, tr, a, e, res) ⦄ := by
by_cases hp : p > 0#i32
· have hpPos : 0 < p.val := by simpa using hp
have hpInt : 1 ≤ p.val := by omega
have hj : j ≤ 20 := by
by_cases hl : 19 ≤ p.val
· have hb := hbudgets.1 (by simpa [cur, recOf] using hl)
have hjInt : (j : Int) ≤ 20 := by
have : 18 * (j : Int) + p.val ≤ 309 := hb
omega
exact_mod_cast hjInt
· by_cases hm : 2 ≤ p.val
· have hb := hbudgets.2.1 (by simpa [cur, recOf] using hm)
(by have hm18 : p.val ≤ 18 := by omega
simpa [cur, recOf] using hm18)
omega
· have hone : p.val = 1 := by omega
by_cases hheadone : head = 1
· have hheadVal :
(List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = head := by
rw [← List.map_take, hmap']
rfl
have hheadOne :
(List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = 1 := by
rw [hheadVal]
exact hheadone
have hb := hbudgets.2.2.1 (by simpa [cur, recOf] using hone)
(by simpa [cur, recOf, List.headD] using hheadOne)
omega
· have hheadVal :
(List.take n.val (List.map (fun b => b.val) a.val)).headD 0 = head := by
rw [← List.map_take, hmap']
rfl
have hheadNotOne :
(List.take n.val (List.map (fun b => b.val) a.val)).headD 0 ≠ 1 := by
rw [hheadVal]
exact hheadone
have hb := hbudgets.2.2.2.1 (by simpa [cur, recOf] using hone)
(by simpa [cur, recOf, List.headD] using hheadNotOne)
omega
have heHi1260 : e.val ≤ 1260 := by
have hjInt : (j : Int) ≤ 20 := by exact_mod_cast hj
have he1200 : e.val ≤ 60 * 20 := by
calc
e.val ≤ 60 * (j : Int) := heHi
_ ≤ 60 * 20 := by nlinarith
omega
rcases hends with ⟨alpha, v, hXend, hYend, halpha, hlt, hsticky'⟩
have hinputCur : n.val ≤ 768 ∧
(∀ b, b ∈ a.val.take n.val -> b.val < 10) ∧
(∃ hh tt, (a.val.take n.val).map (fun b => b.val) = hh :: tt ∧
1 ≤ hh ∧ hh < 10 ∧ (hh :: tt).length = n.val) := by
simpa [cur, recOf] using And.intro hn (And.intro hd hshape')
have hstep := P495_T1_RightLoopStep
(X / (2 : Real) ^ e.val) (Y / (2 : Real) ^ e.val) cur e
(by simpa [cur, recOf] using hpInt)
(by simpa [cur] using hpHi)
(by simpa using heLo) (by simpa using heHi1260) hinputCur
(by simpa [cur, recOf, V] using
(show ∃ alpha v : Real,
X / (2 : Real) ^ e.val = V cur + alpha ∧
Y / (2 : Real) ^ e.val = V cur + v ∧
0 ≤ alpha ∧ alpha < v ∧ (cur.truncated = true ↔ 0 < alpha) from
⟨alpha, v, hXend, hYend, halpha, hlt, hsticky'⟩))
rcases hstep with ⟨d', shift, exp', hbody, hcall, hshift, hexp',
hpointStep, hpointSmall, hn', hd', hshapeNext, hlast, hendsNext,
hstall, hheadExit⟩
rcases hshapeNext with ⟨head', tail', hmapNext, hheadLo',
hheadHi', hlenNext⟩
have hpointLarge : 19 ≤ p.val ->
d'.decimal_point.val = p.val - 18 ∨
d'.decimal_point.val = p.val - 19 := by
intro hl
simpa [cur] using hpointStep (by simpa [cur] using hl)
have hpointSmall' : p.val ≤ 18 ->
d'.decimal_point.val = 0 ∨ d'.decimal_point.val = 1 := by
intro hm
simpa [cur] using hpointSmall (by simpa [cur] using hm)
have hstallHead : p.val = 1 -> d'.decimal_point.val = 1 -> head' = 1 := by
intro hp1 hp'1
have hs := hstall (by simpa [cur] using hp1)
(by simpa [cur] using hp'1)
rcases hs with ⟨t, ht⟩
have hh := congrArg (fun xs : List Nat => xs.headD 0) ht
simpa [hmapNext] using hh
have hheadExit0 : p.val = 1 -> head = 1 -> d'.decimal_point.val = 0 := by
intro hp1 hh
apply hheadExit (by simpa [cur] using hp1)
have hmapCur :
(cur.digits.val.take cur.num_digits.val).map
(fun b => b.val) = head :: tail := by
simpa [cur, recOf] using hmap'
rw [hh] at hmapCur
exact ⟨tail, hmapCur⟩
let s' := (d'.num_digits, d'.decimal_point, d'.truncated,
d'.digits, exp', (none : Option num.imp.dec2flt.common.BiasedFp))
have hpNextLo : 0 ≤ d'.decimal_point.val := by
by_cases hl : 19 ≤ p.val
· rcases hpointLarge hl with hp' | hp' <;> omega
· have hm : p.val ≤ 18 := by omega
rcases hpointSmall' hm with hp' | hp' <;> omega
have hpNextHi : d'.decimal_point.val < 310 := by
have hpOldHi : p.val < 310 := by simpa [cur, recOf] using hpHi
by_cases hl : 19 ≤ p.val
· rcases hpointLarge hl with hp' | hp'
· rw [hp']
have hsub : p.val - 18 ≤ p.val := by omega
exact lt_of_le_of_lt hsub hpOldHi
· rw [hp']
have hsub : p.val - 19 ≤ p.val := by omega
exact lt_of_le_of_lt hsub hpOldHi
· have hm : p.val ≤ 18 := by omega
rcases hpointSmall' hm with hp' | hp' <;> rw [hp'] <;> omega
have hshiftInt : (shift.val : Int) ≤ 60 := by exact_mod_cast hshift
have heLo' : 0 ≤ exp'.val := by
have heNonneg : 0 ≤ e.val := by simpa using heLo
have hk : 0 ≤ (shift.val : Int) := by exact_mod_cast (Nat.zero_le shift.val)
rw [hexp']
exact add_nonneg heNonneg hk
have heHi' : exp'.val ≤ 60 * ((j + 1 : Nat) : Int) := by
rw [hexp']
have heHiNorm : e.val ≤ 60 * (j : Int) := by simpa using heHi
have hshiftBound : (shift.val : Int) ≤ 60 := hshiftInt
push_cast
nlinarith [heHiNorm, hshiftBound]
have hendpoint' : ∃ alpha' v' : Real,
X / (2 : Real) ^ exp'.val = V d' + alpha' ∧
Y / (2 : Real) ^ exp'.val = V d' + v' ∧
0 ≤ alpha' ∧ alpha' < v' ∧
(d'.truncated = true ↔ 0 < alpha') := by
rcases hendsNext with ⟨alpha', v', hXshift, hYshift,
halpha', hlt', hsticky''⟩
have hquotX : (X / (2 : Real) ^ e.val) /
(2 : Real) ^ shift.val = X / (2 : Real) ^ exp'.val := by
rw [div_div]
have hpow : (2 : Real) ^ exp'.val =
(2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
calc
(2 : Real) ^ exp'.val = (2 : Real) ^ (e.val + (shift.val : Int)) := by rw [hexp']
_ = (2 : Real) ^ e.val * (2 : Real) ^ (shift.val : Int) :=
zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _
_ = (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
rw [zpow_natCast]
rw [← hpow]
have hquotY : (Y / (2 : Real) ^ e.val) /
(2 : Real) ^ shift.val = Y / (2 : Real) ^ exp'.val := by
rw [div_div]
have hpow : (2 : Real) ^ exp'.val =
(2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
calc
(2 : Real) ^ exp'.val = (2 : Real) ^ (e.val + (shift.val : Int)) := by rw [hexp']
_ = (2 : Real) ^ e.val * (2 : Real) ^ (shift.val : Int) :=
zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _
_ = (2 : Real) ^ e.val * (2 : Real) ^ shift.val := by
rw [zpow_natCast]
rw [← hpow]
refine ⟨alpha', v', ?_, ?_, halpha', hlt', ?_⟩
· calc
X / (2 : Real) ^ exp'.val =
(X / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val := hquotX.symm
_ = V d' + alpha' := hXshift
· calc
Y / (2 : Real) ^ exp'.val =
(Y / (2 : Real) ^ e.val) / (2 : Real) ^ shift.val := hquotY.symm
_ = V d' + v' := hYshift
· exact hsticky''
have hbudgetNext :
(19 ≤ d'.decimal_point.val ->
18 * ((j + 1 : Nat) : Int) + d'.decimal_point.val ≤ 309) ∧
(2 ≤ d'.decimal_point.val -> d'.decimal_point.val ≤ 18 -> j + 1 ≤ 17) ∧
(d'.decimal_point.val = 1 -> head' = 1 -> j + 1 ≤ 19) ∧
(d'.decimal_point.val = 1 -> head' ≠ 1 -> j + 1 ≤ 18) ∧
(d'.decimal_point.val ≤ 0 -> j + 1 ≤ 20) := by
constructor
· intro hp'large
by_cases hl : 19 ≤ p.val
· have hb := hbLarge hl
rcases hpointLarge hl with hs | hs
· omega
· omega
· have hm : p.val ≤ 18 := by omega
have hps := hpointSmall' hm
omega
constructor
· intro hp'lo hp'hi
by_cases hl : 19 ≤ p.val
· have hb := hbLarge hl
rcases hpointLarge hl with hs | hs
· omega
· omega
· have hm : p.val ≤ 18 := by omega
have hps := hpointSmall' hm
omega
constructor
· intro hp'one hhead'one
by_cases hl : 19 ≤ p.val
· have hb := hbLarge hl
rcases hpointLarge hl with hs | hs
· omega
· omega
· by_cases hm : 2 ≤ p.val
· have hm18 : p.val ≤ 18 := by omega
have hb := hbMedium hm hm18
have hps := hpointSmall' hm18
omega
· have hone : p.val = 1 := by omega
by_cases hheadone : head = 1
· have hb := hbHeadOne hone hheadone
have hexit := hheadExit0 hone hheadone
omega
· have hb := hbHeadOther hone hheadone
have hps := hpointSmall' (by omega)
omega
constructor
· intro hp'one hhead'not
by_cases hl : 19 ≤ p.val
· have hb := hbLarge hl
rcases hpointLarge hl with hs | hs
· omega
· omega
· by_cases hm : 2 ≤ p.val
· have hm18 : p.val ≤ 18 := by omega
have hb := hbMedium hm hm18
have hps := hpointSmall' hm18
omega
· have hone : p.val = 1 := by omega
have hheadone : head ≠ 1 := by
intro h
subst head
have hexit := hheadExit0 hone rfl
omega
have hb := hbHeadOther hone hheadone
have hps := hpointSmall' (by omega)
have hstall' := hstallHead hone hp'one
omega
· intro hp'nonpos
by_cases hl : 19 ≤ p.val
· have hb := hbLarge hl
rcases hpointLarge hl with hs | hs
· omega
· omega
· by_cases hm : 2 ≤ p.val
· have hm18 : p.val ≤ 18 := by omega
have hb := hbMedium hm hm18
have hps := hpointSmall' hm18
omega
· have hone : p.val = 1 := by omega
by_cases hheadone : head = 1
· have hb := hbHeadOne hone hheadone
have hexit := hheadExit0 hone hheadone
omega
· have hb := hbHeadOther hone hheadone
have hps := hpointSmall' (by omega)
omega
have hInvNext : Inv s' := by
simp only [Inv, s', recOf]
refine ⟨j + 1, ?_⟩
constructor
· trivial
constructor
· exact le_trans (by norm_num : (-324 : Int) ≤ 0) hpNextLo
constructor
· exact hpNextHi
constructor
· exact heLo'
constructor
· exact heHi'
constructor
· exact hn'
constructor
· exact hd'
constructor
· exact ⟨head', tail', hmapNext, hheadLo', hheadHi', hlenNext⟩
constructor
· exact Or.inr hlast
constructor
· simpa [s', recOf] using hendpoint'
· simpa [hmapNext, List.headD] using hbudgetNext
have hmeasureNext : measure s' < measure (n, p, tr, a, e, res) := by
have hheadCur :
(((a.val.take n.val).map (fun b => b.val)).headD 0) = head := by
have hh := congrArg (fun xs : List Nat => xs.headD 0) hmap'
simpa using hh
simp only [measure, recOf, s']
rw [hheadCur, hmapNext]
simp only [List.headD_cons]
change rank d'.decimal_point.val (decide (head' = 1)) <
rank p.val (decide (head = 1))
have hrankStep :
(19 ≤ p.val ∧
(d'.decimal_point.val = p.val - 18 ∨
d'.decimal_point.val = p.val - 19)) ∨
(2 ≤ p.val ∧ p.val ≤ 18 ∧
(d'.decimal_point.val = 0 ∨ d'.decimal_point.val = 1)) ∨
(p.val = 1 ∧ decide (head = 1) = true ∧ d'.decimal_point.val = 0) ∨
(p.val = 1 ∧ decide (head = 1) = false ∧
(d'.decimal_point.val = 0 ∨
(d'.decimal_point.val = 1 ∧ decide (head' = 1) = true))) := by
by_cases hl : 19 ≤ p.val
· exact Or.inl ⟨hl, hpointLarge hl⟩
· by_cases hm : 2 ≤ p.val
· exact Or.inr (Or.inl ⟨hm, by omega, hpointSmall' (by omega)⟩)
· have hone : p.val = 1 := by omega
by_cases hh : head = 1
· have hb : decide (head = 1) = true := by simp [hh]
exact Or.inr (Or.inr (Or.inl ⟨hone, hb,
hheadExit0 hone hh⟩))
· have hps := hpointSmall' (by omega)
have hb : decide (head = 1) = false := by simp [hh]
by_cases hp'one : d'.decimal_point.val = 1
· have hb' : decide (head' = 1) = true := by
simp [hstallHead hone hp'one]
exact Or.inr (Or.inr (Or.inr ⟨hone, hb,
Or.inr ⟨hp'one, hb'⟩⟩))
· exact Or.inr (Or.inr (Or.inr ⟨hone, hb,
Or.inl (by rcases hps with hzero | hone' <;> omega)⟩))
exact rank_step p.val d'.decimal_point.val
(decide (head = 1)) (decide (head' = 1))
hpInt hpNextLo hrankStep
have hbodyEq' :
num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 } n p tr a e res =
ok (cont (d'.num_digits, d'.decimal_point, d'.truncated,
d'.digits, exp', none)) := by
simpa [cur, hresNone] using hbody
rw [hbodyEq']
simp only [WP.spec_ok]
exact ⟨by simpa [s'] using hInvNext, hmeasureNext⟩
· have hpval : p.val ≤ 0 := by
have hp' : ¬ 0 < p.val := by simpa using hp
exact not_lt.mp hp'
have hdone :
num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 } n p tr a e res =
ok (done (n, p, tr, a, e, res)) := by
simp [num.imp.dec2flt.slow.parse_long_mantissa_loop0.body, hp,
hresNone]
rw [hdone]
simp only [WP.spec_ok]
change Inv (n, p, tr, a, e, res) ∧ p.val ≤ 0
exact ⟨hsInv, hpval⟩
convert hbodySpec using 1
funext r
cases r <;> rfl
· exact hstart
obtain ⟨out, hout, hpost⟩ := Aeneas.Std.WP.spec_imp_exists hloop
rcases hpost with ⟨hinv, hterminal⟩
rcases out with ⟨n0, p0, b0, a0, e0, result0⟩
rcases hinv with ⟨steps, hnone, hpLo, hpHi, heLo, heHi, hn0,
hd0, hshape0, htrim0, hend0, hbudgets0⟩
let d0 : num.imp.dec2flt.decimal_seq.DecimalSeq :=
{ num_digits := n0, decimal_point := p0, truncated := b0, digits := a0 }
refine ⟨d0, e0, steps, ?_⟩
constructor
· have hresult : result0 = none := by simpa using hnone
simpa [num.imp.dec2flt.slow.parse_long_mantissa_loop0, s0, d0, recOf, hresult] using hout
constructor
· omega
constructor
· simpa [d0] using heLo
constructor
· simpa [d0] using heHi
constructor
· simpa using hXlower
constructor
· simpa [d0] using hpLo
constructor
· simpa [d0] using hterminal
constructor
· simpa [d0] using hn0
constructor
· simpa [d0] using hd0
constructor
· simpa [d0] using hshape0
constructor
· simpa [d0] using htrim0
· rcases hend0 with ⟨alpha0, v0, hX0, hY0, ha0, hav0, hstick0⟩
exact ⟨alpha0, v0, by simpa [d0, V, recOf, List.map_take] using hX0,
by simpa [d0, V, recOf, List.map_take] using hY0, ha0, hav0,
by simpa [d0, recOf] using hstick0⟩
)
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Inspect related source (152)
- Dec2flt_modelNumImpTraitsFloatU64 · traits.rs:309 Program Rust
- parse_long_mantissa · dec2flt/slow.rs:27 Program Rust
- parse_long_mantissa_loop0 · dec2flt/slow.rs:51 Program Rust
More program dependencies (110)
- 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
- BITS · traits.rs:319 Program Rust
- EXP_MASK · traits.rs:321 Program Rust
- INFINITY · traits.rs:312 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
- 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
- SIG_TOTAL_BITS · traits.rs:320 Program Rust
- SMALLEST_POWER_OF_TEN · traits.rs:328 Program Rust
- classify · traits.rs:334 Program Rust
- to_bits · traits.rs:330 Program Rust
- Dec2flt_modelNumImpTraitsInt · traits.rs:51 Program Rust
- BiasedFp · dec2flt/common.rs:56 Program Rust
- zero_pow2 · dec2flt/common.rs:66 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:22 Program Rust
- DECIMAL_POINT_RANGE · dec2flt/decimal_seq.rs:68 Program Rust
- MAX_DIGITS · dec2flt/decimal_seq.rs:64 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
- 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
- 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
- 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
- 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
- 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
- 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
- read_u64 · dec2flt/common.rs:22 Program Rust
- write_u64 · dec2flt/common.rs:29 Program Rust
- Dec2flt_modelNumImpTraitsCastIntoI16 · traits.rs:45 Program Rust
- ONE · traits.rs:53 Program Rust
- ZERO · traits.rs:52 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:44 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- default · dec2flt/decimal_seq.rs:34 Program Rust
- MAX_DIGITS_WITHOUT_OVERFLOW · dec2flt/decimal_seq.rs:67 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
- 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
- number_of_digits_decimal_left_shift · dec2flt/decimal_seq.rs:375 Program Rust
- number_of_digits_decimal_left_shift_loop · dec2flt/decimal_seq.rs:441 Program Rust
- body · dec2flt/decimal_seq.rs:441 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
- 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
- cast · traits.rs:46 Program Rust
- try_add_digit · dec2flt/decimal_seq.rs:74 Program Rust
- TABLE · dec2flt/decimal_seq.rs:377 Program Rust
- TABLE_POW5 · dec2flt/decimal_seq.rs:386 Program Rust
Standard-library dependencies (39)
- 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
- 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
- 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_DIGITS · core/src/num/f64.rs:412 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
- 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
- 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
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
- Binary64Model
- Binary64ModelDefault
- DecimalDigitLexScale
- DecimalLeftShiftDigitGrowth
- DecimalLeftShiftFirstLoopSemantics
- DecimalLeftShiftLoopLex
All 126 entries
- Binary64Model
- Binary64ModelDefault
- DecimalDigitLexScale
- DecimalLeftShiftDigitGrowth
- DecimalLeftShiftFirstLoopSemantics
- DecimalLeftShiftLoopLex
- DecimalLeftShiftSecondLoopSemantics
- DecimalLeftShiftTableCertificate
- DecimalRightShiftU64DyadicBridge
- DecimalSeqLeftShiftRecordSemantics
- 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
- DecimalRightShiftFinalLoopSemantics
- DecimalRightShiftLoop0Execution
- DecimalRightShiftMainLoopSemantics
- DecimalRightShiftPrefixLoopSemantics
- DecimalSeqDyadicShiftSemantics
- DecimalSeqRightShiftRecordSemantics
- DecimalValueBounds
- LoopZeroRightShiftTransport
- RightLoopStep
- RightPrefixLengthBounds
- RightShiftCanonical
- SlowLoop0Execution
- DecimalFoldBounds
- PositiveScaleErrorTransport
- Preamble
- ResultLoopPartial
- 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 common BiasedFp
- num imp dec2flt common BiasedFp zero pow2
- num imp dec2flt common is 8digits
- 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 parse parse scientific
- 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": "P495_T1_SlowLoop0Execution",
"closure_version": "patch_c_v1",
"active_decl_hash": "fd3decd6a3a94372a7ca7319a9e643ebc9ad4c716253c02e8daafa84befafd28",
"active_statement_hash": "7f259ed22561e71caa908498f059b54eb26a69b24237971891e44a81d88ff1e0",
"kernel_axioms": [
"Classical.choice",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-181",
"boundary_theorems": {},
"strict_theorem_deps": {
"P472_T1_DecimalValueBounds": "4b5c924b5d52bc9d",
"P495_T1_RightLoopStep": "b873eecaa227a3e1",
"num_imp_dec2flt_slow_parse_long_mantissa": "d2b4145772dccc04"
},
"strict_definition_deps": {
"F64": "ec4e25fbaf4e11d4",
"F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
"num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
"num_imp_dec2flt_decimal_seq_DecimalSeq": "59bf1ff9fe88fa8d",
"num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE": "0cc5155758bc976a",
"num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "1aaf1bb11c0b6a49",
"num_imp_dec2flt_slow_parse_long_mantissa": "0ce7bdcf55d68c29",
"num_imp_dec2flt_slow_parse_long_mantissa_closure_Insts_CoreOpsFunctionFnTupleUsizeUsize_call": "7df8a2c8e3717790"
}
}Prose assessment
{
"label": "Recorded Sound: VerifierPass",
"assessment_status": "VerifierPass",
"fingerprint_relation": "matches current fingerprint",
"assessment_fingerprint": "sound-v2:dfb26d638e4893e772d88fc7d2d7eb333939d66e642be14f11096e9d5e1ffeef",
"current_fingerprint": "sound-v2:dfb26d638e4893e772d88fc7d2d7eb333939d66e642be14f11096e9d5e1ffeef",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}