|
| 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