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.Exp

16 declarations. Mathlib docs · Source

Exponential enclosures for interval_dyadic_real

This file defines an inclusion operation for the interval_dyadic_real inclusion family that encloses Real.exp of an interval.

Implementation notes

The exp of the endpoints is constructed by evaluating the Taylor partial sum up to the required precision level. The exponent is rewritten as exp x = exp (x / m) ^ m, where m is an integer chosen so that |x / m| < 1 / 2. The exponent is divided further by 2 ^ k (with k growing as √prec) so that the Taylor series converges faster, and k squarings with outward rounding undo that division.

This file is opt-in so that dyadic_interval doesn't import unnecessary theories.

TODO

For larger exponents, we would eventually want to implement another optimisation that shifts the exp exponent by multiples of log 2 (which only shifts the exponent of the dyadic result). This requires a certified computation of log 2 to arbitrary precision, which is available as Inclusion.IntervalDyadicReal.logTwo (with bounds Inclusion.IntervalDyadicReal.logTwo_spec).

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

∀ (motive : ℕ → Sort u_1) (n : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ),
  n = 0 →
    (match n with
      | 0 => h_1 ()
      | n.succ => h_2 n) ≍
      h_1 ()

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

∀ (motive : WithBot Dyadic → Sort u_1) (x : WithBot Dyadic) (h_1 : (l : Dyadic) → motive (some l))
  (h_2 : Unit → motive none),
  x = none →
    (match x with
      | some l => h_1 l
      | none => h_2 ()) ≍
      h_2 ()

theorem Inclusion.IntervalDyadicReal.exp.match_3.congr_eq_1 E1 #

∀ (motive : WithTop Dyadic → Sort u_1) (x : WithTop Dyadic) (h_1 : (u : Dyadic) → motive (some u))
  (h_2 : Unit → motive none) (u : Dyadic),
  x = some u →
    (match x with
      | some u => h_1 u
      | none => h_2 ()) ≍
      h_1 u

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

∀ (motive : WithBot Dyadic → Sort u_1) (x : WithBot Dyadic) (h_1 : (l : Dyadic) → motive (some l))
  (h_2 : Unit → motive none) (l : Dyadic),
  x = some l →
    (match x with
      | some l => h_1 l
      | none => h_2 ()) ≍
      h_1 l

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

∀ (motive : ℕ → Sort u_1) (n : ℕ) (h_1 : Unit → motive 0) (h_2 : (n : ℕ) → motive n.succ) (n_1 : ℕ),
  n = n_1.succ →
    (match n with
      | 0 => h_1 ()
      | n.succ => h_2 n) ≍
      h_2 n_1

theorem Inclusion.IntervalDyadicReal.exp.match_3.congr_eq_2 E1 #

∀ (motive : WithTop Dyadic → Sort u_1) (x : WithTop Dyadic) (h_1 : (u : Dyadic) → motive (some u))
  (h_2 : Unit → motive none),
  x = none →
    (match x with
      | some u => h_1 u
      | none => h_2 ()) ≍
      h_2 ()

def Inclusion.IntervalDyadicReal.expPartialSumNum E1 #

ℤ → ℕ → ℕ → ℤ

The numerator of the partial Taylor sum ∑ m ∈ range n, (a / b) ^ m / m! as an unreduced fraction over the common denominator b ^ n * n!.

theorem Inclusion.IntervalDyadicReal.expPartialSumNum_div E1 #

∀ (a : ℤ) {b : ℕ},
  b ≠ 0 →
    ∀ (n : ℕ),
      ↑(Inclusion.IntervalDyadicReal.expPartialSumNum a b n) / (↑b ^ n * ↑n.factorial) =
        ∑ m ∈ Finset.range n, (↑a / ↑b) ^ m / ↑m.factorial

def Inclusion.IntervalDyadicReal.expRatTaylor E1 #

ℤ → ℕ → ℕ → ℕ → Inclusion.Interval Dyadic

An enclosure of exp (a / b) by the first n terms of its Taylor series and the remainder bound of Real.exp_bound, rounded outward to precision prec. This is only intended for use when | a / b | ≤ 1.

theorem Inclusion.IntervalDyadicReal.expRatTaylor_mem E1 #

