P616_T1_FrameNormality

Lean checked

Statement

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

Lemma · Normal fixed-frame output for every compatible package

For every total abstract package C satisfying DispatchContracts and every source-valid Rust string s of complete byte length at most A=3458764513820540928, there exist a Rust parsing result r and a trace \tau such that \mathrm{P9\_T1\_DispatchFrame}(\mathrm{P9\_T1\_EmbedComponents}(C),s) =\mathrm{ok}(r,\tau). A Rust Err is a normal result; outer failure or divergence is not. The theorem does not require any actual conversion call to return normally.

Lean statement

Trellis authored these statements and proofs. Lean checks the formal proofs; the assumptions used by each proof are listed below.

import Tablet.DispatchContracts
import Tablet.P9_T1_DispatchFrame
import Tablet.P9_T1_EmbedComponents
import Tablet.P616_T1_SignStrippedClassification
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.ModelF64MantissaDigits
import Tablet.ModelU64Shl
import Tablet.ModelU64BitOr
import Tablet.num_imp_dec2flt_pfe_empty
import Tablet.num_imp_dec2flt_pfe_invalid
import Tablet.num_imp_traits_Float_SIG_BITS_default
import Tablet.num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq
import Tablet.ParserExponentConstants

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_FrameNormality]
theorem P616_T1_FrameNormality :
    forall C : P9_T1_AbstractComponents, DispatchContracts C ->
      forall s : Str, DecimalGoalVocabularyDefault.sourceString s ->
      s.val.length <= 3458764513820540928 ->
      exists r trace, P9_T1_DispatchFrame (P9_T1_EmbedComponents C) s = ok (r, trace) := 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 C, its compatible laws, and s. Evaluate the source-ordered definition DispatchFrame. All seven embedded component operations in EmbedComponents return ok of their total abstract value; this accounts for those binds but not yet for the fixed primitive binds, which we check explicitly below.
The string-to-byte binding ModelStrAsBytes returns ok of s, and ModelSliceFirst returns ok of its optional head. If there is no head, the list is empty. num imp dec2flt pfe empty is ok of the Empty error constructor; the resulting pair is Rust Err of that error and the EmptyInput trace. No subsequent operation is executed in this branch.
If the first byte is c, the list is nonempty. When c=45 or c=43 the frame indexes the range starting at 1; otherwise it retains the whole slice. For a sign case, the range index's required check is 1\leq|s|, true from the head. The accepted width premise in Assumptions gives Usize width 64, so the index literal one is in range and the slice length is its exact natural length. The installed Aeneas range-index primitive returns the tail slice with those exact bytes, of length |s|-1, with no element read beyond the boundary. Thus every case supplies a normal body b satisfying the exact list equation of SignStrippedClassification. Its first two conclusions give source validity and |b|\leq|s|\leq A. The slice-empty primitive is the Boolean comparison of that list length with zero and has a normal return. If it is empty, num imp dec2flt pfe invalid returns ok of the Invalid error, and the frame returns Rust Err and SignOnly(b,c=45).
Suppose henceforth that b is nonempty. The embedded numeric call returns ok of C.\mathrm{parseNumber}(b). If it is None, the embedded special call returns ok of its optional value with sign c=45. Its None case uses the normal Invalid error constructor and produces the Invalid trace, with both options None; its Some case produces Rust Ok of that word and the Special trace containing the same body, sign, None numeric option and returned special option. Both cases are normal.
If the numeric value is Some d, the full-domain record_bounds law in DispatchContracts applies to the already proved source-valid nonempty body. It gives d.\mathit{negative}=\mathrm{false} and d.\mathit{mantissa}.\mathit{val}<10^{19}, with no grammar premise. The embedded native call on d with its sign overwritten to c=45 returns normally. A Some native value gives Rust Ok and the FastPath trace directly, without assembly or final negation. For native None, the first embedded integer call gives a normal pair f_1=C.\mathrm{integer}(d.\mathit{exponent},d.\mathit{mantissa}). The following Boolean tests and tuple constructions are total: the second-call guard is exactly many_digits and f_1.p_{\rm biased}\geq0.
Only when this guard is true does the frame add one to the U64 mantissa. Its normality obligation is an upper bound, not merely an abstract endpoint law. From d.\mathit{mantissa}.\mathit{val}<10^{19}, natural discreteness gives its successor at most 10^{19}, and
10^{19}=10000000000000000000 <18446744073709551616=2^{64}.
Hence checked U64 addition succeeds and has exactly the mathematical successor value. The second embedded integer call is normal. num imp dec2flt common BiasedFp Insts CoreCmpPartialEqBiasedFp eq compares first the mantissa fields and then the biased exponent fields, and always returns ok of their exact equality Boolean. If equal the post-comparison pair is f_1 and forced_deferral is false; otherwise it is f_1 with exponent replaced by -1 and forced_deferral true. The I32 literal -1 is within [-2^{31},2^{31}-1]. The returned optional second operands and result and equality Boolean are all Some of these actual abstract values. With guard false, the tuple keeps f_1, sets all four second-call observations to None and forced_deferral to false. There is no unexecuted successor in that case.
The post-comparison negative-exponent test is total. When it is true, the embedded slow call on the unchanged b returns a normal replacement; the selected pair is that replacement, the slow guard is true, and the slow result option is Some of it. Otherwise the selected pair is the post-comparison pair, with false slow guard and None slow option. Neither branch needs a range bound on the selected pair's I32 exponent.
For every selected pair, the I32-to-U64 hcast in the next bind is a total bitvector reinterpretation with natural value p_{\rm biased}.\mathit{val}\bmod2^{64}, using the nonnegative Euclidean remainder and its natural embedding. The SIG_BITS constant is obtained from num imp traits Float SIG BITS default: its input SIG_TOTAL_BITS is the normal value 53 in ModelF64MantissaDigits. Subtracting one is checked in U32 and succeeds since 1\leq53<2^{32}, giving 52. The left-shift bind underlying ModelU64Shl therefore has count 52<64 and returns its bounded 64-bit word even if high bits are discarded; left shift is not checked arithmetic multiplication. Bitwise OR, as in ModelU64BitOr, is total and returns the assembled raw word. The embedded assembly call also returns normally. If c=45, the embedded negation returns normally; otherwise no negation is executed. These are all remaining binds.
In either final sign case the frame constructs Rust Ok and its Assembled trace using the computed values. The two temporary many_digits Booleans both equal d.\mathit{many\_digits}, so the recorded numeric option and signed native input retain that flag. The trace's first operands, first result, guard, optional second observations, equality, forced-deferral flag, post-comparison pair, slow observations, selected pair, raw word, assembly result, sign-applied flag and final word are exactly the tuple values just evaluated. Tuple and trace constructors introduce no failure. Successive substitution of these normal equations through the Result binds yields ok of the constructed result and trace. Every branch of the option and Boolean cases has been covered, proving output existence for the arbitrary compatible package.

