Commit 2026-06-25 19:06 68b30e53
View on Github →feat: NSMul/NPow type class (#38036)
This PR is adds NSMul, NPow, ZSMul and ZPow classes for the nsmul, npow, zsmul, zpow data fields.
This has a few advantages:
- If you first declare a
SMulinstance, then you don't need to manually writensmul := (· • ·)andzsmul := (· • ·). ForPow, the extra benefit is that inferring the instance is preferred over the default fieldnpowRecAuto. So this helps avoid accidental diamonds. - If you first declare a
SMulinstance on a type synonym, theninferInstanceAswill infer thensmulfield from theSMulinstance. This makes it easier to avoid diamonds on type synonyms likeMatrixandMonoidAlgebra. - The not-yet-merged instance diamond linter will be able to detect cases where the
NSMulandSMulclasses do not agree. In the process of making this PR, I have identified two existingNPowdiamonds: - In
Mathlib.Algebra.Order.Positive.Field, there were two conflictingNPowinstances. - For
Fin, there are two conflictingNPowinstances. I have overwritten the one in core lean with the one from mathlib that is more computationally efficient. TODO: the same forQSMulandNNQSMul.