Zulip Chat Archive

Stream: mathlib4

Topic: Finset.max


Violeta Hernández (Aug 31 2025 at 10:04):

Just ran into some annoyances with missing API with docs#Finset.max, only to realize that this is actually just a thin wrapper around docs#Finset.sup, which does have the API I want.

Violeta Hernández (Aug 31 2025 at 10:05):

I could go ahead and add said API, but I think it's worth asking, why have both definitions?

Violeta Hernández (Aug 31 2025 at 10:07):

I get the logic behind having both max and sup, it being that Lean also caters to programmers. But does this logic go all the way up to Finset?

Violeta Hernández (Aug 31 2025 at 10:08):

(Also, why does Finset.sup take an extra function argument, while Finset.max doesn't?)

Yakov Pechersky (Aug 31 2025 at 13:24):

Because sup is like sum.

Yakov Pechersky (Aug 31 2025 at 13:25):

And max withBots for the user. There are also sup' and max'

Yakov Pechersky (Aug 31 2025 at 13:26):

Max is specialized for linear orders. And there is docs#Finset.max_eq_sup_coe

Yakov Pechersky (Aug 31 2025 at 13:27):

I think both are worth having. What api would you like to add?

Violeta Hernández (Sep 01 2025 at 02:53):

Yakov Pechersky said:

And max withBots for the user. There are also sup' and max'

I don't really understand the asymmetry here. Why can't sup do the same? Why can't max take in an extra function argument? What is the benefit of specializing to linear orders?

Violeta Hernández (Sep 01 2025 at 02:54):

Yakov Pechersky said:

I think both are worth having. What api would you like to add?

I noticed we don't have a max analog of docs#Finset.sup'_eq_sup

Jakub Nowak (Sep 01 2025 at 03:45):

Violeta Hernández said:

What is the benefit of specializing to linear orders?

E.g. docs#Finset.mem_of_max is not true for sup.

Jakub Nowak (Sep 01 2025 at 03:53):

Although, I've noticed that there's instance of docs#Max docs#SemilatticeSup.toMax, which is defined in terms of SemilatticeSup.sup. The documentation of docs#Max says "Returns the greater of its two arguments.", which is not true for docs#SemilatticeSup.toMax (because, it can return neither of its two arguments). There seems to be inconsistency with max vs sup terminology in mathlib.

Violeta Hernández (Sep 01 2025 at 23:44):

MrQubo said:

Violeta Hernández said:

What is the benefit of specializing to linear orders?

E.g. docs#Finset.mem_of_max is not true for sup.

What do you mean? It is true, if you take a LinearOrder assumption.

Jakub Nowak (Sep 02 2025 at 01:06):

Ah, you're right.
Isn't putting more assumption than necessary at the definition an anti-pattern in lean? Even if there is a reason to have both max and sup, there is no need for LinearOrder assumption at the definition of max. Though, sup also doesn't need SemilatticeSup at the definition. Just Max. Although, as I've stated previously, SemilatticeSup shouldn't implement Max in the first place.

Aaron Liu (Sep 02 2025 at 01:36):

MrQubo said:

Ah, you're right.
Isn't putting more assumption than necessary at the definition an anti-pattern in lean? Even if there is a reason to have both max and sup, there is no need for LinearOrder assumption at the definition of max. Though, sup also doesn't need SemilatticeSup at the definition. Just Max. Although, as I've stated previously, SemilatticeSup shouldn't implement Max in the first place.

it works with any commutative associative operation

Jakub Nowak (Sep 02 2025 at 01:40):

Well, yes, it's just sum. But you might want to have multiple different operations on your type, like addition, multiplication etc, so we have different classes for those. We need to refer to one of these classes, Max/Sup in this case.

Aaron Liu (Sep 02 2025 at 01:43):

so do we just put [m : Max α] [Std.Commutative m.max] [Std.Associative m.max]

Jakub Nowak (Sep 02 2025 at 01:44):

You don't need Commutative and Associative in the definition I think? Only Max and OrderBot.

Aaron Liu (Sep 02 2025 at 01:47):

Max means an arbitrary binary operation which is called "max"

Jakub Nowak (Sep 02 2025 at 01:48):

Yes.

Aaron Liu (Sep 02 2025 at 01:48):

and I think commutativity and associativity are necessary

Jakub Nowak (Sep 02 2025 at 02:47):

Anyway, it doesn't matter, because I doubt there are any interesting properties without assuming relation between max and partial order.

Back to main topic, I think there are use cases to have max. It's I think similar to like we have e.g. Monoid and Semigroup. Like, Monoid is just Semigroup with additional properties, but we still have it, duplicating some of the API of Semigroup with it. We should probably just mirror the api from sup to max, all the proofs should be trivial as LinearOrder implements SemilatticeSup.

Aaron Liu (Sep 02 2025 at 10:18):

I think we already do that?

Jakub Nowak (Sep 02 2025 at 18:03):

Probably yes, just not the whole api apparently.


Last updated: Dec 20 2025 at 21:32 UTC