ClassificationDeterminism

Lean checked

Statement

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

Theorem

Every finite byte string has at most one classification, and whenever it is numeric its complete parsed decimal lexeme is unique.

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.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

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ClassificationDeterminism]
theorem ClassificationDeterminism :
    (∀ (bs : List Nat) c₁ c₂, (∀ b ∈ bs, b < 256) ->
      DecimalGoalVocabularyDefault.classifies bs c₁ -> DecimalGoalVocabularyDefault.classifies bs c₂ -> c₁ = c₂) ∧
    (∀ (bs : List Nat) x₁ x₂, (∀ b ∈ bs, b < 256) ->
      DecimalGoalVocabularyDefault.classifies bs (some (Sum.inl x₁)) ->
      DecimalGoalVocabularyDefault.classifies bs (some (Sum.inl x₂)) -> x₁ = x₂) := 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.

Earlier prose review

An earlier review questioned the prose argument. Lean subsequently checked the formal proof. Review of the statement’s intended meaning is a separate judgment.

Proof

Unfold the concrete grammar and rendering supplied by DecimalGoalVocabularyDefault. We first record two elementary cancellation facts about lists of natural numbers. Write S(s) for the rendering of an optional sign and D(d_1\ldots d_k) for the list (48+d_1)\ldots(48+d_k). Thus S(\mathsf{none})=[], S(\mathsf{some\ false})=[43], and S(\mathsf{some\ true})=[45].
First, suppose
S(s_1)\mathbin{++}u_1=S(s_2)\mathbin{++}u_2
and neither nonempty u_j begins with 43 or 45. Case analysis on s_1,s_2 recovers the signs: if exactly one sign is present, the first byte on the unsigned side would be 43 or 45, contrary to the hypothesis; if both are present, equality of the first bytes distinguishes 43 from 45. After cancelling equal first bytes when necessary, one obtains both s_1=s_2 and u_1=u_2.
Second, suppose every member of digit lists a_1,a_2 is less than 10, neither nonempty remainder r_j begins with a byte in 48,\ldots,57, and
D(a_1)\mathbin{++}r_1=D(a_2)\mathbin{++}r_2. \tag{1}
Then a_1=a_2 and r_1=r_2. This follows by induction on a_1. If a_1=[] but a_2=d::a'_2, equality would make r_1 begin with 48+d; since d<10, that byte lies in 48,\ldots,57, a contradiction. The symmetric empty case is identical. If both lists are nonempty, equality of their first rendered bytes gives 48+d_1=48+d_2, hence d_1=d_2; cancel those bytes and apply the induction hypothesis. Consequently (1) uniquely recovers a maximal run of rendered digits, including an empty run, and decoding subtracts 48 from each byte uniquely.
We now prove that numeric rendering is injective on valid numeric lexemes. All rendered digit bytes lie in 48,\ldots,57, whereas the sign, point, and exponent marker bytes 43,45,46,69,101 lie outside that interval. Moreover, validity says either the integer digit list is nonempty or a present fraction digit list is nonempty. Hence, immediately after the optional leading sign, a valid rendering begins either with a digit byte or with 46; in particular it cannot begin with 43 or 45. The first cancellation fact therefore recovers the leading-sign field from equality of two numeric renderings.
After that sign, the integer digit bytes form the uniquely determined maximal initial run in 48,\ldots,57: what follows is either 46, 69, 101, or the end of the list. The second cancellation fact recovers the entire integer-digit field and leaves equal suffixes. A suffix beginning with 46 uniquely records that the fraction field is present; a suffix without that byte records that it is absent. In the present case, cancel 46. The next maximal digit run is precisely the fraction list, because its following suffix begins with 69 or 101 or is empty. The second cancellation fact therefore recovers the fraction digits even when that list is empty, and it leaves equal exponent suffixes.
An empty exponent suffix uniquely records an absent exponent. Otherwise its first byte is 69 or 101, uniquely recording respectively the uppercase or lowercase case bit. Cancel that marker. The next component is the optional exponent sign. Validity makes the exponent digit list nonempty, and every one of its rendered bytes lies in 48,\ldots,57, so the first cancellation fact recovers the optional exponent-sign field. The nonempty remaining maximal digit run then recovers every exponent digit by the second cancellation fact. The render equality is equality with the complete input list, so no byte can remain after this run. We have recovered, in order, the leading sign, integer digits, optional fraction (including the distinction between absence and a present empty list), and optional exponent with its case bit, sign, and digits. These are all four fields of the numeric lexeme, so the two lexemes are equal.
Next consider two special witnesses for the same byte list. Every accepted body begins with a case-variant of 110 for nan, or of 105 for inf and infinity. Such a first byte is respectively 110 or 78, or 105 or 73, and hence is neither 43 nor 45. Applying the first cancellation fact recovers the optional special sign and leaves equal bodies. The pointwise case relation also forces the body to have the same length as its fixed lowercase word. Thus length 8 distinguishes infinity from the two length-3 words. Between the length-3 words, the first letter after case-normalization is 110 for nan and 105 for inf; their possible actual bytes \{110,78\} and \{105,73\} are disjoint. Therefore an equal body has a unique word, and in particular a unique Boolean kind (NaN versus infinity). Together with the recovered sign, this proves uniqueness of the complete special classification payload.
Numeric and special witnesses cannot coexist for one byte list. Apply the first cancellation fact to their optional leading signs; it applies on the numeric side by validity as above and on the special side by the preceding first-byte calculation. After the signs are removed, a valid numeric body begins with a byte in 48,\ldots,57 when the integer list is nonempty, and otherwise begins with the point byte 46. A special body begins with one of 110,78,105,73. These sets are disjoint, contradicting equality of the unsigned bodies.
It remains to analyze the two classification hypotheses. If both values are numeric, numeric-render injectivity makes their lexemes, and hence their classifications, equal. If both are special, special uniqueness makes their sign/kind pairs equal. A numeric value and a special value contradict the disjointness just proved. If one classification is none, its definition asserts both that no numeric witness exists and that no special witness exists; either possible some classification supplies exactly the forbidden witness. Finally, two none values are definitionally equal. This exhaustive case analysis proves the first conjunct.
For the second conjunct, apply the first conjunct to \mathsf{some}(\mathsf{Sum.inl}(x_1)) and \mathsf{some}(\mathsf{Sum.inl}(x_2)). Injectivity of \mathsf{Option.some} and then of \mathsf{Sum.inl} yields x_1=x_2; equivalently this is the numeric-render injectivity argument above. The premise that every member of the input is below 256 is unused: all of the separation and cancellation arguments are purely syntactic and hold for every finite List Nat.

