Skip to content

Commit

Permalink
feat(data/list/count): add lemma count_le_count_map (#11148)
Browse files Browse the repository at this point in the history
Generalises `count_map_map`: for any `f : α → β` (not necessarily injective), `count x l ≤ count (f x) (map f l)`
  • Loading branch information
stuart-presnell committed Dec 31, 2021
1 parent dc57b54 commit b142b69
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/data/list/count.lean
Expand Up @@ -149,8 +149,8 @@ begin
{ simpa }
end

@[simp] lemma count_map_map {α β} [decidable_eq α] [decidable_eq β] (l : list α) (f : α → β)
(hf : function.injective f) (x : α) :
@[simp] lemma count_map_of_injective {α β} [decidable_eq α] [decidable_eq β]
(l : list α) (f : α → β) (hf : function.injective f) (x : α) :
count (f x) (map f l) = count x l :=
begin
induction l with y l IH generalizing x,
Expand All @@ -161,6 +161,15 @@ begin
{ simpa [h, hf.ne h] using IH _ } }
end

lemma count_le_count_map [decidable_eq β] (l : list α) (f : α → β) (x : α) :
count x l ≤ count (f x) (map f l) :=
begin
induction l with a as IH, { simp },
rcases eq_or_ne x a with rfl | hxa,
{ simp [succ_le_succ IH] },
{ simp [hxa, le_add_right IH, count_cons'] }
end

@[simp] lemma count_erase_self (a : α) :
∀ (s : list α), count a (list.erase s a) = pred (count a s)
| [] := by simp
Expand Down

0 comments on commit b142b69

Please sign in to comment.