@@ -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 :=
165165countp_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 :=
168168by 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+
171177lemma 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
179185lemma repeat_count_eq_of_count_eq_length {a : α} {l : list α} (h : count a l = length l) :
180186 repeat a (count a l) = l :=
0 commit comments