ParserInfinity

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 infinity literal, the extracted f64 parser returns normally with Ok of positive or negative infinity according to the lexical sign.

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.SpecialHelperInfinity
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: ParserInfinity]
theorem ParserInfinity :
    ∀ (s : Str) (sign : Option Bool), DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes s) sign false -> ∃ 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.isInfinity (sign = some true) 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 \tag{1}
and either
\mathsf{List.Forall2}(R,B,[105,110,102]) \tag{2a}
or
\mathsf{List.Forall2} (R,B,[105,110,102,105,110,105,116,121]), \tag{2b}
where R(a,l) means a=l or a+32=l. Equality of lengths in Forall2 makes |B|=3 in (2a) and |B|=8 in (2b). In both cases B is nonempty and its first byte is either 105 (ASCII lowercase i) or 73 (ASCII uppercase I). 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 follow the initial dispatcher operations exactly. By ModelStrAsBytes, the first bind in num imp dec2flt dec2flt with trace succeeds with the identical complete ordered byte slice of s. By ModelSliceFirst, the next bind returns its actual first byte. The bytes field unfolded in (1) maps each actual U8 to its natural value, once and in order; two U8 values having the same natural value are equal. Thus (1) and (3) determine the head and tail of the represented slice itself, not only an unrelated list of byte observations. We distinguish the three possible values of \mathit{sign}.
If \mathit{sign}=\mathsf{some\ true}, the complete slice has value list [45]\mathbin{++}B and length 1+|B|, hence length 4 or 9. Its first byte is exactly 45, so the minus test succeeds. The ensuing range-from-one request has start 1, and 1\leq4 or 1\leq9; it therefore cannot fail and returns exactly the suffix obtained by dropping that first byte. If \mathit{sign}=\mathsf{some\ false}, the complete length is again 4 or 9, its first byte is exactly 43, the minus test is false, the plus test is true, and the same explicitly in-bounds range-from-one request returns exactly the same suffix. If \mathit{sign}=\mathsf{none}, the complete slice already has value list B and length 3 or 8. Its first byte is 105 or 73, neither 45 nor 43, so both sign tests are false and no range request is made. Consequently all three branches pass one and the same unsigned body slice, which we denote by \beta, with
\mathsf{bytes}(\beta)=B,\qquad |\beta|\in\{3,8\}. \tag{4}
The dispatcher Boolean c=45 is respectively true, false, and false in these three branches. Hence, writing it as \mathit{negative},
\mathit{negative}=(\mathit{sign}=\mathsf{some\ true}). \tag{5}
In particular \beta is nonempty, so the extracted emptiness test is false and the sign-only branch is not taken.
The first conjunct of sourceString in DecimalGoalVocabularyDefault bounds the complete source byte length by 2^{63}-1=9223372036854775807. In the unsigned case \beta is that complete slice, and in either signed case it is its one-byte suffix. Thus |\beta| is at most the source length and inherits this bound, which is exactly SourceValidByteSlice. Independently, (4) supplies the sharper bound |\beta|\leq8\leq9223372036854120459 required below.
We now show that \beta is not the complete rendering of a valid unsigned numeric lexeme. Suppose, to the contrary, that a lexeme x had x.\mathit{leadingSign}=\mathsf{none}, satisfied validNumeric, and satisfied \mathsf{bytes}(\beta)=\mathsf{renderNumeric}(x). Unfold DecimalGoalVocabularyDefault once more. If x.\mathit{integerDigits} is nonempty, its first digit d satisfies d<10 by the first validity clause. Since the leading sign is absent, the first rendered byte is then 48+d, which lies in 48,\ldots,57. If the integer-digit list is empty, the nonempty-significand validity clause forces x.\mathit{fractionDigits}=\mathsf{some}\,D for a nonempty list D; the absent leading sign then makes the first rendered byte the point byte 46. Both alternatives contradict (2a)--(2b), which make the first byte of (4) equal to 105 or 73. Therefore no such unsigned valid numeric lexeme exists.
All premises of NumberHelperRejectionSafeLength now hold for \beta: source validity was inherited above, nonemptiness and length three or eight follow from (4), the numerical safe-length bound follows from 8\leq9223372036854120459, and the preceding contradiction is exactly the theorem's unsigned-rendering exclusion. For the extracted call num imp dec2flt parse parse number, it yields
\texttt{parse\_number}(\beta)=\texttt{ok none}. \tag{6}
Equations (2a)--(2b) also give precisely \mathsf{specialLiteral}(\mathsf{bytes}(\beta), \mathsf{none},\mathsf{false}): choose the same list B, use \mathsf{signBytes}(\mathsf{none})=[], use (4) for the required complete byte equality, and retain the applicable Forall2 proof. Apply SpecialHelperInfinity to this identical slice \beta and the Boolean \mathit{negative} from (5). It supplies an f such that
\texttt{parse\_inf\_nan} (\mathsf{F64Float},\beta,\mathit{negative}) =\texttt{ok (some }f\texttt{)} \tag{7}
and
\mathsf{isInfinity}(\mathit{negative},f). \tag{8}
Here (7) is the operation num imp dec2flt parse parse inf nan; its bit-level keyword match, infinity construction, and optional negation are exactly what SpecialHelperInfinity proves, so none of that argument is being assumed again here.
It remains to verify that the instance in (7) 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 in (7). Thus (7) can be substituted directly; no trait conversion or extensional equality is needed.
Finally unfold num imp dec2flt dec2flt with trace at the concrete instances in the theorem statement. The initial successful operations and sign branches established above give body \beta and Boolean \mathit{negative}; (4) makes the body nonempty; (6) selects the none arm of the numeric result; and (7), at the definitionally identical instance just checked, selects the some f arm of the special result. The definition consequently returns
\texttt{ok}\bigl(\texttt{Result.Ok }f, \texttt{Dec2FltTrace.Special }\beta\ \mathit{negative}\ \texttt{none}\ (\texttt{some }f)\ f\bigr), \tag{9}
where the trace term is exactly the corresponding constructor of num imp dec2flt Dec2FltTrace. Unfolding the public wrapper num imp dec2flt dec2flt, its sole bind consumes (9) and projects the first component, proving
\texttt{dec2flt}(s)=\texttt{ok (Result.Ok }f\texttt{)}. \tag{10}
Equation (8), rewritten by the Boolean equality (5), is exactly \mathsf{isInfinity}(\mathit{sign}=\mathsf{some\ true},f). The same f therefore supplies both conjuncts 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 ∨ body.length = 8 := by
    rcases body_case with short_case | long_case
    · left
      exact List.Forall₂.length_eq short_case
    · right
      exact List.Forall₂.length_eq long_case
  have body_nonempty : body ≠ [] := by
    intro empty_body
    subst body
    simp at body_length
  have body_safe : body.length ≤ 9223372036854120459 := by
    rcases body_length with short_length | long_length <;> omega
  have numeric_rejection : ∀ (q : Slice Std.U8) (a : Std.U8) (tail : List Std.U8),
      DecimalGoalVocabularyDefault.bytes q = (a :: tail).map (fun b : Std.U8 => b.val) ->
      (a.val = 105 ∨ a.val = 73) ->
      Not (∃ x : DecimalLexeme,
        x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
        DecimalGoalVocabularyDefault.bytes q =
          DecimalGoalVocabularyDefault.renderNumeric x) := by
    intro q a tail q_shape first_cases
    intro witness
    rcases witness with ⟨x, sign_shape, valid_shape, render_shape⟩
    have direct_shape : (a :: tail).map (fun b : Std.U8 => b.val) =
        DecimalGoalVocabularyDefault.renderNumeric x := by
      exact q_shape.symm.trans 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
  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⟩
    cases vals with
    | nil =>
      exact (body_nonempty source_shape.symm).elim
    | cons a tail =>
      have first_cases : a.val = 105 ∨ a.val = 73 := by
        rcases body_case with short_case | long_case
        · have copied := short_case
          rw [← source_shape] at copied
          cases copied with
          | cons head rest =>
            rcases head with head | head
            · exact Or.inl head
            · right
              have head_value : a.val + 32 = 105 := by simpa using head
              omega
        · have copied := long_case
          rw [← source_shape] at copied
          cases copied with
          | cons head rest =>
            rcases head with head | head
            · exact Or.inl head
            · right
              have head_value : a.val + 32 = 105 := by simpa using head
              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_length : (a :: tail).length = body.length := by
        rw [← List.length_map (fun b : Std.U8 => b.val), source_shape]
      have slice_valid : SourceValidByteSlice (⟨a :: tail, bound⟩ : Slice Std.U8) := by
        dsimp [SourceValidByteSlice]
        change (a :: tail).length ≤ 9223372036854775807
        rw [slice_length]
        omega
      have no_numeric : Not (∃ x : DecimalLexeme,
          x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
          DecimalGoalVocabularyDefault.bytes (⟨a :: tail, bound⟩ : Slice Std.U8) =
            DecimalGoalVocabularyDefault.renderNumeric x) := by
        apply numeric_rejection (⟨a :: tail, bound⟩ : Slice Std.U8) a tail
        · rfl
        · exact first_cases
      have number_result := NumberHelperRejectionSafeLength
        (⟨a :: tail, bound⟩ : Slice Std.U8) slice_valid (by simp)
        (by rw [slice_length]; exact body_safe) no_numeric
      have special_body : DecimalGoalVocabularyDefault.specialLiteral
          (DecimalGoalVocabularyDefault.bytes (⟨a :: tail, bound⟩ : Slice Std.U8)) none false := by
        dsimp [DecimalGoalVocabularyDefault]
        refine ⟨body, ?_, body_case⟩
        simpa using source_shape
      obtain ⟨f, special_result, infinity_result⟩ := SpecialHelperInfinity
        (⟨a :: tail, bound⟩ : Slice Std.U8) false special_body
      refine ⟨f, ?_, infinity_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 =>
      rcases s with ⟨vals, bound⟩
      cases vals with
      | nil =>
        simp at bytes_shape
      | cons p tail =>
        have source_shape : (p :: tail).map (fun b : Std.U8 => b.val) = 43 :: body := by
          simpa using bytes_shape
        have tail_shape : tail.map (fun b : Std.U8 => b.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
        cases tail with
        | nil =>
          exact (body_nonempty tail_shape.symm).elim
        | cons a rest =>
          have first_cases : a.val = 105 ∨ a.val = 73 := by
            rcases body_case with short_case | long_case
            · have copied := short_case
              rw [← tail_shape] at copied
              cases copied with
              | cons head rest_case =>
                rcases head with head | head
                · exact Or.inl head
                · right
                  have head_value : a.val + 32 = 105 := by simpa using head
                  omega
            · have copied := long_case
              rw [← tail_shape] at copied
              cases copied with
              | cons head rest_case =>
                rcases head with head | head
                · exact Or.inl head
                · right
                  have head_value : a.val + 32 = 105 := by simpa using head
                  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 :: rest).length ≤ Usize.max := by scalar_tac
          have slice_length : (a :: rest).length = body.length := by
            rw [← List.length_map (fun b : Std.U8 => b.val), tail_shape]
          have slice_valid : SourceValidByteSlice
              (⟨a :: rest, tail_bound⟩ : Slice Std.U8) := by
            dsimp [SourceValidByteSlice]
            change (a :: rest).length ≤ 9223372036854775807
            rw [slice_length]
            omega
          have no_numeric : Not (∃ x : DecimalLexeme,
              x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
              DecimalGoalVocabularyDefault.bytes (⟨a :: rest, tail_bound⟩ : Slice Std.U8) =
                DecimalGoalVocabularyDefault.renderNumeric x) := by
            apply numeric_rejection (⟨a :: rest, tail_bound⟩ : Slice Std.U8) a rest
            · rfl
            · exact first_cases
          have number_result := NumberHelperRejectionSafeLength
            (⟨a :: rest, tail_bound⟩ : Slice Std.U8) slice_valid (by simp)
            (by rw [slice_length]; exact body_safe) no_numeric
          have special_body : DecimalGoalVocabularyDefault.specialLiteral
              (DecimalGoalVocabularyDefault.bytes (⟨a :: rest, tail_bound⟩ : Slice Std.U8)) none false := by
            dsimp [DecimalGoalVocabularyDefault]
            refine ⟨body, ?_, body_case⟩
            simpa using tail_shape
          obtain ⟨f, special_result, infinity_result⟩ := SpecialHelperInfinity
            (⟨a :: rest, tail_bound⟩ : Slice Std.U8) false special_body
          refine ⟨f, ?_, infinity_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 =>
      rcases s with ⟨vals, bound⟩
      cases vals with
      | nil =>
        simp at bytes_shape
      | cons p tail =>
        have source_shape : (p :: tail).map (fun b : Std.U8 => b.val) = 45 :: body := by
          simpa using bytes_shape
        have tail_shape : tail.map (fun b : Std.U8 => b.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
        cases tail with
        | nil =>
          exact (body_nonempty tail_shape.symm).elim
        | cons a rest =>
          have first_cases : a.val = 105 ∨ a.val = 73 := by
            rcases body_case with short_case | long_case
            · have copied := short_case
              rw [← tail_shape] at copied
              cases copied with
              | cons head rest_case =>
                rcases head with head | head
                · exact Or.inl head
                · right
                  have head_value : a.val + 32 = 105 := by simpa using head
                  omega
            · have copied := long_case
              rw [← tail_shape] at copied
              cases copied with
              | cons head rest_case =>
                rcases head with head | head
                · exact Or.inl head
                · right
                  have head_value : a.val + 32 = 105 := by simpa using head
                  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 :: rest).length ≤ Usize.max := by scalar_tac
          have slice_length : (a :: rest).length = body.length := by
            rw [← List.length_map (fun b : Std.U8 => b.val), tail_shape]
          have slice_valid : SourceValidByteSlice
              (⟨a :: rest, tail_bound⟩ : Slice Std.U8) := by
            dsimp [SourceValidByteSlice]
            change (a :: rest).length ≤ 9223372036854775807
            rw [slice_length]
            omega
          have no_numeric : Not (∃ x : DecimalLexeme,
              x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
              DecimalGoalVocabularyDefault.bytes (⟨a :: rest, tail_bound⟩ : Slice Std.U8) =
                DecimalGoalVocabularyDefault.renderNumeric x) := by
            apply numeric_rejection (⟨a :: rest, tail_bound⟩ : Slice Std.U8) a rest
            · rfl
            · exact first_cases
          have number_result := NumberHelperRejectionSafeLength
            (⟨a :: rest, tail_bound⟩ : Slice Std.U8) slice_valid (by simp)
            (by rw [slice_length]; exact body_safe) no_numeric
          have special_body : DecimalGoalVocabularyDefault.specialLiteral
              (DecimalGoalVocabularyDefault.bytes (⟨a :: rest, tail_bound⟩ : Slice Std.U8)) none false := by
            dsimp [DecimalGoalVocabularyDefault]
            refine ⟨body, ?_, body_case⟩
            simpa using tail_shape
          obtain ⟨f, special_result, infinity_result⟩ := SpecialHelperInfinity
            (⟨a :: rest, tail_bound⟩ : Slice Std.U8) true special_body
          refine ⟨f, ?_, infinity_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.SpecialHelperInfinity
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: ParserInfinity]
theorem ParserInfinity :
    ∀ (s : Str) (sign : Option Bool), DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.specialLiteral (DecimalGoalVocabularyDefault.bytes s) sign false -> ∃ 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.isInfinity (sign = some true) 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 ∨ body.length = 8 := by
    rcases body_case with short_case | long_case
    · left
      exact List.Forall₂.length_eq short_case
    · right
      exact List.Forall₂.length_eq long_case
  have body_nonempty : body ≠ [] := by
    intro empty_body
    subst body
    simp at body_length
  have body_safe : body.length ≤ 9223372036854120459 := by
    rcases body_length with short_length | long_length <;> omega
  have numeric_rejection : ∀ (q : Slice Std.U8) (a : Std.U8) (tail : List Std.U8),
      DecimalGoalVocabularyDefault.bytes q = (a :: tail).map (fun b : Std.U8 => b.val) ->
      (a.val = 105 ∨ a.val = 73) ->
      Not (∃ x : DecimalLexeme,
        x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
        DecimalGoalVocabularyDefault.bytes q =
          DecimalGoalVocabularyDefault.renderNumeric x) := by
    intro q a tail q_shape first_cases
    intro witness
    rcases witness with ⟨x, sign_shape, valid_shape, render_shape⟩
    have direct_shape : (a :: tail).map (fun b : Std.U8 => b.val) =
        DecimalGoalVocabularyDefault.renderNumeric x := by
      exact q_shape.symm.trans 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
  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⟩
    cases vals with
    | nil =>
      exact (body_nonempty source_shape.symm).elim
    | cons a tail =>
      have first_cases : a.val = 105 ∨ a.val = 73 := by
        rcases body_case with short_case | long_case
        · have copied := short_case
          rw [← source_shape] at copied
          cases copied with
          | cons head rest =>
            rcases head with head | head
            · exact Or.inl head
            · right
              have head_value : a.val + 32 = 105 := by simpa using head
              omega
        · have copied := long_case
          rw [← source_shape] at copied
          cases copied with
          | cons head rest =>
            rcases head with head | head
            · exact Or.inl head
            · right
              have head_value : a.val + 32 = 105 := by simpa using head
              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_length : (a :: tail).length = body.length := by
        rw [← List.length_map (fun b : Std.U8 => b.val), source_shape]
      have slice_valid : SourceValidByteSlice (⟨a :: tail, bound⟩ : Slice Std.U8) := by
        dsimp [SourceValidByteSlice]
        change (a :: tail).length ≤ 9223372036854775807
        rw [slice_length]
        omega
      have no_numeric : Not (∃ x : DecimalLexeme,
          x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
          DecimalGoalVocabularyDefault.bytes (⟨a :: tail, bound⟩ : Slice Std.U8) =
            DecimalGoalVocabularyDefault.renderNumeric x) := by
        apply numeric_rejection (⟨a :: tail, bound⟩ : Slice Std.U8) a tail
        · rfl
        · exact first_cases
      have number_result := NumberHelperRejectionSafeLength
        (⟨a :: tail, bound⟩ : Slice Std.U8) slice_valid (by simp)
        (by rw [slice_length]; exact body_safe) no_numeric
      have special_body : DecimalGoalVocabularyDefault.specialLiteral
          (DecimalGoalVocabularyDefault.bytes (⟨a :: tail, bound⟩ : Slice Std.U8)) none false := by
        dsimp [DecimalGoalVocabularyDefault]
        refine ⟨body, ?_, body_case⟩
        simpa using source_shape
      obtain ⟨f, special_result, infinity_result⟩ := SpecialHelperInfinity
        (⟨a :: tail, bound⟩ : Slice Std.U8) false special_body
      refine ⟨f, ?_, infinity_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 =>
      rcases s with ⟨vals, bound⟩
      cases vals with
      | nil =>
        simp at bytes_shape
      | cons p tail =>
        have source_shape : (p :: tail).map (fun b : Std.U8 => b.val) = 43 :: body := by
          simpa using bytes_shape
        have tail_shape : tail.map (fun b : Std.U8 => b.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
        cases tail with
        | nil =>
          exact (body_nonempty tail_shape.symm).elim
        | cons a rest =>
          have first_cases : a.val = 105 ∨ a.val = 73 := by
            rcases body_case with short_case | long_case
            · have copied := short_case
              rw [← tail_shape] at copied
              cases copied with
              | cons head rest_case =>
                rcases head with head | head
                · exact Or.inl head
                · right
                  have head_value : a.val + 32 = 105 := by simpa using head
                  omega
            · have copied := long_case
              rw [← tail_shape] at copied
              cases copied with
              | cons head rest_case =>
                rcases head with head | head
                · exact Or.inl head
                · right
                  have head_value : a.val + 32 = 105 := by simpa using head
                  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 :: rest).length ≤ Usize.max := by scalar_tac
          have slice_length : (a :: rest).length = body.length := by
            rw [← List.length_map (fun b : Std.U8 => b.val), tail_shape]
          have slice_valid : SourceValidByteSlice
              (⟨a :: rest, tail_bound⟩ : Slice Std.U8) := by
            dsimp [SourceValidByteSlice]
            change (a :: rest).length ≤ 9223372036854775807
            rw [slice_length]
            omega
          have no_numeric : Not (∃ x : DecimalLexeme,
              x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
              DecimalGoalVocabularyDefault.bytes (⟨a :: rest, tail_bound⟩ : Slice Std.U8) =
                DecimalGoalVocabularyDefault.renderNumeric x) := by
            apply numeric_rejection (⟨a :: rest, tail_bound⟩ : Slice Std.U8) a rest
            · rfl
            · exact first_cases
          have number_result := NumberHelperRejectionSafeLength
            (⟨a :: rest, tail_bound⟩ : Slice Std.U8) slice_valid (by simp)
            (by rw [slice_length]; exact body_safe) no_numeric
          have special_body : DecimalGoalVocabularyDefault.specialLiteral
              (DecimalGoalVocabularyDefault.bytes (⟨a :: rest, tail_bound⟩ : Slice Std.U8)) none false := by
            dsimp [DecimalGoalVocabularyDefault]
            refine ⟨body, ?_, body_case⟩
            simpa using tail_shape
          obtain ⟨f, special_result, infinity_result⟩ := SpecialHelperInfinity
            (⟨a :: rest, tail_bound⟩ : Slice Std.U8) false special_body
          refine ⟨f, ?_, infinity_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 =>
      rcases s with ⟨vals, bound⟩
      cases vals with
      | nil =>
        simp at bytes_shape
      | cons p tail =>
        have source_shape : (p :: tail).map (fun b : Std.U8 => b.val) = 45 :: body := by
          simpa using bytes_shape
        have tail_shape : tail.map (fun b : Std.U8 => b.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
        cases tail with
        | nil =>
          exact (body_nonempty tail_shape.symm).elim
        | cons a rest =>
          have first_cases : a.val = 105 ∨ a.val = 73 := by
            rcases body_case with short_case | long_case
            · have copied := short_case
              rw [← tail_shape] at copied
              cases copied with
              | cons head rest_case =>
                rcases head with head | head
                · exact Or.inl head
                · right
                  have head_value : a.val + 32 = 105 := by simpa using head
                  omega
            · have copied := long_case
              rw [← tail_shape] at copied
              cases copied with
              | cons head rest_case =>
                rcases head with head | head
                · exact Or.inl head
                · right
                  have head_value : a.val + 32 = 105 := by simpa using head
                  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 :: rest).length ≤ Usize.max := by scalar_tac
          have slice_length : (a :: rest).length = body.length := by
            rw [← List.length_map (fun b : Std.U8 => b.val), tail_shape]
          have slice_valid : SourceValidByteSlice
              (⟨a :: rest, tail_bound⟩ : Slice Std.U8) := by
            dsimp [SourceValidByteSlice]
            change (a :: rest).length ≤ 9223372036854775807
            rw [slice_length]
            omega
          have no_numeric : Not (∃ x : DecimalLexeme,
              x.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric x ∧
              DecimalGoalVocabularyDefault.bytes (⟨a :: rest, tail_bound⟩ : Slice Std.U8) =
                DecimalGoalVocabularyDefault.renderNumeric x) := by
            apply numeric_rejection (⟨a :: rest, tail_bound⟩ : Slice Std.U8) a rest
            · rfl
            · exact first_cases
          have number_result := NumberHelperRejectionSafeLength
            (⟨a :: rest, tail_bound⟩ : Slice Std.U8) slice_valid (by simp)
            (by rw [slice_length]; exact body_safe) no_numeric
          have special_body : DecimalGoalVocabularyDefault.specialLiteral
              (DecimalGoalVocabularyDefault.bytes (⟨a :: rest, tail_bound⟩ : Slice Std.U8)) none false := by
            dsimp [DecimalGoalVocabularyDefault]
            refine ⟨body, ?_, body_case⟩
            simpa using tail_shape
          obtain ⟨f, special_result, infinity_result⟩ := SpecialHelperInfinity
            (⟨a :: rest, tail_bound⟩ : Slice Std.U8) true special_body
          refine ⟨f, ?_, infinity_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": "ParserInfinity",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "da7d2fef4c213b46adad84d39a8f16607258b45078d780262f25aa382d9e956d",
  "active_statement_hash": "903ff0194f5e9e2971005a45afbb6aad1c4c139f28f09c8e6d9daec7aebeb5da",
  "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-124",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalGoalVocabularyDefault": "2bbf2be48b5a4a4b",
    "NumberHelperPartialNumberSafeLength": "4dbd872ba02a631e",
    "NumberHelperRejectionSafeLength": "6080db0f121f1be2",
    "SpecialHelperInfinity": "4124e26dd85ce114",
    "num_imp_dec2flt_dec2flt_with_trace": "f3e7d4ffbf9b4d68",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "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": "7a79218b23bce03e",
    "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": "6722f59984275e94",
    "num_imp_dec2flt_Lemire": "1923f90c53d323e6",
    "num_imp_dec2flt_biased_fp_to_float": "acdde060e8d35ca7",
    "num_imp_dec2flt_common_BiasedFp": "c43614ff2149ecf2",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_dec2flt": "f9f7d93449a25efa",
    "num_imp_dec2flt_dec2flt_with_trace": "5665189e0304a27e",
    "num_imp_dec2flt_decimal_Decimal": "63fd2f021dd0ef41",
    "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:ff350970309d8d659b99ab6a764047d04ee9b4e772d02f719bd50da4943bce01",
  "current_fingerprint": "sound-v2:ff350970309d8d659b99ab6a764047d04ee9b4e772d02f719bd50da4943bce01",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}