P687_T1_ActualEmbeddedFrameEquality

Lean checked

Statement

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

Lemma · Whole actual and embedded frame equality

For any one total package C of AbstractComponents satisfying DispatchContracts and NormalComponentRefinement, and every source-valid complete Rust string s of byte length at most A=3458764513820540928, as defined in DecimalGoalVocabularyDefault,
\mathrm{P9\_T1\_DispatchFrame}(\mathrm{P9\_T1\_ActualDispatchOperations},s) = \mathrm{P9\_T1\_DispatchFrame}(\mathrm{P9\_T1\_EmbedComponents}(C),s).
This is equality of the whole outer Result: failure and divergence as well as normal return, its Rust parsing result and every trace field. There is no actual-call or public-success premise, no additional correctness assumption, and no numeric-only or shortened-body restriction. The same C is used at every call.

Lean statement

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

import Tablet.P661_T1_PrefixRealization
import Tablet.P9_T1_DispatchFrame
import Tablet.P9_T1_EmbedComponents
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.DispatchContracts
import Tablet.P9_T1_AbstractComponents
import Tablet.P9_T1_NormalComponentRefinement
import Tablet.P9_T1_ReachedDispatchCall
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.DecimalGoalVocabularyDefault

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P687_T1_ActualEmbeddedFrameEquality]
theorem P687_T1_ActualEmbeddedFrameEquality (C : P9_T1_AbstractComponents)
    (hc : DispatchContracts C) (hr : P9_T1_NormalComponentRefinement C)
    (s : Str) (hs : DecimalGoalVocabularyDefault.sourceString s)
    (hA : s.val.length <= 3458764513820540928) :
    P9_T1_DispatchFrame P9_T1_ActualDispatchOperations s =
      P9_T1_DispatchFrame (P9_T1_EmbedComponents C) s := 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,s and the stated hypotheses of DispatchContracts, NormalComponentRefinement and DecimalGoalVocabularyDefault. Write O for the actual operation record of ActualDispatchOperations. Every operation in EmbedComponents is \mathrm{ok} of the corresponding value of C. Throughout the proof apply PrefixRealization with this fixed C, its two laws and the original complete-string source-validity and A-bound. We build its reached-call premises using exactly the constructors of ReachedDispatchCall. No invocation of that lemma uses a current-call success assumption.
We use the following elementary Result-bind rule at fixed primitive binds. For any R and continuations k,k', to prove R\mathbin{\gg=}k =R\mathbin{\gg=}k' it suffices to prove k(v)=k'(v) whenever R=\mathrm{ok}(v). Indeed, for failure both binds return the same failure, for divergence both return divergence, and for \mathrm{ok}(v) they are the two continuations at v. Also, an established equation O.f(a)=\mathrm{ok}(C.f(a)) can be substituted through any Result-valued continuation, without a success premise for that continuation. These rules preserve complete returned pairs, not merely their first projections.
Unfold the fixed finite frame of DispatchFrame on both sides. ModelStrAsBytes supplies the identical slice s, and ModelSliceFirst supplies its optional head. On an empty list the two remaining expressions, including the empty-error primitive and EmptyInput trace, are identical, so their whole Results agree. Otherwise write s.\mathit{val}=c::t. The two frames use the same \nu=\operatorname{decide}(c=45) and the same conditional range-index expression. In either sign case the range starts at one and 1\leq|s| follows from this cons equation. The installed Aeneas range-index definition therefore returns the slice whose list is s.\mathit{val}.\mathrm{drop}(1)=t. If c is neither 45 nor 43, the body is s itself. Thus the common body b satisfies
b.\mathit{val}= \begin{cases}t&c=45\text{ or }c=43,\\s.\mathit{val}&\text{otherwise}. \end{cases}
The installed slice-empty definition returns the Boolean of b's length being zero. If b is empty, both continuations are the identical invalid error primitive followed by SignOnly(b,\nu); their whole Results agree. If b is nonempty, the cons equation, displayed body equation and this nonemptiness construct the number reach derivation. The number clause of PrefixRealization now gives O.\mathrm{parseNumber}(b)=\mathrm{ok}(C.\mathrm{parseNumber}(b)). Substitute this equation in the actual frame and split the common option.
If it is None, the just established actual None equation and the number reach derivation construct special reach. The special clause of PrefixRealization gives the normal special equation with the same body and separate \nu. Substitution aligns both special options. On special None both expressions use the same invalid-error primitive, Rust Err and Invalid trace with both helper options None. On special Some v, both return Rust Ok of v and the same Special trace containing b,\nu, numeric None, special Some and v. These are direct returns: neither side selects a pair, assembles it or negates v again.
If the numeric option is Some d, its established actual Some equation constructs native reach. The native clause of PrefixRealization gives actual normal agreement with C.\mathrm{native}(\{d\text{ with negative}:=\nu\}). This is precisely the signed record in both frames, with every other field unchanged. On native Some v, both return Rust Ok of v and the same FastPath trace, including the numeric Some, signed native input and native Some. Again the return is direct and performs no final negation. On native None, its actual equation constructs first-integer reach. The first clause supplies the actual equation to f_1=C.\mathrm{integer}(d.e,d.w), at the original exponent and mantissa. Substitution aligns the first result and the initial five-field tuple.
If d.\mathit{many\_digits} is false, the tuple has false many flags and false second guard, and the six-field second-stage tuple is (f_1,\mathrm{None},\mathrm{None},\mathrm{None},\mathrm{None},\mathrm{false}) on both sides. The first equation and the false guard construct post-direct reach to f_1. If many_digits is true but f_1.p_{\rm biased}<0, the many flags are true, the second guard is still false, and the same six-field tuple and post-direct reach result. The scalar comparisons here coincide with the comparisons of the I32 values, so these cases are exactly the negation of the increment constructor's conjunction.
In the remaining case many_digits is true and f_1.p_{\rm biased}\geq0. Use this exact guard and the established first equation to construct increment reach. The increment clause of PrefixRealization supplies d.w<10^{19} and an actual checked normal successor n with d.w+1=\mathrm{ok}(n) and n.\mathit{val}=d.w.\mathit{val}+1. Substitute this SAME checked-addition equation on both sides; no modular successor or overflow-to-deferral branch is substituted. Only now construct second reach. Its prefix clause gives O.\mathrm{integer}(d.e,n)=\mathrm{ok}(C.\mathrm{integer}(d.e,n)). Put f_2=C.\mathrm{integer}(d.e,n) and substitute this equation before constructing compare reach. The compare clause gives the normal Boolean
\epsilon=\operatorname{decide}(f_1.m=f_2.m\ \land\ f_1.p_{\rm biased}=f_2.p_{\rm biased}).
Thus both complete fields are compared, not just the exponent or the assembled rounding value. Substitute that comparison equation. The pair/forced-flag tuple is (f_1,\mathrm{false}) when \epsilon is true and (\{f_1\text{ with }p_{\rm biased}:=-1\},\mathrm{true}) otherwise. Inverting its normal tuple equation identifies the post pair with exactly this conditional. The compare reach and comparison equation construct post-compared reach. Both six-field tuples now contain this same post pair, Some d.e, Some n, Some f_2, Some \epsilon, and the same forced flag. In particular forced deferral changes only the first pair's exponent to -1.
For either post constructor let p be its reached post pair. If p.p_{\rm biased}<0, construct slow reach from this guard, then use the slow clause of PrefixRealization to obtain O.\mathrm{slow}(b)=\mathrm{ok}(C.\mathrm{slow}(b)) on the UNCHANGED body. It supplies this current-call equation, rather than a conclusion conditional on slow success. Substitution makes both selection tuples (C.\mathrm{slow}(b),\mathrm{true},\mathrm{Some}(C.\mathrm{slow}(b))). Only after this equation construct assemble-slow reach to that selected pair. If the post exponent is nonnegative, both selection tuples are (p,\mathrm{false},\mathrm{None}) and the same guard constructs assemble-direct reach. These two cases also prove selection transport for arbitrary continuations that agree at each such reached assembly input.
Let a be either common selected pair. The raw I32-to-U64 cast, the fixed SIG_BITS computation, the checked shift and the raw OR lift appearing before assembly in DispatchFrame have identical expressions and inputs. Apply the Result-bind rule successively to these four binds. A failure or divergence at any one is preserved automatically; in a normal continuation their common values give the identical assembled_word field. Equality does not require a new no-failure premise or a new range estimate for these fixed primitives.
At the reached assembly call, PrefixRealization gives O.\mathrm{assemble}(a)=\mathrm{ok}(C.\mathrm{assemble}(a)). Write m=C.\mathrm{assemble}(a) and substitute. If c\ne45, both frames return this word with false negative and lexical_sign_applied flags. If c=45, the assembly reach has sign true, and the actual assembly equation just proved constructs negate reach at m. The negate clause of the same prefix lemma gives m.\mathit{val}<2^{63} and O.\mathrm{negate}(m)=\mathrm{ok}(C.\mathrm{negate}(m)). Substitution aligns the final word and the true lexical-sign flags.
In either assembled case, the complete Assembled record fields agree: body, negative flag, numeric option with its retained many flag, signed native input and native None, first operands and result, second guard and all optional operands/results, both-field comparison, forced-deferral flag, post pair, slow guard and optional replacement, selected pair, assembled_word, pre-sign assembly word, lexical_sign_applied and final word. All earlier tuple projections are the same on both sides, so record construction gives literal equality of the traces and their Rust results. The fixed primitive-bind rule also preserves every outer non-normal outcome. The exhaustive finite branch analysis therefore proves the displayed whole-Result equality without presupposing its normality.

