Skip to content

Commit

Permalink
feat(data/finset): max_of_ne_empty, min_of_ne_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
spl authored and johoelzl committed Sep 3, 2018
1 parent 7ee7614 commit 6ddc3fc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions data/finset.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1237,11 +1237,12 @@ max_singleton
theorem max_of_mem {s : finset α} {a : α} (h : a ∈ s) : ∃ b, b ∈ s.max :=
(@le_sup (with_bot α) _ _ _ _ _ h _ rfl).imp $ λ b, Exists.fst

theorem max_of_ne_empty {s : finset α} (h : s ≠ ∅) : ∃ a, a ∈ s.max :=
let ⟨a, ha⟩ := exists_mem_of_ne_empty h in max_of_mem ha

theorem max_eq_none {s : finset α} : s.max = none ↔ s = ∅ :=
⟨λ h, by_contradiction
(λ hs, let ⟨a, ha⟩ := exists_mem_of_ne_empty hs in
let ⟨b, hb⟩ := max_of_mem ha in
by simpa [h] using hb),
⟨λ h, by_contradiction $
λ hs, let ⟨a, ha⟩ := max_of_ne_empty hs in by simpa [h] using ha,
λ h, h.symm ▸ max_empty⟩

theorem mem_of_max {s : finset α} : ∀ {a : α}, a ∈ s.max → a ∈ s :=
Expand Down Expand Up @@ -1278,11 +1279,12 @@ by simp [finset.min, option.lift_or_get]
theorem min_of_mem {s : finset α} {a : α} (h : a ∈ s) : ∃ b, b ∈ s.min :=
(@inf_le (with_top α) _ _ _ _ _ h _ rfl).imp $ λ b, Exists.fst

theorem min_of_ne_empty {s : finset α} (h : s ≠ ∅) : ∃ a, a ∈ s.min :=
let ⟨a, ha⟩ := exists_mem_of_ne_empty h in min_of_mem ha

theorem min_eq_none {s : finset α} : s.min = none ↔ s = ∅ :=
⟨λ h, by_contradiction
(λ hs, let ⟨a, ha⟩ := exists_mem_of_ne_empty hs in
let ⟨b, hb⟩ := min_of_mem ha in
by simpa [h] using hb),
⟨λ h, by_contradiction $
λ hs, let ⟨a, ha⟩ := min_of_ne_empty hs in by simpa [h] using ha,
λ h, h.symm ▸ min_empty⟩

theorem mem_of_min {s : finset α} : ∀ {a : α}, a ∈ s.min → a ∈ s :=
Expand Down

0 comments on commit 6ddc3fc

Please sign in to comment.