P13_T1_ParserNumericSign

Lean checked

Statement

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

Theorem

Every normally successful numeric result of the actual specialized dec2flt, on any source-valid Rust string, has its literal's lexical sign. Its sign bit is set exactly when the complete literal has a leading minus. The claim includes underflow to zero and overflow to infinity, and has no A or B restriction. Whole-input numeric grammar, lexical sign, and word-sign observations are DecimalGoalVocabularyDefault. The specialization is ActualDispatchOperations.

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.P9_T1_ActualDispatchOperations
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.SourceValidByteSlice
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.SpecialHelperRejection
import Tablet.P13_T1_NativeCorrectOrDefer
import Tablet.ParserSelectedMagnitudeSign
import Tablet.AssemblyCorrespondence
import Tablet.Binary64ApplySign

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P13_T1_ParserNumericSign]
theorem P13_T1_ParserNumericSign :
    forall (s : Str) (x : DecimalLexeme) (f : F64),
      DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes s ->
      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.isNegative f ↔
        DecimalGoalVocabularyDefault.lexicalNegative x = true) := 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 proof: SKETCH. The explanatory prose is preserved as it stood when captured.

Proof

SKETCH: Relate the stripped sign to the native record sign and final assembled-word sign application on every normally successful numeric branch.

Lean proof


  intro s x f hsource hvalid hrender hpublic
  have bind_ok_inv : ∀ {α β : Type} (r : Result α) (g : α → Result β) y,
      Bind.bind r g = ok y → ∃ z, r = ok z ∧ g z = ok y := by
    intro α β r g y hr
    cases r with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hr
    | div => simp [Bind.bind, Aeneas.Std.bind] at hr
    | ok z => exact ⟨z, rfl, hr⟩
  have signed_negative : ∀ (negative : Bool) (magnitude result : F64),
      DecimalGoalVocabularyDefault.signedMagnitude negative magnitude result →
      (DecimalGoalVocabularyDefault.isNegative result ↔ negative = true) := by
    intro negative magnitude result hsigned
    dsimp only [DecimalGoalVocabularyDefault] at hsigned ⊢
    rcases hsigned with ⟨hbound, hval⟩
    cases negative <;> simp only [Bool.false_eq_true, if_false, if_true, add_zero] at hval ⊢
    · rw [hval]
      exact ⟨fun h => (Nat.not_le_of_lt hbound h).elim, False.elim⟩
    · rw [hval]
      exact ⟨fun _ => trivial, fun _ => Nat.le_add_left _ _⟩
  let fractionBytes : List Nat :=
    match x.fractionDigits with | none => [] | some ds => 46 :: ds.map (fun d => 48 + d)
  let exponentBytes : List Nat :=
    match x.exponent with
    | none => []
    | some (upper, sign, ds) =>
      (if upper then 69 else 101) ::
        (match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
        ds.map (fun d => 48 + d)
  let numericBody : List Nat :=
    x.integerDigits.map (fun d => 48 + d) ++ fractionBytes ++ exponentBytes
  have numericHead : ∃ head rest, numericBody = head :: rest ∧
      (head = 46 ∨ (48 ≤ head ∧ head < 58)) := by
    have hv := hvalid
    dsimp only [DecimalGoalVocabularyDefault] at hv
    cases hi : x.integerDigits with
    | nil =>
      cases hf : x.fractionDigits with
      | none => simp [hi, hf] at hv
      | some ds =>
        refine ⟨46, ds.map (fun d => 48 + d) ++ exponentBytes, ?_, Or.inl rfl⟩
        simp [numericBody, fractionBytes, hi, hf]
    | cons d ds =>
      refine ⟨48 + d, ds.map (fun d => 48 + d) ++ fractionBytes ++ exponentBytes,
        ?_, Or.inr ?_⟩
      · simp [numericBody, hi]
      · have hd : d < 10 := hv.1 d (by simp [hi])
        omega
  obtain ⟨head, rest, hhead, hheadRange⟩ := numericHead
  have hrenderBody :
      (match x.leadingSign with
        | none => [] | some negative => [if negative then 45 else 43]) ++
          (head :: rest) = DecimalGoalVocabularyDefault.bytes s := by
    rw [← hhead]
    simpa only [DecimalGoalVocabularyDefault, numericBody, fractionBytes,
      exponentBytes, List.append_assoc] using hrender
  have notSpecial : ∀ nan : Bool,
      ¬ DecimalGoalVocabularyDefault.specialLiteral (head :: rest) none nan := by
    intro nan hspecial
    dsimp only [DecimalGoalVocabularyDefault] at hspecial
    rcases hspecial with ⟨specialBody, hspecialBody, hcase⟩
    simp only [List.nil_append] at hspecialBody
    rw [← hspecialBody] at hcase
    cases nan with
    | false =>
      simp only [Bool.false_eq_true, if_false] at hcase
      rcases hcase with hcase | hcase <;>
        simp only [List.forall₂_cons] at hcase <;> omega
    | true =>
      simp only [if_true, List.forall₂_cons] at hcase
      omega
  unfold num.imp.dec2flt.dec2flt at hpublic
  obtain ⟨out, hout, hpublic⟩ := bind_ok_inv _ _ _ hpublic
  rcases out with ⟨publicResult, trace⟩
  cases hpublic
  have traced :
      num.imp.dec2flt.dec2flt_with_trace
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s =
        ok (core.result.Result.Ok f, trace) := hout
  rcases s with ⟨source, source_bound⟩
  cases source with
  | nil =>
    unfold num.imp.dec2flt.dec2flt_with_trace at traced
    obtain ⟨body, hbody, traced⟩ := bind_ok_inv _ _ _ traced
    have hbodyEq : body = (⟨[], source_bound⟩ : Slice Std.U8) := by
      simpa [core.str.Str.as_bytes, ModelStrAsBytes] using hbody.symm
    subst body
    obtain ⟨firstOption, hfirst, traced⟩ := bind_ok_inv _ _ _ traced
    have hfirstEq : firstOption = none := by
      simpa [core.slice.Slice.first, ModelSliceFirst] using hfirst.symm
    subst firstOption
    obtain ⟨pfe, hpfe, traced⟩ := bind_ok_inv _ _ _ traced
    cases traced
  | cons first tail =>
    unfold num.imp.dec2flt.dec2flt_with_trace at traced
    obtain ⟨body, hbody, traced⟩ := bind_ok_inv _ _ _ traced
    have hbodyEq : body = (⟨first :: tail, source_bound⟩ : Slice Std.U8) := by
      simpa [core.str.Str.as_bytes, ModelStrAsBytes] using hbody.symm
    subst body
    obtain ⟨firstOption, hfirst, traced⟩ := bind_ok_inv _ _ _ traced
    have hfirstEq : firstOption = some first := by
      simpa [core.slice.Slice.first, ModelSliceFirst] using hfirst.symm
    subst firstOption
    obtain ⟨body1, hbody1, traced⟩ := bind_ok_inv _ _ _ traced
    have hstrip : decide (first = 45#u8) = DecimalGoalVocabularyDefault.lexicalNegative x ∧
        DecimalGoalVocabularyDefault.bytes body1 = head :: rest ∧
        SourceValidByteSlice body1 := by
      have hslen := hsource.1
      dsimp only [DecimalGoalVocabularyDefault] at hrenderBody
      simp only [List.map_cons] at hrenderBody
      cases hsign : x.leadingSign with
      | none =>
        simp only [hsign, List.nil_append, List.cons.injEq] at hrenderBody
        have hminus : first ≠ 45#u8 := by
          intro heq
          have hv := congrArg UScalar.val heq
          norm_num at hv
          omega
        have hplus : first ≠ 43#u8 := by
          intro heq
          have hv := congrArg UScalar.val heq
          norm_num at hv
          omega
        simp only [hminus, hplus, if_false] at hbody1
        cases hbody1
        refine ⟨?_, ?_, hslen⟩
        · simp [DecimalGoalVocabularyDefault, hsign, hminus]
        · dsimp only [DecimalGoalVocabularyDefault]
          simp only [List.map_cons]
          rw [← hrenderBody.1, ← hrenderBody.2]
      | some negative =>
        cases negative with
        | false =>
          simp only [hsign, Bool.false_eq_true, if_false, List.cons_append,
            List.nil_append, List.cons.injEq] at hrenderBody
          have hfirstPlus : first = 43#u8 := by
            apply UScalar.eq_of_val_eq
            norm_num
            exact hrenderBody.1.symm
          simp only [hfirstPlus, if_false, if_true] at hbody1
          simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
            Slice.drop] at hbody1
          cases hbody1
          refine ⟨?_, ?_, ?_⟩
          · simp [DecimalGoalVocabularyDefault, hsign, hfirstPlus]
          · simpa only [DecimalGoalVocabularyDefault] using hrenderBody.2.symm
          · unfold SourceValidByteSlice
            simp at hslen ⊢
            omega
        | true =>
          simp only [hsign, if_true, List.cons_append, List.nil_append,
            List.cons.injEq] at hrenderBody
          have hfirstMinus : first = 45#u8 := by
            apply UScalar.eq_of_val_eq
            norm_num
            exact hrenderBody.1.symm
          simp only [hfirstMinus, if_true] at hbody1
          simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
            Slice.drop] at hbody1
          cases hbody1
          refine ⟨?_, ?_, ?_⟩
          · simp [DecimalGoalVocabularyDefault, hsign, hfirstMinus]
          · simpa only [DecimalGoalVocabularyDefault] using hrenderBody.2.symm
          · unfold SourceValidByteSlice
            simp at hslen ⊢
            omega
    obtain ⟨empty, hempty, traced⟩ := bind_ok_inv _ _ _ traced
    by_cases emptyTrue : empty = true
    · simp only [emptyTrue, if_true] at traced
      obtain ⟨pfe, hpfe, traced⟩ := bind_ok_inv _ _ _ traced
      cases traced
    · have emptyFalse : empty = false := Bool.eq_false_of_not_eq_true emptyTrue
      simp only [emptyFalse, if_false] at traced
      obtain ⟨parsed, hparsed, traced⟩ := bind_ok_inv _ _ _ traced
      cases parsed with
      | none =>
        obtain ⟨special, hspecial, traced⟩ := bind_ok_inv _ _ _ traced
        have hrejection := SpecialHelperRejection body1 (decide (first = 45#u8))
          hstrip.2.2 (by rw [hstrip.2.1]; exact notSpecial false)
          (by rw [hstrip.2.1]; exact notSpecial true)
        rw [hrejection] at hspecial
        cases hspecial
        obtain ⟨pfe, hpfe, traced⟩ := bind_ok_inv _ _ _ traced
        cases traced
      | some r =>
        obtain ⟨fast, hfast, traced⟩ := bind_ok_inv _ _ _ traced
        cases fast with
        | some value =>
          have hnative := P13_T1_NativeCorrectOrDefer
            ({ r with negative := decide (first = 45#u8) }) (some value) hfast
          rcases hnative with hnone |
            ⟨value', magnitude, hvalue, _, _, hsigned⟩
          · simp at hnone
          · cases hvalue
            cases traced
            have hnegative := signed_negative _ _ _ hsigned
            simpa only [hstrip.1] using hnegative
        | none =>
          obtain ⟨firstPair, hfirstPair, traced⟩ := bind_ok_inv _ _ _ traced
          obtain ⟨phase1, hphase1, traced⟩ := bind_ok_inv _ _ _ traced
          rcases phase1 with ⟨many1, many2, firstPair1, fp, guard⟩
          obtain ⟨phase2, hphase2, traced⟩ := bind_ok_inv _ _ _ traced
          rcases phase2 with
            ⟨post, secondExp, secondMant, secondResult, secondEqual, forced⟩
          obtain ⟨phase3, hphase3, traced⟩ := bind_ok_inv _ _ _ traced
          rcases phase3 with ⟨selected, slowGuard, slowResult⟩
          obtain ⟨i, hi, traced⟩ := bind_ok_inv _ _ _ traced
          obtain ⟨i1, hi1, traced⟩ := bind_ok_inv _ _ _ traced
          obtain ⟨i2, hi2, traced⟩ := bind_ok_inv _ _ _ traced
          obtain ⟨word, hword, traced⟩ := bind_ok_inv _ _ _ traced
          obtain ⟨assembled, hassembled, traced⟩ := bind_ok_inv _ _ _ traced
          by_cases negative : first = 45#u8
          · simp only [negative, if_true] at traced
            obtain ⟨result, hresult, traced⟩ := bind_ok_inv _ _ _ traced
            cases traced
            obtain ⟨wordSpec, wordBound⟩ := ParserSelectedMagnitudeSign
              (⟨first :: tail, source_bound⟩ : Str) f _ hsource hout
            change DecimalGoalVocabularyDefault.assembledWord selected word at wordSpec
            change word.val < 2 ^ 63 at wordBound
            obtain ⟨canonical, hcanonical, canonicalSpec⟩ := AssemblyCorrespondence selected
            rw [hassembled] at hcanonical
            cases hcanonical
            have assembledVal : assembled.val = word.val := by
              dsimp only [DecimalGoalVocabularyDefault] at wordSpec canonicalSpec
              exact canonicalSpec.trans wordSpec.symm
            have assembledEq : assembled = word := UScalar.eq_of_val_eq assembledVal
            subst assembled
            change ModelF64Neg word = ok f at hresult
            obtain ⟨signed, hsign, hsigned⟩ := Binary64ApplySign true word wordBound
            simp only [if_true, hresult, bind_tc_ok] at hsign
            cases hsign
            have hnegative := signed_negative _ _ _ hsigned
            have hlexical : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
              rw [← hstrip.1]
              simp [negative]
            simpa only [hlexical] using hnegative
          · simp only [negative, if_false] at traced
            cases traced
            obtain ⟨wordSpec, wordBound⟩ := ParserSelectedMagnitudeSign
              (⟨first :: tail, source_bound⟩ : Str) f _ hsource hout
            change DecimalGoalVocabularyDefault.assembledWord selected word at wordSpec
            change word.val < 2 ^ 63 at wordBound
            obtain ⟨canonical, hcanonical, canonicalSpec⟩ := AssemblyCorrespondence selected
            rw [hassembled] at hcanonical
            cases hcanonical
            have resultVal : f.val = word.val := by
              dsimp only [DecimalGoalVocabularyDefault] at wordSpec canonicalSpec
              exact canonicalSpec.trans wordSpec.symm
            have hlexical : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
              rw [← hstrip.1]
              simp [negative]
            dsimp only [DecimalGoalVocabularyDefault] at wordBound ⊢
            rw [resultVal]
            change 2 ^ 63 ≤ word.val ↔ DecimalGoalVocabularyDefault.lexicalNegative x = true
            rw [hlexical]
            simp only [Bool.false_eq_true, iff_false]
            omega

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.num_imp_dec2flt_dec2flt
import Tablet.SourceValidByteSlice
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.SpecialHelperRejection
import Tablet.P13_T1_NativeCorrectOrDefer
import Tablet.ParserSelectedMagnitudeSign
import Tablet.AssemblyCorrespondence
import Tablet.Binary64ApplySign

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P13_T1_ParserNumericSign]
theorem P13_T1_ParserNumericSign :
    forall (s : Str) (x : DecimalLexeme) (f : F64),
      DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes s ->
      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.isNegative f ↔
        DecimalGoalVocabularyDefault.lexicalNegative x = true) := by
-- BODY
  intro s x f hsource hvalid hrender hpublic
  have bind_ok_inv : ∀ {α β : Type} (r : Result α) (g : α → Result β) y,
      Bind.bind r g = ok y → ∃ z, r = ok z ∧ g z = ok y := by
    intro α β r g y hr
    cases r with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hr
    | div => simp [Bind.bind, Aeneas.Std.bind] at hr
    | ok z => exact ⟨z, rfl, hr⟩
  have signed_negative : ∀ (negative : Bool) (magnitude result : F64),
      DecimalGoalVocabularyDefault.signedMagnitude negative magnitude result →
      (DecimalGoalVocabularyDefault.isNegative result ↔ negative = true) := by
    intro negative magnitude result hsigned
    dsimp only [DecimalGoalVocabularyDefault] at hsigned ⊢
    rcases hsigned with ⟨hbound, hval⟩
    cases negative <;> simp only [Bool.false_eq_true, if_false, if_true, add_zero] at hval ⊢
    · rw [hval]
      exact ⟨fun h => (Nat.not_le_of_lt hbound h).elim, False.elim⟩
    · rw [hval]
      exact ⟨fun _ => trivial, fun _ => Nat.le_add_left _ _⟩
  let fractionBytes : List Nat :=
    match x.fractionDigits with | none => [] | some ds => 46 :: ds.map (fun d => 48 + d)
  let exponentBytes : List Nat :=
    match x.exponent with
    | none => []
    | some (upper, sign, ds) =>
      (if upper then 69 else 101) ::
        (match sign with | none => [] | some neg => [if neg then 45 else 43]) ++
        ds.map (fun d => 48 + d)
  let numericBody : List Nat :=
    x.integerDigits.map (fun d => 48 + d) ++ fractionBytes ++ exponentBytes
  have numericHead : ∃ head rest, numericBody = head :: rest ∧
      (head = 46 ∨ (48 ≤ head ∧ head < 58)) := by
    have hv := hvalid
    dsimp only [DecimalGoalVocabularyDefault] at hv
    cases hi : x.integerDigits with
    | nil =>
      cases hf : x.fractionDigits with
      | none => simp [hi, hf] at hv
      | some ds =>
        refine ⟨46, ds.map (fun d => 48 + d) ++ exponentBytes, ?_, Or.inl rfl⟩
        simp [numericBody, fractionBytes, hi, hf]
    | cons d ds =>
      refine ⟨48 + d, ds.map (fun d => 48 + d) ++ fractionBytes ++ exponentBytes,
        ?_, Or.inr ?_⟩
      · simp [numericBody, hi]
      · have hd : d < 10 := hv.1 d (by simp [hi])
        omega
  obtain ⟨head, rest, hhead, hheadRange⟩ := numericHead
  have hrenderBody :
      (match x.leadingSign with
        | none => [] | some negative => [if negative then 45 else 43]) ++
          (head :: rest) = DecimalGoalVocabularyDefault.bytes s := by
    rw [← hhead]
    simpa only [DecimalGoalVocabularyDefault, numericBody, fractionBytes,
      exponentBytes, List.append_assoc] using hrender
  have notSpecial : ∀ nan : Bool,
      ¬ DecimalGoalVocabularyDefault.specialLiteral (head :: rest) none nan := by
    intro nan hspecial
    dsimp only [DecimalGoalVocabularyDefault] at hspecial
    rcases hspecial with ⟨specialBody, hspecialBody, hcase⟩
    simp only [List.nil_append] at hspecialBody
    rw [← hspecialBody] at hcase
    cases nan with
    | false =>
      simp only [Bool.false_eq_true, if_false] at hcase
      rcases hcase with hcase | hcase <;>
        simp only [List.forall₂_cons] at hcase <;> omega
    | true =>
      simp only [if_true, List.forall₂_cons] at hcase
      omega
  unfold num.imp.dec2flt.dec2flt at hpublic
  obtain ⟨out, hout, hpublic⟩ := bind_ok_inv _ _ _ hpublic
  rcases out with ⟨publicResult, trace⟩
  cases hpublic
  have traced :
      num.imp.dec2flt.dec2flt_with_trace
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s =
        ok (core.result.Result.Ok f, trace) := hout
  rcases s with ⟨source, source_bound⟩
  cases source with
  | nil =>
    unfold num.imp.dec2flt.dec2flt_with_trace at traced
    obtain ⟨body, hbody, traced⟩ := bind_ok_inv _ _ _ traced
    have hbodyEq : body = (⟨[], source_bound⟩ : Slice Std.U8) := by
      simpa [core.str.Str.as_bytes, ModelStrAsBytes] using hbody.symm
    subst body
    obtain ⟨firstOption, hfirst, traced⟩ := bind_ok_inv _ _ _ traced
    have hfirstEq : firstOption = none := by
      simpa [core.slice.Slice.first, ModelSliceFirst] using hfirst.symm
    subst firstOption
    obtain ⟨pfe, hpfe, traced⟩ := bind_ok_inv _ _ _ traced
    cases traced
  | cons first tail =>
    unfold num.imp.dec2flt.dec2flt_with_trace at traced
    obtain ⟨body, hbody, traced⟩ := bind_ok_inv _ _ _ traced
    have hbodyEq : body = (⟨first :: tail, source_bound⟩ : Slice Std.U8) := by
      simpa [core.str.Str.as_bytes, ModelStrAsBytes] using hbody.symm
    subst body
    obtain ⟨firstOption, hfirst, traced⟩ := bind_ok_inv _ _ _ traced
    have hfirstEq : firstOption = some first := by
      simpa [core.slice.Slice.first, ModelSliceFirst] using hfirst.symm
    subst firstOption
    obtain ⟨body1, hbody1, traced⟩ := bind_ok_inv _ _ _ traced
    have hstrip : decide (first = 45#u8) = DecimalGoalVocabularyDefault.lexicalNegative x ∧
        DecimalGoalVocabularyDefault.bytes body1 = head :: rest ∧
        SourceValidByteSlice body1 := by
      have hslen := hsource.1
      dsimp only [DecimalGoalVocabularyDefault] at hrenderBody
      simp only [List.map_cons] at hrenderBody
      cases hsign : x.leadingSign with
      | none =>
        simp only [hsign, List.nil_append, List.cons.injEq] at hrenderBody
        have hminus : first ≠ 45#u8 := by
          intro heq
          have hv := congrArg UScalar.val heq
          norm_num at hv
          omega
        have hplus : first ≠ 43#u8 := by
          intro heq
          have hv := congrArg UScalar.val heq
          norm_num at hv
          omega
        simp only [hminus, hplus, if_false] at hbody1
        cases hbody1
        refine ⟨?_, ?_, hslen⟩
        · simp [DecimalGoalVocabularyDefault, hsign, hminus]
        · dsimp only [DecimalGoalVocabularyDefault]
          simp only [List.map_cons]
          rw [← hrenderBody.1, ← hrenderBody.2]
      | some negative =>
        cases negative with
        | false =>
          simp only [hsign, Bool.false_eq_true, if_false, List.cons_append,
            List.nil_append, List.cons.injEq] at hrenderBody
          have hfirstPlus : first = 43#u8 := by
            apply UScalar.eq_of_val_eq
            norm_num
            exact hrenderBody.1.symm
          simp only [hfirstPlus, if_false, if_true] at hbody1
          simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
            Slice.drop] at hbody1
          cases hbody1
          refine ⟨?_, ?_, ?_⟩
          · simp [DecimalGoalVocabularyDefault, hsign, hfirstPlus]
          · simpa only [DecimalGoalVocabularyDefault] using hrenderBody.2.symm
          · unfold SourceValidByteSlice
            simp at hslen ⊢
            omega
        | true =>
          simp only [hsign, if_true, List.cons_append, List.nil_append,
            List.cons.injEq] at hrenderBody
          have hfirstMinus : first = 45#u8 := by
            apply UScalar.eq_of_val_eq
            norm_num
            exact hrenderBody.1.symm
          simp only [hfirstMinus, if_true] at hbody1
          simp [core.slice.index.SliceIndexRangeFromUsizeSlice.index,
            Slice.drop] at hbody1
          cases hbody1
          refine ⟨?_, ?_, ?_⟩
          · simp [DecimalGoalVocabularyDefault, hsign, hfirstMinus]
          · simpa only [DecimalGoalVocabularyDefault] using hrenderBody.2.symm
          · unfold SourceValidByteSlice
            simp at hslen ⊢
            omega
    obtain ⟨empty, hempty, traced⟩ := bind_ok_inv _ _ _ traced
    by_cases emptyTrue : empty = true
    · simp only [emptyTrue, if_true] at traced
      obtain ⟨pfe, hpfe, traced⟩ := bind_ok_inv _ _ _ traced
      cases traced
    · have emptyFalse : empty = false := Bool.eq_false_of_not_eq_true emptyTrue
      simp only [emptyFalse, if_false] at traced
      obtain ⟨parsed, hparsed, traced⟩ := bind_ok_inv _ _ _ traced
      cases parsed with
      | none =>
        obtain ⟨special, hspecial, traced⟩ := bind_ok_inv _ _ _ traced
        have hrejection := SpecialHelperRejection body1 (decide (first = 45#u8))
          hstrip.2.2 (by rw [hstrip.2.1]; exact notSpecial false)
          (by rw [hstrip.2.1]; exact notSpecial true)
        rw [hrejection] at hspecial
        cases hspecial
        obtain ⟨pfe, hpfe, traced⟩ := bind_ok_inv _ _ _ traced
        cases traced
      | some r =>
        obtain ⟨fast, hfast, traced⟩ := bind_ok_inv _ _ _ traced
        cases fast with
        | some value =>
          have hnative := P13_T1_NativeCorrectOrDefer
            ({ r with negative := decide (first = 45#u8) }) (some value) hfast
          rcases hnative with hnone |
            ⟨value', magnitude, hvalue, _, _, hsigned⟩
          · simp at hnone
          · cases hvalue
            cases traced
            have hnegative := signed_negative _ _ _ hsigned
            simpa only [hstrip.1] using hnegative
        | none =>
          obtain ⟨firstPair, hfirstPair, traced⟩ := bind_ok_inv _ _ _ traced
          obtain ⟨phase1, hphase1, traced⟩ := bind_ok_inv _ _ _ traced
          rcases phase1 with ⟨many1, many2, firstPair1, fp, guard⟩
          obtain ⟨phase2, hphase2, traced⟩ := bind_ok_inv _ _ _ traced
          rcases phase2 with
            ⟨post, secondExp, secondMant, secondResult, secondEqual, forced⟩
          obtain ⟨phase3, hphase3, traced⟩ := bind_ok_inv _ _ _ traced
          rcases phase3 with ⟨selected, slowGuard, slowResult⟩
          obtain ⟨i, hi, traced⟩ := bind_ok_inv _ _ _ traced
          obtain ⟨i1, hi1, traced⟩ := bind_ok_inv _ _ _ traced
          obtain ⟨i2, hi2, traced⟩ := bind_ok_inv _ _ _ traced
          obtain ⟨word, hword, traced⟩ := bind_ok_inv _ _ _ traced
          obtain ⟨assembled, hassembled, traced⟩ := bind_ok_inv _ _ _ traced
          by_cases negative : first = 45#u8
          · simp only [negative, if_true] at traced
            obtain ⟨result, hresult, traced⟩ := bind_ok_inv _ _ _ traced
            cases traced
            obtain ⟨wordSpec, wordBound⟩ := ParserSelectedMagnitudeSign
              (⟨first :: tail, source_bound⟩ : Str) f _ hsource hout
            change DecimalGoalVocabularyDefault.assembledWord selected word at wordSpec
            change word.val < 2 ^ 63 at wordBound
            obtain ⟨canonical, hcanonical, canonicalSpec⟩ := AssemblyCorrespondence selected
            rw [hassembled] at hcanonical
            cases hcanonical
            have assembledVal : assembled.val = word.val := by
              dsimp only [DecimalGoalVocabularyDefault] at wordSpec canonicalSpec
              exact canonicalSpec.trans wordSpec.symm
            have assembledEq : assembled = word := UScalar.eq_of_val_eq assembledVal
            subst assembled
            change ModelF64Neg word = ok f at hresult
            obtain ⟨signed, hsign, hsigned⟩ := Binary64ApplySign true word wordBound
            simp only [if_true, hresult, bind_tc_ok] at hsign
            cases hsign
            have hnegative := signed_negative _ _ _ hsigned
            have hlexical : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
              rw [← hstrip.1]
              simp [negative]
            simpa only [hlexical] using hnegative
          · simp only [negative, if_false] at traced
            cases traced
            obtain ⟨wordSpec, wordBound⟩ := ParserSelectedMagnitudeSign
              (⟨first :: tail, source_bound⟩ : Str) f _ hsource hout
            change DecimalGoalVocabularyDefault.assembledWord selected word at wordSpec
            change word.val < 2 ^ 63 at wordBound
            obtain ⟨canonical, hcanonical, canonicalSpec⟩ := AssemblyCorrespondence selected
            rw [hassembled] at hcanonical
            cases hcanonical
            have resultVal : f.val = word.val := by
              dsimp only [DecimalGoalVocabularyDefault] at wordSpec canonicalSpec
              exact canonicalSpec.trans wordSpec.symm
            have hlexical : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
              rw [← hstrip.1]
              simp [negative]
            dsimp only [DecimalGoalVocabularyDefault] at wordBound ⊢
            rw [resultVal]
            change 2 ^ 63 ≤ word.val ↔ DecimalGoalVocabularyDefault.lexicalNegative x = true
            rw [hlexical]
            simp only [Bool.false_eq_true, iff_false]
            omega

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (199)
More program dependencies (157)
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 186 entries
Technical checking records
Local closure summary
{
  "node": "P13_T1_ParserNumericSign",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "9fe04ea301c1927508bc9484c2ca823b9089f41d6e51ff2b013dafc7315411fe",
  "active_statement_hash": "fddb0a2ab82c02fc87f6341ee7223003ac16c4896b285b50659fdae506a621b1",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-199",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "AssemblyCorrespondence": "e3495a6647394e20",
    "Binary64ApplySign": "d55a8c73d5261f86",
    "DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
    "P13_T1_NativeCorrectOrDefer": "bc7b08c927fd6202",
    "ParserSelectedMagnitudeSign": "70c47baac228615a",
    "SpecialHelperRejection": "4dbd872ba02a631e",
    "num_imp_dec2flt_dec2flt_with_trace": "32d9110750ebf062",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "3016c00221d29252",
    "DecimalLexeme": "c43614ff2149ecf2",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_CoreOpsArithDivF64F64": "dc44e13a99fc6bed",
    "F64_Insts_CoreOpsArithMulF64F64": "1ae1a9021a654abd",
    "F64_Insts_CoreOpsArithNegF64": "2d9be310c546ea2e",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64": "60afe26c6a80cf0f",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "ModelF64Neg": "78a021de99eb373b",
    "ModelSliceFirst": "a31394b3c1080f71",
    "Preamble": "5575719dcb1443eb",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "core_ops_arith_Neg": "0ff07135a60bcbf9",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "7bda5de02611ad76",
    "num_imp_dec2flt_Dec2FltTrace": "f5d0731ff1ab56ce",
    "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": "Lean proof closed; predictive prose review no longer required",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "sound-v2:3753b7d11333143981e12a174c70c3fd29b8395240b4e9c5cf30a6c04d8d7a57",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}