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

Commit ee8451b

Browse files
committed
feat(data/list): more lemmas on joins and sums (#2501)
A few more lemmas on lists (especially joins) and sums. I also linted the file `lists/basic.lean` and converted some comments to section headers. Some lemmas got renamed: `of_fn_prod_take` -> `prod_take_of_fn` `of_fn_sum_take` -> `sum_take_of_fn` `of_fn_prod` ->`prod_of_fn` `of_fn_sum` -> `sum_of_fn` The arguments of `nth_le_repeat` were changed for better `simp` efficiency
1 parent 6795c9d commit ee8451b

File tree

8 files changed

+313
-76
lines changed

8 files changed

+313
-76
lines changed

src/algebra/big_operators.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Some big operators for lists and finite sets.
77
-/
88
import data.finset
99
import data.nat.enat
10+
import tactic.omega
1011

1112
universes u v w
1213
variables {α : Type u} {β : Type v} {γ : Type w}
@@ -359,6 +360,18 @@ lemma prod_range_succ' (f : ℕ → β) :
359360
| (n + 1) := by rw [prod_range_succ (λ m, f (nat.succ m)), mul_assoc, ← prod_range_succ'];
360361
exact prod_range_succ _ _
361362

363+
/-- A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function reduces to the difference of
364+
the last and first terms when the function we are summing is monotone. -/
365+
lemma sum_range_sub_of_monotone {f : ℕ → ℕ} (h : monotone f) (n : ℕ) :
366+
(finset.range n).sum (λ i, f (i+1) - f i) = f n - f 0 :=
367+
begin
368+
induction n with n IH, { simp },
369+
rw [finset.sum_range_succ, IH, nat.succ_eq_add_one],
370+
have : f n ≤ f (n+1) := h (nat.le_succ _),
371+
have : f 0 ≤ f n := h (nat.zero_le _),
372+
omega
373+
end
374+
362375
lemma sum_Ico_add {δ : Type*} [add_comm_monoid δ] (f : ℕ → δ) (m n k : ℕ) :
363376
(Ico m n).sum (λ l, f (k + l)) = (Ico (m + k) (n + k)).sum f :=
364377
Ico.image_add m n k ▸ eq.symm $ sum_image $ λ x hx y hy h, nat.add_left_cancel h

src/analysis/analytic/composition.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def comp_change_of_variables (N : ℕ) (i : Σ n, (fin n) → ℕ) (hi : i ∈ c
373373
begin
374374
rcases i with ⟨n, f⟩,
375375
rw mem_comp_partial_sum_source_iff at hi,
376-
exact ⟨finset.univ.sum f, list.of_fn (λ a, ⟨f a, (hi.2 a).1⟩), by simp [list.of_fn_sum]⟩
376+
exact ⟨finset.univ.sum f, list.of_fn (λ a, ⟨f a, (hi.2 a).1⟩), by simp [list.sum_of_fn]⟩
377377
end
378378

379379
@[simp] lemma comp_change_of_variables_length

src/combinatorics/composition.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def blocks_fun : fin c.length → ℕ := λ i, nth_le c.blocks i.1 i.2
129129

130130
lemma sum_blocks_fun : finset.univ.sum c.blocks_fun = n :=
131131
begin
132-
conv_rhs { rw [← c.blocks_sum, ← of_fn_nth_le c.blocks, of_fn_sum] },
132+
conv_rhs { rw [← c.blocks_sum, ← of_fn_nth_le c.blocks, sum_of_fn] },
133133
simp [blocks_fun, length],
134134
refl
135135
end

src/data/fintype/basic.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ instance {α : Type*} (β : α → Type*)
349349
[fintype α] [∀ a, fintype (β a)] : fintype (sigma β) :=
350350
⟨univ.sigma (λ _, univ), λ ⟨a, b⟩, by simp⟩
351351

352+
@[simp] lemma finset.univ_sigma_univ {α : Type*} {β : α → Type*} [fintype α] [∀ a, fintype (β a)] :
353+
(univ : finset α).sigma (λ a, (univ : finset (β a))) = univ := rfl
354+
352355
instance (α β : Type*) [fintype α] [fintype β] : fintype (α × β) :=
353356
⟨univ.product univ, λ ⟨a, b⟩, by simp⟩
354357

src/data/fintype/card.lean

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,32 @@ lemma fin.sum_pow_mul_eq_add_pow {n : ℕ} {R : Type*} [comm_semiring R] (a b :
149149
(a + b) ^ n :=
150150
by simpa using fintype.sum_pow_mul_eq_add_pow (fin n) a b
151151

152+
/-- It is equivalent to sum a function over `fin n` or `finset.range n`. -/
153+
@[to_additive]
154+
lemma fin.prod_univ_eq_prod_range [comm_monoid α] (f : ℕ → α) (n : ℕ) :
155+
finset.univ.prod (λ (i : fin n), f i.val) = (finset.range n).prod f :=
156+
begin
157+
apply finset.prod_bij (λ (a : fin n) ha, a.val),
158+
{ assume a ha, simp [a.2] },
159+
{ assume a ha, refl },
160+
{ assume a b ha hb H, exact (fin.ext_iff _ _).2 H },
161+
{ assume b hb, exact ⟨⟨b, list.mem_range.mp hb⟩, finset.mem_univ _, rfl⟩, }
162+
end
163+
164+
@[to_additive]
165+
lemma prod_equiv [fintype α] [fintype β] [comm_monoid γ] (e : α ≃ β) (f : β → γ) :
166+
finset.univ.prod (f ∘ e) = finset.univ.prod f :=
167+
begin
168+
apply prod_bij (λ i hi, e i) (λ i hi, mem_univ _) _ (λ a b _ _ h, e.injective h),
169+
{ assume b hb,
170+
rcases e.surjective b with ⟨a, ha⟩,
171+
exact ⟨a, mem_univ _, ha.symm⟩, },
172+
{ simp }
173+
end
174+
152175
namespace list
153176

154-
lemma of_fn_prod_take [comm_monoid α] {n : ℕ} (f : fin n → α) (i : ℕ) :
177+
lemma prod_take_of_fn [comm_monoid α] {n : ℕ} (f : fin n → α) (i : ℕ) :
155178
((of_fn f).take i).prod = (finset.univ.filter (λ (j : fin n), j.val < i)).prod f :=
156179
begin
157180
have A : ∀ (j : fin n), ¬ (j.val < 0) := λ j, not_lt_bot,
@@ -177,9 +200,9 @@ begin
177200
simp [← A, B, IH] }
178201
end
179202

180-
-- `to_additive` does not work on `of_fn_prod_take` because of `0 : ℕ` in the proof. Copy-paste the
203+
-- `to_additive` does not work on `prod_take_of_fn` because of `0 : ℕ` in the proof. Copy-paste the
181204
-- proof instead...
182-
lemma of_fn_sum_take [add_comm_monoid α] {n : ℕ} (f : fin n → α) (i : ℕ) :
205+
lemma sum_take_of_fn [add_comm_monoid α] {n : ℕ} (f : fin n → α) (i : ℕ) :
183206
((of_fn f).take i).sum = (finset.univ.filter (λ (j : fin n), j.val < i)).sum f :=
184207
begin
185208
have A : ∀ (j : fin n), ¬ (j.val < 0) := λ j, not_lt_bot,
@@ -205,13 +228,13 @@ begin
205228
simp [← A, B, IH] }
206229
end
207230

208-
attribute [to_additive] of_fn_prod_take
231+
attribute [to_additive] prod_take_of_fn
209232

210233
@[to_additive]
211-
lemma of_fn_prod [comm_monoid α] {n : ℕ} {f : fin n → α} :
234+
lemma prod_of_fn [comm_monoid α] {n : ℕ} {f : fin n → α} :
212235
(of_fn f).prod = finset.univ.prod f :=
213236
begin
214-
convert of_fn_prod_take f n,
237+
convert prod_take_of_fn f n,
215238
{ rw [take_all_of_le (le_of_eq (length_of_fn f))] },
216239
{ have : ∀ (j : fin n), j.val < n := λ j, j.2,
217240
simp [this] }

0 commit comments

Comments
 (0)