Skip to content

[Merged by Bors] - feat: CommAlgCat is cocartesian-monoidal - #25365

Closed
YaelDillies wants to merge 2 commits into
masterfrom
comm_alg_cat_monoidal
Closed

YaelDillies wants to merge 2 commits into
masterfrom
comm_alg_cat_monoidal

Conversation

@YaelDillies

Copy link
Copy Markdown
Contributor

Construct the cocartesian-monoidal category structure on CommAlgCat R explicitly from the tensor product.

From Toric

Co-authored-by: Andrew Yang [email protected]
Co-authored-by: Michał Mrugała [email protected]
Co-authored-by: Christian Merten [email protected]


Open in Gitpod

@github-actions

github-actions Bot commented Jun 2, 2025 •

Copy link
Copy Markdown

PR summary 12bf70911d

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Algebra.Category.CommAlgCat.Monoidal (new file) 1375

Declarations diff

+ associator_hom_hom
+ associator_inv_hom
+ binaryCofan
+ binaryCofanIsColimit
+ binaryCofan_inl
+ binaryCofan_inr
+ binaryCofan_pt
+ braiding_hom_hom
+ braiding_inv_hom
+ coe_tensorObj
+ coe_tensorUnit
+ fst_unop_hom
+ instance : BraidedCategory (CommAlgCat.{u} R)
+ instance : CartesianMonoidalCategory (CommAlgCat.{u} R)ᵒᵖ
+ instance : MonoidalCategory (CommAlgCat.{u} R)
+ isInitialSelf
+ lift_unop_hom
+ snd_unop_hom
+ tensorHom_hom
+ toUnit_unop_hom
+ whiskerLeft_hom
+ whiskerRight_hom

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions Bot added the t-algebra Algebra (groups, rings, fields, etc) label Jun 2, 2025
@YaelDillies YaelDillies added the toric Part of the ongoing formalisation of toric varieties label Jun 2, 2025
@YaelDillies
YaelDillies requested a review from joelriou June 14, 2025 10:39
Comment on lines +61 to +79
instance : MonoidalCategory (CommAlgCat.{u} R)ᵒᵖ where
tensorObj S T := op <| of R (S.unop ⊗[R] T.unop)
whiskerLeft S {T₁ T₂} f := .op <| ofHom (Algebra.TensorProduct.map (.id _ _) f.unop.hom)
whiskerRight {S₁ S₂} f T := .op <| ofHom (Algebra.TensorProduct.map f.unop.hom (.id _ _))
tensorHom {S₁ S₂ T₁ T₂} f g := .op <| ofHom (map f.unop.hom g.unop.hom)
tensorUnit := .op (.of R R)
associator {S T U} := .op <| isoMk (Algebra.TensorProduct.assoc R R _ _ _).symm
leftUnitor S := .op <| isoMk (Algebra.TensorProduct.lid R _).symm
rightUnitor _ := .op <| isoMk (Algebra.TensorProduct.rid R R _).symm
tensorHom_def := by intros; ext <;> rfl
tensor_id := by intros; ext <;> rfl
tensor_comp := by intros; ext <;> rfl
whiskerLeft_id := by intros; ext <;> rfl
id_whiskerRight := by intros; ext <;> rfl
associator_naturality := by intros; ext <;> rfl
leftUnitor_naturality := by intros; rfl
rightUnitor_naturality := by intros; rfl
pentagon := by intros; ext <;> rfl
triangle := by intros; ext <;> rfl

@robin-carlier robin-carlier Jun 17, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that to make sense of a cocartesian monoidal category you need to put the monoidal structure on the opposite category, but we do have CategoryTheory.monoidalCategoryOp (you need an extra import to make this work), so this proof could be something like

