ParserNumericTraceShape

Lean checked

Statement

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

Lemma

Let s be a source string and x a valid numeric lexeme such that the byte values of s are renderNumeric(x). Let f be an F64 binary64 word and let t be a Dec2FltTrace F64. Suppose
\begin{split} &\texttt{num.imp.dec2flt.dec2flt\_with\_trace}\\ &\quad\texttt{F64.Insts.Dec2flt\_modelNumImpDec2fltLemireU64}\\ &\quad\texttt{F64.Insts.CoreOpsArithDivF64F64}\\ &\quad\texttt{F64.Insts.CoreOpsArithMulF64F64}\\ &\quad\texttt{F64.Insts.CoreOpsArithNegF64}\ s =\texttt{ok (Ok }f\texttt{, }t\texttt{)}. \end{split}
Put x_0 equal to x with only leadingSign replaced by none. Then one of the following surviving trace shapes is exhibited.
In the fast case there are a body b, sign Boolean n, parsed record d, fast input d_f, and optional fast result o such that t = FastPath b n (some d) d_f o f; moreover b is nonempty and source-valid, its byte values are renderNumeric(x_0), $n=lexicalNegative(x), and parse_number(b) = ok (some d).
In the assembled case there are an assembly record a and parsed record d such that t = Assembled a; moreover a.\mathit{body} is nonempty and source-valid, its byte values are renderNumeric(x_0), a.\mathit{negative}=\operatorname{lexicalNegative}(x), a.\mathit{parse\_number\_result}=\texttt{some }d, and parse_number(a.\mathit{body}) = ok (some d). The constructor equalities and all accompanying facts are the conjunctions displayed in the Lean statement.

Lean statement

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

import Tablet.ParserSuccessfulTrace
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.SpecialHelperRejection
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.num_imp_dec2flt_Dec2FltAssemblyTrace
import Tablet.num_imp_dec2flt_Dec2FltTrace
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_inf_nan

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNumericTraceShape]
theorem ParserNumericTraceShape :
    ∀ (s : Str) (x : DecimalLexeme) (f : F64)
      (tr : num.imp.dec2flt.Dec2FltTrace F64),
      DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.bytes s =
        DecimalGoalVocabularyDefault.renderNumeric x ->
      num.imp.dec2flt.dec2flt_with_trace
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s =
          ok (core.result.Result.Ok f, tr) ->
      (∃ (body : Slice Std.U8) (negative : Bool)
          (parsed fastInput : num.imp.dec2flt.decimal.Decimal)
          (fastResult : Option F64),
          tr = num.imp.dec2flt.Dec2FltTrace.FastPath body negative
            (some parsed) fastInput fastResult f ∧
          body.val ≠ [] ∧ SourceValidByteSlice body ∧
          DecimalGoalVocabularyDefault.bytes body =
            DecimalGoalVocabularyDefault.renderNumeric
              { x with leadingSign := none } ∧
          negative = DecimalGoalVocabularyDefault.lexicalNegative x ∧
          num.imp.dec2flt.parse.parse_number body = ok (some parsed)) ∨
        ∃ (assemblyTrace : num.imp.dec2flt.Dec2FltAssemblyTrace F64)
          (parsed : num.imp.dec2flt.decimal.Decimal),
          tr = num.imp.dec2flt.Dec2FltTrace.Assembled assemblyTrace ∧
          assemblyTrace.body.val ≠ [] ∧
          SourceValidByteSlice assemblyTrace.body ∧
          DecimalGoalVocabularyDefault.bytes assemblyTrace.body =
            DecimalGoalVocabularyDefault.renderNumeric
              { x with leadingSign := none } ∧
          assemblyTrace.negative =
            DecimalGoalVocabularyDefault.lexicalNegative x ∧
          assemblyTrace.parse_number_result = some parsed ∧
          num.imp.dec2flt.parse.parse_number assemblyTrace.body =
            ok (some parsed) := 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 B=\operatorname{bytes}(s). Unfold DecimalGoalVocabularyDefault. Validity says that every recorded digit is below ten, that an exponent (when present) has a digit, and that the integer and fractional parts contain at least one digit between them. Consequently the rendered list B is nonempty. If x has negative sign its first byte is 45; if it has positive sign its first byte is 43; and if it has no sign its first byte is a digit byte in 48,\ldots,57 or the decimal point 46. In particular, after deleting a present sign, the remaining list is still nonempty and is exactly renderNumeric(x_0).
By ModelStrAsBytes, the first bind in num imp dec2flt dec2flt with trace returns the full slice whose byte values are B. The source-string length bound also makes this slice source-valid in the sense of SourceValidByteSlice. By ModelSliceFirst, its nonempty first call returns the first byte c. Now inspect the two sign branches of the cited dispatcher definition. For c=45 the in-bounds range-from-one operation deletes precisely that negative sign; for c=43 it deletes precisely the positive sign; otherwise it returns the original slice. Denote the resulting slice by b. The range operation cannot fail in either sign case because the byte just returned at index zero exists. Therefore
b.\mathit{val}\ne[],\qquad \operatorname{bytes}(b)=\operatorname{renderNumeric}(x_0),\qquad (c=45)=\operatorname{lexicalNegative}(x). \tag{1}
Deleting zero or one byte cannot increase length, so the source bound on B and SourceValidByteSlice give SourceValidByteSlice(b).
The next emptiness test is false by (1), so the dispatcher reaches parse_number(b). A failure at this or any later bind would propagate as a failed Result, contradicting the assumed normal equation. We show that the returned option cannot be none. The unsigned byte list in (1) begins with a digit or decimal point. Hence it is neither a case-insensitive inf/infinity body nor a case-insensitive nan body under the specialLiteral definition in DecimalGoalVocabularyDefault.
It is important here that the rejection theorem is applied to the actual instance passed by the dispatcher. Unfold F64 Insts Dec2flt modelNumImpDec2fltLemireU64: its traitsFloatExtInst field is exactly F64 Insts Dec2flt modelNumImpTraitsFloatExtU64. Unfold that record: its FloatInst field is exactly F64 Insts Dec2flt modelNumImpTraitsFloatU64; unfolding the latter identifies the concrete binary64 float record used by the specialized helper. Thus the call in num imp dec2flt dec2flt with trace is literally the call in the conclusion of SpecialHelperRejection, with slice b and Boolean c=45. Source-validity and the two keyword exclusions just proved discharge its hypotheses, so the call returns ok none. If parse_number(b) had returned ok none, the following match would therefore take its invalid arm and return first component Err, not the assumed Ok f. Hence, for some record r,
\texttt{parse\_number($b$)=ok (some $r$)}. \tag{2}
Continue through the two arms after (2) in the extracted dispatcher. Its native call is made on r with only negative replaced by c=45. If the call returns some v, the returned pair is definitionally
\texttt{(Ok $v$, FastPath $b$ $(c=45)$ (some $r$) $r[negative:=(c=45)]$ (some $v$) $v$)}.
Equality with the assumed pair gives v=f by constructor injectivity. Choose b,c=45,r,r[\mathit{negative}:=(c=45)], and some f. The exact FastPath equality follows, while (1), source-validity, and (2) give all five accompanying facts of the first alternative.
If the native result is none, every successful continuation returns an Assembled constructor. Let a be the complete record displayed by that return. Both final sign arms set a.\mathit{body}=b and set a.\mathit{negative} to the Boolean c=45. They set
a.\mathit{parse\_number\_result} =\texttt{some }\{r\texttt{ with many\_digits}:=b_1\},
where the immediately preceding branch sets b_1 to true when r.\mathit{many\_digits} is true and to false otherwise. A case split on that Boolean shows that this record update is exactly r. Thus, choosing d=r, the field is some d and (2) is precisely the required parse equation for a.\mathit{body}. Constructor injectivity gives the exact equation t = Assembled a; (1) and the source-validity argument give the remaining assembled facts. These native-result cases exhaust the successful numeric execution and establish the disjunction.

