Skip to content

feat(LinearAlgebra/TensorAlgebra): implement HopfAlgebra for TensorAlgebra#31898

Open
ntapiam wants to merge 25 commits into
leanprover-community:masterfrom
ntapiam:tensor_hopf
Open

feat(LinearAlgebra/TensorAlgebra): implement HopfAlgebra for TensorAlgebra#31898
ntapiam wants to merge 25 commits into
leanprover-community:masterfrom
ntapiam:tensor_hopf

Conversation

@ntapiam

@ntapiam ntapiam commented Nov 21, 2025

Copy link
Copy Markdown
Contributor

implementation of the natural Hopf algebra structure on the TensorAlgebra

@github-actions github-actions Bot added new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) labels Nov 21, 2025
@ntapiam

ntapiam commented Nov 21, 2025

Copy link
Copy Markdown
Contributor Author

-awaiting-author

@github-actions github-actions Bot added the t-algebra Algebra (groups, rings, fields, etc) label Nov 21, 2025
@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 Nov 21, 2025
@github-actions

github-actions Bot commented Nov 21, 2025

Copy link
Copy Markdown

PR summary 0a01e3ed11

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.RingTheory.Bialgebra.FreeAlgebra (new file) 875
Mathlib.RingTheory.Bialgebra.TensorAlgebra (new file) 886
Mathlib.RingTheory.HopfAlgebra.TensorAlgebra (new file) 888

Declarations diff

+ algebraMapInv_ι
+ algebraMapInv_ι_apply
+ algebraMapInv_ι_eq_zero
+ antipode
+ antipode_algebraMap_apply
+ antipode_antihom
+ antipode_antihom_apply
+ antipode_ι_apply
+ comul
+ comul_ι
+ instHopfAlgebra
++ instBialgebra

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).

@kckennylau kckennylau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The review is not finished (there's still a very long proof that I haven't gone over), but I think I've pointed out enough things to fix for the moment. Please ping me (@kenny Lau) on Zulip when you're done.

Comment thread Mathlib/LinearAlgebra/TensorAlgebra/Hopf.lean Outdated
Comment thread Mathlib/LinearAlgebra/TensorAlgebra/Hopf.lean Outdated
Comment thread Mathlib/LinearAlgebra/TensorAlgebra/Hopf.lean Outdated
Comment thread Mathlib/LinearAlgebra/TensorAlgebra/Hopf.lean Outdated
Comment on lines +39 to +41
/-- Antipode in `TensorAlgebra R M` as an algebra map. -/
def antipode : T[M] →ₗ[R] T[M] := (MulOpposite.opLinearEquiv R).symm.comp
(lift R ((MulOpposite.opLinearEquiv R).comp (-(ι R)))).toLinearMap

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(MulOpposite.opLinearEquiv R): but R is commutative?

@ntapiam ntapiam Nov 22, 2025

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.

MulOpposite.opLinearEquiv R has implicit parameter {N} [AddCommMonoid N] [Module R N] so it is actually of type T[M] →ₗ[R] T[M]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think you understood my point. What I meant is that R is commutative so MulOpposite.opLinearEquiv R is just the identity map.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think I'm wrong here, it seems like you wanted to do MulOpposite for T[M].

Comment thread Mathlib/LinearAlgebra/TensorAlgebra/Hopf.lean Outdated
Comment thread Mathlib/LinearAlgebra/TensorAlgebra/Hopf.lean Outdated
Comment thread Mathlib/LinearAlgebra/TensorAlgebra/Hopf.lean Outdated
simp

@[simp]
lemma antipode_ι_apply (x : M) : antipode R ((ι R) x) = -(ι R) x := by

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If this is true, doesn't it mean that the antipode is just negation? In this case, it would just be LinearEquiv.neg.

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.

This holds only on the image of ι R. For example

antipode R (ι R x * ι R y) = ι R y * ι R x

In general, for x in T[M]

antipode R ((tprod R M n) x) = (-1)^n • (tprod R M n) (fun i => x (n - i))

so there's an alternating minus sings and a reversal. I'm not sure if this is the best way to write it.

