Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Theorem
parse_number has
d.\mathit{negative}=\texttt{false} and
d.\mathit{mantissa}<10^{19}. Source validity is
SourceValidByteSlice, without a UTF-8 condition. The actual
call is ActualDispatchOperations. There is no numeric-grammar,
A, B, reachability, or record-well-formedness premise; only normal
Some return is required.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.Assumptions
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.ModelSliceSplitFirst
import Tablet.NumberHelperDigitScanExact
import Tablet.NumberHelperDigitScanSourceLength
import Tablet.NumberHelperTryParse19SafeLength
import Tablet.U64_Insts_CoreOpsBitBitAndU64U64
import Tablet.U64_Insts_CoreOpsBitBitOrU64U64
import Tablet.num_imp_dec2flt_decimal_Decimal
import Tablet.num_imp_dec2flt_parse_parse_many_digits
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.num_imp_dec2flt_parse_parse_scientific
import Tablet.SourceValidByteSlice
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.P364_T1_NumberHelperOffsetSourceLength
import Tablet.P364_T1_NumberHelperAdjustCountExact
import Tablet.P364_T1_NumberHelperManyDigitBound
import Tablet.P364_T1_NumberHelperDigitPrefix
import Tablet.NumberHelperDecimalPrefixInterval
import Tablet.DecimalDigitTrimDecomposition
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P13_T1_NumberHelperRecordBounds]
theorem P13_T1_NumberHelperRecordBounds :
forall (s : Slice Std.U8) (d : num.imp.dec2flt.decimal.Decimal),
SourceValidByteSlice s -> s.val ≠ [] ->
P9_T1_ActualDispatchOperations.parseNumber s = ok (some d) ->
d.negative = false ∧ d.mantissa.val < 10 ^ 19 := 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
Some result implies a normal Some result
(d,\ell) of num imp dec2flt parse parse partial number:
failure, divergence, or None propagates to a result different
from the assumed one, and the wrapper's remaining-length equality check
can only retain the very same record or return None.
We prove the stronger field conclusion for this partial-parser result.ok, fail, and divergence, since the
latter two propagate. In particular, later exponent and length operations
need not succeed on every input: only their executed normal branches can
contribute a record under the given hypothesis.i64 is exact and supplies exponent -|F|.
Without a dot take F=[], retain the integer accumulator and remainder,
and use exponent zero. In either case the checked sum of the counts
is exactly N=|I|+|F|, with 0\leq N\leq |s|\leq C.
Thus the signed addition is safe; in the no-dot case it is addition of
zero. If N=0, the partial parser returns None, contradicting
its assumed Some result.None follows the residual behavior
ModelOptionFromResidual and cannot produce the assumed record.
For a returned exponent, the checked addition to the fractional exponent
must be normal, followed by the consumed offset and its length cast.
A remainder with neither exponent marker takes the non-scientific
continuation and computes its consumed offset and length directly.
These cases cover both the dot and no-dot branches, including an input
whose entire remainder is empty immediately after the integer scan.
Every executed offset, cast, and exponent addition not already established
safe above is forced normal by bind inversion. We claim neither
unconditional exponent safety nor a scientific-grammar fact here.negative to false in
all three cases. The first two use the retained accumulator, bounded
above by M; the third uses the retry accumulator, also bounded by M.
Injectivity of the normally returned option and pair identifies this
constructor with d. Hence d.\mathit{negative}=\texttt{false} and
d.\mathit{mantissa}\leq M<10^{19}, as required on the full stated domain.Lean proof
have hbits := Dec2Flt.P340_T1_selected_target_numBits
intro s d hsource hne hparse
change num.imp.dec2flt.parse.parse_number s = ok (some d) at hparse
have hlen : s.val.length <= 9223372036854775807 := by
simpa [SourceValidByteSlice] using hsource
have bind_ok_inv : forall {alpha beta : Type} (r : Result alpha)
(f : alpha -> Result beta) y,
Bind.bind r f = ok y -> exists x, r = ok x /\ f x = ok y := by
intro alpha beta r f y h
cases r with
| fail err => simp [Bind.bind, Aeneas.Std.bind] at h
| div => simp [Bind.bind, Aeneas.Std.bind] at h
| ok x => exact ⟨x, rfl, h⟩
have offset_exact := P364_T1_NumberHelperOffsetSourceLength
have adjust_exact := P364_T1_NumberHelperAdjustCountExact
have split_digits := P364_T1_NumberHelperDigitPrefix
have parse_many_bound := P364_T1_NumberHelperManyDigitBound
have record_branches : forall (total : Std.Isize)
(shortMantissa : Std.U64) (intEnd : Slice Std.U8)
(shortExponent retryExponent : Std.I64) (len outLen : Std.Usize),
(total.val <= 19 -> shortMantissa.val <= 9999999999999999999) ->
(forall (nMore adjusted : Std.Isize),
total - 19#isize = ok nMore ->
num.imp.dec2flt.parse.adjust_many_digit_count s nMore = ok adjusted ->
Not (total.val <= 19) ->
Not (0 < adjusted.val) ->
shortMantissa.val <= 9999999999999999999) ->
(if total.val <= 19 then
ok (some
(num.imp.dec2flt.decimal.Decimal.mk shortExponent shortMantissa
false false, len))
else do
let nMore <- total - 19#isize
let adjusted <-
num.imp.dec2flt.parse.adjust_many_digit_count s nMore
if 0 < adjusted.val then
let (manyMantissa, manyExponent) <-
num.imp.dec2flt.parse.parse_many_digits s intEnd retryExponent
ok (some
(num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
false true, len))
else
ok (some
(num.imp.dec2flt.decimal.Decimal.mk shortExponent shortMantissa
false false, len))) = ok (some (d, outLen)) ->
d.negative = false /\ d.mantissa.val < 10 ^ 19 := by
intro total shortMantissa intEnd shortExponent retryExponent len outLen
hshort hnonpositive hresult
by_cases hsmall : total.val <= 19
· simp [hsmall] at hresult
rcases hresult with ⟨rfl, rfl⟩
refine ⟨rfl, ?_⟩
have hb := hshort hsmall
norm_num
omega
· simp [hsmall] at hresult
obtain ⟨nMore, hsub, hresult⟩ := bind_ok_inv _ _ _ hresult
obtain ⟨adjusted, hadjust, hresult⟩ := bind_ok_inv _ _ _ hresult
by_cases hpositive : 0 < adjusted.val
· simp only [if_pos hpositive] at hresult
obtain ⟨manyResult, hmany, hresult⟩ :=
bind_ok_inv _ _ _ hresult
rcases manyResult with ⟨manyMantissa, manyExponent⟩
rcases hresult with ⟨rfl, rfl⟩
refine ⟨rfl, ?_⟩
have hb := parse_many_bound s intEnd retryExponent manyExponent
manyMantissa hmany
norm_num
omega
· simp only [if_neg hpositive] at hresult
rcases hresult with ⟨rfl, rfl⟩
refine ⟨rfl, ?_⟩
have hb := hnonpositive nMore adjusted hsub hadjust hsmall hpositive
norm_num
omega
have fold_upper (digits : List Std.U8) (a : Nat)
(hd : forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57) :
digits.foldl (fun x b => 10 * x + (b.val - 48)) a <
(a + 1) * 10 ^ digits.length := by
have hm : forall z, z ∈ digits.map (fun b => b.val - 48) -> z < 10 := by
intro z hz
obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hz
have := hd b hb
omega
let ds : List Nat := digits.map (fun b => b.val - 48)
have hds : forall z, z ∈ ds -> z < 10 := hm
have hp0 := NumberHelperDecimalPrefixInterval [a] ds hds (0 : Int)
dsimp only at hp0
obtain ⟨_, hp⟩ := hp0
simp only [List.foldl_append, List.foldl_cons, List.foldl_nil,
Nat.mul_zero, Nat.zero_add,
Int.zero_add, zpow_zero, mul_one, zpow_natCast] at hp
have hn : ds.foldl (fun x z => 10 * x + z) a <
(a + 1) * 10 ^ ds.length := by exact_mod_cast hp
simpa [ds, List.foldl_map] using hn
have fold_ge_start : forall (digits : List Std.U8) (a : Nat),
a <= digits.foldl (fun x b => 10 * x + (b.val - 48)) a := by
intro digits
induction digits with
| nil => intro a; rfl
| cons b bs ih =>
intro a
apply le_trans (b := 10 * a + (b.val - 48))
· omega
· exact ih _
have zero_fold : forall digits : List Std.U8,
(forall b, List.Mem b digits -> b = 48#u8) ->
digits.foldl (fun x b => 10 * x + (b.val - 48)) 0 = 0 := by
intro digits hzero
induction digits with
| nil => rfl
| cons b bs ih =>
have hb := hzero b List.mem_cons_self
have hbs : forall c, List.Mem c bs -> c = 48#u8 := by
intro c hc
exact hzero c (List.mem_cons_of_mem b hc)
simp [hb, ih hbs]
have split_zeros (digits : List Std.U8)
(hd : forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57) :
exists zeros tail,
digits = zeros ++ tail /\
(forall b, b ∈ zeros -> b = 48#u8) /\
(tail = [] \/ exists b rest, tail = b :: rest /\ b ≠ 48#u8) := by
let decode : Std.U8 -> Nat := fun b => b.val - 48
let zeros := digits.takeWhile (fun b => b == 48#u8)
let tail := digits.dropWhile (fun b => b == 48#u8)
have hmap : tail.map decode =
(digits.map decode).dropWhile (fun z => z == 0) := by
dsimp only [tail]
induction digits with
| nil => rfl
| cons b bs ih =>
have hb := hd b (by simp)
have hbs : forall c, c ∈ bs -> 48 <= c.val /\ c.val <= 57 := by
intro c hc
exact hd c (by simp [hc])
have hzero : decode b = 0 ↔ b = 48#u8 := by
simp only [decode]
constructor
· intro h
apply UScalar.eq_of_val_eq
norm_num
omega
· intro h
simp [h]
simp only [List.map_cons, List.dropWhile_cons]
by_cases hb0 : b = 48#u8
· simp [hb0, decode, ih hbs]
· simp [hb0, hzero, decode]
obtain ⟨z, q, hz, hq, hsplit, htrim, hstop, hlast⟩ :=
DecimalDigitTrimDecomposition (digits.map decode)
rw [← hmap] at hstop
refine ⟨zeros, tail, ?_, ?_, ?_⟩
· exact (List.takeWhile_append_dropWhile).symm
· intro b hb
have := List.mem_takeWhile_imp hb
simpa using this
· cases ht : tail with
| nil => exact Or.inl rfl
| cons b bs =>
right
refine ⟨b, bs, rfl, ?_⟩
rcases hstop with hn | hn
· simp [ht] at hn
· intro hb
simp [ht, decode, hb] at hn
have count_zeros : forall zeros : List Std.U8,
(forall b, List.Mem b zeros -> b = 48#u8) ->
zeros.count 48#u8 = zeros.length := by
intro zeros hzeros
induction zeros with
| nil => rfl
| cons b bs ih =>
have hb := hzeros b List.mem_cons_self
have hbs : forall c, List.Mem c bs -> c = 48#u8 := by
intro c hc
exact hzeros c (List.mem_cons_of_mem b hc)
simp [hb, ih hbs]
have split_significand_zeros : forall
(integer fraction suffix : List Std.U8),
(forall b, List.Mem b integer -> 48 <= b.val /\ b.val <= 57) ->
(forall b, List.Mem b fraction -> 48 <= b.val /\ b.val <= 57) ->
Not (forall b, List.Mem b (integer ++ fraction) -> b = 48#u8) ->
exists rawZeros rawTail sigZeros sigTail,
integer ++ 46#u8 :: (fraction ++ suffix) = rawZeros ++ rawTail /\
(forall b, List.Mem b rawZeros -> b = 48#u8 \/ b = 46#u8) /\
(exists b rest, rawTail = b :: rest /\
b ≠ 48#u8 /\ b ≠ 46#u8) /\
integer ++ fraction = sigZeros ++ sigTail /\
(forall b, List.Mem b sigZeros -> b = 48#u8) /\
(exists b rest, sigTail = b :: rest /\ b ≠ 48#u8) /\
rawZeros.count 48#u8 = sigZeros.length := by
intro integer fraction suffix hinteger hfraction hnonzero
obtain ⟨intZeros, intSig, hintSplit, hintZeros, hintSig⟩ :=
split_zeros integer hinteger
rcases hintSig with hintNil | ⟨b, intRest, hintSigEq, hb⟩
· obtain ⟨fracZeros, fracSig, hfracSplit, hfracZeros, hfracSig⟩ :=
split_zeros fraction hfraction
rcases hfracSig with hfracNil | ⟨c, fracRest, hfracSigEq, hc⟩
· exfalso
apply hnonzero
intro x hx
rcases List.mem_append.mp hx with hx | hx
· rw [hintSplit, hintNil] at hx
exact hintZeros x (by simpa using hx)
· rw [hfracSplit, hfracNil] at hx
exact hfracZeros x (by simpa using hx)
· refine ⟨intZeros ++ 46#u8 :: fracZeros,
fracSig ++ suffix, intZeros ++ fracZeros, fracSig,
?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
· rw [hintSplit, hintNil, hfracSplit]
simp [List.append_assoc]
· intro x hx
rcases List.mem_append.mp hx with hx | hx
· exact Or.inl (hintZeros x hx)
· rcases List.mem_cons.mp hx with rfl | hx
· exact Or.inr rfl
· exact Or.inl (hfracZeros x hx)
· refine ⟨c, fracRest ++ suffix, by simp [hfracSigEq], hc, ?_⟩
have hcdigit := hfraction c (by
rw [hfracSplit, hfracSigEq]
exact List.mem_append_right fracZeros List.mem_cons_self)
intro hpoint
subst c
norm_num at hcdigit
· rw [hintSplit, hintNil, hfracSplit]
simp [List.append_assoc]
· intro x hx
rcases List.mem_append.mp hx with hx | hx
· exact hintZeros x hx
· exact hfracZeros x hx
· exact ⟨c, fracRest, hfracSigEq, hc⟩
· rw [List.count_append, List.count_cons,
count_zeros intZeros hintZeros,
count_zeros fracZeros hfracZeros]
norm_num
· refine ⟨intZeros, intSig ++ 46#u8 :: (fraction ++ suffix),
intZeros, intSig ++ fraction, ?_, ?_, ?_, ?_, hintZeros, ?_, ?_⟩
· rw [hintSplit]
simp [List.append_assoc]
· intro x hx
exact Or.inl (hintZeros x hx)
· refine ⟨b, intRest ++ 46#u8 :: (fraction ++ suffix),
by simp [hintSigEq], hb, ?_⟩
have hbdigit := hinteger b (by
rw [hintSplit, hintSigEq]
exact List.mem_append_right intZeros List.mem_cons_self)
intro hpoint
subst b
norm_num at hbdigit
· rw [hintSplit]
simp [List.append_assoc]
· exact ⟨b, intRest ++ fraction, by simp [hintSigEq], hb⟩
· exact count_zeros intZeros hintZeros
obtain ⟨intDigits, intTail, hsval, hintDigits, hintTail⟩ :=
split_digits s.val
have hintTailProp : intTail.length <= Usize.max := by
have hp := s.property
rw [hsval] at hp
simp only [List.length_append] at hp
omega
let intRest : Slice Std.U8 := ⟨intTail, hintTailProp⟩
obtain ⟨intMantissa, scannedIntRest, hscanInt, hscannedIntRest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 intDigits intTail hsval
hintDigits hintTail hlen
have hscannedIntRestEq : scannedIntRest = intRest :=
(Slice.eq_iff _ _).2 (by simpa [intRest] using hscannedIntRest)
subst scannedIntRest
obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
offset_exact s intRest hlen (by
rw [hsval]
simp [intRest])
have hnDigitsEq : nDigits.val = intDigits.length := by
rw [hnDigitsVal, hsval]
simp [intRest]
have hpartial : exists len,
num.imp.dec2flt.parse.parse_partial_number s = ok (some (d, len)) := by
unfold num.imp.dec2flt.parse.parse_number at hparse
cases hp : num.imp.dec2flt.parse.parse_partial_number s with
| fail err => simp [hp] at hparse
| div => simp [hp] at hparse
| ok result =>
cases result with
| none => simp [hp] at hparse
| some pair =>
rcases pair with ⟨record, len⟩
simp [hp] at hparse
split at hparse
· have hrecord : record = d := by simpa using hparse
subst d
exact ⟨len, rfl⟩
· simp at hparse
obtain ⟨parsedLen, hpartial⟩ := hpartial
cases intTail with
| nil =>
have hsplitInt : core.slice.Slice.split_first intRest = ok none := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst, intRest]
have haddZero : nDigits + 0#isize = ok nDigits := by
have hb := IScalar.hBounds nDigits
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec (x := nDigits) (y := 0#isize) (by
simp [IScalar.min, IScalarTy.numBits,
hbits]
omega) (by
simp [IScalar.max, IScalarTy.numBits,
hbits] at hb ⊢
omega))
rw [hz]
congr 2
apply IScalar.eq_of_val_eq
simpa using hzval
have hfullOffset :
SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from
intRest s = ok nDigits := by
simpa [intRest] using hoffInt
have hcastLen : lift (IScalar.hcast .Usize nDigits) =
ok (Slice.len s) := by
have hbound : 0 <= nDigits.val /\
nDigits.val <= UScalar.max .Usize := by
rw [hnDigitsEq]
constructor
· omega
· have hp := s.property
rw [hsval] at hp
simpa [UScalar.max, Usize.max, Usize.numBits,
hbits] using hp
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize nDigits hbound)
rw [hz]
congr 2
apply UScalar.eq_of_val_eq
rw [hnDigitsEq] at hzval
have hslen : s.val.length = intDigits.length := by simp [hsval]
simpa [Slice.len_val, hslen] using hzval
unfold num.imp.dec2flt.parse.parse_partial_number at hpartial
simp [hne, hscanInt, hoffInt, hsplitInt, haddZero,
hcastLen] at hpartial
by_cases hnzero : nDigits = 0#isize
· simp [hnzero] at hpartial
· simp [hnzero] at hpartial
by_cases hsmall : nDigits.val <= 19
· simp [hsmall] at hpartial
rcases hpartial with ⟨rfl, rfl⟩
constructor
· rfl
· have hfoldLt := fold_upper intDigits 0 hintDigits
norm_num at hfoldLt
have hlen19 : intDigits.length <= 19 := by
omega
have hbound : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [U64.max_eq]
have hp := hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat)) hlen19)
norm_num at hp ⊢
omega
obtain ⟨value, rest, hexact, hrest, hvalue⟩ :=
NumberHelperDigitScanExact s 0#u64 intDigits []
(by simpa using hsval) hintDigits (by
intro b rest h
cases h) hlen hbound
rw [hscanInt] at hexact
simp at hexact
rcases hexact with ⟨rfl, rfl⟩
rw [hvalue]
norm_num
exact hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat)) hlen19)
· have hlarge : 19 < nDigits.val := by omega
have hsubBounds : IScalar.min .Isize <= nDigits.val - 19 /\
nDigits.val - 19 <= IScalar.max .Isize := by
have hb := IScalar.hBounds nDigits
simp [IScalar.min, IScalar.max, IScalarTy.numBits,
hbits] at hb ⊢
omega
obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.sub_spec (x := nDigits) (y := 19#isize)
(by norm_num; omega) (by norm_num; omega))
norm_num at hnMoreVal
simp [hsmall, hnMore] at hpartial
obtain ⟨zeros, nonzeroTail, hzeroSplit, hzeros, hzeroTail⟩ :=
split_zeros intDigits hintDigits
have hcount := count_zeros zeros hzeros
have hsAdjust : s.val = zeros ++ nonzeroTail := by
simpa [hzeroSplit] using hsval
have htailSharp : nonzeroTail = [] \/ exists b rest,
nonzeroTail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
rcases hzeroTail with hnil | ⟨b, rest, htailEq, hb⟩
· exact Or.inl hnil
· right
refine ⟨b, rest, htailEq, hb, ?_⟩
have hbdigit := hintDigits b (by
rw [hzeroSplit, htailEq]
exact List.mem_append_right zeros List.mem_cons_self)
intro heq
subst b
norm_num at hbdigit
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, hnDigitsEq, hsval]
simp only [List.length_append, List.length_nil, Nat.add_zero]
omega
have hadjustLower : IScalar.min .Isize <=
nMore.val - (zeros.count 48#u8 : Int) := by
rw [hnMoreVal, hcount, hnDigitsEq]
have hzerosLen : zeros.length <= intDigits.length := by
rw [hzeroSplit]
simp
simp [IScalar.min, IScalarTy.numBits,
hbits]
omega
obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
adjust_exact s nMore zeros nonzeroTail hsAdjust
(by intro b hb; exact Or.inl (hzeros b hb)) htailSharp hlen
hnMoreNonneg hnMoreLe hadjustLower
rw [hadjust] at hpartial
by_cases hpositive : 0 < adjusted.val
· simp [hpositive] at hpartial
cases hmany :
num.imp.dec2flt.parse.parse_many_digits s intRest 0#i64 with
| fail err => simp [hmany] at hpartial
| div => simp [hmany] at hpartial
| ok result =>
rcases result with ⟨manyMantissa, manyExponent⟩
simp [hmany] at hpartial
rcases hpartial with ⟨rfl, rfl⟩
refine ⟨rfl, ?_⟩
change manyMantissa.val < 10 ^ 19
have hb := parse_many_bound s intRest 0#i64 manyExponent
manyMantissa hmany
omega
· simp [hpositive] at hpartial
have htailLen : nonzeroTail.length <= 19 := by
rw [hadjustVal, hnMoreVal, hcount, hnDigitsEq] at hpositive
have hlenEq := congrArg List.length hzeroSplit
simp only [List.length_append] at hlenEq
omega
have htailDigits : forall b, List.Mem b nonzeroTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hintDigits b
rw [hzeroSplit]
exact List.mem_append_right zeros hb
have hzeroFold := zero_fold zeros hzeros
have hfoldLt : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 < 10 ^ 19 := by
rcases hzeroTail with hnil | hcons
· subst nonzeroTail
rw [hzeroSplit, List.append_nil, hzeroFold]
norm_num
· rw [hzeroSplit, List.foldl_append, hzeroFold]
have htailLt := fold_upper nonzeroTail 0 htailDigits
norm_num at htailLt
exact htailLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat))
htailLen)
have hfoldBound : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [U64.max_eq]
omega
obtain ⟨value, rest, hexact, hrest, hvalue⟩ :=
NumberHelperDigitScanExact s 0#u64 intDigits []
(by simpa using hsval) hintDigits (by
intro b rest h
cases h) hlen hfoldBound
rw [hscanInt] at hexact
simp at hexact
rcases hexact with ⟨rfl, rfl⟩
rcases hpartial with ⟨rfl, rfl⟩
refine ⟨rfl, ?_⟩
norm_num at hvalue ⊢
rw [hvalue]
exact hfoldLt
| cons first tail =>
have htailProp : tail.length <= Usize.max := by
have hp := intRest.property
simp [intRest] at hp ⊢
omega
let afterFirst : Slice Std.U8 := ⟨tail, htailProp⟩
have hsplitInt : core.slice.Slice.split_first intRest =
ok (some (first, afterFirst)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
intRest, afterFirst]
by_cases hpoint : first = 46#u8
· subst first
obtain ⟨fracDigits, fracTail, hfracSplit, hfracDigits, hfracTail⟩ :=
split_digits tail
have hfracTailProp : fracTail.length <= Usize.max := by
have hp := afterFirst.property
simp [afterFirst, hfracSplit] at hp ⊢
omega
let fracRest : Slice Std.U8 := ⟨fracTail, hfracTailProp⟩
have hlenAfter : afterFirst.val.length <= 9223372036854775807 := by
simp [afterFirst]
rw [hsval] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega
obtain ⟨fracMantissa, scannedFracRest, hscanFrac, hscannedFracRest⟩ :=
NumberHelperDigitScanSourceLength afterFirst intMantissa fracDigits
fracTail (by simp [afterFirst, hfracSplit]) hfracDigits hfracTail
hlenAfter
have hscannedFracRestEq : scannedFracRest = fracRest :=
(Slice.eq_iff _ _).2 (by
simpa [fracRest] using hscannedFracRest)
subst scannedFracRest
obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
offset_exact afterFirst fracRest hlenAfter (by
simp [afterFirst, fracRest, hfracSplit])
have hnAfterEq : nAfter.val = fracDigits.length := by
rw [hnAfterVal]
simp [afterFirst, fracRest, hfracSplit]
have hnAfterNotMin : nAfter.val ≠ IScalar.min .Isize := by
rw [hnAfterEq, IScalar.min]
simp [IScalarTy.numBits, hbits]
obtain ⟨negAfter, hnegAfter, hnegAfterVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(HNeg.hNeg.step nAfter hnAfterNotMin)
have hnegCastBounds : IScalar.min .I64 <= negAfter.val /\
negAfter.val <= IScalar.max .I64 := by
rw [hnegAfterVal, hnAfterEq,
IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
constructor <;> omega
obtain ⟨fracExponent, hfracExponent, hfracExponentVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.cast_inBounds_spec .I64 negAfter hnegCastBounds)
have htotalBounds : IScalar.min .Isize <=
nDigits.val + nAfter.val /\
nDigits.val + nAfter.val <= IScalar.max .Isize := by
rw [hnDigitsEq, hnAfterEq]
simp [IScalar.min, IScalar.max, IScalarTy.numBits,
hbits]
rw [hsval, hfracSplit] at hlen
simp only [List.length_append, List.length_cons] at hlen
constructor <;> omega
obtain ⟨totalDigits, htotal, htotalVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec htotalBounds.1 htotalBounds.2)
have hsigDigits : forall b,
List.Mem b (intDigits ++ fracDigits) ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
rcases List.mem_append.mp hb with hb | hb
· exact hintDigits b hb
· exact hfracDigits b hb
have hexactScans :
(intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max ->
fracMantissa.val = (intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 := by
intro hfullBound
have hprefixLe := fold_ge_start fracDigits
(intDigits.foldl (fun x b => 10 * x + (b.val - 48)) 0)
rw [← List.foldl_append] at hprefixLe
have hintBound : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max :=
hprefixLe.trans hfullBound
obtain ⟨intValue, intScanRest, hexactInt, hexactIntRest,
hintValue⟩ :=
NumberHelperDigitScanExact s 0#u64 intDigits
(46#u8 :: tail) (by simpa using hsval) hintDigits hintTail
hlen hintBound
rw [hscanInt] at hexactInt
simp at hexactInt
rcases hexactInt with ⟨rfl, rfl⟩
have hfracBound : fracDigits.foldl
(fun x b => 10 * x + (b.val - 48)) intMantissa.val <=
U64.max := by
norm_num at hintValue
rw [hintValue, ← List.foldl_append]
exact hfullBound
obtain ⟨fracValue, fracScanRest, hexactFrac, hexactFracRest,
hfracValue⟩ :=
NumberHelperDigitScanExact afterFirst intMantissa fracDigits
fracTail (by simp [afterFirst, hfracSplit]) hfracDigits
hfracTail hlenAfter hfracBound
rw [hscanFrac] at hexactFrac
simp at hexactFrac
rcases hexactFrac with ⟨rfl, rfl⟩
norm_num at hintValue hfracValue ⊢
rw [hfracValue, hintValue]
have hshort : totalDigits.val <= 19 ->
fracMantissa.val <= 9999999999999999999 := by
intro hsmall
have hsigLen : intDigits.length + fracDigits.length <= 19 := by
rw [htotalVal, hnDigitsEq, hnAfterEq] at hsmall
omega
have hfoldLt := fold_upper (intDigits ++ fracDigits) 0 hsigDigits
norm_num at hfoldLt
have hfold19 := hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat)) hsigLen)
have hfoldBound : (intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [U64.max_eq]
norm_num
omega
rw [hexactScans hfoldBound]
norm_num
omega
have hnonpositive : forall (nMore adjusted : Std.Isize),
totalDigits - 19#isize = ok nMore ->
num.imp.dec2flt.parse.adjust_many_digit_count s nMore = ok adjusted ->
Not (totalDigits.val <= 19) ->
Not (0 < adjusted.val) ->
fracMantissa.val <= 9999999999999999999 := by
intro nMore adjusted hsub hadjust hlarge hnonpos
by_cases hallzero : forall b,
List.Mem b (intDigits ++ fracDigits) -> b = 48#u8
· have hfoldZero := zero_fold (intDigits ++ fracDigits) hallzero
have hfoldBound : (intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [hfoldZero]
exact Nat.zero_le _
rw [hexactScans hfoldBound, hfoldZero]
norm_num
· obtain ⟨rawZeros, rawTail, sigZeros, sigTail, hrawSplit,
hrawZeros, hrawTail, hsigSplit, hsigZeros, hsigTail, hcount⟩ :=
split_significand_zeros intDigits fracDigits fracTail
hintDigits hfracDigits hallzero
have hsAdjust : s.val = rawZeros ++ rawTail := by
rw [hsval, hfracSplit]
exact hrawSplit
have hnMoreVal : nMore.val = totalDigits.val - 19 := by
have heq := IScalar.sub_equiv totalDigits 19#isize
rw [hsub] at heq
have hval := heq.2.1
norm_num at hval ⊢
exact hval
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq, hsval,
hfracSplit]
simp only [List.length_append, List.length_cons]
omega
have hadjustLower : IScalar.min .Isize <=
nMore.val - (rawZeros.count 48#u8 : Int) := by
rw [hnMoreVal, hcount, htotalVal, hnDigitsEq, hnAfterEq]
have hzlen : sigZeros.length <=
(intDigits ++ fracDigits).length := by
rw [hsigSplit]
simp
have hsigSource : (intDigits ++ fracDigits).length <=
s.val.length := by
rw [hsval, hfracSplit]
simp only [List.length_append, List.length_cons]
omega
have hzBound : sigZeros.length <= 9223372036854775807 :=
hzlen.trans (hsigSource.trans hlen)
simp [IScalar.min, IScalarTy.numBits,
hbits]
omega
obtain ⟨adjusted2, hadjust2, hadjust2Val⟩ :=
adjust_exact s nMore rawZeros rawTail hsAdjust
hrawZeros (Or.inr hrawTail) hlen hnMoreNonneg hnMoreLe
hadjustLower
rw [hadjust] at hadjust2
simp at hadjust2
subst adjusted2
have hsigTailLen : sigTail.length <= 19 := by
rw [hadjust2Val, hnMoreVal, hcount, htotalVal, hnDigitsEq,
hnAfterEq] at hnonpos
have hlenEq := congrArg List.length hsigSplit
simp only [List.length_append] at hlenEq
omega
have hsigTailDigits : forall b, List.Mem b sigTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hsigDigits b
rw [hsigSplit]
exact List.mem_append_right sigZeros hb
have hzeroFold := zero_fold sigZeros hsigZeros
have htailLt := fold_upper sigTail 0 hsigTailDigits
norm_num at htailLt
have hfoldLt : (intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 < 10 ^ 19 := by
rw [hsigSplit, List.foldl_append, hzeroFold]
exact htailLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat))
hsigTailLen)
have hfoldBound : (intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
exact (Nat.le_of_lt hfoldLt).trans (by
norm_num [U64.max_eq])
rw [hexactScans hfoldBound]
norm_num at hfoldLt ⊢
omega
unfold num.imp.dec2flt.parse.parse_partial_number at hpartial
simp [hne, hscanInt, hoffInt, hsplitInt, hscanFrac, hoffFrac,
hnegAfter, hfracExponent] at hpartial
simp only [UScalar.ofNatCore] at hpartial
simp [htotal] at hpartial
by_cases hzero : totalDigits = 0#isize
· simp [hzero] at hpartial
· simp [hzero] at hpartial
cases fracTail with
| nil =>
have hsplitFrac : core.slice.Slice.split_first fracRest =
ok none := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
fracRest]
simp [hsplitFrac] at hpartial
obtain ⟨off, hoff, hpartial⟩ := bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ := bind_ok_inv _ _ _ hpartial
exact record_branches totalDigits fracMantissa intRest fracExponent
0#i64 len parsedLen hshort hnonpositive hpartial
| cons marker suffix =>
have hsuffixProp : suffix.length <= Usize.max := by
have hp := fracRest.property
simp [fracRest] at hp ⊢
omega
let afterMarker : Slice Std.U8 := ⟨suffix, hsuffixProp⟩
have hsplitFrac : core.slice.Slice.split_first fracRest =
ok (some (marker, afterMarker)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
fracRest, afterMarker]
simp [hsplitFrac] at hpartial
by_cases hlower : marker = (⟨101#8⟩ : Std.U8)
· subst marker
obtain ⟨sciResult, hsci, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
rcases sciResult with ⟨optExp, sciRest⟩
cases optExp with
| none =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
ModelOptionFromResidual] at hpartial
| some parsedExp =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch] at hpartial
obtain ⟨combined, hsum, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨off, hoff, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
exact record_branches totalDigits fracMantissa intRest combined
parsedExp len parsedLen hshort hnonpositive hpartial
· by_cases hupper : marker = (⟨69#8⟩ : Std.U8)
· subst marker
obtain ⟨sciResult, hsci, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
rcases sciResult with ⟨optExp, sciRest⟩
cases optExp with
| none =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
ModelOptionFromResidual] at hpartial
| some parsedExp =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch] at hpartial
obtain ⟨combined, hsum, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨off, hoff, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
exact record_branches totalDigits fracMantissa intRest combined
parsedExp len parsedLen hshort hnonpositive hpartial
· simp [hlower, hupper] at hpartial
obtain ⟨off, hoff, hpartial⟩ := bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ := bind_ok_inv _ _ _ hpartial
exact record_branches totalDigits fracMantissa intRest
fracExponent 0#i64 len parsedLen hshort hnonpositive hpartial
· have haddZero : nDigits + 0#isize = ok nDigits := by
have hb := IScalar.hBounds nDigits
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec (x := nDigits) (y := 0#isize) (by
simp [IScalar.min, IScalarTy.numBits,
hbits]
omega) (by
simp [IScalar.max, IScalarTy.numBits,
hbits] at hb ⊢
omega))
rw [hz]
congr 2
apply IScalar.eq_of_val_eq
simpa using hzval
have hshort : nDigits.val <= 19 ->
intMantissa.val <= 9999999999999999999 := by
intro hsmall
have hlen19 : intDigits.length <= 19 := by omega
have hfoldLt := fold_upper intDigits 0 hintDigits
norm_num at hfoldLt
have hfold19 : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 < 10 ^ 19 :=
hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat)) hlen19)
have hfoldBound : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [U64.max_eq]
omega
obtain ⟨value, rest, hexact, hrest, hvalue⟩ :=
NumberHelperDigitScanExact s 0#u64 intDigits (first :: tail)
(by simpa using hsval) hintDigits hintTail hlen hfoldBound
rw [hscanInt] at hexact
simp at hexact
rcases hexact with ⟨rfl, rfl⟩
norm_num at hvalue ⊢
rw [hvalue]
omega
have hnonpositive : forall (nMore adjusted : Std.Isize),
nDigits - 19#isize = ok nMore ->
num.imp.dec2flt.parse.adjust_many_digit_count s nMore = ok adjusted ->
Not (nDigits.val <= 19) ->
Not (0 < adjusted.val) ->
intMantissa.val <= 9999999999999999999 := by
intro nMore adjusted hsub hadjust hlarge hnonpos
have hnMoreVal : nMore.val = nDigits.val - 19 := by
have heq := IScalar.sub_equiv nDigits 19#isize
rw [hsub] at heq
have hval := heq.2.1
norm_num at hval ⊢
exact hval
obtain ⟨zeros, nzTail, hzeroSplit, hzeros, hnzTail⟩ :=
split_zeros intDigits hintDigits
have hcount := count_zeros zeros hzeros
let rawTail : List Std.U8 := nzTail ++ first :: tail
have hsAdjust : s.val = zeros ++ rawTail := by
rw [hsval, hzeroSplit]
simp [rawTail, List.append_assoc]
have hrawTail : rawTail = [] \/ exists b rest,
rawTail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
right
rcases hnzTail with hnil | ⟨b, rest, heq, hb⟩
· subst nzTail
refine ⟨first, tail, by simp [rawTail], ?_, hpoint⟩
intro hzero
subst first
have hnot := hintTail 48#u8 tail rfl
norm_num at hnot
· refine ⟨b, rest ++ first :: tail, by simp [rawTail, heq], hb, ?_⟩
have hbdigit := hintDigits b (by
rw [hzeroSplit, heq]
exact List.mem_append_right zeros List.mem_cons_self)
intro heq46
subst b
norm_num at hbdigit
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, hnDigitsEq, hsval]
simp only [List.length_append, List.length_cons]
omega
have hadjustLower : IScalar.min .Isize <=
nMore.val - (zeros.count 48#u8 : Int) := by
rw [hnMoreVal, hcount, hnDigitsEq]
have hzlen : zeros.length <= intDigits.length := by
rw [hzeroSplit]
simp
simp [IScalar.min, IScalarTy.numBits,
hbits]
omega
obtain ⟨adjusted2, hadjust2, hadjust2Val⟩ :=
adjust_exact s nMore zeros rawTail hsAdjust
(by intro b hb; exact Or.inl (hzeros b hb)) hrawTail hlen
hnMoreNonneg hnMoreLe hadjustLower
rw [hadjust] at hadjust2
simp at hadjust2
subst adjusted2
have hnzLen : nzTail.length <= 19 := by
rw [hadjust2Val, hnMoreVal, hcount, hnDigitsEq] at hnonpos
have hlenEq := congrArg List.length hzeroSplit
simp only [List.length_append] at hlenEq
omega
have hnzDigits : forall b, List.Mem b nzTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hintDigits b
rw [hzeroSplit]
exact List.mem_append_right zeros hb
have hzeroFold := zero_fold zeros hzeros
have hfoldLt : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 < 10 ^ 19 := by
rcases hnzTail with hnil | hcons
· subst nzTail
rw [hzeroSplit, List.append_nil, hzeroFold]
norm_num
· rw [hzeroSplit, List.foldl_append, hzeroFold]
have htailLt := fold_upper nzTail 0 hnzDigits
norm_num at htailLt
exact htailLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat)) hnzLen)
have hfoldBound : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [U64.max_eq]
omega
obtain ⟨value, rest, hexact, hrest, hvalue⟩ :=
NumberHelperDigitScanExact s 0#u64 intDigits (first :: tail)
(by simpa using hsval) hintDigits hintTail hlen hfoldBound
rw [hscanInt] at hexact
simp at hexact
rcases hexact with ⟨rfl, rfl⟩
norm_num at hvalue ⊢
rw [hvalue]
omega
have hpointVal : first.val ≠ 46 := by
intro hval
apply hpoint
exact UScalar.eq_of_val_eq hval
unfold num.imp.dec2flt.parse.parse_partial_number at hpartial
simp [hne, hscanInt, hoffInt, hsplitInt] at hpartial
split at hpartial
all_goals try { exfalso; apply hpointVal; rfl }
simp [haddZero] at hpartial
by_cases hnzero : nDigits = 0#isize
· simp [hnzero] at hpartial
· simp [hnzero, hsplitInt] at hpartial
by_cases hlower : first = 101#u8
· subst first
obtain ⟨sciResult, hsci, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
rcases sciResult with ⟨optExp, sciRest⟩
cases optExp with
| none =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
ModelOptionFromResidual] at hpartial
| some parsedExp =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch] at hpartial
obtain ⟨combined, hsum, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨off, hoff, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
exact record_branches nDigits intMantissa intRest combined
parsedExp len parsedLen hshort hnonpositive hpartial
· by_cases hupper : first = 69#u8
· simp [hlower] at hpartial
subst first
obtain ⟨sciResult, hsci, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
rcases sciResult with ⟨optExp, sciRest⟩
cases optExp with
| none =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
ModelOptionFromResidual] at hpartial
| some parsedExp =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch] at hpartial
obtain ⟨combined, hsum, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨off, hoff, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
exact record_branches nDigits intMantissa intRest combined
parsedExp len parsedLen hshort hnonpositive hpartial
· simp [hlower, hupper] at hpartial
rw [hoffInt] at hpartial
simp at hpartial
obtain ⟨len, hcast, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
exact record_branches nDigits intMantissa intRest 0#i64 0#i64
len parsedLen hshort hnonpositive hpartial
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.Assumptions
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.ModelSliceSplitFirst
import Tablet.NumberHelperDigitScanExact
import Tablet.NumberHelperDigitScanSourceLength
import Tablet.NumberHelperTryParse19SafeLength
import Tablet.U64_Insts_CoreOpsBitBitAndU64U64
import Tablet.U64_Insts_CoreOpsBitBitOrU64U64
import Tablet.num_imp_dec2flt_decimal_Decimal
import Tablet.num_imp_dec2flt_parse_parse_many_digits
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_partial_number
import Tablet.num_imp_dec2flt_parse_parse_scientific
import Tablet.SourceValidByteSlice
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.P364_T1_NumberHelperOffsetSourceLength
import Tablet.P364_T1_NumberHelperAdjustCountExact
import Tablet.P364_T1_NumberHelperManyDigitBound
import Tablet.P364_T1_NumberHelperDigitPrefix
import Tablet.NumberHelperDecimalPrefixInterval
import Tablet.DecimalDigitTrimDecomposition
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P13_T1_NumberHelperRecordBounds]
theorem P13_T1_NumberHelperRecordBounds :
forall (s : Slice Std.U8) (d : num.imp.dec2flt.decimal.Decimal),
SourceValidByteSlice s -> s.val ≠ [] ->
P9_T1_ActualDispatchOperations.parseNumber s = ok (some d) ->
d.negative = false ∧ d.mantissa.val < 10 ^ 19 := by
-- BODY
have hbits := Dec2Flt.P340_T1_selected_target_numBits
intro s d hsource hne hparse
change num.imp.dec2flt.parse.parse_number s = ok (some d) at hparse
have hlen : s.val.length <= 9223372036854775807 := by
simpa [SourceValidByteSlice] using hsource
have bind_ok_inv : forall {alpha beta : Type} (r : Result alpha)
(f : alpha -> Result beta) y,
Bind.bind r f = ok y -> exists x, r = ok x /\ f x = ok y := by
intro alpha beta r f y h
cases r with
| fail err => simp [Bind.bind, Aeneas.Std.bind] at h
| div => simp [Bind.bind, Aeneas.Std.bind] at h
| ok x => exact ⟨x, rfl, h⟩
have offset_exact := P364_T1_NumberHelperOffsetSourceLength
have adjust_exact := P364_T1_NumberHelperAdjustCountExact
have split_digits := P364_T1_NumberHelperDigitPrefix
have parse_many_bound := P364_T1_NumberHelperManyDigitBound
have record_branches : forall (total : Std.Isize)
(shortMantissa : Std.U64) (intEnd : Slice Std.U8)
(shortExponent retryExponent : Std.I64) (len outLen : Std.Usize),
(total.val <= 19 -> shortMantissa.val <= 9999999999999999999) ->
(forall (nMore adjusted : Std.Isize),
total - 19#isize = ok nMore ->
num.imp.dec2flt.parse.adjust_many_digit_count s nMore = ok adjusted ->
Not (total.val <= 19) ->
Not (0 < adjusted.val) ->
shortMantissa.val <= 9999999999999999999) ->
(if total.val <= 19 then
ok (some
(num.imp.dec2flt.decimal.Decimal.mk shortExponent shortMantissa
false false, len))
else do
let nMore <- total - 19#isize
let adjusted <-
num.imp.dec2flt.parse.adjust_many_digit_count s nMore
if 0 < adjusted.val then
let (manyMantissa, manyExponent) <-
num.imp.dec2flt.parse.parse_many_digits s intEnd retryExponent
ok (some
(num.imp.dec2flt.decimal.Decimal.mk manyExponent manyMantissa
false true, len))
else
ok (some
(num.imp.dec2flt.decimal.Decimal.mk shortExponent shortMantissa
false false, len))) = ok (some (d, outLen)) ->
d.negative = false /\ d.mantissa.val < 10 ^ 19 := by
intro total shortMantissa intEnd shortExponent retryExponent len outLen
hshort hnonpositive hresult
by_cases hsmall : total.val <= 19
· simp [hsmall] at hresult
rcases hresult with ⟨rfl, rfl⟩
refine ⟨rfl, ?_⟩
have hb := hshort hsmall
norm_num
omega
· simp [hsmall] at hresult
obtain ⟨nMore, hsub, hresult⟩ := bind_ok_inv _ _ _ hresult
obtain ⟨adjusted, hadjust, hresult⟩ := bind_ok_inv _ _ _ hresult
by_cases hpositive : 0 < adjusted.val
· simp only [if_pos hpositive] at hresult
obtain ⟨manyResult, hmany, hresult⟩ :=
bind_ok_inv _ _ _ hresult
rcases manyResult with ⟨manyMantissa, manyExponent⟩
rcases hresult with ⟨rfl, rfl⟩
refine ⟨rfl, ?_⟩
have hb := parse_many_bound s intEnd retryExponent manyExponent
manyMantissa hmany
norm_num
omega
· simp only [if_neg hpositive] at hresult
rcases hresult with ⟨rfl, rfl⟩
refine ⟨rfl, ?_⟩
have hb := hnonpositive nMore adjusted hsub hadjust hsmall hpositive
norm_num
omega
have fold_upper (digits : List Std.U8) (a : Nat)
(hd : forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57) :
digits.foldl (fun x b => 10 * x + (b.val - 48)) a <
(a + 1) * 10 ^ digits.length := by
have hm : forall z, z ∈ digits.map (fun b => b.val - 48) -> z < 10 := by
intro z hz
obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hz
have := hd b hb
omega
let ds : List Nat := digits.map (fun b => b.val - 48)
have hds : forall z, z ∈ ds -> z < 10 := hm
have hp0 := NumberHelperDecimalPrefixInterval [a] ds hds (0 : Int)
dsimp only at hp0
obtain ⟨_, hp⟩ := hp0
simp only [List.foldl_append, List.foldl_cons, List.foldl_nil,
Nat.mul_zero, Nat.zero_add,
Int.zero_add, zpow_zero, mul_one, zpow_natCast] at hp
have hn : ds.foldl (fun x z => 10 * x + z) a <
(a + 1) * 10 ^ ds.length := by exact_mod_cast hp
simpa [ds, List.foldl_map] using hn
have fold_ge_start : forall (digits : List Std.U8) (a : Nat),
a <= digits.foldl (fun x b => 10 * x + (b.val - 48)) a := by
intro digits
induction digits with
| nil => intro a; rfl
| cons b bs ih =>
intro a
apply le_trans (b := 10 * a + (b.val - 48))
· omega
· exact ih _
have zero_fold : forall digits : List Std.U8,
(forall b, List.Mem b digits -> b = 48#u8) ->
digits.foldl (fun x b => 10 * x + (b.val - 48)) 0 = 0 := by
intro digits hzero
induction digits with
| nil => rfl
| cons b bs ih =>
have hb := hzero b List.mem_cons_self
have hbs : forall c, List.Mem c bs -> c = 48#u8 := by
intro c hc
exact hzero c (List.mem_cons_of_mem b hc)
simp [hb, ih hbs]
have split_zeros (digits : List Std.U8)
(hd : forall b, b ∈ digits -> 48 <= b.val /\ b.val <= 57) :
exists zeros tail,
digits = zeros ++ tail /\
(forall b, b ∈ zeros -> b = 48#u8) /\
(tail = [] \/ exists b rest, tail = b :: rest /\ b ≠ 48#u8) := by
let decode : Std.U8 -> Nat := fun b => b.val - 48
let zeros := digits.takeWhile (fun b => b == 48#u8)
let tail := digits.dropWhile (fun b => b == 48#u8)
have hmap : tail.map decode =
(digits.map decode).dropWhile (fun z => z == 0) := by
dsimp only [tail]
induction digits with
| nil => rfl
| cons b bs ih =>
have hb := hd b (by simp)
have hbs : forall c, c ∈ bs -> 48 <= c.val /\ c.val <= 57 := by
intro c hc
exact hd c (by simp [hc])
have hzero : decode b = 0 ↔ b = 48#u8 := by
simp only [decode]
constructor
· intro h
apply UScalar.eq_of_val_eq
norm_num
omega
· intro h
simp [h]
simp only [List.map_cons, List.dropWhile_cons]
by_cases hb0 : b = 48#u8
· simp [hb0, decode, ih hbs]
· simp [hb0, hzero, decode]
obtain ⟨z, q, hz, hq, hsplit, htrim, hstop, hlast⟩ :=
DecimalDigitTrimDecomposition (digits.map decode)
rw [← hmap] at hstop
refine ⟨zeros, tail, ?_, ?_, ?_⟩
· exact (List.takeWhile_append_dropWhile).symm
· intro b hb
have := List.mem_takeWhile_imp hb
simpa using this
· cases ht : tail with
| nil => exact Or.inl rfl
| cons b bs =>
right
refine ⟨b, bs, rfl, ?_⟩
rcases hstop with hn | hn
· simp [ht] at hn
· intro hb
simp [ht, decode, hb] at hn
have count_zeros : forall zeros : List Std.U8,
(forall b, List.Mem b zeros -> b = 48#u8) ->
zeros.count 48#u8 = zeros.length := by
intro zeros hzeros
induction zeros with
| nil => rfl
| cons b bs ih =>
have hb := hzeros b List.mem_cons_self
have hbs : forall c, List.Mem c bs -> c = 48#u8 := by
intro c hc
exact hzeros c (List.mem_cons_of_mem b hc)
simp [hb, ih hbs]
have split_significand_zeros : forall
(integer fraction suffix : List Std.U8),
(forall b, List.Mem b integer -> 48 <= b.val /\ b.val <= 57) ->
(forall b, List.Mem b fraction -> 48 <= b.val /\ b.val <= 57) ->
Not (forall b, List.Mem b (integer ++ fraction) -> b = 48#u8) ->
exists rawZeros rawTail sigZeros sigTail,
integer ++ 46#u8 :: (fraction ++ suffix) = rawZeros ++ rawTail /\
(forall b, List.Mem b rawZeros -> b = 48#u8 \/ b = 46#u8) /\
(exists b rest, rawTail = b :: rest /\
b ≠ 48#u8 /\ b ≠ 46#u8) /\
integer ++ fraction = sigZeros ++ sigTail /\
(forall b, List.Mem b sigZeros -> b = 48#u8) /\
(exists b rest, sigTail = b :: rest /\ b ≠ 48#u8) /\
rawZeros.count 48#u8 = sigZeros.length := by
intro integer fraction suffix hinteger hfraction hnonzero
obtain ⟨intZeros, intSig, hintSplit, hintZeros, hintSig⟩ :=
split_zeros integer hinteger
rcases hintSig with hintNil | ⟨b, intRest, hintSigEq, hb⟩
· obtain ⟨fracZeros, fracSig, hfracSplit, hfracZeros, hfracSig⟩ :=
split_zeros fraction hfraction
rcases hfracSig with hfracNil | ⟨c, fracRest, hfracSigEq, hc⟩
· exfalso
apply hnonzero
intro x hx
rcases List.mem_append.mp hx with hx | hx
· rw [hintSplit, hintNil] at hx
exact hintZeros x (by simpa using hx)
· rw [hfracSplit, hfracNil] at hx
exact hfracZeros x (by simpa using hx)
· refine ⟨intZeros ++ 46#u8 :: fracZeros,
fracSig ++ suffix, intZeros ++ fracZeros, fracSig,
?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
· rw [hintSplit, hintNil, hfracSplit]
simp [List.append_assoc]
· intro x hx
rcases List.mem_append.mp hx with hx | hx
· exact Or.inl (hintZeros x hx)
· rcases List.mem_cons.mp hx with rfl | hx
· exact Or.inr rfl
· exact Or.inl (hfracZeros x hx)
· refine ⟨c, fracRest ++ suffix, by simp [hfracSigEq], hc, ?_⟩
have hcdigit := hfraction c (by
rw [hfracSplit, hfracSigEq]
exact List.mem_append_right fracZeros List.mem_cons_self)
intro hpoint
subst c
norm_num at hcdigit
· rw [hintSplit, hintNil, hfracSplit]
simp [List.append_assoc]
· intro x hx
rcases List.mem_append.mp hx with hx | hx
· exact hintZeros x hx
· exact hfracZeros x hx
· exact ⟨c, fracRest, hfracSigEq, hc⟩
· rw [List.count_append, List.count_cons,
count_zeros intZeros hintZeros,
count_zeros fracZeros hfracZeros]
norm_num
· refine ⟨intZeros, intSig ++ 46#u8 :: (fraction ++ suffix),
intZeros, intSig ++ fraction, ?_, ?_, ?_, ?_, hintZeros, ?_, ?_⟩
· rw [hintSplit]
simp [List.append_assoc]
· intro x hx
exact Or.inl (hintZeros x hx)
· refine ⟨b, intRest ++ 46#u8 :: (fraction ++ suffix),
by simp [hintSigEq], hb, ?_⟩
have hbdigit := hinteger b (by
rw [hintSplit, hintSigEq]
exact List.mem_append_right intZeros List.mem_cons_self)
intro hpoint
subst b
norm_num at hbdigit
· rw [hintSplit]
simp [List.append_assoc]
· exact ⟨b, intRest ++ fraction, by simp [hintSigEq], hb⟩
· exact count_zeros intZeros hintZeros
obtain ⟨intDigits, intTail, hsval, hintDigits, hintTail⟩ :=
split_digits s.val
have hintTailProp : intTail.length <= Usize.max := by
have hp := s.property
rw [hsval] at hp
simp only [List.length_append] at hp
omega
let intRest : Slice Std.U8 := ⟨intTail, hintTailProp⟩
obtain ⟨intMantissa, scannedIntRest, hscanInt, hscannedIntRest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 intDigits intTail hsval
hintDigits hintTail hlen
have hscannedIntRestEq : scannedIntRest = intRest :=
(Slice.eq_iff _ _).2 (by simpa [intRest] using hscannedIntRest)
subst scannedIntRest
obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
offset_exact s intRest hlen (by
rw [hsval]
simp [intRest])
have hnDigitsEq : nDigits.val = intDigits.length := by
rw [hnDigitsVal, hsval]
simp [intRest]
have hpartial : exists len,
num.imp.dec2flt.parse.parse_partial_number s = ok (some (d, len)) := by
unfold num.imp.dec2flt.parse.parse_number at hparse
cases hp : num.imp.dec2flt.parse.parse_partial_number s with
| fail err => simp [hp] at hparse
| div => simp [hp] at hparse
| ok result =>
cases result with
| none => simp [hp] at hparse
| some pair =>
rcases pair with ⟨record, len⟩
simp [hp] at hparse
split at hparse
· have hrecord : record = d := by simpa using hparse
subst d
exact ⟨len, rfl⟩
· simp at hparse
obtain ⟨parsedLen, hpartial⟩ := hpartial
cases intTail with
| nil =>
have hsplitInt : core.slice.Slice.split_first intRest = ok none := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst, intRest]
have haddZero : nDigits + 0#isize = ok nDigits := by
have hb := IScalar.hBounds nDigits
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec (x := nDigits) (y := 0#isize) (by
simp [IScalar.min, IScalarTy.numBits,
hbits]
omega) (by
simp [IScalar.max, IScalarTy.numBits,
hbits] at hb ⊢
omega))
rw [hz]
congr 2
apply IScalar.eq_of_val_eq
simpa using hzval
have hfullOffset :
SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from
intRest s = ok nDigits := by
simpa [intRest] using hoffInt
have hcastLen : lift (IScalar.hcast .Usize nDigits) =
ok (Slice.len s) := by
have hbound : 0 <= nDigits.val /\
nDigits.val <= UScalar.max .Usize := by
rw [hnDigitsEq]
constructor
· omega
· have hp := s.property
rw [hsval] at hp
simpa [UScalar.max, Usize.max, Usize.numBits,
hbits] using hp
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize nDigits hbound)
rw [hz]
congr 2
apply UScalar.eq_of_val_eq
rw [hnDigitsEq] at hzval
have hslen : s.val.length = intDigits.length := by simp [hsval]
simpa [Slice.len_val, hslen] using hzval
unfold num.imp.dec2flt.parse.parse_partial_number at hpartial
simp [hne, hscanInt, hoffInt, hsplitInt, haddZero,
hcastLen] at hpartial
by_cases hnzero : nDigits = 0#isize
· simp [hnzero] at hpartial
· simp [hnzero] at hpartial
by_cases hsmall : nDigits.val <= 19
· simp [hsmall] at hpartial
rcases hpartial with ⟨rfl, rfl⟩
constructor
· rfl
· have hfoldLt := fold_upper intDigits 0 hintDigits
norm_num at hfoldLt
have hlen19 : intDigits.length <= 19 := by
omega
have hbound : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [U64.max_eq]
have hp := hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat)) hlen19)
norm_num at hp ⊢
omega
obtain ⟨value, rest, hexact, hrest, hvalue⟩ :=
NumberHelperDigitScanExact s 0#u64 intDigits []
(by simpa using hsval) hintDigits (by
intro b rest h
cases h) hlen hbound
rw [hscanInt] at hexact
simp at hexact
rcases hexact with ⟨rfl, rfl⟩
rw [hvalue]
norm_num
exact hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat)) hlen19)
· have hlarge : 19 < nDigits.val := by omega
have hsubBounds : IScalar.min .Isize <= nDigits.val - 19 /\
nDigits.val - 19 <= IScalar.max .Isize := by
have hb := IScalar.hBounds nDigits
simp [IScalar.min, IScalar.max, IScalarTy.numBits,
hbits] at hb ⊢
omega
obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.sub_spec (x := nDigits) (y := 19#isize)
(by norm_num; omega) (by norm_num; omega))
norm_num at hnMoreVal
simp [hsmall, hnMore] at hpartial
obtain ⟨zeros, nonzeroTail, hzeroSplit, hzeros, hzeroTail⟩ :=
split_zeros intDigits hintDigits
have hcount := count_zeros zeros hzeros
have hsAdjust : s.val = zeros ++ nonzeroTail := by
simpa [hzeroSplit] using hsval
have htailSharp : nonzeroTail = [] \/ exists b rest,
nonzeroTail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
rcases hzeroTail with hnil | ⟨b, rest, htailEq, hb⟩
· exact Or.inl hnil
· right
refine ⟨b, rest, htailEq, hb, ?_⟩
have hbdigit := hintDigits b (by
rw [hzeroSplit, htailEq]
exact List.mem_append_right zeros List.mem_cons_self)
intro heq
subst b
norm_num at hbdigit
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, hnDigitsEq, hsval]
simp only [List.length_append, List.length_nil, Nat.add_zero]
omega
have hadjustLower : IScalar.min .Isize <=
nMore.val - (zeros.count 48#u8 : Int) := by
rw [hnMoreVal, hcount, hnDigitsEq]
have hzerosLen : zeros.length <= intDigits.length := by
rw [hzeroSplit]
simp
simp [IScalar.min, IScalarTy.numBits,
hbits]
omega
obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
adjust_exact s nMore zeros nonzeroTail hsAdjust
(by intro b hb; exact Or.inl (hzeros b hb)) htailSharp hlen
hnMoreNonneg hnMoreLe hadjustLower
rw [hadjust] at hpartial
by_cases hpositive : 0 < adjusted.val
· simp [hpositive] at hpartial
cases hmany :
num.imp.dec2flt.parse.parse_many_digits s intRest 0#i64 with
| fail err => simp [hmany] at hpartial
| div => simp [hmany] at hpartial
| ok result =>
rcases result with ⟨manyMantissa, manyExponent⟩
simp [hmany] at hpartial
rcases hpartial with ⟨rfl, rfl⟩
refine ⟨rfl, ?_⟩
change manyMantissa.val < 10 ^ 19
have hb := parse_many_bound s intRest 0#i64 manyExponent
manyMantissa hmany
omega
· simp [hpositive] at hpartial
have htailLen : nonzeroTail.length <= 19 := by
rw [hadjustVal, hnMoreVal, hcount, hnDigitsEq] at hpositive
have hlenEq := congrArg List.length hzeroSplit
simp only [List.length_append] at hlenEq
omega
have htailDigits : forall b, List.Mem b nonzeroTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hintDigits b
rw [hzeroSplit]
exact List.mem_append_right zeros hb
have hzeroFold := zero_fold zeros hzeros
have hfoldLt : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 < 10 ^ 19 := by
rcases hzeroTail with hnil | hcons
· subst nonzeroTail
rw [hzeroSplit, List.append_nil, hzeroFold]
norm_num
· rw [hzeroSplit, List.foldl_append, hzeroFold]
have htailLt := fold_upper nonzeroTail 0 htailDigits
norm_num at htailLt
exact htailLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat))
htailLen)
have hfoldBound : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [U64.max_eq]
omega
obtain ⟨value, rest, hexact, hrest, hvalue⟩ :=
NumberHelperDigitScanExact s 0#u64 intDigits []
(by simpa using hsval) hintDigits (by
intro b rest h
cases h) hlen hfoldBound
rw [hscanInt] at hexact
simp at hexact
rcases hexact with ⟨rfl, rfl⟩
rcases hpartial with ⟨rfl, rfl⟩
refine ⟨rfl, ?_⟩
norm_num at hvalue ⊢
rw [hvalue]
exact hfoldLt
| cons first tail =>
have htailProp : tail.length <= Usize.max := by
have hp := intRest.property
simp [intRest] at hp ⊢
omega
let afterFirst : Slice Std.U8 := ⟨tail, htailProp⟩
have hsplitInt : core.slice.Slice.split_first intRest =
ok (some (first, afterFirst)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
intRest, afterFirst]
by_cases hpoint : first = 46#u8
· subst first
obtain ⟨fracDigits, fracTail, hfracSplit, hfracDigits, hfracTail⟩ :=
split_digits tail
have hfracTailProp : fracTail.length <= Usize.max := by
have hp := afterFirst.property
simp [afterFirst, hfracSplit] at hp ⊢
omega
let fracRest : Slice Std.U8 := ⟨fracTail, hfracTailProp⟩
have hlenAfter : afterFirst.val.length <= 9223372036854775807 := by
simp [afterFirst]
rw [hsval] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega
obtain ⟨fracMantissa, scannedFracRest, hscanFrac, hscannedFracRest⟩ :=
NumberHelperDigitScanSourceLength afterFirst intMantissa fracDigits
fracTail (by simp [afterFirst, hfracSplit]) hfracDigits hfracTail
hlenAfter
have hscannedFracRestEq : scannedFracRest = fracRest :=
(Slice.eq_iff _ _).2 (by
simpa [fracRest] using hscannedFracRest)
subst scannedFracRest
obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
offset_exact afterFirst fracRest hlenAfter (by
simp [afterFirst, fracRest, hfracSplit])
have hnAfterEq : nAfter.val = fracDigits.length := by
rw [hnAfterVal]
simp [afterFirst, fracRest, hfracSplit]
have hnAfterNotMin : nAfter.val ≠ IScalar.min .Isize := by
rw [hnAfterEq, IScalar.min]
simp [IScalarTy.numBits, hbits]
obtain ⟨negAfter, hnegAfter, hnegAfterVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(HNeg.hNeg.step nAfter hnAfterNotMin)
have hnegCastBounds : IScalar.min .I64 <= negAfter.val /\
negAfter.val <= IScalar.max .I64 := by
rw [hnegAfterVal, hnAfterEq,
IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
constructor <;> omega
obtain ⟨fracExponent, hfracExponent, hfracExponentVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.cast_inBounds_spec .I64 negAfter hnegCastBounds)
have htotalBounds : IScalar.min .Isize <=
nDigits.val + nAfter.val /\
nDigits.val + nAfter.val <= IScalar.max .Isize := by
rw [hnDigitsEq, hnAfterEq]
simp [IScalar.min, IScalar.max, IScalarTy.numBits,
hbits]
rw [hsval, hfracSplit] at hlen
simp only [List.length_append, List.length_cons] at hlen
constructor <;> omega
obtain ⟨totalDigits, htotal, htotalVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec htotalBounds.1 htotalBounds.2)
have hsigDigits : forall b,
List.Mem b (intDigits ++ fracDigits) ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
rcases List.mem_append.mp hb with hb | hb
· exact hintDigits b hb
· exact hfracDigits b hb
have hexactScans :
(intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max ->
fracMantissa.val = (intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 := by
intro hfullBound
have hprefixLe := fold_ge_start fracDigits
(intDigits.foldl (fun x b => 10 * x + (b.val - 48)) 0)
rw [← List.foldl_append] at hprefixLe
have hintBound : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max :=
hprefixLe.trans hfullBound
obtain ⟨intValue, intScanRest, hexactInt, hexactIntRest,
hintValue⟩ :=
NumberHelperDigitScanExact s 0#u64 intDigits
(46#u8 :: tail) (by simpa using hsval) hintDigits hintTail
hlen hintBound
rw [hscanInt] at hexactInt
simp at hexactInt
rcases hexactInt with ⟨rfl, rfl⟩
have hfracBound : fracDigits.foldl
(fun x b => 10 * x + (b.val - 48)) intMantissa.val <=
U64.max := by
norm_num at hintValue
rw [hintValue, ← List.foldl_append]
exact hfullBound
obtain ⟨fracValue, fracScanRest, hexactFrac, hexactFracRest,
hfracValue⟩ :=
NumberHelperDigitScanExact afterFirst intMantissa fracDigits
fracTail (by simp [afterFirst, hfracSplit]) hfracDigits
hfracTail hlenAfter hfracBound
rw [hscanFrac] at hexactFrac
simp at hexactFrac
rcases hexactFrac with ⟨rfl, rfl⟩
norm_num at hintValue hfracValue ⊢
rw [hfracValue, hintValue]
have hshort : totalDigits.val <= 19 ->
fracMantissa.val <= 9999999999999999999 := by
intro hsmall
have hsigLen : intDigits.length + fracDigits.length <= 19 := by
rw [htotalVal, hnDigitsEq, hnAfterEq] at hsmall
omega
have hfoldLt := fold_upper (intDigits ++ fracDigits) 0 hsigDigits
norm_num at hfoldLt
have hfold19 := hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat)) hsigLen)
have hfoldBound : (intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [U64.max_eq]
norm_num
omega
rw [hexactScans hfoldBound]
norm_num
omega
have hnonpositive : forall (nMore adjusted : Std.Isize),
totalDigits - 19#isize = ok nMore ->
num.imp.dec2flt.parse.adjust_many_digit_count s nMore = ok adjusted ->
Not (totalDigits.val <= 19) ->
Not (0 < adjusted.val) ->
fracMantissa.val <= 9999999999999999999 := by
intro nMore adjusted hsub hadjust hlarge hnonpos
by_cases hallzero : forall b,
List.Mem b (intDigits ++ fracDigits) -> b = 48#u8
· have hfoldZero := zero_fold (intDigits ++ fracDigits) hallzero
have hfoldBound : (intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [hfoldZero]
exact Nat.zero_le _
rw [hexactScans hfoldBound, hfoldZero]
norm_num
· obtain ⟨rawZeros, rawTail, sigZeros, sigTail, hrawSplit,
hrawZeros, hrawTail, hsigSplit, hsigZeros, hsigTail, hcount⟩ :=
split_significand_zeros intDigits fracDigits fracTail
hintDigits hfracDigits hallzero
have hsAdjust : s.val = rawZeros ++ rawTail := by
rw [hsval, hfracSplit]
exact hrawSplit
have hnMoreVal : nMore.val = totalDigits.val - 19 := by
have heq := IScalar.sub_equiv totalDigits 19#isize
rw [hsub] at heq
have hval := heq.2.1
norm_num at hval ⊢
exact hval
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq, hsval,
hfracSplit]
simp only [List.length_append, List.length_cons]
omega
have hadjustLower : IScalar.min .Isize <=
nMore.val - (rawZeros.count 48#u8 : Int) := by
rw [hnMoreVal, hcount, htotalVal, hnDigitsEq, hnAfterEq]
have hzlen : sigZeros.length <=
(intDigits ++ fracDigits).length := by
rw [hsigSplit]
simp
have hsigSource : (intDigits ++ fracDigits).length <=
s.val.length := by
rw [hsval, hfracSplit]
simp only [List.length_append, List.length_cons]
omega
have hzBound : sigZeros.length <= 9223372036854775807 :=
hzlen.trans (hsigSource.trans hlen)
simp [IScalar.min, IScalarTy.numBits,
hbits]
omega
obtain ⟨adjusted2, hadjust2, hadjust2Val⟩ :=
adjust_exact s nMore rawZeros rawTail hsAdjust
hrawZeros (Or.inr hrawTail) hlen hnMoreNonneg hnMoreLe
hadjustLower
rw [hadjust] at hadjust2
simp at hadjust2
subst adjusted2
have hsigTailLen : sigTail.length <= 19 := by
rw [hadjust2Val, hnMoreVal, hcount, htotalVal, hnDigitsEq,
hnAfterEq] at hnonpos
have hlenEq := congrArg List.length hsigSplit
simp only [List.length_append] at hlenEq
omega
have hsigTailDigits : forall b, List.Mem b sigTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hsigDigits b
rw [hsigSplit]
exact List.mem_append_right sigZeros hb
have hzeroFold := zero_fold sigZeros hsigZeros
have htailLt := fold_upper sigTail 0 hsigTailDigits
norm_num at htailLt
have hfoldLt : (intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 < 10 ^ 19 := by
rw [hsigSplit, List.foldl_append, hzeroFold]
exact htailLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat))
hsigTailLen)
have hfoldBound : (intDigits ++ fracDigits).foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
exact (Nat.le_of_lt hfoldLt).trans (by
norm_num [U64.max_eq])
rw [hexactScans hfoldBound]
norm_num at hfoldLt ⊢
omega
unfold num.imp.dec2flt.parse.parse_partial_number at hpartial
simp [hne, hscanInt, hoffInt, hsplitInt, hscanFrac, hoffFrac,
hnegAfter, hfracExponent] at hpartial
simp only [UScalar.ofNatCore] at hpartial
simp [htotal] at hpartial
by_cases hzero : totalDigits = 0#isize
· simp [hzero] at hpartial
· simp [hzero] at hpartial
cases fracTail with
| nil =>
have hsplitFrac : core.slice.Slice.split_first fracRest =
ok none := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
fracRest]
simp [hsplitFrac] at hpartial
obtain ⟨off, hoff, hpartial⟩ := bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ := bind_ok_inv _ _ _ hpartial
exact record_branches totalDigits fracMantissa intRest fracExponent
0#i64 len parsedLen hshort hnonpositive hpartial
| cons marker suffix =>
have hsuffixProp : suffix.length <= Usize.max := by
have hp := fracRest.property
simp [fracRest] at hp ⊢
omega
let afterMarker : Slice Std.U8 := ⟨suffix, hsuffixProp⟩
have hsplitFrac : core.slice.Slice.split_first fracRest =
ok (some (marker, afterMarker)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
fracRest, afterMarker]
simp [hsplitFrac] at hpartial
by_cases hlower : marker = (⟨101#8⟩ : Std.U8)
· subst marker
obtain ⟨sciResult, hsci, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
rcases sciResult with ⟨optExp, sciRest⟩
cases optExp with
| none =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
ModelOptionFromResidual] at hpartial
| some parsedExp =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch] at hpartial
obtain ⟨combined, hsum, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨off, hoff, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
exact record_branches totalDigits fracMantissa intRest combined
parsedExp len parsedLen hshort hnonpositive hpartial
· by_cases hupper : marker = (⟨69#8⟩ : Std.U8)
· subst marker
obtain ⟨sciResult, hsci, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
rcases sciResult with ⟨optExp, sciRest⟩
cases optExp with
| none =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
ModelOptionFromResidual] at hpartial
| some parsedExp =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch] at hpartial
obtain ⟨combined, hsum, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨off, hoff, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
exact record_branches totalDigits fracMantissa intRest combined
parsedExp len parsedLen hshort hnonpositive hpartial
· simp [hlower, hupper] at hpartial
obtain ⟨off, hoff, hpartial⟩ := bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ := bind_ok_inv _ _ _ hpartial
exact record_branches totalDigits fracMantissa intRest
fracExponent 0#i64 len parsedLen hshort hnonpositive hpartial
· have haddZero : nDigits + 0#isize = ok nDigits := by
have hb := IScalar.hBounds nDigits
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec (x := nDigits) (y := 0#isize) (by
simp [IScalar.min, IScalarTy.numBits,
hbits]
omega) (by
simp [IScalar.max, IScalarTy.numBits,
hbits] at hb ⊢
omega))
rw [hz]
congr 2
apply IScalar.eq_of_val_eq
simpa using hzval
have hshort : nDigits.val <= 19 ->
intMantissa.val <= 9999999999999999999 := by
intro hsmall
have hlen19 : intDigits.length <= 19 := by omega
have hfoldLt := fold_upper intDigits 0 hintDigits
norm_num at hfoldLt
have hfold19 : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 < 10 ^ 19 :=
hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat)) hlen19)
have hfoldBound : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [U64.max_eq]
omega
obtain ⟨value, rest, hexact, hrest, hvalue⟩ :=
NumberHelperDigitScanExact s 0#u64 intDigits (first :: tail)
(by simpa using hsval) hintDigits hintTail hlen hfoldBound
rw [hscanInt] at hexact
simp at hexact
rcases hexact with ⟨rfl, rfl⟩
norm_num at hvalue ⊢
rw [hvalue]
omega
have hnonpositive : forall (nMore adjusted : Std.Isize),
nDigits - 19#isize = ok nMore ->
num.imp.dec2flt.parse.adjust_many_digit_count s nMore = ok adjusted ->
Not (nDigits.val <= 19) ->
Not (0 < adjusted.val) ->
intMantissa.val <= 9999999999999999999 := by
intro nMore adjusted hsub hadjust hlarge hnonpos
have hnMoreVal : nMore.val = nDigits.val - 19 := by
have heq := IScalar.sub_equiv nDigits 19#isize
rw [hsub] at heq
have hval := heq.2.1
norm_num at hval ⊢
exact hval
obtain ⟨zeros, nzTail, hzeroSplit, hzeros, hnzTail⟩ :=
split_zeros intDigits hintDigits
have hcount := count_zeros zeros hzeros
let rawTail : List Std.U8 := nzTail ++ first :: tail
have hsAdjust : s.val = zeros ++ rawTail := by
rw [hsval, hzeroSplit]
simp [rawTail, List.append_assoc]
have hrawTail : rawTail = [] \/ exists b rest,
rawTail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
right
rcases hnzTail with hnil | ⟨b, rest, heq, hb⟩
· subst nzTail
refine ⟨first, tail, by simp [rawTail], ?_, hpoint⟩
intro hzero
subst first
have hnot := hintTail 48#u8 tail rfl
norm_num at hnot
· refine ⟨b, rest ++ first :: tail, by simp [rawTail, heq], hb, ?_⟩
have hbdigit := hintDigits b (by
rw [hzeroSplit, heq]
exact List.mem_append_right zeros List.mem_cons_self)
intro heq46
subst b
norm_num at hbdigit
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, hnDigitsEq, hsval]
simp only [List.length_append, List.length_cons]
omega
have hadjustLower : IScalar.min .Isize <=
nMore.val - (zeros.count 48#u8 : Int) := by
rw [hnMoreVal, hcount, hnDigitsEq]
have hzlen : zeros.length <= intDigits.length := by
rw [hzeroSplit]
simp
simp [IScalar.min, IScalarTy.numBits,
hbits]
omega
obtain ⟨adjusted2, hadjust2, hadjust2Val⟩ :=
adjust_exact s nMore zeros rawTail hsAdjust
(by intro b hb; exact Or.inl (hzeros b hb)) hrawTail hlen
hnMoreNonneg hnMoreLe hadjustLower
rw [hadjust] at hadjust2
simp at hadjust2
subst adjusted2
have hnzLen : nzTail.length <= 19 := by
rw [hadjust2Val, hnMoreVal, hcount, hnDigitsEq] at hnonpos
have hlenEq := congrArg List.length hzeroSplit
simp only [List.length_append] at hlenEq
omega
have hnzDigits : forall b, List.Mem b nzTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hintDigits b
rw [hzeroSplit]
exact List.mem_append_right zeros hb
have hzeroFold := zero_fold zeros hzeros
have hfoldLt : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 < 10 ^ 19 := by
rcases hnzTail with hnil | hcons
· subst nzTail
rw [hzeroSplit, List.append_nil, hzeroFold]
norm_num
· rw [hzeroSplit, List.foldl_append, hzeroFold]
have htailLt := fold_upper nzTail 0 hnzDigits
norm_num at htailLt
exact htailLt.trans_le
(Nat.pow_le_pow_right (by norm_num : 0 < (10 : Nat)) hnzLen)
have hfoldBound : intDigits.foldl
(fun x b => 10 * x + (b.val - 48)) 0 <= U64.max := by
rw [U64.max_eq]
omega
obtain ⟨value, rest, hexact, hrest, hvalue⟩ :=
NumberHelperDigitScanExact s 0#u64 intDigits (first :: tail)
(by simpa using hsval) hintDigits hintTail hlen hfoldBound
rw [hscanInt] at hexact
simp at hexact
rcases hexact with ⟨rfl, rfl⟩
norm_num at hvalue ⊢
rw [hvalue]
omega
have hpointVal : first.val ≠ 46 := by
intro hval
apply hpoint
exact UScalar.eq_of_val_eq hval
unfold num.imp.dec2flt.parse.parse_partial_number at hpartial
simp [hne, hscanInt, hoffInt, hsplitInt] at hpartial
split at hpartial
all_goals try { exfalso; apply hpointVal; rfl }
simp [haddZero] at hpartial
by_cases hnzero : nDigits = 0#isize
· simp [hnzero] at hpartial
· simp [hnzero, hsplitInt] at hpartial
by_cases hlower : first = 101#u8
· subst first
obtain ⟨sciResult, hsci, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
rcases sciResult with ⟨optExp, sciRest⟩
cases optExp with
| none =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
ModelOptionFromResidual] at hpartial
| some parsedExp =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch] at hpartial
obtain ⟨combined, hsum, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨off, hoff, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
exact record_branches nDigits intMantissa intRest combined
parsedExp len parsedLen hshort hnonpositive hpartial
· by_cases hupper : first = 69#u8
· simp [hlower] at hpartial
subst first
obtain ⟨sciResult, hsci, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
rcases sciResult with ⟨optExp, sciRest⟩
cases optExp with
| none =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
ModelOptionFromResidual] at hpartial
| some parsedExp =>
simp [core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch] at hpartial
obtain ⟨combined, hsum, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨off, hoff, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
obtain ⟨len, hcast, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
exact record_branches nDigits intMantissa intRest combined
parsedExp len parsedLen hshort hnonpositive hpartial
· simp [hlower, hupper] at hpartial
rw [hoffInt] at hpartial
simp at hpartial
obtain ⟨len, hcast, hpartial⟩ :=
bind_ok_inv _ _ _ hpartial
exact record_branches nDigits intMantissa intRest 0#i64 0#i64
len parsedLen hshort hnonpositive hpartial
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
- Assumptions
- DecimalDigitTrimDecomposition
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceSplitFirst
- NumberHelperDecimalPrefixInterval
All 22 entries
- Assumptions
- DecimalDigitTrimDecomposition
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceSplitFirst
- NumberHelperDecimalPrefixInterval
- NumberHelperDigitScanExact
- NumberHelperDigitScanSourceLength
- NumberHelperTryParse19SafeLength
- NumberHelperAdjustCountExact
- NumberHelperDigitPrefix
- NumberHelperManyDigitBound
- NumberHelperOffsetSourceLength
- ActualDispatchOperations
- SourceValidByteSlice
- U64 Insts CoreOpsBitBitAndU64U64
- U64 Insts CoreOpsBitBitOrU64U64
- num imp dec2flt decimal Decimal
- num imp dec2flt parse parse many digits
- num imp dec2flt parse parse number
- num imp dec2flt parse parse partial number
- num imp dec2flt parse parse scientific
Used by
Inspect related source (198)
- Decimal · dec2flt/decimal.rs:32 Program Rust
- parse_many_digits · dec2flt/parse.rs:104 Program Rust
- parse_number · dec2flt/parse.rs:234 Program Rust
More program dependencies (156)
- parse_partial_number · dec2flt/parse.rs:164 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
- Dec2flt_modelNumImpDec2fltLemireU64 · dec2flt/mod.rs:217 Program Rust
- offset_from · dec2flt/common.rs:34 Program Rust
- read_u64 · dec2flt/common.rs:22 Program Rust
- is_8digits · dec2flt/common.rs:44 Program Rust
- dec2flt_with_trace · dec2flt/mod.rs:355 Program Rust
- MIN_19DIGIT_INT · dec2flt/parse.rs:8 Program Rust
- adjust_many_digit_count · dec2flt/parse.rs:86 Program Rust
- adjust_many_digit_count_loop · dec2flt/parse.rs:89 Program Rust
- body · dec2flt/parse.rs:89 Program Rust
- parse_8digits · dec2flt/parse.rs:18 Program Rust
- try_parse_19digits · dec2flt/parse.rs:61 Program Rust
- try_parse_19digits_loop · dec2flt/parse.rs:64 Program Rust
- body · dec2flt/parse.rs:64 Program Rust
- try_parse_digits · dec2flt/parse.rs:30 Program Rust
- try_parse_digits_loop0 · dec2flt/parse.rs:33 Program Rust
- body · dec2flt/parse.rs:33 Program Rust
- try_parse_digits_loop1 · dec2flt/parse.rs:50 Program Rust
- body · dec2flt/parse.rs:50 Program Rust
- MAX_EXPONENT_DISGUISED_FAST_PATH · dec2flt/mod.rs:220 Program Rust
- MAX_EXPONENT_FAST_PATH · dec2flt/mod.rs:219 Program Rust
- from_u64 · dec2flt/mod.rs:263 Program Rust
- pow10_fast_path · dec2flt/mod.rs:222 Program Rust
- Dec2flt_modelNumImpTraitsFloatExtU64 · traits.rs:339 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:329 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:295 Program Rust
- Lemire · dec2flt/mod.rs:115 Program Rust
- default · dec2flt/mod.rs:128 Program Rust
- default · dec2flt/mod.rs:121 Program Rust
- biased_fp_to_float · dec2flt/mod.rs:282 Program Rust
- BiasedFp · dec2flt/common.rs:56 Program Rust
- eq · dec2flt/common.rs:55 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- try_fast_path · dec2flt/decimal.rs:59 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:22 Program Rust
- compute_float · dec2flt/lemire.rs:26 Program Rust
- MASK · dec2flt/parse.rs:19 Program Rust
- MUL1 · dec2flt/parse.rs:20 Program Rust
- MUL2 · dec2flt/parse.rs:21 Program Rust
- parse_inf_nan · dec2flt/parse.rs:244 Program Rust
- pfe_empty · dec2flt/mod.rs:270 Program Rust
- pfe_invalid · dec2flt/mod.rs:277 Program Rust
- parse_long_mantissa · dec2flt/slow.rs:27 Program Rust
- parse_long_mantissa_loop0 · dec2flt/slow.rs:51 Program Rust
- body · dec2flt/slow.rs:51 Program Rust
- parse_long_mantissa_loop1 · dec2flt/slow.rs:69 Program Rust
- body · dec2flt/slow.rs:69 Program Rust
- parse_long_mantissa_loop2 · dec2flt/slow.rs:94 Program Rust
- body · dec2flt/slow.rs:94 Program Rust
- CastInto · traits.rs:18 Program Rust
- Float · traits.rs:74 Program Rust
- FloatExt · traits.rs:170 Program Rust
- Int · traits.rs:27 Program Rust
- from_u64_bits · traits.rs:341 Program Rust
- integer_decode · traits.rs:348 Program Rust
- Dec2flt_modelNumImpTraitsFloatU64 · traits.rs:309 Program Rust
- zero_pow2 · dec2flt/common.rs:66 Program Rust
- can_use_fast_path · dec2flt/decimal.rs:42 Program Rust
- INT_POW10 · dec2flt/decimal.rs:8 Program Rust
- DECIMAL_POINT_RANGE · dec2flt/decimal_seq.rs:68 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
- set_precision · dec2flt/fpu.rs:99 Program Rust
- compute_product_approx · dec2flt/lemire.rs:134 Program Rust
- power · dec2flt/lemire.rs:121 Program Rust
- MAX_SHIFT · dec2flt/slow.rs:28 Program Rust
- call · dec2flt/slow.rs:33 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
- write_u64 · dec2flt/common.rs:29 Program Rust
- Dec2flt_modelNumImpTraitsInt · traits.rs:51 Program Rust
- default · dec2flt/decimal_seq.rs:34 Program Rust
- MAX_DIGITS · dec2flt/decimal_seq.rs:64 Program Rust
- MAX_DIGITS_WITHOUT_OVERFLOW · dec2flt/decimal_seq.rs:67 Program Rust
- 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
- full_multiplication · dec2flt/lemire.rs:126 Program Rust
- NUM_POWERS · dec2flt/slow.rs:29 Program Rust
- POWERS · dec2flt/slow.rs:30 Program Rust
- closure · dec2flt/slow.rs:33 Program Rust
- LARGEST_POWER_OF_FIVE · dec2flt/table.rs:10 Program Rust
- POWER_OF_FIVE_128 · dec2flt/table.rs:19 Program Rust
- SMALLEST_POWER_OF_FIVE · dec2flt/table.rs:9 Program Rust
- 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
- Dec2flt_modelNumImpTraitsCastIntoI16 · traits.rs:45 Program Rust
- ONE · traits.rs:53 Program Rust
- ZERO · traits.rs:52 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
- cast · traits.rs:46 Program Rust
Standard-library dependencies (39)
- from_residual · core/src/option.rs:2793 Rust library
- branch · core/src/option.rs:2779 Rust library
- split_first · core/src/slice/mod.rs:198 Rust library
- clone · core/src/clone.rs:698 Rust library
- div · core/src/ops/arith.rs:515 Rust library
- mul · core/src/ops/arith.rs:350 Rust library
- neg · core/src/ops/arith.rs:719 Rust library
- 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
- first · core/src/slice/mod.rs:155 Rust library
- as_bytes · core/src/str/mod.rs:498 Rust library
- CoreOpsBitBitAndU64U64 · core/src/ops/bit.rs:174 Rust library
- CoreOpsBitBitOrU64U64 · core/src/ops/bit.rs:278 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
- BitOr · core/src/ops/bit.rs:254 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
- Shl · core/src/ops/bit.rs:461 Rust library
- Shr · core/src/ops/bit.rs:584 Rust library
- CoreMarkerCopy · core/src/marker.rs:57 Rust library
- CoreCloneClone · core/src/clone.rs:696 Rust library
- CoreOpsBitShlU32U64 · core/src/ops/bit.rs:483 Rust library
- CoreOpsBitShrU32U64 · core/src/ops/bit.rs:606 Rust library
Related source and models come from the extraction records and declared dependencies.
Proof assumptions and review
Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.
Transitive assumptions
- Classical.choice
- Dec2Flt.P340_T1_selected_target_numBits
- Quot.sound
- propext
This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.
Helper theorems included
- Binary64Model
- Binary64ModelDefault
- DecimalDigitTrimDecomposition
- F64
- F64 Insts CoreCloneClone
- F64 Insts CoreMarkerCopy
All 154 entries
- Binary64Model
- Binary64ModelDefault
- DecimalDigitTrimDecomposition
- F64
- F64 Insts CoreCloneClone
- F64 Insts CoreMarkerCopy
- F64 Insts CoreOpsArithDivF64F64
- F64 Insts CoreOpsArithMulF64F64
- F64 Insts CoreOpsArithNegF64
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64 MAX EXPONENT DISGUISED FAST PATH
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64 MAX EXPONENT FAST PATH
- F64 Insts Dec2flt modelNumImpDec2fltLemireU64 pow10 fast path
- F64 Insts Dec2flt modelNumImpTraitsFloatExtU64
- F64 Insts Dec2flt modelNumImpTraitsFloatExtU64 from u64 bits
- F64 Insts Dec2flt modelNumImpTraitsFloatExtU64 integer decode
- F64 Insts Dec2flt modelNumImpTraitsFloatU64
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 BITS
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 EXP MASK
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 INFINITY
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 LARGEST POWER OF TEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 MAX EXPONENT ROUND TO EVEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 MIN EXPONENT ROUND TO EVEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 NAN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 NEG INFINITY
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 NEG NAN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 SIG MASK
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 SIG TOTAL BITS
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 SMALLEST POWER OF TEN
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 classify
- F64 Insts Dec2flt modelNumImpTraitsFloatU64 to bits
- ModelF64Classify
- ModelF64Clone
- ModelF64Div
- ModelF64ExponentMask
- ModelF64FromBits
- ModelF64FromU64
- ModelF64Infinity
- ModelF64MantissaDigits
- ModelF64MantissaMask
- ModelF64Mul
- ModelF64Nan
- ModelF64Neg
- ModelF64NegInfinity
- ModelF64ToBits
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceFirst
- ModelSliceSplitFirst
- ModelStrAsBytes
- ModelU64BitAnd
- ModelU64BitOr
- ModelU64Shl
- ModelU64Shr
- ModelU8IsAsciiDigit
- NumberHelperDecimalPrefixInterval
- NumberHelperDigitScanExact
- NumberHelperDigitScanSourceLength
- NumberHelperEightDigitWord
- NumberHelperParseEightDigitsExact
- NumberHelperParseEightDigitsSafe
- NumberHelperReadEightBytes
- NumberHelperTryParse19SafeLength
- NumberHelperRecordBounds
- NumberHelperAdjustCountExact
- NumberHelperDigitPrefix
- NumberHelperManyDigitBound
- NumberHelperOffsetSourceLength
- ActualDispatchOperations
- DispatchOperations
- Preamble
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice write u64
- SourceValidByteSlice
- U64 Insts CoreOpsBitBitAndU64U64
- U64 Insts CoreOpsBitBitOrU64U64
- U64 Insts CoreOpsBitShlU32U64
- U64 Insts CoreOpsBitShrU32U64
- U64 Insts Dec2flt modelNumImpTraitsCastIntoI16
- U64 Insts Dec2flt modelNumImpTraitsCastIntoI16 cast
- U64 Insts Dec2flt modelNumImpTraitsInt
- U64 Insts Dec2flt modelNumImpTraitsInt ONE
- U64 Insts Dec2flt modelNumImpTraitsInt ZERO
- core num FpCategory
- core ops arith Div
- core ops arith Mul
- core ops arith Neg
- core ops bit BitOr
- core ops bit Shl
- core ops bit Shr
- num imp dec2flt Lemire
- num imp dec2flt Lemire MAX MANTISSA FAST PATH default
- num imp dec2flt biased fp to float
- num imp dec2flt common BiasedFp
- num imp dec2flt common BiasedFp zero pow2
- num imp dec2flt common is 8digits
- num imp dec2flt decimal Decimal
- num imp dec2flt decimal Decimal can use fast path
- num imp dec2flt decimal Decimal try fast path
- num imp dec2flt decimal INT POW10
- num imp dec2flt decimal seq DecimalSeq
- num imp dec2flt decimal seq DecimalSeq DECIMAL POINT RANGE
- num imp dec2flt decimal seq DecimalSeq Insts CoreDefaultDefault default
- num imp dec2flt decimal seq DecimalSeq MAX DIGITS
- num imp dec2flt decimal seq DecimalSeq MAX DIGITS WITHOUT OVERFLOW
- num imp dec2flt decimal seq DecimalSeq left shift
- num imp dec2flt decimal seq DecimalSeq right shift
- num imp dec2flt decimal seq DecimalSeq round
- num imp dec2flt decimal seq DecimalSeq trim
- num imp dec2flt decimal seq DecimalSeq try add digit
- num imp dec2flt decimal seq count trailing zeros
- num imp dec2flt decimal seq final decimal point
- num imp dec2flt decimal seq number of digits decimal left shift
- num imp dec2flt decimal seq number of digits decimal left shift TABLE
- num imp dec2flt decimal seq number of digits decimal left shift TABLE POW5
- num imp dec2flt decimal seq parse decimal seq
- num imp dec2flt decimal seq parse digits into seq
- num imp dec2flt fpu fpu precision set precision
- num imp dec2flt lemire compute float
- num imp dec2flt lemire compute product approx
- num imp dec2flt lemire full multiplication
- num imp dec2flt lemire power
- num imp dec2flt parse MIN 19DIGIT INT
- num imp dec2flt parse adjust many digit count
- num imp dec2flt parse parse 8digits
- num imp dec2flt parse parse 8digits MASK
- num imp dec2flt parse parse 8digits MUL1
- num imp dec2flt parse parse 8digits MUL2
- num imp dec2flt parse parse inf nan
- num imp dec2flt parse parse many digits
- num imp dec2flt parse parse number
- num imp dec2flt parse parse partial number
- num imp dec2flt parse parse scientific
- num imp dec2flt parse try parse 19digits
- num imp dec2flt parse try parse digits
- num imp dec2flt slow parse long mantissa
- num imp dec2flt slow parse long mantissa MAX SHIFT
- num imp dec2flt slow parse long mantissa NUM POWERS
- num imp dec2flt slow parse long mantissa POWERS
- num imp dec2flt slow parse long mantissa closure
- num imp dec2flt slow parse long mantissa closure Insts CoreOpsFunctionFnTupleUsizeUsize call
- num imp dec2flt table LARGEST POWER OF FIVE
- num imp dec2flt table POWER OF FIVE 128
- num imp dec2flt table SMALLEST POWER OF FIVE
- num imp traits CastInto
- num imp traits Float
- num imp traits FloatExt
- num imp traits Float EXP BIAS default
- num imp traits Float EXP BITS default
- num imp traits Float EXP MIN default
- num imp traits Float EXP SAT default
- num imp traits Float SIG BITS default
- num imp traits Int
Technical checking records
Local closure summary
{
"node": "P13_T1_NumberHelperRecordBounds",
"closure_version": "patch_c_v1",
"active_decl_hash": "8a423b0d2fe383c6b8a78883cd43eb117e967ea1d8ad516f312464ee6598fb0c",
"active_statement_hash": "827d50dd04d3a61f3b17d397d59c4fa41a56ce9cdabdb989801cc752c9b154ce",
"kernel_axioms": [
"Classical.choice",
"Dec2Flt.P340_T1_selected_target_numBits",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-181",
"boundary_theorems": {},
"strict_theorem_deps": {
"DecimalDigitTrimDecomposition": "74d5424585de54f0",
"ModelSliceSplitFirst": "f617ee05dd2925a9",
"NumberHelperDecimalPrefixInterval": "5c32858414034b55",
"NumberHelperDigitScanExact": "6bcf20c61d10dea3",
"NumberHelperDigitScanSourceLength": "8892b939bba0ecf9",
"P364_T1_NumberHelperAdjustCountExact": "8999fa99d4681219",
"P364_T1_NumberHelperDigitPrefix": "3426b4efc0d98c81",
"P364_T1_NumberHelperManyDigitBound": "07a8916e7242c7bb",
"P364_T1_NumberHelperOffsetSourceLength": "de0168dfeba3b802",
"num_imp_dec2flt_parse_parse_partial_number": "854af4cc12136a58"
},
"strict_definition_deps": {
"ModelOptionBranch": "2b227898dbe15e59",
"ModelOptionFromResidual": "6d48ecfbc617744f",
"P9_T1_ActualDispatchOperations": "d8bf51ebbbf153ac",
"P9_T1_DispatchOperations": "9b177bb1b830a655",
"Preamble": "4adf4172ae751d7d",
"SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830",
"SourceValidByteSlice": "3dc42716a6378d26",
"num_imp_dec2flt_decimal_Decimal": "b702e549017701b8",
"num_imp_dec2flt_parse_adjust_many_digit_count": "4e59e3776b6cfdaa",
"num_imp_dec2flt_parse_parse_many_digits": "50c9ef13b3ed7fe8",
"num_imp_dec2flt_parse_parse_number": "b8693ec58f01c43c",
"num_imp_dec2flt_parse_parse_partial_number": "94ed7b2ff71604ef",
"num_imp_dec2flt_parse_parse_scientific": "447f722d5841d2c5",
"num_imp_dec2flt_parse_try_parse_digits": "238b4a73cd46fc56"
}
}Prose assessment
{
"label": "Lean proof closed; predictive prose review no longer required",
"assessment_status": null,
"fingerprint_relation": "unknown",
"assessment_fingerprint": null,
"current_fingerprint": "sound-v2:b904ecdacab60dc1eaf5482f8a2cb5bcccb302c4120ef3426cc2482b0ac2b12c",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"substantiveness_status": "Pass"
}