P529_T1_LeftLeadingProgress

Lean checked

Statement

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

Lemma · Correlated leading-digit progress

Let d,d' have decimal retained words z::t,z'::t' of lengths equal to their recorded counts, with z,z'\ge1, and let d.n\le768. If an actual left shift by k\le60 returns d', then:
\begin{array}{ll} p=p'=-1,\ k=3&\Longrightarrow z'\ge7,\\ p=p'=0,\ (z,k)=(1,2)\ \hbox{or}\ (2,1)&\Longrightarrow z'\ge3,\\ p=p'=0,\ z\ge3,\ k=1&\Longrightarrow z'\ge5,\\ p=-1,\ p'=0,\ z\ge7,\ k=3&\Longrightarrow z'\ge5. \end{array}
Additionally z\ge7 implies that the actual digit-growth call on d at shift three returns exactly one.

Lean statement

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

import Tablet.DecimalSeqLeftShiftRecordSemantics
import Tablet.DecimalLeftShiftDigitGrowth
import Tablet.P472_T1_DecimalValueBounds
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_LeftLeadingProgress]
theorem P529_T1_LeftLeadingProgress
    (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq) (shift : Std.Usize)
    (z z' : Nat) (zs zs' : List Nat)
    (hshift : shift.val <= 60)
    (hcap : d.num_digits.val <= 768)
    (hdigits : forall b, b ∈ d.digits.val.take d.num_digits.val -> b.val < 10)
    (hdigits' : forall b, b ∈ d'.digits.val.take d'.num_digits.val -> b.val < 10)
    (hshape : (d.digits.val.take d.num_digits.val).map (fun b => b.val) = z :: zs)
    (hshape' : (d'.digits.val.take d'.num_digits.val).map (fun b => b.val) = z' :: zs')
    (hlen : (z :: zs).length = d.num_digits.val)
    (hlen' : (z' :: zs').length = d'.num_digits.val)
    (hz : 1 <= z) (hz' : 1 <= z')
    (hcall : num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift = ok d') :
    (d.decimal_point.val = -1 -> d'.decimal_point.val = -1 ->
      shift.val = 3 -> 7 <= z') /\
    (d.decimal_point.val = 0 -> d'.decimal_point.val = 0 ->
      ((z = 1 /\ shift.val = 2) \/ (z = 2 /\ shift.val = 1)) -> 3 <= z') /\
    (d.decimal_point.val = 0 -> d'.decimal_point.val = 0 ->
      3 <= z -> shift.val = 1 -> 5 <= z') /\
    (d.decimal_point.val = -1 -> d'.decimal_point.val = 0 ->
      7 <= z -> shift.val = 3 -> 5 <= z') /\
    (7 <= z ->
      num.imp.dec2flt.decimal_seq.number_of_digits_decimal_left_shift
        d 3#usize = ok 1#usize) := 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

For either retained word, the fold identity F(z::t)=z10^{|t|}+F(t) and induction on its decimal tail give 0\le F(t)<10^{|t|}. Multiplication by the positive decimal scale gives
z10^{p-1}\le V(d)<(z+1)10^{p-1},\quad z'10^{p'-1}\le V(d')<(z'+1)10^{p'-1}.
Positivity, also supplied by DecimalValueBounds, permits DecimalSeqLeftShiftRecordSemantics on the given call:
V(d')=2^kV(d)-\rho,\quad 0\le\rho<10^{p'-768}.
For p=p'=-1,k=3, the lower estimate is V(d')\ge8z/100-\rho>7/100, since z\ge1 and \rho<10^{-769}<1/100. If z'\le6, the upper estimate is V(d')<7/100, a contradiction. For the second case the lower scale is 4/10 and \rho<10^{-768}<1/10, so V(d')>3/10; z'\le2 would give V(d')<3/10. For the third case the lower scale is at least 6/10, so V(d')>5/10, whereas z'\le4 would give V(d')<5/10. For the fourth case the lower scale is at least 56/100; \rho<10^{-768}<1/100 gives V(d')>55/100, contradicting the upper estimate V(d')<5/10 if z'\le4. All scale comparisons are strict integer-power comparisons at positive base ten.
For the final conclusion put n=d.n and I=F(z::t). The positional lower bound gives I\ge7\,10^{n-1}, hence 8I\ge56\,10^{n-1}\ge10^n. The retained-length hypothesis and n\le768 identify this n with the length in DecimalLeftShiftDigitGrowth. Apply that principal with shift three and bracket 1<8<10. Its exact threshold formula returns one when 10^n\le8I, which we have proved. This constructs the stated normal growth call.

Lean proof


  let xs := (d.digits.val.take d.num_digits.val).map (fun b => b.val)
  let xs' := (d'.digits.val.take d'.num_digits.val).map (fun b => b.val)
  let F := fun ys : List Nat => ys.foldl (fun a b => 10 * a + b) 0
  let V := fun (q : num.imp.dec2flt.decimal_seq.DecimalSeq) =>
    let digits := (q.digits.val.take q.num_digits.val).map (fun b => b.val)
    let integer := F digits
    (integer : Real) * (10 : Real) ^ (q.decimal_point.val - (q.num_digits.val : Int))
  have hxs : xs = z :: zs := by simpa [xs] using hshape
  have hxs' : xs' = z' :: zs' := by simpa [xs'] using hshape'
  have hdigitsF : forall b, b ∈ xs -> b < 10 := by
    intro b hb
    simp only [xs, List.mem_map] at hb
    rcases hb with ⟨q, hq, rfl⟩
    exact hdigits q hq
  have hdigitsF' : forall b, b ∈ xs' -> b < 10 := by
    intro b hb
    simp only [xs', List.mem_map] at hb
    rcases hb with ⟨q, hq, rfl⟩
    exact hdigits' q hq
  have foldFrom (ys : List Nat) (a : Nat) :
      ys.foldl (fun n b => 10 * n + b) a = a * 10 ^ ys.length + F ys := by
    induction ys generalizing a with
    | nil => simp [F]
    | cons b ys ih =>
      simp only [List.foldl_cons, List.length_cons]
      rw [ih, pow_succ]
      change (10 * a + b) * 10 ^ ys.length + F ys =
        a * (10 ^ ys.length * 10) + (b :: ys).foldl (fun n q => 10 * n + q) 0
      simp only [List.foldl_cons]
      rw [ih]
      ring
  have foldBound (ys : List Nat) (hd : forall b, b ∈ ys -> b < 10) :
      F ys < 10 ^ ys.length := by
    induction ys with
    | nil => simp [F]
    | cons b ys ih =>
      have hb : b < 10 := hd b (by simp)
      have htail : forall q, q ∈ ys -> q < 10 := by
        intro q hq
        exact hd q (by simp [hq])
      have hi := ih htail
      rw [show F (b :: ys) = b * 10 ^ ys.length + F ys by
        simpa [F] using foldFrom ys b, List.length_cons, pow_succ]
      have hm : b * 10 ^ ys.length <= 9 * 10 ^ ys.length :=
        Nat.mul_le_mul_right _ (by omega)
      calc
        b * 10 ^ ys.length + F ys < b * 10 ^ ys.length + 10 ^ ys.length :=
          Nat.add_lt_add_left hi _
        _ <= 9 * 10 ^ ys.length + 10 ^ ys.length := Nat.add_le_add_right hm _
        _ = 10 ^ (ys.length + 1) := by rw [pow_succ]; ring
  have htail : F zs < 10 ^ zs.length := by
    apply foldBound
    intro b hb
    have hb' : b ∈ xs := by simpa [hxs] using (Or.inr hb)
    exact hdigitsF b hb'
  have htail' : F zs' < 10 ^ zs'.length := by
    apply foldBound
    intro b hb
    have hb' : b ∈ xs' := by simpa [hxs'] using (Or.inr hb)
    exact hdigitsF' b hb'
  have hfold : F xs = z * 10 ^ zs.length + F zs := by
    rw [hxs]
    simpa [F] using foldFrom zs z
  have hfold' : F xs' = z' * 10 ^ zs'.length + F zs' := by
    rw [hxs']
    simpa [F] using foldFrom zs' z'
  have hlenN : d.num_digits.val = zs.length + 1 := by
    have := hlen
    simp only [List.length_cons] at this
    omega
  have hlenN' : d'.num_digits.val = zs'.length + 1 := by
    have := hlen'
    simp only [List.length_cons] at this
    omega
  have hVd : V d = (F xs : Real) * (10 : Real) ^
      (d.decimal_point.val - (d.num_digits.val : Int)) := by rfl
  have hVd' : V d' = (F xs' : Real) * (10 : Real) ^
      (d'.decimal_point.val - (d'.num_digits.val : Int)) := by rfl
  have hpos : 0 < V d := by
    rw [hVd, hfold]
    have : 0 < (10 : Real) ^ zs.length := by positivity
    have : 0 < (z : Real) * (10 : Real) ^ zs.length + (F zs : Real) := by
      have hzR : (0 : Real) < z := by exact_mod_cast hz
      positivity
    have hp : 0 < (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) :=
      zpow_pos (by norm_num) _
    positivity
  obtain ⟨rho, hrho0, hrho, hrecord, _⟩ :=
    DecimalSeqLeftShiftRecordSemantics d d' shift hshift hpos hdigits hcall
  have hVrel : V d' = (2 : Real) ^ shift.val * V d - rho := by
    simpa [V] using hrecord
  have hpowd : (10 : Real) ^ (d.decimal_point.val - 1) =
      (10 : Real) ^ (zs.length : Int) *
        (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) := by
    rw [← zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
    congr 1
    rw [hlenN]
    push_cast
    omega
  have hpowd' : (10 : Real) ^ (d'.decimal_point.val - 1) =
      (10 : Real) ^ (zs'.length : Int) *
        (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) := by
    rw [← zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
    congr 1
    rw [hlenN']
    push_cast
    omega
  have hposBounds : (z : Real) * (10 : Real) ^ (d.decimal_point.val - 1) <= V d ∧
      V d < ((z + 1 : Nat) : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
    have hp : 0 < (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) :=
      zpow_pos (by norm_num) _
    have hnatlo : z * 10 ^ zs.length <= z * 10 ^ zs.length + F zs := by omega
    have hnathi : z * 10 ^ zs.length + F zs < (z + 1) * 10 ^ zs.length := by
      calc
        z * 10 ^ zs.length + F zs < z * 10 ^ zs.length + 10 ^ zs.length :=
          Nat.add_lt_add_left htail _
        _ = (z + 1) * 10 ^ zs.length := by ring
    have hloR : (z : Real) * (10 : Real) ^ zs.length <=
        ((z * 10 ^ zs.length + F zs : Nat) : Real) := by exact_mod_cast hnatlo
    have hhiR : ((z * 10 ^ zs.length + F zs : Nat) : Real) <
        (((z + 1) * 10 ^ zs.length : Nat) : Real) := by exact_mod_cast hnathi
    constructor
    · calc
        (z : Real) * (10 : Real) ^ (d.decimal_point.val - 1) =
            ((z : Real) * (10 : Real) ^ zs.length) *
              (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) := by
                rw [hpowd, ← zpow_natCast (10 : Real) zs.length]; ring
        _ <= ((z * 10 ^ zs.length + F zs : Nat) : Real) *
              (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) :=
                mul_le_mul_of_nonneg_right hloR (le_of_lt hp)
        _ = V d := by rw [hVd, hfold]
    · calc
        V d = ((z * 10 ^ zs.length + F zs : Nat) : Real) *
            (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) := by
              rw [hVd, hfold]
        _ < (((z + 1) * 10 ^ zs.length : Nat) : Real) *
              (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) :=
                mul_lt_mul_of_pos_right hhiR hp
        _ = ((z + 1 : Nat) : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
              rw [hpowd]
              have hc : (((z + 1) * 10 ^ zs.length : Nat) : Real) =
                  ((z + 1 : Nat) : Real) * (10 : Real) ^ zs.length := by
                norm_cast
              rw [hc]
              rw [← zpow_natCast (10 : Real) zs.length]
              ring
  have hposBounds' : (z' : Real) * (10 : Real) ^ (d'.decimal_point.val - 1) <= V d' ∧
      V d' < ((z' + 1 : Nat) : Real) * (10 : Real) ^ (d'.decimal_point.val - 1) := by
    have hp : 0 < (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) :=
      zpow_pos (by norm_num) _
    have hnatlo : z' * 10 ^ zs'.length <= z' * 10 ^ zs'.length + F zs' := by omega
    have hnathi : z' * 10 ^ zs'.length + F zs' < (z' + 1) * 10 ^ zs'.length := by
      calc
        z' * 10 ^ zs'.length + F zs' < z' * 10 ^ zs'.length + 10 ^ zs'.length :=
          Nat.add_lt_add_left htail' _
        _ = (z' + 1) * 10 ^ zs'.length := by ring
    have hloR : (z' : Real) * (10 : Real) ^ zs'.length <=
        ((z' * 10 ^ zs'.length + F zs' : Nat) : Real) := by exact_mod_cast hnatlo
    have hhiR : ((z' * 10 ^ zs'.length + F zs' : Nat) : Real) <
        (((z' + 1) * 10 ^ zs'.length : Nat) : Real) := by exact_mod_cast hnathi
    constructor
    · calc
        (z' : Real) * (10 : Real) ^ (d'.decimal_point.val - 1) =
            ((z' : Real) * (10 : Real) ^ zs'.length) *
              (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) := by
                rw [hpowd', ← zpow_natCast (10 : Real) zs'.length]; ring
        _ <= ((z' * 10 ^ zs'.length + F zs' : Nat) : Real) *
              (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) :=
                mul_le_mul_of_nonneg_right hloR (le_of_lt hp)
        _ = V d' := by rw [hVd', hfold']
    · calc
        V d' = ((z' * 10 ^ zs'.length + F zs' : Nat) : Real) *
            (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) := by
              rw [hVd', hfold']
        _ < (((z' + 1) * 10 ^ zs'.length : Nat) : Real) *
              (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) :=
                mul_lt_mul_of_pos_right hhiR hp
        _ = ((z' + 1 : Nat) : Real) * (10 : Real) ^ (d'.decimal_point.val - 1) := by
              rw [hpowd']
              have hc : (((z' + 1) * 10 ^ zs'.length : Nat) : Real) =
                  ((z' + 1 : Nat) : Real) * (10 : Real) ^ zs'.length := by
                norm_cast
              rw [hc]
              rw [← zpow_natCast (10 : Real) zs'.length]
              ring
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · intro hp hp' hk
    have hlow := hposBounds.1
    rw [hp] at hlow
    have hrel := hVrel
    rw [hk] at hrel
    norm_num at hlow hrel
    have hloss : rho < (1 : Real) / 100 := by
      rw [hp'] at hrho
      have hpow : (10 : Real) ^ (-769 : Int) < (1 : Real) / 100 := by
        calc
          (10 : Real) ^ (-769 : Int) < (10 : Real) ^ (-2 : Int) :=
            zpow_lt_zpow_right₀ (by norm_num) (by omega)
          _ = (1 : Real) / 100 := by norm_num
      exact lt_trans hrho hpow
    have hzR : (1 : Real) <= z := by exact_mod_cast hz
    have hlarge : (7 : Real) / 100 < V d' := by nlinarith
    by_contra hn
    have hzup : z' <= 6 := by omega
    have hupper := hposBounds'.2
    rw [hp'] at hupper
    norm_num at hupper
    have hzupR : (z' : Real) <= 6 := by exact_mod_cast hzup
    have hupperSmall : V d' < (7 : Real) / 100 := by
      nlinarith only [hupper, hzupR]
    linarith only [hlarge, hupperSmall]
  · intro hp hp' hcases
    rcases hcases with ⟨hzcase, hk⟩ | ⟨hzcase, hk⟩
    · have hlow := hposBounds.1
      rw [hp] at hlow
      rw [hzcase] at hlow
      norm_num at hlow
      have hrel := hVrel
      rw [hk] at hrel
      norm_num at hrel
      have hloss : rho < (1 : Real) / 10 := by
        rw [hp'] at hrho
        have hpow : (10 : Real) ^ (-768 : Int) < (1 : Real) / 10 := by
          calc
            (10 : Real) ^ (-768 : Int) < (10 : Real) ^ (-1 : Int) :=
              zpow_lt_zpow_right₀ (by norm_num) (by omega)
            _ = (1 : Real) / 10 := by norm_num
        exact lt_trans hrho hpow
      have hlarge : (3 : Real) / 10 < V d' := by nlinarith
      by_contra hn
      have hzup : z' <= 2 := by omega
      have hupper := hposBounds'.2
      rw [hp'] at hupper
      norm_num at hupper
      have hzupR : (z' : Real) <= 2 := by exact_mod_cast hzup
      have hupperSmall : V d' < (3 : Real) / 10 := by
        nlinarith only [hupper, hzupR]
      linarith only [hlarge, hupperSmall]
    · have hlow := hposBounds.1
      rw [hp] at hlow
      rw [hzcase] at hlow
      norm_num at hlow
      have hrel := hVrel
      rw [hk] at hrel
      norm_num at hrel
      have hloss : rho < (1 : Real) / 10 := by
        rw [hp'] at hrho
        have hpow : (10 : Real) ^ (-768 : Int) < (1 : Real) / 10 := by
          calc
            (10 : Real) ^ (-768 : Int) < (10 : Real) ^ (-1 : Int) :=
              zpow_lt_zpow_right₀ (by norm_num) (by omega)
            _ = (1 : Real) / 10 := by norm_num
        exact lt_trans hrho hpow
      have hlarge : (3 : Real) / 10 < V d' := by nlinarith
      by_contra hn
      have hzup : z' <= 2 := by omega
      have hupper := hposBounds'.2
      rw [hp'] at hupper
      norm_num at hupper
      have hzupR : (z' : Real) <= 2 := by exact_mod_cast hzup
      have hupperSmall : V d' < (3 : Real) / 10 := by
        nlinarith only [hupper, hzupR]
      linarith only [hlarge, hupperSmall]
  · intro hp hp' hzlo hk
    have hlow := hposBounds.1
    rw [hp] at hlow
    norm_num at hlow
    have hrel := hVrel
    rw [hk] at hrel
    norm_num at hrel
    have hloss : rho < (1 : Real) / 10 := by
      rw [hp'] at hrho
      have hpow : (10 : Real) ^ (-768 : Int) < (1 : Real) / 10 := by
        calc
          (10 : Real) ^ (-768 : Int) < (10 : Real) ^ (-1 : Int) :=
            zpow_lt_zpow_right₀ (by norm_num) (by omega)
          _ = (1 : Real) / 10 := by norm_num
      exact lt_trans hrho hpow
    have hzloR : (3 : Real) <= z := by exact_mod_cast hzlo
    have hlarge : (1 : Real) / 2 < V d' := by nlinarith
    by_contra hn
    have hzup : z' <= 4 := by omega
    have hupper := hposBounds'.2
    rw [hp'] at hupper
    norm_num at hupper
    have hzupR : (z' : Real) <= 4 := by exact_mod_cast hzup
    have hupperSmall : V d' < (1 : Real) / 2 := by
      nlinarith only [hupper, hzupR]
    linarith only [hlarge, hupperSmall]
  · intro hp hp' hzlo hk
    have hlow := hposBounds.1
    rw [hp] at hlow
    norm_num at hlow
    have hrel := hVrel
    rw [hk] at hrel
    norm_num at hrel
    have hloss : rho < (1 : Real) / 100 := by
      rw [hp'] at hrho
      have hpow : (10 : Real) ^ (-768 : Int) < (1 : Real) / 100 := by
        calc
          (10 : Real) ^ (-768 : Int) < (10 : Real) ^ (-2 : Int) :=
            zpow_lt_zpow_right₀ (by norm_num) (by omega)
          _ = (1 : Real) / 100 := by norm_num
      exact lt_trans hrho hpow
    have hzloR : (7 : Real) <= z := by exact_mod_cast hzlo
    have hlarge : (11 : Real) / 20 < V d' := by nlinarith
    by_contra hn
    have hzup : z' <= 4 := by omega
    have hupper := hposBounds'.2
    rw [hp'] at hupper
    norm_num at hupper
    have hzupR : (z' : Real) <= 4 := by exact_mod_cast hzup
    have hupperSmall : V d' < (1 : Real) / 2 := by
      nlinarith only [hupper, hzupR]
    linarith only [hlarge, hupperSmall]
  · intro hzlo
    have hI : 10 ^ d.num_digits.val <= 8 * F xs := by
      rw [hlenN, hfold]
      have hp : 0 < 10 ^ zs.length := by positivity
      have hmul : 7 * 10 ^ zs.length <= z * 10 ^ zs.length :=
        Nat.mul_le_mul_right _ (by omega)
      have hbase : 10 * 10 ^ zs.length <=
          8 * (z * 10 ^ zs.length + F zs) := by
        omega
      simpa [pow_succ, Nat.mul_comm] using hbase
    have hgrowth := DecimalLeftShiftDigitGrowth d (3#usize) 1
      (by norm_num) (by norm_num) (by norm_num) hcap hdigits
    rcases hgrowth with ⟨out, hout, houtval⟩
    have houtval' : out.val =
        if 10 ^ d.num_digits.val <= F xs * 2 ^ (3 : Nat) then 1 else 0 := by
      simpa [xs, F] using houtval
    have hthreshold : 10 ^ d.num_digits.val <= F xs * 2 ^ (3 : Nat) := by
      norm_num at hI ⊢
      omega
    rw [if_pos hthreshold] at houtval'
    have houtEq : out = 1#usize := UScalar.eq_of_val_eq (by simpa using houtval')
    simpa [houtEq] using hout

end dec2flt_model

Download Lean source · Download TeX source

Complete Lean module
import Tablet.DecimalSeqLeftShiftRecordSemantics
import Tablet.DecimalLeftShiftDigitGrowth
import Tablet.P472_T1_DecimalValueBounds
open Aeneas Aeneas.Std Result ControlFlow Error
set_option autoImplicit false
namespace dec2flt_model

-- [TABLET NODE: P529_T1_LeftLeadingProgress]
theorem P529_T1_LeftLeadingProgress
    (d d' : num.imp.dec2flt.decimal_seq.DecimalSeq) (shift : Std.Usize)
    (z z' : Nat) (zs zs' : List Nat)
    (hshift : shift.val <= 60)
    (hcap : d.num_digits.val <= 768)
    (hdigits : forall b, b ∈ d.digits.val.take d.num_digits.val -> b.val < 10)
    (hdigits' : forall b, b ∈ d'.digits.val.take d'.num_digits.val -> b.val < 10)
    (hshape : (d.digits.val.take d.num_digits.val).map (fun b => b.val) = z :: zs)
    (hshape' : (d'.digits.val.take d'.num_digits.val).map (fun b => b.val) = z' :: zs')
    (hlen : (z :: zs).length = d.num_digits.val)
    (hlen' : (z' :: zs').length = d'.num_digits.val)
    (hz : 1 <= z) (hz' : 1 <= z')
    (hcall : num.imp.dec2flt.decimal_seq.DecimalSeq.left_shift d shift = ok d') :
    (d.decimal_point.val = -1 -> d'.decimal_point.val = -1 ->
      shift.val = 3 -> 7 <= z') /\
    (d.decimal_point.val = 0 -> d'.decimal_point.val = 0 ->
      ((z = 1 /\ shift.val = 2) \/ (z = 2 /\ shift.val = 1)) -> 3 <= z') /\
    (d.decimal_point.val = 0 -> d'.decimal_point.val = 0 ->
      3 <= z -> shift.val = 1 -> 5 <= z') /\
    (d.decimal_point.val = -1 -> d'.decimal_point.val = 0 ->
      7 <= z -> shift.val = 3 -> 5 <= z') /\
    (7 <= z ->
      num.imp.dec2flt.decimal_seq.number_of_digits_decimal_left_shift
        d 3#usize = ok 1#usize) := by
-- BODY
  let xs := (d.digits.val.take d.num_digits.val).map (fun b => b.val)
  let xs' := (d'.digits.val.take d'.num_digits.val).map (fun b => b.val)
  let F := fun ys : List Nat => ys.foldl (fun a b => 10 * a + b) 0
  let V := fun (q : num.imp.dec2flt.decimal_seq.DecimalSeq) =>
    let digits := (q.digits.val.take q.num_digits.val).map (fun b => b.val)
    let integer := F digits
    (integer : Real) * (10 : Real) ^ (q.decimal_point.val - (q.num_digits.val : Int))
  have hxs : xs = z :: zs := by simpa [xs] using hshape
  have hxs' : xs' = z' :: zs' := by simpa [xs'] using hshape'
  have hdigitsF : forall b, b ∈ xs -> b < 10 := by
    intro b hb
    simp only [xs, List.mem_map] at hb
    rcases hb with ⟨q, hq, rfl⟩
    exact hdigits q hq
  have hdigitsF' : forall b, b ∈ xs' -> b < 10 := by
    intro b hb
    simp only [xs', List.mem_map] at hb
    rcases hb with ⟨q, hq, rfl⟩
    exact hdigits' q hq
  have foldFrom (ys : List Nat) (a : Nat) :
      ys.foldl (fun n b => 10 * n + b) a = a * 10 ^ ys.length + F ys := by
    induction ys generalizing a with
    | nil => simp [F]
    | cons b ys ih =>
      simp only [List.foldl_cons, List.length_cons]
      rw [ih, pow_succ]
      change (10 * a + b) * 10 ^ ys.length + F ys =
        a * (10 ^ ys.length * 10) + (b :: ys).foldl (fun n q => 10 * n + q) 0
      simp only [List.foldl_cons]
      rw [ih]
      ring
  have foldBound (ys : List Nat) (hd : forall b, b ∈ ys -> b < 10) :
      F ys < 10 ^ ys.length := by
    induction ys with
    | nil => simp [F]
    | cons b ys ih =>
      have hb : b < 10 := hd b (by simp)
      have htail : forall q, q ∈ ys -> q < 10 := by
        intro q hq
        exact hd q (by simp [hq])
      have hi := ih htail
      rw [show F (b :: ys) = b * 10 ^ ys.length + F ys by
        simpa [F] using foldFrom ys b, List.length_cons, pow_succ]
      have hm : b * 10 ^ ys.length <= 9 * 10 ^ ys.length :=
        Nat.mul_le_mul_right _ (by omega)
      calc
        b * 10 ^ ys.length + F ys < b * 10 ^ ys.length + 10 ^ ys.length :=
          Nat.add_lt_add_left hi _
        _ <= 9 * 10 ^ ys.length + 10 ^ ys.length := Nat.add_le_add_right hm _
        _ = 10 ^ (ys.length + 1) := by rw [pow_succ]; ring
  have htail : F zs < 10 ^ zs.length := by
    apply foldBound
    intro b hb
    have hb' : b ∈ xs := by simpa [hxs] using (Or.inr hb)
    exact hdigitsF b hb'
  have htail' : F zs' < 10 ^ zs'.length := by
    apply foldBound
    intro b hb
    have hb' : b ∈ xs' := by simpa [hxs'] using (Or.inr hb)
    exact hdigitsF' b hb'
  have hfold : F xs = z * 10 ^ zs.length + F zs := by
    rw [hxs]
    simpa [F] using foldFrom zs z
  have hfold' : F xs' = z' * 10 ^ zs'.length + F zs' := by
    rw [hxs']
    simpa [F] using foldFrom zs' z'
  have hlenN : d.num_digits.val = zs.length + 1 := by
    have := hlen
    simp only [List.length_cons] at this
    omega
  have hlenN' : d'.num_digits.val = zs'.length + 1 := by
    have := hlen'
    simp only [List.length_cons] at this
    omega
  have hVd : V d = (F xs : Real) * (10 : Real) ^
      (d.decimal_point.val - (d.num_digits.val : Int)) := by rfl
  have hVd' : V d' = (F xs' : Real) * (10 : Real) ^
      (d'.decimal_point.val - (d'.num_digits.val : Int)) := by rfl
  have hpos : 0 < V d := by
    rw [hVd, hfold]
    have : 0 < (10 : Real) ^ zs.length := by positivity
    have : 0 < (z : Real) * (10 : Real) ^ zs.length + (F zs : Real) := by
      have hzR : (0 : Real) < z := by exact_mod_cast hz
      positivity
    have hp : 0 < (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) :=
      zpow_pos (by norm_num) _
    positivity
  obtain ⟨rho, hrho0, hrho, hrecord, _⟩ :=
    DecimalSeqLeftShiftRecordSemantics d d' shift hshift hpos hdigits hcall
  have hVrel : V d' = (2 : Real) ^ shift.val * V d - rho := by
    simpa [V] using hrecord
  have hpowd : (10 : Real) ^ (d.decimal_point.val - 1) =
      (10 : Real) ^ (zs.length : Int) *
        (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) := by
    rw [← zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
    congr 1
    rw [hlenN]
    push_cast
    omega
  have hpowd' : (10 : Real) ^ (d'.decimal_point.val - 1) =
      (10 : Real) ^ (zs'.length : Int) *
        (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) := by
    rw [← zpow_add₀ (by norm_num : (10 : Real) ≠ 0)]
    congr 1
    rw [hlenN']
    push_cast
    omega
  have hposBounds : (z : Real) * (10 : Real) ^ (d.decimal_point.val - 1) <= V d ∧
      V d < ((z + 1 : Nat) : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
    have hp : 0 < (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) :=
      zpow_pos (by norm_num) _
    have hnatlo : z * 10 ^ zs.length <= z * 10 ^ zs.length + F zs := by omega
    have hnathi : z * 10 ^ zs.length + F zs < (z + 1) * 10 ^ zs.length := by
      calc
        z * 10 ^ zs.length + F zs < z * 10 ^ zs.length + 10 ^ zs.length :=
          Nat.add_lt_add_left htail _
        _ = (z + 1) * 10 ^ zs.length := by ring
    have hloR : (z : Real) * (10 : Real) ^ zs.length <=
        ((z * 10 ^ zs.length + F zs : Nat) : Real) := by exact_mod_cast hnatlo
    have hhiR : ((z * 10 ^ zs.length + F zs : Nat) : Real) <
        (((z + 1) * 10 ^ zs.length : Nat) : Real) := by exact_mod_cast hnathi
    constructor
    · calc
        (z : Real) * (10 : Real) ^ (d.decimal_point.val - 1) =
            ((z : Real) * (10 : Real) ^ zs.length) *
              (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) := by
                rw [hpowd, ← zpow_natCast (10 : Real) zs.length]; ring
        _ <= ((z * 10 ^ zs.length + F zs : Nat) : Real) *
              (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) :=
                mul_le_mul_of_nonneg_right hloR (le_of_lt hp)
        _ = V d := by rw [hVd, hfold]
    · calc
        V d = ((z * 10 ^ zs.length + F zs : Nat) : Real) *
            (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) := by
              rw [hVd, hfold]
        _ < (((z + 1) * 10 ^ zs.length : Nat) : Real) *
              (10 : Real) ^ (d.decimal_point.val - (d.num_digits.val : Int)) :=
                mul_lt_mul_of_pos_right hhiR hp
        _ = ((z + 1 : Nat) : Real) * (10 : Real) ^ (d.decimal_point.val - 1) := by
              rw [hpowd]
              have hc : (((z + 1) * 10 ^ zs.length : Nat) : Real) =
                  ((z + 1 : Nat) : Real) * (10 : Real) ^ zs.length := by
                norm_cast
              rw [hc]
              rw [← zpow_natCast (10 : Real) zs.length]
              ring
  have hposBounds' : (z' : Real) * (10 : Real) ^ (d'.decimal_point.val - 1) <= V d' ∧
      V d' < ((z' + 1 : Nat) : Real) * (10 : Real) ^ (d'.decimal_point.val - 1) := by
    have hp : 0 < (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) :=
      zpow_pos (by norm_num) _
    have hnatlo : z' * 10 ^ zs'.length <= z' * 10 ^ zs'.length + F zs' := by omega
    have hnathi : z' * 10 ^ zs'.length + F zs' < (z' + 1) * 10 ^ zs'.length := by
      calc
        z' * 10 ^ zs'.length + F zs' < z' * 10 ^ zs'.length + 10 ^ zs'.length :=
          Nat.add_lt_add_left htail' _
        _ = (z' + 1) * 10 ^ zs'.length := by ring
    have hloR : (z' : Real) * (10 : Real) ^ zs'.length <=
        ((z' * 10 ^ zs'.length + F zs' : Nat) : Real) := by exact_mod_cast hnatlo
    have hhiR : ((z' * 10 ^ zs'.length + F zs' : Nat) : Real) <
        (((z' + 1) * 10 ^ zs'.length : Nat) : Real) := by exact_mod_cast hnathi
    constructor
    · calc
        (z' : Real) * (10 : Real) ^ (d'.decimal_point.val - 1) =
            ((z' : Real) * (10 : Real) ^ zs'.length) *
              (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) := by
                rw [hpowd', ← zpow_natCast (10 : Real) zs'.length]; ring
        _ <= ((z' * 10 ^ zs'.length + F zs' : Nat) : Real) *
              (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) :=
                mul_le_mul_of_nonneg_right hloR (le_of_lt hp)
        _ = V d' := by rw [hVd', hfold']
    · calc
        V d' = ((z' * 10 ^ zs'.length + F zs' : Nat) : Real) *
            (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) := by
              rw [hVd', hfold']
        _ < (((z' + 1) * 10 ^ zs'.length : Nat) : Real) *
              (10 : Real) ^ (d'.decimal_point.val - (d'.num_digits.val : Int)) :=
                mul_lt_mul_of_pos_right hhiR hp
        _ = ((z' + 1 : Nat) : Real) * (10 : Real) ^ (d'.decimal_point.val - 1) := by
              rw [hpowd']
              have hc : (((z' + 1) * 10 ^ zs'.length : Nat) : Real) =
                  ((z' + 1 : Nat) : Real) * (10 : Real) ^ zs'.length := by
                norm_cast
              rw [hc]
              rw [← zpow_natCast (10 : Real) zs'.length]
              ring
  refine ⟨?_, ?_, ?_, ?_, ?_⟩
  · intro hp hp' hk
    have hlow := hposBounds.1
    rw [hp] at hlow
    have hrel := hVrel
    rw [hk] at hrel
    norm_num at hlow hrel
    have hloss : rho < (1 : Real) / 100 := by
      rw [hp'] at hrho
      have hpow : (10 : Real) ^ (-769 : Int) < (1 : Real) / 100 := by
        calc
          (10 : Real) ^ (-769 : Int) < (10 : Real) ^ (-2 : Int) :=
            zpow_lt_zpow_right₀ (by norm_num) (by omega)
          _ = (1 : Real) / 100 := by norm_num
      exact lt_trans hrho hpow
    have hzR : (1 : Real) <= z := by exact_mod_cast hz
    have hlarge : (7 : Real) / 100 < V d' := by nlinarith
    by_contra hn
    have hzup : z' <= 6 := by omega
    have hupper := hposBounds'.2
    rw [hp'] at hupper
    norm_num at hupper
    have hzupR : (z' : Real) <= 6 := by exact_mod_cast hzup
    have hupperSmall : V d' < (7 : Real) / 100 := by
      nlinarith only [hupper, hzupR]
    linarith only [hlarge, hupperSmall]
  · intro hp hp' hcases
    rcases hcases with ⟨hzcase, hk⟩ | ⟨hzcase, hk⟩
    · have hlow := hposBounds.1
      rw [hp] at hlow
      rw [hzcase] at hlow
      norm_num at hlow
      have hrel := hVrel
      rw [hk] at hrel
      norm_num at hrel
      have hloss : rho < (1 : Real) / 10 := by
        rw [hp'] at hrho
        have hpow : (10 : Real) ^ (-768 : Int) < (1 : Real) / 10 := by
          calc
            (10 : Real) ^ (-768 : Int) < (10 : Real) ^ (-1 : Int) :=
              zpow_lt_zpow_right₀ (by norm_num) (by omega)
            _ = (1 : Real) / 10 := by norm_num
        exact lt_trans hrho hpow
      have hlarge : (3 : Real) / 10 < V d' := by nlinarith
      by_contra hn
      have hzup : z' <= 2 := by omega
      have hupper := hposBounds'.2
      rw [hp'] at hupper
      norm_num at hupper
      have hzupR : (z' : Real) <= 2 := by exact_mod_cast hzup
      have hupperSmall : V d' < (3 : Real) / 10 := by
        nlinarith only [hupper, hzupR]
      linarith only [hlarge, hupperSmall]
    · have hlow := hposBounds.1
      rw [hp] at hlow
      rw [hzcase] at hlow
      norm_num at hlow
      have hrel := hVrel
      rw [hk] at hrel
      norm_num at hrel
      have hloss : rho < (1 : Real) / 10 := by
        rw [hp'] at hrho
        have hpow : (10 : Real) ^ (-768 : Int) < (1 : Real) / 10 := by
          calc
            (10 : Real) ^ (-768 : Int) < (10 : Real) ^ (-1 : Int) :=
              zpow_lt_zpow_right₀ (by norm_num) (by omega)
            _ = (1 : Real) / 10 := by norm_num
        exact lt_trans hrho hpow
      have hlarge : (3 : Real) / 10 < V d' := by nlinarith
      by_contra hn
      have hzup : z' <= 2 := by omega
      have hupper := hposBounds'.2
      rw [hp'] at hupper
      norm_num at hupper
      have hzupR : (z' : Real) <= 2 := by exact_mod_cast hzup
      have hupperSmall : V d' < (3 : Real) / 10 := by
        nlinarith only [hupper, hzupR]
      linarith only [hlarge, hupperSmall]
  · intro hp hp' hzlo hk
    have hlow := hposBounds.1
    rw [hp] at hlow
    norm_num at hlow
    have hrel := hVrel
    rw [hk] at hrel
    norm_num at hrel
    have hloss : rho < (1 : Real) / 10 := by
      rw [hp'] at hrho
      have hpow : (10 : Real) ^ (-768 : Int) < (1 : Real) / 10 := by
        calc
          (10 : Real) ^ (-768 : Int) < (10 : Real) ^ (-1 : Int) :=
            zpow_lt_zpow_right₀ (by norm_num) (by omega)
          _ = (1 : Real) / 10 := by norm_num
      exact lt_trans hrho hpow
    have hzloR : (3 : Real) <= z := by exact_mod_cast hzlo
    have hlarge : (1 : Real) / 2 < V d' := by nlinarith
    by_contra hn
    have hzup : z' <= 4 := by omega
    have hupper := hposBounds'.2
    rw [hp'] at hupper
    norm_num at hupper
    have hzupR : (z' : Real) <= 4 := by exact_mod_cast hzup
    have hupperSmall : V d' < (1 : Real) / 2 := by
      nlinarith only [hupper, hzupR]
    linarith only [hlarge, hupperSmall]
  · intro hp hp' hzlo hk
    have hlow := hposBounds.1
    rw [hp] at hlow
    norm_num at hlow
    have hrel := hVrel
    rw [hk] at hrel
    norm_num at hrel
    have hloss : rho < (1 : Real) / 100 := by
      rw [hp'] at hrho
      have hpow : (10 : Real) ^ (-768 : Int) < (1 : Real) / 100 := by
        calc
          (10 : Real) ^ (-768 : Int) < (10 : Real) ^ (-2 : Int) :=
            zpow_lt_zpow_right₀ (by norm_num) (by omega)
          _ = (1 : Real) / 100 := by norm_num
      exact lt_trans hrho hpow
    have hzloR : (7 : Real) <= z := by exact_mod_cast hzlo
    have hlarge : (11 : Real) / 20 < V d' := by nlinarith
    by_contra hn
    have hzup : z' <= 4 := by omega
    have hupper := hposBounds'.2
    rw [hp'] at hupper
    norm_num at hupper
    have hzupR : (z' : Real) <= 4 := by exact_mod_cast hzup
    have hupperSmall : V d' < (1 : Real) / 2 := by
      nlinarith only [hupper, hzupR]
    linarith only [hlarge, hupperSmall]
  · intro hzlo
    have hI : 10 ^ d.num_digits.val <= 8 * F xs := by
      rw [hlenN, hfold]
      have hp : 0 < 10 ^ zs.length := by positivity
      have hmul : 7 * 10 ^ zs.length <= z * 10 ^ zs.length :=
        Nat.mul_le_mul_right _ (by omega)
      have hbase : 10 * 10 ^ zs.length <=
          8 * (z * 10 ^ zs.length + F zs) := by
        omega
      simpa [pow_succ, Nat.mul_comm] using hbase
    have hgrowth := DecimalLeftShiftDigitGrowth d (3#usize) 1
      (by norm_num) (by norm_num) (by norm_num) hcap hdigits
    rcases hgrowth with ⟨out, hout, houtval⟩
    have houtval' : out.val =
        if 10 ^ d.num_digits.val <= F xs * 2 ^ (3 : Nat) then 1 else 0 := by
      simpa [xs, F] using houtval
    have hthreshold : 10 ^ d.num_digits.val <= F xs * 2 ^ (3 : Nat) := by
      norm_num at hI ⊢
      omega
    rw [if_pos hthreshold] at houtval'
    have houtEq : out = 1#usize := UScalar.eq_of_val_eq (by simpa using houtval')
    simpa [houtEq] using hout

end dec2flt_model

Proof structure

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

Explore this dependency tree

Inspect related source (117)
More program dependencies (84)
Standard-library dependencies (30)

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 17 entries
Technical checking records
Local closure summary
{
  "node": "P529_T1_LeftLeadingProgress",
  "closure_version": "patch_c_v1",
  "active_decl_hash": "ec026ed1597b02baa7c0449a68af1777601266d4e9e739e920bc4aadb2fb4e25",
  "active_statement_hash": "d79e4a959b1fe281600fbfef0e333caf005d97138a291a2ca73db9abc005b6bd",
  "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-181",
  "boundary_theorems": {},
  "strict_theorem_deps": {
    "DecimalLeftShiftDigitGrowth": "6dcf8858df4713eb",
    "DecimalSeqLeftShiftRecordSemantics": "abe9f51b6cd0693a"
  },
  "strict_definition_deps": {
    "num_imp_dec2flt_decimal_seq_DecimalSeq": "b0286c42454b158d",
    "num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift": "fd298e37d5ae4f86",
    "num_imp_dec2flt_decimal_seq_number_of_digits_decimal_left_shift": "b3efbd0e6b3fe061"
  }
}
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:0cc48f200f429a3aec6c1dfb61876d1a2f0a1530f5e217f7966da60e30b3b2ef",
  "superseded_for_theorem_closure": false
}
Review verdicts
{
  "corr_status": "Pass",
  "substantiveness_status": "Pass"
}