P13_T1_ParserSignedZero

Lean checked

Statement

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

Theorem

On acceptance by the actual specialized dec2flt, every numeric literal denoting mathematical exact zero returns the zero word with its lexical sign: raw word 2^{63} for a leading minus and raw word 0 otherwise. This applies to every source-valid Rust string with no A or B bound. Zero refers to the ordinary mathematical exact magnitude, not merely an accumulated or underflowed value. Grammar, exact magnitude and lexical sign are DecimalGoalVocabularyDefault; acceptance means normal Rust Ok. 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.num_imp_dec2flt_dec2flt_with_trace
import Tablet.SourceValidByteSlice
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.SpecialHelperRejection
import Tablet.P401_T1_ExactZeroSignificand
import Tablet.P401_T1_UnsignedZeroRecord
import Tablet.P401_T1_ZeroRounding
import Tablet.P401_T1_ComputeZeroPair
import Tablet.P13_T1_NativeCorrectOrDefer
import Tablet.RoundingDeterminism
import Tablet.AssemblyCorrespondence
import Tablet.Binary64ApplySign

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P13_T1_ParserSignedZero]
theorem P13_T1_ParserSignedZero :
    forall (s : Str) (x : DecimalLexeme) (f : F64),
      DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes s ->
      DecimalGoalVocabularyDefault.exactMagnitude x = 0 ->
      num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f) ->
      f.val = if DecimalGoalVocabularyDefault.lexicalNegative x then 2 ^ 63 else 0 := 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 the source string, valid numeric lexeme x, and returned word f in the statement. By ExactZeroSignificand, ordinary exact zero implies that every integer and fractional digit of x is zero. This implication uses the nonvanishing of every real integer power of ten, not a bound on the mathematical or accumulated exponent.
Unfold num imp dec2flt dec2flt. A Result bind whose final value is ok has a normally returning first computation and a normally returning continuation: failure and divergence propagate unchanged. Thus the premise supplies a normal num imp dec2flt dec2flt with trace execution with Rust result Ok f. Invert each reached bind of that execution in the same way below. This does not assert normality on any other input.
The byte conversion is the identity by ModelStrAsBytes, and the head observation is ModelSliceFirst. Empty input returns Rust Err, incompatible with the premise. Validity and rendering in DecimalGoalVocabularyDefault give a nonempty unsigned body B: it starts with an integer digit in [48,57] if the integer digit list is nonempty, and otherwise with the point byte 46 (validity then requires a nonempty fractional digit list). Rendering has the following three disjoint cases. With absent leading sign, the first input byte is the first byte of B, hence is neither 43 nor 45, and the parser keeps the whole slice. With leading plus or minus, the first byte is 43 or 45 respectively and the parser drops exactly that one byte. The drop is in bounds since the head observation already showed at least one input byte. In every case its resulting slice b has contents B, and the Boolean \nu testing the original first byte for 45 equals the lexical negative Boolean of x. By the source-string length clause of DecimalGoalVocabularyDefault, the retained slice has length at most 2^{63}-1, so it satisfies SourceValidByteSlice. The reached sign-only test cannot produce success, since that branch returns Rust Err.
The model calls parse_number before the special helper. If its normal result were None, the next reached call would be the special helper on b with sign \nu. This body is neither special keyword: its first byte is 46 or in [48,57], whereas the unsigned case-insensitive infinity spellings start with 105 or 73 and the NaN spelling with 110 or 78. These alternatives are incompatible with the first-byte case relation in DecimalGoalVocabularyDefault. Thus both special-literal predicates are false on the complete body. Apply SpecialHelperRejection to the source-valid b with separate sign \nu. The special helper returns None, so the reached branch returns Rust Err, again contradicting success. Consequently the numeric helper returns Some r normally.
Let x_0 be x with only its leading sign replaced by absent sign. The validity predicate does not inspect that field, so x_0 is valid; its rendering is exactly B, and its integer and fractional digits are unchanged and all zero. Apply UnsignedZeroRecord to b,x_0,r and the actual normal Some result. It gives r.\mathit{mantissa}=0, r.\mathit{many\_digits}=\texttt{false}, and r.\mathit{negative}=\texttt{false} over the entire source-length domain. In particular, this application has no A or B length premise.
The native input in the extracted trace is r with negative field \nu; its other three fields are unchanged. If the reached native result is Some f, NativeCorrectOrDefer, for this exact record and successful result, concludes that some magnitude word m rounds its real record magnitude and that f is its sign application. The record magnitude is 0\cdot10^{r.\mathit{exponent}}=0 for every stored exponent. By ZeroRounding, the raw zero word also rounds zero, and RoundingDeterminism applied to the nonnegative real zero identifies m with that word. The signed-magnitude equation of DecimalGoalVocabularyDefault now gives f.val=0+(2^{63}\text{ if }\nu\text{ else }0), the desired answer. These rounding and sign facts are conclusions of the native theorem, not a parser invariant or a premise assumed about the returned word.
Otherwise the reached native result is None. The first integer-conversion call has the exact arguments (r.\mathit{exponent},r.\mathit{mantissa})=(r.\mathit{exponent},0). Its normal return is forced by inversion of the successful trace; hence ComputeZeroPair identifies it with (0,0). Now follow the guards in num imp dec2flt dec2flt with trace literally. Because many_digits is false, the second-compute guard is false; there is no mantissa increment, second conversion, comparison, or forced deferral. The post-comparison pair is the first pair (0,0). Its signed biased exponent is zero, so the slow-path guard p<0 is false; the selected pair is still (0,0), with no slow call. The intervening assembled-word calculation is normally returning as forced by the execution premise; it does not change the selected pair. Apply AssemblyCorrespondence to that selected pair and compare its normally returned assembly with the reached assembly result a. The assembly predicate of DecimalGoalVocabularyDefault reduces to
a.val=\operatorname{lor}\left(0, ((0\mathbin{\mathrm{emod}}2^{64}).\mathit{toNat}\,2^{52}) \bmod2^{64}\right)=0.
Thus assembly is the unsigned zero word and in particular is below 2^{63}. With \nu false the trace returns a directly. With \nu true it performs the concrete negation selected by ActualDispatchOperations; Binary64ApplySign applies to this zero magnitude and identifies the successful sign branch with raw value 0+2^{63}. Since \nu is the lexical sign already established, both cases give the stated word. No unrestricted accumulated-rounding theorem or many-digits-positive slow-path theorem is used.

