P856_T1_FinalLeftShiftExecution

Lean checked

Statement

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

Helper · Reachable loop-2 state and final 53-bit shift

Let d_1,e_1 be a normalized nonempty decimal record with point zero, leading digit at least five, at most 768 digits, decimal digits below ten, and endpoint equations for A/2^{e_1} and B/2^{e_1} with nonnegative strictly ordered errors and exact sticky equivalence. Assume e_1\geq-1079, the checked decrement returns e_s=e_1-1, and the exact extracted loop-2 call returns (d_2,e_2). Then
-17\leq d_2.\mathit{point}\leq0.
Moreover, either d_2=d_1 and e_2+1=e_1, or there is a shift k\leq58 for which the exact right shift d_1/2^k returns d_2 and e_2+1=e_1+k.
The exact 53-bit left shift of d_2 succeeds with a record d_3. Its retained length is at most 768, every retained digit is below ten, it is nonempty with leading digit in [1,10), and its last retained digit is nonzero. Writing V_3 for its retained decimal value, there are 0\leq\eta_3<u_3 such that
A/2^{e_2-52}=V_3+\eta_3,\qquad B/2^{e_2-52}=V_3+u_3,
with d_3.\mathit{truncated}=\mathsf{true} exactly when \eta_3>0, and d_3.\mathit{point}<19.

Lean statement

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

