Skip to content

chore(Algebra): use IsMulCommutative to spell Std.Commutative (· * ·)#37448

Open
SnirBroshi wants to merge 15 commits intoleanprover-community:masterfrom
SnirBroshi:chore/algebra/std-commutative-to-is-mul-commutative
Open

chore(Algebra): use IsMulCommutative to spell Std.Commutative (· * ·)#37448
SnirBroshi wants to merge 15 commits intoleanprover-community:masterfrom
SnirBroshi:chore/algebra/std-commutative-to-is-mul-commutative

Conversation

@SnirBroshi
Copy link
Copy Markdown
Collaborator

and use IsAddCommutative to spell Std.Commutative (· + ·).

Also makes Is{Mul/Add}Commutative.is_comm instances so that core lemmas (or grind) can synthesize Std.Commutative.


Hopefully this is useful since #36549 was merged.

Open in Gitpod

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

PR summary d4d96de5f1

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ IsCyclic.isMulCommutative
+ instance (priority := low) (M) [MulOne M] [IsMulCommutative M] :
+ isMulCommutative_iff_isLieAbelian
- IsCyclic.commutative
- IsQuadraticExtension.isMulCommutative_galoisGroup
- commGroup_isMulCommutative
- instance (priority := low) (M) [MulOne M] [Std.Commutative (α := M) (· * ·)] :
- instance [Group G] (H : Subgroup G) [IsCyclic H] : IsMulCommutative H

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.

You can run this locally as

./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-group-theory Group theory label Mar 31, 2026
Comment on lines +199 to +200
class IsAddCommutative (M : Type*) [Add M] : Prop where
is_comm : Std.Commutative (α := 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.

The design here seems odd. Why nest typeclasses instead of doing something like this?

Suggested change
class IsAddCommutative (M : Type*) [Add M] : Prop where
is_comm : Std.Commutative (α := M) (· + ·)
abbrev IsAddCommutative (M : Type*) [Add M] : Prop :=
Std.Commutative (α := M) (· + ·)

Copy link
Copy Markdown
Collaborator Author

@SnirBroshi SnirBroshi Apr 1, 2026

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh actually, won't this cause the same performance issues as ContravariantClass has, since TC-search will search through all Std.Commutative instances regardless of the operation?

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.

Yes, I believe the point is exactly that we want to avoid the performance impact of the same class being parameterized over the function.

@SnirBroshi
Copy link
Copy Markdown
Collaborator Author

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Apr 1, 2026

Benchmark results for 6d77e2a against d4d96de are in. There are no significant changes. @SnirBroshi

  • 🟥 build//instructions: +36.5G (+0.02%)

Medium changes (1🟥)

  • 🟥 build/module/Mathlib.GroupTheory.SchurZassenhaus//instructions: +3.9G (+24.41%)

Small changes (5🟥)

  • 🟥 build/module/Mathlib.Data.ZMod.QuotientGroup//instructions: +1.0G (+5.81%)
  • 🟥 build/module/Mathlib.GroupTheory.Focal//instructions: +2.5G (+15.07%)
  • 🟥 build/module/Mathlib.GroupTheory.Schreier//instructions: +917.7M (+6.14%)
  • 🟥 build/module/Mathlib.RepresentationTheory.AlgebraRepresentation.Basic//instructions: +915.0M (+10.59%)
  • 🟥 build/module/Mathlib.Topology.Algebra.StarSubalgebra//instructions: +3.0G (+13.32%)

obtain ⟨b', hb'⟩ := is_surj b
simp only [← ha', ← hb', ← map_mul]
rw [is_comm.comm]
rw [is_comm.is_comm.comm]
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 not use mul_comm' here (and everywhere else)?

Copy link
Copy Markdown
Collaborator Author

@SnirBroshi SnirBroshi Apr 1, 2026

Choose a reason for hiding this comment

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

Done except for SpecificGroups/Dihedral.lean where it can't easily infer the type,
and h'.is_comm.comm (r 1) (sr 0) seems better than mul_comm' (r (n := n + 3) 1) (sr 0)

@j-loreaux j-loreaux added the awaiting-author A reviewer has asked the author a question or requested changes. label Apr 1, 2026
@SnirBroshi
Copy link
Copy Markdown
Collaborator Author

Just testing the abbrev version, I'm interested in seeing the performance

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Apr 1, 2026

Benchmark results for 0c2121f against d4d96de are in. There are no significant changes. @SnirBroshi

  • 🟥 build//instructions: +39.3G (+0.02%)

Medium changes (2🟥)

  • 🟥 build/module/Mathlib.GroupTheory.SchurZassenhaus//instructions: +5.3G (+32.73%)
  • 🟥 build/module/Mathlib.RepresentationTheory.AlgebraRepresentation.Basic//instructions: +2.2G (+25.15%)

Small changes (1✅, 6🟥)

  • 🟥 build/module/Mathlib.Algebra.Star.Subalgebra//instructions: +2.6G (+4.09%)
  • build/module/Mathlib.CategoryTheory.Limits.Types.Coequalizers//instructions: -373.4M (-5.81%)
  • 🟥 build/module/Mathlib.Data.ZMod.QuotientGroup//instructions: +1.7G (+9.71%)
  • 🟥 build/module/Mathlib.GroupTheory.Focal//instructions: +3.1G (+18.84%)
  • 🟥 build/module/Mathlib.GroupTheory.Schreier//instructions: +1.1G (+7.35%)
  • 🟥 build/module/Mathlib.Lean.Meta.Basic//instructions: +143.6M (+3.70%)
  • 🟥 build/module/Mathlib.Topology.Algebra.StarSubalgebra//instructions: +4.8G (+21.58%)

@SnirBroshi
Copy link
Copy Markdown
Collaborator Author

Hmm switching to abbrev seems to have basically the same performance, maybe we don't have enough Std.Commutative instances to see the issue?
In any case I reverted back to a one-field class.

@SnirBroshi SnirBroshi removed the awaiting-author A reviewer has asked the author a question or requested changes. label Apr 1, 2026
@SnirBroshi SnirBroshi requested a review from j-loreaux April 1, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-group-theory Group theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants