File: Mathlib/Data/Finset/Sort.lean

full_name: Finset.sort
code: /-- `sort s` constructs a sorted list from the unordered set `s`.
  (Uses merge sort algorithm.) -/
def sort (s : Finset α) : List α 
goal: List α

full_name: Finset.sort_sorted
code: @[simp]
theorem sort_sorted (s : Finset α) : List.Sorted r (sort r s) 
goal: List.Sorted r (Finset.sort r s)

full_name: Finset.sort_eq
code: @[simp]
theorem sort_eq (s : Finset α) : ↑(sort r s) = s.1 
goal: ↑(Finset.sort r s) = s.val

full_name: Finset.sort_nodup
code: @[simp]
theorem sort_nodup (s : Finset α) : (sort r s).Nodup 
goal: (Finset.sort r s).Nodup

full_name: Finset.sort_toFinset
code: @[simp]
theorem sort_toFinset [DecidableEq α] (s : Finset α) : (sort r s).toFinset = s 
goal: (Finset.sort r s).toFinset = s

full_name: Finset.mem_sort
code: @[simp]
theorem mem_sort {s : Finset α} {a : α} : a ∈ sort r s ↔ a ∈ s 
goal: a ∈ Finset.sort r s ↔ a ∈ s

full_name: Finset.length_sort
code: @[simp]
theorem length_sort {s : Finset α} : (sort r s).length = s.card 
goal: (Finset.sort r s).length = s.card

full_name: Finset.sort_empty
code: @[simp]
theorem sort_empty : sort r ∅ = [] 
goal: Finset.sort r ∅ = []

full_name: Finset.sort_singleton
code: @[simp]
theorem sort_singleton (a : α) : sort r {a} = [a] 
goal: Finset.sort r {a} = [a]

full_name: Finset.sort_perm_toList
code: theorem sort_perm_toList (s : Finset α) : sort r s ~ s.toList 
goal: (Finset.sort r s).Perm s.toList

full_name: Finset.sort_sorted_lt
code: theorem sort_sorted_lt (s : Finset α) : List.Sorted (· < ·) (sort (· ≤ ·) s) 
goal: List.Sorted (fun x x_1 => x < x_1) (Finset.sort (fun x x_1 => x ≤ x_1) s)

full_name: Finset.sort_sorted_gt
code: theorem sort_sorted_gt (s : Finset α) : List.Sorted (· > ·) (sort (· ≥ ·) s) 
goal: List.Sorted (fun x x_1 => x > x_1) (Finset.sort (fun x x_1 => x ≥ x_1) s)

full_name: Finset.sorted_zero_eq_min'_aux
code: theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).get ⟨0, h⟩ = s.min' H 
goal: (Finset.sort (fun x x_1 => x ≤ x_1) s).get ⟨0, h⟩ = s.min' H

full_name: Finset.sorted_zero_eq_min'
code: theorem sorted_zero_eq_min' {s : Finset α} {h : 0 < (s.sort (· ≤ ·)).length} :
    (s.sort (· ≤ ·)).get ⟨0, h⟩ = s.min' (card_pos.1 <| by rwa [length_sort] at h) 
goal: (Finset.sort (fun x x_1 => x ≤ x_1) s).get ⟨0, h⟩ = s.min' ⋯

full_name: Finset.min'_eq_sorted_zero
code: theorem min'_eq_sorted_zero {s : Finset α} {h : s.Nonempty} :
    s.min' h = (s.sort (· ≤ ·)).get ⟨0, (by rw [length_sort]; exact card_pos.2 h)⟩ 
goal: s.min' h = (Finset.sort (fun x x_1 => x ≤ x_1) s).get ⟨0, ⋯⟩

full_name: Finset.sorted_last_eq_max'_aux
code: theorem sorted_last_eq_max'_aux (s : Finset α)
    (h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) :
    (s.sort (· ≤ ·)).get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ = s.max' H 
goal: (Finset.sort (fun x x_1 => x ≤ x_1) s).get ⟨(Finset.sort (fun x x_1 => x ≤ x_1) s).length - 1, h⟩ = s.max' H

full_name: Finset.sorted_last_eq_max'
code: theorem sorted_last_eq_max' {s : Finset α}
    {h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length} :
    (s.sort (· ≤ ·)).get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ =
      s.max' (by rw [length_sort] at h; exact card_pos.1 (lt_of_le_of_lt bot_le h)) 
goal: (Finset.sort (fun x x_1 => x ≤ x_1) s).get ⟨(Finset.sort (fun x x_1 => x ≤ x_1) s).length - 1, h⟩ = s.max' ⋯

full_name: Finset.max'_eq_sorted_last
code: theorem max'_eq_sorted_last {s : Finset α} {h : s.Nonempty} :
    s.max' h =
      (s.sort (· ≤ ·)).get ⟨(s.sort (· ≤ ·)).length - 1,
        by simpa using Nat.sub_lt (card_pos.mpr h) Nat.zero_lt_one⟩ 
goal: s.max' h = (Finset.sort (fun x x_1 => x ≤ x_1) s).get ⟨(Finset.sort (fun x x_1 => x ≤ x_1) s).length - 1, ⋯⟩

full_name: Finset.orderIsoOfFin
code: /-- 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 orderIsoOfFin (s : Finset α) {k : ℕ} (h : s.card = k) : Fin k ≃o s 
goal: Fin k ≃o { x // x ∈ s }

full_name: Finset.orderEmbOfFin
code: /-- 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. -/
def orderEmbOfFin (s : Finset α) {k : ℕ} (h : s.card = k) : Fin k ↪o α 
goal: Fin k ↪o α

full_name: Finset.coe_orderIsoOfFin_apply
code: @[simp]
theorem coe_orderIsoOfFin_apply (s : Finset α) {k : ℕ} (h : s.card = k) (i : Fin k) :
    ↑(orderIsoOfFin s h i) = orderEmbOfFin s h i 
goal: ↑((s.orderIsoOfFin h) i) = (s.orderEmbOfFin h) i

full_name: Finset.orderIsoOfFin_symm_apply
code: theorem orderIsoOfFin_symm_apply (s : Finset α) {k : ℕ} (h : s.card = k) (x : s) :
    ↑((s.orderIsoOfFin h).symm x) = (s.sort (· ≤ ·)).indexOf ↑x 
goal: ↑((s.orderIsoOfFin h).symm x) = List.indexOf (↑x) (Finset.sort (fun x x_1 => x ≤ x_1) s)

full_name: Finset.orderEmbOfFin_apply
code: theorem orderEmbOfFin_apply (s : Finset α) {k : ℕ} (h : s.card = k) (i : Fin k) :
    s.orderEmbOfFin h i =
      (s.sort (· ≤ ·)).get ⟨i, by rw [length_sort, h]; exact i.2⟩ 
goal: (s.orderEmbOfFin h) i = (Finset.sort (fun x x_1 => x ≤ x_1) s).get ⟨↑i, ⋯⟩

full_name: Finset.orderEmbOfFin_mem
code: @[simp]
theorem orderEmbOfFin_mem (s : Finset α) {k : ℕ} (h : s.card = k) (i : Fin k) :
    s.orderEmbOfFin h i ∈ s 
goal: (s.orderEmbOfFin h) i ∈ s

full_name: Finset.range_orderEmbOfFin
code: @[simp]
theorem range_orderEmbOfFin (s : Finset α) {k : ℕ} (h : s.card = k) :
    Set.range (s.orderEmbOfFin h) = s 
goal: Set.range ⇑(s.orderEmbOfFin h) = ↑s

full_name: Finset.orderEmbOfFin_zero
code: /-- The bijection `orderEmbOfFin s h` sends `0` to the minimum of `s`. -/
theorem orderEmbOfFin_zero {s : Finset α} {k : ℕ} (h : s.card = k) (hz : 0 < k) :
    orderEmbOfFin s h ⟨0, hz⟩ = s.min' (card_pos.mp (h.symm ▸ hz)) 
goal: (s.orderEmbOfFin h) ⟨0, hz⟩ = s.min' ⋯

full_name: Finset.orderEmbOfFin_last
code: /-- The bijection `orderEmbOfFin s h` sends `k-1` to the maximum of `s`. -/
theorem orderEmbOfFin_last {s : Finset α} {k : ℕ} (h : s.card = k) (hz : 0 < k) :
    orderEmbOfFin s h ⟨k - 1, Nat.sub_lt hz (Nat.succ_pos 0)⟩ =
      s.max' (card_pos.mp (h.symm ▸ hz)) 
goal: (s.orderEmbOfFin h) ⟨k - 1, ⋯⟩ = s.max' ⋯

full_name: Finset.orderEmbOfFin_singleton
code: /-- `orderEmbOfFin {a} h` sends any argument to `a`. -/
@[simp]
theorem orderEmbOfFin_singleton (a : α) (i : Fin 1) :
    orderEmbOfFin {a} (card_singleton a) i = a 
goal: ({a}.orderEmbOfFin ⋯) i = a

full_name: Finset.orderEmbOfFin_unique
code: /-- Any increasing map `f` from `Fin k` to a finset of cardinality `k` has to coincide with
the increasing bijection `orderEmbOfFin s h`. -/
theorem orderEmbOfFin_unique {s : Finset α} {k : ℕ} (h : s.card = k) {f : Fin k → α}
    (hfs : ∀ x, f x ∈ s) (hmono : StrictMono f) : f = s.orderEmbOfFin h 
goal: f = ⇑(s.orderEmbOfFin h)

full_name: Finset.orderEmbOfFin_unique'
code: /-- An order embedding `f` from `Fin k` to a finset of cardinality `k` has to coincide with
the increasing bijection `orderEmbOfFin s h`. -/
theorem orderEmbOfFin_unique' {s : Finset α} {k : ℕ} (h : s.card = k) {f : Fin k ↪o α}
    (hfs : ∀ x, f x ∈ s) : f = s.orderEmbOfFin h 
goal: f = s.orderEmbOfFin h

full_name: Finset.orderEmbOfFin_eq_orderEmbOfFin_iff
code: /-- 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 : ℕ)`. -/
@[simp]
theorem orderEmbOfFin_eq_orderEmbOfFin_iff {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 : ℕ) 
goal: (s.orderEmbOfFin h) i = (s.orderEmbOfFin h') j ↔ ↑i = ↑j

full_name: Finset.orderEmbOfCardLe
code: /-- 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`. -/
def orderEmbOfCardLe (s : Finset α) {k : ℕ} (h : k ≤ s.card) : Fin k ↪o α 
goal: Fin k ↪o α

full_name: Finset.orderEmbOfCardLe_mem
code: theorem orderEmbOfCardLe_mem (s : Finset α) {k : ℕ} (h : k ≤ s.card) (a) :
    orderEmbOfCardLe s h a ∈ s 
goal: (s.orderEmbOfCardLe h) a ∈ s

full_name: Finset.instRepr
code: unsafe instance [Repr α] : Repr (Finset α) 
goal: Repr (Finset α)

full_name: Fin.sort_univ
code: theorem sort_univ (n : ℕ) : Finset.univ.sort (fun x y : Fin n => x ≤ y) = List.finRange n 
goal: Finset.sort (fun x y => x ≤ y) Finset.univ = List.finRange n