Zulip Chat Archive

Stream: mathlib4

Topic: DirectSum defeqs


Johan Commelin (Mar 11 2025 at 10:31):

DirectSum is defined to be DFinsupp, and this defeq is used a lot, for example to write x.sum when x is a term of a direct sum, but the .sum refers to DFinsupp.sum.
However, this leads to proofs like

theorem mul_eq_dfinsupp_sum [ (i : ι) (x : A i), Decidable (x  0)] (a a' :  i, A i) :
    a * a'
      = a.sum fun _ ai => a'.sum fun _ aj => DirectSum.of _ _ <| GradedMonoid.GMul.mul ai aj := by
  change mulHom _ a a' = _
  -- Porting note: I have no idea how the proof from ml3 worked it used to be
  -- simpa only [mul_hom, to_add_monoid, dfinsupp.lift_add_hom_apply, dfinsupp.sum_add_hom_apply,
  -- add_monoid_hom.dfinsupp_sum_apply, flip_apply, add_monoid_hom.dfinsupp_sum_add_hom_apply],
  rw [mulHom, toAddMonoid, DFinsupp.liftAddHom_apply]
  dsimp only [DirectSum]
  rw [DFinsupp.sumAddHom_apply, AddMonoidHom.dfinsupp_sum_apply]
  apply congrArg _
  simp_rw [flip_apply]
  funext x
  -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
  erw [DFinsupp.sumAddHom_apply]
  simp only [gMulHom, AddMonoidHom.dfinsupp_sum_apply, flip_apply, coe_comp, AddMonoidHom.coe_mk,
    ZeroHom.coe_mk, Function.comp_apply, AddMonoidHom.compHom_apply_apply]

Should DirectSum be an abbrev? Or a 1-field structure?
It seems to me that at the moment it is trying to act a bit like both.

Eric Wieser (Mar 11 2025 at 10:36):

I tried to set things up such that DFinsupp : DirectSum :: Finsupp : AddMonoidAlgebra

Eric Wieser (Mar 11 2025 at 10:38):

Which in theory would include one using pointwise multiplication and the other using convolutive multiplication, which rules out an abbrev

Eric Wieser (Mar 11 2025 at 10:38):

As an aside, docs#mul_eq_dfinsupp_sum looks like it should be true by definition, at least if the RHS is adjusted to use DirectSum APIs

Eric Wieser (Mar 11 2025 at 10:42):

I think a one-field structure (with name coeff or component) would be sensible here. That could also remove the coercion to function, which is maybe desirable.

Riccardo Brasca (Mar 11 2025 at 10:50):

It looks a good idea to me.

Eric Wieser (Mar 11 2025 at 10:56):

@Damiano Testa and I talked about doing the same thing for MonoidAlgebra two years ago

Eric Wieser (Mar 11 2025 at 10:56):

docs#SkewMonoidAlgebra got the right treatment at least

Damiano Testa (Mar 11 2025 at 12:43):

I remember the conversation and I also started to refactor, but as I was doing it, it became apparent that untangling MonoidAlgebra and AddMonoidAlgebra was a very useful preliminary step, but I did not have the capacity to do that!

Matthew Ballard (Mar 11 2025 at 13:57):

I think an abbrev is a bad idea. I started a refactor via a structure wrapper a while back but got led off into the sorry state of deriving handlers which never produced anything.

Eric Wieser (Mar 11 2025 at 14:09):

I think more automation for single-field structures is perhaps a better investment than doing this refactor

Eric Wieser (Mar 11 2025 at 14:09):

(in that we need it anyway, and it will make the refactor easier)

Matthew Ballard (Mar 11 2025 at 14:14):

It would be nice not to make life harder when doing the prudent thing.


Last updated: May 02 2025 at 03:31 UTC