Suggested change
instance : MonoidalCategory (CommAlgCat.{u} R)ᵒᵖ where
tensorObj S T := op <| of R (S.unop ⊗[R] T.unop)
whiskerLeft S {T₁ T₂} f := .op <| ofHom (Algebra.TensorProduct.map (.id _ _) f.unop.hom)
whiskerRight {S₁ S₂} f T := .op <| ofHom (Algebra.TensorProduct.map f.unop.hom (.id _ _))
tensorHom {S₁ S₂ T₁ T₂} f g := .op <| ofHom (map f.unop.hom g.unop.hom)
tensorUnit := .op (.of R R)
associator {S T U} := .op <| isoMk (Algebra.TensorProduct.assoc R R _ _ _).symm
leftUnitor S := .op <| isoMk (Algebra.TensorProduct.lid R _).symm
rightUnitor _ := .op <| isoMk (Algebra.TensorProduct.rid R R _).symm
tensorHom_def := by intros; ext <;> rfl
tensor_id := by intros; ext <;> rfl
tensor_comp := by intros; ext <;> rfl
whiskerLeft_id := by intros; ext <;> rfl
id_whiskerRight := by intros; ext <;> rfl
associator_naturality := by intros; ext <;> rfl
leftUnitor_naturality := by intros; rfl
rightUnitor_naturality := by intros; rfl
pentagon := by intros; ext <;> rfl
triangle := by intros; ext <;> rfl
letI : MonoidalCategory (CommAlgCat.{u} R) :=
{ tensorObj S T := of R (S ⊗[R] T)
whiskerLeft _ {_ _} f := ofHom (Algebra.TensorProduct.map (.id _ _) f.hom)
whiskerRight {_ _} f T := ofHom (Algebra.TensorProduct.map f.hom (.id _ _))
tensorHom {_ _ _ _} f g := ofHom (map f.hom g.hom)
tensorUnit := .of R R
associator {_ _ _} := isoMk (Algebra.TensorProduct.assoc R R _ _ _)
leftUnitor _ := isoMk (Algebra.TensorProduct.lid R _)
rightUnitor _ := isoMk (Algebra.TensorProduct.rid R R _)
pentagon _ _ _ _ := by dsimp; ext <;> rfl
triangle _ _ := by sorry
associator_naturality _ _ _ := by ext <;> rfl }
monoidalCategoryOp

and I’d argue that the monoidal structure on CommAlgCat.{u} R itself that I gave in the letI is something we could want on its own.
For reasons I don’t fully understand, though, a rfl for the triangle field does not want to go through, while it does for the opposite. So there’s something fishy.

Also, rather than making Quiver.Hom.unop_inj a local ext, maybe #25914 is onto something that would make automation better for the proofs if instead we only go with the "opposite category only" structure?

I recall seeing #21603 introducing chosen finite coproducts. Now that cartesian monoidal categories have replaced chosen finite products, maybe it could be worth looking into salvaging this, and then rather define a CocartesianMonoidalCategory instance on CommAlg.{u} R rather than a CartesianMonoidalCategory one on its opposite?

Also, and sorry to ask if this is obvious, but presumably the monoidal structure on CommAlgCat could be obtained by transfering a monoidal structure along an equivalence with CommMon_ ModuleCat + a general monoidal structure on CommMon_ C for a symetric monoidal category C (and such structures are always cocartesian monoidal).
Is the reason you’re not going with that is that it gives bad defeqs?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also wasn’t explicitly stated in my first comment, but defining first a monoidal structure on CommAlgCat and then on its opposite via monoidalCategoryOp does not change any of long list of defeqs you state below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erdOne was against this when I suggested it because it induces duplication. His philosophy is that if C is cocartesian-monoidal, then Cᵒᵖ is cartesian-monoidal and you should just use that instead of introducing two ways to talk about things

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than making Quiver.Hom.unop_inj a local ext, maybe #25914 is onto something that would make automation better for the proofs if instead we only go with the "opposite category only" structure?

Indeed, and that's why Eric cut the grass under my feet by opening that PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presumably the monoidal structure on CommAlgCat could be obtained by transfering a monoidal structure along an equivalence with CommMon_ ModuleCat + a general monoidal structure on CommMon_ C for a symetric monoidal category C (and such structures are always cocartesian monoidal).
Is the reason you’re not going with that is that it gives bad defeqs?

Yes, exactly. We really want CommAlgCat R to be "[CommRing A] + [Algebra R A], but bundled" so that we can leverage the category theory library to prove things about unbundled commutative algebras, and vice-versa

@robin-carlier robin-carlier Jun 18, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I convince you that replacing CartesianMonoidalCategory (CommAlgCat R)ᵒᵖ with CocartesianMonoidalCategory (CommAlgCat R) can be done in a later refactor? Right now my job is to disentangle this mess, and you can see that Toric.Mathlib.Algebra.Category.CommAlgCat.Monoidal is quite high up in there.

If the argument behind wanting things this way is "I need this now and like this to accomodate my downstream project", this is a "how much mathlib should accomodate downstream projects" situation. I am not qualified to have any opinion here, and only maintainers are qualified to.

If maintainers decide that this is fine to get this as is and refactor later, so be it, and I’ll work on the refactor (although I’d still ask you to make the braided monoidal structure on CommAlgCat R rather than on its opposite, again via instance inferring you lose nothing).
Otherwise, we first add the relevant API.
Tl;dr don’t ask me to take a decision based on "what a downstream project needs", this is not my role.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the point of CartesianMonoidalCategory is to get defeqs on lift and toUnit and I don't think people would be happy to make them into Nonempty. (I'm not sure if this is what you are suggesting)

