P616_T1_FrameCorrectness

Lean checked

Statement

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

Lemma · Generic fixed-frame classification, rounding and sign

For every total abstract package C satisfying DispatchContracts, every source-valid Rust string s of complete byte length at most A=3458764513820540928, and every normal result (r,\tau) of the fixed DispatchFrame using EmbedComponents, the following three assertions hold. Invalid whole-input classification implies r is Rust Err. Every complete special classification (\sigma,\mathit{nan}) implies r is Rust Ok of a NaN if its flag is true, or of infinity with sign \sigma=\mathrm{some\ true} otherwise. Every complete numeric classification x implies r is Rust Ok of a word f, with a magnitude word m rounding the full-significand accumulated-exponent magnitude of x, and f is m with exactly x's lexical sign. No actual component compliance or actual helper normality is assumed. This lemma deliberately leaves ordinary exact transport to the independent B-bounded bridge.

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.P616_T1_RoundingCellConvexity
import Tablet.ClassificationDeterminism
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

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_FrameCorrectness]
theorem P616_T1_FrameCorrectness :
    forall C : P9_T1_AbstractComponents, DispatchContracts C ->
      forall (s : Str) r trace, DecimalGoalVocabularyDefault.sourceString s ->
      s.val.length <= 3458764513820540928 ->
      P9_T1_DispatchFrame (P9_T1_EmbedComponents C) s = ok (r, trace) ->
      ((DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s) none ->
        exists error, r = core.result.Result.Err error) ∧
      (forall sign nan,
        DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
          (some (Sum.inr (sign, nan))) ->
        exists f, r = core.result.Result.Ok f ∧
          (if nan then DecimalGoalVocabularyDefault.isNan f
          else DecimalGoalVocabularyDefault.isInfinity (decide (sign = some true)) f)) ∧
      (forall x : DecimalLexeme,
        DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
          (some (Sum.inl x)) ->
        exists f magnitude, r = core.result.Result.Ok f ∧
          DecimalGoalVocabularyDefault.roundsMagnitude
            (DecimalGoalVocabularyDefault.accumulatedMagnitude x) magnitude ∧
          DecimalGoalVocabularyDefault.signedMagnitude
            (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude f)) := by
Proof

Natural-language proof

The status above describes the Lean proof. Its explanatory prose may remain a sketch after that proof closes.

Explanatory prose status

Prose retained as authored. The explanatory prose is preserved as it stood when captured.

Proof

Fix C, its laws, s, and the normal frame equation. All predicates and values below are those of DecimalGoalVocabularyDefault. Unfold DispatchFrame and its embedding EmbedComponents. Bind inversion of the normal equation identifies the results in its executed branch with the specified abstract values; no claim about actual source success is needed. ModelStrAsBytes returns the identical byte slice and ModelSliceFirst its optional head. An empty input returns the Rust Err and EmptyInput trace given by num imp dec2flt pfe empty. A sign-only input returns Rust Err and SignOnly through num imp dec2flt pfe invalid.
Otherwise let c be the first byte, \nu=(c=45) its Boolean test, and b the nonempty sign-stripped body. On either sign byte the installed range-index primitive starts at one, whose bound follows from the head; it gives the exact tail, and otherwise the body is unchanged. The width is the ratified 64-bit premise in Assumptions. Thus SignStrippedClassification applies, giving source validity of b and |b|\leq|s|\leq A, as well as its forward and reverse classification clauses. Every U8 value is below 256, so ClassificationDeterminism is applicable to the complete byte map. The contract fields used below are explicitly those of DispatchContracts, at these just established domains.
Assume first that the complete input is invalid. If b admitted an unsigned numeric lexeme, the reverse numeric clause of the sign-removal lemma would give a complete numeric classification, contrary to the invalid classification's defining exclusion. Similarly the reverse special clause excludes every unsigned special spelling of b. The contract number_reject, using nonemptiness and the A-bound, forces C.\mathrm{parseNumber}(b)=\mathrm{None}. In that branch the full-domain special_reject law forces C.\mathrm{parseSpecial}(b,\nu)=\mathrm{None}. The frame returns Rust Err of the normal Invalid error and the Invalid trace with these two None observations. The earlier empty and sign-only branches already returned Rust Err, so the invalid assertion holds in all cases.
Assume next a complete special classification (\sigma,\mathit{nan}). Its unsigned body is nonempty and the sign-removal lemma gives its specialLiteral predicate and \nu=\operatorname{decide}(\sigma= \mathrm{some\ true}). No valid unsigned numeric rendering of b can exist: its reverse clause would produce a complete numeric classification, inconsistent with the supplied special one by ClassificationDeterminism. Thus number_reject forces None before any special call. Depending on the NaN Boolean, special_nan or special_infinity supplies Some f with exactly the claimed word predicate at sign \nu. The frame's Special branch returns that same f and records the numeric None and special Some. It executes neither numeric conversion nor a second negation; the separate special sign has already been applied by its law. This proves the special assertion and respects numeric-before-special ordering rather than replacing the two calls by a free classifier.
Finally assume a complete numeric classification x. Let y be x with leading sign removed. The sign-removal lemma gives validity of y, its rendering equal to the bytes of b, equality of both magnitudes, and x's lexical-negative flag equal to \nu. This body is nonempty, so the earlier error branches cannot apply. Contract number_accept gives C.\mathrm{parseNumber}(b)=\mathrm{Some}(d) for some record. Record_bounds gives d.\mathit{negative}=\mathrm{false} and w:=d.\mathit{mantissa}.\mathit{val}<10^{19}. Put q=d.\mathit{exponent}.\mathit{val}, L=w10^q, U=(w+1)10^q, and V=\mathrm{accumulatedMagnitude}(y)=\mathrm{accumulatedMagnitude}(x). Record_accumulated gives V=L when many_digits is false and L\leq V<U otherwise. Since 10^q>0, L\geq0 and L<U.
The native input d' differs from d only by overwriting its negative flag with \nu. Consequently its decimalMagnitude is still L and its many_digits flag is unchanged. If C.\mathrm{native}(d') is Some f, native_normal supplies a magnitude m rounding L, the signedMagnitude(\nu,m,f) predicate, and many_digits false. The latter makes V=L by representation. Substituting this equality gives rounding of V and thus of x's accumulated magnitude. The FastPath branch returns exactly f and records the signed input; there is no further sign operation on this branch. Its supplied sign predicate and the equality of lexical sign prove the numeric assertion.
It remains to treat native None. Write f_1=C.\mathrm{integer}(d.\mathit{exponent},d.\mathit{mantissa}). Integer_normal says either f_1.p_{\rm biased}<0, or C.\mathrm{assemble}(f_1) is a clear-sign rounding of L. The scalar guard f_1.p_{\rm biased}\geq0 is exactly the opposite integer inequality. There are the following exhaustive selections.
If many_digits is false and the first exponent is nonnegative, no second call is executed and f_1 is selected without slow fallback. Its assembled magnitude rounds L=V by the nondeferral alternative. If the first exponent is negative, regardless of many_digits, the second guard is false and the unchanged negative pair reaches slow fallback. Slow_normal applies on the source-valid unsigned numeric b, with no A restriction needed, and says that the assembled slow replacement is a clear-sign rounding of V.
The remaining case has many_digits true and first exponent nonnegative, so the guarded second call is executed. The checked successor is normal and exactly w+1: w<10^{19} implies w+1\leq10^{19}<2^{64}. Thus its endpoint value is precisely U, not a wrapping successor. Let f_2 be the second abstract integer result. The pair comparison num imp dec2flt common BiasedFp Insts CoreCmpPartialEqBiasedFp eq returns true precisely when both fields agree. Pair extensionality then gives f_2=f_1. In this equality case f_2 too has nonnegative exponent, so both integer_normal laws take their nondeferral alternative. The same word m=C.\mathrm{assemble}(f_1)=C.\mathrm{assemble}(f_2) rounds both L and U. Apply RoundingCellConvexity with L\leq V and V<U (hence V\leq U). It gives that m rounds V, including odd/even ties and zero or infinity endpoints. The post-comparison pair remains f_1, forced_deferral is false and there is no slow call. If the comparison is false, the frame overwrites the first exponent with -1. The post-comparison negative test is therefore true, forced_deferral is true and the slow call uses the same b, not a truncated record or a sign-bearing string. Slow_normal again supplies the clear-sign rounding of V for the selected replacement. No value law is required of the unequal endpoint pair itself.
In every assembled case just enumerated, let f_* be the selected pair and m=C.\mathrm{assemble}(f_*). We proved rounding of V and m.\mathit{val}<2^{63} by the integer or slow law. This also follows from the common rounding-word bound m.\mathit{val}\leq 2047\,2^{52}=2^{63}-2^{52}. We impose no exponent-range condition on arbitrary selected pairs. The frame's raw I32-to-U64 cast has natural value (f_*.p_{\rm biased}.\mathit{val}\bmod2^{64}); the SIG_BITS computation num imp traits Float SIG BITS default uses ModelF64MantissaDigits's 53 and checked subtraction of one to give 52. This count is below 64, so the shift underlying ModelU64Shl is the 64-bit modular shift. The OR underlying ModelU64BitOr is total. Consequently the resulting trace raw word has exactly the natural value in assembledWord(f_*,\cdot). Contract assembly_all gives that same formula for m; word extensionality identifies them. The embedded assembly call returns ok of m, as recorded in assembly_result.
If \nu is false, the returned word is f=m, so signedMagnitude holds with no added sign bit. If \nu is true, the embedded negation returns f=C.\mathrm{negate}(m), and negate_all together with m.\mathit{val}<2^{63} gives f.\mathit{val}=m.\mathit{val}+2^{63}. These are exactly both clauses of signedMagnitude(\nu,m,f), including zero and infinity. The sum is below 2^{64}, so this is the full natural word equation. Replace \nu by the lexical-negative flag of x to obtain the stated predicate.
The Assembled trace is built from these same values: its many_digits record updates retain the original flag, its native input has the overwritten sign, its first and guarded second operands and pairs are the ones used above, and its comparison, forced-deferral and slow fields are the selected branch's actual Booleans and options. Its raw and assembly words are equal as proved; its lexical_sign_applied flag is \nu, and its result is the final word just signed. Substitution in the given normal equation and injectivity of ok identify its Rust result r with Ok of this f. Native and special traces likewise retain their direct-return values and select no assembly pair. Thus every possible normal frame output has the three asserted classification, accumulated-rounding and sign properties. No public parser theorem or dispatch-composition theorem was used.

