ParserSlowLoop2

Lean checked

Statement

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

Lemma · Slow subnormal adjustment with fixed endpoints

Let the loop-1 exit have point zero, nonzero count, leading digit at least five, exponent e_1\geq-1079, and fixed-endpoint invariant for A<B. The checked decrement gives e_s=e_1-1. The third extracted loop returns (d_2,e_2) with
e_2=\max(e_s,-1022),\qquad q=(e_2-e_s)_{\mathbb N}\leq58,
where q is the exact total right shift. No shift resets the record, and d_2 has point at least -2047, nonzero count, decimal cells and positive leading digit. Its endpoint invariant is
A/2^{e_2+1}=V(d_2)+\eta_2,qquad B/2^{e_2+1}=V(d_2)+u_2,qquad0\leq\eta_2<u_2,qquad d_2.\mathit{truncated}\iff0<\eta_2.

Lean statement

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

import Tablet.DecimalSeqRightShiftCanonical
import Tablet.DecimalRightShiftLoop0Execution
import Tablet.ParserSlowLoop1
import Tablet.ParserExponentConstants
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa_MAX_SHIFT

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserSlowLoop2]
theorem ParserSlowLoop2 :
    forall (A B : Real) (d1 : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (exp1 : Std.I32),
      -1079 <= exp1.val -> d1.decimal_point.val = 0 ->
      d1.num_digits.val != 0 -> 5 <= d1.digits.val[0].val ->
      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 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)) ->
      exists (expStart : Std.I32)
        (d2 : num.imp.dec2flt.decimal_seq.DecimalSeq)
        (exp2 : Std.I32) (totalShift : Nat),
        exp1 - 1#i32 = ok expStart /\
        num.imp.dec2flt.slow.parse_long_mantissa_loop2
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
            ok (d2, exp2) /\
        totalShift <= 58 /\
        expStart.val = exp1.val - 1 /\
        exp2.val = max expStart.val (-1022) /\
        totalShift = (exp2.val - expStart.val).toNat /\
        -2047 <= d2.decimal_point.val /\ d2.num_digits.val != 0 /\
        let digits2 :=
          (d2.digits.val.take d2.num_digits.val).map (fun z => z.val)
        let integer2 : Nat := digits2.foldl (fun n digit => 10 * n + digit) 0
        let value2 : Real := integer2 * (10 : Real) ^
          (d2.decimal_point.val - (d2.num_digits.val : Int))
        d2.num_digits.val <= 768 /\
        (forall z, z ∈ d2.digits.val.take d2.num_digits.val -> z.val < 10) /\
        (exists z zs, digits2 = z :: zs /\ 1 <= z /\ z < 10 /\
          digits2.length = d2.num_digits.val) /\
        exists eta2 u2 : Real,
          A / (2 : Real) ^ (exp2.val + 1) = value2 + eta2 /\
          B / (2 : Real) ^ (exp2.val + 1) = value2 + u2 /\
          0 <= eta2 /\ eta2 < u2 /\
          (d2.truncated = true <-> 0 < eta2) := 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

First derive the canonical retained-list shape that is not explicit among the hypotheses. The digit array has length 768, and the count is at most 768, so taking the first n_1 cells and mapping to naturals gives a list of length exactly n_1. Since n_1\ne0, write that list as z::z_s. Looking at index zero in the take and map shows z=d_1.\mathit{digits}[0]. Thus z\geq5, and the digit-bound hypothesis applied to the first retained cell gives z<10. In particular the input has the positive-leading shape required below.
Checked subtraction of one from e_1\geq-1079 is within I32 range; call its result e_s, so e_s=e_1-1\geq-1080. By ParserExponentConstants, the binary64 minimum exponent returned by the traits record is -1022.
Suppose first that e_s\geq-1022. Unfold loop 2 in num imp dec2flt slow parse long mantissa. Its initial comparison -1022>e_s is false, so the body returns the unchanged pair and the generic loop finishes immediately. Take d_2=d_1, e_2=e_s, and q=0. Then e_2=\max(e_s,-1022) and q=(e_2-e_s)_{\mathbb N}=0\leq58. Point, count, digits, leading shape, and sticky relation are unchanged. Since e_s+1=e_1, the two assumed endpoint equations are already the required final equations.
Now suppose e_s<-1022. The checked I32 difference g=-1022-e_s exists and satisfies
1\leq g\leq58,
the upper bound following from e_s\geq-1080. Its checked cast to Usize therefore has the same value. The extracted cap is literally 60 by num imp dec2flt slow parse long mantissa MAX SHIFT; hence the comparison with the cap is false and the selected shift is exactly g. Apply DecimalRightShiftLoop0Execution to the point-zero record, the canonical list just derived, and g\leq58\leq60. Its point hypotheses 0\leq p<310 follow from p=0. It executes every checked operation in the decimal right shift, proves the prospective point is at least -2047, excludes reset, and supplies a normally returned record d_2 with nonzero count.
The checked cast of g\leq58 back to I32 exists. Adding it to e_s is within range and gives
e_2=e_s+g=-1022.
Thus the first loop body returns a continuation at (d_2,e_2). On the next body call the strict comparison -1022>e_2 is false, so the loop terminates. This proves the exact loop call, e_2=\max(e_s,-1022), and q=g=(e_2-e_s)_{\mathbb N}\leq58.
Finally apply DecimalSeqRightShiftCanonical to the successful shift call. Its hypotheses are precisely the count bound, per-cell digit bound, positive-leading shape, fixed endpoints, g\leq58\leq60, and nonzero output established above. It supplies the output count and digit bounds, positive leading list shape, point lower bound, sticky equivalence, and errors \eta_2,u_2 with transported endpoints. Since
e_2+1=e_s+g+1=e_1+g,
the elementary power law 2^{e_1+g}=2^{e_1}2^g rewrites those transported equations as
A/2^{e_2+1}=V(d_2)+\eta_2, \qquad B/2^{e_2+1}=V(d_2)+u_2.
All remaining inequalities and the truncation equivalence are exactly those returned by the canonical-shift theorem, completing every existential clause.

