P856_T1_SeparationPackage

Lean checked

Statement

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

Helper · Reachable final separation package

Let A,B,d,d_0,d_1,d_2,e_0,e_1,e_s,e_2 satisfy the complete initial adjacent-cell package and the exact loop-0, loop-1, checked-decrement, and loop-2 histories displayed in Lean. Assume also the displayed canonical and endpoint package for d_2. Then the exact 53-bit left shift of d_2 returns a record d_3. Writing V_3 for its retained decimal value, this record has at most 768 decimal digits, a nonzero leading digit, a nonzero last digit, and point below 19. There are 0\leq\eta_3<u_3 with
A/2^{e_2-52}=V_3+\eta_3,\qquad B/2^{e_2-52}=V_3+u_3,
and its truncation flag is true exactly when \eta_3>0. Moreover
0\leq A/2^{e_2-52}<2^{64}-\tfrac12,
and, for every n\in\mathbb N, neither an integer midpoint nor an odd integer lies strictly inside the final interval:
n+\tfrac12\leq V_3\ \lor\ B/2^{e_2-52}\leq n+\tfrac12,
2n+1\leq V_3\ \lor\ B/2^{e_2-52}\leq2n+1.

Lean statement

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

import Tablet.P856_T1_ReachableCapacity
import Tablet.P856_T1_FinalLeftShiftExecution
import Tablet.P856_T1_LeftHistoryTransport
import Tablet.P856_T1_RightHistoryTransport
import Tablet.P856_T1_CoefficientGridAlignment
import Tablet.P798_T1_GridAlignment
import Tablet.P798_T1_GridBoundaryRetained
import Tablet.P798_T1_LeftBoundaryTransport
import Tablet.P798_T1_RightBoundaryTransport
import Tablet.P804_T1_DecimalValueBounds
import Tablet.ParserSlowReachableNormalizationBounds
import Mathlib.Tactic.FieldSimp

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P856_T1_SeparationPackage]
theorem P856_T1_SeparationPackage :
    forall (A B : Real)
      (d d0 d1 d2 : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (exp0 exp1 expStart exp2 : Std.I32),
      -324 <= d.decimal_point.val -> d.decimal_point.val < 310 ->
      let digits :=
        (d.digits.val.take d.num_digits.val).map (fun z => z.val)
      let integer : Nat := digits.foldl (fun n digit => 10 * n + digit) 0
      let value : Real := integer * (10 : Real) ^
        (d.decimal_point.val - (d.num_digits.val : Int))
      let cutoff : Real := (10 : Real) ^
        (d.decimal_point.val - (768 : Int))
      d.num_digits.val <= 768 /\
      (forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) /\
      (exists z zs, digits = z :: zs /\ 1 <= z /\ z < 10 /\
        digits.length = d.num_digits.val) /\
      B = value + cutoff /\
      (exists eta : Real,
        A = value + eta /\ 0 <= eta /\ eta < cutoff /\
        (d.truncated = true <-> 0 < eta)) ->
      num.imp.dec2flt.slow.parse_long_mantissa_loop0
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 0#i32 }
        d.num_digits d.decimal_point d.truncated d.digits 0#i32 none =
          ok (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits,
            exp0, none) ->
      num.imp.dec2flt.slow.parse_long_mantissa_loop1
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 2047#i32 }
        d0.num_digits d0.decimal_point d0.truncated d0.digits exp0 none =
          ok (d1.num_digits, d1.decimal_point, d1.truncated, d1.digits,
            exp1, none) ->
      exp1 - 1#i32 = ok expStart ->
      num.imp.dec2flt.slow.parse_long_mantissa_loop2
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
          ok (d2, exp2) ->
      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)) ->
      exists d3 : num.imp.dec2flt.decimal_seq.DecimalSeq,
        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 /\
        0 <= A / (2 : Real) ^ (exp2.val - 52) /\
        A / (2 : Real) ^ (exp2.val - 52) <
          (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) /\
        (forall n : Nat,
          (n : Real) + (1 / 2 : Real) <= value3 \/
            B / (2 : Real) ^ (exp2.val - 52) <=
              (n : Real) + (1 / 2 : Real)) /\
        (forall n : Nat,
          ((2 * n + 1 : Nat) : Real) <= value3 \/
            B / (2 : Real) ^ (exp2.val - 52) <=
              ((2 * n + 1 : Nat) : Real)) := 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

Write V(q) for the retained decimal value of a record q. Apply ParserSlowLoop0 and ParserSlowLoop1 to the initial package. Injectivity of successful results identifies their outputs with the supplied d_0,e_0 and d_1,e_1. Thus all canonical record and endpoint facts in those statements hold for the displayed histories. Their reachability lower bound, together with those same histories, permits ParserSlowReachableNormalizationBounds; hence
B/2^{e_1}\leq1,\qquad -1079\leq e_1. \tag{1}
The original adjacent-cell equations also give A<B, because their common retained value is followed by errors 0\leq\eta<10^{p-768} and 10^{p-768}>0.
Apply ReachableCapacity to the exact histories. It gives the key reachable capacity
0\leq e_2-e_0+715-d_0.\mathit{point}. \tag{2}
Next apply FinalLeftShiftExecution. Its hypotheses are exactly (1), the checked decrement, the loop-2 call, and the canonical endpoint package just obtained for d_1. It supplies d_3, the successful 53-bit shift, all the asserted digit, trim, endpoint, sticky, and point facts, and the following exhaustive description of the last pre-shift step: either d_2=d_1 and e_2+1=e_1, or an exact right shift by some k\leq58 takes d_1 to d_2 and e_2+1=e_1+k. (3)
We establish one coefficient-parametric separation fact. Fix c\in\mathbb N and R\in\mathbb Z, suppose the 768-cell capacity inequality for the boundary c2^R holds at d_0, d_2, and d_3, and assume for contradiction
V(d_3)<c2^{R-(e_2-52)}<B/2^{e_2-52}. \tag{4}
If c2^{R-(e_2+1)}\leq V(d_2), then CoefficientGridAlignment aligns its factor-2^{53} multiple to the 768-cell grid of d_3. Positivity of V(d_2) follows from its nonzero leading digit and DecimalValueBounds. Consequently LeftBoundaryTransport, applied to the exact 53-bit shift, puts that multiple below V(d_3), contradicting the first inequality in (4). Therefore
V(d_2)<c2^{R-(e_2+1)}. \tag{5}
In the identity case of (3), (5) immediately says V(d_1)<c2^{R-e_1}. In its right-shift case, suppose instead that c2^{R-e_1}\leq V(d_1). Align the divided boundary to the grid of d_2 using CoefficientGridAlignment. The nonempty canonical shape of d_2 excludes the reset record, and positivity of V(d_1) again follows from DecimalValueBounds. Thus RightBoundaryTransport puts the divided boundary below V(d_2), contradicting (5). In both cases,
V(d_1)<c2^{R-e_1}. \tag{6}
The capacity and strict-order clauses of LeftHistoryTransport carry (6) backward through the exact loop-1 history, giving V(d_0)<c2^{R-e_0}. Those of RightHistoryTransport then carry it backward through the exact loop-0 history, giving
V(d)<c2^R. \tag{7}
The upper half of (4), multiplied by the positive 2^{e_2-52}, gives c2^R<B. Put q=10^{d.\mathit{point}-768}>0. GridAlignment writes V(d)=aq, while coefficient alignment writes c2^R=bq, for naturals a,b. Let \rho=c2^R-V(d). Equation (7) gives \rho>0, and the adjacent-cell identity B=V(d)+q together with c2^R<B gives \rho<q. From bq=aq+\rho, GridBoundaryRetained yields bq\leq aq, contradicting (7). This proves the coefficient-parametric separation fact.
For the midpoint take c=2n+1 and R=e_2-53; then
c2^{R-(e_2-52)}=(2n+1)/2=n+\tfrac12.
Capacity at d_0 is exactly (2), while capacity at d_2 follows from -17\leq d_2.\mathit{point} and at d_3 from d_3.\mathit{point}<19. The parametric fact therefore excludes strict containment of this midpoint and yields the first disjunction. For the odd integer take the same c and R=e_2-52. Its boundary is 2n+1, and its three capacity inequalities are one unit stronger, so the same argument yields the second disjunction.
It remains only the numerical range. The positive leading digit of d_3 and DecimalValueBounds give V(d_3)>0; the final endpoint equation and \eta_3\geq0 therefore give A/2^{e_2-52}\geq0. From (1), positivity of powers gives B\leq2^{e_1}. Equation (3) gives e_1-1\leq e_2, whence
A/2^{e_2-52}<B/2^{e_2-52} \leq2^{e_1-e_2+52}\leq2^{53}<2^{64}-\tfrac12.
Together with the facts supplied by the final-shift theorem, this proves every asserted conjunct.

Lean proof


  dsimp only
  intro A B d d0 d1 d2 exp0 exp1 expStart exp2 hpLo hpHi hinitial
    hloop0 hloop1 hsub hloop2 hstate2
  classical
  let Digits := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    (q.digits.val.take q.num_digits.val).map (fun z => z.val)
  let Value := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    ((Digits q).foldl (fun n digit => 10 * n + digit) 0 : Nat) *
      (10 : Real) ^ (q.decimal_point.val - (q.num_digits.val : Int))
  rcases hinitial with ⟨hcap, hdigit, hpositive, hB, hcanonicalA⟩
  rcases hpositive with ⟨z, zs, hzshape, hzLo, hzHi, hzlen⟩
  have hdne : d.num_digits.val != 0 := by
    have hpos : 0 < d.num_digits.val := by
      rw [← hzlen, hzshape]
      simp
    simpa [bne_iff_ne] using hpos.ne'
  have hcanonicalPack :
      d.num_digits.val <= 768 /\
      (forall q, q ∈ d.digits.val.take d.num_digits.val -> q.val < 10) /\
      (exists z zs, Digits d = z :: zs /\ 1 <= z /\ z < 10 /\
        (Digits d).length = d.num_digits.val) /\
      (exists eta : Real,
        A = Value d + eta /\ 0 <= eta /\
        eta < (10 : Real) ^ (d.decimal_point.val - (768 : Int)) /\
        (d.truncated = true <-> 0 < eta)) :=
    ⟨hcap, hdigit, ⟨z, zs, hzshape, hzLo, hzHi, hzlen⟩, hcanonicalA⟩
  have hspec0 := ParserSlowLoop0 A B d hdne hpLo hpHi hB
    (by simpa [Digits, Value] using hcanonicalPack)
  dsimp only at hspec0
  rcases hspec0 with ⟨q0, e0, steps0, hcall0, hsteps0, he0Lo,
    he0Hi, hALower, hp0Lo, hp0Hi, hselector0, hshape0⟩
  have htuple0 := Result.ok.inj (hcall0.symm.trans hloop0)
  have hq0 : q0 = d0 := by
    cases q0
    cases d0
    simp only [Prod.mk.injEq] at htuple0
    simp only [num.imp.dec2flt.decimal_seq.DecimalSeq.mk.injEq]
    tauto
  have he0 : e0 = exp0 := congrArg
    (fun x : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
      Std.I32 × Option num.imp.dec2flt.common.BiasedFp => x.2.2.2.2.1)
    htuple0
  subst q0
  subst e0
  rcases hshape0 with ⟨hcap0, hdigit0, hpositive0, hend0⟩
  have hshape0Pack :
      d0.num_digits.val <= 768 /\
      (forall q, q ∈ d0.digits.val.take d0.num_digits.val -> q.val < 10) /\
      (exists z zs, Digits d0 = z :: zs /\ 1 <= z /\ z < 10 /\
        (Digits d0).length = d0.num_digits.val) :=
    ⟨hcap0, hdigit0, by simpa [Digits] using hpositive0⟩
  have hend0Pack :
      exists eta u : Real,
        A / (2 : Real) ^ exp0.val = Value d0 + eta /\
        B / (2 : Real) ^ exp0.val = Value d0 + u /\
        0 <= eta /\ eta < u /\ (d0.truncated = true <-> 0 < eta) := by
    simpa [Value, Digits] using hend0
  have hspec1 := ParserSlowLoop1 A B d0 exp0 hp0Lo hp0Hi he0Lo
    ⟨hcap0, hdigit0, hpositive0, hend0⟩
  dsimp only at hspec1
  rcases hspec1 with ⟨q1, e1, steps1, hcall1, hsteps1, he1Hi,
    hp1, hnum1, hlead1, hlead1Hi, hshape1⟩
  have htuple1 := Result.ok.inj (hcall1.symm.trans hloop1)
  have hq1 : q1 = d1 := by
    cases q1
    cases d1
    simp only [Prod.mk.injEq] at htuple1
    simp only [num.imp.dec2flt.decimal_seq.DecimalSeq.mk.injEq]
    tauto
  have he1 : e1 = exp1 := congrArg
    (fun x : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
      Std.I32 × Option num.imp.dec2flt.common.BiasedFp => x.2.2.2.2.1)
    htuple1
  subst q1
  subst e1
  rcases hshape1 with ⟨hcap1, hdigit1, hpositive1, hend1⟩
  have hpositive1One : exists z zs,
      Digits d1 = z :: zs /\ 1 <= z /\ z < 10 /\
        (Digits d1).length = d1.num_digits.val := by
    rcases hpositive1 with ⟨z1, zs1, hzshape1, hz1Lo, hz1Hi, hzlen1⟩
    exact ⟨z1, zs1, hzshape1, by omega, hz1Hi, hzlen1⟩
  have hnorm := ParserSlowReachableNormalizationBounds A B d d0 d1 exp0 exp1
    hpLo hpHi hB (by simpa [Digits, Value] using hcanonicalPack) hALower
    hloop0 hloop1 hp1 hnum1 hlead1 (by simpa [Digits, Value] using hend1)
  rcases hstate2 with ⟨hcap2, hdigit2, hpositive2, hend2⟩
  have hcapacity := P856_T1_ReachableCapacity A B d d0 d1 d2 exp0 exp1
    expStart exp2 hpLo hpHi hB (by simpa [Digits, Value] using hcanonicalPack)
    hloop0 hloop1 hsub hloop2
  have hfinal := P856_T1_FinalLeftShiftExecution A B d1 d2 exp1 expStart exp2
    hnorm.2 hp1 hnum1 hlead1
    (by exact ⟨hcap1, hdigit1, hpositive1One, hend1⟩) hsub hloop2
  rcases hfinal with ⟨d3, hp2Lo, hp2Hi, hloop2Step, hleft53, hstate3⟩
  dsimp only at hstate3
  rcases hstate3 with ⟨hcap3, hdigit3, hpositive3, hend3, hp3Hi⟩
  rcases hpositive0 with ⟨z0, zs0, hzshape0, hz0Lo, hz0Hi, hzlen0⟩
  rcases hpositive1 with ⟨z1, zs1, hzshape1, hz1Lo, hz1Hi, hzlen1⟩
  rcases hpositive2 with ⟨z2, zs2, hzshape2, hz2Lo, hz2Hi, hzlen2⟩
  rcases hpositive3 with
    ⟨z3, zs3, hzshape3, hz3Lo, hz3Hi, hzlen3, hlast3⟩
  have valuePos (q : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (zq : Nat) (zsq : List Nat)
      (hshapeq : Digits q = zq :: zsq) (hzq : 1 <= zq)
      (hlenq : (Digits q).length = q.num_digits.val)
      (hdigitq : forall w, w ∈ q.digits.val.take q.num_digits.val ->
        w.val < 10) : 0 < Value q := by
    have hv := P804_T1_DecimalValueBounds (Digits q) zq zsq hshapeq hzq
      (by
        intro w hw
        simp only [Digits, List.mem_map] at hw
        rcases hw with ⟨w8, hw8, rfl⟩
        exact hdigitq w8 hw8) q.decimal_point.val
    dsimp only at hv
    rw [hlenq] at hv
    have hp : 0 < (zq : Real) * (10 : Real) ^
        (q.decimal_point.val - 1) :=
      mul_pos (by exact_mod_cast hzq) (zpow_pos (by norm_num) _)
    change 0 < Value q
    simpa [Value, Digits] using lt_of_lt_of_le hp hv.1
  have hvalue0Pos := valuePos d0 z0 zs0 (by simpa [Digits] using hzshape0)
    hz0Lo hzlen0 hdigit0
  have hvalue1Pos := valuePos d1 z1 zs1 (by simpa [Digits] using hzshape1)
    (by omega) hzlen1 hdigit1
  have hvalue2Pos := valuePos d2 z2 zs2 (by simpa [Digits] using hzshape2)
    hz2Lo hzlen2 hdigit2
  have separate (c : Nat) (R : Int)
      (hcap0R : 0 <= R - exp0.val + 768 - d0.decimal_point.val)
      (hcap2R : 0 <= R - (exp2.val + 1) + 768 - d2.decimal_point.val)
      (hcap3R : 0 <= R - (exp2.val - 52) + 768 - d3.decimal_point.val)
      (hlower : Value d3 <
        (c : Real) * (2 : Real) ^ (R - (exp2.val - 52)))
      (hupper : (c : Real) * (2 : Real) ^ (R - (exp2.val - 52)) <
        B / (2 : Real) ^ (exp2.val - 52)) : False := by
    have hstrict2 : Value d2 <
        (c : Real) * (2 : Real) ^ (R - (exp2.val + 1)) := by
      by_contra hnot
      have hbound2 :
          (c : Real) * (2 : Real) ^ (R - (exp2.val + 1)) <= Value d2 :=
        le_of_not_gt hnot
      obtain ⟨b3, hb3⟩ := P856_T1_CoefficientGridAlignment c
        (R - (exp2.val - 52)) d3.decimal_point.val (by omega) hcap3R
      have hscale :
          (c : Real) * (2 : Real) ^ (R - (exp2.val - 52)) =
            (2 : Real) ^ (53 : Nat) *
              ((c : Real) * (2 : Real) ^ (R - (exp2.val + 1))) := by
        rw [show R - (exp2.val - 52) =
          (R - (exp2.val + 1)) + 53 by omega]
        rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
        norm_num only [zpow_natCast]
        ring
      have hbound :
          (b3 : Real) * (10 : Real) ^ (d3.decimal_point.val - 768) <=
            (2 : Real) ^ (53 : Nat) * Value d2 := by
        rw [← hb3, hscale]
        exact mul_le_mul_of_nonneg_left hbound2 (by positivity)
      have ht := P798_T1_LeftBoundaryTransport d2 d3 53#usize b3
        (by norm_num) hvalue2Pos hdigit2 hleft53 hcap3 hbound
      have ht' :
          (b3 : Real) * (10 : Real) ^ (d3.decimal_point.val - 768) <=
            Value d3 := by simpa [Value, Digits] using ht
      rw [hb3] at hlower
      exact (not_lt_of_ge ht') hlower
    have hstrict1 : Value d1 <
        (c : Real) * (2 : Real) ^ (R - exp1.val) := by
      rcases hloop2Step with hid | hshift
      · rcases hid with ⟨hd, he⟩
        rw [hd] at hstrict2
        simpa [he] using hstrict2
      · rcases hshift with ⟨shift, hshift58, hright, he⟩
        by_contra hnot
        have hbound1 :
            (c : Real) * (2 : Real) ^ (R - exp1.val) <= Value d1 :=
          le_of_not_gt hnot
        obtain ⟨b2, hb2⟩ := P856_T1_CoefficientGridAlignment c
          (R - (exp2.val + 1)) d2.decimal_point.val (by omega) hcap2R
        have hscale :
            (c : Real) * (2 : Real) ^ (R - (exp2.val + 1)) =
              ((c : Real) * (2 : Real) ^ (R - exp1.val)) /
                (2 : Real) ^ shift.val := by
          rw [he]
          rw [show R - (exp1.val + (shift.val : Int)) =
            (R - exp1.val) - (shift.val : Int) by omega]
          rw [zpow_sub₀ (by norm_num : (2 : Real) ≠ 0)]
          norm_num only [zpow_natCast]
          ring
        have hbound :
            (b2 : Real) * (10 : Real) ^ (d2.decimal_point.val - 768) <=
              Value d1 / (2 : Real) ^ shift.val := by
          rw [← hb2, hscale]
          exact div_le_div_of_nonneg_right hbound1 (by positivity)
        have hnonreset : ¬ (d2.num_digits.val = 0 /\
            d2.decimal_point.val = 0 /\ d2.truncated = false) := by
          intro hr
          have hlenPos := hzlen2
          rw [hzshape2] at hlenPos
          simp only [List.length_cons] at hlenPos
          omega
        have ht := P798_T1_RightBoundaryTransport d1 d2 shift b2
          (by omega) hvalue1Pos hdigit1 hright hnonreset hcap2 hbound
        have ht' :
            (b2 : Real) * (10 : Real) ^ (d2.decimal_point.val - 768) <=
              Value d2 := by simpa [Value, Digits] using ht
        rw [hb2] at hstrict2
        exact (not_lt_of_ge ht') hstrict2
    have hleftHistory := P856_T1_LeftHistoryTransport A B d0 d1 exp0 exp1
      c R hp0Lo hp0Hi (by simpa [Digits] using hshape0Pack)
      (by simpa [Value, Digits] using hend0Pack) hloop1 hcap0R
    have hstrict0 := hleftHistory.2 (by simpa [Value, Digits] using hstrict1)
    have hrightHistory := P856_T1_RightHistoryTransport A B d d0 0#i32 exp0
      c R hpLo hpHi
      (by exact ⟨hcap, hdigit, ⟨z, zs, hzshape, hzLo, hzHi, hzlen⟩⟩)
      (by
        rcases hcanonicalA with ⟨eta, hAeq, heta0, hetaCut, hsticky⟩
        refine ⟨eta, (10 : Real) ^ (d.decimal_point.val - 768), ?_, ?_,
          heta0, hetaCut, hsticky⟩
        · simpa [Value, Digits] using hAeq
        · simpa [Value, Digits] using hB)
      hloop0 hcap0R
    have hstrictInit := hrightHistory.2
      (by simpa [Value, Digits] using hstrict0)
    have hpowFinalPos : 0 < (2 : Real) ^ (exp2.val - 52) :=
      zpow_pos (by norm_num) _
    have hupperMul := (lt_div_iff₀ hpowFinalPos).mp hupper
    have hboundaryScale :
        ((c : Real) * (2 : Real) ^ (R - (exp2.val - 52))) *
            (2 : Real) ^ (exp2.val - 52) =
          (c : Real) * (2 : Real) ^ R := by
      rw [mul_assoc, ← zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      congr 2
      omega
    have hupperInit : (c : Real) * (2 : Real) ^ R < B := by
      rw [← hboundaryScale]
      exact hupperMul
    obtain ⟨a, ha⟩ := P798_T1_GridAlignment d hcap
    obtain ⟨b, hb⟩ := P856_T1_CoefficientGridAlignment c R
      d.decimal_point.val (by omega) (by simpa using hrightHistory.1)
    let q : Real := (10 : Real) ^ (d.decimal_point.val - 768)
    let rho : Real := (c : Real) * (2 : Real) ^ R - Value d
    have hq : 0 < q := zpow_pos (by norm_num) _
    have hrho : rho < q := by
      dsimp only [rho, q]
      have hB' : B = Value d + (10 : Real) ^ (d.decimal_point.val - 768) := by
        simpa [Value, Digits] using hB
      linarith
    have hboundary : (b : Real) * q <= (a : Real) * q + rho := by
      have ha' : Value d = (a : Real) * q := by
        simpa [Value, Digits, q, List.map_take] using ha
      have hb' : (c : Real) * (2 : Real) ^ R = (b : Real) * q := by
        simpa [q] using hb
      rw [← hb', ← ha']
      simp [rho]
    have hretained := P798_T1_GridBoundaryRetained a b q rho hq hrho hboundary
    have ha' : Value d = (a : Real) * q := by
      simpa [Value, Digits, q, List.map_take] using ha
    have hb' : (c : Real) * (2 : Real) ^ R = (b : Real) * q := by
      simpa [q] using hb
    rw [← hb', ← ha'] at hretained
    exact (not_lt_of_ge hretained) (by simpa [Value, Digits] using hstrictInit)
  rcases hend3 with ⟨eta3, u3, hA3, hB3, heta3, heta3u3, hsticky3⟩
  have hA_nonneg : 0 <= A / (2 : Real) ^ (exp2.val - 52) := by
    have hvalue3Pos := valuePos d3 z3 zs3 (by simpa [Digits] using hzshape3)
      hz3Lo hzlen3 hdigit3
    rw [hA3]
    linarith
  have hAB : A < B := by
    rcases hcanonicalA with ⟨eta, hAeq, hetaLo, hetaHi, hsticky⟩
    have hcutPos : 0 < (10 : Real) ^ (d.decimal_point.val - 768) :=
      zpow_pos (by norm_num) _
    rw [hAeq, hB]
    linarith
  have hpow1Pos : 0 < (2 : Real) ^ exp1.val := zpow_pos (by norm_num) _
  have hBpow : B <= (2 : Real) ^ exp1.val := by
    have hm := (div_le_iff₀ hpow1Pos).mp hnorm.1
    simpa using hm
  have heRel : exp1.val - 1 <= exp2.val := by
    rcases hloop2Step with hid | hshift
    · omega
    · rcases hshift with ⟨shift, hshift58, hright, he⟩
      omega
  have hA_upper53 : A / (2 : Real) ^ (exp2.val - 52) <
      (2 : Real) ^ (53 : Nat) := by
    have hpowFinalPos : 0 < (2 : Real) ^ (exp2.val - 52) :=
      zpow_pos (by norm_num) _
    calc
      A / (2 : Real) ^ (exp2.val - 52) <
          B / (2 : Real) ^ (exp2.val - 52) :=
        (div_lt_div_iff_of_pos_right hpowFinalPos).2 hAB
      _ <= (2 : Real) ^ exp1.val / (2 : Real) ^ (exp2.val - 52) :=
        div_le_div_of_nonneg_right hBpow hpowFinalPos.le
      _ = (2 : Real) ^ (exp1.val - exp2.val + 52) := by
        rw [show exp1.val - exp2.val + 52 =
          exp1.val - (exp2.val - 52) by omega]
        exact (zpow_sub₀ (by norm_num : (2 : Real) ≠ 0)
          exp1.val (exp2.val - 52)).symm
      _ <= (2 : Real) ^ (53 : Nat) := by
        rw [← zpow_natCast]
        exact zpow_le_zpow_right₀ (by norm_num) (by omega)
  have hA_u64 : A / (2 : Real) ^ (exp2.val - 52) <
      (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) := by
    have hconst : (2 : Real) ^ (53 : Nat) <
        (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) := by norm_num
    exact hA_upper53.trans hconst
  have hhalf : forall n : Nat,
      (n : Real) + (1 / 2 : Real) <= Value d3 \/
        B / (2 : Real) ^ (exp2.val - 52) <=
          (n : Real) + (1 / 2 : Real) := by
    intro n
    let c : Nat := 2 * n + 1
    let R : Int := exp2.val - 53
    have hboundary : (c : Real) * (2 : Real) ^
        (R - (exp2.val - 52)) = (n : Real) + (1 / 2 : Real) := by
      simp only [c, R]
      rw [show exp2.val - 53 - (exp2.val - 52) = -1 by omega]
      norm_num [zpow_neg]
      push_cast
      ring
    by_cases hlower : (n : Real) + (1 / 2 : Real) <= Value d3
    · exact Or.inl hlower
    · right
      by_contra hupperNot
      have hlower' : Value d3 < (c : Real) * (2 : Real) ^
          (R - (exp2.val - 52)) := by
        rw [hboundary]
        exact lt_of_not_ge hlower
      have hupper' : (c : Real) * (2 : Real) ^
          (R - (exp2.val - 52)) <
          B / (2 : Real) ^ (exp2.val - 52) := by
        rw [hboundary]
        exact lt_of_not_ge hupperNot
      exact (separate c R (by dsimp only [R]; omega)
        (by dsimp only [R]; omega) (by dsimp only [R]; omega)
        hlower' hupper').elim
  have hodd : forall n : Nat,
      ((2 * n + 1 : Nat) : Real) <= Value d3 \/
        B / (2 : Real) ^ (exp2.val - 52) <=
          ((2 * n + 1 : Nat) : Real) := by
    intro n
    let c : Nat := 2 * n + 1
    let R : Int := exp2.val - 52
    have hboundary : (c : Real) * (2 : Real) ^
        (R - (exp2.val - 52)) = ((2 * n + 1 : Nat) : Real) := by
      simp [c, R]
    by_cases hlower : ((2 * n + 1 : Nat) : Real) <= Value d3
    · exact Or.inl hlower
    · right
      by_contra hupperNot
      have hlower' : Value d3 < (c : Real) * (2 : Real) ^
          (R - (exp2.val - 52)) := by
        rw [hboundary]
        exact lt_of_not_ge hlower
      have hupper' : (c : Real) * (2 : Real) ^
          (R - (exp2.val - 52)) <
          B / (2 : Real) ^ (exp2.val - 52) := by
        rw [hboundary]
        exact lt_of_not_ge hupperNot
      exact (separate c R (by dsimp only [R]; omega)
        (by dsimp only [R]; omega) (by dsimp only [R]; omega)
        hlower' hupper').elim
  refine ⟨d3, hleft53, ?_⟩
  dsimp only
  exact ⟨hcap3, hdigit3,
    ⟨z3, zs3, hzshape3, hz3Lo, hz3Hi, hzlen3, hlast3⟩,
    ⟨eta3, u3, hA3, hB3, heta3, heta3u3, hsticky3⟩,
    hp3Hi, hA_nonneg, hA_u64, hhalf, hodd⟩

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P856_T1_ReachableCapacity
import Tablet.P856_T1_FinalLeftShiftExecution
import Tablet.P856_T1_LeftHistoryTransport
import Tablet.P856_T1_RightHistoryTransport
import Tablet.P856_T1_CoefficientGridAlignment
import Tablet.P798_T1_GridAlignment
import Tablet.P798_T1_GridBoundaryRetained
import Tablet.P798_T1_LeftBoundaryTransport
import Tablet.P798_T1_RightBoundaryTransport
import Tablet.P804_T1_DecimalValueBounds
import Tablet.ParserSlowReachableNormalizationBounds
import Mathlib.Tactic.FieldSimp

open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false

namespace dec2flt_model

-- [TABLET NODE: P856_T1_SeparationPackage]
theorem P856_T1_SeparationPackage :
    forall (A B : Real)
      (d d0 d1 d2 : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (exp0 exp1 expStart exp2 : Std.I32),
      -324 <= d.decimal_point.val -> d.decimal_point.val < 310 ->
      let digits :=
        (d.digits.val.take d.num_digits.val).map (fun z => z.val)
      let integer : Nat := digits.foldl (fun n digit => 10 * n + digit) 0
      let value : Real := integer * (10 : Real) ^
        (d.decimal_point.val - (d.num_digits.val : Int))
      let cutoff : Real := (10 : Real) ^
        (d.decimal_point.val - (768 : Int))
      d.num_digits.val <= 768 /\
      (forall z, z ∈ d.digits.val.take d.num_digits.val -> z.val < 10) /\
      (exists z zs, digits = z :: zs /\ 1 <= z /\ z < 10 /\
        digits.length = d.num_digits.val) /\
      B = value + cutoff /\
      (exists eta : Real,
        A = value + eta /\ 0 <= eta /\ eta < cutoff /\
        (d.truncated = true <-> 0 < eta)) ->
      num.imp.dec2flt.slow.parse_long_mantissa_loop0
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 0#i32 }
        d.num_digits d.decimal_point d.truncated d.digits 0#i32 none =
          ok (d0.num_digits, d0.decimal_point, d0.truncated, d0.digits,
            exp0, none) ->
      num.imp.dec2flt.slow.parse_long_mantissa_loop1
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64
        { m := 0#u64, p_biased := 2047#i32 }
        d0.num_digits d0.decimal_point d0.truncated d0.digits exp0 none =
          ok (d1.num_digits, d1.decimal_point, d1.truncated, d1.digits,
            exp1, none) ->
      exp1 - 1#i32 = ok expStart ->
      num.imp.dec2flt.slow.parse_long_mantissa_loop2
        F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 expStart =
          ok (d2, exp2) ->
      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)) ->
      exists d3 : num.imp.dec2flt.decimal_seq.DecimalSeq,
        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 /\
        0 <= A / (2 : Real) ^ (exp2.val - 52) /\
        A / (2 : Real) ^ (exp2.val - 52) <
          (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) /\
        (forall n : Nat,
          (n : Real) + (1 / 2 : Real) <= value3 \/
            B / (2 : Real) ^ (exp2.val - 52) <=
              (n : Real) + (1 / 2 : Real)) /\
        (forall n : Nat,
          ((2 * n + 1 : Nat) : Real) <= value3 \/
            B / (2 : Real) ^ (exp2.val - 52) <=
              ((2 * n + 1 : Nat) : Real)) := by
-- BODY
  dsimp only
  intro A B d d0 d1 d2 exp0 exp1 expStart exp2 hpLo hpHi hinitial
    hloop0 hloop1 hsub hloop2 hstate2
  classical
  let Digits := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    (q.digits.val.take q.num_digits.val).map (fun z => z.val)
  let Value := fun q : num.imp.dec2flt.decimal_seq.DecimalSeq =>
    ((Digits q).foldl (fun n digit => 10 * n + digit) 0 : Nat) *
      (10 : Real) ^ (q.decimal_point.val - (q.num_digits.val : Int))
  rcases hinitial with ⟨hcap, hdigit, hpositive, hB, hcanonicalA⟩
  rcases hpositive with ⟨z, zs, hzshape, hzLo, hzHi, hzlen⟩
  have hdne : d.num_digits.val != 0 := by
    have hpos : 0 < d.num_digits.val := by
      rw [← hzlen, hzshape]
      simp
    simpa [bne_iff_ne] using hpos.ne'
  have hcanonicalPack :
      d.num_digits.val <= 768 /\
      (forall q, q ∈ d.digits.val.take d.num_digits.val -> q.val < 10) /\
      (exists z zs, Digits d = z :: zs /\ 1 <= z /\ z < 10 /\
        (Digits d).length = d.num_digits.val) /\
      (exists eta : Real,
        A = Value d + eta /\ 0 <= eta /\
        eta < (10 : Real) ^ (d.decimal_point.val - (768 : Int)) /\
        (d.truncated = true <-> 0 < eta)) :=
    ⟨hcap, hdigit, ⟨z, zs, hzshape, hzLo, hzHi, hzlen⟩, hcanonicalA⟩
  have hspec0 := ParserSlowLoop0 A B d hdne hpLo hpHi hB
    (by simpa [Digits, Value] using hcanonicalPack)
  dsimp only at hspec0
  rcases hspec0 with ⟨q0, e0, steps0, hcall0, hsteps0, he0Lo,
    he0Hi, hALower, hp0Lo, hp0Hi, hselector0, hshape0⟩
  have htuple0 := Result.ok.inj (hcall0.symm.trans hloop0)
  have hq0 : q0 = d0 := by
    cases q0
    cases d0
    simp only [Prod.mk.injEq] at htuple0
    simp only [num.imp.dec2flt.decimal_seq.DecimalSeq.mk.injEq]
    tauto
  have he0 : e0 = exp0 := congrArg
    (fun x : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
      Std.I32 × Option num.imp.dec2flt.common.BiasedFp => x.2.2.2.2.1)
    htuple0
  subst q0
  subst e0
  rcases hshape0 with ⟨hcap0, hdigit0, hpositive0, hend0⟩
  have hshape0Pack :
      d0.num_digits.val <= 768 /\
      (forall q, q ∈ d0.digits.val.take d0.num_digits.val -> q.val < 10) /\
      (exists z zs, Digits d0 = z :: zs /\ 1 <= z /\ z < 10 /\
        (Digits d0).length = d0.num_digits.val) :=
    ⟨hcap0, hdigit0, by simpa [Digits] using hpositive0⟩
  have hend0Pack :
      exists eta u : Real,
        A / (2 : Real) ^ exp0.val = Value d0 + eta /\
        B / (2 : Real) ^ exp0.val = Value d0 + u /\
        0 <= eta /\ eta < u /\ (d0.truncated = true <-> 0 < eta) := by
    simpa [Value, Digits] using hend0
  have hspec1 := ParserSlowLoop1 A B d0 exp0 hp0Lo hp0Hi he0Lo
    ⟨hcap0, hdigit0, hpositive0, hend0⟩
  dsimp only at hspec1
  rcases hspec1 with ⟨q1, e1, steps1, hcall1, hsteps1, he1Hi,
    hp1, hnum1, hlead1, hlead1Hi, hshape1⟩
  have htuple1 := Result.ok.inj (hcall1.symm.trans hloop1)
  have hq1 : q1 = d1 := by
    cases q1
    cases d1
    simp only [Prod.mk.injEq] at htuple1
    simp only [num.imp.dec2flt.decimal_seq.DecimalSeq.mk.injEq]
    tauto
  have he1 : e1 = exp1 := congrArg
    (fun x : Std.Usize × Std.I32 × Bool × Array Std.U8 768#usize ×
      Std.I32 × Option num.imp.dec2flt.common.BiasedFp => x.2.2.2.2.1)
    htuple1
  subst q1
  subst e1
  rcases hshape1 with ⟨hcap1, hdigit1, hpositive1, hend1⟩
  have hpositive1One : exists z zs,
      Digits d1 = z :: zs /\ 1 <= z /\ z < 10 /\
        (Digits d1).length = d1.num_digits.val := by
    rcases hpositive1 with ⟨z1, zs1, hzshape1, hz1Lo, hz1Hi, hzlen1⟩
    exact ⟨z1, zs1, hzshape1, by omega, hz1Hi, hzlen1⟩
  have hnorm := ParserSlowReachableNormalizationBounds A B d d0 d1 exp0 exp1
    hpLo hpHi hB (by simpa [Digits, Value] using hcanonicalPack) hALower
    hloop0 hloop1 hp1 hnum1 hlead1 (by simpa [Digits, Value] using hend1)
  rcases hstate2 with ⟨hcap2, hdigit2, hpositive2, hend2⟩
  have hcapacity := P856_T1_ReachableCapacity A B d d0 d1 d2 exp0 exp1
    expStart exp2 hpLo hpHi hB (by simpa [Digits, Value] using hcanonicalPack)
    hloop0 hloop1 hsub hloop2
  have hfinal := P856_T1_FinalLeftShiftExecution A B d1 d2 exp1 expStart exp2
    hnorm.2 hp1 hnum1 hlead1
    (by exact ⟨hcap1, hdigit1, hpositive1One, hend1⟩) hsub hloop2
  rcases hfinal with ⟨d3, hp2Lo, hp2Hi, hloop2Step, hleft53, hstate3⟩
  dsimp only at hstate3
  rcases hstate3 with ⟨hcap3, hdigit3, hpositive3, hend3, hp3Hi⟩
  rcases hpositive0 with ⟨z0, zs0, hzshape0, hz0Lo, hz0Hi, hzlen0⟩
  rcases hpositive1 with ⟨z1, zs1, hzshape1, hz1Lo, hz1Hi, hzlen1⟩
  rcases hpositive2 with ⟨z2, zs2, hzshape2, hz2Lo, hz2Hi, hzlen2⟩
  rcases hpositive3 with
    ⟨z3, zs3, hzshape3, hz3Lo, hz3Hi, hzlen3, hlast3⟩
  have valuePos (q : num.imp.dec2flt.decimal_seq.DecimalSeq)
      (zq : Nat) (zsq : List Nat)
      (hshapeq : Digits q = zq :: zsq) (hzq : 1 <= zq)
      (hlenq : (Digits q).length = q.num_digits.val)
      (hdigitq : forall w, w ∈ q.digits.val.take q.num_digits.val ->
        w.val < 10) : 0 < Value q := by
    have hv := P804_T1_DecimalValueBounds (Digits q) zq zsq hshapeq hzq
      (by
        intro w hw
        simp only [Digits, List.mem_map] at hw
        rcases hw with ⟨w8, hw8, rfl⟩
        exact hdigitq w8 hw8) q.decimal_point.val
    dsimp only at hv
    rw [hlenq] at hv
    have hp : 0 < (zq : Real) * (10 : Real) ^
        (q.decimal_point.val - 1) :=
      mul_pos (by exact_mod_cast hzq) (zpow_pos (by norm_num) _)
    change 0 < Value q
    simpa [Value, Digits] using lt_of_lt_of_le hp hv.1
  have hvalue0Pos := valuePos d0 z0 zs0 (by simpa [Digits] using hzshape0)
    hz0Lo hzlen0 hdigit0
  have hvalue1Pos := valuePos d1 z1 zs1 (by simpa [Digits] using hzshape1)
    (by omega) hzlen1 hdigit1
  have hvalue2Pos := valuePos d2 z2 zs2 (by simpa [Digits] using hzshape2)
    hz2Lo hzlen2 hdigit2
  have separate (c : Nat) (R : Int)
      (hcap0R : 0 <= R - exp0.val + 768 - d0.decimal_point.val)
      (hcap2R : 0 <= R - (exp2.val + 1) + 768 - d2.decimal_point.val)
      (hcap3R : 0 <= R - (exp2.val - 52) + 768 - d3.decimal_point.val)
      (hlower : Value d3 <
        (c : Real) * (2 : Real) ^ (R - (exp2.val - 52)))
      (hupper : (c : Real) * (2 : Real) ^ (R - (exp2.val - 52)) <
        B / (2 : Real) ^ (exp2.val - 52)) : False := by
    have hstrict2 : Value d2 <
        (c : Real) * (2 : Real) ^ (R - (exp2.val + 1)) := by
      by_contra hnot
      have hbound2 :
          (c : Real) * (2 : Real) ^ (R - (exp2.val + 1)) <= Value d2 :=
        le_of_not_gt hnot
      obtain ⟨b3, hb3⟩ := P856_T1_CoefficientGridAlignment c
        (R - (exp2.val - 52)) d3.decimal_point.val (by omega) hcap3R
      have hscale :
          (c : Real) * (2 : Real) ^ (R - (exp2.val - 52)) =
            (2 : Real) ^ (53 : Nat) *
              ((c : Real) * (2 : Real) ^ (R - (exp2.val + 1))) := by
        rw [show R - (exp2.val - 52) =
          (R - (exp2.val + 1)) + 53 by omega]
        rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
        norm_num only [zpow_natCast]
        ring
      have hbound :
          (b3 : Real) * (10 : Real) ^ (d3.decimal_point.val - 768) <=
            (2 : Real) ^ (53 : Nat) * Value d2 := by
        rw [← hb3, hscale]
        exact mul_le_mul_of_nonneg_left hbound2 (by positivity)
      have ht := P798_T1_LeftBoundaryTransport d2 d3 53#usize b3
        (by norm_num) hvalue2Pos hdigit2 hleft53 hcap3 hbound
      have ht' :
          (b3 : Real) * (10 : Real) ^ (d3.decimal_point.val - 768) <=
            Value d3 := by simpa [Value, Digits] using ht
      rw [hb3] at hlower
      exact (not_lt_of_ge ht') hlower
    have hstrict1 : Value d1 <
        (c : Real) * (2 : Real) ^ (R - exp1.val) := by
      rcases hloop2Step with hid | hshift
      · rcases hid with ⟨hd, he⟩
        rw [hd] at hstrict2
        simpa [he] using hstrict2
      · rcases hshift with ⟨shift, hshift58, hright, he⟩
        by_contra hnot
        have hbound1 :
            (c : Real) * (2 : Real) ^ (R - exp1.val) <= Value d1 :=
          le_of_not_gt hnot
        obtain ⟨b2, hb2⟩ := P856_T1_CoefficientGridAlignment c
          (R - (exp2.val + 1)) d2.decimal_point.val (by omega) hcap2R
        have hscale :
            (c : Real) * (2 : Real) ^ (R - (exp2.val + 1)) =
              ((c : Real) * (2 : Real) ^ (R - exp1.val)) /
                (2 : Real) ^ shift.val := by
          rw [he]
          rw [show R - (exp1.val + (shift.val : Int)) =
            (R - exp1.val) - (shift.val : Int) by omega]
          rw [zpow_sub₀ (by norm_num : (2 : Real) ≠ 0)]
          norm_num only [zpow_natCast]
          ring
        have hbound :
            (b2 : Real) * (10 : Real) ^ (d2.decimal_point.val - 768) <=
              Value d1 / (2 : Real) ^ shift.val := by
          rw [← hb2, hscale]
          exact div_le_div_of_nonneg_right hbound1 (by positivity)
        have hnonreset : ¬ (d2.num_digits.val = 0 /\
            d2.decimal_point.val = 0 /\ d2.truncated = false) := by
          intro hr
          have hlenPos := hzlen2
          rw [hzshape2] at hlenPos
          simp only [List.length_cons] at hlenPos
          omega
        have ht := P798_T1_RightBoundaryTransport d1 d2 shift b2
          (by omega) hvalue1Pos hdigit1 hright hnonreset hcap2 hbound
        have ht' :
            (b2 : Real) * (10 : Real) ^ (d2.decimal_point.val - 768) <=
              Value d2 := by simpa [Value, Digits] using ht
        rw [hb2] at hstrict2
        exact (not_lt_of_ge ht') hstrict2
    have hleftHistory := P856_T1_LeftHistoryTransport A B d0 d1 exp0 exp1
      c R hp0Lo hp0Hi (by simpa [Digits] using hshape0Pack)
      (by simpa [Value, Digits] using hend0Pack) hloop1 hcap0R
    have hstrict0 := hleftHistory.2 (by simpa [Value, Digits] using hstrict1)
    have hrightHistory := P856_T1_RightHistoryTransport A B d d0 0#i32 exp0
      c R hpLo hpHi
      (by exact ⟨hcap, hdigit, ⟨z, zs, hzshape, hzLo, hzHi, hzlen⟩⟩)
      (by
        rcases hcanonicalA with ⟨eta, hAeq, heta0, hetaCut, hsticky⟩
        refine ⟨eta, (10 : Real) ^ (d.decimal_point.val - 768), ?_, ?_,
          heta0, hetaCut, hsticky⟩
        · simpa [Value, Digits] using hAeq
        · simpa [Value, Digits] using hB)
      hloop0 hcap0R
    have hstrictInit := hrightHistory.2
      (by simpa [Value, Digits] using hstrict0)
    have hpowFinalPos : 0 < (2 : Real) ^ (exp2.val - 52) :=
      zpow_pos (by norm_num) _
    have hupperMul := (lt_div_iff₀ hpowFinalPos).mp hupper
    have hboundaryScale :
        ((c : Real) * (2 : Real) ^ (R - (exp2.val - 52))) *
            (2 : Real) ^ (exp2.val - 52) =
          (c : Real) * (2 : Real) ^ R := by
      rw [mul_assoc, ← zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      congr 2
      omega
    have hupperInit : (c : Real) * (2 : Real) ^ R < B := by
      rw [← hboundaryScale]
      exact hupperMul
    obtain ⟨a, ha⟩ := P798_T1_GridAlignment d hcap
    obtain ⟨b, hb⟩ := P856_T1_CoefficientGridAlignment c R
      d.decimal_point.val (by omega) (by simpa using hrightHistory.1)
    let q : Real := (10 : Real) ^ (d.decimal_point.val - 768)
    let rho : Real := (c : Real) * (2 : Real) ^ R - Value d
    have hq : 0 < q := zpow_pos (by norm_num) _
    have hrho : rho < q := by
      dsimp only [rho, q]
      have hB' : B = Value d + (10 : Real) ^ (d.decimal_point.val - 768) := by
        simpa [Value, Digits] using hB
      linarith
    have hboundary : (b : Real) * q <= (a : Real) * q + rho := by
      have ha' : Value d = (a : Real) * q := by
        simpa [Value, Digits, q, List.map_take] using ha
      have hb' : (c : Real) * (2 : Real) ^ R = (b : Real) * q := by
        simpa [q] using hb
      rw [← hb', ← ha']
      simp [rho]
    have hretained := P798_T1_GridBoundaryRetained a b q rho hq hrho hboundary
    have ha' : Value d = (a : Real) * q := by
      simpa [Value, Digits, q, List.map_take] using ha
    have hb' : (c : Real) * (2 : Real) ^ R = (b : Real) * q := by
      simpa [q] using hb
    rw [← hb', ← ha'] at hretained
    exact (not_lt_of_ge hretained) (by simpa [Value, Digits] using hstrictInit)
  rcases hend3 with ⟨eta3, u3, hA3, hB3, heta3, heta3u3, hsticky3⟩
  have hA_nonneg : 0 <= A / (2 : Real) ^ (exp2.val - 52) := by
    have hvalue3Pos := valuePos d3 z3 zs3 (by simpa [Digits] using hzshape3)
      hz3Lo hzlen3 hdigit3
    rw [hA3]
    linarith
  have hAB : A < B := by
    rcases hcanonicalA with ⟨eta, hAeq, hetaLo, hetaHi, hsticky⟩
    have hcutPos : 0 < (10 : Real) ^ (d.decimal_point.val - 768) :=
      zpow_pos (by norm_num) _
    rw [hAeq, hB]
    linarith
  have hpow1Pos : 0 < (2 : Real) ^ exp1.val := zpow_pos (by norm_num) _
  have hBpow : B <= (2 : Real) ^ exp1.val := by
    have hm := (div_le_iff₀ hpow1Pos).mp hnorm.1
    simpa using hm
  have heRel : exp1.val - 1 <= exp2.val := by
    rcases hloop2Step with hid | hshift
    · omega
    · rcases hshift with ⟨shift, hshift58, hright, he⟩
      omega
  have hA_upper53 : A / (2 : Real) ^ (exp2.val - 52) <
      (2 : Real) ^ (53 : Nat) := by
    have hpowFinalPos : 0 < (2 : Real) ^ (exp2.val - 52) :=
      zpow_pos (by norm_num) _
    calc
      A / (2 : Real) ^ (exp2.val - 52) <
          B / (2 : Real) ^ (exp2.val - 52) :=
        (div_lt_div_iff_of_pos_right hpowFinalPos).2 hAB
      _ <= (2 : Real) ^ exp1.val / (2 : Real) ^ (exp2.val - 52) :=
        div_le_div_of_nonneg_right hBpow hpowFinalPos.le
      _ = (2 : Real) ^ (exp1.val - exp2.val + 52) := by
        rw [show exp1.val - exp2.val + 52 =
          exp1.val - (exp2.val - 52) by omega]
        exact (zpow_sub₀ (by norm_num : (2 : Real) ≠ 0)
          exp1.val (exp2.val - 52)).symm
      _ <= (2 : Real) ^ (53 : Nat) := by
        rw [← zpow_natCast]
        exact zpow_le_zpow_right₀ (by norm_num) (by omega)
  have hA_u64 : A / (2 : Real) ^ (exp2.val - 52) <
      (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) := by
    have hconst : (2 : Real) ^ (53 : Nat) <
        (2 : Real) ^ (64 : Nat) - (1 / 2 : Real) := by norm_num
    exact hA_upper53.trans hconst
  have hhalf : forall n : Nat,
      (n : Real) + (1 / 2 : Real) <= Value d3 \/
        B / (2 : Real) ^ (exp2.val - 52) <=
          (n : Real) + (1 / 2 : Real) := by
    intro n
    let c : Nat := 2 * n + 1
    let R : Int := exp2.val - 53
    have hboundary : (c : Real) * (2 : Real) ^
        (R - (exp2.val - 52)) = (n : Real) + (1 / 2 : Real) := by
      simp only [c, R]
      rw [show exp2.val - 53 - (exp2.val - 52) = -1 by omega]
      norm_num [zpow_neg]
      push_cast
      ring
    by_cases hlower : (n : Real) + (1 / 2 : Real) <= Value d3
    · exact Or.inl hlower
    · right
      by_contra hupperNot
      have hlower' : Value d3 < (c : Real) * (2 : Real) ^
          (R - (exp2.val - 52)) := by
        rw [hboundary]
        exact lt_of_not_ge hlower
      have hupper' : (c : Real) * (2 : Real) ^
          (R - (exp2.val - 52)) <
          B / (2 : Real) ^ (exp2.val - 52) := by
        rw [hboundary]
        exact lt_of_not_ge hupperNot
      exact (separate c R (by dsimp only [R]; omega)
        (by dsimp only [R]; omega) (by dsimp only [R]; omega)
        hlower' hupper').elim
  have hodd : forall n : Nat,
      ((2 * n + 1 : Nat) : Real) <= Value d3 \/
        B / (2 : Real) ^ (exp2.val - 52) <=
          ((2 * n + 1 : Nat) : Real) := by
    intro n
    let c : Nat := 2 * n + 1
    let R : Int := exp2.val - 52
    have hboundary : (c : Real) * (2 : Real) ^
        (R - (exp2.val - 52)) = ((2 * n + 1 : Nat) : Real) := by
      simp [c, R]
    by_cases hlower : ((2 * n + 1 : Nat) : Real) <= Value d3
    · exact Or.inl hlower
    · right
      by_contra hupperNot
      have hlower' : Value d3 < (c : Real) * (2 : Real) ^
          (R - (exp2.val - 52)) := by
        rw [hboundary]
        exact lt_of_not_ge hlower
      have hupper' : (c : Real) * (2 : Real) ^
          (R - (exp2.val - 52)) <
          B / (2 : Real) ^ (exp2.val - 52) := by
        rw [hboundary]
        exact lt_of_not_ge hupperNot
      exact (separate c R (by dsimp only [R]; omega)
        (by dsimp only [R]; omega) (by dsimp only [R]; omega)
        hlower' hupper').elim
  refine ⟨d3, hleft53, ?_⟩
  dsimp only
  exact ⟨hcap3, hdigit3,
    ⟨z3, zs3, hzshape3, hz3Lo, hz3Hi, hzlen3, hlast3⟩,
    ⟨eta3, u3, hA3, hB3, heta3, heta3u3, hsticky3⟩,
    hp3Hi, hA_nonneg, hA_u64, hhalf, hodd⟩

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 164 entries
Technical checking records
Local closure summary
{
  "node": "P856_T1_SeparationPackage",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "e961cedf9f8c9d1d9e5531681b8cb7b314b62b9d1d77a1562c85eee171c45d57",
  "active_statement_hash": "d0ef76ebd7e643c2134db44f2a5f6116e9ca374dfa11e227dd6ef93777890bd5",
  "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": {
    "P798_T1_GridAlignment": "f2e86c75264ff7d3",
    "P798_T1_GridBoundaryRetained": "76774c228a980cf9",
    "P798_T1_LeftBoundaryTransport": "8382fe6b25ea536f",
    "P798_T1_RightBoundaryTransport": "d22f654164869df6",
    "P804_T1_DecimalValueBounds": "4b5c924b5d52bc9d",
    "P856_T1_CoefficientGridAlignment": "811bf9ec1aa2ffd7",
    "P856_T1_FinalLeftShiftExecution": "df4cdab1afdae62f",
    "P856_T1_LeftHistoryTransport": "2973008451f726d3",
    "P856_T1_ReachableCapacity": "4b2ef1b3db393e0d",
    "P856_T1_RightHistoryTransport": "ac5b841fb2508def",
    "ParserSlowLoop0": "33531ee210efb042",
    "ParserSlowLoop1": "f2b7099d6b2b429c",
    "ParserSlowReachableNormalizationBounds": "3d4872e8ccb1d877",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "3c283430b9003d37"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "ParserSlowLoop0": "7ebc2b39d69850c4",
    "num_imp_dec2flt_common_BiasedFp": "63baac539d218a81",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "fd298e37d5ae4f86",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift": "1aaf1bb11c0b6a49",
    "num_imp_dec2flt_slow_parse_long_mantissa": "f4b1825aa46c08b9"
  }
}
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:1bb0be1b23062260d76b94e1224868b2a95354814356c6258df9df9aa3c6822c",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}