The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V03. Sets, finite structures and big operators

Mathlib.Data.Finset.Sort

57 declarations. Mathlib docs · Source

Construct a sorted list from a finset.

sort

theorem Finset.sort.congr_simp E1 #

∀ {α : Type u_1} (s s_1 : Finset α),
  s = s_1 →
    ∀ (r r_1 : α → α → Prop) (e_r : r = r_1) {inst : DecidableRel r} [inst_1 : DecidableRel r_1] [inst_2 : IsTrans α r]
      [inst_3 : Std.Antisymm r] [inst_4 : Std.Total r], s.sort r = s_1.sort r_1

theorem Finset.orderIsoOfFin.congr_simp E1 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α) {k : ℕ} (h : s.card = k), s.orderIsoOfFin h = s.orderIsoOfFin h

theorem Finset.orderEmbOfFin.congr_simp E1 #

∀ {α : Type u_1} [inst : LinearOrder α] (s s_1 : Finset α) (e_s : s = s_1) {k : ℕ} (h : s.card = k),
  s.orderEmbOfFin h = s_1.orderEmbOfFin ⋯

theorem Fin.castLEOrderEmb.congr_simp E1 #

∀ {m n : ℕ} (h : n ≤ m), Fin.castLEOrderEmb h = Fin.castLEOrderEmb h

def Finset.sort E1 #

{α : Type u_1} →
  Finset α →
    (r : autoParam (α → α → Prop) Finset.sort._auto_1) →
      [DecidableRel r] → [IsTrans α r] → [Std.Antisymm r] → [Std.Total r] → List α

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

theorem Finset.sort_val E0 #

∀ {α : Type u_1} (s : Finset α) (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r]
  [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r], s.val.sort r = s.sort r

theorem Finset.pairwise_sort E0 #

∀ {α : Type u_1} (s : Finset α) (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r]
  [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r], List.Pairwise r (s.sort r)

theorem Finset.sort_eq E0 #

∀ {α : Type u_1} (s : Finset α) (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r]
  [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r], ↑(s.sort r) = s.val

theorem Finset.sort_nodup E0 #

∀ {α : Type u_1} (s : Finset α) (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r]
  [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r], (s.sort r).Nodup

theorem Finset.sort_toFinset E0 #

∀ {α : Type u_1} (s : Finset α) (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r]
  [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r] [inst_4 : DecidableEq α], (s.sort r).toFinset = s

theorem Finset.sort_empty E0 #

∀ {α : Type u_1} (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r] [inst_2 : Std.Antisymm r]
  [inst_3 : Std.Total r], ∅.sort r = []

theorem Finset.sort_singleton E0 #

∀ {α : Type u_1} (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r] [inst_2 : Std.Antisymm r]
  [inst_3 : Std.Total r] (a : α), {a}.sort r = [a]

theorem Finset.map_sort E0 #

