Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 9eefd40

Browse files
ChrisHughes24mergify[bot]
authored andcommitted
refactor(data/list/min_max): use with_top for maximum and define argmax (#1320)
* refactor(data/list/min_max): use option for maximum and define argmax * prove minimum_singleton * fix build * use with_bot for maximum * update comments
1 parent 92fa24c commit 9eefd40

File tree

3 files changed

+252
-151
lines changed

3 files changed

+252
-151
lines changed

src/data/equiv/denumerable.lean

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,20 @@ lemma of_nat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, of_nat s n =
166166
(λ (y : ℕ) (hy : y ∈ s), ⟨y, hy⟩) (by simp) in
167167
have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩,
168168
by simp [list.mem_filter, subtype.ext, t]; intros; refl,
169-
if ht : t = [] then0, le_antisymm (@bot_le s _ _)
170-
(le_of_not_gt (λ h, list.not_mem_nil ⊥ $
171-
by rw [← ht, hmt]; exact h))⟩
172-
else by letI : inhabited s := ⟨⊥⟩;
173-
exact have wf : (list.maximum t).1 < x, by simpa [hmt] using list.maximum_mem ht,
174-
let ⟨a, ha⟩ := of_nat_surjective_aux (list.maximum t).2 in
175-
⟨a + 1, le_antisymm
176-
(by rw of_nat; exact succ_le_of_lt (by rw ha; exact wf)) $
177-
by rw of_nat; exact le_succ_of_forall_lt_le
178-
(λ z hz, by rw ha; exact list.le_maximum_of_mem (hmt.2 hz))⟩
169+
have wf : ∀ m : s, list.maximum t = m → m.1 < x,
170+
from λ m hmax, by simpa [hmt] using list.maximum_mem hmax,
171+
begin
172+
cases hmax : list.maximum t with m,
173+
{ exact ⟨0, le_antisymm (@bot_le s _ _)
174+
(le_of_not_gt (λ h, list.not_mem_nil (⊥ : s) $
175+
by rw [← list.maximum_eq_none.1 hmax, hmt]; exact h))⟩ },
176+
{ cases of_nat_surjective_aux m.2 with a ha,
177+
exact ⟨a + 1, le_antisymm
178+
(by rw of_nat; exact succ_le_of_lt (by rw ha; exact wf _ hmax)) $
179+
by rw of_nat; exact le_succ_of_forall_lt_le
180+
(λ z hz, by rw ha; cases m; exact list.le_maximum_of_mem (hmt.2 hz) hmax)⟩ }
181+
end
182+
using_well_founded {dec_tac := `[tauto]}
179183

180184
lemma of_nat_surjective : surjective (of_nat s) :=
181185
λ ⟨x, hx⟩, of_nat_surjective_aux hx

0 commit comments

Comments
 (0)