Add semi-additive categories infrastructure#2305
Conversation
|
Also apologies if there are any nits I missed - I'll give it another lookover soon. |
|
Refactored. File is about 20% shorter than before at 800 lines instead of 1000. Going through it again... |
|
@jdchristensen In light of yesterday’s disastrous PR attempt, and out of respect for your time, I’d like to hold off on this PR for a few more weeks to ensure it’s truly shipshape. The rest of my contributions to Coq-HoTT will remain focused on the formalization. |
|
We're now down to about half the length of the original PR. Continuing. |
|
@CharlesCNorton I haven't looked at this yet and will wait until you ok it. But I'll point out a couple of things that may help. First, there's a trick for showing the a binary operation The second thing that sometimes is helpful is to study the triple product The Baer sum formalization should be particularly relevant, since it uses a lot about biproducts of abelian groups which should generalize to biproducts in any category. |
Thank you very much! |
|
@jdchristensen Ready for review! Was having a tough time implementing the twist, and so kept a more direct proof for associativity. Please let me know what you think. Happy to make any required changes. 👍 |
jdchristensen
left a comment
There was a problem hiding this comment.
I've only looked over the first 20% or so.
| (biproduct_coprod_mor (semiadditive_biproduct Y Y) Y | ||
| 1%morphism 1%morphism | ||
| o biproduct_prod_mor (semiadditive_biproduct Y Y) X | ||
| f g)%morphism. |
There was a problem hiding this comment.
This is verbose. Can you come up with a better way to express these morphisms, with some arguments implicit and provided via typeclass search? This comes up a lot in the file. (A similar thing appears in the ⊕ Notation.)
|
|
||
| (** ** Biproduct characterization lemmas *) | ||
|
|
||
| Section BiproductCharacterization. |
There was a problem hiding this comment.
It seems to me that the lemmas in the section only require a single Biproduct to exist, rather than a SemiAdditiveCategory structure, so they could be proved in Biproducts.v.
|
|
||
| (** ** Swap morphism for biproducts *) | ||
|
|
||
| Section BiproductSwap. |
There was a problem hiding this comment.
Again, some or all of this section probably belongs in Biproducts.v, since these results could be useful for a single biproduct object, even if you don't know you are in a semiadditive category.
| Definition biproduct_swap (A : object C) | ||
| : morphism C (A ⊕ A) (A ⊕ A) |
There was a problem hiding this comment.
Why not [A ⊕ B -> B ⊕ A]? Then you are probably close to proving that biproducts are commutative.
| Lemma biproduct_zero_right_is_inl (Y Z : object C) (h : morphism C Z Y) | ||
| : biproduct_prod_mor (semiadditive_biproduct Y Y) Z h (zero_morphism Z Y) | ||
| = (Biproducts.inl (biproduct_data (semiadditive_biproduct Y Y)) o h)%morphism. |
There was a problem hiding this comment.
This and the next lemma are ok, but I think the proof could be built out of a few more conceptual tools. In Biproducts.v, you could prove that Biproducts.inl = biproduct_prod_mor id zero (not typed precisely), which is a useful general fact. Then the third lemma in this section is a naturality result, which tells you that biproduct_prod_mor id zero o h = biproduct_prod_mor (id o h) (zero o h). Then you just use the properties of id and zero. Seems cleaner, and that result about inl is independently useful.
There was a problem hiding this comment.
Also, I think one of the Ys can be changed to a fresh object Y', giving a slightly more general result.
| Lemma biproduct_comp_general (W X Y Z : object C) | ||
| (f : morphism C W X) (g : morphism C W Y) (h : morphism C Z W) | ||
| : (biproduct_prod_mor (semiadditive_biproduct X Y) W f g o h)%morphism | ||
| = biproduct_prod_mor (semiadditive_biproduct X Y) Z (f o h) (g o h). |
There was a problem hiding this comment.
This is a naturality result, so that should be mentioned in the comment and in the name. (Also, this is a result that is just a fact about products, not biproducts. Really products (and coproducts) should have been studied on their own first, and then biproducts could make use of those results, but I think that's a refactoring for another time.)
The examples where I've seen it used are for proving equivalences That said, the proof of associativity still looks really long, and conceptually I don't see why it should be long. I wonder if what you are missing is the associativity of the biproduct itself (for which the twist approach would help). #2016 does this for wild categories using the twist approach (but doesn't get to addition of morphisms). Not sure if it would be worth trying this. It would certainly be a lot of work, but the idea is that instead of pushing through proofs, one tries to develop the basic tools that make later proofs easy. And knowing that biproducts are associative is one of the basic facts one would expect to have. Probably not worth it here, so just take this as an aside. (This also suggests the idea of switching to wild categories. We have more about biproducts there, and they are also defined in terms of coproducts and products, so results are stated at the correct level of generality. But #2016 is still a work in progress, with @ThomatoTomato planning to reorganize things a bit.) |
|
@jdchristensen Thanks for the review. Do you think I should switch to WildCat now or stick with the current approach? I suspect I know the answer, but wanted your opinion in case there's some utility in continuing. |
I don't think there's an easy answer. If your current proofs just needed mild touch-ups, I'd lean towards just sticking with Categories, since the code has already been written and it might be quite a burden to rewrite it. But so far it seems that each file needs fairly substantial revisions, which makes me wonder if it wouldn't be that much extra work to switch to WildCat. The advantage of switching is that multiple people will be interested in using some of these results and may be able to contribute to review or even proofs. One disadvantage of switching (besides the fact that you already have code for Categories) is that dealing with the plethora of typeclasses used by WildCat can be a bit confusing. |
7bca181 to
7236d28
Compare
|
This should be ok for review now @jdchristensen - it appears that the alectryon fail is a different issue? |
|
@CharlesCNorton Thanks for the update. I'm not sure when I'll get a chance to look at this PR, but it's on my radar.
Yes, that's a different issue, #2340. (I'm hoping @Alizter can finish that up or revert to the old code.) |
jdchristensen
left a comment
There was a problem hiding this comment.
So far I only reviewed the changes to Biproducts.v. After fixing things, can you re-read your other changes to make sure you are not missing generalizations?
| (** Pairing into a self-biproduct. *) | ||
| Definition biproduct_sum_pair {X Y : object C} | ||
| `{BYY : @Biproduct C Z Y Y} | ||
| (f g : morphism C X Y) | ||
| : morphism C X BYY | ||
| := biproduct_prod_mor BYY X f g. |
There was a problem hiding this comment.
Is it useful to have this definition? Except for the different choices of implicit arguments, one can just use biproduct_prod_mor.
(And it would seem reasonable to make the W argument of biproduct_prod_mor implicit, since it can be deduced from the provided maps. Not sure how well it would work to make the biproduct argument implicit, but you could try.)
| (** A morphism induced on self-biproducts by maps on the two summands. *) | ||
| Definition biproduct_sum_map {Y Y' : object C} | ||
| `{BY : @Biproduct C Z Y Y} `{BY' : @Biproduct C Z Y' Y'} | ||
| (a b : morphism C Y Y') | ||
| : morphism C BY BY' | ||
| := biproduct_prod_mor BY' BY (a o outl BY) (b o outr BY). |
There was a problem hiding this comment.
This works equally well for biproducts of non-equal objects, and is just the functoriality of biproducts, so it should be done in that generality.
| Lemma biproduct_inl_sum_pair {Y : object C} | ||
| `{BYY : @Biproduct C Z Y Y} | ||
| : inl BYY = biproduct_sum_pair 1%morphism (zero_morphism Y Y). | ||
| Proof. | ||
| symmetry. | ||
| unfold biproduct_sum_pair. | ||
| rewrite biproduct_prod_zero_r. | ||
| apply right_identity. | ||
| Qed. |
There was a problem hiding this comment.
This and the next result don't need the objects the same. (biproduct_prod_zero_l is the dual result, generalized even further.)
| Qed. | ||
|
|
||
| (** Product pairing is natural in the domain. *) | ||
| Lemma biproduct_prod_comp (V W : object C) |
There was a problem hiding this comment.
The name of this and the next result should mention nat for naturality. Not sure how to indicate that it involves the domain. Maybe there are other examples to compare to?
| (** Pairing is natural in the codomain. *) | ||
| Lemma biproduct_sum_pair_natural {X Y Y' : object C} | ||
| `{BYY : @Biproduct C Z Y Y} `{BYY' : @Biproduct C Z Y' Y'} | ||
| (a : morphism C Y Y') (f g : morphism C X Y) | ||
| : biproduct_sum_pair (a o f) (a o g) | ||
| = (biproduct_sum_map a a o biproduct_sum_pair f g)%morphism. |
There was a problem hiding this comment.
This also works when the objects are not the same. Same with most or all later results.
| Lemma biproduct_codiagonal_factor_through_sum_map {Y Y' : object C} | ||
| `{BYY : @Biproduct C Z Y Y} `{BYY' : @Biproduct C Z Y' Y'} | ||
| (a b : morphism C Y Y') | ||
| : (biproduct_codiagonal Y' o biproduct_sum_map a b)%morphism | ||
| = biproduct_coprod_mor BYY Y' a b. |
There was a problem hiding this comment.
This is a special case of naturality of biproduct_coprod_mor in the domain, so maybe it should be proved in that generality first?
| Definition biproduct_swap (Y : object C) | ||
| `{BYY : @Biproduct C Z Y Y} | ||
| : morphism C BYY BYY | ||
| := biproduct_sum_pair (outr BYY) (outl BYY). |
There was a problem hiding this comment.
As I mentioned a few months ago, there's no reason to only define the swap when the two objects are the same.
| Lemma biproduct_prod_swap {X Y : object C} | ||
| `{BYY : @Biproduct C Z Y Y} | ||
| (f g : morphism C X Y) | ||
| : biproduct_sum_pair g f | ||
| = (biproduct_swap Y o biproduct_sum_pair f g)%morphism. |
There was a problem hiding this comment.
This also generalizes to different objects.
|
Re-read SemiAdditive.v; nothing else generalizes. Also removed biproduct_sum_pair, proved copairing natural in the domain and derived the codiagonal factorization from it, and proved uniqueness of the enrichment. |
There was a problem hiding this comment.
Pull request overview
This PR introduces foundational infrastructure for semi-additive categories in the additive category theory development, extracting a lightweight structure (zero object + biproducts) that induces a commutative monoid structure on hom-sets.
Changes:
- Updates additive-category prerequisites (
ZeroObjects.v,Biproducts.v) to use the newerCategory.Core/Category.Objectsimports. - Extends
Biproducts.vwith additional lemmas/operations for self-biproducts (codiagonal, swap, naturality, interaction lemmas). - Adds
SemiAdditive.v, definingSemiAdditiveCategoryand deriving commutative monoid structure on morphisms, plus an enrichment uniqueness result.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| theories/Categories/Additive/ZeroObjects.v | Adjusts imports to Basics.* / Category.Core / Category.Objects for zero objects and zero morphisms. |
| theories/Categories/Additive/Biproducts.v | Adds lemmas and operations (naturality, codiagonal, swap) supporting semi-additive structure derivations. |
| theories/Categories/Additive/SemiAdditive.v | Introduces SemiAdditiveCategory and morphism-addition + commutative monoid construction from biproducts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| From HoTT Require Import Basics.Overture. | ||
| From HoTT.Categories Require Import Category.Core. | ||
| From HoTT.Categories.Additive Require Import ZeroObjects Biproducts. | ||
| From HoTT.Classes.interfaces Require Import abstract_algebra. |
There was a problem hiding this comment.
The reason the build succeeds is because those dependencies must be coming via one of the other imports. But I agree with copilot that we should explicit require the things we use. (I don't remember for sure, but I may have been the one to suggest trimming the imports too aggressively.)
jdchristensen
left a comment
There was a problem hiding this comment.
So far I just skimmed Biproducts.v and there are some obvious mistakes in organization. Please re-read SemiAdditive.v and look for similar issues. Can you also check whether all of my previous comments have been addressed? (Even if github flags them as outdated, they are often still relevant.)
| (** A morphism induced on self-biproducts by maps on the two summands. *) | ||
| Definition biproduct_sum_map {X Y X' Y' : object C} | ||
| `{BXY : @Biproduct C Z X Y} `{BXY' : @Biproduct C Z X' Y'} | ||
| (a : morphism C X X') (b : morphism C Y Y') | ||
| : morphism C BXY BXY' | ||
| := biproduct_prod_mor BXY' (a o outl BXY) (b o outr BXY). |
There was a problem hiding this comment.
This should move elsewhere, and the comment should be updated, as it's not about self-biproducts. (Please check the other results too.)
|
|
||
| (** The codiagonal is natural in the codomain. *) | ||
| Lemma biproduct_codiagonal_natural {Y Y' : object C} | ||
| `{BYY : @Biproduct C Z Y Y} |
There was a problem hiding this comment.
It looks like you always have to write @Biproduct C Z Y Y, probably because Z can't be inferred. That suggests that Z should be made an explicit argument, so you could write Biproduct Z Y Y. Can you look for other places where the notation is awkward and can be improved?
| Lemma biproduct_codiagonal_natural {Y Y' : object C} | ||
| `{BYY : @Biproduct C Z Y Y} | ||
| (a : morphism C Y Y') | ||
| : (a o biproduct_codiagonal Y)%morphism |
There was a problem hiding this comment.
Can these %morphism annotations be avoided? Does the whole Categories library need to always annotate composition? Is that because o is overloaded?
| (** The functorial biproduct map commutes with pairing. *) | ||
| Lemma biproduct_sum_map_prod {X Y X' Y' W : object C} |
There was a problem hiding this comment.
Not about self-biproducts.
|
Fixed in b32c4cf and 17de95f: the zero object is now explicit ( |
jdchristensen
left a comment
There was a problem hiding this comment.
I made a quick review through everything. I still want to make another pass through SemiAdditive.v after you respond to my feedback.
| Local Notation "X ⊕ Y" := | ||
| (semiadditive_biproduct X Y) | ||
| (at level 40, left associativity). |
There was a problem hiding this comment.
We usually reserve notations in Basics/Notations.v. (I'm not exactly sure why, but I guess we should do so here too.)
| : biproduct_sum_map a b o inl BXY | ||
| = inl BX'Y' o a. | ||
| Proof. | ||
| etransitivity (biproduct_prod_mor BX'Y' a (zero_morphism X Y')). |
There was a problem hiding this comment.
I'll push a commit showing a slightly cleaner way to do this using rhs_V. More generally, lhs, lhs_V, rhs, and rhs_V can be used to avoid using rewrite when the thing being rewritten is at the top level of one side of an equality.
| intros f g. | ||
| unfold sgop_morphism. | ||
| rewrite (biproduct_prod_swap f g). | ||
| rewrite <- Category.Core.associativity. |
There was a problem hiding this comment.
I think Category.Core. can be removed here and elsewhere.
| Lemma addition_of_pairs (X Y : object C) (f1 f2 g1 g2 : morphism C X Y) | ||
| : sgop_morphism C X (Y ⊕ Y) | ||
| (biproduct_prod_mor (Y ⊕ Y) f1 g1) | ||
| (biproduct_prod_mor (Y ⊕ Y) f2 g2) | ||
| = biproduct_prod_mor (Y ⊕ Y) | ||
| (sgop_morphism C X Y f1 f2) | ||
| (sgop_morphism C X Y g1 g2). |
There was a problem hiding this comment.
I think this generalizes to Y ⊕ Y'.
| rewrite biproduct_prod_beta_l. | ||
| rewrite biproduct_prod_beta_l. |
There was a problem hiding this comment.
rewrite 2 here and below?
| (** ** Identity laws for morphism addition *) | ||
|
|
||
| Section IdentityLaws. | ||
| Context (C : SemiAdditiveCategory). |
There was a problem hiding this comment.
I think C should be implicit. Elsewhere too. And X Y below.
| Addition is the codiagonal composed with the pairing morphism. *) | ||
|
|
||
| Section MorphismAddition. | ||
| Context (C : SemiAdditiveCategory) (X Y : object C). |
| (X Y : object C) (f g h : morphism C X Y) | ||
| : (f + g) + h = f + (g + h). | ||
| Proof. | ||
| unfold sgop_morphism at 1. |
There was a problem hiding this comment.
This unfold doesn't seem to do anything.
| etransitivity | ||
| (biproduct_codiagonal Y | ||
| o biproduct_prod_mor (Y ⊕ Y) (sgop_morphism C X Y f g) | ||
| (sgop_morphism C X Y (zero_morphism X Y) h)). |
There was a problem hiding this comment.
This seems overly complicated. Can this be expressed using + notation? Can we avoid the etransitivity by adjusting the lhs with zero_left_identity directly?
|
Arguments are implicit wherever inferable from the morphisms, |
|
LGTM! Can you squash to one commit? |
Co-authored-by: Dan Christensen <jdc@uwo.ca>
|
done |
|
Thanks! |
Extracting SemiAdditive.v from additive categories work per PR #2304 review as part of general formalization for #2288
Provides:
SemiAdditiveCategory: Class with just cat, zero object, and biproductsIsCommutativeMonoidstructure on morphisms using biproductsNote: The file is almost 1000 lines and requires refactoring, especially the associativity proof. @jdchristensen this was the only way I could get it to work - would very much appreciate help simplifying and identifying which helper lemmas can be removed. The associativity proof in particular requires many intermediate lemmas about how biproducts interact. It took me an entire week of 16 hour days to get here, but I assume there is a much more elegant method.