Lean proof


  intro s x f hsource hvalid hrender hzero 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⟩
  obtain ⟨zeroFold, zeroDigits⟩ := P401_T1_ExactZeroSignificand x hzero
  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_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] 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 =>
        have unsignedRender : DecimalGoalVocabularyDefault.renderNumeric
            { x with leadingSign := none } = DecimalGoalVocabularyDefault.bytes body1 := by
          change numericBody = DecimalGoalVocabularyDefault.bytes body1
          rw [hhead, hstrip.2.1]
        obtain ⟨hrzero, hrmany, hrnegative⟩ := P401_T1_UnsignedZeroRecord body1
          { x with leadingSign := none } r hstrip.2.2 rfl hvalid unsignedRender zeroDigits hparsed
        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, _, hround, hsigned⟩
          · simp at hnone
          · cases hvalue
            have hdecimalZero : DecimalGoalVocabularyDefault.decimalMagnitude
                { r with negative := decide (first = 45#u8) } = 0 := by
              dsimp only [DecimalGoalVocabularyDefault]
              rw [hrzero]
              simp
            rw [hdecimalZero] at hround
            have hmzero := RoundingDeterminism 0 magnitude
              (⟨BitVec.ofNat 64 0⟩ : F64) (le_refl 0) hround P401_T1_ZeroRounding
            subst magnitude
            cases traced
            dsimp only [DecimalGoalVocabularyDefault] at hsigned
            have signedVal : f.val = 0 +
                if decide (first = 45#u8) then 2 ^ 63 else 0 := hsigned.2
            simpa only [hstrip.1, Nat.zero_add] using signedVal
        | none =>
          obtain ⟨firstPair, hfirstPair, traced⟩ := bind_ok_inv _ _ _ traced
          have hrword : r.mantissa = 0#u64 := by
            apply UScalar.eq_of_val_eq
            simpa using hrzero
          rw [hrword] at hfirstPair
          have hpair := P401_T1_ComputeZeroPair r.exponent firstPair hfirstPair
          subst firstPair
          have hnotnegative : ¬ (0#i32 : Std.I32) < 0#i32 := by decide
          obtain ⟨phase1, hphase1, traced⟩ := bind_ok_inv _ _ _ traced
          simp only [hrmany, Bool.false_eq_true, if_false] at hphase1
          cases hphase1
          obtain ⟨phase2, hphase2, traced⟩ := bind_ok_inv _ _ _ traced
          simp only [Bool.false_eq_true, if_false] at hphase2
          cases hphase2
          obtain ⟨phase3, hphase3, traced⟩ := bind_ok_inv _ _ _ traced
          simp only [hnotnegative, if_false] at hphase3
          cases hphase3
          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
          obtain ⟨canonical, hcanonical, canonicalSpec⟩ := AssemblyCorrespondence
            { m := 0#u64, p_biased := 0#i32 }
          rw [hassembled] at hcanonical
          cases hcanonical
          have assembledZero : assembled.val = 0 := by
            change assembled.val = Nat.lor 0
              (((0 : Int).emod (2 ^ 64)).toNat * 2 ^ 52 % 2 ^ 64) at canonicalSpec
            exact canonicalSpec
          by_cases negative : first = 45#u8
          · simp only [negative, if_true] at traced
            obtain ⟨result, hresult, traced⟩ := bind_ok_inv _ _ _ traced
            cases traced
            change ModelF64Neg assembled = ok f at hresult
            obtain ⟨signed, hsign, hsigned⟩ := Binary64ApplySign true assembled
              (by rw [assembledZero]; norm_num)
            simp only [if_true, hresult, bind_tc_ok] at hsign
            cases hsign
            have hlexical : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
              rw [← hstrip.1]
              simp [negative]
            dsimp only [DecimalGoalVocabularyDefault] at hsigned
            simpa only [hlexical, if_true, assembledZero, Nat.zero_add] using hsigned.2
          · simp only [negative, if_false] at traced
            cases traced
            have hlexical : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
              rw [← hstrip.1]
              simp [negative]
            simpa only [hlexical, Bool.false_eq_true, if_false] using assembledZero

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.num_imp_dec2flt_dec2flt_with_trace
import Tablet.SourceValidByteSlice
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.SpecialHelperRejection
import Tablet.P401_T1_ExactZeroSignificand
import Tablet.P401_T1_UnsignedZeroRecord
import Tablet.P401_T1_ZeroRounding
import Tablet.P401_T1_ComputeZeroPair
import Tablet.P13_T1_NativeCorrectOrDefer
import Tablet.RoundingDeterminism
import Tablet.AssemblyCorrespondence
import Tablet.Binary64ApplySign

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P13_T1_ParserSignedZero]
theorem P13_T1_ParserSignedZero :
    forall (s : Str) (x : DecimalLexeme) (f : F64),
      DecimalGoalVocabularyDefault.sourceString s ->
      DecimalGoalVocabularyDefault.validNumeric x ->
      DecimalGoalVocabularyDefault.renderNumeric x = DecimalGoalVocabularyDefault.bytes s ->
      DecimalGoalVocabularyDefault.exactMagnitude x = 0 ->
      num.imp.dec2flt.dec2flt F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s = ok (core.result.Result.Ok f) ->
      f.val = if DecimalGoalVocabularyDefault.lexicalNegative x then 2 ^ 63 else 0 := by
-- BODY
  intro s x f hsource hvalid hrender hzero 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⟩
  obtain ⟨zeroFold, zeroDigits⟩ := P401_T1_ExactZeroSignificand x hzero
  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_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] 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 =>
        have unsignedRender : DecimalGoalVocabularyDefault.renderNumeric
            { x with leadingSign := none } = DecimalGoalVocabularyDefault.bytes body1 := by
          change numericBody = DecimalGoalVocabularyDefault.bytes body1
          rw [hhead, hstrip.2.1]
        obtain ⟨hrzero, hrmany, hrnegative⟩ := P401_T1_UnsignedZeroRecord body1
          { x with leadingSign := none } r hstrip.2.2 rfl hvalid unsignedRender zeroDigits hparsed
        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, _, hround, hsigned⟩
          · simp at hnone
          · cases hvalue
            have hdecimalZero : DecimalGoalVocabularyDefault.decimalMagnitude
                { r with negative := decide (first = 45#u8) } = 0 := by
              dsimp only [DecimalGoalVocabularyDefault]
              rw [hrzero]
              simp
            rw [hdecimalZero] at hround
            have hmzero := RoundingDeterminism 0 magnitude
              (⟨BitVec.ofNat 64 0⟩ : F64) (le_refl 0) hround P401_T1_ZeroRounding
            subst magnitude
            cases traced
            dsimp only [DecimalGoalVocabularyDefault] at hsigned
            have signedVal : f.val = 0 +
                if decide (first = 45#u8) then 2 ^ 63 else 0 := hsigned.2
            simpa only [hstrip.1, Nat.zero_add] using signedVal
        | none =>
          obtain ⟨firstPair, hfirstPair, traced⟩ := bind_ok_inv _ _ _ traced
          have hrword : r.mantissa = 0#u64 := by
            apply UScalar.eq_of_val_eq
            simpa using hrzero
          rw [hrword] at hfirstPair
          have hpair := P401_T1_ComputeZeroPair r.exponent firstPair hfirstPair
          subst firstPair
          have hnotnegative : ¬ (0#i32 : Std.I32) < 0#i32 := by decide
          obtain ⟨phase1, hphase1, traced⟩ := bind_ok_inv _ _ _ traced
          simp only [hrmany, Bool.false_eq_true, if_false] at hphase1
          cases hphase1
          obtain ⟨phase2, hphase2, traced⟩ := bind_ok_inv _ _ _ traced
          simp only [Bool.false_eq_true, if_false] at hphase2
          cases hphase2
          obtain ⟨phase3, hphase3, traced⟩ := bind_ok_inv _ _ _ traced
          simp only [hnotnegative, if_false] at hphase3
          cases hphase3
          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
          obtain ⟨canonical, hcanonical, canonicalSpec⟩ := AssemblyCorrespondence
            { m := 0#u64, p_biased := 0#i32 }
          rw [hassembled] at hcanonical
          cases hcanonical
          have assembledZero : assembled.val = 0 := by
            change assembled.val = Nat.lor 0
              (((0 : Int).emod (2 ^ 64)).toNat * 2 ^ 52 % 2 ^ 64) at canonicalSpec
            exact canonicalSpec
          by_cases negative : first = 45#u8
          · simp only [negative, if_true] at traced
            obtain ⟨result, hresult, traced⟩ := bind_ok_inv _ _ _ traced
            cases traced
            change ModelF64Neg assembled = ok f at hresult
            obtain ⟨signed, hsign, hsigned⟩ := Binary64ApplySign true assembled
              (by rw [assembledZero]; norm_num)
            simp only [if_true, hresult, bind_tc_ok] at hsign
            cases hsign
            have hlexical : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
              rw [← hstrip.1]
              simp [negative]
            dsimp only [DecimalGoalVocabularyDefault] at hsigned
            simpa only [hlexical, if_true, assembledZero, Nat.zero_add] using hsigned.2
          · simp only [negative, if_false] at traced
            cases traced
            have hlexical : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
              rw [← hstrip.1]
              simp [negative]
            simpa only [hlexical, Bool.false_eq_true, if_false] using assembledZero

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 184 entries
Technical checking records
Local closure summary
{
  "node": "P13_T1_ParserSignedZero",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "378337ae82312ba5a5f714403ba2de2b974668c7d102d02def71dd065ef851ec",
  "active_statement_hash": "dcace059f19d8de16c7207dafde94ba8e5a528debce98bbd22f8940866dee5ae",
  "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",
    "P401_T1_ComputeZeroPair": "03467f615e0c7324",
    "P401_T1_ExactZeroSignificand": "a72feccdedf9c943",
    "P401_T1_UnsignedZeroRecord": "65a799b64ae093aa",
    "P401_T1_ZeroRounding": "1e8cf14ea5c2868a",
    "RoundingDeterminism": "6500074d31847e13",
    "SpecialHelperRejection": "87bf7c2abde897a2",
    "num_imp_dec2flt_dec2flt_with_trace": "d2b4145772dccc04",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "c08dd4b4aea4abb4",
    "DecimalGoalVocabularyDefault": "3016c00221d29252",
    "DecimalLexeme": "303e59678842cea4",
    "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",
    "ModelStrAsBytes": "024fe35b4dbfa9a3",
    "P401_T1_ExactZeroSignificand": "55eb6bce0e8a4131",
    "Preamble": "7a79218b23bce03e",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "core_ops_arith_Neg": "0ff07135a60bcbf9",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "7bda5de02611ad76",
    "num_imp_dec2flt_Dec2FltTrace": "8fa376ebb5c489ee",
    "num_imp_dec2flt_Lemire": "1923f90c53d323e6",
    "num_imp_dec2flt_biased_fp_to_float": "acdde060e8d35ca7",
    "num_imp_dec2flt_common_BiasedFp": "5c88d5d7976c5e8f",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_dec2flt": "f9f7d93449a25efa",
    "num_imp_dec2flt_dec2flt_with_trace": "ebe6a57c6dce0df6",
    "num_imp_dec2flt_decimal_Decimal": "fe99f3f976739f2d",
    "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:00dc6e30b6f09e89ad44cce485a820e1bdccc5e76c39bb3d2c26a932a6f20937",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}