ParserNanAcceptance

Lean checked

Statement

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

Theorem

For every source-valid optionally signed, ASCII-case-insensitive NaN literal, the extracted f64 parser returns normally with Ok of a word satisfying the binary64 NaN predicate.

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_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.ModelSliceFirst
import Tablet.ModelStrAsBytes
import Tablet.NumberHelperRejectionSafeLength
import Tablet.SourceValidByteSlice
import Tablet.SpecialHelperNan
import Tablet.num_imp_dec2flt_Dec2FltTrace
import Tablet.num_imp_dec2flt_Lemire
import Tablet.num_imp_dec2flt_dec2flt
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
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_biased_fp_to_float
import Tablet.num_imp_traits_FloatExt

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNanAcceptance]
theorem ParserNanAcceptance :
    ∀ (s : Str) (sign : Option Bool), DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes s) sign true -> ∃ f : F64,
      num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f) ∧ DecimalGoalVocabularyDefault.isNan f := 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

Fix s and \mathit{sign} satisfying the two hypotheses. Unfold DecimalGoalVocabularyDefault in the special-literal hypothesis. There is a list B such that
\mathsf{bytes}(s)=\mathsf{signBytes}(\mathit{sign})\mathbin{++}B \quad\hbox{and}\quad \mathsf{List.Forall2}(R,B,[110,97,110]), \tag{1}
where R(a,l) means a=l or a+32=l. Equality of lengths in the Forall2 relation gives |B|=3. Its three clauses say, in order, that the entries of B lie in
\{110,78\},\qquad \{97,65\},\qquad \{110,78\}. \tag{2}
In particular B is nonempty and its first byte is either 110 or 78. The same unfolding gives
\mathsf{signBytes}(\mathsf{none})=[],\quad \mathsf{signBytes}(\mathsf{some\ true})=[45],\quad \mathsf{signBytes}(\mathsf{some\ false})=[43]. \tag{3}
We next follow the initial dispatcher operations exactly. By ModelStrAsBytes, the first bind in num imp dec2flt dec2flt with trace succeeds with the complete ordered byte slice of s, and by ModelSliceFirst the second bind returns its actual first byte. The bytes field unfolded in (1) maps each actual U8 to its value, preserving list length and order; two U8 values with equal natural values are equal. Consequently (1) and (3) determine the actual head and tail of the represented slice, not merely an unrelated list of observations. Split into the three possible values of \mathit{sign}. For some true, (1) and (3) make that byte 45; the first sign test succeeds, the range-from-one index has start 1 in a four-byte slice, and therefore succeeds with exactly its three-byte tail B. For some false, the first byte is 43; the minus test is false, the plus test is true, and the same in-bounds range call returns the same tail B. For none, the whole slice has byte list B and its first byte is 110 or 78 by (2), hence is neither 45 nor 43; both sign tests are false and the dispatcher retains the whole slice. Thus in every case its body1 is one and the same represented slice, which we also call B, whose unsigned-value list is the B of (1). Its Boolean c = 45 is respectively true, false, and false, so it equals
\mathit{negative}:=(\mathit{sign}=\mathsf{some\ true}). \tag{4}
Since |B|=3, the extracted emptiness test is false and no sign-only branch is taken.
The first conjunct of sourceString in DecimalGoalVocabularyDefault bounds the complete source byte length by 2^{63}-1. The dispatcher body just identified is either that complete slice or its one-byte suffix, so it inherits this bound and satisfies SourceValidByteSlice. More sharply, (1) already gives |B|=3; hence |B|\leq9223372036854120459, as required by the safe-length numeric helper theorem.
We claim that B is not the complete rendering of a valid unsigned numeric lexeme. Suppose instead that a lexeme x had x.\mathit{leadingSign}=\mathsf{none}, satisfied validNumeric, and rendered to B. Unfold DecimalGoalVocabularyDefault again. If x.\mathit{integerDigits} is nonempty, its first digit d satisfies d<10, and because the leading sign is absent the first rendered byte is 48+d\in\{48,\ldots,57\}. If the integer list is empty, the nonempty- significand clause of validNumeric forces the fraction to be some ds with ds\ne[]; the absent leading sign then makes the first rendered byte the decimal point 46. Both conclusions contradict (2), which makes the first byte 110 or 78. This proves the required exclusion.
We may therefore apply NumberHelperRejectionSafeLength to the exact body slice: source validity was inherited above, nonemptiness and length three follow from (1), and the preceding paragraph is precisely its unsigned numeric-rendering exclusion. For the call defined by num imp dec2flt parse parse number, it yields
\texttt{parse\_number}(B)=\texttt{ok none}. \tag{5}
Also, (1) is exactly \mathsf{specialLiteral}(\mathsf{bytes}(B),\mathsf{none},\mathsf{true}): choose the same list B, use the empty unsigned sign prefix, and retain the same Forall2 proof. Apply SpecialHelperNan with the Boolean (4). It supplies an f such that
\texttt{parse\_inf\_nan} (\mathsf{F64Float},B,\mathit{negative})=\texttt{ok (some }f\texttt{)} \quad\hbox{and}\quad \mathsf{isNan}(f). \tag{6}
Here the helper call is the extracted operation num imp dec2flt parse parse inf nan, and \mathsf{isNan} is the raw-word predicate fixed by DecimalGoalVocabularyDefault.
It remains to check that (6) is literally the instance selected by the public dispatcher. The traitsFloatExtInst field in the concrete record F64 Insts Dec2flt modelNumImpDec2fltLemireU64, whose field schema is num imp dec2flt Lemire, reduces to F64 Insts Dec2flt modelNumImpTraitsFloatExtU64. Its FloatInst projection, as specified by the structure num imp traits FloatExt, reduces in turn to exactly F64 Insts Dec2flt modelNumImpTraitsFloatU64, the \mathsf{F64Float} instance used in (6). Thus no trait conversion or extensional identification is being assumed.
Finally unfold num imp dec2flt dec2flt with trace with the exact initial execution established above. Its body is nonempty, (5) selects the none arm of the numeric result, and (6) substitutes some f for the following special-helper result. The definition therefore returns normally with first component Ok f and trace
\texttt{Special }B\ \mathit{negative}\ \texttt{none}\ \texttt{(some }f\texttt{)}\ f,
which is exactly the corresponding constructor of num imp dec2flt Dec2FltTrace. Unfolding num imp dec2flt dec2flt, the public wrapper binds that successful pair and projects its first component, so its result is ok (Result.Ok f). The second conjunct from (6) says \mathsf{isNan}(f). This f is the existential witness required by the theorem.

