Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Theorem
many_digits is false then d.\mathit{mantissa}\,10^{d.\mathit{exponent}} equals the literal's accumulated-exponent value; if it is true, that value lies in the half-open interval from d.\mathit{mantissa}\,10^{d.\mathit{exponent}} to (d.\mathit{mantissa}+1)10^{d.\mathit{exponent}}.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.DecimalGoalVocabularyDefault
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.ModelSliceSplitFirst
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.ModelU8IsAsciiDigit
import Tablet.NumberHelperAdjustManyExact
import Tablet.NumberHelperDecimalPrefixInterval
import Tablet.NumberHelperDigitScanExact
import Tablet.NumberHelperDigitScanSourceLength
import Tablet.NumberHelperFractionalManyExact
import Tablet.NumberHelperIntegralManyExact
import Tablet.NumberHelperOffsetSourceLength
import Tablet.NumberHelperParseEightDigitsExact
import Tablet.NumberHelperScientificExact
import Tablet.NumberHelperSplitExponentSuffix
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.SourceValidByteSlice
import Tablet.U64_Insts_CoreOpsBitBitAndU64U64
import Tablet.U64_Insts_CoreOpsBitBitOrU64U64
import Tablet.num_imp_dec2flt_common_is_8digits
import Tablet.num_imp_dec2flt_decimal_Decimal
import Tablet.num_imp_dec2flt_parse_MIN_19DIGIT_INT
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
import Tablet.num_imp_dec2flt_parse_parse_8digits
import Tablet.num_imp_dec2flt_parse_parse_8digits_MASK
import Tablet.num_imp_dec2flt_parse_parse_8digits_MUL1
import Tablet.num_imp_dec2flt_parse_parse_8digits_MUL2
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.num_imp_dec2flt_parse_try_parse_19digits
import Tablet.num_imp_dec2flt_parse_try_parse_digits
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 1000000
set_option maxRecDepth 10000
namespace dec2flt_model
-- [TABLET NODE: NumberHelperAccumulatedValue]
theorem NumberHelperAccumulatedValue :
∀ (s : Slice Std.U8) (x : DecimalLexeme) d, SourceValidByteSlice s -> s.val ≠ [] -> x.leadingSign = none ->
DecimalGoalVocabularyDefault.validNumeric x -> DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x ->
num.imp.dec2flt.parse.parse_number s = ok (some d) ->
(d.many_digits = false ∧ DecimalGoalVocabularyDefault.decimalMagnitude d = DecimalGoalVocabularyDefault.accumulatedMagnitude x) ∨
(d.many_digits = true ∧ DecimalGoalVocabularyDefault.decimalMagnitude d <= DecimalGoalVocabularyDefault.accumulatedMagnitude x ∧
DecimalGoalVocabularyDefault.accumulatedMagnitude x <
((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := 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
none, the rendering premise says that the byte values of s are
exactly
e or E, \sigma is empty, [43], or [45], and H is
the nonempty exponent-digit list. Validity says that every digit value is in
\{0,\ldots,9\} and that at least one digit occurs in I F.0x4646464646464646, wrapping subtraction by
0x3030303030303030, disjunction, and the high-bit mask
0x8080808080808080. The conjunction and disjunction have their
exact bounded-word meanings by
U64 Insts CoreOpsBitBitAndU64U64,
U64 Insts CoreOpsBitBitOrU64U64,
ModelU64BitAnd, and ModelU64BitOr. To check the test
bytewise, let r_j be the borrow entering byte j of the subtraction and
q_j the carry entering byte j of the addition. Both start at zero. If
r_j=0 and b_j<48, the subtraction byte is in [208,255], contradicting
the accepted zero high bit. Induction from the low byte therefore gives
b_j\ge48 and r_{j+1}=0; the same high-bit condition first gives
b_j\le175. If now q_j=0 and b_j\ge58, the addition byte lies in
[128,245], another contradiction. Hence b_j\le57 and
q_{j+1}=0. Conversely bytes in [48,57] create neither carries nor
borrows and make every masked high bit zero. Thus the test accepts exactly
eight ASCII digits b_j=48+r_j' with 0\le r_j'\le9.0x3030303030303030 has no borrow and gives
v'=\sum_j r_j'2^{8j}\le\texttt{0x0909090909090909}<2^{60}.
Thus 10v'<2^{64} and
u32 and widening to u64 are exact.
This proves the exact eight-digit decoding, with every checked operation in
that path discharged.count < len; and the final suffix begins at a count
no greater than the slice length. Since each loop removes or counts a
positive number of bytes when continuing, these inductions also cover loop
termination.Usize and Isize at 64 bits.
Hence both suffix lengths cast to Isize, their nonnegative
differences are in range, the fractional difference can be negated and cast
to i64, and the checked sum forming n_digits1 succeeds
with exact value D\le|s|. Before a scientific suffix is added, the
exponent variable is therefore exactly -F_{\!\ell}.some E and the suffix following all of H.some E to
Continue E; ModelOptionFromResidual confirms that only
the excluded none case could take the residual route. The checked
addition to the pre-scientific exponent, on the hypothesized normally
returned record path, is therefore the ordinary signed sum
E-F_{\!\ell}. In the absent-exponent case the remaining slice is already
empty and E=0. Equation (1) excludes every other suffix byte. All final
offsets are differences of suffix lengths bounded by |s| and cast exactly
by the same 64-bit argument. Consequently the returned length is |s|.Isize. Thus every index increment, cast, and checked subtraction
succeeds.offset_from(int_end,start1) is the exact number
i64 are exact. Finally, normal return of the hypothesized record
implies that the checked addition of E succeeds. Since checked signed
addition agrees with integer addition when it succeeds, (11) and (12) both
give
e, and upper-case E, each followed by the D\le19,
D>19,A>0, or D>19,A\le0 decision. Unfolding
num imp dec2flt decimal Decimal identifies the displayed literal's
mantissa, exponent, and many-digits entries with the corresponding projections
used in the theorem. Unfolding
num imp dec2flt parse parse number, an
ok (some d) result can only bind such a
some (d,\ell) and pass the final test \ell=|s|; it does not
alter the record. The execution just analyzed does pass that test, and any
failed checked operation would instead have propagated a failure, so no
unaccounted failing path can produce the assumed result.decimalMagnitude and using
d.\mathit{mantissa}.\mathit{val}=m is exactly the required half-open
interval. Together with the two false branches, this proves the stated
disjunction.Lean proof
intro s x d hsource hne hsign hvalid hbytes hparse
rcases x with ⟨sign, ints, frac, expo⟩
simp only at hsign
subst sign
simp [DecimalGoalVocabularyDefault] at hvalid hbytes ⊢
rcases hvalid with ⟨hints, hfrac, hsome, hexpo⟩
have hlen : s.val.length <= 9223372036854775807 := by
simpa [SourceValidByteSlice] using hsource
have byte_digits : forall (bs : List Std.U8) (ds : List Nat),
List.map (fun b : Std.U8 => b.val) bs =
List.map (fun d : Nat => 48 + d) ds ->
(forall d, List.Mem d ds -> d < 10) ->
forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57 := by
intro bs ds hmap hds b hb
have hbmap : b.val ∈ List.map (fun b : Std.U8 => b.val) bs :=
List.mem_map_of_mem hb
rw [hmap] at hbmap
obtain ⟨digit, hdigit, hdigitVal⟩ := List.mem_map.mp hbmap
have := hds digit hdigit
omega
let digitStep : Nat -> Std.U8 -> Nat :=
fun a b => 10 * a + (b.val - 48)
let natStep : Nat -> Nat -> Nat := fun a digit => 10 * a + digit
have unrender_digits : forall (bs : List Std.U8) (ds : List Nat),
List.map (fun b : Std.U8 => b.val) bs =
List.map (fun digit : Nat => 48 + digit) ds ->
(forall digit, List.Mem digit ds -> digit < 10) ->
List.map (fun b : Std.U8 => b.val - 48) bs = ds := by
intro bs ds hmap hds
calc
List.map (fun b : Std.U8 => b.val - 48) bs =
List.map (fun n : Nat => n - 48)
(List.map (fun b : Std.U8 => b.val) bs) := by
simp [List.map_map]
_ = List.map (fun n : Nat => n - 48)
(List.map (fun digit : Nat => 48 + digit) ds) := by rw [hmap]
_ = ds := by
have cancel : forall xs : List Nat,
List.map (fun n : Nat => n - 48)
(List.map (fun digit : Nat => 48 + digit) xs) = xs := by
intro xs
induction xs with
| nil => rfl
| cons digit xs ih =>
simp only [List.map_cons, Nat.add_sub_cancel_left]
exact congrArg (List.cons digit) ih
exact cancel ds
have u8_list_eq_of_val_map : forall xs ys : List Std.U8,
xs.map (fun b : Std.U8 => b.val) =
ys.map (fun b : Std.U8 => b.val) -> xs = ys := by
intro xs
induction xs with
| nil =>
intro ys h
cases ys <;> simp_all
| cons x xs ih =>
intro ys h
cases ys with
| nil => simp at h
| cons y ys =>
simp only [List.map_cons, List.cons.injEq] at h
have hxy : x = y := UScalar.eq_of_val_eq h.1
subst y
rw [ih ys h.2]
have split_val_map : forall (preVals suffix : List Nat)
(bs : List Std.U8),
bs.map (fun b : Std.U8 => b.val) = preVals ++ suffix ->
exists prefixBytes suffixBytes,
bs = prefixBytes ++ suffixBytes /\
prefixBytes.map (fun b : Std.U8 => b.val) = preVals /\
suffixBytes.map (fun b : Std.U8 => b.val) = suffix := by
intro preVals
induction preVals with
| nil =>
intro suffix bs h
exact ⟨[], bs, by simp, rfl, by simpa using h⟩
| cons value preVals ih =>
intro suffix bs h
cases bs with
| nil => simp at h
| cons b bs =>
simp only [List.map_cons, List.cons_append, List.cons.injEq] at h
obtain ⟨prefixBytes, suffixBytes, hsplit, hp, hs⟩ :=
ih suffix bs h.2
exact ⟨b :: prefixBytes, suffixBytes, by simp [hsplit],
by simp [h.1, hp], hs⟩
have fold_map : forall (bs : List Std.U8) (a : Nat),
bs.foldl digitStep a =
(bs.map (fun b : Std.U8 => b.val - 48)).foldl natStep a := by
intro bs a
induction bs generalizing a with
| nil => rfl
| cons b bs ih =>
simp only [List.foldl_cons, List.map_cons]
exact ih _
have guarded_fold_map : forall (bs : List Std.U8) (a : Nat),
bs.foldl (fun a b => if a < 65536 then
10 * a + (b.val - 48) else a) a =
(bs.map (fun b : Std.U8 => b.val - 48)).foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) a := by
intro bs a
induction bs generalizing a with
| nil => rfl
| cons b bs ih =>
simp only [List.foldl_cons, List.map_cons]
exact ih _
have signed_if_eq_match : forall (sign : Option Bool) (n : Int),
(if sign = some true then -n else n) =
match sign with
| some true => -n
| _ => n := by
intro sign n
cases sign with
| none => rfl
| some negative => cases negative <;> rfl
have fold_upper : forall (bs : List Std.U8) (a : Nat),
(forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
bs.foldl digitStep a < (a + 1) * 10 ^ bs.length := by
intro bs
induction bs with
| nil => intro a h; simp
| cons b bs ih =>
intro a h
have hb := h b List.mem_cons_self
have hbs : forall c, List.Mem c bs -> 48 <= c.val /\ c.val <= 57 := by
intro c hc
exact h c (List.mem_cons_of_mem b hc)
simp only [List.foldl_cons, List.length_cons, Nat.pow_succ]
have hrec := ih (digitStep a b) hbs
have hcoeff : digitStep a b + 1 <= 10 * (a + 1) := by
simp only [digitStep]
omega
have hmul := Nat.mul_le_mul_right (10 ^ bs.length) hcoeff
exact hrec.trans_le (by
simpa [Nat.mul_assoc, Nat.mul_comm, Nat.mul_left_comm] using hmul)
have fold_lower : forall (bs : List Std.U8) (a : Nat),
a * 10 ^ bs.length <= bs.foldl digitStep a := by
intro bs
induction bs with
| nil => intro a; simp
| cons b bs ih =>
intro a
simp only [List.foldl_cons, List.length_cons, Nat.pow_succ]
calc
a * (10 ^ bs.length * 10) = (10 * a) * 10 ^ bs.length := by ring
_ <= digitStep a b * 10 ^ bs.length := by
apply Nat.mul_le_mul_right
simp [digitStep]
_ <= bs.foldl digitStep (digitStep a b) := ih _
have fold_ge_start : forall (bs : List Std.U8) (a : Nat),
a <= bs.foldl digitStep a := by
intro bs
induction bs with
| nil => intro a; rfl
| cons b bs ih =>
intro a
apply le_trans (b := digitStep a b)
· simp [digitStep]
omega
· exact ih _
have split_zeros : forall bs : List Std.U8,
(forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
exists zeros tail,
bs = zeros ++ tail /\
(forall b, List.Mem b zeros -> b = 48#u8) /\
(tail = [] \/ exists b rest, tail = b :: rest /\ b != 48#u8) := by
intro bs
induction bs with
| nil =>
intro h
exact ⟨[], [], rfl, (by intro b hb; cases hb), Or.inl rfl⟩
| cons b bs ih =>
intro h
by_cases hb : b = 48#u8
· obtain ⟨zeros, tail, hsplit, hzeros, htail⟩ := ih (by
intro c hc
exact h c (List.mem_cons_of_mem b hc))
refine ⟨b :: zeros, tail, by simp [hsplit], ?_, htail⟩
intro c hc
rcases List.mem_cons.mp hc with rfl | hc
· exact hb
· exact hzeros c hc
· exact ⟨[], b :: bs, rfl, (by intro c hc; cases hc), Or.inr ⟨b, bs, rfl, by
simpa only [bne_iff_ne] using hb⟩⟩
have zero_fold : forall zeros : List Std.U8,
(forall b, List.Mem b zeros -> b = 48#u8) ->
zeros.foldl digitStep 0 = 0 := 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, digitStep, ih hbs]
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
induction zeros with
| nil => intro h; rfl
| cons b bs ih =>
intro h
have hb := h b List.mem_cons_self
have hbs : forall c, List.Mem c bs -> c = 48#u8 := by
intro c hc
exact h c (List.mem_cons_of_mem b hc)
simp [hb, ih hbs]
have split_significand_zeros : forall
(integer fraction tail : 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) ->
(tail = [] \/ exists b rest, tail = b :: rest /\
b ≠ 48#u8 /\ b ≠ 46#u8) ->
exists rawZeros rawTail sigZeros sigTail,
integer ++ 46#u8 :: (fraction ++ tail) = rawZeros ++ rawTail /\
(forall b, List.Mem b rawZeros -> b = 48#u8 \/ b = 46#u8) /\
(rawTail = [] \/ 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) /\
(sigTail = [] \/ exists b rest, sigTail = b :: rest /\
b ≠ 48#u8) /\
rawZeros.count 48#u8 = sigZeros.length := by
intro integer fraction tail hinteger hfraction htail
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
have hfracSigNe : fracSig = [] \/ exists c rest,
fracSig = c :: rest /\ c ≠ 48#u8 := by
rcases hfracSig with hnil | ⟨c, rest, heq, hc⟩
· exact Or.inl hnil
· exact Or.inr ⟨c, rest, heq,
by simpa only [bne_iff_ne] using hc⟩
refine ⟨intZeros ++ 46#u8 :: fracZeros, fracSig ++ tail,
intZeros ++ fracZeros, fracSig, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
· rw [hintSplit, hintNil, hfracSplit]
simp [List.append_assoc]
· intro c hc
rcases List.mem_append.mp hc with hc | hc
· exact Or.inl (hintZeros c hc)
· rcases List.mem_cons.mp hc with rfl | hc
· exact Or.inr rfl
· exact Or.inl (hfracZeros c hc)
· rcases hfracSigNe with hnil | ⟨c, rest, hfracSigEq, hc⟩
· rw [hnil]
simpa using htail
· right
refine ⟨c, rest ++ tail, by simp [hfracSigEq], ?_, ?_⟩
· exact 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 c hc
rcases List.mem_append.mp hc with hc | hc
· exact hintZeros c hc
· exact hfracZeros c hc
· exact hfracSigNe
· rw [List.count_append, List.count_cons, count_zeros intZeros hintZeros,
count_zeros fracZeros hfracZeros]
norm_num
· refine ⟨intZeros, intSig ++ 46#u8 :: (fraction ++ tail),
intZeros, intSig ++ fraction, ?_, ?_, ?_, ?_, hintZeros, ?_, ?_⟩
· rw [hintSplit]
simp [List.append_assoc]
· intro c hc
exact Or.inl (hintZeros c hc)
· right
refine ⟨b, intRest ++ 46#u8 :: (fraction ++ tail),
by simp [hintSigEq], ?_, ?_⟩
· simpa only [bne_iff_ne] using 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 Or.inr ⟨b, intRest ++ fraction, by simp [hintSigEq],
by simpa only [bne_iff_ne] using hb⟩
· exact count_zeros intZeros hintZeros
have finish_value : forall (record : num.imp.dec2flt.decimal.Decimal)
(bytes : List Std.U8) (digits : List Nat) (e : Int),
bytes.map (fun b : Std.U8 => b.val - 48) = digits ->
(forall digit, List.Mem digit digits -> digit < 10) ->
((record.many_digits = false /\
record.mantissa.val = bytes.foldl digitStep 0 /\
record.exponent.val = e) \/
(record.many_digits = true /\ exists consumed remaining,
bytes = consumed ++ remaining /\
record.mantissa.val = consumed.foldl digitStep 0 /\
record.exponent.val = e + remaining.length)) ->
(record.many_digits = false /\
DecimalGoalVocabularyDefault.decimalMagnitude record =
((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e) \/
(record.many_digits = true /\
DecimalGoalVocabularyDefault.decimalMagnitude record <=
((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e /\
((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e <
((record.mantissa.val + 1 : Nat) : Real) *
(10 : Real) ^ record.exponent.val) := by
intro record bytes digits e hmap hdigits hrepresentation
rcases hrepresentation with ⟨hmany, hmantissa, hexponent⟩ |
⟨hmany, consumed, remaining, hpartition, hmantissa, hexponent⟩
· left
refine ⟨hmany, ?_⟩
simp only [DecimalGoalVocabularyDefault]
rw [hmantissa, hexponent, fold_map, hmap]
· right
let headDigits := consumed.map (fun b : Std.U8 => b.val - 48)
let suffixDigits := remaining.map (fun b : Std.U8 => b.val - 48)
have hsuffixDigits : forall digit, List.Mem digit suffixDigits ->
digit < 10 := by
intro digit hdigit
apply hdigits digit
rw [← hmap, hpartition, List.map_append]
exact List.mem_append_right headDigits hdigit
have hrenderPartition : headDigits ++ suffixDigits = digits := by
rw [← List.map_append, ← hpartition]
exact hmap
obtain ⟨hintervalLower, hintervalUpper⟩ :=
NumberHelperDecimalPrefixInterval headDigits suffixDigits
hsuffixDigits e
rw [hrenderPartition] at hintervalLower hintervalUpper
have hconsumedFold := fold_map consumed 0
dsimp [headDigits, suffixDigits] at hintervalLower hintervalUpper
rw [← hconsumedFold] at hintervalLower hintervalUpper
refine ⟨hmany, ?_, ?_⟩
· simpa [DecimalGoalVocabularyDefault, natStep, hmantissa, hexponent,
hrenderPartition] using hintervalLower
· simpa [DecimalGoalVocabularyDefault, natStep, hmantissa, hexponent,
hrenderPartition] using hintervalUpper
cases frac with
| none =>
simp at hfrac hsome
cases expo with
| none =>
simp at hbytes hexpo
have hsdigits := byte_digits s.val ints hbytes hints
obtain ⟨mantissa, rest, hscan, hrest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 s.val [] (by simp)
hsdigits (by simp) hlen
let empty : Slice Std.U8 := ⟨[], by simp⟩
have hrestEq : rest = empty := (Slice.eq_iff _ _).2 (by
simpa [empty] using hrest)
obtain ⟨nDigits, hoff, hnDigitsVal⟩ :=
NumberHelperOffsetSourceLength s rest hlen (by simp [hrest])
have hnDigitsEq : nDigits.val = s.val.length := by
simpa [hrest] using hnDigitsVal
have hsplit : core.slice.Slice.split_first rest = ok none := by
rw [hrestEq]
simp [core.slice.Slice.split_first, ModelSliceSplitFirst, empty]
have hnotempty : Not (s.val = []) := by simpa using hne
have hsLenEq : s.val.length = ints.length := by
have := congrArg List.length hbytes
simpa using this
have hnpos : 0 < nDigits.val := by
rw [hnDigitsEq, hsLenEq]
exact_mod_cast List.length_pos_of_ne_nil hsome
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,
Dec2Flt.configured_x86_64_numBits]
omega) (by
simp [IScalar.max, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits] at hb ⊢
omega))
rw [hz]
congr 2
apply IScalar.eq_of_val_eq
simpa using hzval
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]
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
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
simpa [Slice.len_val] using hzval
have hdigitMap : s.val.map (fun b : Std.U8 => b.val - 48) = ints :=
unrender_digits s.val ints hbytes hints
have hfoldEq : s.val.foldl digitStep 0 = ints.foldl natStep 0 := by
rw [fold_map, hdigitMap]
simp [num.imp.dec2flt.parse.parse_number,
num.imp.dec2flt.parse.parse_partial_number, hscan, hoff, hsplit,
hnotempty, haddzero, hnpos.ne', hcastlen] at hparse
by_cases hsmall : nDigits.val <= 19
· simp [hsmall] at hparse
subst d
left
refine ⟨rfl, ?_⟩
have hfoldLt : s.val.foldl digitStep 0 < 10 ^ s.val.length := by
simpa using fold_upper s.val 0 hsdigits
have hfoldBound : s.val.foldl digitStep 0 <= U64.max := by
have hlen19 : s.val.length <= 19 := by omega
have hpow : 10 ^ s.val.length <= 10 ^ 19 := by
exact Nat.pow_le_pow_right (by norm_num) hlen19
have : s.val.foldl digitStep 0 < 10 ^ 19 := hfoldLt.trans_le hpow
rw [U64.max_eq]
norm_num
omega
obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 s.val []
(by simp) hsdigits (by simp) hlen (by simpa [digitStep] using hfoldBound)
have hmantissa : mantissa.val = s.val.foldl digitStep 0 := by
rw [hscan] at hexactScan
simp at hexactScan
rcases hexactScan with ⟨rfl, rfl⟩
simpa [digitStep] using hexactValue
simp only [num.imp.dec2flt.decimal.Decimal.many_digits,
num.imp.dec2flt.decimal.Decimal.mantissa,
num.imp.dec2flt.decimal.Decimal.exponent]
norm_num
rw [hmantissa, hfoldEq]
· have hlarge : 19 < nDigits.val := by omega
simp [hsmall] at hparse
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,
Dec2Flt.configured_x86_64_numBits] 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
rw [hnMore] at hparse
simp at hparse
obtain ⟨zeros, tail, hsZeros, hzeros, htail⟩ :=
split_zeros s.val hsdigits
have hcount : zeros.count 48#u8 = zeros.length :=
count_zeros zeros hzeros
have htailSharp : tail = [] \/ exists b rest,
tail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
rcases htail with hnil | ⟨b, restTail, htailEq, hb⟩
· exact Or.inl hnil
· right
refine ⟨b, restTail, htailEq, ?_, ?_⟩
· simpa only [bne_iff_ne] using hb
· have hbdigit := hsdigits b (by
rw [hsZeros]
exact List.mem_append_right zeros (by simp [htailEq]))
intro h46
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]
omega
have hadjustLower : IScalar.min .Isize <=
nMore.val - (zeros.count 48#u8 : Int) := by
rw [hnMoreVal, hcount]
have hzerosLen : zeros.length <= s.val.length := by
rw [hsZeros]
simp
simp [IScalar.min, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
NumberHelperAdjustManyExact s nMore zeros tail hsZeros (by
intro b hb
exact Or.inl (hzeros b hb)) htailSharp hlen hnMoreNonneg
hnMoreLe hadjustLower
rw [hadjust] at hparse
by_cases hpositive : 0 < adjusted.val
· simp [hpositive] at hparse
cases hmany : num.imp.dec2flt.parse.parse_many_digits s rest 0#i64 with
| fail err => simp [hmany] at hparse
| div => simp [hmany] at hparse
| ok result =>
rcases result with ⟨manyMantissa, manyExponent⟩
simp [hmany] at hparse
have htailLen : 19 < tail.length := by
rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
rw [hsZeros] at hpositive
simp only [List.length_append] at hpositive
omega
have htailCons : exists first tailRest,
tail = first :: tailRest /\
first ≠ 48#u8 /\ first ≠ 46#u8 := by
rcases htailSharp with hnil | hcons
· rw [hnil] at htailLen
simp at htailLen
· exact hcons
rcases htailCons with
⟨first, tailRest, htailEq, hfirstNe, hfirstPoint⟩
have hfirstDigit := hsdigits first (by
rw [hsZeros, htailEq]
exact List.mem_append_right zeros List.mem_cons_self)
have hthreshold : 1000000000000000000 <=
s.val.foldl (fun a b => 10 * a + (b.val - 48)) 0 := by
have hzero := zero_fold zeros hzeros
have hlower := fold_lower tailRest (first.val - 48)
rw [hsZeros, List.foldl_append, hzero, htailEq,
List.foldl_cons]
change 1000000000000000000 <=
tailRest.foldl digitStep (digitStep 0 first)
have hfirstPos : 1 <= first.val - 48 := by
have hneVal : first.val ≠ 48 := by
intro h
apply hfirstNe
apply UScalar.eq_of_val_eq
simpa using h
omega
have hpowLower : 1000000000000000000 <=
10 ^ tailRest.length := by
have hlenRest : 18 <= tailRest.length := by
rw [htailEq] at htailLen
simp only [List.length_cons] at htailLen
omega
have hp := Nat.pow_le_pow_right (by norm_num : 0 < 10) hlenRest
norm_num at hp ⊢
exact hp
have hstep : 10 ^ tailRest.length <=
(first.val - 48) * 10 ^ tailRest.length := by
nlinarith
exact hpowLower.trans (hstep.trans (by
simpa [digitStep] using hlower))
obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
hmanyExponent⟩ := NumberHelperIntegralManyExact s rest
0#i64 manyExponent manyMantissa s.val [] (by simp) hrest
hsdigits (by simp) hlen hthreshold hmany
let headDigits := consumed.map (fun b : Std.U8 => b.val - 48)
let suffixDigits := remaining.map (fun b : Std.U8 => b.val - 48)
have hsuffixDigits : forall digit, List.Mem digit suffixDigits ->
digit < 10 := by
intro digit hdigit
obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hdigit
have hbAll : List.Mem b s.val := by
rw [hpartition]
exact List.mem_append_right consumed hb
have hbDigit := hsdigits b hbAll
omega
have hrenderPartition : headDigits ++ suffixDigits = ints := by
rw [← List.map_append, ← hpartition]
exact hdigitMap
obtain ⟨hintervalLower, hintervalUpper⟩ :=
NumberHelperDecimalPrefixInterval headDigits suffixDigits
hsuffixDigits 0
have hconsumedFold := fold_map consumed 0
dsimp [headDigits, suffixDigits] at hintervalLower hintervalUpper
rw [← hconsumedFold] at hintervalLower hintervalUpper
subst d
right
refine ⟨rfl, ?_, ?_⟩
· simpa [headDigits, suffixDigits, natStep,
hmanyMantissa, hmanyExponent, hrenderPartition] using
hintervalLower
· simpa [headDigits, suffixDigits, natStep,
hmanyMantissa, hmanyExponent, hrenderPartition] using
hintervalUpper
· simp [hpositive] at hparse
have htailLen : tail.length <= 19 := by
rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
rw [hsZeros] at hpositive
simp only [List.length_append] at hpositive
omega
have htailDigits : forall b, List.Mem b tail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hsdigits b
rw [hsZeros]
exact List.mem_append_right zeros hb
have hzero := zero_fold zeros hzeros
have hfoldLtTail : tail.foldl digitStep 0 < 10 ^ tail.length := by
simpa using fold_upper tail 0 htailDigits
have hfoldLt : s.val.foldl digitStep 0 < 10 ^ 19 := by
rw [hsZeros, List.foldl_append, hzero]
exact hfoldLtTail.trans_le
(Nat.pow_le_pow_right (by norm_num) htailLen)
have hfoldBound : s.val.foldl digitStep 0 <= U64.max := by
rw [U64.max_eq]
norm_num
omega
obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 s.val []
(by simp) hsdigits (by simp) hlen
(by simpa [digitStep] using hfoldBound)
have hmantissa : mantissa.val = s.val.foldl digitStep 0 := by
rw [hscan] at hexactScan
simp at hexactScan
rcases hexactScan with ⟨rfl, rfl⟩
simpa [digitStep] using hexactValue
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa, hfoldEq]
| some e =>
let upper : Bool := e.1
let expSign : Option Bool := e.2.1
let expDigits : List Nat := e.2.2
change expDigits ≠ [] /\
(forall digit, List.Mem digit expDigits -> digit < 10) at hexpo
rcases hexpo with ⟨hexpNe, hexpDigits⟩
simp [upper, expSign, expDigits] at hbytes
obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
List.map_eq_append_iff.mp hbytes
obtain ⟨marker, suffixBytes, hafterVal, hmarkerVal, hsuffixMap⟩ :=
List.map_eq_cons_iff.mp hafterMap
have hmarker : marker = if upper then 69#u8 else 101#u8 := by
by_cases hu : upper = true
· rw [if_pos hu]
apply UScalar.eq_of_val_eq
simpa [hu, upper] using hmarkerVal
· rw [if_neg hu]
apply UScalar.eq_of_val_eq
simpa [hu, upper] using hmarkerVal
subst marker
have hsdecomp : s.val = intBytes ++
(if upper then 69#u8 else 101#u8) :: suffixBytes := by
rw [hsval, hafterVal]
have hintDigits := byte_digits intBytes ints hintMap hints
have hintTailProp :
((if upper then 69#u8 else 101#u8) :: suffixBytes).length <=
Usize.max := by
have hp := s.property
rw [hsdecomp] at hp
simp only [List.length_append] at hp ⊢
omega
let intTail : Slice Std.U8 :=
⟨(if upper then 69#u8 else 101#u8) :: suffixBytes,
hintTailProp⟩
have hintTailNotDigit : forall b restBytes,
intTail.val = b :: restBytes ->
Not (48 <= b.val /\ b.val <= 57) := by
intro b restBytes hb
simp [intTail] at hb
rcases hb with ⟨rfl, _⟩
cases upper <;> norm_num
obtain ⟨mantissa, intRest, hscan, hintRest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
(by simpa [intTail] using hsdecomp) hintDigits hintTailNotDigit hlen
have hintRestEq : intRest = intTail :=
(Slice.eq_iff _ _).2 (by simpa using hintRest)
subst intRest
obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
NumberHelperOffsetSourceLength s intTail hlen (by
rw [hsdecomp]
simp [intTail])
have hnDigitsEq : nDigits.val = intBytes.length := by
rw [hnDigitsVal, hsdecomp]
simp [intTail]
have hsuffixProp : suffixBytes.length <= Usize.max := by
have hp := intTail.property
simp [intTail] at hp
omega
let suffix : Slice Std.U8 := ⟨suffixBytes, hsuffixProp⟩
have hsplitMarker : core.slice.Slice.split_first intTail =
ok (some (if upper then 69#u8 else 101#u8, suffix)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
intTail, suffix]
obtain ⟨expBytes, hsuffixDecomp, hexpMap⟩ :=
NumberHelperSplitExponentSuffix expSign suffixBytes expDigits hsuffixMap
have hexpByteDigits := byte_digits expBytes expDigits hexpMap hexpDigits
have hexpDigitMap : expBytes.map (fun b : Std.U8 => b.val - 48) =
expDigits := unrender_digits expBytes expDigits hexpMap hexpDigits
have hexpByteNeProp : expBytes ≠ [] := by
intro hempty
rw [hempty] at hexpDigitMap
simp at hexpDigitMap
exact hexpNe hexpDigitMap
have hexpByteNe : expBytes != [] := by
simpa only [bne_iff_ne] using hexpByteNeProp
have hsignByteMap :
(match expSign with
| none => ([] : List Std.U8)
| some negative => [if negative then 45#u8 else 43#u8]).map
(fun b : Std.U8 => b.val) =
(match expSign with
| none => []
| some negative => [if negative then 45 else 43]) := by
cases expSign with
| none => rfl
| some negative => cases negative <;> rfl
have hsuffixDecomp' : suffix.val =
(match expSign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expBytes := by
change suffixBytes = _
apply u8_list_eq_of_val_map
dsimp [expSign, expDigits] at hsignByteMap ⊢
rw [hsuffixMap, List.map_append, hsignByteMap, hexpMap]
rfl
obtain ⟨parsedExp, scientificRest, hscientific, hscientificRest,
hparsedExp⟩ := NumberHelperScientificExact suffix expSign expBytes
hexpByteNe hexpByteDigits hsuffixDecomp'
have hparsedExpValue : parsedExp.val =
if expSign = some true then
-((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
else ((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int) := by
rw [hparsedExp, guarded_fold_map, hexpDigitMap]
have hparsedExpTarget : parsedExp.val =
(match expSign with
| some true => -((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
| _ => ((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)) := by
rw [hparsedExpValue]
exact signed_if_eq_match expSign _
have hnotempty : Not (s.val = []) := by simpa using hne
have hnpos : 0 < nDigits.val := by
rw [hnDigitsEq]
have hintLen : intBytes.length = ints.length := by
have := congrArg List.length hintMap
simpa using this
rw [hintLen]
exact_mod_cast List.length_pos_of_ne_nil hsome
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,
Dec2Flt.configured_x86_64_numBits]
omega) (by
simp [IScalar.max, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits] at hb ⊢
omega))
rw [hz]
congr 2
apply IScalar.eq_of_val_eq
simpa using hzval
have haddExp : (0#i64 + parsedExp) = ok parsedExp := by
have hb : IScalar.min .I64 <= (0#i64).val + parsedExp.val /\
(0#i64).val + parsedExp.val <= IScalar.max .I64 := by
have hp := IScalar.hBounds parsedExp
rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
norm_num at hp ⊢
omega
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec hb.1 hb.2)
rw [hz]
congr 2
apply IScalar.eq_of_val_eq
norm_num at hzval
exact hzval
obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
NumberHelperOffsetSourceLength s scientificRest hlen (by
simp [hscientificRest])
have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
ok (Slice.len s) := by
have hbound : 0 <= fullOffset.val /\
fullOffset.val <= UScalar.max .Usize := by
rw [hfullOffsetVal, hscientificRest]
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
rw [hz]
congr 2
apply UScalar.eq_of_val_eq
rw [hfullOffsetVal, hscientificRest] at hzval
simpa [Slice.len_val] using hzval
simp [num.imp.dec2flt.parse.parse_number,
num.imp.dec2flt.parse.parse_partial_number, hnotempty, hscan,
hoffInt, haddzero, hnpos.ne', hsplitMarker, hscientific,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch, haddExp, hoffFull, hfullCast] at hparse
cases hupper : upper <;>
simp [hupper, hsplitMarker, hscientific,
UScalar.ofNatCore,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch, ModelOptionFromResidual,
haddExp, hoffFull, hfullCast] at hparse
all_goals
have hdigitMap : intBytes.map (fun b : Std.U8 => b.val - 48) = ints :=
unrender_digits intBytes ints hintMap hints
have hfoldEq : intBytes.foldl digitStep 0 =
ints.foldl natStep 0 := by
rw [fold_map, hdigitMap]
by_cases hsmall : nDigits.val <= 19
· simp [haddzero, hnpos.ne', hsmall] at hparse
have hfoldLt : intBytes.foldl digitStep 0 <
10 ^ intBytes.length := by
simpa using fold_upper intBytes 0 hintDigits
have hfoldBound : intBytes.foldl digitStep 0 <= U64.max := by
have hlen19 : intBytes.length <= 19 := by
omega
have hpow : 10 ^ intBytes.length <= 10 ^ 19 :=
Nat.pow_le_pow_right (by norm_num) hlen19
have hlt : intBytes.foldl digitStep 0 < 10 ^ 19 :=
hfoldLt.trans_le hpow
rw [U64.max_eq]
norm_num
omega
obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
intTail.val (by simpa [intTail] using hsdecomp) hintDigits
hintTailNotDigit hlen (by simpa [digitStep] using hfoldBound)
have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
rw [hscan] at hexactScan
simp at hexactScan
rcases hexactScan with ⟨rfl, rfl⟩
simpa [digitStep] using hexactValue
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa, hfoldEq, hparsedExpTarget]
rfl
· 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,
Dec2Flt.configured_x86_64_numBits] 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 [haddzero, hnpos.ne', hsmall, hnMore] at hparse
obtain ⟨zeros, sigTail, hintZeros, hzeros, hsigTail⟩ :=
split_zeros intBytes hintDigits
let rawTail : List Std.U8 := sigTail ++ intTail.val
have hsAdjust : s.val = zeros ++ rawTail := by
rw [hsdecomp, hintZeros]
simp [rawTail, intTail, List.append_assoc]
have hrawTailSharp : rawTail = [] \/ exists b rest,
rawTail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
rcases hsigTail with hnil | ⟨b, restTail, htailEq, hb⟩
· right
refine ⟨if upper then 69#u8 else 101#u8, suffixBytes,
?_, ?_, ?_⟩
· simp [rawTail, hnil, intTail]
· norm_num [hupper, UScalar.ofNatCore]
· norm_num [hupper, UScalar.ofNatCore]
· right
refine ⟨b, restTail ++ intTail.val, ?_, ?_, ?_⟩
· simp [rawTail, htailEq]
· simpa only [bne_iff_ne] using hb
· have hbdigit := hintDigits b (by
rw [hintZeros, htailEq]
exact List.mem_append_right zeros List.mem_cons_self)
intro hpoint
subst b
norm_num at hbdigit
have hcount : zeros.count 48#u8 = zeros.length :=
count_zeros zeros hzeros
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, hnDigitsEq, hsdecomp]
simp only [List.length_append]
omega
have hadjustLower : IScalar.min .Isize <=
nMore.val - (zeros.count 48#u8 : Int) := by
rw [hnMoreVal, hcount, hnDigitsEq]
have hzerosLen : zeros.length <= intBytes.length := by
rw [hintZeros]
simp
simp [IScalar.min, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
NumberHelperAdjustManyExact s nMore zeros rawTail hsAdjust (by
intro b hb
exact Or.inl (hzeros b hb)) hrawTailSharp hlen hnMoreNonneg
hnMoreLe hadjustLower
rw [hadjust] at hparse
by_cases hpositive : 0 < adjusted.val
· simp [hpositive] at hparse
cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
parsedExp with
| fail err => simp [hmany] at hparse
| div => simp [hmany] at hparse
| ok result =>
rcases result with ⟨manyMantissa, manyExponent⟩
simp [hmany] at hparse
have hsigTailLen : 19 < sigTail.length := by
rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
rw [hintZeros] at hpositive
simp only [List.length_append] at hpositive
omega
have hsigTailCons : exists first tailRest,
sigTail = first :: tailRest /\
first ≠ 48#u8 /\ first ≠ 46#u8 := by
rcases hsigTail with hnil | hcons
· rw [hnil] at hsigTailLen
simp at hsigTailLen
· rcases hcons with ⟨b, restTail, hbEq, hbNe⟩
refine ⟨b, restTail, hbEq, ?_, ?_⟩
· simpa only [bne_iff_ne] using hbNe
· have hbdigit := hintDigits b (by
rw [hintZeros, hbEq]
exact List.mem_append_right zeros List.mem_cons_self)
intro hpoint
subst b
norm_num at hbdigit
rcases hsigTailCons with
⟨first, tailRest, htailEq, hfirstNe, hfirstPoint⟩
have hfirstDigit := hintDigits first (by
rw [hintZeros, htailEq]
exact List.mem_append_right zeros List.mem_cons_self)
have hthreshold : 1000000000000000000 <=
intBytes.foldl digitStep 0 := by
have hzero := zero_fold zeros hzeros
have hlower := fold_lower tailRest (first.val - 48)
rw [hintZeros, List.foldl_append, hzero, htailEq,
List.foldl_cons]
change 1000000000000000000 <=
tailRest.foldl digitStep (digitStep 0 first)
have hfirstPos : 1 <= first.val - 48 := by
have hneVal : first.val ≠ 48 := by
intro h
apply hfirstNe
apply UScalar.eq_of_val_eq
simpa using h
omega
have hpowLower : 1000000000000000000 <=
10 ^ tailRest.length := by
have hlenRest : 18 <= tailRest.length := by
rw [htailEq] at hsigTailLen
simp only [List.length_cons] at hsigTailLen
omega
have hp := Nat.pow_le_pow_right
(by norm_num : 0 < 10) hlenRest
norm_num at hp ⊢
exact hp
have hstep : 10 ^ tailRest.length <=
(first.val - 48) * 10 ^ tailRest.length := by
nlinarith
exact hpowLower.trans (hstep.trans (by
simpa [digitStep] using hlower))
obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
hmanyExponent⟩ := NumberHelperIntegralManyExact s intTail
parsedExp manyExponent manyMantissa intBytes intTail.val
(by simpa [intTail] using hsdecomp) rfl hintDigits
hintTailNotDigit hlen hthreshold hmany
subst d
have hresult := finish_value
(num.imp.dec2flt.decimal.Decimal.mk manyExponent
manyMantissa false true)
intBytes ints parsedExp.val hdigitMap hints
(Or.inr ⟨rfl, consumed, remaining, hpartition,
hmanyMantissa, hmanyExponent⟩)
simpa [DecimalGoalVocabularyDefault, natStep, hparsedExpTarget,
expSign, expDigits] using hresult
· simp [hpositive] at hparse
have hsigTailLen : sigTail.length <= 19 := by
rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
rw [hintZeros] at hpositive
simp only [List.length_append] at hpositive
omega
have hsigTailDigits : forall b, List.Mem b sigTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hintDigits b
rw [hintZeros]
exact List.mem_append_right zeros hb
have hzero := zero_fold zeros hzeros
have hfoldLtTail : sigTail.foldl digitStep 0 <
10 ^ sigTail.length := by
simpa using fold_upper sigTail 0 hsigTailDigits
have hfoldLt : intBytes.foldl digitStep 0 < 10 ^ 19 := by
rw [hintZeros, List.foldl_append, hzero]
exact hfoldLtTail.trans_le
(Nat.pow_le_pow_right (by norm_num) hsigTailLen)
have hfoldBound : intBytes.foldl digitStep 0 <= U64.max := by
rw [U64.max_eq]
norm_num
omega
obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
intTail.val (by simpa [intTail] using hsdecomp) hintDigits
hintTailNotDigit hlen
(by simpa [digitStep] using hfoldBound)
have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
rw [hscan] at hexactScan
simp at hexactScan
rcases hexactScan with ⟨rfl, rfl⟩
simpa [digitStep] using hexactValue
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa, hfoldEq, hparsedExpTarget]
rfl
| some fracs =>
simp at hfrac hsome
cases expo with
| none =>
simp at hbytes hexpo
obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
List.map_eq_append_iff.mp hbytes
obtain ⟨point, fracBytes, hafterVal, hpointVal, hfracMap⟩ :=
List.map_eq_cons_iff.mp hafterMap
have hpoint : point = 46#u8 := by
apply UScalar.eq_of_val_eq
simpa using hpointVal
subst point
have hsdecomp : s.val = intBytes ++ 46#u8 :: fracBytes := by
rw [hsval, hafterVal]
have hintDigits := byte_digits intBytes ints hintMap hints
have hfracDigits := byte_digits fracBytes fracs hfracMap hfrac
have hintTailProp : (46#u8 :: fracBytes).length <= Usize.max := by
have hp := s.property
rw [hsdecomp] at hp
simp only [List.length_append] at hp
omega
let intTail : Slice Std.U8 := ⟨46#u8 :: fracBytes, hintTailProp⟩
have hintTailNotDigit : forall b rest, intTail.val = b :: rest ->
Not (48 <= b.val /\ b.val <= 57) := by
intro b rest hb
simp [intTail] at hb
rcases hb with ⟨rfl, _⟩
norm_num
obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
(by simpa [intTail] using hsdecomp) hintDigits
hintTailNotDigit hlen
have hintRestEq : intRest = intTail :=
(Slice.eq_iff _ _).2 (by simpa using hintRest)
subst intRest
obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
NumberHelperOffsetSourceLength s intTail hlen (by
rw [hsdecomp]
simp [intTail])
have hnDigitsEq : nDigits.val = intBytes.length := by
rw [hnDigitsVal, hsdecomp]
simp [intTail]
have hfracProp : fracBytes.length <= Usize.max := by
have hp := intTail.property
simp [intTail] at hp ⊢
omega
let fracSlice : Slice Std.U8 := ⟨fracBytes, hfracProp⟩
have hsplitPoint : core.slice.Slice.split_first intTail =
ok (some (46#u8, fracSlice)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
intTail, fracSlice]
obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
NumberHelperDigitScanSourceLength fracSlice mantissa fracBytes []
(by simp [fracSlice]) hfracDigits (by simp) (by
simp [fracSlice]
rw [hsdecomp] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega)
let empty : Slice Std.U8 := ⟨[], by simp⟩
have hfracRestEq : fracRest = empty :=
(Slice.eq_iff _ _).2 (by simpa [empty] using hfracRest)
subst fracRest
obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
NumberHelperOffsetSourceLength fracSlice empty (by
simp [fracSlice]
rw [hsdecomp] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega) (by simp [empty])
have hnAfterEq : nAfter.val = fracBytes.length := by
rw [hnAfterVal]
simp [fracSlice, empty]
have hnAfterNotMin : nAfter.val ≠ IScalar.min .Isize := by
rw [hnAfterEq, IScalar.min]
simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits]
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
have hp := hlen
rw [hsdecomp] at hp
simp only [List.length_append, List.length_cons] at hp
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 hfracExponentEq : fracExponent.val = -(fracBytes.length : Int) := by
rw [hfracExponentVal, hnegAfterVal, hnAfterEq]
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,
Dec2Flt.configured_x86_64_numBits]
rw [hsdecomp] 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 hintLen : intBytes.length = ints.length := by
have hp := congrArg List.length hintMap
simpa using hp
have hfracLen : fracBytes.length = fracs.length := by
have hp := congrArg List.length hfracMap
simpa using hp
have htotalPos : 0 < totalDigits.val := by
rw [htotalVal, hnDigitsEq, hnAfterEq]
rcases hsome with hneInt | hneFrac
· have hp := List.length_pos_of_ne_nil hneInt
omega
· have hp := List.length_pos_of_ne_nil hneFrac
omega
obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
NumberHelperOffsetSourceLength s empty hlen (by simp [empty])
have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
ok (Slice.len s) := by
have hbound : 0 <= fullOffset.val /\
fullOffset.val <= UScalar.max .Usize := by
rw [hfullOffsetVal]
simp [empty, UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
rw [hz]
congr 2
apply UScalar.eq_of_val_eq
rw [hfullOffsetVal] at hzval
simpa [empty, Slice.len_val] using hzval
have hnotempty : Not (s.val = []) := by simpa using hne
have hsplitEmpty : core.slice.Slice.split_first empty = ok none := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst, empty]
unfold num.imp.dec2flt.parse.parse_number at hparse
simp [hnotempty] at hparse
unfold num.imp.dec2flt.parse.parse_partial_number at hparse
simp [hnotempty, hscanInt, hoffInt, hsplitPoint, hscanFrac,
hoffFrac, hnegAfter, hfracExponent] at hparse
norm_num at hparse
simp only [UScalar.ofNat, UScalar.ofNatCore] at hparse
simp [htotal, htotalPos, hsplitEmpty, hoffFull, hfullCast] at hparse
have hdigitInt : intBytes.map (fun b : Std.U8 => b.val - 48) = ints :=
unrender_digits intBytes ints hintMap hints
have hdigitFrac : fracBytes.map (fun b : Std.U8 => b.val - 48) =
fracs := unrender_digits fracBytes fracs hfracMap hfrac
have hsigMap : (intBytes ++ fracBytes).map
(fun b : Std.U8 => b.val - 48) = ints ++ fracs := by
simp [hdigitInt, hdigitFrac]
have hsigDigits : forall b, List.Mem b (intBytes ++ fracBytes) ->
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 hsigFoldEq : (intBytes ++ fracBytes).foldl digitStep 0 =
(ints ++ fracs).foldl natStep 0 := by
rw [fold_map, hsigMap]
have hfracExponentTarget : fracExponent.val = -(fracs.length : Int) := by
rw [hfracExponentEq, hfracLen]
have hexactScans : (intBytes ++ fracBytes).foldl digitStep 0 <=
U64.max ->
mantissa.val = intBytes.foldl digitStep 0 /\
mantissa1.val = (intBytes ++ fracBytes).foldl digitStep 0 := by
as_aux_lemma =>
intro hfullBound
have hprefixLe : intBytes.foldl digitStep 0 <=
(intBytes ++ fracBytes).foldl digitStep 0 := by
rw [List.foldl_append]
exact fold_ge_start fracBytes _
have hintBound : intBytes.foldl digitStep 0 <= U64.max :=
hprefixLe.trans hfullBound
obtain ⟨exactInt, exactIntRest, hexactInt, hexactIntRest,
hexactIntValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
intTail.val (by simpa [intTail] using hsdecomp) hintDigits
hintTailNotDigit hlen (by simpa [digitStep] using hintBound)
have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
rw [hscanInt] at hexactInt
simp at hexactInt
rcases hexactInt with ⟨rfl, rfl⟩
simpa [digitStep] using hexactIntValue
have hfracBound : fracBytes.foldl digitStep mantissa.val <=
U64.max := by
rw [hmantissa, ← List.foldl_append]
exact hfullBound
obtain ⟨exactFrac, exactFracRest, hexactFrac, hexactFracRest,
hexactFracValue⟩ := NumberHelperDigitScanExact fracSlice mantissa
fracBytes [] (by simp [fracSlice]) hfracDigits (by simp) (by
simp [fracSlice]
rw [hsdecomp] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega) (by simpa [digitStep] using hfracBound)
have hmantissa1 : mantissa1.val =
(intBytes ++ fracBytes).foldl digitStep 0 := by
rw [hscanFrac] at hexactFrac
simp at hexactFrac
rcases hexactFrac with ⟨rfl, rfl⟩
rw [List.foldl_append, ← hmantissa]
simpa [digitStep] using hexactFracValue
exact ⟨hmantissa, hmantissa1⟩
by_cases hsmall : totalDigits.val <= 19
· simp [hsmall] at hparse
have hsigLen : (intBytes ++ fracBytes).length <= 19 := by
rw [List.length_append]
omega
have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
10 ^ (intBytes ++ fracBytes).length := by
simpa using fold_upper (intBytes ++ fracBytes) 0 hsigDigits
have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
U64.max := by
have hp := hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num) hsigLen)
have hpowMax : 10 ^ 19 <= U64.max := by
norm_num [U64.max_eq]
exact (Nat.le_of_lt hp).trans hpowMax
obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa1, hsigFoldEq, hfracExponentTarget,
List.foldl_append]
simp [natStep]
· have hlarge : 19 < totalDigits.val := by omega
have hsubBounds : IScalar.min .Isize <= totalDigits.val - 19 /\
totalDigits.val - 19 <= IScalar.max .Isize := by
have hb := IScalar.hBounds totalDigits
simp [IScalar.min, IScalar.max, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits] at hb ⊢
omega
obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.sub_spec (x := totalDigits) (y := 19#isize)
(by norm_num; omega) (by norm_num; omega))
norm_num at hnMoreVal
simp [hsmall, hnMore] at hparse
obtain ⟨rawZeros, rawTail, sigZeros, sigTail, hsRaw,
hrawZeros, hrawTail, hsSig, hsigZeros, hsigTailSharp, hcount⟩ :=
split_significand_zeros intBytes fracBytes [] hintDigits
hfracDigits (Or.inl rfl)
have hsAdjust : s.val = rawZeros ++ rawTail := by
rw [hsdecomp]
simpa using hsRaw
have hsigLenEq : intBytes.length + fracBytes.length =
sigZeros.length + sigTail.length := by
have hp := congrArg List.length hsSig
simpa using hp
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq, hsdecomp]
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 <=
(intBytes ++ fracBytes).length := by
rw [hsSig]
simp
simp [IScalar.min, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
NumberHelperAdjustManyExact s nMore rawZeros rawTail hsAdjust
hrawZeros hrawTail hlen hnMoreNonneg hnMoreLe hadjustLower
rw [hadjust] at hparse
by_cases hpositive : 0 < adjusted.val
· simp [hpositive] at hparse
cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
0#i64 with
| fail err => simp [hmany] at hparse
| div => simp [hmany] at hparse
| ok result =>
rcases result with ⟨manyMantissa, manyExponent⟩
simp [hmany] at hparse
have hsigTailLen : 19 < sigTail.length := by
rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
hnAfterEq] at hpositive
omega
have hsigTailCons : exists first tailRest,
sigTail = first :: tailRest /\ first ≠ 48#u8 := by
rcases hsigTailSharp with hnil | hcons
· rw [hnil] at hsigTailLen
simp at hsigTailLen
· exact hcons
rcases hsigTailCons with ⟨first, tailRest, htailEq, hfirstNe⟩
have hfirstDigit := hsigDigits first (by
rw [hsSig, htailEq]
exact List.mem_append_right sigZeros List.mem_cons_self)
have hthreshold : 1000000000000000000 <=
(intBytes ++ fracBytes).foldl digitStep 0 := by
have hzero := zero_fold sigZeros hsigZeros
have hlower := fold_lower tailRest (first.val - 48)
rw [hsSig, List.foldl_append, hzero, htailEq,
List.foldl_cons]
change 1000000000000000000 <=
tailRest.foldl digitStep (digitStep 0 first)
have hfirstPos : 1 <= first.val - 48 := by
have hneVal : first.val ≠ 48 := by
intro h
apply hfirstNe
apply UScalar.eq_of_val_eq
simpa using h
omega
have hpowLower : 1000000000000000000 <=
10 ^ tailRest.length := by
have hlenRest : 18 <= tailRest.length := by
rw [htailEq] at hsigTailLen
simp only [List.length_cons] at hsigTailLen
omega
have hp := Nat.pow_le_pow_right
(by norm_num : 0 < 10) hlenRest
norm_num at hp ⊢
exact hp
have hstep : 10 ^ tailRest.length <=
(first.val - 48) * 10 ^ tailRest.length := by
simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
hfirstPos
exact hpowLower.trans (hstep.trans (by
simpa [digitStep] using hlower))
obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
hmanyExponent⟩ := NumberHelperFractionalManyExact s intTail
0#i64 manyExponent manyMantissa intBytes fracBytes []
(by simpa [List.append_assoc] using hsdecomp)
(by simp [intTail]) hintDigits hfracDigits (by simp) hlen
hthreshold hmany
have hmanyExponentTarget : manyExponent.val =
-(fracs.length : Int) + remaining.length := by
rw [hmanyExponent, hfracLen]
norm_num
subst d
have hresult := finish_value
(num.imp.dec2flt.decimal.Decimal.mk manyExponent
manyMantissa false true)
(intBytes ++ fracBytes) (ints ++ fracs)
(-(fracs.length : Int)) hsigMap (by
intro digit hdigit
rcases List.mem_append.mp hdigit with hdigit | hdigit
· exact hints digit hdigit
· exact hfrac digit hdigit)
(Or.inr ⟨rfl, consumed, remaining, hpartition,
hmanyMantissa, hmanyExponentTarget⟩)
simpa [DecimalGoalVocabularyDefault, natStep,
List.foldl_append] using hresult
· simp [hpositive] at hparse
have hsigTailLen : sigTail.length <= 19 := by
rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
hnAfterEq] at hpositive
omega
have hsigTailDigits : forall b, List.Mem b sigTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hsigDigits b
rw [hsSig]
exact List.mem_append_right sigZeros hb
have hzero := zero_fold sigZeros hsigZeros
have hfoldLtTail : sigTail.foldl digitStep 0 <
10 ^ sigTail.length := by
simpa using fold_upper sigTail 0 hsigTailDigits
have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
10 ^ 19 := by
rw [hsSig, List.foldl_append, hzero]
exact hfoldLtTail.trans_le
(Nat.pow_le_pow_right (by norm_num) hsigTailLen)
have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
U64.max := by
have hpowMax : 10 ^ 19 <= U64.max := by
norm_num [U64.max_eq]
exact (Nat.le_of_lt hfoldLt).trans hpowMax
obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa1, hsigFoldEq, hfracExponentTarget,
List.foldl_append]
simp [natStep]
| some e =>
let upper : Bool := e.1
let expSign : Option Bool := e.2.1
let expDigits : List Nat := e.2.2
change expDigits ≠ [] /\
(forall digit, List.Mem digit expDigits -> digit < 10) at hexpo
rcases hexpo with ⟨hexpNe, hexpDigits⟩
simp [upper, expSign, expDigits] at hbytes
obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
List.map_eq_append_iff.mp hbytes
obtain ⟨point, afterPoint, hafterVal, hpointVal, hafterPointMap⟩ :=
List.map_eq_cons_iff.mp hafterMap
have hpoint : point = 46#u8 := by
apply UScalar.eq_of_val_eq
simpa using hpointVal
subst point
obtain ⟨fracBytes, afterFrac, hafterPointVal, hfracMap,
hafterFracMap⟩ := List.map_eq_append_iff.mp hafterPointMap
obtain ⟨marker, suffixBytes, hafterFracVal, hmarkerVal, hsuffixMap⟩ :=
List.map_eq_cons_iff.mp hafterFracMap
have hmarker : marker = if upper then 69#u8 else 101#u8 := by
by_cases hu : upper = true
· rw [if_pos hu]
apply UScalar.eq_of_val_eq
simpa [hu, upper] using hmarkerVal
· rw [if_neg hu]
apply UScalar.eq_of_val_eq
simpa [hu, upper] using hmarkerVal
subst marker
have hsdecomp : s.val = intBytes ++ 46#u8 ::
(fracBytes ++ (if upper then 69#u8 else 101#u8) :: suffixBytes) := by
rw [hsval, hafterVal, hafterPointVal, hafterFracVal]
have hintDigits := byte_digits intBytes ints hintMap hints
have hfracDigits := byte_digits fracBytes fracs hfracMap hfrac
have hmarkerTailProp :
((if upper then 69#u8 else 101#u8) :: suffixBytes).length <=
Usize.max := by
have hp := s.property
rw [hsdecomp] at hp
simp only [List.length_append, List.length_cons] at hp ⊢
omega
let markerTail : Slice Std.U8 :=
⟨(if upper then 69#u8 else 101#u8) :: suffixBytes,
hmarkerTailProp⟩
have hmarkerTailNotDigit : forall b rest,
markerTail.val = b :: rest ->
Not (48 <= b.val /\ b.val <= 57) := by
intro b rest hb
simp [markerTail] at hb
rcases hb with ⟨rfl, _⟩
by_cases hu : upper = true
· simp [hu]
· have hu' : upper = false := Bool.eq_false_of_not_eq_true hu
simp [hu']
have hintTailProp :
(46#u8 :: (fracBytes ++ markerTail.val)).length <= Usize.max := by
have hp := s.property
rw [hsdecomp] at hp
simp [markerTail] at hp ⊢
omega
let intTail : Slice Std.U8 :=
⟨46#u8 :: (fracBytes ++ markerTail.val), hintTailProp⟩
have hstart : s.val = intBytes ++ 46#u8 ::
(fracBytes ++ markerTail.val) := by
simpa [markerTail] using hsdecomp
have hintTailNotDigit : forall b rest, intTail.val = b :: rest ->
Not (48 <= b.val /\ b.val <= 57) := by
intro b rest hb
simp [intTail] at hb
rcases hb with ⟨rfl, _⟩
norm_num
obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
hstart hintDigits hintTailNotDigit hlen
have hintRestEq : intRest = intTail :=
(Slice.eq_iff _ _).2 (by simpa using hintRest)
subst intRest
obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
NumberHelperOffsetSourceLength s intTail hlen (by
rw [hstart]
simp [intTail])
have hnDigitsEq : nDigits.val = intBytes.length := by
rw [hnDigitsVal, hstart]
simp [intTail]
have hfracSliceProp : (fracBytes ++ markerTail.val).length <=
Usize.max := by
have hp := intTail.property
simp [intTail] at hp ⊢
omega
let fracSlice : Slice Std.U8 :=
⟨fracBytes ++ markerTail.val, hfracSliceProp⟩
have hsplitPoint : core.slice.Slice.split_first intTail =
ok (some (46#u8, fracSlice)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
intTail, fracSlice]
obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
NumberHelperDigitScanSourceLength fracSlice mantissa fracBytes
markerTail.val (by simp [fracSlice]) hfracDigits
hmarkerTailNotDigit (by
simp [fracSlice]
rw [hstart] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega)
have hfracRestEq : fracRest = markerTail :=
(Slice.eq_iff _ _).2 (by simpa using hfracRest)
subst fracRest
obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
NumberHelperOffsetSourceLength fracSlice markerTail (by
simp [fracSlice]
rw [hstart] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega) (by simp [fracSlice])
have hnAfterEq : nAfter.val = fracBytes.length := by
rw [hnAfterVal]
simp [fracSlice]
have hnAfterNotMin : nAfter.val ≠ IScalar.min .Isize := by
rw [hnAfterEq, IScalar.min]
simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits]
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
have hp := hlen
rw [hstart] at hp
simp only [List.length_append, List.length_cons] at hp
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 hfracExponentEq : fracExponent.val = -(fracBytes.length : Int) := by
rw [hfracExponentVal, hnegAfterVal, hnAfterEq]
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,
Dec2Flt.configured_x86_64_numBits]
rw [hstart] 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 hintLen : intBytes.length = ints.length := by
have hp := congrArg List.length hintMap
simpa using hp
have hfracLen : fracBytes.length = fracs.length := by
have hp := congrArg List.length hfracMap
simpa using hp
have htotalPos : 0 < totalDigits.val := by
rw [htotalVal, hnDigitsEq, hnAfterEq]
rcases hsome with hneInt | hneFrac
· have hp := List.length_pos_of_ne_nil hneInt
omega
· have hp := List.length_pos_of_ne_nil hneFrac
omega
have hsuffixProp : suffixBytes.length <= Usize.max := by
have hp := markerTail.property
simp [markerTail] at hp
omega
let suffix : Slice Std.U8 := ⟨suffixBytes, hsuffixProp⟩
have hsplitMarker : core.slice.Slice.split_first markerTail =
ok (some (if upper then 69#u8 else 101#u8, suffix)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
markerTail, suffix]
obtain ⟨expBytes, hsuffixDecomp, hexpMap⟩ :=
NumberHelperSplitExponentSuffix expSign suffixBytes expDigits hsuffixMap
have hexpByteDigits := byte_digits expBytes expDigits hexpMap hexpDigits
have hexpDigitMap : expBytes.map (fun b : Std.U8 => b.val - 48) =
expDigits := unrender_digits expBytes expDigits hexpMap hexpDigits
have hexpByteNeProp : expBytes ≠ [] := by
intro hempty
rw [hempty] at hexpDigitMap
simp at hexpDigitMap
exact hexpNe hexpDigitMap
have hexpByteNe : expBytes != [] := by
simpa only [bne_iff_ne] using hexpByteNeProp
have hsignByteMap :
(match expSign with
| none => ([] : List Std.U8)
| some negative => [if negative then 45#u8 else 43#u8]).map
(fun b : Std.U8 => b.val) =
(match expSign with
| none => []
| some negative => [if negative then 45 else 43]) := by
cases expSign with
| none => rfl
| some negative => cases negative <;> rfl
have hsuffixDecomp' : suffix.val =
(match expSign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expBytes := by
change suffixBytes = _
apply u8_list_eq_of_val_map
dsimp [expSign, expDigits] at hsignByteMap ⊢
rw [hsuffixMap, List.map_append, hsignByteMap, hexpMap]
rfl
obtain ⟨parsedExp, scientificRest, hscientific, hscientificRest,
hparsedExp⟩ := NumberHelperScientificExact suffix expSign expBytes
hexpByteNe hexpByteDigits hsuffixDecomp'
have hparsedExpValue : parsedExp.val =
if expSign = some true then
-((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
else ((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int) := by
rw [hparsedExp, guarded_fold_map, hexpDigitMap]
have hparsedExpTarget : parsedExp.val =
(match expSign with
| some true => -((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
| _ => ((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)) := by
rw [hparsedExpValue]
exact signed_if_eq_match expSign _
obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
NumberHelperOffsetSourceLength s scientificRest hlen (by
simp [hscientificRest])
have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
ok (Slice.len s) := by
have hbound : 0 <= fullOffset.val /\
fullOffset.val <= UScalar.max .Usize := by
rw [hfullOffsetVal, hscientificRest]
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
rw [hz]
congr 2
apply UScalar.eq_of_val_eq
rw [hfullOffsetVal, hscientificRest] at hzval
simpa [Slice.len_val] using hzval
have hnotempty : Not (s.val = []) := by simpa using hne
unfold num.imp.dec2flt.parse.parse_number at hparse
simp [hnotempty] at hparse
unfold num.imp.dec2flt.parse.parse_partial_number at hparse
simp [hnotempty, hscanInt, hoffInt, hsplitPoint, hscanFrac,
hoffFrac, hnegAfter, hfracExponent] at hparse
norm_num at hparse
simp only [UScalar.ofNat, UScalar.ofNatCore] at hparse
cases hupper : upper <;>
simp [hupper, htotal, htotalPos, hsplitMarker, hscientific,
hoffFull, hfullCast, UScalar.ofNatCore,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch, ModelOptionFromResidual] at hparse
all_goals
cases hsum : fracExponent + parsedExp with
| fail err => simp [hsum] at hparse
| div => simp [hsum] at hparse
| ok combinedExponent =>
simp [hsum] at hparse
have hcombinedVal : combinedExponent.val =
fracExponent.val + parsedExp.val := by
have h := IScalar.add_equiv fracExponent parsedExp
rw [hsum] at h
exact h.2.1
have hdigitInt : intBytes.map (fun b : Std.U8 => b.val - 48) =
ints := unrender_digits intBytes ints hintMap hints
have hdigitFrac : fracBytes.map (fun b : Std.U8 => b.val - 48) =
fracs := unrender_digits fracBytes fracs hfracMap hfrac
have hsigMap : (intBytes ++ fracBytes).map
(fun b : Std.U8 => b.val - 48) = ints ++ fracs := by
simp [hdigitInt, hdigitFrac]
have hsigDigits : forall b, List.Mem b (intBytes ++ fracBytes) ->
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 hsigFoldEq : (intBytes ++ fracBytes).foldl digitStep 0 =
(ints ++ fracs).foldl natStep 0 := by
rw [fold_map, hsigMap]
have hcombinedExponentTarget : combinedExponent.val =
parsedExp.val - (fracs.length : Int) := by
rw [hcombinedVal, hfracExponentEq, hfracLen]
omega
have hexactScans : (intBytes ++ fracBytes).foldl digitStep 0 <=
U64.max ->
mantissa.val = intBytes.foldl digitStep 0 /\
mantissa1.val = (intBytes ++ fracBytes).foldl digitStep 0 := by
as_aux_lemma =>
intro hfullBound
have hprefixLe : intBytes.foldl digitStep 0 <=
(intBytes ++ fracBytes).foldl digitStep 0 := by
rw [List.foldl_append]
exact fold_ge_start fracBytes _
have hintBound : intBytes.foldl digitStep 0 <= U64.max :=
hprefixLe.trans hfullBound
obtain ⟨exactInt, exactIntRest, hexactInt, hexactIntRest,
hexactIntValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
intTail.val hstart hintDigits hintTailNotDigit hlen
(by simpa [digitStep] using hintBound)
have hmantissa : mantissa.val =
intBytes.foldl digitStep 0 := by
rw [hscanInt] at hexactInt
simp at hexactInt
rcases hexactInt with ⟨rfl, rfl⟩
simpa [digitStep] using hexactIntValue
have hfracBound : fracBytes.foldl digitStep mantissa.val <=
U64.max := by
rw [hmantissa, ← List.foldl_append]
exact hfullBound
obtain ⟨exactFrac, exactFracRest, hexactFrac, hexactFracRest,
hexactFracValue⟩ := NumberHelperDigitScanExact fracSlice
mantissa fracBytes markerTail.val (by simp [fracSlice])
hfracDigits hmarkerTailNotDigit (by
simp [fracSlice]
rw [hstart] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega) (by simpa [digitStep] using hfracBound)
have hmantissa1 : mantissa1.val =
(intBytes ++ fracBytes).foldl digitStep 0 := by
rw [hscanFrac] at hexactFrac
simp at hexactFrac
rcases hexactFrac with ⟨rfl, rfl⟩
rw [List.foldl_append, ← hmantissa]
simpa [digitStep] using hexactFracValue
exact ⟨hmantissa, hmantissa1⟩
by_cases hsmall : totalDigits.val <= 19
· simp [hsmall] at hparse
have hsigLen : (intBytes ++ fracBytes).length <= 19 := by
rw [List.length_append]
omega
have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
10 ^ (intBytes ++ fracBytes).length := by
simpa using fold_upper (intBytes ++ fracBytes) 0 hsigDigits
have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
U64.max := by
have hp := hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num) hsigLen)
have hpowMax : 10 ^ 19 <= U64.max := by
norm_num [U64.max_eq]
exact (Nat.le_of_lt hp).trans hpowMax
obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa1, hsigFoldEq, hcombinedExponentTarget,
List.foldl_append]
simp [natStep, hparsedExpTarget, expSign, expDigits]
all_goals exact Or.inl rfl
· have hlarge : 19 < totalDigits.val := by omega
have hsubBounds : IScalar.min .Isize <= totalDigits.val - 19 /\
totalDigits.val - 19 <= IScalar.max .Isize := by
have hb := IScalar.hBounds totalDigits
simp [IScalar.min, IScalar.max, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits] at hb ⊢
omega
obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.sub_spec (x := totalDigits) (y := 19#isize)
(by norm_num; omega) (by norm_num; omega))
norm_num at hnMoreVal
simp [hsmall, hnMore] at hparse
obtain ⟨rawZeros, rawTail, sigZeros, sigTail, hsRaw,
hrawZeros, hrawTail, hsSig, hsigZeros, hsigTailSharp,
hcount⟩ := split_significand_zeros intBytes fracBytes
markerTail.val hintDigits hfracDigits (by
right
refine ⟨if upper then 69#u8 else 101#u8, suffixBytes,
by simp [markerTail], ?_, ?_⟩
· simp [hupper]
· simp [hupper])
have hsAdjust : s.val = rawZeros ++ rawTail := by
rw [hstart]
simpa using hsRaw
have hsigLenEq : intBytes.length + fracBytes.length =
sigZeros.length + sigTail.length := by
have hp := congrArg List.length hsSig
simpa using hp
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq, hstart]
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 <=
(intBytes ++ fracBytes).length := by
rw [hsSig]
simp
simp [IScalar.min, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
NumberHelperAdjustManyExact s nMore rawZeros rawTail hsAdjust
hrawZeros hrawTail hlen hnMoreNonneg hnMoreLe hadjustLower
rw [hadjust] at hparse
by_cases hpositive : 0 < adjusted.val
· simp [hpositive] at hparse
cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
parsedExp with
| fail err => simp [hmany] at hparse
| div => simp [hmany] at hparse
| ok result =>
rcases result with ⟨manyMantissa, manyExponent⟩
simp [hmany] at hparse
have hsigTailLen : 19 < sigTail.length := by
rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
hnAfterEq] at hpositive
omega
have hsigTailCons : exists first tailRest,
sigTail = first :: tailRest /\ first ≠ 48#u8 := by
rcases hsigTailSharp with hnil | hcons
· rw [hnil] at hsigTailLen
simp at hsigTailLen
· exact hcons
rcases hsigTailCons with
⟨first, tailRest, htailEq, hfirstNe⟩
have hfirstDigit := hsigDigits first (by
rw [hsSig, htailEq]
exact List.mem_append_right sigZeros List.mem_cons_self)
have hthreshold : 1000000000000000000 <=
(intBytes ++ fracBytes).foldl digitStep 0 := by
have hzero := zero_fold sigZeros hsigZeros
have hlower := fold_lower tailRest (first.val - 48)
rw [hsSig, List.foldl_append, hzero, htailEq,
List.foldl_cons]
change 1000000000000000000 <=
tailRest.foldl digitStep (digitStep 0 first)
have hfirstPos : 1 <= first.val - 48 := by
have hneVal : first.val ≠ 48 := by
intro h
apply hfirstNe
apply UScalar.eq_of_val_eq
simpa using h
omega
have hpowLower : 1000000000000000000 <=
10 ^ tailRest.length := by
have hlenRest : 18 <= tailRest.length := by
rw [htailEq] at hsigTailLen
simp only [List.length_cons] at hsigTailLen
omega
have hp := Nat.pow_le_pow_right
(by norm_num : 0 < 10) hlenRest
norm_num at hp ⊢
exact hp
have hstep : 10 ^ tailRest.length <=
(first.val - 48) * 10 ^ tailRest.length := by
simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
hfirstPos
exact hpowLower.trans (hstep.trans (by
simpa [digitStep] using hlower))
obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
hmanyExponent⟩ := NumberHelperFractionalManyExact s
intTail parsedExp manyExponent manyMantissa intBytes
fracBytes markerTail.val hstart (by simp [intTail])
hintDigits hfracDigits hmarkerTailNotDigit hlen
hthreshold hmany
have hmanyExponentTarget : manyExponent.val =
parsedExp.val - (fracs.length : Int) +
remaining.length := by
rw [hmanyExponent, hfracLen]
subst d
have hresult := finish_value
(num.imp.dec2flt.decimal.Decimal.mk manyExponent
manyMantissa false true)
(intBytes ++ fracBytes) (ints ++ fracs)
(parsedExp.val - (fracs.length : Int)) hsigMap (by
intro digit hdigit
rcases List.mem_append.mp hdigit with hdigit | hdigit
· exact hints digit hdigit
· exact hfrac digit hdigit)
(Or.inr ⟨rfl, consumed, remaining, hpartition,
hmanyMantissa, hmanyExponentTarget⟩)
simpa [DecimalGoalVocabularyDefault, natStep,
List.foldl_append, hparsedExpTarget, expSign, expDigits]
using hresult
· simp [hpositive] at hparse
have hsigTailLen : sigTail.length <= 19 := by
rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
hnAfterEq] at hpositive
omega
have hsigTailDigits : forall b, List.Mem b sigTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hsigDigits b
rw [hsSig]
exact List.mem_append_right sigZeros hb
have hzero := zero_fold sigZeros hsigZeros
have hfoldLtTail : sigTail.foldl digitStep 0 <
10 ^ sigTail.length := by
simpa using fold_upper sigTail 0 hsigTailDigits
have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
10 ^ 19 := by
rw [hsSig, List.foldl_append, hzero]
exact hfoldLtTail.trans_le
(Nat.pow_le_pow_right (by norm_num) hsigTailLen)
have hfullBound :
(intBytes ++ fracBytes).foldl digitStep 0 <= U64.max := by
have hpowMax : 10 ^ 19 <= U64.max := by
norm_num [U64.max_eq]
exact (Nat.le_of_lt hfoldLt).trans hpowMax
obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa1, hsigFoldEq, hcombinedExponentTarget,
List.foldl_append]
simp [natStep, hparsedExpTarget, expSign, expDigits]
all_goals exact Or.inl rfl
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.Assumptions
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.ModelSliceSplitFirst
import Tablet.ModelU64BitAnd
import Tablet.ModelU64BitOr
import Tablet.ModelU8IsAsciiDigit
import Tablet.NumberHelperAdjustManyExact
import Tablet.NumberHelperDecimalPrefixInterval
import Tablet.NumberHelperDigitScanExact
import Tablet.NumberHelperDigitScanSourceLength
import Tablet.NumberHelperFractionalManyExact
import Tablet.NumberHelperIntegralManyExact
import Tablet.NumberHelperOffsetSourceLength
import Tablet.NumberHelperParseEightDigitsExact
import Tablet.NumberHelperScientificExact
import Tablet.NumberHelperSplitExponentSuffix
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.SourceValidByteSlice
import Tablet.U64_Insts_CoreOpsBitBitAndU64U64
import Tablet.U64_Insts_CoreOpsBitBitOrU64U64
import Tablet.num_imp_dec2flt_common_is_8digits
import Tablet.num_imp_dec2flt_decimal_Decimal
import Tablet.num_imp_dec2flt_parse_MIN_19DIGIT_INT
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
import Tablet.num_imp_dec2flt_parse_parse_8digits
import Tablet.num_imp_dec2flt_parse_parse_8digits_MASK
import Tablet.num_imp_dec2flt_parse_parse_8digits_MUL1
import Tablet.num_imp_dec2flt_parse_parse_8digits_MUL2
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.num_imp_dec2flt_parse_try_parse_19digits
import Tablet.num_imp_dec2flt_parse_try_parse_digits
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 1000000
set_option maxRecDepth 10000
namespace dec2flt_model
-- [TABLET NODE: NumberHelperAccumulatedValue]
theorem NumberHelperAccumulatedValue :
∀ (s : Slice Std.U8) (x : DecimalLexeme) d, SourceValidByteSlice s -> s.val ≠ [] -> x.leadingSign = none ->
DecimalGoalVocabularyDefault.validNumeric x -> DecimalGoalVocabularyDefault.bytes s = DecimalGoalVocabularyDefault.renderNumeric x ->
num.imp.dec2flt.parse.parse_number s = ok (some d) ->
(d.many_digits = false ∧ DecimalGoalVocabularyDefault.decimalMagnitude d = DecimalGoalVocabularyDefault.accumulatedMagnitude x) ∨
(d.many_digits = true ∧ DecimalGoalVocabularyDefault.decimalMagnitude d <= DecimalGoalVocabularyDefault.accumulatedMagnitude x ∧
DecimalGoalVocabularyDefault.accumulatedMagnitude x <
((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := by
-- BODY
intro s x d hsource hne hsign hvalid hbytes hparse
rcases x with ⟨sign, ints, frac, expo⟩
simp only at hsign
subst sign
simp [DecimalGoalVocabularyDefault] at hvalid hbytes ⊢
rcases hvalid with ⟨hints, hfrac, hsome, hexpo⟩
have hlen : s.val.length <= 9223372036854775807 := by
simpa [SourceValidByteSlice] using hsource
have byte_digits : forall (bs : List Std.U8) (ds : List Nat),
List.map (fun b : Std.U8 => b.val) bs =
List.map (fun d : Nat => 48 + d) ds ->
(forall d, List.Mem d ds -> d < 10) ->
forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57 := by
intro bs ds hmap hds b hb
have hbmap : b.val ∈ List.map (fun b : Std.U8 => b.val) bs :=
List.mem_map_of_mem hb
rw [hmap] at hbmap
obtain ⟨digit, hdigit, hdigitVal⟩ := List.mem_map.mp hbmap
have := hds digit hdigit
omega
let digitStep : Nat -> Std.U8 -> Nat :=
fun a b => 10 * a + (b.val - 48)
let natStep : Nat -> Nat -> Nat := fun a digit => 10 * a + digit
have unrender_digits : forall (bs : List Std.U8) (ds : List Nat),
List.map (fun b : Std.U8 => b.val) bs =
List.map (fun digit : Nat => 48 + digit) ds ->
(forall digit, List.Mem digit ds -> digit < 10) ->
List.map (fun b : Std.U8 => b.val - 48) bs = ds := by
intro bs ds hmap hds
calc
List.map (fun b : Std.U8 => b.val - 48) bs =
List.map (fun n : Nat => n - 48)
(List.map (fun b : Std.U8 => b.val) bs) := by
simp [List.map_map]
_ = List.map (fun n : Nat => n - 48)
(List.map (fun digit : Nat => 48 + digit) ds) := by rw [hmap]
_ = ds := by
have cancel : forall xs : List Nat,
List.map (fun n : Nat => n - 48)
(List.map (fun digit : Nat => 48 + digit) xs) = xs := by
intro xs
induction xs with
| nil => rfl
| cons digit xs ih =>
simp only [List.map_cons, Nat.add_sub_cancel_left]
exact congrArg (List.cons digit) ih
exact cancel ds
have u8_list_eq_of_val_map : forall xs ys : List Std.U8,
xs.map (fun b : Std.U8 => b.val) =
ys.map (fun b : Std.U8 => b.val) -> xs = ys := by
intro xs
induction xs with
| nil =>
intro ys h
cases ys <;> simp_all
| cons x xs ih =>
intro ys h
cases ys with
| nil => simp at h
| cons y ys =>
simp only [List.map_cons, List.cons.injEq] at h
have hxy : x = y := UScalar.eq_of_val_eq h.1
subst y
rw [ih ys h.2]
have split_val_map : forall (preVals suffix : List Nat)
(bs : List Std.U8),
bs.map (fun b : Std.U8 => b.val) = preVals ++ suffix ->
exists prefixBytes suffixBytes,
bs = prefixBytes ++ suffixBytes /\
prefixBytes.map (fun b : Std.U8 => b.val) = preVals /\
suffixBytes.map (fun b : Std.U8 => b.val) = suffix := by
intro preVals
induction preVals with
| nil =>
intro suffix bs h
exact ⟨[], bs, by simp, rfl, by simpa using h⟩
| cons value preVals ih =>
intro suffix bs h
cases bs with
| nil => simp at h
| cons b bs =>
simp only [List.map_cons, List.cons_append, List.cons.injEq] at h
obtain ⟨prefixBytes, suffixBytes, hsplit, hp, hs⟩ :=
ih suffix bs h.2
exact ⟨b :: prefixBytes, suffixBytes, by simp [hsplit],
by simp [h.1, hp], hs⟩
have fold_map : forall (bs : List Std.U8) (a : Nat),
bs.foldl digitStep a =
(bs.map (fun b : Std.U8 => b.val - 48)).foldl natStep a := by
intro bs a
induction bs generalizing a with
| nil => rfl
| cons b bs ih =>
simp only [List.foldl_cons, List.map_cons]
exact ih _
have guarded_fold_map : forall (bs : List Std.U8) (a : Nat),
bs.foldl (fun a b => if a < 65536 then
10 * a + (b.val - 48) else a) a =
(bs.map (fun b : Std.U8 => b.val - 48)).foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) a := by
intro bs a
induction bs generalizing a with
| nil => rfl
| cons b bs ih =>
simp only [List.foldl_cons, List.map_cons]
exact ih _
have signed_if_eq_match : forall (sign : Option Bool) (n : Int),
(if sign = some true then -n else n) =
match sign with
| some true => -n
| _ => n := by
intro sign n
cases sign with
| none => rfl
| some negative => cases negative <;> rfl
have fold_upper : forall (bs : List Std.U8) (a : Nat),
(forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
bs.foldl digitStep a < (a + 1) * 10 ^ bs.length := by
intro bs
induction bs with
| nil => intro a h; simp
| cons b bs ih =>
intro a h
have hb := h b List.mem_cons_self
have hbs : forall c, List.Mem c bs -> 48 <= c.val /\ c.val <= 57 := by
intro c hc
exact h c (List.mem_cons_of_mem b hc)
simp only [List.foldl_cons, List.length_cons, Nat.pow_succ]
have hrec := ih (digitStep a b) hbs
have hcoeff : digitStep a b + 1 <= 10 * (a + 1) := by
simp only [digitStep]
omega
have hmul := Nat.mul_le_mul_right (10 ^ bs.length) hcoeff
exact hrec.trans_le (by
simpa [Nat.mul_assoc, Nat.mul_comm, Nat.mul_left_comm] using hmul)
have fold_lower : forall (bs : List Std.U8) (a : Nat),
a * 10 ^ bs.length <= bs.foldl digitStep a := by
intro bs
induction bs with
| nil => intro a; simp
| cons b bs ih =>
intro a
simp only [List.foldl_cons, List.length_cons, Nat.pow_succ]
calc
a * (10 ^ bs.length * 10) = (10 * a) * 10 ^ bs.length := by ring
_ <= digitStep a b * 10 ^ bs.length := by
apply Nat.mul_le_mul_right
simp [digitStep]
_ <= bs.foldl digitStep (digitStep a b) := ih _
have fold_ge_start : forall (bs : List Std.U8) (a : Nat),
a <= bs.foldl digitStep a := by
intro bs
induction bs with
| nil => intro a; rfl
| cons b bs ih =>
intro a
apply le_trans (b := digitStep a b)
· simp [digitStep]
omega
· exact ih _
have split_zeros : forall bs : List Std.U8,
(forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
exists zeros tail,
bs = zeros ++ tail /\
(forall b, List.Mem b zeros -> b = 48#u8) /\
(tail = [] \/ exists b rest, tail = b :: rest /\ b != 48#u8) := by
intro bs
induction bs with
| nil =>
intro h
exact ⟨[], [], rfl, (by intro b hb; cases hb), Or.inl rfl⟩
| cons b bs ih =>
intro h
by_cases hb : b = 48#u8
· obtain ⟨zeros, tail, hsplit, hzeros, htail⟩ := ih (by
intro c hc
exact h c (List.mem_cons_of_mem b hc))
refine ⟨b :: zeros, tail, by simp [hsplit], ?_, htail⟩
intro c hc
rcases List.mem_cons.mp hc with rfl | hc
· exact hb
· exact hzeros c hc
· exact ⟨[], b :: bs, rfl, (by intro c hc; cases hc), Or.inr ⟨b, bs, rfl, by
simpa only [bne_iff_ne] using hb⟩⟩
have zero_fold : forall zeros : List Std.U8,
(forall b, List.Mem b zeros -> b = 48#u8) ->
zeros.foldl digitStep 0 = 0 := 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, digitStep, ih hbs]
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
induction zeros with
| nil => intro h; rfl
| cons b bs ih =>
intro h
have hb := h b List.mem_cons_self
have hbs : forall c, List.Mem c bs -> c = 48#u8 := by
intro c hc
exact h c (List.mem_cons_of_mem b hc)
simp [hb, ih hbs]
have split_significand_zeros : forall
(integer fraction tail : 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) ->
(tail = [] \/ exists b rest, tail = b :: rest /\
b ≠ 48#u8 /\ b ≠ 46#u8) ->
exists rawZeros rawTail sigZeros sigTail,
integer ++ 46#u8 :: (fraction ++ tail) = rawZeros ++ rawTail /\
(forall b, List.Mem b rawZeros -> b = 48#u8 \/ b = 46#u8) /\
(rawTail = [] \/ 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) /\
(sigTail = [] \/ exists b rest, sigTail = b :: rest /\
b ≠ 48#u8) /\
rawZeros.count 48#u8 = sigZeros.length := by
intro integer fraction tail hinteger hfraction htail
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
have hfracSigNe : fracSig = [] \/ exists c rest,
fracSig = c :: rest /\ c ≠ 48#u8 := by
rcases hfracSig with hnil | ⟨c, rest, heq, hc⟩
· exact Or.inl hnil
· exact Or.inr ⟨c, rest, heq,
by simpa only [bne_iff_ne] using hc⟩
refine ⟨intZeros ++ 46#u8 :: fracZeros, fracSig ++ tail,
intZeros ++ fracZeros, fracSig, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩
· rw [hintSplit, hintNil, hfracSplit]
simp [List.append_assoc]
· intro c hc
rcases List.mem_append.mp hc with hc | hc
· exact Or.inl (hintZeros c hc)
· rcases List.mem_cons.mp hc with rfl | hc
· exact Or.inr rfl
· exact Or.inl (hfracZeros c hc)
· rcases hfracSigNe with hnil | ⟨c, rest, hfracSigEq, hc⟩
· rw [hnil]
simpa using htail
· right
refine ⟨c, rest ++ tail, by simp [hfracSigEq], ?_, ?_⟩
· exact 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 c hc
rcases List.mem_append.mp hc with hc | hc
· exact hintZeros c hc
· exact hfracZeros c hc
· exact hfracSigNe
· rw [List.count_append, List.count_cons, count_zeros intZeros hintZeros,
count_zeros fracZeros hfracZeros]
norm_num
· refine ⟨intZeros, intSig ++ 46#u8 :: (fraction ++ tail),
intZeros, intSig ++ fraction, ?_, ?_, ?_, ?_, hintZeros, ?_, ?_⟩
· rw [hintSplit]
simp [List.append_assoc]
· intro c hc
exact Or.inl (hintZeros c hc)
· right
refine ⟨b, intRest ++ 46#u8 :: (fraction ++ tail),
by simp [hintSigEq], ?_, ?_⟩
· simpa only [bne_iff_ne] using 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 Or.inr ⟨b, intRest ++ fraction, by simp [hintSigEq],
by simpa only [bne_iff_ne] using hb⟩
· exact count_zeros intZeros hintZeros
have finish_value : forall (record : num.imp.dec2flt.decimal.Decimal)
(bytes : List Std.U8) (digits : List Nat) (e : Int),
bytes.map (fun b : Std.U8 => b.val - 48) = digits ->
(forall digit, List.Mem digit digits -> digit < 10) ->
((record.many_digits = false /\
record.mantissa.val = bytes.foldl digitStep 0 /\
record.exponent.val = e) \/
(record.many_digits = true /\ exists consumed remaining,
bytes = consumed ++ remaining /\
record.mantissa.val = consumed.foldl digitStep 0 /\
record.exponent.val = e + remaining.length)) ->
(record.many_digits = false /\
DecimalGoalVocabularyDefault.decimalMagnitude record =
((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e) \/
(record.many_digits = true /\
DecimalGoalVocabularyDefault.decimalMagnitude record <=
((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e /\
((digits.foldl natStep 0 : Nat) : Real) * (10 : Real) ^ e <
((record.mantissa.val + 1 : Nat) : Real) *
(10 : Real) ^ record.exponent.val) := by
intro record bytes digits e hmap hdigits hrepresentation
rcases hrepresentation with ⟨hmany, hmantissa, hexponent⟩ |
⟨hmany, consumed, remaining, hpartition, hmantissa, hexponent⟩
· left
refine ⟨hmany, ?_⟩
simp only [DecimalGoalVocabularyDefault]
rw [hmantissa, hexponent, fold_map, hmap]
· right
let headDigits := consumed.map (fun b : Std.U8 => b.val - 48)
let suffixDigits := remaining.map (fun b : Std.U8 => b.val - 48)
have hsuffixDigits : forall digit, List.Mem digit suffixDigits ->
digit < 10 := by
intro digit hdigit
apply hdigits digit
rw [← hmap, hpartition, List.map_append]
exact List.mem_append_right headDigits hdigit
have hrenderPartition : headDigits ++ suffixDigits = digits := by
rw [← List.map_append, ← hpartition]
exact hmap
obtain ⟨hintervalLower, hintervalUpper⟩ :=
NumberHelperDecimalPrefixInterval headDigits suffixDigits
hsuffixDigits e
rw [hrenderPartition] at hintervalLower hintervalUpper
have hconsumedFold := fold_map consumed 0
dsimp [headDigits, suffixDigits] at hintervalLower hintervalUpper
rw [← hconsumedFold] at hintervalLower hintervalUpper
refine ⟨hmany, ?_, ?_⟩
· simpa [DecimalGoalVocabularyDefault, natStep, hmantissa, hexponent,
hrenderPartition] using hintervalLower
· simpa [DecimalGoalVocabularyDefault, natStep, hmantissa, hexponent,
hrenderPartition] using hintervalUpper
cases frac with
| none =>
simp at hfrac hsome
cases expo with
| none =>
simp at hbytes hexpo
have hsdigits := byte_digits s.val ints hbytes hints
obtain ⟨mantissa, rest, hscan, hrest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 s.val [] (by simp)
hsdigits (by simp) hlen
let empty : Slice Std.U8 := ⟨[], by simp⟩
have hrestEq : rest = empty := (Slice.eq_iff _ _).2 (by
simpa [empty] using hrest)
obtain ⟨nDigits, hoff, hnDigitsVal⟩ :=
NumberHelperOffsetSourceLength s rest hlen (by simp [hrest])
have hnDigitsEq : nDigits.val = s.val.length := by
simpa [hrest] using hnDigitsVal
have hsplit : core.slice.Slice.split_first rest = ok none := by
rw [hrestEq]
simp [core.slice.Slice.split_first, ModelSliceSplitFirst, empty]
have hnotempty : Not (s.val = []) := by simpa using hne
have hsLenEq : s.val.length = ints.length := by
have := congrArg List.length hbytes
simpa using this
have hnpos : 0 < nDigits.val := by
rw [hnDigitsEq, hsLenEq]
exact_mod_cast List.length_pos_of_ne_nil hsome
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,
Dec2Flt.configured_x86_64_numBits]
omega) (by
simp [IScalar.max, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits] at hb ⊢
omega))
rw [hz]
congr 2
apply IScalar.eq_of_val_eq
simpa using hzval
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]
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
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
simpa [Slice.len_val] using hzval
have hdigitMap : s.val.map (fun b : Std.U8 => b.val - 48) = ints :=
unrender_digits s.val ints hbytes hints
have hfoldEq : s.val.foldl digitStep 0 = ints.foldl natStep 0 := by
rw [fold_map, hdigitMap]
simp [num.imp.dec2flt.parse.parse_number,
num.imp.dec2flt.parse.parse_partial_number, hscan, hoff, hsplit,
hnotempty, haddzero, hnpos.ne', hcastlen] at hparse
by_cases hsmall : nDigits.val <= 19
· simp [hsmall] at hparse
subst d
left
refine ⟨rfl, ?_⟩
have hfoldLt : s.val.foldl digitStep 0 < 10 ^ s.val.length := by
simpa using fold_upper s.val 0 hsdigits
have hfoldBound : s.val.foldl digitStep 0 <= U64.max := by
have hlen19 : s.val.length <= 19 := by omega
have hpow : 10 ^ s.val.length <= 10 ^ 19 := by
exact Nat.pow_le_pow_right (by norm_num) hlen19
have : s.val.foldl digitStep 0 < 10 ^ 19 := hfoldLt.trans_le hpow
rw [U64.max_eq]
norm_num
omega
obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 s.val []
(by simp) hsdigits (by simp) hlen (by simpa [digitStep] using hfoldBound)
have hmantissa : mantissa.val = s.val.foldl digitStep 0 := by
rw [hscan] at hexactScan
simp at hexactScan
rcases hexactScan with ⟨rfl, rfl⟩
simpa [digitStep] using hexactValue
simp only [num.imp.dec2flt.decimal.Decimal.many_digits,
num.imp.dec2flt.decimal.Decimal.mantissa,
num.imp.dec2flt.decimal.Decimal.exponent]
norm_num
rw [hmantissa, hfoldEq]
· have hlarge : 19 < nDigits.val := by omega
simp [hsmall] at hparse
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,
Dec2Flt.configured_x86_64_numBits] 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
rw [hnMore] at hparse
simp at hparse
obtain ⟨zeros, tail, hsZeros, hzeros, htail⟩ :=
split_zeros s.val hsdigits
have hcount : zeros.count 48#u8 = zeros.length :=
count_zeros zeros hzeros
have htailSharp : tail = [] \/ exists b rest,
tail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
rcases htail with hnil | ⟨b, restTail, htailEq, hb⟩
· exact Or.inl hnil
· right
refine ⟨b, restTail, htailEq, ?_, ?_⟩
· simpa only [bne_iff_ne] using hb
· have hbdigit := hsdigits b (by
rw [hsZeros]
exact List.mem_append_right zeros (by simp [htailEq]))
intro h46
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]
omega
have hadjustLower : IScalar.min .Isize <=
nMore.val - (zeros.count 48#u8 : Int) := by
rw [hnMoreVal, hcount]
have hzerosLen : zeros.length <= s.val.length := by
rw [hsZeros]
simp
simp [IScalar.min, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
NumberHelperAdjustManyExact s nMore zeros tail hsZeros (by
intro b hb
exact Or.inl (hzeros b hb)) htailSharp hlen hnMoreNonneg
hnMoreLe hadjustLower
rw [hadjust] at hparse
by_cases hpositive : 0 < adjusted.val
· simp [hpositive] at hparse
cases hmany : num.imp.dec2flt.parse.parse_many_digits s rest 0#i64 with
| fail err => simp [hmany] at hparse
| div => simp [hmany] at hparse
| ok result =>
rcases result with ⟨manyMantissa, manyExponent⟩
simp [hmany] at hparse
have htailLen : 19 < tail.length := by
rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
rw [hsZeros] at hpositive
simp only [List.length_append] at hpositive
omega
have htailCons : exists first tailRest,
tail = first :: tailRest /\
first ≠ 48#u8 /\ first ≠ 46#u8 := by
rcases htailSharp with hnil | hcons
· rw [hnil] at htailLen
simp at htailLen
· exact hcons
rcases htailCons with
⟨first, tailRest, htailEq, hfirstNe, hfirstPoint⟩
have hfirstDigit := hsdigits first (by
rw [hsZeros, htailEq]
exact List.mem_append_right zeros List.mem_cons_self)
have hthreshold : 1000000000000000000 <=
s.val.foldl (fun a b => 10 * a + (b.val - 48)) 0 := by
have hzero := zero_fold zeros hzeros
have hlower := fold_lower tailRest (first.val - 48)
rw [hsZeros, List.foldl_append, hzero, htailEq,
List.foldl_cons]
change 1000000000000000000 <=
tailRest.foldl digitStep (digitStep 0 first)
have hfirstPos : 1 <= first.val - 48 := by
have hneVal : first.val ≠ 48 := by
intro h
apply hfirstNe
apply UScalar.eq_of_val_eq
simpa using h
omega
have hpowLower : 1000000000000000000 <=
10 ^ tailRest.length := by
have hlenRest : 18 <= tailRest.length := by
rw [htailEq] at htailLen
simp only [List.length_cons] at htailLen
omega
have hp := Nat.pow_le_pow_right (by norm_num : 0 < 10) hlenRest
norm_num at hp ⊢
exact hp
have hstep : 10 ^ tailRest.length <=
(first.val - 48) * 10 ^ tailRest.length := by
nlinarith
exact hpowLower.trans (hstep.trans (by
simpa [digitStep] using hlower))
obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
hmanyExponent⟩ := NumberHelperIntegralManyExact s rest
0#i64 manyExponent manyMantissa s.val [] (by simp) hrest
hsdigits (by simp) hlen hthreshold hmany
let headDigits := consumed.map (fun b : Std.U8 => b.val - 48)
let suffixDigits := remaining.map (fun b : Std.U8 => b.val - 48)
have hsuffixDigits : forall digit, List.Mem digit suffixDigits ->
digit < 10 := by
intro digit hdigit
obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hdigit
have hbAll : List.Mem b s.val := by
rw [hpartition]
exact List.mem_append_right consumed hb
have hbDigit := hsdigits b hbAll
omega
have hrenderPartition : headDigits ++ suffixDigits = ints := by
rw [← List.map_append, ← hpartition]
exact hdigitMap
obtain ⟨hintervalLower, hintervalUpper⟩ :=
NumberHelperDecimalPrefixInterval headDigits suffixDigits
hsuffixDigits 0
have hconsumedFold := fold_map consumed 0
dsimp [headDigits, suffixDigits] at hintervalLower hintervalUpper
rw [← hconsumedFold] at hintervalLower hintervalUpper
subst d
right
refine ⟨rfl, ?_, ?_⟩
· simpa [headDigits, suffixDigits, natStep,
hmanyMantissa, hmanyExponent, hrenderPartition] using
hintervalLower
· simpa [headDigits, suffixDigits, natStep,
hmanyMantissa, hmanyExponent, hrenderPartition] using
hintervalUpper
· simp [hpositive] at hparse
have htailLen : tail.length <= 19 := by
rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
rw [hsZeros] at hpositive
simp only [List.length_append] at hpositive
omega
have htailDigits : forall b, List.Mem b tail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hsdigits b
rw [hsZeros]
exact List.mem_append_right zeros hb
have hzero := zero_fold zeros hzeros
have hfoldLtTail : tail.foldl digitStep 0 < 10 ^ tail.length := by
simpa using fold_upper tail 0 htailDigits
have hfoldLt : s.val.foldl digitStep 0 < 10 ^ 19 := by
rw [hsZeros, List.foldl_append, hzero]
exact hfoldLtTail.trans_le
(Nat.pow_le_pow_right (by norm_num) htailLen)
have hfoldBound : s.val.foldl digitStep 0 <= U64.max := by
rw [U64.max_eq]
norm_num
omega
obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 s.val []
(by simp) hsdigits (by simp) hlen
(by simpa [digitStep] using hfoldBound)
have hmantissa : mantissa.val = s.val.foldl digitStep 0 := by
rw [hscan] at hexactScan
simp at hexactScan
rcases hexactScan with ⟨rfl, rfl⟩
simpa [digitStep] using hexactValue
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa, hfoldEq]
| some e =>
let upper : Bool := e.1
let expSign : Option Bool := e.2.1
let expDigits : List Nat := e.2.2
change expDigits ≠ [] /\
(forall digit, List.Mem digit expDigits -> digit < 10) at hexpo
rcases hexpo with ⟨hexpNe, hexpDigits⟩
simp [upper, expSign, expDigits] at hbytes
obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
List.map_eq_append_iff.mp hbytes
obtain ⟨marker, suffixBytes, hafterVal, hmarkerVal, hsuffixMap⟩ :=
List.map_eq_cons_iff.mp hafterMap
have hmarker : marker = if upper then 69#u8 else 101#u8 := by
by_cases hu : upper = true
· rw [if_pos hu]
apply UScalar.eq_of_val_eq
simpa [hu, upper] using hmarkerVal
· rw [if_neg hu]
apply UScalar.eq_of_val_eq
simpa [hu, upper] using hmarkerVal
subst marker
have hsdecomp : s.val = intBytes ++
(if upper then 69#u8 else 101#u8) :: suffixBytes := by
rw [hsval, hafterVal]
have hintDigits := byte_digits intBytes ints hintMap hints
have hintTailProp :
((if upper then 69#u8 else 101#u8) :: suffixBytes).length <=
Usize.max := by
have hp := s.property
rw [hsdecomp] at hp
simp only [List.length_append] at hp ⊢
omega
let intTail : Slice Std.U8 :=
⟨(if upper then 69#u8 else 101#u8) :: suffixBytes,
hintTailProp⟩
have hintTailNotDigit : forall b restBytes,
intTail.val = b :: restBytes ->
Not (48 <= b.val /\ b.val <= 57) := by
intro b restBytes hb
simp [intTail] at hb
rcases hb with ⟨rfl, _⟩
cases upper <;> norm_num
obtain ⟨mantissa, intRest, hscan, hintRest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
(by simpa [intTail] using hsdecomp) hintDigits hintTailNotDigit hlen
have hintRestEq : intRest = intTail :=
(Slice.eq_iff _ _).2 (by simpa using hintRest)
subst intRest
obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
NumberHelperOffsetSourceLength s intTail hlen (by
rw [hsdecomp]
simp [intTail])
have hnDigitsEq : nDigits.val = intBytes.length := by
rw [hnDigitsVal, hsdecomp]
simp [intTail]
have hsuffixProp : suffixBytes.length <= Usize.max := by
have hp := intTail.property
simp [intTail] at hp
omega
let suffix : Slice Std.U8 := ⟨suffixBytes, hsuffixProp⟩
have hsplitMarker : core.slice.Slice.split_first intTail =
ok (some (if upper then 69#u8 else 101#u8, suffix)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
intTail, suffix]
obtain ⟨expBytes, hsuffixDecomp, hexpMap⟩ :=
NumberHelperSplitExponentSuffix expSign suffixBytes expDigits hsuffixMap
have hexpByteDigits := byte_digits expBytes expDigits hexpMap hexpDigits
have hexpDigitMap : expBytes.map (fun b : Std.U8 => b.val - 48) =
expDigits := unrender_digits expBytes expDigits hexpMap hexpDigits
have hexpByteNeProp : expBytes ≠ [] := by
intro hempty
rw [hempty] at hexpDigitMap
simp at hexpDigitMap
exact hexpNe hexpDigitMap
have hexpByteNe : expBytes != [] := by
simpa only [bne_iff_ne] using hexpByteNeProp
have hsignByteMap :
(match expSign with
| none => ([] : List Std.U8)
| some negative => [if negative then 45#u8 else 43#u8]).map
(fun b : Std.U8 => b.val) =
(match expSign with
| none => []
| some negative => [if negative then 45 else 43]) := by
cases expSign with
| none => rfl
| some negative => cases negative <;> rfl
have hsuffixDecomp' : suffix.val =
(match expSign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expBytes := by
change suffixBytes = _
apply u8_list_eq_of_val_map
dsimp [expSign, expDigits] at hsignByteMap ⊢
rw [hsuffixMap, List.map_append, hsignByteMap, hexpMap]
rfl
obtain ⟨parsedExp, scientificRest, hscientific, hscientificRest,
hparsedExp⟩ := NumberHelperScientificExact suffix expSign expBytes
hexpByteNe hexpByteDigits hsuffixDecomp'
have hparsedExpValue : parsedExp.val =
if expSign = some true then
-((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
else ((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int) := by
rw [hparsedExp, guarded_fold_map, hexpDigitMap]
have hparsedExpTarget : parsedExp.val =
(match expSign with
| some true => -((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
| _ => ((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)) := by
rw [hparsedExpValue]
exact signed_if_eq_match expSign _
have hnotempty : Not (s.val = []) := by simpa using hne
have hnpos : 0 < nDigits.val := by
rw [hnDigitsEq]
have hintLen : intBytes.length = ints.length := by
have := congrArg List.length hintMap
simpa using this
rw [hintLen]
exact_mod_cast List.length_pos_of_ne_nil hsome
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,
Dec2Flt.configured_x86_64_numBits]
omega) (by
simp [IScalar.max, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits] at hb ⊢
omega))
rw [hz]
congr 2
apply IScalar.eq_of_val_eq
simpa using hzval
have haddExp : (0#i64 + parsedExp) = ok parsedExp := by
have hb : IScalar.min .I64 <= (0#i64).val + parsedExp.val /\
(0#i64).val + parsedExp.val <= IScalar.max .I64 := by
have hp := IScalar.hBounds parsedExp
rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
norm_num at hp ⊢
omega
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec hb.1 hb.2)
rw [hz]
congr 2
apply IScalar.eq_of_val_eq
norm_num at hzval
exact hzval
obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
NumberHelperOffsetSourceLength s scientificRest hlen (by
simp [hscientificRest])
have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
ok (Slice.len s) := by
have hbound : 0 <= fullOffset.val /\
fullOffset.val <= UScalar.max .Usize := by
rw [hfullOffsetVal, hscientificRest]
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
rw [hz]
congr 2
apply UScalar.eq_of_val_eq
rw [hfullOffsetVal, hscientificRest] at hzval
simpa [Slice.len_val] using hzval
simp [num.imp.dec2flt.parse.parse_number,
num.imp.dec2flt.parse.parse_partial_number, hnotempty, hscan,
hoffInt, haddzero, hnpos.ne', hsplitMarker, hscientific,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch, haddExp, hoffFull, hfullCast] at hparse
cases hupper : upper <;>
simp [hupper, hsplitMarker, hscientific,
UScalar.ofNatCore,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch, ModelOptionFromResidual,
haddExp, hoffFull, hfullCast] at hparse
all_goals
have hdigitMap : intBytes.map (fun b : Std.U8 => b.val - 48) = ints :=
unrender_digits intBytes ints hintMap hints
have hfoldEq : intBytes.foldl digitStep 0 =
ints.foldl natStep 0 := by
rw [fold_map, hdigitMap]
by_cases hsmall : nDigits.val <= 19
· simp [haddzero, hnpos.ne', hsmall] at hparse
have hfoldLt : intBytes.foldl digitStep 0 <
10 ^ intBytes.length := by
simpa using fold_upper intBytes 0 hintDigits
have hfoldBound : intBytes.foldl digitStep 0 <= U64.max := by
have hlen19 : intBytes.length <= 19 := by
omega
have hpow : 10 ^ intBytes.length <= 10 ^ 19 :=
Nat.pow_le_pow_right (by norm_num) hlen19
have hlt : intBytes.foldl digitStep 0 < 10 ^ 19 :=
hfoldLt.trans_le hpow
rw [U64.max_eq]
norm_num
omega
obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
intTail.val (by simpa [intTail] using hsdecomp) hintDigits
hintTailNotDigit hlen (by simpa [digitStep] using hfoldBound)
have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
rw [hscan] at hexactScan
simp at hexactScan
rcases hexactScan with ⟨rfl, rfl⟩
simpa [digitStep] using hexactValue
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa, hfoldEq, hparsedExpTarget]
rfl
· 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,
Dec2Flt.configured_x86_64_numBits] 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 [haddzero, hnpos.ne', hsmall, hnMore] at hparse
obtain ⟨zeros, sigTail, hintZeros, hzeros, hsigTail⟩ :=
split_zeros intBytes hintDigits
let rawTail : List Std.U8 := sigTail ++ intTail.val
have hsAdjust : s.val = zeros ++ rawTail := by
rw [hsdecomp, hintZeros]
simp [rawTail, intTail, List.append_assoc]
have hrawTailSharp : rawTail = [] \/ exists b rest,
rawTail = b :: rest /\ b ≠ 48#u8 /\ b ≠ 46#u8 := by
rcases hsigTail with hnil | ⟨b, restTail, htailEq, hb⟩
· right
refine ⟨if upper then 69#u8 else 101#u8, suffixBytes,
?_, ?_, ?_⟩
· simp [rawTail, hnil, intTail]
· norm_num [hupper, UScalar.ofNatCore]
· norm_num [hupper, UScalar.ofNatCore]
· right
refine ⟨b, restTail ++ intTail.val, ?_, ?_, ?_⟩
· simp [rawTail, htailEq]
· simpa only [bne_iff_ne] using hb
· have hbdigit := hintDigits b (by
rw [hintZeros, htailEq]
exact List.mem_append_right zeros List.mem_cons_self)
intro hpoint
subst b
norm_num at hbdigit
have hcount : zeros.count 48#u8 = zeros.length :=
count_zeros zeros hzeros
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, hnDigitsEq, hsdecomp]
simp only [List.length_append]
omega
have hadjustLower : IScalar.min .Isize <=
nMore.val - (zeros.count 48#u8 : Int) := by
rw [hnMoreVal, hcount, hnDigitsEq]
have hzerosLen : zeros.length <= intBytes.length := by
rw [hintZeros]
simp
simp [IScalar.min, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
NumberHelperAdjustManyExact s nMore zeros rawTail hsAdjust (by
intro b hb
exact Or.inl (hzeros b hb)) hrawTailSharp hlen hnMoreNonneg
hnMoreLe hadjustLower
rw [hadjust] at hparse
by_cases hpositive : 0 < adjusted.val
· simp [hpositive] at hparse
cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
parsedExp with
| fail err => simp [hmany] at hparse
| div => simp [hmany] at hparse
| ok result =>
rcases result with ⟨manyMantissa, manyExponent⟩
simp [hmany] at hparse
have hsigTailLen : 19 < sigTail.length := by
rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
rw [hintZeros] at hpositive
simp only [List.length_append] at hpositive
omega
have hsigTailCons : exists first tailRest,
sigTail = first :: tailRest /\
first ≠ 48#u8 /\ first ≠ 46#u8 := by
rcases hsigTail with hnil | hcons
· rw [hnil] at hsigTailLen
simp at hsigTailLen
· rcases hcons with ⟨b, restTail, hbEq, hbNe⟩
refine ⟨b, restTail, hbEq, ?_, ?_⟩
· simpa only [bne_iff_ne] using hbNe
· have hbdigit := hintDigits b (by
rw [hintZeros, hbEq]
exact List.mem_append_right zeros List.mem_cons_self)
intro hpoint
subst b
norm_num at hbdigit
rcases hsigTailCons with
⟨first, tailRest, htailEq, hfirstNe, hfirstPoint⟩
have hfirstDigit := hintDigits first (by
rw [hintZeros, htailEq]
exact List.mem_append_right zeros List.mem_cons_self)
have hthreshold : 1000000000000000000 <=
intBytes.foldl digitStep 0 := by
have hzero := zero_fold zeros hzeros
have hlower := fold_lower tailRest (first.val - 48)
rw [hintZeros, List.foldl_append, hzero, htailEq,
List.foldl_cons]
change 1000000000000000000 <=
tailRest.foldl digitStep (digitStep 0 first)
have hfirstPos : 1 <= first.val - 48 := by
have hneVal : first.val ≠ 48 := by
intro h
apply hfirstNe
apply UScalar.eq_of_val_eq
simpa using h
omega
have hpowLower : 1000000000000000000 <=
10 ^ tailRest.length := by
have hlenRest : 18 <= tailRest.length := by
rw [htailEq] at hsigTailLen
simp only [List.length_cons] at hsigTailLen
omega
have hp := Nat.pow_le_pow_right
(by norm_num : 0 < 10) hlenRest
norm_num at hp ⊢
exact hp
have hstep : 10 ^ tailRest.length <=
(first.val - 48) * 10 ^ tailRest.length := by
nlinarith
exact hpowLower.trans (hstep.trans (by
simpa [digitStep] using hlower))
obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
hmanyExponent⟩ := NumberHelperIntegralManyExact s intTail
parsedExp manyExponent manyMantissa intBytes intTail.val
(by simpa [intTail] using hsdecomp) rfl hintDigits
hintTailNotDigit hlen hthreshold hmany
subst d
have hresult := finish_value
(num.imp.dec2flt.decimal.Decimal.mk manyExponent
manyMantissa false true)
intBytes ints parsedExp.val hdigitMap hints
(Or.inr ⟨rfl, consumed, remaining, hpartition,
hmanyMantissa, hmanyExponent⟩)
simpa [DecimalGoalVocabularyDefault, natStep, hparsedExpTarget,
expSign, expDigits] using hresult
· simp [hpositive] at hparse
have hsigTailLen : sigTail.length <= 19 := by
rw [hadjustVal, hnMoreVal, hnDigitsEq, hcount] at hpositive
rw [hintZeros] at hpositive
simp only [List.length_append] at hpositive
omega
have hsigTailDigits : forall b, List.Mem b sigTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hintDigits b
rw [hintZeros]
exact List.mem_append_right zeros hb
have hzero := zero_fold zeros hzeros
have hfoldLtTail : sigTail.foldl digitStep 0 <
10 ^ sigTail.length := by
simpa using fold_upper sigTail 0 hsigTailDigits
have hfoldLt : intBytes.foldl digitStep 0 < 10 ^ 19 := by
rw [hintZeros, List.foldl_append, hzero]
exact hfoldLtTail.trans_le
(Nat.pow_le_pow_right (by norm_num) hsigTailLen)
have hfoldBound : intBytes.foldl digitStep 0 <= U64.max := by
rw [U64.max_eq]
norm_num
omega
obtain ⟨exactMantissa, exactRest, hexactScan, hexactRest,
hexactValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
intTail.val (by simpa [intTail] using hsdecomp) hintDigits
hintTailNotDigit hlen
(by simpa [digitStep] using hfoldBound)
have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
rw [hscan] at hexactScan
simp at hexactScan
rcases hexactScan with ⟨rfl, rfl⟩
simpa [digitStep] using hexactValue
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa, hfoldEq, hparsedExpTarget]
rfl
| some fracs =>
simp at hfrac hsome
cases expo with
| none =>
simp at hbytes hexpo
obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
List.map_eq_append_iff.mp hbytes
obtain ⟨point, fracBytes, hafterVal, hpointVal, hfracMap⟩ :=
List.map_eq_cons_iff.mp hafterMap
have hpoint : point = 46#u8 := by
apply UScalar.eq_of_val_eq
simpa using hpointVal
subst point
have hsdecomp : s.val = intBytes ++ 46#u8 :: fracBytes := by
rw [hsval, hafterVal]
have hintDigits := byte_digits intBytes ints hintMap hints
have hfracDigits := byte_digits fracBytes fracs hfracMap hfrac
have hintTailProp : (46#u8 :: fracBytes).length <= Usize.max := by
have hp := s.property
rw [hsdecomp] at hp
simp only [List.length_append] at hp
omega
let intTail : Slice Std.U8 := ⟨46#u8 :: fracBytes, hintTailProp⟩
have hintTailNotDigit : forall b rest, intTail.val = b :: rest ->
Not (48 <= b.val /\ b.val <= 57) := by
intro b rest hb
simp [intTail] at hb
rcases hb with ⟨rfl, _⟩
norm_num
obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
(by simpa [intTail] using hsdecomp) hintDigits
hintTailNotDigit hlen
have hintRestEq : intRest = intTail :=
(Slice.eq_iff _ _).2 (by simpa using hintRest)
subst intRest
obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
NumberHelperOffsetSourceLength s intTail hlen (by
rw [hsdecomp]
simp [intTail])
have hnDigitsEq : nDigits.val = intBytes.length := by
rw [hnDigitsVal, hsdecomp]
simp [intTail]
have hfracProp : fracBytes.length <= Usize.max := by
have hp := intTail.property
simp [intTail] at hp ⊢
omega
let fracSlice : Slice Std.U8 := ⟨fracBytes, hfracProp⟩
have hsplitPoint : core.slice.Slice.split_first intTail =
ok (some (46#u8, fracSlice)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
intTail, fracSlice]
obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
NumberHelperDigitScanSourceLength fracSlice mantissa fracBytes []
(by simp [fracSlice]) hfracDigits (by simp) (by
simp [fracSlice]
rw [hsdecomp] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega)
let empty : Slice Std.U8 := ⟨[], by simp⟩
have hfracRestEq : fracRest = empty :=
(Slice.eq_iff _ _).2 (by simpa [empty] using hfracRest)
subst fracRest
obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
NumberHelperOffsetSourceLength fracSlice empty (by
simp [fracSlice]
rw [hsdecomp] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega) (by simp [empty])
have hnAfterEq : nAfter.val = fracBytes.length := by
rw [hnAfterVal]
simp [fracSlice, empty]
have hnAfterNotMin : nAfter.val ≠ IScalar.min .Isize := by
rw [hnAfterEq, IScalar.min]
simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits]
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
have hp := hlen
rw [hsdecomp] at hp
simp only [List.length_append, List.length_cons] at hp
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 hfracExponentEq : fracExponent.val = -(fracBytes.length : Int) := by
rw [hfracExponentVal, hnegAfterVal, hnAfterEq]
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,
Dec2Flt.configured_x86_64_numBits]
rw [hsdecomp] 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 hintLen : intBytes.length = ints.length := by
have hp := congrArg List.length hintMap
simpa using hp
have hfracLen : fracBytes.length = fracs.length := by
have hp := congrArg List.length hfracMap
simpa using hp
have htotalPos : 0 < totalDigits.val := by
rw [htotalVal, hnDigitsEq, hnAfterEq]
rcases hsome with hneInt | hneFrac
· have hp := List.length_pos_of_ne_nil hneInt
omega
· have hp := List.length_pos_of_ne_nil hneFrac
omega
obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
NumberHelperOffsetSourceLength s empty hlen (by simp [empty])
have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
ok (Slice.len s) := by
have hbound : 0 <= fullOffset.val /\
fullOffset.val <= UScalar.max .Usize := by
rw [hfullOffsetVal]
simp [empty, UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
rw [hz]
congr 2
apply UScalar.eq_of_val_eq
rw [hfullOffsetVal] at hzval
simpa [empty, Slice.len_val] using hzval
have hnotempty : Not (s.val = []) := by simpa using hne
have hsplitEmpty : core.slice.Slice.split_first empty = ok none := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst, empty]
unfold num.imp.dec2flt.parse.parse_number at hparse
simp [hnotempty] at hparse
unfold num.imp.dec2flt.parse.parse_partial_number at hparse
simp [hnotempty, hscanInt, hoffInt, hsplitPoint, hscanFrac,
hoffFrac, hnegAfter, hfracExponent] at hparse
norm_num at hparse
simp only [UScalar.ofNat, UScalar.ofNatCore] at hparse
simp [htotal, htotalPos, hsplitEmpty, hoffFull, hfullCast] at hparse
have hdigitInt : intBytes.map (fun b : Std.U8 => b.val - 48) = ints :=
unrender_digits intBytes ints hintMap hints
have hdigitFrac : fracBytes.map (fun b : Std.U8 => b.val - 48) =
fracs := unrender_digits fracBytes fracs hfracMap hfrac
have hsigMap : (intBytes ++ fracBytes).map
(fun b : Std.U8 => b.val - 48) = ints ++ fracs := by
simp [hdigitInt, hdigitFrac]
have hsigDigits : forall b, List.Mem b (intBytes ++ fracBytes) ->
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 hsigFoldEq : (intBytes ++ fracBytes).foldl digitStep 0 =
(ints ++ fracs).foldl natStep 0 := by
rw [fold_map, hsigMap]
have hfracExponentTarget : fracExponent.val = -(fracs.length : Int) := by
rw [hfracExponentEq, hfracLen]
have hexactScans : (intBytes ++ fracBytes).foldl digitStep 0 <=
U64.max ->
mantissa.val = intBytes.foldl digitStep 0 /\
mantissa1.val = (intBytes ++ fracBytes).foldl digitStep 0 := by
as_aux_lemma =>
intro hfullBound
have hprefixLe : intBytes.foldl digitStep 0 <=
(intBytes ++ fracBytes).foldl digitStep 0 := by
rw [List.foldl_append]
exact fold_ge_start fracBytes _
have hintBound : intBytes.foldl digitStep 0 <= U64.max :=
hprefixLe.trans hfullBound
obtain ⟨exactInt, exactIntRest, hexactInt, hexactIntRest,
hexactIntValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
intTail.val (by simpa [intTail] using hsdecomp) hintDigits
hintTailNotDigit hlen (by simpa [digitStep] using hintBound)
have hmantissa : mantissa.val = intBytes.foldl digitStep 0 := by
rw [hscanInt] at hexactInt
simp at hexactInt
rcases hexactInt with ⟨rfl, rfl⟩
simpa [digitStep] using hexactIntValue
have hfracBound : fracBytes.foldl digitStep mantissa.val <=
U64.max := by
rw [hmantissa, ← List.foldl_append]
exact hfullBound
obtain ⟨exactFrac, exactFracRest, hexactFrac, hexactFracRest,
hexactFracValue⟩ := NumberHelperDigitScanExact fracSlice mantissa
fracBytes [] (by simp [fracSlice]) hfracDigits (by simp) (by
simp [fracSlice]
rw [hsdecomp] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega) (by simpa [digitStep] using hfracBound)
have hmantissa1 : mantissa1.val =
(intBytes ++ fracBytes).foldl digitStep 0 := by
rw [hscanFrac] at hexactFrac
simp at hexactFrac
rcases hexactFrac with ⟨rfl, rfl⟩
rw [List.foldl_append, ← hmantissa]
simpa [digitStep] using hexactFracValue
exact ⟨hmantissa, hmantissa1⟩
by_cases hsmall : totalDigits.val <= 19
· simp [hsmall] at hparse
have hsigLen : (intBytes ++ fracBytes).length <= 19 := by
rw [List.length_append]
omega
have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
10 ^ (intBytes ++ fracBytes).length := by
simpa using fold_upper (intBytes ++ fracBytes) 0 hsigDigits
have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
U64.max := by
have hp := hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num) hsigLen)
have hpowMax : 10 ^ 19 <= U64.max := by
norm_num [U64.max_eq]
exact (Nat.le_of_lt hp).trans hpowMax
obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa1, hsigFoldEq, hfracExponentTarget,
List.foldl_append]
simp [natStep]
· have hlarge : 19 < totalDigits.val := by omega
have hsubBounds : IScalar.min .Isize <= totalDigits.val - 19 /\
totalDigits.val - 19 <= IScalar.max .Isize := by
have hb := IScalar.hBounds totalDigits
simp [IScalar.min, IScalar.max, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits] at hb ⊢
omega
obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.sub_spec (x := totalDigits) (y := 19#isize)
(by norm_num; omega) (by norm_num; omega))
norm_num at hnMoreVal
simp [hsmall, hnMore] at hparse
obtain ⟨rawZeros, rawTail, sigZeros, sigTail, hsRaw,
hrawZeros, hrawTail, hsSig, hsigZeros, hsigTailSharp, hcount⟩ :=
split_significand_zeros intBytes fracBytes [] hintDigits
hfracDigits (Or.inl rfl)
have hsAdjust : s.val = rawZeros ++ rawTail := by
rw [hsdecomp]
simpa using hsRaw
have hsigLenEq : intBytes.length + fracBytes.length =
sigZeros.length + sigTail.length := by
have hp := congrArg List.length hsSig
simpa using hp
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq, hsdecomp]
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 <=
(intBytes ++ fracBytes).length := by
rw [hsSig]
simp
simp [IScalar.min, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
NumberHelperAdjustManyExact s nMore rawZeros rawTail hsAdjust
hrawZeros hrawTail hlen hnMoreNonneg hnMoreLe hadjustLower
rw [hadjust] at hparse
by_cases hpositive : 0 < adjusted.val
· simp [hpositive] at hparse
cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
0#i64 with
| fail err => simp [hmany] at hparse
| div => simp [hmany] at hparse
| ok result =>
rcases result with ⟨manyMantissa, manyExponent⟩
simp [hmany] at hparse
have hsigTailLen : 19 < sigTail.length := by
rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
hnAfterEq] at hpositive
omega
have hsigTailCons : exists first tailRest,
sigTail = first :: tailRest /\ first ≠ 48#u8 := by
rcases hsigTailSharp with hnil | hcons
· rw [hnil] at hsigTailLen
simp at hsigTailLen
· exact hcons
rcases hsigTailCons with ⟨first, tailRest, htailEq, hfirstNe⟩
have hfirstDigit := hsigDigits first (by
rw [hsSig, htailEq]
exact List.mem_append_right sigZeros List.mem_cons_self)
have hthreshold : 1000000000000000000 <=
(intBytes ++ fracBytes).foldl digitStep 0 := by
have hzero := zero_fold sigZeros hsigZeros
have hlower := fold_lower tailRest (first.val - 48)
rw [hsSig, List.foldl_append, hzero, htailEq,
List.foldl_cons]
change 1000000000000000000 <=
tailRest.foldl digitStep (digitStep 0 first)
have hfirstPos : 1 <= first.val - 48 := by
have hneVal : first.val ≠ 48 := by
intro h
apply hfirstNe
apply UScalar.eq_of_val_eq
simpa using h
omega
have hpowLower : 1000000000000000000 <=
10 ^ tailRest.length := by
have hlenRest : 18 <= tailRest.length := by
rw [htailEq] at hsigTailLen
simp only [List.length_cons] at hsigTailLen
omega
have hp := Nat.pow_le_pow_right
(by norm_num : 0 < 10) hlenRest
norm_num at hp ⊢
exact hp
have hstep : 10 ^ tailRest.length <=
(first.val - 48) * 10 ^ tailRest.length := by
simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
hfirstPos
exact hpowLower.trans (hstep.trans (by
simpa [digitStep] using hlower))
obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
hmanyExponent⟩ := NumberHelperFractionalManyExact s intTail
0#i64 manyExponent manyMantissa intBytes fracBytes []
(by simpa [List.append_assoc] using hsdecomp)
(by simp [intTail]) hintDigits hfracDigits (by simp) hlen
hthreshold hmany
have hmanyExponentTarget : manyExponent.val =
-(fracs.length : Int) + remaining.length := by
rw [hmanyExponent, hfracLen]
norm_num
subst d
have hresult := finish_value
(num.imp.dec2flt.decimal.Decimal.mk manyExponent
manyMantissa false true)
(intBytes ++ fracBytes) (ints ++ fracs)
(-(fracs.length : Int)) hsigMap (by
intro digit hdigit
rcases List.mem_append.mp hdigit with hdigit | hdigit
· exact hints digit hdigit
· exact hfrac digit hdigit)
(Or.inr ⟨rfl, consumed, remaining, hpartition,
hmanyMantissa, hmanyExponentTarget⟩)
simpa [DecimalGoalVocabularyDefault, natStep,
List.foldl_append] using hresult
· simp [hpositive] at hparse
have hsigTailLen : sigTail.length <= 19 := by
rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
hnAfterEq] at hpositive
omega
have hsigTailDigits : forall b, List.Mem b sigTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hsigDigits b
rw [hsSig]
exact List.mem_append_right sigZeros hb
have hzero := zero_fold sigZeros hsigZeros
have hfoldLtTail : sigTail.foldl digitStep 0 <
10 ^ sigTail.length := by
simpa using fold_upper sigTail 0 hsigTailDigits
have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
10 ^ 19 := by
rw [hsSig, List.foldl_append, hzero]
exact hfoldLtTail.trans_le
(Nat.pow_le_pow_right (by norm_num) hsigTailLen)
have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
U64.max := by
have hpowMax : 10 ^ 19 <= U64.max := by
norm_num [U64.max_eq]
exact (Nat.le_of_lt hfoldLt).trans hpowMax
obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa1, hsigFoldEq, hfracExponentTarget,
List.foldl_append]
simp [natStep]
| some e =>
let upper : Bool := e.1
let expSign : Option Bool := e.2.1
let expDigits : List Nat := e.2.2
change expDigits ≠ [] /\
(forall digit, List.Mem digit expDigits -> digit < 10) at hexpo
rcases hexpo with ⟨hexpNe, hexpDigits⟩
simp [upper, expSign, expDigits] at hbytes
obtain ⟨intBytes, afterInt, hsval, hintMap, hafterMap⟩ :=
List.map_eq_append_iff.mp hbytes
obtain ⟨point, afterPoint, hafterVal, hpointVal, hafterPointMap⟩ :=
List.map_eq_cons_iff.mp hafterMap
have hpoint : point = 46#u8 := by
apply UScalar.eq_of_val_eq
simpa using hpointVal
subst point
obtain ⟨fracBytes, afterFrac, hafterPointVal, hfracMap,
hafterFracMap⟩ := List.map_eq_append_iff.mp hafterPointMap
obtain ⟨marker, suffixBytes, hafterFracVal, hmarkerVal, hsuffixMap⟩ :=
List.map_eq_cons_iff.mp hafterFracMap
have hmarker : marker = if upper then 69#u8 else 101#u8 := by
by_cases hu : upper = true
· rw [if_pos hu]
apply UScalar.eq_of_val_eq
simpa [hu, upper] using hmarkerVal
· rw [if_neg hu]
apply UScalar.eq_of_val_eq
simpa [hu, upper] using hmarkerVal
subst marker
have hsdecomp : s.val = intBytes ++ 46#u8 ::
(fracBytes ++ (if upper then 69#u8 else 101#u8) :: suffixBytes) := by
rw [hsval, hafterVal, hafterPointVal, hafterFracVal]
have hintDigits := byte_digits intBytes ints hintMap hints
have hfracDigits := byte_digits fracBytes fracs hfracMap hfrac
have hmarkerTailProp :
((if upper then 69#u8 else 101#u8) :: suffixBytes).length <=
Usize.max := by
have hp := s.property
rw [hsdecomp] at hp
simp only [List.length_append, List.length_cons] at hp ⊢
omega
let markerTail : Slice Std.U8 :=
⟨(if upper then 69#u8 else 101#u8) :: suffixBytes,
hmarkerTailProp⟩
have hmarkerTailNotDigit : forall b rest,
markerTail.val = b :: rest ->
Not (48 <= b.val /\ b.val <= 57) := by
intro b rest hb
simp [markerTail] at hb
rcases hb with ⟨rfl, _⟩
by_cases hu : upper = true
· simp [hu]
· have hu' : upper = false := Bool.eq_false_of_not_eq_true hu
simp [hu']
have hintTailProp :
(46#u8 :: (fracBytes ++ markerTail.val)).length <= Usize.max := by
have hp := s.property
rw [hsdecomp] at hp
simp [markerTail] at hp ⊢
omega
let intTail : Slice Std.U8 :=
⟨46#u8 :: (fracBytes ++ markerTail.val), hintTailProp⟩
have hstart : s.val = intBytes ++ 46#u8 ::
(fracBytes ++ markerTail.val) := by
simpa [markerTail] using hsdecomp
have hintTailNotDigit : forall b rest, intTail.val = b :: rest ->
Not (48 <= b.val /\ b.val <= 57) := by
intro b rest hb
simp [intTail] at hb
rcases hb with ⟨rfl, _⟩
norm_num
obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 intBytes intTail.val
hstart hintDigits hintTailNotDigit hlen
have hintRestEq : intRest = intTail :=
(Slice.eq_iff _ _).2 (by simpa using hintRest)
subst intRest
obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
NumberHelperOffsetSourceLength s intTail hlen (by
rw [hstart]
simp [intTail])
have hnDigitsEq : nDigits.val = intBytes.length := by
rw [hnDigitsVal, hstart]
simp [intTail]
have hfracSliceProp : (fracBytes ++ markerTail.val).length <=
Usize.max := by
have hp := intTail.property
simp [intTail] at hp ⊢
omega
let fracSlice : Slice Std.U8 :=
⟨fracBytes ++ markerTail.val, hfracSliceProp⟩
have hsplitPoint : core.slice.Slice.split_first intTail =
ok (some (46#u8, fracSlice)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
intTail, fracSlice]
obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
NumberHelperDigitScanSourceLength fracSlice mantissa fracBytes
markerTail.val (by simp [fracSlice]) hfracDigits
hmarkerTailNotDigit (by
simp [fracSlice]
rw [hstart] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega)
have hfracRestEq : fracRest = markerTail :=
(Slice.eq_iff _ _).2 (by simpa using hfracRest)
subst fracRest
obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
NumberHelperOffsetSourceLength fracSlice markerTail (by
simp [fracSlice]
rw [hstart] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega) (by simp [fracSlice])
have hnAfterEq : nAfter.val = fracBytes.length := by
rw [hnAfterVal]
simp [fracSlice]
have hnAfterNotMin : nAfter.val ≠ IScalar.min .Isize := by
rw [hnAfterEq, IScalar.min]
simp [IScalarTy.numBits, Dec2Flt.configured_x86_64_numBits]
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
have hp := hlen
rw [hstart] at hp
simp only [List.length_append, List.length_cons] at hp
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 hfracExponentEq : fracExponent.val = -(fracBytes.length : Int) := by
rw [hfracExponentVal, hnegAfterVal, hnAfterEq]
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,
Dec2Flt.configured_x86_64_numBits]
rw [hstart] 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 hintLen : intBytes.length = ints.length := by
have hp := congrArg List.length hintMap
simpa using hp
have hfracLen : fracBytes.length = fracs.length := by
have hp := congrArg List.length hfracMap
simpa using hp
have htotalPos : 0 < totalDigits.val := by
rw [htotalVal, hnDigitsEq, hnAfterEq]
rcases hsome with hneInt | hneFrac
· have hp := List.length_pos_of_ne_nil hneInt
omega
· have hp := List.length_pos_of_ne_nil hneFrac
omega
have hsuffixProp : suffixBytes.length <= Usize.max := by
have hp := markerTail.property
simp [markerTail] at hp
omega
let suffix : Slice Std.U8 := ⟨suffixBytes, hsuffixProp⟩
have hsplitMarker : core.slice.Slice.split_first markerTail =
ok (some (if upper then 69#u8 else 101#u8, suffix)) := by
simp [core.slice.Slice.split_first, ModelSliceSplitFirst,
markerTail, suffix]
obtain ⟨expBytes, hsuffixDecomp, hexpMap⟩ :=
NumberHelperSplitExponentSuffix expSign suffixBytes expDigits hsuffixMap
have hexpByteDigits := byte_digits expBytes expDigits hexpMap hexpDigits
have hexpDigitMap : expBytes.map (fun b : Std.U8 => b.val - 48) =
expDigits := unrender_digits expBytes expDigits hexpMap hexpDigits
have hexpByteNeProp : expBytes ≠ [] := by
intro hempty
rw [hempty] at hexpDigitMap
simp at hexpDigitMap
exact hexpNe hexpDigitMap
have hexpByteNe : expBytes != [] := by
simpa only [bne_iff_ne] using hexpByteNeProp
have hsignByteMap :
(match expSign with
| none => ([] : List Std.U8)
| some negative => [if negative then 45#u8 else 43#u8]).map
(fun b : Std.U8 => b.val) =
(match expSign with
| none => []
| some negative => [if negative then 45 else 43]) := by
cases expSign with
| none => rfl
| some negative => cases negative <;> rfl
have hsuffixDecomp' : suffix.val =
(match expSign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expBytes := by
change suffixBytes = _
apply u8_list_eq_of_val_map
dsimp [expSign, expDigits] at hsignByteMap ⊢
rw [hsuffixMap, List.map_append, hsignByteMap, hexpMap]
rfl
obtain ⟨parsedExp, scientificRest, hscientific, hscientificRest,
hparsedExp⟩ := NumberHelperScientificExact suffix expSign expBytes
hexpByteNe hexpByteDigits hsuffixDecomp'
have hparsedExpValue : parsedExp.val =
if expSign = some true then
-((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
else ((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int) := by
rw [hparsedExp, guarded_fold_map, hexpDigitMap]
have hparsedExpTarget : parsedExp.val =
(match expSign with
| some true => -((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)
| _ => ((expDigits.foldl
(fun a digit => if a < 65536 then 10 * a + digit else a) 0 : Nat) : Int)) := by
rw [hparsedExpValue]
exact signed_if_eq_match expSign _
obtain ⟨fullOffset, hoffFull, hfullOffsetVal⟩ :=
NumberHelperOffsetSourceLength s scientificRest hlen (by
simp [hscientificRest])
have hfullCast : lift (IScalar.hcast .Usize fullOffset) =
ok (Slice.len s) := by
have hbound : 0 <= fullOffset.val /\
fullOffset.val <= UScalar.max .Usize := by
rw [hfullOffsetVal, hscientificRest]
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨z, hz, hzval⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize fullOffset hbound)
rw [hz]
congr 2
apply UScalar.eq_of_val_eq
rw [hfullOffsetVal, hscientificRest] at hzval
simpa [Slice.len_val] using hzval
have hnotempty : Not (s.val = []) := by simpa using hne
unfold num.imp.dec2flt.parse.parse_number at hparse
simp [hnotempty] at hparse
unfold num.imp.dec2flt.parse.parse_partial_number at hparse
simp [hnotempty, hscanInt, hoffInt, hsplitPoint, hscanFrac,
hoffFrac, hnegAfter, hfracExponent] at hparse
norm_num at hparse
simp only [UScalar.ofNat, UScalar.ofNatCore] at hparse
cases hupper : upper <;>
simp [hupper, htotal, htotalPos, hsplitMarker, hscientific,
hoffFull, hfullCast, UScalar.ofNatCore,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
ModelOptionBranch, ModelOptionFromResidual] at hparse
all_goals
cases hsum : fracExponent + parsedExp with
| fail err => simp [hsum] at hparse
| div => simp [hsum] at hparse
| ok combinedExponent =>
simp [hsum] at hparse
have hcombinedVal : combinedExponent.val =
fracExponent.val + parsedExp.val := by
have h := IScalar.add_equiv fracExponent parsedExp
rw [hsum] at h
exact h.2.1
have hdigitInt : intBytes.map (fun b : Std.U8 => b.val - 48) =
ints := unrender_digits intBytes ints hintMap hints
have hdigitFrac : fracBytes.map (fun b : Std.U8 => b.val - 48) =
fracs := unrender_digits fracBytes fracs hfracMap hfrac
have hsigMap : (intBytes ++ fracBytes).map
(fun b : Std.U8 => b.val - 48) = ints ++ fracs := by
simp [hdigitInt, hdigitFrac]
have hsigDigits : forall b, List.Mem b (intBytes ++ fracBytes) ->
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 hsigFoldEq : (intBytes ++ fracBytes).foldl digitStep 0 =
(ints ++ fracs).foldl natStep 0 := by
rw [fold_map, hsigMap]
have hcombinedExponentTarget : combinedExponent.val =
parsedExp.val - (fracs.length : Int) := by
rw [hcombinedVal, hfracExponentEq, hfracLen]
omega
have hexactScans : (intBytes ++ fracBytes).foldl digitStep 0 <=
U64.max ->
mantissa.val = intBytes.foldl digitStep 0 /\
mantissa1.val = (intBytes ++ fracBytes).foldl digitStep 0 := by
as_aux_lemma =>
intro hfullBound
have hprefixLe : intBytes.foldl digitStep 0 <=
(intBytes ++ fracBytes).foldl digitStep 0 := by
rw [List.foldl_append]
exact fold_ge_start fracBytes _
have hintBound : intBytes.foldl digitStep 0 <= U64.max :=
hprefixLe.trans hfullBound
obtain ⟨exactInt, exactIntRest, hexactInt, hexactIntRest,
hexactIntValue⟩ := NumberHelperDigitScanExact s 0#u64 intBytes
intTail.val hstart hintDigits hintTailNotDigit hlen
(by simpa [digitStep] using hintBound)
have hmantissa : mantissa.val =
intBytes.foldl digitStep 0 := by
rw [hscanInt] at hexactInt
simp at hexactInt
rcases hexactInt with ⟨rfl, rfl⟩
simpa [digitStep] using hexactIntValue
have hfracBound : fracBytes.foldl digitStep mantissa.val <=
U64.max := by
rw [hmantissa, ← List.foldl_append]
exact hfullBound
obtain ⟨exactFrac, exactFracRest, hexactFrac, hexactFracRest,
hexactFracValue⟩ := NumberHelperDigitScanExact fracSlice
mantissa fracBytes markerTail.val (by simp [fracSlice])
hfracDigits hmarkerTailNotDigit (by
simp [fracSlice]
rw [hstart] at hlen
simp only [List.length_append, List.length_cons] at hlen
omega) (by simpa [digitStep] using hfracBound)
have hmantissa1 : mantissa1.val =
(intBytes ++ fracBytes).foldl digitStep 0 := by
rw [hscanFrac] at hexactFrac
simp at hexactFrac
rcases hexactFrac with ⟨rfl, rfl⟩
rw [List.foldl_append, ← hmantissa]
simpa [digitStep] using hexactFracValue
exact ⟨hmantissa, hmantissa1⟩
by_cases hsmall : totalDigits.val <= 19
· simp [hsmall] at hparse
have hsigLen : (intBytes ++ fracBytes).length <= 19 := by
rw [List.length_append]
omega
have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
10 ^ (intBytes ++ fracBytes).length := by
simpa using fold_upper (intBytes ++ fracBytes) 0 hsigDigits
have hfullBound : (intBytes ++ fracBytes).foldl digitStep 0 <=
U64.max := by
have hp := hfoldLt.trans_le
(Nat.pow_le_pow_right (by norm_num) hsigLen)
have hpowMax : 10 ^ 19 <= U64.max := by
norm_num [U64.max_eq]
exact (Nat.le_of_lt hp).trans hpowMax
obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa1, hsigFoldEq, hcombinedExponentTarget,
List.foldl_append]
simp [natStep, hparsedExpTarget, expSign, expDigits]
all_goals exact Or.inl rfl
· have hlarge : 19 < totalDigits.val := by omega
have hsubBounds : IScalar.min .Isize <= totalDigits.val - 19 /\
totalDigits.val - 19 <= IScalar.max .Isize := by
have hb := IScalar.hBounds totalDigits
simp [IScalar.min, IScalar.max, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits] at hb ⊢
omega
obtain ⟨nMore, hnMore, hnMoreVal⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.sub_spec (x := totalDigits) (y := 19#isize)
(by norm_num; omega) (by norm_num; omega))
norm_num at hnMoreVal
simp [hsmall, hnMore] at hparse
obtain ⟨rawZeros, rawTail, sigZeros, sigTail, hsRaw,
hrawZeros, hrawTail, hsSig, hsigZeros, hsigTailSharp,
hcount⟩ := split_significand_zeros intBytes fracBytes
markerTail.val hintDigits hfracDigits (by
right
refine ⟨if upper then 69#u8 else 101#u8, suffixBytes,
by simp [markerTail], ?_, ?_⟩
· simp [hupper]
· simp [hupper])
have hsAdjust : s.val = rawZeros ++ rawTail := by
rw [hstart]
simpa using hsRaw
have hsigLenEq : intBytes.length + fracBytes.length =
sigZeros.length + sigTail.length := by
have hp := congrArg List.length hsSig
simpa using hp
have hnMoreNonneg : 0 <= nMore.val := by
rw [hnMoreVal]
omega
have hnMoreLe : nMore.val <= s.val.length := by
rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq, hstart]
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 <=
(intBytes ++ fracBytes).length := by
rw [hsSig]
simp
simp [IScalar.min, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨adjusted, hadjust, hadjustVal⟩ :=
NumberHelperAdjustManyExact s nMore rawZeros rawTail hsAdjust
hrawZeros hrawTail hlen hnMoreNonneg hnMoreLe hadjustLower
rw [hadjust] at hparse
by_cases hpositive : 0 < adjusted.val
· simp [hpositive] at hparse
cases hmany : num.imp.dec2flt.parse.parse_many_digits s intTail
parsedExp with
| fail err => simp [hmany] at hparse
| div => simp [hmany] at hparse
| ok result =>
rcases result with ⟨manyMantissa, manyExponent⟩
simp [hmany] at hparse
have hsigTailLen : 19 < sigTail.length := by
rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
hnAfterEq] at hpositive
omega
have hsigTailCons : exists first tailRest,
sigTail = first :: tailRest /\ first ≠ 48#u8 := by
rcases hsigTailSharp with hnil | hcons
· rw [hnil] at hsigTailLen
simp at hsigTailLen
· exact hcons
rcases hsigTailCons with
⟨first, tailRest, htailEq, hfirstNe⟩
have hfirstDigit := hsigDigits first (by
rw [hsSig, htailEq]
exact List.mem_append_right sigZeros List.mem_cons_self)
have hthreshold : 1000000000000000000 <=
(intBytes ++ fracBytes).foldl digitStep 0 := by
have hzero := zero_fold sigZeros hsigZeros
have hlower := fold_lower tailRest (first.val - 48)
rw [hsSig, List.foldl_append, hzero, htailEq,
List.foldl_cons]
change 1000000000000000000 <=
tailRest.foldl digitStep (digitStep 0 first)
have hfirstPos : 1 <= first.val - 48 := by
have hneVal : first.val ≠ 48 := by
intro h
apply hfirstNe
apply UScalar.eq_of_val_eq
simpa using h
omega
have hpowLower : 1000000000000000000 <=
10 ^ tailRest.length := by
have hlenRest : 18 <= tailRest.length := by
rw [htailEq] at hsigTailLen
simp only [List.length_cons] at hsigTailLen
omega
have hp := Nat.pow_le_pow_right
(by norm_num : 0 < 10) hlenRest
norm_num at hp ⊢
exact hp
have hstep : 10 ^ tailRest.length <=
(first.val - 48) * 10 ^ tailRest.length := by
simpa using Nat.mul_le_mul_right (10 ^ tailRest.length)
hfirstPos
exact hpowLower.trans (hstep.trans (by
simpa [digitStep] using hlower))
obtain ⟨consumed, remaining, hpartition, hmanyMantissa,
hmanyExponent⟩ := NumberHelperFractionalManyExact s
intTail parsedExp manyExponent manyMantissa intBytes
fracBytes markerTail.val hstart (by simp [intTail])
hintDigits hfracDigits hmarkerTailNotDigit hlen
hthreshold hmany
have hmanyExponentTarget : manyExponent.val =
parsedExp.val - (fracs.length : Int) +
remaining.length := by
rw [hmanyExponent, hfracLen]
subst d
have hresult := finish_value
(num.imp.dec2flt.decimal.Decimal.mk manyExponent
manyMantissa false true)
(intBytes ++ fracBytes) (ints ++ fracs)
(parsedExp.val - (fracs.length : Int)) hsigMap (by
intro digit hdigit
rcases List.mem_append.mp hdigit with hdigit | hdigit
· exact hints digit hdigit
· exact hfrac digit hdigit)
(Or.inr ⟨rfl, consumed, remaining, hpartition,
hmanyMantissa, hmanyExponentTarget⟩)
simpa [DecimalGoalVocabularyDefault, natStep,
List.foldl_append, hparsedExpTarget, expSign, expDigits]
using hresult
· simp [hpositive] at hparse
have hsigTailLen : sigTail.length <= 19 := by
rw [hadjustVal, hnMoreVal, hcount, htotalVal, hnDigitsEq,
hnAfterEq] at hpositive
omega
have hsigTailDigits : forall b, List.Mem b sigTail ->
48 <= b.val /\ b.val <= 57 := by
intro b hb
apply hsigDigits b
rw [hsSig]
exact List.mem_append_right sigZeros hb
have hzero := zero_fold sigZeros hsigZeros
have hfoldLtTail : sigTail.foldl digitStep 0 <
10 ^ sigTail.length := by
simpa using fold_upper sigTail 0 hsigTailDigits
have hfoldLt : (intBytes ++ fracBytes).foldl digitStep 0 <
10 ^ 19 := by
rw [hsSig, List.foldl_append, hzero]
exact hfoldLtTail.trans_le
(Nat.pow_le_pow_right (by norm_num) hsigTailLen)
have hfullBound :
(intBytes ++ fracBytes).foldl digitStep 0 <= U64.max := by
have hpowMax : 10 ^ 19 <= U64.max := by
norm_num [U64.max_eq]
exact (Nat.le_of_lt hfoldLt).trans hpowMax
obtain ⟨hmantissa, hmantissa1⟩ := hexactScans hfullBound
subst d
left
refine ⟨rfl, ?_⟩
norm_num
rw [hmantissa1, hsigFoldEq, hcombinedExponentTarget,
List.foldl_append]
simp [natStep, hparsedExpTarget, expSign, expDigits]
all_goals exact Or.inl rfl
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
- Assumptions
- DecimalGoalVocabularyDefault
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceSplitFirst
- ModelU64BitAnd
All 37 entries
- Assumptions
- DecimalGoalVocabularyDefault
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceSplitFirst
- ModelU64BitAnd
- ModelU64BitOr
- ModelU8IsAsciiDigit
- NumberHelperAdjustManyExact
- NumberHelperDecimalPrefixInterval
- NumberHelperDigitScanExact
- NumberHelperDigitScanSourceLength
- NumberHelperFractionalManyExact
- NumberHelperIntegralManyExact
- NumberHelperOffsetSourceLength
- NumberHelperParseEightDigitsExact
- NumberHelperScientificExact
- NumberHelperSplitExponentSuffix
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- SourceValidByteSlice
- U64 Insts CoreOpsBitBitAndU64U64
- U64 Insts CoreOpsBitBitOrU64U64
- num imp dec2flt common is 8digits
- num imp dec2flt decimal Decimal
- 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 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
Used by
Inspect related source (71)
- offset_from · dec2flt/common.rs:30 Program Rust
- read_u64 · dec2flt/common.rs:18 Program Rust
- is_8digits · dec2flt/common.rs:40 Program Rust
More program dependencies (36)
- Decimal · dec2flt/decimal.rs:32 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
- MASK · dec2flt/parse.rs:19 Program Rust
- MUL1 · dec2flt/parse.rs:20 Program Rust
- MUL2 · dec2flt/parse.rs:21 Program Rust
- parse_many_digits · dec2flt/parse.rs:104 Program Rust
- parse_number · dec2flt/parse.rs:231 Program Rust
- parse_partial_number · dec2flt/parse.rs:161 Program Rust
- parse_scientific · dec2flt/parse.rs:121 Program Rust
- parse_scientific_loop · dec2flt/parse.rs:142 Program Rust
- body · dec2flt/parse.rs:142 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
- from_u64 · dec2flt/mod.rs:263 Program Rust
- FloatErrorKind · num/mod.rs:18 Program Rust
- ParseFloatError · num/mod.rs:13 Program Rust
- Dec2FltAssemblyTrace · dec2flt/mod.rs:329 Program Rust
- Dec2FltTrace · dec2flt/mod.rs:295 Program Rust
- Lemire · dec2flt/mod.rs:115 Program Rust
- BiasedFp · dec2flt/common.rs:52 Program Rust
- ByteSlice · dec2flt/common.rs:4 Program Rust
- DecimalSeq · dec2flt/decimal_seq.rs:21 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
Standard-library dependencies (32)
- bitand · core/src/ops/bit.rs:178 Rust library
- bitor · core/src/ops/bit.rs:282 Rust library
- is_ascii_digit · core/src/num/mod.rs:958 Rust library
- from_residual · core/src/option.rs:2793 Rust library
- branch · core/src/option.rs:2779 Rust library
- 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
- 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
- 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
- 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
Related source and models come from the extraction records and declared dependencies.
Proof assumptions and review
Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.
Transitive assumptions
- Classical.choice
- Dec2Flt.configured_x86_64_numBits
- Quot.sound
- propext
This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.
Helper theorems included
All 65 entries
- Binary64Model
- Binary64ModelDefault
- DecimalGoalVocabulary
- DecimalGoalVocabularyDefault
- DecimalLexeme
- F64
- ModelF64Classify
- ModelF64Clone
- ModelF64Div
- ModelF64ExponentMask
- ModelF64FromBits
- ModelF64FromU64
- ModelF64Infinity
- ModelF64MantissaDigits
- ModelF64MantissaMask
- ModelF64Mul
- ModelF64Nan
- ModelF64Neg
- ModelF64NegInfinity
- ModelF64ToBits
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceFirst
- ModelSliceSplitFirst
- ModelStrAsBytes
- ModelU64BitAnd
- ModelU64BitOr
- ModelU64Shl
- ModelU64Shr
- ModelU8IsAsciiDigit
- NumberHelperAccumulatedValue
- NumberHelperAdjustManyExact
- NumberHelperDecimalPrefixInterval
- NumberHelperDigitScanExact
- NumberHelperDigitScanSourceLength
- NumberHelperEightDigitWord
- NumberHelperFractionalManyExact
- NumberHelperIntegralManyExact
- NumberHelperOffsetSourceLength
- NumberHelperParseEightDigitsExact
- NumberHelperParseEightDigitsSafe
- NumberHelperReadEightBytes
- NumberHelperScientificExact
- NumberHelperSplitExponentSuffix
- NumberHelperTryParse19SafeLength
- Preamble
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from
- SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64
- SourceValidByteSlice
- core num FpCategory
- num imp dec2flt common BiasedFp
- num imp dec2flt common is 8digits
- num imp dec2flt decimal Decimal
- 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 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
Technical checking records
Local closure summary
{
"node": "NumberHelperAccumulatedValue",
"closure_version": "patch_c_v1",
"active_decl_hash": "0d058b5420bf1d17e8ba8efb8581bab09071e82838e6357a36002016ae6ed899",
"active_statement_hash": "28314528aea932a6d5b9409aa3d7e4af58d4aee38e436cc9622e1be0d889d9f0",
"kernel_axioms": [
"Classical.choice",
"Dec2Flt.configured_x86_64_numBits",
"Quot.sound",
"propext"
],
"toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
"lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
"checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
"approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
"axcheck_status": "Agreed",
"accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-139",
"boundary_theorems": {},
"strict_theorem_deps": {
"DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
"ModelSliceSplitFirst": "f617ee05dd2925a9",
"NumberHelperAdjustManyExact": "8999fa99d4681219",
"NumberHelperDecimalPrefixInterval": "5c32858414034b55",
"NumberHelperDigitScanExact": "6bcf20c61d10dea3",
"NumberHelperDigitScanSourceLength": "8892b939bba0ecf9",
"NumberHelperFractionalManyExact": "4f108f0f2477fa14",
"NumberHelperIntegralManyExact": "4b76d387097e136b",
"NumberHelperOffsetSourceLength": "de0168dfeba3b802",
"NumberHelperScientificExact": "85d7c23c40290390",
"NumberHelperSplitExponentSuffix": "36f92cf2e9d9f766",
"num_imp_dec2flt_parse_parse_partial_number": "854af4cc12136a58"
},
"strict_definition_deps": {
"DecimalGoalVocabulary": "0717fd246d7ea78a",
"DecimalGoalVocabularyDefault": "512f8d0aea894250",
"DecimalLexeme": "303e59678842cea4",
"F64": "ec4e25fbaf4e11d4",
"ModelOptionBranch": "c55e273482c8c0a1",
"ModelOptionFromResidual": "6d48ecfbc617744f",
"NumberHelperSplitExponentSuffix": "3a789d080d66f335",
"Preamble": "7754ffaf671693bf",
"SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830",
"SourceValidByteSlice": "3dc42716a6378d26",
"num_imp_dec2flt_common_BiasedFp": "31d81cf1cf22709f",
"num_imp_dec2flt_decimal_Decimal": "c43614ff2149ecf2",
"num_imp_dec2flt_parse_adjust_many_digit_count": "4e59e3776b6cfdaa",
"num_imp_dec2flt_parse_parse_many_digits": "50c9ef13b3ed7fe8",
"num_imp_dec2flt_parse_parse_number": "f73f8bc11faa6db3",
"num_imp_dec2flt_parse_parse_partial_number": "5712e484f99eb7aa",
"num_imp_dec2flt_parse_parse_scientific": "447f722d5841d2c5",
"num_imp_dec2flt_parse_try_parse_digits": "238b4a73cd46fc56"
}
}Prose assessment
{
"label": "Recorded Sound: VerifierPass",
"assessment_status": "VerifierPass",
"fingerprint_relation": "matches current fingerprint",
"assessment_fingerprint": "sound-v2:25911d09519d5e4a5c06d02dda402a63783a5a7c12af3dc02e5856891ff73e3b",
"current_fingerprint": "sound-v2:25911d09519d5e4a5c06d02dda402a63783a5a7c12af3dc02e5856891ff73e3b",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}