Zulip Chat Archive
Stream: mathlib4
Topic: Any news on semigroup powers?
Uni Marx (Sep 12 2025 at 15:35):
there's #22517 but from what I can gather from an old topic on here it seems to have been abandoned for performance reasons as well as that it is rather annoying to have another power to implement everywhere. has anyone been thinking about new approaches since then/is the old one still considered more-or-less viable? I'd like to work on some semigroup theory but it's quite hard without basics like this nailed down
Alex Meiburg (Sep 12 2025 at 16:05):
+1, I recently "gave up" on formalizing a big results because it was a bunch of terrible working with semigroup powers. (We're proving a weaker result that it's only true on monoids.)
Kevin Buzzard (Sep 12 2025 at 18:40):
I wonder whether we should just basically merge #22517 and take the hit.
Junyan Xu (Sep 12 2025 at 19:17):
I think this is a good opportunity to unbundle npow from Monoid.
Junyan Xu (Sep 12 2025 at 19:49):
I think there needn't be any change to existing classes: you can just define class SemigroupPNatPow like the class MonoidNPow I extract here.
Uni Marx (Sep 12 2025 at 19:52):
the issue with that is that it's a bit unclear (at least to me) where to insert the extra [MonoidNPow] hypothesis for defeq or extensionality reasons
Uni Marx (Sep 12 2025 at 19:55):
you write
theorem blah [Monoid M] (x : M) : x^n = 1 and specialize it to the integers or whatever, then get potentially confused about mismatching instances, right? not as huge of a deal for semigroups since PNat powers are going to be way less prevalent, but important to keep in mind
Matthew Ballard (Sep 12 2025 at 19:59):
Uni Marx (Sep 12 2025 at 20:02):
What about it?
Kenny Lau (Sep 12 2025 at 20:38):
what's the argument for unbundling npow from Monoid?
Matthew Ballard (Sep 12 2025 at 20:38):
I think there is little value beyond unbundling the data. I started an attempt at factoring out as a parent 29482 but then noticed that elaboration helper class in core.
Matthew Ballard (Sep 12 2025 at 20:43):
Inlined data is more likely to get unfolded unnecessarily.
Eric Wieser (Sep 12 2025 at 21:33):
Kevin Buzzard said:
I wonder whether we should just basically merge #22517 and take the hit.
It's picked up conflicts with Kim's work to use a repeated-squaring power implementation by default
Jovan Gerbscheid (Sep 20 2025 at 12:11):
Is it understood what causes the big performace hit?
Jireh Loreaux (Sep 20 2025 at 13:26):
@Matthew Ballard said on GitHub:
I wonder if extending a new PNatPow class would be better. I have been playing around with this for Monoid but don't have the bandwidth to get things building completely. This might be a more targeted test ground.
Why do you think this would be significantly better?
Matthew Ballard (Sep 20 2025 at 14:39):
I’ve seen these provided as inlined lambdas for the existing pow fields. Those can be more aggressively unfolded. Separately, when autoparams inject something compared to you building it by hand, Lean might need to work to figure they are defeq.
Will it be significantly better? Probably not. Most likely it just becomes another field that needs to be checked when Lean has to unify two instances.
Why does it end up here so often? Better diagnostics would be nice.
Even so gating data carrying stuff to be filled out by typeclass synthesis with actual classes seems like good hygiene regardless. Autoparams can be set in the child classes if desired.
Last updated: Dec 20 2025 at 21:32 UTC