Lean proof


  intro s x f tr hsource hvalid hbytes htrace
  have bind_ok_inv : ∀ {α β : Type} (r : Result α) (g : α → Result β) y,
      Bind.bind r g = ok y → ∃ z, r = ok z ∧ g z = ok y := by
    intro α β r g y hr
    cases r with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hr
    | div => simp [Bind.bind, Aeneas.Std.bind] at hr
    | ok z => exact ⟨z, rfl, hr⟩
  have numeric_head : ∀ (y : DecimalLexeme),
      y.leadingSign = none ->
      DecimalGoalVocabularyDefault.validNumeric y ->
      ∃ n rest, DecimalGoalVocabularyDefault.renderNumeric y = n :: rest ∧
        (n = 46 ∨ (48 ≤ n ∧ n ≤ 57)) := by
    intro y hsign hval
    rcases y with ⟨sign, ints, frac, exp⟩
    simp only at hsign
    subst sign
    dsimp only [DecimalGoalVocabularyDefault] at hval ⊢
    rcases hval with ⟨hints, hfrac, hnonempty, hexp⟩
    cases ints with
    | nil =>
        simp only [List.map_nil, List.nil_append] at hnonempty ⊢
        cases frac with
        | none => simp at hnonempty
        | some ds =>
            cases ds with
            | nil => simp at hnonempty
            | cons d ds => exact ⟨46, _, rfl, Or.inl rfl⟩
    | cons d ds =>
        have hd : d < 10 := hints d (by simp)
        exact ⟨48 + d, _, rfl, Or.inr (by omega)⟩
  have numeric_not_special : ∀ (y : DecimalLexeme) (nan : Bool),
      y.leadingSign = none ->
      DecimalGoalVocabularyDefault.validNumeric y ->
      ¬ DecimalGoalVocabularyDefault.specialLiteral
        (DecimalGoalVocabularyDefault.renderNumeric y) none nan := by
    intro y nan hsign hval hspecial
    obtain ⟨n, rest, hrender, hn⟩ := numeric_head y hsign hval
    rcases hspecial with ⟨body, hbody, hcase⟩
    change DecimalGoalVocabularyDefault.renderNumeric y = body at hbody
    rw [hrender] at hbody
    cases hbody
    dsimp only [DecimalGoalVocabularyDefault] at hcase
    cases nan with
    | false =>
        simp only [Bool.false_eq_true, if_false] at hcase
        rcases hcase with hcase | hcase
        · cases hcase
          rename_i hfirst _
          rcases hfirst with hfirst | hfirst <;> omega
        · cases hcase
          rename_i hfirst _
          rcases hfirst with hfirst | hfirst <;> omega
    | true =>
        simp only [if_true] at hcase
        cases hcase
        rename_i hfirst _
        rcases hfirst with hfirst | hfirst <;> omega
  let unsigned : DecimalLexeme := { x with leadingSign := none }
  have unsigned_sign : unsigned.leadingSign = none := rfl
  have unsigned_valid : DecimalGoalVocabularyDefault.validNumeric unsigned := by
    simpa [DecimalGoalVocabularyDefault, unsigned] using hvalid
  obtain ⟨head, rest, unsigned_render, head_range⟩ :=
    numeric_head unsigned unsigned_sign unsigned_valid
  unfold num.imp.dec2flt.dec2flt_with_trace at htrace
  obtain ⟨body, hbody, htrace⟩ := bind_ok_inv _ _ _ htrace
  rcases s with ⟨source, source_bound⟩
  cases source with
  | nil =>
      dsimp only [DecimalGoalVocabularyDefault] at hbytes
      cases hs : x.leadingSign with
      | none =>
          have : DecimalGoalVocabularyDefault.renderNumeric x = [] := hbytes.symm
          obtain ⟨n, tail, hn, _⟩ := numeric_head x hs hvalid
          rw [hn] at this
          simp at this
      | some sign =>
          cases sign <;> simp [DecimalGoalVocabularyDefault, hs] at hbytes
  | cons first tail =>
      have hbodyEq : body = (⟨first :: tail, source_bound⟩ : Slice Std.U8) := by
        simpa [core.str.Str.as_bytes, ModelStrAsBytes] using hbody.symm
      subst body
      obtain ⟨firstOption, hfirst, htrace⟩ := bind_ok_inv _ _ _ htrace
      have hfirstEq : firstOption = some first := by
        simpa [core.slice.Slice.first, ModelSliceFirst] using hfirst.symm
      subst firstOption
      obtain ⟨body1, hbody1, htrace⟩ := bind_ok_inv _ _ _ htrace
      have lexical :
          body1.val ≠ [] ∧ SourceValidByteSlice body1 ∧
          DecimalGoalVocabularyDefault.bytes body1 =
            DecimalGoalVocabularyDefault.renderNumeric unsigned ∧
          (decide (first = 45#u8) : Bool) =
            DecimalGoalVocabularyDefault.lexicalNegative x := by
        cases hsign : x.leadingSign with
        | none =>
            have full : first.val :: tail.map (fun b => b.val) = head :: rest := by
              calc
                first.val :: tail.map (fun b => b.val) =
                    DecimalGoalVocabularyDefault.renderNumeric x := hbytes
                _ = DecimalGoalVocabularyDefault.renderNumeric unsigned := by
                  simp [DecimalGoalVocabularyDefault, unsigned, hsign]
                _ = head :: rest := unsigned_render
            have firstVal : first.val = head := (List.cons.inj full).1
            have hminus : first ≠ 45#u8 := by
              intro heq
              subst first
              simp at firstVal
              rcases head_range with hr | hr <;> omega
            have hplus : first ≠ 43#u8 := by
              intro heq
              subst first
              simp at firstVal
              rcases head_range with hr | hr <;> omega
            simp only [hminus, hplus, if_false] at hbody1
            cases hbody1
            refine ⟨by simp, ?_, ?_, ?_⟩
            · exact hsource.1
            · simpa [DecimalGoalVocabularyDefault, unsigned, hsign] using hbytes
            · simp [DecimalGoalVocabularyDefault, hsign, hminus]
        | some sign =>
            cases sign with
            | false =>
                have full : first.val :: tail.map (fun b => b.val) =
                    43 :: DecimalGoalVocabularyDefault.renderNumeric unsigned := by
                  calc
                    first.val :: tail.map (fun b => b.val) =
                        DecimalGoalVocabularyDefault.renderNumeric x := hbytes
                    _ = 43 :: DecimalGoalVocabularyDefault.renderNumeric unsigned := by
                      simp [DecimalGoalVocabularyDefault, unsigned, hsign]
                have firstVal : first.val = 43 := (List.cons.inj full).1
                have firstEq : first = 43#u8 := UScalar.eq_of_val_eq firstVal
                have tailRender : tail.map (fun b => b.val) =
                    DecimalGoalVocabularyDefault.renderNumeric unsigned :=
                  (List.cons.inj full).2
                simp only [firstEq, reduceCtorEq, if_false, if_true] at hbody1
                simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
                  Slice.drop] at hbody1
                cases hbody1
                refine ⟨?_, ?_, ?_, ?_⟩
                · intro hempty
                  have tailEmpty : tail = [] := by simpa using hempty
                  rw [tailEmpty] at tailRender
                  simp at tailRender
                  rw [unsigned_render] at tailRender
                  simp at tailRender
                · unfold SourceValidByteSlice
                  have hslen := hsource.1
                  simp at hslen ⊢
                  omega
                · exact tailRender
                · simp [DecimalGoalVocabularyDefault, hsign, firstEq]
            | true =>
                have full : first.val :: tail.map (fun b => b.val) =
                    45 :: DecimalGoalVocabularyDefault.renderNumeric unsigned := by
                  calc
                    first.val :: tail.map (fun b => b.val) =
                        DecimalGoalVocabularyDefault.renderNumeric x := hbytes
                    _ = 45 :: DecimalGoalVocabularyDefault.renderNumeric unsigned := by
                      simp [DecimalGoalVocabularyDefault, unsigned, hsign]
                have firstVal : first.val = 45 := (List.cons.inj full).1
                have firstEq : first = 45#u8 := UScalar.eq_of_val_eq firstVal
                have tailRender : tail.map (fun b => b.val) =
                    DecimalGoalVocabularyDefault.renderNumeric unsigned :=
                  (List.cons.inj full).2
                simp only [firstEq, if_true] at hbody1
                simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
                  Slice.drop] at hbody1
                cases hbody1
                refine ⟨?_, ?_, ?_, ?_⟩
                · intro hempty
                  have tailEmpty : tail = [] := by simpa using hempty
                  rw [tailEmpty] at tailRender
                  simp at tailRender
                  rw [unsigned_render] at tailRender
                  simp at tailRender
                · unfold SourceValidByteSlice
                  have hslen := hsource.1
                  simp at hslen ⊢
                  omega
                · exact tailRender
                · simp [DecimalGoalVocabularyDefault, hsign, firstEq]
      rcases lexical with ⟨bodyNonempty, bodyValid, bodyRender, signEq⟩
      have noInf : ¬ DecimalGoalVocabularyDefault.specialLiteral
          (DecimalGoalVocabularyDefault.bytes body1) none false := by
        rw [bodyRender]
        exact numeric_not_special unsigned false unsigned_sign unsigned_valid
      have noNan : ¬ DecimalGoalVocabularyDefault.specialLiteral
          (DecimalGoalVocabularyDefault.bytes body1) none true := by
        rw [bodyRender]
        exact numeric_not_special unsigned true unsigned_sign unsigned_valid
      have specialReject :=
        SpecialHelperRejection body1 (decide (first = 45#u8))
          bodyValid noInf noNan
      obtain ⟨empty, hempty, htrace⟩ := bind_ok_inv _ _ _ htrace
      by_cases emptyTrue : empty = true
      · simp only [emptyTrue, if_true] at htrace
        obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases htrace
      · have emptyFalse : empty = false := Bool.eq_false_of_not_eq_true emptyTrue
        simp only [emptyFalse, if_false] at htrace
        obtain ⟨parsed, hparsed, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases parsed with
        | none =>
            obtain ⟨special, hspecial, htrace⟩ := bind_ok_inv _ _ _ htrace
            rw [specialReject] at hspecial
            cases hspecial
            obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases htrace
        | some r =>
            obtain ⟨fast, hfast, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases fast with
            | some value =>
                simp only at htrace
                injection htrace with hpair
                injection hpair with hresult htr
                injection hresult with hvalue
                cases hvalue
                left
                refine ⟨body1, decide (first = 45#u8), r,
                  { r with negative := decide (first = 45#u8) }, some f,
                  ?_, bodyNonempty, bodyValid, bodyRender, signEq, hparsed⟩
                exact htr.symm
            | none =>
                obtain ⟨firstPair, hfirstPair, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨phase1, hphase1, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase1 with ⟨many1, many2, firstPair1, fp, guard⟩
                have many_eq : { r with many_digits := many1 } = r := by
                  cases r with
                  | mk exponent mantissa rnegative rmany =>
                      cases hm : rmany
                      · simp [hm] at hphase1
                        rcases hphase1 with ⟨hmany, hrest⟩
                        simp [hm, hmany]
                      · simp [hm] at hphase1
                        rcases hphase1 with ⟨hmany, hrest⟩
                        simp [hm, hmany]
                obtain ⟨phase2, hphase2, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase2 with
                  ⟨post, secondExp, secondMant, secondResult, secondEqual, forced⟩
                obtain ⟨phase3, hphase3, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase3 with ⟨selected, slowGuard, slowResult⟩
                obtain ⟨i, hi, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i1, hi1, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i2, hi2, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨word, hword, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨assembled, hassembled, htrace⟩ := bind_ok_inv _ _ _ htrace
                by_cases negative : first = 45#u8
                · simp only [negative, if_true] at htrace
                  obtain ⟨result, hresult, htrace⟩ := bind_ok_inv _ _ _ htrace
                  cases htrace
                  right
                  let assemblyTrace := num.imp.dec2flt.Dec2FltAssemblyTrace.mk
                    body1 true (some { r with many_digits := many1 })
                    { r with negative := true, many_digits := many2 } none r.exponent
                    r.mantissa firstPair1 guard secondExp secondMant secondResult
                    secondEqual forced post slowGuard slowResult selected word assembled true f
                  refine ⟨assemblyTrace, r, ?_, bodyNonempty, bodyValid, bodyRender, ?_, ?_, ?_⟩
                  · rfl
                  · dsimp [assemblyTrace]
                    simpa [negative] using signEq
                  · dsimp [assemblyTrace]
                    rw [many_eq]
                  · exact hparsed
                · simp only [negative, if_false] at htrace
                  cases htrace
                  right
                  let assemblyTrace := num.imp.dec2flt.Dec2FltAssemblyTrace.mk
                    body1 false (some { r with many_digits := many1 })
                    { r with negative := false, many_digits := many2 } none r.exponent
                    r.mantissa firstPair1 guard secondExp secondMant secondResult
                    secondEqual forced post slowGuard slowResult selected word f false f
                  refine ⟨assemblyTrace, r, ?_, bodyNonempty, bodyValid, bodyRender, ?_, ?_, ?_⟩
                  · rfl
                  · dsimp [assemblyTrace]
                    simpa [negative] using signEq
                  · dsimp [assemblyTrace]
                    rw [many_eq]
                  · exact hparsed

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.ParserSuccessfulTrace
import Tablet.DecimalGoalVocabularyDefault
import Tablet.SourceValidByteSlice
import Tablet.SpecialHelperRejection
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.num_imp_dec2flt_Dec2FltAssemblyTrace
import Tablet.num_imp_dec2flt_Dec2FltTrace
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_parse_parse_inf_nan

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNumericTraceShape]
theorem ParserNumericTraceShape :
    ∀ (s : Str) (x : DecimalLexeme) (f : F64)
      (tr : num.imp.dec2flt.Dec2FltTrace F64),
      DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.bytes s =
        DecimalGoalVocabularyDefault.renderNumeric x ->
      num.imp.dec2flt.dec2flt_with_trace
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s =
          ok (core.result.Result.Ok f, tr) ->
      (∃ (body : Slice Std.U8) (negative : Bool)
          (parsed fastInput : num.imp.dec2flt.decimal.Decimal)
          (fastResult : Option F64),
          tr = num.imp.dec2flt.Dec2FltTrace.FastPath body negative
            (some parsed) fastInput fastResult f ∧
          body.val ≠ [] ∧ SourceValidByteSlice body ∧
          DecimalGoalVocabularyDefault.bytes body =
            DecimalGoalVocabularyDefault.renderNumeric
              { x with leadingSign := none } ∧
          negative = DecimalGoalVocabularyDefault.lexicalNegative x ∧
          num.imp.dec2flt.parse.parse_number body = ok (some parsed)) ∨
        ∃ (assemblyTrace : num.imp.dec2flt.Dec2FltAssemblyTrace F64)
          (parsed : num.imp.dec2flt.decimal.Decimal),
          tr = num.imp.dec2flt.Dec2FltTrace.Assembled assemblyTrace ∧
          assemblyTrace.body.val ≠ [] ∧
          SourceValidByteSlice assemblyTrace.body ∧
          DecimalGoalVocabularyDefault.bytes assemblyTrace.body =
            DecimalGoalVocabularyDefault.renderNumeric
              { x with leadingSign := none } ∧
          assemblyTrace.negative =
            DecimalGoalVocabularyDefault.lexicalNegative x ∧
          assemblyTrace.parse_number_result = some parsed ∧
          num.imp.dec2flt.parse.parse_number assemblyTrace.body =
            ok (some parsed) := by
-- BODY
  intro s x f tr hsource hvalid hbytes htrace
  have bind_ok_inv : ∀ {α β : Type} (r : Result α) (g : α → Result β) y,
      Bind.bind r g = ok y → ∃ z, r = ok z ∧ g z = ok y := by
    intro α β r g y hr
    cases r with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hr
    | div => simp [Bind.bind, Aeneas.Std.bind] at hr
    | ok z => exact ⟨z, rfl, hr⟩
  have numeric_head : ∀ (y : DecimalLexeme),
      y.leadingSign = none ->
      DecimalGoalVocabularyDefault.validNumeric y ->
      ∃ n rest, DecimalGoalVocabularyDefault.renderNumeric y = n :: rest ∧
        (n = 46 ∨ (48 ≤ n ∧ n ≤ 57)) := by
    intro y hsign hval
    rcases y with ⟨sign, ints, frac, exp⟩
    simp only at hsign
    subst sign
    dsimp only [DecimalGoalVocabularyDefault] at hval ⊢
    rcases hval with ⟨hints, hfrac, hnonempty, hexp⟩
    cases ints with
    | nil =>
        simp only [List.map_nil, List.nil_append] at hnonempty ⊢
        cases frac with
        | none => simp at hnonempty
        | some ds =>
            cases ds with
            | nil => simp at hnonempty
            | cons d ds => exact ⟨46, _, rfl, Or.inl rfl⟩
    | cons d ds =>
        have hd : d < 10 := hints d (by simp)
        exact ⟨48 + d, _, rfl, Or.inr (by omega)⟩
  have numeric_not_special : ∀ (y : DecimalLexeme) (nan : Bool),
      y.leadingSign = none ->
      DecimalGoalVocabularyDefault.validNumeric y ->
      ¬ DecimalGoalVocabularyDefault.specialLiteral
        (DecimalGoalVocabularyDefault.renderNumeric y) none nan := by
    intro y nan hsign hval hspecial
    obtain ⟨n, rest, hrender, hn⟩ := numeric_head y hsign hval
    rcases hspecial with ⟨body, hbody, hcase⟩
    change DecimalGoalVocabularyDefault.renderNumeric y = body at hbody
    rw [hrender] at hbody
    cases hbody
    dsimp only [DecimalGoalVocabularyDefault] at hcase
    cases nan with
    | false =>
        simp only [Bool.false_eq_true, if_false] at hcase
        rcases hcase with hcase | hcase
        · cases hcase
          rename_i hfirst _
          rcases hfirst with hfirst | hfirst <;> omega
        · cases hcase
          rename_i hfirst _
          rcases hfirst with hfirst | hfirst <;> omega
    | true =>
        simp only [if_true] at hcase
        cases hcase
        rename_i hfirst _
        rcases hfirst with hfirst | hfirst <;> omega
  let unsigned : DecimalLexeme := { x with leadingSign := none }
  have unsigned_sign : unsigned.leadingSign = none := rfl
  have unsigned_valid : DecimalGoalVocabularyDefault.validNumeric unsigned := by
    simpa [DecimalGoalVocabularyDefault, unsigned] using hvalid
  obtain ⟨head, rest, unsigned_render, head_range⟩ :=
    numeric_head unsigned unsigned_sign unsigned_valid
  unfold num.imp.dec2flt.dec2flt_with_trace at htrace
  obtain ⟨body, hbody, htrace⟩ := bind_ok_inv _ _ _ htrace
  rcases s with ⟨source, source_bound⟩
  cases source with
  | nil =>
      dsimp only [DecimalGoalVocabularyDefault] at hbytes
      cases hs : x.leadingSign with
      | none =>
          have : DecimalGoalVocabularyDefault.renderNumeric x = [] := hbytes.symm
          obtain ⟨n, tail, hn, _⟩ := numeric_head x hs hvalid
          rw [hn] at this
          simp at this
      | some sign =>
          cases sign <;> simp [DecimalGoalVocabularyDefault, hs] at hbytes
  | cons first tail =>
      have hbodyEq : body = (⟨first :: tail, source_bound⟩ : Slice Std.U8) := by
        simpa [core.str.Str.as_bytes, ModelStrAsBytes] using hbody.symm
      subst body
      obtain ⟨firstOption, hfirst, htrace⟩ := bind_ok_inv _ _ _ htrace
      have hfirstEq : firstOption = some first := by
        simpa [core.slice.Slice.first, ModelSliceFirst] using hfirst.symm
      subst firstOption
      obtain ⟨body1, hbody1, htrace⟩ := bind_ok_inv _ _ _ htrace
      have lexical :
          body1.val ≠ [] ∧ SourceValidByteSlice body1 ∧
          DecimalGoalVocabularyDefault.bytes body1 =
            DecimalGoalVocabularyDefault.renderNumeric unsigned ∧
          (decide (first = 45#u8) : Bool) =
            DecimalGoalVocabularyDefault.lexicalNegative x := by
        cases hsign : x.leadingSign with
        | none =>
            have full : first.val :: tail.map (fun b => b.val) = head :: rest := by
              calc
                first.val :: tail.map (fun b => b.val) =
                    DecimalGoalVocabularyDefault.renderNumeric x := hbytes
                _ = DecimalGoalVocabularyDefault.renderNumeric unsigned := by
                  simp [DecimalGoalVocabularyDefault, unsigned, hsign]
                _ = head :: rest := unsigned_render
            have firstVal : first.val = head := (List.cons.inj full).1
            have hminus : first ≠ 45#u8 := by
              intro heq
              subst first
              simp at firstVal
              rcases head_range with hr | hr <;> omega
            have hplus : first ≠ 43#u8 := by
              intro heq
              subst first
              simp at firstVal
              rcases head_range with hr | hr <;> omega
            simp only [hminus, hplus, if_false] at hbody1
            cases hbody1
            refine ⟨by simp, ?_, ?_, ?_⟩
            · exact hsource.1
            · simpa [DecimalGoalVocabularyDefault, unsigned, hsign] using hbytes
            · simp [DecimalGoalVocabularyDefault, hsign, hminus]
        | some sign =>
            cases sign with
            | false =>
                have full : first.val :: tail.map (fun b => b.val) =
                    43 :: DecimalGoalVocabularyDefault.renderNumeric unsigned := by
                  calc
                    first.val :: tail.map (fun b => b.val) =
                        DecimalGoalVocabularyDefault.renderNumeric x := hbytes
                    _ = 43 :: DecimalGoalVocabularyDefault.renderNumeric unsigned := by
                      simp [DecimalGoalVocabularyDefault, unsigned, hsign]
                have firstVal : first.val = 43 := (List.cons.inj full).1
                have firstEq : first = 43#u8 := UScalar.eq_of_val_eq firstVal
                have tailRender : tail.map (fun b => b.val) =
                    DecimalGoalVocabularyDefault.renderNumeric unsigned :=
                  (List.cons.inj full).2
                simp only [firstEq, reduceCtorEq, if_false, if_true] at hbody1
                simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
                  Slice.drop] at hbody1
                cases hbody1
                refine ⟨?_, ?_, ?_, ?_⟩
                · intro hempty
                  have tailEmpty : tail = [] := by simpa using hempty
                  rw [tailEmpty] at tailRender
                  simp at tailRender
                  rw [unsigned_render] at tailRender
                  simp at tailRender
                · unfold SourceValidByteSlice
                  have hslen := hsource.1
                  simp at hslen ⊢
                  omega
                · exact tailRender
                · simp [DecimalGoalVocabularyDefault, hsign, firstEq]
            | true =>
                have full : first.val :: tail.map (fun b => b.val) =
                    45 :: DecimalGoalVocabularyDefault.renderNumeric unsigned := by
                  calc
                    first.val :: tail.map (fun b => b.val) =
                        DecimalGoalVocabularyDefault.renderNumeric x := hbytes
                    _ = 45 :: DecimalGoalVocabularyDefault.renderNumeric unsigned := by
                      simp [DecimalGoalVocabularyDefault, unsigned, hsign]
                have firstVal : first.val = 45 := (List.cons.inj full).1
                have firstEq : first = 45#u8 := UScalar.eq_of_val_eq firstVal
                have tailRender : tail.map (fun b => b.val) =
                    DecimalGoalVocabularyDefault.renderNumeric unsigned :=
                  (List.cons.inj full).2
                simp only [firstEq, if_true] at hbody1
                simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
                  Slice.drop] at hbody1
                cases hbody1
                refine ⟨?_, ?_, ?_, ?_⟩
                · intro hempty
                  have tailEmpty : tail = [] := by simpa using hempty
                  rw [tailEmpty] at tailRender
                  simp at tailRender
                  rw [unsigned_render] at tailRender
                  simp at tailRender
                · unfold SourceValidByteSlice
                  have hslen := hsource.1
                  simp at hslen ⊢
                  omega
                · exact tailRender
                · simp [DecimalGoalVocabularyDefault, hsign, firstEq]
      rcases lexical with ⟨bodyNonempty, bodyValid, bodyRender, signEq⟩
      have noInf : ¬ DecimalGoalVocabularyDefault.specialLiteral
          (DecimalGoalVocabularyDefault.bytes body1) none false := by
        rw [bodyRender]
        exact numeric_not_special unsigned false unsigned_sign unsigned_valid
      have noNan : ¬ DecimalGoalVocabularyDefault.specialLiteral
          (DecimalGoalVocabularyDefault.bytes body1) none true := by
        rw [bodyRender]
        exact numeric_not_special unsigned true unsigned_sign unsigned_valid
      have specialReject :=
        SpecialHelperRejection body1 (decide (first = 45#u8))
          bodyValid noInf noNan
      obtain ⟨empty, hempty, htrace⟩ := bind_ok_inv _ _ _ htrace
      by_cases emptyTrue : empty = true
      · simp only [emptyTrue, if_true] at htrace
        obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases htrace
      · have emptyFalse : empty = false := Bool.eq_false_of_not_eq_true emptyTrue
        simp only [emptyFalse, if_false] at htrace
        obtain ⟨parsed, hparsed, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases parsed with
        | none =>
            obtain ⟨special, hspecial, htrace⟩ := bind_ok_inv _ _ _ htrace
            rw [specialReject] at hspecial
            cases hspecial
            obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases htrace
        | some r =>
            obtain ⟨fast, hfast, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases fast with
            | some value =>
                simp only at htrace
                injection htrace with hpair
                injection hpair with hresult htr
                injection hresult with hvalue
                cases hvalue
                left
                refine ⟨body1, decide (first = 45#u8), r,
                  { r with negative := decide (first = 45#u8) }, some f,
                  ?_, bodyNonempty, bodyValid, bodyRender, signEq, hparsed⟩
                exact htr.symm
            | none =>
                obtain ⟨firstPair, hfirstPair, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨phase1, hphase1, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase1 with ⟨many1, many2, firstPair1, fp, guard⟩
                have many_eq : { r with many_digits := many1 } = r := by
                  cases r with
                  | mk exponent mantissa rnegative rmany =>
                      cases hm : rmany
                      · simp [hm] at hphase1
                        rcases hphase1 with ⟨hmany, hrest⟩
                        simp [hm, hmany]
                      · simp [hm] at hphase1
                        rcases hphase1 with ⟨hmany, hrest⟩
                        simp [hm, hmany]
                obtain ⟨phase2, hphase2, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase2 with
                  ⟨post, secondExp, secondMant, secondResult, secondEqual, forced⟩
                obtain ⟨phase3, hphase3, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase3 with ⟨selected, slowGuard, slowResult⟩
                obtain ⟨i, hi, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i1, hi1, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i2, hi2, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨word, hword, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨assembled, hassembled, htrace⟩ := bind_ok_inv _ _ _ htrace
                by_cases negative : first = 45#u8
                · simp only [negative, if_true] at htrace
                  obtain ⟨result, hresult, htrace⟩ := bind_ok_inv _ _ _ htrace
                  cases htrace
                  right
                  let assemblyTrace := num.imp.dec2flt.Dec2FltAssemblyTrace.mk
                    body1 true (some { r with many_digits := many1 })
                    { r with negative := true, many_digits := many2 } none r.exponent
                    r.mantissa firstPair1 guard secondExp secondMant secondResult
                    secondEqual forced post slowGuard slowResult selected word assembled true f
                  refine ⟨assemblyTrace, r, ?_, bodyNonempty, bodyValid, bodyRender, ?_, ?_, ?_⟩
                  · rfl
                  · dsimp [assemblyTrace]
                    simpa [negative] using signEq
                  · dsimp [assemblyTrace]
                    rw [many_eq]
                  · exact hparsed
                · simp only [negative, if_false] at htrace
                  cases htrace
                  right
                  let assemblyTrace := num.imp.dec2flt.Dec2FltAssemblyTrace.mk
                    body1 false (some { r with many_digits := many1 })
                    { r with negative := false, many_digits := many2 } none r.exponent
                    r.mantissa firstPair1 guard secondExp secondMant secondResult
                    secondEqual forced post slowGuard slowResult selected word f false f
                  refine ⟨assemblyTrace, r, ?_, bodyNonempty, bodyValid, bodyRender, ?_, ?_, ?_⟩
                  · rfl
                  · dsimp [assemblyTrace]
                    simpa [negative] using signEq
                  · dsimp [assemblyTrace]
                    rw [many_eq]
                  · exact hparsed

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 153 entries
Technical checking records
Local closure summary
{
  "node": "ParserNumericTraceShape",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "baff5bb601b55f59a30b72ca01288256bdfad4a673cf39db8271cc7ff604d0c5",
  "active_statement_hash": "f8af86f8e0bbdb3f3b0f019b11c02417c04915e64d7cc59d2337ead25978174e",
  "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": "sidecar-sc-20261004-005343-114ae9-ParserNumericTraceShape-cycle-155",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "2bbf2be48b5a4a4b",
    "ParserSpecialRejectionSafeLength": "4dbd872ba02a631e",
    "SpecialHelperRejection": "e1e229c5dd3ecf3c",
    "num_imp_dec2flt_dec2flt_with_trace": "1b73cde8bfea548e",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "986725aca5ee5702",
    "DecimalGoalVocabularyDefault": "4634372c8f7a7f44",
    "DecimalLexeme": "c43614ff2149ecf2",
    "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_Neg": "0ff07135a60bcbf9",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "a143ee24e835ec33",
    "num_imp_dec2flt_Dec2FltTrace": "6722f59984275e94",
    "num_imp_dec2flt_Lemire": "1923f90c53d323e6",
    "num_imp_dec2flt_biased_fp_to_float": "acdde060e8d35ca7",
    "num_imp_dec2flt_common_BiasedFp": "5c88d5d7976c5e8f",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_dec2flt_with_trace": "ebe6a57c6dce0df6",
    "num_imp_dec2flt_decimal_Decimal": "4da4ccbe640ef8e6",
    "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:9f7afb46fc6b11b6ddba7701369c5809c87c6cf74135f7c64773db80bda5d200",
  "current_fingerprint": "sound-v2:9f7afb46fc6b11b6ddba7701369c5809c87c6cf74135f7c64773db80bda5d200",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}