import Tablet.ParserSlowLoop2
import Tablet.P856_T1_RightPrefixReadBound
import Tablet.DecimalRightShiftLoop0Execution
import Tablet.DecimalLeftShiftLoop1Execution
import Tablet.DecimalSeqLeftShiftCanonical
import Tablet.DecimalLeftShiftDigitGrowth
import Tablet.P804_T1_LeftShiftPointGrowth
import Tablet.ParserExponentConstants

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P856_T1_FinalLeftShiftExecution]
theorem P856_T1_FinalLeftShiftExecution
    (A B : Real)
    (d1 d2 : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (exp1 expStart exp2 : Std.I32)
    (hexpLower : -1079 <= exp1.val)
    (hpoint1 : d1.decimal_point.val = 0)
    (hnum1 : d1.num_digits.val != 0)
    (hlead1 : 5 <= d1.digits.val[0].val)
    (hinput :
      let digits1 :=
        (d1.digits.val.take d1.num_digits.val).map (fun z => z.val)
      let integer1 : Nat := digits1.foldl (fun n digit => 10 * n + digit) 0
      let value1 : Real := integer1 * (10 : Real) ^
        (d1.decimal_point.val - (d1.num_digits.val : Int))
      d1.num_digits.val <= 768 /\
      (forall z, z ∈ d1.digits.val.take d1.num_digits.val -> z.val < 10) /\
      (exists z zs, digits1 = z :: zs /\ 1 <= z /\ z < 10 /\
        digits1.length = d1.num_digits.val) /\
      (exists eta1 u1 : Real,
        A / (2 : Real) ^ exp1.val = value1 + eta1 /\
        B / (2 : Real) ^ exp1.val = value1 + u1 /\
        0 <= eta1 /\ eta1 < u1 /\
        (d1.truncated = true <-> 0 < eta1)))
    (hsub : exp1 - 1#i32 = ok expStart)
    (hloop :
      num.imp.dec2flt.slow.parse_long_mantissa_loop2
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
          ok (d2, exp2)) :
    exists d3 : num.imp.dec2flt.decimal_seq.DecimalSeq,
      -17 <= d2.decimal_point.val /\ d2.decimal_point.val <= 0 /\
      ((d2 = d1 /\ exp2.val + 1 = exp1.val) \/
        (exists shift : Std.Usize,
          shift.val <= 58 /\
          num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d1 shift = ok d2 /\
          exp2.val + 1 = exp1.val + (shift.val : Int))) /\
      num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d2 53#usize = ok d3 /\
      (let digits3 :=
        (d3.digits.val.take d3.num_digits.val).map (fun z => z.val)
       let integer3 : Nat := digits3.foldl (fun n digit => 10 * n + digit) 0
       let value3 : Real := integer3 * (10 : Real) ^
         (d3.decimal_point.val - (d3.num_digits.val : Int))
       d3.num_digits.val <= 768 /\
       (forall z, z ∈ d3.digits.val.take d3.num_digits.val -> z.val < 10) /\
       (exists z zs, digits3 = z :: zs /\ 1 <= z /\ z < 10 /\
         digits3.length = d3.num_digits.val /\ digits3.getLast? != some 0) /\
       (exists eta3 u3 : Real,
         A / (2 : Real) ^ (exp2.val - 52) = value3 + eta3 /\
         B / (2 : Real) ^ (exp2.val - 52) = value3 + u3 /\
         0 <= eta3 /\ eta3 < u3 /\
         (d3.truncated = true <-> 0 < eta3)) /\
       d3.decimal_point.val < 19) := 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

Apply ParserSlowLoop2 to the stated normalized record and endpoint package. Injectivity of the two supplied successful result equations identifies its decrement, output record, and output exponent with e_s,d_2,e_2 and supplies the complete canonical and endpoint facts for d_2.
We invert the two branches of the extracted loop-2 body, whose definition is the cited extracted slow parser num imp dec2flt slow parse long mantissa. If e_s\geq-1022, the first body call returns immediately, so injectivity gives d_2=d_1 and e_2=e_s=e_1-1; the point is zero.
Otherwise the checked difference is -1022-e_s. Since e_1\geq-1079 and e_s=e_1-1, it lies in [1,58], so its Usize cast and the later I32 cast are in range. The execution theorem DecimalRightShiftLoop0Execution constructs the exact right shift and its prefix-loop cursor r. The leading digit of the list equals the array cell at index zero (nonemptiness makes that index part of the retained prefix), hence it is at least five. Therefore RightPrefixReadBound gives r\leq18. The extracted right-shift execution states
d_2.\mathit{point}=0-r+1,
so -17\leq d_2.\mathit{point}\leq0. The checked exponent addition is e_s+(-1022-e_s)=-1022; unfolding the following loop body shows immediate termination. Comparing this reconstructed two-body execution with the assumed successful call identifies its record and exponent and gives e_2+1=e_1+k.
Now apply DecimalLeftShiftLoop1Execution to d_2 and the literal shift 53; the just-proved point interval discharges its point range, and the loop-2 canonical package supplies its digit premises. This constructs the successful shift and a nonempty output d_3. Applying DecimalLeftShiftDigitGrowth with h=16 is valid because 10^{15}<2^{53}<10^{16}, and shows that the decimal point grows by either 15 or 16. The exact point identity from LeftShiftPointGrowth, together with d_2.\mathit{point}\leq0, yields d_3.\mathit{point}\leq16<19.
Finally DecimalSeqLeftShiftCanonical transports the complete canonical record and endpoint package across the successful 53-bit shift. Its zero-output alternative contradicts the nonempty execution result. Its nonzero alternative supplies the digit bound, leading digit, recorded length, terminal trim, ordered errors, and sticky equivalence asserted above. The integer-power identity
2^{53}\bigl(A/2^{e_2+1}\bigr)=A/2^{e_2-52}
and its B analogue rewrite the two transported endpoints to the displayed form. All casts and checked arithmetic used above are discharged by the stated intervals.

Lean proof


  dsimp only at hinput
  rcases hinput with ⟨hcap1, hdigit1, hpositive1, hend1⟩
  have hspec := ParserSlowLoop2 A B d1 exp1 hexpLower hpoint1 hnum1 hlead1
    ⟨hcap1, hdigit1, hend1⟩
  dsimp only at hspec
  rcases hspec with ⟨es, q2, e2, total, hsubS, hloopS, htotal,
    hes, he2, htotalEq, hpoint2Lo, hnum2, hshape2⟩
  have hesEq : es = expStart := Result.ok.inj (hsubS.symm.trans hsub)
  subst es
  have houtEq := Result.ok.inj (hloopS.symm.trans hloop)
  have hq2 : q2 = d2 := congrArg Prod.fst houtEq
  have he2Eq : e2 = exp2 := congrArg Prod.snd houtEq
  subst q2
  subst e2
  rcases hshape2 with ⟨hcap2, hdigit2, hpositive2, hend2⟩
  have hstartVal : expStart.val = exp1.val - 1 := by
    have hs := IScalar.sub_equiv exp1 1#i32
    rw [hsub] at hs
    simpa using hs.2.1
  have hpoint2 : (-17 <= d2.decimal_point.val /\
      d2.decimal_point.val <= 0) /\
      ((d2 = d1 /\ exp2.val + 1 = exp1.val) \/
        (exists shift : Std.Usize,
          shift.val <= 58 /\
          num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d1 shift = ok d2 /\
          exp2.val + 1 = exp1.val + (shift.val : Int))) := by
    rcases ParserExponentConstants with
      ⟨hbits, htotalBits, hsig, hexpbits, hexpsat, hinf, hbias, hmin,
        hsmall, hlarge, hroundmin, hroundmax⟩
    by_cases hstartHigh : -1022 <= expStart.val
    · have hbody :
          num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
              ok (done (d1, expStart)) := by
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
        rw [hmin]
        simp only [bind_tc_ok]
        have hnot : ¬ ((-1022)#i32 : Std.I32) > expStart := by
          change ¬ (-1022 : Int) > expStart.val
          omega
        simp [hnot]
      have hconstructed :
          num.imp.dec2flt.slow.parse_long_mantissa_loop2
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
              ok (d1, expStart) := by
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2
        rw [Aeneas.Std.loop.eq_1]
        simpa only [hbody]
      have heq := Result.ok.inj (hconstructed.symm.trans hloop)
      have hd : d1 = d2 := congrArg Prod.fst heq
      have he : expStart = exp2 := congrArg Prod.snd heq
      constructor
      · rw [← hd, hpoint1]
        omega
      · left
        exact ⟨hd.symm, by rw [← he]; omega⟩
    · have hstartLow : expStart.val < -1022 := by omega
      obtain ⟨diff, hdiff, hdiffSpec⟩ := Aeneas.Std.WP.spec_imp_exists
        (IScalar.sub_spec (x := ((-1022)#i32 : Std.I32)) (y := expStart) (by
          rw [IScalar.min_I32_eq]
          norm_num
          omega) (by
          rw [IScalar.max_I32_eq]
          norm_num
          omega))
      have hdiffVal : diff.val = -1022 - expStart.val := by
        simpa using hdiffSpec
      have hgapLo : 1 <= diff.val := by omega
      have hgapHi : diff.val <= 58 := by omega
      obtain ⟨shift, hshiftCast, hshiftSpec⟩ := Aeneas.Std.WP.spec_imp_exists
        (IScalar.hcast_inBounds_spec .Usize diff (by
          rw [hdiffVal]
          constructor <;> scalar_tac))
      have hshiftVal : (shift.val : Int) = diff.val := by
        simpa using hshiftSpec
      have hshift58 : shift.val <= 58 := by omega
      obtain ⟨z1, zs1, hshape1, hz1Lo, hz1Hi, hlen1⟩ :
          exists z zs,
            (d1.digits.val.take d1.num_digits.val).map (fun q => q.val) =
              z :: zs /\ 1 <= z /\ z < 10 /\
              ((d1.digits.val.take d1.num_digits.val).map
                (fun q => q.val)).length = d1.num_digits.val := hpositive1
      have hlen1' : (z1 :: zs1).length = d1.num_digits.val := by
        rw [← hshape1]
        exact hlen1
      have hpositive1Exec :
          exists z zs,
            (d1.digits.val.take d1.num_digits.val).map (fun a => a.val) =
              z :: zs /\ 1 <= z /\ z < 10 /\
              (z :: zs).length = d1.num_digits.val :=
        ⟨z1, zs1, hshape1, hz1Lo, hz1Hi, hlen1'⟩
      have hleadEq : d1.digits.val[0].val = z1 := by
        have hnumPos : 0 < d1.num_digits.val := by
          rw [← hlen1, hshape1]
          simp
        have hindexBound : (0 : Nat) < d1.digits.val.length := by
          rw [d1.digits.property]
          norm_num
        have hget : d1.digits.val[0]? = some d1.digits.val[0] :=
          getElem?_eq_some_iff.mpr ⟨hindexBound, rfl⟩
        have hhead := congrArg List.head? hshape1
        rw [List.head?_eq_getElem?] at hhead
        have htake : (d1.digits.val.take d1.num_digits.val)[0]? =
            some d1.digits.val[0] := by
          rw [List.getElem?_take, if_pos hnumPos]
          exact hget
        simp only [List.getElem?_map, htake] at hhead
        simpa using Option.some.inj hhead
      have hz1Five : 5 <= z1 := by omega
      obtain ⟨read, acc, q2, hpref, hreadLo, hreadHi, haccLo, haccHi,
          hprosLo, hprosHi, hright, hq2point, hq2nonzero⟩ :=
        DecimalRightShiftLoop0Execution d1 shift (by omega) (by omega)
          (by omega) ⟨hcap1, hdigit1, hpositive1Exec⟩
      have hread18 := P856_T1_RightPrefixReadBound d1 shift read acc
        hshift58 hcap1 hdigit1 z1 zs1 hshape1 hz1Five
        hlen1' hpref
      let shiftI : Std.I32 := UScalar.hcast .I32 shift
      have hshiftIVal : shiftI.val = (shift.val : Int) := by
        have hs := UScalar.hcast_inBounds_spec .I32 shift (by
          rw [IScalar.max_I32_eq]
          omega)
        simpa [shiftI, lift, WP.spec_ok] using hs
      obtain ⟨eout, hadd, haddSpec⟩ := Aeneas.Std.WP.spec_imp_exists
        (IScalar.add_spec (x := expStart) (y := shiftI) (by
          rw [hshiftIVal, IScalar.min_I32_eq]
          omega) (by
          rw [hshiftIVal, IScalar.max_I32_eq]
          omega))
      have heout : eout.val = -1022 := by
        rw [haddSpec, hshiftIVal, hshiftVal, hdiffVal]
        omega
      have hmaxShift :
          num.imp.dec2flt.slow.parse_long_mantissa.MAX_SHIFT = 60#usize := by
        rw [num.imp.dec2flt.slow.parse_long_mantissa.MAX_SHIFT.eq_def]
      have hnotCap : ¬ shift >
          num.imp.dec2flt.slow.parse_long_mantissa.MAX_SHIFT := by
        rw [hmaxShift]
        change ¬ shift.val > 60
        omega
      have hbodyCont :
          num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
              ok (cont (q2, eout)) := by
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
        rw [hmin]
        have hgt : ((-1022)#i32 : Std.I32) > expStart := by
          change (-1022 : Int) > expStart.val
          omega
        simp only [bind_tc_ok, hgt, if_true, hdiff]
        rw [hshiftCast]
        simp only [bind_tc_ok, hnotCap, if_false, hright, lift]
        rw [show UScalar.hcast .I32 shift = shiftI by rfl]
        simp only [bind_tc_ok, hadd]
      have hbodyDone :
          num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 q2 eout =
              ok (done (q2, eout)) := by
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
        rw [hmin]
        simp only [bind_tc_ok]
        have hnot : ¬ ((-1022)#i32 : Std.I32) > eout := by
          change ¬ (-1022 : Int) > eout.val
          omega
        simp [hnot]
      have hconstructed :
          num.imp.dec2flt.slow.parse_long_mantissa_loop2
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
              ok (q2, eout) := by
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2
        rw [Aeneas.Std.loop.eq_1]
        simp only [hbodyCont, bind_tc_ok]
        rw [Aeneas.Std.loop.eq_1]
        simpa only [hbodyDone]
      have heq := Result.ok.inj (hconstructed.symm.trans hloop)
      have hd : q2 = d2 := congrArg Prod.fst heq
      have he : eout = exp2 := congrArg Prod.snd heq
      have hp : d2.decimal_point.val =
          d1.decimal_point.val - (read.val : Int) + 1 := by
        rw [← hd, hq2point]
      rw [hpoint1] at hp
      constructor
      · omega
      · right
        refine ⟨shift, hshift58, ?_, ?_⟩
        · rw [← hd]
          exact hright
        · omega
  obtain ⟨z2, zs2, hshape2', hz2Lo, hz2Hi, hlen2⟩ := hpositive2
  have hpositive2Exec :
      exists z zs,
        (d2.digits.val.take d2.num_digits.val).map (fun a => a.val) = z :: zs /\
        1 <= z /\ z < 10 /\ (z :: zs).length = d2.num_digits.val := by
    exact ⟨z2, zs2, hshape2', hz2Lo, hz2Hi, by rw [← hshape2']; exact hlen2⟩
  obtain ⟨d3, q, hleft, hq19, hpoint3Eq, hpoint3Lo, hpoint3Hi, hnum3⟩ :=
    DecimalLeftShiftLoop1Execution d2 53#usize (by norm_num) (by omega)
      hpoint2.1.2 ⟨hcap2, hdigit2, hpositive2Exec⟩
  obtain ⟨growth, hgrowth, hgrowthVal⟩ :=
    DecimalLeftShiftDigitGrowth d2 53#usize 16 (by norm_num) (by norm_num)
      (by norm_num) hcap2 hdigit2
  have hgrowth16 : growth.val <= 16 := by
    rw [hgrowthVal]
    split <;> omega
  have hpoint3 : d3.decimal_point.val =
      d2.decimal_point.val + (growth.val : Int) :=
    P804_T1_LeftShiftPointGrowth d2 d3 53#usize growth hnum2 hgrowth
      (by omega) hleft
  have hcanonical := DecimalSeqLeftShiftCanonical d2 d3 53#usize
    (A / (2 : Real) ^ (exp2.val + 1))
    (B / (2 : Real) ^ (exp2.val + 1))
    ⟨hcap2, hdigit2,
      Or.inr ⟨z2, zs2, hshape2', hz2Lo, hz2Hi, hlen2⟩⟩
      hend2 (by norm_num) hleft
  dsimp only at hcanonical
  rcases hcanonical with ⟨hcap3, hdigit3, hshape3, hend3, q3, hq3,
    hpoint3Canon⟩
  rcases hshape3 with hzero3 | hpositive3
  · exfalso
    have hn : d3.num_digits.val ≠ 0 := by
      simpa [bne_iff_ne] using hnum3
    exact hn hzero3.1
  · rcases hend3 with ⟨eta3, u3, hA3, hB3, heta3, heta3u3, hsticky3⟩
    have hscaleA :
        (2 : Real) ^ (53 : Nat) *
            (A / (2 : Real) ^ (exp2.val + 1)) =
          A / (2 : Real) ^ (exp2.val - 52) := by
      rw [show exp2.val + 1 = (exp2.val - 52) + 53 by omega]
      rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      norm_num only [zpow_natCast]
      field_simp
    have hscaleB :
        (2 : Real) ^ (53 : Nat) *
            (B / (2 : Real) ^ (exp2.val + 1)) =
          B / (2 : Real) ^ (exp2.val - 52) := by
      rw [show exp2.val + 1 = (exp2.val - 52) + 53 by omega]
      rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      norm_num only [zpow_natCast]
      field_simp
    refine ⟨d3, hpoint2.1.1, hpoint2.1.2, hpoint2.2, hleft, ?_⟩
    dsimp only
    refine ⟨hcap3, hdigit3, hpositive3,
      ⟨eta3, u3, ?_, ?_, heta3, heta3u3, hsticky3⟩, ?_⟩
    · rw [← hscaleA]
      exact hA3
    · rw [← hscaleB]
      exact hB3
    · rw [hpoint3]
      omega

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.ParserSlowLoop2
import Tablet.P856_T1_RightPrefixReadBound
import Tablet.DecimalRightShiftLoop0Execution
import Tablet.DecimalLeftShiftLoop1Execution
import Tablet.DecimalSeqLeftShiftCanonical
import Tablet.DecimalLeftShiftDigitGrowth
import Tablet.P804_T1_LeftShiftPointGrowth
import Tablet.ParserExponentConstants

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P856_T1_FinalLeftShiftExecution]
theorem P856_T1_FinalLeftShiftExecution
    (A B : Real)
    (d1 d2 : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (exp1 expStart exp2 : Std.I32)
    (hexpLower : -1079 <= exp1.val)
    (hpoint1 : d1.decimal_point.val = 0)
    (hnum1 : d1.num_digits.val != 0)
    (hlead1 : 5 <= d1.digits.val[0].val)
    (hinput :
      let digits1 :=
        (d1.digits.val.take d1.num_digits.val).map (fun z => z.val)
      let integer1 : Nat := digits1.foldl (fun n digit => 10 * n + digit) 0
      let value1 : Real := integer1 * (10 : Real) ^
        (d1.decimal_point.val - (d1.num_digits.val : Int))
      d1.num_digits.val <= 768 /\
      (forall z, z ∈ d1.digits.val.take d1.num_digits.val -> z.val < 10) /\
      (exists z zs, digits1 = z :: zs /\ 1 <= z /\ z < 10 /\
        digits1.length = d1.num_digits.val) /\
      (exists eta1 u1 : Real,
        A / (2 : Real) ^ exp1.val = value1 + eta1 /\
        B / (2 : Real) ^ exp1.val = value1 + u1 /\
        0 <= eta1 /\ eta1 < u1 /\
        (d1.truncated = true <-> 0 < eta1)))
    (hsub : exp1 - 1#i32 = ok expStart)
    (hloop :
      num.imp.dec2flt.slow.parse_long_mantissa_loop2
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
          ok (d2, exp2)) :
    exists d3 : num.imp.dec2flt.decimal_seq.DecimalSeq,
      -17 <= d2.decimal_point.val /\ d2.decimal_point.val <= 0 /\
      ((d2 = d1 /\ exp2.val + 1 = exp1.val) \/
        (exists shift : Std.Usize,
          shift.val <= 58 /\
          num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d1 shift = ok d2 /\
          exp2.val + 1 = exp1.val + (shift.val : Int))) /\
      num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d2 53#usize = ok d3 /\
      (let digits3 :=
        (d3.digits.val.take d3.num_digits.val).map (fun z => z.val)
       let integer3 : Nat := digits3.foldl (fun n digit => 10 * n + digit) 0
       let value3 : Real := integer3 * (10 : Real) ^
         (d3.decimal_point.val - (d3.num_digits.val : Int))
       d3.num_digits.val <= 768 /\
       (forall z, z ∈ d3.digits.val.take d3.num_digits.val -> z.val < 10) /\
       (exists z zs, digits3 = z :: zs /\ 1 <= z /\ z < 10 /\
         digits3.length = d3.num_digits.val /\ digits3.getLast? != some 0) /\
       (exists eta3 u3 : Real,
         A / (2 : Real) ^ (exp2.val - 52) = value3 + eta3 /\
         B / (2 : Real) ^ (exp2.val - 52) = value3 + u3 /\
         0 <= eta3 /\ eta3 < u3 /\
         (d3.truncated = true <-> 0 < eta3)) /\
       d3.decimal_point.val < 19) := by
-- BODY
  dsimp only at hinput
  rcases hinput with ⟨hcap1, hdigit1, hpositive1, hend1⟩
  have hspec := ParserSlowLoop2 A B d1 exp1 hexpLower hpoint1 hnum1 hlead1
    ⟨hcap1, hdigit1, hend1⟩
  dsimp only at hspec
  rcases hspec with ⟨es, q2, e2, total, hsubS, hloopS, htotal,
    hes, he2, htotalEq, hpoint2Lo, hnum2, hshape2⟩
  have hesEq : es = expStart := Result.ok.inj (hsubS.symm.trans hsub)
  subst es
  have houtEq := Result.ok.inj (hloopS.symm.trans hloop)
  have hq2 : q2 = d2 := congrArg Prod.fst houtEq
  have he2Eq : e2 = exp2 := congrArg Prod.snd houtEq
  subst q2
  subst e2
  rcases hshape2 with ⟨hcap2, hdigit2, hpositive2, hend2⟩
  have hstartVal : expStart.val = exp1.val - 1 := by
    have hs := IScalar.sub_equiv exp1 1#i32
    rw [hsub] at hs
    simpa using hs.2.1
  have hpoint2 : (-17 <= d2.decimal_point.val /\
      d2.decimal_point.val <= 0) /\
      ((d2 = d1 /\ exp2.val + 1 = exp1.val) \/
        (exists shift : Std.Usize,
          shift.val <= 58 /\
          num.imp.dec2flt.decimal_seq.DecimalSeq.right_shift d1 shift = ok d2 /\
          exp2.val + 1 = exp1.val + (shift.val : Int))) := by
    rcases ParserExponentConstants with
      ⟨hbits, htotalBits, hsig, hexpbits, hexpsat, hinf, hbias, hmin,
        hsmall, hlarge, hroundmin, hroundmax⟩
    by_cases hstartHigh : -1022 <= expStart.val
    · have hbody :
          num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
              ok (done (d1, expStart)) := by
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
        rw [hmin]
        simp only [bind_tc_ok]
        have hnot : ¬ ((-1022)#i32 : Std.I32) > expStart := by
          change ¬ (-1022 : Int) > expStart.val
          omega
        simp [hnot]
      have hconstructed :
          num.imp.dec2flt.slow.parse_long_mantissa_loop2
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
              ok (d1, expStart) := by
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2
        rw [Aeneas.Std.loop.eq_1]
        simpa only [hbody]
      have heq := Result.ok.inj (hconstructed.symm.trans hloop)
      have hd : d1 = d2 := congrArg Prod.fst heq
      have he : expStart = exp2 := congrArg Prod.snd heq
      constructor
      · rw [← hd, hpoint1]
        omega
      · left
        exact ⟨hd.symm, by rw [← he]; omega⟩
    · have hstartLow : expStart.val < -1022 := by omega
      obtain ⟨diff, hdiff, hdiffSpec⟩ := Aeneas.Std.WP.spec_imp_exists
        (IScalar.sub_spec (x := ((-1022)#i32 : Std.I32)) (y := expStart) (by
          rw [IScalar.min_I32_eq]
          norm_num
          omega) (by
          rw [IScalar.max_I32_eq]
          norm_num
          omega))
      have hdiffVal : diff.val = -1022 - expStart.val := by
        simpa using hdiffSpec
      have hgapLo : 1 <= diff.val := by omega
      have hgapHi : diff.val <= 58 := by omega
      obtain ⟨shift, hshiftCast, hshiftSpec⟩ := Aeneas.Std.WP.spec_imp_exists
        (IScalar.hcast_inBounds_spec .Usize diff (by
          rw [hdiffVal]
          constructor <;> scalar_tac))
      have hshiftVal : (shift.val : Int) = diff.val := by
        simpa using hshiftSpec
      have hshift58 : shift.val <= 58 := by omega
      obtain ⟨z1, zs1, hshape1, hz1Lo, hz1Hi, hlen1⟩ :
          exists z zs,
            (d1.digits.val.take d1.num_digits.val).map (fun q => q.val) =
              z :: zs /\ 1 <= z /\ z < 10 /\
              ((d1.digits.val.take d1.num_digits.val).map
                (fun q => q.val)).length = d1.num_digits.val := hpositive1
      have hlen1' : (z1 :: zs1).length = d1.num_digits.val := by
        rw [← hshape1]
        exact hlen1
      have hpositive1Exec :
          exists z zs,
            (d1.digits.val.take d1.num_digits.val).map (fun a => a.val) =
              z :: zs /\ 1 <= z /\ z < 10 /\
              (z :: zs).length = d1.num_digits.val :=
        ⟨z1, zs1, hshape1, hz1Lo, hz1Hi, hlen1'⟩
      have hleadEq : d1.digits.val[0].val = z1 := by
        have hnumPos : 0 < d1.num_digits.val := by
          rw [← hlen1, hshape1]
          simp
        have hindexBound : (0 : Nat) < d1.digits.val.length := by
          rw [d1.digits.property]
          norm_num
        have hget : d1.digits.val[0]? = some d1.digits.val[0] :=
          getElem?_eq_some_iff.mpr ⟨hindexBound, rfl⟩
        have hhead := congrArg List.head? hshape1
        rw [List.head?_eq_getElem?] at hhead
        have htake : (d1.digits.val.take d1.num_digits.val)[0]? =
            some d1.digits.val[0] := by
          rw [List.getElem?_take, if_pos hnumPos]
          exact hget
        simp only [List.getElem?_map, htake] at hhead
        simpa using Option.some.inj hhead
      have hz1Five : 5 <= z1 := by omega
      obtain ⟨read, acc, q2, hpref, hreadLo, hreadHi, haccLo, haccHi,
          hprosLo, hprosHi, hright, hq2point, hq2nonzero⟩ :=
        DecimalRightShiftLoop0Execution d1 shift (by omega) (by omega)
          (by omega) ⟨hcap1, hdigit1, hpositive1Exec⟩
      have hread18 := P856_T1_RightPrefixReadBound d1 shift read acc
        hshift58 hcap1 hdigit1 z1 zs1 hshape1 hz1Five
        hlen1' hpref
      let shiftI : Std.I32 := UScalar.hcast .I32 shift
      have hshiftIVal : shiftI.val = (shift.val : Int) := by
        have hs := UScalar.hcast_inBounds_spec .I32 shift (by
          rw [IScalar.max_I32_eq]
          omega)
        simpa [shiftI, lift, WP.spec_ok] using hs
      obtain ⟨eout, hadd, haddSpec⟩ := Aeneas.Std.WP.spec_imp_exists
        (IScalar.add_spec (x := expStart) (y := shiftI) (by
          rw [hshiftIVal, IScalar.min_I32_eq]
          omega) (by
          rw [hshiftIVal, IScalar.max_I32_eq]
          omega))
      have heout : eout.val = -1022 := by
        rw [haddSpec, hshiftIVal, hshiftVal, hdiffVal]
        omega
      have hmaxShift :
          num.imp.dec2flt.slow.parse_long_mantissa.MAX_SHIFT = 60#usize := by
        rw [num.imp.dec2flt.slow.parse_long_mantissa.MAX_SHIFT.eq_def]
      have hnotCap : ¬ shift >
          num.imp.dec2flt.slow.parse_long_mantissa.MAX_SHIFT := by
        rw [hmaxShift]
        change ¬ shift.val > 60
        omega
      have hbodyCont :
          num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
              ok (cont (q2, eout)) := by
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
        rw [hmin]
        have hgt : ((-1022)#i32 : Std.I32) > expStart := by
          change (-1022 : Int) > expStart.val
          omega
        simp only [bind_tc_ok, hgt, if_true, hdiff]
        rw [hshiftCast]
        simp only [bind_tc_ok, hnotCap, if_false, hright, lift]
        rw [show UScalar.hcast .I32 shift = shiftI by rfl]
        simp only [bind_tc_ok, hadd]
      have hbodyDone :
          num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 q2 eout =
              ok (done (q2, eout)) := by
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
        rw [hmin]
        simp only [bind_tc_ok]
        have hnot : ¬ ((-1022)#i32 : Std.I32) > eout := by
          change ¬ (-1022 : Int) > eout.val
          omega
        simp [hnot]
      have hconstructed :
          num.imp.dec2flt.slow.parse_long_mantissa_loop2
            F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
              ok (q2, eout) := by
        unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2
        rw [Aeneas.Std.loop.eq_1]
        simp only [hbodyCont, bind_tc_ok]
        rw [Aeneas.Std.loop.eq_1]
        simpa only [hbodyDone]
      have heq := Result.ok.inj (hconstructed.symm.trans hloop)
      have hd : q2 = d2 := congrArg Prod.fst heq
      have he : eout = exp2 := congrArg Prod.snd heq
      have hp : d2.decimal_point.val =
          d1.decimal_point.val - (read.val : Int) + 1 := by
        rw [← hd, hq2point]
      rw [hpoint1] at hp
      constructor
      · omega
      · right
        refine ⟨shift, hshift58, ?_, ?_⟩
        · rw [← hd]
          exact hright
        · omega
  obtain ⟨z2, zs2, hshape2', hz2Lo, hz2Hi, hlen2⟩ := hpositive2
  have hpositive2Exec :
      exists z zs,
        (d2.digits.val.take d2.num_digits.val).map (fun a => a.val) = z :: zs /\
        1 <= z /\ z < 10 /\ (z :: zs).length = d2.num_digits.val := by
    exact ⟨z2, zs2, hshape2', hz2Lo, hz2Hi, by rw [← hshape2']; exact hlen2⟩
  obtain ⟨d3, q, hleft, hq19, hpoint3Eq, hpoint3Lo, hpoint3Hi, hnum3⟩ :=
    DecimalLeftShiftLoop1Execution d2 53#usize (by norm_num) (by omega)
      hpoint2.1.2 ⟨hcap2, hdigit2, hpositive2Exec⟩
  obtain ⟨growth, hgrowth, hgrowthVal⟩ :=
    DecimalLeftShiftDigitGrowth d2 53#usize 16 (by norm_num) (by norm_num)
      (by norm_num) hcap2 hdigit2
  have hgrowth16 : growth.val <= 16 := by
    rw [hgrowthVal]
    split <;> omega
  have hpoint3 : d3.decimal_point.val =
      d2.decimal_point.val + (growth.val : Int) :=
    P804_T1_LeftShiftPointGrowth d2 d3 53#usize growth hnum2 hgrowth
      (by omega) hleft
  have hcanonical := DecimalSeqLeftShiftCanonical d2 d3 53#usize
    (A / (2 : Real) ^ (exp2.val + 1))
    (B / (2 : Real) ^ (exp2.val + 1))
    ⟨hcap2, hdigit2,
      Or.inr ⟨z2, zs2, hshape2', hz2Lo, hz2Hi, hlen2⟩⟩
      hend2 (by norm_num) hleft
  dsimp only at hcanonical
  rcases hcanonical with ⟨hcap3, hdigit3, hshape3, hend3, q3, hq3,
    hpoint3Canon⟩
  rcases hshape3 with hzero3 | hpositive3
  · exfalso
    have hn : d3.num_digits.val ≠ 0 := by
      simpa [bne_iff_ne] using hnum3
    exact hn hzero3.1
  · rcases hend3 with ⟨eta3, u3, hA3, hB3, heta3, heta3u3, hsticky3⟩
    have hscaleA :
        (2 : Real) ^ (53 : Nat) *
            (A / (2 : Real) ^ (exp2.val + 1)) =
          A / (2 : Real) ^ (exp2.val - 52) := by
      rw [show exp2.val + 1 = (exp2.val - 52) + 53 by omega]
      rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      norm_num only [zpow_natCast]
      field_simp
    have hscaleB :
        (2 : Real) ^ (53 : Nat) *
            (B / (2 : Real) ^ (exp2.val + 1)) =
          B / (2 : Real) ^ (exp2.val - 52) := by
      rw [show exp2.val + 1 = (exp2.val - 52) + 53 by omega]
      rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      norm_num only [zpow_natCast]
      field_simp
    refine ⟨d3, hpoint2.1.1, hpoint2.1.2, hpoint2.2, hleft, ?_⟩
    dsimp only
    refine ⟨hcap3, hdigit3, hpositive3,
      ⟨eta3, u3, ?_, ?_, heta3, heta3u3, hsticky3⟩, ?_⟩
    · rw [← hscaleA]
      exact hA3
    · rw [← hscaleB]
      exact hB3
    · rw [hpoint3]
      omega

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (201)
More program dependencies (159)
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 127 entries
Technical checking records
Local closure summary
{
  "node": "P856_T1_FinalLeftShiftExecution",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "af415feda5c17555d84f1d3086be679e552749c5710beb65fe461ac8843eced5",
  "active_statement_hash": "321c0a659a6a0155d8870693b86c24cd2080fa3b096310446d50e47229f6fa4c",
  "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": "revalidate-cycle-199",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalLeftShiftDigitGrowth": "6dcf8858df4713eb",
    "DecimalLeftShiftLoop1Execution": "c945a26c8d67077b",
    "DecimalRightShiftLoop0Execution": "e27252660de78d95",
    "DecimalSeqLeftShiftCanonical": "bcdb7c96b3a59e9d",
    "P804_T1_LeftShiftPointGrowth": "6a9a6c7c27a2ac4e",
    "P856_T1_RightPrefixReadBound": "ce3631cbe954c768",
    "ParserExponentConstants": "e2a30a7b0c5e9c91",
    "ParserSlowLoop2": "988df2b319919687",
    "SlowShiftSelectorCertificate": "78f0b22ceeb544a4",
    "num_imp_dec2flt_slow_parse_long_mantissa_MAX_SHIFT": "a858290d96a26cbd"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "92d5f91a5a106668",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "fd298e37d5ae4f86",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "4db7c37f5da1c6e0",
    "num_imp_dec2flt_decimal_seq_number_of_digits_decimal_left_shift": "b3efbd0e6b3fe061",
    "num_imp_dec2flt_slow_parse_long_mantissa": "f4b1825aa46c08b9",
    "num_imp_dec2flt_slow_parse_long_mantissa_MAX_SHIFT": "32f403f33bee78a7",
    "num_imp_traits_Float": "996e90a556298539"
  }
}
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:a7b5a860a1939c7ac8e503dc44cb4124c2ccb6df29dcede5b3d822ca6b16b806",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}