∀ {α : Type u_1} {β : Type u_2} (f : α ↪ β) (s : Finset α) (r : α → α → Prop) [inst : DecidableRel r]
  [inst_1 : IsTrans α r] [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r] (r' : β → β → Prop) [inst_4 : DecidableRel r']
  [inst_5 : IsTrans β r'] [inst_6 : Std.Antisymm r'] [inst_7 : Std.Total r'],
  (∀ a ∈ s, ∀ b ∈ s, r a b ↔ r' (f a) (f b)) → List.map (⇑f) (s.sort r) = (Finset.map f s).sort r'

theorem StrictMonoOn.map_finsetSort E0 #

∀ {α : Type u_1} {β : Type u_2} (f : α ↪ β) (s : Finset α) [inst : LinearOrder α] [inst_1 : LinearOrder β],
  StrictMonoOn ⇑f ↑s → List.map (⇑f) (s.sort fun a b ↦ a ≤ b) = (Finset.map f s).sort fun a b ↦ a ≤ b

theorem Finset.sort_range E0 #

∀ (n : ℕ), ((Finset.range n).sort fun a b ↦ a ≤ b) = List.range n

theorem Finset.sort_perm_toList E1 #

∀ {α : Type u_1} (s : Finset α) (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r]
  [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r], (s.sort r).Perm s.toList

theorem List.toFinset_sort E1 #

∀ {α : Type u_1} (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r] [inst_2 : Std.Antisymm r]
  [inst_3 : Std.Total r] [inst_4 : DecidableEq α] {l : List α}, l.Nodup → (l.toFinset.sort r = l ↔ List.Pairwise r l)

theorem List.SortedLT.sort_toFinset E1 #

∀ {α : Type u_1} [inst : LinearOrder α] {l : List α}, l.SortedLT → (l.toFinset.sort fun x1 x2 ↦ x1 ≤ x2) = l

theorem List.SortedGT.sort_toFinset E1 #

∀ {α : Type u_1} [inst : LinearOrder α] {l : List α}, l.SortedGT → (l.toFinset.sort fun x1 x2 ↦ x1 ≥ x2) = l

theorem Finset.sort_mk E0 #

∀ {α : Type u_1} {m : Multiset α} (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r]
  [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r] (h : m.Nodup), { val := m, nodup := h }.sort r = m.sort r

theorem Finset.mem_sort E0 #

∀ {α : Type u_1} {s : Finset α} (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r]
  [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r] {a : α}, a ∈ s.sort r ↔ a ∈ s

theorem Finset.length_sort E0 #

∀ {α : Type u_1} {s : Finset α} (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r]
  [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r], (s.sort r).length = s.card

theorem Finset.sort_cons E1 #

∀ {α : Type u_1} {s : Finset α} (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r]
  [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r] {a : α},
  (∀ b ∈ s, r a b) → ∀ (h₂ : a ∉ s), (Finset.cons a s h₂).sort r = a :: s.sort r

theorem Finset.sort_insert E1 #

∀ {α : Type u_1} {s : Finset α} (r : α → α → Prop) [inst : DecidableRel r] [inst_1 : IsTrans α r]
  [inst_2 : Std.Antisymm r] [inst_3 : Std.Total r] [inst_4 : DecidableEq α] {a : α},
  (∀ b ∈ s, r a b) → a ∉ s → (insert a s).sort r = a :: s.sort r

theorem Finset.sortedLT_sort E1 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α), (s.sort fun a b ↦ a ≤ b).SortedLT

theorem Finset.sortedGT_sort E1 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α), (s.sort fun x1 x2 ↦ x1 ≥ x2).SortedGT

theorem Finset.sorted_zero_eq_min'_aux E0 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α) (h : 0 < (s.sort fun a b ↦ a ≤ b).length) (H : s.Nonempty),
  (s.sort fun a b ↦ a ≤ b).get ⟨0, h⟩ = s.min' H

theorem Finset.sorted_zero_eq_min' E1 #

∀ {α : Type u_1} [inst : LinearOrder α] {s : Finset α} {h : 0 < (s.sort fun a b ↦ a ≤ b).length},
  (s.sort fun a b ↦ a ≤ b)[0] = s.min' ⋯

theorem Finset.min'_eq_sorted_zero E1 #

∀ {α : Type u_1} [inst : LinearOrder α] {s : Finset α} {h : s.Nonempty}, s.min' h = (s.sort fun a b ↦ a ≤ b)[0]

theorem Finset.sorted_last_eq_max'_aux E0 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α)
  (h : (s.sort fun a b ↦ a ≤ b).length - 1 < (s.sort fun a b ↦ a ≤ b).length) (H : s.Nonempty),
  (s.sort fun a b ↦ a ≤ b)[(s.sort fun a b ↦ a ≤ b).length - 1] = s.max' H

theorem Finset.sorted_last_eq_max' E1 #