∀ (a : ℤ) {b : ℕ},
  b ≠ 0 →
    a.natAbs ≤ b →
      ∀ {n : ℕ}, 0 < n → ∀ (prec : ℕ), Real.exp (↑a / ↑b) ∈ Inclusion.IntervalDyadicReal.expRatTaylor a b n prec

def Inclusion.IntervalDyadicReal.squareRoundOut E1 #

ℕ → Inclusion.Interval Dyadic → ℕ → Inclusion.Interval Dyadic

Square I k times, rounding outward to the 2 ^ (-prec) grid after each squaring. Compared with the exact I.pow (2 ^ k), the roundings add an error of less than about 2 ^ (k + 1) * max 1 M ^ (2 ^ k - 1) steps of 2 ^ (-prec), where M is the largest absolute value in I. So the error stays below 2 ^ (-q) when prec is at least about q + k + 1 + (2 ^ k - 1) * log₂ (max 1 M). The roundings keep the endpoints on the 2 ^ (-prec) grid, where I.pow (2 ^ k) would have endpoints with 2 ^ k times as many bits.

theorem Inclusion.IntervalDyadicReal.squareRoundOut_mem E1 #

∀ {x : ℝ} {I : Inclusion.Interval Dyadic},
  x ∈ I → ∀ (k prec : ℕ), x ^ 2 ^ k ∈ Inclusion.IntervalDyadicReal.squareRoundOut k I prec

def Inclusion.IntervalDyadicReal.expPoint E1 #

Dyadic → (prec : ℕ) → optParam ℕ prec.sqrt → Inclusion.Interval Dyadic

An enclosure of exp x by rewriting as (exp (x / N) ^ 2 ^ k) ^ m, where N = m * 2 ^ k, so that |x / N| < 2 ^ (-1 - k) to make the Taylor series converge quickly. The interval is rounded outward after the power to drop the redundant bits for the consumers.

Some relevant precision constants are chosen as follows:

  • m = ⌊2 |x|⌋ + 1 to shrink the exponent below 1/2.
  • k, the number of squarings, is an argument with default ⌊√prec⌋, which balances the cost of the squarings against that of the Taylor terms. powerBits and taylorTerms below are computed from k, so every k gives the same precision and only the cost changes. With k = 0, about prec / 2 terms are needed, and at 4500 bits their recursion exceeds the kernel's default maxRecDepth.
  • precTaylor is the precision of exp (x / N) requested. The powers turn an absolute error δ on exp (x / N) into about N * exp x * δ on exp x (the derivative of the N-th power is N * exp (x / N) ^ (N - 1)). So precTaylor adds three amounts to prec.
    • powerBits is at least ⌈ log₂ N ⌉.
    • sizeBits = ⌊ 1.5x ⌋ + 1 (1.5 > log₂ e) which bounds the number of bits above 1 for exp x.
    • a constant (8 here) so that the powered interval is narrower than 2 ^ (-prec - 1). Rounding it outward to the 2 ^ (-prec - 1) grid then spans at most two grid steps, so the result has width at most 2 ^ (-prec). It also absorbs the roundings in squareRoundOut, which add less than four steps of 2 ^ (-precTaylor) before the amplification.
  • taylorTerms terms bring the Taylor remainder below 2 ^{-precTaylor}. Each term shrinks the remainder by at least 1 + k bits due to the 2 ^ (-1 - k) bound on the exponent, with further shrinking from the factorial. It's sufficient for the number of terms n to satisfy (1 + k) n + log₂ (n!) ≥ precTaylor + 1, and we take a very crude bound here using log₂(n!) ≥ n - 1.

theorem Inclusion.IntervalDyadicReal.expPoint_mem E1 #

∀ (x : Dyadic) (prec : ℕ) {k : ℕ},
  Real.exp (Inclusion.IntervalDyadicReal.Dyadic.toReal x) ∈ Inclusion.IntervalDyadicReal.expPoint x prec k

def Inclusion.IntervalDyadicReal.exp E1 #

Inclusion.Interval Dyadic → ℕ → Inclusion.Interval Dyadic

The exponential of an interval, from the enclosures expPoint at its endpoints.

theorem Inclusion.IntervalDyadicReal.exp_mem E1 #

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