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

Commit 80dc445

Browse files
committed
refactor(order/bounded_lattice): generalize le on with_{top,bot} (#10085)
Before, some lemmas assumed `preorder` even when they were true for just the underlying `le`. In the case of `with_bot`, the missing underlying `has_le` instance is defined. For both `with_{top,bot}`, a few lemmas are generalized accordingly.
1 parent 658a3d7 commit 80dc445

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/data/nat/cast.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ begin
336336
end
337337

338338
lemma one_le_iff_pos {n : with_top ℕ} : 1 ≤ n ↔ 0 < n :=
339-
λ h, (coe_lt_coe.2 zero_lt_one).trans_le h,
339+
lt_of_lt_of_le (coe_lt_coe.mpr zero_lt_one),
340340
λ h, by simpa only [zero_add] using add_one_le_of_lt h⟩
341341

342342
@[elab_as_eliminator]

src/order/bounded_lattice.lean

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ by { cases x, simpa using h, refl, }
473473
@[simp] lemma unbot_coe (x : α) (h : (x : with_bot α) ≠ ⊥ := coe_ne_bot _) :
474474
(x : with_bot α).unbot h = x := rfl
475475

476+
@[priority 10]
477+
instance has_le [has_le α] : has_le (with_bot α) :=
478+
{ le := λ o₁ o₂ : option α, ∀ a ∈ o₁, ∃ b ∈ o₂, a ≤ b }
479+
476480
@[priority 10]
477481
instance has_lt [has_lt α] : has_lt (with_bot α) :=
478482
{ lt := λ o₁ o₂ : option α, ∃ b ∈ o₂, ∀ a ∈ o₁, a < b }
@@ -493,10 +497,10 @@ instance : can_lift (with_bot α) α :=
493497
prf := λ x hx, ⟨option.get $ option.ne_none_iff_is_some.1 hx, option.some_get _⟩ }
494498

