Skip to content

feat(CategoryTheory/Monoidal): tensorμ_braid_swap and tensor-product IsCommComonObj#38314

Open
pedroscortes wants to merge 2 commits intoleanprover-community:masterfrom
pedroscortes:pcortes/tensormu-braid-swap-and-comm-comon-tensor
Open

feat(CategoryTheory/Monoidal): tensorμ_braid_swap and tensor-product IsCommComonObj#38314
pedroscortes wants to merge 2 commits intoleanprover-community:masterfrom
pedroscortes:pcortes/tensormu-braid-swap-and-comm-comon-tensor

Conversation

@pedroscortes
Copy link
Copy Markdown


Summary

Two symmetric-monoidal coherence results in a new file
Mathlib/CategoryTheory/Monoidal/Symmetric/TensorBraidSwap.lean:

  1. MonoidalCategory.tensorμ_braid_swap — canonical rearrangement
    tensorμ A A Y Y intertwines the braiding on A ⊗ Y with the
    pair of braidings on A and Y. Sibling of
    CategoryTheory.MonObj.mul_braiding
    (Mathlib.CategoryTheory.Monoidal.Mon_, line 759).

  2. Tensor-product instance for IsCommComonObj: if A, B carry
    commutative comonoid structures in a symmetric monoidal category,
    so does A ⊗ B. Reduces comul_comm for Δ[A ⊗ B] via
    tensorμ_braid_swap to the pointwise hypotheses. Fills a gap
    in Mathlib/CategoryTheory/Monoidal/CommComon_.lean, which
    currently provides only the unit instance
    (instCommComonObjUnit) and the auto-instance for cartesian
    categories (instIsCommComonObjOfCartesian).

Placement rationale

Placed in a new Symmetric/ subdirectory rather than appended
to Braided/Basic.lean because the latter's top-level
variable [BraidedCategory C] creates an instance diamond
against any locally-added [SymmetricCategory C]. On v4.30.0-rc2
this diamond blocks rw [SymmetricCategory.symmetry] motive
extraction through A ◁ _ ▷ Y — the pattern is literally present
in the target, but the two distinct BraidedCategory C instances
(outer variable vs SymmetricCategory.toBraidedCategory) cause
the rewrite to fail. A new file with only
[SymmetricCategory C] as its variable avoids this.

Downstream consumer

The IsCommComonObj tensor-product instance is load-bearing for
the external library
markovcat (formalising
Fritz–Klingler Markov categories), specifically for symmetry of
the conditional-independence predicate on compound objects.

Checks

  • lake build Mathlib.CategoryTheory.Monoidal.Symmetric.TensorBraidSwap — green.
  • lake exe lint-style — clean (exit 0).
  • Rebased onto current master; single commit; 72 insertions across
    two files (new file + one-line Mathlib.lean registration).

Opening as draft to let CI run before requesting review.

…IsCommComonObj

Adds two symmetric-monoidal coherence results in a new file
`Mathlib.CategoryTheory.Monoidal.Symmetric.TensorBraidSwap`:

* `MonoidalCategory.tensorμ_braid_swap` — the canonical rearrangement
  `tensorμ A A Y Y : (A ⊗ A) ⊗ (Y ⊗ Y) ⟶ (A ⊗ Y) ⊗ (A ⊗ Y)` intertwines
  the braiding on `A ⊗ Y` with the pair of braidings on `A` and `Y`.
  Sibling of `CategoryTheory.MonObj.mul_braiding`
  (`Mathlib.CategoryTheory.Monoidal.Mon_`, line 759) which closes a
  structurally adjacent equation by the same simp + slice recipe.

* Tensor-product instance for `IsCommComonObj`: if `A` and `B` carry
  commutative comonoid structures in a symmetric monoidal category,
  so does `A ⊗ B`. Reduces commutativity of `Δ[A ⊗ B]` via
  `tensorμ_braid_swap` to the pointwise hypotheses on `A` and `B`.

## Placement rationale

These live in a new `Symmetric/` subdirectory rather than being
appended to `Braided/Basic.lean` because the latter's top-level
`variable [BraidedCategory C]` creates an instance diamond with
any locally-added `[SymmetricCategory C]`. On Lean v4.30.0-rc2 that
diamond blocks `rw [SymmetricCategory.symmetry]` motive extraction
through `A ◁ _ ▷ Y` — even though the pattern is literally present
in the target, the two distinct `BraidedCategory C` instances
(outer variable vs `SymmetricCategory.toBraidedCategory`) cause
the rewrite to fail. A clean file with only `[SymmetricCategory C]`
as its variable avoids this.

## Downstream consumers

The tensor-product `IsCommComonObj` instance is load-bearing for
the `markovcat` library (external, https://github.com/pedroscortes/markovcat)
formalising Markov categories — specifically for proving symmetry of
the Fritz-Klingler conditional-independence predicate.

Refs: Fritz 2020 *Adv. Math.* 370; Fritz-Klingler, *JMLR* 24(46) (2023).
@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 Apr 20, 2026
@github-actions
Copy link
Copy Markdown

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

If you haven't already done so, please come to https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR.

Thank you again for joining our community.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 20, 2026

PR summary 8f4785ceef

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.CategoryTheory.Monoidal.Symmetric.TensorBraidSwap (new file) 472

Declarations diff

+ MonoidalCategory.tensorμ_braid_swap
+ instance (A B : C) [ComonObj A] [ComonObj B]

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

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

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


No changes to technical debt.

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/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 Apr 20, 2026
@pedroscortes pedroscortes marked this pull request as ready for review April 20, 2026 20:50
@dagurtomas
Copy link
Copy Markdown
Contributor

In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

Did you use AI to generate this PR?

@dagurtomas dagurtomas added awaiting-author A reviewer has asked the author a question or requested changes. labels Apr 23, 2026
@pedroscortes
Copy link
Copy Markdown
Author

In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

Did you use AI to generate this PR?

hi @dagurtomas!
no, I haven't. sorry I haven't made it over to zulip yet to introduce myself.

quick context: I'm finishing my masters in cs at the Federal University of Espírito Santo, working on categorical foundations of causal inference. these two lemmas came up as a genuine gap while I was building markovcat (still private while my thesis is in progress), a Lean 4 library formalizing Fritz 2020 arkov categories and Fritz–Klingler 2023 d-separation. I expect a handful of similar coherence gaps will keep surfacing as I push further into the formalization, so I'll probably be sending a few more PRs of this flavor over the next year or two.

Copy link
Copy Markdown
Contributor

@dagurtomas dagurtomas left a comment

Choose a reason for hiding this comment

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

There is no need for a new file, you can just put these two declarations in Monoidal/Braided/Basic.lean and Monoidal/CommComon_.lean.

This looks very AI-generated (the wordiness of the docstrings and the heavy use of markdown in both docstrings and PR description). I'll give you the benefit of the doubt this time, but I ask you to please be honest with disclosing AI use.

Comment on lines +20 to +23
Placed in its own file to avoid an instance-diamond issue in `Braided/Basic.lean`,
where the ambient `[BraidedCategory C]` variable clashes with the
`[SymmetricCategory C]`-derived `BraidedCategory` instance, confusing
`rw [SymmetricCategory.symmetry]` motive extraction on Lean v4.30.0-rc2.
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.

There is no diamond, SymmetricCategory extends BraidedCategory. You just need to make sure not to have both assumptions [BraidedCategory C] and [SymmetricCategory C] around, so just put it in its own section with only a
[SymmetricCategory C] assumption.

Comment on lines +36 to +40
/-- **Symmetric-monoidal tensor-braid swap coherence.**
The canonical rearrangement `tensorμ` intertwines the braiding on `A ⊗ Y`
with the pair of braidings on `A` and `Y`. Both sides implement the
permutation `(a₁, a₂, y₁, y₂) ↦ (a₂, y₂, a₁, y₁)`. Sibling of
`MonObj.mul_braiding` (`Mathlib.CategoryTheory.Monoidal.Mon_`). -/
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 docstring is unnecessary

Comment on lines +45 to +55
simp only [tensorμ, Category.assoc,
BraidedCategory.braiding_tensor_right_hom,
BraidedCategory.braiding_tensor_left_hom, comp_whiskerRight,
whisker_assoc, whiskerLeft_comp, pentagon_assoc,
pentagon_inv_hom_hom_hom_inv_assoc, Iso.inv_hom_id_assoc,
whiskerLeft_hom_inv_assoc]
slice_lhs 3 4 => rw [← whiskerLeft_comp, ← comp_whiskerRight,
SymmetricCategory.symmetry]
simp only [id_whiskerRight, whiskerLeft_id, Category.id_comp, Category.assoc,
tensorHom_def, tensor_whiskerLeft, whiskerRight_tensor]
monoidal
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.

Suggested change
simp only [tensorμ, Category.assoc,
BraidedCategory.braiding_tensor_right_hom,
BraidedCategory.braiding_tensor_left_hom, comp_whiskerRight,
whisker_assoc, whiskerLeft_comp, pentagon_assoc,
pentagon_inv_hom_hom_hom_inv_assoc, Iso.inv_hom_id_assoc,
whiskerLeft_hom_inv_assoc]
slice_lhs 3 4 => rw [← whiskerLeft_comp, ← comp_whiskerRight,
SymmetricCategory.symmetry]
simp only [id_whiskerRight, whiskerLeft_id, Category.id_comp, Category.assoc,
tensorHom_def, tensor_whiskerLeft, whiskerRight_tensor]
monoidal
-- simp? [tensorμ] says:
simp only [tensorμ, braiding_tensor_right_hom, braiding_tensor_left_hom, comp_whiskerRight,
whisker_assoc, Category.assoc, whiskerLeft_comp, pentagon_assoc,
pentagon_inv_hom_hom_hom_inv_assoc, Iso.inv_hom_id_assoc, whiskerLeft_hom_inv_assoc]
slice_lhs 3 4 => rw [← whiskerLeft_comp, ← comp_whiskerRight, SymmetricCategory.symmetry]
simp [tensorHom_def]

Comment on lines +66 to +69
rw [Comon.tensorObj_comul, Category.assoc,
MonoidalCategory.tensorμ_braid_swap,
← Category.assoc, tensorHom_comp_tensorHom,
IsCommComonObj.comul_comm A, IsCommComonObj.comul_comm B]
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.

Suggested change
rw [Comon.tensorObj_comul, Category.assoc,
MonoidalCategory.tensorμ_braid_swap,
← Category.assoc, tensorHom_comp_tensorHom,
IsCommComonObj.comul_comm A, IsCommComonObj.comul_comm B]
rw [Comon.tensorObj_comul, Category.assoc, MonoidalCategory.tensorμ_braid_swap]
simp

Comment on lines +59 to +62
/-- The tensor product of two commutative comonoid objects is again a
commutative comonoid object. The proof reduces the commutativity
equation for `Δ[A ⊗ B]` to `tensorμ_braid_swap` plus the two pointwise
commutativity hypotheses `IsCommComonObj.comul_comm A`, `.comul_comm B`. -/
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 docstring is unnecessary

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

Labels

awaiting-author A reviewer has asked the author a question or requested changes. 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.

2 participants