Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Nearest-even rounding from an arbitrary open endpoint
Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_round
import Tablet.DecimalGoalVocabularyDefault
import Tablet.DecimalSeqPrimitiveSemantics
import Tablet.NumberHelperDecimalPrefixInterval
import Tablet.DecimalSeqFractionalDigitInterval
import Tablet.DecimalSeqRoundLoopValue
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: DecimalSeqRoundArbitraryEndpoint]
theorem DecimalSeqRoundArbitraryEndpoint :
forall (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (X B : Real),
let digits :=
(d.digits.val.take d.num_digits.val).map (fun z => z.val)
let integer : Nat := digits.foldl (fun n digit => 10 * n + digit) 0
let value : Real := integer * (10 : Real) ^
(d.decimal_point.val - (d.num_digits.val : Int))
d.num_digits.val <= 768 /\
(forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) /\
((d.num_digits.val = 0 /\ digits = [] /\ d.truncated = false /\
X = 0) \/
(exists z zs, digits = z :: zs /\ 1 <= z /\ z < 10 /\
digits.length = d.num_digits.val /\
digits.getLast? != some 0)) /\
(exists eta u : Real,
X = value + eta /\ B = value + u /\
0 <= eta /\ eta < u /\
(d.truncated = true <-> 0 < eta)) ->
d.decimal_point.val < 19 ->
0 <= X -> X < (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) ->
(forall n : Nat,
(n : Real) + (1 / 2 : Real) <= value \/
B <= (n : Real) + (1 / 2 : Real)) ->
exists m : Std.U64,
num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok m /\
X <= (m.val : Real) + (1 / 2 : Real) /\
(m.val : Real) <= X + (1 / 2 : Real) /\
(X = (m.val : Real) + (1 / 2 : Real) \/
X = (m.val : Real) - (1 / 2 : Real) -> m.val % 2 = 0) := by
Proof
Natural-language proof
The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.
Explanatory prose status
Prose retained as authored. The explanatory prose is preserved as it stood when captured.
Earlier prose review
An earlier review questioned the prose argument. Lean subsequently checked the formal proof. Review of the statement’s intended meaning is a separate judgment.
Proof
round_up to false and returns N. We have
N=V\leq X. Applying (1) at n=N rules out N+1/2\leq V=N and gives
B\leq N+1/2; hence X<B\leq N+1/2. These inequalities prove the result,
and their strictness excludes a midpoint tie.Lean proof
dsimp
intro d X B hshape hp19 hX0 hXbound hsep
let digits := (d.digits.val.take d.num_digits.val).map (fun z => z.val)
let integer : Nat := digits.foldl (fun n digit => 10 * n + digit) 0
let value : Real := integer * (10 : Real) ^
(d.decimal_point.val - (d.num_digits.val : Int))
change d.num_digits.val <= 768 /\
(forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) /\
((d.num_digits.val = 0 /\ digits = [] /\ d.truncated = false /\ X = 0) \/
(exists z zs, digits = z :: zs /\ 1 <= z /\ z < 10 /\
digits.length = d.num_digits.val /\ digits.getLast? != some 0)) /\
(exists eta u : Real, X = value + eta /\ B = value + u /\
0 <= eta /\ eta < u /\ (d.truncated = true <-> 0 < eta)) at hshape
change forall n : Nat, (n : Real) + 1 / 2 <= value \/
B <= (n : Real) + 1 / 2 at hsep
rcases hshape with ⟨hnum, hdigit, hcanon,
eta, u, hX, hB, heta0, hetau, hsticky⟩
simp only [bne_iff_ne] at hcanon
have hXB : X < B := by rw [hX, hB]; linarith
have hdigits : forall z, z ∈ digits -> z < 10 := by
intro z hz
simp only [digits, List.mem_map] at hz
rcases hz with ⟨w, hw, rfl⟩
exact hdigit w hw
by_cases hzero : d.num_digits.val = 0
· have hword : d.num_digits = 0#usize :=
UScalar.eq_of_val_eq (by simpa using hzero)
have hXeq : X = 0 := by
rcases hcanon with hz | hp
· exact hz.2.2.2
· rcases hp with ⟨z, zs, hds, hz1, hz10, hlen, hlast⟩
rw [hzero] at hlen
simp [hds] at hlen
refine ⟨0#u64, ?_, ?_, ?_, ?_⟩
· unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword]
· norm_num [hXeq]
· norm_num [hXeq]
· norm_num [hXeq]
have hword : d.num_digits ≠ 0#usize := by
intro he
apply hzero
exact congrArg UScalar.val he
rcases hcanon with hz | hp
· exact (hzero hz.1).elim
rcases hp with ⟨z, zs, hdigitsCons, hz1, hz10, hdigitsLen, hlast⟩
by_cases hpneg : d.decimal_point.val < 0
· have hpword : d.decimal_point < 0#i32 := by
simpa [IScalar.lt_equiv] using hpneg
have hsuffix := NumberHelperDecimalPrefixInterval [] digits hdigits
(d.decimal_point.val - (digits.length : Int))
dsimp only at hsuffix
have hexp : d.decimal_point.val - (digits.length : Int) +
(digits.length : Int) = d.decimal_point.val := by omega
have hvaluePow : value < (10 : Real) ^ d.decimal_point.val := by
rw [hexp] at hsuffix
rw [hdigitsLen] at hsuffix
simpa [value, integer] using hsuffix.2
have hpLe : d.decimal_point.val <= (-1 : Int) := by omega
have hpowLe : (10 : Real) ^ d.decimal_point.val <= 1 / 10 := by
calc
(10 : Real) ^ d.decimal_point.val <= (10 : Real) ^ (-1 : Int) :=
zpow_le_zpow_right₀ (by norm_num) hpLe
_ = 1 / 10 := by norm_num [zpow_neg]
have hvalueHalf : value < 1 / 2 := by linarith
have hBhalf : B <= 1 / 2 := by
rcases hsep 0 with h | h
· norm_num at h
linarith
· simpa using h
have hXhalf : X < 1 / 2 := lt_of_lt_of_le hXB hBhalf
refine ⟨0#u64, ?_, ?_, ?_, ?_⟩
· unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpword]
· norm_num
exact hXhalf.le
· norm_num
linarith
· norm_num
have hp0 : 0 <= d.decimal_point.val := by omega
have hpnotword : ¬ d.decimal_point < 0#i32 := by
simpa [IScalar.lt_equiv] using (not_lt.mpr hp0)
have hcap : lift (UScalar.hcast .I32
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW) =
ok 19#i32 := by
have hmaxVal := DecimalSeqPrimitiveSemantics.2.2.1
have hbound :
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW.val <=
IScalar.max .I32 := by
rw [hmaxVal]
simp [I32.max_eq]
obtain ⟨i, hi, hival⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.hcast_inBounds_spec .I32
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW hbound)
have hieq : i = 19#i32 := by
apply IScalar.eq_of_val_eq
rw [hival, hmaxVal]
norm_num
subst i
exact hi
have hguard : ¬ d.decimal_point >= 19#i32 := by
simpa [IScalar.le_equiv] using (not_le.mpr hp19)
have hguardVal : ¬ (19 : Int) <= d.decimal_point.val := not_le.mpr hp19
have hdpBounds : 0 <= d.decimal_point.val /\
d.decimal_point.val <= UScalar.max .Usize := by
constructor
· exact hp0
· rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [UScalar.max, hbits] <;> omega
obtain ⟨dp, hdpCast0, hdpVal⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize d.decimal_point hdpBounds)
have hdpCast : lift (IScalar.hcast .Usize d.decimal_point) = ok dp := by
simpa [lift] using hdpCast0
have hpdp : d.decimal_point.val = (dp.val : Int) := hdpVal.symm
have hdp18 : dp.val <= 18 := by omega
obtain ⟨n, hloop, hnPrefix, hnAfter⟩ :=
DecimalSeqRoundLoopValue d dp hdp18 hnum hdigit
by_cases hfrac : dp.val < d.num_digits.val
· have hnval := hnPrefix hfrac
have hmath := DecimalSeqFractionalDigitInterval digits dp.val
(by simpa [hdigitsLen] using hfrac) hdigits
(by simpa [bne_iff_ne] using hlast)
dsimp only at hmath
have hN :
(digits.take dp.val).foldl (fun a z => 10 * a + z) 0 = n.val :=
hnval.symm
have hV : (integer : Real) *
(10 : Real) ^ ((dp.val : Int) - (digits.length : Int)) = value := by
simp only [value]
rw [hpdp, hdigitsLen]
rw [hN, hV] at hmath
have hvalueLower : (n.val : Real) <= value := hmath.1
have hvalueUpper : value < (n.val : Real) + 1 := hmath.2.1
have hXgeN : (n.val : Real) <= X := by rw [hX]; linarith
have hnextB : B <= (n.val : Real) + 3 / 2 := by
rcases hsep (n.val + 1) with h | h
· norm_num at h
push_cast at h
linarith
· push_cast at h
norm_num at h ⊢
linarith
have hXnext : X < (n.val : Real) + 3 / 2 := lt_of_lt_of_le hXB hnextB
have hdpWord : dp < d.num_digits := by
simpa [UScalar.lt_equiv] using hfrac
have hidx : dp.val < d.digits.val.length := by
have ha : d.digits.val.length = 768 := by simpa using d.digits.property
omega
obtain ⟨digit, hdigitRead, hdigitReadVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(Array.index_usize_spec d.digits dp
(by simpa [Array.length] using hidx))
have hdigitVal : digit.val = digits[dp.val] := by
have hraw : digit = d.digits.val[dp.val]'hidx := hdigitReadVal
have htake :
(d.digits.val.take d.num_digits.val)[dp.val]'(by
simp
omega) = d.digits.val[dp.val]'hidx := by
apply List.getElem_take
simp only [digits, List.getElem_map]
rw [htake, ← hraw]
have hdigitLt : digit.val < 10 := by
rw [hdigitVal]
exact hdigits _ (List.getElem_mem _)
have haddBound : dp.val + 1 <= UScalar.max .Usize := by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [UScalar.max, hbits] <;> omega
obtain ⟨dp1, hdpAdd, hdp1Val⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.add_spec (x := dp) (y := 1#usize) (by simpa using haddBound))
have finishDown (hmid : X < (n.val : Real) + 1 / 2)
(hround : num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok n) :
exists m : Std.U64,
num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok m /\
X <= (m.val : Real) + 1 / 2 /\
(m.val : Real) <= X + 1 / 2 /\
(X = (m.val : Real) + 1 / 2 \/
X = (m.val : Real) - 1 / 2 -> m.val % 2 = 0) := by
refine ⟨n, hround, hmid.le, by linarith, ?_⟩
intro htie
exfalso
rcases htie with h | h <;> linarith
have increment (hsafe : (n.val : Real) + 1 < (2 : Real) ^ (64 : Nat)) :
exists n1 : Std.U64, n + 1#u64 = ok n1 /\ n1.val = n.val + 1 := by
have hnat : n.val + 1 < 2 ^ 64 := by exact_mod_cast hsafe
have hbound : n.val + 1 <= U64.max := by
rw [U64.max_eq]
omega
obtain ⟨n1, hn1, hn1val⟩ := Aeneas.Std.WP.spec_imp_exists
(U64.add_spec (x := n) (y := 1#u64) (by simpa using hbound))
exact ⟨n1, hn1, by simpa using hn1val⟩
have finishUp (habove : (n.val : Real) + 1 / 2 < X)
(hcode : num.imp.dec2flt.decimal_seq.DecimalSeq.round d = n + 1#u64) :
exists m : Std.U64,
num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok m /\
X <= (m.val : Real) + 1 / 2 /\
(m.val : Real) <= X + 1 / 2 /\
(X = (m.val : Real) + 1 / 2 \/
X = (m.val : Real) - 1 / 2 -> m.val % 2 = 0) := by
have hsafe : (n.val : Real) + 1 < (2 : Real) ^ (64 : Nat) := by
linarith
obtain ⟨n1, hn1, hn1val⟩ := increment hsafe
rw [hn1] at hcode
refine ⟨n1, hcode, ?_, ?_, ?_⟩
· rw [hn1val]
push_cast
linarith
· rw [hn1val]
push_cast
linarith
· intro htie
exfalso
rw [hn1val] at htie
push_cast at htie
rcases htie with h | h <;> linarith
have finishTieDown (htie : X = (n.val : Real) + 1 / 2)
(heven : n.val % 2 = 0)
(hround : num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok n) :
exists m : Std.U64,
num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok m /\
X <= (m.val : Real) + 1 / 2 /\
(m.val : Real) <= X + 1 / 2 /\
(X = (m.val : Real) + 1 / 2 \/
X = (m.val : Real) - 1 / 2 -> m.val % 2 = 0) := by
refine ⟨n, hround, htie.le, by rw [htie]; linarith, ?_⟩
exact fun _ => heven
have finishTieUp (htie : X = (n.val : Real) + 1 / 2)
(hodd : n.val % 2 = 1)
(hcode : num.imp.dec2flt.decimal_seq.DecimalSeq.round d = n + 1#u64) :
exists m : Std.U64,
num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok m /\
X <= (m.val : Real) + 1 / 2 /\
(m.val : Real) <= X + 1 / 2 /\
(X = (m.val : Real) + 1 / 2 \/
X = (m.val : Real) - 1 / 2 -> m.val % 2 = 0) := by
have hsafe : (n.val : Real) + 1 < (2 : Real) ^ (64 : Nat) := by
linarith
obtain ⟨n1, hn1, hn1val⟩ := increment hsafe
rw [hn1] at hcode
refine ⟨n1, hcode, ?_, ?_, ?_⟩
· rw [hn1val, htie]
push_cast
linarith
· rw [hn1val, htie]
push_cast
linarith
· intro _
rw [hn1val]
omega
by_cases hbelow : digit.val < 5
· have hvalueMid : value < (n.val : Real) + 1 / 2 :=
hmath.2.2.1 (by simpa [hdigitVal] using hbelow)
have hBmid : B <= (n.val : Real) + 1 / 2 := by
rcases hsep n.val with h | h
· linarith
· exact h
have hXmid : X < (n.val : Real) + 1 / 2 := lt_of_lt_of_le hXB hBmid
apply finishDown hXmid
have hdigitNe : digit ≠ 5#u8 := by
intro he
have := congrArg UScalar.val he
norm_num at this
omega
have hnotge : ¬ digit >= 5#u8 := by
simpa [UScalar.le_equiv] using (not_le.mpr hbelow)
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitNe, hnotge]
omega
by_cases habove : 5 < digit.val
· have hvalueMid : (n.val : Real) + 1 / 2 < value :=
hmath.2.2.2.1 (by simpa [hdigitVal] using habove)
have hXmid : (n.val : Real) + 1 / 2 < X := by
rw [hX]
linarith
apply finishUp hXmid
have hdigitNe : digit ≠ 5#u8 := by
intro he
have := congrArg UScalar.val he
norm_num at this
omega
have hge : digit >= 5#u8 := by
simpa [UScalar.le_equiv] using (by omega : 5 <= digit.val)
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitNe, hge]
omega
· have hdigitVal5 : digit.val = 5 := by omega
have hdigitEq : digit = 5#u8 :=
UScalar.eq_of_val_eq (by simpa using hdigitVal5)
have hfirst5 : digits[dp.val] = 5 := by
rw [← hdigitVal]
exact hdigitVal5
have htieMath := hmath.2.2.2.2 hfirst5
have hdp1Nat : dp1.val = dp.val + 1 := by
simpa using hdp1Val
by_cases hterminal : dp1 = d.num_digits
· have hterminalNat : dp.val + 1 = digits.length := by
rw [hdigitsLen, ← hdp1Nat]
exact congrArg UScalar.val hterminal
have hvalueTie : value = (n.val : Real) + 1 / 2 :=
htieMath.1 hterminalNat
by_cases htrunc : d.truncated = true
· have hetaPos : 0 < eta := hsticky.mp htrunc
have hXmid : (n.val : Real) + 1 / 2 < X := by
rw [hX, hvalueTie]
linarith
apply finishUp hXmid
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitEq, hdpAdd, hterminal, htrunc]
· have hetaNotPos : ¬ 0 < eta := by
intro he
exact htrunc (hsticky.mpr he)
have hetaEq : eta = 0 := by linarith
have hXtie : X = (n.val : Real) + 1 / 2 := by
rw [hX, hvalueTie, hetaEq]
ring
by_cases hdpZero : dp.val = 0
· have hdpEq : dp = 0#usize :=
UScalar.eq_of_val_eq (by simpa using hdpZero)
subst dp
apply finishTieDown hXtie
· rw [hnval]
simp
· unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hzero, hdigitRead, hdigitEq, hdpAdd, hterminal, htrunc]
· have hdpPos : 0 < dp.val := by omega
obtain ⟨dpm1, hdpSub, hdpm1Val⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.sub_spec (x := dp) (y := 1#usize)
(by simpa using hdpPos))
norm_num at hdpm1Val
have hdpm1Eq : dpm1.val = dp.val - 1 := hdpm1Val.1
have hprevIdx : dpm1.val < d.digits.val.length := by
have ha : d.digits.val.length = 768 := by
simpa using d.digits.property
omega
obtain ⟨prev, hprevRead, hprevReadVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(Array.index_usize_spec d.digits dpm1
(by simpa [Array.length] using hprevIdx))
have hprevVal : prev.val = digits[dp.val - 1] := by
have hrawVal := congrArg UScalar.val hprevReadVal
rw [hrawVal]
simp [digits, List.getElem_map, List.getElem_take, hdpm1Eq]
let pref := (digits.take (dp.val - 1)).foldl
(fun a z => 10 * a + z) 0
have htakeLast : digits.take dp.val =
digits.take (dp.val - 1) ++ [digits[dp.val - 1]] := by
conv_lhs => rw [show dp.val = (dp.val - 1) + 1 by omega]
exact List.take_succ_eq_append_getElem
(by omega : dp.val - 1 < digits.length)
have hnLast : n.val = 10 * pref + digits[dp.val - 1] := by
rw [hnval]
rw [htakeLast, List.foldl_append]
simp [pref]
let bit : Std.U8 := 1#u8 &&& prev
have hbitLift : lift (1#u8 &&& prev) = ok bit := by
rfl
have hbitVal : bit.val = prev.val % 2 := by
change (BitVec.ofNat 8 1 &&& prev.bv).toNat =
prev.bv.toNat % 2
rw [BitVec.toNat_and]
norm_num [Nat.one_and_eq_mod_two]
have hnParity : n.val % 2 = prev.val % 2 := by
rw [hnLast, hprevVal]
omega
have hdpNe : dp != 0#usize := by
simp only [bne_iff_ne]
intro he
apply hdpZero
exact congrArg UScalar.val he
by_cases heven : n.val % 2 = 0
· have hbitZeroVal : bit.val = 0 := by
rw [hbitVal, ← hnParity, heven]
have hbitZero : bit = 0#u8 :=
UScalar.eq_of_val_eq (by simpa using hbitZeroVal)
apply finishTieDown hXtie heven
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitEq, hdpAdd, hterminal, htrunc,
hdpNe, hdpZero, hdpSub, hprevRead, hbitLift, hbitZero]
· have hodd : n.val % 2 = 1 := by
have := Nat.mod_lt n.val (by omega : 0 < 2)
omega
have hbitOneVal : bit.val = 1 := by
rw [hbitVal, ← hnParity, hodd]
have hbitNe : bit != 0#u8 := by
simp only [bne_iff_ne]
intro he
have := congrArg UScalar.val he
norm_num [hbitOneVal] at this
apply finishTieUp hXtie hodd
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitEq, hdpAdd, hterminal, htrunc,
hdpNe, hdpZero, hdpSub, hprevRead, hbitLift, hbitNe]
· have hnotTerminalNat : dp.val + 1 ≠ digits.length := by
intro he
apply hterminal
apply UScalar.eq_of_val_eq
rw [hdp1Nat]
simpa [hdigitsLen] using he
have hnonterminalNat : dp.val + 1 < digits.length := by omega
have hvalueMid : (n.val : Real) + 1 / 2 < value :=
htieMath.2 hnonterminalNat
have hXmid : (n.val : Real) + 1 / 2 < X := by
rw [hX]
linarith
apply finishUp hXmid
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitEq, hdpAdd, hterminal]
· have hle : d.num_digits.val <= dp.val := by omega
have hnval := hnAfter hle
have hvalueN : value = (n.val : Real) := by
dsimp only [value, integer]
rw [hnval, hpdp, ← Nat.cast_sub hle, zpow_natCast]
push_cast
ring
have hXge : (n.val : Real) <= X := by
rw [hX, hvalueN]
linarith
have hBmid : B <= (n.val : Real) + 1 / 2 := by
rcases hsep n.val with h | h
· rw [hvalueN] at h
linarith
· exact h
have hXmid : X < (n.val : Real) + 1 / 2 := lt_of_lt_of_le hXB hBmid
have hdpWord : ¬ dp < d.num_digits := by
simpa [UScalar.lt_equiv] using hfrac
refine ⟨n, ?_, hXmid.le, by linarith, ?_⟩
· unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop, hfrac]
· intro htie
exfalso
rcases htie with h | h <;> linarith
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_round
import Tablet.DecimalGoalVocabularyDefault
import Tablet.DecimalSeqPrimitiveSemantics
import Tablet.NumberHelperDecimalPrefixInterval
import Tablet.DecimalSeqFractionalDigitInterval
import Tablet.DecimalSeqRoundLoopValue
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: DecimalSeqRoundArbitraryEndpoint]
theorem DecimalSeqRoundArbitraryEndpoint :
forall (d : num.imp.dec2flt.decimal_seq.DecimalSeq) (X B : Real),
let digits :=
(d.digits.val.take d.num_digits.val).map (fun z => z.val)
let integer : Nat := digits.foldl (fun n digit => 10 * n + digit) 0
let value : Real := integer * (10 : Real) ^
(d.decimal_point.val - (d.num_digits.val : Int))
d.num_digits.val <= 768 /\
(forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) /\
((d.num_digits.val = 0 /\ digits = [] /\ d.truncated = false /\
X = 0) \/
(exists z zs, digits = z :: zs /\ 1 <= z /\ z < 10 /\
digits.length = d.num_digits.val /\
digits.getLast? != some 0)) /\
(exists eta u : Real,
X = value + eta /\ B = value + u /\
0 <= eta /\ eta < u /\
(d.truncated = true <-> 0 < eta)) ->
d.decimal_point.val < 19 ->
0 <= X -> X < (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) ->
(forall n : Nat,
(n : Real) + (1 / 2 : Real) <= value \/
B <= (n : Real) + (1 / 2 : Real)) ->
exists m : Std.U64,
num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok m /\
X <= (m.val : Real) + (1 / 2 : Real) /\
(m.val : Real) <= X + (1 / 2 : Real) /\
(X = (m.val : Real) + (1 / 2 : Real) \/
X = (m.val : Real) - (1 / 2 : Real) -> m.val % 2 = 0) := by
-- BODY
dsimp
intro d X B hshape hp19 hX0 hXbound hsep
let digits := (d.digits.val.take d.num_digits.val).map (fun z => z.val)
let integer : Nat := digits.foldl (fun n digit => 10 * n + digit) 0
let value : Real := integer * (10 : Real) ^
(d.decimal_point.val - (d.num_digits.val : Int))
change d.num_digits.val <= 768 /\
(forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) /\
((d.num_digits.val = 0 /\ digits = [] /\ d.truncated = false /\ X = 0) \/
(exists z zs, digits = z :: zs /\ 1 <= z /\ z < 10 /\
digits.length = d.num_digits.val /\ digits.getLast? != some 0)) /\
(exists eta u : Real, X = value + eta /\ B = value + u /\
0 <= eta /\ eta < u /\ (d.truncated = true <-> 0 < eta)) at hshape
change forall n : Nat, (n : Real) + 1 / 2 <= value \/
B <= (n : Real) + 1 / 2 at hsep
rcases hshape with ⟨hnum, hdigit, hcanon,
eta, u, hX, hB, heta0, hetau, hsticky⟩
simp only [bne_iff_ne] at hcanon
have hXB : X < B := by rw [hX, hB]; linarith
have hdigits : forall z, z ∈ digits -> z < 10 := by
intro z hz
simp only [digits, List.mem_map] at hz
rcases hz with ⟨w, hw, rfl⟩
exact hdigit w hw
by_cases hzero : d.num_digits.val = 0
· have hword : d.num_digits = 0#usize :=
UScalar.eq_of_val_eq (by simpa using hzero)
have hXeq : X = 0 := by
rcases hcanon with hz | hp
· exact hz.2.2.2
· rcases hp with ⟨z, zs, hds, hz1, hz10, hlen, hlast⟩
rw [hzero] at hlen
simp [hds] at hlen
refine ⟨0#u64, ?_, ?_, ?_, ?_⟩
· unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword]
· norm_num [hXeq]
· norm_num [hXeq]
· norm_num [hXeq]
have hword : d.num_digits ≠ 0#usize := by
intro he
apply hzero
exact congrArg UScalar.val he
rcases hcanon with hz | hp
· exact (hzero hz.1).elim
rcases hp with ⟨z, zs, hdigitsCons, hz1, hz10, hdigitsLen, hlast⟩
by_cases hpneg : d.decimal_point.val < 0
· have hpword : d.decimal_point < 0#i32 := by
simpa [IScalar.lt_equiv] using hpneg
have hsuffix := NumberHelperDecimalPrefixInterval [] digits hdigits
(d.decimal_point.val - (digits.length : Int))
dsimp only at hsuffix
have hexp : d.decimal_point.val - (digits.length : Int) +
(digits.length : Int) = d.decimal_point.val := by omega
have hvaluePow : value < (10 : Real) ^ d.decimal_point.val := by
rw [hexp] at hsuffix
rw [hdigitsLen] at hsuffix
simpa [value, integer] using hsuffix.2
have hpLe : d.decimal_point.val <= (-1 : Int) := by omega
have hpowLe : (10 : Real) ^ d.decimal_point.val <= 1 / 10 := by
calc
(10 : Real) ^ d.decimal_point.val <= (10 : Real) ^ (-1 : Int) :=
zpow_le_zpow_right₀ (by norm_num) hpLe
_ = 1 / 10 := by norm_num [zpow_neg]
have hvalueHalf : value < 1 / 2 := by linarith
have hBhalf : B <= 1 / 2 := by
rcases hsep 0 with h | h
· norm_num at h
linarith
· simpa using h
have hXhalf : X < 1 / 2 := lt_of_lt_of_le hXB hBhalf
refine ⟨0#u64, ?_, ?_, ?_, ?_⟩
· unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpword]
· norm_num
exact hXhalf.le
· norm_num
linarith
· norm_num
have hp0 : 0 <= d.decimal_point.val := by omega
have hpnotword : ¬ d.decimal_point < 0#i32 := by
simpa [IScalar.lt_equiv] using (not_lt.mpr hp0)
have hcap : lift (UScalar.hcast .I32
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW) =
ok 19#i32 := by
have hmaxVal := DecimalSeqPrimitiveSemantics.2.2.1
have hbound :
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW.val <=
IScalar.max .I32 := by
rw [hmaxVal]
simp [I32.max_eq]
obtain ⟨i, hi, hival⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.hcast_inBounds_spec .I32
num.imp.dec2flt.decimal_seq.DecimalSeq.MAX_DIGITS_WITHOUT_OVERFLOW hbound)
have hieq : i = 19#i32 := by
apply IScalar.eq_of_val_eq
rw [hival, hmaxVal]
norm_num
subst i
exact hi
have hguard : ¬ d.decimal_point >= 19#i32 := by
simpa [IScalar.le_equiv] using (not_le.mpr hp19)
have hguardVal : ¬ (19 : Int) <= d.decimal_point.val := not_le.mpr hp19
have hdpBounds : 0 <= d.decimal_point.val /\
d.decimal_point.val <= UScalar.max .Usize := by
constructor
· exact hp0
· rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [UScalar.max, hbits] <;> omega
obtain ⟨dp, hdpCast0, hdpVal⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize d.decimal_point hdpBounds)
have hdpCast : lift (IScalar.hcast .Usize d.decimal_point) = ok dp := by
simpa [lift] using hdpCast0
have hpdp : d.decimal_point.val = (dp.val : Int) := hdpVal.symm
have hdp18 : dp.val <= 18 := by omega
obtain ⟨n, hloop, hnPrefix, hnAfter⟩ :=
DecimalSeqRoundLoopValue d dp hdp18 hnum hdigit
by_cases hfrac : dp.val < d.num_digits.val
· have hnval := hnPrefix hfrac
have hmath := DecimalSeqFractionalDigitInterval digits dp.val
(by simpa [hdigitsLen] using hfrac) hdigits
(by simpa [bne_iff_ne] using hlast)
dsimp only at hmath
have hN :
(digits.take dp.val).foldl (fun a z => 10 * a + z) 0 = n.val :=
hnval.symm
have hV : (integer : Real) *
(10 : Real) ^ ((dp.val : Int) - (digits.length : Int)) = value := by
simp only [value]
rw [hpdp, hdigitsLen]
rw [hN, hV] at hmath
have hvalueLower : (n.val : Real) <= value := hmath.1
have hvalueUpper : value < (n.val : Real) + 1 := hmath.2.1
have hXgeN : (n.val : Real) <= X := by rw [hX]; linarith
have hnextB : B <= (n.val : Real) + 3 / 2 := by
rcases hsep (n.val + 1) with h | h
· norm_num at h
push_cast at h
linarith
· push_cast at h
norm_num at h ⊢
linarith
have hXnext : X < (n.val : Real) + 3 / 2 := lt_of_lt_of_le hXB hnextB
have hdpWord : dp < d.num_digits := by
simpa [UScalar.lt_equiv] using hfrac
have hidx : dp.val < d.digits.val.length := by
have ha : d.digits.val.length = 768 := by simpa using d.digits.property
omega
obtain ⟨digit, hdigitRead, hdigitReadVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(Array.index_usize_spec d.digits dp
(by simpa [Array.length] using hidx))
have hdigitVal : digit.val = digits[dp.val] := by
have hraw : digit = d.digits.val[dp.val]'hidx := hdigitReadVal
have htake :
(d.digits.val.take d.num_digits.val)[dp.val]'(by
simp
omega) = d.digits.val[dp.val]'hidx := by
apply List.getElem_take
simp only [digits, List.getElem_map]
rw [htake, ← hraw]
have hdigitLt : digit.val < 10 := by
rw [hdigitVal]
exact hdigits _ (List.getElem_mem _)
have haddBound : dp.val + 1 <= UScalar.max .Usize := by
rcases System.Platform.numBits_eq with hbits | hbits <;>
simp [UScalar.max, hbits] <;> omega
obtain ⟨dp1, hdpAdd, hdp1Val⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.add_spec (x := dp) (y := 1#usize) (by simpa using haddBound))
have finishDown (hmid : X < (n.val : Real) + 1 / 2)
(hround : num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok n) :
exists m : Std.U64,
num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok m /\
X <= (m.val : Real) + 1 / 2 /\
(m.val : Real) <= X + 1 / 2 /\
(X = (m.val : Real) + 1 / 2 \/
X = (m.val : Real) - 1 / 2 -> m.val % 2 = 0) := by
refine ⟨n, hround, hmid.le, by linarith, ?_⟩
intro htie
exfalso
rcases htie with h | h <;> linarith
have increment (hsafe : (n.val : Real) + 1 < (2 : Real) ^ (64 : Nat)) :
exists n1 : Std.U64, n + 1#u64 = ok n1 /\ n1.val = n.val + 1 := by
have hnat : n.val + 1 < 2 ^ 64 := by exact_mod_cast hsafe
have hbound : n.val + 1 <= U64.max := by
rw [U64.max_eq]
omega
obtain ⟨n1, hn1, hn1val⟩ := Aeneas.Std.WP.spec_imp_exists
(U64.add_spec (x := n) (y := 1#u64) (by simpa using hbound))
exact ⟨n1, hn1, by simpa using hn1val⟩
have finishUp (habove : (n.val : Real) + 1 / 2 < X)
(hcode : num.imp.dec2flt.decimal_seq.DecimalSeq.round d = n + 1#u64) :
exists m : Std.U64,
num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok m /\
X <= (m.val : Real) + 1 / 2 /\
(m.val : Real) <= X + 1 / 2 /\
(X = (m.val : Real) + 1 / 2 \/
X = (m.val : Real) - 1 / 2 -> m.val % 2 = 0) := by
have hsafe : (n.val : Real) + 1 < (2 : Real) ^ (64 : Nat) := by
linarith
obtain ⟨n1, hn1, hn1val⟩ := increment hsafe
rw [hn1] at hcode
refine ⟨n1, hcode, ?_, ?_, ?_⟩
· rw [hn1val]
push_cast
linarith
· rw [hn1val]
push_cast
linarith
· intro htie
exfalso
rw [hn1val] at htie
push_cast at htie
rcases htie with h | h <;> linarith
have finishTieDown (htie : X = (n.val : Real) + 1 / 2)
(heven : n.val % 2 = 0)
(hround : num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok n) :
exists m : Std.U64,
num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok m /\
X <= (m.val : Real) + 1 / 2 /\
(m.val : Real) <= X + 1 / 2 /\
(X = (m.val : Real) + 1 / 2 \/
X = (m.val : Real) - 1 / 2 -> m.val % 2 = 0) := by
refine ⟨n, hround, htie.le, by rw [htie]; linarith, ?_⟩
exact fun _ => heven
have finishTieUp (htie : X = (n.val : Real) + 1 / 2)
(hodd : n.val % 2 = 1)
(hcode : num.imp.dec2flt.decimal_seq.DecimalSeq.round d = n + 1#u64) :
exists m : Std.U64,
num.imp.dec2flt.decimal_seq.DecimalSeq.round d = ok m /\
X <= (m.val : Real) + 1 / 2 /\
(m.val : Real) <= X + 1 / 2 /\
(X = (m.val : Real) + 1 / 2 \/
X = (m.val : Real) - 1 / 2 -> m.val % 2 = 0) := by
have hsafe : (n.val : Real) + 1 < (2 : Real) ^ (64 : Nat) := by
linarith
obtain ⟨n1, hn1, hn1val⟩ := increment hsafe
rw [hn1] at hcode
refine ⟨n1, hcode, ?_, ?_, ?_⟩
· rw [hn1val, htie]
push_cast
linarith
· rw [hn1val, htie]
push_cast
linarith
· intro _
rw [hn1val]
omega
by_cases hbelow : digit.val < 5
· have hvalueMid : value < (n.val : Real) + 1 / 2 :=
hmath.2.2.1 (by simpa [hdigitVal] using hbelow)
have hBmid : B <= (n.val : Real) + 1 / 2 := by
rcases hsep n.val with h | h
· linarith
· exact h
have hXmid : X < (n.val : Real) + 1 / 2 := lt_of_lt_of_le hXB hBmid
apply finishDown hXmid
have hdigitNe : digit ≠ 5#u8 := by
intro he
have := congrArg UScalar.val he
norm_num at this
omega
have hnotge : ¬ digit >= 5#u8 := by
simpa [UScalar.le_equiv] using (not_le.mpr hbelow)
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitNe, hnotge]
omega
by_cases habove : 5 < digit.val
· have hvalueMid : (n.val : Real) + 1 / 2 < value :=
hmath.2.2.2.1 (by simpa [hdigitVal] using habove)
have hXmid : (n.val : Real) + 1 / 2 < X := by
rw [hX]
linarith
apply finishUp hXmid
have hdigitNe : digit ≠ 5#u8 := by
intro he
have := congrArg UScalar.val he
norm_num at this
omega
have hge : digit >= 5#u8 := by
simpa [UScalar.le_equiv] using (by omega : 5 <= digit.val)
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitNe, hge]
omega
· have hdigitVal5 : digit.val = 5 := by omega
have hdigitEq : digit = 5#u8 :=
UScalar.eq_of_val_eq (by simpa using hdigitVal5)
have hfirst5 : digits[dp.val] = 5 := by
rw [← hdigitVal]
exact hdigitVal5
have htieMath := hmath.2.2.2.2 hfirst5
have hdp1Nat : dp1.val = dp.val + 1 := by
simpa using hdp1Val
by_cases hterminal : dp1 = d.num_digits
· have hterminalNat : dp.val + 1 = digits.length := by
rw [hdigitsLen, ← hdp1Nat]
exact congrArg UScalar.val hterminal
have hvalueTie : value = (n.val : Real) + 1 / 2 :=
htieMath.1 hterminalNat
by_cases htrunc : d.truncated = true
· have hetaPos : 0 < eta := hsticky.mp htrunc
have hXmid : (n.val : Real) + 1 / 2 < X := by
rw [hX, hvalueTie]
linarith
apply finishUp hXmid
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitEq, hdpAdd, hterminal, htrunc]
· have hetaNotPos : ¬ 0 < eta := by
intro he
exact htrunc (hsticky.mpr he)
have hetaEq : eta = 0 := by linarith
have hXtie : X = (n.val : Real) + 1 / 2 := by
rw [hX, hvalueTie, hetaEq]
ring
by_cases hdpZero : dp.val = 0
· have hdpEq : dp = 0#usize :=
UScalar.eq_of_val_eq (by simpa using hdpZero)
subst dp
apply finishTieDown hXtie
· rw [hnval]
simp
· unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hzero, hdigitRead, hdigitEq, hdpAdd, hterminal, htrunc]
· have hdpPos : 0 < dp.val := by omega
obtain ⟨dpm1, hdpSub, hdpm1Val⟩ := Aeneas.Std.WP.spec_imp_exists
(UScalar.sub_spec (x := dp) (y := 1#usize)
(by simpa using hdpPos))
norm_num at hdpm1Val
have hdpm1Eq : dpm1.val = dp.val - 1 := hdpm1Val.1
have hprevIdx : dpm1.val < d.digits.val.length := by
have ha : d.digits.val.length = 768 := by
simpa using d.digits.property
omega
obtain ⟨prev, hprevRead, hprevReadVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(Array.index_usize_spec d.digits dpm1
(by simpa [Array.length] using hprevIdx))
have hprevVal : prev.val = digits[dp.val - 1] := by
have hrawVal := congrArg UScalar.val hprevReadVal
rw [hrawVal]
simp [digits, List.getElem_map, List.getElem_take, hdpm1Eq]
let pref := (digits.take (dp.val - 1)).foldl
(fun a z => 10 * a + z) 0
have htakeLast : digits.take dp.val =
digits.take (dp.val - 1) ++ [digits[dp.val - 1]] := by
conv_lhs => rw [show dp.val = (dp.val - 1) + 1 by omega]
exact List.take_succ_eq_append_getElem
(by omega : dp.val - 1 < digits.length)
have hnLast : n.val = 10 * pref + digits[dp.val - 1] := by
rw [hnval]
rw [htakeLast, List.foldl_append]
simp [pref]
let bit : Std.U8 := 1#u8 &&& prev
have hbitLift : lift (1#u8 &&& prev) = ok bit := by
rfl
have hbitVal : bit.val = prev.val % 2 := by
change (BitVec.ofNat 8 1 &&& prev.bv).toNat =
prev.bv.toNat % 2
rw [BitVec.toNat_and]
norm_num [Nat.one_and_eq_mod_two]
have hnParity : n.val % 2 = prev.val % 2 := by
rw [hnLast, hprevVal]
omega
have hdpNe : dp != 0#usize := by
simp only [bne_iff_ne]
intro he
apply hdpZero
exact congrArg UScalar.val he
by_cases heven : n.val % 2 = 0
· have hbitZeroVal : bit.val = 0 := by
rw [hbitVal, ← hnParity, heven]
have hbitZero : bit = 0#u8 :=
UScalar.eq_of_val_eq (by simpa using hbitZeroVal)
apply finishTieDown hXtie heven
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitEq, hdpAdd, hterminal, htrunc,
hdpNe, hdpZero, hdpSub, hprevRead, hbitLift, hbitZero]
· have hodd : n.val % 2 = 1 := by
have := Nat.mod_lt n.val (by omega : 0 < 2)
omega
have hbitOneVal : bit.val = 1 := by
rw [hbitVal, ← hnParity, hodd]
have hbitNe : bit != 0#u8 := by
simp only [bne_iff_ne]
intro he
have := congrArg UScalar.val he
norm_num [hbitOneVal] at this
apply finishTieUp hXtie hodd
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitEq, hdpAdd, hterminal, htrunc,
hdpNe, hdpZero, hdpSub, hprevRead, hbitLift, hbitNe]
· have hnotTerminalNat : dp.val + 1 ≠ digits.length := by
intro he
apply hterminal
apply UScalar.eq_of_val_eq
rw [hdp1Nat]
simpa [hdigitsLen] using he
have hnonterminalNat : dp.val + 1 < digits.length := by omega
have hvalueMid : (n.val : Real) + 1 / 2 < value :=
htieMath.2 hnonterminalNat
have hXmid : (n.val : Real) + 1 / 2 < X := by
rw [hX]
linarith
apply finishUp hXmid
unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop,
hfrac, hdigitRead, hdigitEq, hdpAdd, hterminal]
· have hle : d.num_digits.val <= dp.val := by omega
have hnval := hnAfter hle
have hvalueN : value = (n.val : Real) := by
dsimp only [value, integer]
rw [hnval, hpdp, ← Nat.cast_sub hle, zpow_natCast]
push_cast
ring
have hXge : (n.val : Real) <= X := by
rw [hX, hvalueN]
linarith
have hBmid : B <= (n.val : Real) + 1 / 2 := by
rcases hsep n.val with h | h
· rw [hvalueN] at h
linarith
· exact h
have hXmid : X < (n.val : Real) + 1 / 2 := lt_of_lt_of_le hXB hBmid
have hdpWord : ¬ dp < d.num_digits := by
simpa [UScalar.lt_equiv] using hfrac
refine ⟨n, ?_, hXmid.le, by linarith, ?_⟩
· unfold num.imp.dec2flt.decimal_seq.DecimalSeq.round
simp [hword, hpnotword, hcap, hguardVal, hdpCast, hloop, hfrac]
· intro htie
exfalso
rcases htie with h | h <;> linarith
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
Inspect related source (116)
- round · dec2flt/decimal_seq.rs:96 Program Rust
- round_loop · dec2flt/decimal_seq.rs:106 Program Rust
- body · dec2flt/decimal_seq.rs:106 Program Rust
More program dependencies (83)
- DecimalSeq · dec2flt/decimal_seq.rs:21 Program Rust
- default · dec2flt/decimal_seq.rs:33 Program Rust
- MAX_DIGITS · dec2flt/decimal_seq.rs:63 Program Rust
- MAX_DIGITS_WITHOUT_OVERFLOW · dec2flt/decimal_seq.rs:66 Program Rust
- try_add_digit · dec2flt/decimal_seq.rs:73 Program Rust
- from_u64 · dec2flt/mod.rs:263 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
- BiasedFp · dec2flt/common.rs:52 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- Decimal · dec2flt/decimal.rs:32 Program Rust
- CastInto · traits.rs:18 Program Rust
- Float · traits.rs:74 Program Rust
- FloatExt · traits.rs:170 Program Rust
- Int · traits.rs:27 Program Rust
- parse_long_mantissa · dec2flt/slow.rs:27 Program Rust
- parse_long_mantissa_loop0 · dec2flt/slow.rs:51 Program Rust
- body · dec2flt/slow.rs:51 Program Rust
- parse_long_mantissa_loop1 · dec2flt/slow.rs:69 Program Rust
- body · dec2flt/slow.rs:69 Program Rust
- parse_long_mantissa_loop2 · dec2flt/slow.rs:94 Program Rust
- body · dec2flt/slow.rs:94 Program Rust
- zero_pow2 · dec2flt/common.rs:62 Program Rust
- DECIMAL_POINT_RANGE · dec2flt/decimal_seq.rs:67 Program Rust
- left_shift · dec2flt/decimal_seq.rs:129 Program Rust
- left_shift_loop0 · dec2flt/decimal_seq.rs:138 Program Rust
- body · dec2flt/decimal_seq.rs:138 Program Rust
- left_shift_loop1 · dec2flt/decimal_seq.rs:152 Program Rust
- body · dec2flt/decimal_seq.rs:152 Program Rust
- right_shift · dec2flt/decimal_seq.rs:175 Program Rust
- right_shift_loop0 · dec2flt/decimal_seq.rs:180 Program Rust
- body · dec2flt/decimal_seq.rs:180 Program Rust
- right_shift_loop0_loop0 · dec2flt/decimal_seq.rs:190 Program Rust
- body · dec2flt/decimal_seq.rs:190 Program Rust
- right_shift_loop1 · dec2flt/decimal_seq.rs:209 Program Rust
- body · dec2flt/decimal_seq.rs:209 Program Rust
- right_shift_loop2 · dec2flt/decimal_seq.rs:216 Program Rust
- body · dec2flt/decimal_seq.rs:216 Program Rust
- parse_decimal_seq · dec2flt/decimal_seq.rs:283 Program Rust
- parse_decimal_seq_loop0 · dec2flt/decimal_seq.rs:290 Program Rust
- body · dec2flt/decimal_seq.rs:290 Program Rust
- parse_decimal_seq_loop1 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop2 · dec2flt/decimal_seq.rs:303 Program Rust
- body · dec2flt/decimal_seq.rs:303 Program Rust
- parse_decimal_seq_loop3 · dec2flt/decimal_seq.rs:307 Program Rust
- body · dec2flt/decimal_seq.rs:307 Program Rust
- parse_decimal_seq_loop4 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop5 · dec2flt/decimal_seq.rs:307 Program Rust
- body · dec2flt/decimal_seq.rs:307 Program Rust
- parse_decimal_seq_loop6 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- parse_decimal_seq_loop7 · dec2flt/decimal_seq.rs:361 Program Rust
- body · dec2flt/decimal_seq.rs:361 Program Rust
- MAX_SHIFT · dec2flt/slow.rs:28 Program Rust
- call · dec2flt/slow.rs:33 Program Rust
- read_u64 · dec2flt/common.rs:18 Program Rust
- write_u64 · dec2flt/common.rs:25 Program Rust
- is_8digits · dec2flt/common.rs:40 Program Rust
- trim · dec2flt/decimal_seq.rs:82 Program Rust
- trim_loop · dec2flt/decimal_seq.rs:91 Program Rust
- body · dec2flt/decimal_seq.rs:91 Program Rust
- count_trailing_zeros · dec2flt/decimal_seq.rs:235 Program Rust
- count_trailing_zeros_loop · dec2flt/decimal_seq.rs:239 Program Rust
- body · dec2flt/decimal_seq.rs:239 Program Rust
- number_of_digits_decimal_left_shift · dec2flt/decimal_seq.rs:368 Program Rust
- number_of_digits_decimal_left_shift_loop · dec2flt/decimal_seq.rs:434 Program Rust
- body · dec2flt/decimal_seq.rs:434 Program Rust
- parse_decimal_exponent · dec2flt/decimal_seq.rs:269 Program Rust
- parse_decimal_exponent_loop · dec2flt/decimal_seq.rs:272 Program Rust
- body · dec2flt/decimal_seq.rs:272 Program Rust
- parse_digits_into_seq · dec2flt/decimal_seq.rs:256 Program Rust
- parse_digits_into_seq_loop · dec2flt/decimal_seq.rs:258 Program Rust
- body · dec2flt/decimal_seq.rs:258 Program Rust
- NUM_POWERS · dec2flt/slow.rs:29 Program Rust
- POWERS · dec2flt/slow.rs:30 Program Rust
- closure · dec2flt/slow.rs:33 Program Rust
- TABLE · dec2flt/decimal_seq.rs:370 Program Rust
- TABLE_POW5 · dec2flt/decimal_seq.rs:379 Program Rust
Standard-library dependencies (30)
- 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
- 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.configured_x86_64_numBits
- Quot.sound
- propext
This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.
Helper theorems included
- DecimalSeqFractionalDigitInterval
- DecimalSeqPrimitiveSemantics
- DecimalSeqRoundArbitraryEndpoint
- DecimalSeqRoundLoopPrefixCore
- DecimalSeqRoundLoopValue
- NumberHelperDecimalPrefixInterval
All 12 entries
- DecimalSeqFractionalDigitInterval
- DecimalSeqPrimitiveSemantics
- DecimalSeqRoundArbitraryEndpoint
- DecimalSeqRoundLoopPrefixCore
- DecimalSeqRoundLoopValue
- NumberHelperDecimalPrefixInterval
- num imp dec2flt decimal seq DecimalSeq
- 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 round
- num imp dec2flt decimal seq DecimalSeq try add digit
Technical checking records
Local closure summary
{
"node": "DecimalSeqRoundArbitraryEndpoint",
"closure_version": "patch_c_v1",
"active_decl_hash": "8e29f93f9af73405e9a2862808ee5e73749c58c8cbde5db22ebddcdb4822a9c0",
"active_statement_hash": "694f7ab43baaae6ead6bb46ab84174b48d8ae6294cad509327f4a34edb241d79",
"kernel_axioms": [
"Classical.choice",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-182",
"boundary_theorems": {},
"strict_theorem_deps": {
"DecimalSeqFractionalDigitInterval": "24315b479bbec2fd",
"DecimalSeqPrimitiveSemantics": "d1871c68600bfbcd",
"DecimalSeqRoundLoopValue": "89c751600a31491b",
"NumberHelperDecimalPrefixInterval": "5c32858414034b55",
"num_imp_dec2flt_decimal_seq_DecimalSeq_round": "cb99c951cfc3a86f"
},
"strict_definition_deps": {
"num_imp_dec2flt_decimal_seq_DecimalSeq": "59bf1ff9fe88fa8d",
"num_imp_dec2flt_decimal_seq_DecimalSeq_Insts_CoreDefaultDefault_default": "7b9921904495bc2a",
"num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS": "39f6cb231ef80388",
"num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS_WITHOUT_OVERFLOW": "65634ac95536dcca",
"num_imp_dec2flt_decimal_seq_DecimalSeq_round": "74fa9a4c095ca758",
"num_imp_dec2flt_decimal_seq_DecimalSeq_try_add_digit": "69a4869a11307175"
}
}Prose assessment
{
"label": "Sound flag superseded by recorded Lean closure",
"assessment_status": "ReviewerPinnedFail",
"fingerprint_relation": "differs from current fingerprint",
"assessment_fingerprint": "sound-v2:7841d27da62fb03c99ad2ed5586438dd704c59e91ce0b3685ea73da290796758",
"current_fingerprint": "sound-v2:070e509914c7827e64b7e00d6ef2869296b4eef7f4df012d635674bf7f4fbc33",
"superseded_for_theorem_closure": true
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Fail",
"substantiveness_status": "Pass"
}