Skip to content

Commit ef9f57c

Browse files
committed
feat)List/MinMax): getD_maximum?_eq_unbot'_maximum (#14836)
And also for minimum This links the two definitions
1 parent b06cc0b commit ef9f57c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Mathlib/Data/List/MinMax.lean

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,26 @@ theorem minimum_of_length_pos_le_getElem {i : ℕ} (w : i < l.length) (h := (Nat
487487
l.minimum_of_length_pos h ≤ l[i] :=
488488
getElem_le_maximum_of_length_pos (α := αᵒᵈ) w
489489

490+
lemma getD_maximum?_eq_unbot'_maximum (l : List α) (d : α) :
491+
l.maximum?.getD d = l.maximum.unbot' d := by
492+
cases hy : l.maximum with
493+
| bot => simp [List.maximum_eq_bot.mp hy]
494+
| coe y =>
495+
rw [List.maximum_eq_coe_iff] at hy
496+
simp only [WithBot.unbot'_coe]
497+
cases hz : l.maximum? with
498+
| none => simp [List.maximum?_eq_none_iff.mp hz] at hy
499+
| some z =>
500+
have : Antisymm (α := α) (· ≤ ·) := ⟨_root_.le_antisymm⟩
501+
rw [List.maximum?_eq_some_iff] at hz
502+
· rw [Option.getD_some]
503+
exact _root_.le_antisymm (hy.right _ hz.left) (hz.right _ hy.left)
504+
all_goals simp [le_total]
505+
506+
lemma getD_minimum?_eq_untop'_minimum (l : List α) (d : α) :
507+
l.minimum?.getD d = l.minimum.untop' d :=
508+
getD_maximum?_eq_unbot'_maximum (α := αᵒᵈ) _ _
509+
490510
end LinearOrder
491511

492512
end MaximumMinimum

0 commit comments

Comments
 (0)