ParserSlowControlFlow

Lean checked

Statement

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

Lemma · Slow-guard control-flow certificate

Suppose the traced dispatcher is invoked on a source-valid string s, returns successfully with an assembled record t, its slow-path guard is true, and parsing t.\mathit{body} returns the numeric record r. Suppose also that a true many_digits field implies r.\mathit{mantissa}>0. Then
-342\le r.\mathit{exponent}\le308,
and there is a decimal sequence d such that parse_decimal_seq(t.body)=ok d and parse_long_mantissa(t.body)=ok t.selected\_pair for the concrete binary64 trait instance.

Lean statement

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

import Tablet.DecimalGoalVocabularyDefault
import Tablet.ParserExponentConstants
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.num_imp_dec2flt_Dec2FltAssemblyTrace
import Tablet.num_imp_dec2flt_biased_fp_to_float
import Tablet.num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq
import Tablet.num_imp_dec2flt_common_BiasedFp_zero_pow2
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq
import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserSlowControlFlow]
theorem ParserSlowControlFlow :
    forall (s : Str) (f : F64)
      (tr : num.imp.dec2flt.Dec2FltAssemblyTrace F64)
      (r : num.imp.dec2flt.decimal.Decimal),
      DecimalGoalVocabularyDefault.sourceString s ->
      num.imp.dec2flt.dec2flt_with_trace
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s =
          ok (core.result.Result.Ok f,
            num.imp.dec2flt.Dec2FltTrace.Assembled tr) ->
      tr.slow_path_guard = true ->
      num.imp.dec2flt.parse.parse_number tr.body = ok (some r) ->
      (r.many_digits = true -> 0 < r.mantissa.val) ->
      -342 <= r.exponent.val /\ r.exponent.val <= 308 /\
        exists d : num.imp.dec2flt.decimal_seq.DecimalSeq,
          num.imp.dec2flt.decimal_seq.parse_decimal_seq tr.body = ok d /\
          num.imp.dec2flt.slow.parse_long_mantissa
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 tr.body =
              ok tr.selected_pair := 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.

Earlier prose review

An earlier review questioned the prose argument. Lean subsequently checked the formal proof. Review of the statement’s intended meaning is a separate judgment.

Proof

Unfold num imp dec2flt dec2flt with trace along the assumed normal return. Every failed bind would propagate a failed Result, so all binds on this execution return normally. The supplied parse equation and determinism of the extracted function identify its record with the record used by the dispatcher. The assembled constructor rules out the native fast-result arm. Hence the first integer call is exactly
\texttt{compute\_float}(r.\mathit{exponent},r.\mathit{mantissa}).
We prove the exponent bounds by contradiction. By ParserExponentConstants, the concrete smallest and largest decimal powers read by num imp dec2flt lemire compute float are -342 and 308, and its infinite biased exponent is 2047. Unfolding num imp dec2flt common BiasedFp zero pow2 at biased exponents zero and 2047 gives exactly the fixed zero and infinity pairs, each with mantissa zero and with its stated biased exponent. If the mantissa is zero, the first branch of the compute definition returns the fixed zero pair. If the mantissa is nonzero and r.\mathit{exponent}<-342, the next cutoff branch returns that same zero pair. If the mantissa is nonzero and r.\mathit{exponent}>308, the upper cutoff branch returns the fixed infinity pair, whose biased exponent is 2047. Thus outside the closed interval the first pair always has nonnegative biased exponent.
If many_digits is false, the dispatcher does not make an adjacent call and uses this fixed pair directly. If it is true, nonnegativity enables the adjacent call with mantissa plus one. Normal return of the surrounding dispatcher discharges the checked increment. The added premise makes the original mantissa nonzero in this branch, and its successor is nonzero as well. For the same out-of-range exponent, both compute calls therefore reach the same exponent cutoff and return the same fixed zero or infinity pair. Unfolding num imp dec2flt common BiasedFp Insts CoreCmpPartialEqBiasedFp eq at either identical concrete pair makes the mantissa comparison true and then the biased-exponent comparison true. The extracted adjacent-pair equality test is therefore true, so the post-comparison pair is again that fixed pair rather than the forced -1-exponent sentinel. In both many and non-many cases its biased exponent is nonnegative. The following test post_comparison_pair.p_biased < 0 is false, forcing slow_path_guard=false. This contradicts the hypothesis. Hence -342\le r.\mathit{exponent}\le308.
With the slow guard true, that same final comparison took its negative arm. The branch makes exactly one call to num imp dec2flt slow parse long mantissa on t.\mathit{body} and assigns its returned pair simultaneously to selected_pair and to some slow_path_result. Constructor injectivity for the assumed assembled trace therefore gives
\texttt{parse\_long\_mantissa($t.body$)=ok $t.selected\_pair$}. \tag{1}
Finally unfold the slow function in (1). After constructing the fixed zero and infinity pairs, its first input-dependent bind is precisely num imp dec2flt decimal seq parse decimal seq on the same body. If this bind failed, the slow call could not equal the normal result in (1). Thus it returns ok d for some sequence d. Choosing that d, together with (1) and the already proved exponent bounds, gives every conjunct and the existential conclusion.

