Zulip Chat Archive

Stream: Is there code for X?

Topic: Find the nth element of an ordered finset


Jujian Zhang (Apr 11 2022 at 13:22):

Given a well order type ι\iota and a finite set σ\sigma, is there an easy way to find the nn-th largest element? I.e., what be the easiest way of doing the following:

import data.finset

section examples

variables {ι : Type*} [linear_order ι] [is_well_order ι (() : ι  ι  Prop)]

example (σ : finset ι) :  f : fin σ.card  σ, strict_mono f := sorry

end examples

Thanks for any help

Yaël Dillies (Apr 11 2022 at 13:22):

Why would you need a well order for this?

Yaël Dillies (Apr 11 2022 at 13:23):

You can use docs#finset.sort and docs#list.nth

Eric Wieser (Apr 11 2022 at 13:23):

docs#finset.sort?

Eric Wieser (Apr 11 2022 at 13:24):

Arguably we should implement a partitioning algorithm which would be faster, but that probably doesn't matter until lean 4

Jujian Zhang (Apr 11 2022 at 13:25):

Yaël Dillies said:

Why would you need a well order for this?

I don't need well order for this, it just happens that I need to work with well ordered type


Last updated: Dec 20 2023 at 11:08 UTC