Comment thread Mathlib/LinearAlgebra/TensorAlgebra/Hopf.lean Outdated
@kckennylau kckennylau added the awaiting-author A reviewer has asked the author a question or requested changes. label Nov 21, 2025
@kckennylau

Copy link
Copy Markdown
Collaborator

Also, welcome to Mathlib! I hope that this PR will teach you a lot about how to write better Lean/Mathlib code.

@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.

I'm confused: Aren't you duplicating the content of Mathlib.RingTheory.HopfAlgebra.TensorProduct? Also, just so you know, there's more Hopf algebra material in Toric that's currently being upstreamed.

@ntapiam

ntapiam commented Nov 22, 2025

Copy link
Copy Markdown
Contributor Author

Thanks you both for your comments!

I'm confused: Aren't you duplicating the content of Mathlib.RingTheory.HopfAlgebra.TensorProduct? Also, just so you know, there's more Hopf algebra material in Toric that's currently being upstreamed.

@YaelDillies I think this is different as, as far as I understand, the file you mention proves that the tensor product of two Hopf algebras is again a Hopf algebra, while here I'm showing that the tensor algebra itself is a Hopf algebra where the coproduct is naturally induced by its freeness as an algebra (lift of (x : M) → ι R x ⊗ₜ[R] 1 + 1 ⊗ₜ[R] ι R x).

I'm not sure that this can be deduced from HopfAlgebra.ofAlgHom since antipode in this case is not an algebra homomorphism, but an antihomomorphism, which it always is.

It may be interesting to add those results to Mathlib.RingTheory.HopfAlgebra.Basic, maybe?

The reason I'm interested in this particular structure is that it–and its dual, the shuffle algebra–appears very frequently in my field (rough paths).

@YaelDillies

Copy link
Copy Markdown
Contributor

Ah yes, thank you for the clarification. I would put this in RingTheory.HopfAlgebra.TensorAlgebra.

@YaelDillies YaelDillies added t-ring-theory Ring theory and removed t-algebra Algebra (groups, rings, fields, etc) labels Nov 22, 2025
@ntapiam

ntapiam commented Nov 22, 2025

Copy link
Copy Markdown
Contributor Author

I could move it to a new file after the review is done.
Also, shouldn't HopfAlgebra.ofAlgHom be changed to something like HopfAlgebra.ofLinearMap since AFAIK it's very rare that antipode is actually an AlgHom.

In this file, at some point I tried defining it as antipode : T[M] →ₐ[R] T[M]ᵐᵒᵖ but that really only caused me problems because of the MulOpposites, which I didn't know how to handle, so I ended up with just T[M] →ₗ[R] T[M]. What's the preferred Mathlib way of dealing with antihoms?

@ntapiam

ntapiam commented Nov 22, 2025

Copy link
Copy Markdown
Contributor Author

-awaiting-author

@github-actions github-actions Bot removed the awaiting-author A reviewer has asked the author a question or requested changes. label Nov 22, 2025
Comment thread Mathlib/RingTheory/HopfAlgebra/TensorAlgebra.lean Outdated
Comment thread Mathlib/RingTheory/HopfAlgebra/TensorAlgebra.lean Outdated
Comment thread Mathlib/RingTheory/HopfAlgebra/TensorAlgebra.lean Outdated
Comment thread Mathlib/RingTheory/HopfAlgebra/TensorAlgebra.lean
open Algebra Bialgebra Coalgebra in
instance instHopfAlgebra : HopfAlgebra R T[M] where
antipode := antipode R
mul_antipode_rTensor_comul := by

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.

Why is the proof of this so long? Can you explain why this proof is difficult?

@ntapiam ntapiam Nov 22, 2025

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.

This may be due in part to my own incompetence with Lean/Mathlib, apologies.

The more straightforward proof uses that if A is generated as an algebra by its primitive elements, then then antipode is the unique anti alg hom such that antipode R x = -x for all primitive elements.
This is exactly the case here, but I don't know if such a result is available in Mathlib or how to use them.

