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

Commit 088f753

Browse files
refactor(geo_sum): remove duplicate proofs about geometric sums (#706)
* feat(data/finset): add range_add_one * feat(algebra/big_operators): geometric sum for semiring, ring and division ring * refactor(geo_sum): remove duplicate proofs about geometric sums
1 parent 484d864 commit 088f753

File tree

4 files changed

+28
-46
lines changed

4 files changed

+28
-46
lines changed

src/algebra/big_operators.lean

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,24 @@ theorem geom_sum_mul [ring α] (x : α) (n : ℕ) :
549549
have _ := geom_sum_mul_add (x-1) n,
550550
by rw [sub_add_cancel] at this; rw [← this, add_sub_cancel]
551551

552-
theorem geom_sum [division_ring α] (x : α) (h : x ≠ 1) (n : ℕ) :
552+
theorem geom_sum [division_ring α] {x : α} (h : x ≠ 1) (n : ℕ) :
553553
(range n).sum (λ i, x^i) = (x^n-1)/(x-1) :=
554554
have x - 10, by simp [*, -sub_eq_add_neg, sub_eq_iff_eq_add] at *,
555555
by rw [← geom_sum_mul, mul_div_cancel _ this]
556556

557+
lemma geom_sum_inv [division_ring α] {x : α} (hx1 : x ≠ 1) (hx0 : x ≠ 0) (n : ℕ) :
558+
(range n).sum (λ m, x⁻¹ ^ m) = (x - 1)⁻¹ * (x - x⁻¹ ^ n * x) :=
559+
have h₁ : x⁻¹ ≠ 1, by rwa [inv_eq_one_div, ne.def, div_eq_iff_mul_eq hx0, one_mul],
560+
have h₂ : x⁻¹ - 10, from mt sub_eq_zero.1 h₁,
561+
have h₃ : x - 10, from mt sub_eq_zero.1 hx1,
562+
have h₄ : x * x⁻¹ ^ n = x⁻¹ ^ n * x,
563+
from nat.cases_on n (by simp)
564+
(λ _, by conv { to_rhs, rw [pow_succ', mul_assoc, inv_mul_cancel hx0, mul_one] };
565+
rw [pow_succ, ← mul_assoc, mul_inv_cancel hx0, one_mul]),
566+
by rw [geom_sum h₁, div_eq_iff_mul_eq h₂, ← domain.mul_left_inj h₃,
567+
← mul_assoc, ← mul_assoc, mul_inv_cancel h₃];
568+
simp [mul_add, add_mul, mul_inv_cancel hx0, mul_assoc, h₄]
569+
557570
end geom_sum
558571

559572
section group

src/analysis/specific_limits.lean

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,6 @@ lemma tendsto_one_div_add_at_top_nhds_0_nat : tendsto (λ n : ℕ, 1 / ((n : ℝ
154154
suffices tendsto (λ n : ℕ, 1 / (↑(n + 1) : ℝ)) at_top (nhds 0), by simpa,
155155
tendsto_comp_succ_at_top_iff.2 tendsto_one_div_at_top_nhds_0_nat
156156

157-
lemma sum_geometric' {r : ℝ} (h : r ≠ 0) :
158-
∀{n}, (finset.range n).sum (λi, (r + 1) ^ i) = ((r + 1) ^ n - 1) / r
159-
| 0 := by simp [zero_div]
160-
| (n+1) :=
161-
by simp [@sum_geometric' n, h, pow_succ, range_succ, add_div_eq_mul_add_div, add_mul, mul_comm, mul_assoc]
162-
163-
lemma sum_geometric {r : ℝ} {n : ℕ} (h : r ≠ 1) :
164-
(range n).sum (λi, r ^ i) = (r ^ n - 1) / (r - 1) :=
165-
calc (range n).sum (λi, r ^ i) = (range n).sum (λi, ((r - 1) + 1) ^ i) :
166-
by simp
167-
... = (((r - 1) + 1) ^ n - 1) / (r - 1) :
168-
sum_geometric' $ by simp [sub_eq_iff_eq_add, -sub_eq_add_neg, h]
169-
... = (r ^ n - 1) / (r - 1) :
170-
by simp
171-
172157
lemma is_sum_geometric {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
173158
is_sum (λn:ℕ, r ^ n) (1 / (1 - r)) :=
174159
have r ≠ 1, from ne_of_lt h₂,
@@ -178,7 +163,7 @@ have tendsto (λn, (r ^ n - 1) * (r - 1)⁻¹) at_top (nhds ((0 - 1) * (r - 1)
178163
from tendsto_mul
179164
(tendsto_sub (tendsto_pow_at_top_nhds_0_of_lt_1 h₁ h₂) tendsto_const_nhds) tendsto_const_nhds,
180165
(is_sum_iff_tendsto_nat_of_nonneg $ pow_nonneg h₁).mpr $
181-
by simp [neg_inv, sum_geometric, div_eq_mul_inv, *] at *
166+
by simp [neg_inv, geom_sum, div_eq_mul_inv, *] at *
182167

183168
lemma is_sum_geometric_two (a : ℝ) : is_sum (λn:ℕ, (a / 2) / 2 ^ n) a :=
184169
begin

src/data/complex/basic.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,19 @@ ext_iff.2 $ begin
218218
rw [← div_div_eq_div_mul, div_self h, one_div_eq_inv]
219219
end
220220

221-
lemma inv_zero : (0⁻¹ : ℂ) = 0 :=
221+
protected lemma inv_zero : (0⁻¹ : ℂ) = 0 :=
222222
by rw [← of_real_zero, ← of_real_inv, inv_zero]
223223

224-
theorem mul_inv_cancel {z : ℂ} (h : z ≠ 0) : z * z⁻¹ = 1 :=
224+
protected theorem mul_inv_cancel {z : ℂ} (h : z ≠ 0) : z * z⁻¹ = 1 :=
225225
by rw [inv_def, ← mul_assoc, mul_conj, ← of_real_mul,
226226
mul_inv_cancel (mt norm_sq_eq_zero.1 h), of_real_one]
227227

228228
noncomputable instance : discrete_field ℂ :=
229229
{ inv := has_inv.inv,
230230
zero_ne_one := mt (congr_arg re) zero_ne_one,
231-
mul_inv_cancel := @mul_inv_cancel,
232-
inv_mul_cancel := λ z h, by rw [mul_comm, mul_inv_cancel h],
233-
inv_zero := inv_zero,
231+
mul_inv_cancel := @complex.mul_inv_cancel,
232+
inv_mul_cancel := λ z h, by rw [mul_comm, complex.mul_inv_cancel h],
233+
inv_zero := complex.inv_zero,
234234
has_decidable_eq := classical.dec_eq _,
235235
..complex.comm_ring }
236236

src/data/complex/exponential.lean

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,6 @@ open is_absolute_value
1414
section
1515
open real is_absolute_value finset
1616

17-
lemma geo_sum_eq {α : Type*} [field α] {x : α} : ∀ (n : ℕ) (hx1 : x ≠ 1),
18-
(range n).sum (λ m, x ^ m) = (1 - x ^ n) / (1 - x)
19-
| 0 hx1 := by simp
20-
| (n+1) hx1 := have 1 - x ≠ 0 := mt sub_eq_zero_iff_eq.1 hx1.symm,
21-
by rw [sum_range_succ, ← mul_div_cancel (x ^ n) this, geo_sum_eq n hx1, ← add_div, _root_.pow_succ];
22-
simp [mul_add, add_mul, mul_comm]
23-
24-
lemma geo_sum_inv_eq {α : Type*} [discrete_field α] {x : α} (n : ℕ) (hx1 : x ≠ 1) (hx0 : x ≠ 0) :
25-
(range n).sum (λ m, x⁻¹ ^ m) = (x - x * x⁻¹ ^ n) / (x - 1) :=
26-
have hx1' : x⁻¹ ≠ 1, from λ h, by rw [← @inv_inv' _ _ x, h] at hx1; simpa using hx1,
27-
have h1x' : 1 - x⁻¹ ≠ 0, from sub_ne_zero.2 hx1'.symm,
28-
have h1x : x - 10, from sub_ne_zero.2 hx1,
29-
by rw [geo_sum_eq _ hx1', div_eq_div_iff h1x' h1x];
30-
simp [mul_add, add_mul, mul_inv_cancel hx0, mul_comm x, mul_left_comm x,
31-
mul_assoc, inv_mul_cancel hx0]
32-
3317
lemma forall_ge_le_of_forall_le_succ {α : Type*} [preorder α] (f : ℕ → α) {m : ℕ}
3418
(h : ∀ n ≥ m, f n.succ ≤ f n) : ∀ {l}, ∀ k ≥ m, k ≤ l → f l ≤ f k :=
3519
begin
@@ -122,10 +106,11 @@ lemma is_cau_geo_series {β : Type*} [field β] {abv : β → α} [is_absolute_v
122106
have hx1' : abv x ≠ 1 := λ h, by simpa [h, lt_irrefl] using hx1,
123107
is_cau_series_of_abv_cau
124108
begin
125-
simp only [abv_pow abv, geo_sum_eq _ hx1'] {eta := ff},
109+
simp only [abv_pow abv, geom_sum hx1'] {eta := ff},
110+
conv in (_ / _) { rw [← neg_div_neg_eq, neg_sub, neg_sub] },
126111
refine @is_cau_of_mono_bounded _ _ _ _ ((1 : α) / (1 - abv x)) 0 _ _,
127112
{ assume n hn,
128-
rw abs_of_nonneg ,
113+
rw abs_of_nonneg,
129114
refine div_le_div_of_le_of_pos (sub_le_self _ (abv_pow abv x n ▸ abv_nonneg _ _))
130115
(sub_pos.2 hx1),
131116
refine div_nonneg (sub_nonneg.2 _) (sub_pos.2 hx1),
@@ -877,12 +862,11 @@ calc (filter (λ k, n ≤ k) (range j)).sum (λ m : ℕ, (1 / m.fact : α))
877862
have h₂ : (n.succ : α) ≠ 0, from nat.cast_ne_zero.2 (nat.succ_ne_zero _),
878863
have h₃ : (n.fact * n : α) ≠ 0, from mul_ne_zero (nat.cast_ne_zero.2 (nat.pos_iff_ne_zero.1 (nat.fact_pos _)))
879864
(nat.cast_ne_zero.2 (nat.pos_iff_ne_zero.1 hn)),
880-
have h₄ : (n.succ - 1 : α) * (n.fact : ℕ) ≠ 0,
881-
from mul_ne_zero (sub_ne_zero.2 h₁)
882-
(nat.cast_ne_zero.2 (nat.pos_iff_ne_zero.1 (nat.fact_pos _))),
883-
by rw [geo_sum_inv_eq _ h₁ h₂, mul_comm, ← div_eq_mul_inv, div_div_eq_div_mul,
884-
div_eq_div_iff h₄ h₃];
885-
simp [mul_add, add_mul, mul_comm, mul_assoc, mul_left_comm]
865+
have h₄ : (n.succ - 1 : α) = n, by simp,
866+
by rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq _ _ h₃, mul_comm _ (n.fact * n : α),
867+
← mul_assoc (n.fact⁻¹ : α), ← mul_inv', h₄, ← mul_assoc (n.fact * n : α),
868+
mul_comm (n : α) n.fact, mul_inv_cancel h₃];
869+
simp [mul_add, add_mul, mul_assoc, mul_comm]
886870
... ≤ n.succ / (n.fact * n) :
887871
begin
888872
refine (div_le_div_right (mul_pos _ _)).2 _,

0 commit comments

Comments
 (0)