Zulip Chat Archive
Stream: mathlib4
Topic: What is `DFinsupp`?
Luna (Sep 05 2025 at 19:56):
I'm trying to find the definition of the internal DirectSum for modules. This led me to DFinsupp and I'm trying to parse exactly what it means.
The definition in mathlib is below:
structure DFinsupp [∀ i, Zero (β i)] : Type max u v where mk' ::
/-- The underlying function of a dependent function with finite support (aka `DFinsupp`). -/
toFun : ∀ i, β i
/-- The support of a dependent function with finite support (aka `DFinsupp`). -/
support' : Trunc { s : Multiset ι // ∀ i, i ∈ s ∨ toFun i = 0 }
From the vibes I'm getting, I think it says that finitely many β i are non-zero, but I'm confused on how support' enforces this. I also don't understand what Trunc is?
And if I'm correct in the above, does that mean that a DirectSum of module is just an (arbitrarily large) product of modules with finite non-zero entries?
Ruben Van de Velde (Sep 05 2025 at 20:09):
It basically says there exists a multiset, and each i is either in that (finite) multiset or maps to zero
Ruben Van de Velde (Sep 05 2025 at 20:10):
I have only the vaguest idea of what Trunc is, though
Weiyi Wang (Sep 05 2025 at 20:10):
DFinsupp.support (without ') probably explains more
Ruben Van de Velde (Sep 05 2025 at 20:12):
Weiyi Wang (Sep 05 2025 at 20:15):
sorry I misremembered how the doc was structured
Weiyi Wang (Sep 05 2025 at 20:15):
The main explanation is in the header of that page
Eric Wieser (Sep 05 2025 at 22:29):
@Luna, is there something we could add to the docstring of docs#DFinsupp itself to make this more obvious? Ideally the docstring should be enough to tell you what DFinsupp means without you having to dig into how it's implemented.
Alfredo Moreira-Rosa (Sep 06 2025 at 00:39):
@Eric Wieser i think a link to wikipedia would be good. When you pointed out to me to use DFinsupp, the docs where obscur to me, but when reading the wikipedia page, it all became clear :
https://en.wikipedia.org/wiki/Support_(mathematics)
And in general, i think mathlib should point whenever possible to wikipedia or another math source to expand on the mathematics behind some mathlib definitions
Violeta Hernández (Sep 06 2025 at 02:54):
Ruben Van de Velde said:
I have only the vaguest idea of what Trunc is, though
It's the quotient by the always true relationship
Violeta Hernández (Sep 06 2025 at 02:56):
The idea with DFinsupp is that it's often computationally expensive/and or requires extra decidability assumptions to compute the exact support of a function (e.g. the support of f + g might be an arbitrary subset of the union of both supports), so you instead compute some superset. What Trunc does is ensure that even if two finsupps have different support supersets, they remain propositionally equal.
Violeta Hernández (Sep 06 2025 at 06:43):
(My question is, what stops us from copying this design to Finsupp?)
Ruben Van de Velde (Sep 06 2025 at 08:25):
Oh right, the clever thing is that the multiset can still include elements that map to zero, but nothing outside it can map to something nonzero
Eric Wieser (Sep 06 2025 at 08:32):
Violeta Hernández said:
(My question is, what stops us from copying this design to
Finsupp?)
There'd be little point, we might as well just make Finsupp an abbrev for DFinsupp if we're going to use the same design
Violeta Hernández (Sep 06 2025 at 08:32):
Well, what stops us from doing that?
Violeta Hernández (Sep 06 2025 at 08:33):
Is it just "no one has wanted to do it yet", or are there other considerations?
Eric Wieser (Sep 06 2025 at 08:41):
It's too big a thing to do / review in one go
Eric Wieser (Sep 06 2025 at 08:42):
@Yaël Dillies is working on adding some abstraction barriers which will make it easier to do piecewise
Eric Wieser (Sep 06 2025 at 08:42):
#25324 also works in that direction
Luna (Sep 06 2025 at 17:14):
Eric Wieser said:
Luna, is there something we could add to the docstring of docs#DFinsupp itself to make this more obvious? Ideally the docstring should be enough to tell you what DFinsupp means without you having to dig into how it's implemented.
Ah the above makes sense. I think it was just the combination of seeing Trunc and Multiset that through me for a loop.
Also is there a reason why its defined with Multiset instead of Finset? Could support equally be defined like support' : {s : Finset ι // ∀ i, i ∉ s → β i = 0}?
Eric Wieser (Sep 06 2025 at 17:17):
Finset would require decidable equality for adding the functions
Luna (Sep 06 2025 at 17:19):
Oh ok! To compute a Finset, you need to remove duplicates which means that equality needs to be decidable. So the solution is to use a Multiset and just don't remove duplicates.
Luna (Sep 06 2025 at 17:20):
A tangential question, why does Mathlib care about computability? Are there efforts to create algorithms from various theorems?
Eric Wieser (Sep 06 2025 at 17:21):
Computability is a property of definitions not theorems
Luna (Sep 06 2025 at 17:22):
Or maybe I'm using the wrong word. Why is decidability important for Mathlib?
Aaron Liu (Sep 06 2025 at 17:23):
Luna said:
Or maybe I'm using the wrong word. Why is decidability important for Mathlib?
it means you can #eval your definitions
Aaron Liu (Sep 06 2025 at 17:23):
usually it also means you can #reduce your definitions
Ruben Van de Velde (Sep 06 2025 at 18:23):
It's not considered particularly important in mathlib, but sometimes it can be helpful to be able to tell the computer "just run the algorithm"
Violeta Hernández (Sep 07 2025 at 00:51):
Decidability is one of those things that's great when it works and a total pain point when it doesn't
Luna (Sep 08 2025 at 04:13):
I have another related question, what is the conceptual definition of DFinsupp.sumAddHom? I'm having a lot of trouble parsing/following along its definition. Can someone write out in standard mathematical notation what the function is supposed to be?
Luna (Sep 08 2025 at 04:20):
And thanks for the responses all. @Aaron Liu I'm still on chapter 10 for MIL but it hasn't talked much about decidability and its uses with #eval. When is it used in mathlib? Off the top of my head, I'm imagining it can be used for not just knowing a matrix can be put into RREF but actually compute the entries of the matrix when its reduced to RREF?
Ruben Van de Velde (Sep 08 2025 at 07:29):
Given a iota-indexed dfinsupp f and a iota-indexed collection of functions φ that preserve addition (i.e. g (x + y) = g x + g y), sumAddHom φ is another function that preserves addition, and sumAddHom φ f is the sum of φ i (f i) for all i in the support of f
Ruben Van de Velde (Sep 08 2025 at 07:30):
So if iota is {0, 1} and \phi 0 (f 0) = 3, \phi 1 (f 0) = 5, then sumAddHom \phi f = 3 + 5
Ruben Van de Velde (Sep 08 2025 at 07:30):
I think I got that right, at least
Luna (Sep 08 2025 at 14:07):
Ah! Ok so putting it into my own words, its doing the following:
Given and , where is a module homomorphism and s.t. finitely many are non-zero. Then sumAddHom Φ X is
And this is well-defined because there is finitely non-zero (e.g. a finite support).
Is that correct?
Kevin Buzzard (Sep 08 2025 at 15:35):
Yes that looks right. The input is additive group homs for all and the output is an additive group hom defined as the sum of the (i.e. how you said it was defined).
Kevin Buzzard (Sep 08 2025 at 15:37):
I agree that the docstring is useless. Please make a PR changing it! The docstring seems to be assuming that you've read some of the docstrings above it, which IMO a docstring should never do.
Eric Wieser (Sep 08 2025 at 15:46):
Note that using in the docstring would be wrong, since that docs#DirectSum.toModule instead!
Kevin Buzzard (Sep 08 2025 at 16:08):
Bleurgh so we have two ways of saying the same thing?
Eric Wieser (Sep 08 2025 at 16:35):
One has convolutive multiplication, the other doesn't (and should have pointwise)
Eric Wieser (Sep 08 2025 at 16:35):
DFinsupp is to DirectSum as Finsupp is to AddMonoidAlgebra
Last updated: Dec 20 2025 at 21:32 UTC