The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V34. The tactics of Mathlib

Mathlib.Tactic.Inclusion.Extension.IntervalDyadicReal.Log

31 declarations. Mathlib docs · Source

Real.log extension for tactic dyadic_interval

This file implements Real.log extension for the tactic dyadic_interval.

Implementation notes

We first define Inclusion.IntervalDyadicReal.smallArtanh, which computes artanh of a small rational number num / den using the binary splitting method. Then we use the identity log 2 = 6 * artanh (1 / 17) + 4 * artanh (1 / 19) + 4 * artanh (1 / 31) to obtain a dyadic approximation of log 2.

With these, log x is computed for arbitrary x by first bringing |x| into the interval [1, 2) (writing x = x' * 2 ^ k with |x'| ∈ [1, 2)) and then adding k * log 2; this keeps the argument of the series small, so that it converges quickly.

We use artanh rather than log itself because all the terms of its series are positive (for a positive argument). Hence every truncated partial sum is a lower bound, and an upper bound is obtained by adding a step prec.

References

theorem Inclusion.IntervalDyadicReal.logSum.fun_cases_unfolding E1 #

∀ (m prec : ℕ) (motive : Dyadic → Prop),
  (have e := m.log2;
    ∀ (P3 Q3 : ℕ),
      Inclusion.IntervalDyadicReal.smallArtanh (m - 2 ^ e) (m + 2 ^ e) (prec / 3 + 1) = (P3, Q3) →
        motive (2 * Inclusion.IntervalDyadicReal.natDivLower P3 Q3 (prec + 2))) →
    motive (Inclusion.IntervalDyadicReal.logSum m prec)

theorem Inclusion.IntervalDyadicReal.smallArtanh.go.match_1.congr_eq_1 E1 #

∀ (motive : ℕ × ℕ × ℕ → Sort u_1) (x : ℕ × ℕ × ℕ) (h_1 : (Pr Qr Rr : ℕ) → motive (Pr, Qr, Rr)) (Pr Qr Rr : ℕ),
  x = (Pr, Qr, Rr) →
    (match x with
      | (Pr, Qr, Rr) => h_1 Pr Qr Rr) ≍
      h_1 Pr Qr Rr

theorem Inclusion.IntervalDyadicReal.lowerLog.match_1.congr_eq_2 E1 #

∀ (motive : Dyadic → Sort u_1) (x : Dyadic) (h_1 : Unit → motive Dyadic.zero)
  (h_2 : (n p : ℤ) → (hn : n % 2 = 1) → motive (Dyadic.ofOdd n p hn)) (n p : ℤ) (hn : n % 2 = 1),
  x = Dyadic.ofOdd n p hn →
    (match x with
      | Dyadic.zero => h_1 ()
      | Dyadic.ofOdd n p hn => h_2 n p hn) ≍
      h_2 n p hn

theorem Inclusion.IntervalDyadicReal.smallArtanh.go.induct_unfolding E1 #

∀ (num den : ℕ) (motive : ℕ → ℕ → ℕ × ℕ × ℕ → Prop),
  (∀ (a a_1 : ℕ), a_1 - a = 0 → motive a a_1 (1, 1, 0)) →
    (∀ (a a_1 : ℕ), a_1 - a = 1 → motive a a_1 ((2 * a + 1) * num ^ 2, (2 * a + 3) * den ^ 2, (2 * a + 3) * den ^ 2)) →
      (∀ (a a_1 n : ℕ),
          a_1 - a = n.succ.succ →
            have m := (a + a_1) / 2;
            ∀ (Pr Qr Rr : ℕ),
              Inclusion.IntervalDyadicReal.smallArtanh.go num den a m = (Pr, Qr, Rr) →
                ∀ (Pr_1 Qr_1 Rr_1 : ℕ),
                  Inclusion.IntervalDyadicReal.smallArtanh.go num den m a_1 = (Pr_1, Qr_1, Rr_1) →
                    motive a m (Inclusion.IntervalDyadicReal.smallArtanh.go num den a m) →
                      motive m a_1 (Inclusion.IntervalDyadicReal.smallArtanh.go num den m a_1) →
                        motive a a_1 (Pr * Pr_1, Qr * Qr_1, Qr_1 * Rr + Pr * Rr_1)) →
        ∀ (a a_1 : ℕ), motive a a_1 (Inclusion.IntervalDyadicReal.smallArtanh.go num den a a_1)

theorem Inclusion.IntervalDyadicReal.logTwo.match_1.congr_eq_1 E1 #

