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

Commit a0504eb

Browse files
YaelDilliesurkud
andcommitted
refactor(data/*/interval): generalize finset.Ico to locally finite orders (#7987)
`finset.Ico` currently goes `ℕ → ℕ → finset ℕ`. This generalizes it to `α → α → finset α` where `locally_finite_order α`. This also ports all the existing `finset.Ico` lemmas to the new API, which involves renaming and moving them to `data.finset.interval` or `data.nat.interval` depending on whether I could generalize them away from `ℕ` or not. Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
1 parent ba2454e commit a0504eb

34 files changed

+439
-481
lines changed

src/algebra/big_operators/intervals.lean

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Johannes Hölzl
55
-/
66

77
import algebra.big_operators.basic
8-
import data.finset.intervals
8+
import data.nat.interval
99
import tactic.linarith
1010

1111
/-!
@@ -25,7 +25,7 @@ variables {α : Type u} {β : Type v} {γ : Type w} {s₂ s₁ s : finset α} {a
2525

2626
lemma sum_Ico_add {δ : Type*} [add_comm_monoid δ] (f : ℕ → δ) (m n k : ℕ) :
2727
(∑ l in Ico m n, f (k + l)) = (∑ l in Ico (m + k) (n + k), f l) :=
28-
Ico.image_add m n k ▸ eq.symm $ sum_image $ λ x hx y hy h, nat.add_left_cancel h
28+
image_add_const_Ico m n k ▸ eq.symm $ sum_image $ λ x hx y hy h, nat.add_left_cancel h
2929

3030
@[to_additive]
3131
lemma prod_Ico_add (f : ℕ → β) (m n k : ℕ) :
@@ -34,7 +34,7 @@ lemma prod_Ico_add (f : ℕ → β) (m n k : ℕ) :
3434

3535
lemma sum_Ico_succ_top {δ : Type*} [add_comm_monoid δ] {a b : ℕ}
3636
(hab : a ≤ b) (f : ℕ → δ) : (∑ k in Ico a (b + 1), f k) = (∑ k in Ico a b, f k) + f b :=
37-
by rw [Ico.succ_top hab, sum_insert Ico.not_mem_top, add_comm]
37+
by rw [nat.Ico_succ_right_eq_insert_Ico hab, sum_insert right_not_mem_Ico, add_comm]
3838

3939
@[to_additive]
4040
lemma prod_Ico_succ_top {a b : ℕ} (hab : a ≤ b) (f : ℕ → β) :
@@ -44,7 +44,7 @@ lemma prod_Ico_succ_top {a b : ℕ} (hab : a ≤ b) (f : ℕ → β) :
4444
lemma sum_eq_sum_Ico_succ_bot {δ : Type*} [add_comm_monoid δ] {a b : ℕ}
4545
(hab : a < b) (f : ℕ → δ) : (∑ k in Ico a b, f k) = f a + (∑ k in Ico (a + 1) b, f k) :=
4646
have ha : a ∉ Ico (a + 1) b, by simp,
47-
by rw [← sum_insert ha, Ico.insert_succ_bot hab]
47+
by rw [← sum_insert ha, nat.Ico_insert_succ_left hab]
4848

4949
@[to_additive]
5050
lemma prod_eq_prod_Ico_succ_bot {a b : ℕ} (hab : a < b) (f : ℕ → β) :
@@ -54,12 +54,12 @@ lemma prod_eq_prod_Ico_succ_bot {a b : ℕ} (hab : a < b) (f : ℕ → β) :
5454
@[to_additive]
5555
lemma prod_Ico_consecutive (f : ℕ → β) {m n k : ℕ} (hmn : m ≤ n) (hnk : n ≤ k) :
5656
(∏ i in Ico m n, f i) * (∏ i in Ico n k, f i) = (∏ i in Ico m k, f i) :=
57-
Ico.union_consecutive hmn hnk ▸ eq.symm $ prod_union $ Ico.disjoint_consecutive m n k
57+
Ico_union_Ico_eq_Ico hmn hnk ▸ eq.symm $ prod_union $ Ico_disjoint_Ico_consecutive m n k
5858

5959
@[to_additive]
6060
lemma prod_range_mul_prod_Ico (f : ℕ → β) {m n : ℕ} (h : m ≤ n) :
6161
(∏ k in range m, f k) * (∏ k in Ico m n, f k) = (∏ k in range n, f k) :=
62-
Ico.zero_bot m ▸ Ico.zero_bot n ▸ prod_Ico_consecutive f (nat.zero_le m) h
62+
m.Ico_zero_eq_range ▸ n.Ico_zero_eq_range ▸ prod_Ico_consecutive f m.zero_le h
6363

6464
@[to_additive]
6565
lemma prod_Ico_eq_mul_inv {δ : Type*} [comm_group δ] (f : ℕ → δ) {m n : ℕ} (h : m ≤ n) :
@@ -81,7 +81,7 @@ begin
8181
(λ (x : Σ (i : ℕ), ℕ) _, (⟨x.2, x.1⟩ : Σ (i : ℕ), ℕ)) _ (λ _ _, rfl)
8282
(λ (x : Σ (i : ℕ), ℕ) _, (⟨x.2, x.1⟩ : Σ (i : ℕ), ℕ)) _
8383
(by rintro ⟨⟩ _; refl) (by rintro ⟨⟩ _; refl);
84-
simp only [finset.Ico.mem, sigma.forall, finset.mem_sigma];
84+
simp only [finset.mem_Ico, sigma.forall, finset.mem_sigma];
8585
rintros a b ⟨⟨h₁,h₂⟩, ⟨h₃, h₄⟩⟩; refine ⟨⟨_, _⟩, ⟨_, _⟩⟩; linarith
8686
end
8787

@@ -90,9 +90,9 @@ lemma prod_Ico_eq_prod_range (f : ℕ → β) (m n : ℕ) :
9090
(∏ k in Ico m n, f k) = (∏ k in range (n - m), f (m + k)) :=
9191
begin
9292
by_cases h : m ≤ n,
93-
{ rw [← Ico.zero_bot, prod_Ico_add, zero_add, nat.sub_add_cancel h] },
93+
{ rw [←nat.Ico_zero_eq_range, prod_Ico_add, zero_add, nat.sub_add_cancel h] },
9494
{ replace h : n ≤ m := le_of_not_ge h,
95-
rw [Ico.eq_empty_of_le h, nat.sub_eq_zero_of_le h, range_zero, prod_empty, prod_empty] }
95+
rw [Ico_eq_empty_of_le h, nat.sub_eq_zero_of_le h, range_zero, prod_empty, prod_empty] }
9696
end
9797

9898
lemma prod_Ico_reflect (f : ℕ → β) (k : ℕ) {m n : ℕ} (h : m ≤ n + 1) :
@@ -102,12 +102,12 @@ begin
102102
{ intros i hi,
103103
exact (add_le_add_iff_right 1).1 (le_trans (nat.lt_iff_add_one_le.1 hi) h) },
104104
cases lt_or_le k m with hkm hkm,
105-
{ rw [← finset.Ico.image_const_sub (this _ hkm)],
105+
{ rw [← nat.Ico_image_const_sub_eq_Ico (this _ hkm)],
106106
refine (prod_image _).symm,
107-
simp only [Ico.mem],
107+
simp only [mem_Ico],
108108
rintros i ⟨ki, im⟩ j ⟨kj, jm⟩ Hij,
109109
rw [← nat.sub_sub_self (this _ im), Hij, nat.sub_sub_self (this _ jm)] },
110-
{ simp [Ico.eq_empty_of_le, nat.sub_le_sub_left, hkm] }
110+
{ simp [Ico_eq_empty_of_le, nat.sub_le_sub_left, hkm] }
111111
end
112112

113113
lemma sum_Ico_reflect {δ : Type*} [add_comm_monoid δ] (f : ℕ → δ) (k : ℕ) {m n : ℕ}
@@ -120,8 +120,8 @@ lemma prod_range_reflect (f : ℕ → β) (n : ℕ) :
120120
begin
121121
cases n,
122122
{ simp },
123-
{ simp only [range_eq_Ico, nat.succ_sub_succ_eq_sub, nat.sub_zero],
124-
rw [prod_Ico_reflect _ _ (le_refl _)],
123+
{ simp only [←nat.Ico_zero_eq_range, nat.succ_sub_succ_eq_sub, nat.sub_zero],
124+
rw prod_Ico_reflect _ _ le_rfl,
125125
simp }
126126
end
127127

src/algebra/geom_sum.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,15 @@ lemma nat.geom_sum_Ico_le {b : ℕ} (hb : 2 ≤ b) (a n : ℕ) :
353353
∑ i in Ico 1 n, a/b^i ≤ a/(b - 1) :=
354354
begin
355355
cases n,
356-
{ rw [Ico.eq_empty_of_le zero_le_one, sum_empty],
356+
{ rw [Ico_eq_empty_of_le zero_le_one, sum_empty],
357357
exact nat.zero_le _ },
358358
rw ←add_le_add_iff_left a,
359359
calc
360360
a + ∑ (i : ℕ) in Ico 1 n.succ, a/b^i
361361
= a/b^0 + ∑ (i : ℕ) in Ico 1 n.succ, a/b^i : by rw [pow_zero, nat.div_one]
362362
... = ∑ i in range n.succ, a/b^i : begin
363-
rw [range_eq_Ico, ←finset.Ico.insert_succ_bot (nat.succ_pos _), sum_insert],
364-
exact λ h, zero_lt_one.not_le (Ico.mem.1 h).1,
363+
rw [range_eq_Ico, ←nat.Ico_insert_succ_left (nat.succ_pos _), sum_insert],
364+
exact λ h, zero_lt_one.not_le (mem_Ico.1 h).1,
365365
end
366366
... ≤ a * b/(b - 1) : nat.geom_sum_le hb a _
367367
... = (a * 1 + a * (b - 1))/(b - 1)

src/analysis/analytic/composition.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ finset.sigma (finset.Ico m M) (λ (n : ℕ), fintype.pi_finset (λ (i : fin n),
537537
@[simp] lemma mem_comp_partial_sum_source_iff (m M N : ℕ) (i : Σ n, (fin n) → ℕ) :
538538
i ∈ comp_partial_sum_source m M N ↔
539539
(m ≤ i.1 ∧ i.1 < M) ∧ ∀ (a : fin i.1), 1 ≤ i.2 a ∧ i.2 a < N :=
540-
by simp only [comp_partial_sum_source, finset.Ico.mem, fintype.mem_pi_finset, finset.mem_sigma,
540+
by simp only [comp_partial_sum_source, finset.mem_Ico, fintype.mem_pi_finset, finset.mem_sigma,
541541
iff_self]
542542

543543
/-- Change of variables appearing to compute the composition of partial sums of formal

src/analysis/analytic/inverse.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ begin
370370
refine sum_le_sum_of_subset_of_nonneg _ (λ x hx1 hx2,
371371
prod_nonneg (λ j hj, mul_nonneg hr (mul_nonneg (pow_nonneg ha _) (hp _)))),
372372
rintros ⟨k, c⟩ hd,
373-
simp only [set.mem_to_finset, Ico.mem, mem_sigma, set.mem_set_of_eq] at hd,
373+
simp only [set.mem_to_finset, mem_Ico, mem_sigma, set.mem_set_of_eq] at hd,
374374
simp only [mem_comp_partial_sum_target_iff],
375375
refine ⟨hd.2, c.length_le.trans_lt hd.1.2, λ j, _⟩,
376376
have : c ≠ composition.single k (zero_lt_two.trans_le hd.1.1),
@@ -417,15 +417,15 @@ let I := ∥(i.symm : F →L[𝕜] E)∥ in calc
417417
∑ k in Ico 1 (n + 1), a ^ k * ∥p.right_inv i k∥
418418
= a * I + ∑ k in Ico 2 (n + 1), a ^ k * ∥p.right_inv i k∥ :
419419
by simp only [linear_isometry_equiv.norm_map, pow_one, right_inv_coeff_one,
420-
Ico.succ_singleton, sum_singleton, ← sum_Ico_consecutive _ one_le_two hn]
420+
nat.Ico_succ_singleton, sum_singleton, ← sum_Ico_consecutive _ one_le_two hn]
421421
... = a * I + ∑ k in Ico 2 (n + 1), a ^ k *
422422
∥(i.symm : F →L[𝕜] E).comp_continuous_multilinear_map
423423
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
424424
p.comp_along_composition (p.right_inv i) c)∥ :
425425
begin
426426
congr' 1,
427427
apply sum_congr rfl (λ j hj, _),
428-
rw [right_inv_coeff _ _ _ (Ico.mem.1 hj).1, norm_neg],
428+
rw [right_inv_coeff _ _ _ (mem_Ico.1 hj).1, norm_neg],
429429
end
430430
... ≤ a * ∥(i.symm : F →L[𝕜] E)∥ + ∑ k in Ico 2 (n + 1), a ^ k * (I *
431431
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
@@ -487,7 +487,7 @@ begin
487487
have IRec : ∀ n, 1 ≤ n → S n ≤ (I + 1) * a,
488488
{ apply nat.le_induction,
489489
{ simp only [S],
490-
rw [Ico.eq_empty_of_le (le_refl 1), sum_empty],
490+
rw [Ico_eq_empty_of_le (le_refl 1), sum_empty],
491491
exact mul_nonneg (add_nonneg (norm_nonneg _) zero_le_one) apos.le },
492492
{ assume n one_le_n hn,
493493
have In : 2 ≤ n + 1, by linarith,

src/analysis/p_series.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ begin
5050
exact add_le_add ihn this,
5151
exacts [n.one_le_two_pow, nat.pow_le_pow_of_le_right zero_lt_two n.le_succ] },
5252
have : ∀ k ∈ Ico (2 ^ n) (2 ^ (n + 1)), f k ≤ f (2 ^ n) :=
53-
λ k hk, hf (pow_pos zero_lt_two _) (Ico.mem.mp hk).1,
53+
λ k hk, hf (pow_pos zero_lt_two _) (mem_Ico.mp hk).1,
5454
convert sum_le_sum this,
5555
simp [pow_succ, two_mul]
5656
end
@@ -72,8 +72,8 @@ begin
7272
exacts [add_le_add_right n.one_le_two_pow _,
7373
add_le_add_right (nat.pow_le_pow_of_le_right zero_lt_two n.le_succ) _] },
7474
have : ∀ k ∈ Ico (2 ^ n + 1) (2 ^ (n + 1) + 1), f (2 ^ (n + 1)) ≤ f k :=
75-
λ k hk, hf (n.one_le_two_pow.trans_lt $ (nat.lt_succ_of_le le_rfl).trans_le (Ico.mem.mp hk).1)
76-
(nat.le_of_lt_succ $ (Ico.mem.mp hk).2),
75+
λ k hk, hf (n.one_le_two_pow.trans_lt $ (nat.lt_succ_of_le le_rfl).trans_le (mem_Ico.mp hk).1)
76+
(nat.le_of_lt_succ $ (mem_Ico.mp hk).2),
7777
convert sum_le_sum this,
7878
simp [pow_succ, two_mul]
7979
end

src/analysis/special_functions/exp_log.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,9 @@ begin
796796
eventually_at_top.1 ((tendsto_pow_const_div_const_pow_of_one_lt n
797797
(one_lt_exp_iff.2 zero_lt_one)).eventually (gt_mem_nhds this)),
798798
simp only [← exp_nat_mul, mul_one, div_lt_iff, exp_pos, ← div_eq_inv_mul] at hN,
799-
refine ⟨N, trivial, λ x hx, _⟩, rw mem_Ioi at hx,
799+
refine ⟨N, trivial, λ x hx, _⟩, rw set.mem_Ioi at hx,
800800
have hx₀ : 0 < x, from N.cast_nonneg.trans_lt hx,
801-
rw [mem_Ici, le_div_iff (pow_pos hx₀ _), ← le_div_iff' hC₀],
801+
rw [set.mem_Ici, le_div_iff (pow_pos hx₀ _), ← le_div_iff' hC₀],
802802
calc x ^ n ≤ ⌈x⌉₊ ^ n : pow_le_pow_of_le_left hx₀.le (le_nat_ceil _) _
803803
... ≤ exp ⌈x⌉₊ / (exp 1 * C) : (hN _ (lt_nat_ceil.2 hx).le).le
804804
... ≤ exp (x + 1) / (exp 1 * C) : div_le_div_of_le (mul_pos (exp_pos _) hC₀).le

src/data/fin/interval.lean

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import data.nat.interval
1010
1111
This file proves that `fin n` is a `locally_finite_order` and calculates the cardinality of its
1212
intervals as finsets and fintypes.
13-
14-
## TODO
15-
16-
@Yaël: Add `finset.Ico`. Coming very soon.
1713
-/
1814

1915
open finset fin
@@ -26,13 +22,18 @@ namespace fin
2622
variables {n} (a b : fin n)
2723

2824
lemma Icc_eq_finset_subtype : Icc a b = (Icc (a : ℕ) b).subtype (λ x, x < n) := rfl
25+
lemma Ico_eq_finset_subtype : Ico a b = (Ico (a : ℕ) b).subtype (λ x, x < n) := rfl
2926
lemma Ioc_eq_finset_subtype : Ioc a b = (Ioc (a : ℕ) b).subtype (λ x, x < n) := rfl
3027
lemma Ioo_eq_finset_subtype : Ioo a b = (Ioo (a : ℕ) b).subtype (λ x, x < n) := rfl
3128

3229
@[simp] lemma map_subtype_embedding_Icc :
3330
(Icc a b).map (function.embedding.subtype _) = Icc (a : ℕ) b :=
3431
map_subtype_embedding_Icc _ _ _ (λ _ c x _ hx _, hx.trans_lt)
3532

33+
@[simp] lemma map_subtype_embedding_Ico :
34+
(Ico a b).map (function.embedding.subtype _) = Ico (a : ℕ) b :=
35+
map_subtype_embedding_Ico _ _ _ (λ _ c x _ hx _, hx.trans_lt)
36+
3637
@[simp] lemma map_subtype_embedding_Ioc :
3738
(Ioc a b).map (function.embedding.subtype _) = Ioc (a : ℕ) b :=
3839
map_subtype_embedding_Ioc _ _ _ (λ _ c x _ hx _, hx.trans_lt)
@@ -44,6 +45,9 @@ map_subtype_embedding_Ioo _ _ _ (λ _ c x _ hx _, hx.trans_lt)
4445
@[simp] lemma card_Icc : (Icc a b).card = b + 1 - a :=
4546
by rw [←nat.card_Icc, ←map_subtype_embedding_Icc, card_map]
4647

48+
@[simp] lemma card_Ico : (Ico a b).card = b - a :=
49+
by rw [←nat.card_Ico, ←map_subtype_embedding_Ico, card_map]
50+
4751
@[simp] lemma card_Ioc : (Ioc a b).card = b - a :=
4852
by rw [←nat.card_Ioc, ←map_subtype_embedding_Ioc, card_map]
4953

@@ -53,6 +57,9 @@ by rw [←nat.card_Ioo, ←map_subtype_embedding_Ioo, card_map]
5357
@[simp] lemma card_fintype_Icc : fintype.card (set.Icc a b) = b + 1 - a :=
5458
by rw [←card_Icc, fintype.card_of_finset]
5559

60+
@[simp] lemma card_fintype_Ico : fintype.card (set.Ico a b) = b - a :=
61+
by rw [←card_Ico, fintype.card_of_finset]
62+
5663
@[simp] lemma card_fintype_Ioc : fintype.card (set.Ioc a b) = b - a :=
5764
by rw [←card_Ioc, fintype.card_of_finset]
5865

src/data/finset/default.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import data.finset.basic
22
import data.finset.fold
3-
import data.finset.intervals
3+
import data.finset.interval
44
import data.finset.lattice
55
import data.finset.nat_antidiagonal
66
import data.finset.pi

0 commit comments

Comments
 (0)