ParserNumericSlowPathOverflowWitness

Lean checked

Statement

This explanation was written alongside the formalization to describe the statement and its reasoning.

Lemma · Sharp slow-path overflow witness

Let first be eleven ASCII zeroes, followed by the nineteen bytes of 1000000000000000080, followed by 2147483618 ASCII zeroes, and let body be 0. followed by first. There are Aeneas byte slices with those contents, and an empty remainder slice, for which
|\texttt{body}|=2147483650,\qquad |\texttt{first}|=2147483648=2^{31},\qquad |\texttt{remainder}|=0.
On body, parse_number returns a record with mantissa 1000000000000000080, exponent -30, negative flag false, and many-digits flag true. The native fast path returns None. The two adjacent compute_float calls return respectively (448160529771025,983) and (448160529771026,983), and their extracted comparison is false, so dispatch is forced to the slow parser.
For the slow decimal parser, the narrowing cast of 2^{31} to i32 is i32::MIN, and checked subtraction of that value from zero returns fail integerOverflow. Consequently both parse_decimal_seq(body) and the binary64 specialization of parse_long_mantissa(body) return fail integerOverflow.

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.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_FAST_PATH
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_LARGEST_POWER_OF_TEN
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SMALLEST_POWER_OF_TEN
import Tablet.ModelF64MantissaDigits
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_write_u64
import Tablet.num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq
import Tablet.num_imp_dec2flt_common_BiasedFp_zero_pow2
import Tablet.num_imp_dec2flt_common_is_8digits
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_decimal_Decimal_can_use_fast_path
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_Insts_CoreDefaultDefault_default
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_try_add_digit
import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq
import Tablet.num_imp_dec2flt_decimal_seq_parse_digits_into_seq
import Tablet.num_imp_dec2flt_fpu_fpu_precision_set_precision
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_lemire_compute_product_approx
import Tablet.num_imp_dec2flt_lemire_full_multiplication
import Tablet.num_imp_dec2flt_lemire_power
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
import Tablet.num_imp_dec2flt_parse_MIN_19DIGIT_INT
import Tablet.num_imp_dec2flt_parse_parse_8digits
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_try_parse_19digits
import Tablet.num_imp_dec2flt_parse_try_parse_digits
import Tablet.num_imp_dec2flt_Lemire_MIN_EXPONENT_FAST_PATH_default
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_table_LARGEST_POWER_OF_FIVE
import Tablet.num_imp_dec2flt_table_POWER_OF_FIVE_128
import Tablet.num_imp_dec2flt_table_SMALLEST_POWER_OF_FIVE
import Tablet.num_imp_traits_Float_EXP_BIAS_default
import Tablet.num_imp_traits_Float_EXP_BITS_default
import Tablet.num_imp_traits_Float_EXP_MIN_default
import Tablet.num_imp_traits_Float_EXP_SAT_default
import Tablet.num_imp_traits_Float_INFINITE_POWER_default
import Tablet.num_imp_traits_Float_SIG_BITS_default
import Tablet.ParserNumericRecordCertificate
import Tablet.ParserNumericFastPathCertificate
import Tablet.ParserNumericLemirePairCertificate
import Tablet.ParserNumericDecimalOverflowCertificate
import Tablet.ParserNumericSlowPropagationCertificate

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNumericSlowPathOverflowWitness]
theorem ParserNumericSlowPathOverflowWitness :
    exists (body first remainder : Slice Std.U8)
        (d : num.imp.dec2flt.decimal.Decimal),
      first.val = List.replicate 11 48#u8 ++
        [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
          48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
          48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
        List.replicate 2147483618 48#u8 /\
      body.val = [48#u8, 46#u8] ++ first.val /\
      remainder.val = [] /\
      body.val.length = 2147483650 /\
      first.val.length = 2147483648 /\
      remainder.val.length = 0 /\
      num.imp.dec2flt.parse.parse_number body = ok (some d) /\
      d = {
        exponent := (-30)#i64
        mantissa := 1000000000000000080#u64
        negative := false
        many_digits := true
      } /\
      num.imp.dec2flt.decimal.Decimal.try_fast_path
          F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
          F64.Insts.CoreOpsArithDivF64F64
          F64.Insts.CoreOpsArithMulF64F64
          F64.Insts.CoreOpsArithNegF64 d = ok none /\
      num.imp.dec2flt.lemire.compute_float
          F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64.FloatInst
          (-30)#i64 1000000000000000080#u64 =
        ok { m := 448160529771025#u64, p_biased := 983#i32 } /\
      num.imp.dec2flt.lemire.compute_float
          F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64.FloatInst
          (-30)#i64 1000000000000000081#u64 =
        ok { m := 448160529771026#u64, p_biased := 983#i32 } /\
      ({ m := 448160529771025#u64, p_biased := 983#i32 } :
          num.imp.dec2flt.common.BiasedFp) ≠
        { m := 448160529771026#u64, p_biased := 983#i32 } /\
      num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq
          { m := 448160529771025#u64, p_biased := 983#i32 }
          { m := 448160529771026#u64, p_biased := 983#i32 } = ok false /\
      UScalar.hcast .I32 2147483648#usize = (-2147483648)#i32 /\
      ((0#i32 : Std.I32) - (-2147483648)#i32) = fail integerOverflow /\
      num.imp.dec2flt.decimal_seq.parse_decimal_seq body =
        fail integerOverflow /\
      num.imp.dec2flt.slow.parse_long_mantissa
          F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64.FloatInst body =
        fail integerOverflow := 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

Put K=2147483618=2^{31}-30. By Assumptions, the configured usize and isize carriers have 64 bits. Hence the three lists in the statement, whose lengths are below 2^{32}, define Aeneas slices. The nineteen-byte block has length 19, so direct list arithmetic gives
|\texttt{first}|=11+19+K=2147483648, \qquad |\texttt{body}|=2+2147483648=2147483650.
The chosen remainder is the empty slice and therefore has length zero.
We first execute the number helper. In num imp dec2flt parse parse partial number, the first call to num imp dec2flt parse try parse digits first examines the initial eight bytes. By SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64, the loaded word has those bytes in little-endian order, and direct evaluation of num imp dec2flt common is 8digits is false because its second byte is the point, 46, not an ASCII digit. The scalar loop therefore consumes just the initial integer byte 48 and leaves the point, with accumulator zero.
After splitting at that point, the second digit scan starts on first. Its length is 2^{31}, a multiple of eight, and all its bytes lie between 48 and 57. At each bulk iteration the read above is in bounds, num imp dec2flt common is 8digits evaluates to true, and num imp dec2flt parse parse 8digits returns the base-ten value of those eight bytes. Indeed, after subtracting the all-48 word, that definition has eight bytes in 0,\ldots,9; if this word is v, then v\leq9(2^{64}-1)/255, so both the checked 10v and its following addition of v\mathbin{>{}>}8 are below 2^{64}. The scan drops exactly eight bytes per iteration and therefore terminates after 2^{28} iterations on the empty suffix; its scalar tail has zero iterations. Its outer multiply and add are explicitly wrapping u64 operations and cannot fail, and this accumulated value will be discarded by the retry below. By SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice offset from, the offset from the empty residual to first is |\texttt{first}|-0=2^{31}. This is in the signed 64-bit range, so its negation and cast to i64 are exact. Together with the one integer digit the total count is 1+2^{31}=2147483649>19.
The many-digit adjustment in num imp dec2flt parse adjust many digit count starts from 2147483649-19=2147483630. Its loop subtracts one for the initial integer zero and for each of the eleven fractional leading zeroes; the saturating quantity for the point is 46-47=0, and the loop stops at byte 1. The exact result is 2147483630-12=2147483618>0. Thus the many-digit branch is selected. In num imp dec2flt parse parse many digits, the first call to num imp dec2flt parse try parse 19digits consumes the integer zero and stops at the point with accumulator zero. The exact declaration num imp dec2flt parse MIN 19DIGIT INT makes the loop cutoff 10^{18}. Since zero is below it, the fractional branch skips the point and restarts. The checked-loop invariant after reading j digits is that the accumulator is the base-ten value of the first j suffix digits and the residual drops exactly those j bytes. The eleven leading zeroes preserve zero. The next nineteen digits are exactly 1000000000000000080; before the nineteenth digit the accumulator is 100000000000000008<10^{18}, and after it the accumulator is 1000000000000000080\geq10^{18}. Every intermediate product and sum is at most that final value and hence below 2^{64}. Thus the next guard stops before the trailing zero run. Exactly 11+19=30 fractional bytes were passed, so the cited offset_from declaration returns 30; the model negates it and adds the absent scientific exponent zero, yielding -30.
It follows that the record returned by num imp dec2flt parse parse partial number has exactly the four fields in the statement, and its returned consumed length is the full body length. The equality test in num imp dec2flt parse parse number therefore succeeds and gives ok (some d). Because F64 Insts Dec2flt modelNumImpDec2fltLemireU64 MAX EXPONENT FAST PATH is exactly 22 and num imp dec2flt Lemire MIN EXPONENT FAST PATH default negates that value, the two methods selected by F64 Insts Dec2flt modelNumImpDec2fltLemireU64 return respectively 22 and -22. The first guard in num imp dec2flt decimal Decimal can use fast path is therefore the false comparison -22\leq-30. The preceding precision setup in num imp dec2flt decimal Decimal try fast path is the extracted no-op ok () by num imp dec2flt fpu fpu precision set precision, so the whole function receives that false guard and returns ok none before any conversion or floating-point arithmetic.
We next check the two fixed-width conversions from num imp dec2flt lemire compute float. The selected instance is fixed by F64 Insts Dec2flt modelNumImpTraitsFloatExtU64 and F64 Insts Dec2flt modelNumImpTraitsFloatU64. Its exact decimal cutoffs are -342 and 308 by F64 Insts Dec2flt modelNumImpTraitsFloatU64 SMALLEST POWER OF TEN and F64 Insts Dec2flt modelNumImpTraitsFloatU64 LARGEST POWER OF TEN. Thus -30 is between the cutoffs, and both mantissas are nonzero, so none of the three early zero/infinity returns applies. The calls to num imp dec2flt common BiasedFp zero pow2 used to construct those sentinels all return normally.
For the remaining trait constants, F64 Insts Dec2flt modelNumImpTraitsFloatU64 BITS gives 64, while F64 Insts Dec2flt modelNumImpTraitsFloatU64 SIG TOTAL BITS and ModelF64MantissaDigits give 53. Substitution into num imp traits Float SIG BITS default, num imp traits Float EXP BITS default, num imp traits Float EXP SAT default, and num imp traits Float EXP BIAS default gives, in order, SIG_BITS=52, EXP_BITS=11, EXP_SAT=2047, and EXP_BIAS=1023. Consequently the exact defaults num imp traits Float EXP MIN default and num imp traits Float INFINITE POWER default give EXP_MIN=-1022 and INFINITE_POWER=2047.
Both mantissas have four leading zero bits, so normalization gives 16000000000000001280 and 16000000000000001296, and the precision argument is 52+3=55. The table bounds are exactly -342 and 308 by num imp dec2flt table SMALLEST POWER OF FIVE and num imp dec2flt table LARGEST POWER OF FIVE; hence the assertions for q=-30 succeed and the index is -30-(-342)=312. The entry there in num imp dec2flt table POWER OF FIVE 128 is (11692013098647223345,11611831772799369869). Expanding the two unsigned 128-bit products of the normalized mantissas in num imp dec2flt lemire full multiplication, and num imp dec2flt lemire compute product approx gives
\begin{array}{c|cc} w_{\rm normalized} & \mathit{lo} & \mathit{hi}\\ \hline 16000000000000001280 & 13355886962484770048 & 10141204801825836022\\ 16000000000000001296 & 15960655803744827408 & 10141204801825836032. \end{array}
Here the precision mask is 2^9-1=511, and the two high limbs modulo 512 are respectively 502 and 0, neither 511. Thus the optional second multiplication is not taken. Neither low limb is 2^{64}-1, so the approximation-error return is also not taken. Both high limbs are at least 2^{63}, hence have upper bit one. Direct evaluation of num imp dec2flt lemire power at -30 is -37, so the biased power arithmetic is -37+1-4-(-1022)+1=983. Shifting the two high limbs right by ten gives 9903520314283042 and 9903520314283043. The round-bit additions and the following division by two give 4951760157141521 and 4951760157141522; masking off the implicit 2^{52} bit gives 448160529771025 and 448160529771026. In both cases the low limb is greater than one, so the conjunction for the tie-clearing branch is false. All table indices, casts, additions, and shift counts just displayed lie in their fixed-width ranges, and 983<2047, so the final infinity guard is false. This establishes the two stated results. Their mantissas differ, so equality of the two records would contradict equality of their mantissa projections; hence the records are unequal. Unfolding num imp dec2flt common BiasedFp Insts CoreCmpPartialEqBiasedFp eq returns ok false.
We now verify the dispatch assertion in the lemma statement directly from num imp dec2flt dec2flt with trace. After the stated parse_number and fast-path results, the first conversion is (448160529771025,983). Since many_digits is true and 983\geq0, the extracted second-computation guard is true. Its checked mantissa increment succeeds because 1000000000000000080+1=1000000000000000081<2^{64}. The stated second conversion and false comparison therefore take the unequal arm, which keeps the first mantissa, replaces its biased power by -1, and sets the forced_deferral flag. The immediately following slow-path guard is -1<0, so it invokes the binary64 parse_long_mantissa(body) call appearing in the statement. Thus the two unequal adjacent results do force slow dispatch; no caller hypothesis is being used for this branch calculation.
It remains to execute the beginning of the slow parser. In num imp dec2flt decimal seq parse decimal seq, num imp dec2flt decimal seq DecimalSeq Insts CoreDefaultDefault default first creates a sequence with num_digits=0 and a zeroed array of length 768; the same bound is the exact num imp dec2flt decimal seq DecimalSeq MAX DIGITS value. The leading-zero loop removes the integer zero and leaves the point, and the first call to num imp dec2flt decimal seq parse digits into seq consumes no byte. The point branch names the entire fractional suffix first, of length 2^{31}. Its fractional leading-zero loop removes exactly eleven bytes and stops at 1, leaving 19+K=2147483637 digits.
At a bulk-loop state with stored count i, the guard requires at least eight remaining bytes and i+8<768. All remaining bytes are digits. Hence the direct declarations SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice read u64, num imp dec2flt common is 8digits, and SliceU8 Insts Dec2flt modelNumImpDec2fltCommonByteSlice write u64 respectively read the next eight bytes, accept them, subtract byte 48 and write the eight digit values, after which the loop drops eight bytes and adds eight to i. The subtraction is nonnegative bytewise, the destination slice has length 768-i\geq16 at every executed start, and the written eight-byte prefix is therefore in bounds. The possible starting counts are therefore 0,8,\ldots,752. Each of these 95 starts succeeds because 752+8=760<768; at the next start i=760, the storage guard is the false statement 760+8<768. Thus the bulk loop performs exactly 95 iterations, consumes and stores 95\cdot8=760 digits, and leaves 2147483637-760=2147482877 digits.
The following scalar digit loop consumes all those remaining bytes. By num imp dec2flt decimal seq DecimalSeq try add digit, each iteration increments num_digits, but it updates the array only while the old count is below 768. Starting from 760, exactly its first eight iterations store, filling indices 760 through 767; all later iterations leave the now 768-element stored prefix unchanged while continuing to count and consume digits. The largest count is 760+2147482877=2147483637<2^{64}, so no checked usize increment fails. The returned residual is empty, of the same contents and length zero as the chosen remainder.
The next three lines of the pinned decimal-sequence definition cast those two lengths and subtract. Aeneas UScalar.hcast is the Rust truncating as cast; with the 64-bit source width from Assumptions, the low 32 bits of 2^{31} denote -2147483648=\texttt{i32::MIN}, while zero casts to zero. The extracted subtraction is checked signed subtraction. Its mathematical result would be 2147483648, one above i32::MAX, so it returns fail integerOverflow. This happens before trailing-zero counting or any later decimal arithmetic. Result-monad binding propagates the same failure out of parse_decimal_seq. Finally, num imp dec2flt slow parse long mantissa first constructs its zero and infinity records normally using the cited zero_pow2 and INFINITE_POWER declarations, then binds parse_decimal_seq before examining the decimal sequence. The identical failure therefore propagates from that bind. It also propagates from the slow call selected in the dispatcher calculation above, before any assembly. This proves every conjunct and the stated forced-dispatch claim.

Lean proof


  let firstBytes : List Std.U8 :=
    List.replicate 11 48#u8 ++
      [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
      List.replicate 2147483618 48#u8
  have hfirstBytesLen : firstBytes.length = 2147483648 := by
    simp only [firstBytes, List.length_append, List.length_replicate,
      List.length_cons, List.length_nil]
  have hfirstBound : firstBytes.length <= Usize.max := by
    rw [hfirstBytesLen]
    simp [Usize.max, Usize.numBits, Dec2Flt.configured_x86_64_numBits]
  let first : Slice Std.U8 := ⟨firstBytes, hfirstBound⟩
  have hfirst : first.val =
      List.replicate 11 48#u8 ++
        [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
          48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
          48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
        List.replicate 2147483618 48#u8 := by
    rfl
  have hfirstLen : first.val.length = 2147483648 := by
    simpa [first] using hfirstBytesLen
  have hpointBound : (46#u8 :: first.val).length <= Usize.max := by
    rw [List.length_cons, hfirstLen]
    simp [Usize.max, Usize.numBits, Dec2Flt.configured_x86_64_numBits]
  let point : Slice Std.U8 := ⟨46#u8 :: first.val, hpointBound⟩
  have hpoint : point.val = 46#u8 :: first.val := by rfl
  have hpointLen : point.val.length = 2147483649 := by
    rw [hpoint, List.length_cons, hfirstLen]
  have hbodyBound : (48#u8 :: point.val).length <= Usize.max := by
    rw [List.length_cons, hpointLen]
    simp [Usize.max, Usize.numBits, Dec2Flt.configured_x86_64_numBits]
  let body : Slice Std.U8 := ⟨48#u8 :: point.val, hbodyBound⟩
  have hbodyCons : body.val = 48#u8 :: point.val := by rfl
  have hbody : body.val = [48#u8, 46#u8] ++ first.val := by
    rw [hbodyCons, hpoint]
    rfl
  have hbodyLen : body.val.length = 2147483650 := by
    rw [hbodyCons, List.length_cons, hpointLen]
  let remainder : Slice Std.U8 := ⟨[], by simp⟩
  have hremainder : remainder.val = [] := by rfl
  have hremainderLen : remainder.val.length = 0 := by rfl
  let d : num.imp.dec2flt.decimal.Decimal := {
    exponent := (-30)#i64
    mantissa := 1000000000000000080#u64
    negative := false
    many_digits := true
  }
  have hparse : num.imp.dec2flt.parse.parse_number body = ok (some d) := by
    simpa [d] using
      ParserNumericRecordCertificate body first point hfirst hpoint hbodyCons
  have hd : d = {
      exponent := (-30)#i64
      mantissa := 1000000000000000080#u64
      negative := false
      many_digits := true } := by
    rfl
  have hfast :
      num.imp.dec2flt.decimal.Decimal.try_fast_path
          F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
          F64.Insts.CoreOpsArithDivF64F64
          F64.Insts.CoreOpsArithMulF64F64
          F64.Insts.CoreOpsArithNegF64 d = ok none := by
    simpa [d] using ParserNumericFastPathCertificate
  rcases ParserNumericLemirePairCertificate with ⟨hlemire0, hlemire1⟩
  have hne : ({ m := 448160529771025#u64, p_biased := 983#i32 } :
      num.imp.dec2flt.common.BiasedFp) ≠
      { m := 448160529771026#u64, p_biased := 983#i32 } := by
    intro h
    have hm := congrArg num.imp.dec2flt.common.BiasedFp.m h
    scalar_tac
  have heq :
      num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq
        { m := 448160529771025#u64, p_biased := 983#i32 }
        { m := 448160529771026#u64, p_biased := 983#i32 } = ok false := by
    rfl
  have hcast : UScalar.hcast .I32 2147483648#usize =
      (-2147483648)#i32 := by
    rw [IScalar.eq_equiv_bv_eq]
    apply BitVec.eq_of_toNat_eq
    simp only [UScalar.hcast, BitVec.zeroExtend_eq_setWidth,
      BitVec.toNat_setWidth, UScalar.bv_toNat, I32.ofInt_bv,
      BitVec.toNat_ofInt]
    norm_num
    rfl
  have hsub : ((0#i32 : Std.I32) - (-2147483648)#i32) =
      fail integerOverflow := by
    rfl
  have hdecimal : num.imp.dec2flt.decimal_seq.parse_decimal_seq body =
      fail integerOverflow :=
    ParserNumericDecimalOverflowCertificate body first hfirst hbody
  have hslow :
      num.imp.dec2flt.slow.parse_long_mantissa
          F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64.FloatInst body =
        fail integerOverflow :=
    ParserNumericSlowPropagationCertificate body hdecimal
  exact ⟨body, first, remainder, d, hfirst, hbody, hremainder,
    hbodyLen, hfirstLen, hremainderLen, hparse, hd, hfast,
    hlemire0, hlemire1, hne, heq, hcast, hsub, hdecimal, hslow⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.Assumptions
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64_MAX_EXPONENT_FAST_PATH
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_LARGEST_POWER_OF_TEN
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SMALLEST_POWER_OF_TEN
import Tablet.ModelF64MantissaDigits
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_offset_from
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_read_u64
import Tablet.SliceU8_Insts_Dec2flt_modelNumImpDec2fltCommonByteSlice_write_u64
import Tablet.num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq
import Tablet.num_imp_dec2flt_common_BiasedFp_zero_pow2
import Tablet.num_imp_dec2flt_common_is_8digits
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_decimal_Decimal_can_use_fast_path
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_Insts_CoreDefaultDefault_default
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_MAX_DIGITS
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq_try_add_digit
import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq
import Tablet.num_imp_dec2flt_decimal_seq_parse_digits_into_seq
import Tablet.num_imp_dec2flt_fpu_fpu_precision_set_precision
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_lemire_compute_product_approx
import Tablet.num_imp_dec2flt_lemire_full_multiplication
import Tablet.num_imp_dec2flt_lemire_power
import Tablet.num_imp_dec2flt_parse_adjust_many_digit_count
import Tablet.num_imp_dec2flt_parse_MIN_19DIGIT_INT
import Tablet.num_imp_dec2flt_parse_parse_8digits
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_try_parse_19digits
import Tablet.num_imp_dec2flt_parse_try_parse_digits
import Tablet.num_imp_dec2flt_Lemire_MIN_EXPONENT_FAST_PATH_default
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_table_LARGEST_POWER_OF_FIVE
import Tablet.num_imp_dec2flt_table_POWER_OF_FIVE_128
import Tablet.num_imp_dec2flt_table_SMALLEST_POWER_OF_FIVE
import Tablet.num_imp_traits_Float_EXP_BIAS_default
import Tablet.num_imp_traits_Float_EXP_BITS_default
import Tablet.num_imp_traits_Float_EXP_MIN_default
import Tablet.num_imp_traits_Float_EXP_SAT_default
import Tablet.num_imp_traits_Float_INFINITE_POWER_default
import Tablet.num_imp_traits_Float_SIG_BITS_default
import Tablet.ParserNumericRecordCertificate
import Tablet.ParserNumericFastPathCertificate
import Tablet.ParserNumericLemirePairCertificate
import Tablet.ParserNumericDecimalOverflowCertificate
import Tablet.ParserNumericSlowPropagationCertificate

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNumericSlowPathOverflowWitness]
theorem ParserNumericSlowPathOverflowWitness :
    exists (body first remainder : Slice Std.U8)
        (d : num.imp.dec2flt.decimal.Decimal),
      first.val = List.replicate 11 48#u8 ++
        [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
          48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
          48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
        List.replicate 2147483618 48#u8 /\
      body.val = [48#u8, 46#u8] ++ first.val /\
      remainder.val = [] /\
      body.val.length = 2147483650 /\
      first.val.length = 2147483648 /\
      remainder.val.length = 0 /\
      num.imp.dec2flt.parse.parse_number body = ok (some d) /\
      d = {
        exponent := (-30)#i64
        mantissa := 1000000000000000080#u64
        negative := false
        many_digits := true
      } /\
      num.imp.dec2flt.decimal.Decimal.try_fast_path
          F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
          F64.Insts.CoreOpsArithDivF64F64
          F64.Insts.CoreOpsArithMulF64F64
          F64.Insts.CoreOpsArithNegF64 d = ok none /\
      num.imp.dec2flt.lemire.compute_float
          F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64.FloatInst
          (-30)#i64 1000000000000000080#u64 =
        ok { m := 448160529771025#u64, p_biased := 983#i32 } /\
      num.imp.dec2flt.lemire.compute_float
          F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64.FloatInst
          (-30)#i64 1000000000000000081#u64 =
        ok { m := 448160529771026#u64, p_biased := 983#i32 } /\
      ({ m := 448160529771025#u64, p_biased := 983#i32 } :
          num.imp.dec2flt.common.BiasedFp) ≠
        { m := 448160529771026#u64, p_biased := 983#i32 } /\
      num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq
          { m := 448160529771025#u64, p_biased := 983#i32 }
          { m := 448160529771026#u64, p_biased := 983#i32 } = ok false /\
      UScalar.hcast .I32 2147483648#usize = (-2147483648)#i32 /\
      ((0#i32 : Std.I32) - (-2147483648)#i32) = fail integerOverflow /\
      num.imp.dec2flt.decimal_seq.parse_decimal_seq body =
        fail integerOverflow /\
      num.imp.dec2flt.slow.parse_long_mantissa
          F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64.FloatInst body =
        fail integerOverflow := by
-- BODY
  let firstBytes : List Std.U8 :=
    List.replicate 11 48#u8 ++
      [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
        48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
      List.replicate 2147483618 48#u8
  have hfirstBytesLen : firstBytes.length = 2147483648 := by
    simp only [firstBytes, List.length_append, List.length_replicate,
      List.length_cons, List.length_nil]
  have hfirstBound : firstBytes.length <= Usize.max := by
    rw [hfirstBytesLen]
    simp [Usize.max, Usize.numBits, Dec2Flt.configured_x86_64_numBits]
  let first : Slice Std.U8 := ⟨firstBytes, hfirstBound⟩
  have hfirst : first.val =
      List.replicate 11 48#u8 ++
        [49#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
          48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8, 48#u8,
          48#u8, 48#u8, 48#u8, 56#u8, 48#u8] ++
        List.replicate 2147483618 48#u8 := by
    rfl
  have hfirstLen : first.val.length = 2147483648 := by
    simpa [first] using hfirstBytesLen
  have hpointBound : (46#u8 :: first.val).length <= Usize.max := by
    rw [List.length_cons, hfirstLen]
    simp [Usize.max, Usize.numBits, Dec2Flt.configured_x86_64_numBits]
  let point : Slice Std.U8 := ⟨46#u8 :: first.val, hpointBound⟩
  have hpoint : point.val = 46#u8 :: first.val := by rfl
  have hpointLen : point.val.length = 2147483649 := by
    rw [hpoint, List.length_cons, hfirstLen]
  have hbodyBound : (48#u8 :: point.val).length <= Usize.max := by
    rw [List.length_cons, hpointLen]
    simp [Usize.max, Usize.numBits, Dec2Flt.configured_x86_64_numBits]
  let body : Slice Std.U8 := ⟨48#u8 :: point.val, hbodyBound⟩
  have hbodyCons : body.val = 48#u8 :: point.val := by rfl
  have hbody : body.val = [48#u8, 46#u8] ++ first.val := by
    rw [hbodyCons, hpoint]
    rfl
  have hbodyLen : body.val.length = 2147483650 := by
    rw [hbodyCons, List.length_cons, hpointLen]
  let remainder : Slice Std.U8 := ⟨[], by simp⟩
  have hremainder : remainder.val = [] := by rfl
  have hremainderLen : remainder.val.length = 0 := by rfl
  let d : num.imp.dec2flt.decimal.Decimal := {
    exponent := (-30)#i64
    mantissa := 1000000000000000080#u64
    negative := false
    many_digits := true
  }
  have hparse : num.imp.dec2flt.parse.parse_number body = ok (some d) := by
    simpa [d] using
      ParserNumericRecordCertificate body first point hfirst hpoint hbodyCons
  have hd : d = {
      exponent := (-30)#i64
      mantissa := 1000000000000000080#u64
      negative := false
      many_digits := true } := by
    rfl
  have hfast :
      num.imp.dec2flt.decimal.Decimal.try_fast_path
          F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
          F64.Insts.CoreOpsArithDivF64F64
          F64.Insts.CoreOpsArithMulF64F64
          F64.Insts.CoreOpsArithNegF64 d = ok none := by
    simpa [d] using ParserNumericFastPathCertificate
  rcases ParserNumericLemirePairCertificate with ⟨hlemire0, hlemire1⟩
  have hne : ({ m := 448160529771025#u64, p_biased := 983#i32 } :
      num.imp.dec2flt.common.BiasedFp) ≠
      { m := 448160529771026#u64, p_biased := 983#i32 } := by
    intro h
    have hm := congrArg num.imp.dec2flt.common.BiasedFp.m h
    scalar_tac
  have heq :
      num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq
        { m := 448160529771025#u64, p_biased := 983#i32 }
        { m := 448160529771026#u64, p_biased := 983#i32 } = ok false := by
    rfl
  have hcast : UScalar.hcast .I32 2147483648#usize =
      (-2147483648)#i32 := by
    rw [IScalar.eq_equiv_bv_eq]
    apply BitVec.eq_of_toNat_eq
    simp only [UScalar.hcast, BitVec.zeroExtend_eq_setWidth,
      BitVec.toNat_setWidth, UScalar.bv_toNat, I32.ofInt_bv,
      BitVec.toNat_ofInt]
    norm_num
    rfl
  have hsub : ((0#i32 : Std.I32) - (-2147483648)#i32) =
      fail integerOverflow := by
    rfl
  have hdecimal : num.imp.dec2flt.decimal_seq.parse_decimal_seq body =
      fail integerOverflow :=
    ParserNumericDecimalOverflowCertificate body first hfirst hbody
  have hslow :
      num.imp.dec2flt.slow.parse_long_mantissa
          F64.Insts.Dec2flt_modelNumImpTraitsFloatExtU64.FloatInst body =
        fail integerOverflow :=
    ParserNumericSlowPropagationCertificate body hdecimal
  exact ⟨body, first, remainder, d, hfirst, hbody, hremainder,
    hbodyLen, hfirstLen, hremainderLen, hparse, hd, hfast,
    hlemire0, hlemire1, hne, heq, hcast, hsub, hdecimal, hslow⟩

end dec2flt_model

Proof structure

Follow the declared dependencies to read the supporting statements and proofs.

Uses

All 56 entries

Explore this dependency tree

Inspect related source (200)
More program dependencies (158)
Standard-library dependencies (39)

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

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 161 entries
Technical checking records
Local closure summary
{
  "node": "ParserNumericSlowPathOverflowWitness",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "6c50c0d9fa221dd22f14a24f86d58d9c222e08326d821784da1c86f47f8526b4",
  "active_statement_hash": "4e949b82b71b3c83fea3b35f672b574d5ec2c4cc3962ac2755c95c458107d236",
  "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-126",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "ParserNumericDecimalOverflowCertificate": "adb11feefab774aa",
    "ParserNumericFastPathCertificate": "90c80057461ea9e2",
    "ParserNumericLemirePairCertificate": "8e00ab896e90d6be",
    "ParserNumericRecordCertificate": "cdd5b02a1d357d0f",
    "ParserNumericSlowPropagationCertificate": "2b68ed2a30d90c04"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_CoreOpsArithDivF64F64": "dc44e13a99fc6bed",
    "F64_Insts_CoreOpsArithMulF64F64": "1ae1a9021a654abd",
    "F64_Insts_CoreOpsArithNegF64": "2d9be310c546ea2e",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64": "60afe26c6a80cf0f",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_decimal_Decimal": "4da4ccbe640ef8e6",
    "num_imp_dec2flt_decimal_Decimal_try_fast_path": "2e4888f65a06b49f",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "244cf8318357caab",
    "num_imp_dec2flt_lemire_compute_float": "39d89e3f0a8a9d4c",
    "num_imp_dec2flt_parse_parse_number": "f73f8bc11faa6db3",
    "num_imp_dec2flt_slow_parse_long_mantissa": "cd8af64c3688b60f",
    "num_imp_traits_FloatExt": "f996e5400649797d"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:df7dbcddc31b626c9aedf898d625ef865dc81486a72dee7ec182bf3404f1027c",
  "current_fingerprint": "sound-v2:df7dbcddc31b626c9aedf898d625ef865dc81486a72dee7ec182bf3404f1027c",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}