Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit eba4829

Browse files
feat(data/real/pi): Wallis product for pi (#6568)
Co-authored-by: hrmacbeth <25316162+hrmacbeth@users.noreply.github.com>
1 parent c65146d commit eba4829

File tree

2 files changed

+158
-5
lines changed

2 files changed

+158
-5
lines changed

src/analysis/special_functions/integrals.lean

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ import measure_theory.interval_integral
1111
This file contains proofs of the integrals of various simple functions, including `pow`, `exp`,
1212
`inv`/`one_div`, `sin`, `cos`, and `λ x, 1 / (1 + x^2)`.
1313
14+
There are also facts about more complicated integrals:
15+
* `sin x ^ n`: We prove a recursive formula for `sin x ^ (n + 2)` in terms of `sin x ^ n`,
16+
along with explicit product formulas for even and odd `n`.
17+
1418
With these lemmas, many simple integrals can be computed by `simp` or `norm_num`.
1519
1620
This file is still being developed.
1721
-/
1822

19-
open real set interval_integral
23+
open real set interval_integral filter
24+
open_locale real big_operators topological_space
2025
variables {a b : ℝ}
2126

2227
namespace interval_integral
@@ -96,8 +101,6 @@ end
96101
lemma interval_integrable_inv_one_add_sq : interval_integrable (λ x:ℝ, (1 + x^2)⁻¹) μ a b :=
97102
by simpa only [one_div] using interval_integrable_one_div_one_add_sq
98103

99-
end interval_integral
100-
101104
@[simp]
102105
lemma integral_pow (n : ℕ) : ∫ x in a..b, x ^ n = (b^(n+1) - a^(n+1)) / (n + 1) :=
103106
begin
@@ -151,6 +154,69 @@ by simp only [one_div, integral_inv_of_neg ha hb]
151154
lemma integral_sin : ∫ x in a..b, sin x = cos a - cos b :=
152155
by rw integral_deriv_eq_sub' (λ x, -cos x); norm_num [continuous_on_sin]
153156

157+
lemma integral_sin_pow_aux (n : ℕ) : ∫ x in 0..π, sin x ^ (n + 2) =
158+
((n + 1) * ∫ x in 0..π, sin x ^ n) - (n + 1) * ∫ x in 0..π, sin x ^ (n + 2) :=
159+
begin
160+
have hv : ∀ x ∈ interval 0 π, has_deriv_at (-cos) (sin x) x,
161+
{ intros, convert (has_deriv_at_cos x).neg, rw neg_neg },
162+
have hu : ∀ x ∈ interval 0 π, has_deriv_at (λ x, sin x ^ (n + 1)) ((n + 1) * cos x * sin x ^ n) x,
163+
{ intros,
164+
convert (has_deriv_at_pow (n + 1) (sin x)).comp x (has_deriv_at_sin x) using 1,
165+
simp [mul_right_comm], },
166+
calc ∫ (x : ℝ) in 0..π, sin x ^ (n + 2)
167+
= ∫ (x : ℝ) in 0..π, sin x ^ (n + 1) * sin x : by { congr, ext, ring }
168+
... = ∫ (x : ℝ) in 0..π, cos x * (λ (x : ℝ), (↑n + 1) * cos x * sin x ^ n) x : by
169+
{ simp [integral_mul_deriv_eq_deriv_mul hu hv (by continuity : continuous _).continuous_on
170+
(by continuity : continuous _).continuous_on] }
171+
... = (↑n + 1) * ∫ (x : ℝ) in 0..π, cos x ^ 2 * sin x ^ n : by
172+
{ rw ← integral_const_mul, congr, ext, simp only, ring }
173+
... = (↑n + 1) * ∫ (x : ℝ) in 0..π, sin x ^ n - sin x ^ (n + 2) : by
174+
{ simp [integral_const_mul, cos_square', sub_mul, ← pow_add, add_comm] }
175+
... = _ - _ : by { rw [integral_sub, mul_sub],
176+
{ exact ((continuous_pow n).comp continuous_sin).interval_integrable 0 π },
177+
{ exact ((continuous_pow (n + 2)).comp continuous_sin).interval_integrable 0 π } },
178+
end
179+
180+
lemma integral_sin_pow_succ_succ (n : ℕ) :
181+
∫ x in 0..π, sin x ^ (n + 2) = (n + 1) / (n + 2) * ∫ x in 0..π, sin x ^ n :=
182+
begin
183+
have : (n:ℝ) + 20 := by { norm_cast, norm_num },
184+
field_simp,
185+
convert eq_sub_iff_add_eq.mp (integral_sin_pow_aux n),
186+
ring
187+
end
188+
189+
theorem integral_sin_pow_odd (n : ℕ) :
190+
∫ x in 0..π, sin x ^ (2 * n + 1) = 2 * ∏ i in finset.range n, (2 * i + 2) / (2 * i + 3) :=
191+
begin
192+
induction n with k ih,
193+
{ norm_num, },
194+
rw [finset.prod_range_succ, ← mul_assoc, mul_comm (2:ℝ) ((2 * k + 2) / (2 * k + 3)),
195+
mul_assoc, ← ih],
196+
have h₁ : 2 * k.succ + 1 = 2 * k + 1 + 2, { ring },
197+
have h₂ : (2:ℝ) * k + 1 + 1 = 2 * k + 2, { norm_cast, },
198+
have h₃ : (2:ℝ) * k + 1 + 2 = 2 * k + 3, { norm_cast, },
199+
simp [h₁, h₂, h₃, integral_sin_pow_succ_succ (2 * k + 1)]
200+
end
201+
202+
theorem integral_sin_pow_even (n : ℕ) :
203+
∫ x in 0..π, sin x ^ (2 * n) = π * ∏ i in finset.range n, (2 * i + 1) / (2 * i + 2) :=
204+
begin
205+
induction n with k ih,
206+
{ norm_num, },
207+
rw [finset.prod_range_succ, ← mul_assoc, mul_comm π ((2 * k + 1) / (2 * k + 2)), mul_assoc, ← ih],
208+
simp [nat.succ_eq_add_one, mul_add, mul_one, integral_sin_pow_succ_succ _],
209+
end
210+
211+
lemma integral_sin_pow_pos (n : ℕ) : 0 < ∫ x in 0..π, sin x ^ n :=
212+
begin
213+
rcases nat.even_or_odd' n with ⟨k, h, h⟩;
214+
simp only [h, integral_sin_pow_even, integral_sin_pow_odd];
215+
refine mul_pos (by norm_num [pi_pos]) (finset.prod_pos (λ n hn, div_pos _ _));
216+
norm_cast;
217+
linarith
218+
end
219+
154220
@[simp]
155221
lemma integral_cos : ∫ x in a..b, cos x = sin b - sin a :=
156222
by rw integral_deriv_eq_sub'; norm_num [continuous_on_cos]
@@ -168,3 +234,5 @@ end
168234

169235
lemma integral_one_div_one_add_sq : ∫ x : ℝ in a..b, 1 / (1 + x^2) = arctan b - arctan a :=
170236
by simp
237+
238+
end interval_integral

src/data/real/pi.lean

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ Copyright (c) 2019 Floris van Doorn. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Floris van Doorn, Benjamin Davidson
55
-/
6-
import analysis.special_functions.pow
6+
import analysis.special_functions.integrals
77
/-!
88
# Pi
99
1010
This file contains lemmas which establish bounds on or approximations of `real.pi`. Notably, these
1111
include `pi_gt_sqrt_two_add_series` and `pi_lt_sqrt_two_add_series`, which bound `π` using series;
1212
numerical bounds on `π` such as `pi_gt_314`and `pi_lt_315` (more precise versions are given, too);
13-
and `tendsto_sum_pi_div_four`, Leibniz's series for `π`.
13+
and exact (infinite) formulas involving `π`, such as `tendsto_sum_pi_div_four`, Leibniz's
14+
series for `π`, and `tendsto_prod_pi_div_two`, the Wallis product for `π`.
1415
-/
1516

1617
open_locale real
@@ -275,4 +276,88 @@ begin
275276
... = 1 - (u k) + (u k)^(2*(k:ℝ)+1) : by { rw [← pow_succ' (U:ℝ) (2*k)], norm_cast },
276277
end
277278

279+
open finset interval_integral
280+
281+
lemma integral_sin_pow_antimono (n : ℕ) :
282+
∫ (x : ℝ) in 0..π, sin x ^ (n + 1) ≤ ∫ (x : ℝ) in 0..π, sin x ^ n :=
283+
begin
284+
refine integral_mono_on _ _ pi_pos.le (λ x hx, _),
285+
{ exact ((continuous_pow (n + 1)).comp continuous_sin).interval_integrable 0 π },
286+
{ exact ((continuous_pow n).comp continuous_sin).interval_integrable 0 π },
287+
refine pow_le_pow_of_le_one _ (sin_le_one x) (nat.le_add_right n 1),
288+
rw interval_of_le pi_pos.le at hx,
289+
exact sin_nonneg_of_mem_Icc hx,
290+
end
291+
292+
lemma integral_sin_pow_div_tendsto_one :
293+
tendsto (λ k, (∫ x in 0..π, sin x ^ (2 * k + 1)) / ∫ x in 0..π, sin x ^ (2 * k)) at_top (𝓝 1) :=
294+
begin
295+
have h₃ : ∀ n, (∫ x in 0..π, sin x ^ (2 * n + 1)) / ∫ x in 0..π, sin x ^ (2 * n) ≤ 1 :=
296+
λ n, (div_le_one (integral_sin_pow_pos _)).mpr (integral_sin_pow_antimono _),
297+
have h₄ :
298+
∀ n, (∫ x in 0..π, sin x ^ (2 * n + 1)) / ∫ x in 0..π, sin x ^ (2 * n) ≥ 2 * n / (2 * n + 1),
299+
{ intro, cases n,
300+
{ have : 0 ≤ (1 + 1) / π, exact div_nonneg (by norm_num) pi_pos.le,
301+
simp [this] },
302+
calc (∫ x in 0..π, sin x ^ (2 * n.succ + 1)) / ∫ x in 0..π, sin x ^ (2 * n.succ) ≥
303+
(∫ x in 0..π, sin x ^ (2 * n.succ + 1)) / ∫ x in 0..π, sin x ^ (2 * n + 1) :
304+
by { refine div_le_div (integral_sin_pow_pos _).le (le_refl _) (integral_sin_pow_pos _) _,
305+
convert integral_sin_pow_antimono (2 * n + 1) using 1 }
306+
... = 2 * ↑(n.succ) / (2 * ↑(n.succ) + 1) :
307+
by { symmetry, rw [eq_div_iff, nat.succ_eq_add_one],
308+
convert (integral_sin_pow_succ_succ (2 * n + 1)).symm using 3,
309+
simp [mul_add], ring, simp [mul_add], ring,
310+
exact norm_num.ne_zero_of_pos _ (integral_sin_pow_pos (2 * n + 1)) } },
311+
refine tendsto_of_tendsto_of_tendsto_of_le_of_le _ _ (λ n, (h₄ n).le) (λ n, (h₃ n)),
312+
{ refine metric.tendsto_at_top.mpr (λ ε hε, ⟨nat_ceil (1 / ε), λ n hn, _⟩),
313+
have h : (2:ℝ) * n / (2 * n + 1) - 1 = -1 / (2 * n + 1),
314+
{ conv_lhs { congr, skip, rw ← @div_self _ _ ((2:ℝ) * n + 1) (by { norm_cast, linarith }), },
315+
rw [← sub_div, ← sub_sub, sub_self, zero_sub] },
316+
have hpos : (0:ℝ) < 2 * n + 1, { norm_cast, norm_num },
317+
rw [real.dist_eq, h, abs_div, abs_neg, abs_one, abs_of_pos hpos, one_div_lt hpos hε],
318+
calc 1 / ε ≤ nat_ceil (1 / ε) : le_nat_ceil _
319+
... ≤ n : by exact_mod_cast hn.le
320+
... < 2 * n + 1 : by { norm_cast, linarith } },
321+
exact tendsto_const_nhds,
322+
end
323+
324+
/-- This theorem establishes the Wallis Product for `π`. Our proof is largely about analyzing
325+
the behavior of the ratio of the integral of `sin x ^ n` as `n → ∞`.
326+
See: https://en.wikipedia.org/wiki/Wallis_product
327+
328+
The proof can be broken down into two pieces.
329+
(Pieces involving general properties of the integral of `sin x ^n` can be found
330+
in `analysis.special_functions.integrals`.) First, we use integration by parts to obtain a
331+
recursive formula for `∫ x in 0..π, sin x ^ (n + 2)` in terms of `∫ x in 0..π, sin x ^ n`.
332+
From this we can obtain closed form products of `∫ x in 0..π, sin x ^ (2 * n)` and
333+
`∫ x in 0..π, sin x ^ (2 * n + 1)` via induction. Next, we study the behavior of the ratio
334+
`∫ (x : ℝ) in 0..π, sin x ^ (2 * k + 1)) / ∫ (x : ℝ) in 0..π, sin x ^ (2 * k)` and prove that
335+
it converges to one using the squeeze theorem. The final product for `π` is obtained after some
336+
algebraic manipulation. -/
337+
theorem tendsto_prod_pi_div_two :
338+
tendsto (λ k, ∏ i in range k,
339+
(((2:ℝ) * i + 2) / (2 * i + 1)) * ((2 * i + 2) / (2 * i + 3))) at_top (𝓝 (π/2)) :=
340+
begin
341+
suffices h : tendsto (λ k, 2 / π * ∏ i in range k,
342+
(((2:ℝ) * i + 2) / (2 * i + 1)) * ((2 * i + 2) / (2 * i + 3))) at_top (𝓝 1),
343+
{ have := tendsto.const_mul (π / 2) h,
344+
have h : π / 20, norm_num [pi_ne_zero],
345+
simp only [← mul_assoc, ← @inv_div _ _ π 2, mul_inv_cancel h, one_mul, mul_one] at this,
346+
exact this },
347+
have h : (λ (k : ℕ), (2:ℝ) / π * ∏ (i : ℕ) in range k,
348+
((2 * i + 2) / (2 * i + 1)) * ((2 * i + 2) / (2 * i + 3))) =
349+
λ k, (2 * ∏ i in range k,
350+
(2 * i + 2) / (2 * i + 3)) / (π * ∏ (i : ℕ) in range k, (2 * i + 1) / (2 * i + 2)),
351+
{ funext,
352+
have h : ∏ (i : ℕ) in range k, ((2:ℝ) * ↑i + 2) / (2 * ↑i + 1) =
353+
1 / (∏ (i : ℕ) in range k, (2 * ↑i + 1) / (2 * ↑i + 2)),
354+
{ rw [one_div, ← finset.prod_inv_distrib'],
355+
refine prod_congr rfl (λ x hx, _),
356+
field_simp },
357+
rw [prod_mul_distrib, h],
358+
field_simp },
359+
simp only [h, ← integral_sin_pow_even, ← integral_sin_pow_odd],
360+
exact integral_sin_pow_div_tendsto_one,
361+
end
362+
278363
end real

0 commit comments

Comments
 (0)