Lean proof


  intro s sign source_ok special_ok
  dsimp [DecimalGoalVocabularyDefault] at source_ok special_ok
  rcases special_ok with ⟨body, bytes_shape, body_case⟩
  have body_length : body.length = 3 := by
    exact List.Forall₂.length_eq body_case
  cases sign with
  | none =>
    have source_shape : s.val.map (fun b : Std.U8 => b.val) = body := by
      simpa using bytes_shape
    rcases s with ⟨vals, bound⟩
    obtain ⟨a, b, c, vals_shape⟩ := (List.length_eq_three.mp (by
      rw [← List.length_map (fun b : Std.U8 => b.val), source_shape]
      exact body_length))
    dsimp at vals_shape
    subst vals
    have body_case' : List.Forall₂ (fun actual lower => actual = lower ∨ actual + 32 = lower)
        [a.val, b.val, c.val] [110, 97, 110] := by
      have copied := body_case
      rw [← source_shape] at copied
      simpa using copied
    have value_identity (x : Std.U8) : x = @UScalar.ofNatCore .U8 x.val x.bv.isLt := by
      apply UScalar.eq_of_val_eq
      simp
    cases body_case' with
    | cons ha rest =>
      have first_cases : a.val = 110 ∨ a.val = 78 := by
        rcases ha with ha | ha
        · exact Or.inl ha
        · right
          omega
      have a_not45 : a ≠ 45#u8 := by
        intro equality
        have value_equality := congrArg (fun x : Std.U8 => x.val) equality
        simp at value_equality
        omega
      have a_not43 : a ≠ 43#u8 := by
        intro equality
        have value_equality := congrArg (fun x : Std.U8 => x.val) equality
        simp at value_equality
        omega
      have slice_valid : SourceValidByteSlice (⟨[a, b, c], bound⟩ : Slice Std.U8) := by
        simp [SourceValidByteSlice] at source_ok ⊢
      have no_numeric : Not (∃ x : DecimalLexeme,
          x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
          DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], bound⟩ : Slice Std.U8) =
            DecimalGoalVocabularyDefault.renderNumeric x) := by
        intro witness
        rcases witness with ⟨x, sign_shape, valid_shape, render_shape⟩
        have direct_shape : [a.val, b.val, c.val] =
            (DecimalGoalVocabularyDefault.renderNumeric x) := by
          dsimp [DecimalGoalVocabularyDefault] at render_shape ⊢
          simpa using render_shape
        dsimp [DecimalGoalVocabularyDefault] at valid_shape
        cases digits : x.integerDigits with
        | nil =>
          have nonempty_fraction := valid_shape.2.2.1
          simp [digits] at nonempty_fraction
          cases fraction : x.fractionDigits with
          | none => simp [fraction] at nonempty_fraction
          | some ds =>
            have head_shape := congrArg List.head? direct_shape
            simp [DecimalGoalVocabularyDefault, sign_shape, digits, fraction] at head_shape
            omega
        | cons d ds =>
          have digit_bound := valid_shape.1 d (by simp [digits])
          have head_shape := congrArg List.head? direct_shape
          simp [DecimalGoalVocabularyDefault, sign_shape, digits] at head_shape
          omega
      have number_result := NumberHelperRejectionSafeLength
        (⟨[a, b, c], bound⟩ : Slice Std.U8) slice_valid (by simp) (by norm_num) no_numeric
      have special_body : DecimalGoalVocabularyDefault.specialLiteral
          (DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], bound⟩ : Slice Std.U8)) none true := by
        dsimp [DecimalGoalVocabularyDefault]
        refine ⟨body, ?_, body_case⟩
        simpa using source_shape
      obtain ⟨f, special_result, nan_result⟩ := SpecialHelperNan
        (⟨[a, b, c], bound⟩ : Slice Std.U8) false special_body
      refine ⟨f, ?_, nan_result⟩
      simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
        core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes,
        ModelSliceFirst, number_result, special_result,
        a_not45, a_not43]
  | some negative =>
    cases negative with
    | false =>
      have source_length : s.val.length = 4 := by
        rw [← List.length_map (fun b : Std.U8 => b.val), bytes_shape]
        simp [body_length]
      rcases s with ⟨vals, bound⟩
      obtain ⟨p, a, b, c, vals_shape⟩ :=
        (List.length_eq_four.mp (by simpa using source_length))
      subst vals
      have source_shape : [p.val, a.val, b.val, c.val] = 43 :: body := by
        simpa using bytes_shape
      have tail_shape : [a.val, b.val, c.val] = body := by
        have copied := congrArg List.tail source_shape
        simpa using copied
      have prefix_value : p.val = 43 := by
        have copied := congrArg List.head? source_shape
        simpa using copied
      have prefix_identity : p = 43#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using prefix_value
      have body_case' : List.Forall₂ (fun actual lower => actual = lower ∨ actual + 32 = lower)
          [a.val, b.val, c.val] [110, 97, 110] := by
        have copied := body_case
        rw [← tail_shape] at copied
        simpa using copied
      cases body_case' with
      | cons ha rest =>
        have first_cases : a.val = 110 ∨ a.val = 78 := by
          rcases ha with ha | ha
          · exact Or.inl ha
          · right
            omega
        have a_not45 : a ≠ 45#u8 := by
          intro equality
          have value_equality := congrArg (fun x : Std.U8 => x.val) equality
          simp at value_equality
          omega
        have a_not43 : a ≠ 43#u8 := by
          intro equality
          have value_equality := congrArg (fun x : Std.U8 => x.val) equality
          simp at value_equality
          omega
        have tail_bound : [a, b, c].length ≤ Usize.max := by scalar_tac
        have slice_valid : SourceValidByteSlice (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) := by
          simp [SourceValidByteSlice]
        have no_numeric : Not (∃ x : DecimalLexeme,
            x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
            DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) =
              DecimalGoalVocabularyDefault.renderNumeric x) := by
          intro witness
          rcases witness with ⟨x, sign_shape, valid_shape, render_shape⟩
          have direct_shape : [a.val, b.val, c.val] =
              (DecimalGoalVocabularyDefault.renderNumeric x) := by
            dsimp [DecimalGoalVocabularyDefault] at render_shape ⊢
            simpa using render_shape
          dsimp [DecimalGoalVocabularyDefault] at valid_shape
          cases digits : x.integerDigits with
          | nil =>
            have nonempty_fraction := valid_shape.2.2.1
            simp [digits] at nonempty_fraction
            cases fraction : x.fractionDigits with
            | none => simp [fraction] at nonempty_fraction
            | some ds =>
              have head_shape := congrArg List.head? direct_shape
              simp [DecimalGoalVocabularyDefault, sign_shape, digits, fraction] at head_shape
              omega
          | cons d ds =>
            have digit_bound := valid_shape.1 d (by simp [digits])
            have head_shape := congrArg List.head? direct_shape
            simp [DecimalGoalVocabularyDefault, sign_shape, digits] at head_shape
            omega
        have number_result := NumberHelperRejectionSafeLength
          (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) slice_valid (by simp) (by norm_num) no_numeric
        have special_body : DecimalGoalVocabularyDefault.specialLiteral
            (DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], tail_bound⟩ : Slice Std.U8)) none true := by
          dsimp [DecimalGoalVocabularyDefault]
          refine ⟨body, ?_, body_case⟩
          simpa using tail_shape
        obtain ⟨f, special_result, nan_result⟩ := SpecialHelperNan
          (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) false special_body
        refine ⟨f, ?_, nan_result⟩
        simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
          core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes,
          ModelSliceFirst, core.slice.index.SliceIndexRangeFromUsizeSlice.index,
          Slice.drop, number_result, special_result, a_not45, a_not43,
          prefix_identity]
    | true =>
      have source_length : s.val.length = 4 := by
        rw [← List.length_map (fun b : Std.U8 => b.val), bytes_shape]
        simp [body_length]
      rcases s with ⟨vals, bound⟩
      obtain ⟨p, a, b, c, vals_shape⟩ :=
        (List.length_eq_four.mp (by simpa using source_length))
      subst vals
      have source_shape : [p.val, a.val, b.val, c.val] = 45 :: body := by
        simpa using bytes_shape
      have tail_shape : [a.val, b.val, c.val] = body := by
        have copied := congrArg List.tail source_shape
        simpa using copied
      have prefix_value : p.val = 45 := by
        have copied := congrArg List.head? source_shape
        simpa using copied
      have prefix_identity : p = 45#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using prefix_value
      have body_case' : List.Forall₂ (fun actual lower => actual = lower ∨ actual + 32 = lower)
          [a.val, b.val, c.val] [110, 97, 110] := by
        have copied := body_case
        rw [← tail_shape] at copied
        simpa using copied
      cases body_case' with
      | cons ha rest =>
        have first_cases : a.val = 110 ∨ a.val = 78 := by
          rcases ha with ha | ha
          · exact Or.inl ha
          · right
            omega
        have a_not45 : a ≠ 45#u8 := by
          intro equality
          have value_equality := congrArg (fun x : Std.U8 => x.val) equality
          simp at value_equality
          omega
        have a_not43 : a ≠ 43#u8 := by
          intro equality
          have value_equality := congrArg (fun x : Std.U8 => x.val) equality
          simp at value_equality
          omega
        have tail_bound : [a, b, c].length ≤ Usize.max := by scalar_tac
        have slice_valid : SourceValidByteSlice (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) := by
          simp [SourceValidByteSlice]
        have no_numeric : Not (∃ x : DecimalLexeme,
            x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
            DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) =
              DecimalGoalVocabularyDefault.renderNumeric x) := by
          intro witness
          rcases witness with ⟨x, sign_shape, valid_shape, render_shape⟩
          have direct_shape : [a.val, b.val, c.val] =
              (DecimalGoalVocabularyDefault.renderNumeric x) := by
            dsimp [DecimalGoalVocabularyDefault] at render_shape ⊢
            simpa using render_shape
          dsimp [DecimalGoalVocabularyDefault] at valid_shape
          cases digits : x.integerDigits with
          | nil =>
            have nonempty_fraction := valid_shape.2.2.1
            simp [digits] at nonempty_fraction
            cases fraction : x.fractionDigits with
            | none => simp [fraction] at nonempty_fraction
            | some ds =>
              have head_shape := congrArg List.head? direct_shape
              simp [DecimalGoalVocabularyDefault, sign_shape, digits, fraction] at head_shape
              omega
          | cons d ds =>
            have digit_bound := valid_shape.1 d (by simp [digits])
            have head_shape := congrArg List.head? direct_shape
            simp [DecimalGoalVocabularyDefault, sign_shape, digits] at head_shape
            omega
        have number_result := NumberHelperRejectionSafeLength
          (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) slice_valid (by simp) (by norm_num) no_numeric
        have special_body : DecimalGoalVocabularyDefault.specialLiteral
            (DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], tail_bound⟩ : Slice Std.U8)) none true := by
          dsimp [DecimalGoalVocabularyDefault]
          refine ⟨body, ?_, body_case⟩
          simpa using tail_shape
        obtain ⟨f, special_result, nan_result⟩ := SpecialHelperNan
          (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) true special_body
        refine ⟨f, ?_, nan_result⟩
        simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
          core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes,
          ModelSliceFirst, core.slice.index.SliceIndexRangeFromUsizeSlice.index,
          Slice.drop, number_result, special_result, a_not45, a_not43,
          prefix_identity]

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.ModelSliceFirst
import Tablet.ModelStrAsBytes
import Tablet.NumberHelperRejectionSafeLength
import Tablet.SourceValidByteSlice
import Tablet.SpecialHelperNan
import Tablet.num_imp_dec2flt_Dec2FltTrace
import Tablet.num_imp_dec2flt_Lemire
import Tablet.num_imp_dec2flt_dec2flt
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
import Tablet.num_imp_dec2flt_decimal_Decimal_try_fast_path
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_biased_fp_to_float
import Tablet.num_imp_traits_FloatExt

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserNanAcceptance]
theorem ParserNanAcceptance :
    ∀ (s : Str) (sign : Option Bool), DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes s) sign true -> ∃ f : F64,
      num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f) ∧ DecimalGoalVocabularyDefault.isNan f := by
