|
7 | 7 |
|
8 | 8 | public import Mathlib.Logic.Function.Basic |
9 | 9 | public import Mathlib.Logic.Relator |
| 10 | +public import Mathlib.Tactic.Linter.DeprecatedModule |
10 | 11 |
|
11 | | -/-! |
12 | | -# Types that are empty |
13 | | -
|
14 | | -In this file we define a typeclass `IsEmpty`, which expresses that a type has no elements. |
15 | | -
|
16 | | -## Main declaration |
17 | | -
|
18 | | -* `IsEmpty`: a typeclass that expresses that a type is empty. |
19 | | --/ |
20 | | - |
21 | | -@[expose] public section |
22 | | - |
23 | | -variable {α β γ : Sort*} |
24 | | - |
25 | | -/-- `IsEmpty α` expresses that `α` is empty. -/ |
26 | | -class IsEmpty (α : Sort*) : Prop where |
27 | | - protected false : α → False |
28 | | - |
29 | | -instance Empty.instIsEmpty : IsEmpty Empty := |
30 | | - ⟨Empty.elim⟩ |
31 | | - |
32 | | -instance PEmpty.instIsEmpty : IsEmpty PEmpty := |
33 | | - ⟨PEmpty.elim⟩ |
34 | | - |
35 | | -instance : IsEmpty False := |
36 | | - ⟨id⟩ |
37 | | - |
38 | | -instance Fin.isEmpty : IsEmpty (Fin 0) := |
39 | | - ⟨fun n ↦ Nat.not_lt_zero n.1 n.2⟩ |
40 | | - |
41 | | -instance Fin.isEmpty' : IsEmpty (Fin Nat.zero) := |
42 | | - Fin.isEmpty |
43 | | - |
44 | | -protected theorem Function.isEmpty [IsEmpty β] (f : α → β) : IsEmpty α := |
45 | | - ⟨fun x ↦ IsEmpty.false (f x)⟩ |
46 | | - |
47 | | -theorem Function.Surjective.isEmpty [IsEmpty α] {f : α → β} (hf : f.Surjective) : IsEmpty β := |
48 | | - ⟨fun y ↦ let ⟨x, _⟩ := hf y; IsEmpty.false x⟩ |
49 | | - |
50 | | --- See note [instance argument order] |
51 | | -instance {p : α → Sort*} [∀ x, IsEmpty (p x)] [h : Nonempty α] : IsEmpty (∀ x, p x) := |
52 | | - h.elim fun x ↦ Function.isEmpty <| Function.eval x |
53 | | - |
54 | | -instance PProd.isEmpty_left [IsEmpty α] : IsEmpty (PProd α β) := |
55 | | - Function.isEmpty PProd.fst |
56 | | - |
57 | | -instance PProd.isEmpty_right [IsEmpty β] : IsEmpty (PProd α β) := |
58 | | - Function.isEmpty PProd.snd |
59 | | - |
60 | | -instance Prod.isEmpty_left {α β} [IsEmpty α] : IsEmpty (α × β) := |
61 | | - Function.isEmpty Prod.fst |
62 | | - |
63 | | -instance Prod.isEmpty_right {α β} [IsEmpty β] : IsEmpty (α × β) := |
64 | | - Function.isEmpty Prod.snd |
65 | | - |
66 | | -instance Quot.instIsEmpty {α : Sort*} [IsEmpty α] {r : α → α → Prop} : IsEmpty (Quot r) := |
67 | | - Function.Surjective.isEmpty Quot.exists_rep |
68 | | - |
69 | | -instance Quotient.instIsEmpty {α : Sort*} [IsEmpty α] {s : Setoid α} : IsEmpty (Quotient s) := |
70 | | - Quot.instIsEmpty |
71 | | - |
72 | | -instance [IsEmpty α] [IsEmpty β] : IsEmpty (α ⊕' β) := |
73 | | - ⟨fun x ↦ PSum.rec IsEmpty.false IsEmpty.false x⟩ |
74 | | - |
75 | | -instance instIsEmptySum {α β} [IsEmpty α] [IsEmpty β] : IsEmpty (α ⊕ β) := |
76 | | - ⟨fun x ↦ Sum.rec IsEmpty.false IsEmpty.false x⟩ |
77 | | - |
78 | | -/-- subtypes of an empty type are empty -/ |
79 | | -instance [IsEmpty α] (p : α → Prop) : IsEmpty (Subtype p) := |
80 | | - ⟨fun x ↦ IsEmpty.false x.1⟩ |
81 | | - |
82 | | -/-- subtypes by an all-false predicate are false. -/ |
83 | | -theorem Subtype.isEmpty_of_false {p : α → Prop} (hp : ∀ a, ¬p a) : IsEmpty (Subtype p) := |
84 | | - ⟨fun x ↦ hp _ x.2⟩ |
85 | | - |
86 | | -/-- subtypes by false are false. -/ |
87 | | -instance Subtype.isEmpty_false : IsEmpty { _a : α // False } := |
88 | | - Subtype.isEmpty_of_false fun _ ↦ id |
89 | | - |
90 | | -instance Sigma.isEmpty_left {α} [IsEmpty α] {E : α → Type*} : IsEmpty (Sigma E) := |
91 | | - Function.isEmpty Sigma.fst |
92 | | - |
93 | | -example [h : Nonempty α] [IsEmpty β] : IsEmpty (α → β) := by infer_instance |
94 | | - |
95 | | -/-- Eliminate out of a type that `IsEmpty` (without using projection notation). -/ |
96 | | -@[elab_as_elim] |
97 | | -def isEmptyElim [IsEmpty α] {p : α → Sort*} (a : α) : p a := |
98 | | - (IsEmpty.false a).elim |
99 | | - |
100 | | -theorem isEmpty_iff : IsEmpty α ↔ α → False := |
101 | | - ⟨@IsEmpty.false α, IsEmpty.mk⟩ |
102 | | - |
103 | | -namespace IsEmpty |
104 | | - |
105 | | -open Function |
106 | | - |
107 | | -universe u in |
108 | | -/-- Eliminate out of a type that `IsEmpty` (using projection notation). -/ |
109 | | -@[elab_as_elim] |
110 | | -protected def elim {α : Sort u} (_ : IsEmpty α) {p : α → Sort*} (a : α) : p a := |
111 | | - isEmptyElim a |
112 | | - |
113 | | -/-- Non-dependent version of `IsEmpty.elim`. Helpful if the elaborator cannot elaborate `h.elim a` |
114 | | -correctly. -/ |
115 | | -protected def elim' {β : Sort*} (h : IsEmpty α) (a : α) : β := |
116 | | - (h.false a).elim |
117 | | - |
118 | | -protected theorem prop_iff {p : Prop} : IsEmpty p ↔ ¬p := |
119 | | - isEmpty_iff |
120 | | - |
121 | | -variable [IsEmpty α] |
122 | | - |
123 | | -@[simp] |
124 | | -theorem forall_iff {p : α → Prop} : (∀ a, p a) ↔ True := |
125 | | - iff_true_intro isEmptyElim |
126 | | - |
127 | | -@[simp] |
128 | | -theorem exists_iff {p : α → Prop} : (∃ a, p a) ↔ False := |
129 | | - iff_false_intro fun ⟨x, _⟩ ↦ IsEmpty.false x |
130 | | - |
131 | | --- see Note [lower instance priority] |
132 | | -instance (priority := 100) : Subsingleton α := |
133 | | - ⟨isEmptyElim⟩ |
134 | | - |
135 | | -end IsEmpty |
136 | | - |
137 | | -@[simp, push] |
138 | | -theorem not_nonempty_iff : ¬Nonempty α ↔ IsEmpty α := |
139 | | - ⟨fun h ↦ ⟨fun x ↦ h ⟨x⟩⟩, fun h1 h2 ↦ h2.elim h1.elim⟩ |
140 | | - |
141 | | -@[simp, push] |
142 | | -theorem not_isEmpty_iff : ¬IsEmpty α ↔ Nonempty α := |
143 | | - not_iff_comm.mp not_nonempty_iff |
144 | | - |
145 | | -@[simp] |
146 | | -theorem isEmpty_Prop {p : Prop} : IsEmpty p ↔ ¬p := by |
147 | | - simp only [← not_nonempty_iff, nonempty_prop] |
148 | | - |
149 | | -@[simp] |
150 | | -theorem isEmpty_pi {π : α → Sort*} : IsEmpty (∀ a, π a) ↔ ∃ a, IsEmpty (π a) := by |
151 | | - simp only [← not_nonempty_iff, Classical.nonempty_pi, not_forall] |
152 | | - |
153 | | -theorem isEmpty_fun : IsEmpty (α → β) ↔ Nonempty α ∧ IsEmpty β := by |
154 | | - rw [isEmpty_pi, ← exists_true_iff_nonempty, ← exists_and_right, true_and] |
155 | | - |
156 | | -@[simp] |
157 | | -theorem nonempty_fun : Nonempty (α → β) ↔ IsEmpty α ∨ Nonempty β := |
158 | | - not_iff_not.mp <| by rw [not_or, not_nonempty_iff, not_nonempty_iff, isEmpty_fun, not_isEmpty_iff] |
159 | | - |
160 | | -@[simp] |
161 | | -theorem isEmpty_sigma {α} {E : α → Type*} : IsEmpty (Sigma E) ↔ ∀ a, IsEmpty (E a) := by |
162 | | - simp only [← not_nonempty_iff, nonempty_sigma, not_exists] |
163 | | - |
164 | | -@[simp] |
165 | | -theorem isEmpty_psigma {α} {E : α → Sort*} : IsEmpty (PSigma E) ↔ ∀ a, IsEmpty (E a) := by |
166 | | - simp only [← not_nonempty_iff, nonempty_psigma, not_exists] |
167 | | - |
168 | | -theorem isEmpty_subtype (p : α → Prop) : IsEmpty (Subtype p) ↔ ∀ x, ¬p x := by |
169 | | - simp only [← not_nonempty_iff, nonempty_subtype, not_exists] |
170 | | - |
171 | | -@[simp] |
172 | | -theorem isEmpty_prod {α β : Type*} : IsEmpty (α × β) ↔ IsEmpty α ∨ IsEmpty β := by |
173 | | - simp only [← not_nonempty_iff, nonempty_prod, not_and_or] |
174 | | - |
175 | | -@[simp] |
176 | | -theorem isEmpty_pprod : IsEmpty (PProd α β) ↔ IsEmpty α ∨ IsEmpty β := by |
177 | | - simp only [← not_nonempty_iff, nonempty_pprod, not_and_or] |
178 | | - |
179 | | -@[simp] |
180 | | -theorem isEmpty_sum {α β} : IsEmpty (α ⊕ β) ↔ IsEmpty α ∧ IsEmpty β := by |
181 | | - simp only [← not_nonempty_iff, nonempty_sum, not_or] |
182 | | - |
183 | | -@[simp] |
184 | | -theorem isEmpty_psum {α β} : IsEmpty (α ⊕' β) ↔ IsEmpty α ∧ IsEmpty β := by |
185 | | - simp only [← not_nonempty_iff, nonempty_psum, not_or] |
186 | | - |
187 | | -@[simp] |
188 | | -theorem isEmpty_ulift {α} : IsEmpty (ULift α) ↔ IsEmpty α := by |
189 | | - simp only [← not_nonempty_iff, nonempty_ulift] |
190 | | - |
191 | | -@[simp] |
192 | | -theorem isEmpty_plift {α} : IsEmpty (PLift α) ↔ IsEmpty α := by |
193 | | - simp only [← not_nonempty_iff, nonempty_plift] |
194 | | - |
195 | | -theorem wellFounded_of_isEmpty {α} [IsEmpty α] (r : α → α → Prop) : WellFounded r := |
196 | | - ⟨isEmptyElim⟩ |
197 | | - |
198 | | -variable (α) |
199 | | - |
200 | | -theorem isEmpty_or_nonempty : IsEmpty α ∨ Nonempty α := |
201 | | - (em <| IsEmpty α).elim Or.inl <| Or.inr ∘ not_isEmpty_iff.mp |
202 | | - |
203 | | -@[simp] |
204 | | -theorem not_isEmpty_of_nonempty [h : Nonempty α] : ¬IsEmpty α := |
205 | | - not_isEmpty_iff.mpr h |
206 | | - |
207 | | -variable {α} |
208 | | - |
209 | | -theorem Function.extend_of_isEmpty [IsEmpty α] (f : α → β) (g : α → γ) (h : β → γ) : |
210 | | - Function.extend f g h = h := |
211 | | - funext fun _ ↦ (Function.extend_apply' _ _ _) fun ⟨a, _⟩ ↦ isEmptyElim a |
212 | | - |
213 | | -open Relator |
214 | | - |
215 | | -variable {α β : Type*} (R : α → β → Prop) |
216 | | - |
217 | | -@[simp] |
218 | | -theorem leftTotal_empty [IsEmpty α] : LeftTotal R := by |
219 | | - simp only [LeftTotal, IsEmpty.forall_iff] |
220 | | - |
221 | | -theorem leftTotal_iff_isEmpty_left [IsEmpty β] : LeftTotal R ↔ IsEmpty α := by |
222 | | - simp only [LeftTotal, IsEmpty.exists_iff, isEmpty_iff] |
223 | | - |
224 | | -@[simp] |
225 | | -theorem rightTotal_empty [IsEmpty β] : RightTotal R := by |
226 | | - simp only [RightTotal, IsEmpty.forall_iff] |
227 | | - |
228 | | -theorem rightTotal_iff_isEmpty_right [IsEmpty α] : RightTotal R ↔ IsEmpty β := by |
229 | | - simp only [RightTotal, IsEmpty.exists_iff, isEmpty_iff] |
230 | | - |
231 | | -@[simp] |
232 | | -theorem biTotal_empty [IsEmpty α] [IsEmpty β] : BiTotal R := |
233 | | - ⟨leftTotal_empty R, rightTotal_empty R⟩ |
234 | | - |
235 | | -theorem biTotal_iff_isEmpty_right [IsEmpty α] : BiTotal R ↔ IsEmpty β := by |
236 | | - simp only [BiTotal, leftTotal_empty, rightTotal_iff_isEmpty_right, true_and] |
237 | | - |
238 | | -theorem biTotal_iff_isEmpty_left [IsEmpty β] : BiTotal R ↔ IsEmpty α := by |
239 | | - simp only [BiTotal, leftTotal_iff_isEmpty_left, rightTotal_empty, and_true] |
240 | | - |
241 | | -theorem Function.Surjective.of_isEmpty [IsEmpty β] (f : α → β) : f.Surjective := IsEmpty.elim ‹_› |
242 | | - |
243 | | -theorem Function.surjective_iff_isEmpty [IsEmpty α] (f : α → β) : f.Surjective ↔ IsEmpty β := |
244 | | - ⟨Surjective.isEmpty, fun _ ↦ .of_isEmpty f⟩ |
245 | | - |
246 | | -theorem Function.Bijective.of_isEmpty (f : α → β) [IsEmpty β] : f.Bijective := |
247 | | - have := f.isEmpty |
248 | | - ⟨injective_of_subsingleton f, .of_isEmpty f⟩ |
249 | | - |
250 | | -theorem Function.not_surjective_of_isEmpty_of_nonempty [IsEmpty α] [Nonempty β] (f : α → β) : |
251 | | - ¬f.Surjective := |
252 | | - (not_isEmpty_of_nonempty β ·.isEmpty) |
| 12 | +deprecated_module "import Mathlib.Logic.IsEmpty.Basic instead" (since := "2026-02-11") |
0 commit comments