Lean proof


  classical
  have realize := P661_T1_PrefixRealization C hc hr s hs hA
  have finish {α : Type} (body : Slice Std.U8) (c : Std.U8)
      (d : num.imp.dec2flt.decimal.Decimal) (selected : num.imp.dec2flt.common.BiasedFp)
      (reach : P9_T1_ReachedDispatchCall s (.assemble body (c = 45#u8) d selected))
      (kn : F64 → F64 → Result α) (kp : F64 → Result α) :
      (do
        let magnitude ← P9_T1_ActualDispatchOperations.assemble selected
        if c = 45#u8 then do
          let result ← P9_T1_ActualDispatchOperations.negate magnitude
          kn magnitude result
        else kp magnitude) =
      (if c = 45#u8 then kn (C.assemble selected) (C.negate (C.assemble selected))
       else kp (C.assemble selected)) := by
    have ha := realize (.assemble body (c = 45#u8) d selected) reach
    rw [ha, bind_tc_ok]
    by_cases hm : c = 45#u8
    · have reach' : P9_T1_ReachedDispatchCall s (.assemble body true d selected) := by
        simpa only [hm, decide_true] using reach
      have rn := P9_T1_ReachedDispatchCall.negate body d selected (C.assemble selected) reach' ha
      have hn := (realize (.negate body d selected (C.assemble selected)) rn).2
      simp only [hm, if_true, hn, bind_tc_ok]
    · simp only [hm, if_false]
  have select_transport {α : Type} (body : Slice Std.U8) (c : Std.U8)
      (d : num.imp.dec2flt.decimal.Decimal) (post : num.imp.dec2flt.common.BiasedFp)
      (reach : P9_T1_ReachedDispatchCall s (.post body (c = 45#u8) d post))
      (ka ke : (num.imp.dec2flt.common.BiasedFp × Bool ×
        Option num.imp.dec2flt.common.BiasedFp) → Result α)
      (hk : forall selected guard slow,
        P9_T1_ReachedDispatchCall s (.assemble body (c = 45#u8) d selected) →
        ka (selected, guard, slow) = ke (selected, guard, slow)) :
      Bind.bind
        (
          if post.p_biased < 0#i32 then do
            let replacement ← P9_T1_ActualDispatchOperations.slow body
            ok (replacement, true, some replacement)
          else ok (post, false, none)) ka =
      Bind.bind
        (
          if post.p_biased < 0#i32 then ok (C.slow body, true, some (C.slow body))
          else ok (post, false, none)) ke := by
    by_cases hp : post.p_biased < 0#i32
    · have hval : post.p_biased.val < 0 := by simpa using hp
      have rs := P9_T1_ReachedDispatchCall.slow body (c = 45#u8) d post reach hval
      have hslow := (realize (.slow body (c = 45#u8) d post) rs).2.2.2.2
      have ra := P9_T1_ReachedDispatchCall.assemble_slow body (c = 45#u8) d
        post (C.slow body) rs hslow
      simp only [hp, if_true, hslow, bind_tc_ok]
      exact hk _ _ _ ra
    · have hval : 0 <= post.p_biased.val := by
        have : ¬ post.p_biased.val < 0 := by simpa using hp
        omega
      have ra := P9_T1_ReachedDispatchCall.assemble_direct body (c = 45#u8) d post reach hval
      simp only [hp, if_false, bind_tc_ok]
      exact hk _ _ _ ra
  unfold P9_T1_DispatchFrame
  rw [bind_eq_iff]
  intro bytes hbytes
  have heq : bytes = s := by
    simpa only [core.str.Str.as_bytes, ModelStrAsBytes, Result.ok.injEq] using hbytes.symm
  subst bytes
  rw [bind_eq_iff]
  intro head hhead
  have heq : 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 => rfl
  | cons c tail =>
    simp only [List.head?_cons]
    rw [bind_eq_iff]
    intro body hbody
    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 : body.val = if c = 45#u8 ∨ c = 43#u8 then tail else s.val := by
      by_cases hm : c = 45#u8
      · simp [hm, hindex] at hbody
        subst body
        simp [Slice.drop, hlist, hm]
      · by_cases hp : c = 43#u8
        · simp [hp, hindex] at hbody
          subst body
          simp [Slice.drop, hlist, hp]
        · simp only [hm, hp, ite_false, Result.ok.injEq] at hbody
          subst body
          simp [hm, hp]
    rw [bind_eq_iff]
    intro empty hempty
    have heq : empty = decide (body.val = []) := by
      simpa only [core.slice.Slice.is_empty, Slice.length, List.length_eq_zero_iff,
        Result.ok.injEq] using hempty.symm
    subst empty
    by_cases hne : body.val = []
    · simp only [hne, decide_true, ite_true]
    · simp only [hne, decide_false, Bool.false_eq_true, ite_false]
      have rn := P9_T1_ReachedDispatchCall.number c tail body hlist hbodyval hne
      have hn := (realize (.number body (c = 45#u8)) rn).2.2.2
      rw [hn]
      simp only [P9_T1_EmbedComponents, bind_tc_ok]
      cases hnum : C.parseNumber body with
      | none =>
        dsimp only
        have rn0 : P9_T1_ActualDispatchOperations.parseNumber body = ok none := hn.trans (by rw [hnum])
        have rs := P9_T1_ReachedDispatchCall.special body (c = 45#u8) rn rn0
        have hsp := (realize (.special body (c = 45#u8)) rs).2.2.2
        rw [hsp, bind_tc_ok]
      | some d =>
        dsimp only
        have rn1 : P9_T1_ActualDispatchOperations.parseNumber body = ok (some d) := hn.trans (by rw [hnum])
        have rnative := P9_T1_ReachedDispatchCall.native body (c = 45#u8) d rn rn1
        have hnat := (realize (.native body (c = 45#u8) d) rnative).2.2.2.2.2
        rw [hnat, bind_tc_ok]
        cases hnative : C.native { d with negative := (c = 45#u8) } with
        | some value => rfl
        | none =>
          dsimp only
          have rnat0 : P9_T1_ActualDispatchOperations.native { d with negative := (c = 45#u8) } = ok none :=
            hnat.trans (by rw [hnative])
          have rfirst := P9_T1_ReachedDispatchCall.first body (c = 45#u8) d rnative rnat0
          have hf := (realize (.first body (c = 45#u8) d) rfirst).2.2.2.2
          rw [hf, bind_tc_ok]
          rw [bind_eq_iff]
          rintro ⟨many1, many2, first, fp, secondGuard⟩ hstage
          cases hd : d.many_digits with
          | false =>
            simp only [hd, Bool.false_eq_true, if_false] at hstage
            cases hstage
            simp only [Aeneas.Std.uncurry]
            simp only [Bool.false_eq_true, if_false]
            rw [bind_eq_iff]
            rintro ⟨post, secondExponent, secondMantissa, secondResult, secondEqual, forced⟩ hpoststage
            cases hpoststage
            simp only [Aeneas.Std.uncurry]
            have rpost := P9_T1_ReachedDispatchCall.post_direct body (c = 45#u8) d
              (C.integer d.exponent d.mantissa) rfirst hf (by simp [hd])
            refine select_transport body c d (C.integer d.exponent d.mantissa) rpost _ _ ?_
            intro selected guard slow reach
            simp only [Aeneas.Std.uncurry]
            repeat' (rw [bind_eq_iff]; intro _ _)
            exact finish body c d selected reach _ _
          | true =>
            simp only [hd, if_true] at hstage
            cases hstage
            simp only [Aeneas.Std.uncurry]
            by_cases hp : (C.integer d.exponent d.mantissa).p_biased >= 0#i32
            · simp only [hp, decide_true, if_true]
              have hval : 0 <= (C.integer d.exponent d.mantissa).p_biased.val := by simpa using hp
              have ri := P9_T1_ReachedDispatchCall.increment body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) rfirst hf ⟨hd, hval⟩
              obtain ⟨next, hadd, hnext⟩ :=
                (realize (.increment body (c = 45#u8) d (C.integer d.exponent d.mantissa)) ri).2
              simp only [bind_assoc_eq, hadd, bind_tc_ok]
              have rsecond := P9_T1_ReachedDispatchCall.second body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) next ri hadd
              have hsecond := (realize (.second body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) next) rsecond).2
              simp only [hsecond, bind_tc_ok]
              have rcompare := P9_T1_ReachedDispatchCall.compare body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) (C.integer d.exponent next) next rsecond hsecond
              have hcompare := realize (.compare body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) (C.integer d.exponent next)) rcompare
              simp only [hcompare, bind_tc_ok]
              rw [bind_eq_iff]
              rintro ⟨post, forced⟩ hpair
              simp only [Aeneas.Std.uncurry]
              have hpost : post =
                  (if decide ((C.integer d.exponent d.mantissa).m = (C.integer d.exponent next).m ∧
                    (C.integer d.exponent d.mantissa).p_biased = (C.integer d.exponent next).p_biased)
                   then C.integer d.exponent d.mantissa
                   else { C.integer d.exponent d.mantissa with p_biased := (-1)#i32 }) := by
                generalize heq : decide ((C.integer d.exponent d.mantissa).m = (C.integer d.exponent next).m ∧
                  (C.integer d.exponent d.mantissa).p_biased = (C.integer d.exponent next).p_biased) = equal at hpair ⊢
                cases equal <;> simp only [Bool.false_eq_true, if_false, if_true,
                  Result.ok.injEq, Prod.mk.injEq] at hpair ⊢ <;> exact hpair.1.symm
              have rpost' := P9_T1_ReachedDispatchCall.post_compared body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) (C.integer d.exponent next)
                (decide ((C.integer d.exponent d.mantissa).m = (C.integer d.exponent next).m ∧
                  (C.integer d.exponent d.mantissa).p_biased = (C.integer d.exponent next).p_biased))
                rcompare hcompare
              have rpost : P9_T1_ReachedDispatchCall s (.post body (c = 45#u8) d post) := hpost ▸ rpost'
              rw [bind_eq_iff]
              rintro ⟨post2, secondExponent, secondMantissa, secondResult, secondEqual, forced2⟩ hpoststage
              cases hpoststage
              simp only [Aeneas.Std.uncurry]
              refine select_transport body c d post rpost _ _ ?_
              intro selected guard slow reach
              simp only [Aeneas.Std.uncurry]
              repeat' (rw [bind_eq_iff]; intro _ _)
              exact finish body c d selected reach _ _
            · simp only [hp, decide_false, Bool.false_eq_true, if_false]
              rw [bind_eq_iff]
              rintro ⟨post, secondExponent, secondMantissa, secondResult, secondEqual, forced⟩ hpoststage
              cases hpoststage
              simp only [Aeneas.Std.uncurry]
              have hval : ¬ 0 <= (C.integer d.exponent d.mantissa).p_biased.val := by simpa using hp
              have rpost := P9_T1_ReachedDispatchCall.post_direct body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) rfirst hf (by simp only [hd, true_and]; exact hval)
              refine select_transport body c d (C.integer d.exponent d.mantissa) rpost _ _ ?_
              intro selected guard slow reach
              simp only [Aeneas.Std.uncurry]
              repeat' (rw [bind_eq_iff]; intro _ _)
              exact finish body c d selected reach _ _

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P661_T1_PrefixRealization
import Tablet.P9_T1_DispatchFrame
import Tablet.P9_T1_EmbedComponents
import Tablet.ModelStrAsBytes
import Tablet.ModelSliceFirst
import Tablet.DispatchContracts
import Tablet.P9_T1_AbstractComponents
import Tablet.P9_T1_NormalComponentRefinement
import Tablet.P9_T1_ReachedDispatchCall
import Tablet.P9_T1_ActualDispatchOperations
import Tablet.DecimalGoalVocabularyDefault

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P687_T1_ActualEmbeddedFrameEquality]
theorem P687_T1_ActualEmbeddedFrameEquality (C : P9_T1_AbstractComponents)
    (hc : DispatchContracts C) (hr : P9_T1_NormalComponentRefinement C)
    (s : Str) (hs : DecimalGoalVocabularyDefault.sourceString s)
    (hA : s.val.length <= 3458764513820540928) :
    P9_T1_DispatchFrame P9_T1_ActualDispatchOperations s =
      P9_T1_DispatchFrame (P9_T1_EmbedComponents C) s := by
-- BODY
  classical
  have realize := P661_T1_PrefixRealization C hc hr s hs hA
  have finish {α : Type} (body : Slice Std.U8) (c : Std.U8)
      (d : num.imp.dec2flt.decimal.Decimal) (selected : num.imp.dec2flt.common.BiasedFp)
      (reach : P9_T1_ReachedDispatchCall s (.assemble body (c = 45#u8) d selected))
      (kn : F64 → F64 → Result α) (kp : F64 → Result α) :
      (do
        let magnitude ← P9_T1_ActualDispatchOperations.assemble selected
        if c = 45#u8 then do
          let result ← P9_T1_ActualDispatchOperations.negate magnitude
          kn magnitude result
        else kp magnitude) =
      (if c = 45#u8 then kn (C.assemble selected) (C.negate (C.assemble selected))
       else kp (C.assemble selected)) := by
    have ha := realize (.assemble body (c = 45#u8) d selected) reach
    rw [ha, bind_tc_ok]
    by_cases hm : c = 45#u8
    · have reach' : P9_T1_ReachedDispatchCall s (.assemble body true d selected) := by
        simpa only [hm, decide_true] using reach
      have rn := P9_T1_ReachedDispatchCall.negate body d selected (C.assemble selected) reach' ha
      have hn := (realize (.negate body d selected (C.assemble selected)) rn).2
      simp only [hm, if_true, hn, bind_tc_ok]
    · simp only [hm, if_false]
  have select_transport {α : Type} (body : Slice Std.U8) (c : Std.U8)
      (d : num.imp.dec2flt.decimal.Decimal) (post : num.imp.dec2flt.common.BiasedFp)
      (reach : P9_T1_ReachedDispatchCall s (.post body (c = 45#u8) d post))
      (ka ke : (num.imp.dec2flt.common.BiasedFp × Bool ×
        Option num.imp.dec2flt.common.BiasedFp) → Result α)
      (hk : forall selected guard slow,
        P9_T1_ReachedDispatchCall s (.assemble body (c = 45#u8) d selected) →
        ka (selected, guard, slow) = ke (selected, guard, slow)) :
      Bind.bind
        (
          if post.p_biased < 0#i32 then do
            let replacement ← P9_T1_ActualDispatchOperations.slow body
            ok (replacement, true, some replacement)
          else ok (post, false, none)) ka =
      Bind.bind
        (
          if post.p_biased < 0#i32 then ok (C.slow body, true, some (C.slow body))
          else ok (post, false, none)) ke := by
    by_cases hp : post.p_biased < 0#i32
    · have hval : post.p_biased.val < 0 := by simpa using hp
      have rs := P9_T1_ReachedDispatchCall.slow body (c = 45#u8) d post reach hval
      have hslow := (realize (.slow body (c = 45#u8) d post) rs).2.2.2.2
      have ra := P9_T1_ReachedDispatchCall.assemble_slow body (c = 45#u8) d
        post (C.slow body) rs hslow
      simp only [hp, if_true, hslow, bind_tc_ok]
      exact hk _ _ _ ra
    · have hval : 0 <= post.p_biased.val := by
        have : ¬ post.p_biased.val < 0 := by simpa using hp
        omega
      have ra := P9_T1_ReachedDispatchCall.assemble_direct body (c = 45#u8) d post reach hval
      simp only [hp, if_false, bind_tc_ok]
      exact hk _ _ _ ra
  unfold P9_T1_DispatchFrame
  rw [bind_eq_iff]
  intro bytes hbytes
  have heq : bytes = s := by
    simpa only [core.str.Str.as_bytes, ModelStrAsBytes, Result.ok.injEq] using hbytes.symm
  subst bytes
  rw [bind_eq_iff]
  intro head hhead
  have heq : 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 => rfl
  | cons c tail =>
    simp only [List.head?_cons]
    rw [bind_eq_iff]
    intro body hbody
    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 : body.val = if c = 45#u8 ∨ c = 43#u8 then tail else s.val := by
      by_cases hm : c = 45#u8
      · simp [hm, hindex] at hbody
        subst body
        simp [Slice.drop, hlist, hm]
      · by_cases hp : c = 43#u8
        · simp [hp, hindex] at hbody
          subst body
          simp [Slice.drop, hlist, hp]
        · simp only [hm, hp, ite_false, Result.ok.injEq] at hbody
          subst body
          simp [hm, hp]
    rw [bind_eq_iff]
    intro empty hempty
    have heq : empty = decide (body.val = []) := by
      simpa only [core.slice.Slice.is_empty, Slice.length, List.length_eq_zero_iff,
        Result.ok.injEq] using hempty.symm
    subst empty
    by_cases hne : body.val = []
    · simp only [hne, decide_true, ite_true]
    · simp only [hne, decide_false, Bool.false_eq_true, ite_false]
      have rn := P9_T1_ReachedDispatchCall.number c tail body hlist hbodyval hne
      have hn := (realize (.number body (c = 45#u8)) rn).2.2.2
      rw [hn]
      simp only [P9_T1_EmbedComponents, bind_tc_ok]
      cases hnum : C.parseNumber body with
      | none =>
        dsimp only
        have rn0 : P9_T1_ActualDispatchOperations.parseNumber body = ok none := hn.trans (by rw [hnum])
        have rs := P9_T1_ReachedDispatchCall.special body (c = 45#u8) rn rn0
        have hsp := (realize (.special body (c = 45#u8)) rs).2.2.2
        rw [hsp, bind_tc_ok]
      | some d =>
        dsimp only
        have rn1 : P9_T1_ActualDispatchOperations.parseNumber body = ok (some d) := hn.trans (by rw [hnum])
        have rnative := P9_T1_ReachedDispatchCall.native body (c = 45#u8) d rn rn1
        have hnat := (realize (.native body (c = 45#u8) d) rnative).2.2.2.2.2
        rw [hnat, bind_tc_ok]
        cases hnative : C.native { d with negative := (c = 45#u8) } with
        | some value => rfl
        | none =>
          dsimp only
          have rnat0 : P9_T1_ActualDispatchOperations.native { d with negative := (c = 45#u8) } = ok none :=
            hnat.trans (by rw [hnative])
          have rfirst := P9_T1_ReachedDispatchCall.first body (c = 45#u8) d rnative rnat0
          have hf := (realize (.first body (c = 45#u8) d) rfirst).2.2.2.2
          rw [hf, bind_tc_ok]
          rw [bind_eq_iff]
          rintro ⟨many1, many2, first, fp, secondGuard⟩ hstage
          cases hd : d.many_digits with
          | false =>
            simp only [hd, Bool.false_eq_true, if_false] at hstage
            cases hstage
            simp only [Aeneas.Std.uncurry]
            simp only [Bool.false_eq_true, if_false]
            rw [bind_eq_iff]
            rintro ⟨post, secondExponent, secondMantissa, secondResult, secondEqual, forced⟩ hpoststage
            cases hpoststage
            simp only [Aeneas.Std.uncurry]
            have rpost := P9_T1_ReachedDispatchCall.post_direct body (c = 45#u8) d
              (C.integer d.exponent d.mantissa) rfirst hf (by simp [hd])
            refine select_transport body c d (C.integer d.exponent d.mantissa) rpost _ _ ?_
            intro selected guard slow reach
            simp only [Aeneas.Std.uncurry]
            repeat' (rw [bind_eq_iff]; intro _ _)
            exact finish body c d selected reach _ _
          | true =>
            simp only [hd, if_true] at hstage
            cases hstage
            simp only [Aeneas.Std.uncurry]
            by_cases hp : (C.integer d.exponent d.mantissa).p_biased >= 0#i32
            · simp only [hp, decide_true, if_true]
              have hval : 0 <= (C.integer d.exponent d.mantissa).p_biased.val := by simpa using hp
              have ri := P9_T1_ReachedDispatchCall.increment body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) rfirst hf ⟨hd, hval⟩
              obtain ⟨next, hadd, hnext⟩ :=
                (realize (.increment body (c = 45#u8) d (C.integer d.exponent d.mantissa)) ri).2
              simp only [bind_assoc_eq, hadd, bind_tc_ok]
              have rsecond := P9_T1_ReachedDispatchCall.second body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) next ri hadd
              have hsecond := (realize (.second body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) next) rsecond).2
              simp only [hsecond, bind_tc_ok]
              have rcompare := P9_T1_ReachedDispatchCall.compare body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) (C.integer d.exponent next) next rsecond hsecond
              have hcompare := realize (.compare body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) (C.integer d.exponent next)) rcompare
              simp only [hcompare, bind_tc_ok]
              rw [bind_eq_iff]
              rintro ⟨post, forced⟩ hpair
              simp only [Aeneas.Std.uncurry]
              have hpost : post =
                  (if decide ((C.integer d.exponent d.mantissa).m = (C.integer d.exponent next).m ∧
                    (C.integer d.exponent d.mantissa).p_biased = (C.integer d.exponent next).p_biased)
                   then C.integer d.exponent d.mantissa
                   else { C.integer d.exponent d.mantissa with p_biased := (-1)#i32 }) := by
                generalize heq : decide ((C.integer d.exponent d.mantissa).m = (C.integer d.exponent next).m ∧
                  (C.integer d.exponent d.mantissa).p_biased = (C.integer d.exponent next).p_biased) = equal at hpair ⊢
                cases equal <;> simp only [Bool.false_eq_true, if_false, if_true,
                  Result.ok.injEq, Prod.mk.injEq] at hpair ⊢ <;> exact hpair.1.symm
              have rpost' := P9_T1_ReachedDispatchCall.post_compared body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) (C.integer d.exponent next)
                (decide ((C.integer d.exponent d.mantissa).m = (C.integer d.exponent next).m ∧
                  (C.integer d.exponent d.mantissa).p_biased = (C.integer d.exponent next).p_biased))
                rcompare hcompare
              have rpost : P9_T1_ReachedDispatchCall s (.post body (c = 45#u8) d post) := hpost ▸ rpost'
              rw [bind_eq_iff]
              rintro ⟨post2, secondExponent, secondMantissa, secondResult, secondEqual, forced2⟩ hpoststage
              cases hpoststage
              simp only [Aeneas.Std.uncurry]
              refine select_transport body c d post rpost _ _ ?_
              intro selected guard slow reach
              simp only [Aeneas.Std.uncurry]
              repeat' (rw [bind_eq_iff]; intro _ _)
              exact finish body c d selected reach _ _
            · simp only [hp, decide_false, Bool.false_eq_true, if_false]
              rw [bind_eq_iff]
              rintro ⟨post, secondExponent, secondMantissa, secondResult, secondEqual, forced⟩ hpoststage
              cases hpoststage
              simp only [Aeneas.Std.uncurry]
              have hval : ¬ 0 <= (C.integer d.exponent d.mantissa).p_biased.val := by simpa using hp
              have rpost := P9_T1_ReachedDispatchCall.post_direct body (c = 45#u8) d
                (C.integer d.exponent d.mantissa) rfirst hf (by simp only [hd, true_and]; exact hval)
              refine select_transport body c d (C.integer d.exponent d.mantissa) rpost _ _ ?_
              intro selected guard slow reach
              simp only [Aeneas.Std.uncurry]
              repeat' (rw [bind_eq_iff]; intro _ _)
              exact finish body c d selected reach _ _

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (198)
More program dependencies (156)
Standard-library dependencies (39)

Related source and models come from the extraction records and declared dependencies.

Proof assumptions and review

Lean checks the formal proof. Trellis also reviews how the statement corresponds to the intended requirement.

Transitive assumptions

This list combines the assumptions recorded for this declaration and its dependencies. It may include assumptions used by auxiliary declarations in those modules.

Helper theorems included
All 307 entries
Technical checking records
Local closure summary
{
  "node": "P687_T1_ActualEmbeddedFrameEquality",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "f1fb98bc9dd1ebb9e99f508a5aff398dd3dbee86e991c8668beab5a9de3bd056",
  "active_statement_hash": "30f0507e3a6f2c79d9870e4661fe8338efdb25a65b99fbdd9a1d0f85d47cb9fc",
  "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-200",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "P661_T1_PrefixRealization": "d16c80e7b6e71737",
    "P9_T1_DispatchFrame": "f3e7d4ffbf9b4d68",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "65227461bf3cac06",
    "DecimalGoalVocabularyDefault": "71a18a6c119a3cdc",
    "DecimalLexeme": "c43614ff2149ecf2",
    "DispatchContracts": "008abfbd503545bf",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "ModelSliceFirst": "a31394b3c1080f71",
    "ModelStrAsBytes": "024fe35b4dbfa9a3",
    "P661_T1_PrefixRealization": "397d926a710930c4",
    "P9_T1_AbstractComponents": "0a7e8b7bdbce0180",
    "P9_T1_ActualDispatchOperations": "d8bf51ebbbf153ac",
    "P9_T1_DispatchCall": "25dcebcaf4f1f844",
    "P9_T1_DispatchFrame": "5665189e0304a27e",
    "P9_T1_DispatchOperations": "c43614ff2149ecf2",
    "P9_T1_EmbedComponents": "c6037220641c6c08",
    "P9_T1_NormalComponentRefinement": "008abfbd503545bf",
    "P9_T1_ReachedDispatchCall": "ed7526a12336d5a7",
    "Preamble": "7a79218b23bce03e",
    "SourceValidByteSlice": "3dc42716a6378d26",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "644abe66cec8ac98",
    "num_imp_dec2flt_Dec2FltTrace": "f5d0731ff1ab56ce",
    "num_imp_dec2flt_Lemire": "1923f90c53d323e6",
    "num_imp_dec2flt_common_BiasedFp": "31d81cf1cf22709f",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_decimal_Decimal": "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": "Lean proof closed; predictive prose review no longer required",
  "assessment_status": null,
  "fingerprint_relation": "unknown",
  "assessment_fingerprint": null,
  "current_fingerprint": "sound-v2:8d1789e7bba5b3eda6450b3d9cf9fa1bbc3ac8b327084d04af6c3ba9a03684b9",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}