P529_T1_SeparationPackage

Lean checked

Statement

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

Lemma · Both separations from the original decimal cell

Let d have positive exact-length decimal shape, count at most 768 and -324\le p<310, with original endpoints X=V(d)+\eta, Y=V(d)+10^{p-768}, 0\le\eta<10^{p-768} and sticky iff \eta>0. Assume the exact specialized loop-zero and loop-one equations to (d_0,e_0,\mathsf{none}) and (d_1,e_1,\mathsf{none}), the actual checked decrement to e_s, the actual loop-two equation to (d_2,e_2), and the actual 53-bit left shift to d_3. Then for every natural n,
n+\tfrac12\le V(d_3)\ \lor\ Y/2^{e_2-52}\le n+\tfrac12, \qquad 2n+1\le V(d_3)\ \lor\ Y/2^{e_2-52}\le2n+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.P529_T1_ReachableCapacity
import Tablet.P495_T1_SlowLoop0Execution
import Tablet.P529_T1_Loop1Execution
import Tablet.P529_T1_NormalizationBounds
import Tablet.P529_T1_Loop2Execution
import Tablet.P529_T1_FinalShiftCertificate
import Tablet.P856_T1_CoefficientGridAlignment
import Tablet.P472_T1_DecimalValueBounds
import Tablet.P529_T1_LeftHistoryBoundary
import Tablet.P529_T1_RightHistoryBoundary
import Tablet.P529_T1_RightBoundaryTransport
import Tablet.P798_T1_LeftBoundaryTransport
import Tablet.P798_T1_GridAlignment
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_SeparationPackage]
theorem P529_T1_SeparationPackage (X Y : Real)
    (d d0 d1 d2 d3 : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (exp0 exp1 exps exp2 : Std.I32)
    (hpointLo : -324 <= d.decimal_point.val)
    (hpointHi : d.decimal_point.val < 310)
    (hinput : d.num_digits.val <= 768 /\
      (forall b, b ∈ d.digits.val.take d.num_digits.val -> b.val < 10) /\
      (exists h tail,
        (d.digits.val.take d.num_digits.val).map (fun b => b.val) = h :: tail /\
        1 <= h /\ h < 10 /\ (h :: tail).length = d.num_digits.val))
    (hloop0 : 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))
    (hloop1 : 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))
    (hdecrement : exp1 - 1#i32 = ok exps)
    (hloop2 : num.imp.dec2flt.slow.parse_long_mantissa_loop2
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 exps = ok (d2, exp2))
    (hshift : num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d2 53#usize = ok d3) :
    let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      ((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
        (fun n z => 10 * n + z) 0 : Nat) : Real) *
        (10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
    Y = V d + (10 : Real) ^ (d.decimal_point.val - 768) ->
    (exists eta : Real, X = V d + eta /\ 0 <= eta /\
      eta < (10 : Real) ^ (d.decimal_point.val - 768) /\
      (d.truncated = true <-> 0 < eta)) ->
    (forall n : Nat,
      (n : Real) + 1 / 2 <= V d3 \/
        Y / (2 : Real) ^ (exp2.val - 52) <= (n : Real) + 1 / 2) /\
    (forall n : Nat,
      (2 * n + 1 : Nat) <= V d3 \/
        Y / (2 : Real) ^ (exp2.val - 52) <= (2 * n + 1 : Nat)) := 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 SlowLoop0Execution and Loop1Execution to the initial package, identifying their results with the supplied calls by injectivity. Their endpoints and shape give the hypotheses of NormalizationBounds, so X<Y, Y/2^{e_1}\le1 and e_1\ge-1079. Apply Loop2Execution, identifying its checked decrement and normal loop with the supplied ones. It gives e_2=\max(e_1-1,-1022), -18\le p_2\le0, positive decimal shape, the endpoints at e_2+1, and the exhaustive identity or actual nonreset right-shift alternative with e_2+1=e_1+k, k\le58. Since e_2+1\ge e_1 and Y>0, Y/2^{e_2+1}\le Y/2^{e_1}\le1. FinalShiftCertificate identifies the given d_3 with its normal shift result and gives p_3\le16, positive trimmed shape, output count, and the endpoints at e_2-52. ReachableCapacity gives
e_2-e_0+715-p_0\ge0. \tag{1}
We prove a coefficient-parametric fact at the two exponents needed. Let c be natural and let R=e_2-53 or R=e_2-52. The capacity at d_0 is R-e_0+768-p_0, which is (1) or one unit larger. At d_2 it is R-(e_2+1)+768-p_2=714-p_2 or 715-p_2, nonnegative. At d_3 it is R-(e_2-52)+768-p_3=767-p_3 or 768-p_3, nonnegative. Each point is at most 768. Consequently CoefficientGridAlignment is available at each of these actual states.
Suppose V(d_3)<c2^{R-(e_2-52)}<Y/2^{e_2-52}. If c2^{R-(e_2+1)}\le V(d_2), multiplication by 2^{53} places the aligned d_3 boundary below 2^{53}V(d_2). The exact shift, positive input value, decimal cells and output count meet LeftBoundaryTransport, giving c2^{R-(e_2-52)}\le V(d_3), a contradiction. Hence V(d_2)<c2^{R-(e_2+1)}. In the loop-two identity case this is V(d_1)<c2^{R-e_1}. In its right-shift case, if c2^{R-e_1}\le V(d_1), division by 2^k places the aligned d_2 boundary below V(d_1)/2^k. Positive value follows from DecimalValueBounds, and the positive output count excludes reset. RightBoundaryTransport again contradicts the strict order. Thus in both cases V(d_1)<c2^{R-e_1}.
The general clause of LeftHistoryBoundary, using the proved capacity at d_0, now gives V(d_0)<c2^{R-e_0}. RightHistoryBoundary, with the same terminal capacity, gives V(d)<c2^R and initial capacity R+768-p\ge0. The upper strict inequality in our supposed crossing gives c2^R<Y. At the initial grid, GridAlignment writes V(d)=aq and coefficient alignment writes c2^R=bq, where q=10^{p-768}>0 and a,b are natural. Since Y=(a+1)q, the strict inequalities are a<b<a+1 after cancelling q. No natural b satisfies them. This contradiction proves the parametric noncrossing fact.
For a half-integer choose c=2n+1,R=e_2-53; its final boundary is (2n+1)2^{-1}=n+1/2. For an odd integer choose c=2n+1,R=e_2-52; its final boundary is 2n+1. The absence of strict crossing is exactly the respective displayed disjunction in the linear order on reals. The argument separately verifies all capacities, including the one-unit-stronger odd-integer case.

Lean proof


  intro V hY hX
  have h0pkg := P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi hinput hY hX
  rcases h0pkg with ⟨d0', e0', steps, h0', hsteps, hstepsLo, hstepsHi,
    hXlow, hp0lo, hp0hi, hn0, hd0, hshape0, htrim0, herr0⟩
  have h0eq := h0'.symm.trans hloop0
  injection h0eq with h0tuple
  simp only [Prod.mk.injEq] at h0tuple
  rcases h0tuple with ⟨h0num, h0point, h0trunc, h0digits, h0exp, _⟩
  have h0record : d0' = d0 := by
    cases d0' with
    | mk n p t ds =>
      cases d0 with
      | mk n' p' t' ds' => simp_all
  cases h0record
  cases h0exp
  have h1pkg := P529_T1_Loop1Execution X Y d0 exp0 hp0lo hp0hi hstepsLo
    (by exact ⟨hn0, hd0, hshape0⟩) herr0
  rcases h1pkg with ⟨d1', e1', bound, h1', hbound, hboundlo, hboundhi,
    hp1, hn1, hhead1lo, hhead1hi, hn1cap, hd1, hshape1, herr1⟩
  have h1eq := h1'.symm.trans hloop1
  injection h1eq with h1tuple
  simp only [Prod.mk.injEq] at h1tuple
  rcases h1tuple with ⟨h1num, h1point, h1trunc, h1digits, h1exp, _⟩
  have h1record : d1' = d1 := by
    cases d1' with
    | mk n p t ds =>
      cases d1 with
      | mk n' p' t' ds' => simp_all
  cases h1record
  cases h1exp
  have hnorm := P529_T1_NormalizationBounds X Y d d0 d1 exp0 exp1
    hpointLo hpointHi hinput hloop0 hloop1 hY hX
  rcases hnorm with ⟨hXlow', hXY, hYbound1, hexp1lo, hexp1hi⟩
  have h2pkg := P529_T1_Loop2Execution X Y d1 exp1 hexp1lo hp1
    (by exact ⟨hn1cap, hd1, hshape1⟩) herr1
  rcases h2pkg with ⟨exps', exp2', d2', shift, hdec', hexpsval,
    hexpslo, h2', hexp2val, hshiftval, hshiftle, h2case,
    hp2lo, hp2hi, hn2, hd2, hshape2, hnonreset, herr2⟩
  have hdeceq := hdec'.symm.trans hdecrement
  injection hdeceq with hexps
  cases hexps
  have h2eq := h2'.symm.trans hloop2
  injection h2eq with h2tuple
  simp only [Prod.mk.injEq] at h2tuple
  rcases h2tuple with ⟨h2record, h2exp⟩
  have h2record' : d2' = d2 := by
    cases d2' with
    | mk n p t ds =>
      cases d2 with
      | mk n' p' t' ds' => simp_all
  cases h2record'
  cases h2exp
  have hexp2 : exp2.val = max (exp1.val - 1) (-1022) := by
    rw [← hexpsval]
    exact hexp2val
  have hcap0 := P529_T1_ReachableCapacity X Y d d0 d1 exp0 exp1 exp2
    hpointLo hpointHi hinput hloop0 hloop1 hexp2 hY hX
  have he2lower : exp1.val ≤ exp2.val + 1 := by
    rw [hexp2]
    omega
  have hYle : Y ≤ (2 : Real) ^ exp1.val :=
    (div_le_one (by positivity)).mp hYbound1
  have hpowmon : (2 : Real) ^ exp1.val ≤ (2 : Real) ^ (exp2.val + 1) :=
    zpow_le_zpow_right₀ (by norm_num) he2lower
  have hYupper : Y / (2 : Real) ^ (exp2.val + 1) ≤ 1 :=
    (div_le_one (by positivity)).2 (le_trans hYle hpowmon)
  have h3pkg := P529_T1_FinalShiftCertificate X Y d2 exp2 hp2lo hp2hi
    (by exact ⟨hn2, hd2, hshape2⟩) hYupper herr2
  rcases h3pkg with ⟨d3', h3', hp3lo, hp3hi, hn3, hd3, hshape3,
    htrim3, hXpos3, hXupper3, herr3⟩
  have h3eq := h3'.symm.trans hshift
  injection h3eq with h3
  have h3record : d3' = d3 := by
    cases d3' with
    | mk n p t ds =>
      cases d3 with
      | mk n' p' t' ds' => simp_all
  cases h3record
  have hleftHist := P529_T1_LeftHistoryBoundary X Y d0 d1 exp0 exp1
    hp0lo hp0hi hstepsLo ⟨hn0, hd0, hshape0⟩ hloop1 herr0
  rcases hleftHist with ⟨hbasecap, hprogress, hleftBoundary⟩
  have hrightHist := P529_T1_RightHistoryBoundary X Y d d0 exp0
    hpointLo hpointHi hinput hloop0 hY hX
  rcases hrightHist with ⟨hrightZero, hrightBoundary⟩
  rcases hshape1 with ⟨z1, zs1, hxs1, hz1, hz1lt, hlen1⟩
  have hdmap1 : ∀ q, q ∈ (d1.digits.val.take d1.num_digits.val).map
      (fun b => b.val) -> q < 10 := by
    intro q hq
    rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩
    exact hd1 b hb
  have hvbounds1 := P472_T1_DecimalValueBounds
    ((d1.digits.val.take d1.num_digits.val).map (fun b => b.val))
    z1 zs1 hxs1 (by omega) hdmap1 d1.decimal_point.val
  have htake1 : (d1.digits.val.take d1.num_digits.val).map
      (fun b => b.val) =
      (d1.digits.val.map (fun b => b.val)).take d1.num_digits.val := by
    simp
  have hv1 : 0 < V d1 := by
    have hz1pos : (0 : Real) < z1 := by exact_mod_cast (show 0 < z1 by omega)
    have hpow : (0 : Real) < (10 : Real) ^ (d1.decimal_point.val - 1) :=
      zpow_pos (by norm_num) _
    have hlow : (z1 : Real) * (10 : Real) ^ (d1.decimal_point.val - 1) ≤ V d1 := by
      simpa [V, ← htake1, hxs1, hlen1] using hvbounds1.1
    exact lt_of_lt_of_le (mul_pos hz1pos hpow) hlow
  rcases hshape2 with ⟨z2, zs2, hxs2, hz2, hz2lt, hlen2⟩
  have hdmap2 : ∀ q, q ∈ (d2.digits.val.take d2.num_digits.val).map
      (fun b => b.val) -> q < 10 := by
    intro q hq
    rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩
    exact hd2 b hb
  have hvbounds2 := P472_T1_DecimalValueBounds
    ((d2.digits.val.take d2.num_digits.val).map (fun b => b.val))
    z2 zs2 hxs2 (by omega) hdmap2 d2.decimal_point.val
  have htake2 : (d2.digits.val.take d2.num_digits.val).map
      (fun b => b.val) =
      (d2.digits.val.map (fun b => b.val)).take d2.num_digits.val := by
    simp
  have hv2 : 0 < V d2 := by
    have hz2pos : (0 : Real) < z2 := by exact_mod_cast (show 0 < z2 by omega)
    have hpow : (0 : Real) < (10 : Real) ^ (d2.decimal_point.val - 1) :=
      zpow_pos (by norm_num) _
    have hlow : (z2 : Real) * (10 : Real) ^ (d2.decimal_point.val - 1) ≤ V d2 := by
      simpa [V, ← htake2, hxs2, hlen2] using hvbounds2.1
    exact lt_of_lt_of_le (mul_pos hz2pos hpow) hlow
  have hcapacity0 (R : Int)
      (hR : R = exp2.val - 53 ∨ R = exp2.val - 52) :
      0 ≤ R - exp0.val + 768 - d0.decimal_point.val := by
    have h := hcap0
    rcases hR with hR | hR <;> rw [hR] <;> omega
  have hcapacity2 (R : Int)
      (hR : R = exp2.val - 53 ∨ R = exp2.val - 52) :
      0 ≤ R - (exp2.val + 1) + 768 - d2.decimal_point.val := by
    rcases hR with hR | hR <;> rw [hR] <;> omega
  have hcapacity3 (R : Int)
      (hR : R = exp2.val - 53 ∨ R = exp2.val - 52) :
      0 ≤ R - (exp2.val - 52) + 768 - d3.decimal_point.val := by
    rcases hR with hR | hR <;> rw [hR] <;> omega
  have hnoncross (c : Nat) (R : Int)
      (hR : R = exp2.val - 53 ∨ R = exp2.val - 52) :
      V d3 < (c : Real) * (2 : Real) ^ (R - (exp2.val - 52)) ->
      (c : Real) * (2 : Real) ^ R < Y -> False := by
    intro hcross3 hcrossY
    have hcap2 := hcapacity2 R hR
    have hcap3 := hcapacity3 R hR
    have halign2 := P856_T1_CoefficientGridAlignment c
      (R - (exp2.val + 1)) d2.decimal_point.val (by omega) hcap2
    rcases halign2 with ⟨b2, hb2⟩
    have halign3 := P856_T1_CoefficientGridAlignment c
      (R - (exp2.val - 52)) d3.decimal_point.val (by omega) hcap3
    rcases halign3 with ⟨b3, hb3⟩
    have hpow53 : (2 : Real) ^ (53 : Nat) *
        (2 : Real) ^ (R - (exp2.val + 1)) =
        (2 : Real) ^ (R - (exp2.val - 52)) := by
      have hnat : (2 : Real) ^ (53 : Nat) = (2 : Real) ^ (53 : Int) := by
        norm_num
      rw [hnat, ← zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      congr 1
      omega
    have hcoefPower : (c : Real) *
        (2 : Real) ^ (R - (exp2.val - 52)) =
        (2 : Real) ^ (53 : Nat) *
          ((c : Real) * (2 : Real) ^ (R - (exp2.val + 1))) := by
      have hnatpow : (2 : Real) ^ (53 : Nat) =
          (2 : Real) ^ (53 : Int) := by norm_num
      rw [hnatpow]
      rw [show R - (exp2.val - 52) = (53 : Int) +
          (R - (exp2.val + 1)) by omega]
      rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      ring
    have hshifttransport := P798_T1_LeftBoundaryTransport d2 d3
      53#usize b3 (by norm_num) hv2 hd2 hshift hn3
    have hcross2 : V d2 < (c : Real) *
        (2 : Real) ^ (R - (exp2.val + 1)) := by
      by_contra hnot
      have hle : (c : Real) * (2 : Real) ^ (R - (exp2.val + 1)) ≤ V d2 :=
        le_of_not_gt hnot
      have hmul := mul_le_mul_of_nonneg_left hle
        (le_of_lt (show (0 : Real) < (2 : Real) ^ (53 : Nat) by positivity))
      have htransportIn : (b3 : Real) *
          (10 : Real) ^ (d3.decimal_point.val - 768) ≤
          (2 : Real) ^ (53 : Nat) * V d2 := by
        calc
          (b3 : Real) * (10 : Real) ^ (d3.decimal_point.val - 768) =
              (c : Real) * (2 : Real) ^ (R - (exp2.val - 52)) := hb3.symm
          _ = (2 : Real) ^ (53 : Nat) *
              ((c : Real) * (2 : Real) ^ (R - (exp2.val + 1))) := by
                exact hcoefPower
          _ ≤ (2 : Real) ^ (53 : Nat) * V d2 := hmul
      have htransportOut := hshifttransport htransportIn
      rw [← hb3] at htransportOut
      exact (not_lt_of_ge htransportOut) hcross3
    have hloop2Exponent : exp2.val + 1 = exp1.val + shift.val := by
      rcases h2case with hident | hright
      · rcases hident with ⟨hcut, hzero, hd2eq, he2eq⟩
        have he2 : exp2.val = exps.val :=
          congrArg (fun e : Std.I32 => e.val) he2eq
        omega
      · rcases hright with ⟨hcut, hpositive, hcall, hexp2reset⟩
        omega
    have hcross1 : V d1 < (c : Real) *
        (2 : Real) ^ (R - exp1.val) := by
      by_contra hnot
      have hle : (c : Real) * (2 : Real) ^ (R - exp1.val) ≤ V d1 :=
        le_of_not_gt hnot
      rcases h2case with hident | hright
      · rcases hident with ⟨hcut, hzero, hd2eq, he2eq⟩
        have he2 : exp2.val = exps.val :=
          congrArg (fun e : Std.I32 => e.val) he2eq
        have hexp : exp2.val + 1 = exp1.val := by omega
        rw [hd2eq] at hcross2
        rw [show R - (exp2.val + 1) = R - exp1.val by omega] at hcross2
        exact (not_lt_of_ge hle) hcross2
      · rcases hright with ⟨hcut, hpositive, hcall, hexp2reset⟩
        have hnonreset2 : ¬ (d2.num_digits.val = 0 ∧
            d2.decimal_point.val = 0 ∧ d2.truncated = false) := by
          intro hreset
          have hn2pos : 0 < d2.num_digits.val := by
            rw [← hlen2]
            simp
          omega
        have hrighttransport := P529_T1_RightBoundaryTransport
          d1 d2 shift (by omega) hd1 hcall hnonreset2 hn2 hv1
        have hshiftpowpos : (0 : Real) < (2 : Real) ^ shift.val := by
          positivity
        have hnatpow : (2 : Real) ^ shift.val =
            (2 : Real) ^ (shift.val : Int) := by
          norm_num [zpow_natCast]
        have hpowRel : (2 : Real) ^ (R - exp1.val) =
            (2 : Real) ^ (R - (exp2.val + 1)) * (2 : Real) ^ shift.val := by
          rw [show R - exp1.val = (R - (exp2.val + 1)) +
              (shift.val : Int) by omega]
          rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
          rw [← hnatpow]
        have hmulBound : (c : Real) *
            (2 : Real) ^ (R - (exp2.val + 1)) * (2 : Real) ^ shift.val ≤ V d1 := by
          calc
            (c : Real) * (2 : Real) ^ (R - (exp2.val + 1)) *
                (2 : Real) ^ shift.val =
                (c : Real) * ((2 : Real) ^ (R - (exp2.val + 1)) *
                  (2 : Real) ^ shift.val) := by ring
            _ = (c : Real) * (2 : Real) ^ (R - exp1.val) := by
              rw [← hpowRel]
            _ ≤ V d1 := hle
        have htransportIn : (b2 : Real) *
            (10 : Real) ^ (d2.decimal_point.val - 768) ≤
            V d1 / (2 : Real) ^ shift.val := by
          rw [← hb2]
          exact (le_div_iff₀ hshiftpowpos).2 (by simpa [mul_assoc] using hmulBound)
        have htransportOut := hrighttransport b2 htransportIn
        rw [← hb2] at htransportOut
        exact (not_lt_of_ge htransportOut) hcross2
    have hleftStep := hleftBoundary c R (hcapacity0 R hR)
    have hcross0 := hleftStep.2 hcross1
    have hrightStep := hrightBoundary c R (hcapacity0 R hR)
    have hcrossd := hrightStep.2 hcross0
    have hgrid := P798_T1_GridAlignment d hinput.1
    rcases hgrid with ⟨a, ha⟩
    have halign0 := P856_T1_CoefficientGridAlignment c R
      d.decimal_point.val (by omega) hrightStep.1
    rcases halign0 with ⟨b, hb⟩
    let q : Real := (10 : Real) ^ (d.decimal_point.val - 768)
    have htakeD : (d.digits.val.take d.num_digits.val).map
        (fun z => z.val) =
        (d.digits.val.map (fun z => z.val)).take d.num_digits.val := by
      simp
    have hq : 0 < q := by
      dsimp [q]
      exact zpow_pos (by norm_num) _
    have ha' : V d = (a : Real) * q := by
      simpa only [V, q, htakeD] using ha
    have hb' : (c : Real) * (2 : Real) ^ R = (b : Real) * q := by
      simpa [q] using hb
    have hcrossd' : (a : Real) * q < (c : Real) * (2 : Real) ^ R := by
      rw [← ha']
      exact hcrossd
    have habreal : (a : Real) * q < (b : Real) * q := by
      rw [← hb']
      exact hcrossd'
    have hab : a < b := by
      exact_mod_cast (lt_of_mul_lt_mul_right habreal (le_of_lt hq))
    have hbaReal : (b : Real) * q < ((a : Nat) + 1 : Real) * q := by
      calc
        (b : Real) * q = (c : Real) * (2 : Real) ^ R := hb'.symm
        _ < Y := hcrossY
        _ = V d + q := by simpa [q] using hY
        _ = (a : Real) * q + q := by rw [ha']
        _ = ((a : Nat) + 1 : Real) * q := by push_cast; ring
    have hba : b < a + 1 := by
      exact_mod_cast (lt_of_mul_lt_mul_right hbaReal (le_of_lt hq))
    omega
  have hpowFactor (r s : Int) :
      (2 : Real) ^ r = (2 : Real) ^ (r - s) * (2 : Real) ^ s := by
    calc
      (2 : Real) ^ r = (2 : Real) ^ ((r - s) + s) := by congr 1 <;> omega
      _ = (2 : Real) ^ (r - s) * (2 : Real) ^ s :=
        zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _
  constructor
  · intro n
    by_contra hbad
    push_neg at hbad
    rcases hbad with ⟨hleft, hright⟩
    let c : Nat := 2 * n + 1
    let R : Int := exp2.val - 53
    let s : Int := exp2.val - 52
    have hboundary : (n : Real) + 1 / 2 = (c : Real) *
        (2 : Real) ^ (R - s) := by
      have hexp : R - s = -1 := by dsimp [R, s]; omega
      rw [hexp]
      have hpow : (2 : Real) ^ (-1 : Int) = (1 / 2 : Real) := by norm_num
      rw [hpow]
      dsimp [c]
      push_cast
      ring
    have hupperMul : ((n : Real) + 1 / 2) * (2 : Real) ^ s < Y :=
      (lt_div_iff₀ (zpow_pos (by norm_num) s)).mp hright
    have hcrossY : (c : Real) * (2 : Real) ^ R < Y := by
      calc
        (c : Real) * (2 : Real) ^ R =
            ((c : Real) * (2 : Real) ^ (R - s)) * (2 : Real) ^ s := by
              conv_lhs => rw [hpowFactor R s]
              ring
        _ = ((n : Real) + 1 / 2) * (2 : Real) ^ s := by rw [← hboundary]
        _ < Y := hupperMul
    have hR : R = exp2.val - 53 ∨ R = exp2.val - 52 := Or.inl rfl
    have hcross3 : V d3 < (c : Real) * (2 : Real) ^ (R - s) := by
      rw [← hboundary]
      exact hleft
    exact hnoncross c R hR hcross3 hcrossY
  · intro n
    by_contra hbad
    push_neg at hbad
    rcases hbad with ⟨hleft, hright⟩
    let c : Nat := 2 * n + 1
    let R : Int := exp2.val - 52
    let s : Int := exp2.val - 52
    have hboundary : (2 * n + 1 : Nat) = (c : Real) *
        (2 : Real) ^ (R - s) := by
      have hexp : R - s = 0 := by dsimp [R, s]; omega
      rw [hexp]
      simp [c]
    have hupperMul : ((2 * n + 1 : Nat) : Real) *
        (2 : Real) ^ s < Y := (lt_div_iff₀ (zpow_pos (by norm_num) s)).mp hright
    have hcrossY : (c : Real) * (2 : Real) ^ R < Y := by
      calc
        (c : Real) * (2 : Real) ^ R =
            ((c : Real) * (2 : Real) ^ (R - s)) * (2 : Real) ^ s := by
              conv_lhs => rw [hpowFactor R s]
              ring
        _ = ((2 * n + 1 : Nat) : Real) * (2 : Real) ^ s := by
              rw [← hboundary]
        _ < Y := hupperMul
    have hR : R = exp2.val - 53 ∨ R = exp2.val - 52 := Or.inr rfl
    have hcross3 : V d3 < (c : Real) * (2 : Real) ^ (R - s) := by
      rw [← hboundary]
      exact hleft
    exact hnoncross c R hR hcross3 hcrossY

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.P529_T1_ReachableCapacity
import Tablet.P495_T1_SlowLoop0Execution
import Tablet.P529_T1_Loop1Execution
import Tablet.P529_T1_NormalizationBounds
import Tablet.P529_T1_Loop2Execution
import Tablet.P529_T1_FinalShiftCertificate
import Tablet.P856_T1_CoefficientGridAlignment
import Tablet.P472_T1_DecimalValueBounds
import Tablet.P529_T1_LeftHistoryBoundary
import Tablet.P529_T1_RightHistoryBoundary
import Tablet.P529_T1_RightBoundaryTransport
import Tablet.P798_T1_LeftBoundaryTransport
import Tablet.P798_T1_GridAlignment
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_SeparationPackage]
theorem P529_T1_SeparationPackage (X Y : Real)
    (d d0 d1 d2 d3 : num.imp.dec2flt.decimal_seq.DecimalSeq)
    (exp0 exp1 exps exp2 : Std.I32)
    (hpointLo : -324 <= d.decimal_point.val)
    (hpointHi : d.decimal_point.val < 310)
    (hinput : d.num_digits.val <= 768 /\
      (forall b, b ∈ d.digits.val.take d.num_digits.val -> b.val < 10) /\
      (exists h tail,
        (d.digits.val.take d.num_digits.val).map (fun b => b.val) = h :: tail /\
        1 <= h /\ h < 10 /\ (h :: tail).length = d.num_digits.val))
    (hloop0 : 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))
    (hloop1 : 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))
    (hdecrement : exp1 - 1#i32 = ok exps)
    (hloop2 : num.imp.dec2flt.slow.parse_long_mantissa_loop2
      F64.Insts.Dec2flt_modelNumImpTraitsFloatU64 d1 exps = ok (d2, exp2))
    (hshift : num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d2 53#usize = ok d3) :
    let V := fun a : num.imp.dec2flt.decimal_seq.DecimalSeq =>
      ((((a.digits.val.take a.num_digits.val).map (fun b => b.val)).foldl
        (fun n z => 10 * n + z) 0 : Nat) : Real) *
        (10 : Real) ^ (a.decimal_point.val - (a.num_digits.val : Int))
    Y = V d + (10 : Real) ^ (d.decimal_point.val - 768) ->
    (exists eta : Real, X = V d + eta /\ 0 <= eta /\
      eta < (10 : Real) ^ (d.decimal_point.val - 768) /\
      (d.truncated = true <-> 0 < eta)) ->
    (forall n : Nat,
      (n : Real) + 1 / 2 <= V d3 \/
        Y / (2 : Real) ^ (exp2.val - 52) <= (n : Real) + 1 / 2) /\
    (forall n : Nat,
      (2 * n + 1 : Nat) <= V d3 \/
        Y / (2 : Real) ^ (exp2.val - 52) <= (2 * n + 1 : Nat)) := by
-- BODY
  intro V hY hX
  have h0pkg := P495_T1_SlowLoop0Execution X Y d hpointLo hpointHi hinput hY hX
  rcases h0pkg with ⟨d0', e0', steps, h0', hsteps, hstepsLo, hstepsHi,
    hXlow, hp0lo, hp0hi, hn0, hd0, hshape0, htrim0, herr0⟩
  have h0eq := h0'.symm.trans hloop0
  injection h0eq with h0tuple
  simp only [Prod.mk.injEq] at h0tuple
  rcases h0tuple with ⟨h0num, h0point, h0trunc, h0digits, h0exp, _⟩
  have h0record : d0' = d0 := by
    cases d0' with
    | mk n p t ds =>
      cases d0 with
      | mk n' p' t' ds' => simp_all
  cases h0record
  cases h0exp
  have h1pkg := P529_T1_Loop1Execution X Y d0 exp0 hp0lo hp0hi hstepsLo
    (by exact ⟨hn0, hd0, hshape0⟩) herr0
  rcases h1pkg with ⟨d1', e1', bound, h1', hbound, hboundlo, hboundhi,
    hp1, hn1, hhead1lo, hhead1hi, hn1cap, hd1, hshape1, herr1⟩
  have h1eq := h1'.symm.trans hloop1
  injection h1eq with h1tuple
  simp only [Prod.mk.injEq] at h1tuple
  rcases h1tuple with ⟨h1num, h1point, h1trunc, h1digits, h1exp, _⟩
  have h1record : d1' = d1 := by
    cases d1' with
    | mk n p t ds =>
      cases d1 with
      | mk n' p' t' ds' => simp_all
  cases h1record
  cases h1exp
  have hnorm := P529_T1_NormalizationBounds X Y d d0 d1 exp0 exp1
    hpointLo hpointHi hinput hloop0 hloop1 hY hX
  rcases hnorm with ⟨hXlow', hXY, hYbound1, hexp1lo, hexp1hi⟩
  have h2pkg := P529_T1_Loop2Execution X Y d1 exp1 hexp1lo hp1
    (by exact ⟨hn1cap, hd1, hshape1⟩) herr1
  rcases h2pkg with ⟨exps', exp2', d2', shift, hdec', hexpsval,
    hexpslo, h2', hexp2val, hshiftval, hshiftle, h2case,
    hp2lo, hp2hi, hn2, hd2, hshape2, hnonreset, herr2⟩
  have hdeceq := hdec'.symm.trans hdecrement
  injection hdeceq with hexps
  cases hexps
  have h2eq := h2'.symm.trans hloop2
  injection h2eq with h2tuple
  simp only [Prod.mk.injEq] at h2tuple
  rcases h2tuple with ⟨h2record, h2exp⟩
  have h2record' : d2' = d2 := by
    cases d2' with
    | mk n p t ds =>
      cases d2 with
      | mk n' p' t' ds' => simp_all
  cases h2record'
  cases h2exp
  have hexp2 : exp2.val = max (exp1.val - 1) (-1022) := by
    rw [← hexpsval]
    exact hexp2val
  have hcap0 := P529_T1_ReachableCapacity X Y d d0 d1 exp0 exp1 exp2
    hpointLo hpointHi hinput hloop0 hloop1 hexp2 hY hX
  have he2lower : exp1.val ≤ exp2.val + 1 := by
    rw [hexp2]
    omega
  have hYle : Y ≤ (2 : Real) ^ exp1.val :=
    (div_le_one (by positivity)).mp hYbound1
  have hpowmon : (2 : Real) ^ exp1.val ≤ (2 : Real) ^ (exp2.val + 1) :=
    zpow_le_zpow_right₀ (by norm_num) he2lower
  have hYupper : Y / (2 : Real) ^ (exp2.val + 1) ≤ 1 :=
    (div_le_one (by positivity)).2 (le_trans hYle hpowmon)
  have h3pkg := P529_T1_FinalShiftCertificate X Y d2 exp2 hp2lo hp2hi
    (by exact ⟨hn2, hd2, hshape2⟩) hYupper herr2
  rcases h3pkg with ⟨d3', h3', hp3lo, hp3hi, hn3, hd3, hshape3,
    htrim3, hXpos3, hXupper3, herr3⟩
  have h3eq := h3'.symm.trans hshift
  injection h3eq with h3
  have h3record : d3' = d3 := by
    cases d3' with
    | mk n p t ds =>
      cases d3 with
      | mk n' p' t' ds' => simp_all
  cases h3record
  have hleftHist := P529_T1_LeftHistoryBoundary X Y d0 d1 exp0 exp1
    hp0lo hp0hi hstepsLo ⟨hn0, hd0, hshape0⟩ hloop1 herr0
  rcases hleftHist with ⟨hbasecap, hprogress, hleftBoundary⟩
  have hrightHist := P529_T1_RightHistoryBoundary X Y d d0 exp0
    hpointLo hpointHi hinput hloop0 hY hX
  rcases hrightHist with ⟨hrightZero, hrightBoundary⟩
  rcases hshape1 with ⟨z1, zs1, hxs1, hz1, hz1lt, hlen1⟩
  have hdmap1 : ∀ q, q ∈ (d1.digits.val.take d1.num_digits.val).map
      (fun b => b.val) -> q < 10 := by
    intro q hq
    rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩
    exact hd1 b hb
  have hvbounds1 := P472_T1_DecimalValueBounds
    ((d1.digits.val.take d1.num_digits.val).map (fun b => b.val))
    z1 zs1 hxs1 (by omega) hdmap1 d1.decimal_point.val
  have htake1 : (d1.digits.val.take d1.num_digits.val).map
      (fun b => b.val) =
      (d1.digits.val.map (fun b => b.val)).take d1.num_digits.val := by
    simp
  have hv1 : 0 < V d1 := by
    have hz1pos : (0 : Real) < z1 := by exact_mod_cast (show 0 < z1 by omega)
    have hpow : (0 : Real) < (10 : Real) ^ (d1.decimal_point.val - 1) :=
      zpow_pos (by norm_num) _
    have hlow : (z1 : Real) * (10 : Real) ^ (d1.decimal_point.val - 1) ≤ V d1 := by
      simpa [V, ← htake1, hxs1, hlen1] using hvbounds1.1
    exact lt_of_lt_of_le (mul_pos hz1pos hpow) hlow
  rcases hshape2 with ⟨z2, zs2, hxs2, hz2, hz2lt, hlen2⟩
  have hdmap2 : ∀ q, q ∈ (d2.digits.val.take d2.num_digits.val).map
      (fun b => b.val) -> q < 10 := by
    intro q hq
    rcases List.mem_map.mp hq with ⟨b, hb, rfl⟩
    exact hd2 b hb
  have hvbounds2 := P472_T1_DecimalValueBounds
    ((d2.digits.val.take d2.num_digits.val).map (fun b => b.val))
    z2 zs2 hxs2 (by omega) hdmap2 d2.decimal_point.val
  have htake2 : (d2.digits.val.take d2.num_digits.val).map
      (fun b => b.val) =
      (d2.digits.val.map (fun b => b.val)).take d2.num_digits.val := by
    simp
  have hv2 : 0 < V d2 := by
    have hz2pos : (0 : Real) < z2 := by exact_mod_cast (show 0 < z2 by omega)
    have hpow : (0 : Real) < (10 : Real) ^ (d2.decimal_point.val - 1) :=
      zpow_pos (by norm_num) _
    have hlow : (z2 : Real) * (10 : Real) ^ (d2.decimal_point.val - 1) ≤ V d2 := by
      simpa [V, ← htake2, hxs2, hlen2] using hvbounds2.1
    exact lt_of_lt_of_le (mul_pos hz2pos hpow) hlow
  have hcapacity0 (R : Int)
      (hR : R = exp2.val - 53 ∨ R = exp2.val - 52) :
      0 ≤ R - exp0.val + 768 - d0.decimal_point.val := by
    have h := hcap0
    rcases hR with hR | hR <;> rw [hR] <;> omega
  have hcapacity2 (R : Int)
      (hR : R = exp2.val - 53 ∨ R = exp2.val - 52) :
      0 ≤ R - (exp2.val + 1) + 768 - d2.decimal_point.val := by
    rcases hR with hR | hR <;> rw [hR] <;> omega
  have hcapacity3 (R : Int)
      (hR : R = exp2.val - 53 ∨ R = exp2.val - 52) :
      0 ≤ R - (exp2.val - 52) + 768 - d3.decimal_point.val := by
    rcases hR with hR | hR <;> rw [hR] <;> omega
  have hnoncross (c : Nat) (R : Int)
      (hR : R = exp2.val - 53 ∨ R = exp2.val - 52) :
      V d3 < (c : Real) * (2 : Real) ^ (R - (exp2.val - 52)) ->
      (c : Real) * (2 : Real) ^ R < Y -> False := by
    intro hcross3 hcrossY
    have hcap2 := hcapacity2 R hR
    have hcap3 := hcapacity3 R hR
    have halign2 := P856_T1_CoefficientGridAlignment c
      (R - (exp2.val + 1)) d2.decimal_point.val (by omega) hcap2
    rcases halign2 with ⟨b2, hb2⟩
    have halign3 := P856_T1_CoefficientGridAlignment c
      (R - (exp2.val - 52)) d3.decimal_point.val (by omega) hcap3
    rcases halign3 with ⟨b3, hb3⟩
    have hpow53 : (2 : Real) ^ (53 : Nat) *
        (2 : Real) ^ (R - (exp2.val + 1)) =
        (2 : Real) ^ (R - (exp2.val - 52)) := by
      have hnat : (2 : Real) ^ (53 : Nat) = (2 : Real) ^ (53 : Int) := by
        norm_num
      rw [hnat, ← zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      congr 1
      omega
    have hcoefPower : (c : Real) *
        (2 : Real) ^ (R - (exp2.val - 52)) =
        (2 : Real) ^ (53 : Nat) *
          ((c : Real) * (2 : Real) ^ (R - (exp2.val + 1))) := by
      have hnatpow : (2 : Real) ^ (53 : Nat) =
          (2 : Real) ^ (53 : Int) := by norm_num
      rw [hnatpow]
      rw [show R - (exp2.val - 52) = (53 : Int) +
          (R - (exp2.val + 1)) by omega]
      rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
      ring
    have hshifttransport := P798_T1_LeftBoundaryTransport d2 d3
      53#usize b3 (by norm_num) hv2 hd2 hshift hn3
    have hcross2 : V d2 < (c : Real) *
        (2 : Real) ^ (R - (exp2.val + 1)) := by
      by_contra hnot
      have hle : (c : Real) * (2 : Real) ^ (R - (exp2.val + 1)) ≤ V d2 :=
        le_of_not_gt hnot
      have hmul := mul_le_mul_of_nonneg_left hle
        (le_of_lt (show (0 : Real) < (2 : Real) ^ (53 : Nat) by positivity))
      have htransportIn : (b3 : Real) *
          (10 : Real) ^ (d3.decimal_point.val - 768) ≤
          (2 : Real) ^ (53 : Nat) * V d2 := by
        calc
          (b3 : Real) * (10 : Real) ^ (d3.decimal_point.val - 768) =
              (c : Real) * (2 : Real) ^ (R - (exp2.val - 52)) := hb3.symm
          _ = (2 : Real) ^ (53 : Nat) *
              ((c : Real) * (2 : Real) ^ (R - (exp2.val + 1))) := by
                exact hcoefPower
          _ ≤ (2 : Real) ^ (53 : Nat) * V d2 := hmul
      have htransportOut := hshifttransport htransportIn
      rw [← hb3] at htransportOut
      exact (not_lt_of_ge htransportOut) hcross3
    have hloop2Exponent : exp2.val + 1 = exp1.val + shift.val := by
      rcases h2case with hident | hright
      · rcases hident with ⟨hcut, hzero, hd2eq, he2eq⟩
        have he2 : exp2.val = exps.val :=
          congrArg (fun e : Std.I32 => e.val) he2eq
        omega
      · rcases hright with ⟨hcut, hpositive, hcall, hexp2reset⟩
        omega
    have hcross1 : V d1 < (c : Real) *
        (2 : Real) ^ (R - exp1.val) := by
      by_contra hnot
      have hle : (c : Real) * (2 : Real) ^ (R - exp1.val) ≤ V d1 :=
        le_of_not_gt hnot
      rcases h2case with hident | hright
      · rcases hident with ⟨hcut, hzero, hd2eq, he2eq⟩
        have he2 : exp2.val = exps.val :=
          congrArg (fun e : Std.I32 => e.val) he2eq
        have hexp : exp2.val + 1 = exp1.val := by omega
        rw [hd2eq] at hcross2
        rw [show R - (exp2.val + 1) = R - exp1.val by omega] at hcross2
        exact (not_lt_of_ge hle) hcross2
      · rcases hright with ⟨hcut, hpositive, hcall, hexp2reset⟩
        have hnonreset2 : ¬ (d2.num_digits.val = 0 ∧
            d2.decimal_point.val = 0 ∧ d2.truncated = false) := by
          intro hreset
          have hn2pos : 0 < d2.num_digits.val := by
            rw [← hlen2]
            simp
          omega
        have hrighttransport := P529_T1_RightBoundaryTransport
          d1 d2 shift (by omega) hd1 hcall hnonreset2 hn2 hv1
        have hshiftpowpos : (0 : Real) < (2 : Real) ^ shift.val := by
          positivity
        have hnatpow : (2 : Real) ^ shift.val =
            (2 : Real) ^ (shift.val : Int) := by
          norm_num [zpow_natCast]
        have hpowRel : (2 : Real) ^ (R - exp1.val) =
            (2 : Real) ^ (R - (exp2.val + 1)) * (2 : Real) ^ shift.val := by
          rw [show R - exp1.val = (R - (exp2.val + 1)) +
              (shift.val : Int) by omega]
          rw [zpow_add₀ (by norm_num : (2 : Real) ≠ 0)]
          rw [← hnatpow]
        have hmulBound : (c : Real) *
            (2 : Real) ^ (R - (exp2.val + 1)) * (2 : Real) ^ shift.val ≤ V d1 := by
          calc
            (c : Real) * (2 : Real) ^ (R - (exp2.val + 1)) *
                (2 : Real) ^ shift.val =
                (c : Real) * ((2 : Real) ^ (R - (exp2.val + 1)) *
                  (2 : Real) ^ shift.val) := by ring
            _ = (c : Real) * (2 : Real) ^ (R - exp1.val) := by
              rw [← hpowRel]
            _ ≤ V d1 := hle
        have htransportIn : (b2 : Real) *
            (10 : Real) ^ (d2.decimal_point.val - 768) ≤
            V d1 / (2 : Real) ^ shift.val := by
          rw [← hb2]
          exact (le_div_iff₀ hshiftpowpos).2 (by simpa [mul_assoc] using hmulBound)
        have htransportOut := hrighttransport b2 htransportIn
        rw [← hb2] at htransportOut
        exact (not_lt_of_ge htransportOut) hcross2
    have hleftStep := hleftBoundary c R (hcapacity0 R hR)
    have hcross0 := hleftStep.2 hcross1
    have hrightStep := hrightBoundary c R (hcapacity0 R hR)
    have hcrossd := hrightStep.2 hcross0
    have hgrid := P798_T1_GridAlignment d hinput.1
    rcases hgrid with ⟨a, ha⟩
    have halign0 := P856_T1_CoefficientGridAlignment c R
      d.decimal_point.val (by omega) hrightStep.1
    rcases halign0 with ⟨b, hb⟩
    let q : Real := (10 : Real) ^ (d.decimal_point.val - 768)
    have htakeD : (d.digits.val.take d.num_digits.val).map
        (fun z => z.val) =
        (d.digits.val.map (fun z => z.val)).take d.num_digits.val := by
      simp
    have hq : 0 < q := by
      dsimp [q]
      exact zpow_pos (by norm_num) _
    have ha' : V d = (a : Real) * q := by
      simpa only [V, q, htakeD] using ha
    have hb' : (c : Real) * (2 : Real) ^ R = (b : Real) * q := by
      simpa [q] using hb
    have hcrossd' : (a : Real) * q < (c : Real) * (2 : Real) ^ R := by
      rw [← ha']
      exact hcrossd
    have habreal : (a : Real) * q < (b : Real) * q := by
      rw [← hb']
      exact hcrossd'
    have hab : a < b := by
      exact_mod_cast (lt_of_mul_lt_mul_right habreal (le_of_lt hq))
    have hbaReal : (b : Real) * q < ((a : Nat) + 1 : Real) * q := by
      calc
        (b : Real) * q = (c : Real) * (2 : Real) ^ R := hb'.symm
        _ < Y := hcrossY
        _ = V d + q := by simpa [q] using hY
        _ = (a : Real) * q + q := by rw [ha']
        _ = ((a : Nat) + 1 : Real) * q := by push_cast; ring
    have hba : b < a + 1 := by
      exact_mod_cast (lt_of_mul_lt_mul_right hbaReal (le_of_lt hq))
    omega
  have hpowFactor (r s : Int) :
      (2 : Real) ^ r = (2 : Real) ^ (r - s) * (2 : Real) ^ s := by
    calc
      (2 : Real) ^ r = (2 : Real) ^ ((r - s) + s) := by congr 1 <;> omega
      _ = (2 : Real) ^ (r - s) * (2 : Real) ^ s :=
        zpow_add₀ (by norm_num : (2 : Real) ≠ 0) _ _
  constructor
  · intro n
    by_contra hbad
    push_neg at hbad
    rcases hbad with ⟨hleft, hright⟩
    let c : Nat := 2 * n + 1
    let R : Int := exp2.val - 53
    let s : Int := exp2.val - 52
    have hboundary : (n : Real) + 1 / 2 = (c : Real) *
        (2 : Real) ^ (R - s) := by
      have hexp : R - s = -1 := by dsimp [R, s]; omega
      rw [hexp]
      have hpow : (2 : Real) ^ (-1 : Int) = (1 / 2 : Real) := by norm_num
      rw [hpow]
      dsimp [c]
      push_cast
      ring
    have hupperMul : ((n : Real) + 1 / 2) * (2 : Real) ^ s < Y :=
      (lt_div_iff₀ (zpow_pos (by norm_num) s)).mp hright
    have hcrossY : (c : Real) * (2 : Real) ^ R < Y := by
      calc
        (c : Real) * (2 : Real) ^ R =
            ((c : Real) * (2 : Real) ^ (R - s)) * (2 : Real) ^ s := by
              conv_lhs => rw [hpowFactor R s]
              ring
        _ = ((n : Real) + 1 / 2) * (2 : Real) ^ s := by rw [← hboundary]
        _ < Y := hupperMul
    have hR : R = exp2.val - 53 ∨ R = exp2.val - 52 := Or.inl rfl
    have hcross3 : V d3 < (c : Real) * (2 : Real) ^ (R - s) := by
      rw [← hboundary]
      exact hleft
    exact hnoncross c R hR hcross3 hcrossY
  · intro n
    by_contra hbad
    push_neg at hbad
    rcases hbad with ⟨hleft, hright⟩
    let c : Nat := 2 * n + 1
    let R : Int := exp2.val - 52
    let s : Int := exp2.val - 52
    have hboundary : (2 * n + 1 : Nat) = (c : Real) *
        (2 : Real) ^ (R - s) := by
      have hexp : R - s = 0 := by dsimp [R, s]; omega
      rw [hexp]
      simp [c]
    have hupperMul : ((2 * n + 1 : Nat) : Real) *
        (2 : Real) ^ s < Y := (lt_div_iff₀ (zpow_pos (by norm_num) s)).mp hright
    have hcrossY : (c : Real) * (2 : Real) ^ R < Y := by
      calc
        (c : Real) * (2 : Real) ^ R =
            ((c : Real) * (2 : Real) ^ (R - s)) * (2 : Real) ^ s := by
              conv_lhs => rw [hpowFactor R s]
              ring
        _ = ((2 * n + 1 : Nat) : Real) * (2 : Real) ^ s := by
              rw [← hboundary]
        _ < Y := hupperMul
    have hR : R = exp2.val - 53 ∨ R = exp2.val - 52 := Or.inr rfl
    have hcross3 : V d3 < (c : Real) * (2 : Real) ^ (R - s) := by
      rw [← hboundary]
      exact hleft
    exact hnoncross c R hR hcross3 hcrossY

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (152)
More program dependencies (110)
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 155 entries
Technical checking records
Local closure summary
{
  "node": "P529_T1_SeparationPackage",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "64f0bc07a289fd833fd0add89c1791a27e9dd7fd5ad7a29c1e60b934835408b8",
  "active_statement_hash": "a39a916e9e2ea30a4cb0f96373fcaa0f11fc1bf4bcef962186bb3dce3eacb7da",
  "kernel_axioms": [
    "Classical.choice",
    "Quot.sound",
    "propext"
  ],
  "toolchain_hash": "ce4c4e3d87434b9663f46de25ce34b48a0cf0d392e0a320a0787b4674a2d7b61",
  "lean_executable_hash": "3e0d0d3d801675359f2d4cf9815bfdb417b20b92fdd9d48b3b14c95bbae28bbf",
  "checker_script_hash": "c8e4a03273e23b9a8f2e141020652a4e0b7b0a8ab0883366ea9d031ca3f37aa1",
  "approved_axioms_hash": "576e6bf9480cfd32f53c309c7ac8fb115c1ba6e413f299ed5ff9fa7c647e6769",
  "axcheck_status": "Agreed",
  "accepted_at_snapshot_id": "worker-result-local-closure-issuance-cycle-200",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "P472_T1_DecimalValueBounds": "4b5c924b5d52bc9d",
    "P495_T1_SlowLoop0Execution": "5a1e49d921a1825a",
    "P529_T1_FinalShiftCertificate": "6a5bd46c366c9837",
    "P529_T1_LeftHistoryBoundary": "81ad17a70873ae99",
    "P529_T1_Loop1Execution": "da66766413255a0f",
    "P529_T1_Loop2Execution": "e8eeb6e19acff10b",
    "P529_T1_NormalizationBounds": "deb4bf7513f18e80",
    "P529_T1_ReachableCapacity": "eb6e974cd4ed2841",
    "P529_T1_RightBoundaryTransport": "bb615631f8d7363c",
    "P529_T1_RightHistoryBoundary": "2f9292b355b28e68",
    "P798_T1_GridAlignment": "f2e86c75264ff7d3",
    "P798_T1_LeftBoundaryTransport": "8382fe6b25ea536f",
    "P856_T1_CoefficientGridAlignment": "811bf9ec1aa2ffd7",
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "3c283430b9003d37"
  },
  "strict_definition_deps": {
    "F64": "ec4e25fbaf4e11d4",
    "F64_Insts_Dec2flt_modelNumImpTraitsFloatU64": "94095c9bf79da164",
    "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": "Recorded Sound: VerifierPass",
  "assessment_status": "VerifierPass",
  "fingerprint_relation": "matches current fingerprint",
  "assessment_fingerprint": "sound-v2:d0c9d0915c0468f276a043f9699a35ed0d2739be584e7cfe8666e3400f82b9ca",
  "current_fingerprint": "sound-v2:d0c9d0915c0468f276a043f9699a35ed0d2739be584e7cfe8666e3400f82b9ca",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "sound_status": "Pass",
  "substantiveness_status": "Pass"
}