Zulip Chat Archive
Stream: Is there code for X?
Topic: Finsupp-like partial function
Martin Dvořák (Oct 11 2024 at 15:28):
Do we have a notion of functions f : α → Option M
such that f x = none
for all but finitely many x
in Mathlib?
Eric Wieser (Oct 11 2024 at 15:32):
You can use Finsupp with WithZero
(which is Option, but writing none
as 0
)
Martin Dvořák (Oct 11 2024 at 15:36):
I need to work with the actual 0
in this setting. Can I use none
with Finsupp
somehow?
Martin Dvořák (Oct 11 2024 at 15:42):
I guess custom notation will save the day:
notation "∅" => (none : WithZero A)
notation "O" => (some 0 : WithZero A)
Martin Dvořák (Oct 11 2024 at 15:46):
Also, do we have the notion of extension of a partial function? I mean something that maps everything [that the original function maps to some x
] to the same element, but potentially mapping other elements.
Yaël Dillies (Oct 11 2024 at 15:52):
There is a long-wished refactor here. cc @Sky Wilshaw
Yuyang Zhao (Oct 11 2024 at 15:59):
Previous discussion: https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/Finsupp.20generalisations
Martin Dvořák (Oct 11 2024 at 16:01):
When we are at it, what is the best way to eliminate on a Finsupp
constant built using single
and update
s?
Yuyang Zhao (Oct 11 2024 at 16:05):
I also need this generalization in my own repository, which basically copies the API of docs#DFinsupp.
Eric Wieser (Oct 11 2024 at 16:06):
Martin Dvořák said:
When we are at it, what is the best way to eliminate on a
Finsupp
constant built usingsingle
andupdate
s?
@loogle Finsupp, "ind"
loogle (Oct 11 2024 at 16:06):
:search: Finsupp.single_eq_set_indicator, Finsupp.induction_linear, and 111 more
Eric Wieser (Oct 11 2024 at 16:07):
The spelling is with + single
not update
Martin Dvořák (Oct 11 2024 at 16:32):
Martin Dvořák said:
When we are at it, what is the best way to eliminate on a
Finsupp
constant built usingsingle
andupdate
s?
-> #mathlib4 > Finsupp and FreeAbelianGroup
Eric Wieser (Oct 11 2024 at 17:05):
Oh, I thought you meant "eliminate" as in "induct"
Martin Dvořák (Oct 11 2024 at 17:09):
I'm searching for a tactic or lemma such that
import Mathlib
noncomputable def g : ℕ →₀ WithZero Char := fun₀
| 5 => 'x'
| 7 => 'y'
example {n : ℕ} {c : Char} (hnc : g n = c) : False := by
the_tactic at hnc
will give me three cases :
n=5
and c='x'
n=7
and c='y'
n≠5 ∧ n≠7
and c=0
Martin Dvořák (Oct 11 2024 at 17:13):
[updated above]
Martin Dvořák (Oct 11 2024 at 17:16):
Anything smarter (such that for given concrete n
it will eliminate impossible cases) is a plus.
Sky Wilshaw (Nov 21 2024 at 11:02):
Yaël Dillies said:
There is a long-wished refactor here. cc Sky Wilshaw
I think you've motivated me to get this done for mathlib4. It turns out I also need these more general Finsupp
s for something I'm working on.
Sky Wilshaw (Nov 21 2024 at 11:38):
https://github.com/leanprover-community/mathlib4/tree/zeramorphic/finsupp-refactor
Sky Wilshaw (Nov 21 2024 at 11:38):
Code structure and naming suggestions are welcome.
Sky Wilshaw (Nov 21 2024 at 15:31):
#19337 (pinging @Yaël Dillies for a review)
Yaël Dillies (Nov 21 2024 at 15:32):
Will take a while to get to it. Just like the UK, I'm rained under
Eric Wieser (Nov 21 2024 at 15:37):
Instead of replacing Finsupp
, should we replace DFinsupp
?
Sky Wilshaw (Nov 21 2024 at 15:38):
I thought that we were going to unify them both eventually, but that has far reaching implications. I just wanted to get some initial code in to avoid bikeshedding.
Sky Wilshaw (Nov 21 2024 at 15:38):
My use case closely matches Finsupp
API and computability, as well, so I'm biased in that sense.
Last updated: May 02 2025 at 03:31 UTC