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

Commit cb1932d

Browse files
committed
feat(data/complex/exponential): bound on exp for arbitrary arguments (#8667)
This PR is for a new lemma (currently called `exp_bound'`) which proves `exp x` is close to its `n`th degree taylor expansion for sufficiently large `n`. Unlike the previous bound, this lemma can be instantiated on any real `x` rather than just `x` with absolute value less than or equal to 1. I am separating this lemma out from #8002 because I think it stands on its own. The last time I checked it was sorry free - but that was before I merged with master and moved it to a different branch. It may also benefit from a little golfing. There are a few lemmas I proved as well to support this - one about the relative size of factorials and a few about sums of geometric sequences. The ~~geometric series ones should probably be generalized and moved to another file~~ this generalization sort of exists and is in the algebra.geom_sum file. I didn't find it initially since I was searching for "geometric" not "geom".
1 parent fe47777 commit cb1932d

File tree

4 files changed

+66
-7
lines changed

4 files changed

+66
-7
lines changed

src/algebra/big_operators/basic.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,12 @@ begin
774774
{ rw [nat.add_succ, prod_range_succ, hm, prod_range_succ, mul_assoc], },
775775
end
776776

777+
@[to_additive]
778+
lemma prod_range_add_div_prod_range {α : Type*} [comm_group α] (f : ℕ → α) (n m : ℕ) :
779+
(∏ k in range (n + m), f k) / (∏ k in range n, f k) = ∏ k in finset.range m, f (n + k) :=
780+
div_eq_of_eq_mul' (prod_range_add f n m)
781+
782+
777783
@[to_additive]
778784
lemma prod_range_zero (f : ℕ → β) :
779785
∏ k in range 0, f k = 1 :=

src/algebra/group/basic.lean

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ calc a / 1 = a * 1⁻¹ : div_eq_mul_inv a 1
336336
end group
337337

338338
section add_group
339+
-- TODO: Generalize the contents of this section with to_additive as per
340+
-- https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.238667
339341
variables {G : Type u} [add_group G] {a b c d : G}
340342

341343
@[simp] lemma sub_self (a : G) : a - a = 0 :=
@@ -445,9 +447,15 @@ variables {G : Type u} [comm_group G]
445447
lemma mul_inv (a b : G) : (a * b)⁻¹ = a⁻¹ * b⁻¹ :=
446448
by rw [mul_inv_rev, mul_comm]
447449

450+
@[to_additive]
451+
lemma div_eq_of_eq_mul' {a b c : G} (h : a = b * c) : a / b = c :=
452+
by rw [h, div_eq_mul_inv, mul_comm, inv_mul_cancel_left]
453+
448454
end comm_group
449455

450456
section add_comm_group
457+
-- TODO: Generalize the contents of this section with to_additive as per
458+
-- https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.238667
451459
variables {G : Type u} [add_comm_group G] {a b c d : G}
452460

453461
local attribute [simp] add_assoc add_comm add_left_comm sub_eq_add_neg
@@ -473,9 +481,6 @@ by simp
473481
lemma eq_sub_of_add_eq' (h : c + a = b) : a = b - c :=
474482
by simp [h.symm]
475483

476-
lemma sub_eq_of_eq_add' (h : a = b + c) : a - b = c :=
477-
begin simp [h], rw [add_left_comm], simp end
478-
479484
lemma eq_add_of_sub_eq' (h : a - b = c) : a = b + c :=
480485
by simp [h.symm]
481486

src/data/complex/exponential.lean

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ by rw [sum_sigma', sum_sigma']; exact sum_bij
210210
mem_range.2 (nat.lt_succ_of_le (nat.le_add_left _ _))⟩,
211211
sigma.mk.inj_iff.2 ⟨rfl, heq_of_eq (nat.add_sub_cancel _ _).symm⟩⟩⟩)
212212

213+
-- TODO move to src/algebra/big_operators/basic.lean, rewrite with comm_group, and make to_additive
213214
lemma sum_range_sub_sum_range {α : Type*} [add_comm_group α] {f : ℕ → α}
214215
{n m : ℕ} (hnm : n ≤ m) : ∑ k in range m, f k - ∑ k in range n, f k =
215216
∑ k in (range m).filter (λ k, n ≤ k), f k :=
@@ -1279,17 +1280,52 @@ begin
12791280
refine sum_le_sum (λ m hm, _),
12801281
rw [abs_mul, abv_pow abs, abs_div, abs_cast_nat],
12811282
refine mul_le_mul_of_nonneg_left ((div_le_div_right _).2 _) _,
1282-
exact nat.cast_pos.2 (nat.factorial_pos _),
1283-
rw abv_pow abs,
1284-
exact (pow_le_one _ (abs_nonneg _) hx),
1285-
exact pow_nonneg (abs_nonneg _) _
1283+
{ exact nat.cast_pos.2 (nat.factorial_pos _), },
1284+
{ rw abv_pow abs,
1285+
exact (pow_le_one _ (abs_nonneg _) hx), },
1286+
{ exact pow_nonneg (abs_nonneg _) _ },
12861287
end
12871288
... = abs x ^ n * (∑ m in (range j).filter (λ k, n ≤ k), (1 / m! : ℝ)) :
12881289
by simp [abs_mul, abv_pow abs, abs_div, mul_sum.symm]
12891290
... ≤ abs x ^ n * (n.succ * (n! * n)⁻¹) :
12901291
mul_le_mul_of_nonneg_left (sum_div_factorial_le _ _ hn) (pow_nonneg (abs_nonneg _) _)
12911292
end
12921293

1294+
lemma exp_bound' {x : ℂ} {n : ℕ} (hx : abs x / (n.succ) ≤ 1 / 2) :
1295+
abs (exp x - ∑ m in range n, x ^ m / m!) ≤ abs x ^ n / (n!) * 2 :=
1296+
begin
1297+
rw [← lim_const (∑ m in range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_abs],
1298+
refine lim_le (cau_seq.le_of_exists ⟨n, λ j hj, _⟩),
1299+
simp_rw [←sub_eq_add_neg],
1300+
show abs (∑ m in range j, x ^ m / m! - ∑ m in range n, x ^ m / m!) ≤ abs x ^ n / (n!) * 2,
1301+
let k := j - n,
1302+
have hj : j = n + k := (nat.add_sub_of_le hj).symm,
1303+
rw [hj, sum_range_add_sub_sum_range],
1304+
calc abs (∑ (i : ℕ) in range k, x ^ (n + i) / ((n + i)! : ℂ))
1305+
≤ ∑ (i : ℕ) in range k, abs (x ^ (n + i) / ((n + i)! : ℂ)) : abv_sum_le_sum_abv _ _
1306+
... ≤ ∑ (i : ℕ) in range k, (abs x) ^ (n + i) / (n + i)! :
1307+
by simp only [complex.abs_cast_nat, complex.abs_div, abv_pow abs]
1308+
... ≤ ∑ (i : ℕ) in range k, (abs x) ^ (n + i) / (n! * n.succ ^ i) : _
1309+
... = ∑ (i : ℕ) in range k, (abs x) ^ (n) / (n!) * ((abs x)^i / n.succ ^ i) : _
1310+
... ≤ abs x ^ n / (↑n!) * 2 : _,
1311+
{ refine sum_le_sum (λ m hm, div_le_div (pow_nonneg (abs_nonneg x) (n + m)) (le_refl _) _ _),
1312+
{ exact_mod_cast mul_pos n.factorial_pos (pow_pos n.succ_pos _), },
1313+
{ exact_mod_cast (nat.factorial_mul_pow_le_factorial), }, },
1314+
{ refine finset.sum_congr rfl (λ _ _, _),
1315+
simp only [pow_add, div_eq_inv_mul, mul_inv', mul_left_comm, mul_assoc], },
1316+
{ rw [←mul_sum],
1317+
apply mul_le_mul_of_nonneg_left,
1318+
{ simp_rw [←div_pow],
1319+
rw [←geom_sum_def, geom_sum_eq, div_le_iff_of_neg],
1320+
{ transitivity (-1 : ℝ),
1321+
{ linarith },
1322+
{ simp only [neg_le_sub_iff_le_add, div_pow, nat.cast_succ, le_add_iff_nonneg_left],
1323+
exact div_nonneg (pow_nonneg (abs_nonneg x) k) (pow_nonneg (n+1).cast_nonneg k) } },
1324+
{ linarith },
1325+
{ linarith }, },
1326+
{ exact div_nonneg (pow_nonneg (abs_nonneg x) n) (nat.cast_nonneg (n!)), }, },
1327+
end
1328+
12931329
lemma abs_exp_sub_one_le {x : ℂ} (hx : abs x ≤ 1) :
12941330
abs (exp x - 1) ≤ 2 * abs x :=
12951331
calc abs (exp x - 1) = abs (exp x - ∑ m in range 1, x ^ m / m!) :

src/data/nat/factorial.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ begin
159159
exact add_factorial_succ_le_factorial_add_succ i h,
160160
end
161161

162+
lemma factorial_mul_pow_sub_le_factorial {n m : ℕ} (hnm : n ≤ m) : n! * n ^ (m - n) ≤ m! :=
163+
begin
164+
suffices : n! * (n + 1) ^ (m - n) ≤ m!,
165+
{ apply trans _ this,
166+
rw mul_le_mul_left,
167+
apply pow_le_pow_of_le_left (zero_le n) (le_succ n),
168+
exact factorial_pos n,},
169+
convert nat.factorial_mul_pow_le_factorial,
170+
exact (nat.add_sub_of_le hnm).symm,
171+
end
172+
173+
162174
end factorial
163175

164176
/-! ### Ascending and descending factorials -/

0 commit comments

Comments
 (0)