-- BODY
  intro s sign source_ok special_ok
  dsimp [DecimalGoalVocabularyDefault] at source_ok special_ok
  rcases special_ok with ⟨body, bytes_shape, body_case⟩
  have body_length : body.length = 3 := by
    exact List.Forall₂.length_eq body_case
  cases sign with
  | none =>
    have source_shape : s.val.map (fun b : Std.U8 => b.val) = body := by
      simpa using bytes_shape
    rcases s with ⟨vals, bound⟩
    obtain ⟨a, b, c, vals_shape⟩ := (List.length_eq_three.mp (by
      rw [← List.length_map (fun b : Std.U8 => b.val), source_shape]
      exact body_length))
    dsimp at vals_shape
    subst vals
    have body_case' : List.Forall₂ (fun actual lower => actual = lower ∨ actual + 32 = lower)
        [a.val, b.val, c.val] [110, 97, 110] := by
      have copied := body_case
      rw [← source_shape] at copied
      simpa using copied
    have value_identity (x : Std.U8) : x = @UScalar.ofNatCore .U8 x.val x.bv.isLt := by
      apply UScalar.eq_of_val_eq
      simp
    cases body_case' with
    | cons ha rest =>
      have first_cases : a.val = 110 ∨ a.val = 78 := by
        rcases ha with ha | ha
        · exact Or.inl ha
        · right
          omega
      have a_not45 : a ≠ 45#u8 := by
        intro equality
        have value_equality := congrArg (fun x : Std.U8 => x.val) equality
        simp at value_equality
        omega
      have a_not43 : a ≠ 43#u8 := by
        intro equality
        have value_equality := congrArg (fun x : Std.U8 => x.val) equality
        simp at value_equality
        omega
      have slice_valid : SourceValidByteSlice (⟨[a, b, c], bound⟩ : Slice Std.U8) := by
        simp [SourceValidByteSlice] at source_ok ⊢
      have no_numeric : Not (∃ x : DecimalLexeme,
          x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
          DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], bound⟩ : Slice Std.U8) =
            DecimalGoalVocabularyDefault.renderNumeric x) := by
        intro witness
        rcases witness with ⟨x, sign_shape, valid_shape, render_shape⟩
        have direct_shape : [a.val, b.val, c.val] =
            (DecimalGoalVocabularyDefault.renderNumeric x) := by
          dsimp [DecimalGoalVocabularyDefault] at render_shape ⊢
          simpa using render_shape
        dsimp [DecimalGoalVocabularyDefault] at valid_shape
        cases digits : x.integerDigits with
        | nil =>
          have nonempty_fraction := valid_shape.2.2.1
          simp [digits] at nonempty_fraction
          cases fraction : x.fractionDigits with
          | none => simp [fraction] at nonempty_fraction
          | some ds =>
            have head_shape := congrArg List.head? direct_shape
            simp [DecimalGoalVocabularyDefault, sign_shape, digits, fraction] at head_shape
            omega
        | cons d ds =>
          have digit_bound := valid_shape.1 d (by simp [digits])
          have head_shape := congrArg List.head? direct_shape
          simp [DecimalGoalVocabularyDefault, sign_shape, digits] at head_shape
          omega
      have number_result := NumberHelperRejectionSafeLength
        (⟨[a, b, c], bound⟩ : Slice Std.U8) slice_valid (by simp) (by norm_num) no_numeric
      have special_body : DecimalGoalVocabularyDefault.specialLiteral
          (DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], bound⟩ : Slice Std.U8)) none true := by
        dsimp [DecimalGoalVocabularyDefault]
        refine ⟨body, ?_, body_case⟩
        simpa using source_shape
      obtain ⟨f, special_result, nan_result⟩ := SpecialHelperNan
        (⟨[a, b, c], bound⟩ : Slice Std.U8) false special_body
      refine ⟨f, ?_, nan_result⟩
      simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
        core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes,
        ModelSliceFirst, number_result, special_result,
        a_not45, a_not43]
  | some negative =>
    cases negative with
    | false =>
      have source_length : s.val.length = 4 := by
        rw [← List.length_map (fun b : Std.U8 => b.val), bytes_shape]
        simp [body_length]
      rcases s with ⟨vals, bound⟩
      obtain ⟨p, a, b, c, vals_shape⟩ :=
        (List.length_eq_four.mp (by simpa using source_length))
      subst vals
      have source_shape : [p.val, a.val, b.val, c.val] = 43 :: body := by
        simpa using bytes_shape
      have tail_shape : [a.val, b.val, c.val] = body := by
        have copied := congrArg List.tail source_shape
        simpa using copied
      have prefix_value : p.val = 43 := by
        have copied := congrArg List.head? source_shape
        simpa using copied
      have prefix_identity : p = 43#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using prefix_value
      have body_case' : List.Forall₂ (fun actual lower => actual = lower ∨ actual + 32 = lower)
          [a.val, b.val, c.val] [110, 97, 110] := by
        have copied := body_case
        rw [← tail_shape] at copied
        simpa using copied
      cases body_case' with
      | cons ha rest =>
        have first_cases : a.val = 110 ∨ a.val = 78 := by
          rcases ha with ha | ha
          · exact Or.inl ha
          · right
            omega
        have a_not45 : a ≠ 45#u8 := by
          intro equality
          have value_equality := congrArg (fun x : Std.U8 => x.val) equality
          simp at value_equality
          omega
        have a_not43 : a ≠ 43#u8 := by
          intro equality
          have value_equality := congrArg (fun x : Std.U8 => x.val) equality
          simp at value_equality
          omega
        have tail_bound : [a, b, c].length ≤ Usize.max := by scalar_tac
        have slice_valid : SourceValidByteSlice (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) := by
          simp [SourceValidByteSlice]
        have no_numeric : Not (∃ x : DecimalLexeme,
            x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
            DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) =
              DecimalGoalVocabularyDefault.renderNumeric x) := by
          intro witness
          rcases witness with ⟨x, sign_shape, valid_shape, render_shape⟩
          have direct_shape : [a.val, b.val, c.val] =
              (DecimalGoalVocabularyDefault.renderNumeric x) := by
            dsimp [DecimalGoalVocabularyDefault] at render_shape ⊢
            simpa using render_shape
          dsimp [DecimalGoalVocabularyDefault] at valid_shape
          cases digits : x.integerDigits with
          | nil =>
            have nonempty_fraction := valid_shape.2.2.1
            simp [digits] at nonempty_fraction
            cases fraction : x.fractionDigits with
            | none => simp [fraction] at nonempty_fraction
            | some ds =>
              have head_shape := congrArg List.head? direct_shape
              simp [DecimalGoalVocabularyDefault, sign_shape, digits, fraction] at head_shape
              omega
          | cons d ds =>
            have digit_bound := valid_shape.1 d (by simp [digits])
            have head_shape := congrArg List.head? direct_shape
            simp [DecimalGoalVocabularyDefault, sign_shape, digits] at head_shape
            omega
        have number_result := NumberHelperRejectionSafeLength
          (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) slice_valid (by simp) (by norm_num) no_numeric
        have special_body : DecimalGoalVocabularyDefault.specialLiteral
            (DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], tail_bound⟩ : Slice Std.U8)) none true := by
          dsimp [DecimalGoalVocabularyDefault]
          refine ⟨body, ?_, body_case⟩
          simpa using tail_shape
        obtain ⟨f, special_result, nan_result⟩ := SpecialHelperNan
          (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) false special_body
        refine ⟨f, ?_, nan_result⟩
        simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
          core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes,
          ModelSliceFirst, core.slice.index.SliceIndexRangeFromUsizeSlice.index,
          Slice.drop, number_result, special_result, a_not45, a_not43,
          prefix_identity]
    | true =>
      have source_length : s.val.length = 4 := by
        rw [← List.length_map (fun b : Std.U8 => b.val), bytes_shape]
        simp [body_length]
      rcases s with ⟨vals, bound⟩
      obtain ⟨p, a, b, c, vals_shape⟩ :=
        (List.length_eq_four.mp (by simpa using source_length))
      subst vals
      have source_shape : [p.val, a.val, b.val, c.val] = 45 :: body := by
        simpa using bytes_shape
      have tail_shape : [a.val, b.val, c.val] = body := by
        have copied := congrArg List.tail source_shape
        simpa using copied
      have prefix_value : p.val = 45 := by
        have copied := congrArg List.head? source_shape
        simpa using copied
      have prefix_identity : p = 45#u8 := by
        apply UScalar.eq_of_val_eq
        simpa using prefix_value
      have body_case' : List.Forall₂ (fun actual lower => actual = lower ∨ actual + 32 = lower)
          [a.val, b.val, c.val] [110, 97, 110] := by
        have copied := body_case
        rw [← tail_shape] at copied
        simpa using copied
      cases body_case' with
      | cons ha rest =>
        have first_cases : a.val = 110 ∨ a.val = 78 := by
          rcases ha with ha | ha
          · exact Or.inl ha
          · right
            omega
        have a_not45 : a ≠ 45#u8 := by
          intro equality
          have value_equality := congrArg (fun x : Std.U8 => x.val) equality
          simp at value_equality
          omega
        have a_not43 : a ≠ 43#u8 := by
          intro equality
          have value_equality := congrArg (fun x : Std.U8 => x.val) equality
          simp at value_equality
          omega
        have tail_bound : [a, b, c].length ≤ Usize.max := by scalar_tac
        have slice_valid : SourceValidByteSlice (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) := by
          simp [SourceValidByteSlice]
        have no_numeric : Not (∃ x : DecimalLexeme,
            x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
            DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) =
              DecimalGoalVocabularyDefault.renderNumeric x) := by
          intro witness
          rcases witness with ⟨x, sign_shape, valid_shape, render_shape⟩
          have direct_shape : [a.val, b.val, c.val] =
              (DecimalGoalVocabularyDefault.renderNumeric x) := by
            dsimp [DecimalGoalVocabularyDefault] at render_shape ⊢
            simpa using render_shape
          dsimp [DecimalGoalVocabularyDefault] at valid_shape
          cases digits : x.integerDigits with
          | nil =>
            have nonempty_fraction := valid_shape.2.2.1
            simp [digits] at nonempty_fraction
            cases fraction : x.fractionDigits with
            | none => simp [fraction] at nonempty_fraction
            | some ds =>
              have head_shape := congrArg List.head? direct_shape
              simp [DecimalGoalVocabularyDefault, sign_shape, digits, fraction] at head_shape
              omega
          | cons d ds =>
            have digit_bound := valid_shape.1 d (by simp [digits])
            have head_shape := congrArg List.head? direct_shape
            simp [DecimalGoalVocabularyDefault, sign_shape, digits] at head_shape
            omega
        have number_result := NumberHelperRejectionSafeLength
          (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) slice_valid (by simp) (by norm_num) no_numeric
        have special_body : DecimalGoalVocabularyDefault.specialLiteral
            (DecimalGoalVocabularyDefault.bytes (⟨[a, b, c], tail_bound⟩ : Slice Std.U8)) none true := by
          dsimp [DecimalGoalVocabularyDefault]
          refine ⟨body, ?_, body_case⟩
          simpa using tail_shape
        obtain ⟨f, special_result, nan_result⟩ := SpecialHelperNan
          (⟨[a, b, c], tail_bound⟩ : Slice Std.U8) true special_body
        refine ⟨f, ?_, nan_result⟩
        simp [num.imp.dec2flt.dec2flt, num.imp.dec2flt.dec2flt_with_trace,
          core.str.Str.as_bytes, core.slice.Slice.first, ModelStrAsBytes,
          ModelSliceFirst, core.slice.index.SliceIndexRangeFromUsizeSlice.index,
          Slice.drop, number_result, special_result, a_not45, a_not43,
          prefix_identity]

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": "ParserNanAcceptance",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "2e8abe2deee26813aafd2a804653c8cd6f1245fbcac7ef565b5c90a47ad13c7d",
  "active_statement_hash": "52f22c2e2aa93fd97bcff58486567f137b4d46fee50989431d8e13755f5d9a27",
  "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-116",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
    "NumberHelperPartialNumberSafeLength": "4dbd872ba02a631e",
    "NumberHelperRejectionSafeLength": "6080db0f121f1be2",
    "SpecialHelperNan": "1abf1a568c158d53",
    "num_imp_dec2flt_dec2flt_with_trace": "f3e7d4ffbf9b4d68",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "f230c9551c8d76e0",
    "DecimalLexeme": "8127b3eaeae00dd2",
    "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": "94ab5f784cdf5db8",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "7bda5de02611ad76",
    "num_imp_dec2flt_Dec2FltTrace": "ef050fc88fd50bb9",
    "num_imp_dec2flt_Lemire": "94ab5f784cdf5db8",
    "num_imp_dec2flt_biased_fp_to_float": "acdde060e8d35ca7",
    "num_imp_dec2flt_common_BiasedFp": "31d81cf1cf22709f",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_dec2flt": "f9f7d93449a25efa",
    "num_imp_dec2flt_dec2flt_with_trace": "8bc9229f6c14573d",
    "num_imp_dec2flt_decimal_Decimal": "4c41a56bf44cb31e",
    "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:cf24a111e6cca3d416a0962330182df02bd8a097130117346301a44ca367ba8f",
  "current_fingerprint": "sound-v2:cf24a111e6cca3d416a0962330182df02bd8a097130117346301a44ca367ba8f",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}