Commit 2026-07-04 08:56 61303857
View on Github →refactor(Algebra): make MonoidAlgebra into a one-field structure (#38714)
Replace
def MonoidAlgebra (R M : Type*) [Semiring R] : Type _ := M →₀ R
by
structure MonoidAlgebra (R M : Type*) [Semiring R] where
ofCoeff :: coeff : M →₀ R
and similarly for AddMonoidAlgebra. Since elements of MonoidAlgebra R M shouldn't be considered as finitely supported functions M → R anymore, I also remove the coercion to functions.
This is a major change with many ramifications in mathlib. The foremost consequence is that it is now by design impossible to abuse defeqs by using Finsupp API on MonoidAlgebra. There are more consequences:
coeffis now used very widely. Many lemma names are renamed to containcoeffsince their type signature changed.- For convenience, I copy more
FinsuppAPI over toMonoidAlgebra. This includes induction principles (induction) and linear combinations (supported). - The existing API copied over from
Finsupphas no reason to be so throughabbrev(anymore?/ever), so I make themdefs instead. - Many equalities in
MonoidAlgebrathat were previously obtained through direct applications of the relevantFinsupplemmas are now replaced byext; simp. - Many
set_option backward.isDefEq.respectTransparency falseare removed and a similar (but slightly smaller) number are added, essentially because we are pushing further the boundary of abuse. In many cases, the easiest solution to something breaking was to rid it of its own abuse. Therefore the following that changes that are a priori orthogonal to the titular change were made: - Make
PolynomialModulea one-field structure, similarly toMonoidAlgebra. - Deduce the
MvPolynomialbase change results from theAddMonoidAlgebraones. In particular, theAddMonoidAlgebraones take the base ring on the left while theMvPolynomialones took it on the right. Left is the correct side because of how heterogeneous base change is set up in mathlib. - Make the representation theory library use
MonoidAlgebramore, whereas previously it was usingMonoidAlgebraandFinsuppinterchangeably. - Add
ModuleCat.monoidAlgebraFreeas an alternative toModuleCat.freethat usesMonoidAlgebrainstead ofFinsupp. This is useful to fix homological results that broke due to point 3. Some points that are left as future work: Polynomial Ris currently defined as a one-field structure aroundAddMonoidAlgebra R ℕ. Pending performance, it could become anabbrevinstead.MonoidAlgebracould become anabbrevofSkewMonoidAlgebrasince it is a special case of it. In fact,SkewMonoidAlgebracould itself become a special case ofCrossProductAlgebrafrom BrauerGroup.MvPowerSeriesandPowerSeriesshould follow the same treatment asMonoidAlgebra.Finsuppshould become anabbrevof (non-dependent)DFinsupp. This becomes easier after the current PR since theFinsuppAPI is used much less widely.