Zulip Chat Archive
Stream: general
Topic: Argmax for Finset
Konstantin Weitz (May 02 2025 at 20:54):
I have a Finset of type A, and would like to get the largest element with respect to a function f : A -> Real. What's the best way to do this? I know about Finset.max and Finset.max', but didn't see an Finset.argmax or something like that.
Aaron Liu (May 02 2025 at 20:54):
docs#Finset.image it and then max maybe
Yaël Dillies (May 02 2025 at 20:55):
docs#Finset.sup' is the idiomatic spellingSorry, I see you want the index with maximal value, not the maximal value itself
Aaron Liu (May 02 2025 at 20:57):
or maybe docs#List.argmax with some docs#Finset.toList
Konstantin Weitz (May 02 2025 at 21:09):
Thanks. I also see that Finset.max takes a LinearOrder. Is there an easy way to instantiate a linear order with a mapping from the set to Real (like my function f)?
Aaron Liu (May 02 2025 at 21:09):
If it's injective you can pull back the linear order from Real
Aaron Liu (May 02 2025 at 21:10):
Yaël Dillies (May 02 2025 at 21:13):
You really shouldn't be pulling any linear order back! What Konstantin wants is simply the existence of an argument with maximal value + choice to actually get one
Bhavik Mehta (May 02 2025 at 21:21):
docs#Finset.exists_max_image is the usual way to get this existence
Last updated: Dec 20 2025 at 21:32 UTC