Lean proof


  let signBytes : Option Bool → List Nat := fun sign =>
    match sign with | none => [] | some negative => [if negative then 45 else 43]
  let digitBytes : List Nat → List Nat := fun ds => ds.map (fun d => 48 + d)
  let AllDigits : List Nat → Prop := fun ds => ∀ d ∈ ds, d < 10
  let SignFreeHead : List Nat → Prop := fun xs =>
    ∀ h t, xs = h :: t → h ≠ 43 ∧ h ≠ 45
  let DigitFreeHead : List Nat → Prop := fun xs =>
    ∀ h t, xs = h :: t → h < 48 ∨ 58 ≤ h
  let exponentBytes : Option (Bool × Option Bool × List Nat) → List Nat := fun e =>
    match e with
    | none => []
    | some (upper, sign, ds) =>
        (if upper then 69 else 101) :: signBytes sign ++ digitBytes ds
  let fractionBytes : Option (List Nat) → List Nat := fun f =>
    match f with | none => [] | some ds => 46 :: digitBytes ds
  let ValidNumeric : DecimalLexeme → Prop := fun x =>
    AllDigits x.integerDigits ∧
    (match x.fractionDigits with | none => True | some ds => AllDigits ds) ∧
    (x.integerDigits ≠ [] ∨
      match x.fractionDigits with | none => False | some ds => ds ≠ []) ∧
    (match x.exponent with
      | none => True
      | some (_, _, ds) => ds ≠ [] ∧ AllDigits ds)
  let RenderNumeric : DecimalLexeme → List Nat := fun x =>
    signBytes x.leadingSign ++ digitBytes x.integerDigits ++
      fractionBytes x.fractionDigits ++ exponentBytes x.exponent
  let CaseEq : List Nat → List Nat → Prop := fun xs ys =>
    List.Forall₂ (fun actual lower => actual = lower ∨ actual + 32 = lower) xs ys
  let SpecialBody : List Nat → Bool → Prop := fun body nan =>
    if nan then CaseEq body [110, 97, 110]
    else CaseEq body [105, 110, 102] ∨
      CaseEq body [105, 110, 102, 105, 110, 105, 116, 121]
  let SpecialLiteral : List Nat → Option Bool → Bool → Prop := fun bs sign nan =>
    ∃ body, bs = signBytes sign ++ body ∧ SpecialBody body nan
  let NumericLiteral : List Nat → DecimalLexeme → Prop := fun bs x =>
    ValidNumeric x ∧ RenderNumeric x = bs
  let Classifies : List Nat → Option (Sum DecimalLexeme (Option Bool × Bool)) → Prop :=
    fun bs c => match c with
    | some (Sum.inl x) => NumericLiteral bs x
    | some (Sum.inr (sign, nan)) => SpecialLiteral bs sign nan
    | none => (¬ ∃ x, NumericLiteral bs x) ∧ (¬ ∃ sign nan, SpecialLiteral bs sign nan)

  have sign_split : ∀ s₁ s₂ xs ys,
      SignFreeHead xs → SignFreeHead ys →
      signBytes s₁ ++ xs = signBytes s₂ ++ ys → s₁ = s₂ ∧ xs = ys := by
    intro s₁ s₂ xs ys hxs hys heq
    cases s₁ with
    | none =>
      cases s₂ with
      | none => exact ⟨rfl, by simpa [signBytes] using heq⟩
      | some b₂ =>
        cases b₂ <;> simp only [signBytes, ↓reduceIte, List.nil_append,
          List.cons_append, List.append_nil] at heq
        · have := hxs 43 ys heq
          exact False.elim (this.1 rfl)
        · have := hxs 45 ys heq
          exact False.elim (this.2 rfl)
    | some b₁ =>
      cases s₂ with
      | none =>
        cases b₁ <;> simp only [signBytes, ↓reduceIte, List.nil_append,
          List.cons_append, List.append_nil] at heq
        · have := hys 43 xs heq.symm
          exact False.elim (this.1 rfl)
        · have := hys 45 xs heq.symm
          exact False.elim (this.2 rfl)
      | some b₂ =>
        cases b₁ <;> cases b₂
        · simp only [signBytes, ↓reduceIte, List.cons_append, List.append_nil,
            List.cons.injEq] at heq
          exact ⟨rfl, heq.2⟩
        · simp [signBytes] at heq
        · simp [signBytes] at heq
        · simp only [signBytes, ↓reduceIte, List.cons_append, List.append_nil,
            List.cons.injEq] at heq
          exact ⟨rfl, heq.2⟩

  have digits_split : ∀ ds₁ ds₂ xs ys,
      AllDigits ds₁ → AllDigits ds₂ →
      DigitFreeHead xs → DigitFreeHead ys →
      digitBytes ds₁ ++ xs = digitBytes ds₂ ++ ys → ds₁ = ds₂ ∧ xs = ys := by
    intro ds₁
    induction ds₁ with
    | nil =>
      intro bs xs ys has hbs hxs hys heq
      cases bs with
      | nil => exact ⟨rfl, by simpa [digitBytes] using heq⟩
      | cons b bs =>
        simp only [digitBytes, List.map_cons, List.nil_append, List.cons_append,
          List.cons.injEq] at heq
        have hb : b < 10 := hbs b (by simp)
        have hx := hxs (48 + b) (digitBytes bs ++ ys) heq
        omega
    | cons a ds₁ ih =>
      intro bs xs ys has hbs hxs hys heq
      cases bs with
      | nil =>
        simp only [digitBytes, List.map_cons, List.nil_append, List.cons_append,
          List.cons.injEq] at heq
        have ha : a < 10 := has a (by simp)
        have hy := hys (48 + a) (digitBytes ds₁ ++ xs) heq.symm
        omega
      | cons b bs =>
        simp only [digitBytes, List.map_cons, List.cons_append, List.cons.injEq] at heq
        have hab : a = b := by omega
        subst b
        have has' : AllDigits ds₁ := by
          intro d hd
          exact has d (by simp [hd])
        have hbs' : AllDigits bs := by
          intro d hd
          exact hbs d (by simp [hd])
        have hr := ih bs xs ys has' hbs' hxs hys heq.2
        exact ⟨by simp [hr.1], hr.2⟩

  have digitBytes_signfree : ∀ ds,
      AllDigits ds → SignFreeHead (digitBytes ds) := by
    intro ds hds h t heq
    cases ds with
    | nil => simp [digitBytes] at heq
    | cons d ds =>
      simp only [digitBytes, List.map_cons, List.cons.injEq] at heq
      have hd : d < 10 := hds d (by simp)
      omega

  have exponentBytes_digitfree : ∀ e, DigitFreeHead (exponentBytes e) := by
    intro e h t heq
    cases e with
    | none => simp [exponentBytes] at heq
    | some value =>
      rcases value with ⟨upper, sign, ds⟩
      cases upper <;> simp [exponentBytes] at heq <;> omega

  have fracExp_digitfree : ∀ f e,
      DigitFreeHead (fractionBytes f ++ exponentBytes e) := by
    intro f e h t heq
    cases f with
    | none =>
      simpa [fractionBytes] using exponentBytes_digitfree e h t heq
    | some ds =>
      simp [fractionBytes] at heq
      omega

  have numericBody_signfree : ∀ i f e,
      AllDigits i →
      (i ≠ [] ∨ match f with | none => False | some ds => ds ≠ []) →
      SignFreeHead (digitBytes i ++ fractionBytes f ++ exponentBytes e) := by
    intro i f e hi hnonempty h t heq
    cases i with
    | nil =>
      simp only [List.nil_eq, ne_eq, not_true_eq_false, false_or] at hnonempty
      cases f with
      | none => simp at hnonempty
      | some ds =>
        cases ds with
        | nil => simp at hnonempty
        | cons d ds =>
          simp [digitBytes, fractionBytes] at heq
          omega
    | cons d ds =>
      simp only [digitBytes, List.map_cons, List.cons_append, List.cons.injEq] at heq
      have hd : d < 10 := hi d (by simp)
      omega

  have exponent_inj : ∀ e₁ e₂,
      (match e₁ with | none => True | some (_, _, ds) => AllDigits ds) →
      (match e₂ with | none => True | some (_, _, ds) => AllDigits ds) →
      exponentBytes e₁ = exponentBytes e₂ → e₁ = e₂ := by
    intro e₁ e₂ hv₁ hv₂ heq
    cases e₁ with
    | none =>
      cases e₂ with
      | none => rfl
      | some value₂ =>
        rcases value₂ with ⟨upper₂, sign₂, ds₂⟩
        cases upper₂ <;> simp [exponentBytes] at heq
    | some value₁ =>
      rcases value₁ with ⟨upper₁, sign₁, ds₁⟩
      cases e₂ with
      | none => cases upper₁ <;> simp [exponentBytes] at heq
      | some value₂ =>
        rcases value₂ with ⟨upper₂, sign₂, ds₂⟩
        cases upper₁ <;> cases upper₂
        · have htail : signBytes sign₁ ++ digitBytes ds₁ =
              signBytes sign₂ ++ digitBytes ds₂ := by
            simpa [exponentBytes] using heq
          have hs := sign_split sign₁ sign₂ (digitBytes ds₁) (digitBytes ds₂)
            (digitBytes_signfree ds₁ hv₁) (digitBytes_signfree ds₂ hv₂) htail
          have hd := digits_split ds₁ ds₂ [] [] hv₁ hv₂
            (by simp [DigitFreeHead]) (by simp [DigitFreeHead]) (by simpa using hs.2)
          simp [hs.1, hd.1]
        · simp [exponentBytes] at heq
        · simp [exponentBytes] at heq
        · have htail : signBytes sign₁ ++ digitBytes ds₁ =
              signBytes sign₂ ++ digitBytes ds₂ := by
            simpa [exponentBytes] using heq
          have hs := sign_split sign₁ sign₂ (digitBytes ds₁) (digitBytes ds₂)
            (digitBytes_signfree ds₁ hv₁) (digitBytes_signfree ds₂ hv₂) htail
          have hd := digits_split ds₁ ds₂ [] [] hv₁ hv₂
            (by simp [DigitFreeHead]) (by simp [DigitFreeHead]) (by simpa using hs.2)
          simp [hs.1, hd.1]

  have exponentValidity_digits : ∀ (e : Option (Bool × Option Bool × List Nat)),
      (match e with | none => True | some (_, _, ds) => ds ≠ [] ∧ AllDigits ds) →
      (match e with | none => True | some (_, _, ds) => AllDigits ds) := by
    intro e h
    cases e with
    | none => trivial
    | some value =>
      rcases value with ⟨upper, sign, ds⟩
      exact h.2

  have fracExp_inj : ∀ f₁ f₂ e₁ e₂,
      (match f₁ with | none => True | some ds => AllDigits ds) →
      (match f₂ with | none => True | some ds => AllDigits ds) →
      (match e₁ with | none => True | some (_, _, ds) => AllDigits ds) →
      (match e₂ with | none => True | some (_, _, ds) => AllDigits ds) →
      fractionBytes f₁ ++ exponentBytes e₁ =
        fractionBytes f₂ ++ exponentBytes e₂ →
      f₁ = f₂ ∧ e₁ = e₂ := by
    intro f₁ f₂ e₁ e₂ hf₁ hf₂ he₁ he₂ heq
    cases f₁ with
    | none =>
      cases f₂ with
      | none =>
        have he : e₁ = e₂ := exponent_inj e₁ e₂ he₁ he₂ (by simpa [fractionBytes] using heq)
        exact ⟨rfl, he⟩
      | some ds₂ =>
        cases e₁ with
        | none => simp [fractionBytes, exponentBytes] at heq
        | some value₁ =>
          rcases value₁ with ⟨upper₁, sign₁, es₁⟩
          cases upper₁ <;> simp [fractionBytes, exponentBytes] at heq
    | some ds₁ =>
      cases f₂ with
      | none =>
        cases e₂ with
        | none => simp [fractionBytes, exponentBytes] at heq
        | some value₂ =>
          rcases value₂ with ⟨upper₂, sign₂, es₂⟩
          cases upper₂ <;> simp [fractionBytes, exponentBytes] at heq
      | some ds₂ =>
        simp only [fractionBytes, List.cons_append, List.cons.injEq] at heq
        have hd := digits_split ds₁ ds₂ (exponentBytes e₁) (exponentBytes e₂)
          hf₁ hf₂ (exponentBytes_digitfree e₁) (exponentBytes_digitfree e₂) heq.2
        have he := exponent_inj e₁ e₂ he₁ he₂ hd.2
        exact ⟨by simp [hd.1], he⟩

  have numeric_inj : ∀ x₁ x₂,
      ValidNumeric x₁ → ValidNumeric x₂ →
      RenderNumeric x₁ = RenderNumeric x₂ → x₁ = x₂ := by
    rintro ⟨s₁, i₁, f₁, e₁⟩ ⟨s₂, i₂, f₂, e₂⟩ hv₁ hv₂ heq
    simp only [ValidNumeric] at hv₁ hv₂
    simp only [RenderNumeric] at heq
    have hs := sign_split s₁ s₂
      (digitBytes i₁ ++ fractionBytes f₁ ++ exponentBytes e₁)
      (digitBytes i₂ ++ fractionBytes f₂ ++ exponentBytes e₂)
      (numericBody_signfree i₁ f₁ e₁ hv₁.1 hv₁.2.2.1)
      (numericBody_signfree i₂ f₂ e₂ hv₂.1 hv₂.2.2.1)
      (by simpa [List.append_assoc] using heq)
    have hi := digits_split i₁ i₂
      (fractionBytes f₁ ++ exponentBytes e₁)
      (fractionBytes f₂ ++ exponentBytes e₂)
      hv₁.1 hv₂.1 (fracExp_digitfree f₁ e₁) (fracExp_digitfree f₂ e₂)
      (by simpa [List.append_assoc] using hs.2)
    have he₁ := exponentValidity_digits e₁ hv₁.2.2.2
    have he₂ := exponentValidity_digits e₂ hv₂.2.2.2
    have hf := fracExp_inj f₁ f₂ e₁ e₂ hv₁.2.1 hv₂.2.1 he₁ he₂ hi.2
    cases hs.1
    cases hi.1
    cases hf.1
    cases hf.2
    rfl

  have caseEq_largeHead : ∀ body lower lowers,
      90 ≤ lower → CaseEq body (lower :: lowers) →
      ∃ actual rest, body = actual :: rest ∧ 58 ≤ actual := by
    intro body lower lowers hlower hcase
    cases hcase with
    | cons hhead htail =>
      refine ⟨_, _, rfl, ?_⟩
      rcases hhead with hhead | hhead <;> omega

  have specialBody_largeHead : ∀ body nan,
      SpecialBody body nan → ∃ actual rest, body = actual :: rest ∧ 58 ≤ actual := by
    intro body nan hbody
    cases nan
    · simp only [SpecialBody, Bool.false_eq_true, if_false] at hbody
      rcases hbody with hshort | hlong
      · exact caseEq_largeHead body 105 [110, 102] (by omega) hshort
      · exact caseEq_largeHead body 105 [110, 102, 105, 110, 105, 116, 121] (by omega) hlong
    · simp only [SpecialBody, if_true] at hbody
      exact caseEq_largeHead body 110 [97, 110] (by omega) hbody

  have specialBody_signfree : ∀ body nan,
      SpecialBody body nan → SignFreeHead body := by
    intro body nan hbody h t heq
    rcases specialBody_largeHead body nan hbody with ⟨actual, rest, hshape, hlarge⟩
    rw [hshape] at heq
    simp only [List.cons.injEq] at heq
    omega

  have nan_inf_disjoint : ∀ body infTail,
      CaseEq body [110, 97, 110] → CaseEq body (105 :: infTail) → False := by
    intro body infTail hnan hinf
    cases hnan with
    | cons hnanHead hnanTail =>
      cases hinf with
      | cons hinfHead hinfTailProof =>
        rcases hnanHead with hnanHead | hnanHead <;>
          rcases hinfHead with hinfHead | hinfHead <;> omega

  have special_inj : ∀ bs s₁ nan₁ s₂ nan₂,
      SpecialLiteral bs s₁ nan₁ → SpecialLiteral bs s₂ nan₂ →
      (s₁, nan₁) = (s₂, nan₂) := by
    intro bs s₁ nan₁ s₂ nan₂ h₁ h₂
    rcases h₁ with ⟨body₁, hbs₁, hbody₁⟩
    rcases h₂ with ⟨body₂, hbs₂, hbody₂⟩
    have heq : signBytes s₁ ++ body₁ = signBytes s₂ ++ body₂ := hbs₁.symm.trans hbs₂
    have hs := sign_split s₁ s₂ body₁ body₂
      (specialBody_signfree body₁ nan₁ hbody₁)
      (specialBody_signfree body₂ nan₂ hbody₂) heq
    cases hs.1
    cases hs.2
    cases nan₁ <;> cases nan₂
    · rfl
    · simp only [SpecialBody, Bool.false_eq_true, if_false] at hbody₁
      simp only [SpecialBody, if_true] at hbody₂
      rcases hbody₁ with hshort | hlong
      · exact False.elim (nan_inf_disjoint body₁ [110, 102] hbody₂ hshort)
      · exact False.elim
          (nan_inf_disjoint body₁ [110, 102, 105, 110, 105, 116, 121] hbody₂ hlong)
    · simp only [SpecialBody, if_true] at hbody₁
      simp only [SpecialBody, Bool.false_eq_true, if_false] at hbody₂
      rcases hbody₂ with hshort | hlong
      · exact False.elim (nan_inf_disjoint body₁ [110, 102] hbody₁ hshort)
      · exact False.elim
          (nan_inf_disjoint body₁ [110, 102, 105, 110, 105, 116, 121] hbody₁ hlong)
    · rfl

  have numericBody_smallHead : ∀ i f e,
      AllDigits i →
      (i ≠ [] ∨ match f with | none => False | some ds => ds ≠ []) →
      ∃ actual rest,
        digitBytes i ++ fractionBytes f ++ exponentBytes e = actual :: rest ∧ actual < 58 := by
    intro i f e hi hnonempty
    cases i with
    | nil =>
      simp only [ne_eq, not_true_eq_false, false_or] at hnonempty
      cases f with
      | none => simp at hnonempty
      | some ds =>
        refine ⟨46, digitBytes ds ++ exponentBytes e, ?_, by omega⟩
        simp [digitBytes, fractionBytes]
    | cons d ds =>
      have hd : d < 10 := hi d (by simp)
      refine ⟨48 + d, digitBytes ds ++ fractionBytes f ++ exponentBytes e, ?_, by omega⟩
      simp [digitBytes]

  have numeric_special_disjoint : ∀ x bs sign nan,
      ValidNumeric x → RenderNumeric x = bs → SpecialLiteral bs sign nan → False := by
    rintro ⟨lead, i, f, e⟩ bs sign nan hv hrender hspecial
    simp only [ValidNumeric] at hv
    simp only [RenderNumeric] at hrender
    rcases hspecial with ⟨body, hbs, hbody⟩
    have heq : signBytes lead ++ (digitBytes i ++ fractionBytes f ++ exponentBytes e) =
        signBytes sign ++ body := by
      rw [← hbs, ← hrender]
      simp [List.append_assoc]
    have hs := sign_split lead sign (digitBytes i ++ fractionBytes f ++ exponentBytes e) body
      (numericBody_signfree i f e hv.1 hv.2.2.1) (specialBody_signfree body nan hbody) heq
    rcases numericBody_smallHead i f e hv.1 hv.2.2.1 with ⟨nhead, ntail, hnshape, hnsmall⟩
    rcases specialBody_largeHead body nan hbody with ⟨shead, stail, hsshape, hslarge⟩
    rw [hnshape, hsshape] at hs
    simp only [List.cons.injEq] at hs
    omega

  have classification_unique : ∀ bs c₁ c₂,
      Classifies bs c₁ → Classifies bs c₂ → c₁ = c₂ := by
    intro bs c₁ c₂ h₁ h₂
    cases c₁ with
    | none =>
      cases c₂ with
      | none => rfl
      | some value₂ =>
        cases value₂ with
        | inl x₂ =>
          exact False.elim (h₁.1 ⟨x₂, h₂⟩)
        | inr special₂ =>
          rcases special₂ with ⟨sign₂, nan₂⟩
          exact False.elim (h₁.2 ⟨sign₂, nan₂, h₂⟩)
    | some value₁ =>
      cases c₂ with
      | none =>
        cases value₁ with
        | inl x₁ =>
          exact False.elim (h₂.1 ⟨x₁, h₁⟩)
        | inr special₁ =>
          rcases special₁ with ⟨sign₁, nan₁⟩
          exact False.elim (h₂.2 ⟨sign₁, nan₁, h₁⟩)
      | some value₂ =>
        cases value₁ with
        | inl x₁ =>
          cases value₂ with
          | inl x₂ =>
            have hx := numeric_inj x₁ x₂ h₁.1 h₂.1 (h₁.2.trans h₂.2.symm)
            cases hx
            rfl
          | inr special₂ =>
            rcases special₂ with ⟨sign₂, nan₂⟩
            exact False.elim (numeric_special_disjoint x₁ bs sign₂ nan₂ h₁.1 h₁.2 h₂)
        | inr special₁ =>
          rcases special₁ with ⟨sign₁, nan₁⟩
          cases value₂ with
          | inl x₂ =>
            exact False.elim (numeric_special_disjoint x₂ bs sign₁ nan₁ h₂.1 h₂.2 h₁)
          | inr special₂ =>
            rcases special₂ with ⟨sign₂, nan₂⟩
            have hs := special_inj bs sign₁ nan₁ sign₂ nan₂ h₁ h₂
            cases hs
            rfl

  constructor
  · intro bs c₁ c₂ _ h₁ h₂
    change Classifies bs c₁ at h₁
    change Classifies bs c₂ at h₂
    exact classification_unique bs c₁ c₂ h₁ h₂
  · intro bs x₁ x₂ _ h₁ h₂
    change NumericLiteral bs x₁ at h₁
    change NumericLiteral bs x₂ at h₂
    exact numeric_inj x₁ x₂ h₁.1 h₂.1 (h₁.2.trans h₂.2.symm)

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.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

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ClassificationDeterminism]
theorem ClassificationDeterminism :
    (∀ (bs : List Nat) c₁ c₂, (∀ b ∈ bs, b < 256) ->
      DecimalGoalVocabularyDefault.classifies bs c₁ -> DecimalGoalVocabularyDefault.classifies bs c₂ -> c₁ = c₂) ∧
    (∀ (bs : List Nat) x₁ x₂, (∀ b ∈ bs, b < 256) ->
      DecimalGoalVocabularyDefault.classifies bs (some (Sum.inl x₁)) ->
      DecimalGoalVocabularyDefault.classifies bs (some (Sum.inl x₂)) -> x₁ = x₂) := by