∀ (motive : ℕ × ℕ → Sort u_1) (x : ℕ × ℕ) (h_1 : (P3 Q3 : ℕ) → motive (P3, Q3)) (P3 Q3 : ℕ),
  x = (P3, Q3) →
    (match x with
      | (P3, Q3) => h_1 P3 Q3) ≍
      h_1 P3 Q3

theorem Inclusion.IntervalDyadicReal.lowerLog.match_1.congr_eq_1 E1 #

∀ (motive : Dyadic → Sort u_1) (x : Dyadic) (h_1 : Unit → motive Dyadic.zero)
  (h_2 : (n p : ℤ) → (hn : n % 2 = 1) → motive (Dyadic.ofOdd n p hn)),
  x = Dyadic.zero →
    (match x with
      | Dyadic.zero => h_1 ()
      | Dyadic.ofOdd n p hn => h_2 n p hn) ≍
      h_1 ()

theorem Inclusion.IntervalDyadicReal.log.match_1.congr_eq_1 E1 #

∀ (motive : Inclusion.Interval Dyadic → Sort u_1) (x : Inclusion.Interval Dyadic)
  (h_1 : (l u : Dyadic) → motive { lb := some l, ub := some u })
  (h_2 : (l : Dyadic) → motive { lb := some l, ub := none })
  (h_3 : (ub : WithTop Dyadic) → motive { lb := none, ub := ub }) (l u : Dyadic),
  x = { lb := some l, ub := some u } →
    (match x with
      | { lb := some l, ub := some u } => h_1 l u
      | { lb := some l, ub := none } => h_2 l
      | { lb := none, ub := ub } => h_3 ub) ≍
      h_1 l u

theorem Inclusion.IntervalDyadicReal.smallArtanh.go.match_3.congr_eq_1 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : x = 0 → motive 0) (h_2 : x = 1 → motive 1)
  (h_3 : (n : ℕ) → x = n.succ.succ → motive n.succ.succ) (heq_1 : x = 0),
  (match h : x with
    | 0 => h_1 h
    | 1 => h_2 h
    | n.succ.succ => h_3 n h) ≍
    h_1 heq_1

theorem Inclusion.IntervalDyadicReal.log.match_1.congr_eq_3 E1 #

∀ (motive : Inclusion.Interval Dyadic → Sort u_1) (x : Inclusion.Interval Dyadic)
  (h_1 : (l u : Dyadic) → motive { lb := some l, ub := some u })
  (h_2 : (l : Dyadic) → motive { lb := some l, ub := none })
  (h_3 : (ub : WithTop Dyadic) → motive { lb := none, ub := ub }) (ub : WithTop Dyadic),
  x = { lb := none, ub := ub } →
    (match x with
      | { lb := some l, ub := some u } => h_1 l u
      | { lb := some l, ub := none } => h_2 l
      | { lb := none, ub := ub } => h_3 ub) ≍
      h_3 ub

theorem Inclusion.IntervalDyadicReal.log.match_1.congr_eq_2 E1 #

∀ (motive : Inclusion.Interval Dyadic → Sort u_1) (x : Inclusion.Interval Dyadic)
  (h_1 : (l u : Dyadic) → motive { lb := some l, ub := some u })
  (h_2 : (l : Dyadic) → motive { lb := some l, ub := none })
  (h_3 : (ub : WithTop Dyadic) → motive { lb := none, ub := ub }) (l : Dyadic),
  x = { lb := some l, ub := none } →
    (match x with
      | { lb := some l, ub := some u } => h_1 l u
      | { lb := some l, ub := none } => h_2 l
      | { lb := none, ub := ub } => h_3 ub) ≍
      h_2 l

theorem Inclusion.IntervalDyadicReal.lowerLog.fun_cases_unfolding E1 #

∀ (prec : ℕ) (motive : Dyadic → Dyadic → Prop),
  motive Dyadic.zero 0 →
    (∀ (n p : ℤ) (hn : n % 2 = 1),
        have m := n.natAbs;
        have k := ↑m.log2 - p;
        have wp := prec + k.natAbs.log2 + 2;
        have l2 :=
          if 0 ≤ k then Inclusion.IntervalDyadicReal.logTwo wp
          else Inclusion.IntervalDyadicReal.logTwo wp + Inclusion.IntervalDyadicReal.Dyadic.step ↑wp;
        motive (Dyadic.ofOdd n p hn) (Inclusion.IntervalDyadicReal.logSum m (prec + 1) + ↑k * l2)) →
      ∀ (x : Dyadic), motive x (Inclusion.IntervalDyadicReal.lowerLog x prec)