I’m not exactly suggesting this, as said, my experiments making it CocartesianMonoidal and let the CartesianMonoidal on the opposite be infered showed that you get the same defeqs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will raise a question in the reviewers chat. In the mean time can @YaelDillies refactor out the braided monoidal structure on CommAlgCat R since (I think) we have a consensus on this and this could be done now without waiting for any refactor.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just in case, my experiments with CocartesianMonoidal are available in this branch in my fork)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can @YaelDillies refactor out the braided monoidal structure on CommAlgCat R

Done

@robin-carlier

robin-carlier commented Jun 18, 2025 •

Copy link
Copy Markdown
Contributor

Apart from admittedly nitpicks about how vars are handled (and perhaps one identation), up to the decision about waiting on a CocartesianMonoidalCategory struct, lgtm. (edit: actually, a few more nits, but I like the compact format!)

@leanprover-community-bot-assistant leanprover-community-bot-assistant added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jul 5, 2025
@leanprover-community-bot-assistant

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please merge master and resolve them.

Construct the cocartesian-monoidal category structure on `CommAlgCat R` explicitly from the tensor product.

From Toric

Co-authored-by: Andrew Yang <[email protected]>
Co-authored-by: Michał Mrugała <[email protected]>
Co-authored-by: Christian Merten <[email protected]>
@YaelDillies
YaelDillies force-pushed the comm_alg_cat_monoidal branch from 85e3e6f to 20d7ee1 Compare July 5, 2025 08:53
@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Jul 5, 2025
@smorel394

Copy link
Copy Markdown
Collaborator

Did you guys reach a decision on a CocartesianMonoidalCategory structure?
@robin-carlier , do you have more nits or do you think that this can be merged?

@robin-carlier

Copy link
Copy Markdown
Contributor

No clear-cut decision emerged from the higher ups.

Except for the thing about CocartesianMonoidal, it’s good to go I think. So instead of stalling this more than it should have been, I’m willing to agree to CartesianMonoidal _ᵒᵖ for now, and will bring a definition for CocartesianMonoidal and refactor this soon. From my experiments, this won’t change a single defeq in this file, just merely how the instance on the opposite category is inferred, so this should be relatively harmless.

@robin-carlier

Copy link
Copy Markdown
Contributor

Sorry for the delay between this and my last comment, I wanted to have a last look before putting it on the queue. As said, I’ll work on CocartesianMonoidalCategory ASAP to hotswap the instances.

maintainer merge

@github-actions

Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by robin-carlier.

@ghost ghost added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Jul 11, 2025

@jcommelin jcommelin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 🎉

bors merge

@ghost ghost added ready-to-merge This PR has been sent to bors. and removed maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. labels Jul 11, 2025
mathlib-bors Bot pushed a commit that referenced this pull request Jul 11, 2025
Construct the cocartesian-monoidal category structure on `CommAlgCat R` explicitly from the tensor product.

From Toric

Co-authored-by: Andrew Yang <[email protected]>
Co-authored-by: Michał Mrugała <[email protected]>
Co-authored-by: Christian Merten <[email protected]>
@mathlib-bors

mathlib-bors Bot commented Jul 11, 2025

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title feat: CommAlgCat is cocartesian-monoidal [Merged by Bors] - feat: CommAlgCat is cocartesian-monoidal Jul 11, 2025
@mathlib-bors mathlib-bors Bot closed this Jul 11, 2025
@mathlib-bors
mathlib-bors Bot deleted the comm_alg_cat_monoidal branch July 11, 2025 12:09
BeibeiX0 pushed a commit to BeibeiX0/mathlib4 that referenced this pull request Jul 16, 2025
Construct the cocartesian-monoidal category structure on `CommAlgCat R` explicitly from the tensor product.

From Toric

Co-authored-by: Andrew Yang <[email protected]>
Co-authored-by: Michał Mrugała <[email protected]>
Co-authored-by: Christian Merten <[email protected]>
callesonne pushed a commit to callesonne/mathlib4 that referenced this pull request Jul 24, 2025
Construct the cocartesian-monoidal category structure on `CommAlgCat R` explicitly from the tensor product.

From Toric

Co-authored-by: Andrew Yang <[email protected]>
Co-authored-by: Michał Mrugała <[email protected]>
Co-authored-by: Christian Merten <[email protected]>
hrmacbeth pushed a commit to szqzs/mathlib4 that referenced this pull request Jul 28, 2025
Construct the cocartesian-monoidal category structure on `CommAlgCat R` explicitly from the tensor product.

From Toric

Co-authored-by: Andrew Yang <[email protected]>
Co-authored-by: Michał Mrugała <[email protected]>
Co-authored-by: Christian Merten <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has been sent to bors. t-algebra Algebra (groups, rings, fields, etc) toric Part of the ongoing formalisation of toric varieties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants