Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Capacity and order backward on the actual right history
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.P495_T1_RightLoopStep
import Tablet.P529_T1_RightBoundaryTransport
import Tablet.P826_T1_ResultLoopBackward
import Tablet.ResultLoopPartial
import Tablet.P856_T1_CoefficientGridAlignment
import Tablet.P472_T1_DecimalValueBounds
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P529_T1_RightHistoryBoundary]
theorem P529_T1_RightHistoryBoundary (X Y : Real)
(d d0 : num.imp.dec2flt.decimal_seq.DecimalSeq) (exp0 : Std.I32)
(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))
(hcall : 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)) :
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)) ->
(d0.decimal_point.val < 0 -> exp0.val = 0) /\
(forall (c : Nat) (R : Int),
0 <= R - exp0.val + 768 - d0.decimal_point.val ->
0 <= R + 768 - d.decimal_point.val /\
(V d0 < (c : Real) * (2 : Real) ^ (R - exp0.val) ->
V d < (c : Real) * (2 : Real) ^ R)) := 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
dsimp only
intro hY hX
classical
rcases hX with ⟨eta, hxeq, hetaLo, hetaHi, hsticky⟩
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))
rcases hinput with ⟨hcap, hdigit, hlead⟩
have hrun := P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi
⟨hcap, hdigit, hlead⟩ hY ⟨eta, hxeq, hetaLo, hetaHi, hsticky⟩
rcases hrun with ⟨dF, eF, steps, hrun, hsteps, heFLo, heFHi,
hXlower, hpFLo, hpFHi, hcapF, hdigitF, hleadF, hlastF, hendF⟩
have hfinalEq := Result.ok.inj (hrun.symm.trans hcall)
have hn : dF.num_digits = d0.num_digits := congrArg (fun z => z.1) hfinalEq
have hp : dF.decimal_point = d0.decimal_point :=
congrArg (fun z => z.2.1) hfinalEq
have ht : dF.truncated = d0.truncated := congrArg (fun z => z.2.2.1) hfinalEq
have ha : dF.digits = d0.digits := congrArg (fun z => z.2.2.2.1) hfinalEq
have he : eF = exp0 := congrArg (fun z => z.2.2.2.2.1) hfinalEq
have hterminal : -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) := by
exact ⟨by simpa [hp] using hpFLo, by simpa [hp] using hpFHi,
by simpa [hn] using hcapF, by simpa [hn, ha] using hdigitF,
by simpa [hn, ha] using hleadF⟩
have hendpoints : ∃ 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
simpa [V, he, hn, hp, ht, ha] using hendF
have hterminalExp : 0 <= exp0.val ∧ exp0.val <= 1260 := by
constructor
· simpa [he] using heFLo
· calc
exp0.val <= 60 * steps := by simpa [he] using heFHi
_ <= 60 * 21 := by omega
_ = 1260 := by norm_num
have bodyMono (a a' : num.imp.dec2flt.decimal_seq.DecimalSeq)
(e e' : Std.I32)
(hb : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
a.num_digits a.decimal_point a.truncated a.digits e none =
ok (cont (a'.num_digits, a'.decimal_point, a'.truncated,
a'.digits, e', none))) :
∃ k : Std.Usize,
k.val <= 60 ∧ e'.val = e.val + (k.val : Int) ∧
(19 <= a.decimal_point.val -> k.val = 60) ∧
(a.decimal_point.val <= 18 ->
a.decimal_point.val <= (k.val : Int)) := by
unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hb
by_cases houter : a.decimal_point > 0#i32
· simp only [if_pos houter, core.option.Option.is_none] at hb
split at hb
· obtain ⟨n, hncast, hnval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize a.decimal_point (by scalar_tac))
let traits := F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
let shift : Std.Usize := match n.val with
| 0 => 0#usize | 1 => 3#usize | 2 => 6#usize | 3 => 9#usize
| 4 => 13#usize | 5 => 16#usize | 6 => 19#usize | 7 => 23#usize
| 8 => 26#usize | 9 => 29#usize | 10 => 33#usize | 11 => 36#usize
| 12 => 39#usize | 13 => 43#usize | 14 => 46#usize | 15 => 49#usize
| 16 => 53#usize | 17 => 56#usize | 18 => 59#usize | _ => 60#usize
have hcert := SlowShiftSelectorCertificate traits n
dsimp only at hcert
rcases hcert with ⟨hselector, hshift, _, hsmall, hlarge⟩
have hs : num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok shift := by
simpa [traits, shift] using hselector
have hneg : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE =
ok (-2047)#i32 := by
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
change IScalar.neg (2047#i32 : Std.I32) = _
unfold IScalar.neg IScalar.tryMk IScalar.tryMkOpt
norm_num [IScalar.check_bounds, IScalarTy.numBits]
simp only [Bind.bind, Aeneas.Std.bind, hncast, hs, hneg] at hb
cases hr : num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift
{ num_digits := a.num_digits, decimal_point := a.decimal_point,
truncated := a.truncated, digits := a.digits } shift <;>
simp [hr] at hb
split at hb
· simp at hb
· cases hc : lift (UScalar.hcast .I32 shift) with
| fail err => simp [hc] at hb
| div => simp [hc] at hb
| ok i3 =>
simp [hc] at hb
cases ha : e + i3 with
| fail err => simp [ha] at hb
| div => simp [ha] at hb
| ok out =>
simp [ha] at hb
have haddval := IScalar.add_equiv e i3
rw [ha] at haddval
obtain ⟨_, houtval, _⟩ := haddval
have hshiftI : (i3.val : Int) = (shift.val : Int) := by
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.hcast_inBounds_spec .I32 shift (by
have hi : (shift.val : Int) <= 60 := by exact_mod_cast hshift
rw [IScalar.max_I32_eq]
norm_num [IScalarTy.numBits]
omega))
have hz' : lift (UScalar.hcast .I32 shift) = ok z := by
simpa [lift] using hz
have hiz : i3 = z := Result.ok.inj (hc.symm.trans hz')
subst z
simpa [WP.spec_ok] using hzval
have hout : out.val = e.val + (shift.val : Int) := by
simpa [hshiftI] using houtval
rcases hb with ⟨_, hpointEq, _, _, houtEq⟩
have hlargeK : 19 <= a.decimal_point.val -> shift.val = 60 := by
intro hp
have hnlarge : 19 <= n.val := by
have hn : (n.val : Int) = a.decimal_point.val := by
simpa using hnval
exact_mod_cast (by omega : (19 : Int) <= (n.val : Int))
exact (hlarge hnlarge).1
have hsmallK : a.decimal_point.val <= 18 ->
a.decimal_point.val <= (shift.val : Int) := by
intro hp
have hn : (n.val : Int) = a.decimal_point.val := by
simpa using hnval
have hnpos : 1 <= n.val := by
have hpPos : (0 : Int) < a.decimal_point.val := by
simpa only [gt_iff_lt, IScalar.lt_equiv] using houter
have hnp : (1 : Int) <= a.decimal_point.val := by omega
rw [← hn] at hnp
exact_mod_cast hnp
have hnsmall : n.val <= 18 := by
have hnp : (n.val : Int) <= 18 := by rw [hn]; exact hp
exact_mod_cast hnp
have hkSmall : n.val <= shift.val := by
have hpow := (hsmall (by omega) hnsmall).2
have h2 : 2 ^ n.val <= 10 ^ n.val :=
Nat.pow_le_pow_left (by norm_num) _
have hpow2 : 2 ^ n.val < 2 ^ (shift.val + 1) :=
lt_of_le_of_lt h2 hpow
have hexp : n.val < shift.val + 1 :=
(Nat.pow_lt_pow_iff_right (by norm_num : 1 < (2 : Nat))).mp hpow2
omega
have hkSmallI : (n.val : Int) <= (shift.val : Int) := by
exact_mod_cast (show n.val <= shift.val from hkSmall)
omega
refine ⟨shift, hshift, ?_, hlargeK, hsmallK⟩
have hout' : e'.val = out.val := congrArg IScalar.val houtEq.symm
omega
· simp at hb
· simp [houter] at hb
let State := Std.Usize × Std.I32 × Bool × (Array Std.U8 768#usize) ×
Std.I32 × Option num.imp.dec2flt.common.BiasedFp
let stateDec := fun s : State =>
num.imp.dec2flt.decimal_seq.DecimalSeq.mk s.1 s.2.1
s.2.2.1 s.2.2.2.1
let stateExp := fun s : State => s.2.2.2.2.1
let stateBody := fun s : State =>
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
let sStart : State := (d.num_digits, d.decimal_point, d.truncated,
d.digits, 0#i32, none)
let sFinal : State := (d0.num_digits, d0.decimal_point, d0.truncated,
d0.digits, exp0, none)
have hloop : Aeneas.Std.loop stateBody sStart = ok sFinal := by
simpa [stateBody, sStart, sFinal,
num.imp.dec2flt.slow.parse_long_mantissa_loop0] using hcall
let stateInv := fun s : State =>
let a := stateDec s;
-324 <= a.decimal_point.val ∧ a.decimal_point.val < 310 ∧
a.num_digits.val <= 768 ∧
(forall b, b ∈ a.digits.val.take a.num_digits.val -> b.val < 10) ∧
(exists h tail,
(a.digits.val.take a.num_digits.val).map (fun b => b.val) = h :: tail ∧
1 <= h ∧ h < 10 ∧ (h :: tail).length = a.num_digits.val) ∧
0 <= (stateExp s).val ∧ (stateExp s).val <= 1260 ∧
s.2.2.2.2.2 = none ∧
(exists etaS uS : Real,
X / (2 : Real) ^ (stateExp s).val = V a + etaS ∧
Y / (2 : Real) ^ (stateExp s).val = V a + uS ∧
0 <= etaS ∧ etaS < uS ∧ (a.truncated = true ↔ 0 < etaS))
have hstartInv : stateInv sStart := by
dsimp [stateInv, stateDec, stateExp, sStart]
refine ⟨hpointLo, hpointHi, hcap, hdigit, hlead, by norm_num,
by norm_num, rfl, ?_⟩
refine ⟨eta, 10 ^ (d.decimal_point.val - 768), ?_, ?_, hetaLo, ?_, hsticky⟩
· simpa [V, List.map_take, zpow_zero, div_one] using hxeq
· simpa [V, List.map_take] using hY
· dsimp
exact hetaHi
have hfinalInv : stateInv sFinal := by
dsimp [stateInv, stateDec, stateExp, sFinal]
refine ⟨hterminal.1, ?_, hterminal.2.2.1,
hterminal.2.2.2.1, hterminal.2.2.2.2,
hterminalExp.1, hterminalExp.2, rfl, ?_⟩
· exact lt_of_le_of_lt hterminal.2.1 (by norm_num)
· exact hendpoints
have doneIdentity (s t : State)
(hb : stateBody s = ok (done t)) : s = t := by
by_cases hp : 0 < s.2.1.val
· by_cases hn : s.2.2.2.2.2 = none
· simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hp, hn] at hb
cases hfirst : lift (IScalar.hcast .Usize s.2.1) with
| fail err => simp [hfirst] at hb
| div => simp [hfirst] at hb
| ok n =>
simp only [Bind.bind, Aeneas.Std.bind, hfirst] at hb
cases hs : num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n with
| fail err => simp [hs] at hb
| div => simp [hs] at hb
| ok shift =>
cases hr : num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift
{ num_digits := s.1, decimal_point := s.2.1,
truncated := s.2.2.1, digits := s.2.2.2.1 } shift with
| fail err => simp [hs, hr] at hb
| div => simp [hs, hr] at hb
| ok a =>
have hneg : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE =
ok (-2047)#i32 := by
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
change IScalar.neg (2047#i32 : Std.I32) = _
unfold IScalar.neg IScalar.tryMk IScalar.tryMkOpt
norm_num [IScalar.check_bounds, IScalarTy.numBits]
simp only [hs, hr, hneg] at hb
split at hb
· simp at hb
· cases hc : lift (UScalar.hcast .I32 shift) with
| fail err => simp [hc] at hb
| div => simp [hc] at hb
| ok i3 =>
cases ha : s.2.2.2.2.1 + i3 with
| fail err => simp [hc, ha] at hb
| div => simp [hc, ha] at hb
| ok out => simp [hc, ha] at hb
· simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hp, hn] at hb
exact hb
· simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hp] at hb
exact hb
have hExpOrder : ∀ s t, Aeneas.Std.loop stateBody s = ok t →
t.2.2.2.2.2 = none ->
s.2.2.2.2.2 = none ∧ (stateExp s).val ≤ (stateExp t).val := by
apply P826_T1_ResultLoopBackward (fun s t =>
t.2.2.2.2.2 = none ->
s.2.2.2.2.2 = none ∧ (stateExp s).val ≤ (stateExp t).val) stateBody
· intro s t hb
intro htNone
have hs := doneIdentity s t hb
subst t
exact ⟨htNone, le_rfl⟩
· intro s s' t hb ih
intro htNone
rcases ih htNone with ⟨hnextNone, horder⟩
have hcurNone : s.2.2.2.2.2 = none := by
by_contra hn
simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hn] at hb
have hnextTuple :
(s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
s'.2.2.2.2.1, none) = s' := by
cases s' with
| mk n rest =>
cases rest with
| mk p rest =>
cases rest with
| mk b rest =>
cases rest with
| mk arr rest =>
cases rest with
| mk e opt => simp_all
have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
(stateDec s).num_digits (stateDec s).decimal_point
(stateDec s).truncated (stateDec s).digits (stateExp s) none =
ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
(stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
have hb0 := hb
rw [← hnextTuple] at hb0
simpa [stateBody, stateDec, stateExp, hcurNone] using hb0
obtain ⟨k, _, hupdate, _, _⟩ := bodyMono (stateDec s) (stateDec s')
(stateExp s) (stateExp s') hb'
have hmono : (stateExp s).val <= (stateExp s').val := by
have hk : (0 : Int) <= (k.val : Int) := Int.natCast_nonneg _
omega
exact ⟨hcurNone, le_trans hmono horder⟩
let stateCapRel := fun s t : State =>
∀ (c : Nat) (R : Int),
0 <= R - (stateExp t).val + 768 - (stateDec t).decimal_point.val ->
0 <= R - (stateExp s).val + 768 - (stateDec s).decimal_point.val ∧
(V (stateDec t) < (c : Real) * (2 : Real) ^ (R - (stateExp t).val) ->
V (stateDec s) < (c : Real) * (2 : Real) ^ (R - (stateExp s).val))
let historyRel := fun s t : State =>
(t.2.2.2.2.2 = none ->
s.2.2.2.2.2 = none ∧ (stateExp s).val <= (stateExp t).val) ∧
(stateInv t -> stateInv s ->
((stateDec s).decimal_point.val >= 0 ->
(stateDec t).decimal_point.val >= 0) ∧
((stateDec t).decimal_point.val < 0 ->
(stateExp s).val = (stateExp t).val) ∧
stateCapRel s t)
have hhistory : ∀ s t, Aeneas.Std.loop stateBody s = ok t ->
historyRel s t := (set_option maxHeartbeats 1600000 in by
apply P826_T1_ResultLoopBackward historyRel stateBody
· intro s t hb
have hst := doneIdentity s t hb
subst t
constructor
· intro hnone
exact ⟨hnone, le_rfl⟩
· intro htInv hsInv
refine ⟨fun h => h, fun _ => rfl, ?_⟩
intro c R hcap
exact ⟨hcap, fun hlt => hlt⟩
· intro s s' t hb ih
constructor
· intro htNone
rcases ih.1 htNone with ⟨hnextNone, hexpOrder⟩
have hcurNone : s.2.2.2.2.2 = none := by
by_contra hn
simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hn] at hb
have hnextTuple :
(s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
s'.2.2.2.2.1, none) = s' := by
cases s' with
| mk n rest =>
cases rest with
| mk p rest =>
cases rest with
| mk b rest =>
cases rest with
| mk arr rest =>
cases rest with
| mk e opt => simp_all
have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
(stateDec s).num_digits (stateDec s).decimal_point
(stateDec s).truncated (stateDec s).digits (stateExp s) none =
ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
(stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
have hb0 := hb
rw [← hnextTuple] at hb0
simpa [stateBody, stateDec, stateExp, hcurNone] using hb0
obtain ⟨k, _, hupdate, _, _⟩ := bodyMono (stateDec s) (stateDec s')
(stateExp s) (stateExp s') hb'
have hkNonneg : (0 : Int) <= (↑↑k : Int) := Int.natCast_nonneg _
have hmono : (stateExp s).val <= (stateExp s').val := by omega
exact ⟨hcurNone, le_trans hmono hexpOrder⟩
· intro htInv hsInv
have htInvSaved := htInv
dsimp only [stateInv, stateDec, stateExp] at htInv hsInv
rcases htInv with ⟨hpLoT, hpHiT, hcountT, hdigitT, hshapeT,
hexpLoT, hexpHiT, hsentT, hendT⟩
rcases hsInv with ⟨hpLoS, hpHiS, hcountS, hdigitS, hshapeS,
hexpLoS, hexpHiS, hsentS, hendS⟩
rcases hshapeS with ⟨headS, tailS, hshapeS, hheadS, hhead10S, hlenS⟩
have hnextBound := ih.1 hsentT
rcases hnextBound with ⟨hsentNext, hexpNextT⟩
have hpointPos : 1 <= (stateDec s).decimal_point.val := by
change 1 <= s.2.1.val
by_contra hn
have hp : ¬ 0 < s.2.1.val := by omega
simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hp] at hb
rcases hendS with ⟨etaS, uS, hXS, hYS, hetaS, hetauS, hstickyS⟩
have hstep := P495_T1_RightLoopStep (X / (2 : Real) ^ (stateExp s).val)
(Y / (2 : Real) ^ (stateExp s).val) (stateDec s) (stateExp s)
hpointPos hpHiS hexpLoS hexpHiS
⟨hcountS, hdigitS,
⟨headS, tailS, hshapeS, hheadS, hhead10S, hlenS⟩⟩
⟨etaS, uS, hXS, hYS, hetaS, hetauS, hstickyS⟩
rcases hstep with ⟨dn, shift, en, hbStep, hright, hshift, hexpStep,
hpLarge, hpSmall, hcountN, hdigitN, hshapeN, htrimN,
hendN, hstall, hrecover⟩
have hpLargeS : 19 <= s.2.1.val ->
dn.decimal_point.val = s.2.1.val - 18 ∨
dn.decimal_point.val = s.2.1.val - 19 := by
simpa [stateDec] using hpLarge
have hpSmallS : s.2.1.val <= 18 ->
dn.decimal_point.val = 0 ∨ dn.decimal_point.val = 1 := by
simpa [stateDec] using hpSmall
have hnextTuple :
(dn.num_digits, dn.decimal_point, dn.truncated, dn.digits,
en, none) = s' := by
have hb0 := hb
have hnextTuple0 :
(s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
s'.2.2.2.2.1, none) = s' := by
cases s' with
| mk n rest =>
cases rest with
| mk p rest =>
cases rest with
| mk b rest =>
cases rest with
| mk arr rest =>
cases rest with
| mk e opt => simp_all
rw [← hnextTuple0] at hb0
have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
(stateDec s).num_digits (stateDec s).decimal_point
(stateDec s).truncated (stateDec s).digits (stateExp s) none =
ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
(stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
simpa [stateBody, stateDec, stateExp, hsentS] using hb0
have hEq := Result.ok.inj (hbStep.symm.trans hb')
injection hEq with htup
rw [← hnextTuple0]
simpa [stateDec, stateExp] using htup
have hpointNLo : -324 <= dn.decimal_point.val := by
by_cases hlarge : 19 <= s.2.1.val
· rcases hpLargeS hlarge with hp | hp <;> omega
· rcases hpSmallS (by omega) with hp | hp <;> omega
have hpointNHi : dn.decimal_point.val < 310 := by
by_cases hlarge : 19 <= s.2.1.val
· rcases hpLargeS hlarge with hp | hp <;> omega
· rcases hpSmallS (by omega) with hp | hp <;> omega
have henEq : en = stateExp s' := by
have hh := congrArg (fun z : State => z.2.2.2.2.1) hnextTuple
simpa [stateExp] using hh
rcases hendN with ⟨etaN, uN, hXN, hYN, hetaN, hetauN, hstickyN⟩
have hscaleX : X / (2 : Real) ^
((stateExp s).val + (shift.val : Int)) =
(X / (2 : Real) ^ (stateExp s).val) /
(2 : Real) ^ (shift.val : Int) := by
rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _]
ring
have hscaleY : Y / (2 : Real) ^
((stateExp s).val + (shift.val : Int)) =
(Y / (2 : Real) ^ (stateExp s).val) /
(2 : Real) ^ (shift.val : Int) := by
rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _]
ring
have hXNext : X / (2 : Real) ^ en.val = V dn + etaN := by
rw [hexpStep, hscaleX]
exact hXN
have hYNext : Y / (2 : Real) ^ en.val = V dn + uN := by
rw [hexpStep, hscaleY]
exact hYN
have hnextInv : stateInv s' := by
rw [← hnextTuple]
dsimp only [stateInv, stateDec, stateExp]
refine ⟨hpointNLo, hpointNHi, hcountN, hdigitN, hshapeN,
?_, ?_, rfl, ?_⟩
· rw [hexpStep]
have hshiftNonneg : (0 : Int) <= (↑↑shift : Int) := by
exact Int.natCast_nonneg _
exact add_nonneg hexpLoS hshiftNonneg
· have hupper : (stateExp s').val <= 1260 :=
le_trans hexpNextT hexpHiT
simpa [henEq] using hupper
· exact ⟨etaN, uN, hXNext, hYNext, hetaN, hetauN, hstickyN⟩
have hback := ih.2 htInvSaved hnextInv
rcases hback with ⟨hpointBack, hnegativeBack, hcapBack⟩
have hpNextNonneg : 0 <= dn.decimal_point.val := by
by_cases hlarge : 19 <= s.2.1.val
· rcases hpLargeS hlarge with hp | hp <;> omega
· rcases hpSmallS (by omega) with hp | hp <;> omega
have hpNextState : 0 <= (stateDec s').decimal_point.val := by
have hpointEq : dn.decimal_point = s'.2.1 := by
have hh := congrArg (fun z : State => z.2.1) hnextTuple
simpa using hh
simpa [stateDec, hpointEq] using hpNextNonneg
refine ⟨?_, ?_, ?_⟩
· intro _
exact hpointBack hpNextState
· intro hpT
have hpT' : 0 <= (stateDec t).decimal_point.val := hpointBack hpNextState
omega
· intro c R hcapT
rcases hcapBack c R hcapT with ⟨hcapNext, hstrictNext⟩
have hbodyMono : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
(stateDec s).num_digits (stateDec s).decimal_point
(stateDec s).truncated (stateDec s).digits (stateExp s) none =
ok (cont (dn.num_digits, dn.decimal_point, dn.truncated,
dn.digits, en, none)) := by
have hb0 := hb
rw [← hnextTuple] at hb0
simpa [stateBody, stateDec, stateExp, hsentS] using hb0
obtain ⟨k, hkBound, hkUpdate, hkLarge, hkSmall⟩ :=
bodyMono (stateDec s) dn (stateExp s) en hbodyMono
have hkEq : (k.val : Int) = (shift.val : Int) := by
omega
have hpointDiff : s.2.1.val - dn.decimal_point.val <=
(shift.val : Int) := by
by_cases hlarge : 19 <= s.2.1.val
· have hp := hpLargeS hlarge
rcases hp with hp | hp
· rw [hp]
have h60 : (shift.val : Int) = 60 := by
have hkNat : k.val = 60 := hkLarge (by simpa [stateDec] using hlarge)
omega
omega
· rw [hp]
have h60 : (shift.val : Int) = 60 := by
have hkNat : k.val = 60 := hkLarge (by simpa [stateDec] using hlarge)
omega
omega
· have hpSmallS' : s.2.1.val <= 18 := by omega
have hp := hpSmallS hpSmallS'
rcases hp with hp | hp
· rw [hp]
have hkP := hkSmall (by simpa [stateDec] using hpSmallS')
change s.2.1.val <= (k.val : Int) at hkP
omega
· rw [hp]
have hkP := hkSmall (by simpa [stateDec] using hpSmallS')
change s.2.1.val <= (k.val : Int) at hkP
omega
have hcapSource : 0 <= R - (stateExp s).val + 768 -
(stateDec s).decimal_point.val := by
have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
have hh := congrArg (fun z : State => z.2.1) hnextTuple
simpa [stateDec] using hh
have hcapNext' : 0 <= R - en.val + 768 - dn.decimal_point.val := by
have heVal := congrArg IScalar.val henEq
have hpVal : dn.decimal_point.val =
(stateDec s').decimal_point.val := by simpa using congrArg IScalar.val hpEq
rw [heVal, hpVal]
exact hcapNext
change 0 <= R - (stateExp s).val + 768 - s.2.1.val
omega
have hstrictSource :
V (stateDec t) < (c : Real) *
(2 : Real) ^ (R - (stateExp t).val) ->
V (stateDec s) < (c : Real) *
(2 : Real) ^ (R - (stateExp s).val) :=
(set_option maxHeartbeats 1600000 in by
intro hstrictTerminal
by_contra hnot
have hle : (c : Real) * (2 : Real) ^
(R - (stateExp s).val) <= V (stateDec s) := le_of_not_gt hnot
have hgrid := P856_T1_CoefficientGridAlignment c
(R - en.val) dn.decimal_point.val (by omega) (by
have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
have hh := congrArg (fun z : State => z.2.1) hnextTuple
simpa [stateDec] using hh
have heVal := congrArg IScalar.val henEq
have hpVal : dn.decimal_point.val =
(stateDec s').decimal_point.val := by simpa using congrArg IScalar.val hpEq
rw [heVal, hpVal]
exact hcapNext)
rcases hgrid with ⟨b, hbgrid⟩
have hpowRel : (2 : Real) ^ (R - (stateExp s).val) =
(2 : Real) ^ (R - en.val) * (2 : Real) ^ shift.val := by
rw [show R - (stateExp s).val = (R - en.val) +
(shift.val : Int) by omega]
rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
norm_num [zpow_natCast]
have hmulBound : (c : Real) *
(2 : Real) ^ (R - en.val) * (2 : Real) ^ shift.val <=
V (stateDec s) := by
calc
(c : Real) * (2 : Real) ^ (R - en.val) *
(2 : Real) ^ shift.val =
(c : Real) * ((2 : Real) ^ (R - en.val) *
(2 : Real) ^ shift.val) := by ring
_ = (c : Real) * (2 : Real) ^
(R - (stateExp s).val) := by rw [← hpowRel]
_ <= V (stateDec s) := hle
have hshiftPos : (0 : Real) < (2 : Real) ^ shift.val := by
positivity
have hnatpow : (2 : Real) ^ shift.val =
(2 : Real) ^ (shift.val : Int) := by
norm_num [zpow_natCast]
have hboundary : (b : Real) *
(10 : Real) ^ (dn.decimal_point.val - 768) <=
V (stateDec s) / (2 : Real) ^ shift.val := by
rw [← hbgrid, hnatpow]
exact (le_div_iff₀ hshiftPos).2 (by simpa [mul_assoc] using hmulBound)
have hnonreset : ¬ (dn.num_digits.val = 0 ∧
dn.decimal_point.val = 0 ∧ dn.truncated = false) := by
intro hreset
rcases hshapeN with ⟨headN, tailN, _, hheadN, _, hlenN⟩
have hposN : 1 <= dn.num_digits.val := by
rw [← hlenN]
simp
omega
have hxs := hdigitS
have hvbounds := P472_T1_DecimalValueBounds
((stateDec s).digits.val.take (stateDec s).num_digits.val |>.map
(fun z => z.val)) headS tailS hshapeS hheadS
(fun q hq => by
rcases List.mem_map.mp hq with ⟨z, hz, hzq⟩
have hzd := hdigitS z hz
simpa [hzq] using hzd)
(stateDec s).decimal_point.val
have hVpositive : 0 < V (stateDec s) := by
have hlow := hvbounds.1
have hpowpos : (0 : Real) < (10 : Real) ^
((stateDec s).decimal_point.val - 1) := by
exact zpow_pos (by norm_num) _
have hheadReal : (1 : Real) <= (headS : Real) := by
exact_mod_cast hheadS
have hprod : 0 < (headS : Real) * (10 : Real) ^
((stateDec s).decimal_point.val - 1) :=
mul_pos (by linarith) hpowpos
have hlow' : (headS : Real) * (10 : Real) ^
((stateDec s).decimal_point.val - 1) <=
V (stateDec s) := by
rw [hshapeS, hlenS] at hlow
dsimp only [V]
rw [hshapeS]
simpa [V, List.map_take, List.foldl_cons] using hlow
exact lt_of_lt_of_le hprod hlow'
have htransport := P529_T1_RightBoundaryTransport
(stateDec s) dn shift hshift hdigitS hright hnonreset hcountN
hVpositive b hboundary
have hstrictNext' : V dn <
(c : Real) * (2 : Real) ^ (R - en.val) := by
have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
have hh := congrArg (fun z : State => z.2.1) hnextTuple
simpa [stateDec] using hh
have hnEq : dn.num_digits = (stateDec s').num_digits := by
have hh := congrArg (fun z : State => z.1) hnextTuple
simpa [stateDec] using hh
have hdEq : dn.digits = (stateDec s').digits := by
have hh := congrArg (fun z : State => z.2.2.2.1) hnextTuple
simpa [stateDec] using hh
have hstrictNextInput := hstrictNext hstrictTerminal
simpa [V, stateDec, hpEq, hnEq, hdEq, henEq] using hstrictNextInput
have hstrictGrid : V dn < (b : Real) *
(10 : Real) ^ (dn.decimal_point.val - 768) := by
rw [← hbgrid]
exact hstrictNext'
exact (not_lt_of_ge htransport) hstrictGrid
)
exact ⟨hcapSource, hstrictSource⟩
)
have hhist := hhistory sStart sFinal hloop
rcases hhist with ⟨hfinalNone, hhistoryProp⟩
have hnegResult : d0.decimal_point.val < 0 -> exp0.val = 0 := by
intro hneg
have hsame := (hhistoryProp hfinalInv hstartInv).2.1 hneg
simpa [sStart, sFinal, stateExp] using hsame.symm
have hcapacityResult : ∀ (c : Nat) (R : Int),
0 <= R - exp0.val + 768 - d0.decimal_point.val ->
0 <= R + 768 - d.decimal_point.val ∧
(V d0 < (c : Real) * (2 : Real) ^ (R - exp0.val) ->
V d < (c : Real) * (2 : Real) ^ R) := by
intro c R hcap0
have hcap := (hhistoryProp hfinalInv hstartInv).2.2 c R (by
simpa [sFinal, stateDec, stateExp] using hcap0)
simpa [sStart, sFinal, stateDec, stateExp] using hcap
exact ⟨hnegResult, hcapacityResult⟩
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.P495_T1_SlowLoop0Execution
import Tablet.P495_T1_RightLoopStep
import Tablet.P529_T1_RightBoundaryTransport
import Tablet.P826_T1_ResultLoopBackward
import Tablet.ResultLoopPartial
import Tablet.P856_T1_CoefficientGridAlignment
import Tablet.P472_T1_DecimalValueBounds
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P529_T1_RightHistoryBoundary]
theorem P529_T1_RightHistoryBoundary (X Y : Real)
(d d0 : num.imp.dec2flt.decimal_seq.DecimalSeq) (exp0 : Std.I32)
(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))
(hcall : 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)) :
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)) ->
(d0.decimal_point.val < 0 -> exp0.val = 0) /\
(forall (c : Nat) (R : Int),
0 <= R - exp0.val + 768 - d0.decimal_point.val ->
0 <= R + 768 - d.decimal_point.val /\
(V d0 < (c : Real) * (2 : Real) ^ (R - exp0.val) ->
V d < (c : Real) * (2 : Real) ^ R)) := by
-- BODY
dsimp only
intro hY hX
classical
rcases hX with ⟨eta, hxeq, hetaLo, hetaHi, hsticky⟩
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))
rcases hinput with ⟨hcap, hdigit, hlead⟩
have hrun := P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi
⟨hcap, hdigit, hlead⟩ hY ⟨eta, hxeq, hetaLo, hetaHi, hsticky⟩
rcases hrun with ⟨dF, eF, steps, hrun, hsteps, heFLo, heFHi,
hXlower, hpFLo, hpFHi, hcapF, hdigitF, hleadF, hlastF, hendF⟩
have hfinalEq := Result.ok.inj (hrun.symm.trans hcall)
have hn : dF.num_digits = d0.num_digits := congrArg (fun z => z.1) hfinalEq
have hp : dF.decimal_point = d0.decimal_point :=
congrArg (fun z => z.2.1) hfinalEq
have ht : dF.truncated = d0.truncated := congrArg (fun z => z.2.2.1) hfinalEq
have ha : dF.digits = d0.digits := congrArg (fun z => z.2.2.2.1) hfinalEq
have he : eF = exp0 := congrArg (fun z => z.2.2.2.2.1) hfinalEq
have hterminal : -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) := by
exact ⟨by simpa [hp] using hpFLo, by simpa [hp] using hpFHi,
by simpa [hn] using hcapF, by simpa [hn, ha] using hdigitF,
by simpa [hn, ha] using hleadF⟩
have hendpoints : ∃ 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
simpa [V, he, hn, hp, ht, ha] using hendF
have hterminalExp : 0 <= exp0.val ∧ exp0.val <= 1260 := by
constructor
· simpa [he] using heFLo
· calc
exp0.val <= 60 * steps := by simpa [he] using heFHi
_ <= 60 * 21 := by omega
_ = 1260 := by norm_num
have bodyMono (a a' : num.imp.dec2flt.decimal_seq.DecimalSeq)
(e e' : Std.I32)
(hb : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
a.num_digits a.decimal_point a.truncated a.digits e none =
ok (cont (a'.num_digits, a'.decimal_point, a'.truncated,
a'.digits, e', none))) :
∃ k : Std.Usize,
k.val <= 60 ∧ e'.val = e.val + (k.val : Int) ∧
(19 <= a.decimal_point.val -> k.val = 60) ∧
(a.decimal_point.val <= 18 ->
a.decimal_point.val <= (k.val : Int)) := by
unfold num.imp.dec2flt.slow.parse_long_mantissa_loop0.body at hb
by_cases houter : a.decimal_point > 0#i32
· simp only [if_pos houter, core.option.Option.is_none] at hb
split at hb
· obtain ⟨n, hncast, hnval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize a.decimal_point (by scalar_tac))
let traits := F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
let shift : Std.Usize := match n.val with
| 0 => 0#usize | 1 => 3#usize | 2 => 6#usize | 3 => 9#usize
| 4 => 13#usize | 5 => 16#usize | 6 => 19#usize | 7 => 23#usize
| 8 => 26#usize | 9 => 29#usize | 10 => 33#usize | 11 => 36#usize
| 12 => 39#usize | 13 => 43#usize | 14 => 46#usize | 15 => 49#usize
| 16 => 53#usize | 17 => 56#usize | 18 => 59#usize | _ => 60#usize
have hcert := SlowShiftSelectorCertificate traits n
dsimp only at hcert
rcases hcert with ⟨hselector, hshift, _, hsmall, hlarge⟩
have hs : num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n = ok shift := by
simpa [traits, shift] using hselector
have hneg : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE =
ok (-2047)#i32 := by
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
change IScalar.neg (2047#i32 : Std.I32) = _
unfold IScalar.neg IScalar.tryMk IScalar.tryMkOpt
norm_num [IScalar.check_bounds, IScalarTy.numBits]
simp only [Bind.bind, Aeneas.Std.bind, hncast, hs, hneg] at hb
cases hr : num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift
{ num_digits := a.num_digits, decimal_point := a.decimal_point,
truncated := a.truncated, digits := a.digits } shift <;>
simp [hr] at hb
split at hb
· simp at hb
· cases hc : lift (UScalar.hcast .I32 shift) with
| fail err => simp [hc] at hb
| div => simp [hc] at hb
| ok i3 =>
simp [hc] at hb
cases ha : e + i3 with
| fail err => simp [ha] at hb
| div => simp [ha] at hb
| ok out =>
simp [ha] at hb
have haddval := IScalar.add_equiv e i3
rw [ha] at haddval
obtain ⟨_, houtval, _⟩ := haddval
have hshiftI : (i3.val : Int) = (shift.val : Int) := by
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.hcast_inBounds_spec .I32 shift (by
have hi : (shift.val : Int) <= 60 := by exact_mod_cast hshift
rw [IScalar.max_I32_eq]
norm_num [IScalarTy.numBits]
omega))
have hz' : lift (UScalar.hcast .I32 shift) = ok z := by
simpa [lift] using hz
have hiz : i3 = z := Result.ok.inj (hc.symm.trans hz')
subst z
simpa [WP.spec_ok] using hzval
have hout : out.val = e.val + (shift.val : Int) := by
simpa [hshiftI] using houtval
rcases hb with ⟨_, hpointEq, _, _, houtEq⟩
have hlargeK : 19 <= a.decimal_point.val -> shift.val = 60 := by
intro hp
have hnlarge : 19 <= n.val := by
have hn : (n.val : Int) = a.decimal_point.val := by
simpa using hnval
exact_mod_cast (by omega : (19 : Int) <= (n.val : Int))
exact (hlarge hnlarge).1
have hsmallK : a.decimal_point.val <= 18 ->
a.decimal_point.val <= (shift.val : Int) := by
intro hp
have hn : (n.val : Int) = a.decimal_point.val := by
simpa using hnval
have hnpos : 1 <= n.val := by
have hpPos : (0 : Int) < a.decimal_point.val := by
simpa only [gt_iff_lt, IScalar.lt_equiv] using houter
have hnp : (1 : Int) <= a.decimal_point.val := by omega
rw [← hn] at hnp
exact_mod_cast hnp
have hnsmall : n.val <= 18 := by
have hnp : (n.val : Int) <= 18 := by rw [hn]; exact hp
exact_mod_cast hnp
have hkSmall : n.val <= shift.val := by
have hpow := (hsmall (by omega) hnsmall).2
have h2 : 2 ^ n.val <= 10 ^ n.val :=
Nat.pow_le_pow_left (by norm_num) _
have hpow2 : 2 ^ n.val < 2 ^ (shift.val + 1) :=
lt_of_le_of_lt h2 hpow
have hexp : n.val < shift.val + 1 :=
(Nat.pow_lt_pow_iff_right (by norm_num : 1 < (2 : Nat))).mp hpow2
omega
have hkSmallI : (n.val : Int) <= (shift.val : Int) := by
exact_mod_cast (show n.val <= shift.val from hkSmall)
omega
refine ⟨shift, hshift, ?_, hlargeK, hsmallK⟩
have hout' : e'.val = out.val := congrArg IScalar.val houtEq.symm
omega
· simp at hb
· simp [houter] at hb
let State := Std.Usize × Std.I32 × Bool × (Array Std.U8 768#usize) ×
Std.I32 × Option num.imp.dec2flt.common.BiasedFp
let stateDec := fun s : State =>
num.imp.dec2flt.decimal_seq.DecimalSeq.mk s.1 s.2.1
s.2.2.1 s.2.2.2.1
let stateExp := fun s : State => s.2.2.2.2.1
let stateBody := fun s : State =>
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
let sStart : State := (d.num_digits, d.decimal_point, d.truncated,
d.digits, 0#i32, none)
let sFinal : State := (d0.num_digits, d0.decimal_point, d0.truncated,
d0.digits, exp0, none)
have hloop : Aeneas.Std.loop stateBody sStart = ok sFinal := by
simpa [stateBody, sStart, sFinal,
num.imp.dec2flt.slow.parse_long_mantissa_loop0] using hcall
let stateInv := fun s : State =>
let a := stateDec s;
-324 <= a.decimal_point.val ∧ a.decimal_point.val < 310 ∧
a.num_digits.val <= 768 ∧
(forall b, b ∈ a.digits.val.take a.num_digits.val -> b.val < 10) ∧
(exists h tail,
(a.digits.val.take a.num_digits.val).map (fun b => b.val) = h :: tail ∧
1 <= h ∧ h < 10 ∧ (h :: tail).length = a.num_digits.val) ∧
0 <= (stateExp s).val ∧ (stateExp s).val <= 1260 ∧
s.2.2.2.2.2 = none ∧
(exists etaS uS : Real,
X / (2 : Real) ^ (stateExp s).val = V a + etaS ∧
Y / (2 : Real) ^ (stateExp s).val = V a + uS ∧
0 <= etaS ∧ etaS < uS ∧ (a.truncated = true ↔ 0 < etaS))
have hstartInv : stateInv sStart := by
dsimp [stateInv, stateDec, stateExp, sStart]
refine ⟨hpointLo, hpointHi, hcap, hdigit, hlead, by norm_num,
by norm_num, rfl, ?_⟩
refine ⟨eta, 10 ^ (d.decimal_point.val - 768), ?_, ?_, hetaLo, ?_, hsticky⟩
· simpa [V, List.map_take, zpow_zero, div_one] using hxeq
· simpa [V, List.map_take] using hY
· dsimp
exact hetaHi
have hfinalInv : stateInv sFinal := by
dsimp [stateInv, stateDec, stateExp, sFinal]
refine ⟨hterminal.1, ?_, hterminal.2.2.1,
hterminal.2.2.2.1, hterminal.2.2.2.2,
hterminalExp.1, hterminalExp.2, rfl, ?_⟩
· exact lt_of_le_of_lt hterminal.2.1 (by norm_num)
· exact hendpoints
have doneIdentity (s t : State)
(hb : stateBody s = ok (done t)) : s = t := by
by_cases hp : 0 < s.2.1.val
· by_cases hn : s.2.2.2.2.2 = none
· simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hp, hn] at hb
cases hfirst : lift (IScalar.hcast .Usize s.2.1) with
| fail err => simp [hfirst] at hb
| div => simp [hfirst] at hb
| ok n =>
simp only [Bind.bind, Aeneas.Std.bind, hfirst] at hb
cases hs : num.imp.dec2flt.slow.parse_long_mantissa.closure.Insts.CoreOpsFunctionFnTupleUsizeUsize.call
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 () n with
| fail err => simp [hs] at hb
| div => simp [hs] at hb
| ok shift =>
cases hr : num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift
{ num_digits := s.1, decimal_point := s.2.1,
truncated := s.2.2.1, digits := s.2.2.2.1 } shift with
| fail err => simp [hs, hr] at hb
| div => simp [hs, hr] at hb
| ok a =>
have hneg : -. num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE =
ok (-2047)#i32 := by
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.DECIMAL_POINT_RANGE
change IScalar.neg (2047#i32 : Std.I32) = _
unfold IScalar.neg IScalar.tryMk IScalar.tryMkOpt
norm_num [IScalar.check_bounds, IScalarTy.numBits]
simp only [hs, hr, hneg] at hb
split at hb
· simp at hb
· cases hc : lift (UScalar.hcast .I32 shift) with
| fail err => simp [hc] at hb
| div => simp [hc] at hb
| ok i3 =>
cases ha : s.2.2.2.2.1 + i3 with
| fail err => simp [hc, ha] at hb
| div => simp [hc, ha] at hb
| ok out => simp [hc, ha] at hb
· simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hp, hn] at hb
exact hb
· simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hp] at hb
exact hb
have hExpOrder : ∀ s t, Aeneas.Std.loop stateBody s = ok t →
t.2.2.2.2.2 = none ->
s.2.2.2.2.2 = none ∧ (stateExp s).val ≤ (stateExp t).val := by
apply P826_T1_ResultLoopBackward (fun s t =>
t.2.2.2.2.2 = none ->
s.2.2.2.2.2 = none ∧ (stateExp s).val ≤ (stateExp t).val) stateBody
· intro s t hb
intro htNone
have hs := doneIdentity s t hb
subst t
exact ⟨htNone, le_rfl⟩
· intro s s' t hb ih
intro htNone
rcases ih htNone with ⟨hnextNone, horder⟩
have hcurNone : s.2.2.2.2.2 = none := by
by_contra hn
simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hn] at hb
have hnextTuple :
(s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
s'.2.2.2.2.1, none) = s' := by
cases s' with
| mk n rest =>
cases rest with
| mk p rest =>
cases rest with
| mk b rest =>
cases rest with
| mk arr rest =>
cases rest with
| mk e opt => simp_all
have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
(stateDec s).num_digits (stateDec s).decimal_point
(stateDec s).truncated (stateDec s).digits (stateExp s) none =
ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
(stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
have hb0 := hb
rw [← hnextTuple] at hb0
simpa [stateBody, stateDec, stateExp, hcurNone] using hb0
obtain ⟨k, _, hupdate, _, _⟩ := bodyMono (stateDec s) (stateDec s')
(stateExp s) (stateExp s') hb'
have hmono : (stateExp s).val <= (stateExp s').val := by
have hk : (0 : Int) <= (k.val : Int) := Int.natCast_nonneg _
omega
exact ⟨hcurNone, le_trans hmono horder⟩
let stateCapRel := fun s t : State =>
∀ (c : Nat) (R : Int),
0 <= R - (stateExp t).val + 768 - (stateDec t).decimal_point.val ->
0 <= R - (stateExp s).val + 768 - (stateDec s).decimal_point.val ∧
(V (stateDec t) < (c : Real) * (2 : Real) ^ (R - (stateExp t).val) ->
V (stateDec s) < (c : Real) * (2 : Real) ^ (R - (stateExp s).val))
let historyRel := fun s t : State =>
(t.2.2.2.2.2 = none ->
s.2.2.2.2.2 = none ∧ (stateExp s).val <= (stateExp t).val) ∧
(stateInv t -> stateInv s ->
((stateDec s).decimal_point.val >= 0 ->
(stateDec t).decimal_point.val >= 0) ∧
((stateDec t).decimal_point.val < 0 ->
(stateExp s).val = (stateExp t).val) ∧
stateCapRel s t)
have hhistory : ∀ s t, Aeneas.Std.loop stateBody s = ok t ->
historyRel s t := (set_option maxHeartbeats 1600000 in by
apply P826_T1_ResultLoopBackward historyRel stateBody
· intro s t hb
have hst := doneIdentity s t hb
subst t
constructor
· intro hnone
exact ⟨hnone, le_rfl⟩
· intro htInv hsInv
refine ⟨fun h => h, fun _ => rfl, ?_⟩
intro c R hcap
exact ⟨hcap, fun hlt => hlt⟩
· intro s s' t hb ih
constructor
· intro htNone
rcases ih.1 htNone with ⟨hnextNone, hexpOrder⟩
have hcurNone : s.2.2.2.2.2 = none := by
by_contra hn
simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hn] at hb
have hnextTuple :
(s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
s'.2.2.2.2.1, none) = s' := by
cases s' with
| mk n rest =>
cases rest with
| mk p rest =>
cases rest with
| mk b rest =>
cases rest with
| mk arr rest =>
cases rest with
| mk e opt => simp_all
have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
(stateDec s).num_digits (stateDec s).decimal_point
(stateDec s).truncated (stateDec s).digits (stateExp s) none =
ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
(stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
have hb0 := hb
rw [← hnextTuple] at hb0
simpa [stateBody, stateDec, stateExp, hcurNone] using hb0
obtain ⟨k, _, hupdate, _, _⟩ := bodyMono (stateDec s) (stateDec s')
(stateExp s) (stateExp s') hb'
have hkNonneg : (0 : Int) <= (↑↑k : Int) := Int.natCast_nonneg _
have hmono : (stateExp s).val <= (stateExp s').val := by omega
exact ⟨hcurNone, le_trans hmono hexpOrder⟩
· intro htInv hsInv
have htInvSaved := htInv
dsimp only [stateInv, stateDec, stateExp] at htInv hsInv
rcases htInv with ⟨hpLoT, hpHiT, hcountT, hdigitT, hshapeT,
hexpLoT, hexpHiT, hsentT, hendT⟩
rcases hsInv with ⟨hpLoS, hpHiS, hcountS, hdigitS, hshapeS,
hexpLoS, hexpHiS, hsentS, hendS⟩
rcases hshapeS with ⟨headS, tailS, hshapeS, hheadS, hhead10S, hlenS⟩
have hnextBound := ih.1 hsentT
rcases hnextBound with ⟨hsentNext, hexpNextT⟩
have hpointPos : 1 <= (stateDec s).decimal_point.val := by
change 1 <= s.2.1.val
by_contra hn
have hp : ¬ 0 < s.2.1.val := by omega
simp [stateBody, num.imp.dec2flt.slow.parse_long_mantissa_loop0.body,
hp] at hb
rcases hendS with ⟨etaS, uS, hXS, hYS, hetaS, hetauS, hstickyS⟩
have hstep := P495_T1_RightLoopStep (X / (2 : Real) ^ (stateExp s).val)
(Y / (2 : Real) ^ (stateExp s).val) (stateDec s) (stateExp s)
hpointPos hpHiS hexpLoS hexpHiS
⟨hcountS, hdigitS,
⟨headS, tailS, hshapeS, hheadS, hhead10S, hlenS⟩⟩
⟨etaS, uS, hXS, hYS, hetaS, hetauS, hstickyS⟩
rcases hstep with ⟨dn, shift, en, hbStep, hright, hshift, hexpStep,
hpLarge, hpSmall, hcountN, hdigitN, hshapeN, htrimN,
hendN, hstall, hrecover⟩
have hpLargeS : 19 <= s.2.1.val ->
dn.decimal_point.val = s.2.1.val - 18 ∨
dn.decimal_point.val = s.2.1.val - 19 := by
simpa [stateDec] using hpLarge
have hpSmallS : s.2.1.val <= 18 ->
dn.decimal_point.val = 0 ∨ dn.decimal_point.val = 1 := by
simpa [stateDec] using hpSmall
have hnextTuple :
(dn.num_digits, dn.decimal_point, dn.truncated, dn.digits,
en, none) = s' := by
have hb0 := hb
have hnextTuple0 :
(s'.1, s'.2.1, s'.2.2.1, s'.2.2.2.1,
s'.2.2.2.2.1, none) = s' := by
cases s' with
| mk n rest =>
cases rest with
| mk p rest =>
cases rest with
| mk b rest =>
cases rest with
| mk arr rest =>
cases rest with
| mk e opt => simp_all
rw [← hnextTuple0] at hb0
have hb' : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
(stateDec s).num_digits (stateDec s).decimal_point
(stateDec s).truncated (stateDec s).digits (stateExp s) none =
ok (cont ((stateDec s').num_digits, (stateDec s').decimal_point,
(stateDec s').truncated, (stateDec s').digits, stateExp s', none)) := by
simpa [stateBody, stateDec, stateExp, hsentS] using hb0
have hEq := Result.ok.inj (hbStep.symm.trans hb')
injection hEq with htup
rw [← hnextTuple0]
simpa [stateDec, stateExp] using htup
have hpointNLo : -324 <= dn.decimal_point.val := by
by_cases hlarge : 19 <= s.2.1.val
· rcases hpLargeS hlarge with hp | hp <;> omega
· rcases hpSmallS (by omega) with hp | hp <;> omega
have hpointNHi : dn.decimal_point.val < 310 := by
by_cases hlarge : 19 <= s.2.1.val
· rcases hpLargeS hlarge with hp | hp <;> omega
· rcases hpSmallS (by omega) with hp | hp <;> omega
have henEq : en = stateExp s' := by
have hh := congrArg (fun z : State => z.2.2.2.2.1) hnextTuple
simpa [stateExp] using hh
rcases hendN with ⟨etaN, uN, hXN, hYN, hetaN, hetauN, hstickyN⟩
have hscaleX : X / (2 : Real) ^
((stateExp s).val + (shift.val : Int)) =
(X / (2 : Real) ^ (stateExp s).val) /
(2 : Real) ^ (shift.val : Int) := by
rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _]
ring
have hscaleY : Y / (2 : Real) ^
((stateExp s).val + (shift.val : Int)) =
(Y / (2 : Real) ^ (stateExp s).val) /
(2 : Real) ^ (shift.val : Int) := by
rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _]
ring
have hXNext : X / (2 : Real) ^ en.val = V dn + etaN := by
rw [hexpStep, hscaleX]
exact hXN
have hYNext : Y / (2 : Real) ^ en.val = V dn + uN := by
rw [hexpStep, hscaleY]
exact hYN
have hnextInv : stateInv s' := by
rw [← hnextTuple]
dsimp only [stateInv, stateDec, stateExp]
refine ⟨hpointNLo, hpointNHi, hcountN, hdigitN, hshapeN,
?_, ?_, rfl, ?_⟩
· rw [hexpStep]
have hshiftNonneg : (0 : Int) <= (↑↑shift : Int) := by
exact Int.natCast_nonneg _
exact add_nonneg hexpLoS hshiftNonneg
· have hupper : (stateExp s').val <= 1260 :=
le_trans hexpNextT hexpHiT
simpa [henEq] using hupper
· exact ⟨etaN, uN, hXNext, hYNext, hetaN, hetauN, hstickyN⟩
have hback := ih.2 htInvSaved hnextInv
rcases hback with ⟨hpointBack, hnegativeBack, hcapBack⟩
have hpNextNonneg : 0 <= dn.decimal_point.val := by
by_cases hlarge : 19 <= s.2.1.val
· rcases hpLargeS hlarge with hp | hp <;> omega
· rcases hpSmallS (by omega) with hp | hp <;> omega
have hpNextState : 0 <= (stateDec s').decimal_point.val := by
have hpointEq : dn.decimal_point = s'.2.1 := by
have hh := congrArg (fun z : State => z.2.1) hnextTuple
simpa using hh
simpa [stateDec, hpointEq] using hpNextNonneg
refine ⟨?_, ?_, ?_⟩
· intro _
exact hpointBack hpNextState
· intro hpT
have hpT' : 0 <= (stateDec t).decimal_point.val := hpointBack hpNextState
omega
· intro c R hcapT
rcases hcapBack c R hcapT with ⟨hcapNext, hstrictNext⟩
have hbodyMono : num.imp.dec2flt.slow.parse_long_mantissa_loop0.body
F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
{ m := 0#u64, p_biased := 0#i32 }
(stateDec s).num_digits (stateDec s).decimal_point
(stateDec s).truncated (stateDec s).digits (stateExp s) none =
ok (cont (dn.num_digits, dn.decimal_point, dn.truncated,
dn.digits, en, none)) := by
have hb0 := hb
rw [← hnextTuple] at hb0
simpa [stateBody, stateDec, stateExp, hsentS] using hb0
obtain ⟨k, hkBound, hkUpdate, hkLarge, hkSmall⟩ :=
bodyMono (stateDec s) dn (stateExp s) en hbodyMono
have hkEq : (k.val : Int) = (shift.val : Int) := by
omega
have hpointDiff : s.2.1.val - dn.decimal_point.val <=
(shift.val : Int) := by
by_cases hlarge : 19 <= s.2.1.val
· have hp := hpLargeS hlarge
rcases hp with hp | hp
· rw [hp]
have h60 : (shift.val : Int) = 60 := by
have hkNat : k.val = 60 := hkLarge (by simpa [stateDec] using hlarge)
omega
omega
· rw [hp]
have h60 : (shift.val : Int) = 60 := by
have hkNat : k.val = 60 := hkLarge (by simpa [stateDec] using hlarge)
omega
omega
· have hpSmallS' : s.2.1.val <= 18 := by omega
have hp := hpSmallS hpSmallS'
rcases hp with hp | hp
· rw [hp]
have hkP := hkSmall (by simpa [stateDec] using hpSmallS')
change s.2.1.val <= (k.val : Int) at hkP
omega
· rw [hp]
have hkP := hkSmall (by simpa [stateDec] using hpSmallS')
change s.2.1.val <= (k.val : Int) at hkP
omega
have hcapSource : 0 <= R - (stateExp s).val + 768 -
(stateDec s).decimal_point.val := by
have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
have hh := congrArg (fun z : State => z.2.1) hnextTuple
simpa [stateDec] using hh
have hcapNext' : 0 <= R - en.val + 768 - dn.decimal_point.val := by
have heVal := congrArg IScalar.val henEq
have hpVal : dn.decimal_point.val =
(stateDec s').decimal_point.val := by simpa using congrArg IScalar.val hpEq
rw [heVal, hpVal]
exact hcapNext
change 0 <= R - (stateExp s).val + 768 - s.2.1.val
omega
have hstrictSource :
V (stateDec t) < (c : Real) *
(2 : Real) ^ (R - (stateExp t).val) ->
V (stateDec s) < (c : Real) *
(2 : Real) ^ (R - (stateExp s).val) :=
(set_option maxHeartbeats 1600000 in by
intro hstrictTerminal
by_contra hnot
have hle : (c : Real) * (2 : Real) ^
(R - (stateExp s).val) <= V (stateDec s) := le_of_not_gt hnot
have hgrid := P856_T1_CoefficientGridAlignment c
(R - en.val) dn.decimal_point.val (by omega) (by
have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
have hh := congrArg (fun z : State => z.2.1) hnextTuple
simpa [stateDec] using hh
have heVal := congrArg IScalar.val henEq
have hpVal : dn.decimal_point.val =
(stateDec s').decimal_point.val := by simpa using congrArg IScalar.val hpEq
rw [heVal, hpVal]
exact hcapNext)
rcases hgrid with ⟨b, hbgrid⟩
have hpowRel : (2 : Real) ^ (R - (stateExp s).val) =
(2 : Real) ^ (R - en.val) * (2 : Real) ^ shift.val := by
rw [show R - (stateExp s).val = (R - en.val) +
(shift.val : Int) by omega]
rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
norm_num [zpow_natCast]
have hmulBound : (c : Real) *
(2 : Real) ^ (R - en.val) * (2 : Real) ^ shift.val <=
V (stateDec s) := by
calc
(c : Real) * (2 : Real) ^ (R - en.val) *
(2 : Real) ^ shift.val =
(c : Real) * ((2 : Real) ^ (R - en.val) *
(2 : Real) ^ shift.val) := by ring
_ = (c : Real) * (2 : Real) ^
(R - (stateExp s).val) := by rw [← hpowRel]
_ <= V (stateDec s) := hle
have hshiftPos : (0 : Real) < (2 : Real) ^ shift.val := by
positivity
have hnatpow : (2 : Real) ^ shift.val =
(2 : Real) ^ (shift.val : Int) := by
norm_num [zpow_natCast]
have hboundary : (b : Real) *
(10 : Real) ^ (dn.decimal_point.val - 768) <=
V (stateDec s) / (2 : Real) ^ shift.val := by
rw [← hbgrid, hnatpow]
exact (le_div_iff₀ hshiftPos).2 (by simpa [mul_assoc] using hmulBound)
have hnonreset : ¬ (dn.num_digits.val = 0 ∧
dn.decimal_point.val = 0 ∧ dn.truncated = false) := by
intro hreset
rcases hshapeN with ⟨headN, tailN, _, hheadN, _, hlenN⟩
have hposN : 1 <= dn.num_digits.val := by
rw [← hlenN]
simp
omega
have hxs := hdigitS
have hvbounds := P472_T1_DecimalValueBounds
((stateDec s).digits.val.take (stateDec s).num_digits.val |>.map
(fun z => z.val)) headS tailS hshapeS hheadS
(fun q hq => by
rcases List.mem_map.mp hq with ⟨z, hz, hzq⟩
have hzd := hdigitS z hz
simpa [hzq] using hzd)
(stateDec s).decimal_point.val
have hVpositive : 0 < V (stateDec s) := by
have hlow := hvbounds.1
have hpowpos : (0 : Real) < (10 : Real) ^
((stateDec s).decimal_point.val - 1) := by
exact zpow_pos (by norm_num) _
have hheadReal : (1 : Real) <= (headS : Real) := by
exact_mod_cast hheadS
have hprod : 0 < (headS : Real) * (10 : Real) ^
((stateDec s).decimal_point.val - 1) :=
mul_pos (by linarith) hpowpos
have hlow' : (headS : Real) * (10 : Real) ^
((stateDec s).decimal_point.val - 1) <=
V (stateDec s) := by
rw [hshapeS, hlenS] at hlow
dsimp only [V]
rw [hshapeS]
simpa [V, List.map_take, List.foldl_cons] using hlow
exact lt_of_lt_of_le hprod hlow'
have htransport := P529_T1_RightBoundaryTransport
(stateDec s) dn shift hshift hdigitS hright hnonreset hcountN
hVpositive b hboundary
have hstrictNext' : V dn <
(c : Real) * (2 : Real) ^ (R - en.val) := by
have hpEq : dn.decimal_point = (stateDec s').decimal_point := by
have hh := congrArg (fun z : State => z.2.1) hnextTuple
simpa [stateDec] using hh
have hnEq : dn.num_digits = (stateDec s').num_digits := by
have hh := congrArg (fun z : State => z.1) hnextTuple
simpa [stateDec] using hh
have hdEq : dn.digits = (stateDec s').digits := by
have hh := congrArg (fun z : State => z.2.2.2.1) hnextTuple
simpa [stateDec] using hh
have hstrictNextInput := hstrictNext hstrictTerminal
simpa [V, stateDec, hpEq, hnEq, hdEq, henEq] using hstrictNextInput
have hstrictGrid : V dn < (b : Real) *
(10 : Real) ^ (dn.decimal_point.val - 768) := by
rw [← hbgrid]
exact hstrictNext'
exact (not_lt_of_ge htransport) hstrictGrid
)
exact ⟨hcapSource, hstrictSource⟩
)
have hhist := hhistory sStart sFinal hloop
rcases hhist with ⟨hfinalNone, hhistoryProp⟩
have hnegResult : d0.decimal_point.val < 0 -> exp0.val = 0 := by
intro hneg
have hsame := (hhistoryProp hfinalInv hstartInv).2.1 hneg
simpa [sStart, sFinal, stateExp] using hsame.symm
have hcapacityResult : ∀ (c : Nat) (R : Int),
0 <= R - exp0.val + 768 - d0.decimal_point.val ->
0 <= R + 768 - d.decimal_point.val ∧
(V d0 < (c : Real) * (2 : Real) ^ (R - exp0.val) ->
V d < (c : Real) * (2 : Real) ^ R) := by
intro c R hcap0
have hcap := (hhistoryProp hfinalInv hstartInv).2.2 c R (by
simpa [sFinal, stateDec, stateExp] using hcap0)
simpa [sStart, sFinal, stateDec, stateExp] using hcap
exact ⟨hnegResult, hcapacityResult⟩
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 133 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
- RightBoundaryTransport
- RightHistoryBoundary
- GridAlignment
- GridBoundaryRetained
- DecimalFoldBounds
- PowerGridAlignment
- ResultLoopBackward
- CoefficientGridAlignment
- 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": "P529_T1_RightHistoryBoundary",
"closure_version": "patch_c_v1",
"active_decl_hash": "1db27f176bffd8fe67e4ce2cdb351d999d2e0c6a3b269b6fe33798333e613560",
"active_statement_hash": "d6933e70ddfd44043a39018b3ec7c2ed57851cd8991efa87bdce47fa72efb865",
"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-188",
"boundary_theorems": {},
"strict_theorem_deps": {
"P472_T1_DecimalValueBounds": "4b5c924b5d52bc9d",
"P495_T1_RightLoopStep": "b873eecaa227a3e1",
"P495_T1_SlowLoop0Execution": "5a1e49d921a1825a",
"P529_T1_RightBoundaryTransport": "bb615631f8d7363c",
"P826_T1_ResultLoopBackward": "46222c89d1819e7b",
"P856_T1_CoefficientGridAlignment": "811bf9ec1aa2ffd7",
"SlowShiftSelectorCertificate": "963b7a2e670856e8",
"num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE": "01b84a7a35e5bcf4",
"num_imp_dec2flt_slow_parse_long_mantissa": "0eb6fb2627d0ff5c"
},
"strict_definition_deps": {
"F64": "ec4e25fbaf4e11d4",
"F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
"SlowShiftSelectorCertificate": "7ebc2b39d69850c4",
"num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
"num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
"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",
"num_imp_traits_Float": "94ab5f784cdf5db8"
}
}Prose assessment
{
"label": "Recorded Sound: VerifierPass",
"assessment_status": "VerifierPass",
"fingerprint_relation": "matches current fingerprint",
"assessment_fingerprint": "sound-v2:0efb1dad0a913512bc6c20f52075b24fecbbd4a32872959070652e2b282ea4f0",
"current_fingerprint": "sound-v2:0efb1dad0a913512bc6c20f52075b24fecbbd4a32872959070652e2b282ea4f0",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}