Module docstring
{"# Maximum and minimum of finite sets ","### max and min of finite sets "}
{"# Maximum and minimum of finite sets ","### max and min of finite sets "}
Finset.max
definition
(s : Finset α) : WithBot α
Finset.max_eq_sup_coe
theorem
{s : Finset α} : s.max = s.sup (↑)
theorem max_eq_sup_coe {s : Finset α} : s.max = s.sup (↑) :=
rfl
Finset.max_eq_sup_withBot
theorem
(s : Finset α) : s.max = sup s (↑)
theorem max_eq_sup_withBot (s : Finset α) : s.max = sup s (↑) :=
rfl
Finset.max_empty
theorem
: (∅ : Finset α).max = ⊥
Finset.max_insert
theorem
{a : α} {s : Finset α} : (insert a s).max = max (↑a) s.max
@[simp]
theorem max_insert {a : α} {s : Finset α} : (insert a s).max = max ↑a s.max :=
fold_insert_idem
Finset.max_singleton
theorem
{a : α} : Finset.max { a } = (a : WithBot α)
@[simp]
theorem max_singleton {a : α} : Finset.max {a} = (a : WithBot α) := by
rw [← insert_empty_eq]
exact max_insert
Finset.max_of_mem
theorem
{s : Finset α} {a : α} (h : a ∈ s) : ∃ b : α, s.max = b
theorem max_of_mem {s : Finset α} {a : α} (h : a ∈ s) : ∃ b : α, s.max = b := by
obtain ⟨b, h, _⟩ := le_sup (α := WithBot α) h _ rfl
exact ⟨b, h⟩
Finset.max_of_nonempty
theorem
{s : Finset α} (h : s.Nonempty) : ∃ a : α, s.max = a
theorem max_of_nonempty {s : Finset α} (h : s.Nonempty) : ∃ a : α, s.max = a :=
let ⟨_, h⟩ := h
max_of_mem h
Finset.max_eq_bot
theorem
{s : Finset α} : s.max = ⊥ ↔ s = ∅
Finset.mem_of_max
theorem
{s : Finset α} : ∀ {a : α}, s.max = a → a ∈ s
theorem mem_of_max {s : Finset α} : ∀ {a : α}, s.max = a → a ∈ s := by
induction' s using Finset.induction_on with b s _ ih
· intro _ H; cases H
· intro a h
by_cases p : b = a
· induction p
exact mem_insert_self b s
· rcases max_choice (↑b) s.max with q | q <;> rw [max_insert, q] at h
· cases h
cases p rfl
· exact mem_insert_of_mem (ih h)
Finset.le_max
theorem
{a : α} {s : Finset α} (as : a ∈ s) : ↑a ≤ s.max
Finset.not_mem_of_max_lt_coe
theorem
{a : α} {s : Finset α} (h : s.max < a) : a ∉ s
Finset.le_max_of_eq
theorem
{s : Finset α} {a b : α} (h₁ : a ∈ s) (h₂ : s.max = b) : a ≤ b
theorem le_max_of_eq {s : Finset α} {a b : α} (h₁ : a ∈ s) (h₂ : s.max = b) : a ≤ b :=
WithBot.coe_le_coe.mp <| (le_max h₁).trans h₂.le
Finset.not_mem_of_max_lt
theorem
{s : Finset α} {a b : α} (h₁ : b < a) (h₂ : s.max = ↑b) : a ∉ s
theorem not_mem_of_max_lt {s : Finset α} {a b : α} (h₁ : b < a) (h₂ : s.max = ↑b) : a ∉ s :=
Finset.not_mem_of_max_lt_coe <| h₂.trans_lt <| WithBot.coe_lt_coe.mpr h₁
Finset.max_union
theorem
{s t : Finset α} : (s ∪ t).max = s.max ⊔ t.max
Finset.max_mono
theorem
{s t : Finset α} (st : s ⊆ t) : s.max ≤ t.max
Finset.max_le
theorem
{M : WithBot α} {s : Finset α} (st : ∀ a ∈ s, (a : WithBot α) ≤ M) : s.max ≤ M
protected theorem max_le {M : WithBot α} {s : Finset α} (st : ∀ a ∈ s, (a : WithBot α) ≤ M) :
s.max ≤ M :=
Finset.sup_le st
Finset.max_le_iff
theorem
{m : WithBot α} {s : Finset α} : s.max ≤ m ↔ ∀ a ∈ s, a ≤ m
@[simp]
protected lemma max_le_iff {m : WithBot α} {s : Finset α} : s.max ≤ m ↔ ∀ a ∈ s, a ≤ m :=
Finset.sup_le_iff
Finset.max_eq_top
theorem
[OrderTop α] {s : Finset α} : s.max = ⊤ ↔ ⊤ ∈ s
@[simp]
protected lemma max_eq_top [OrderTop α] {s : Finset α} : s.max = ⊤ ↔ ⊤ ∈ s :=
Finset.sup_eq_top_iff.trans <| by simp
Finset.min
definition
(s : Finset α) : WithTop α
Finset.min_eq_inf_withTop
theorem
(s : Finset α) : s.min = inf s (↑)
theorem min_eq_inf_withTop (s : Finset α) : s.min = inf s (↑) :=
rfl
Finset.min_empty
theorem
: (∅ : Finset α).min = ⊤
Finset.min_insert
theorem
{a : α} {s : Finset α} : (insert a s).min = min (↑a) s.min
@[simp]
theorem min_insert {a : α} {s : Finset α} : (insert a s).min = min (↑a) s.min :=
fold_insert_idem
Finset.min_singleton
theorem
{a : α} : Finset.min { a } = (a : WithTop α)
@[simp]
theorem min_singleton {a : α} : Finset.min {a} = (a : WithTop α) := by
rw [← insert_empty_eq]
exact min_insert
Finset.min_of_mem
theorem
{s : Finset α} {a : α} (h : a ∈ s) : ∃ b : α, s.min = b
theorem min_of_mem {s : Finset α} {a : α} (h : a ∈ s) : ∃ b : α, s.min = b := by
obtain ⟨b, h, _⟩ := inf_le (α := WithTop α) h _ rfl
exact ⟨b, h⟩
Finset.min_of_nonempty
theorem
{s : Finset α} (h : s.Nonempty) : ∃ a : α, s.min = a
theorem min_of_nonempty {s : Finset α} (h : s.Nonempty) : ∃ a : α, s.min = a :=
let ⟨_, h⟩ := h
min_of_mem h
Finset.min_eq_top
theorem
{s : Finset α} : s.min = ⊤ ↔ s = ∅
@[simp]
theorem min_eq_top {s : Finset α} : s.min = ⊤ ↔ s = ∅ := by
simp [Finset.min, eq_empty_iff_forall_not_mem]
Finset.mem_of_min
theorem
{s : Finset α} : ∀ {a : α}, s.min = a → a ∈ s
theorem mem_of_min {s : Finset α} : ∀ {a : α}, s.min = a → a ∈ s :=
@mem_of_max αᵒᵈ _ s
Finset.min_le
theorem
{a : α} {s : Finset α} (as : a ∈ s) : s.min ≤ a
Finset.not_mem_of_coe_lt_min
theorem
{a : α} {s : Finset α} (h : ↑a < s.min) : a ∉ s
Finset.min_le_of_eq
theorem
{s : Finset α} {a b : α} (h₁ : b ∈ s) (h₂ : s.min = a) : a ≤ b
theorem min_le_of_eq {s : Finset α} {a b : α} (h₁ : b ∈ s) (h₂ : s.min = a) : a ≤ b :=
WithTop.coe_le_coe.mp <| h₂.ge.trans (min_le h₁)
Finset.not_mem_of_lt_min
theorem
{s : Finset α} {a b : α} (h₁ : a < b) (h₂ : s.min = ↑b) : a ∉ s
theorem not_mem_of_lt_min {s : Finset α} {a b : α} (h₁ : a < b) (h₂ : s.min = ↑b) : a ∉ s :=
Finset.not_mem_of_coe_lt_min <| (WithTop.coe_lt_coe.mpr h₁).trans_eq h₂.symm
Finset.min_union
theorem
{s t : Finset α} : (s ∪ t).min = s.min ⊓ t.min
Finset.min_mono
theorem
{s t : Finset α} (st : s ⊆ t) : t.min ≤ s.min
Finset.le_min
theorem
{m : WithTop α} {s : Finset α} (st : ∀ a : α, a ∈ s → m ≤ a) : m ≤ s.min
Finset.le_min_iff
theorem
{m : WithTop α} {s : Finset α} : m ≤ s.min ↔ ∀ a ∈ s, m ≤ a
@[simp]
protected theorem le_min_iff {m : WithTop α} {s : Finset α} : m ≤ s.min ↔ ∀ a ∈ s, m ≤ a :=
Finset.le_inf_iff
Finset.min_eq_bot
theorem
[OrderBot α] {s : Finset α} : s.min = ⊥ ↔ ⊥ ∈ s
@[simp]
protected theorem min_eq_bot [OrderBot α] {s : Finset α} : s.min = ⊥ ↔ ⊥ ∈ s :=
Finset.max_eq_top (α := αᵒᵈ)
Finset.min'
definition
(s : Finset α) (H : s.Nonempty) : α
Finset.max'
definition
(s : Finset α) (H : s.Nonempty) : α
Finset.min'_mem
theorem
: s.min' H ∈ s
theorem min'_mem : s.min' H ∈ s :=
mem_of_min <| by simp only [Finset.min, min', id_eq, coe_inf', Function.comp_def]
Finset.min'_le
theorem
(x) (H2 : x ∈ s) : s.min' ⟨x, H2⟩ ≤ x
theorem min'_le (x) (H2 : x ∈ s) : s.min' ⟨x, H2⟩ ≤ x :=
min_le_of_eq H2 (WithTop.coe_untop _ _).symm
Finset.le_min'
theorem
(x) (H2 : ∀ y ∈ s, x ≤ y) : x ≤ s.min' H
theorem le_min' (x) (H2 : ∀ y ∈ s, x ≤ y) : x ≤ s.min' H :=
H2 _ <| min'_mem _ _
Finset.isLeast_min'
theorem
: IsLeast (↑s) (s.min' H)
theorem isLeast_min' : IsLeast (↑s) (s.min' H) :=
⟨min'_mem _ _, min'_le _⟩
Finset.le_min'_iff
theorem
{x} : x ≤ s.min' H ↔ ∀ y ∈ s, x ≤ y
@[simp]
theorem le_min'_iff {x} : x ≤ s.min' H ↔ ∀ y ∈ s, x ≤ y :=
le_isGLB_iff (isLeast_min' s H).isGLB
Finset.min'_singleton
theorem
(a : α) : ({ a } : Finset α).min' (singleton_nonempty _) = a
/-- `{a}.min' _` is `a`. -/
@[simp]
theorem min'_singleton (a : α) : ({a} : Finset α).min' (singleton_nonempty _) = a := by simp [min']
Finset.max'_mem
theorem
: s.max' H ∈ s
theorem max'_mem : s.max' H ∈ s :=
mem_of_max <| by simp only [max', Finset.max, id_eq, coe_sup', Function.comp_def]
Finset.le_max'
theorem
(x) (H2 : x ∈ s) : x ≤ s.max' ⟨x, H2⟩
theorem le_max' (x) (H2 : x ∈ s) : x ≤ s.max' ⟨x, H2⟩ :=
le_max_of_eq H2 (WithBot.coe_unbot _ _).symm
Finset.max'_le
theorem
(x) (H2 : ∀ y ∈ s, y ≤ x) : s.max' H ≤ x
theorem max'_le (x) (H2 : ∀ y ∈ s, y ≤ x) : s.max' H ≤ x :=
H2 _ <| max'_mem _ _
Finset.isGreatest_max'
theorem
: IsGreatest (↑s) (s.max' H)
theorem isGreatest_max' : IsGreatest (↑s) (s.max' H) :=
⟨max'_mem _ _, le_max' _⟩
Finset.max'_le_iff
theorem
{x} : s.max' H ≤ x ↔ ∀ y ∈ s, y ≤ x
@[simp]
theorem max'_le_iff {x} : s.max' H ≤ x ↔ ∀ y ∈ s, y ≤ x :=
isLUB_le_iff (isGreatest_max' s H).isLUB
Finset.max'_lt_iff
theorem
{x} : s.max' H < x ↔ ∀ y ∈ s, y < x
@[simp]
theorem max'_lt_iff {x} : s.max' H < x ↔ ∀ y ∈ s, y < x :=
⟨fun Hlt y hy => (s.le_max' y hy).trans_lt Hlt, fun H => H _ <| s.max'_mem _⟩
Finset.lt_min'_iff
theorem
: x < s.min' H ↔ ∀ y ∈ s, x < y
@[simp]
theorem lt_min'_iff : x < s.min' H ↔ ∀ y ∈ s, x < y :=
@max'_lt_iff αᵒᵈ _ _ H _
Finset.max'_eq_sup'
theorem
: s.max' H = s.sup' H id
theorem max'_eq_sup' : s.max' H = s.sup' H id := rfl
Finset.min'_eq_inf'
theorem
: s.min' H = s.inf' H id
theorem min'_eq_inf' : s.min' H = s.inf' H id := rfl
Finset.max'_singleton
theorem
(a : α) : ({ a } : Finset α).max' (singleton_nonempty _) = a
/-- `{a}.max' _` is `a`. -/
@[simp]
theorem max'_singleton (a : α) : ({a} : Finset α).max' (singleton_nonempty _) = a := by simp [max']
Finset.min'_lt_max'
theorem
{i j} (H1 : i ∈ s) (H2 : j ∈ s) (H3 : i ≠ j) : s.min' ⟨i, H1⟩ < s.max' ⟨i, H1⟩
theorem min'_lt_max' {i j} (H1 : i ∈ s) (H2 : j ∈ s) (H3 : i ≠ j) :
s.min' ⟨i, H1⟩ < s.max' ⟨i, H1⟩ :=
isGLB_lt_isLUB_of_ne (s.isLeast_min' _).isGLB (s.isGreatest_max' _).isLUB H1 H2 H3
Finset.min'_lt_max'_of_card
theorem
(h₂ : 1 < card s) : s.min' (Finset.card_pos.1 <| by omega) < s.max' (Finset.card_pos.1 <| by omega)
/-- If there's more than 1 element, the min' is less than the max'. An alternate version of
`min'_lt_max'` which is sometimes more convenient.
-/
theorem min'_lt_max'_of_card (h₂ : 1 < card s) :
s.min' (Finset.card_pos.1 <| by omega) < s.max' (Finset.card_pos.1 <| by omega) := by
rcases one_lt_card.1 h₂ with ⟨a, ha, b, hb, hab⟩
exact s.min'_lt_max' ha hb hab
Finset.max'_union
theorem
{s₁ s₂ : Finset α} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty) :
(s₁ ∪ s₂).max' (h₁.mono subset_union_left) = s₁.max' h₁ ⊔ s₂.max' h₂
theorem max'_union {s₁ s₂ : Finset α} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty) :
(s₁ ∪ s₂).max' (h₁.mono subset_union_left) = s₁.max' h₁ ⊔ s₂.max' h₂ := sup'_union h₁ h₂ id
Finset.min'_union
theorem
{s₁ s₂ : Finset α} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty) :
(s₁ ∪ s₂).min' (h₁.mono subset_union_left) = s₁.min' h₁ ⊓ s₂.min' h₂
theorem min'_union {s₁ s₂ : Finset α} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty) :
(s₁ ∪ s₂).min' (h₁.mono subset_union_left) = s₁.min' h₁ ⊓ s₂.min' h₂ := inf'_union h₁ h₂ id
Finset.map_ofDual_min
theorem
(s : Finset αᵒᵈ) : s.min.map ofDual = (s.image ofDual).max
theorem map_ofDual_min (s : Finset αᵒᵈ) : s.min.map ofDual = (s.image ofDual).max := by
rw [max_eq_sup_withBot, sup_image]
exact congr_fun Option.map_id _
Finset.map_ofDual_max
theorem
(s : Finset αᵒᵈ) : s.max.map ofDual = (s.image ofDual).min
theorem map_ofDual_max (s : Finset αᵒᵈ) : s.max.map ofDual = (s.image ofDual).min := by
rw [min_eq_inf_withTop, inf_image]
exact congr_fun Option.map_id _
Finset.map_toDual_min
theorem
(s : Finset α) : s.min.map toDual = (s.image toDual).max
theorem map_toDual_min (s : Finset α) : s.min.map toDual = (s.image toDual).max := by
rw [max_eq_sup_withBot, sup_image]
exact congr_fun Option.map_id _
Finset.map_toDual_max
theorem
(s : Finset α) : s.max.map toDual = (s.image toDual).min
theorem map_toDual_max (s : Finset α) : s.max.map toDual = (s.image toDual).min := by
rw [min_eq_inf_withTop, inf_image]
exact congr_fun Option.map_id _
Finset.ofDual_min'
theorem
{s : Finset αᵒᵈ} (hs : s.Nonempty) : ofDual (min' s hs) = max' (s.image ofDual) (hs.image _)
theorem ofDual_min' {s : Finset αᵒᵈ} (hs : s.Nonempty) :
ofDual (min' s hs) = max' (s.image ofDual) (hs.image _) := by
rw [← WithBot.coe_eq_coe]
simp [min'_eq_inf', max'_eq_sup']
Finset.ofDual_max'
theorem
{s : Finset αᵒᵈ} (hs : s.Nonempty) : ofDual (max' s hs) = min' (s.image ofDual) (hs.image _)
theorem ofDual_max' {s : Finset αᵒᵈ} (hs : s.Nonempty) :
ofDual (max' s hs) = min' (s.image ofDual) (hs.image _) := by
rw [← WithTop.coe_eq_coe]
simp [min'_eq_inf', max'_eq_sup']
Finset.toDual_min'
theorem
{s : Finset α} (hs : s.Nonempty) : toDual (min' s hs) = max' (s.image toDual) (hs.image _)
theorem toDual_min' {s : Finset α} (hs : s.Nonempty) :
toDual (min' s hs) = max' (s.image toDual) (hs.image _) := by
rw [← WithBot.coe_eq_coe]
simp [min'_eq_inf', max'_eq_sup']
Finset.toDual_max'
theorem
{s : Finset α} (hs : s.Nonempty) : toDual (max' s hs) = min' (s.image toDual) (hs.image _)
theorem toDual_max' {s : Finset α} (hs : s.Nonempty) :
toDual (max' s hs) = min' (s.image toDual) (hs.image _) := by
rw [← WithTop.coe_eq_coe]
simp [min'_eq_inf', max'_eq_sup']
Finset.max'_subset
theorem
{s t : Finset α} (H : s.Nonempty) (hst : s ⊆ t) : s.max' H ≤ t.max' (H.mono hst)
Finset.min'_subset
theorem
{s t : Finset α} (H : s.Nonempty) (hst : s ⊆ t) : t.min' (H.mono hst) ≤ s.min' H
Finset.max'_insert
theorem
(a : α) (s : Finset α) (H : s.Nonempty) : (insert a s).max' (s.insert_nonempty a) = max (s.max' H) a
theorem max'_insert (a : α) (s : Finset α) (H : s.Nonempty) :
(insert a s).max' (s.insert_nonempty a) = max (s.max' H) a :=
(isGreatest_max' _ _).unique <| by
rw [coe_insert, max_comm]
exact (isGreatest_max' _ _).insert _
Finset.min'_insert
theorem
(a : α) (s : Finset α) (H : s.Nonempty) : (insert a s).min' (s.insert_nonempty a) = min (s.min' H) a
theorem min'_insert (a : α) (s : Finset α) (H : s.Nonempty) :
(insert a s).min' (s.insert_nonempty a) = min (s.min' H) a :=
(isLeast_min' _ _).unique <| by
rw [coe_insert, min_comm]
exact (isLeast_min' _ _).insert _
Finset.lt_max'_of_mem_erase_max'
theorem
[DecidableEq α] {a : α} (ha : a ∈ s.erase (s.max' H)) : a < s.max' H
theorem lt_max'_of_mem_erase_max' [DecidableEq α] {a : α} (ha : a ∈ s.erase (s.max' H)) :
a < s.max' H :=
lt_of_le_of_ne (le_max' _ _ (mem_of_mem_erase ha)) <| ne_of_mem_of_not_mem ha <| not_mem_erase _ _
Finset.min'_lt_of_mem_erase_min'
theorem
[DecidableEq α] {a : α} (ha : a ∈ s.erase (s.min' H)) : s.min' H < a
theorem min'_lt_of_mem_erase_min' [DecidableEq α] {a : α} (ha : a ∈ s.erase (s.min' H)) :
s.min' H < a :=
@lt_max'_of_mem_erase_max' αᵒᵈ _ s H _ a ha
Finset.max'_image
theorem
[LinearOrder β] {f : α → β} (hf : Monotone f) (s : Finset α) (h : (s.image f).Nonempty) :
(s.image f).max' h = f (s.max' h.of_image)
/-- To rewrite from right to left, use `Monotone.map_finset_max'`. -/
@[simp]
theorem max'_image [LinearOrder β] {f : α → β} (hf : Monotone f) (s : Finset α)
(h : (s.image f).Nonempty) : (s.image f).max' h = f (s.max' h.of_image) := by
simp only [max', sup'_image]
exact .symm <| comp_sup'_eq_sup'_comp _ _ fun _ _ ↦ hf.map_max
Monotone.map_finset_max'
theorem
[LinearOrder β] {f : α → β} (hf : Monotone f) {s : Finset α} (h : s.Nonempty) :
f (s.max' h) = (s.image f).max' (h.image f)
/-- A version of `Finset.max'_image` with LHS and RHS reversed.
Also, this version assumes that `s` is nonempty, not its image. -/
lemma _root_.Monotone.map_finset_max' [LinearOrder β] {f : α → β} (hf : Monotone f) {s : Finset α}
(h : s.Nonempty) : f (s.max' h) = (s.image f).max' (h.image f) :=
.symm <| max'_image hf ..
Finset.min'_image
theorem
[LinearOrder β] {f : α → β} (hf : Monotone f) (s : Finset α) (h : (s.image f).Nonempty) :
(s.image f).min' h = f (s.min' h.of_image)
/-- To rewrite from right to left, use `Monotone.map_finset_min'`. -/
@[simp]
theorem min'_image [LinearOrder β] {f : α → β} (hf : Monotone f) (s : Finset α)
(h : (s.image f).Nonempty) : (s.image f).min' h = f (s.min' h.of_image) := by
simp only [min', inf'_image]
exact .symm <| comp_inf'_eq_inf'_comp _ _ fun _ _ ↦ hf.map_min
Monotone.map_finset_min'
theorem
[LinearOrder β] {f : α → β} (hf : Monotone f) {s : Finset α} (h : s.Nonempty) :
f (s.min' h) = (s.image f).min' (h.image f)
/-- A version of `Finset.min'_image` with LHS and RHS reversed.
Also, this version assumes that `s` is nonempty, not its image. -/
lemma _root_.Monotone.map_finset_min' [LinearOrder β] {f : α → β} (hf : Monotone f) {s : Finset α}
(h : s.Nonempty) : f (s.min' h) = (s.image f).min' (h.image f) :=
.symm <| min'_image hf ..
Finset.coe_max'
theorem
{s : Finset α} (hs : s.Nonempty) : ↑(s.max' hs) = s.max
Finset.coe_min'
theorem
{s : Finset α} (hs : s.Nonempty) : ↑(s.min' hs) = s.min
Finset.max_mem_image_coe
theorem
{s : Finset α} (hs : s.Nonempty) : s.max ∈ (s.image (↑) : Finset (WithBot α))
theorem max_mem_image_coe {s : Finset α} (hs : s.Nonempty) :
s.max ∈ (s.image (↑) : Finset (WithBot α)) :=
mem_image.2 ⟨max' s hs, max'_mem _ _, coe_max' hs⟩
Finset.min_mem_image_coe
theorem
{s : Finset α} (hs : s.Nonempty) : s.min ∈ (s.image (↑) : Finset (WithTop α))
theorem min_mem_image_coe {s : Finset α} (hs : s.Nonempty) :
s.min ∈ (s.image (↑) : Finset (WithTop α)) :=
mem_image.2 ⟨min' s hs, min'_mem _ _, coe_min' hs⟩
Finset.max_mem_insert_bot_image_coe
theorem
(s : Finset α) : s.max ∈ (insert ⊥ (s.image (↑)) : Finset (WithBot α))
theorem max_mem_insert_bot_image_coe (s : Finset α) :
s.max ∈ (insert ⊥ (s.image (↑)) : Finset (WithBot α)) :=
mem_insert.2 <| s.eq_empty_or_nonempty.imp max_eq_bot.2 max_mem_image_coe
Finset.min_mem_insert_top_image_coe
theorem
(s : Finset α) : s.min ∈ (insert ⊤ (s.image (↑)) : Finset (WithTop α))
theorem min_mem_insert_top_image_coe (s : Finset α) :
s.min ∈ (insert ⊤ (s.image (↑)) : Finset (WithTop α)) :=
mem_insert.2 <| s.eq_empty_or_nonempty.imp min_eq_top.2 min_mem_image_coe
Finset.max'_erase_ne_self
theorem
{s : Finset α} (s0 : (s.erase x).Nonempty) : (s.erase x).max' s0 ≠ x
theorem max'_erase_ne_self {s : Finset α} (s0 : (s.erase x).Nonempty) : (s.erase x).max' s0 ≠ x :=
ne_of_mem_erase (max'_mem _ s0)
Finset.min'_erase_ne_self
theorem
{s : Finset α} (s0 : (s.erase x).Nonempty) : (s.erase x).min' s0 ≠ x
theorem min'_erase_ne_self {s : Finset α} (s0 : (s.erase x).Nonempty) : (s.erase x).min' s0 ≠ x :=
ne_of_mem_erase (min'_mem _ s0)
Finset.max_erase_ne_self
theorem
{s : Finset α} : (s.erase x).max ≠ x
theorem max_erase_ne_self {s : Finset α} : (s.erase x).max ≠ x := by
by_cases s0 : (s.erase x).Nonempty
· refine ne_of_eq_of_ne (coe_max' s0).symm ?_
exact WithBot.coe_eq_coe.not.mpr (max'_erase_ne_self _)
· rw [not_nonempty_iff_eq_empty.mp s0, max_empty]
exact WithBot.bot_ne_coe
Finset.min_erase_ne_self
theorem
{s : Finset α} : (s.erase x).min ≠ x
theorem min_erase_ne_self {s : Finset α} : (s.erase x).min ≠ x := by
apply mt (congr_arg (WithTop.map toDual))
rw [map_toDual_min, image_erase toDual.injective, WithTop.map_coe]
apply max_erase_ne_self
Finset.exists_next_right
theorem
{x : α} {s : Finset α} (h : ∃ y ∈ s, x < y) : ∃ y ∈ s, x < y ∧ ∀ z ∈ s, x < z → y ≤ z
theorem exists_next_right {x : α} {s : Finset α} (h : ∃ y ∈ s, x < y) :
∃ y ∈ s, x < y ∧ ∀ z ∈ s, x < z → y ≤ z :=
have Hne : (s.filter (x < ·)).Nonempty := h.imp fun y hy => mem_filter.2 (by simpa)
have aux := mem_filter.1 (min'_mem _ Hne)
⟨min' _ Hne, aux.1, by simp, fun z hzs hz => min'_le _ _ <| mem_filter.2 ⟨hzs, by simpa⟩⟩
Finset.exists_next_left
theorem
{x : α} {s : Finset α} (h : ∃ y ∈ s, y < x) : ∃ y ∈ s, y < x ∧ ∀ z ∈ s, z < x → z ≤ y
theorem exists_next_left {x : α} {s : Finset α} (h : ∃ y ∈ s, y < x) :
∃ y ∈ s, y < x ∧ ∀ z ∈ s, z < x → z ≤ y :=
@exists_next_right αᵒᵈ _ x s h
Finset.card_le_of_interleaved
theorem
{s t : Finset α} (h : ∀ᵉ (x ∈ s) (y ∈ s), x < y → (∀ z ∈ s, z ∉ Set.Ioo x y) → ∃ z ∈ t, x < z ∧ z < y) :
s.card ≤ t.card + 1
/-- If finsets `s` and `t` are interleaved, then `Finset.card s ≤ Finset.card t + 1`. -/
theorem card_le_of_interleaved {s t : Finset α}
(h : ∀ᵉ (x ∈ s) (y ∈ s),
x < y → (∀ z ∈ s, z ∉ Set.Ioo x y) → ∃ z ∈ t, x < z ∧ z < y) :
s.card ≤ t.card + 1 := by
replace h : ∀ᵉ (x ∈ s) (y ∈ s), x < y → ∃ z ∈ t, x < z ∧ z < y := by
intro x hx y hy hxy
rcases exists_next_right ⟨y, hy, hxy⟩ with ⟨a, has, hxa, ha⟩
rcases h x hx a has hxa fun z hzs hz => hz.2.not_le <| ha _ hzs hz.1 with ⟨b, hbt, hxb, hba⟩
exact ⟨b, hbt, hxb, hba.trans_le <| ha _ hy hxy⟩
set f : α → WithTop α := fun x => (t.filter fun y => x < y).min
have f_mono : StrictMonoOn f s := by
intro x hx y hy hxy
rcases h x hx y hy hxy with ⟨a, hat, hxa, hay⟩
calc
f x ≤ a := min_le (mem_filter.2 ⟨hat, by simpa⟩)
_ < f y :=
(Finset.lt_inf_iff <| WithTop.coe_lt_top a).2 fun b hb =>
WithTop.coe_lt_coe.2 <| hay.trans (by simpa using (mem_filter.1 hb).2)
calc
s.card = (s.image f).card := (card_image_of_injOn f_mono.injOn).symm
_ ≤ (insert ⊤ (t.image (↑)) : Finset (WithTop α)).card :=
card_mono <| image_subset_iff.2 fun x _ =>
insert_subset_insert _ (image_subset_image <| filter_subset _ _)
(min_mem_insert_top_image_coe _)
_ ≤ t.card + 1 := (card_insert_le _ _).trans (Nat.add_le_add_right card_image_le _)
Finset.card_le_diff_of_interleaved
theorem
{s t : Finset α} (h : ∀ᵉ (x ∈ s) (y ∈ s), x < y → (∀ z ∈ s, z ∉ Set.Ioo x y) → ∃ z ∈ t, x < z ∧ z < y) :
s.card ≤ (t \ s).card + 1
/-- If finsets `s` and `t` are interleaved, then `Finset.card s ≤ Finset.card (t \ s) + 1`. -/
theorem card_le_diff_of_interleaved {s t : Finset α}
(h :
∀ᵉ (x ∈ s) (y ∈ s),
x < y → (∀ z ∈ s, z ∉ Set.Ioo x y) → ∃ z ∈ t, x < z ∧ z < y) :
s.card ≤ (t \ s).card + 1 :=
card_le_of_interleaved fun x hx y hy hxy hs =>
let ⟨z, hzt, hxz, hzy⟩ := h x hx y hy hxy hs
⟨z, mem_sdiff.2 ⟨hzt, fun hzs => hs z hzs ⟨hxz, hzy⟩⟩, hxz, hzy⟩
Finset.induction_on_max
theorem
[DecidableEq α] {p : Finset α → Prop} (s : Finset α) (h0 : p ∅)
(step : ∀ a s, (∀ x ∈ s, x < a) → p s → p (insert a s)) : p s
/-- Induction principle for `Finset`s in a linearly ordered type: a predicate is true on all
`s : Finset α` provided that:
* it is true on the empty `Finset`,
* for every `s : Finset α` and an element `a` strictly greater than all elements of `s`, `p s`
implies `p (insert a s)`. -/
@[elab_as_elim]
theorem induction_on_max [DecidableEq α] {p : Finset α → Prop} (s : Finset α) (h0 : p ∅)
(step : ∀ a s, (∀ x ∈ s, x < a) → p s → p (insert a s)) : p s := by
induction' s using Finset.strongInductionOn with s ihs
rcases s.eq_empty_or_nonempty with (rfl | hne)
· exact h0
· have H : s.max' hne ∈ s := max'_mem s hne
rw [← insert_erase H]
exact step _ _ (fun x => s.lt_max'_of_mem_erase_max' hne) (ihs _ <| erase_ssubset H)
Finset.induction_on_min
theorem
[DecidableEq α] {p : Finset α → Prop} (s : Finset α) (h0 : p ∅)
(step : ∀ a s, (∀ x ∈ s, a < x) → p s → p (insert a s)) : p s
/-- Induction principle for `Finset`s in a linearly ordered type: a predicate is true on all
`s : Finset α` provided that:
* it is true on the empty `Finset`,
* for every `s : Finset α` and an element `a` strictly less than all elements of `s`, `p s`
implies `p (insert a s)`. -/
@[elab_as_elim]
theorem induction_on_min [DecidableEq α] {p : Finset α → Prop} (s : Finset α) (h0 : p ∅)
(step : ∀ a s, (∀ x ∈ s, a < x) → p s → p (insert a s)) : p s :=
@induction_on_max αᵒᵈ _ _ _ s h0 step
Finset.induction_on_max_value
theorem
[DecidableEq ι] (f : ι → α) {p : Finset ι → Prop} (s : Finset ι) (h0 : p ∅)
(step : ∀ a s, a ∉ s → (∀ x ∈ s, f x ≤ f a) → p s → p (insert a s)) : p s
/-- Induction principle for `Finset`s in any type from which a given function `f` maps to a linearly
ordered type : a predicate is true on all `s : Finset α` provided that:
* it is true on the empty `Finset`,
* for every `s : Finset α` and an element `a` such that for elements of `s` denoted by `x` we have
`f x ≤ f a`, `p s` implies `p (insert a s)`. -/
@[elab_as_elim]
theorem induction_on_max_value [DecidableEq ι] (f : ι → α) {p : Finset ι → Prop} (s : Finset ι)
(h0 : p ∅) (step : ∀ a s, a ∉ s → (∀ x ∈ s, f x ≤ f a) → p s → p (insert a s)) : p s := by
induction' s using Finset.strongInductionOn with s ihs
rcases (s.image f).eq_empty_or_nonempty with (hne | hne)
· simp only [image_eq_empty] at hne
simp only [hne, h0]
· have H : (s.image f).max' hne ∈ s.image f := max'_mem (s.image f) hne
simp only [mem_image, exists_prop] at H
rcases H with ⟨a, has, hfa⟩
rw [← insert_erase has]
refine step _ _ (not_mem_erase a s) (fun x hx => ?_) (ihs _ <| erase_ssubset has)
rw [hfa]
exact le_max' _ _ (mem_image_of_mem _ <| mem_of_mem_erase hx)
Finset.induction_on_min_value
theorem
[DecidableEq ι] (f : ι → α) {p : Finset ι → Prop} (s : Finset ι) (h0 : p ∅)
(step : ∀ a s, a ∉ s → (∀ x ∈ s, f a ≤ f x) → p s → p (insert a s)) : p s
/-- Induction principle for `Finset`s in any type from which a given function `f` maps to a linearly
ordered type : a predicate is true on all `s : Finset α` provided that:
* it is true on the empty `Finset`,
* for every `s : Finset α` and an element `a` such that for elements of `s` denoted by `x` we have
`f a ≤ f x`, `p s` implies `p (insert a s)`. -/
@[elab_as_elim]
theorem induction_on_min_value [DecidableEq ι] (f : ι → α) {p : Finset ι → Prop} (s : Finset ι)
(h0 : p ∅) (step : ∀ a s, a ∉ s → (∀ x ∈ s, f a ≤ f x) → p s → p (insert a s)) : p s :=
@induction_on_max_value αᵒᵈ ι _ _ _ _ s h0 step
Finset.exists_max_image
theorem
(s : Finset β) (f : β → α) (h : s.Nonempty) : ∃ x ∈ s, ∀ x' ∈ s, f x' ≤ f x
theorem exists_max_image (s : Finset β) (f : β → α) (h : s.Nonempty) :
∃ x ∈ s, ∀ x' ∈ s, f x' ≤ f x := by
obtain ⟨y, hy⟩ := max_of_nonempty (h.image f)
rcases mem_image.mp (mem_of_max hy) with ⟨x, hx, rfl⟩
exact ⟨x, hx, fun x' hx' => le_max_of_eq (mem_image_of_mem f hx') hy⟩
Finset.exists_min_image
theorem
(s : Finset β) (f : β → α) (h : s.Nonempty) : ∃ x ∈ s, ∀ x' ∈ s, f x ≤ f x'
theorem exists_min_image (s : Finset β) (f : β → α) (h : s.Nonempty) :
∃ x ∈ s, ∀ x' ∈ s, f x ≤ f x' :=
@exists_max_image αᵒᵈ β _ s f h
Finset.isGLB_iff_isLeast
theorem
[LinearOrder α] (i : α) (s : Finset α) (hs : s.Nonempty) : IsGLB (s : Set α) i ↔ IsLeast (↑s) i
theorem isGLB_iff_isLeast [LinearOrder α] (i : α) (s : Finset α) (hs : s.Nonempty) :
IsGLBIsGLB (s : Set α) i ↔ IsLeast (↑s) i := by
refine ⟨fun his => ?_, IsLeast.isGLB⟩
suffices i = min' s hs by
rw [this]
exact isLeast_min' s hs
rw [IsGLB, IsGreatest, mem_lowerBounds, mem_upperBounds] at his
exact le_antisymm (his.1 (Finset.min' s hs) (Finset.min'_mem s hs)) (his.2 _ (Finset.min'_le s))
Finset.isLUB_iff_isGreatest
theorem
[LinearOrder α] (i : α) (s : Finset α) (hs : s.Nonempty) : IsLUB (s : Set α) i ↔ IsGreatest (↑s) i
theorem isLUB_iff_isGreatest [LinearOrder α] (i : α) (s : Finset α) (hs : s.Nonempty) :
IsLUBIsLUB (s : Set α) i ↔ IsGreatest (↑s) i :=
@isGLB_iff_isLeast αᵒᵈ _ i s hs
Finset.isGLB_mem
theorem
[LinearOrder α] {i : α} (s : Finset α) (his : IsGLB (s : Set α) i) (hs : s.Nonempty) : i ∈ s
Finset.isLUB_mem
theorem
[LinearOrder α] {i : α} (s : Finset α) (his : IsLUB (s : Set α) i) (hs : s.Nonempty) : i ∈ s
Multiset.exists_max_image
theorem
{α R : Type*} [LinearOrder R] (f : α → R) {s : Multiset α} (hs : s ≠ 0) : ∃ y ∈ s, ∀ z ∈ s, f z ≤ f y
theorem Multiset.exists_max_image {α R : Type*} [LinearOrder R] (f : α → R) {s : Multiset α}
(hs : s ≠ 0) : ∃ y ∈ s, ∀ z ∈ s, f z ≤ f y := by
classical
obtain ⟨y, hys, hy⟩ := Finset.exists_max_image s.toFinset f (toFinset_nonempty.mpr hs)
exact ⟨y, mem_toFinset.mp hys, fun _ hz ↦ hy _ (mem_toFinset.mpr hz)⟩
Multiset.exists_min_image
theorem
{α R : Type*} [LinearOrder R] (f : α → R) {s : Multiset α} (hs : s ≠ 0) : ∃ y ∈ s, ∀ z ∈ s, f y ≤ f z
theorem Multiset.exists_min_image {α R : Type*} [LinearOrder R] (f : α → R) {s : Multiset α}
(hs : s ≠ 0) : ∃ y ∈ s, ∀ z ∈ s, f y ≤ f z :=
@exists_max_image α Rᵒᵈ _ f s hs