Skip to content

feat: class for chosen finite coproducts - #28718

Open
imbrem wants to merge 1 commit into
leanprover-community:masterfrom
imbrem:chosen-finite-coproducts
Open

imbrem wants to merge 1 commit into
leanprover-community:masterfrom
imbrem:chosen-finite-coproducts

Conversation

@imbrem

@imbrem imbrem commented Aug 20, 2025 •

Copy link
Copy Markdown
Contributor

Added basic ChosenFiniteCoproducts class, and started porting some of the lemmas about ChosenFiniteProducts suitably translated


This, combined with #20182 modified to use chosen finite coproducts and premonoidal categories (#21488), should be enough for me to formalize strong Elgot categories, and hence a lot of categorical iteration theory for my PhD thesis.

Re-done from #21603 to deal with changes in #24399 and #24390

Eventually, if we really want to harmonize approaches, we could introduce an AddMonoidalCategory struct and do the analogous to #24399 and #24390 for additive monoidal structure, but that seems like a massive overcomplication for now. It would allow formalizing fun things like rig categories, though.

@github-actions github-actions Bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Aug 20, 2025
@github-actions

Copy link
Copy Markdown

PR summary f253e9b0ec

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.CategoryTheory.ChosenFiniteCoproducts (new file) 601

Declarations diff

+ ChosenFiniteCoproducts
+ addHom
+ addHom_desc
+ coprodComparison
+ coprodComparison_comp
+ coprodComparison_id
+ coprodComparison_inv_natural
+ coprodComparison_natural
+ coprodObj
+ desc
+ desc_comp
+ desc_comp_inl_inr
+ desc_inl_comp_inr_comp
+ desc_inl_inr
+ epi_desc_of_epi_left
+ epi_desc_of_epi_right
+ fromZero
+ fromZero_unique
+ hom_ext
+ initialComparison
+ initialComparison_comp_map_fromZero
+ initialComparison_isIso_of_preservesColimits
+ initialObj
+ inl
+ inl_addHom
+ inl_coprodComparison
+ inl_desc
+ inr
+ inr_addHom
+ inr_coprodComparison
+ inr_desc
+ instance (X : C) : Unique (𝟘_ C ⟶ X)
+ instance (priority := 100) : Limits.HasFiniteCoproducts C
+ map_inl_inv_coprodComparison
+ map_inr_inv_coprodComparison
+ ofFiniteCoproducts
+ preservesColimit_empty_of_isIso_initialComparison
+ preservesInitialIso
+ preservesInitialIso_inv

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-category-theory Category theory label Aug 20, 2025

@YaelDillies YaelDillies left a comment

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.

You're following the now-outdated ChosenFiniteProducts paradigm. Could you please instead follow the new CartesianMonoidalCategory one? Thanks!

@YaelDillies YaelDillies added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Aug 21, 2025
@imbrem

imbrem commented Aug 21, 2025

Copy link
Copy Markdown
Contributor Author

@YaelDillies the issue with that is that we'd like (e.g. in Distributive) to deal with categories having both a monoidal and coproduct structure. Eventually, it would make sense to have AddMonoidalCategory as a dual to MonoidalCategory but that seems an overcomplication for now, hence this as a compromise. Do you instead propose we have a class which says that our MonoidalCategory instance is in fact cocartesian? I feel this is confusing, and also belongs more in AddMonoidalCategory anyways since a biproduct is usually written ⊕

@robin-carlier

Copy link
Copy Markdown
Contributor

I agree with @YaelDillies’s suggestion here: I think we really want to have a class for monoidal categories (with additive and multiplicative notations) that are cocartesians: there is of course the example of bicartesian monoidal categories that you mention, in which the notation is often additive, but there is also the case of commutative monoid objects internal to a symmetric monoidal category: these already have a monoidal structure in mathlib, with a multiplicative notation. I think it would be good to be able to state that these are cocartesian monoidal categories as well without giving up multiplicative notations (in fact, this example was the one behind my interest in the previous PR!). Setting this up only for AddMonoidalCategory or with additive notations would sadly not make that possible as far as I can see.

I understand that notation-wise, this is not so well-suited for distributive or bimonoidal/semirig-categories frameworks. For the latter two, I think it might be really worth investigating if there is a way to use the to_additive setup from the algebraic hierarchy of Mathlib (which is how we can have both AddGroup and Group without redoing everything twice): this way, we could have AddMonoidalCategory (and all related monoidal lemmas!) while also keeping the amount of code duplication manageable (this would also make the existing CartesianMonoidalCategory typeclass available to additive notations, which may help defining bi-cartesian monoidal categories).

To give some more context about what happened to the old ChosenFiniteProduct design and why we moved away from it, Mathlib used to have ChosenFiniteProduct essentially as a constructor for cartesian monoidal category structures (the intended way to "use" ChosenFiniteProduct was mostly via monoidal notations), but some cases where there was a pre-existing monoidal (mainly opposites of cocartesian monoidal categories, e.g the opposite of CommAlgCat) structure showed up and which would compete with the ChosenFiniteProduct one.

@YaelDillies

Copy link
Copy Markdown
Contributor

Put another way, we see your PR as doing two big orthogonal things at once:

  1. Introduce monoidal categories with additive notation
  2. Introduce cocartesian monoidal categories

Each of these steps can be made without much thinking involved:

  1. Just stick to_additive on a bunch of declarations
  2. Just copy-paste a bunch of files (and possibly in the near future it might become "Just stick to_dual on a bunch of declarations", cc @JovanGerb )

But you're doing neither of these, filling up the square from the diagonal without following any pre-existing code, which is both harder for you to write and for us to review, AND creates technical debt that will need to be cleaned up when inevitably someone will need the other two entries of the square.

I understand that filling up the square is more than you need for ring categories, but it is, we believe, the easiest route for throth writing, reviewing and maintaining the code. Does this make sense?

PS: In fact I think we needn't fully complete the square, because it seems no one cares about cartesian monoidal categories with additive notation. This means you can first translate however many files you need on cartesian-monoidal categories to cocartesian ones, then additivise only the cocartesian ones.

@imbrem

imbrem commented Aug 22, 2025 •

Copy link
Copy Markdown
Contributor Author

OK, so would you guys welcome a PR copying over the basics of AddMonoidalCategory, just copy pasted for now (with to dual punted to later)? Tbf I'm just rushing as I'm wrapping up my PhD and would like to upstream as much of my formalization work as possible while I've got time (we've got a whole theory of premonoidal Elgot categories worked out!)

@YaelDillies

Copy link
Copy Markdown
Contributor

Sure! I don't think you even need to copy-paste much for AddMonoidalCategory: Past the definition, one should be able to simply tag a bunch of things with to_additive. Am happy to provide more guidance if necessary.

@imbrem

imbrem commented Oct 3, 2025 •

Copy link
Copy Markdown
Contributor Author

@YaelDillies sorry for taking forever to get around to this; I've made a PR for AddMonoidalCategory over at #30150! Going to try to revive the premonoidal stuff too, as I really want to get my thesis formalization off my fork of MonoidalCategory since that's janky.

@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Oct 3, 2025
@mathlib4-dependent-issues-bot

Copy link
Copy Markdown

This PR/issue depends on:

@mathlib4-merge-conflict-bot mathlib4-merge-conflict-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 19, 2025
@mathlib4-merge-conflict-bot

Copy link
Copy Markdown

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

@grunweg grunweg changed the title Added chosen finite coproducts feat: class for chosen finite coproducts Nov 19, 2025

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-category-theory Category theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants