Skip to content

Commit

Permalink
feat(Order/WithBot): add some lemmas (#6275)
Browse files Browse the repository at this point in the history
The `WithTop` version of the last 3 lemmas already exists.
  • Loading branch information
negiizhao committed Sep 25, 2023
1 parent fe2c350 commit b915222
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Mathlib/Data/Polynomial/Degree/Definitions.lean
Expand Up @@ -218,11 +218,11 @@ theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree
#align polynomial.degree_le_degree Polynomial.degree_le_degree

theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n :=
WithBot.unbot'_bot_le_iff
WithBot.unbot'_le_iff (fun _ ↦ bot_le)
#align polynomial.nat_degree_le_iff_degree_le Polynomial.natDegree_le_iff_degree_le

theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n :=
WithBot.unbot'_lt_iff <| degree_eq_bot.not.mpr hp
WithBot.unbot'_lt_iff (absurd · (degree_eq_bot.not.mpr hp))
#align polynomial.nat_degree_lt_iff_degree_lt Polynomial.natDegree_lt_iff_degree_lt

alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Order/GaloisConnection.lean
Expand Up @@ -961,7 +961,7 @@ def gci_Ici_sInf [CompleteSemilatticeInf α] :
coercion form a Galois insertion. -/
def WithBot.giUnbot'Bot [Preorder α] [OrderBot α] :
GaloisInsertion (WithBot.unbot' ⊥) (some : α → WithBot α) where
gc _ _ := WithBot.unbot'_bot_le_iff
gc _ _ := WithBot.unbot'_le_iff (fun _ ↦ bot_le)
le_l_u _ := le_rfl
choice o _ := o.unbot' ⊥
choice_eq _ _ := rfl
Expand Down
46 changes: 38 additions & 8 deletions Mathlib/Order/WithBot.lean
Expand Up @@ -227,6 +227,12 @@ theorem not_coe_le_bot (a : α) : ¬(a : WithBot α) ≤ ⊥ := fun h =>
Option.not_mem_none _ hb
#align with_bot.not_coe_le_bot WithBot.not_coe_le_bot

/-- There is a general version `le_bot_iff`, but this lemma does not require a `PartialOrder`. -/
@[simp]
protected theorem le_bot_iff : ∀ {a : WithBot α}, a ≤ ⊥ ↔ a = ⊥
| (a : α) => by simp [not_coe_le_bot _]
| ⊥ => by simp

theorem coe_le : ∀ {o : Option α}, b ∈ o → ((a : WithBot α) ≤ o ↔ a ≤ b)
| _, rfl => coe_le_coe
#align with_bot.coe_le WithBot.coe_le
Expand Down Expand Up @@ -394,16 +400,18 @@ theorem le_coe_unbot' [Preorder α] : ∀ (a : WithBot α) (b : α), a ≤ a.unb
| ⊥, _ => bot_le
#align with_bot.le_coe_unbot' WithBot.le_coe_unbot'

theorem unbot'_bot_le_iff [LE α] [OrderBot α] {a : WithBot α} {b : α} :
a.unbot' ⊥ ≤ b ↔ a ≤ b := by
cases a <;> simp [none_eq_bot, some_eq_coe]
#align with_bot.unbot'_bot_le_iff WithBot.unbot'_bot_le_iff
theorem unbot'_le_iff [LE α] {a : WithBot α} {b c : α} (h : a = ⊥ → b ≤ c) :
a.unbot' b ≤ c ↔ a ≤ c := by
cases a
· simpa using h rfl
· simp [some_eq_coe]
#align with_bot.unbot'_bot_le_iff WithBot.unbot'_le_iff

theorem unbot'_lt_iff [LT α] {a : WithBot α} {b c : α} (ha : a ≠ ⊥) : a.unbot' b < c ↔ a < c := by
theorem unbot'_lt_iff [LT α] {a : WithBot α} {b c : α} (h : a = ⊥ → b < c) :
a.unbot' b < c ↔ a < c := by
cases a
· exact (ha rfl).elim
· rw [some_eq_coe, unbot'_coe, coe_lt_coe]
#align with_bot.unbot'_lt_iff WithBot.unbot'_lt_iff
· simpa [bot_lt_coe] using h rfl
· simp [some_eq_coe]

instance semilatticeSup [SemilatticeSup α] : SemilatticeSup (WithBot α) :=
{ WithBot.partialOrder, @WithBot.orderBot α _ with
Expand Down Expand Up @@ -863,6 +871,12 @@ theorem not_top_le_coe (a : α) : ¬(⊤ : WithTop α) ≤ ↑a :=
WithBot.not_coe_le_bot (toDual a)
#align with_top.not_top_le_coe WithTop.not_top_le_coe

/-- There is a general version `top_le_iff`, but this lemma does not require a `PartialOrder`. -/
@[simp]
protected theorem top_le_iff : ∀ {a : WithTop α}, ⊤ ≤ a ↔ a = ⊤
| (a : α) => by simp [not_top_le_coe _]
| ⊤ => by simp

theorem le_coe : ∀ {o : Option α}, a ∈ o → (@LE.le (WithTop α) _ o b ↔ a ≤ b)
| _, rfl => coe_le_coe
#align with_top.le_coe WithTop.le_coe
Expand Down Expand Up @@ -1179,6 +1193,22 @@ theorem map_le_iff [Preorder α] [Preorder β] (f : α → β) (a b : WithTop α
simp [mono_iff]
#align with_top.map_le_iff WithTop.map_le_iff

theorem coe_untop'_le [Preorder α] : ∀ (a : WithTop α) (b : α), a.untop' b ≤ a
| (a : α), _ => le_rfl
| ⊤, _ => le_top

theorem le_untop'_iff [LE α] {a : WithTop α} {b c : α} (h : a = ⊤ → c ≤ b) :
c ≤ a.untop' b ↔ c ≤ a := by
cases a
· simpa using h rfl
· simp [some_eq_coe]

theorem lt_untop'_iff [LT α] {a : WithTop α} {b c : α} (h : a = ⊤ → c < b) :
c < a.untop' b ↔ c < a := by
cases a
· simpa [none_eq_top, coe_lt_top] using h rfl
· simp [some_eq_coe]

instance semilatticeInf [SemilatticeInf α] : SemilatticeInf (WithTop α) :=
{ WithTop.partialOrder with
inf := Option.liftOrGet (· ⊓ ·),
Expand Down

0 comments on commit b915222

Please sign in to comment.