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

Commit 8ef2c02

Browse files
committed
chore(order/bounded_order): move order_dual instances up, use them to golf lemmas (#14544)
I only golf lemmas and `Prop`-valued instances to be sure that I don't add `order_dual`s to the statements.
1 parent 5002452 commit 8ef2c02

File tree

1 file changed

+35
-60
lines changed

1 file changed

+35
-60
lines changed

src/order/bounded_order.lean

Lines changed: 35 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class order_bot (α : Type u) [has_le α] extends has_bot α :=
154154
(bot_le : ∀ a : α, ⊥ ≤ a)
155155

156156
section order_bot
157+
157158
section has_le
158159
variables [has_le α] [order_bot α] {a : α}
159160

@@ -162,6 +163,27 @@ variables [has_le α] [order_bot α] {a : α}
162163

163164
end has_le
164165

166+
namespace order_dual
167+
variable (α)
168+
169+
instance [has_bot α] : has_top αᵒᵈ := ⟨(⊥ : α)⟩
170+
instance [has_top α] : has_bot αᵒᵈ := ⟨(⊤ : α)⟩
171+
172+
instance [has_le α] [order_bot α] : order_top αᵒᵈ :=
173+
{ le_top := @bot_le α _ _,
174+
.. order_dual.has_top α }
175+
176+
instance [has_le α] [order_top α] : order_bot αᵒᵈ :=
177+
{ bot_le := @le_top α _ _,
178+
.. order_dual.has_bot α }
179+
180+
@[simp] lemma of_dual_bot [has_top α] : of_dual ⊥ = (⊤ : α) := rfl
181+
@[simp] lemma of_dual_top [has_bot α] : of_dual ⊤ = (⊥ : α) := rfl
182+
@[simp] lemma to_dual_bot [has_bot α] : to_dual (⊥ : α) = ⊤ := rfl
183+
@[simp] lemma to_dual_top [has_top α] : to_dual (⊤ : α) = ⊥ := rfl
184+
185+
end order_dual
186+
165187
section preorder
166188
variables [preorder α] [order_bot α] {a b : α}
167189

@@ -201,15 +223,14 @@ lemma ne.bot_lt' (h : ⊥ ≠ a) : ⊥ < a := h.symm.bot_lt
201223
lemma ne_bot_of_le_ne_bot (hb : b ≠ ⊥) (hab : b ≤ a) : a ≠ ⊥ := (hb.bot_lt.trans_le hab).ne'
202224

203225
lemma strict_mono.apply_eq_bot_iff (hf : strict_mono f) : f a = f ⊥ ↔ a = ⊥ :=
204-
⟨λ h, not_bot_lt_iff.1 $ λ ha, (hf ha).ne' h, congr_arg _⟩
226+
hf.dual.apply_eq_top_iff
205227

206228
lemma strict_anti.apply_eq_bot_iff (hf : strict_anti f) : f a = f ⊥ ↔ a = ⊥ :=
207-
⟨λ h, not_bot_lt_iff.1 $ λ ha, (hf ha).ne h, congr_arg _⟩
229+
hf.dual.apply_eq_top_iff
208230

209231
variables [nontrivial α]
210232

211-
lemma not_is_max_bot : ¬ is_max (⊥ : α) :=
212-
λ h, let ⟨a, ha⟩ := exists_ne (⊥ : α) in ha $ le_bot_iff.1 $ h bot_le
233+
lemma not_is_max_bot : ¬ is_max (⊥ : α) := @not_is_min_top αᵒᵈ _ _ _
213234

214235
end order_bot
215236

@@ -267,7 +288,7 @@ inf_of_le_right le_top
267288
inf_of_le_left le_top
268289

269290
@[simp] theorem inf_eq_top_iff : a ⊓ b = ⊤ ↔ (a = ⊤ ∧ b = ⊤) :=
270-
by rw [eq_top_iff, le_inf_iff]; simp
291+
@sup_eq_bot_iff αᵒᵈ _ _ _ _
271292

272293
end semilattice_inf_top
273294

@@ -289,6 +310,9 @@ end semilattice_inf_bot
289310
@[ancestor order_top order_bot]
290311
class bounded_order (α : Type u) [has_le α] extends order_top α, order_bot α.
291312

313+
instance (α : Type u) [has_le α] [bounded_order α] : bounded_order αᵒᵈ :=
314+
{ .. order_dual.order_top α, .. order_dual.order_bot α }
315+
292316
theorem bounded_order.ext {α} [partial_order α] {A B : bounded_order α} : A = B :=
293317
begin
294318
have ht : @bounded_order.to_order_top α _ A = @bounded_order.to_order_top α _ B := order_top.ext,
@@ -821,7 +845,7 @@ def untop : Π (x : with_top α), x ≠ ⊤ → α :=
821845
with_bot.unbot
822846

823847
@[simp] lemma coe_untop (x : with_top α) (h : x ≠ ⊤) : (x.untop h : with_top α) = x :=
824-
by { cases x, simpa using h, refl, }
848+
with_bot.coe_unbot x h
825849

826850
@[simp] lemma untop_coe (x : α) (h : (x : with_top α) ≠ ⊤ := coe_ne_top) :
827851
(x : with_top α).untop h = x := rfl
@@ -852,8 +876,7 @@ instance [order_bot α] : order_bot (with_top α) :=
852876
instance [order_bot α] : bounded_order (with_top α) :=
853877
{ ..with_top.order_top, ..with_top.order_bot }
854878

855-
lemma not_top_le_coe (a : α) : ¬ (⊤ : with_top α) ≤ ↑a :=
856-
λ h, let ⟨b, hb, _⟩ := h _ rfl in option.not_mem_none _ hb
879+
lemma not_top_le_coe (a : α) : ¬ (⊤ : with_top α) ≤ ↑a := with_bot.not_coe_le_bot (to_dual a)
857880

858881
lemma le_coe : ∀ {o : option α}, a ∈ o → (@has_le.le (with_top α) _ o b ↔ a ≤ b) | _ rfl :=
859882
coe_le_coe
@@ -966,11 +989,7 @@ instance decidable_lt [has_lt α] [@decidable_rel α (<)] : @decidable_rel (with
966989
λ x y, @with_bot.decidable_lt αᵒᵈ _ _ y x
967990

968991
instance is_total_le [has_le α] [is_total α (≤)] : is_total (with_top α) (≤) :=
969-
⟨λ a b, match a, b with
970-
| _ , none := or.inl le_top
971-
| none , _ := or.inr le_top
972-
| some x, some y := (total_of (≤) x y).imp some_le_some.2 some_le_some.2
973-
end
992+
@order_dual.is_total_le (with_bot αᵒᵈ) _ _
974993

975994
instance [linear_order α] : linear_order (with_top α) := lattice.to_linear_order _
976995

@@ -998,36 +1017,18 @@ lemma _root_.with_bot.well_founded_gt [preorder α] (h : @well_founded α (>)) :
9981017
@with_top.well_founded_lt αᵒᵈ _ h
9991018

10001019
instance [has_lt α] [densely_ordered α] [no_max_order α] : densely_ordered (with_top α) :=
1001-
⟨ λ a b,
1002-
match a, b with
1003-
| none, a := λ h : ⊤ < a, (not_none_lt _ h).elim
1004-
| some a, none := λ h, let ⟨b, hb⟩ := exists_gt a in ⟨b, coe_lt_coe.2 hb, coe_lt_top b⟩
1005-
| some a, some b := λ h, let ⟨a, ha₁, ha₂⟩ := exists_between (coe_lt_coe.1 h) in
1006-
⟨a, coe_lt_coe.2 ha₁, coe_lt_coe.2 ha₂⟩
1007-
end
1020+
order_dual.densely_ordered (with_bot αᵒᵈ)
10081021

10091022
lemma lt_iff_exists_coe_btwn [preorder α] [densely_ordered α] [no_max_order α] {a b : with_top α} :
10101023
a < b ↔ ∃ x : α, a < ↑x ∧ ↑x < b :=
10111024
⟨λ h, let ⟨y, hy⟩ := exists_between h, ⟨x, hx⟩ := lt_iff_exists_coe.1 hy.2 in ⟨x, hx.1 ▸ hy⟩,
10121025
λ ⟨x, hx⟩, lt_trans hx.1 hx.2
10131026

10141027
instance [has_le α] [no_bot_order α] [nonempty α] : no_bot_order (with_top α) :=
1015-
begin
1016-
apply with_top.rec_top_coe,
1017-
{ exact ‹nonempty α›.elim (λ a, ⟨a, not_top_le_coe a⟩) },
1018-
{ intro a,
1019-
obtain ⟨b, h⟩ := exists_not_ge a,
1020-
exact ⟨b, by rwa coe_le_coe⟩ }
1021-
end
1028+
order_dual.no_bot_order (with_bot αᵒᵈ)
10221029

10231030
instance [has_lt α] [no_min_order α] [nonempty α] : no_min_order (with_top α) :=
1024-
begin
1025-
apply rec_top_coe,
1026-
{ exact ‹nonempty α›.elim (λ a, ⟨a, with_top.coe_lt_top a⟩) },
1027-
{ intro a,
1028-
obtain ⟨b, ha⟩ := exists_lt a,
1029-
exact ⟨b, coe_lt_coe.mpr ha⟩ }
1030-
end
1031+
order_dual.no_min_order (with_bot αᵒᵈ)
10311032

10321033
end with_top
10331034

@@ -1107,32 +1108,6 @@ by rw [←coe_top htop, ext_iff]
11071108

11081109
end subtype
11091110

1110-
section order_dual
1111-
variable (α)
1112-
1113-
instance [has_bot α] : has_top αᵒᵈ := ⟨(⊥ : α)⟩
1114-
instance [has_top α] : has_bot αᵒᵈ := ⟨(⊤ : α)⟩
1115-
1116-
instance [has_le α] [order_bot α] : order_top αᵒᵈ :=
1117-
{ le_top := @bot_le α _ _,
1118-
.. order_dual.has_top α }
1119-
1120-
instance [has_le α] [order_top α] : order_bot αᵒᵈ :=
1121-
{ bot_le := @le_top α _ _,
1122-
.. order_dual.has_bot α }
1123-
1124-
instance [has_le α] [bounded_order α] : bounded_order αᵒᵈ :=
1125-
{ .. order_dual.order_top α, .. order_dual.order_bot α }
1126-
1127-
open order_dual
1128-
1129-
@[simp] lemma of_dual_bot [has_top α] : of_dual ⊥ = (⊤ : α) := rfl
1130-
@[simp] lemma of_dual_top [has_bot α] : of_dual ⊤ = (⊥ : α) := rfl
1131-
@[simp] lemma to_dual_bot [has_bot α] : to_dual (⊥ : α) = ⊤ := rfl
1132-
@[simp] lemma to_dual_top [has_top α] : to_dual (⊤ : α) = ⊥ := rfl
1133-
1134-
end order_dual
1135-
11361111
namespace prod
11371112
variables (α β)
11381113

0 commit comments

Comments
 (0)