∀ {α : Type u_1} [inst : LinearOrder α] {s : Finset α}
  {h : (s.sort fun a b ↦ a ≤ b).length - 1 < (s.sort fun a b ↦ a ≤ b).length},
  (s.sort fun a b ↦ a ≤ b)[(s.sort fun a b ↦ a ≤ b).length - 1] = s.max' ⋯

theorem Finset.max'_eq_sorted_last E1 #

∀ {α : Type u_1} [inst : LinearOrder α] {s : Finset α} {h : s.Nonempty},
  s.max' h = (s.sort fun a b ↦ a ≤ b)[(s.sort fun a b ↦ a ≤ b).length - 1]

def Finset.orderIsoOfFin E1 #

{α : Type u_1} → [inst : LinearOrder α] → (s : Finset α) → {k : ℕ} → s.card = k → Fin k ≃o ↥s

Given a finset s of cardinality k in a linear order α, the map orderIsoOfFin s h is the increasing bijection between Fin k and s as an OrderIso. 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.

def Finset.orderEmbOfFin E1 #

{α : Type u_1} → [inst : LinearOrder α] → (s : Finset α) → {k : ℕ} → s.card = k → Fin k ↪o α

Given a finset s of cardinality k in a linear order α, the map orderEmbOfFin 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.

theorem Finset.coe_orderIsoOfFin_apply E0 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α) {k : ℕ} (h : s.card = k) (i : Fin k),
  ↑((s.orderIsoOfFin h) i) = (s.orderEmbOfFin h) i

theorem Finset.orderIsoOfFin_symm_apply E0 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α) {k : ℕ} (h : s.card = k) (x : ↥s),
  ↑((s.orderIsoOfFin h).symm x) = List.idxOf (↑x) (s.sort fun a b ↦ a ≤ b)

theorem Finset.orderEmbOfFin_apply E0 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α) {k : ℕ} (h : s.card = k) (i : Fin k),
  (s.orderEmbOfFin h) i = (s.sort fun a b ↦ a ≤ b)[i]

theorem Finset.orderEmbOfFin_mem E0 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α) {k : ℕ} (h : s.card = k) (i : Fin k), (s.orderEmbOfFin h) i ∈ s

theorem Finset.range_orderEmbOfFin E0 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α) {k : ℕ} (h : s.card = k), Set.range ⇑(s.orderEmbOfFin h) = ↑s

theorem Finset.image_orderEmbOfFin_univ E0 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α) {k : ℕ} (h : s.card = k),
  Finset.image (⇑(s.orderEmbOfFin h)) Finset.univ = s

theorem Finset.map_orderEmbOfFin_univ E0 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α) {k : ℕ} (h : s.card = k),
  Finset.map (s.orderEmbOfFin h).toEmbedding Finset.univ = s

theorem Finset.listMap_orderEmbOfFin_finRange E0 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α) {k : ℕ} (h : s.card = k),
  List.map (⇑(s.orderEmbOfFin h)) (List.finRange k) = s.sort fun a b ↦ a ≤ b

theorem Finset.orderEmbOfFin_zero E1 #

∀ {α : Type u_1} [inst : LinearOrder α] {s : Finset α} {k : ℕ} (h : s.card = k) (hz : 0 < k),
  (s.orderEmbOfFin h) ⟨0, hz⟩ = s.min' ⋯

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

theorem Finset.orderEmbOfFin_last E1 #

∀ {α : Type u_1} [inst : LinearOrder α] {s : Finset α} {k : ℕ} (h : s.card = k) (hz : 0 < k),
  (s.orderEmbOfFin h) ⟨k - 1, ⋯⟩ = s.max' ⋯

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

theorem Finset.orderEmbOfFin_singleton E0 #

∀ {α : Type u_1} [inst : LinearOrder α] (a : α) (i : Fin 1), ({a}.orderEmbOfFin ⋯) i = a

orderEmbOfFin {a} h sends any argument to a.

