Repository navigation
feat: QuotType - #30668
feat: QuotType#30668astrainfinita wants to merge 37 commits into
QuotType#30668Conversation
Comments from Original PR #16421This section contains 1 comment(s) from the original PR, excluding bot comments. @YaelDillies (2024-11-02 15:10 UTC): |
PR summary d7c8cc9054Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
vihdzp
left a comment
There was a problem hiding this comment.
This new design seems really good. I agree that using ⟦x⟧ with any type that isn't syn-eq to Quotient r just leads to trouble, and having to duplicate basic quotient API for every new quotient type is quite annoying. I do have a few questions about this design, however.
| scoped instance {α} [s : Setoid α] : QuotLike.HasQuot (Quotient s) α (· ≈ ·) where | ||
| ``` | ||
| -/ | ||
| class HasQuot (Q : outParam Sort*) (α : Sort*) (r : outParam (α → α → Prop)) |
There was a problem hiding this comment.
Why do we need this, as well as QuotLike? And why do we need both the ⟦x⟧ notation as well as the mkQ' x notation?
There was a problem hiding this comment.
Why do we need this, as well as
QuotLike?
This actually provides a quotient map notation similar to Lean3, where the meaning of ⟦(x : A)⟧ is determined by searching the typeclass Setoid A (like Quotient.mk' in Lean4). That is, sometimes the output type may be unavailable, or the quotient map cannot be determined from the output type. In such cases, using a (maybe local or scoped) instance of this typeclass can help.
And why do we need both the
⟦x⟧notation as well as themkQ' xnotation?
It's simply because this makes ⟦x⟧ the notation for the term mkQ x (without a custom term elaborator). I forget if only using the ⟦x⟧ notation would cause any problems, but if it doesn't, then we may make ⟦x⟧ try to find the quotient map using the input type on failure.
| instance (p : Submodule R M) : QuotLike.Hint p (M ⧸ p) M p.quotientRel where | ||
| ``` | ||
| -/ | ||
| class Hint {Hint : Sort*} (hint : Hint) |
There was a problem hiding this comment.
I don't understand, what is the hint used for, and how is it used?
There was a problem hiding this comment.
For quotient groups, quotient rings, and quotient modules, we need to know the subobjects used to distinguish different quotient objects. For example, we would write ⟦(x : M)⟧_p : M ⧸ p. Perhaps this shouldn't be called a hint, but I haven't come up with a better name.
There was a problem hiding this comment.
This is an interesting design. I do wonder if we could get away with just writing (⟦x⟧ : M ⧸ p), though.
There was a problem hiding this comment.
My idea is to replace all existing quotient maps with the new notations. IIRC we need more type annotations than before without hinted notation. But maybe we can split the notation into another PR and give it a try. (upd: removed this part)
|
|
||
| /-- The canonical quotient map. Inferred from the hint via typeclass `QuotLike.Hint` or | ||
| the hint and the input type via typeclass `QuotLike.HasQuotHint`. -/ | ||
| syntax:max (name := mkQ_) "mkQ_" term:max : term |
There was a problem hiding this comment.
mkQ' and mkQ_ have very weird names. Are they supposed to be implementation details, or proper public API? In the former case I'd like the docstrings to explain this; in the latter I'd like to come up with better names for this.
There was a problem hiding this comment.
I've already explained the purpose of these notations in the module docstring.
| fun h ↦ Quot.exact (eq_iff_quotMk.mp h) | ||
|
|
||
| @[simp] | ||
| theorem eq [IsEquiv α r] {a b : α} : (⟦a⟧ : Q) = ⟦b⟧ ↔ r a b := |
There was a problem hiding this comment.
I don't believe this should be a simp theorem. The reason we often work with quotients is because equality is nicer to reason about than an arbitrary equivalence relation; this theorem only helps to undo this.
I don't think Quotient.eq should be simp either, but that's a question for another time.
There was a problem hiding this comment.
But at the same time, this is about any equality in the quotient, this is about equality of two values of the quotient map. This lemma looks like a good simp lemma to me
There was a problem hiding this comment.
Fair enough. I guess we can make it simp and later see if it causes any problems.
|
This pull request has conflicts, please merge |
| @[inherit_doc mkQ] | ||
| elab "⟦" a:term "⟧" : term <= Q => do |
There was a problem hiding this comment.
When attempting to replace existing mathlib APIs with QuotType, I discovered that Lean attempts to synthesize QuotType (SomeQuotientOf α) (Subtype (_ : α → Prop)) ?_. The original API could automatically insert the coercion.
I don't know if this can be considered a core issue. (AFAIK core is unlikely to change features related to typeclasses now) I'm also not sure if this issue is worth resolving. But I made this elaborator to ensure that the quotient map is derived from the output type.
There was a problem hiding this comment.
Can we not use Eq.ndrec? It doesn't have as many theorems about it as Eq.rec.
There was a problem hiding this comment.
Quot.rec and Quotient.rec use Eq.ndrec, so I used it too. Did it cause trouble in mathlib?
|
@astrainfinita what's the status here, is the discussion stuck on something in particular? What is the relation to #30750? |
|
(these are mostly unrelated, but #30750 defines stuff twice for |
|
What are we waiting on here? |
This typeclass is primarily for use by type synonyms of
QuotandQuotient. UsingQuotTypeAPI for type synonyms ofQuotandQuotientwill avoid defeq abuse caused by directly usingQuotandQuotientAPIs.This PR also adds some typeclasses to support different ways to find the quotient map that should be used. See the documentation comments of these typeclasses for examples of usage.
It's not a typical design to use these auxiliary typeclasses and term elaborators, but I haven't found a better way to support these notations.
Some of the naming may need to be discussed. For example:
⟦·⟧is currently calledmkQin names. This distinguishes it from other.mks and makes it possible to write the quotient map asmkQmkQ'. But this will also require changing the old lemma names.mkQ_ hIt would be helpful if the names of new type classes explained their functionality better.
awaiting-zulip: https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/migrate.20to.20.60QuotLike.60.20API
This PR continues the work from #16421.
Original PR: #16421