ParserNumericOverflowPropagation

Lean checked

Statement

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

Lemma · Numeric helper overflow propagates through dispatch

There are a source-valid numeric string s and its valid exactly rendered lexeme x of byte length 9223372036854120459 for which the extracted f64 parser returns fail integerOverflow. Concretely, the bytes are a point, then 9223372036854120450 copies of ASCII 1, then e-655359. The lexeme has no leading sign or integer digits, has those 9223372036854120450 fractional digits all equal to one, and has a lower-case exponent with negative sign and digits [6,5,5,3,5,9].

Lean statement

Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.

import Tablet.DecimalGoalVocabularyDefault
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.ModelSliceFirst
import Tablet.ModelStrAsBytes
import Tablet.NumberHelperSafeLengthSharpness
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_parse_parse_number

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNumericOverflowPropagation]
theorem ParserNumericOverflowPropagation :
    exists (s : Str) (x : DecimalLexeme),
      s.val = [46#u8] ++ List.replicate 9223372036854120450 49#u8 ++
        [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8] /\
      s.val.length = 9223372036854120459 /\
      x = {
        leadingSign := none
        integerDigits := []
        fractionDigits := some (List.replicate 9223372036854120450 1)
        exponent := some (false, some true, [6, 5, 5, 3, 5, 9])
      } /\
      DecimalGoalVocabularyDefault.sourceString s /\
      DecimalGoalVocabularyDefault.validNumeric x /\
      DecimalGoalVocabularyDefault.bytes s =
        DecimalGoalVocabularyDefault.renderNumeric x /\
      num.imp.dec2flt.dec2flt
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64
        F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = 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

Let C=9223372036854120458 and K=C-8=9223372036854120450. Apply NumberHelperSafeLengthSharpness. It supplies an Aeneas byte slice s and lexeme x with
s.\mathit{val}=[46]\mathbin{++}\operatorname{replicate}(K,49) \mathbin{++}[101,45,54,53,53,51,53,57],
length C+1, no leading sign, no integer digits, K fractional one digits, and negative exponent digits [6,5,5,3,5,9]. Its statement gives numeric validity, exact rendering, and the execution equation
\texttt{parse\_number}(s)=\texttt{fail integerOverflow}. \tag{1}
The same Aeneas carrier is the extracted Str carrier.
It remains to establish the stronger source-string predicate, since the helper lemma needed only the source byte-slice bound. Take the Lean string made with String.ofList from the character list consisting of one ., K copies of 1, and the eight characters e-655359. Every displayed character is ASCII and its UTF-8 encoding is the corresponding single displayed byte. The standard flatMap-over-append and flatMap-over-replicate equations therefore show symbolically, without expanding the enormous list, that the UTF-8 byte list is exactly s.\mathit{val}. Its length is 1+K+8=C+1=9223372036854120459<2^{63}-1. Unfolding DecimalGoalVocabularyDefault proves sourceString s. The same definition and the helper's fields give the numeric-validity and rendering conjuncts in the statement.
Now execute only the outer dispatcher prefix. By ModelStrAsBytes, Str.as_bytes returns ok s. The list is nonempty and starts with byte 46, so ModelSliceFirst returns that byte. It is neither minus nor plus; hence no range slice is taken, the computed body is exactly s, and its nonempty test is false. The next operation of num imp dec2flt dec2flt with trace is consequently the left side of (1). Result-monad binding propagates integerOverflow immediately: none of the option match, native conversion, integer conversion, slow fallback, assembly, or sign operations is evaluated. Thus dec2flt_with_trace itself is fail integerOverflow. Finally, num imp dec2flt dec2flt binds that call before projecting the ordinary result, so the same failure propagates through the public function. This proves every conjunct, including the asserted exact parser equation.

Lean proof


  have source_of_shape : forall s : Str,
      s.val = [46#u8] ++ List.replicate 9223372036854120450 49#u8 ++
        [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8] ->
      s.val.length = 9223372036854120459 ->
      DecimalGoalVocabularyDefault.sourceString s := by
    as_aux_lemma =>
      intro s hsVal hsLen
      have byteArray_toList_eq_data (b : ByteArray) :
          b.toList = b.data.toList := by
        have aux (i : Nat) (r : List UInt8) (hi : i ≤ b.size) :
            ByteArray.toList.loop b i r =
              r.reverse ++ b.data.toList.drop i := by
          fun_induction ByteArray.toList.loop b i r with
          | case1 i r h ih =>
              rw [ih (by omega)]
              simp only [List.reverse_cons, List.append_assoc,
                List.singleton_append]
              have hlen : i < b.data.toList.length := by simpa using h
              rw [List.drop_eq_getElem_cons hlen]
              congr
              cases b
              rename_i data
              exact getElem!_pos data i (by simpa using h)
          | case2 i r h =>
              have hieq : i = b.size := by omega
              simp [hieq]
        unfold ByteArray.toList
        simpa using aux 0 [] (Nat.zero_le _)
      have utf8_ofList (l : List Char) :
          (String.ofList l).toUTF8.toList =
            l.flatMap String.utf8EncodeChar := by
        rw [String.toUTF8, String.toByteArray_ofList]
        rw [byteArray_toList_eq_data]
        simp only [List.utf8Encode, List.toList_data_toByteArray]
      have utf8_ones (n : Nat) :
          (List.replicate n '1').flatMap String.utf8EncodeChar =
            List.replicate n (49 : UInt8) := by
        rw [List.flatMap_replicate]
        have h : String.utf8EncodeChar '1' = [(49 : UInt8)] := by decide
        rw [h, List.flatten_replicate_singleton]
      dsimp only [DecimalGoalVocabularyDefault]
      constructor
      · rw [hsLen]
        norm_num
      · refine ⟨String.ofList
            (['.'] ++ List.replicate 9223372036854120450 '1' ++
              ['e', '-', '6', '5', '5', '3', '5', '9']), ?_⟩
        rw [hsVal, utf8_ofList]
        simp only [List.flatMap_append, utf8_ones, List.flatMap_cons,
          List.flatMap_nil, List.map_append, List.map_replicate,
          List.map_cons, List.map_nil]
        have hPoint : (String.utf8EncodeChar '.').map UInt8.toNat = [46] := by
          decide
        have hE : (String.utf8EncodeChar 'e').map UInt8.toNat = [101] := by
          decide
        have hMinus : (String.utf8EncodeChar '-').map UInt8.toNat = [45] := by
          decide
        have hSix : (String.utf8EncodeChar '6').map UInt8.toNat = [54] := by
          decide
        have hFive : (String.utf8EncodeChar '5').map UInt8.toNat = [53] := by
          decide
        have hThree : (String.utf8EncodeChar '3').map UInt8.toNat = [51] := by
          decide
        have hNine : (String.utf8EncodeChar '9').map UInt8.toNat = [57] := by
          decide
        have hOne : UInt8.toNat (49 : UInt8) = 49 := by decide
        rw [hPoint, hE, hMinus, hSix, hFive, hThree, hNine]
        rw [hOne]
        norm_num
  have public_failure : forall s : Str,
      s.val = [46#u8] ++ List.replicate 9223372036854120450 49#u8 ++
        [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8] ->
      num.imp.dec2flt.parse.parse_number s = fail integerOverflow ->
      num.imp.dec2flt.dec2flt
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64
        F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = fail integerOverflow := by
    as_aux_lemma =>
      intro s hsVal hparse
      have tail_exists : exists tail : List Std.U8,
          tail = List.replicate 9223372036854120450 49#u8 ++
            [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8,
              57#u8] := by
        exact ⟨_, rfl⟩
      obtain ⟨tail, htail⟩ := tail_exists
      have hcompact : s.val = 46#u8 :: tail := by
        rw [htail]
        simpa only [List.cons_append, List.nil_append] using hsVal
      simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
        core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes,
        ModelSliceFirst, hcompact, hparse]
  obtain ⟨s, x, hsVal, hsLen, hx, hsourceSlice, hnonempty, hunsigned,
    hvalid, hrenders, hparse⟩ := NumberHelperSafeLengthSharpness
  have hsource := source_of_shape s hsVal hsLen
  have hpublic := public_failure s hsVal hparse
  exact ⟨s, x, hsVal, hsLen, hx, hsource, hvalid, hrenders, hpublic⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.ModelSliceFirst
import Tablet.ModelStrAsBytes
import Tablet.NumberHelperSafeLengthSharpness
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_parse_parse_number

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNumericOverflowPropagation]
theorem ParserNumericOverflowPropagation :
    exists (s : Str) (x : DecimalLexeme),
      s.val = [46#u8] ++ List.replicate 9223372036854120450 49#u8 ++
        [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8] /\
      s.val.length = 9223372036854120459 /\
      x = {
        leadingSign := none
        integerDigits := []
        fractionDigits := some (List.replicate 9223372036854120450 1)
        exponent := some (false, some true, [6, 5, 5, 3, 5, 9])
      } /\
      DecimalGoalVocabularyDefault.sourceString s /\
      DecimalGoalVocabularyDefault.validNumeric x /\
      DecimalGoalVocabularyDefault.bytes s =
        DecimalGoalVocabularyDefault.renderNumeric x /\
      num.imp.dec2flt.dec2flt
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64
        F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = fail integerOverflow := by
-- BODY
  have source_of_shape : forall s : Str,
      s.val = [46#u8] ++ List.replicate 9223372036854120450 49#u8 ++
        [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8] ->
      s.val.length = 9223372036854120459 ->
      DecimalGoalVocabularyDefault.sourceString s := by
    as_aux_lemma =>
      intro s hsVal hsLen
      have byteArray_toList_eq_data (b : ByteArray) :
          b.toList = b.data.toList := by
        have aux (i : Nat) (r : List UInt8) (hi : i ≤ b.size) :
            ByteArray.toList.loop b i r =
              r.reverse ++ b.data.toList.drop i := by
          fun_induction ByteArray.toList.loop b i r with
          | case1 i r h ih =>
              rw [ih (by omega)]
              simp only [List.reverse_cons, List.append_assoc,
                List.singleton_append]
              have hlen : i < b.data.toList.length := by simpa using h
              rw [List.drop_eq_getElem_cons hlen]
              congr
              cases b
              rename_i data
              exact getElem!_pos data i (by simpa using h)
          | case2 i r h =>
              have hieq : i = b.size := by omega
              simp [hieq]
        unfold ByteArray.toList
        simpa using aux 0 [] (Nat.zero_le _)
      have utf8_ofList (l : List Char) :
          (String.ofList l).toUTF8.toList =
            l.flatMap String.utf8EncodeChar := by
        rw [String.toUTF8, String.toByteArray_ofList]
        rw [byteArray_toList_eq_data]
        simp only [List.utf8Encode, List.toList_data_toByteArray]
      have utf8_ones (n : Nat) :
          (List.replicate n '1').flatMap String.utf8EncodeChar =
            List.replicate n (49 : UInt8) := by
        rw [List.flatMap_replicate]
        have h : String.utf8EncodeChar '1' = [(49 : UInt8)] := by decide
        rw [h, List.flatten_replicate_singleton]
      dsimp only [DecimalGoalVocabularyDefault]
      constructor
      · rw [hsLen]
        norm_num
      · refine ⟨String.ofList
            (['.'] ++ List.replicate 9223372036854120450 '1' ++
              ['e', '-', '6', '5', '5', '3', '5', '9']), ?_⟩
        rw [hsVal, utf8_ofList]
        simp only [List.flatMap_append, utf8_ones, List.flatMap_cons,
          List.flatMap_nil, List.map_append, List.map_replicate,
          List.map_cons, List.map_nil]
        have hPoint : (String.utf8EncodeChar '.').map UInt8.toNat = [46] := by
          decide
        have hE : (String.utf8EncodeChar 'e').map UInt8.toNat = [101] := by
          decide
        have hMinus : (String.utf8EncodeChar '-').map UInt8.toNat = [45] := by
          decide
        have hSix : (String.utf8EncodeChar '6').map UInt8.toNat = [54] := by
          decide
        have hFive : (String.utf8EncodeChar '5').map UInt8.toNat = [53] := by
          decide
        have hThree : (String.utf8EncodeChar '3').map UInt8.toNat = [51] := by
          decide
        have hNine : (String.utf8EncodeChar '9').map UInt8.toNat = [57] := by
          decide
        have hOne : UInt8.toNat (49 : UInt8) = 49 := by decide
        rw [hPoint, hE, hMinus, hSix, hFive, hThree, hNine]
        rw [hOne]
        norm_num
  have public_failure : forall s : Str,
      s.val = [46#u8] ++ List.replicate 9223372036854120450 49#u8 ++
        [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8, 57#u8] ->
      num.imp.dec2flt.parse.parse_number s = fail integerOverflow ->
      num.imp.dec2flt.dec2flt
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64
        F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = fail integerOverflow := by
    as_aux_lemma =>
      intro s hsVal hparse
      have tail_exists : exists tail : List Std.U8,
          tail = List.replicate 9223372036854120450 49#u8 ++
            [101#u8, 45#u8, 54#u8, 53#u8, 53#u8, 51#u8, 53#u8,
              57#u8] := by
        exact ⟨_, rfl⟩
      obtain ⟨tail, htail⟩ := tail_exists
      have hcompact : s.val = 46#u8 :: tail := by
        rw [htail]
        simpa only [List.cons_append, List.nil_append] using hsVal
      simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
        core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes,
        ModelSliceFirst, hcompact, hparse]
  obtain ⟨s, x, hsVal, hsLen, hx, hsourceSlice, hnonempty, hunsigned,
    hvalid, hrenders, hparse⟩ := NumberHelperSafeLengthSharpness
  have hsource := source_of_shape s hsVal hsLen
  have hpublic := public_failure s hsVal hparse
  exact ⟨s, x, hsVal, hsLen, hx, hsource, hvalid, hrenders, hpublic⟩

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (201)
More program dependencies (159)
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 166 entries
Technical checking records
Local closure summary
{
  "node": "ParserNumericOverflowPropagation",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "62fe88fecb02fd925c57a9b1622e70d61990e1acdb370baf27cae850f58558e5",
  "active_statement_hash": "ebf42c88c62d8ef013371606645a9a2a499c27365620f4ba26349ab4eadf2c47",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-125",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "NumberHelperSafeLengthSharpness": "4e8605e902e86049",
    "num_imp_dec2flt_dec2flt_with_trace": "8f54814ba9c190ea",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "65227461bf3cac06",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "DecimalLexeme": "8ad754cf2c272e73",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_CoreOpsArithDivF64F64": "dc44e13a99fc6bed",
    "F64_Insts_CoreOpsArithMulF64F64": "1ae1a9021a654abd",
    "F64_Insts_CoreOpsArithNegF64": "2d9be310c546ea2e",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64": "60afe26c6a80cf0f",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "ModelSliceFirst": "a31394b3c1080f71",
    "ModelStrAsBytes": "024fe35b4dbfa9a3",
    "Preamble": "86dc391ab250c79b",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "core_ops_arith_Div": "6e5df64b87169aa0",
    "core_ops_arith_Mul": "6e5df64b87169aa0",
    "core_ops_arith_Neg": "0ff07135a60bcbf9",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "7bda5de02611ad76",
    "num_imp_dec2flt_Dec2FltTrace": "ef050fc88fd50bb9",
    "num_imp_dec2flt_Lemire": "1923f90c53d323e6",
    "num_imp_dec2flt_biased_fp_to_float": "acdde060e8d35ca7",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_dec2flt": "f9f7d93449a25efa",
    "num_imp_dec2flt_dec2flt_with_trace": "ebe6a57c6dce0df6",
    "num_imp_dec2flt_decimal_Decimal": "b702e549017701b8",
    "num_imp_dec2flt_decimal_Decimal_try_fast_path": "2e4888f65a06b49f",
    "num_imp_dec2flt_lemire_compute_float": "39d89e3f0a8a9d4c",
    "num_imp_dec2flt_parse_parse_inf_nan": "85655c19a8791b54",
    "num_imp_dec2flt_parse_parse_number": "f73f8bc11faa6db3",
    "num_imp_dec2flt_pfe_empty": "89046d1da5ac1ce2",
    "num_imp_dec2flt_pfe_invalid": "21db875427d92c6d",
    "num_imp_dec2flt_slow_parse_long_mantissa": "cd8af64c3688b60f",
    "num_imp_traits_Float": "02acccb9db3e30f2",
    "num_imp_traits_FloatExt": "f996e5400649797d"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:b1ed66b4489dd3457c54aceb96d7b8f521af99f16c307157f809f286cdba7219",
  "current_fingerprint": "sound-v2:b1ed66b4489dd3457c54aceb96d7b8f521af99f16c307157f809f286cdba7219",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}