theorem Finset.orderEmbOfFin_unique E1 #

∀ {α : Type u_1} [inst : LinearOrder α] {s : Finset α} {k : ℕ} (h : s.card = k) {f : Fin k → α},
  (∀ (x : Fin k), f x ∈ s) → StrictMono f → f = ⇑(s.orderEmbOfFin h)

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

theorem Finset.orderEmbOfFin_unique' E1 #

∀ {α : Type u_1} [inst : LinearOrder α] {s : Finset α} {k : ℕ} (h : s.card = k) {f : Fin k ↪o α},
  (∀ (x : Fin k), f x ∈ s) → f = s.orderEmbOfFin h

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

theorem Finset.orderEmbOfFin_eq_orderEmbOfFin_iff E0 #

∀ {α : Type u_1} [inst : LinearOrder α] {k l : ℕ} {s : Finset α} {i : Fin k} {j : Fin l} {h : s.card = k}
  {h' : s.card = l}, (s.orderEmbOfFin h) i = (s.orderEmbOfFin h') j ↔ ↑i = ↑j

Two parametrizations orderEmbOfFin 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 : ℕ).

def Finset.orderEmbOfCardLe E1 #

{α : Type u_1} → [inst : LinearOrder α] → (s : Finset α) → {k : ℕ} → k ≤ s.card → Fin k ↪o α

Given a finset s of size at least k in a linear order α, the map orderEmbOfCardLe is an order embedding from Fin k to α whose image is contained in s. Specifically, it maps Fin k to an initial segment of s.

theorem Finset.orderEmbOfCardLe_mem E1 #

∀ {α : Type u_1} [inst : LinearOrder α] (s : Finset α) {k : ℕ} (h : k ≤ s.card) (a : Fin k),
  (s.orderEmbOfCardLe h) a ∈ s

theorem Finset.orderEmbOfFin_compl_singleton E1 #

∀ {n : ℕ} {i : Fin (n + 1)} {k : ℕ} (h : {i}ᶜ.card = k),
  {i}ᶜ.orderEmbOfFin h = RelEmbedding.trans (Fin.castOrderIso ⋯).toOrderEmbedding i.succAboveOrderEmb

theorem Finset.orderEmbOfFin_compl_singleton_eq_succAboveOrderEmb E0 #

∀ {n : ℕ} (i : Fin (n + 1)), {i}ᶜ.orderEmbOfFin ⋯ = i.succAboveOrderEmb

theorem Finset.orderEmbOfFin_compl_singleton_apply E0 #

∀ {n : ℕ} {i : Fin (n + 1)} {k : ℕ} (h : {i}ᶜ.card = k) (j : Fin k),
  ({i}ᶜ.orderEmbOfFin h) j = i.succAbove (Fin.cast ⋯ j)

instance Finset.instRepr E0 #

{α : Type u_1} → [Repr α] → Repr (Finset α)

theorem Fin.sort_univ E1 #

∀ (n : ℕ), (Finset.univ.sort fun x y ↦ x ≤ y) = List.finRange n

def Fintype.orderIsoFinOfCardEq E1 #

(α : Type u_1) → [inst : LinearOrder α] → [inst_1 : Fintype α] → {k : ℕ} → Fintype.card α = k → Fin k ≃o α

Given a Fintype α of cardinality k, the map orderIsoFinOfCardEq s h is the increasing bijection between Fin k and α as an OrderIso. Here, h is a proof that the cardinality of α is k. We use this instead of an iso Fin (Fintype.card α) ≃o α to avoid casting issues in further uses of this function.

theorem nonempty_orderEmbedding_of_finite_infinite E1 #

∀ (α : Type u_1) [inst : LinearOrder α] [hα : Finite α] (β : Type u_2) [inst_1 : LinearOrder β] [hβ : Infinite β],
  Nonempty (α ↪o β)

Any finite linear order order-embeds into any infinite linear order.