Zulip Chat Archive
Stream: new members
Topic: Typeclass synthesis fails with extra assumption
Dion Leijnse (Jan 14 2026 at 10:50):
In the following code, Lean fails to infer the instance Algebra R (myQuot R I) in the last lemma, and the problem seems to be due to adding the assumption that R is a field. What is going on here, and how can I access the algebra structures in lemmas where I require R to be a field?
import Mathlib
variable (R : Type) [CommRing R]
variable (I : Ideal R)
def myQuot : Type :=
R ⧸ I
deriving CommRing, Algebra R
lemma test1 : algebraMap R (myQuot R I) 1 = 1 := by sorry
lemma test2 [Field R] : algebraMap R (myQuot R I) 1 = 1 := by sorry
-- failed to synthesize instance of type class Algebra R (myQuot R I)
Riccardo Brasca (Jan 14 2026 at 10:51):
You both have CommRing R and Field R, so now you have two (totally unrelated) ring structure on R.
Dion Leijnse (Jan 14 2026 at 10:51):
Thanks! So the way to go is to add an assumption IsField R?
Riccardo Brasca (Jan 14 2026 at 10:52):
You can do something like
import Mathlib
variable (R : Type)
section CommRing
variable [CommRing R] (I : Ideal R)
def myQuot : Type :=
R ⧸ I
deriving CommRing, Algebra R
lemma test1 : algebraMap R (myQuot R I) 1 = 1 := by sorry
end CommRing
section Field
variable [Field R] (I : Ideal R)
lemma test2 : algebraMap R (myQuot R I) 1 = 1 := by sorry
end Field
Riccardo Brasca (Jan 14 2026 at 10:53):
Also using IsField is OK.
Riccardo Brasca (Jan 14 2026 at 10:53):
It depends a little on what you want to do (do you really want to speak about an ideal of a field?)
Dion Leijnse (Jan 14 2026 at 10:54):
Riccardo Brasca said:
It depends a little on what you want to do (do you really want to speak about an ideal of a field?)
No, but this was a MWE extracted from something more complicated (where R is a polynomial ring over a field)
Dion Leijnse (Jan 14 2026 at 10:55):
Riccardo Brasca said:
You can do something like
import Mathlib variable (R : Type) section CommRing variable [CommRing R] (I : Ideal R) def myQuot : Type := R ⧸ I deriving CommRing, Algebra R lemma test1 : algebraMap R (myQuot R I) 1 = 1 := by sorry end CommRing section Field variable [Field R] (I : Ideal R) lemma test2 : algebraMap R (myQuot R I) 1 = 1 := by sorry end Field
Thanks, this does indeed look like a better solution (because it would be nice to just use the instance Field R where I work with it).
Riccardo Brasca (Jan 14 2026 at 10:57):
A maybe more elegant solution is just to declare R and K at the beginning, with the relevant assumptions.
Last updated: Feb 28 2026 at 14:05 UTC