theorem Inclusion.IntervalDyadicReal.smallArtanh.go.match_3.congr_eq_2 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : x = 0 → motive 0) (h_2 : x = 1 → motive 1)
  (h_3 : (n : ℕ) → x = n.succ.succ → motive n.succ.succ) (heq_1 : x = 1),
  (match h : x with
    | 0 => h_1 h
    | 1 => h_2 h
    | n.succ.succ => h_3 n h) ≍
    h_2 heq_1

theorem Inclusion.IntervalDyadicReal.log.fun_cases_unfolding E1 #

∀ (I : Inclusion.Interval Dyadic) (prec : ℕ) (motive : Inclusion.Interval Dyadic → Prop),
  (I.abs = { lb := some 0, ub := some 0 } → motive (Inclusion.Interval.singleton 0)) →
    (∀ (u : Dyadic),
        ¬u = 0 →
          I.abs = { lb := some 0, ub := some u } →
            motive
              ((Inclusion.Interval.singleton 0).hull
                (Inclusion.Interval.Iic (Inclusion.IntervalDyadicReal.logPoint u prec).ub))) →
      (∀ (l u : Dyadic),
          I.abs = { lb := some l, ub := some u } →
            ¬l = 0 →
              motive
                (Inclusion.Interval.Icc (Inclusion.IntervalDyadicReal.logPoint l prec).lb
                  (Inclusion.IntervalDyadicReal.logPoint u prec).ub)) →
        (I.abs = { lb := some 0, ub := none } → motive (Inclusion.Interval.univ Dyadic)) →
          (∀ (l : Dyadic),
              I.abs = { lb := some l, ub := none } →
                ¬l = 0 → motive (Inclusion.Interval.Ici (Inclusion.IntervalDyadicReal.logPoint l prec).lb)) →
            (∀ (ub : WithTop Dyadic), I.abs = { lb := none, ub := ub } → motive (Inclusion.Interval.univ Dyadic)) →
              motive (Inclusion.IntervalDyadicReal.log I prec)

theorem Inclusion.IntervalDyadicReal.smallArtanh.go.match_3.congr_eq_3 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : x = 0 → motive 0) (h_2 : x = 1 → motive 1)
  (h_3 : (n : ℕ) → x = n.succ.succ → motive n.succ.succ) (n : ℕ) (heq_1 : x = n.succ.succ),
  (match h : x with
    | 0 => h_1 h
    | 1 => h_2 h
    | n.succ.succ => h_3 n h) ≍
    h_3 n heq_1

def Inclusion.IntervalDyadicReal.smallArtanh E1 #

ℕ → ℕ → ℕ → ℕ × ℕ

The n-th partial sum of the artanh series at num / den, returned as (P, Q) with P / Q equal to this sum. Note that the series converges slowly when the input is close to 1.

def Inclusion.IntervalDyadicReal.smallArtanh.go E1 #

ℕ → ℕ → ℕ → ℕ → ℕ × ℕ × ℕ

Binary splitting auxiliary function: go a b returns (P, Q, R) on segment [a, b).

R is the numerator of ∑ k ∈ Finset.Ico a b, ∏ j ∈ Finset.Ico a k, t (j + 1) / t j put over the common denominator of the term ratios ((2 * k + 1) * num ^ 2) / ((2 * k + 3) * den ^ 2).

theorem Inclusion.IntervalDyadicReal.smallArtanh.go_spec E1 #

∀ (num den a b : ℕ),
  (Inclusion.IntervalDyadicReal.smallArtanh.go num den a b).1 = ∏ i ∈ Finset.Ico a b, (2 * i + 1) * num ^ 2 ∧
    (Inclusion.IntervalDyadicReal.smallArtanh.go num den a b).2.1 = ∏ i ∈ Finset.Ico a b, (2 * i + 3) * den ^ 2 ∧
      (Inclusion.IntervalDyadicReal.smallArtanh.go num den a b).2.2 =
        ∑ i ∈ Finset.Ico a b,
          (∏ j ∈ Finset.Ico a i, (2 * j + 1) * num ^ 2) * ∏ j ∈ Finset.Ico i b, (2 * j + 3) * den ^ 2

theorem Inclusion.IntervalDyadicReal.smallArtanh.den_ne_zero E1 #

∀ (num den n : ℕ), den ≠ 0 → (Inclusion.IntervalDyadicReal.smallArtanh num den n).2 ≠ 0

theorem Inclusion.IntervalDyadicReal.smallArtanh.spec E1 #

