Skip to content

Commit 3cb7427

Browse files
committed
feat(Order): WithBotTop and the extended integers (leanprover-community#33876)
This files defines an abbreviation `WithBotTop ι` for `WithBot (WithTop ι)`. We also introduce an abbreviation `EInt` for `WithBotTop ℤ`. Kevin Buzzard is made a coauthor of the file because it is very similar to `Data.EReal.Basic`.
1 parent a91e88c commit 3cb7427

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5753,6 +5753,7 @@ public import Mathlib.Order.WellFounded
57535753
public import Mathlib.Order.WellFoundedSet
57545754
public import Mathlib.Order.WellQuasiOrder
57555755
public import Mathlib.Order.WithBot
5756+
public import Mathlib.Order.WithBotTop
57565757
public import Mathlib.Order.Zorn
57575758
public import Mathlib.Order.ZornAtoms
57585759
public import Mathlib.Probability.BorelCantelli

Mathlib/Order/WithBotTop.lean

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/-
2+
Copyright (c) 2025 Joël Riou. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Joël Riou, Kevin Buzzard
5+
-/
6+
module
7+
8+
public import Mathlib.Order.WithBot
9+
10+
/-!
11+
# Adding both `⊥` and `⊤` to a type
12+
13+
This files defines an abbreviation `WithBotTop ι` for `WithBot (WithTop ι)`.
14+
We also introduce an abbreviation `EInt` for `WithBotTop ℤ`.
15+
-/
16+
17+
@[expose] public section
18+
19+
variable {ι : Type*}
20+
21+
variable (ι) in
22+
/-- The type obtained by adding both `⊥` and `⊤` to a type. -/
23+
@[to_dual /-- The type obtained by adding both `⊤` and `⊥` to a type. -/]
24+
abbrev WithBotTop := WithBot (WithTop ι)
25+
26+
/-- The canonical inclusion `ι → WithBotTop ι`. Registered as a coercion. -/
27+
def WithBotTop.coe : ι → WithBotTop ι :=
28+
WithBot.some ∘ WithTop.some
29+
30+
namespace WithBotTop
31+
32+
instance : Coe ι (WithBotTop ι) := ⟨WithBotTop.coe⟩
33+
34+
theorem coe_injective : Function.Injective (WithBotTop.coe : ι → _) := by rintro _ _ ⟨⟩; rfl
35+
36+
@[simp] lemma coe_ne_bot (a : ι) : (a : WithBotTop ι) ≠ ⊥ := by rintro ⟨⟩
37+
@[simp] lemma coe_ne_top (a : ι) : (a : WithBotTop ι) ≠ ⊤ := by rintro ⟨⟩
38+
@[simp] lemma top_ne_bot : (⊤ : WithBotTop ι) ≠ ⊥ := by rintro ⟨⟩
39+
40+
section
41+
42+
variable {motive : (WithBotTop ι) → Sort*}
43+
(bot : motive ⊥) (coe : ∀ a : ι, motive a) (top : motive ⊤)
44+
45+
/-- A recursor for `WithBotTop` in terms of the coercion. -/
46+
@[elab_as_elim]
47+
protected def rec : ∀ a, motive a
48+
| ⊥ => bot
49+
| (a : ι) => coe a
50+
| ⊤ => top
51+
52+
@[simp] lemma rec_bot : WithBotTop.rec (motive := motive) bot coe top ⊥ = bot := rfl
53+
@[simp] lemma rec_coe (a : ι) : WithBotTop.rec (motive := motive) bot coe top a = coe a := rfl
54+
@[simp] lemma rec_top : WithBotTop.rec (motive := motive) bot coe top ⊤ = top := rfl
55+
56+
end
57+
58+
@[simp]
59+
lemma coe_le_coe [LE ι] {a b : ι} :
60+
(a : WithBotTop ι) ≤ b ↔ a ≤ b := by
61+
rw [← WithTop.coe_le_coe (α := ι)]
62+
exact WithBot.coe_le_coe
63+
64+
@[simp]
65+
lemma coe_lt_coe [LT ι] {a b : ι} :
66+
(a : WithBotTop ι) < b ↔ a < b := by
67+
rw [← WithTop.coe_lt_coe (α := ι)]
68+
exact WithBot.coe_lt_coe
69+
70+
@[simp]
71+
theorem coe_strictMono [Preorder ι] : StrictMono (WithBotTop.coe : ι → _) :=
72+
WithBot.coe_strictMono.comp WithTop.coe_strictMono
73+
74+
lemma coe_monotone [Preorder ι] :
75+
Monotone (WithBotTop.coe : ι → _) :=
76+
fun _ _ _ ↦ by simpa
77+
78+
end WithBotTop
79+
80+
/-- The type of extended integers `[-∞, ∞]`, constructed as `WithBot (WithTop ℤ)`. -/
81+
abbrev EInt := WithBotTop ℤ

0 commit comments

Comments
 (0)