Lean proof


  classical
  intro C hc s r trace hs hA hrun
  have hbytes : ∀ b ∈ DecimalGoalVocabularyDefault.bytes s, b < 256 := by
    intro b hb
    dsimp [DecimalGoalVocabularyDefault] at hb ⊢
    rcases List.mem_map.mp hb with ⟨u, hu, rfl⟩
    exact u.bv.isLt
  have bind_ok_inv : forall {alpha beta : Type} (x : Result alpha)
      (g : alpha -> Result beta) y,
      Bind.bind x g = ok y -> exists z, x = ok z /\ g z = ok y := by
    intro alpha beta x g y hx
    cases x with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hx
    | div => simp [Bind.bind, Aeneas.Std.bind] at hx
    | ok z => exact ⟨z, rfl, hx⟩
  have noUnsignedNumericEmpty : forall x : DecimalLexeme,
      DecimalGoalVocabularyDefault.validNumeric x -> x.leadingSign = none ->
      DecimalGoalVocabularyDefault.renderNumeric x = [] -> False := by
    intro x hv hs hr
    dsimp only [DecimalGoalVocabularyDefault] at hv hs hr
    rcases hv with ⟨_, _, hne, _⟩
    cases hi : x.integerDigits with
    | nil =>
      cases hf : x.fractionDigits with
      | none => simp_all [hi, hf]
      | some ds => cases ds <;> simp_all [hi, hf]
    | cons d ds => simp [hi] at hr
  unfold P9_T1_DispatchFrame at hrun
  obtain ⟨body, hbody, hrun⟩ := bind_ok_inv _ _ _ hrun
  have hbody_eq : body = s := by
    simpa only [core.str.Str.as_bytes, ModelStrAsBytes, Result.ok.injEq] using hbody.symm
  subst body
  obtain ⟨head, hhead, hrun⟩ := bind_ok_inv _ _ _ hrun
  have hhead_eq : head = s.val.head? := by
    simpa only [core.slice.Slice.first, ModelSliceFirst, Result.ok.injEq] using hhead.symm
  subst head
  cases hlist : s.val with
  | nil =>
    simp only [hlist, List.head?_nil] at hrun
    obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
    cases hrun
    constructor
    · intro _
      exact ⟨_, rfl⟩
    constructor
    · intro sign nan hclass
      dsimp only [DecimalGoalVocabularyDefault] at hclass
      simp [hlist] at hclass
    · intro x hclass
      dsimp only [DecimalGoalVocabularyDefault] at hclass
      simp [hlist] at hclass
      rcases hclass with ⟨_, _, hnonempty, _, _, hi, hf, _⟩
      cases hfrac : x.fractionDigits <;> simp_all [hfrac]
  | cons c tail =>
    simp only [hlist, List.head?_cons] at hrun
    obtain ⟨body1, hbody1, hrun⟩ := bind_ok_inv _ _ _ hrun
    have hindex : core.slice.index.Slice.index
        (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
        { start := 1#usize } = ok (s.drop 1#usize) := by
      simp [Slice.index_SliceIndexRangeFromUsizeSliceInst,
        core.slice.index.SliceIndexRangeFromUsizeSlice.index, hlist]
    have hbodyval : body1.val = if c = 45#u8 ∨ c = 43#u8 then tail else s.val := by
      by_cases hm : c = 45#u8
      · simp [hm, hindex] at hbody1
        subst body1
        simp [Slice.drop, hlist, hm]
      · by_cases hp : c = 43#u8
        · simp [hp, hindex] at hbody1
          subst body1
          simp [Slice.drop, hlist, hp]
        · simp only [hm, hp, ite_false, Result.ok.injEq] at hbody1
          subst body1
          simp [hm, hp]
    have hbodyval' : body1.val =
        if s.val.head? = some (45#u8) ∨ s.val.head? = some (43#u8)
        then s.val.drop 1 else s.val := by
      simpa [hlist, Slice.drop] using hbodyval
    have hstrip := P616_T1_SignStrippedClassification s body1 hs hbodyval'
    have hbodySource : SourceValidByteSlice body1 := hstrip.1
    have hbodyLength : body1.val.length <= s.val.length := hstrip.2.1
    obtain ⟨empty, hempty, hrun⟩ := bind_ok_inv _ _ _ hrun
    have hempty_eq : empty = decide (body1.val = []) := by
      simpa only [core.slice.Slice.is_empty, Slice.length,
        List.length_eq_zero_iff, Result.ok.injEq] using hempty.symm
    by_cases hbodyempty : body1.val = []
    · simp only [hempty_eq, hbodyempty, decide_true, if_true] at hrun
      obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
      cases hrun
      constructor
      · intro _
        exact ⟨_, rfl⟩
      constructor
      · intro sign nan hclass
        have hsbody := (hstrip.2.2.2.1 sign nan hclass).1
        dsimp only [DecimalGoalVocabularyDefault] at hsbody
        simp [hbodyempty] at hsbody
      · intro x hclass
        let y : DecimalLexeme := { x with leadingSign := none }
        have hnum := hstrip.2.2.1 x hclass
        have hrender : DecimalGoalVocabularyDefault.renderNumeric y = [] := by
          dsimp only [DecimalGoalVocabularyDefault]
          dsimp only [DecimalGoalVocabularyDefault] at hnum
          simpa [y, hbodyempty] using hnum.2.1
        exact (noUnsignedNumericEmpty y hnum.1 rfl hrender).elim
    · have hempty_false : empty = false := by
        simp [hempty_eq, hbodyempty]
      rw [hempty_false] at hrun
      obtain ⟨parsed, hparsed, hrun⟩ := bind_ok_inv _ _ _ hrun
      cases parsed with
      | none =>
        obtain ⟨special, hspecial, hrun⟩ := bind_ok_inv _ _ _ hrun
        cases special with
        | none =>
          obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
          cases hrun
          constructor
          · intro _
            exact ⟨_, rfl⟩
          constructor
          · intro sign nan hclass
            have hsbody := (hstrip.2.2.2.1 sign nan hclass).1
            cases nan with
            | false =>
              obtain ⟨f, hparse, _⟩ := hc.special_infinity body1 (decide (c = 45#u8))
                hbodySource hsbody
              have hnone : C.parseSpecial body1 (decide (c = 45#u8)) = none := by
                simpa [P9_T1_EmbedComponents] using hspecial
              rw [hnone] at hparse
              cases hparse
            | true =>
              obtain ⟨f, hparse, _⟩ := hc.special_nan body1 (decide (c = 45#u8))
                hbodySource hsbody
              have hnone : C.parseSpecial body1 (decide (c = 45#u8)) = none := by
                simpa [P9_T1_EmbedComponents] using hspecial
              rw [hnone] at hparse
              cases hparse
          · intro x hclass
            let y : DecimalLexeme := { x with leadingSign := none }
            have hnum := hstrip.2.2.1 x hclass
            obtain ⟨d, hparse⟩ := hc.number_accept body1 y hbodySource hbodyempty
              (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1
            have hnone : C.parseNumber body1 = none := by
              simpa [P9_T1_EmbedComponents] using hparsed
            rw [hnone] at hparse
            cases hparse
        | some value =>
          have hspecialC : C.parseSpecial body1 (decide (c = 45#u8)) = some value := by
            simpa [P9_T1_EmbedComponents] using hspecial
          cases hrun
          constructor
          · intro hclass
            have hnoSpecial : ¬ exists nan,
                DecimalGoalVocabularyDefault.specialLiteral
                  (DecimalGoalVocabularyDefault.bytes body1) none nan := by
              intro hx
              obtain ⟨sign, nan, hclass'⟩ := hstrip.2.2.2.2.2 hx
              exact hclass.2 ⟨sign, nan, hclass'⟩
            have hnone := hc.special_reject body1 (decide (c = 45#u8))
              hbodySource hnoSpecial
            rw [hnone] at hspecialC
            cases hspecialC
          constructor
          · intro sign nan hclass
            have hsdata := hstrip.2.2.2.1 sign nan hclass
            have hnegative : decide (sign = some true) = decide (c = 45#u8) := by
              simpa [hlist] using hsdata.2
            cases nan with
            | false =>
              obtain ⟨f, hparse, hinf⟩ := hc.special_infinity body1
                (decide (c = 45#u8)) hbodySource hsdata.1
              rw [hspecialC] at hparse
              cases hparse
              refine ⟨value, rfl, ?_⟩
              simpa [hnegative] using hinf
            | true =>
              obtain ⟨f, hparse, hnan⟩ := hc.special_nan body1
                (decide (c = 45#u8)) hbodySource hsdata.1
              rw [hspecialC] at hparse
              cases hparse
              exact ⟨value, rfl, hnan⟩
          · intro x hclass
            let y : DecimalLexeme := { x with leadingSign := none }
            have hnum := hstrip.2.2.1 x hclass
            obtain ⟨d, hparse⟩ := hc.number_accept body1 y hbodySource hbodyempty
              (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1
            have hnone : C.parseNumber body1 = none := by
              simpa [P9_T1_EmbedComponents] using hparsed
            rw [hnone] at hparse
            cases hparse
      | some d =>
        have hparse : C.parseNumber body1 = some d := by
          simpa [P9_T1_EmbedComponents] using hparsed
        have hnotInvalid :
            DecimalGoalVocabularyDefault.classifies
              (DecimalGoalVocabularyDefault.bytes s) none -> False := by
          intro hclass
          have hnoBodyNum : ¬ exists y : DecimalLexeme,
              y.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric y ∧
              DecimalGoalVocabularyDefault.renderNumeric y = DecimalGoalVocabularyDefault.bytes body1 := by
            intro hx
            obtain ⟨x', hx'⟩ := hstrip.2.2.2.2.1 hx
            exact hclass.1 ⟨x', hx'⟩
          have hn := hc.number_reject body1 hbodySource hbodyempty
            (Nat.le_trans hbodyLength hA) hnoBodyNum
          simp [hn] at hparse
        have hnotSpecial : ∀ sign nan,
            DecimalGoalVocabularyDefault.classifies
              (DecimalGoalVocabularyDefault.bytes s) (some (Sum.inr (sign, nan))) -> False := by
          intro sign nan hclass
          have hnoFullNum : ¬ exists x : DecimalLexeme,
              DecimalGoalVocabularyDefault.classifies
                (DecimalGoalVocabularyDefault.bytes s) (some (Sum.inl x)) := by
            intro hx
            obtain ⟨x, hx⟩ := hx
            have heq := ClassificationDeterminism.1
              (DecimalGoalVocabularyDefault.bytes s) (some (Sum.inr (sign, nan)))
              (some (Sum.inl x)) hbytes hclass hx
            cases heq
          have hnoBodyNum : ¬ exists y : DecimalLexeme,
              y.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric y ∧
              DecimalGoalVocabularyDefault.renderNumeric y = DecimalGoalVocabularyDefault.bytes body1 := by
            intro hx
            obtain ⟨x, hx⟩ := hstrip.2.2.2.2.1 hx
            exact hnoFullNum ⟨x, hx⟩
          have hn := hc.number_reject body1 hbodySource hbodyempty
            (Nat.le_trans hbodyLength hA) hnoBodyNum
          simp [hn] at hparse
        obtain ⟨fast, hfast, hrun⟩ := bind_ok_inv _ _ _ hrun
        cases fast with
        | none =>
          have hnativeNone : C.native
              { d with negative := decide (c = 45#u8), many_digits := d.many_digits } = none := by
            change ok (C.native { d with negative := decide (c = 45#u8), many_digits := d.many_digits }) =
              ok none at hfast
            injection hfast with hnativeNone
          obtain ⟨first, hfirst, hrun⟩ := bind_ok_inv _ _ _ hrun
          obtain ⟨phase1, hphase1, hrun⟩ := bind_ok_inv _ _ _ hrun
          rcases phase1 with ⟨many1, many2, first1, fp, secondGuard⟩
          obtain ⟨phase2, hphase2, hrun⟩ := bind_ok_inv _ _ _ hrun
          rcases phase2 with ⟨post, secondExp, secondMant, secondResult,
            secondEqual, forced⟩
          obtain ⟨phase3, hphase3, hrun⟩ := bind_ok_inv _ _ _ hrun
          rcases phase3 with ⟨selected, slowGuard, slowResult⟩
          have hfirstC : C.integer d.exponent d.mantissa = first := by
            change ok (C.integer d.exponent d.mantissa) = ok first at hfirst
            injection hfirst with hfirstC
          by_cases hmany : d.many_digits
          · simp only [hmany, if_pos] at hphase1
            cases hphase1
            by_cases hfirstNegative : first.p_biased < 0#i32
            · have hltVal : first.p_biased.val < 0 := by simpa using hfirstNegative
              have hfirstBelow : ¬ 0 ≤ first.p_biased.val := by omega
              simp [hfirstBelow] at hphase2
              rcases hphase2 with ⟨hpost, hphase2⟩
              subst post
              simp only [hfirstNegative, if_pos] at hphase3
              cases hphase3
              obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
              by_cases hnegative : c = 45#u8
              · simp only [hnegative, if_pos] at hrun
                obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  let magnitude := C.assemble (C.slow body1)
                  have hnum := hstrip.2.2.1 x hclass
                  have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                  have hround := hslow.1
                  rw [hnum.2.2.1] at hround
                  have hclear := hslow.2
                  have hassemblyC : C.assemble (C.slow body1) = assembly := by
                    change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
                    injection hassembly with hassemblyC
                  have hnegateC : C.negate assembly = result := by
                    change ok (C.negate assembly) = ok result at hnegate
                    injection hnegate with hnegateC
                  have hresult : result = C.negate magnitude := by
                    calc
                      result = C.negate assembly := hnegateC.symm
                      _ = C.negate magnitude := by rw [← hassemblyC]
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = true := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      true magnitude (C.negate magnitude) := by
                    change magnitude.val < 2 ^ 63 ∧
                      (C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
                    rw [hc.negate_all magnitude]
                    constructor
                    · exact hclear
                    · rw [if_pos hclear]
                      simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
                      (C.negate magnitude) := by rw [hlex]; exact hsign
                  exact ⟨C.negate magnitude, magnitude,
                    congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
              · simp only [hnegative, if_neg] at hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  let magnitude := C.assemble (C.slow body1)
                  have hnum := hstrip.2.2.1 x hclass
                  have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                  have hround := hslow.1
                  rw [hnum.2.2.1] at hround
                  have hclear := hslow.2
                  have hassemblyC : C.assemble (C.slow body1) = assembly := by
                    change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
                    injection hassembly with hassemblyC
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = false := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      false magnitude magnitude := by
                    change magnitude.val < 2 ^ 63 ∧
                      magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
                    constructor
                    · exact hclear
                    · simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
                    rw [hlex]
                    exact hsign
                  have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
                    rw [← hassemblyC]
                    exact hsignLex
                  exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
            · have hnotLtVal : ¬ first.p_biased.val < 0 := by simpa using hfirstNegative
              have hfirstNonneg : 0 ≤ first.p_biased.val := by omega
              simp [hfirstNonneg] at hphase2
              obtain ⟨next, hnext, hphase2⟩ := bind_ok_inv _ _ _ hphase2
              obtain ⟨second, hsecond, hphase2⟩ := bind_ok_inv _ _ _ hphase2
              obtain ⟨equal, hequal, hphase2⟩ := bind_ok_inv _ _ _ hphase2
              cases equal
              · simp at hphase2
                rcases hphase2 with ⟨hpost, hExp, hMant, hSecond, hEqual, hForced⟩
                have hpostNegative : post.p_biased < 0#i32 := by
                  rw [← hpost]
                  simp
                simp only [hpostNegative, if_pos] at hphase3
                cases hphase3
                obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
                have hassemblyC : C.assemble (C.slow body1) = assembly := by
                  change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
                  injection hassembly with hassemblyC
                by_cases hnegative : c = 45#u8
                · simp only [hnegative, if_pos] at hrun
                  obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
                  cases hrun
                  constructor
                  · intro hclass
                    exact (hnotInvalid hclass).elim
                  constructor
                  · intro sign nan hclass
                    exact (hnotSpecial sign nan hclass).elim
                  · intro x hclass
                    let y : DecimalLexeme := { x with leadingSign := none }
                    let magnitude := C.assemble (C.slow body1)
                    have hnum := hstrip.2.2.1 x hclass
                    have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                    have hround := hslow.1
                    rw [hnum.2.2.1] at hround
                    have hclear := hslow.2
                    have hnegateC : C.negate assembly = result := by
                      change ok (C.negate assembly) = ok result at hnegate
                      injection hnegate with hnegateC
                    have hresult : result = C.negate magnitude := by
                      calc
                        result = C.negate assembly := hnegateC.symm
                        _ = C.negate magnitude := by rw [← hassemblyC]
                    have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
                      calc
                        DecimalGoalVocabularyDefault.lexicalNegative x =
                            decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                        _ = true := by simp [hlist, hnegative]
                    have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                        true magnitude (C.negate magnitude) := by
                      change magnitude.val < 2 ^ 63 ∧
                        (C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
                      rw [hc.negate_all magnitude]
                      constructor
                      · exact hclear
                      · rw [if_pos hclear]
                        simp
                    have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                        (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
                        (C.negate magnitude) := by rw [hlex]; exact hsign
                    exact ⟨C.negate magnitude, magnitude,
                      congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
                · simp only [hnegative, if_neg] at hrun
                  cases hrun
                  constructor
                  · intro hclass
                    exact (hnotInvalid hclass).elim
                  constructor
                  · intro sign nan hclass
                    exact (hnotSpecial sign nan hclass).elim
                  · intro x hclass
                    let y : DecimalLexeme := { x with leadingSign := none }
                    let magnitude := C.assemble (C.slow body1)
                    have hnum := hstrip.2.2.1 x hclass
                    have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                    have hround := hslow.1
                    rw [hnum.2.2.1] at hround
                    have hclear := hslow.2
                    have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
                      calc
                        DecimalGoalVocabularyDefault.lexicalNegative x =
                            decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                        _ = false := by simp [hlist, hnegative]
                    have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                        false magnitude magnitude := by
                      change magnitude.val < 2 ^ 63 ∧
                        magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
                      constructor
                      · exact hclear
                      · simp
                    have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                        (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
                      rw [hlex]
                      exact hsign
                    have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
                        (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
                      rw [← hassemblyC]
                      exact hsignLex
                    exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
              · simp at hphase2
                rcases hphase2 with ⟨hpost, hExp, hMant, hSecond, hEqual, hForced⟩
                subst post
                simp [hfirstNegative] at hphase3
                have hselected : selected = first := by
                  exact hphase3.1.symm
                subst selected
                obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
                have hassemblyC : C.assemble first = assembly := by
                  change ok (C.assemble first) = ok assembly at hassembly
                  injection hassembly with hassemblyC
                have hsecondC : C.integer d.exponent next = second := by
                  change ok (C.integer d.exponent next) = ok second at hsecond
                  injection hsecond with hsecondC
                have hpair : first = second := by
                  have hm : first.m = second.m := by
                    by_contra h
                    simp [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq, h] at hequal
                  have hp : first.p_biased = second.p_biased := by
                    have hh : decide (first.p_biased = second.p_biased) = true := by
                      simpa [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq, hm] using hequal
                    simpa using hh
                  have hf := And.intro hm hp
                  rcases hf with ⟨hm, hp⟩
                  cases first
                  cases second
                  cases hm
                  cases hp
                  rfl
                have hnextval : next.val = d.mantissa.val + 1 := by
                  have hadd := UScalar.add_equiv d.mantissa (1#u64)
                  rw [hnext] at hadd
                  simpa using hadd.2.1
                have hbounds := hc.record_bounds body1 d hbodySource hbodyempty hparse
                have hfirstNormal := hc.integer_normal d.exponent d.mantissa
                have hfirstRound : DecimalGoalVocabularyDefault.roundsMagnitude
                    (DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
                  have hnot : ¬ (C.integer d.exponent d.mantissa).p_biased.val < 0 := by
                    rw [hfirstC]
                    exact hnotLtVal
                  rcases hfirstNormal with hneg | ⟨hr, hclear⟩
                  · exact (hnot hneg).elim
                  · simpa only [DecimalGoalVocabularyDefault, hfirstC] using hr
                have hfirstClear : (C.assemble first).val < 2 ^ 63 := by
                  have hnot : ¬ (C.integer d.exponent d.mantissa).p_biased.val < 0 := by
                    rw [hfirstC]
                    exact hnotLtVal
                  rcases hfirstNormal with hneg | ⟨hr, hclear⟩
                  · exact (hnot hneg).elim
                  · simpa [hfirstC] using hclear
                have hsecondNormal := hc.integer_normal d.exponent next
                have hsecondRound : DecimalGoalVocabularyDefault.roundsMagnitude
                    ((next.val : Real) * (10 : Real) ^ d.exponent.val)
                    (C.assemble second) := by
                  have hnot : ¬ (C.integer d.exponent next).p_biased.val < 0 := by
                    rw [hsecondC, ← hpair]
                    exact hnotLtVal
                  rcases hsecondNormal with hneg | ⟨hr, hclear⟩
                  · exact (hnot hneg).elim
                  · simpa [hsecondC] using hr
                have hsecondRound' : DecimalGoalVocabularyDefault.roundsMagnitude
                    ((((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val))
                    (C.assemble first) := by
                  rw [← hpair] at hsecondRound
                  rw [hnextval] at hsecondRound
                  exact hsecondRound
                have hupperRewrite :
                    ((next.val : Real) * (10 : Real) ^ d.exponent.val) =
                    (((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := by
                  rw [hnextval]
                have hsecondRound'' := hsecondRound
                rw [hupperRewrite] at hsecondRound''
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  have hnum := hstrip.2.2.1 x hclass
                  have hacc := hc.record_accumulated body1 y d hbodySource
                    (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
                  have hinterval :
                      DecimalGoalVocabularyDefault.decimalMagnitude d ≤
                          DecimalGoalVocabularyDefault.accumulatedMagnitude y ∧
                      DecimalGoalVocabularyDefault.accumulatedMagnitude y <
                        (((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := by
                    simpa [hmany] using hacc
                  have hroundMag := P616_T1_RoundingCellConvexity
                    (DecimalGoalVocabularyDefault.decimalMagnitude d)
                    (((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val)
                    (DecimalGoalVocabularyDefault.accumulatedMagnitude y) (C.assemble first)
                    hfirstRound hsecondRound' hinterval.1 (le_of_lt hinterval.2)
                  have hround := hroundMag
                  rw [hnum.2.2.1] at hround
                  by_cases hnegative : c = 45#u8
                  · simp only [hnegative, if_pos] at hrun
                    obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
                    cases hrun
                    have hnegateC : C.negate assembly = result := by
                      change ok (C.negate assembly) = ok result at hnegate
                      injection hnegate with hnegateC
                    have hresult : result = C.negate (C.assemble first) := by
                      calc
                        result = C.negate assembly := hnegateC.symm
                        _ = C.negate (C.assemble first) := by rw [← hassemblyC]
                    have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
                      calc
                        DecimalGoalVocabularyDefault.lexicalNegative x =
                            decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                        _ = true := by simp [hlist, hnegative]
                    have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                        true (C.assemble first) (C.negate (C.assemble first)) := by
                      change (C.assemble first).val < 2 ^ 63 ∧
                        (C.negate (C.assemble first)).val =
                          (C.assemble first).val + (if true then 2 ^ 63 else 0)
                      rw [hc.negate_all]
                      constructor
                      · exact hfirstClear
                      · rw [if_pos hfirstClear]
                        simp
                    have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                        (DecimalGoalVocabularyDefault.lexicalNegative x)
                        (C.assemble first) (C.negate (C.assemble first)) := by
                      rw [hlex]
                      exact hsign
                    exact ⟨C.negate (C.assemble first), C.assemble first,
                      congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
                  · simp only [hnegative, if_neg] at hrun
                    cases hrun
                    have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
                      calc
                        DecimalGoalVocabularyDefault.lexicalNegative x =
                            decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                        _ = false := by simp [hlist, hnegative]
                    have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                        false (C.assemble first) (C.assemble first) := by
                      change (C.assemble first).val < 2 ^ 63 ∧
                        (C.assemble first).val =
                          (C.assemble first).val + (if false then 2 ^ 63 else 0)
                      constructor
                      · exact hfirstClear
                      · simp
                    have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                        (DecimalGoalVocabularyDefault.lexicalNegative x)
                        (C.assemble first) assembly := by
                      rw [hlex, ← hassemblyC]
                      exact hsign
                    exact ⟨assembly, C.assemble first, rfl, hround, hsignLex⟩
          · simp only [hmany, Bool.false_eq_true, if_false] at hphase1
            cases hphase1
            simp only [Bool.false_eq_true, if_false] at hphase2
            cases hphase2
            by_cases hfirstNegative : first.p_biased < 0#i32
            · simp only [hfirstNegative, if_pos] at hphase3
              cases hphase3
              obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
              by_cases hnegative : c = 45#u8
              · simp only [hnegative, if_pos] at hrun
                obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  let magnitude := C.assemble (C.slow body1)
                  have hnum := hstrip.2.2.1 x hclass
                  have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                  have hround := hslow.1
                  rw [hnum.2.2.1] at hround
                  have hclear := hslow.2
                  have hassemblyC : C.assemble (C.slow body1) = assembly := by
                    change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
                    injection hassembly with hassemblyC
                  have hnegateC : C.negate assembly = result := by
                    change ok (C.negate assembly) = ok result at hnegate
                    injection hnegate with hnegateC
                  have hresult : result = C.negate magnitude := by
                    calc
                      result = C.negate assembly := hnegateC.symm
                      _ = C.negate magnitude := by
                        rw [← hassemblyC]
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = true := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      true magnitude (C.negate magnitude) := by
                    change magnitude.val < 2 ^ 63 ∧
                      (C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
                    rw [hc.negate_all magnitude]
                    constructor
                    · exact hclear
                    · rw [if_pos hclear]
                      simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
                      (C.negate magnitude) := by
                    rw [hlex]
                    exact hsign
                  exact ⟨C.negate magnitude, magnitude, congrArg
                    (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
              · simp only [hnegative, if_neg] at hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  let magnitude := C.assemble (C.slow body1)
                  have hnum := hstrip.2.2.1 x hclass
                  have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                  have hround := hslow.1
                  rw [hnum.2.2.1] at hround
                  have hclear := hslow.2
                  have hassemblyC : C.assemble (C.slow body1) = assembly := by
                    change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
                    injection hassembly with hassemblyC
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = false := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      false magnitude magnitude := by
                    change magnitude.val < 2 ^ 63 ∧
                      magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
                    constructor
                    · exact hclear
                    · simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
                    rw [hlex]
                    exact hsign
                  have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
                    rw [← hassemblyC]
                    exact hsignLex
                  exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
            · simp only [hfirstNegative, if_neg] at hphase3
              cases hphase3
              obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
              have hassemblyC : C.assemble first = assembly := by
                change ok (C.assemble first) = ok assembly at hassembly
                injection hassembly with hassemblyC
              by_cases hnegative : c = 45#u8
              · simp only [hnegative, if_pos] at hrun
                obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  have hnum := hstrip.2.2.1 x hclass
                  have hacc := hc.record_accumulated body1 y d hbodySource
                    (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
                  have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
                      DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
                    simpa [hmany] using hacc
                  have hinteger := hc.integer_normal d.exponent d.mantissa
                  have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
                      (DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
                    have hnonneg : ¬ first.p_biased.val < 0 := by
                      simpa using hfirstNegative
                    rw [← hfirstC] at hnonneg
                    rcases hinteger with hneg | ⟨hr, hclear⟩
                    · exact (hnonneg hneg).elim
                    · simpa [hfirstC] using hr
                  have hround := hroundD
                  rw [hdecimal, hnum.2.2.1] at hround
                  have hclear : (C.assemble first).val < 2 ^ 63 := by
                    have hnonneg : ¬ first.p_biased.val < 0 := by
                      simpa using hfirstNegative
                    rw [← hfirstC] at hnonneg
                    rcases hinteger with hneg | ⟨hr, hclear⟩
                    · exact (hnonneg hneg).elim
                    · simpa [hfirstC] using hclear
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = true := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      true (C.assemble first) (C.negate (C.assemble first)) := by
                    change (C.assemble first).val < 2 ^ 63 ∧
                      (C.negate (C.assemble first)).val =
                        (C.assemble first).val + (if true then 2 ^ 63 else 0)
                    rw [hc.negate_all]
                    constructor
                    · exact hclear
                    · rw [if_pos hclear]
                      simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x)
                      (C.assemble first) (C.negate (C.assemble first)) := by
                    rw [hlex]
                    exact hsign
                  have hresult : result = C.negate (C.assemble first) := by
                    have hnegateC : C.negate assembly = result := by
                      change ok (C.negate assembly) = ok result at hnegate
                      injection hnegate with hnegateC
                    simpa [hassemblyC] using hnegateC.symm
                  exact ⟨C.negate (C.assemble first), C.assemble first,
                    congrArg (fun z => core.result.Result.Ok z) hresult,
                    hround, hsignLex⟩
              · simp only [hnegative, if_neg] at hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  have hnum := hstrip.2.2.1 x hclass
                  have hacc := hc.record_accumulated body1 y d hbodySource
                    (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
                  have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
                      DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
                    simpa [hmany] using hacc
                  have hinteger := hc.integer_normal d.exponent d.mantissa
                  have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
                      (DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
                    have hnonneg : ¬ first.p_biased.val < 0 := by
                      simpa using hfirstNegative
                    rw [← hfirstC] at hnonneg
                    rcases hinteger with hneg | ⟨hr, hclear⟩
                    · exact (hnonneg hneg).elim
                    · simpa [hfirstC] using hr
                  have hround := hroundD
                  rw [hdecimal, hnum.2.2.1] at hround
                  have hclear : (C.assemble first).val < 2 ^ 63 := by
                    have hnonneg : ¬ first.p_biased.val < 0 := by
                      simpa using hfirstNegative
                    rw [← hfirstC] at hnonneg
                    rcases hinteger with hneg | ⟨hr, hclear⟩
                    · exact (hnonneg hneg).elim
                    · simpa [hfirstC] using hclear
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = false := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      false (C.assemble first) (C.assemble first) := by
                    change (C.assemble first).val < 2 ^ 63 ∧
                      (C.assemble first).val =
                        (C.assemble first).val + (if false then 2 ^ 63 else 0)
                    constructor
                    · exact hclear
                    · simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x)
                      (C.assemble first) (C.assemble first) := by
                    rw [hlex]
                    exact hsign
                  have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x)
                      (C.assemble first) assembly := by
                    rw [← hassemblyC]
                    exact hsignLex
                  exact ⟨assembly, C.assemble first, rfl, hround, hsignLexAssembly⟩
        | some value =>
          have hnative : C.native
              { d with negative := decide (c = 45#u8), many_digits := d.many_digits } = some value := by
            change ok (C.native { d with negative := decide (c = 45#u8), many_digits := d.many_digits }) =
              ok (some value) at hfast
            injection hfast with hnative
          cases hrun
          constructor
          · intro hclass
            exact (hnotInvalid hclass).elim
          constructor
          · intro sign nan hclass
            exact (hnotSpecial sign nan hclass).elim
          · intro x hclass
            let y : DecimalLexeme := { x with leadingSign := none }
            let nativeRecord : num.imp.dec2flt.decimal.Decimal :=
              { d with negative := decide (c = 45#u8), many_digits := d.many_digits }
            have hnum := hstrip.2.2.1 x hclass
            have hnativeNormal := hc.native_normal nativeRecord value hnative
            rcases hnativeNormal with ⟨hmd, hrest⟩
            rcases hrest with ⟨magnitude, hround, hsigned⟩
            have hmany : d.many_digits = false := by
              change nativeRecord.many_digits = false at hmd
              simpa [nativeRecord] using hmd
            have hacc := hc.record_accumulated body1 y d hbodySource
              (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
            have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
                DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
              simpa [hmany] using hacc
            have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
                (DecimalGoalVocabularyDefault.decimalMagnitude d) magnitude := by
              simpa only [DecimalGoalVocabularyDefault] using hround
            rw [hdecimal, hnum.2.2.1] at hroundD
            have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = decide (c = 45#u8) := by
              calc
                DecimalGoalVocabularyDefault.lexicalNegative x =
                    decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                _ = decide (c = 45#u8) := by simp [hlist]
            have hsigned' : DecimalGoalVocabularyDefault.signedMagnitude
                (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude value := by
              rw [hlex]
              simpa only [DecimalGoalVocabularyDefault, nativeRecord] using hsigned
            exact ⟨value, magnitude, rfl, hroundD, hsigned'⟩
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.P616_T1_RoundingCellConvexity
import Tablet.ClassificationDeterminism
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

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model
-- [TABLET NODE: P616_T1_FrameCorrectness]
theorem P616_T1_FrameCorrectness :
    forall C : P9_T1_AbstractComponents, DispatchContracts C ->
      forall (s : Str) r trace, DecimalGoalVocabularyDefault.sourceString s ->
      s.val.length <= 3458764513820540928 ->
      P9_T1_DispatchFrame (P9_T1_EmbedComponents C) s = ok (r, trace) ->
      ((DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s) none ->
        exists error, r = core.result.Result.Err error) ∧
      (forall sign nan,
        DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
          (some (Sum.inr (sign, nan))) ->
        exists f, r = core.result.Result.Ok f ∧
          (if nan then DecimalGoalVocabularyDefault.isNan f
          else DecimalGoalVocabularyDefault.isInfinity (decide (sign = some true)) f)) ∧
      (forall x : DecimalLexeme,
        DecimalGoalVocabularyDefault.classifies (DecimalGoalVocabularyDefault.bytes s)
          (some (Sum.inl x)) ->
        exists f magnitude, r = core.result.Result.Ok f ∧
          DecimalGoalVocabularyDefault.roundsMagnitude
            (DecimalGoalVocabularyDefault.accumulatedMagnitude x) magnitude ∧
          DecimalGoalVocabularyDefault.signedMagnitude
            (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude f)) := by
-- BODY
  classical
  intro C hc s r trace hs hA hrun
  have hbytes : ∀ b ∈ DecimalGoalVocabularyDefault.bytes s, b < 256 := by
    intro b hb
    dsimp [DecimalGoalVocabularyDefault] at hb ⊢
    rcases List.mem_map.mp hb with ⟨u, hu, rfl⟩
    exact u.bv.isLt
  have bind_ok_inv : forall {alpha beta : Type} (x : Result alpha)
      (g : alpha -> Result beta) y,
      Bind.bind x g = ok y -> exists z, x = ok z /\ g z = ok y := by
    intro alpha beta x g y hx
    cases x with
    | fail err => simp [Bind.bind, Aeneas.Std.bind] at hx
    | div => simp [Bind.bind, Aeneas.Std.bind] at hx
    | ok z => exact ⟨z, rfl, hx⟩
  have noUnsignedNumericEmpty : forall x : DecimalLexeme,
      DecimalGoalVocabularyDefault.validNumeric x -> x.leadingSign = none ->
      DecimalGoalVocabularyDefault.renderNumeric x = [] -> False := by
    intro x hv hs hr
    dsimp only [DecimalGoalVocabularyDefault] at hv hs hr
    rcases hv with ⟨_, _, hne, _⟩
    cases hi : x.integerDigits with
    | nil =>
      cases hf : x.fractionDigits with
      | none => simp_all [hi, hf]
      | some ds => cases ds <;> simp_all [hi, hf]
    | cons d ds => simp [hi] at hr
  unfold P9_T1_DispatchFrame at hrun
  obtain ⟨body, hbody, hrun⟩ := bind_ok_inv _ _ _ hrun
  have hbody_eq : body = s := by
    simpa only [core.str.Str.as_bytes, ModelStrAsBytes, Result.ok.injEq] using hbody.symm
  subst body
  obtain ⟨head, hhead, hrun⟩ := bind_ok_inv _ _ _ hrun
  have hhead_eq : head = s.val.head? := by
    simpa only [core.slice.Slice.first, ModelSliceFirst, Result.ok.injEq] using hhead.symm
  subst head
  cases hlist : s.val with
  | nil =>
    simp only [hlist, List.head?_nil] at hrun
    obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
    cases hrun
    constructor
    · intro _
      exact ⟨_, rfl⟩
    constructor
    · intro sign nan hclass
      dsimp only [DecimalGoalVocabularyDefault] at hclass
      simp [hlist] at hclass
    · intro x hclass
      dsimp only [DecimalGoalVocabularyDefault] at hclass
      simp [hlist] at hclass
      rcases hclass with ⟨_, _, hnonempty, _, _, hi, hf, _⟩
      cases hfrac : x.fractionDigits <;> simp_all [hfrac]
  | cons c tail =>
    simp only [hlist, List.head?_cons] at hrun
    obtain ⟨body1, hbody1, hrun⟩ := bind_ok_inv _ _ _ hrun
    have hindex : core.slice.index.Slice.index
        (core.slice.index.SliceIndexRangeFromUsizeSlice Std.U8) s
        { start := 1#usize } = ok (s.drop 1#usize) := by
      simp [Slice.index_SliceIndexRangeFromUsizeSliceInst,
        core.slice.index.SliceIndexRangeFromUsizeSlice.index, hlist]
    have hbodyval : body1.val = if c = 45#u8 ∨ c = 43#u8 then tail else s.val := by
      by_cases hm : c = 45#u8
      · simp [hm, hindex] at hbody1
        subst body1
        simp [Slice.drop, hlist, hm]
      · by_cases hp : c = 43#u8
        · simp [hp, hindex] at hbody1
          subst body1
          simp [Slice.drop, hlist, hp]
        · simp only [hm, hp, ite_false, Result.ok.injEq] at hbody1
          subst body1
          simp [hm, hp]
    have hbodyval' : body1.val =
        if s.val.head? = some (45#u8) ∨ s.val.head? = some (43#u8)
        then s.val.drop 1 else s.val := by
      simpa [hlist, Slice.drop] using hbodyval
    have hstrip := P616_T1_SignStrippedClassification s body1 hs hbodyval'
    have hbodySource : SourceValidByteSlice body1 := hstrip.1
    have hbodyLength : body1.val.length <= s.val.length := hstrip.2.1
    obtain ⟨empty, hempty, hrun⟩ := bind_ok_inv _ _ _ hrun
    have hempty_eq : empty = decide (body1.val = []) := by
      simpa only [core.slice.Slice.is_empty, Slice.length,
        List.length_eq_zero_iff, Result.ok.injEq] using hempty.symm
    by_cases hbodyempty : body1.val = []
    · simp only [hempty_eq, hbodyempty, decide_true, if_true] at hrun
      obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
      cases hrun
      constructor
      · intro _
        exact ⟨_, rfl⟩
      constructor
      · intro sign nan hclass
        have hsbody := (hstrip.2.2.2.1 sign nan hclass).1
        dsimp only [DecimalGoalVocabularyDefault] at hsbody
        simp [hbodyempty] at hsbody
      · intro x hclass
        let y : DecimalLexeme := { x with leadingSign := none }
        have hnum := hstrip.2.2.1 x hclass
        have hrender : DecimalGoalVocabularyDefault.renderNumeric y = [] := by
          dsimp only [DecimalGoalVocabularyDefault]
          dsimp only [DecimalGoalVocabularyDefault] at hnum
          simpa [y, hbodyempty] using hnum.2.1
        exact (noUnsignedNumericEmpty y hnum.1 rfl hrender).elim
    · have hempty_false : empty = false := by
        simp [hempty_eq, hbodyempty]
      rw [hempty_false] at hrun
      obtain ⟨parsed, hparsed, hrun⟩ := bind_ok_inv _ _ _ hrun
      cases parsed with
      | none =>
        obtain ⟨special, hspecial, hrun⟩ := bind_ok_inv _ _ _ hrun
        cases special with
        | none =>
          obtain ⟨pfe, hpfe, hrun⟩ := bind_ok_inv _ _ _ hrun
          cases hrun
          constructor
          · intro _
            exact ⟨_, rfl⟩
          constructor
          · intro sign nan hclass
            have hsbody := (hstrip.2.2.2.1 sign nan hclass).1
            cases nan with
            | false =>
              obtain ⟨f, hparse, _⟩ := hc.special_infinity body1 (decide (c = 45#u8))
                hbodySource hsbody
              have hnone : C.parseSpecial body1 (decide (c = 45#u8)) = none := by
                simpa [P9_T1_EmbedComponents] using hspecial
              rw [hnone] at hparse
              cases hparse
            | true =>
              obtain ⟨f, hparse, _⟩ := hc.special_nan body1 (decide (c = 45#u8))
                hbodySource hsbody
              have hnone : C.parseSpecial body1 (decide (c = 45#u8)) = none := by
                simpa [P9_T1_EmbedComponents] using hspecial
              rw [hnone] at hparse
              cases hparse
          · intro x hclass
            let y : DecimalLexeme := { x with leadingSign := none }
            have hnum := hstrip.2.2.1 x hclass
            obtain ⟨d, hparse⟩ := hc.number_accept body1 y hbodySource hbodyempty
              (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1
            have hnone : C.parseNumber body1 = none := by
              simpa [P9_T1_EmbedComponents] using hparsed
            rw [hnone] at hparse
            cases hparse
        | some value =>
          have hspecialC : C.parseSpecial body1 (decide (c = 45#u8)) = some value := by
            simpa [P9_T1_EmbedComponents] using hspecial
          cases hrun
          constructor
          · intro hclass
            have hnoSpecial : ¬ exists nan,
                DecimalGoalVocabularyDefault.specialLiteral
                  (DecimalGoalVocabularyDefault.bytes body1) none nan := by
              intro hx
              obtain ⟨sign, nan, hclass'⟩ := hstrip.2.2.2.2.2 hx
              exact hclass.2 ⟨sign, nan, hclass'⟩
            have hnone := hc.special_reject body1 (decide (c = 45#u8))
              hbodySource hnoSpecial
            rw [hnone] at hspecialC
            cases hspecialC
          constructor
          · intro sign nan hclass
            have hsdata := hstrip.2.2.2.1 sign nan hclass
            have hnegative : decide (sign = some true) = decide (c = 45#u8) := by
              simpa [hlist] using hsdata.2
            cases nan with
            | false =>
              obtain ⟨f, hparse, hinf⟩ := hc.special_infinity body1
                (decide (c = 45#u8)) hbodySource hsdata.1
              rw [hspecialC] at hparse
              cases hparse
              refine ⟨value, rfl, ?_⟩
              simpa [hnegative] using hinf
            | true =>
              obtain ⟨f, hparse, hnan⟩ := hc.special_nan body1
                (decide (c = 45#u8)) hbodySource hsdata.1
              rw [hspecialC] at hparse
              cases hparse
              exact ⟨value, rfl, hnan⟩
          · intro x hclass
            let y : DecimalLexeme := { x with leadingSign := none }
            have hnum := hstrip.2.2.1 x hclass
            obtain ⟨d, hparse⟩ := hc.number_accept body1 y hbodySource hbodyempty
              (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1
            have hnone : C.parseNumber body1 = none := by
              simpa [P9_T1_EmbedComponents] using hparsed
            rw [hnone] at hparse
            cases hparse
      | some d =>
        have hparse : C.parseNumber body1 = some d := by
          simpa [P9_T1_EmbedComponents] using hparsed
        have hnotInvalid :
            DecimalGoalVocabularyDefault.classifies
              (DecimalGoalVocabularyDefault.bytes s) none -> False := by
          intro hclass
          have hnoBodyNum : ¬ exists y : DecimalLexeme,
              y.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric y ∧
              DecimalGoalVocabularyDefault.renderNumeric y = DecimalGoalVocabularyDefault.bytes body1 := by
            intro hx
            obtain ⟨x', hx'⟩ := hstrip.2.2.2.2.1 hx
            exact hclass.1 ⟨x', hx'⟩
          have hn := hc.number_reject body1 hbodySource hbodyempty
            (Nat.le_trans hbodyLength hA) hnoBodyNum
          simp [hn] at hparse
        have hnotSpecial : ∀ sign nan,
            DecimalGoalVocabularyDefault.classifies
              (DecimalGoalVocabularyDefault.bytes s) (some (Sum.inr (sign, nan))) -> False := by
          intro sign nan hclass
          have hnoFullNum : ¬ exists x : DecimalLexeme,
              DecimalGoalVocabularyDefault.classifies
                (DecimalGoalVocabularyDefault.bytes s) (some (Sum.inl x)) := by
            intro hx
            obtain ⟨x, hx⟩ := hx
            have heq := ClassificationDeterminism.1
              (DecimalGoalVocabularyDefault.bytes s) (some (Sum.inr (sign, nan)))
              (some (Sum.inl x)) hbytes hclass hx
            cases heq
          have hnoBodyNum : ¬ exists y : DecimalLexeme,
              y.leadingSign = none ∧ DecimalGoalVocabularyDefault.validNumeric y ∧
              DecimalGoalVocabularyDefault.renderNumeric y = DecimalGoalVocabularyDefault.bytes body1 := by
            intro hx
            obtain ⟨x, hx⟩ := hstrip.2.2.2.2.1 hx
            exact hnoFullNum ⟨x, hx⟩
          have hn := hc.number_reject body1 hbodySource hbodyempty
            (Nat.le_trans hbodyLength hA) hnoBodyNum
          simp [hn] at hparse
        obtain ⟨fast, hfast, hrun⟩ := bind_ok_inv _ _ _ hrun
        cases fast with
        | none =>
          have hnativeNone : C.native
              { d with negative := decide (c = 45#u8), many_digits := d.many_digits } = none := by
            change ok (C.native { d with negative := decide (c = 45#u8), many_digits := d.many_digits }) =
              ok none at hfast
            injection hfast with hnativeNone
          obtain ⟨first, hfirst, hrun⟩ := bind_ok_inv _ _ _ hrun
          obtain ⟨phase1, hphase1, hrun⟩ := bind_ok_inv _ _ _ hrun
          rcases phase1 with ⟨many1, many2, first1, fp, secondGuard⟩
          obtain ⟨phase2, hphase2, hrun⟩ := bind_ok_inv _ _ _ hrun
          rcases phase2 with ⟨post, secondExp, secondMant, secondResult,
            secondEqual, forced⟩
          obtain ⟨phase3, hphase3, hrun⟩ := bind_ok_inv _ _ _ hrun
          rcases phase3 with ⟨selected, slowGuard, slowResult⟩
          have hfirstC : C.integer d.exponent d.mantissa = first := by
            change ok (C.integer d.exponent d.mantissa) = ok first at hfirst
            injection hfirst with hfirstC
          by_cases hmany : d.many_digits
          · simp only [hmany, if_pos] at hphase1
            cases hphase1
            by_cases hfirstNegative : first.p_biased < 0#i32
            · have hltVal : first.p_biased.val < 0 := by simpa using hfirstNegative
              have hfirstBelow : ¬ 0 ≤ first.p_biased.val := by omega
              simp [hfirstBelow] at hphase2
              rcases hphase2 with ⟨hpost, hphase2⟩
              subst post
              simp only [hfirstNegative, if_pos] at hphase3
              cases hphase3
              obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
              by_cases hnegative : c = 45#u8
              · simp only [hnegative, if_pos] at hrun
                obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  let magnitude := C.assemble (C.slow body1)
                  have hnum := hstrip.2.2.1 x hclass
                  have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                  have hround := hslow.1
                  rw [hnum.2.2.1] at hround
                  have hclear := hslow.2
                  have hassemblyC : C.assemble (C.slow body1) = assembly := by
                    change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
                    injection hassembly with hassemblyC
                  have hnegateC : C.negate assembly = result := by
                    change ok (C.negate assembly) = ok result at hnegate
                    injection hnegate with hnegateC
                  have hresult : result = C.negate magnitude := by
                    calc
                      result = C.negate assembly := hnegateC.symm
                      _ = C.negate magnitude := by rw [← hassemblyC]
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = true := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      true magnitude (C.negate magnitude) := by
                    change magnitude.val < 2 ^ 63 ∧
                      (C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
                    rw [hc.negate_all magnitude]
                    constructor
                    · exact hclear
                    · rw [if_pos hclear]
                      simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
                      (C.negate magnitude) := by rw [hlex]; exact hsign
                  exact ⟨C.negate magnitude, magnitude,
                    congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
              · simp only [hnegative, if_neg] at hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  let magnitude := C.assemble (C.slow body1)
                  have hnum := hstrip.2.2.1 x hclass
                  have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                  have hround := hslow.1
                  rw [hnum.2.2.1] at hround
                  have hclear := hslow.2
                  have hassemblyC : C.assemble (C.slow body1) = assembly := by
                    change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
                    injection hassembly with hassemblyC
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = false := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      false magnitude magnitude := by
                    change magnitude.val < 2 ^ 63 ∧
                      magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
                    constructor
                    · exact hclear
                    · simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
                    rw [hlex]
                    exact hsign
                  have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
                    rw [← hassemblyC]
                    exact hsignLex
                  exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
            · have hnotLtVal : ¬ first.p_biased.val < 0 := by simpa using hfirstNegative
              have hfirstNonneg : 0 ≤ first.p_biased.val := by omega
              simp [hfirstNonneg] at hphase2
              obtain ⟨next, hnext, hphase2⟩ := bind_ok_inv _ _ _ hphase2
              obtain ⟨second, hsecond, hphase2⟩ := bind_ok_inv _ _ _ hphase2
              obtain ⟨equal, hequal, hphase2⟩ := bind_ok_inv _ _ _ hphase2
              cases equal
              · simp at hphase2
                rcases hphase2 with ⟨hpost, hExp, hMant, hSecond, hEqual, hForced⟩
                have hpostNegative : post.p_biased < 0#i32 := by
                  rw [← hpost]
                  simp
                simp only [hpostNegative, if_pos] at hphase3
                cases hphase3
                obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
                have hassemblyC : C.assemble (C.slow body1) = assembly := by
                  change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
                  injection hassembly with hassemblyC
                by_cases hnegative : c = 45#u8
                · simp only [hnegative, if_pos] at hrun
                  obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
                  cases hrun
                  constructor
                  · intro hclass
                    exact (hnotInvalid hclass).elim
                  constructor
                  · intro sign nan hclass
                    exact (hnotSpecial sign nan hclass).elim
                  · intro x hclass
                    let y : DecimalLexeme := { x with leadingSign := none }
                    let magnitude := C.assemble (C.slow body1)
                    have hnum := hstrip.2.2.1 x hclass
                    have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                    have hround := hslow.1
                    rw [hnum.2.2.1] at hround
                    have hclear := hslow.2
                    have hnegateC : C.negate assembly = result := by
                      change ok (C.negate assembly) = ok result at hnegate
                      injection hnegate with hnegateC
                    have hresult : result = C.negate magnitude := by
                      calc
                        result = C.negate assembly := hnegateC.symm
                        _ = C.negate magnitude := by rw [← hassemblyC]
                    have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
                      calc
                        DecimalGoalVocabularyDefault.lexicalNegative x =
                            decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                        _ = true := by simp [hlist, hnegative]
                    have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                        true magnitude (C.negate magnitude) := by
                      change magnitude.val < 2 ^ 63 ∧
                        (C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
                      rw [hc.negate_all magnitude]
                      constructor
                      · exact hclear
                      · rw [if_pos hclear]
                        simp
                    have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                        (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
                        (C.negate magnitude) := by rw [hlex]; exact hsign
                    exact ⟨C.negate magnitude, magnitude,
                      congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
                · simp only [hnegative, if_neg] at hrun
                  cases hrun
                  constructor
                  · intro hclass
                    exact (hnotInvalid hclass).elim
                  constructor
                  · intro sign nan hclass
                    exact (hnotSpecial sign nan hclass).elim
                  · intro x hclass
                    let y : DecimalLexeme := { x with leadingSign := none }
                    let magnitude := C.assemble (C.slow body1)
                    have hnum := hstrip.2.2.1 x hclass
                    have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                    have hround := hslow.1
                    rw [hnum.2.2.1] at hround
                    have hclear := hslow.2
                    have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
                      calc
                        DecimalGoalVocabularyDefault.lexicalNegative x =
                            decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                        _ = false := by simp [hlist, hnegative]
                    have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                        false magnitude magnitude := by
                      change magnitude.val < 2 ^ 63 ∧
                        magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
                      constructor
                      · exact hclear
                      · simp
                    have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                        (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
                      rw [hlex]
                      exact hsign
                    have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
                        (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
                      rw [← hassemblyC]
                      exact hsignLex
                    exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
              · simp at hphase2
                rcases hphase2 with ⟨hpost, hExp, hMant, hSecond, hEqual, hForced⟩
                subst post
                simp [hfirstNegative] at hphase3
                have hselected : selected = first := by
                  exact hphase3.1.symm
                subst selected
                obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
                obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
                have hassemblyC : C.assemble first = assembly := by
                  change ok (C.assemble first) = ok assembly at hassembly
                  injection hassembly with hassemblyC
                have hsecondC : C.integer d.exponent next = second := by
                  change ok (C.integer d.exponent next) = ok second at hsecond
                  injection hsecond with hsecondC
                have hpair : first = second := by
                  have hm : first.m = second.m := by
                    by_contra h
                    simp [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq, h] at hequal
                  have hp : first.p_biased = second.p_biased := by
                    have hh : decide (first.p_biased = second.p_biased) = true := by
                      simpa [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq, hm] using hequal
                    simpa using hh
                  have hf := And.intro hm hp
                  rcases hf with ⟨hm, hp⟩
                  cases first
                  cases second
                  cases hm
                  cases hp
                  rfl
                have hnextval : next.val = d.mantissa.val + 1 := by
                  have hadd := UScalar.add_equiv d.mantissa (1#u64)
                  rw [hnext] at hadd
                  simpa using hadd.2.1
                have hbounds := hc.record_bounds body1 d hbodySource hbodyempty hparse
                have hfirstNormal := hc.integer_normal d.exponent d.mantissa
                have hfirstRound : DecimalGoalVocabularyDefault.roundsMagnitude
                    (DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
                  have hnot : ¬ (C.integer d.exponent d.mantissa).p_biased.val < 0 := by
                    rw [hfirstC]
                    exact hnotLtVal
                  rcases hfirstNormal with hneg | ⟨hr, hclear⟩
                  · exact (hnot hneg).elim
                  · simpa only [DecimalGoalVocabularyDefault, hfirstC] using hr
                have hfirstClear : (C.assemble first).val < 2 ^ 63 := by
                  have hnot : ¬ (C.integer d.exponent d.mantissa).p_biased.val < 0 := by
                    rw [hfirstC]
                    exact hnotLtVal
                  rcases hfirstNormal with hneg | ⟨hr, hclear⟩
                  · exact (hnot hneg).elim
                  · simpa [hfirstC] using hclear
                have hsecondNormal := hc.integer_normal d.exponent next
                have hsecondRound : DecimalGoalVocabularyDefault.roundsMagnitude
                    ((next.val : Real) * (10 : Real) ^ d.exponent.val)
                    (C.assemble second) := by
                  have hnot : ¬ (C.integer d.exponent next).p_biased.val < 0 := by
                    rw [hsecondC, ← hpair]
                    exact hnotLtVal
                  rcases hsecondNormal with hneg | ⟨hr, hclear⟩
                  · exact (hnot hneg).elim
                  · simpa [hsecondC] using hr
                have hsecondRound' : DecimalGoalVocabularyDefault.roundsMagnitude
                    ((((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val))
                    (C.assemble first) := by
                  rw [← hpair] at hsecondRound
                  rw [hnextval] at hsecondRound
                  exact hsecondRound
                have hupperRewrite :
                    ((next.val : Real) * (10 : Real) ^ d.exponent.val) =
                    (((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := by
                  rw [hnextval]
                have hsecondRound'' := hsecondRound
                rw [hupperRewrite] at hsecondRound''
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  have hnum := hstrip.2.2.1 x hclass
                  have hacc := hc.record_accumulated body1 y d hbodySource
                    (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
                  have hinterval :
                      DecimalGoalVocabularyDefault.decimalMagnitude d ≤
                          DecimalGoalVocabularyDefault.accumulatedMagnitude y ∧
                      DecimalGoalVocabularyDefault.accumulatedMagnitude y <
                        (((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val) := by
                    simpa [hmany] using hacc
                  have hroundMag := P616_T1_RoundingCellConvexity
                    (DecimalGoalVocabularyDefault.decimalMagnitude d)
                    (((d.mantissa.val + 1 : Nat) : Real) * (10 : Real) ^ d.exponent.val)
                    (DecimalGoalVocabularyDefault.accumulatedMagnitude y) (C.assemble first)
                    hfirstRound hsecondRound' hinterval.1 (le_of_lt hinterval.2)
                  have hround := hroundMag
                  rw [hnum.2.2.1] at hround
                  by_cases hnegative : c = 45#u8
                  · simp only [hnegative, if_pos] at hrun
                    obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
                    cases hrun
                    have hnegateC : C.negate assembly = result := by
                      change ok (C.negate assembly) = ok result at hnegate
                      injection hnegate with hnegateC
                    have hresult : result = C.negate (C.assemble first) := by
                      calc
                        result = C.negate assembly := hnegateC.symm
                        _ = C.negate (C.assemble first) := by rw [← hassemblyC]
                    have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
                      calc
                        DecimalGoalVocabularyDefault.lexicalNegative x =
                            decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                        _ = true := by simp [hlist, hnegative]
                    have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                        true (C.assemble first) (C.negate (C.assemble first)) := by
                      change (C.assemble first).val < 2 ^ 63 ∧
                        (C.negate (C.assemble first)).val =
                          (C.assemble first).val + (if true then 2 ^ 63 else 0)
                      rw [hc.negate_all]
                      constructor
                      · exact hfirstClear
                      · rw [if_pos hfirstClear]
                        simp
                    have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                        (DecimalGoalVocabularyDefault.lexicalNegative x)
                        (C.assemble first) (C.negate (C.assemble first)) := by
                      rw [hlex]
                      exact hsign
                    exact ⟨C.negate (C.assemble first), C.assemble first,
                      congrArg (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
                  · simp only [hnegative, if_neg] at hrun
                    cases hrun
                    have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
                      calc
                        DecimalGoalVocabularyDefault.lexicalNegative x =
                            decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                        _ = false := by simp [hlist, hnegative]
                    have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                        false (C.assemble first) (C.assemble first) := by
                      change (C.assemble first).val < 2 ^ 63 ∧
                        (C.assemble first).val =
                          (C.assemble first).val + (if false then 2 ^ 63 else 0)
                      constructor
                      · exact hfirstClear
                      · simp
                    have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                        (DecimalGoalVocabularyDefault.lexicalNegative x)
                        (C.assemble first) assembly := by
                      rw [hlex, ← hassemblyC]
                      exact hsign
                    exact ⟨assembly, C.assemble first, rfl, hround, hsignLex⟩
          · simp only [hmany, Bool.false_eq_true, if_false] at hphase1
            cases hphase1
            simp only [Bool.false_eq_true, if_false] at hphase2
            cases hphase2
            by_cases hfirstNegative : first.p_biased < 0#i32
            · simp only [hfirstNegative, if_pos] at hphase3
              cases hphase3
              obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
              by_cases hnegative : c = 45#u8
              · simp only [hnegative, if_pos] at hrun
                obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  let magnitude := C.assemble (C.slow body1)
                  have hnum := hstrip.2.2.1 x hclass
                  have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                  have hround := hslow.1
                  rw [hnum.2.2.1] at hround
                  have hclear := hslow.2
                  have hassemblyC : C.assemble (C.slow body1) = assembly := by
                    change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
                    injection hassembly with hassemblyC
                  have hnegateC : C.negate assembly = result := by
                    change ok (C.negate assembly) = ok result at hnegate
                    injection hnegate with hnegateC
                  have hresult : result = C.negate magnitude := by
                    calc
                      result = C.negate assembly := hnegateC.symm
                      _ = C.negate magnitude := by
                        rw [← hassemblyC]
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = true := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      true magnitude (C.negate magnitude) := by
                    change magnitude.val < 2 ^ 63 ∧
                      (C.negate magnitude).val = magnitude.val + (if true then 2 ^ 63 else 0)
                    rw [hc.negate_all magnitude]
                    constructor
                    · exact hclear
                    · rw [if_pos hclear]
                      simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude
                      (C.negate magnitude) := by
                    rw [hlex]
                    exact hsign
                  exact ⟨C.negate magnitude, magnitude, congrArg
                    (fun z => core.result.Result.Ok z) hresult, hround, hsignLex⟩
              · simp only [hnegative, if_neg] at hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  let magnitude := C.assemble (C.slow body1)
                  have hnum := hstrip.2.2.1 x hclass
                  have hslow := hc.slow_normal body1 y hbodySource rfl hnum.1 hnum.2.1
                  have hround := hslow.1
                  rw [hnum.2.2.1] at hround
                  have hclear := hslow.2
                  have hassemblyC : C.assemble (C.slow body1) = assembly := by
                    change ok (C.assemble (C.slow body1)) = ok assembly at hassembly
                    injection hassembly with hassemblyC
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = false := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      false magnitude magnitude := by
                    change magnitude.val < 2 ^ 63 ∧
                      magnitude.val = magnitude.val + (if false then 2 ^ 63 else 0)
                    constructor
                    · exact hclear
                    · simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude magnitude := by
                    rw [hlex]
                    exact hsign
                  have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude assembly := by
                    rw [← hassemblyC]
                    exact hsignLex
                  exact ⟨assembly, magnitude, rfl, hround, hsignLexAssembly⟩
            · simp only [hfirstNegative, if_neg] at hphase3
              cases hphase3
              obtain ⟨i, hi, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i1, hi1, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨i2, hi2, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembledWord, hword, hrun⟩ := bind_ok_inv _ _ _ hrun
              obtain ⟨assembly, hassembly, hrun⟩ := bind_ok_inv _ _ _ hrun
              have hassemblyC : C.assemble first = assembly := by
                change ok (C.assemble first) = ok assembly at hassembly
                injection hassembly with hassemblyC
              by_cases hnegative : c = 45#u8
              · simp only [hnegative, if_pos] at hrun
                obtain ⟨result, hnegate, hrun⟩ := bind_ok_inv _ _ _ hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  have hnum := hstrip.2.2.1 x hclass
                  have hacc := hc.record_accumulated body1 y d hbodySource
                    (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
                  have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
                      DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
                    simpa [hmany] using hacc
                  have hinteger := hc.integer_normal d.exponent d.mantissa
                  have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
                      (DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
                    have hnonneg : ¬ first.p_biased.val < 0 := by
                      simpa using hfirstNegative
                    rw [← hfirstC] at hnonneg
                    rcases hinteger with hneg | ⟨hr, hclear⟩
                    · exact (hnonneg hneg).elim
                    · simpa [hfirstC] using hr
                  have hround := hroundD
                  rw [hdecimal, hnum.2.2.1] at hround
                  have hclear : (C.assemble first).val < 2 ^ 63 := by
                    have hnonneg : ¬ first.p_biased.val < 0 := by
                      simpa using hfirstNegative
                    rw [← hfirstC] at hnonneg
                    rcases hinteger with hneg | ⟨hr, hclear⟩
                    · exact (hnonneg hneg).elim
                    · simpa [hfirstC] using hclear
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = true := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = true := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      true (C.assemble first) (C.negate (C.assemble first)) := by
                    change (C.assemble first).val < 2 ^ 63 ∧
                      (C.negate (C.assemble first)).val =
                        (C.assemble first).val + (if true then 2 ^ 63 else 0)
                    rw [hc.negate_all]
                    constructor
                    · exact hclear
                    · rw [if_pos hclear]
                      simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x)
                      (C.assemble first) (C.negate (C.assemble first)) := by
                    rw [hlex]
                    exact hsign
                  have hresult : result = C.negate (C.assemble first) := by
                    have hnegateC : C.negate assembly = result := by
                      change ok (C.negate assembly) = ok result at hnegate
                      injection hnegate with hnegateC
                    simpa [hassemblyC] using hnegateC.symm
                  exact ⟨C.negate (C.assemble first), C.assemble first,
                    congrArg (fun z => core.result.Result.Ok z) hresult,
                    hround, hsignLex⟩
              · simp only [hnegative, if_neg] at hrun
                cases hrun
                constructor
                · intro hclass
                  exact (hnotInvalid hclass).elim
                constructor
                · intro sign nan hclass
                  exact (hnotSpecial sign nan hclass).elim
                · intro x hclass
                  let y : DecimalLexeme := { x with leadingSign := none }
                  have hnum := hstrip.2.2.1 x hclass
                  have hacc := hc.record_accumulated body1 y d hbodySource
                    (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
                  have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
                      DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
                    simpa [hmany] using hacc
                  have hinteger := hc.integer_normal d.exponent d.mantissa
                  have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
                      (DecimalGoalVocabularyDefault.decimalMagnitude d) (C.assemble first) := by
                    have hnonneg : ¬ first.p_biased.val < 0 := by
                      simpa using hfirstNegative
                    rw [← hfirstC] at hnonneg
                    rcases hinteger with hneg | ⟨hr, hclear⟩
                    · exact (hnonneg hneg).elim
                    · simpa [hfirstC] using hr
                  have hround := hroundD
                  rw [hdecimal, hnum.2.2.1] at hround
                  have hclear : (C.assemble first).val < 2 ^ 63 := by
                    have hnonneg : ¬ first.p_biased.val < 0 := by
                      simpa using hfirstNegative
                    rw [← hfirstC] at hnonneg
                    rcases hinteger with hneg | ⟨hr, hclear⟩
                    · exact (hnonneg hneg).elim
                    · simpa [hfirstC] using hclear
                  have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = false := by
                    calc
                      DecimalGoalVocabularyDefault.lexicalNegative x =
                          decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                      _ = false := by simp [hlist, hnegative]
                  have hsign : DecimalGoalVocabularyDefault.signedMagnitude
                      false (C.assemble first) (C.assemble first) := by
                    change (C.assemble first).val < 2 ^ 63 ∧
                      (C.assemble first).val =
                        (C.assemble first).val + (if false then 2 ^ 63 else 0)
                    constructor
                    · exact hclear
                    · simp
                  have hsignLex : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x)
                      (C.assemble first) (C.assemble first) := by
                    rw [hlex]
                    exact hsign
                  have hsignLexAssembly : DecimalGoalVocabularyDefault.signedMagnitude
                      (DecimalGoalVocabularyDefault.lexicalNegative x)
                      (C.assemble first) assembly := by
                    rw [← hassemblyC]
                    exact hsignLex
                  exact ⟨assembly, C.assemble first, rfl, hround, hsignLexAssembly⟩
        | some value =>
          have hnative : C.native
              { d with negative := decide (c = 45#u8), many_digits := d.many_digits } = some value := by
            change ok (C.native { d with negative := decide (c = 45#u8), many_digits := d.many_digits }) =
              ok (some value) at hfast
            injection hfast with hnative
          cases hrun
          constructor
          · intro hclass
            exact (hnotInvalid hclass).elim
          constructor
          · intro sign nan hclass
            exact (hnotSpecial sign nan hclass).elim
          · intro x hclass
            let y : DecimalLexeme := { x with leadingSign := none }
            let nativeRecord : num.imp.dec2flt.decimal.Decimal :=
              { d with negative := decide (c = 45#u8), many_digits := d.many_digits }
            have hnum := hstrip.2.2.1 x hclass
            have hnativeNormal := hc.native_normal nativeRecord value hnative
            rcases hnativeNormal with ⟨hmd, hrest⟩
            rcases hrest with ⟨magnitude, hround, hsigned⟩
            have hmany : d.many_digits = false := by
              change nativeRecord.many_digits = false at hmd
              simpa [nativeRecord] using hmd
            have hacc := hc.record_accumulated body1 y d hbodySource
              (Nat.le_trans hbodyLength hA) rfl hnum.1 hnum.2.1 hparse
            have hdecimal : DecimalGoalVocabularyDefault.decimalMagnitude d =
                DecimalGoalVocabularyDefault.accumulatedMagnitude y := by
              simpa [hmany] using hacc
            have hroundD : DecimalGoalVocabularyDefault.roundsMagnitude
                (DecimalGoalVocabularyDefault.decimalMagnitude d) magnitude := by
              simpa only [DecimalGoalVocabularyDefault] using hround
            rw [hdecimal, hnum.2.2.1] at hroundD
            have hlex : DecimalGoalVocabularyDefault.lexicalNegative x = decide (c = 45#u8) := by
              calc
                DecimalGoalVocabularyDefault.lexicalNegative x =
                    decide (s.val.head? = some (45#u8)) := hnum.2.2.2.2
                _ = decide (c = 45#u8) := by simp [hlist]
            have hsigned' : DecimalGoalVocabularyDefault.signedMagnitude
                (DecimalGoalVocabularyDefault.lexicalNegative x) magnitude value := by
              rw [hlex]
              simpa only [DecimalGoalVocabularyDefault, nativeRecord] using hsigned
            exact ⟨value, magnitude, rfl, hroundD, hsigned'⟩
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 104 entries
Technical checking records
Local closure summary
{
  "node": "P616_T1_FrameCorrectness",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "81c41ad76837b03cfeca21241d48d9ae2f4f9396614477893e63775b433280fe",
  "active_statement_hash": "30a7e9e6e93641aad3cdf56323e99428a145f940da881f4b9ab4dc20e2ea6af3",
  "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": {
    "ClassificationDeterminism": "1887cc51648312b8",
    "DecimalGoalVocabularyDefault": "94cb4c406f8efb78",
    "DispatchContracts": "ae67c1a1a952d0f1",
    "P616_T1_RoundingCellConvexity": "5c69841b2c941bc4",
    "P616_T1_SignStrippedClassification": "4dbd872ba02a631e",
    "P9_T1_DispatchFrame": "1b73cde8bfea548e",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "986725aca5ee5702",
    "DecimalGoalVocabularyDefault": "3016c00221d29252",
    "DecimalLexeme": "8127b3eaeae00dd2",
    "DispatchContracts": "008abfbd503545bf",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "ModelSliceFirst": "a31394b3c1080f71",
    "ModelStrAsBytes": "024fe35b4dbfa9a3",
    "P9_T1_AbstractComponents": "0a7e8b7bdbce0180",
    "P9_T1_DispatchFrame": "20ad2431db4aaf28",
    "P9_T1_DispatchOperations": "c43614ff2149ecf2",
    "P9_T1_EmbedComponents": "c6037220641c6c08",
    "Preamble": "7a79218b23bce03e",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "7bda5de02611ad76",
    "num_imp_dec2flt_Dec2FltTrace": "f5d0731ff1ab56ce",
    "num_imp_dec2flt_Lemire": "1923f90c53d323e6",
    "num_imp_dec2flt_common_BiasedFp": "b22d5c76996d8b0d",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_decimal_Decimal": "4c41a56bf44cb31e",
    "num_imp_dec2flt_pfe_empty": "89046d1da5ac1ce2",
    "num_imp_dec2flt_pfe_invalid": "21db875427d92c6d",
    "num_imp_traits_Float": "02acccb9db3e30f2",
    "num_imp_traits_FloatExt": "f996e5400649797d"
  }
}
Prose assessment
{
  "label": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:ea02de75b595e4eec6820996dee652c8fc02066d41dc4d375c63328ff34d4324",
  "current_fingerprint": "sound-v2:ea02de75b595e4eec6820996dee652c8fc02066d41dc4d375c63328ff34d4324",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}