∀ (num den n : ℕ),
  ↑(Inclusion.IntervalDyadicReal.smallArtanh num den n).1 / ↑(Inclusion.IntervalDyadicReal.smallArtanh num den n).2 =
    ∑ k ∈ Finset.range n, (↑num / ↑den) ^ (2 * k + 1) / (2 * ↑k + 1)

theorem Inclusion.IntervalDyadicReal.smallArtanh.div_le_artanh E1 #

∀ {num den : ℕ},
  num < den →
    ∀ (n : ℕ),
      ↑(Inclusion.IntervalDyadicReal.smallArtanh num den n).1 /
          ↑(Inclusion.IntervalDyadicReal.smallArtanh num den n).2 ≤
        Real.artanh (↑num / ↑den)

The partial sums computed by smallArtanh are lower bounds for artanh (num / den).

theorem Inclusion.IntervalDyadicReal.smallArtanh.artanh_le_div_add E1 #

∀ {num den : ℕ},
  num < den →
    ∀ (n : ℕ),
      Real.artanh (↑num / ↑den) ≤
        ↑(Inclusion.IntervalDyadicReal.smallArtanh num den n).1 /
            ↑(Inclusion.IntervalDyadicReal.smallArtanh num den n).2 +
          (↑num / ↑den) ^ (2 * n + 1) / (1 - (↑num / ↑den) ^ 2)

An upper bound for artanh (num / den) in terms of the partial sums computed by smallArtanh.

def Inclusion.IntervalDyadicReal.logTwo E1 #

ℕ → Dyadic

Computes a lower bound l : Dyadic for log 2 with precision prec.

theorem Inclusion.IntervalDyadicReal.logTwo_spec E1 #

∀ (prec : ℕ),
  ↑↑(Inclusion.IntervalDyadicReal.logTwo prec) ≤ Real.log 2 ∧
    Real.log 2 ≤ ↑↑(Inclusion.IntervalDyadicReal.logTwo prec) + ↑↑(Inclusion.IntervalDyadicReal.Dyadic.step ↑prec)

def Inclusion.IntervalDyadicReal.logSum E1 #

ℕ → ℕ → Dyadic

Computes a lower bound l : Dyadic for log (m / 2 ^ m.log2) with precision prec. Note that m / 2 ^ m.log2 ∈ [1, 2) when m ≠ 0.

theorem Inclusion.IntervalDyadicReal.logSum_spec E1 #

∀ {m : ℕ},
  m ≠ 0 →
    ∀ (prec : ℕ),
      ↑↑(Inclusion.IntervalDyadicReal.logSum m prec) ≤ Real.log (↑m / 2 ^ m.log2) ∧
        Real.log (↑m / 2 ^ m.log2) ≤
          ↑↑(Inclusion.IntervalDyadicReal.logSum m prec) + ↑↑(Inclusion.IntervalDyadicReal.Dyadic.step ↑prec)

def Inclusion.IntervalDyadicReal.lowerLog E1 #

Dyadic → ℕ → Dyadic

Computes a lower bound for log x with precision prec.

theorem Inclusion.IntervalDyadicReal.lowerLog_spec E1 #

∀ (x : Dyadic) (prec : ℕ),
  ↑↑(Inclusion.IntervalDyadicReal.lowerLog x prec) ≤ Real.log ↑↑x ∧
    Real.log ↑↑x ≤ ↑↑(Inclusion.IntervalDyadicReal.lowerLog x prec) + ↑↑(Inclusion.IntervalDyadicReal.Dyadic.step ↑prec)

def Inclusion.IntervalDyadicReal.logPoint E1 #

Dyadic → ℕ → Inclusion.Interval Dyadic

An enclosure of log x of width step prec, which is exact when log x = 0.

theorem Inclusion.IntervalDyadicReal.logPoint_mem E1 #

∀ (x : Dyadic) (prec : ℕ),
  Real.log (Inclusion.IntervalDyadicReal.Dyadic.toReal x) ∈ Inclusion.IntervalDyadicReal.logPoint x prec

def Inclusion.IntervalDyadicReal.log E1 #

Inclusion.Interval Dyadic → ℕ → Inclusion.Interval Dyadic

Logarithm of an Interval Dyadic, computed from the enclosures logPoint at the endpoints of its absolute value. When 0 lies in the interval, the result must also contain log 0 = 0.

theorem Inclusion.IntervalDyadicReal.log_mem E1 #

∀ {x : ℝ} {I : Inclusion.Interval Dyadic} (prec : ℕ), x ∈ I → Real.log x ∈ Inclusion.IntervalDyadicReal.log I prec