Lean proof


  dsimp only
  intro A B d1 exp1 hexpLower hpoint hnumne hlead hinput
  rcases hinput with ⟨hcap, hdigit, eta1, u1, hA, hB, heta0, hetau,
    hsticky⟩
  let Digits := fun d : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    (d.digits.val.take d.num_digits.val).map (fun z => z.val)
  have hnumne' : d1.num_digits.val ≠ 0 := by
    simpa [bne_iff_ne] using hnumne
  have hlen : (Digits d1).length = d1.num_digits.val := by
    simp only [Digits, List.length_map, List.length_take]
    rw [d1.digits.property]
    change min d1.num_digits.val 768 = d1.num_digits.val
    exact Nat.min_eq_left hcap
  have hlistne : Digits d1 ≠ [] := by
    intro hnil
    rw [hnil] at hlen
    simp at hlen
    omega
  obtain ⟨z, zs, hshape⟩ := List.exists_cons_of_ne_nil hlistne
  have hnumPos : 0 < d1.num_digits.val := by omega
  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? hshape
  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 [Digits, List.getElem?_map, htake] at hhead
  have hleadEq : d1.digits.val[0].val = z := by
    simpa using Option.some.inj hhead
  have hdigitNat : forall q, q ∈ Digits d1 -> q < 10 := by
    intro q hq
    simp only [Digits, List.mem_map] at hq
    rcases hq with ⟨a, ha, rfl⟩
    exact hdigit a ha
  have hzLo : 1 <= z := by omega
  have hzHi : z < 10 := hdigitNat z (by rw [hshape]; simp)
  have hlenCons : (z :: zs).length = d1.num_digits.val := by
    rw [← hshape]
    exact hlen
  have hshapeInput :
      d1.num_digits.val <= 768 /\
      (forall q, q ∈ d1.digits.val.take d1.num_digits.val -> q.val < 10) /\
      (exists z zs, Digits d1 = z :: zs /\ 1 <= z /\ z < 10 /\
        (Digits d1).length = d1.num_digits.val) := by
    exact ⟨hcap, hdigit, z, zs, hshape, hzLo, hzHi, hlen⟩
  obtain ⟨expStart, hsub, hsubSpec⟩ := Aeneas.Std.WP.spec_imp_exists
    (IScalar.sub_spec (x := exp1) (y := 1#i32) (by
      rw [IScalar.min_I32_eq]
      norm_num
      omega) (by
      rw [IScalar.max_I32_eq]
      norm_num
      have := exp1.bv.isLt
      scalar_tac))
  have hstartVal : expStart.val = exp1.val - 1 := by
    simpa using hsubSpec
  rcases ParserExponentConstants with
    ⟨hbits, htotal, hsig, hexpbits, hexpsat, hinf, hbias, hmin,
      hsmall, hlarge, hroundmin, hroundmax⟩
  by_cases hstartHigh : -1022 <= expStart.val
  · have hnotGt : ¬ ((-1022)#i32 : Std.I32) > expStart := by
      change ¬ (-1022 : Int) > expStart.val
      omega
    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]
      by_cases hgt : ((-1022)#i32 : Std.I32) > expStart
      · change expStart.val < -1022 at hgt
        omega
      · simp only [hgt, if_false]
    have hloop :
        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]
    refine ⟨expStart, d1, expStart, 0, hsub, hloop, by omega, hstartVal,
      ?_, by simp, by omega, by simpa [bne_iff_ne] using hnumne', ?_⟩
    · simp [max_eq_left hstartHigh]
    · dsimp only
      refine ⟨hcap, hdigit, ⟨z, zs, hshape, hzLo, hzHi, hlen⟩,
        eta1, u1, ?_, ?_, heta0, hetau, hsticky⟩
      · simpa [show expStart.val + 1 = exp1.val by omega] using hA
      · simpa [show expStart.val + 1 = exp1.val by omega] using hB
  · 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 ⟨read, acc, d2, hpref, hreadLo, hreadHi, haccLo, haccHi,
        hprosLo, hprosHi, hright, hd2point, hd2nonzero⟩ :=
      DecimalRightShiftLoop0Execution d1 shift (by omega) (by omega) (by omega)
        ⟨hcap, hdigit, z, zs, by simpa [Digits] using hshape, hzLo, hzHi,
          hlenCons⟩
    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 ⟨exp2, 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 hexp2Val : exp2.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 (d2, exp2)) := 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 hnotGt2 : ¬ ((-1022)#i32 : Std.I32) > exp2 := by
      change ¬ (-1022 : Int) > exp2.val
      omega
    have hbodyDone :
        num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d2 exp2 =
            ok (done (d2, exp2)) := by
      unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
      rw [hmin]
      simp only [bind_tc_ok]
      by_cases hgt : ((-1022)#i32 : Std.I32) > exp2
      · change exp2.val < -1022 at hgt
        omega
      · simp only [hgt, if_false]
    have hloop :
        num.imp.dec2flt.slow.parse_long_mantissa_loop2
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
            ok (d2, exp2) := 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 hcanonical := DecimalSeqRightShiftCanonical d1 d2 shift
      (A / (2 : Real) ^ exp1.val) (B / (2 : Real) ^ exp1.val)
      ⟨hcap, hdigit, z, zs, by simpa [Digits] using hshape, hzLo, hzHi,
        by simpa [Digits] using hlen⟩
      ⟨eta1, u1, hA, hB, heta0, hetau, hsticky⟩
      (by omega) hright hd2nonzero
    dsimp only at hcanonical
    rcases hcanonical with ⟨hcap2, hdigit2, hshapePack, hendPack, hpoint2⟩
    rcases hshapePack with ⟨z2, zs2, hshape2, hz2Lo, hz2Hi, hlen2, hlast2⟩
    rcases hendPack with ⟨eta2, u2, hA2, hB2, heta2, heta2u2, hsticky2⟩
    have hscaleA :
        (A / (2 : Real) ^ exp1.val) / (2 : Real) ^ shift.val =
          A / (2 : Real) ^ (exp2.val + 1) := by
      have heq : exp2.val + 1 = exp1.val + (shift.val : Int) := by omega
      rw [heq, zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      norm_num only [zpow_natCast]
      rw [div_div]
    have hscaleB :
        (B / (2 : Real) ^ exp1.val) / (2 : Real) ^ shift.val =
          B / (2 : Real) ^ (exp2.val + 1) := by
      have heq : exp2.val + 1 = exp1.val + (shift.val : Int) := by omega
      rw [heq, zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      norm_num only [zpow_natCast]
      rw [div_div]
    refine ⟨expStart, d2, exp2, shift.val, hsub, hloop, hshift58,
      hstartVal, ?_, ?_, hpoint2, by simpa [bne_iff_ne] using hd2nonzero, ?_⟩
    · rw [hexp2Val, max_eq_right (by omega)]
    · rw [hexp2Val]
      omega
    · dsimp only
      refine ⟨hcap2, hdigit2, ⟨z2, zs2, hshape2, hz2Lo, hz2Hi, hlen2⟩,
        eta2, u2, ?_, ?_, heta2, heta2u2, hsticky2⟩
      · rw [← hscaleA]
        exact hA2
      · rw [← hscaleB]
        exact hB2


end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalSeqRightShiftCanonical
import Tablet.DecimalRightShiftLoop0Execution
import Tablet.ParserSlowLoop1
import Tablet.ParserExponentConstants
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa
import Tablet.num_imp_dec2flt_slow_parse_long_mantissa_MAX_SHIFT

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: ParserSlowLoop2]
theorem ParserSlowLoop2 :
    forall (A B : Real) (d1 : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (exp1 : Std.I32),
      -1079 <= exp1.val -> d1.decimal_point.val = 0 ->
      d1.num_digits.val != 0 -> 5 <= d1.digits.val[0].val ->
      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 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)) ->
      exists (expStart : Std.I32)
        (d2 : num.imp.dec2flt.decimal_seq.DecimalSeq)
        (exp2 : Std.I32) (totalShift : Nat),
        exp1 - 1#i32 = ok expStart /\
        num.imp.dec2flt.slow.parse_long_mantissa_loop2
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
            ok (d2, exp2) /\
        totalShift <= 58 /\
        expStart.val = exp1.val - 1 /\
        exp2.val = max expStart.val (-1022) /\
        totalShift = (exp2.val - expStart.val).toNat /\
        -2047 <= d2.decimal_point.val /\ d2.num_digits.val != 0 /\
        let digits2 :=
          (d2.digits.val.take d2.num_digits.val).map (fun z => z.val)
        let integer2 : Nat := digits2.foldl (fun n digit => 10 * n + digit) 0
        let value2 : Real := integer2 * (10 : Real) ^
          (d2.decimal_point.val - (d2.num_digits.val : Int))
        d2.num_digits.val <= 768 /\
        (forall z, z ∈ d2.digits.val.take d2.num_digits.val -> z.val < 10) /\
        (exists z zs, digits2 = z :: zs /\ 1 <= z /\ z < 10 /\
          digits2.length = d2.num_digits.val) /\
        exists eta2 u2 : Real,
          A / (2 : Real) ^ (exp2.val + 1) = value2 + eta2 /\
          B / (2 : Real) ^ (exp2.val + 1) = value2 + u2 /\
          0 <= eta2 /\ eta2 < u2 /\
          (d2.truncated = true <-> 0 < eta2) := by
-- BODY
  dsimp only
  intro A B d1 exp1 hexpLower hpoint hnumne hlead hinput
  rcases hinput with ⟨hcap, hdigit, eta1, u1, hA, hB, heta0, hetau,
    hsticky⟩
  let Digits := fun d : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    (d.digits.val.take d.num_digits.val).map (fun z => z.val)
  have hnumne' : d1.num_digits.val ≠ 0 := by
    simpa [bne_iff_ne] using hnumne
  have hlen : (Digits d1).length = d1.num_digits.val := by
    simp only [Digits, List.length_map, List.length_take]
    rw [d1.digits.property]
    change min d1.num_digits.val 768 = d1.num_digits.val
    exact Nat.min_eq_left hcap
  have hlistne : Digits d1 ≠ [] := by
    intro hnil
    rw [hnil] at hlen
    simp at hlen
    omega
  obtain ⟨z, zs, hshape⟩ := List.exists_cons_of_ne_nil hlistne
  have hnumPos : 0 < d1.num_digits.val := by omega
  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? hshape
  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 [Digits, List.getElem?_map, htake] at hhead
  have hleadEq : d1.digits.val[0].val = z := by
    simpa using Option.some.inj hhead
  have hdigitNat : forall q, q ∈ Digits d1 -> q < 10 := by
    intro q hq
    simp only [Digits, List.mem_map] at hq
    rcases hq with ⟨a, ha, rfl⟩
    exact hdigit a ha
  have hzLo : 1 <= z := by omega
  have hzHi : z < 10 := hdigitNat z (by rw [hshape]; simp)
  have hlenCons : (z :: zs).length = d1.num_digits.val := by
    rw [← hshape]
    exact hlen
  have hshapeInput :
      d1.num_digits.val <= 768 /\
      (forall q, q ∈ d1.digits.val.take d1.num_digits.val -> q.val < 10) /\
      (exists z zs, Digits d1 = z :: zs /\ 1 <= z /\ z < 10 /\
        (Digits d1).length = d1.num_digits.val) := by
    exact ⟨hcap, hdigit, z, zs, hshape, hzLo, hzHi, hlen⟩
  obtain ⟨expStart, hsub, hsubSpec⟩ := Aeneas.Std.WP.spec_imp_exists
    (IScalar.sub_spec (x := exp1) (y := 1#i32) (by
      rw [IScalar.min_I32_eq]
      norm_num
      omega) (by
      rw [IScalar.max_I32_eq]
      norm_num
      have := exp1.bv.isLt
      scalar_tac))
  have hstartVal : expStart.val = exp1.val - 1 := by
    simpa using hsubSpec
  rcases ParserExponentConstants with
    ⟨hbits, htotal, hsig, hexpbits, hexpsat, hinf, hbias, hmin,
      hsmall, hlarge, hroundmin, hroundmax⟩
  by_cases hstartHigh : -1022 <= expStart.val
  · have hnotGt : ¬ ((-1022)#i32 : Std.I32) > expStart := by
      change ¬ (-1022 : Int) > expStart.val
      omega
    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]
      by_cases hgt : ((-1022)#i32 : Std.I32) > expStart
      · change expStart.val < -1022 at hgt
        omega
      · simp only [hgt, if_false]
    have hloop :
        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]
    refine ⟨expStart, d1, expStart, 0, hsub, hloop, by omega, hstartVal,
      ?_, by simp, by omega, by simpa [bne_iff_ne] using hnumne', ?_⟩
    · simp [max_eq_left hstartHigh]
    · dsimp only
      refine ⟨hcap, hdigit, ⟨z, zs, hshape, hzLo, hzHi, hlen⟩,
        eta1, u1, ?_, ?_, heta0, hetau, hsticky⟩
      · simpa [show expStart.val + 1 = exp1.val by omega] using hA
      · simpa [show expStart.val + 1 = exp1.val by omega] using hB
  · 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 ⟨read, acc, d2, hpref, hreadLo, hreadHi, haccLo, haccHi,
        hprosLo, hprosHi, hright, hd2point, hd2nonzero⟩ :=
      DecimalRightShiftLoop0Execution d1 shift (by omega) (by omega) (by omega)
        ⟨hcap, hdigit, z, zs, by simpa [Digits] using hshape, hzLo, hzHi,
          hlenCons⟩
    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 ⟨exp2, 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 hexp2Val : exp2.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 (d2, exp2)) := 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 hnotGt2 : ¬ ((-1022)#i32 : Std.I32) > exp2 := by
      change ¬ (-1022 : Int) > exp2.val
      omega
    have hbodyDone :
        num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d2 exp2 =
            ok (done (d2, exp2)) := by
      unfold num.imp.dec2flt.slow.parse_long_mantissa_loop2.body
      rw [hmin]
      simp only [bind_tc_ok]
      by_cases hgt : ((-1022)#i32 : Std.I32) > exp2
      · change exp2.val < -1022 at hgt
        omega
      · simp only [hgt, if_false]
    have hloop :
        num.imp.dec2flt.slow.parse_long_mantissa_loop2
          F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
            ok (d2, exp2) := 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 hcanonical := DecimalSeqRightShiftCanonical d1 d2 shift
      (A / (2 : Real) ^ exp1.val) (B / (2 : Real) ^ exp1.val)
      ⟨hcap, hdigit, z, zs, by simpa [Digits] using hshape, hzLo, hzHi,
        by simpa [Digits] using hlen⟩
      ⟨eta1, u1, hA, hB, heta0, hetau, hsticky⟩
      (by omega) hright hd2nonzero
    dsimp only at hcanonical
    rcases hcanonical with ⟨hcap2, hdigit2, hshapePack, hendPack, hpoint2⟩
    rcases hshapePack with ⟨z2, zs2, hshape2, hz2Lo, hz2Hi, hlen2, hlast2⟩
    rcases hendPack with ⟨eta2, u2, hA2, hB2, heta2, heta2u2, hsticky2⟩
    have hscaleA :
        (A / (2 : Real) ^ exp1.val) / (2 : Real) ^ shift.val =
          A / (2 : Real) ^ (exp2.val + 1) := by
      have heq : exp2.val + 1 = exp1.val + (shift.val : Int) := by omega
      rw [heq, zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      norm_num only [zpow_natCast]
      rw [div_div]
    have hscaleB :
        (B / (2 : Real) ^ exp1.val) / (2 : Real) ^ shift.val =
          B / (2 : Real) ^ (exp2.val + 1) := by
      have heq : exp2.val + 1 = exp1.val + (shift.val : Int) := by omega
      rw [heq, zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      norm_num only [zpow_natCast]
      rw [div_div]
    refine ⟨expStart, d2, exp2, shift.val, hsub, hloop, hshift58,
      hstartVal, ?_, ?_, hpoint2, by simpa [bne_iff_ne] using hd2nonzero, ?_⟩
    · rw [hexp2Val, max_eq_right (by omega)]
    · rw [hexp2Val]
      omega
    · dsimp only
      refine ⟨hcap2, hdigit2, ⟨z2, zs2, hshape2, hz2Lo, hz2Hi, hlen2⟩,
        eta2, u2, ?_, ?_, heta2, heta2u2, hsticky2⟩
      · rw [← hscaleA]
        exact hA2
      · rw [← hscaleB]
        exact hB2


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 121 entries
Technical checking records
Local closure summary
{
  "node": "ParserSlowLoop2",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "55f09187d5c002cdb01291831f813b99a4458ec62ca8086938a09f009022c17b",
  "active_statement_hash": "f3d880b4b019e998f0405c57f89b4fe246df7cb8b941378260bc09058bdbd23a",
  "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-192",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalRightShiftLoop0Execution": "e27252660de78d95",
    "DecimalSeqRightShiftCanonical": "fc2c059f527d234a",
    "ParserExponentConstants": "e2a30a7b0c5e9c91",
    "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": "13e3cec939d02f51",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "1aaf1bb11c0b6a49",
    "num_imp_dec2flt_slow_parse_long_mantissa": "6301f3828274183b",
    "num_imp_dec2flt_slow_parse_long_mantissa_MAX_SHIFT": "32f403f33bee78a7",
    "num_imp_traits_Float": "996e90a556298539"
  }
}
Prose assessment
{
  "label": "Sound flag superseded by recorded Lean closure",
  "assessment_status": "VerifierFail",
  "fingerprint_relation": "differs from current fingerprint",
  "assessment_fingerprint": "sound-v2:5ade3d5fe52e4595917b01abf93699e2bc1e22e403912af7c8a7ef3721137bf3",
  "current_fingerprint": "sound-v2:b5a486f4a7c5ad912bd66ef4d27eae481f1ff76a15722e075c3924fcd87bc5cd",
  "superseded_for_theorem_closure": true
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Fail",
  "substantiveness_status": "Pass"
}