-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - feat(data/multiset): add some lemmas about filter (eq x) #10626
Conversation
Ruben-VandeVelde
commented
Dec 5, 2021
src/data/multiset/basic.lean
Outdated
begin | ||
ext a, | ||
rw [count_repeat, count_filter], | ||
simp_rw [eq_comm], | ||
split_ifs with ha, | ||
{ subst a }, | ||
{ refl } | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A slight golf:
begin | |
ext a, | |
rw [count_repeat, count_filter], | |
simp_rw [eq_comm], | |
split_ifs with ha, | |
{ subst a }, | |
{ refl } | |
end | |
begin | |
ext a, | |
rw [count_repeat, count_filter], | |
simp_rw [eq_comm, ←dif_eq_if], | |
congr' 1 with rfl, | |
refl, | |
end |
up to you whether you think it's an improvement.
src/data/multiset/basic.lean
Outdated
@@ -2152,6 +2160,20 @@ begin | |||
simp only [count_repeat, eq_self_iff_true, if_true, card_repeat]}, | |||
end | |||
|
|||
lemma filter_eq (s : multiset α) (b : α) : s.filter (eq b) = repeat b (count b s) := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a variant for (= b)
too? Perhaps:
lemma filter_eq' (s : multiset α) (b : α) : s.filter (= b) = repeat b (count b s) :=
begin
ext a,
rw [count_repeat, count_filter],
simp_rw [←dif_eq_if],
congr' 1 with rfl,
refl,
end
lemma filter_eq (s : multiset α) (b : α) : s.filter (eq b) = repeat b (count b s) :=
by { simp_rw [←filter_eq', eq_comm], congr }
which also saves needing eq_comm
in both proofs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, it helped me find an even shorter proof with if_ctx_congr
bors d+ Thanks! |
✌️ Ruben-VandeVelde can now approve this pull request. To approve and merge a pull request, simply reply with |
bors merge |
Co-authored-by: Eric <wieser.eric@gmail.com>
Pull request successfully merged into master. Build succeeded: |