Lean proof


  intro s f tr target hsource htrace hslow hparse hpositive
  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⟩
  rcases ParserExponentConstants with
    ⟨hbits, htotal, hsig, hexpbits, hexpsat, hinf, hbias, hmin,
      hsmall, hlarge, hroundmin, hroundmax⟩
  have compute_low : forall (q : Std.I64) (w : Std.U64), q.val < -342 ->
      num.imp.dec2flt.lemire.compute_float
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 q w =
        ok { m := 0#u64, p_biased := 0#i32 } := by
    intro q w hq
    unfold num.imp.dec2flt.lemire.compute_float
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
      ok { m := 0#u64, p_biased := 0#i32 } by rfl, hinf]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
      ok { m := 0#u64, p_biased := 2047#i32 } by rfl]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 (-1)#i32 =
      ok { m := 0#u64, p_biased := (-1)#i32 } by rfl]
    simp only [bind_tc_ok]
    by_cases hw : w = 0#u64
    · simp [hw]
    · simp only [hw, if_false]
      rw [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SMALLEST_POWER_OF_TEN.eq_def]
      rw [show lift (IScalar.cast .I64 (-342)#i32) = ok (-342)#i64 by rfl]
      simp only [bind_tc_ok]
      have hq' : q < (-342)#i64 := by
        simpa only [IScalar.lt_equiv] using hq
      simp [hq']
  have compute_high : forall (q : Std.I64) (w : Std.U64),
      308 < q.val -> 0 < w.val ->
      num.imp.dec2flt.lemire.compute_float
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 q w =
        ok { m := 0#u64, p_biased := 2047#i32 } := by
    intro q w hq hwpos
    unfold num.imp.dec2flt.lemire.compute_float
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
      ok { m := 0#u64, p_biased := 0#i32 } by rfl, hinf]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
      ok { m := 0#u64, p_biased := 2047#i32 } by rfl]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 (-1)#i32 =
      ok { m := 0#u64, p_biased := (-1)#i32 } by rfl]
    simp only [bind_tc_ok]
    have hw : w ≠ 0#u64 := by
      intro heq
      have := UScalar.val_eq_of_eq heq
      simp at this
      omega
    simp only [hw, if_false]
    rw [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SMALLEST_POWER_OF_TEN.eq_def]
    rw [show lift (IScalar.cast .I64 (-342)#i32) = ok (-342)#i64 by rfl]
    simp only [bind_tc_ok]
    have hnlow : ¬ (q < (-342)#i64) := by
      have hqval : 308 < q.val := hq
      have hnlowVal : ¬ (q.val < (-342 : Int)) :=
        not_lt.mpr (le_trans (by norm_num : (-342 : Int) ≤ 308)
          (le_of_lt hqval))
      simpa only [IScalar.lt_equiv] using hnlowVal
    simp only [hnlow, if_false]
    rw [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.LARGEST_POWER_OF_TEN.eq_def]
    rw [show lift (IScalar.cast .I64 308#i32) = ok 308#i64 by rfl]
    simp only [bind_tc_ok]
    have hq' : q > 308#i64 := by
      simpa only [IScalar.lt_equiv] using hq
    simp [hq']
  have compute_zero : forall (q : Std.I64),
      num.imp.dec2flt.lemire.compute_float
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 q (0#u64) =
        ok { m := 0#u64, p_biased := 0#i32 } := by
    intro q
    unfold num.imp.dec2flt.lemire.compute_float
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
      ok { m := 0#u64, p_biased := 0#i32 } by rfl, hinf]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
      ok { m := 0#u64, p_biased := 2047#i32 } by rfl]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 (-1)#i32 =
      ok { m := 0#u64, p_biased := (-1)#i32 } by rfl]
    rfl
  unfold num.imp.dec2flt.dec2flt_with_trace at htrace
  obtain ⟨body, hbody, htrace⟩ := bind_ok_inv _ _ _ htrace
  obtain ⟨first, hfirst, htrace⟩ := bind_ok_inv _ _ _ htrace
  cases first with
  | none =>
      obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
      cases htrace
  | some c =>
      obtain ⟨body1, hbody1, htrace⟩ := bind_ok_inv _ _ _ htrace
      obtain ⟨empty, hempty, htrace⟩ := bind_ok_inv _ _ _ htrace
      by_cases he : empty = true
      · simp only [he, if_true] at htrace
        obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases htrace
      · have hef : empty = false := Bool.eq_false_of_not_eq_true he
        simp only [hef, if_false] at htrace
        obtain ⟨parsed, hparsed, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases parsed with
        | none =>
            obtain ⟨special, hspecial, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases special with
            | none =>
                obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
                cases htrace
            | some value => cases htrace
        | some parsedRecord =>
            obtain ⟨fast, hfast, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases fast with
            | some value => cases htrace
            | none =>
                obtain ⟨firstPair, hfirstPair, htrace⟩ :=
                  bind_ok_inv _ _ _ htrace
                obtain ⟨phase1, hphase1, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase1 with
                  ⟨many1, many2, firstPair1, fp, secondGuard⟩
                obtain ⟨phase2, hphase2, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase2 with
                  ⟨post, secondExp, secondMant, secondResult, secondEqual,
                    forced⟩
                obtain ⟨phase3, hphase3, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase3 with ⟨selected, slowGuard, slowResult⟩
                obtain ⟨i, hi, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i1, hi1, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i2, hi2, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨word, hword, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨assembled, hassembled, htrace⟩ :=
                  bind_ok_inv _ _ _ htrace
                have traceFields : tr.body = body1 /\
                    tr.slow_path_guard = slowGuard /\
                    tr.selected_pair = selected := by
                  by_cases hnegative : c = 45#u8
                  · simp only [hnegative, if_true] at htrace
                    obtain ⟨result, hresult, htrace⟩ :=
                      bind_ok_inv _ _ _ htrace
                    cases htrace
                    exact ⟨rfl, rfl, rfl⟩
                  · simp only [hnegative, if_false] at htrace
                    cases htrace
                    exact ⟨rfl, rfl, rfl⟩
                rcases traceFields with ⟨htraceBody, htraceSlow, htraceSelected⟩
                have htarget : target = parsedRecord := by
                  rw [htraceBody, hparsed] at hparse
                  injection hparse with h
                  exact (Option.some.inj h).symm
                subst target
                have hslow' : slowGuard = true := htraceSlow.symm.trans hslow
                have hslowCall :
                    num.imp.dec2flt.slow.parse_long_mantissa
                        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 body1 =
                      ok selected := by
                    by_cases hneg : post.p_biased < 0#i32
                    · simp only [hneg, if_true] at hphase3
                      obtain ⟨replacement, hreplacement, hphase3⟩ :=
                        bind_ok_inv _ _ _ hphase3
                      cases hphase3
                      exact hreplacement
                    · simp only [hneg, if_false] at hphase3
                      cases hphase3
                      simp at hslow'
                have hbounds : -342 <= parsedRecord.exponent.val /\
                    parsedRecord.exponent.val <= 308 := by
                    by_contra hb
                    have hout : parsedRecord.exponent.val < -342 \/
                        308 < parsedRecord.exponent.val := by omega
                    have hpostNonnegative : 0 <= post.p_biased.val := by
                      have hfp : fp = firstPair := by
                        by_cases hm : parsedRecord.many_digits = true
                        · simp only [hm, if_true] at hphase1
                          cases hphase1
                          rfl
                        · simp only [hm, if_false] at hphase1
                          cases hphase1
                          rfl
                      subst fp
                      by_cases hm : parsedRecord.many_digits = true
                      · simp only [hm, if_true] at hphase1
                        cases hphase1
                        rcases hout with hlow | hhigh
                        · have hfirstFixed := compute_low parsedRecord.exponent
                            parsedRecord.mantissa hlow
                          rw [hfirstPair] at hfirstFixed
                          cases hfirstFixed
                          simp only [ge_iff_le, decide_true, if_true] at hphase2
                          obtain ⟨incremented, hincremented, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          obtain ⟨second, hsecond, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          have hsecondFixed := compute_low parsedRecord.exponent
                            incremented hlow
                          rw [hsecond] at hsecondFixed
                          cases hsecondFixed
                          obtain ⟨equal, hequal, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          have heq : equal = true := by
                            simpa [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq]
                              using hequal
                          subst equal
                          simp only [if_true] at hphase2
                          obtain ⟨chosen, hchosen, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          cases hchosen
                          cases hphase2
                          norm_num
                        · have hwpos := hpositive hm
                          have hfirstFixed := compute_high parsedRecord.exponent
                            parsedRecord.mantissa hhigh hwpos
                          rw [hfirstPair] at hfirstFixed
                          cases hfirstFixed
                          simp only [ge_iff_le, decide_true, if_true] at hphase2
                          obtain ⟨incremented, hincremented, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          have hincVal : incremented.val =
                              parsedRecord.mantissa.val + 1 := by
                            have hadd := UScalar.add_equiv parsedRecord.mantissa
                              (1#u64)
                            rw [hincremented] at hadd
                            simp at hadd
                            omega
                          have hincPos : 0 < incremented.val := by omega
                          obtain ⟨second, hsecond, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          have hsecondFixed := compute_high parsedRecord.exponent
                            incremented hhigh hincPos
                          rw [hsecond] at hsecondFixed
                          cases hsecondFixed
                          obtain ⟨equal, hequal, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          have heq : equal = true := by
                            simpa [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq]
                              using hequal
                          subst equal
                          simp only [if_true] at hphase2
                          obtain ⟨chosen, hchosen, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          cases hchosen
                          cases hphase2
                          norm_num
                      · simp only [hm, if_false] at hphase1
                        cases hphase1
                        simp only [Bool.false_eq_true, if_false] at hphase2
                        cases hphase2
                        rcases hout with hlow | hhigh
                        · have hfixed := compute_low parsedRecord.exponent
                            parsedRecord.mantissa hlow
                          rw [hfirstPair] at hfixed
                          cases hfixed
                          norm_num
                        · by_cases hw : parsedRecord.mantissa.val = 0
                          · have hweq : parsedRecord.mantissa = 0#u64 :=
                              UScalar.eq_of_val_eq hw
                            rw [hweq] at hfirstPair
                            have hfixed := compute_zero parsedRecord.exponent
                            rw [hfirstPair] at hfixed
                            cases hfixed
                            norm_num
                          · have hwpos : 0 < parsedRecord.mantissa.val := by omega
                            have hfixed := compute_high parsedRecord.exponent
                              parsedRecord.mantissa hhigh hwpos
                            rw [hfirstPair] at hfixed
                            cases hfixed
                            norm_num
                    have hnotneg : ¬ (post.p_biased < 0#i32) := by
                      have hnotnegVal : ¬ (post.p_biased.val < (0 : Int)) :=
                        not_lt.mpr hpostNonnegative
                      simpa only [IScalar.lt_equiv] using hnotnegVal
                    simp only [hnotneg, if_false] at hphase3
                    cases hphase3
                    simp at hslow'
                refine ⟨hbounds.1, hbounds.2, ?_⟩
                have hslowCallCopy := hslowCall
                unfold num.imp.dec2flt.slow.parse_long_mantissa at hslowCallCopy
                rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
                  ok { m := 0#u64, p_biased := 0#i32 } by rfl, hinf]
                  at hslowCallCopy
                simp only [bind_tc_ok] at hslowCallCopy
                rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
                  ok { m := 0#u64, p_biased := 2047#i32 } by rfl]
                  at hslowCallCopy
                simp only [bind_tc_ok] at hslowCallCopy
                obtain ⟨d, hd, hrest⟩ := bind_ok_inv _ _ _ hslowCallCopy
                rw [htraceBody, htraceSelected]
                exact ⟨d, hd, hslowCall⟩


end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalGoalVocabularyDefault
import Tablet.ParserExponentConstants
import Tablet.F64_Insts_CoreOpsArithDivF64F64
import Tablet.F64_Insts_CoreOpsArithMulF64F64
import Tablet.F64_Insts_CoreOpsArithNegF64
import Tablet.F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64
import Tablet.F64_Insts_Dec2flt_modelNumImpTraitsFloatU64
import Tablet.num_imp_dec2flt_Dec2FltAssemblyTrace
import Tablet.num_imp_dec2flt_biased_fp_to_float
import Tablet.num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq
import Tablet.num_imp_dec2flt_common_BiasedFp_zero_pow2
import Tablet.num_imp_dec2flt_dec2flt_with_trace
import Tablet.num_imp_dec2flt_decimal_seq_DecimalSeq
import Tablet.num_imp_dec2flt_decimal_seq_parse_decimal_seq
import Tablet.num_imp_dec2flt_lemire_compute_float
import Tablet.num_imp_dec2flt_parse_parse_number
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserSlowControlFlow]
theorem ParserSlowControlFlow :
    forall (s : Str) (f : F64)
      (tr : num.imp.dec2flt.Dec2FltAssemblyTrace F64)
      (r : num.imp.dec2flt.decimal.Decimal),
      DecimalGoalVocabularyDefault.sourceString s ->
      num.imp.dec2flt.dec2flt_with_trace
        F64.Insts.Dec2flt_modelNumImpDec2fltLemireU64
        F64.Insts.CoreOpsArithDivF64F64 F64.Insts.CoreOpsArithMulF64F64
        F64.Insts.CoreOpsArithNegF64 s =
          ok (core.result.Result.Ok f,
            num.imp.dec2flt.Dec2FltTrace.Assembled tr) ->
      tr.slow_path_guard = true ->
      num.imp.dec2flt.parse.parse_number tr.body = ok (some r) ->
      (r.many_digits = true -> 0 < r.mantissa.val) ->
      -342 <= r.exponent.val /\ r.exponent.val <= 308 /\
        exists d : num.imp.dec2flt.decimal_seq.DecimalSeq,
          num.imp.dec2flt.decimal_seq.parse_decimal_seq tr.body = ok d /\
          num.imp.dec2flt.slow.parse_long_mantissa
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 tr.body =
              ok tr.selected_pair := by
-- BODY
  intro s f tr target hsource htrace hslow hparse hpositive
  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⟩
  rcases ParserExponentConstants with
    ⟨hbits, htotal, hsig, hexpbits, hexpsat, hinf, hbias, hmin,
      hsmall, hlarge, hroundmin, hroundmax⟩
  have compute_low : forall (q : Std.I64) (w : Std.U64), q.val < -342 ->
      num.imp.dec2flt.lemire.compute_float
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 q w =
        ok { m := 0#u64, p_biased := 0#i32 } := by
    intro q w hq
    unfold num.imp.dec2flt.lemire.compute_float
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
      ok { m := 0#u64, p_biased := 0#i32 } by rfl, hinf]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
      ok { m := 0#u64, p_biased := 2047#i32 } by rfl]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 (-1)#i32 =
      ok { m := 0#u64, p_biased := (-1)#i32 } by rfl]
    simp only [bind_tc_ok]
    by_cases hw : w = 0#u64
    · simp [hw]
    · simp only [hw, if_false]
      rw [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SMALLEST_POWER_OF_TEN.eq_def]
      rw [show lift (IScalar.cast .I64 (-342)#i32) = ok (-342)#i64 by rfl]
      simp only [bind_tc_ok]
      have hq' : q < (-342)#i64 := by
        simpa only [IScalar.lt_equiv] using hq
      simp [hq']
  have compute_high : forall (q : Std.I64) (w : Std.U64),
      308 < q.val -> 0 < w.val ->
      num.imp.dec2flt.lemire.compute_float
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 q w =
        ok { m := 0#u64, p_biased := 2047#i32 } := by
    intro q w hq hwpos
    unfold num.imp.dec2flt.lemire.compute_float
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
      ok { m := 0#u64, p_biased := 0#i32 } by rfl, hinf]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
      ok { m := 0#u64, p_biased := 2047#i32 } by rfl]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 (-1)#i32 =
      ok { m := 0#u64, p_biased := (-1)#i32 } by rfl]
    simp only [bind_tc_ok]
    have hw : w ≠ 0#u64 := by
      intro heq
      have := UScalar.val_eq_of_eq heq
      simp at this
      omega
    simp only [hw, if_false]
    rw [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.SMALLEST_POWER_OF_TEN.eq_def]
    rw [show lift (IScalar.cast .I64 (-342)#i32) = ok (-342)#i64 by rfl]
    simp only [bind_tc_ok]
    have hnlow : ¬ (q < (-342)#i64) := by
      have hqval : 308 < q.val := hq
      have hnlowVal : ¬ (q.val < (-342 : Int)) :=
        not_lt.mpr (le_trans (by norm_num : (-342 : Int) ≤ 308)
          (le_of_lt hqval))
      simpa only [IScalar.lt_equiv] using hnlowVal
    simp only [hnlow, if_false]
    rw [F64.Insts.Dec2flt_modelNumImpTraitsFloatU64.LARGEST_POWER_OF_TEN.eq_def]
    rw [show lift (IScalar.cast .I64 308#i32) = ok 308#i64 by rfl]
    simp only [bind_tc_ok]
    have hq' : q > 308#i64 := by
      simpa only [IScalar.lt_equiv] using hq
    simp [hq']
  have compute_zero : forall (q : Std.I64),
      num.imp.dec2flt.lemire.compute_float
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 q (0#u64) =
        ok { m := 0#u64, p_biased := 0#i32 } := by
    intro q
    unfold num.imp.dec2flt.lemire.compute_float
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
      ok { m := 0#u64, p_biased := 0#i32 } by rfl, hinf]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
      ok { m := 0#u64, p_biased := 2047#i32 } by rfl]
    simp only [bind_tc_ok]
    rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 (-1)#i32 =
      ok { m := 0#u64, p_biased := (-1)#i32 } by rfl]
    rfl
  unfold num.imp.dec2flt.dec2flt_with_trace at htrace
  obtain ⟨body, hbody, htrace⟩ := bind_ok_inv _ _ _ htrace
  obtain ⟨first, hfirst, htrace⟩ := bind_ok_inv _ _ _ htrace
  cases first with
  | none =>
      obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
      cases htrace
  | some c =>
      obtain ⟨body1, hbody1, htrace⟩ := bind_ok_inv _ _ _ htrace
      obtain ⟨empty, hempty, htrace⟩ := bind_ok_inv _ _ _ htrace
      by_cases he : empty = true
      · simp only [he, if_true] at htrace
        obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases htrace
      · have hef : empty = false := Bool.eq_false_of_not_eq_true he
        simp only [hef, if_false] at htrace
        obtain ⟨parsed, hparsed, htrace⟩ := bind_ok_inv _ _ _ htrace
        cases parsed with
        | none =>
            obtain ⟨special, hspecial, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases special with
            | none =>
                obtain ⟨pfe, hpfe, htrace⟩ := bind_ok_inv _ _ _ htrace
                cases htrace
            | some value => cases htrace
        | some parsedRecord =>
            obtain ⟨fast, hfast, htrace⟩ := bind_ok_inv _ _ _ htrace
            cases fast with
            | some value => cases htrace
            | none =>
                obtain ⟨firstPair, hfirstPair, htrace⟩ :=
                  bind_ok_inv _ _ _ htrace
                obtain ⟨phase1, hphase1, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase1 with
                  ⟨many1, many2, firstPair1, fp, secondGuard⟩
                obtain ⟨phase2, hphase2, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase2 with
                  ⟨post, secondExp, secondMant, secondResult, secondEqual,
                    forced⟩
                obtain ⟨phase3, hphase3, htrace⟩ := bind_ok_inv _ _ _ htrace
                rcases phase3 with ⟨selected, slowGuard, slowResult⟩
                obtain ⟨i, hi, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i1, hi1, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨i2, hi2, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨word, hword, htrace⟩ := bind_ok_inv _ _ _ htrace
                obtain ⟨assembled, hassembled, htrace⟩ :=
                  bind_ok_inv _ _ _ htrace
                have traceFields : tr.body = body1 /\
                    tr.slow_path_guard = slowGuard /\
                    tr.selected_pair = selected := by
                  by_cases hnegative : c = 45#u8
                  · simp only [hnegative, if_true] at htrace
                    obtain ⟨result, hresult, htrace⟩ :=
                      bind_ok_inv _ _ _ htrace
                    cases htrace
                    exact ⟨rfl, rfl, rfl⟩
                  · simp only [hnegative, if_false] at htrace
                    cases htrace
                    exact ⟨rfl, rfl, rfl⟩
                rcases traceFields with ⟨htraceBody, htraceSlow, htraceSelected⟩
                have htarget : target = parsedRecord := by
                  rw [htraceBody, hparsed] at hparse
                  injection hparse with h
                  exact (Option.some.inj h).symm
                subst target
                have hslow' : slowGuard = true := htraceSlow.symm.trans hslow
                have hslowCall :
                    num.imp.dec2flt.slow.parse_long_mantissa
                        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 body1 =
                      ok selected := by
                    by_cases hneg : post.p_biased < 0#i32
                    · simp only [hneg, if_true] at hphase3
                      obtain ⟨replacement, hreplacement, hphase3⟩ :=
                        bind_ok_inv _ _ _ hphase3
                      cases hphase3
                      exact hreplacement
                    · simp only [hneg, if_false] at hphase3
                      cases hphase3
                      simp at hslow'
                have hbounds : -342 <= parsedRecord.exponent.val /\
                    parsedRecord.exponent.val <= 308 := by
                    by_contra hb
                    have hout : parsedRecord.exponent.val < -342 \/
                        308 < parsedRecord.exponent.val := by omega
                    have hpostNonnegative : 0 <= post.p_biased.val := by
                      have hfp : fp = firstPair := by
                        by_cases hm : parsedRecord.many_digits = true
                        · simp only [hm, if_true] at hphase1
                          cases hphase1
                          rfl
                        · simp only [hm, if_false] at hphase1
                          cases hphase1
                          rfl
                      subst fp
                      by_cases hm : parsedRecord.many_digits = true
                      · simp only [hm, if_true] at hphase1
                        cases hphase1
                        rcases hout with hlow | hhigh
                        · have hfirstFixed := compute_low parsedRecord.exponent
                            parsedRecord.mantissa hlow
                          rw [hfirstPair] at hfirstFixed
                          cases hfirstFixed
                          simp only [ge_iff_le, decide_true, if_true] at hphase2
                          obtain ⟨incremented, hincremented, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          obtain ⟨second, hsecond, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          have hsecondFixed := compute_low parsedRecord.exponent
                            incremented hlow
                          rw [hsecond] at hsecondFixed
                          cases hsecondFixed
                          obtain ⟨equal, hequal, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          have heq : equal = true := by
                            simpa [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq]
                              using hequal
                          subst equal
                          simp only [if_true] at hphase2
                          obtain ⟨chosen, hchosen, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          cases hchosen
                          cases hphase2
                          norm_num
                        · have hwpos := hpositive hm
                          have hfirstFixed := compute_high parsedRecord.exponent
                            parsedRecord.mantissa hhigh hwpos
                          rw [hfirstPair] at hfirstFixed
                          cases hfirstFixed
                          simp only [ge_iff_le, decide_true, if_true] at hphase2
                          obtain ⟨incremented, hincremented, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          have hincVal : incremented.val =
                              parsedRecord.mantissa.val + 1 := by
                            have hadd := UScalar.add_equiv parsedRecord.mantissa
                              (1#u64)
                            rw [hincremented] at hadd
                            simp at hadd
                            omega
                          have hincPos : 0 < incremented.val := by omega
                          obtain ⟨second, hsecond, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          have hsecondFixed := compute_high parsedRecord.exponent
                            incremented hhigh hincPos
                          rw [hsecond] at hsecondFixed
                          cases hsecondFixed
                          obtain ⟨equal, hequal, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          have heq : equal = true := by
                            simpa [num.imp.dec2flt.common.BiasedFp.Insts.CoreCmpPartialEqBiasedFp.eq]
                              using hequal
                          subst equal
                          simp only [if_true] at hphase2
                          obtain ⟨chosen, hchosen, hphase2⟩ :=
                            bind_ok_inv _ _ _ hphase2
                          cases hchosen
                          cases hphase2
                          norm_num
                      · simp only [hm, if_false] at hphase1
                        cases hphase1
                        simp only [Bool.false_eq_true, if_false] at hphase2
                        cases hphase2
                        rcases hout with hlow | hhigh
                        · have hfixed := compute_low parsedRecord.exponent
                            parsedRecord.mantissa hlow
                          rw [hfirstPair] at hfixed
                          cases hfixed
                          norm_num
                        · by_cases hw : parsedRecord.mantissa.val = 0
                          · have hweq : parsedRecord.mantissa = 0#u64 :=
                              UScalar.eq_of_val_eq hw
                            rw [hweq] at hfirstPair
                            have hfixed := compute_zero parsedRecord.exponent
                            rw [hfirstPair] at hfixed
                            cases hfixed
                            norm_num
                          · have hwpos : 0 < parsedRecord.mantissa.val := by omega
                            have hfixed := compute_high parsedRecord.exponent
                              parsedRecord.mantissa hhigh hwpos
                            rw [hfirstPair] at hfixed
                            cases hfixed
                            norm_num
                    have hnotneg : ¬ (post.p_biased < 0#i32) := by
                      have hnotnegVal : ¬ (post.p_biased.val < (0 : Int)) :=
                        not_lt.mpr hpostNonnegative
                      simpa only [IScalar.lt_equiv] using hnotnegVal
                    simp only [hnotneg, if_false] at hphase3
                    cases hphase3
                    simp at hslow'
                refine ⟨hbounds.1, hbounds.2, ?_⟩
                have hslowCallCopy := hslowCall
                unfold num.imp.dec2flt.slow.parse_long_mantissa at hslowCallCopy
                rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 0#i32 =
                  ok { m := 0#u64, p_biased := 0#i32 } by rfl, hinf]
                  at hslowCallCopy
                simp only [bind_tc_ok] at hslowCallCopy
                rw [show num.imp.dec2flt.common.BiasedFp.zero_pow2 2047#i32 =
                  ok { m := 0#u64, p_biased := 2047#i32 } by rfl]
                  at hslowCallCopy
                simp only [bind_tc_ok] at hslowCallCopy
                obtain ⟨d, hd, hrest⟩ := bind_ok_inv _ _ _ hslowCallCopy
                rw [htraceBody, htraceSelected]
                exact ⟨d, hd, hslowCall⟩


end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (200)
More program dependencies (158)
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 150 entries
Technical checking records
Local closure summary
{
  "node": "ParserSlowControlFlow",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "6fb04dc87a74077d1600feafa8840ce98ebf4b19cf18808b4fc5350ab954927a",
  "active_statement_hash": "1ac3cf5d05f9133ca76d98336f85c37827e43964a1c2298df27e7c69a9396b1d",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "ab64d13f256386ee0e494a5abcc6a5db49512cf3d90bbdfcabd6327793a31f95",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-164",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_LARGEST_POWER_OF_TEN": "2532cbe447dc07c7",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SMALLEST_POWER_OF_TEN": "8a9e3dfa7e9aa5ec",
    "ParserExponentConstants": "e2a30a7b0c5e9c91",
    "num_imp_dec2flt_dec2flt_with_trace": "f3e7d4ffbf9b4d68",
    "num_imp_dec2flt_lemire_compute_float": "7539bc2a998f5c1c",
    "num_imp_dec2flt_slow_parse_long_mantissa": "adfe9a4161cd7fd6",
    "num_imp_traits_Float_EXP_BIAS_default": "39417be39e20ce5d",
    "num_imp_traits_Float_EXP_BITS_default": "9ab622d85ef04d94",
    "num_imp_traits_Float_EXP_MIN_default": "39417be39e20ce5d",
    "num_imp_traits_Float_EXP_SAT_default": "9ab622d85ef04d94",
    "num_imp_traits_Float_SIG_BITS_default": "9ab622d85ef04d94"
  },
  "strict_definition_deps": {
    "DecimalGoalVocabulary": "1f42f752b5d22513",
    "DecimalGoalVocabularyDefault": "512f8d0aea894250",
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_CoreOpsArithDivF64F64": "dc44e13a99fc6bed",
    "F64_Insts_CoreOpsArithMulF64F64": "1ae1a9021a654abd",
    "F64_Insts_CoreOpsArithNegF64": "2d9be310c546ea2e",
    "F64_Insts_Dec2flt_modelNumImpDec2fltLemireU64": "30963b4ef656cc79",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatExtU64": "60afe26c6a80cf0f",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_BITS": "d9fd91641cb78c5e",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_LARGEST_POWER_OF_TEN": "e23324c94fa5d1b5",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_MAX_EXPONENT_ROUND_TO_EVEN": "3dbd3f15a918cb2c",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_MIN_EXPONENT_ROUND_TO_EVEN": "e508b987ade7bf71",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SIG_TOTAL_BITS": "887b52d84a3fc9c4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64_SMALLEST_POWER_OF_TEN": "0c461c0c4f5aa880",
    "Preamble": "7a79218b23bce03e",
    "core_ops_arith_Neg": "0ff07135a60bcbf9",
    "num_float_parse_ParseFloatError": "c43614ff2149ecf2",
    "num_imp_dec2flt_Dec2FltAssemblyTrace": "7bda5de02611ad76",
    "num_imp_dec2flt_Dec2FltTrace": "27322b4608129f59",
    "num_imp_dec2flt_Lemire": "1923f90c53d323e6",
    "num_imp_dec2flt_biased_fp_to_float": "acdde060e8d35ca7",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_common_BiasedFp_Insts_CoreCmpPartialEqBiasedFp_eq": "fbbf553e3c502a05",
    "num_imp_dec2flt_common_BiasedFp_zero_pow2": "0f99ae12c6707137",
    "num_imp_dec2flt_dec2flt_with_trace": "d34666730435cdb9",
    "num_imp_dec2flt_decimal_Decimal": "4c41a56bf44cb31e",
    "num_imp_dec2flt_decimal_Decimal_try_fast_path": "2e4888f65a06b49f",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "c43614ff2149ecf2",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "fd298e37d5ae4f86",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "1aaf1bb11c0b6a49",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_round": "8ea3c058fea09978",
    "num_imp_dec2flt_decimal_seq_parse_decimal_seq": "244cf8318357caab",
    "num_imp_dec2flt_lemire_compute_float": "39d89e3f0a8a9d4c",
    "num_imp_dec2flt_lemire_compute_product_approx": "af91b9cbef7779f3",
    "num_imp_dec2flt_lemire_power": "56b7c3bd69ca3c6a",
    "num_imp_dec2flt_parse_parse_inf_nan": "85655c19a8791b54",
    "num_imp_dec2flt_parse_parse_number": "f73f8bc11faa6db3",
    "num_imp_dec2flt_pfe_empty": "89046d1da5ac1ce2",
    "num_imp_dec2flt_pfe_invalid": "21db875427d92c6d",
    "num_imp_dec2flt_slow_parse_long_mantissa": "f4b1825aa46c08b9",
    "num_imp_traits_Float": "22e97e73b1292e80",
    "num_imp_traits_FloatExt": "f996e5400649797d"
  }
}
Prose assessment
{
  "label": "Sound flag superseded by recorded Lean closure",
  "assessment_status": "ReviewerPinnedFail",
  "fingerprint_relation": "differs from current fingerprint",
  "assessment_fingerprint": "sound-v2:11c752a6b26ca6039b97d64508c91340795ac8d80569d5a7ebe23fa5472f08c4",
  "current_fingerprint": "sound-v2:334f906989daa2916ffc2ab16dcafede249445e9835e163b2d6edbe6ba15b67b",
  "superseded_for_theorem_closure": true
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Fail",
  "substantiveness_status": "Pass"
}