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

Commit 7c523cb

Browse files
committed
feat(data/list/count): partially sync with multiset (#18125)
* rename `list.count_repeat` to `list.count_repeat_self`; * prove `list.count_repeat` with `if .. then .. else` in the RHS.
1 parent 5758ed3 commit 7c523cb

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

archive/100-theorems-list/30_ballot_problem.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ begin
8282
{ rwa ← list.count_eq_length.2 this },
8383
{ exact λ x hx, (this x hx).symm } },
8484
{ rintro rfl,
85-
simp only [mem_set_of_eq, list.count_repeat, eq_self_iff_true, true_and],
85+
simp only [mem_set_of_eq, list.count_repeat_self, eq_self_iff_true, true_and],
8686
refine ⟨list.count_eq_zero_of_not_mem _, λ x, _⟩; rw list.mem_repeat,
8787
{ norm_num },
8888
{ rintro ⟨-, rfl⟩,
@@ -105,7 +105,7 @@ begin
105105
{ rwa ← list.count_eq_length.2 this },
106106
{ exact λ x hx, (this x hx).symm } },
107107
{ rintro rfl,
108-
simp only [mem_set_of_eq, list.count_repeat, eq_self_iff_true, true_and],
108+
simp only [mem_set_of_eq, list.count_repeat_self, eq_self_iff_true, true_and],
109109
refine ⟨list.count_eq_zero_of_not_mem _, λ x, _⟩; rw list.mem_repeat,
110110
{ norm_num },
111111
{ rintro ⟨-, rfl⟩,

src/data/list/count.lean

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,23 @@ lemma not_mem_of_count_eq_zero {a : α} {l : list α} (h : count a l = 0) : a
164164
@[simp] lemma count_eq_length {a : α} {l} : count a l = l.length ↔ ∀ b ∈ l, a = b :=
165165
countp_eq_length _
166166

167-
@[simp] lemma count_repeat (a : α) (n : ℕ) : count a (repeat a n) = n :=
167+
@[simp] lemma count_repeat_self (a : α) (n : ℕ) : count a (repeat a n) = n :=
168168
by rw [count, countp_eq_length_filter, filter_eq_self.2, length_repeat];
169169
exact λ b m, (eq_of_mem_repeat m).symm
170170

171+
lemma count_repeat (a b : α) (n : ℕ) : count a (repeat b n) = if a = b then n else 0 :=
172+
begin
173+
split_ifs with h,
174+
exacts [h ▸ count_repeat_self _ _, count_eq_zero_of_not_mem (mt eq_of_mem_repeat h)]
175+
end
176+
171177
lemma le_count_iff_repeat_sublist {a : α} {l : list α} {n : ℕ} :
172178
n ≤ count a l ↔ repeat a n <+ l :=
173179
⟨λ h, ((repeat_sublist_repeat a).2 h).trans $
174180
have filter (eq a) l = repeat a (count a l), from eq_repeat.2
175181
by simp only [count, countp_eq_length_filter], λ b m, (of_mem_filter m).symm⟩,
176182
by rw ← this; apply filter_sublist,
177-
λ h, by simpa only [count_repeat] using h.count_le a⟩
183+
λ h, by simpa only [count_repeat_self] using h.count_le a⟩
178184

179185
lemma repeat_count_eq_of_count_eq_length {a : α} {l : list α} (h : count a l = length l) :
180186
repeat a (count a l) = l :=

src/data/multiset/basic.lean

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,12 +1790,7 @@ by simp [repeat]
17901790

17911791
theorem count_repeat (a b : α) (n : ℕ) :
17921792
count a (repeat b n) = if (a = b) then n else 0 :=
1793-
begin
1794-
split_ifs with h₁,
1795-
{ rw [h₁, count_repeat_self] },
1796-
{ rw [count_eq_zero],
1797-
apply mt eq_of_mem_repeat h₁ },
1798-
end
1793+
count_repeat a b n
17991794

18001795
@[simp] theorem count_erase_self (a : α) (s : multiset α) :
18011796
count a (erase s a) = pred (count a s) :=

0 commit comments

Comments
 (0)