Statement
This explanation was written alongside the formalization to describe the statement and its reasoning.
Lemma · Safe partial-number parsing of an invalid unsigned input
parse_partial_number returns normally. Moreover, whenever its
return is Some of a decimal record and consumed length, that length
is not the full input length.Lean statement
Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.
import Tablet.NumberHelperDigitScanSourceLength
import Tablet.NumberHelperOffsetSourceLength
import Tablet.NumberHelperAdjustManySourceLength
import Tablet.NumberHelperIntegralManyDigitsSourceLength
import Tablet.NumberHelperFractionalManyDigitsSourceLength
import Tablet.NumberHelperScientificPrefixSafeLength
import Tablet.NumberHelperScientificClassificationSourceLength
import Tablet.NumberHelperScientificExponentBounds
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.ModelSliceSplitFirst
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.num_imp_dec2flt_parse_parse_partial_number
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 800000
set_option maxRecDepth 10000
namespace dec2flt_model
-- [TABLET NODE: NumberHelperPartialNumberSafeLength]
theorem NumberHelperPartialNumberSafeLength :
forall s : Slice Std.U8,
SourceValidByteSlice s -> s.val != [] ->
s.val.length <= 9223372036854120459 ->
(Not (exists x : DecimalLexeme,
x.leadingSign = none /\
DecimalGoalVocabularyDefault.validNumeric x /\
DecimalGoalVocabularyDefault.bytes s =
DecimalGoalVocabularyDefault.renderNumeric x)) ->
exists o,
num.imp.dec2flt.parse.parse_partial_number s = ok o /\
forall (d : num.imp.dec2flt.decimal.Decimal) (r : Std.Usize),
o = some (d, r) -> Not (r = Slice.len s) := 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
usize and isize are 64-bit. Thus
L\leq B<M; every input length and guarded index below fits
usize, and every cast of a length to nonnegative isize is
exact. By SourceValidByteSlice, the separate source-validity
premise is compatible with this stronger bound. The last premise, using
the definitions in DecimalGoalVocabularyDefault, says precisely
that the whole input is not a valid unsigned numeric rendering.0x46, 0x30, and
0x80. Let d_i be the borrow entering byte i of subtraction by
0x30, initially zero. If the test is true, the high bit of every
result byte is zero. Inductively, b_i<48 would give a subtraction result
in [208,255], a contradiction; hence there is no outgoing borrow and
48\leq b_i\leq175. Let c_i be the carry entering byte i of addition
by 0x46, again initially zero. Under the preceding bound,
b_i\geq58 would give a result in [128,245], a contradiction. Thus there
is no outgoing carry and 48\leq b_i\leq57. These two inductions cover all
eight bytes, including cross-byte carries and borrows.0x30 has no borrow and produces a word v'<2^{60}. The checked
multiplication by ten is below 10\cdot2^{60}<2^{64}. The checked shift by
eight is defined and below 2^{52}, so the following checked addition is
below 10\cdot2^{60}+2^{52}<2^{64}. Its shifts by 16 and 32 are also
defined; intervening masked products and their addition are wrapping. The
word after the final right shift is at most 2^{32}-1, so its checked cast
to u32, and the widening back to u64, are exact.u64 cast is exact, and the
checked count increment remains at most the slice length. The final suffix
therefore starts at an in-bounds count. This establishes normal termination
of a digit scan on arbitrary bytes, not just on digit-only slices, and also
shows that its returned slice is a suffix of its argument consisting of the
unconsumed bytes.i64 is exact. The checked addition producing
D is safe. If D=0, the function returns None normally.e or E,
there is no explicit-exponent arithmetic. Otherwise unfold
num imp dec2flt parse parse scientific. Removing an optional sign
is guarded. An empty signed suffix, or a nondigit first byte, returns
None normally. The option branch and residual operations modeled
by ModelOptionBranch and ModelOptionFromResidual then
make the partial parser return None normally.isize.
After i index-advancing iterations, let z_i be the number of visited zero
digits. Induction over the point and zero branches gives
ok of some option.
Suppose this option were Some with consumed length L. The scans
then provide at least one significand digit; a point, if present, occurs in
its single scanned position; and an exponent, if present, has its marker,
optional sign, and at least one scanned digit. Translating each digit byte
48+d back to d<10 constructs a DecimalLexeme with
leadingSign = None, satisfying
DecimalGoalVocabularyDefault. Full consumption makes its rendered
bytes exactly s. This contradicts the assumed absence of such a lexeme.
Therefore every Some result has consumed length different from the
full input length, as required.Lean proof
intro s hsource hne hlen hinvalid
have hsourceLen : s.val.length <= 9223372036854775807 := by
simp [SourceValidByteSlice] at hsource
exact hsource
have split_digits : forall bs : List Std.U8,
exists digits tail,
bs = digits ++ tail /\
(forall b, List.Mem b digits -> 48 <= b.val /\ b.val <= 57) /\
(forall b rest, tail = b :: rest ->
Not (48 <= b.val /\ b.val <= 57)) := by
intro bs
induction bs with
| nil => exact ⟨[], [], rfl, (by intro b hb; cases hb),
(by intro b rest h; cases h)⟩
| cons b bs ih =>
by_cases hb : 48 <= b.val /\ b.val <= 57
· obtain ⟨digits, tail, hbs, hdigits, htail⟩ := ih
refine ⟨b :: digits, tail, ?_, ?_, htail⟩
· simp [hbs]
· intro c hc
rcases List.mem_cons.mp hc with rfl | hc
· exact hb
· exact hdigits c hc
· exact ⟨[], b :: bs, rfl, (by intro c hc; cases hc), by
intro c rest h
cases h
exact hb⟩
let scientific_sign : List Std.U8 -> Option Bool := fun bs =>
match bs with
| [] => none
| b :: _ => if b = 45#u8 then some true
else if b = 43#u8 then some false else none
let scientific_body : List Std.U8 -> List Std.U8 := fun bs =>
match bs with
| [] => []
| b :: rest => if b = 45#u8 \/ b = 43#u8 then rest else b :: rest
have scientific_split : forall bs : List Std.U8,
bs = (match scientific_sign bs with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
scientific_body bs := by
intro bs
cases bs with
| nil => simp [scientific_sign, scientific_body]
| cons b rest =>
by_cases hm : b = 45#u8
· subst b
simp [scientific_sign, scientific_body]
· by_cases hp : b = 43#u8
· subst b
simp [scientific_sign, scientific_body]
· simp [scientific_sign, scientific_body, hm, hp]
have scientific_unsigned : forall bs : List Std.U8,
scientific_sign bs = none -> forall b rest,
scientific_body bs = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
intro bs
cases bs with
| nil => simp [scientific_body]
| cons b rest =>
by_cases hm : b = 45#u8
· subst b
simp [scientific_sign]
· by_cases hp : b = 43#u8
· subst b
simp [scientific_sign, hm]
· simp only [scientific_sign, scientific_body, hm, hp, if_false,
or_false]
intro _ c cs h
injection h with hbc _
subst c
exact ⟨hm, hp⟩
have render_digits : forall bs : List Std.U8,
(forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
List.map (fun b : Std.U8 => b.val) bs =
List.map (fun d : Nat => 48 + d)
(List.map (fun b : Std.U8 => b.val - 48) bs) := by
intro bs hbs
induction bs with
| nil => rfl
| cons b bs ih =>
have hb := hbs b List.mem_cons_self
have hrest : forall c, List.Mem c bs -> 48 <= c.val /\ c.val <= 57 := by
intro c hc
exact hbs c (List.mem_cons_of_mem b hc)
simp [ih hrest]
omega
have complete_spelling : forall (integer : List Std.U8)
(fraction : Option (List Std.U8))
(expo : Option (Bool × Option Bool × List Std.U8)),
(forall b, List.Mem b integer -> 48 <= b.val /\ b.val <= 57) ->
(match fraction with
| none => True
| some ds => forall b, List.Mem b ds ->
48 <= b.val /\ b.val <= 57) ->
(integer != [] \/
match fraction with | none => False | some ds => ds != []) ->
(match expo with
| none => True
| some (_, _, ds) => ds != [] /\
forall b, List.Mem b ds -> 48 <= b.val /\ b.val <= 57) ->
s.val = integer ++
(match fraction with | none => [] | some ds => 46#u8 :: ds) ++
(match expo with
| none => []
| some (upper, sign, ds) =>
(if upper then 69#u8 else 101#u8) ::
(match sign with
| none => []
| some neg => [if neg then 45#u8 else 43#u8]) ++ ds) ->
False := by
intro integer fraction expo hint hfrac hsome hexpo hs
apply hinvalid
let x : DecimalLexeme := {
leadingSign := none
integerDigits := integer.map (fun b => b.val - 48)
fractionDigits := fraction.map
(fun ds => ds.map (fun b => b.val - 48))
exponent := expo.map (fun e =>
(e.1, e.2.1, e.2.2.map (fun b => b.val - 48)))
}
refine ⟨x, rfl, ?_, ?_⟩
· simp [DecimalGoalVocabularyDefault, x]
constructor
· intro d hd
have := hint d hd
omega
constructor
· cases fraction with
| none => simp
| some fs =>
simp only [Option.map_some]
intro d hd
obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hd
have := hfrac b hb
omega
constructor
· cases fraction <;> simpa using hsome
· cases expo with
| none => simp
| some e =>
rcases e with ⟨upper, sign, es⟩
simp at hexpo ⊢
refine ⟨hexpo.1, ?_⟩
intro d hd
have := hexpo.2 d hd
omega
· simp [DecimalGoalVocabularyDefault, x]
rw [hs]
simp only [List.map_append, List.map_cons]
have hintRender :
List.map ((fun d : Nat => 48 + d) ∘
fun b : Std.U8 => b.val - 48) integer =
List.map (fun b : Std.U8 => b.val) integer := by
simpa [List.map_map] using (render_digits integer hint).symm
rw [hintRender]
cases fraction with
| none =>
simp only [Option.map_none]
simp at hfrac
cases expo with
| none => simp
| some e =>
rcases e with ⟨upper, sign, es⟩
simp only [Option.map_some, List.map_map]
simp at hexpo ⊢
have hexpRender :
List.map ((fun d : Nat => 48 + d) ∘
fun b : Std.U8 => b.val - 48) es =
List.map (fun b : Std.U8 => b.val) es := by
simpa [List.map_map] using (render_digits es hexpo.2).symm
rw [hexpRender]
cases upper <;> cases sign with
| none => norm_num
| some neg => cases neg <;> norm_num
| some fs =>
simp only [Option.map_some, List.map_map]
simp at hfrac
have hfracRender :
List.map ((fun d : Nat => 48 + d) ∘
fun b : Std.U8 => b.val - 48) fs =
List.map (fun b : Std.U8 => b.val) fs := by
simpa [List.map_map] using (render_digits fs hfrac).symm
rw [hfracRender]
cases expo with
| none => simp
| some e =>
rcases e with ⟨upper, sign, es⟩
simp only [Option.map_some, List.map_map]
simp at hexpo ⊢
have hexpRender :
List.map ((fun d : Nat => 48 + d) ∘
fun b : Std.U8 => b.val - 48) es =
List.map (fun b : Std.U8 => b.val) es := by
simpa [List.map_map] using (render_digits es hexpo.2).symm
rw [hexpRender]
cases upper <;> cases sign with
| none => norm_num
| some neg => cases neg <;> norm_num
obtain ⟨integer, intTailBytes, hsval, hintDigits, hintTail⟩ :=
split_digits s.val
obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 integer intTailBytes
hsval hintDigits hintTail hsourceLen
obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
NumberHelperOffsetSourceLength s intRest hsourceLen (by
rw [hintRest, hsval]
simp)
have hnDigitsEq : nDigits.val = integer.length := by
rw [hnDigitsVal, hintRest, hsval]
simp
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 hnotempty : Not (s.val = []) := by simpa using hne
cases htailEq : intTailBytes with
| nil =>
have hintegerNeProp : integer ≠ [] := by
intro hi
rw [hi, htailEq] at hsval
simp at hsval
exact hnotempty hsval
have hintegerNe : integer != [] := by
simpa only [bne_iff_ne] using hintegerNeProp
exact False.elim (complete_spelling integer none none hintDigits (by
simp) (by left; exact hintegerNe) (by simp) (by
simpa [htailEq] using hsval))
| cons c cs =>
have hintRestVal : intRest.val = c :: cs := by simpa [htailEq] using hintRest
have hcsProp : cs.length <= Usize.max := by
have hp := intRest.property
rw [hintRestVal] at hp
simp only [List.length_cons] at hp
omega
let afterFirst : Slice Std.U8 := ⟨cs, hcsProp⟩
have h46Target : (46#u8 : Std.U8) = 46#uscalar := by
apply UScalar.eq_of_val_eq
rfl
have h101Target : (101#u8 : Std.U8) = 101#uscalar := by
apply UScalar.eq_of_val_eq
rfl
have h69Target : (69#u8 : Std.U8) = 69#uscalar := by
apply UScalar.eq_of_val_eq
rfl
have hsplitInt : core.slice.Slice.split_first intRest =
ok (some (c, afterFirst)) := by
have hirest : intRest = (⟨c :: cs, by simpa [hintRestVal] using
intRest.property⟩ : Slice Std.U8) := (Slice.eq_iff _ _).2 hintRestVal
rw [hirest]
simp [core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst,
afterFirst]
by_cases hpoint : c = 46#u8
· subst c
obtain ⟨fraction, fracTail, hcs, hfracDigits, hfracTail⟩ :=
split_digits cs
have hafterVal : afterFirst.val = fraction ++ fracTail := by
simp [afterFirst, hcs]
have hafterLen : afterFirst.val.length <= 9223372036854775807 := by
rw [hafterVal]
rw [hsval, htailEq, hcs] at hlen
simp at hlen
rw [List.length_append]
omega
obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
NumberHelperDigitScanSourceLength afterFirst mantissa fraction fracTail
hafterVal hfracDigits hfracTail hafterLen
obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
NumberHelperOffsetSourceLength afterFirst fracRest hafterLen (by
rw [hfracRest, hafterVal]
simp)
have hnAfterEq : nAfter.val = fraction.length := by
rw [hnAfterVal, hfracRest, hafterVal]
simp
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
rw [hnegAfterVal, hnAfterEq,
IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
have hl := hlen
rw [hsval, htailEq, hcs] at hl
simp at hl
constructor <;> omega
obtain ⟨fracExponent, hfracExponent, hfracExponentVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.cast_inBounds_spec .I64 negAfter hnegCastBounds)
have htotalBounds : IScalar.min .Isize <= nDigits.val + nAfter.val /\
nDigits.val + nAfter.val <= IScalar.max .Isize := by
rw [hnDigitsEq, hnAfterEq]
simp [IScalar.min, IScalar.max, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits]
have hl := hlen
rw [hsval, htailEq, hcs] at hl
simp at hl
constructor <;> omega
obtain ⟨totalDigits, htotal, htotalVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec htotalBounds.1 htotalBounds.2)
by_cases htotalZero : totalDigits = 0#isize
· unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac, hoffFrac,
hnegAfter, hfracExponent, htotal, htotalZero]
norm_num
simp only [UScalar.ofNat, UScalar.ofNatCore]
simp [htotal, htotalZero]
· have htotalPos : 0 < totalDigits.val := by
have hb := IScalar.hBounds totalDigits
have hz : totalDigits.val ≠ 0 := by
intro hv
apply htotalZero
apply IScalar.eq_of_val_eq
simpa using hv
rw [htotalVal, hnDigitsEq, hnAfterEq] at hz ⊢
omega
have hsome : integer != [] \/ fraction != [] := by
simp only [bne_iff_ne]
by_contra hnone
push_neg at hnone
rcases hnone with ⟨hi, hf⟩
subst integer
subst fraction
rw [htotalVal, hnDigitsEq, hnAfterEq] at htotalPos
norm_num at htotalPos
cases htailCase : fracTail with
| nil =>
exact False.elim (complete_spelling integer (some fraction) none
hintDigits (by simpa using hfracDigits) hsome (by simp) (by
rw [hsval, htailEq, hcs, htailCase]
simp [List.append_assoc]))
| cons q qs =>
have hqsProp : qs.length <= Usize.max := by
have hp := fracRest.property
rw [hfracRest, htailCase] at hp
simp at hp ⊢
omega
let afterFrac : Slice Std.U8 := ⟨qs, hqsProp⟩
have hsplitFrac : core.slice.Slice.split_first fracRest =
ok (some (q, afterFrac)) := by
have hr : fracRest = (⟨q :: qs, by
rw [← htailCase, ← hfracRest]
exact fracRest.property⟩ : Slice Std.U8) :=
(Slice.eq_iff _ _).2 (by simpa [htailCase] using hfracRest)
rw [hr]
simp [core.slice.Slice.split_first,
dec2flt_model.ModelSliceSplitFirst, afterFrac]
by_cases hfracMarker : q = 101#u8 \/ q = 69#u8
· obtain ⟨upper, hmarkerByte⟩ : exists upper : Bool,
q = if upper then 69#u8 else 101#u8 := by
rcases hfracMarker with hq | hq
· exact ⟨false, by simpa using hq⟩
· exact ⟨true, by simpa using hq⟩
let sign := scientific_sign qs
let expBody := scientific_body qs
have hqsSign : qs =
(match sign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expBody := by
exact scientific_split qs
have hunsigned : sign = none -> forall b rest,
expBody = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
exact scientific_unsigned qs
obtain ⟨expDigits, expTail, hbody, hexpDigits, hexpTail⟩ :=
split_digits expBody
have hsci : afterFrac.val =
(match sign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expDigits ++ expTail := by
change qs = _
rw [hqsSign, hbody, List.append_assoc]
obtain hnoexp | hexp :=
NumberHelperScientificClassificationSourceLength afterFrac sign
expDigits expTail hexpDigits hexpTail hsci (by
intro hd hs b rest ht
apply hunsigned hs b rest
rw [hbody, hd]
simpa using ht)
· rcases hnoexp with ⟨_, rest, hscientific⟩
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
hsplitFrac]
norm_num
simp only [UScalar.ofNat, UScalar.ofNatCore]
cases upper <;>
simp at hmarkerByte <;>
subst q <;>
simp [htotal, htotalPos, hsplitFrac, h101Target, h69Target,
hscientific,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
dec2flt_model.ModelOptionBranch,
dec2flt_model.ModelOptionFromResidual]
· rcases hexp with ⟨hexpNe, parsedExp, sciRest, hscientific,
hsciRest, hexplo, hexphi, hexpshort, hexpnonnegative⟩
cases htailExp : expTail with
| nil =>
exact False.elim (complete_spelling integer (some fraction)
(some (upper, sign, expDigits)) hintDigits hfracDigits hsome
⟨hexpNe, hexpDigits⟩ (by
rw [hsval, htailEq, hcs, htailCase, hmarkerByte,
hqsSign, hbody, htailExp]
simp [List.append_assoc]))
| cons z zs =>
obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
NumberHelperOffsetSourceLength s sciRest hsourceLen (by
rw [hsciRest, htailExp]
have hl := congrArg List.length hsval
rw [htailEq, hcs, htailCase, hqsSign, hbody, htailExp] at hl
simp at hl ⊢
omega)
have hcastBounds : 0 <= consumed.val /\
consumed.val <= UScalar.max .Usize := by
rw [hconsumedVal]
have hrestLe : sciRest.val.length <= s.val.length := by
rw [hsciRest, htailExp]
have hl := congrArg List.length hsval
rw [htailEq, hcs, htailCase, hqsSign, hbody, htailExp] at hl
simp at hl ⊢
omega
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨len, hcastLen, hlenVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
have hlenNe : len ≠ Slice.len s := by
intro heq
have heqv : (len.val : Int) = s.val.length := by
have h := congrArg UScalar.val heq
simpa [Slice.len_val] using h
have hrestPos : 0 < sciRest.val.length := by
rw [hsciRest, htailExp]
simp
have hlenConsumed : (len.val : Int) = consumed.val := by
norm_num at hlenVal
exact hlenVal
rw [hconsumedVal] at hlenConsumed
omega
have hsuffixLenEq : qs.length =
(match sign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]).length +
(expDigits.length + expTail.length) := by
have hl := congrArg List.length hqsSign
rw [hbody] at hl
simpa using hl
have hcombinedBounds : IScalar.min .I64 <=
fracExponent.val + parsedExp.val /\
fracExponent.val + parsedExp.val <= IScalar.max .I64 := by
have hparts := hlen
rw [hsval, htailEq, hcs, htailCase] at hparts
simp only [List.length_append, List.length_cons] at hparts
rw [hfracExponentVal, hnegAfterVal, hnAfterEq,
IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
constructor
· by_cases hshort : expDigits.length <= 5
· have hsharp := hexpshort hshort
omega
· have hq : 6 <= expDigits.length := by omega
by_cases hnegative : sign = some true
· simp [hnegative] at hsuffixLenEq
rw [htailExp] at hsuffixLenEq
simp at hsuffixLenEq
omega
· have hnonnegative := hexpnonnegative hnegative
omega
· omega
obtain ⟨combinedExponent, hcombinedExponent,
hcombinedExponentVal⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec hcombinedBounds.1 hcombinedBounds.2)
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
hsplitFrac]
norm_num
simp only [UScalar.ofNat, UScalar.ofNatCore]
cases upper <;>
simp at hmarkerByte <;>
subst q <;>
simp [htotal, htotalPos, hsplitFrac, h101Target, h69Target,
hscientific, hcombinedExponent, hoffConsumed, hcastLen,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
dec2flt_model.ModelOptionBranch,
dec2flt_model.ModelOptionFromResidual]
all_goals
by_cases hsmall : totalDigits.val <= 19
· refine ⟨some ({
exponent := combinedExponent
mantissa := mantissa1
negative := false
many_digits := false
}, len), ?_, ?_⟩
· simp [hsmall]
· intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hsmall]
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 simpa using hsubBounds.1)
(by simpa using hsubBounds.2))
rw [hnMore]
simp
obtain ⟨adjusted, hadjusted⟩ :=
NumberHelperAdjustManySourceLength s nMore hsourceLen (by
norm_num at hnMoreVal
omega) (by
norm_num at hnMoreVal
rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq]
have hl := congrArg List.length hsval
rw [htailEq, hcs] at hl
simp at hl
omega)
rw [hadjusted]
by_cases hpositive : 0 < adjusted.val
· simp [hpositive]
obtain ⟨mantissa2, exponent2, hmany⟩ :=
NumberHelperFractionalManyDigitsSourceLength s intRest
parsedExp integer fraction fracTail (by
simpa [htailEq, hcs, List.append_assoc] using hsval)
(by simpa [htailEq, hcs] using hintRest) hintDigits
hfracDigits hfracTail hsourceLen (by
have hb := hcombinedBounds.1
rw [hfracExponentVal, hnegAfterVal, hnAfterEq] at hb
simpa [IScalar.min_IScalarTy_I64_eq, I64.min_eq]
using hb) (by
rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
have hl := hlen
rw [hsval, htailEq, hcs] at hl
simp at hl
omega)
rw [hmany]
refine ⟨some ({
exponent := exponent2
mantissa := mantissa2
negative := false
many_digits := true
}, len), rfl, ?_⟩
intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hpositive]
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· have hq101 : q ≠ 101#u8 := by tauto
have hq69 : q ≠ 69#u8 := by tauto
obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
NumberHelperOffsetSourceLength s fracRest hsourceLen (by
have hsLenEq := congrArg List.length hsval
rw [htailEq, hcs, htailCase] at hsLenEq
rw [hfracRest, htailCase]
simp at hsLenEq ⊢
omega)
have hrestLe : fracRest.val.length <= s.val.length := by
have hsLenEq := congrArg List.length hsval
rw [htailEq, hcs, htailCase] at hsLenEq
rw [hfracRest, htailCase]
simp at hsLenEq ⊢
omega
have hcastBounds : 0 <= consumed.val /\
consumed.val <= UScalar.max .Usize := by
rw [hconsumedVal]
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨len, hcastLen, hlenVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
have hlenEq : len.val = integer.length + 1 + fraction.length := by
norm_num at hlenVal
rw [hconsumedVal, hsval, htailEq, hcs, hfracRest, htailCase]
at hlenVal
simp at hlenVal
omega
have hlenNe : len ≠ Slice.len s := by
intro heq
have heqv := congrArg UScalar.val heq
simp [Slice.len_val, hlenEq, hsval, htailEq, hcs, htailCase]
at heqv
omega
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
hsplitFrac, hq101, hq69, hoffConsumed, hcastLen]
norm_num
simp only [UScalar.ofNat, UScalar.ofNatCore]
simp [htotal, htotalPos, hsplitFrac, hq101, hq69,
hoffConsumed, hcastLen]
split <;> try contradiction
split <;> try contradiction
split
· rename_i hsmall
refine ⟨some ({
exponent := fracExponent
mantissa := mantissa1
negative := false
many_digits := false
}, len), ?_, ?_⟩
· rfl
· intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· rename_i hsmall
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 simpa using hsubBounds.1)
(by simpa using hsubBounds.2))
rw [hnMore]
simp
obtain ⟨adjusted, hadjusted⟩ :=
NumberHelperAdjustManySourceLength s nMore hsourceLen (by
norm_num at hnMoreVal
omega) (by
norm_num at hnMoreVal
rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq]
omega)
rw [hadjusted]
by_cases hpositive : 0 < adjusted.val
· simp [hpositive]
obtain ⟨mantissa2, exponent2, hmany⟩ :=
NumberHelperFractionalManyDigitsSourceLength s intRest
0#i64 integer fraction (q :: qs) (by
simpa [htailEq, hcs, htailCase, List.append_assoc]
using hsval) (by
simpa [htailEq, hcs, htailCase] using hintRest) hintDigits
hfracDigits (by
intro b rest h
exact hfracTail b rest (by simpa [htailCase] using h))
hsourceLen (by
rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq]
norm_num
have hl := hlen
rw [hsval, htailEq, hcs, htailCase] at hl
simp at hl
omega) (by
rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
norm_num
rw [htotalVal, hnDigitsEq, hnAfterEq] at hsmall
omega)
rw [hmany]
refine ⟨some ({
exponent := exponent2
mantissa := mantissa2
negative := false
many_digits := true
}, len), rfl, ?_⟩
intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hpositive]
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· cases c
rename_i cbv
let c : Std.U8 := @UScalar.mk .U8 cbv
have hcbv : cbv ≠ 46 := by
intro heq
subst cbv
exact hpoint (by rfl)
have hpointMatch :
(match (@UScalar.mk .U8 cbv) with
| 46#uscalar => do
let (s3, mantissa2) ←
num.imp.dec2flt.parse.try_parse_digits afterFirst mantissa
let nAfter ←
SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from
s3 afterFirst
let negAfter ← -. nAfter
let fracExponent ← lift (IScalar.cast .I64 negAfter)
ok (s3, mantissa2, nAfter, fracExponent)
| _ => ok (intRest, mantissa, 0#isize, 0#i64)) =
ok (intRest, mantissa, 0#isize, 0#i64) := by
split <;> try contradiction
all_goals rfl
by_cases hintegerEmpty : integer = []
· have hnzero : nDigits = 0#isize := by
apply IScalar.eq_of_val_eq
rw [hnDigitsEq, hintegerEmpty]
norm_num
have haddZeroZero : (0#isize + 0#isize) = ok 0#isize := by
simpa [hnzero] using haddZero
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt]
split <;> try contradiction
simp [haddZeroZero, hnzero]
· have hnpos : 0 < nDigits.val := by
rw [hnDigitsEq]
have := List.length_pos_of_ne_nil hintegerEmpty
omega
by_cases hmarker : c = 101#u8 \/ c = 69#u8
· obtain ⟨upper, hupper⟩ : exists upper : Bool,
c = if upper then 69#u8 else 101#u8 := by
rcases hmarker with hc | hc
· exact ⟨false, by simpa using hc⟩
· exact ⟨true, by simpa using hc⟩
have hmarkerByte : (@UScalar.mk .U8 cbv) =
if upper then 69#u8 else 101#u8 := by
simpa [c] using hupper
let sign := scientific_sign cs
let expBody := scientific_body cs
have hcsSign : cs =
(match sign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expBody := by
exact scientific_split cs
have hunsigned : sign = none -> forall b rest,
expBody = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
exact scientific_unsigned cs
obtain ⟨expDigits, expTail, hbody, hexpDigits, hexpTail⟩ :=
split_digits expBody
have hsci : afterFirst.val =
(match sign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expDigits ++ expTail := by
change cs = _
rw [hcsSign, hbody, List.append_assoc]
obtain hnoexp | hexp :=
NumberHelperScientificClassificationSourceLength afterFirst sign
expDigits expTail hexpDigits hexpTail hsci (by
intro hd hs b rest ht
apply hunsigned hs b rest
rw [hbody, hd]
simpa using ht)
· rcases hnoexp with ⟨_, rest, hscientific⟩
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt]
split <;> try contradiction
simp [haddZero, hnpos, hsplitInt]
cases upper with
| false =>
have hb := congrArg UScalar.bv hmarkerByte
simp at hb
subst cbv
simp [h101Target, h69Target, hscientific,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
dec2flt_model.ModelOptionBranch,
dec2flt_model.ModelOptionFromResidual]
| true =>
have hb := congrArg UScalar.bv hmarkerByte
simp at hb
subst cbv
simp [h101Target, h69Target, hscientific,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
dec2flt_model.ModelOptionBranch,
dec2flt_model.ModelOptionFromResidual]
· rcases hexp with ⟨hexpNe, parsedExp, sciRest, hscientific,
hsciRest, hexplo, hexphi, hexpshort, hexpnonnegative⟩
cases htailExp : expTail with
| nil =>
exact False.elim (complete_spelling integer none
(some (upper, sign, expDigits)) hintDigits (by simp)
(by left; simpa only [bne_iff_ne] using hintegerEmpty)
⟨hexpNe, hexpDigits⟩ (by
rw [hsval, htailEq, hmarkerByte, hcsSign, hbody, htailExp]
simp [List.append_assoc]))
| cons z zs =>
obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
NumberHelperOffsetSourceLength s sciRest hsourceLen (by
rw [hsciRest, htailExp]
have hl := congrArg List.length hsval
rw [htailEq, hcsSign, hbody, htailExp] at hl
simp at hl ⊢
omega)
have hcastBounds : 0 <= consumed.val /\
consumed.val <= UScalar.max .Usize := by
rw [hconsumedVal]
have hrestLe : sciRest.val.length <= s.val.length := by
rw [hsciRest, htailExp]
have hl := congrArg List.length hsval
rw [htailEq, hcsSign, hbody, htailExp] at hl
simp at hl ⊢
omega
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨len, hcastLen, hlenVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
have hlenNe : len ≠ Slice.len s := by
intro heq
have heqv : (len.val : Int) = s.val.length := by
have h := congrArg UScalar.val heq
simpa [Slice.len_val] using h
have hrestPos : 0 < sciRest.val.length := by
rw [hsciRest, htailExp]
simp
have hlenConsumed : (len.val : Int) = consumed.val := by
norm_num at hlenVal
exact hlenVal
rw [hconsumedVal] at hlenConsumed
omega
have haddBounds : IScalar.min .I64 <=
(0#i64).val + parsedExp.val /\
(0#i64).val + parsedExp.val <= IScalar.max .I64 := by
rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
norm_num
omega
obtain ⟨combined, haddExp, hcombinedVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec haddBounds.1 haddBounds.2)
have hcombined : combined = parsedExp := by
apply IScalar.eq_of_val_eq
norm_num at hcombinedVal
exact hcombinedVal
subst combined
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt]
split <;> try contradiction
simp [haddZero, hnpos, hsplitInt]
cases upper <;>
have hb := congrArg UScalar.bv hmarkerByte <;>
simp at hb <;>
subst cbv <;>
simp [h101Target, h69Target, hscientific, haddExp,
hoffConsumed, hcastLen,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
dec2flt_model.ModelOptionBranch,
dec2flt_model.ModelOptionFromResidual]
all_goals
by_cases hsmall : nDigits.val <= 19
· refine ⟨some ({
exponent := parsedExp
mantissa := mantissa
negative := false
many_digits := false
}, len), ?_, ?_⟩
· simp [hsmall]
· intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hsmall]
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 simpa using hsubBounds.1)
(by simpa using hsubBounds.2))
rw [hnMore]
simp
obtain ⟨adjusted, hadjusted⟩ :=
NumberHelperAdjustManySourceLength s nMore hsourceLen (by
norm_num at hnMoreVal
omega) (by
norm_num at hnMoreVal
rw [hnMoreVal, hnDigitsEq]
omega)
rw [hadjusted]
by_cases hpositive : 0 < adjusted.val
· simp [hpositive]
obtain ⟨mantissa2, exponent2, hmany⟩ :=
NumberHelperIntegralManyDigitsSourceLength s intRest
parsedExp nMore adjusted integer intTailBytes hsval
hintRest hintDigits hintTail (by
intro b rest h
rw [htailEq] at h
injection h with hbc _
subst b
exact hpoint) hsourceLen (by
norm_num at hnMoreVal
rw [hnMoreVal, hnDigitsEq]) hadjusted hpositive (by
rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
have hl := hlen
rw [hsval] at hl
simp at hl
omega)
rw [hmany]
refine ⟨some ({
exponent := exponent2
mantissa := mantissa2
negative := false
many_digits := true
}, len), rfl, ?_⟩
intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hpositive]
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· have hc101 : c ≠ 101#u8 := by tauto
have hc69 : c ≠ 69#u8 := by tauto
have hcbv101 : cbv ≠ (101 : BitVec 8) := by
intro heq
apply hc101
exact congrArg (fun v : BitVec 8 => (@UScalar.mk .U8 v)) heq
have hcbv69 : cbv ≠ (69 : BitVec 8) := by
intro heq
apply hc69
exact congrArg (fun v : BitVec 8 => (@UScalar.mk .U8 v)) heq
obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
NumberHelperOffsetSourceLength s intRest hsourceLen (by
rw [hintRest, hsval]
simp)
have hcastBounds : 0 <= consumed.val /\
consumed.val <= UScalar.max .Usize := by
rw [hconsumedVal]
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨len, hcastLen, hlenVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
have hlenEq : len.val = integer.length := by
norm_num at hlenVal
rw [hconsumedVal, hintRest, hsval] at hlenVal
simp at hlenVal
omega
have hlenNe : len ≠ Slice.len s := by
intro heq
have heqv := congrArg UScalar.val heq
simp [Slice.len_val, hlenEq, hsval, htailEq] at heqv
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt]
split <;> try contradiction
simp [haddZero, hnpos, hsplitInt, h101Target, h69Target, hc101,
hc69, hcbv101, hcbv69, hoffConsumed, hcastLen]
split <;> try contradiction
split <;> try contradiction
by_cases hsmall : nDigits.val <= 19
· refine ⟨some ({
exponent := 0#i64
mantissa := mantissa
negative := false
many_digits := false
}, len), ?_, ?_⟩
· simp [hsmall]
· intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hsmall]
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 simpa using hsubBounds.1)
(by simpa using hsubBounds.2))
rw [hnMore]
simp
obtain ⟨adjusted, hadjusted⟩ :=
NumberHelperAdjustManySourceLength s nMore hsourceLen (by
norm_num at hnMoreVal
omega) (by
norm_num at hnMoreVal
rw [hnMoreVal, hnDigitsEq, hsval]
simp
omega)
rw [hadjusted]
by_cases hpositive : 0 < adjusted.val
· simp [hpositive]
obtain ⟨mantissa2, exponent2, hmany⟩ :=
NumberHelperIntegralManyDigitsSourceLength s intRest 0#i64
nMore adjusted integer (c :: cs) (by
rw [htailEq] at hsval
simpa [c] using hsval) (by
rw [htailEq] at hintRest
simpa [c] using hintRest) hintDigits (by
intro b rest h
apply hintTail b rest
rw [htailEq]
simpa [c] using h) (by
intro b rest h
injection h with hbc _
subst b
simpa [c] using hpoint) hsourceLen (by
norm_num at hnMoreVal
rw [hnMoreVal, hnDigitsEq]) hadjusted hpositive (by
rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
norm_num
have hl := hlen
rw [hsval] at hl
simp at hl
omega)
rw [hmany]
refine ⟨some ({
exponent := exponent2
mantissa := mantissa2
negative := false
many_digits := true
}, len), rfl, ?_⟩
intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hpositive]
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
end dec2flt_model
Download Lean source · Download TeX source
Complete Lean module
import Tablet.NumberHelperDigitScanSourceLength
import Tablet.NumberHelperOffsetSourceLength
import Tablet.NumberHelperAdjustManySourceLength
import Tablet.NumberHelperIntegralManyDigitsSourceLength
import Tablet.NumberHelperFractionalManyDigitsSourceLength
import Tablet.NumberHelperScientificPrefixSafeLength
import Tablet.NumberHelperScientificClassificationSourceLength
import Tablet.NumberHelperScientificExponentBounds
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.ModelSliceSplitFirst
import Tablet.ModelOptionBranch
import Tablet.ModelOptionFromResidual
import Tablet.num_imp_dec2flt_parse_parse_partial_number
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
set_option maxHeartbeats 800000
set_option maxRecDepth 10000
namespace dec2flt_model
-- [TABLET NODE: NumberHelperPartialNumberSafeLength]
theorem NumberHelperPartialNumberSafeLength :
forall s : Slice Std.U8,
SourceValidByteSlice s -> s.val != [] ->
s.val.length <= 9223372036854120459 ->
(Not (exists x : DecimalLexeme,
x.leadingSign = none /\
DecimalGoalVocabularyDefault.validNumeric x /\
DecimalGoalVocabularyDefault.bytes s =
DecimalGoalVocabularyDefault.renderNumeric x)) ->
exists o,
num.imp.dec2flt.parse.parse_partial_number s = ok o /\
forall (d : num.imp.dec2flt.decimal.Decimal) (r : Std.Usize),
o = some (d, r) -> Not (r = Slice.len s) := by
-- BODY
intro s hsource hne hlen hinvalid
have hsourceLen : s.val.length <= 9223372036854775807 := by
simp [SourceValidByteSlice] at hsource
exact hsource
have split_digits : forall bs : List Std.U8,
exists digits tail,
bs = digits ++ tail /\
(forall b, List.Mem b digits -> 48 <= b.val /\ b.val <= 57) /\
(forall b rest, tail = b :: rest ->
Not (48 <= b.val /\ b.val <= 57)) := by
intro bs
induction bs with
| nil => exact ⟨[], [], rfl, (by intro b hb; cases hb),
(by intro b rest h; cases h)⟩
| cons b bs ih =>
by_cases hb : 48 <= b.val /\ b.val <= 57
· obtain ⟨digits, tail, hbs, hdigits, htail⟩ := ih
refine ⟨b :: digits, tail, ?_, ?_, htail⟩
· simp [hbs]
· intro c hc
rcases List.mem_cons.mp hc with rfl | hc
· exact hb
· exact hdigits c hc
· exact ⟨[], b :: bs, rfl, (by intro c hc; cases hc), by
intro c rest h
cases h
exact hb⟩
let scientific_sign : List Std.U8 -> Option Bool := fun bs =>
match bs with
| [] => none
| b :: _ => if b = 45#u8 then some true
else if b = 43#u8 then some false else none
let scientific_body : List Std.U8 -> List Std.U8 := fun bs =>
match bs with
| [] => []
| b :: rest => if b = 45#u8 \/ b = 43#u8 then rest else b :: rest
have scientific_split : forall bs : List Std.U8,
bs = (match scientific_sign bs with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
scientific_body bs := by
intro bs
cases bs with
| nil => simp [scientific_sign, scientific_body]
| cons b rest =>
by_cases hm : b = 45#u8
· subst b
simp [scientific_sign, scientific_body]
· by_cases hp : b = 43#u8
· subst b
simp [scientific_sign, scientific_body]
· simp [scientific_sign, scientific_body, hm, hp]
have scientific_unsigned : forall bs : List Std.U8,
scientific_sign bs = none -> forall b rest,
scientific_body bs = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
intro bs
cases bs with
| nil => simp [scientific_body]
| cons b rest =>
by_cases hm : b = 45#u8
· subst b
simp [scientific_sign]
· by_cases hp : b = 43#u8
· subst b
simp [scientific_sign, hm]
· simp only [scientific_sign, scientific_body, hm, hp, if_false,
or_false]
intro _ c cs h
injection h with hbc _
subst c
exact ⟨hm, hp⟩
have render_digits : forall bs : List Std.U8,
(forall b, List.Mem b bs -> 48 <= b.val /\ b.val <= 57) ->
List.map (fun b : Std.U8 => b.val) bs =
List.map (fun d : Nat => 48 + d)
(List.map (fun b : Std.U8 => b.val - 48) bs) := by
intro bs hbs
induction bs with
| nil => rfl
| cons b bs ih =>
have hb := hbs b List.mem_cons_self
have hrest : forall c, List.Mem c bs -> 48 <= c.val /\ c.val <= 57 := by
intro c hc
exact hbs c (List.mem_cons_of_mem b hc)
simp [ih hrest]
omega
have complete_spelling : forall (integer : List Std.U8)
(fraction : Option (List Std.U8))
(expo : Option (Bool × Option Bool × List Std.U8)),
(forall b, List.Mem b integer -> 48 <= b.val /\ b.val <= 57) ->
(match fraction with
| none => True
| some ds => forall b, List.Mem b ds ->
48 <= b.val /\ b.val <= 57) ->
(integer != [] \/
match fraction with | none => False | some ds => ds != []) ->
(match expo with
| none => True
| some (_, _, ds) => ds != [] /\
forall b, List.Mem b ds -> 48 <= b.val /\ b.val <= 57) ->
s.val = integer ++
(match fraction with | none => [] | some ds => 46#u8 :: ds) ++
(match expo with
| none => []
| some (upper, sign, ds) =>
(if upper then 69#u8 else 101#u8) ::
(match sign with
| none => []
| some neg => [if neg then 45#u8 else 43#u8]) ++ ds) ->
False := by
intro integer fraction expo hint hfrac hsome hexpo hs
apply hinvalid
let x : DecimalLexeme := {
leadingSign := none
integerDigits := integer.map (fun b => b.val - 48)
fractionDigits := fraction.map
(fun ds => ds.map (fun b => b.val - 48))
exponent := expo.map (fun e =>
(e.1, e.2.1, e.2.2.map (fun b => b.val - 48)))
}
refine ⟨x, rfl, ?_, ?_⟩
· simp [DecimalGoalVocabularyDefault, x]
constructor
· intro d hd
have := hint d hd
omega
constructor
· cases fraction with
| none => simp
| some fs =>
simp only [Option.map_some]
intro d hd
obtain ⟨b, hb, rfl⟩ := List.mem_map.mp hd
have := hfrac b hb
omega
constructor
· cases fraction <;> simpa using hsome
· cases expo with
| none => simp
| some e =>
rcases e with ⟨upper, sign, es⟩
simp at hexpo ⊢
refine ⟨hexpo.1, ?_⟩
intro d hd
have := hexpo.2 d hd
omega
· simp [DecimalGoalVocabularyDefault, x]
rw [hs]
simp only [List.map_append, List.map_cons]
have hintRender :
List.map ((fun d : Nat => 48 + d) ∘
fun b : Std.U8 => b.val - 48) integer =
List.map (fun b : Std.U8 => b.val) integer := by
simpa [List.map_map] using (render_digits integer hint).symm
rw [hintRender]
cases fraction with
| none =>
simp only [Option.map_none]
simp at hfrac
cases expo with
| none => simp
| some e =>
rcases e with ⟨upper, sign, es⟩
simp only [Option.map_some, List.map_map]
simp at hexpo ⊢
have hexpRender :
List.map ((fun d : Nat => 48 + d) ∘
fun b : Std.U8 => b.val - 48) es =
List.map (fun b : Std.U8 => b.val) es := by
simpa [List.map_map] using (render_digits es hexpo.2).symm
rw [hexpRender]
cases upper <;> cases sign with
| none => norm_num
| some neg => cases neg <;> norm_num
| some fs =>
simp only [Option.map_some, List.map_map]
simp at hfrac
have hfracRender :
List.map ((fun d : Nat => 48 + d) ∘
fun b : Std.U8 => b.val - 48) fs =
List.map (fun b : Std.U8 => b.val) fs := by
simpa [List.map_map] using (render_digits fs hfrac).symm
rw [hfracRender]
cases expo with
| none => simp
| some e =>
rcases e with ⟨upper, sign, es⟩
simp only [Option.map_some, List.map_map]
simp at hexpo ⊢
have hexpRender :
List.map ((fun d : Nat => 48 + d) ∘
fun b : Std.U8 => b.val - 48) es =
List.map (fun b : Std.U8 => b.val) es := by
simpa [List.map_map] using (render_digits es hexpo.2).symm
rw [hexpRender]
cases upper <;> cases sign with
| none => norm_num
| some neg => cases neg <;> norm_num
obtain ⟨integer, intTailBytes, hsval, hintDigits, hintTail⟩ :=
split_digits s.val
obtain ⟨mantissa, intRest, hscanInt, hintRest⟩ :=
NumberHelperDigitScanSourceLength s 0#u64 integer intTailBytes
hsval hintDigits hintTail hsourceLen
obtain ⟨nDigits, hoffInt, hnDigitsVal⟩ :=
NumberHelperOffsetSourceLength s intRest hsourceLen (by
rw [hintRest, hsval]
simp)
have hnDigitsEq : nDigits.val = integer.length := by
rw [hnDigitsVal, hintRest, hsval]
simp
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 hnotempty : Not (s.val = []) := by simpa using hne
cases htailEq : intTailBytes with
| nil =>
have hintegerNeProp : integer ≠ [] := by
intro hi
rw [hi, htailEq] at hsval
simp at hsval
exact hnotempty hsval
have hintegerNe : integer != [] := by
simpa only [bne_iff_ne] using hintegerNeProp
exact False.elim (complete_spelling integer none none hintDigits (by
simp) (by left; exact hintegerNe) (by simp) (by
simpa [htailEq] using hsval))
| cons c cs =>
have hintRestVal : intRest.val = c :: cs := by simpa [htailEq] using hintRest
have hcsProp : cs.length <= Usize.max := by
have hp := intRest.property
rw [hintRestVal] at hp
simp only [List.length_cons] at hp
omega
let afterFirst : Slice Std.U8 := ⟨cs, hcsProp⟩
have h46Target : (46#u8 : Std.U8) = 46#uscalar := by
apply UScalar.eq_of_val_eq
rfl
have h101Target : (101#u8 : Std.U8) = 101#uscalar := by
apply UScalar.eq_of_val_eq
rfl
have h69Target : (69#u8 : Std.U8) = 69#uscalar := by
apply UScalar.eq_of_val_eq
rfl
have hsplitInt : core.slice.Slice.split_first intRest =
ok (some (c, afterFirst)) := by
have hirest : intRest = (⟨c :: cs, by simpa [hintRestVal] using
intRest.property⟩ : Slice Std.U8) := (Slice.eq_iff _ _).2 hintRestVal
rw [hirest]
simp [core.slice.Slice.split_first, dec2flt_model.ModelSliceSplitFirst,
afterFirst]
by_cases hpoint : c = 46#u8
· subst c
obtain ⟨fraction, fracTail, hcs, hfracDigits, hfracTail⟩ :=
split_digits cs
have hafterVal : afterFirst.val = fraction ++ fracTail := by
simp [afterFirst, hcs]
have hafterLen : afterFirst.val.length <= 9223372036854775807 := by
rw [hafterVal]
rw [hsval, htailEq, hcs] at hlen
simp at hlen
rw [List.length_append]
omega
obtain ⟨mantissa1, fracRest, hscanFrac, hfracRest⟩ :=
NumberHelperDigitScanSourceLength afterFirst mantissa fraction fracTail
hafterVal hfracDigits hfracTail hafterLen
obtain ⟨nAfter, hoffFrac, hnAfterVal⟩ :=
NumberHelperOffsetSourceLength afterFirst fracRest hafterLen (by
rw [hfracRest, hafterVal]
simp)
have hnAfterEq : nAfter.val = fraction.length := by
rw [hnAfterVal, hfracRest, hafterVal]
simp
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
rw [hnegAfterVal, hnAfterEq,
IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
have hl := hlen
rw [hsval, htailEq, hcs] at hl
simp at hl
constructor <;> omega
obtain ⟨fracExponent, hfracExponent, hfracExponentVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.cast_inBounds_spec .I64 negAfter hnegCastBounds)
have htotalBounds : IScalar.min .Isize <= nDigits.val + nAfter.val /\
nDigits.val + nAfter.val <= IScalar.max .Isize := by
rw [hnDigitsEq, hnAfterEq]
simp [IScalar.min, IScalar.max, IScalarTy.numBits,
Dec2Flt.configured_x86_64_numBits]
have hl := hlen
rw [hsval, htailEq, hcs] at hl
simp at hl
constructor <;> omega
obtain ⟨totalDigits, htotal, htotalVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec htotalBounds.1 htotalBounds.2)
by_cases htotalZero : totalDigits = 0#isize
· unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac, hoffFrac,
hnegAfter, hfracExponent, htotal, htotalZero]
norm_num
simp only [UScalar.ofNat, UScalar.ofNatCore]
simp [htotal, htotalZero]
· have htotalPos : 0 < totalDigits.val := by
have hb := IScalar.hBounds totalDigits
have hz : totalDigits.val ≠ 0 := by
intro hv
apply htotalZero
apply IScalar.eq_of_val_eq
simpa using hv
rw [htotalVal, hnDigitsEq, hnAfterEq] at hz ⊢
omega
have hsome : integer != [] \/ fraction != [] := by
simp only [bne_iff_ne]
by_contra hnone
push_neg at hnone
rcases hnone with ⟨hi, hf⟩
subst integer
subst fraction
rw [htotalVal, hnDigitsEq, hnAfterEq] at htotalPos
norm_num at htotalPos
cases htailCase : fracTail with
| nil =>
exact False.elim (complete_spelling integer (some fraction) none
hintDigits (by simpa using hfracDigits) hsome (by simp) (by
rw [hsval, htailEq, hcs, htailCase]
simp [List.append_assoc]))
| cons q qs =>
have hqsProp : qs.length <= Usize.max := by
have hp := fracRest.property
rw [hfracRest, htailCase] at hp
simp at hp ⊢
omega
let afterFrac : Slice Std.U8 := ⟨qs, hqsProp⟩
have hsplitFrac : core.slice.Slice.split_first fracRest =
ok (some (q, afterFrac)) := by
have hr : fracRest = (⟨q :: qs, by
rw [← htailCase, ← hfracRest]
exact fracRest.property⟩ : Slice Std.U8) :=
(Slice.eq_iff _ _).2 (by simpa [htailCase] using hfracRest)
rw [hr]
simp [core.slice.Slice.split_first,
dec2flt_model.ModelSliceSplitFirst, afterFrac]
by_cases hfracMarker : q = 101#u8 \/ q = 69#u8
· obtain ⟨upper, hmarkerByte⟩ : exists upper : Bool,
q = if upper then 69#u8 else 101#u8 := by
rcases hfracMarker with hq | hq
· exact ⟨false, by simpa using hq⟩
· exact ⟨true, by simpa using hq⟩
let sign := scientific_sign qs
let expBody := scientific_body qs
have hqsSign : qs =
(match sign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expBody := by
exact scientific_split qs
have hunsigned : sign = none -> forall b rest,
expBody = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
exact scientific_unsigned qs
obtain ⟨expDigits, expTail, hbody, hexpDigits, hexpTail⟩ :=
split_digits expBody
have hsci : afterFrac.val =
(match sign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expDigits ++ expTail := by
change qs = _
rw [hqsSign, hbody, List.append_assoc]
obtain hnoexp | hexp :=
NumberHelperScientificClassificationSourceLength afterFrac sign
expDigits expTail hexpDigits hexpTail hsci (by
intro hd hs b rest ht
apply hunsigned hs b rest
rw [hbody, hd]
simpa using ht)
· rcases hnoexp with ⟨_, rest, hscientific⟩
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
hsplitFrac]
norm_num
simp only [UScalar.ofNat, UScalar.ofNatCore]
cases upper <;>
simp at hmarkerByte <;>
subst q <;>
simp [htotal, htotalPos, hsplitFrac, h101Target, h69Target,
hscientific,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
dec2flt_model.ModelOptionBranch,
dec2flt_model.ModelOptionFromResidual]
· rcases hexp with ⟨hexpNe, parsedExp, sciRest, hscientific,
hsciRest, hexplo, hexphi, hexpshort, hexpnonnegative⟩
cases htailExp : expTail with
| nil =>
exact False.elim (complete_spelling integer (some fraction)
(some (upper, sign, expDigits)) hintDigits hfracDigits hsome
⟨hexpNe, hexpDigits⟩ (by
rw [hsval, htailEq, hcs, htailCase, hmarkerByte,
hqsSign, hbody, htailExp]
simp [List.append_assoc]))
| cons z zs =>
obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
NumberHelperOffsetSourceLength s sciRest hsourceLen (by
rw [hsciRest, htailExp]
have hl := congrArg List.length hsval
rw [htailEq, hcs, htailCase, hqsSign, hbody, htailExp] at hl
simp at hl ⊢
omega)
have hcastBounds : 0 <= consumed.val /\
consumed.val <= UScalar.max .Usize := by
rw [hconsumedVal]
have hrestLe : sciRest.val.length <= s.val.length := by
rw [hsciRest, htailExp]
have hl := congrArg List.length hsval
rw [htailEq, hcs, htailCase, hqsSign, hbody, htailExp] at hl
simp at hl ⊢
omega
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨len, hcastLen, hlenVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
have hlenNe : len ≠ Slice.len s := by
intro heq
have heqv : (len.val : Int) = s.val.length := by
have h := congrArg UScalar.val heq
simpa [Slice.len_val] using h
have hrestPos : 0 < sciRest.val.length := by
rw [hsciRest, htailExp]
simp
have hlenConsumed : (len.val : Int) = consumed.val := by
norm_num at hlenVal
exact hlenVal
rw [hconsumedVal] at hlenConsumed
omega
have hsuffixLenEq : qs.length =
(match sign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]).length +
(expDigits.length + expTail.length) := by
have hl := congrArg List.length hqsSign
rw [hbody] at hl
simpa using hl
have hcombinedBounds : IScalar.min .I64 <=
fracExponent.val + parsedExp.val /\
fracExponent.val + parsedExp.val <= IScalar.max .I64 := by
have hparts := hlen
rw [hsval, htailEq, hcs, htailCase] at hparts
simp only [List.length_append, List.length_cons] at hparts
rw [hfracExponentVal, hnegAfterVal, hnAfterEq,
IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
constructor
· by_cases hshort : expDigits.length <= 5
· have hsharp := hexpshort hshort
omega
· have hq : 6 <= expDigits.length := by omega
by_cases hnegative : sign = some true
· simp [hnegative] at hsuffixLenEq
rw [htailExp] at hsuffixLenEq
simp at hsuffixLenEq
omega
· have hnonnegative := hexpnonnegative hnegative
omega
· omega
obtain ⟨combinedExponent, hcombinedExponent,
hcombinedExponentVal⟩ := Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec hcombinedBounds.1 hcombinedBounds.2)
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
hsplitFrac]
norm_num
simp only [UScalar.ofNat, UScalar.ofNatCore]
cases upper <;>
simp at hmarkerByte <;>
subst q <;>
simp [htotal, htotalPos, hsplitFrac, h101Target, h69Target,
hscientific, hcombinedExponent, hoffConsumed, hcastLen,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
dec2flt_model.ModelOptionBranch,
dec2flt_model.ModelOptionFromResidual]
all_goals
by_cases hsmall : totalDigits.val <= 19
· refine ⟨some ({
exponent := combinedExponent
mantissa := mantissa1
negative := false
many_digits := false
}, len), ?_, ?_⟩
· simp [hsmall]
· intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hsmall]
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 simpa using hsubBounds.1)
(by simpa using hsubBounds.2))
rw [hnMore]
simp
obtain ⟨adjusted, hadjusted⟩ :=
NumberHelperAdjustManySourceLength s nMore hsourceLen (by
norm_num at hnMoreVal
omega) (by
norm_num at hnMoreVal
rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq]
have hl := congrArg List.length hsval
rw [htailEq, hcs] at hl
simp at hl
omega)
rw [hadjusted]
by_cases hpositive : 0 < adjusted.val
· simp [hpositive]
obtain ⟨mantissa2, exponent2, hmany⟩ :=
NumberHelperFractionalManyDigitsSourceLength s intRest
parsedExp integer fraction fracTail (by
simpa [htailEq, hcs, List.append_assoc] using hsval)
(by simpa [htailEq, hcs] using hintRest) hintDigits
hfracDigits hfracTail hsourceLen (by
have hb := hcombinedBounds.1
rw [hfracExponentVal, hnegAfterVal, hnAfterEq] at hb
simpa [IScalar.min_IScalarTy_I64_eq, I64.min_eq]
using hb) (by
rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
have hl := hlen
rw [hsval, htailEq, hcs] at hl
simp at hl
omega)
rw [hmany]
refine ⟨some ({
exponent := exponent2
mantissa := mantissa2
negative := false
many_digits := true
}, len), rfl, ?_⟩
intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hpositive]
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· have hq101 : q ≠ 101#u8 := by tauto
have hq69 : q ≠ 69#u8 := by tauto
obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
NumberHelperOffsetSourceLength s fracRest hsourceLen (by
have hsLenEq := congrArg List.length hsval
rw [htailEq, hcs, htailCase] at hsLenEq
rw [hfracRest, htailCase]
simp at hsLenEq ⊢
omega)
have hrestLe : fracRest.val.length <= s.val.length := by
have hsLenEq := congrArg List.length hsval
rw [htailEq, hcs, htailCase] at hsLenEq
rw [hfracRest, htailCase]
simp at hsLenEq ⊢
omega
have hcastBounds : 0 <= consumed.val /\
consumed.val <= UScalar.max .Usize := by
rw [hconsumedVal]
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨len, hcastLen, hlenVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
have hlenEq : len.val = integer.length + 1 + fraction.length := by
norm_num at hlenVal
rw [hconsumedVal, hsval, htailEq, hcs, hfracRest, htailCase]
at hlenVal
simp at hlenVal
omega
have hlenNe : len ≠ Slice.len s := by
intro heq
have heqv := congrArg UScalar.val heq
simp [Slice.len_val, hlenEq, hsval, htailEq, hcs, htailCase]
at heqv
omega
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt, hscanFrac,
hoffFrac, hnegAfter, hfracExponent, htotal, htotalPos,
hsplitFrac, hq101, hq69, hoffConsumed, hcastLen]
norm_num
simp only [UScalar.ofNat, UScalar.ofNatCore]
simp [htotal, htotalPos, hsplitFrac, hq101, hq69,
hoffConsumed, hcastLen]
split <;> try contradiction
split <;> try contradiction
split
· rename_i hsmall
refine ⟨some ({
exponent := fracExponent
mantissa := mantissa1
negative := false
many_digits := false
}, len), ?_, ?_⟩
· rfl
· intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· rename_i hsmall
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 simpa using hsubBounds.1)
(by simpa using hsubBounds.2))
rw [hnMore]
simp
obtain ⟨adjusted, hadjusted⟩ :=
NumberHelperAdjustManySourceLength s nMore hsourceLen (by
norm_num at hnMoreVal
omega) (by
norm_num at hnMoreVal
rw [hnMoreVal, htotalVal, hnDigitsEq, hnAfterEq]
omega)
rw [hadjusted]
by_cases hpositive : 0 < adjusted.val
· simp [hpositive]
obtain ⟨mantissa2, exponent2, hmany⟩ :=
NumberHelperFractionalManyDigitsSourceLength s intRest
0#i64 integer fraction (q :: qs) (by
simpa [htailEq, hcs, htailCase, List.append_assoc]
using hsval) (by
simpa [htailEq, hcs, htailCase] using hintRest) hintDigits
hfracDigits (by
intro b rest h
exact hfracTail b rest (by simpa [htailCase] using h))
hsourceLen (by
rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq]
norm_num
have hl := hlen
rw [hsval, htailEq, hcs, htailCase] at hl
simp at hl
omega) (by
rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
norm_num
rw [htotalVal, hnDigitsEq, hnAfterEq] at hsmall
omega)
rw [hmany]
refine ⟨some ({
exponent := exponent2
mantissa := mantissa2
negative := false
many_digits := true
}, len), rfl, ?_⟩
intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hpositive]
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· cases c
rename_i cbv
let c : Std.U8 := @UScalar.mk .U8 cbv
have hcbv : cbv ≠ 46 := by
intro heq
subst cbv
exact hpoint (by rfl)
have hpointMatch :
(match (@UScalar.mk .U8 cbv) with
| 46#uscalar => do
let (s3, mantissa2) ←
num.imp.dec2flt.parse.try_parse_digits afterFirst mantissa
let nAfter ←
SliceU8.Insts.Dec2flt_modelNumImpDec2fltCommonByteSlice.offset_from
s3 afterFirst
let negAfter ← -. nAfter
let fracExponent ← lift (IScalar.cast .I64 negAfter)
ok (s3, mantissa2, nAfter, fracExponent)
| _ => ok (intRest, mantissa, 0#isize, 0#i64)) =
ok (intRest, mantissa, 0#isize, 0#i64) := by
split <;> try contradiction
all_goals rfl
by_cases hintegerEmpty : integer = []
· have hnzero : nDigits = 0#isize := by
apply IScalar.eq_of_val_eq
rw [hnDigitsEq, hintegerEmpty]
norm_num
have haddZeroZero : (0#isize + 0#isize) = ok 0#isize := by
simpa [hnzero] using haddZero
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt]
split <;> try contradiction
simp [haddZeroZero, hnzero]
· have hnpos : 0 < nDigits.val := by
rw [hnDigitsEq]
have := List.length_pos_of_ne_nil hintegerEmpty
omega
by_cases hmarker : c = 101#u8 \/ c = 69#u8
· obtain ⟨upper, hupper⟩ : exists upper : Bool,
c = if upper then 69#u8 else 101#u8 := by
rcases hmarker with hc | hc
· exact ⟨false, by simpa using hc⟩
· exact ⟨true, by simpa using hc⟩
have hmarkerByte : (@UScalar.mk .U8 cbv) =
if upper then 69#u8 else 101#u8 := by
simpa [c] using hupper
let sign := scientific_sign cs
let expBody := scientific_body cs
have hcsSign : cs =
(match sign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expBody := by
exact scientific_split cs
have hunsigned : sign = none -> forall b rest,
expBody = b :: rest -> b ≠ 45#u8 /\ b ≠ 43#u8 := by
exact scientific_unsigned cs
obtain ⟨expDigits, expTail, hbody, hexpDigits, hexpTail⟩ :=
split_digits expBody
have hsci : afterFirst.val =
(match sign with
| none => []
| some negative => [if negative then 45#u8 else 43#u8]) ++
expDigits ++ expTail := by
change cs = _
rw [hcsSign, hbody, List.append_assoc]
obtain hnoexp | hexp :=
NumberHelperScientificClassificationSourceLength afterFirst sign
expDigits expTail hexpDigits hexpTail hsci (by
intro hd hs b rest ht
apply hunsigned hs b rest
rw [hbody, hd]
simpa using ht)
· rcases hnoexp with ⟨_, rest, hscientific⟩
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt]
split <;> try contradiction
simp [haddZero, hnpos, hsplitInt]
cases upper with
| false =>
have hb := congrArg UScalar.bv hmarkerByte
simp at hb
subst cbv
simp [h101Target, h69Target, hscientific,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
dec2flt_model.ModelOptionBranch,
dec2flt_model.ModelOptionFromResidual]
| true =>
have hb := congrArg UScalar.bv hmarkerByte
simp at hb
subst cbv
simp [h101Target, h69Target, hscientific,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
core.option.Option.Insts.CoreOpsTry_traitFromResidualOptionInfallible.from_residual,
dec2flt_model.ModelOptionBranch,
dec2flt_model.ModelOptionFromResidual]
· rcases hexp with ⟨hexpNe, parsedExp, sciRest, hscientific,
hsciRest, hexplo, hexphi, hexpshort, hexpnonnegative⟩
cases htailExp : expTail with
| nil =>
exact False.elim (complete_spelling integer none
(some (upper, sign, expDigits)) hintDigits (by simp)
(by left; simpa only [bne_iff_ne] using hintegerEmpty)
⟨hexpNe, hexpDigits⟩ (by
rw [hsval, htailEq, hmarkerByte, hcsSign, hbody, htailExp]
simp [List.append_assoc]))
| cons z zs =>
obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
NumberHelperOffsetSourceLength s sciRest hsourceLen (by
rw [hsciRest, htailExp]
have hl := congrArg List.length hsval
rw [htailEq, hcsSign, hbody, htailExp] at hl
simp at hl ⊢
omega)
have hcastBounds : 0 <= consumed.val /\
consumed.val <= UScalar.max .Usize := by
rw [hconsumedVal]
have hrestLe : sciRest.val.length <= s.val.length := by
rw [hsciRest, htailExp]
have hl := congrArg List.length hsval
rw [htailEq, hcsSign, hbody, htailExp] at hl
simp at hl ⊢
omega
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨len, hcastLen, hlenVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
have hlenNe : len ≠ Slice.len s := by
intro heq
have heqv : (len.val : Int) = s.val.length := by
have h := congrArg UScalar.val heq
simpa [Slice.len_val] using h
have hrestPos : 0 < sciRest.val.length := by
rw [hsciRest, htailExp]
simp
have hlenConsumed : (len.val : Int) = consumed.val := by
norm_num at hlenVal
exact hlenVal
rw [hconsumedVal] at hlenConsumed
omega
have haddBounds : IScalar.min .I64 <=
(0#i64).val + parsedExp.val /\
(0#i64).val + parsedExp.val <= IScalar.max .I64 := by
rw [IScalar.min_IScalarTy_I64_eq, I64.min_eq,
IScalar.max_IScalarTy_I64_eq, I64.max_eq]
norm_num
omega
obtain ⟨combined, haddExp, hcombinedVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.add_spec haddBounds.1 haddBounds.2)
have hcombined : combined = parsedExp := by
apply IScalar.eq_of_val_eq
norm_num at hcombinedVal
exact hcombinedVal
subst combined
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt]
split <;> try contradiction
simp [haddZero, hnpos, hsplitInt]
cases upper <;>
have hb := congrArg UScalar.bv hmarkerByte <;>
simp at hb <;>
subst cbv <;>
simp [h101Target, h69Target, hscientific, haddExp,
hoffConsumed, hcastLen,
core.option.Option.Insts.CoreOpsTry_traitTry.branch,
dec2flt_model.ModelOptionBranch,
dec2flt_model.ModelOptionFromResidual]
all_goals
by_cases hsmall : nDigits.val <= 19
· refine ⟨some ({
exponent := parsedExp
mantissa := mantissa
negative := false
many_digits := false
}, len), ?_, ?_⟩
· simp [hsmall]
· intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hsmall]
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 simpa using hsubBounds.1)
(by simpa using hsubBounds.2))
rw [hnMore]
simp
obtain ⟨adjusted, hadjusted⟩ :=
NumberHelperAdjustManySourceLength s nMore hsourceLen (by
norm_num at hnMoreVal
omega) (by
norm_num at hnMoreVal
rw [hnMoreVal, hnDigitsEq]
omega)
rw [hadjusted]
by_cases hpositive : 0 < adjusted.val
· simp [hpositive]
obtain ⟨mantissa2, exponent2, hmany⟩ :=
NumberHelperIntegralManyDigitsSourceLength s intRest
parsedExp nMore adjusted integer intTailBytes hsval
hintRest hintDigits hintTail (by
intro b rest h
rw [htailEq] at h
injection h with hbc _
subst b
exact hpoint) hsourceLen (by
norm_num at hnMoreVal
rw [hnMoreVal, hnDigitsEq]) hadjusted hpositive (by
rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
have hl := hlen
rw [hsval] at hl
simp at hl
omega)
rw [hmany]
refine ⟨some ({
exponent := exponent2
mantissa := mantissa2
negative := false
many_digits := true
}, len), rfl, ?_⟩
intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hpositive]
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· have hc101 : c ≠ 101#u8 := by tauto
have hc69 : c ≠ 69#u8 := by tauto
have hcbv101 : cbv ≠ (101 : BitVec 8) := by
intro heq
apply hc101
exact congrArg (fun v : BitVec 8 => (@UScalar.mk .U8 v)) heq
have hcbv69 : cbv ≠ (69 : BitVec 8) := by
intro heq
apply hc69
exact congrArg (fun v : BitVec 8 => (@UScalar.mk .U8 v)) heq
obtain ⟨consumed, hoffConsumed, hconsumedVal⟩ :=
NumberHelperOffsetSourceLength s intRest hsourceLen (by
rw [hintRest, hsval]
simp)
have hcastBounds : 0 <= consumed.val /\
consumed.val <= UScalar.max .Usize := by
rw [hconsumedVal]
simp [UScalar.max, Dec2Flt.configured_x86_64_numBits]
omega
obtain ⟨len, hcastLen, hlenVal⟩ :=
Aeneas.Std.WP.spec_imp_exists
(IScalar.hcast_inBounds_spec .Usize consumed hcastBounds)
have hlenEq : len.val = integer.length := by
norm_num at hlenVal
rw [hconsumedVal, hintRest, hsval] at hlenVal
simp at hlenVal
omega
have hlenNe : len ≠ Slice.len s := by
intro heq
have heqv := congrArg UScalar.val heq
simp [Slice.len_val, hlenEq, hsval, htailEq] at heqv
unfold num.imp.dec2flt.parse.parse_partial_number
simp [hnotempty, hscanInt, hoffInt, hsplitInt]
split <;> try contradiction
simp [haddZero, hnpos, hsplitInt, h101Target, h69Target, hc101,
hc69, hcbv101, hcbv69, hoffConsumed, hcastLen]
split <;> try contradiction
split <;> try contradiction
by_cases hsmall : nDigits.val <= 19
· refine ⟨some ({
exponent := 0#i64
mantissa := mantissa
negative := false
many_digits := false
}, len), ?_, ?_⟩
· simp [hsmall]
· intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hsmall]
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 simpa using hsubBounds.1)
(by simpa using hsubBounds.2))
rw [hnMore]
simp
obtain ⟨adjusted, hadjusted⟩ :=
NumberHelperAdjustManySourceLength s nMore hsourceLen (by
norm_num at hnMoreVal
omega) (by
norm_num at hnMoreVal
rw [hnMoreVal, hnDigitsEq, hsval]
simp
omega)
rw [hadjusted]
by_cases hpositive : 0 < adjusted.val
· simp [hpositive]
obtain ⟨mantissa2, exponent2, hmany⟩ :=
NumberHelperIntegralManyDigitsSourceLength s intRest 0#i64
nMore adjusted integer (c :: cs) (by
rw [htailEq] at hsval
simpa [c] using hsval) (by
rw [htailEq] at hintRest
simpa [c] using hintRest) hintDigits (by
intro b rest h
apply hintTail b rest
rw [htailEq]
simpa [c] using h) (by
intro b rest h
injection h with hbc _
subst b
simpa [c] using hpoint) hsourceLen (by
norm_num at hnMoreVal
rw [hnMoreVal, hnDigitsEq]) hadjusted hpositive (by
rw [IScalar.max_IScalarTy_I64_eq, I64.max_eq]
norm_num
have hl := hlen
rw [hsval] at hl
simp at hl
omega)
rw [hmany]
refine ⟨some ({
exponent := exponent2
mantissa := mantissa2
negative := false
many_digits := true
}, len), rfl, ?_⟩
intro d r ho
simp only [Option.some.injEq, Prod.mk.injEq] at ho
rcases ho with ⟨_, rfl⟩
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
· simp [hpositive]
intro hv
apply hlenNe
apply UScalar.eq_of_val_eq
simpa [Slice.len_val] using hv
end dec2flt_model
Proof structure
Follow the declared dependencies to read the supporting statements and proofs.
Uses
- DecimalGoalVocabularyDefault
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceSplitFirst
- NumberHelperAdjustManySourceLength
- NumberHelperDigitScanSourceLength
All 14 entries
- DecimalGoalVocabularyDefault
- ModelOptionBranch
- ModelOptionFromResidual
- ModelSliceSplitFirst
- NumberHelperAdjustManySourceLength
- NumberHelperDigitScanSourceLength
- NumberHelperFractionalManyDigitsSourceLength
- NumberHelperIntegralManyDigitsSourceLength
- NumberHelperOffsetSourceLength
- NumberHelperScientificClassificationSourceLength
- NumberHelperScientificExponentBounds
- NumberHelperScientificPrefixSafeLength
- SourceValidByteSlice
- num imp dec2flt parse parse partial number
Inspect related source (68)
- parse_partial_number · dec2flt/parse.rs:161 Program Rust
- offset_from · dec2flt/common.rs:30 Program Rust
- read_u64 · dec2flt/common.rs:18 Program Rust
More program dependencies (35)
- is_8digits · dec2flt/common.rs:40 Program Rust
- Decimal · dec2flt/decimal.rs:32 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
- parse_many_digits · dec2flt/parse.rs:104 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_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
- MIN_19DIGIT_INT · dec2flt/parse.rs:8 Program Rust
- MASK · dec2flt/parse.rs:19 Program Rust
- MUL1 · dec2flt/parse.rs:20 Program Rust
- MUL2 · dec2flt/parse.rs:21 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
- 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 (30)
- 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
- is_ascii_digit · core/src/num/mod.rs:958 Rust library
- clone · core/src/clone.rs:698 Rust library
- div · core/src/ops/arith.rs:515 Rust library
- mul · core/src/ops/arith.rs:350 Rust library
- neg · core/src/ops/arith.rs:719 Rust library
- bitand · core/src/ops/bit.rs:178 Rust library
- bitor · core/src/ops/bit.rs:282 Rust library
- shl · core/src/ops/bit.rs:489 Rust library
- shr · core/src/ops/bit.rs:612 Rust library
- EXPONENT_MASK · core/src/num/f64.rs:615 Rust library
- INFINITY · core/src/num/f64.rs:512 Rust library
- MANTISSA_DIGITS · core/src/num/f64.rs:412 Rust library
- MANTISSA_MASK · core/src/num/f64.rs:637 Rust library
- NAN · core/src/num/f64.rs:509 Rust library
- NEG_INFINITY · core/src/num/f64.rs:515 Rust library
- classify · core/src/num/f64.rs:782 Rust library
- from_bits · core/src/num/f64.rs:1269 Rust library
- to_bits · core/src/num/f64.rs:1223 Rust library
- first · core/src/slice/mod.rs:155 Rust library
- as_bytes · core/src/str/mod.rs:498 Rust library
- FpCategory · core/src/num/mod.rs:1522 Rust library
- Div · core/src/ops/arith.rs:460 Rust library
- Mul · core/src/ops/arith.rs:322 Rust library
- Neg · core/src/ops/arith.rs:690 Rust library
- BitOr · core/src/ops/bit.rs:254 Rust library
- Shl · core/src/ops/bit.rs:461 Rust library
- Shr · core/src/ops/bit.rs:584 Rust library
Related source and models come from the extraction records and declared dependencies.
Proof assumptions and review
Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.
Transitive assumptions
- Classical.choice
- Dec2Flt.configured_x86_64_numBits
- Quot.sound
- propext
This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.
Helper theorems included
All 62 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
- NumberHelperAdjustManySourceLength
- NumberHelperDigitScanSourceLength
- NumberHelperEightDigitWord
- NumberHelperFractionalManyDigitsSourceLength
- NumberHelperIntegralAdjustmentSourceLength
- NumberHelperIntegralManyDigitsSourceLength
- NumberHelperOffsetSourceLength
- NumberHelperParseEightDigitsSafe
- NumberHelperPartialNumberSafeLength
- NumberHelperReadEightBytes
- NumberHelperScientificClassificationSourceLength
- NumberHelperScientificPrefixSafeLength
- 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 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": "NumberHelperPartialNumberSafeLength",
"closure_version": "patch_c_v1",
"active_decl_hash": "fdcd06c8d54adc2b3871ff3d26f474e45db26f2ac610f1d05ff77d2dd4899aaf",
"active_statement_hash": "1dac06f386f4425bcc0ffdab42c712fde5cab559cf4c9f8d17194ee727c97bcb",
"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-116",
"boundary_theorems": {},
"strict_theorem_deps": {
"DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
"ModelSliceSplitFirst": "f617ee05dd2925a9",
"NumberHelperAdjustManySourceLength": "43aa71b5b9fb578d",
"NumberHelperDigitScanSourceLength": "8892b939bba0ecf9",
"NumberHelperFractionalManyDigitsSourceLength": "d9edc04302c7e34a",
"NumberHelperIntegralManyDigitsSourceLength": "65c9aa63b230b4f0",
"NumberHelperOffsetSourceLength": "de0168dfeba3b802",
"NumberHelperScientificClassificationSourceLength": "8f49a3f3533503f0",
"num_imp_dec2flt_parse_parse_partial_number": "854af4cc12136a58"
},
"strict_definition_deps": {
"DecimalGoalVocabulary": "c08dd4b4aea4abb4",
"DecimalGoalVocabularyDefault": "4634372c8f7a7f44",
"DecimalLexeme": "c43614ff2149ecf2",
"F64": "ec4e25fbaf4e11d4",
"ModelOptionBranch": "c55e273482c8c0a1",
"ModelOptionFromResidual": "6d48ecfbc617744f",
"Preamble": "4adf4172ae751d7d",
"SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from": "7e7284dc9bc88830",
"SourceValidByteSlice": "3dc42716a6378d26",
"num_imp_dec2flt_common_BiasedFp": "5c88d5d7976c5e8f",
"num_imp_dec2flt_decimal_Decimal": "4c41a56bf44cb31e",
"num_imp_dec2flt_parse_adjust_many_digit_count": "4e59e3776b6cfdaa",
"num_imp_dec2flt_parse_parse_many_digits": "50c9ef13b3ed7fe8",
"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:e5062f53eacca1ac92c53cf211454dd7ce06dbe3b3b879ea88a62b948b08c087",
"current_fingerprint": "sound-v2:e5062f53eacca1ac92c53cf211454dd7ce06dbe3b3b879ea88a62b948b08c087",
"superseded_for_theorem_closure": false
}Review verdicts
{
"corr_status": "Pass",
"sound_status": "Pass",
"substantiveness_status": "Pass"
}