Zulip Chat Archive
Stream: mathlib4
Topic: debugging TC synth failure
Johan Commelin (Mar 22 2024 at 14:19):
Can someone recommend a next step in debugging this failure? (This is from a branch...)
instance (X : Cα΅α΅) : RingHomId (R.map (π X)) where
eq_id := by rw [R.map_id X]; rfl
instance (X : Cα΅α΅) : RingHomId (R.map (π X)) := inferInstance -- works
set_option trace.Meta.synthInstance true
@[simp]
theorem map_id (P : PresheafOfModules R) (X : Cα΅α΅) :
P.map (π X) = LinearMap.id' := by
-- failed to synthesize instance RingHomId β(R.map (π X))
ext
simp
-- [Meta.synthInstance] β RingHomId β(R.map (π X)) βΌ
-- [] no instances for RingHomId β(R.map (π X)) βΌ
-- [instances] #[]
Johan Commelin (Mar 22 2024 at 14:28):
In particular, how can I get more info from Lean why it thinks there are no instances? Clearly there is an instance a few lines up. (And this instance works when provided manually.)
Adam Topaz (Mar 22 2024 at 14:35):
your code seems to work as is for me?
Johan Commelin (Mar 22 2024 at 15:34):
Right, because I didn't give you my branch. I'll push it now.
Johan Commelin (Mar 22 2024 at 15:34):
Matthew Ballard (Mar 22 2024 at 15:37):
Whatβs the imports?
Johan Commelin (Mar 22 2024 at 15:42):
The problem occurs halfway the file Mathlib/Algebra/Category/ModuleCat/Presheaf.lean
on that branch.
Matthew Ballard (Mar 22 2024 at 15:52):
It is trying to coerce from a ring hom whereas the instance is coercing from a function.
Johan Commelin (Mar 22 2024 at 15:55):
Can you tell me how you found that?
Matthew Ballard (Mar 22 2024 at 15:58):
Expanding the term coming from the instance and expanding what was expected at the failure
Matthew Ballard (Mar 22 2024 at 15:59):
I canβt really dig anymore at the moment
Johan Commelin (Mar 22 2024 at 16:04):
Ok, I think I understand what you mean:
- the instance is using
RingCat.instFunLike
under the hood, whereas - the failure expects something using
RingHom.instFunLike
.
Those two are defeq, but Lean probably doesn't get a chance to realize that.
Matthew Ballard (Mar 22 2024 at 16:06):
Oh right! Sorry \to
and \hom
look almost the same now in nvim
Johan Commelin (Mar 22 2024 at 16:58):
I guess this note is relevant:
instance instFunLike {X Y : RingCat} : FunLike (X βΆ Y) X Y :=
-- Note: this is apparently _not_ defeq to RingHom.instFunLike with reducible transparency
ConcreteCategory.instFunLike
Johan Commelin (Mar 22 2024 at 16:59):
And I should point out:
example (R S : RingCat) : @RingCat.instFunLike R S = RingHom.instFunLike := rfl -- works
Adam Topaz (Mar 22 2024 at 16:59):
Can we just put Homs of RingCat et al. in a structure wrapper already?
Johan Commelin (Mar 22 2024 at 17:01):
Part of me is a bit sad if that is necessary, but maybe it's the path of least resistance.
Adam Topaz (Mar 22 2024 at 17:02):
The path of more resistance would be to unbundle homs from Category
.
Adam Topaz (Mar 22 2024 at 17:03):
or maybe make certain things reducible in a clever way which isn't obvious to me.
Johan Commelin (Mar 22 2024 at 17:12):
This works, but it's an ugly convert
hack.
diff --git a/Mathlib/Algebra/Category/ModuleCat/Presheaf.lean b/Mathlib/Algebra/Category/ModuleCat/Presheaf.lean
index 572cc07091..6a36a907ec 100644
--- a/Mathlib/Algebra/Category/ModuleCat/Presheaf.lean
+++ b/Mathlib/Algebra/Category/ModuleCat/Presheaf.lean
@@ -62,37 +62,22 @@ theorem map_apply (P : PresheafOfModules R) {X Y : Cα΅α΅} (f : X βΆ Y) (x) :
P.map f x = (P.presheaf.map f) x :=
rfl
-instance (X : Cα΅α΅) : RingHomId (R.map (π X)) where
+instance ringHomId (X : Cα΅α΅) : RingHomId (R.map (π X)) where
eq_id := by rw [R.map_id X]; rfl
-instance {X Y Z : Cα΅α΅} (f : X βΆ Y) (g : Y βΆ Z) :
+instance ringHomCompTriple {X Y Z : Cα΅α΅} (f : X βΆ Y) (g : Y βΆ Z) :
RingHomCompTriple (R.map f) (R.map g) (R.map (f β« g)) where
comp_eq := by rw [R.map_comp f g]; rfl
@[simp]
theorem map_id (P : PresheafOfModules R) (X : Cα΅α΅) :
- P.map (π X) = LinearMap.id' := by
+ P.map (π X) = by convert LinearMap.id'; apply ringHomId := by
ext
simp
@[simp]
theorem map_comp (P : PresheafOfModules R) {X Y Z : Cα΅α΅} (f : X βΆ Y) (g : Y βΆ Z) :
- P.map (f β« g) = (P.map g).comp (P.map f) := by
+ P.map (f β« g) = by convert (P.map g).comp (P.map f); apply ringHomCompTriple := by
ext
simp
Adam Topaz (Mar 22 2024 at 17:14):
I suppose RingHom.comp (P.map g) (P.map f)
should also work instead of convert ...
?
Matthew Ballard (Mar 22 2024 at 17:14):
Got a little time. Let me poke at the reducible and instances defeq failure
Johan Commelin (Mar 22 2024 at 17:15):
I opened #11590 with this changes.
Johan Commelin (Mar 22 2024 at 17:15):
Feel free to push to that branch
Johan Commelin (Mar 22 2024 at 17:15):
The goal is to refactor RingHomCompTriple
so that it no longer talks about ring homs, but just any functions. Then the infrastructure can be reused for other kinds of equivariant homs.
Johan Commelin (Mar 22 2024 at 17:16):
@Antoine Chambert-Loir needs something like that for #6057
Matthew Ballard (Mar 22 2024 at 17:16):
It wonβt unfold CategoryTheory.forget RingCat
Matthew Ballard (Mar 22 2024 at 17:20):
Strange
Matthew Ballard (Mar 22 2024 at 17:23):
Here is a default transparency successful trace
[Meta.isDefEq] β
RingCat.instFunLike =?= RingHom.instFunLike βΌ
[] β
RingCat.instFunLike =?= { coe := fun f β¦ f.toFun, coe_injective' := β― } βΌ
[] β
CategoryTheory.ConcreteCategory.instFunLike =?= { coe := fun f β¦ f.toFun, coe_injective' := β― } βΌ
[] β
{ coe := fun f β¦ (CategoryTheory.forget RingCat).map f,
coe_injective' := β― } =?= { coe := fun f β¦ f.toFun, coe_injective' := β― } βΌ
[] β
fun f β¦ (CategoryTheory.forget RingCat).map f =?= fun f β¦ f.toFun βΌ
[] β
R βΆ S =?= βR β+* βS βΌ
[] β
CategoryTheory.CategoryStruct.toQuiver.1 R S =?= βR β+* βS βΌ
[] β
CategoryTheory.BundledHom.MapHom SemiRingCat.AssocRingHom (@Ring.toSemiring) R.str S.str =?= βR β+* βS βΌ
[] β
SemiRingCat.AssocRingHom βR βS =?= βR β+* βS βΌ
[] β
βR β+* βS =?= βR β+* βS
[] β
(CategoryTheory.forget RingCat).map f =?= f.toFun βΌ
[] β
(CategoryTheory.forget RingCat).toPrefunctor.2 f =?= (ββf).1 βΌ
[] β
(CategoryTheory.BundledHom.bundledHomOfParentProjection SemiRingCat.AssocRingHom @Ring.toSemiring).toFun R.str S.str
f =?= (ββf).1 βΌ
[] β
(CategoryTheory.BundledHom.bundledHomOfParentProjection SemiRingCat.AssocRingHom @Ring.toSemiring).1 R.str S.str
f =?= (ββf).1 βΌ
[] β
SemiRingCat.bundledHom.toFun Ring.toSemiring Ring.toSemiring f =?= (ββf).1 βΌ
[] β
SemiRingCat.bundledHom.1 Ring.toSemiring Ring.toSemiring f =?= (ββf).1 βΌ
[] β
βf =?= (ββf).1 βΌ
[] β
RingHom.instFunLike.1 f =?= (ββf).1 βΌ
[] β
f.toFun =?= (ββf).1 βΌ
[] β
(ββf).1 =?= (ββf).1 βΌ
[] β
ββf =?= ββf βΌ
[] β
(βf).1 =?= (βf).1 βΌ
[] β
βf =?= βf βΌ
[] β
f.1 =?= f.1
[] β
R βΆ S =?= βR β+* βS
[] β
(CategoryTheory.forget RingCat).obj R =?= βR βΌ
[] β
(CategoryTheory.forget RingCat).toPrefunctor.1 R =?= R.1 βΌ
[] β
βR =?= R.1 βΌ
[] β
R.1 =?= R.1
[] β
fun x β¦ (CategoryTheory.forget RingCat).obj S =?= fun x β¦ βS βΌ
[] β
(CategoryTheory.forget RingCat).obj R =?= βR
[] β
(CategoryTheory.forget RingCat).obj S =?= βS βΌ
[] β
(CategoryTheory.forget RingCat).toPrefunctor.1 S =?= S.1 βΌ
[] β
βS =?= S.1 βΌ
[] β
S.1 =?= S.1
Matthew Ballard (Mar 22 2024 at 17:26):
Versus the unsuccessful with_reducible_and_instances rfl
[Meta.isDefEq] β RingCat.instFunLike =?= RingHom.instFunLike βΌ
[] β RingCat.instFunLike =?= { coe := fun f β¦ f.toFun, coe_injective' := β― } βΌ
[] β CategoryTheory.ConcreteCategory.instFunLike =?= { coe := fun f β¦ f.toFun, coe_injective' := β― } βΌ
[] β { coe := fun f β¦ (CategoryTheory.forget RingCat).map f,
coe_injective' := β― } =?= { coe := fun f β¦ f.toFun, coe_injective' := β― } βΌ
[] β fun f β¦ (CategoryTheory.forget RingCat).map f =?= fun f β¦ f.toFun βΌ
[] β
R βΆ S =?= βR β+* βS βΌ
[] β @Quiver.Hom =?= RingHom
[onFailure] β R βΆ S =?= βR β+* βS
[] β
CategoryTheory.BundledHom.MapHom SemiRingCat.AssocRingHom (@Ring.toSemiring) R.str S.str =?= βR β+* βS βΌ
[] β
SemiRingCat.AssocRingHom βR βS =?= βR β+* βS βΌ
[] β
βR β+* βS =?= βR β+* βS
[] β (CategoryTheory.forget RingCat).map f =?= f.toFun βΌ
[] β (CategoryTheory.forget RingCat).toPrefunctor.2 f =?= (ββf).1 βΌ
[onFailure] β (CategoryTheory.forget RingCat).toPrefunctor.2 f =?= (ββf).1
Matthew Ballard (Mar 22 2024 at 17:36):
This is a possibility
instance bundledHom : BundledHom AssocRingHom where
toFun _ _ f := f
id _ := RingHom.id _
comp _ _ _ f g := f.comp g
Matthew Ballard (Mar 22 2024 at 17:37):
I see two non-reducible declarations in there
Matthew Ballard (Mar 22 2024 at 17:47):
No it is most likely non-reducibility of RingCat
Matthew Ballard (Mar 22 2024 at 17:51):
Hmm. Nope
Matthew Ballard (Mar 22 2024 at 17:57):
Well I fixed it Nevermind the error wasnβt highlighted
Matthew Ballard (Mar 22 2024 at 18:00):
Apparently you can delete deriving
for LargeCategory RingCat
and nothing between there and this file breaks
Johan Commelin (Mar 22 2024 at 18:03):
Lol, crazy mathlib facts you're spitting there (-;
Matthew Ballard (Mar 22 2024 at 18:12):
Ok now I think I really did fix it. Make RingCat
reducible
and then ConcreteCategory RingCat
becomes a inferInstance
but you need to change the proof to that. Or you can just get rid of the explicit LargeCategory
and ConcreteCategory
instances since Lean can find them with RingCat
reducible
Matthew Ballard (Mar 22 2024 at 18:13):
And duh. That deletion I mentioned only works because I made RingCat
reducible
Matthew Ballard (Mar 22 2024 at 18:14):
It seems fine to make RingCat
reducible
since it wraps Bundled Ring
which is a structure instance
Matthew Ballard (Mar 22 2024 at 18:17):
I guess one should check performance to be safe
Matthew Ballard (Mar 22 2024 at 18:22):
Unfortunately it still doesnβt fix the error you originally presented since Bundled.\a
is not reducible (I think)
Matthew Ballard (Mar 22 2024 at 18:28):
Making that reducible doesnβt help
Johan Commelin (Mar 22 2024 at 18:37):
Hmmz, ok. So maybe the conclusion should be that these lemmas are crossing API boundaries?
Matthew Ballard (Mar 22 2024 at 18:38):
I certainly think cleaner boundaries would help
Matthew Ballard (Mar 22 2024 at 18:49):
Here is _a_ fix to the original problem given the above is already implemented:
def bizzle (X : Cα΅α΅) : R.obj X β+* R.obj X := R.map (π X)
instance (X : Cα΅α΅) : RingHomId (bizzle (R := R) X) where
eq_id := sorry
Matthew Ballard (Mar 22 2024 at 18:50):
I havenβt tried to disentangle the two things
Matthew Ballard (Mar 22 2024 at 21:48):
#11595 makes SemiRingCat
and RingCat
reducible. Performance impact currently being assessed
Matthew Ballard (Mar 22 2024 at 22:14):
At worst neutral
Last updated: May 02 2025 at 03:31 UTC