Zulip Chat Archive
Stream: Is there code for X?
Topic: Ordered finset as list
Dagur Asgeirsson (Jul 30 2023 at 07:38):
I have a linearly ordered Finset
and want it as a List
, ordered "correctly". Do we have this? I know of Finset.toList
but this doesn't care about the order on J
.
import Mathlib.Data.Finset.Basic
variable (I : Type _) [LinearOrder I] (J : Finset I)
/-- J as a list, in the correct order -/
def OrderedFinset.asList : List I := sorry
Kevin Buzzard (Jul 30 2023 at 07:47):
Can you just now sort it?
Dagur Asgeirsson (Jul 30 2023 at 07:49):
Ok, I guess this works:
import Mathlib.Data.Finset.Basic
import Mathlib.Data.List.Sort
variable (I : Type _) [LinearOrder I] (J : Finset I)
noncomputable
def OrderedFinset.asList : List I := List.insertionSort (·≤·) J.toList
Eric Wieser (Jul 30 2023 at 08:10):
Eric Wieser (Jul 30 2023 at 08:10):
That one is computable too
Dagur Asgeirsson (Jul 30 2023 at 08:35):
Cool, thanks!
Last updated: Dec 20 2023 at 11:08 UTC