Lean proof


  intro C hC s hs hlen
  have hcastOK (p : num.imp.dec2flt.common.BiasedFp) :
      lift (IScalar.hcast .U64 p.p_biased) = ok (IScalar.hcast .U64 p.p_biased) := by
    simp [lift, IScalar.hcast]
  have hshiftOK (i : Std.U64) : ∃ y, i <<< 52#u32 = ok y := by
    simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_UScalar, UScalar.shiftLeft]
    exact ⟨_, rfl⟩
  have hshiftEq (i : Std.U64) :
      i <<< 52#u32 = ok ⟨i.bv.shiftLeft 52⟩ := by
    simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_UScalar, UScalar.shiftLeft]
    rfl
  have hbitOr (x y : Std.U64) : lift (x ||| y) = ok (x ||| y) := by
    simp [lift]
  have hsub53 : 53#u32 - 1#u32 = ok 52#u32 := by
    rfl
  obtain ⟨_, htotal53, hsig52, _, _, _, _, _, _, _, _, _⟩ := ParserExponentConstants
  have hsigSub :
      (do let x ← F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS
          x - 1#u32) = ok 52#u32 := by
    simp only [Bind.bind, Aeneas.Std.bind]
    cases h : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS with
    | ok x =>
        have hx : x = 53#u32 := by
          have e := htotal53.symm.trans h
          injection e with hxx
          exact hxx.symm
        subst x
        rfl
    | fail e => simp [h] at htotal53
    | div => simp [h] at htotal53
  rcases s with ⟨xs, hxs⟩
  cases xs with
  | nil =>
    simp [P9_T1_DispatchFrame, P9_T1_EmbedComponents,
      core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
      ModelSliceFirst, num.imp.dec2flt.pfe_empty]
  | cons c tail =>
    by_cases hminus : c = 45#u8
    · subst c
      simp only [P9_T1_DispatchFrame, P9_T1_EmbedComponents,
        core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
        ModelSliceFirst, core.slice.Slice.is_empty, Slice.length,
        Slice.index_SliceIndexRangeFromUsizeSliceInst,
        core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
        num.imp.dec2flt.pfe_invalid]
      have htailbound : tail.length ≤ Usize.max := by
        have h := hxs
        simp only [List.length_cons] at h
        omega
      let body : Slice Std.U8 := ⟨tail, htailbound⟩
      by_cases htail : tail = []
      · simp [htail]
      · cases hn : C.parseNumber body with
        | none =>
          cases hsp : C.parseSpecial body true <;> simp [body, htail, hn, hsp]
        | some d =>
          cases hnat : C.native { d with negative := true } with
          | some value => simp [body, htail, hn, hnat]
          | none =>
            have hlen' : tail.length ≤ 3458764513820540928 := by
              simp only [List.length_cons] at hlen
              omega
            have hvalid : SourceValidByteSlice body := by
              unfold SourceValidByteSlice
              change tail.length ≤ 9223372036854775807
              exact Nat.le_trans hlen' (by norm_num)
            have hne : body.val ≠ [] := by simp [body, htail]
            have hrecord := hC.record_bounds body d hvalid hne hn
            have haddBound : d.mantissa.val + 1 ≤ U64.max := by
              rw [U64.max_eq]
              omega
            have hadd := UScalar.add_spec (x := d.mantissa) (y := 1#u64) (by
              simpa using haddBound)
            obtain ⟨next, hadd, hnext⟩ := Aeneas.Std.WP.spec_imp_exists hadd
            cases htot : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS with
            | ok sig =>
              have hsigVal : sig = 53#u32 := by
                have e := htotal53.symm.trans htot
                injection e with he
                exact he.symm
              subst sig
              by_cases hmany : d.many_digits = true
              · have hnatMany : C.native { d with negative := true, many_digits := true } = none := by
                  simpa [hmany] using hnat
                by_cases hp : ((C.integer d.exponent d.mantissa).p_biased : Int) ≥ 0
                · simp [body, htail, hn, hnatMany, hadd, hmany, hp, htotal53, hsig52, hsub53,
                    num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                    simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind]
                  by_cases hmEq : (C.integer d.exponent d.mantissa).m =
                    (C.integer d.exponent next).m
                  · by_cases hpEq : (C.integer d.exponent d.mantissa).p_biased =
                      (C.integer d.exponent next).p_biased
                    · have hpEqInt : (↑(C.integer d.exponent d.mantissa).p_biased : Int) =
                        (↑(C.integer d.exponent next).p_biased : Int) :=
                          congrArg IScalar.val hpEq
                      have hnotneg : ¬ ((C.integer d.exponent next).p_biased : Int) < 0 := by
                        rw [← hpEqInt]
                        omega
                      simp [hmEq, hpEq, hpEqInt, hp, hnotneg]
                    · simp [hmEq, hpEq, hp]
                  · simp [hmEq, hp]
                · have hpNeg : ((C.integer d.exponent d.mantissa).p_biased : Int) < 0 := by omega
                  simp [body, htail, hn, hnatMany, hadd, hmany, hp, hpNeg,
                    htotal53, hsig52, hsub53,
                    num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                    simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                    simp
              · have hmany' : d.many_digits = false := Bool.eq_false_of_not_eq_true hmany
                have hnatFew : C.native { d with negative := true, many_digits := false } = none := by
                  simpa [hmany'] using hnat
                simp [body, htail, hn, hnatFew, hmany', hsig52, hsub53] <;>
                  simp only [hnatFew, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                  split_ifs <;> simp only [Bind.bind, Aeneas.Std.bind] <;> simp
            | fail e => simp [htot] at htotal53
            | div => simp [htot] at htotal53
    · by_cases hplus : c = 43#u8
      · subst c
        simp only [P9_T1_DispatchFrame, P9_T1_EmbedComponents,
          core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
          ModelSliceFirst, core.slice.Slice.is_empty, Slice.length,
          Slice.index_SliceIndexRangeFromUsizeSliceInst,
          core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
          num.imp.dec2flt.pfe_invalid]
        have htailbound : tail.length ≤ Usize.max := by
          have h := hxs
          simp only [List.length_cons] at h
          omega
        let body : Slice Std.U8 := ⟨tail, htailbound⟩
        by_cases htail : tail = []
        · simp [htail]
        · cases hn : C.parseNumber body with
          | none =>
            cases hsp : C.parseSpecial body false <;> simp [body, htail, hn, hsp]
          | some d =>
            cases hnat : C.native { d with negative := false } with
            | some value => simp [body, htail, hn, hnat]
            | none =>
              have hlen' : tail.length ≤ 3458764513820540928 := by
                simp only [List.length_cons] at hlen
                omega
              have hvalid : SourceValidByteSlice body := by
                unfold SourceValidByteSlice
                simp [body]
                omega
              have hne : body.val ≠ [] := by simp [body, htail]
              have hrecord := hC.record_bounds body d hvalid hne hn
              have haddBound : d.mantissa.val + 1 ≤ U64.max := by
                rw [U64.max_eq]
                omega
              have hadd := UScalar.add_spec (x := d.mantissa) (y := 1#u64) (by
                simpa using haddBound)
              obtain ⟨next, hadd, hnext⟩ := Aeneas.Std.WP.spec_imp_exists hadd
              cases htot : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS with
              | ok sig =>
                have hsigVal : sig = 53#u32 := by
                  have e := htotal53.symm.trans htot
                  injection e with he
                  exact he.symm
                subst sig
                by_cases hmany : d.many_digits = true
                · have hnatMany : C.native { d with negative := false, many_digits := true } = none := by
                    simpa [hmany] using hnat
                  by_cases hp : ((C.integer d.exponent d.mantissa).p_biased : Int) ≥ 0
                  · simp [body, htail, hn, hnatMany, hadd, hmany, hp, htotal53, hsig52, hsub53,
                      num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                      simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind]
                    by_cases hmEq : (C.integer d.exponent d.mantissa).m =
                      (C.integer d.exponent next).m
                    · by_cases hpEq : (C.integer d.exponent d.mantissa).p_biased =
                        (C.integer d.exponent next).p_biased
                      · have hpEqInt : (↑(C.integer d.exponent d.mantissa).p_biased : Int) =
                          (↑(C.integer d.exponent next).p_biased : Int) :=
                            congrArg IScalar.val hpEq
                        have hnotneg : ¬ ((C.integer d.exponent next).p_biased : Int) < 0 := by
                          rw [← hpEqInt]
                          omega
                        simp [hmEq, hpEq, hpEqInt, hp, hnotneg]
                      · simp [hmEq, hpEq, hp]
                    · simp [hmEq, hp]
                  · have hpNeg : ((C.integer d.exponent d.mantissa).p_biased : Int) < 0 := by omega
                    simp [body, htail, hn, hnatMany, hadd, hmany, hp, hpNeg,
                      htotal53, hsig52, hsub53,
                      num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                      simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                      simp
                · have hmany' : d.many_digits = false := Bool.eq_false_of_not_eq_true hmany
                  have hnatFew : C.native { d with negative := false, many_digits := false } = none := by
                    simpa [hmany'] using hnat
                  simp [body, htail, hn, hnatFew, hmany', hsig52, hsub53] <;>
                    simp only [hnatFew, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                    split_ifs <;> simp only [Bind.bind, Aeneas.Std.bind] <;> simp
              | fail e => simp [htot] at htotal53
              | div => simp [htot] at htotal53
      · simp [P9_T1_DispatchFrame, P9_T1_EmbedComponents,
          core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
          ModelSliceFirst, core.slice.Slice.is_empty, Slice.length,
          core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
          hminus, hplus, num.imp.dec2flt.pfe_invalid]
        let body : Slice Std.U8 := ⟨c :: tail, hxs⟩
        cases hn : C.parseNumber body with
        | none =>
          cases hsp : C.parseSpecial body false <;> simp [body, hn, hsp]
        | some d =>
          cases hnat : C.native { d with negative := false } with
          | some value => simp [body, hn, hnat]
          | none =>
            have hlen' : (c :: tail).length ≤ 3458764513820540928 := by
              simp only [List.length_cons] at hlen
              omega
            have hvalid : SourceValidByteSlice body := by
              unfold SourceValidByteSlice
              change (c :: tail).length ≤ 9223372036854775807
              exact Nat.le_trans hlen' (by norm_num)
            have hne : body.val ≠ [] := by simp [body]
            have hrecord := hC.record_bounds body d hvalid hne hn
            have haddBound : d.mantissa.val + 1 ≤ U64.max := by
              rw [U64.max_eq]
              omega
            have hadd := UScalar.add_spec (x := d.mantissa) (y := 1#u64) (by
              simpa using haddBound)
            obtain ⟨next, hadd, hnext⟩ := Aeneas.Std.WP.spec_imp_exists hadd
            cases htot : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS with
            | ok sig =>
              have hsigVal : sig = 53#u32 := by
                have e := htotal53.symm.trans htot
                injection e with he
                exact he.symm
              subst sig
              by_cases hmany : d.many_digits = true
              · have hnatMany : C.native { d with negative := false, many_digits := true } = none := by
                  simpa [hmany] using hnat
                by_cases hp : ((C.integer d.exponent d.mantissa).p_biased : Int) ≥ 0
                · simp [body, hn, hnatMany, hadd, hmany, hp, htotal53, hsig52, hsub53,
                    num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                    simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind]
                  by_cases hmEq : (C.integer d.exponent d.mantissa).m =
                    (C.integer d.exponent next).m
                  · by_cases hpEq : (C.integer d.exponent d.mantissa).p_biased =
                      (C.integer d.exponent next).p_biased
                    · have hpEqInt : (↑(C.integer d.exponent d.mantissa).p_biased : Int) =
                        (↑(C.integer d.exponent next).p_biased : Int) :=
                          congrArg IScalar.val hpEq
                      have hnotneg : ¬ ((C.integer d.exponent next).p_biased : Int) < 0 := by
                        rw [← hpEqInt]
                        omega
                      simp [hmEq, hpEq, hpEqInt, hp, hnotneg]
                    · simp [hmEq, hpEq, hp]
                  · simp [hmEq, hp] <;> simp_all
                · have hpNeg : ((C.integer d.exponent d.mantissa).p_biased : Int) < 0 := by omega
                  simp [body, hn, hnatMany, hadd, hmany, hp, hpNeg,
                    htotal53, hsig52, hsub53,
                    num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                    simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                    simp
              · have hmany' : d.many_digits = false := Bool.eq_false_of_not_eq_true hmany
                have hnatFew : C.native { d with negative := false, many_digits := false } = none := by
                  simpa [hmany'] using hnat
                simp [body, hn, hnatFew, hmany', hsig52, hsub53] <;>
                  simp only [hnatFew, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                  split_ifs <;> simp only [Bind.bind, Aeneas.Std.bind] <;> simp
            | fail e => simp [htot] at htotal53
            | div => simp [htot] at htotal53
end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DispatchContracts
import Tablet.P9_T1_DispatchFrame
import Tablet.P9_T1_EmbedComponents
import Tablet.P616_T1_SignStrippedClassification
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.ModelF64MantissaDigits
import Tablet.ModelU64Shl
import Tablet.ModelU64BitOr
import Tablet.num_imp_dec2flt_pfe_empty
import Tablet.num_imp_dec2flt_pfe_invalid
import Tablet.num_imp_traits_Float_SIG_BITS_default
import Tablet.num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq
import Tablet.ParserExponentConstants

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_FrameNormality]
theorem P616_T1_FrameNormality :
    forall C : P9_T1_AbstractComponents, DispatchContracts C ->
      forall s : Str, DecimalGoalVocabularyDefault.sourceString s ->
      s.val.length <= 3458764513820540928 ->
      exists r trace, P9_T1_DispatchFrame (P9_T1_EmbedComponents C) s = ok (r, trace) := by
-- BODY
  intro C hC s hs hlen
  have hcastOK (p : num.imp.dec2flt.common.BiasedFp) :
      lift (IScalar.hcast .U64 p.p_biased) = ok (IScalar.hcast .U64 p.p_biased) := by
    simp [lift, IScalar.hcast]
  have hshiftOK (i : Std.U64) : ∃ y, i <<< 52#u32 = ok y := by
    simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_UScalar, UScalar.shiftLeft]
    exact ⟨_, rfl⟩
  have hshiftEq (i : Std.U64) :
      i <<< 52#u32 = ok ⟨i.bv.shiftLeft 52⟩ := by
    simp only [HShiftLeft.hShiftLeft, UScalar.shiftLeft_UScalar, UScalar.shiftLeft]
    rfl
  have hbitOr (x y : Std.U64) : lift (x ||| y) = ok (x ||| y) := by
    simp [lift]
  have hsub53 : 53#u32 - 1#u32 = ok 52#u32 := by
    rfl
  obtain ⟨_, htotal53, hsig52, _, _, _, _, _, _, _, _, _⟩ := ParserExponentConstants
  have hsigSub :
      (do let x ← F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS
          x - 1#u32) = ok 52#u32 := by
    simp only [Bind.bind, Aeneas.Std.bind]
    cases h : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS with
    | ok x =>
        have hx : x = 53#u32 := by
          have e := htotal53.symm.trans h
          injection e with hxx
          exact hxx.symm
        subst x
        rfl
    | fail e => simp [h] at htotal53
    | div => simp [h] at htotal53
  rcases s with ⟨xs, hxs⟩
  cases xs with
  | nil =>
    simp [P9_T1_DispatchFrame, P9_T1_EmbedComponents,
      core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
      ModelSliceFirst, num.imp.dec2flt.pfe_empty]
  | cons c tail =>
    by_cases hminus : c = 45#u8
    · subst c
      simp only [P9_T1_DispatchFrame, P9_T1_EmbedComponents,
        core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
        ModelSliceFirst, core.slice.Slice.is_empty, Slice.length,
        Slice.index_SliceIndexRangeFromUsizeSliceInst,
        core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
        num.imp.dec2flt.pfe_invalid]
      have htailbound : tail.length ≤ Usize.max := by
        have h := hxs
        simp only [List.length_cons] at h
        omega
      let body : Slice Std.U8 := ⟨tail, htailbound⟩
      by_cases htail : tail = []
      · simp [htail]
      · cases hn : C.parseNumber body with
        | none =>
          cases hsp : C.parseSpecial body true <;> simp [body, htail, hn, hsp]
        | some d =>
          cases hnat : C.native { d with negative := true } with
          | some value => simp [body, htail, hn, hnat]
          | none =>
            have hlen' : tail.length ≤ 3458764513820540928 := by
              simp only [List.length_cons] at hlen
              omega
            have hvalid : SourceValidByteSlice body := by
              unfold SourceValidByteSlice
              change tail.length ≤ 9223372036854775807
              exact Nat.le_trans hlen' (by norm_num)
            have hne : body.val ≠ [] := by simp [body, htail]
            have hrecord := hC.record_bounds body d hvalid hne hn
            have haddBound : d.mantissa.val + 1 ≤ U64.max := by
              rw [U64.max_eq]
              omega
            have hadd := UScalar.add_spec (x := d.mantissa) (y := 1#u64) (by
              simpa using haddBound)
            obtain ⟨next, hadd, hnext⟩ := Aeneas.Std.WP.spec_imp_exists hadd
            cases htot : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS with
            | ok sig =>
              have hsigVal : sig = 53#u32 := by
                have e := htotal53.symm.trans htot
                injection e with he
                exact he.symm
              subst sig
              by_cases hmany : d.many_digits = true
              · have hnatMany : C.native { d with negative := true, many_digits := true } = none := by
                  simpa [hmany] using hnat
                by_cases hp : ((C.integer d.exponent d.mantissa).p_biased : Int) ≥ 0
                · simp [body, htail, hn, hnatMany, hadd, hmany, hp, htotal53, hsig52, hsub53,
                    num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                    simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind]
                  by_cases hmEq : (C.integer d.exponent d.mantissa).m =
                    (C.integer d.exponent next).m
                  · by_cases hpEq : (C.integer d.exponent d.mantissa).p_biased =
                      (C.integer d.exponent next).p_biased
                    · have hpEqInt : (↑(C.integer d.exponent d.mantissa).p_biased : Int) =
                        (↑(C.integer d.exponent next).p_biased : Int) :=
                          congrArg IScalar.val hpEq
                      have hnotneg : ¬ ((C.integer d.exponent next).p_biased : Int) < 0 := by
                        rw [← hpEqInt]
                        omega
                      simp [hmEq, hpEq, hpEqInt, hp, hnotneg]
                    · simp [hmEq, hpEq, hp]
                  · simp [hmEq, hp]
                · have hpNeg : ((C.integer d.exponent d.mantissa).p_biased : Int) < 0 := by omega
                  simp [body, htail, hn, hnatMany, hadd, hmany, hp, hpNeg,
                    htotal53, hsig52, hsub53,
                    num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                    simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                    simp
              · have hmany' : d.many_digits = false := Bool.eq_false_of_not_eq_true hmany
                have hnatFew : C.native { d with negative := true, many_digits := false } = none := by
                  simpa [hmany'] using hnat
                simp [body, htail, hn, hnatFew, hmany', hsig52, hsub53] <;>
                  simp only [hnatFew, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                  split_ifs <;> simp only [Bind.bind, Aeneas.Std.bind] <;> simp
            | fail e => simp [htot] at htotal53
            | div => simp [htot] at htotal53
    · by_cases hplus : c = 43#u8
      · subst c
        simp only [P9_T1_DispatchFrame, P9_T1_EmbedComponents,
          core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
          ModelSliceFirst, core.slice.Slice.is_empty, Slice.length,
          Slice.index_SliceIndexRangeFromUsizeSliceInst,
          core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
          num.imp.dec2flt.pfe_invalid]
        have htailbound : tail.length ≤ Usize.max := by
          have h := hxs
          simp only [List.length_cons] at h
          omega
        let body : Slice Std.U8 := ⟨tail, htailbound⟩
        by_cases htail : tail = []
        · simp [htail]
        · cases hn : C.parseNumber body with
          | none =>
            cases hsp : C.parseSpecial body false <;> simp [body, htail, hn, hsp]
          | some d =>
            cases hnat : C.native { d with negative := false } with
            | some value => simp [body, htail, hn, hnat]
            | none =>
              have hlen' : tail.length ≤ 3458764513820540928 := by
                simp only [List.length_cons] at hlen
                omega
              have hvalid : SourceValidByteSlice body := by
                unfold SourceValidByteSlice
                simp [body]
                omega
              have hne : body.val ≠ [] := by simp [body, htail]
              have hrecord := hC.record_bounds body d hvalid hne hn
              have haddBound : d.mantissa.val + 1 ≤ U64.max := by
                rw [U64.max_eq]
                omega
              have hadd := UScalar.add_spec (x := d.mantissa) (y := 1#u64) (by
                simpa using haddBound)
              obtain ⟨next, hadd, hnext⟩ := Aeneas.Std.WP.spec_imp_exists hadd
              cases htot : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS with
              | ok sig =>
                have hsigVal : sig = 53#u32 := by
                  have e := htotal53.symm.trans htot
                  injection e with he
                  exact he.symm
                subst sig
                by_cases hmany : d.many_digits = true
                · have hnatMany : C.native { d with negative := false, many_digits := true } = none := by
                    simpa [hmany] using hnat
                  by_cases hp : ((C.integer d.exponent d.mantissa).p_biased : Int) ≥ 0
                  · simp [body, htail, hn, hnatMany, hadd, hmany, hp, htotal53, hsig52, hsub53,
                      num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                      simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind]
                    by_cases hmEq : (C.integer d.exponent d.mantissa).m =
                      (C.integer d.exponent next).m
                    · by_cases hpEq : (C.integer d.exponent d.mantissa).p_biased =
                        (C.integer d.exponent next).p_biased
                      · have hpEqInt : (↑(C.integer d.exponent d.mantissa).p_biased : Int) =
                          (↑(C.integer d.exponent next).p_biased : Int) :=
                            congrArg IScalar.val hpEq
                        have hnotneg : ¬ ((C.integer d.exponent next).p_biased : Int) < 0 := by
                          rw [← hpEqInt]
                          omega
                        simp [hmEq, hpEq, hpEqInt, hp, hnotneg]
                      · simp [hmEq, hpEq, hp]
                    · simp [hmEq, hp]
                  · have hpNeg : ((C.integer d.exponent d.mantissa).p_biased : Int) < 0 := by omega
                    simp [body, htail, hn, hnatMany, hadd, hmany, hp, hpNeg,
                      htotal53, hsig52, hsub53,
                      num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                      simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                      simp
                · have hmany' : d.many_digits = false := Bool.eq_false_of_not_eq_true hmany
                  have hnatFew : C.native { d with negative := false, many_digits := false } = none := by
                    simpa [hmany'] using hnat
                  simp [body, htail, hn, hnatFew, hmany', hsig52, hsub53] <;>
                    simp only [hnatFew, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                    split_ifs <;> simp only [Bind.bind, Aeneas.Std.bind] <;> simp
              | fail e => simp [htot] at htotal53
              | div => simp [htot] at htotal53
      · simp [P9_T1_DispatchFrame, P9_T1_EmbedComponents,
          core.str.Str.as_bytes, ModelStrAsBytes, core.slice.Slice.first,
          ModelSliceFirst, core.slice.Slice.is_empty, Slice.length,
          core.slice.index.SliceIndexRangeFromUsizeSlice.index, Slice.drop,
          hminus, hplus, num.imp.dec2flt.pfe_invalid]
        let body : Slice Std.U8 := ⟨c :: tail, hxs⟩
        cases hn : C.parseNumber body with
        | none =>
          cases hsp : C.parseSpecial body false <;> simp [body, hn, hsp]
        | some d =>
          cases hnat : C.native { d with negative := false } with
          | some value => simp [body, hn, hnat]
          | none =>
            have hlen' : (c :: tail).length ≤ 3458764513820540928 := by
              simp only [List.length_cons] at hlen
              omega
            have hvalid : SourceValidByteSlice body := by
              unfold SourceValidByteSlice
              change (c :: tail).length ≤ 9223372036854775807
              exact Nat.le_trans hlen' (by norm_num)
            have hne : body.val ≠ [] := by simp [body]
            have hrecord := hC.record_bounds body d hvalid hne hn
            have haddBound : d.mantissa.val + 1 ≤ U64.max := by
              rw [U64.max_eq]
              omega
            have hadd := UScalar.add_spec (x := d.mantissa) (y := 1#u64) (by
              simpa using haddBound)
            obtain ⟨next, hadd, hnext⟩ := Aeneas.Std.WP.spec_imp_exists hadd
            cases htot : F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SIG_TOTAL_BITS with
            | ok sig =>
              have hsigVal : sig = 53#u32 := by
                have e := htotal53.symm.trans htot
                injection e with he
                exact he.symm
              subst sig
              by_cases hmany : d.many_digits = true
              · have hnatMany : C.native { d with negative := false, many_digits := true } = none := by
                  simpa [hmany] using hnat
                by_cases hp : ((C.integer d.exponent d.mantissa).p_biased : Int) ≥ 0
                · simp [body, hn, hnatMany, hadd, hmany, hp, htotal53, hsig52, hsub53,
                    num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                    simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind]
                  by_cases hmEq : (C.integer d.exponent d.mantissa).m =
                    (C.integer d.exponent next).m
                  · by_cases hpEq : (C.integer d.exponent d.mantissa).p_biased =
                      (C.integer d.exponent next).p_biased
                    · have hpEqInt : (↑(C.integer d.exponent d.mantissa).p_biased : Int) =
                        (↑(C.integer d.exponent next).p_biased : Int) :=
                          congrArg IScalar.val hpEq
                      have hnotneg : ¬ ((C.integer d.exponent next).p_biased : Int) < 0 := by
                        rw [← hpEqInt]
                        omega
                      simp [hmEq, hpEq, hpEqInt, hp, hnotneg]
                    · simp [hmEq, hpEq, hp]
                  · simp [hmEq, hp] <;> simp_all
                · have hpNeg : ((C.integer d.exponent d.mantissa).p_biased : Int) < 0 := by omega
                  simp [body, hn, hnatMany, hadd, hmany, hp, hpNeg,
                    htotal53, hsig52, hsub53,
                    num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq] <;>
                    simp only [hnatMany, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                    simp
              · have hmany' : d.many_digits = false := Bool.eq_false_of_not_eq_true hmany
                have hnatFew : C.native { d with negative := false, many_digits := false } = none := by
                  simpa [hmany'] using hnat
                simp [body, hn, hnatFew, hmany', hsig52, hsub53] <;>
                  simp only [hnatFew, hcastOK, hshiftEq, hbitOr, Bind.bind, Aeneas.Std.bind] <;>
                  split_ifs <;> simp only [Bind.bind, Aeneas.Std.bind] <;> simp
            | fail e => simp [htot] at htotal53
            | div => simp [htot] at htotal53
end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (198)
More program dependencies (156)
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 102 entries
Technical checking records
Local closure summary
{
  "node": "P616_T1_FrameNormality",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "feb41f9a45612c63003c33b3a562a7318ca457e6d8446355ab4db7e2761cb73d",
  "active_statement_hash": "8f3ff13a8aa8e7fb9f7db59ec1500baed4fe079df38426df3139210564aa98cc",
  "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-181",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DispatchContracts": "b6ed9d0f697e9dae",
    "P9_T1_DispatchFrame": "32d9110750ebf062",
    "ParserExponentConstants": "e2a30a7b0c5e9c91",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "1f42f752b5d22513",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "DispatchContracts": "008abfbd503545bf",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "ModelSliceFirst": "a31394b3c1080f71",
    "ModelStrAsBytes": "024fe35b4dbfa9a3",
    "P9_T1_AbstractComponents": "0a7e8b7bdbce0180",
    "P9_T1_DispatchFrame": "3d36c6a218e86be3",
    "P9_T1_DispatchOperations": "c43614ff2149ecf2",
    "P9_T1_EmbedComponents": "c6037220641c6c08",
    "Preamble": "86dc391ab250c79b",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_float_parse_FloatErrorKind": "20698e72f41a7333",
    "num_float_parse_ParseFloatError": "50fdc93f3a82a17e",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "7bda5de02611ad76",
    "num_imp_dec2flt_Dec2FltTrace": "ef050fc88fd50bb9",
    "num_imp_dec2flt_Lemire": "1923f90c53d323e6",
    "num_imp_dec2flt_common_BiasedFp": "31d81cf1cf22709f",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_decimal_Decimal": "fe99f3f976739f2d",
    "num_imp_dec2flt_pfe_empty": "89046d1da5ac1ce2",
    "num_imp_dec2flt_pfe_invalid": "21db875427d92c6d",
    "num_imp_traits_Float": "94ab5f784cdf5db8",
    "num_imp_traits_FloatExt": "f996e5400649797d"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:faa2e625e85166890130ac62d579f8df465fe5644ccb44a0ea79029261986dd9",
  "current_fingerprint": "sound-v2:faa2e625e85166890130ac62d579f8df465fe5644ccb44a0ea79029261986dd9",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}