Short of that, the pen-and-paper proof I know, which I tried to reproduce here (see image below), makes heavy use of Sweedler's notation, and the inductive nature of the Tensor Algebra. It then involves some juggling around with products such as the little assoc4 lemma in the proof.

Maybe this could be simplified, I tried my best.

image

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.

Could you try doing the proof involving primitive elements, to compare?

@ntapiam ntapiam Nov 22, 2025

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.

The argument is more abstract. If you know there is an antipode (in this case there is by graded connectedness), it must satisfy antipode R x = -x for all primitives. The tensor algebra is generated as an algebra by the image of ι R which is a submodule of the module of primitive elements. Therefore, any linear map f : M →ₗ[R] T[M] satisfying f ∘ₗ ι R = -ι R must be the antipode.

This argument bypasses showing the required identity altogether, so I'm not sure how difficult it would be to implement it in Mathlib.

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.

Try it, and come back to us if/when you get stuck 😉

@YaelDillies YaelDillies added the awaiting-author A reviewer has asked the author a question or requested changes. label Nov 22, 2025
@ntapiam

ntapiam commented Nov 22, 2025

Copy link
Copy Markdown
Contributor Author

-awaiting-author

@github-actions github-actions Bot removed the awaiting-author A reviewer has asked the author a question or requested changes. label Nov 22, 2025
@erdOne erdOne added the awaiting-author A reviewer has asked the author a question or requested changes. label Nov 23, 2025

@kckennylau kckennylau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Again I have not touched your long proof yet, because we haven't cleared up the definitions before.

Comment thread Mathlib/RingTheory/Bialgebra/TensorAlgebra.lean Outdated
Comment thread Mathlib/RingTheory/Bialgebra/TensorAlgebra.lean Outdated
Comment thread Mathlib/RingTheory/Bialgebra/TensorAlgebra.lean Outdated
Comment on lines +39 to +41
/-- Antipode in `TensorAlgebra R M` as an algebra map. -/
def antipode : T[M] →ₗ[R] T[M] := (MulOpposite.opLinearEquiv R).symm.comp
(lift R ((MulOpposite.opLinearEquiv R).comp (-(ι R)))).toLinearMap

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think you understood my point. What I meant is that R is commutative so MulOpposite.opLinearEquiv R is just the identity map.

Comment on lines +51 to +54
instance instBialgebra : Bialgebra R T[M] := Bialgebra.ofAlgHom (comul R) algebraMapInv
(by ext; simpa [comul, Algebra.TensorProduct.one_def, add_tmul, tmul_add] using by abel)
(by ext; simp [comul, algebraMapInv])
(by ext; simp [comul, algebraMapInv])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
instance instBialgebra : Bialgebra R T[M] := Bialgebra.ofAlgHom (comul R) algebraMapInv
(by ext; simpa [comul, Algebra.TensorProduct.one_def, add_tmul, tmul_add] using by abel)
(by ext; simp [comul, algebraMapInv])
(by ext; simp [comul, algebraMapInv])
instance instBialgebra : Bialgebra R T[M] := Bialgebra.ofAlgHom (comul R) algebraMapInv
(by ext; simpa [Algebra.TensorProduct.one_def, add_tmul, tmul_add] using by abel)
(by ext; simp)
(by ext; simp)

Since you have the simp lemmas above, you don't need to unfold them here anymore.

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.

for some reason I can't get it to accept just simp but I have to do simp [comul] for it to unfold the definition.

Comment thread Mathlib/Algebra/FreeAlgebra.lean Outdated
Comment thread Mathlib/RingTheory/Bialgebra/FreeAlgebra.lean Outdated
Comment thread Mathlib/RingTheory/Bialgebra/FreeAlgebra.lean Outdated
Comment on lines +15 to +16
The comultiplication is the unique algebra map satisfying `comul (ι R x) = ι R x ⊗ 1 + 1 ⊗ ι R
x` for all `x : M`, and `algebraMapInv` acts as the counit.

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.

Can you add lemmas stating these?

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.

I added a lemma for comul. The ones for algebraMapInv should be Bialgebra.counit_*

