Zulip Chat Archive
Stream: new members
Topic: Compiler IR check failed
Gareth Ma (Apr 29 2024 at 04:35):
Hello, I don't understand why Polynomial.C
is unknown declaration.
import Mathlib.Algebra.RingQuot
import Mathlib.RingTheory.Ideal.IsPrimary
import Mathlib.RingTheory.Ideal.LocalRing
open Polynomial Ideal
example {R : Type*} [CommRing R] : (R[X] ⧸ (span {X} : Ideal R[X])) ≃+* R where
toFun := fun f ↦ by sorry
invFun := fun f ↦ Quotient.mk _ (C f)
left_inv := by sorry
right_inv := by sorry
map_mul' := by sorry
map_add' := by sorry
Gareth Ma (Apr 29 2024 at 04:36):
(Also, does this exist already? And is there a better way to writing it? It seems Quot
and Quotient
is a bit awkward to work with)
Gareth Ma (Apr 29 2024 at 05:26):
noncomputable example {R : Type*} [CommRing R] : R ≃+* (R[X] ⧸ (span {X} : Ideal R[X])) where
toFun := fun f ↦ Ideal.Quotient.mk _ (C f)
invFun := fun f ↦ by
apply Quot.lift Polynomial.constantCoeff ?_ f
intro f g h
rwa [Submodule.quotientRel_r_def, mem_span_singleton, X_dvd_iff, coeff_sub, sub_eq_zero] at h
left_inv := fun f ↦ by
change constantCoeff (C f) = f
simp
right_inv := fun f ↦ by
apply Quotient.ind ?_ f
intro f
change _ = mk (span {Y}) f
simp [Ideal.Quotient.eq, mem_span_singleton, X_dvd_iff]
map_mul' := fun f g ↦ by simp
map_add' := fun f g ↦ by simp
I finished the proof, plus I still don't understand the issue above. It seems to be related to the fact that I have to add noncomputable
now
Gareth Ma (Apr 29 2024 at 05:28):
(In particular it would be nice for induction
to work for Quot
types using Quotient.ind
- I think mathematically/type-theoretically it's incorrect, but still, it's literally called .ind
)
Riccardo Brasca (Apr 29 2024 at 05:51):
The first one is docs#Polynomial.quotientSpanXSubCAlgEquiv
Riccardo Brasca (Apr 29 2024 at 05:54):
Or at least very close
Gareth Ma (Apr 29 2024 at 05:57):
It seems that AlgEquiv
extends A ≃ B, A ≃* B, A ≃+ B, A ≃+* B
so I should be able to extract the RingEquiv at the end. But
Gareth Ma (Apr 29 2024 at 05:57):
example {R : Type*} [CommRing R] : R ≃+* (R[X] ⧸ (span {X} : Ideal R[X])) := by
have := Polynomial.quotientSpanXSubCAlgEquiv (R := R) 0
rw [C_0, sub_zero] at this
/-
▶ 45:9-45:28: error:
synthesized type class instance is not definitionally equal to expression inferred by typing rules, synthesized
NonUnitalNonAssocRing.toMul
inferred
Equiv.mul this.toEquiv
-/
exact this.ringEquiv.symm
Have I found a type diamond? Or is this a different issue?
Riccardo Brasca (Apr 29 2024 at 05:58):
What does convert
say?
Gareth Ma (Apr 29 2024 at 05:59):
Actually I don't understand why it extends the earlier 3 classes either
Gareth Ma (Apr 29 2024 at 05:59):
convert
gives two goals, but also throws the same error:
⊢ NonUnitalNonAssocRing.toMul = Equiv.mul this.toEquiv
⊢ Distrib.toAdd = Equiv.add this.toEquiv
Riccardo Brasca (Apr 29 2024 at 05:59):
Ah sorry, the error is at rw
Riccardo Brasca (Apr 29 2024 at 05:59):
Right?
Gareth Ma (Apr 29 2024 at 05:59):
Nono
Gareth Ma (Apr 29 2024 at 05:59):
The exact
Gareth Ma (Apr 29 2024 at 05:59):
My bad
Gareth Ma (Apr 29 2024 at 06:00):
Found something interesting.
have := this.ringEquiv /- this is "ok", but gives
this : let add := Equiv.add this✝.toEquiv;
let mul := Equiv.mul this✝.toEquiv;
R[X] ⧸ span {Y - C 0} ≃+* R
-/
have := this.ringEquiv.symm /- this fails with the same synthesizer error
Riccardo Brasca (Apr 29 2024 at 06:01):
Well, the problem is probably that rw
is modifying the objects you are working on, but not all the instances, and this confuses Lean
Riccardo Brasca (Apr 29 2024 at 06:01):
I don't think it is a diamond.
Gareth Ma (Apr 29 2024 at 06:02):
No, the rw
is irrelevant, see this:
def asdf {R : Type*} [CommRing R] : false := by
have := Polynomial.quotientSpanXSubCAlgEquiv (R := R) 37
have := this.ringEquiv /- works -/
have := this.ringEquiv.symm /- fails -/
Gareth Ma (Apr 29 2024 at 06:03):
I've got to go, but thanks for the help. I can dig around a bit more later but I don't know how far I can get :tear:
Riccardo Brasca (Apr 29 2024 at 06:03):
Can you write a #mwe? Anyway I need a computer to debug this (I will have access to one later today)
Gareth Ma (Apr 29 2024 at 06:05):
MWE is just this:
import Mathlib.Algebra.RingQuot
import Mathlib.RingTheory.Ideal.IsPrimary
import Mathlib.RingTheory.Ideal.LocalRing
open Polynomial Ideal
def asdf {R : Type*} [CommRing R] : false := by
have := Polynomial.quotientSpanXSubCAlgEquiv (R := R) 37
have := this.ringEquiv
have := this.ringEquiv.symm
Riccardo Brasca (Apr 29 2024 at 06:12):
There are 2 .ringEquiv
Yaël Dillies (Apr 29 2024 at 06:14):
The this
in the third have
refers to the second have
, not the first
Gareth Ma (Apr 29 2024 at 06:15):
My bad, but it's still not fixed :(
def asdf {R : Type*} [CommRing R] : false := by
have yael := Polynomial.quotientSpanXSubCAlgEquiv (R := R) 37
have := yael.ringEquiv
have := yael.ringEquiv.symm
Gareth Ma (Apr 29 2024 at 06:16):
(I think {line 1}.ringEquiv = {line 2}.ringEquiv = {line 2} anyways)
Riccardo Brasca (Apr 29 2024 at 06:23):
You are using have
instead of let
maybe?
Riccardo Brasca (Apr 29 2024 at 06:26):
Yes, this is the problem.
import Mathlib.Algebra.RingQuot
import Mathlib.RingTheory.Ideal.IsPrimary
import Mathlib.RingTheory.Ideal.LocalRing
open Polynomial Ideal
noncomputable
def asdf {R : Type*} [CommRing R] : R ≃+* (R[X] ⧸ (span {X} : Ideal R[X])) := by
let f := Polynomial.quotientSpanXSubCAlgEquiv (R := R) 0
rw [C_0, sub_zero] at f
exact f.toRingEquiv.symm
works.
Riccardo Brasca (Apr 29 2024 at 06:26):
It's not really idiomatic since we try to avoid using tactic mode to write definitons, but still.
Gareth Ma (Apr 29 2024 at 06:28):
Ah but .ringEquiv
still fails
Riccardo Brasca (Apr 29 2024 at 06:28):
It's called toRingEquiv
Gareth Ma (Apr 29 2024 at 06:29):
Ah .ringEquiv
just tries to access one of the underlying inherited typeclasses(?)' ringEquiv
, which is just wrong. Okay, makes sense. Thanks!!
Gareth Ma (Apr 29 2024 at 06:29):
Learned a lot :D
Bolton Bailey (Apr 29 2024 at 18:44):
I encountered a similar problem recently. I think it should be considered a bug for Lean to be able to say "unknown declaration" immediately after a #check
statement that confirms the declaration is present in the context.
Bolton Bailey (Apr 29 2024 at 18:48):
lean4#1785 deals with this issue. I encourage people to upvote it if they agree it should be fixed.
Gareth Ma (Apr 30 2024 at 05:19):
IR check failed in presence of noncomputable
Yep I think that's one of the problem originally, upvoted :)
Last updated: May 02 2025 at 03:31 UTC