Skip to content

Commit 1e81efc

Browse files
committed
feat(Data/Finset/Max): min'_pair, max'_pair (#29415)
Add the lemmas: ```lean lemma min'_pair (a b : α) : min' {a, b} (insert_nonempty _ _) = min a b := by ``` ```lean lemma max'_pair (a b : α) : max' {a, b} (insert_nonempty _ _) = max a b := by ``` and corresponding `min_pair` and `max_pair`. So that the primed lemmas can be proved by `simp`, like the unprimed ones, make `min'_insert` and `max'_insert` into `simp` lemmas, and swap the arguments to `min` and `max` on their RHS, also corresponding more closely to the unprimed lemmas `min_insert` and `max_insert`.
1 parent dba1734 commit 1e81efc

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

Mathlib/Data/Finset/Max.lean

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ theorem max_singleton {a : α} : Finset.max {a} = (a : WithBot α) := by
4949
rw [← insert_empty_eq]
5050
exact max_insert
5151

52+
lemma max_pair (a b : α) :
53+
Finset.max {a, b} = max (↑a) (↑b) := by
54+
simp
55+
5256
theorem max_of_mem {s : Finset α} {a : α} (h : a ∈ s) : ∃ b : α, s.max = b := by
5357
obtain ⟨b, h, _⟩ := le_sup (α := WithBot α) h _ rfl
5458
exact ⟨b, h⟩
@@ -132,6 +136,10 @@ theorem min_singleton {a : α} : Finset.min {a} = (a : WithTop α) := by
132136
rw [← insert_empty_eq]
133137
exact min_insert
134138

139+
lemma min_pair (a b : α) :
140+
Finset.min {a, b} = min (↑a) (↑b) := by
141+
simp
142+
135143
theorem min_of_mem {s : Finset α} {a : α} (h : a ∈ s) : ∃ b : α, s.min = b := by
136144
obtain ⟨b, h, _⟩ := inf_le (α := WithTop α) h _ rfl
137145
exact ⟨b, h⟩
@@ -312,18 +320,26 @@ theorem min'_subset {s t : Finset α} (H : s.Nonempty) (hst : s ⊆ t) :
312320
t.min' (H.mono hst) ≤ s.min' H :=
313321
min'_le _ _ (hst (s.min'_mem H))
314322

315-
theorem max'_insert (a : α) (s : Finset α) (H : s.Nonempty) :
316-
(insert a s).max' (s.insert_nonempty a) = max (s.max' H) a :=
323+
@[simp] theorem max'_insert (a : α) (s : Finset α) (H : s.Nonempty) :
324+
(insert a s).max' (s.insert_nonempty a) = max a (s.max' H) :=
317325
(isGreatest_max' _ _).unique <| by
318-
rw [coe_insert, max_comm]
326+
rw [coe_insert]
319327
exact (isGreatest_max' _ _).insert _
320328

321-
theorem min'_insert (a : α) (s : Finset α) (H : s.Nonempty) :
322-
(insert a s).min' (s.insert_nonempty a) = min (s.min' H) a :=
329+
@[simp] theorem min'_insert (a : α) (s : Finset α) (H : s.Nonempty) :
330+
(insert a s).min' (s.insert_nonempty a) = min a (s.min' H) :=
323331
(isLeast_min' _ _).unique <| by
324-
rw [coe_insert, min_comm]
332+
rw [coe_insert]
325333
exact (isLeast_min' _ _).insert _
326334

335+
lemma min'_pair (a b : α) :
336+
min' {a, b} (insert_nonempty _ _) = min a b := by
337+
simp
338+
339+
lemma max'_pair (a b : α) :
340+
max' {a, b} (insert_nonempty _ _) = max a b := by
341+
simp
342+
327343
theorem lt_max'_of_mem_erase_max' [DecidableEq α] {a : α} (ha : a ∈ s.erase (s.max' H)) :
328344
a < s.max' H :=
329345
lt_of_le_of_ne (le_max' _ _ (mem_of_mem_erase ha)) <| ne_of_mem_of_not_mem ha <| notMem_erase _ _

0 commit comments

Comments
 (0)