Comment thread Mathlib/RingTheory/Coalgebra/FreeAlgebra.lean Outdated
@mathlib-merge-conflicts mathlib-merge-conflicts 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 May 23, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

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

@hawkrobe

hawkrobe commented May 24, 2026

Copy link
Copy Markdown
Contributor

It would be nice to have something like HopfAlgebra.ofAlgHom for the general case.

Feel free to write it 🙂

@ntapiam @YaelDillies @kckennylau: I opened #39785 and #39841 which lift this Sweedler proof to a general HopfAlgebra.ofPrimitives constructor so the proof could become something like:

  namespace TensorAlgebra

  open MulOpposite LinearMap

  variable (R : Type*) [CommRing R] {M : Type*} [AddCommGroup M] [Module R M]

  instance instHopfAlgebra : HopfAlgebra R (TensorAlgebra R M) :=
    HopfAlgebra.ofPrimitives
      (lift R <| (opLinearEquiv R).toLinearMap ∘ₗ (-ι R : M →ₗ[R] _))
      (s := Set.range (ι R))
      adjoin_range_ι
      (fun p ⟨m, rfl⟩ =>
        { counit_eq_zero := by simpa using algebraMapInv_ι_apply m
          comul_eq_tmul_one_add_one_tmul := comul_ι m })
      (fun p ⟨m, rfl⟩ => by simp)

  end TensorAlgebra

hawkrobe added a commit to hawkrobe/mathlib4 that referenced this pull request May 24, 2026
Generalize `ofAlgHom` to take `A →ₐ[R] Aᵐᵒᵖ` (non-commutative case
via the opposite ring), and add `rTensor/lTensorAntipodeEqualizer`
subalgebras + `mul_*_comul_eq_of_mem_adjoin` corollaries that let
consumers verify the antipode axiom on a generating set
(Takeuchi 1971, Lemma 1).

Motivates leanprover-community#31898: the TensorAlgebra Hopf instance reduces from a
~100-line Sweedler proof to a ~16-line application of the new API.
hawkrobe added a commit to hawkrobe/mathlib4 that referenced this pull request May 28, 2026
…via the quotient

`SymmetricAlgebra R M` is `RingQuot SymRel`, so its bialgebra and Hopf algebra
instances are inherited from `TensorAlgebra R M` through the quotient
construction: `SymRel` satisfies `IsBialgebraRel`/`IsHopfRel`, with the relation
conditions following from commutativity of the quotient. Replaces the direct
`ofAlgHom` constructions.

(Branch carries its dependencies leanprover-community#39790 and leanprover-community#31898 -- the latter built via
`HopfAlgebra.ofPrimitives` and generalized to `[AddCommMonoid M]` -- until they
land on master, at which point this rebases to the two `SymmetricAlgebra` files.)
mathlib-bors Bot pushed a commit that referenced this pull request Jun 3, 2026
The antipode of a Hopf algebra is [generally](https://arxiv.org/pdf/1409.8356) the two-sided inverse of the identity in the convolution algebra `End(A)`. When `A` is commutative, algebra homs are closed under convolution and this lifts to AlgHom equality. See [this comment](#31898 (comment)) on #31898.
Bergschaf pushed a commit to Bergschaf/mathlib4 that referenced this pull request Jun 3, 2026
…over-community#39785)

The antipode of a Hopf algebra is [generally](https://arxiv.org/pdf/1409.8356) the two-sided inverse of the identity in the convolution algebra `End(A)`. When `A` is commutative, algebra homs are closed under convolution and this lifts to AlgHom equality. See [this comment](leanprover-community#31898 (comment)) on leanprover-community#31898.
ReemMelamed pushed a commit to ReemMelamed/mathlib4 that referenced this pull request Jun 20, 2026
…over-community#39785)

The antipode of a Hopf algebra is [generally](https://arxiv.org/pdf/1409.8356) the two-sided inverse of the identity in the convolution algebra `End(A)`. When `A` is commutative, algebra homs are closed under convolution and this lifts to AlgHom equality. See [this comment](leanprover-community#31898 (comment)) on leanprover-community#31898.
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. 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-ring-theory Ring theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants