data.finset.sort

Construct a sorted list from a finset. #

sort #

def finset.sort {α : Type u_1} (r : α → α → Prop) [ r] [ r] [ r] (s : finset α) :
list α

sort s constructs a sorted list from the unordered set s. (Uses merge sort algorithm.)

Equations
@[simp]
theorem finset.sort_sorted {α : Type u_1} (r : α → α → Prop) [ r] [ r] [ r] (s : finset α) :
s)
@[simp]
theorem finset.sort_eq {α : Type u_1} (r : α → α → Prop) [ r] [ r] [ r] (s : finset α) :
s) = s.val
@[simp]
theorem finset.sort_nodup {α : Type u_1} (r : α → α → Prop) [ r] [ r] [ r] (s : finset α) :
s).nodup
@[simp]
theorem finset.sort_to_finset {α : Type u_1} (r : α → α → Prop) [ r] [ r] [ r] [decidable_eq α] (s : finset α) :
s).to_finset = s
@[simp]
theorem finset.mem_sort {α : Type u_1} (r : α → α → Prop) [ r] [ r] [ r] {s : finset α} {a : α} :
a s a s
@[simp]
theorem finset.length_sort {α : Type u_1} (r : α → α → Prop) [ r] [ r] [ r] {s : finset α} :
s).length = s.card
theorem finset.sort_perm_to_list {α : Type u_1} (r : α → α → Prop) [ r] [ r] [ r] (s : finset α) :
s ~ s.to_list
theorem finset.sort_sorted_lt {α : Type u_1} [linear_order α] (s : finset α) :
theorem finset.sorted_zero_eq_min'_aux {α : Type u_1} [linear_order α] (s : finset α) (h : 0 < ) (H : s.nonempty) :
0 h = s.min' H
theorem finset.sorted_zero_eq_min' {α : Type u_1} [linear_order α] {s : finset α} {h : 0 < } :
0 h = s.min' _
theorem finset.min'_eq_sorted_zero {α : Type u_1} [linear_order α] {s : finset α} {h : s.nonempty} :
s.min' h = 0 _
theorem finset.sorted_last_eq_max'_aux {α : Type u_1} [linear_order α] (s : finset α) (h : - 1 < ) (H : s.nonempty) :
s).length - 1) h = s.max' H
theorem finset.sorted_last_eq_max' {α : Type u_1} [linear_order α] {s : finset α} {h : - 1 < } :
s).length - 1) h = s.max' _
theorem finset.max'_eq_sorted_last {α : Type u_1} [linear_order α] {s : finset α} {h : s.nonempty} :
s.max' h = s).length - 1) _
def finset.order_iso_of_fin {α : Type u_1} [linear_order α] (s : finset α) {k : } (h : s.card = k) :

Given a finset s of cardinality k in a linear order α, the map order_iso_of_fin s h is the increasing bijection between fin k and s as an order_iso. Here, h is a proof that the cardinality of s is k. We use this instead of an iso fin s.card ≃o s to avoid casting issues in further uses of this function.

Equations
def finset.order_emb_of_fin {α : Type u_1} [linear_order α] (s : finset α) {k : } (h : s.card = k) :
fin k ↪o α

Given a finset s of cardinality k in a linear order α, the map order_emb_of_fin s h is the increasing bijection between fin k and s as an order embedding into α. Here, h is a proof that the cardinality of s is k. We use this instead of an embedding fin s.card ↪o α to avoid casting issues in further uses of this function.

Equations
@[simp]
theorem finset.coe_order_iso_of_fin_apply {α : Type u_1} [linear_order α] (s : finset α) {k : } (h : s.card = k) (i : fin k) :
theorem finset.order_iso_of_fin_symm_apply {α : Type u_1} [linear_order α] (s : finset α) {k : } (h : s.card = k) (x : s) :
theorem finset.order_emb_of_fin_apply {α : Type u_1} [linear_order α] (s : finset α) {k : } (h : s.card = k) (i : fin k) :
@[simp]
theorem finset.order_emb_of_fin_mem {α : Type u_1} [linear_order α] (s : finset α) {k : } (h : s.card = k) (i : fin k) :
@[simp]
theorem finset.range_order_emb_of_fin {α : Type u_1} [linear_order α] (s : finset α) {k : } (h : s.card = k) :
= s
theorem finset.order_emb_of_fin_zero {α : Type u_1} [linear_order α] {s : finset α} {k : } (h : s.card = k) (hz : 0 < k) :
(s.order_emb_of_fin h) 0, hz⟩ = s.min' _

The bijection order_emb_of_fin s h sends 0 to the minimum of s.

theorem finset.order_emb_of_fin_last {α : Type u_1} [linear_order α] {s : finset α} {k : } (h : s.card = k) (hz : 0 < k) :
(s.order_emb_of_fin h) k - 1, _⟩ = s.max' _

The bijection order_emb_of_fin s h sends k-1 to the maximum of s.

@[simp]
theorem finset.order_emb_of_fin_singleton {α : Type u_1} [linear_order α] (a : α) (i : fin 1) :

order_emb_of_fin {a} h sends any argument to a.

theorem finset.order_emb_of_fin_unique {α : Type u_1} [linear_order α] {s : finset α} {k : } (h : s.card = k) {f : fin k → α} (hfs : ∀ (x : fin k), f x s) (hmono : strict_mono f) :

Any increasing map f from fin k to a finset of cardinality k has to coincide with the increasing bijection order_emb_of_fin s h.

theorem finset.order_emb_of_fin_unique' {α : Type u_1} [linear_order α] {s : finset α} {k : } (h : s.card = k) {f : fin k ↪o α} (hfs : ∀ (x : fin k), f x s) :
f =

An order embedding f from fin k to a finset of cardinality k has to coincide with the increasing bijection order_emb_of_fin s h.

@[simp]
theorem finset.order_emb_of_fin_eq_order_emb_of_fin_iff {α : Type u_1} [linear_order α] {k l : } {s : finset α} {i : fin k} {j : fin l} {h : s.card = k} {h' : s.card = l} :

Two parametrizations order_emb_of_fin of the same set take the same value on i and j if and only if i = j. Since they can be defined on a priori not defeq types fin k and fin l (although necessarily k = l), the conclusion is rather written (i : ℕ) = (j : ℕ).

theorem finset.card_le_of_interleaved {α : Type u_1} [linear_order α] {s t : finset α} (h : ∀ (x : α), x s∀ (y : α), y sx < y(∃ (z : α) (H : z t), x < z z < y)) :
s.card t.card + 1
@[protected, instance]
def finset.has_repr {α : Type u_1} [has_repr α] :
Equations