Zulip Chat Archive
Stream: mathlib4
Topic: RingHomClass
Kenny Lau (Nov 03 2025 at 14:42):
Should Localization.localRingHom take a RingHomClass?
Aaron Liu (Nov 03 2025 at 14:51):
no
Aaron Liu (Nov 03 2025 at 14:51):
and Ideal.comap should not take a RingHomClass
Aaron Liu (Nov 03 2025 at 14:51):
it should take a plain RingHom
Kenny Lau (Nov 03 2025 at 14:51):
but you could comap a RingEquiv
Aaron Liu (Nov 03 2025 at 14:53):
and then you need a lemma docs#Ideal.comap_coe
Aaron Liu (Nov 03 2025 at 14:53):
and you need to use it backwards sometimes often
Kenny Lau (Nov 03 2025 at 14:54):
but you would need to coerce it a lof of times
Aaron Liu (Nov 03 2025 at 14:55):
I can't seem to find the corresponding lemma for docs#Ideal.map
Kenny Lau (Nov 03 2025 at 14:55):
Aaron Liu (Nov 03 2025 at 14:55):
and we have stuff like docs#Ideal.map_comap_of_equiv
Aaron Liu (Nov 03 2025 at 14:56):
it's stated for the coe on the one side and not coe on the other side
Aaron Liu (Nov 03 2025 at 14:56):
it's probably better to be consistent and have it all coe all the time
Kenny Lau (Nov 03 2025 at 14:56):
I see we haven't picked a simpNF too
Aaron Liu (Nov 03 2025 at 14:57):
Kenny Lau said:
that's stated for a RingHomClass what if I don't have a RingHomClass
Kenny Lau (Nov 03 2025 at 14:59):
I don't understand
Aaron Liu (Nov 03 2025 at 15:01):
import Mathlib
example {R : Type*} [Semiring R] (I : Ideal Nat) :
I.map (Nat.castAddMonoidHom R) = I.map (Nat.castRingHom R) := by
-- is there a better way
rfl
Kenny Lau (Nov 03 2025 at 15:02):
oh, I didn't know Ideal.map takes FunLike...
Kenny Lau (Nov 03 2025 at 15:02):
perhaps it should only take RingHomClass?
Aaron Liu (Nov 03 2025 at 15:05):
@Yaël Dillies back me up here
Andrew Yang (Nov 03 2025 at 15:07):
The rule of thumb is that definitions shouldn't take *HomClass. We don't want ker f and ker f.toRingHom to be different things.
Kenny Lau (Nov 03 2025 at 15:08):
by that do you include Prop?
Kenny Lau (Nov 03 2025 at 15:09):
such as RingHom.Finite (which currently takes RingHom)
Andrew Yang (Nov 03 2025 at 15:09):
For example docs#IsLocalHom is bad, as IsLocalHom f and IsLocalHom f.toRingHom isn't even defeq.
Kenny Lau (Nov 03 2025 at 15:10):
what should it take then?
Aaron Liu (Nov 03 2025 at 15:11):
a plain function?
Aaron Liu (Nov 03 2025 at 15:11):
what's the weakest context this is interesting in?
Aaron Liu (Nov 03 2025 at 15:11):
maybe a monoid hom?
Kenny Lau (Nov 03 2025 at 15:11):
I thought functions are bad
Kenny Lau (Nov 03 2025 at 15:11):
yeah, but it's "intended" to be used with ring homs
Andrew Yang (Nov 03 2025 at 15:11):
Probably a plain function in this case. See #24965
Kenny Lau (Nov 03 2025 at 15:12):
I thought functions are difficult to unify
Aaron Liu (Nov 03 2025 at 15:12):
what does that mean?
Aaron Liu (Nov 03 2025 at 15:12):
are you talking about higher order unification?
Kenny Lau (Nov 03 2025 at 15:13):
I'm talking about how we moved away from IsRingHom f
Aaron Liu (Nov 03 2025 at 15:13):
oh that's for when you're applying them in lemmas
Aaron Liu (Nov 03 2025 at 15:14):
are there lemmas that work for IsLocalHom f even if f is a plain function?
Kenny Lau (Nov 03 2025 at 15:14):
isUnit_of_map_unit, basically the one in its definition
Aaron Liu (Nov 03 2025 at 15:14):
so only one
Kenny Lau (Nov 03 2025 at 15:14):
Aaron Liu (Nov 03 2025 at 15:14):
then that one lemma might have trouble unifying
Kenny Lau (Nov 03 2025 at 15:14):
Aaron Liu (Nov 03 2025 at 15:15):
Kenny Lau said:
MonoidHomClass not plain function
Aaron Liu (Nov 03 2025 at 15:15):
Kenny Lau said:
(same as above) MonoidHomClass
Aaron Liu (Nov 03 2025 at 15:15):
I'm starting to think it should take a MonoidHom
Kenny Lau (Nov 03 2025 at 15:15):
but do they not suffer from the same problem?
Kenny Lau (Nov 03 2025 at 15:16):
I still think it should take RingHom
Kenny Lau (Nov 03 2025 at 15:16):
at the cost of some lemmas not being in the "maximum generality"
Aaron Liu (Nov 03 2025 at 15:16):
Kenny Lau said:
but do they not suffer from the same problem?
well it's a MonoidHomClass therefore not a plain function, so no, it doesn't have the same problem
Aaron Liu (Nov 03 2025 at 15:17):
the problem only applies to plain functions given as fun x => ...
Kenny Lau (Nov 03 2025 at 15:17):
Aaron Liu said:
Kenny Lau said:
but do they not suffer from the same problem?
well it's a
MonoidHomClasstherefore not a plain function, so no, it doesn't have the same problem
if you use Irreducible.of_map and you try to prove x is irreducible, then you apply this lemma, then Lean has to solve Irreducible (?f x)
Aaron Liu (Nov 03 2025 at 15:17):
no, Lean has to solve Irreducible (DFunLike.coe ?f x)
Kenny Lau (Nov 03 2025 at 15:17):
aha! ok that makes sense
Kenny Lau (Nov 03 2025 at 16:43):
AlgEquiv.ofBijective takes A₁ →ₐ[R] A₂ while RingEquiv.ofBijective takes NonUnitalRingHomClass F R S; which one is correct?
Aaron Liu (Nov 03 2025 at 16:43):
AlgEquiv.ofBijective is correct
Aaron Liu (Nov 03 2025 at 16:44):
since you're making data
Kenny Lau (Nov 03 2025 at 16:45):
but I would say that this is a case where you don't need to be concerned about equality / lemma since for this case you probably just want the equiv? as in you just use this as auxiliary
Kenny Lau (Nov 03 2025 at 16:48):
I would argue that the non-API results that show up in the search above are actually wrong
Kenny Lau (Nov 03 2025 at 16:48):
.ofBijective is not meant to be any simp NF
Aaron Liu (Nov 03 2025 at 16:52):
Kenny Lau said:
but I would say that this is a case where you don't need to be concerned about equality / lemma since for this case you probably just want the equiv? as in you just use this as auxiliary
what do you mean by this?
Kenny Lau (Nov 03 2025 at 16:53):
it is not simp NF, so it does not matter that you have two ways of writing like .ofBijective f vs. .ofBijective \u f
Kenny Lau (Nov 03 2025 at 16:53):
its use is to construct new equivs, and then those new equivs are the simpNFs
Aaron Liu (Nov 03 2025 at 16:54):
you still run into the problem of .ofBijective f ⋯ and .ofBijective f.toRingHom ⋯ being different
Kenny Lau (Nov 03 2025 at 16:55):
that is fine, because neither is simpNF
Aaron Liu (Nov 03 2025 at 16:55):
but you will still sometimes have to convert between them
Kenny Lau (Nov 03 2025 at 16:56):
lemme put more pseudocode to make my point clearer:
def foo : AlgHom := ...
def fooEquiv1 : RingEquiv := .ofBijective foo
def fooEquiv2 : RingEquiv := .ofBijective (\u foo)
in this code, fooEquiv1 and fooEquiv2 might not be defeq (i suspect they could be), but that's fine because the simpNF of fooEquiv[12] x is actually foo x
Aaron Liu (Nov 03 2025 at 16:56):
I don't see the lemma that lets me do this
Kenny Lau (Nov 03 2025 at 16:57):
and I argue that this is the only intended use case of .ofBijective
Aaron Liu (Nov 03 2025 at 16:58):
I have an example for you too
Aaron Liu (Nov 03 2025 at 17:03):
I guess making it take just a NonUnitalRingHom doesn't really solve this problem but
def foo : RingHom := ...
def fooAlgHom : AlgHom := { foo with ... }
@[simp] toRingHom_fooAlgHom := ...
def fooRingEquiv : RingEquiv := .ofBijective fooAlgHom <| ...
theorem foo_bar : Bar foo := by
...
-- goal is something complicated containing `fooAlgHom (fooRingEquiv.symm x)`
simp [fooRingEquiv]
-- goal now contains `foo ((RingEquiv.ofBijective fooAlgHom ...).symm x)`
-- which doesn't simplify
Kenny Lau (Nov 03 2025 at 17:05):
you've done something wrong as soon as you see ofBijective in the goal
Aaron Liu (Nov 03 2025 at 17:05):
what's wrong with unfolding your definitions while you prove theorems about them
Kenny Lau (Nov 03 2025 at 17:06):
why would you need to unfold fooRingEquiv?
- "I need to use the fact that it's a ring equiv": it's a ring equiv already
- "I need to simplify its application": that's given by
foo x
Aaron Liu (Nov 03 2025 at 17:07):
Kenny Lau said:
- "I need to simplify its application": that's given by
foo x
I don't understand what you mean?
Kenny Lau (Nov 03 2025 at 17:07):
the simpNF of fooRingEquiv x is foo x, and any property you need can be derived there
Aaron Liu (Nov 03 2025 at 17:07):
it's symm
Kenny Lau (Nov 03 2025 at 17:08):
fooRingEquiv.symm x is the simpNF, you gain nothing by unfolding it into ofBijective, because you can't write down its inverse anyway
Aaron Liu (Nov 03 2025 at 17:08):
I guess with the ofBijective constructors they would reduce to Equiv.ofBijective
Aaron Liu (Nov 03 2025 at 17:08):
Kenny Lau said:
fooRingEquiv.symm xis the simpNF, you gain nothing by unfolding it into ofBijective, because you can't write down its inverse anyway
want to cancel it with a foo
Aaron Liu (Nov 03 2025 at 17:09):
I guess this example is a bit contrived
Kenny Lau (Nov 03 2025 at 17:09):
we need the API that it cancels with foo then...
Aaron Liu (Nov 03 2025 at 17:09):
but the idea is there
Kenny Lau (Nov 03 2025 at 17:09):
which again goes back to the hom_lemmas proposal
Kenny Lau (Nov 03 2025 at 17:09):
Kenny Lau said:
we need the API that it cancels with
foothen...
and if you want to apply functions to it, that's another proposal that has been discussed (similar to reassoc)
Kenny Lau (Nov 03 2025 at 17:10):
ofBijective is never part of the (end result of the) API
Aaron Liu (Nov 03 2025 at 17:11):
I don't want to come up with another more complicated example that addresses all your points
Aaron Liu (Nov 03 2025 at 17:12):
what's the benefit you're getting from making it take a FunLike?
Kenny Lau (Nov 03 2025 at 17:13):
hmm, good point
Kenny Lau (Nov 03 2025 at 17:13):
yeah there's no need to take anything in a higher hierarchy because at that point you would just use a higher ofBijective
Kenny Lau (Nov 03 2025 at 17:23):
so, we need to fix:
- RingHom.ker
Ideal.map- Ideal.comap
- RingEquiv.ofHomInv
- Ideal.mapHom
- Ideal.orderEmbeddingOfSurjective
- Ideal.relIsoOfBijective
- Ideal.giMapComap
- Ideal.relIsoOfSurjective
- DirectLimit.Ring.of ?
- DirectLimit.Ring.lift ?
- RatFunc.mapRingHom
Aaron Liu (Nov 03 2025 at 17:25):
is this only the RingHoms?
Aaron Liu (Nov 03 2025 at 17:26):
for example, I don't see LinearMap.ker on here
Kenny Lau (Nov 03 2025 at 17:26):
it's not all, i only did RingHomClass
Kenny Lau (Nov 07 2025 at 15:09):
https://loogle.lean-lang.org/?q=RingHom.codRestrict
RingHom.codRestrict :clipboard: Mathlib.Algebra.Ring.Subsemiring.Basic
{R : Type u} {S : Type v} [NonAssocSemiring R] [NonAssocSemiring S] {σS : Type u_2} [SetLike σS S] [SubsemiringClass σS S] (f : R →+* S) (s : σS) (h : ∀ (x : R), f x ∈ s) : R →+* ↥s
Should this take Subsemiring instead of class?
Kenny Lau (Nov 07 2025 at 16:43):
Also, should we consider this a consensus that with definitions we prefer e.g. RingHom over e.g. RingHomClass? And then we can reference this consensus in future PR's?
Jireh Loreaux (Nov 07 2025 at 18:00):
@Kenny Lau and @Aaron Liu : I at some point promised this to you: #mathlib4 > Mathlib's morphism hierarchy
Last updated: Dec 20 2025 at 21:32 UTC