-- BODY
  let signBytes : Option Bool → List Nat := fun sign =>
    match sign with | none => [] | some negative => [if negative then 45 else 43]
  let digitBytes : List Nat → List Nat := fun ds => ds.map (fun d => 48 + d)
  let AllDigits : List Nat → Prop := fun ds => ∀ d ∈ ds, d < 10
  let SignFreeHead : List Nat → Prop := fun xs =>
    ∀ h t, xs = h :: t → h ≠ 43 ∧ h ≠ 45
  let DigitFreeHead : List Nat → Prop := fun xs =>
    ∀ h t, xs = h :: t → h < 48 ∨ 58 ≤ h
  let exponentBytes : Option (Bool × Option Bool × List Nat) → List Nat := fun e =>
    match e with
    | none => []
    | some (upper, sign, ds) =>
        (if upper then 69 else 101) :: signBytes sign ++ digitBytes ds
  let fractionBytes : Option (List Nat) → List Nat := fun f =>
    match f with | none => [] | some ds => 46 :: digitBytes ds
  let ValidNumeric : DecimalLexeme → Prop := fun x =>
    AllDigits x.integerDigits ∧
    (match x.fractionDigits with | none => True | some ds => AllDigits ds) ∧
    (x.integerDigits ≠ [] ∨
      match x.fractionDigits with | none => False | some ds => ds ≠ []) ∧
    (match x.exponent with
      | none => True
      | some (_, _, ds) => ds ≠ [] ∧ AllDigits ds)
  let RenderNumeric : DecimalLexeme → List Nat := fun x =>
    signBytes x.leadingSign ++ digitBytes x.integerDigits ++
      fractionBytes x.fractionDigits ++ exponentBytes x.exponent
  let CaseEq : List Nat → List Nat → Prop := fun xs ys =>
    List.Forall₂ (fun actual lower => actual = lower ∨ actual + 32 = lower) xs ys
  let SpecialBody : List Nat → Bool → Prop := fun body nan =>
    if nan then CaseEq body [110, 97, 110]
    else CaseEq body [105, 110, 102] ∨
      CaseEq body [105, 110, 102, 105, 110, 105, 116, 121]
  let SpecialLiteral : List Nat → Option Bool → Bool → Prop := fun bs sign nan =>
    ∃ body, bs = signBytes sign ++ body ∧ SpecialBody body nan
  let NumericLiteral : List Nat → DecimalLexeme → Prop := fun bs x =>
    ValidNumeric x ∧ RenderNumeric x = bs
  let Classifies : List Nat → Option (Sum DecimalLexeme (Option Bool × Bool)) → Prop :=
    fun bs c => match c with
    | some (Sum.inl x) => NumericLiteral bs x
    | some (Sum.inr (sign, nan)) => SpecialLiteral bs sign nan
    | none => (¬ ∃ x, NumericLiteral bs x) ∧ (¬ ∃ sign nan, SpecialLiteral bs sign nan)

  have sign_split : ∀ s₁ s₂ xs ys,
      SignFreeHead xs → SignFreeHead ys →
      signBytes s₁ ++ xs = signBytes s₂ ++ ys → s₁ = s₂ ∧ xs = ys := by
    intro s₁ s₂ xs ys hxs hys heq
    cases s₁ with
    | none =>
      cases s₂ with
      | none => exact ⟨rfl, by simpa [signBytes] using heq⟩
      | some b₂ =>
        cases b₂ <;> simp only [signBytes, ↓reduceIte, List.nil_append,
          List.cons_append, List.append_nil] at heq
        · have := hxs 43 ys heq
          exact False.elim (this.1 rfl)
        · have := hxs 45 ys heq
          exact False.elim (this.2 rfl)
    | some b₁ =>
      cases s₂ with
      | none =>
        cases b₁ <;> simp only [signBytes, ↓reduceIte, List.nil_append,
          List.cons_append, List.append_nil] at heq
        · have := hys 43 xs heq.symm
          exact False.elim (this.1 rfl)
        · have := hys 45 xs heq.symm
          exact False.elim (this.2 rfl)
      | some b₂ =>
        cases b₁ <;> cases b₂
        · simp only [signBytes, ↓reduceIte, List.cons_append, List.append_nil,
            List.cons.injEq] at heq
          exact ⟨rfl, heq.2⟩
        · simp [signBytes] at heq
        · simp [signBytes] at heq
        · simp only [signBytes, ↓reduceIte, List.cons_append, List.append_nil,
            List.cons.injEq] at heq
          exact ⟨rfl, heq.2⟩

  have digits_split : ∀ ds₁ ds₂ xs ys,
      AllDigits ds₁ → AllDigits ds₂ →
      DigitFreeHead xs → DigitFreeHead ys →
      digitBytes ds₁ ++ xs = digitBytes ds₂ ++ ys → ds₁ = ds₂ ∧ xs = ys := by
    intro ds₁
    induction ds₁ with
    | nil =>
      intro bs xs ys has hbs hxs hys heq
      cases bs with
      | nil => exact ⟨rfl, by simpa [digitBytes] using heq⟩
      | cons b bs =>
        simp only [digitBytes, List.map_cons, List.nil_append, List.cons_append,
          List.cons.injEq] at heq
        have hb : b < 10 := hbs b (by simp)
        have hx := hxs (48 + b) (digitBytes bs ++ ys) heq
        omega
    | cons a ds₁ ih =>
      intro bs xs ys has hbs hxs hys heq
      cases bs with
      | nil =>
        simp only [digitBytes, List.map_cons, List.nil_append, List.cons_append,
          List.cons.injEq] at heq
        have ha : a < 10 := has a (by simp)
        have hy := hys (48 + a) (digitBytes ds₁ ++ xs) heq.symm
        omega
      | cons b bs =>
        simp only [digitBytes, List.map_cons, List.cons_append, List.cons.injEq] at heq
        have hab : a = b := by omega
        subst b
        have has' : AllDigits ds₁ := by
          intro d hd
          exact has d (by simp [hd])
        have hbs' : AllDigits bs := by
          intro d hd
          exact hbs d (by simp [hd])
        have hr := ih bs xs ys has' hbs' hxs hys heq.2
        exact ⟨by simp [hr.1], hr.2⟩

  have digitBytes_signfree : ∀ ds,
      AllDigits ds → SignFreeHead (digitBytes ds) := by
    intro ds hds h t heq
    cases ds with
    | nil => simp [digitBytes] at heq
    | cons d ds =>
      simp only [digitBytes, List.map_cons, List.cons.injEq] at heq
      have hd : d < 10 := hds d (by simp)
      omega

  have exponentBytes_digitfree : ∀ e, DigitFreeHead (exponentBytes e) := by
    intro e h t heq
    cases e with
    | none => simp [exponentBytes] at heq
    | some value =>
      rcases value with ⟨upper, sign, ds⟩
      cases upper <;> simp [exponentBytes] at heq <;> omega

  have fracExp_digitfree : ∀ f e,
      DigitFreeHead (fractionBytes f ++ exponentBytes e) := by
    intro f e h t heq
    cases f with
    | none =>
      simpa [fractionBytes] using exponentBytes_digitfree e h t heq
    | some ds =>
      simp [fractionBytes] at heq
      omega

  have numericBody_signfree : ∀ i f e,
      AllDigits i →
      (i ≠ [] ∨ match f with | none => False | some ds => ds ≠ []) →
      SignFreeHead (digitBytes i ++ fractionBytes f ++ exponentBytes e) := by
    intro i f e hi hnonempty h t heq
    cases i with
    | nil =>
      simp only [List.nil_eq, ne_eq, not_true_eq_false, false_or] at hnonempty
      cases f with
      | none => simp at hnonempty
      | some ds =>
        cases ds with
        | nil => simp at hnonempty
        | cons d ds =>
          simp [digitBytes, fractionBytes] at heq
          omega
    | cons d ds =>
      simp only [digitBytes, List.map_cons, List.cons_append, List.cons.injEq] at heq
      have hd : d < 10 := hi d (by simp)
      omega

  have exponent_inj : ∀ e₁ e₂,
      (match e₁ with | none => True | some (_, _, ds) => AllDigits ds) →
      (match e₂ with | none => True | some (_, _, ds) => AllDigits ds) →
      exponentBytes e₁ = exponentBytes e₂ → e₁ = e₂ := by
    intro e₁ e₂ hv₁ hv₂ heq
    cases e₁ with
    | none =>
      cases e₂ with
      | none => rfl
      | some value₂ =>
        rcases value₂ with ⟨upper₂, sign₂, ds₂⟩
        cases upper₂ <;> simp [exponentBytes] at heq
    | some value₁ =>
      rcases value₁ with ⟨upper₁, sign₁, ds₁⟩
      cases e₂ with
      | none => cases upper₁ <;> simp [exponentBytes] at heq
      | some value₂ =>
        rcases value₂ with ⟨upper₂, sign₂, ds₂⟩
        cases upper₁ <;> cases upper₂
        · have htail : signBytes sign₁ ++ digitBytes ds₁ =
              signBytes sign₂ ++ digitBytes ds₂ := by
            simpa [exponentBytes] using heq
          have hs := sign_split sign₁ sign₂ (digitBytes ds₁) (digitBytes ds₂)
            (digitBytes_signfree ds₁ hv₁) (digitBytes_signfree ds₂ hv₂) htail
          have hd := digits_split ds₁ ds₂ [] [] hv₁ hv₂
            (by simp [DigitFreeHead]) (by simp [DigitFreeHead]) (by simpa using hs.2)
          simp [hs.1, hd.1]
        · simp [exponentBytes] at heq
        · simp [exponentBytes] at heq
        · have htail : signBytes sign₁ ++ digitBytes ds₁ =
              signBytes sign₂ ++ digitBytes ds₂ := by
            simpa [exponentBytes] using heq
          have hs := sign_split sign₁ sign₂ (digitBytes ds₁) (digitBytes ds₂)
            (digitBytes_signfree ds₁ hv₁) (digitBytes_signfree ds₂ hv₂) htail
          have hd := digits_split ds₁ ds₂ [] [] hv₁ hv₂
            (by simp [DigitFreeHead]) (by simp [DigitFreeHead]) (by simpa using hs.2)
          simp [hs.1, hd.1]

  have exponentValidity_digits : ∀ (e : Option (Bool × Option Bool × List Nat)),
      (match e with | none => True | some (_, _, ds) => ds ≠ [] ∧ AllDigits ds) →
      (match e with | none => True | some (_, _, ds) => AllDigits ds) := by
    intro e h
    cases e with
    | none => trivial
    | some value =>
      rcases value with ⟨upper, sign, ds⟩
      exact h.2

  have fracExp_inj : ∀ f₁ f₂ e₁ e₂,
      (match f₁ with | none => True | some ds => AllDigits ds) →
      (match f₂ with | none => True | some ds => AllDigits ds) →
      (match e₁ with | none => True | some (_, _, ds) => AllDigits ds) →
      (match e₂ with | none => True | some (_, _, ds) => AllDigits ds) →
      fractionBytes f₁ ++ exponentBytes e₁ =
        fractionBytes f₂ ++ exponentBytes e₂ →
      f₁ = f₂ ∧ e₁ = e₂ := by
    intro f₁ f₂ e₁ e₂ hf₁ hf₂ he₁ he₂ heq
    cases f₁ with
    | none =>
      cases f₂ with
      | none =>
        have he : e₁ = e₂ := exponent_inj e₁ e₂ he₁ he₂ (by simpa [fractionBytes] using heq)
        exact ⟨rfl, he⟩
      | some ds₂ =>
        cases e₁ with
        | none => simp [fractionBytes, exponentBytes] at heq
        | some value₁ =>
          rcases value₁ with ⟨upper₁, sign₁, es₁⟩
          cases upper₁ <;> simp [fractionBytes, exponentBytes] at heq
    | some ds₁ =>
      cases f₂ with
      | none =>
        cases e₂ with
        | none => simp [fractionBytes, exponentBytes] at heq
        | some value₂ =>
          rcases value₂ with ⟨upper₂, sign₂, es₂⟩
          cases upper₂ <;> simp [fractionBytes, exponentBytes] at heq
      | some ds₂ =>
        simp only [fractionBytes, List.cons_append, List.cons.injEq] at heq
        have hd := digits_split ds₁ ds₂ (exponentBytes e₁) (exponentBytes e₂)
          hf₁ hf₂ (exponentBytes_digitfree e₁) (exponentBytes_digitfree e₂) heq.2
        have he := exponent_inj e₁ e₂ he₁ he₂ hd.2
        exact ⟨by simp [hd.1], he⟩

  have numeric_inj : ∀ x₁ x₂,
      ValidNumeric x₁ → ValidNumeric x₂ →
      RenderNumeric x₁ = RenderNumeric x₂ → x₁ = x₂ := by
    rintro ⟨s₁, i₁, f₁, e₁⟩ ⟨s₂, i₂, f₂, e₂⟩ hv₁ hv₂ heq
    simp only [ValidNumeric] at hv₁ hv₂
    simp only [RenderNumeric] at heq
    have hs := sign_split s₁ s₂
      (digitBytes i₁ ++ fractionBytes f₁ ++ exponentBytes e₁)
      (digitBytes i₂ ++ fractionBytes f₂ ++ exponentBytes e₂)
      (numericBody_signfree i₁ f₁ e₁ hv₁.1 hv₁.2.2.1)
      (numericBody_signfree i₂ f₂ e₂ hv₂.1 hv₂.2.2.1)
      (by simpa [List.append_assoc] using heq)
    have hi := digits_split i₁ i₂
      (fractionBytes f₁ ++ exponentBytes e₁)
      (fractionBytes f₂ ++ exponentBytes e₂)
      hv₁.1 hv₂.1 (fracExp_digitfree f₁ e₁) (fracExp_digitfree f₂ e₂)
      (by simpa [List.append_assoc] using hs.2)
    have he₁ := exponentValidity_digits e₁ hv₁.2.2.2
    have he₂ := exponentValidity_digits e₂ hv₂.2.2.2
    have hf := fracExp_inj f₁ f₂ e₁ e₂ hv₁.2.1 hv₂.2.1 he₁ he₂ hi.2
    cases hs.1
    cases hi.1
    cases hf.1
    cases hf.2
    rfl

  have caseEq_largeHead : ∀ body lower lowers,
      90 ≤ lower → CaseEq body (lower :: lowers) →
      ∃ actual rest, body = actual :: rest ∧ 58 ≤ actual := by
    intro body lower lowers hlower hcase
    cases hcase with
    | cons hhead htail =>
      refine ⟨_, _, rfl, ?_⟩
      rcases hhead with hhead | hhead <;> omega

  have specialBody_largeHead : ∀ body nan,
      SpecialBody body nan → ∃ actual rest, body = actual :: rest ∧ 58 ≤ actual := by
    intro body nan hbody
    cases nan
    · simp only [SpecialBody, Bool.false_eq_true, if_false] at hbody
      rcases hbody with hshort | hlong
      · exact caseEq_largeHead body 105 [110, 102] (by omega) hshort
      · exact caseEq_largeHead body 105 [110, 102, 105, 110, 105, 116, 121] (by omega) hlong
    · simp only [SpecialBody, if_true] at hbody
      exact caseEq_largeHead body 110 [97, 110] (by omega) hbody

  have specialBody_signfree : ∀ body nan,
      SpecialBody body nan → SignFreeHead body := by
    intro body nan hbody h t heq
    rcases specialBody_largeHead body nan hbody with ⟨actual, rest, hshape, hlarge⟩
    rw [hshape] at heq
    simp only [List.cons.injEq] at heq
    omega

  have nan_inf_disjoint : ∀ body infTail,
      CaseEq body [110, 97, 110] → CaseEq body (105 :: infTail) → False := by
    intro body infTail hnan hinf
    cases hnan with
    | cons hnanHead hnanTail =>
      cases hinf with
      | cons hinfHead hinfTailProof =>
        rcases hnanHead with hnanHead | hnanHead <;>
          rcases hinfHead with hinfHead | hinfHead <;> omega

  have special_inj : ∀ bs s₁ nan₁ s₂ nan₂,
      SpecialLiteral bs s₁ nan₁ → SpecialLiteral bs s₂ nan₂ →
      (s₁, nan₁) = (s₂, nan₂) := by
    intro bs s₁ nan₁ s₂ nan₂ h₁ h₂
    rcases h₁ with ⟨body₁, hbs₁, hbody₁⟩
    rcases h₂ with ⟨body₂, hbs₂, hbody₂⟩
    have heq : signBytes s₁ ++ body₁ = signBytes s₂ ++ body₂ := hbs₁.symm.trans hbs₂
    have hs := sign_split s₁ s₂ body₁ body₂
      (specialBody_signfree body₁ nan₁ hbody₁)
      (specialBody_signfree body₂ nan₂ hbody₂) heq
    cases hs.1
    cases hs.2
    cases nan₁ <;> cases nan₂
    · rfl
    · simp only [SpecialBody, Bool.false_eq_true, if_false] at hbody₁
      simp only [SpecialBody, if_true] at hbody₂
      rcases hbody₁ with hshort | hlong
      · exact False.elim (nan_inf_disjoint body₁ [110, 102] hbody₂ hshort)
      · exact False.elim
          (nan_inf_disjoint body₁ [110, 102, 105, 110, 105, 116, 121] hbody₂ hlong)
    · simp only [SpecialBody, if_true] at hbody₁
      simp only [SpecialBody, Bool.false_eq_true, if_false] at hbody₂
      rcases hbody₂ with hshort | hlong
      · exact False.elim (nan_inf_disjoint body₁ [110, 102] hbody₁ hshort)
      · exact False.elim
          (nan_inf_disjoint body₁ [110, 102, 105, 110, 105, 116, 121] hbody₁ hlong)
    · rfl

  have numericBody_smallHead : ∀ i f e,
      AllDigits i →
      (i ≠ [] ∨ match f with | none => False | some ds => ds ≠ []) →
      ∃ actual rest,
        digitBytes i ++ fractionBytes f ++ exponentBytes e = actual :: rest ∧ actual < 58 := by
    intro i f e hi hnonempty
    cases i with
    | nil =>
      simp only [ne_eq, not_true_eq_false, false_or] at hnonempty
      cases f with
      | none => simp at hnonempty
      | some ds =>
        refine ⟨46, digitBytes ds ++ exponentBytes e, ?_, by omega⟩
        simp [digitBytes, fractionBytes]
    | cons d ds =>
      have hd : d < 10 := hi d (by simp)
      refine ⟨48 + d, digitBytes ds ++ fractionBytes f ++ exponentBytes e, ?_, by omega⟩
      simp [digitBytes]

  have numeric_special_disjoint : ∀ x bs sign nan,
      ValidNumeric x → RenderNumeric x = bs → SpecialLiteral bs sign nan → False := by
    rintro ⟨lead, i, f, e⟩ bs sign nan hv hrender hspecial
    simp only [ValidNumeric] at hv
    simp only [RenderNumeric] at hrender
    rcases hspecial with ⟨body, hbs, hbody⟩
    have heq : signBytes lead ++ (digitBytes i ++ fractionBytes f ++ exponentBytes e) =
        signBytes sign ++ body := by
      rw [← hbs, ← hrender]
      simp [List.append_assoc]
    have hs := sign_split lead sign (digitBytes i ++ fractionBytes f ++ exponentBytes e) body
      (numericBody_signfree i f e hv.1 hv.2.2.1) (specialBody_signfree body nan hbody) heq
    rcases numericBody_smallHead i f e hv.1 hv.2.2.1 with ⟨nhead, ntail, hnshape, hnsmall⟩
    rcases specialBody_largeHead body nan hbody with ⟨shead, stail, hsshape, hslarge⟩
    rw [hnshape, hsshape] at hs
    simp only [List.cons.injEq] at hs
    omega

  have classification_unique : ∀ bs c₁ c₂,
      Classifies bs c₁ → Classifies bs c₂ → c₁ = c₂ := by
    intro bs c₁ c₂ h₁ h₂
    cases c₁ with
    | none =>
      cases c₂ with
      | none => rfl
      | some value₂ =>
        cases value₂ with
        | inl x₂ =>
          exact False.elim (h₁.1 ⟨x₂, h₂⟩)
        | inr special₂ =>
          rcases special₂ with ⟨sign₂, nan₂⟩
          exact False.elim (h₁.2 ⟨sign₂, nan₂, h₂⟩)
    | some value₁ =>
      cases c₂ with
      | none =>
        cases value₁ with
        | inl x₁ =>
          exact False.elim (h₂.1 ⟨x₁, h₁⟩)
        | inr special₁ =>
          rcases special₁ with ⟨sign₁, nan₁⟩
          exact False.elim (h₂.2 ⟨sign₁, nan₁, h₁⟩)
      | some value₂ =>
        cases value₁ with
        | inl x₁ =>
          cases value₂ with
          | inl x₂ =>
            have hx := numeric_inj x₁ x₂ h₁.1 h₂.1 (h₁.2.trans h₂.2.symm)
            cases hx
            rfl
          | inr special₂ =>
            rcases special₂ with ⟨sign₂, nan₂⟩
            exact False.elim (numeric_special_disjoint x₁ bs sign₂ nan₂ h₁.1 h₁.2 h₂)
        | inr special₁ =>
          rcases special₁ with ⟨sign₁, nan₁⟩
          cases value₂ with
          | inl x₂ =>
            exact False.elim (numeric_special_disjoint x₂ bs sign₁ nan₁ h₂.1 h₂.2 h₁)
          | inr special₂ =>
            rcases special₂ with ⟨sign₂, nan₂⟩
            have hs := special_inj bs sign₁ nan₁ sign₂ nan₂ h₁ h₂
            cases hs
            rfl

  constructor
  · intro bs c₁ c₂ _ h₁ h₂
    change Classifies bs c₁ at h₁
    change Classifies bs c₂ at h₂
    exact classification_unique bs c₁ c₂ h₁ h₂
  · intro bs x₁ x₂ _ h₁ h₂
    change NumericLiteral bs x₁ at h₁
    change NumericLiteral bs x₂ at h₂
    exact numeric_inj x₁ x₂ h₁.1 h₂.1 (h₁.2.trans h₂.2.symm)

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 7 entries
Technical checking records
Local closure summary
{
  "node": "ClassificationDeterminism",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "078db0b83673f4ef3ebcc4985b44a6877bdee54b822aba44ac075394103d77d8",
  "active_statement_hash": "0b7214ec43b11184b4c228f612ccb9f369937a0e283b6ad5f3b8b05448f06389",
  "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-91",
  "boundary_theorems": {},
  "strict_theorem_deps": {},
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "64f24e4e46904b6a",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "DecimalLexeme": "bf0c609978369054"
  }
}
Prose assessment
{
  "label": "Sound flag superseded by recorded Lean closure",
  "assessment_status": "ReviewerPinnedFail",
  "fingerprint_relation": "differs from current fingerprint",
  "assessment_fingerprint": "sound-v2:a6c915e712aeb7161bf7af6ddd2eb0852c8f57139c20e732fa3d09ec07b01155",
  "current_fingerprint": "sound-v2:96794f3e1efa4e96954c81f17dd7a1464271168cfed992d9567017bd6d1c784b",
  "superseded_for_theorem_closure": true
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Fail",
  "substantiveness_status": "Pass"
}