Zulip Chat Archive

Stream: mathlib4

Topic: grind on `CostructuredArrow.w`


Robin Carlier (Oct 21 2025 at 08:31):

I was experimenting with grind and was very surprised to see the result of annotating docs#CategoryTheory.CostructuredArrow.w with grind.

as a reminder, the lemma has type

 {C : Type u₁} [inst : Category.{v₁, u₁} C] {D : Type u₂} [inst_1 : Category.{v₂, u₂} D] {T : D} {S : C  D}
  {A B : CostructuredArrow S T} (f : A  B), S.map f.left  B.hom = A.hom

and the generated pattern is

which looks like a problem for making it trigger in nice situations

I suspect grind is trying to unfold the definitions for CostructuredArrows and their morphisms (which under the hood are morphisms in Comma categories with functors involving Discrete PUnit), where it clearly shouldn’t (perhaps because calling left and hom on objects leave no choice but to infer them as objects /homs in commas, and the underlying problem is in fact that we abuse the defeq between CostructuredArrows and Commas?). @Kim Morrison do you have an idea of the culprit/know how to fix this?

Kim Morrison (Jan 06 2026 at 23:16):

The culprit is that Functor.fromPUnit is an abbrev:

abbrev fromPUnit (X : C) : Discrete PUnit.{w + 1}  C :=
  (Functor.const _).obj X

While CostructuredArrow itself is a def (not reducible), Functor.fromPUnit is reducible. When grind's pattern preprocessing calls unfoldReducible (EMatchTheorem.lean:284), it expands Functor.fromPUnit T(Functor.const (Discrete PUnit)).obj T, exposing all the Discrete PUnit machinery.

Do you want to experiment with changing fromPUnit from abbrev to def?

Robin Carlier (Jan 07 2026 at 06:58):

Thanks for the explanation!
I won't have time to experiment seriously with this in the immediate future, but I'll keep in in the backburner and come back to it the next time I'll try to improve the grind experience in category theory (probably around April) if no one beats me to it.


Last updated: Feb 28 2026 at 14:05 UTC