Zulip Chat Archive
Stream: mathlib4
Topic: Refactoring multiplicity
Daniel Weber (Sep 15 2024 at 16:43):
Would refactoring docs#multiplicity to be noncomputable and return values in ℕ∞
instead of PartENat
be good?
Edward van de Meent (Sep 15 2024 at 19:28):
i seem to recall that removing PartENat
in favour of ℕ∞
is somewhere on the list of todos, but i could be wrong.
Geoffrey Irving (Sep 15 2024 at 20:36):
Why would ℕ∞
make it noncomputable?
Yaël Dillies (Sep 15 2024 at 20:38):
because you can't know whether a finite value satisfying the predicate exists, and PartENat
nicely avoids that issue by making equality with ∞
be noncomputable instead
Antoine Chambert-Loir (Sep 15 2024 at 20:45):
What is the gain in this modification ?
Daniel Weber (Sep 16 2024 at 01:52):
PartENat is really annoying to work with
Daniel Weber (Sep 16 2024 at 04:50):
Another option is to have it return values in Nat
, with a junk value when it's infinite
Michael Stoll (Sep 16 2024 at 09:39):
See also here.
Riccardo Brasca (Sep 16 2024 at 10:25):
I am not 100% the junk value solution will work well, since (for example) having multiplicity 0
is a meaningful concept. But it also true that working with multiplicity now is a little pain.
Daniel Weber (Sep 16 2024 at 10:27):
Perhaps we could have both versions, like with dist and edist and degree and natDegree?
Ruben Van de Velde (Sep 16 2024 at 10:38):
In the unix style, we could use Int and return -1 as a junk value
Riccardo Brasca (Sep 16 2024 at 10:41):
Ruben Van de Velde said:
In the unix style, we could use Int and return -1 as a junk value
I would really like to be able to write p^(multiplicity p n)
...
Daniel Weber (Sep 16 2024 at 11:00):
Perhaps 1
makes more sense as a junk value? This keeps multiplicity p n = 0 ↔ ¬p ∣ n
Daniel Weber (Sep 16 2024 at 11:04):
Although it breaks multiplicity a 1 = 0
Johan Commelin (Sep 16 2024 at 12:57):
I think it's fine to have two versions. We could rename the current version to eMultiplicity
to free up multiplicity
. Or we could have a new concept called natMultiplicity
.
Johan Commelin (Sep 16 2024 at 12:58):
Riccardo Brasca said:
I would really like to be able to write
p^(multiplicity p n)
...
I agree, and right now you can't do that either, right? Because you can't raise something to the power k : partEnat
.
Johan Commelin (Sep 16 2024 at 13:00):
Maybe we should have a Part.get!
and a partEnat.get! that return junk (read: default) values. If we do that, we're sorta forced to use
0` as junk value.
Daniel Weber (Sep 16 2024 at 13:28):
I'm trying to create a natMultiplicity
, but I'm unsure how general stuff should be. docs#le_multiplicity_map, for instance - should it take Finite (f a) (f b)
, or the weaker Finite a b → Finite (f a) (f b)
?
Kevin Buzzard (Sep 16 2024 at 13:30):
Surely it should just be exactly as general as the corresponding multiplicity
stuff?
Daniel Weber (Sep 16 2024 at 13:31):
Yes, but this creates a problem in theorems like docs#multiplicity_eq_multiplicity_iff - I need to take an assumption like Finite a b ↔ Finite c d
.
Kevin Buzzard (Sep 16 2024 at 13:32):
Oh I see -- the corresponding theorem really isn't true. I get your point now.
Kevin Buzzard (Sep 16 2024 at 13:36):
The problem with the weaker assumption is that probably in practice I'll have h1 : Finite a b
and h2 : Finite c d
and I don't really want to be faced with a proof obligation that they're logically equivalent. My instinct is just to assume basic finiteness assumptions needed to make the theorems true i.e. Finite a b
and Finite c d
. If people want more general versions then they can add them later.
Edward van de Meent (Sep 16 2024 at 13:42):
import Mathlib
variable (A B : Prop)
example (a:A) (b:B) : A ↔ B := by tauto
besides the point, but proving that they're equivalent is easy?
Edward van de Meent (Sep 16 2024 at 13:43):
(assuming you do indeed have proofs of both)
Daniel Weber (Sep 16 2024 at 13:43):
Yes, but doing it every time it you're doing a bunch of rewrites can be annoying
Edward van de Meent (Sep 16 2024 at 13:43):
fair
Daniel Weber (Sep 16 2024 at 13:45):
What's docs#has_dvd.dvd.multiplicity_pos ? Is this something that was missed in the port?
Daniel Weber (Sep 16 2024 at 13:45):
docs3#has_dvd.dvd.multiplicity_pos
Kevin Buzzard (Sep 16 2024 at 13:47):
I see -- it's enabling dot notation for a terms of a type which was since renamed :-/
Filippo A. E. Nuccio (Sep 16 2024 at 14:26):
I remember discussing this with @Sébastien Gouëzel who agreed that this PartENat
is painful. I would be very much in favour of having multiplicity valued in ℕ∞
as the default, and if needed to keep both verisons.
Riccardo Brasca (Sep 16 2024 at 14:31):
Johan Commelin said:
Riccardo Brasca said:
I would really like to be able to write
p^(multiplicity p n)
...I agree, and right now you can't do that either, right? Because you can't raise something to the power
k : partEnat
.
Yes, it is already a pain. I think that having two versions is a good idea. Maybe a typeclass saying that the multiplicity of all nonunits (or whatever it is needed) is always finite.
Daniel Weber (Sep 16 2024 at 15:02):
I refactored to an ℕ
-valued version at branch#CM_multiplic, if anybody wants to take a look
Daniel Weber (Sep 17 2024 at 06:10):
Daniel Weber (Sep 17 2024 at 06:11):
hmm, this makes docs#padicValNat noncomputable
Daniel Weber (Sep 17 2024 at 07:10):
I'm uncertain what to do with the results in Data.Nat.Multiplicity - should they use emultiplicity
or multiplicity
?
Riccardo Brasca (Sep 17 2024 at 07:28):
I would say multiplicity
, but which one requires less dependencies?
Daniel Weber (Sep 17 2024 at 07:33):
They are in the same file
Matthew Ballard (Sep 17 2024 at 09:19):
Daniel Weber said:
hmm, this makes docs#padicValNat noncomputable
The csimp
on docs#padicValNat.padicValNat_eq_maxPowDiv restores code generation
Eric Wieser (Sep 17 2024 at 18:39):
There was a suggestion elsewhere to just implement padicValNat from scratch to be kernel reducible, which could make it computable at the same time.
Daniel Weber (Sep 18 2024 at 05:47):
#16881 passes CI now! If anybody is able to review it that'd be great
Kevin Buzzard (Sep 18 2024 at 08:37):
That's quite a large diff! However perhaps this is inevitable, and changes like
make me feel like it's making mathlib more readable. Also the removal of random [@DecidableRel R[X] (· ∣ ·)]
s makes me happy too, although I'm very much on the noncomputable side of things when it comes to mathlib decisions.
Riccardo Brasca (Sep 18 2024 at 08:59):
I think that the way to go is the following: do we agree we want both version? I personally do. If this is the case you can split the PR in at least two: first of all just rename multiplicity
to emultiplicity
, without adding anything else, and in a following PR add the new multiplicity
.
Michael Stoll (Sep 18 2024 at 09:07):
I agree that it makes sense to have both emultiplicity
(ENat
-valued) and a Nat
-valued multiplicity
. Getting tid of docs#PartENat is definitely a good thing!
Kevin Buzzard (Sep 18 2024 at 09:16):
Do we need to split the PR into two? A lot of the diff is just renaming lemma names. I've just ploughed through all of it because like Michael I have always found it hard to work with PartENat.
Riccardo Brasca (Sep 18 2024 at 09:18):
Maybe not, I was just suggesting a way of making the diff smaller.
Daniel Weber (Sep 18 2024 at 09:30):
Riccardo Brasca said:
I think that the way to go is the following: do we agree we want both version? I personally do. If this is the case you can split the PR in at least two: first of all just rename
multiplicity
toemultiplicity
, without adding anything else, and in a following PR add the newmultiplicity
.
You mean while keeping PartENat?
Riccardo Brasca (Sep 18 2024 at 09:32):
I forgot there is also this change. Making several PRs makes the review process easier, but it means more work for you, so a trade-off of probably the way to go. But anyway I think we should decide this (having both versions) is the solution we want.
Daniel Weber (Sep 18 2024 at 09:46):
Another option is to use multiplicity and natMultiplicity instead of emultiplicity and mutliplicity, and then less renames are needed
Daniel Weber (Sep 18 2024 at 09:48):
Another thing of note in the PR is moving many results outside of the multiplicity
namespace, as they all had to be renamed anyway to have either multiplicity
or emultiplicity
to disambiguate, so the namespace was redundant
Yaël Dillies (Sep 18 2024 at 10:19):
Daniel Weber said:
Another option is to use multiplicity and natMultiplicity instead of emultiplicity and mutliplicity, and then less renames are needed
Yes but I think this goes against the principle of making the main things have shorter names
Yaël Dillies (Sep 18 2024 at 10:19):
Daniel Weber said:
Another thing of note in the PR is moving many results outside of the
multiplicity
namespace, as they all had to be renamed anyway to have eithermultiplicity
ornatMultiplicity
to disambiguate, so the namespace was redundant
I always hated that namespace. It's not a type! Happy to see it go
Daniel Weber (Sep 18 2024 at 10:22):
There are still some remains, mostly multiplicity.Finite
and a few other lemmas
Daniel Weber (Nov 30 2024 at 07:59):
@Yaël Dillies said:
Daniel Weber said:
Another thing of note in the PR is moving many results outside of the
multiplicity
namespace, as they all had to be renamed anyway to have eithermultiplicity
ornatMultiplicity
to disambiguate, so the namespace was redundantI always hated that namespace. It's not a type! Happy to see it go
#19623 eliminates that namespace completely (up to deprecated aliases), renaming multiplicity.Finite
to FiniteMultiplicity
Johan Commelin (Nov 30 2024 at 17:34):
I think this is a good move. But I do find FiniteMultiplicity
a rather long name. We also have things like fincard
, so how about FinMultiplicity
? Or possibly NatMultiplicity
?
Last updated: May 02 2025 at 03:31 UTC