-
Notifications
You must be signed in to change notification settings - Fork 297
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
fix(algebra/category): make has_coe_to_sort instances for bundled categories reducible #2290
Conversation
…egories reducible
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.
Should we add a linter for this?
Co-Authored-By: Gabriel Ebner <gebner@gebner.org>
... let's see if this is actually the right course before we invest that level of energy. :-) |
…munity/mathlib into has_coe_to_sort_reducible
Sorry, I'm very far from being an expert in reducibility & Lean... I remember that it caused problems when we did the refactoring of concrete categories, but I don't remember any details. |
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.
You've already written this in the "locally reducible category instances" library note:
It's especially important that the
has_coe_to_sort
instance not contain an extraid
as we want thesemiring ↥R
instance to also apply tosemiring R.α
(it seems to be impractical to guarantee that we always accessR.α
through the coercion rather than directly).
This here is exactly the issue we're having with (0 : R) = (0 : R.α)
not being true modulo reducible definitional equality, and hence simp failing to apply obvious lemmas. So I think the change in this PR is the right way to go and also consistent with the existing design.
Another reason to make the has_coe_to_sort
instances reducible is if we ever want to apply the category theory library to actual structures. For examples, if you had an element of the bundled integers x : IntRing
, then you'd want to use it as an element of the unbundled integers x : ℤ
without the simplifier complaining (i.e. ↥IntRing
should be reducibly-definitionally equal to ℤ
).
@@ -44,6 +41,13 @@ to functions, for example. It's especially important that the `has_coe_to_sort` | |||
instance not contain an extra `id` as we want the `semiring ↥R` instance to | |||
also apply to `semiring R.α` (it seems to be impractical to guarantee that | |||
we always access `R.α` through the coercion rather than directly). | |||
|
|||
TODO: Probably @[derive] should be able to create instances of the |
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.
BTW, another option that works is:
instance : concrete_category SemiRing :=
(by apply_instance : concrete_category (bundled semiring))
What would the linter do? Check that all |
Since that is the most common problem here, yes.
What else would you want to check? |
How about that all definitions are reducible? That would solve even more problems with simp, right? :) I think this change is okay but I'm not convinced we are fixing the right problem at the right level. Historically in category theory (e.g. with |
This is a good question. Marking some definitions as reducible can actually be counter-productive. For example, simp lemmas such as Another reason is that a definition might unfold to something "more complex". We can probably write reliable simplification lemmas for the simple definition. But this becomes much harder once it is unfolded and perhaps simplified so that it no longer matches the original definition. I don't think the instances in this PR are problematic in this sense.
I believe it is worthwhile to make simp work.
I think the approach of marking definitions as reducible is the common solution to this kind of problem. If you want the simplifier to unfold a definition during matching, then you typically mark it as reducible. I also thought about adding this simp lemma (and fixing @[simp]
lemma bundled.α_eq_coe (c) (R : bundled c) : R.α = R := rfl Alas, this doesn't work because the simplifier cannot rewrite the |
Just noting that in Lean 3.8 we should be able to reverse this change. #169 there solves this problem. |
Now that Lean 3.8 has arrived, we can essentially revert #2290, but leave in the examples verifying that everything still works. Lovely!
…egories reducible (leanprover-community#2290) * fix(algebra/category): make has_coe_to_sort instances for bundled categories reducible * fix library notes * fix import * Update src/algebra/category/CommRing/basic.lean Co-Authored-By: Gabriel Ebner <gebner@gebner.org> * fix notes Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: Gabriel Ebner <gebner@gebner.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…prover-community#2389) Now that Lean 3.8 has arrived, we can essentially revert leanprover-community#2290, but leave in the examples verifying that everything still works. Lovely!
…egories reducible (leanprover-community#2290) * fix(algebra/category): make has_coe_to_sort instances for bundled categories reducible * fix library notes * fix import * Update src/algebra/category/CommRing/basic.lean Co-Authored-By: Gabriel Ebner <gebner@gebner.org> * fix notes Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: Gabriel Ebner <gebner@gebner.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…prover-community#2389) Now that Lean 3.8 has arrived, we can essentially revert leanprover-community#2290, but leave in the examples verifying that everything still works. Lovely!
…egories reducible (leanprover-community#2290) * fix(algebra/category): make has_coe_to_sort instances for bundled categories reducible * fix library notes * fix import * Update src/algebra/category/CommRing/basic.lean Co-Authored-By: Gabriel Ebner <gebner@gebner.org> * fix notes Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: Gabriel Ebner <gebner@gebner.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…prover-community#2389) Now that Lean 3.8 has arrived, we can essentially revert leanprover-community#2290, but leave in the examples verifying that everything still works. Lovely!
See discussion at https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/unbearable.20unhappiness.20of.20.60simp.60.20not.20working
I have added a
library note
explaining this issue, and put in twoexample
s that ensure correct behaviour.