495499
instance [preorder α] : preorder (with_bot α) :=
496-
{ le := λ o₁ o₂ : option α, ∀ a ∈ o₁, ∃ b ∈ o₂, a ≤ b,
500+
{ le := (≤),
497501
lt := (<),
498502
lt_iff_le_not_le := by intros; cases a; cases b;
499-
simp [lt_iff_le_not_le]; simp [(<)];
503+
simp [lt_iff_le_not_le]; simp [(≤), (<)];
500504
split; refl,
501505
le_refl := λ o a ha, ⟨a, ha, le_refl _⟩,
502506
le_trans := λ o₁ o₂ o₃ h₁ h₂ a ha,
@@ -518,20 +522,20 @@ instance order_bot [partial_order α] : order_bot (with_bot α) :=
518522
{ bot_le := λ a a' h, option.no_confusion h,
519523
..with_bot.partial_order, ..with_bot.has_bot }
520524

521-
@[simp, norm_cast] theorem coe_le_coe [preorder α] {a b : α} :
525+
@[simp, norm_cast] theorem coe_le_coe [has_le α] {a b : α} :
522526
(a : with_bot α) ≤ b ↔ a ≤ b :=
523527
⟨λ h, by rcases h a rfl with ⟨_, ⟨⟩, h⟩; exact h,
524528
λ h a' e, option.some_inj.1 e ▸ ⟨b, rfl, h⟩⟩
525529

526-
@[simp] theorem some_le_some [preorder α] {a b : α} :
530+
@[simp] theorem some_le_some [has_le α] {a b : α} :
527531
@has_le.le (with_bot α) _ (some a) (some b) ↔ a ≤ b := coe_le_coe
528532

529-
theorem coe_le [preorder α] {a b : α} :
533+
theorem coe_le [has_le α] {a b : α} :
530534
∀ {o : option α}, b ∈ o → ((a : with_bot α) ≤ o ↔ a ≤ b)
531535
| _ rfl := coe_le_coe
532536

533537
@[norm_cast]
534-
lemma coe_lt_coe [preorder α] {a b : α} : (a : with_bot α) < b ↔ a < b := some_lt_some
538+
lemma coe_lt_coe [has_lt α] {a b : α} : (a : with_bot α) < b ↔ a < b := some_lt_some
535539

536540
lemma le_coe_get_or_else [preorder α] : ∀ (a : with_bot α) (b : α), a ≤ a.get_or_else b
537541
| (some a) b := le_refl a
@@ -543,7 +547,7 @@ lemma get_or_else_bot_le_iff [order_bot α] {a : with_bot α} {b : α} :
543547
a.get_or_else ⊥ ≤ b ↔ a ≤ b :=
544548
by cases a; simp [none_eq_bot, some_eq_coe]
545549

546-
instance decidable_le [preorder α] [@decidable_rel α (≤)] : @decidable_rel (with_bot α) (≤)
550+
instance decidable_le [has_le α] [@decidable_rel α (≤)] : @decidable_rel (with_bot α) (≤)
547551
| none x := is_true $ λ a h, option.no_confusion h
548552
| (some x) (some y) :=
549553
if h : x ≤ y
@@ -756,12 +760,12 @@ instance order_top [partial_order α] : order_top (with_top α) :=
756760
{ le_top := λ a a' h, option.no_confusion h,
757761
..with_top.partial_order, .. with_top.has_top }
758762

759-
@[simp, norm_cast] theorem coe_le_coe [preorder α] {a b : α} :
763+
@[simp, norm_cast] theorem coe_le_coe [has_le α] {a b : α} :
760764
(a : with_top α) ≤ b ↔ a ≤ b :=
761765
⟨λ h, by rcases h b rfl with ⟨_, ⟨⟩, h⟩; exact h,
762766
λ h a' e, option.some_inj.1 e ▸ ⟨a, rfl, h⟩⟩
763767

764-
theorem le_coe [preorder α] {a b : α} :
768+
theorem le_coe [has_le α] {a b : α} :
765769
∀ {o : option α}, a ∈ o →
766770
(@has_le.le (with_top α) _ o b ↔ a ≤ b)
767771
| _ rfl := coe_le_coe
@@ -779,9 +783,9 @@ theorem lt_iff_exists_coe [partial_order α] : ∀{a b : with_top α}, a < b ↔
779783
| none b := by simp [none_eq_top]
780784

781785
@[norm_cast]
782-
lemma coe_lt_coe [preorder α] {a b : α} : (a : with_top α) < b ↔ a < b := some_lt_some
786+
lemma coe_lt_coe [has_lt α] {a b : α} : (a : with_top α) < b ↔ a < b := some_lt_some
783787

784-
lemma coe_lt_top [preorder α] (a : α) : (a : with_top α) < ⊤ := some_lt_none a
788+
lemma coe_lt_top [has_lt α] (a : α) : (a : with_top α) < ⊤ := some_lt_none a
785789

786790
theorem coe_lt_iff [preorder α] {a : α} : ∀{x : with_top α}, ↑a < x ↔ (∀b:α, x = ↑b → a < b)
787791
| (some b) := by simp [some_eq_coe, coe_eq_coe, coe_lt_coe]
@@ -790,7 +794,7 @@ theorem coe_lt_iff [preorder α] {a : α} : ∀{x : with_top α}, ↑a < x ↔ (
790794
lemma not_top_le_coe [preorder α] (a : α) : ¬ (⊤:with_top α) ≤ ↑a :=
791795
λ h, (lt_irrefl ⊤ (lt_of_le_of_lt h (coe_lt_top a))).elim
792796

793-
instance decidable_le [preorder α] [@decidable_rel α (≤)] : @decidable_rel (with_top α) (≤) :=
797+
instance decidable_le [has_le α] [@decidable_rel α (≤)] : @decidable_rel (with_top α) (≤) :=
794798
λ x y, @with_bot.decidable_le (order_dual α) _ _ y x
795799

796800
instance decidable_lt [has_lt α] [@decidable_rel α (<)] : @decidable_rel (with_top α) (<) :=

0 commit comments

Comments
 (0)