forked from leanprover-community/mathlib4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefs.lean
More file actions
135 lines (93 loc) · 3.99 KB
/
Defs.lean
File metadata and controls
135 lines (93 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
module
public import Mathlib.Init
/-!
# Types that are empty
In this file we define a typeclass `IsEmpty`, which expresses that a type has no elements.
## Main declaration
* `IsEmpty`: a typeclass that expresses that a type is empty.
-/
@[expose] public section
universe u v
variable {α : Sort u} {β : Sort v}
/-- `IsEmpty α` expresses that `α` is empty. -/
class IsEmpty (α : Sort u) : Prop where
protected false : α → False
instance Empty.instIsEmpty : IsEmpty Empty :=
⟨Empty.elim⟩
instance PEmpty.instIsEmpty : IsEmpty PEmpty :=
⟨PEmpty.elim⟩
instance : IsEmpty False :=
⟨id⟩
instance Fin.isEmpty : IsEmpty (Fin 0) :=
⟨fun n ↦ Nat.not_lt_zero n.1 n.2⟩
instance Fin.isEmpty' : IsEmpty (Fin Nat.zero) :=
Fin.isEmpty
protected theorem Function.isEmpty [IsEmpty β] (f : α → β) : IsEmpty α :=
⟨fun x ↦ IsEmpty.false (f x)⟩
theorem Function.Surjective.isEmpty [IsEmpty α] {f : α → β} (hf : f.Surjective) : IsEmpty β :=
⟨fun y ↦ let ⟨x, _⟩ := hf y; IsEmpty.false x⟩
-- See note [instance argument order]
instance {p : α → Sort v} [∀ x, IsEmpty (p x)] [h : Nonempty α] : IsEmpty (∀ x, p x) :=
h.elim fun x ↦ Function.isEmpty fun f ↦ f x
instance PProd.isEmpty_left [IsEmpty α] : IsEmpty (PProd α β) :=
Function.isEmpty PProd.fst
instance PProd.isEmpty_right [IsEmpty β] : IsEmpty (PProd α β) :=
Function.isEmpty PProd.snd
instance Prod.isEmpty_left {α β} [IsEmpty α] : IsEmpty (α × β) :=
Function.isEmpty Prod.fst
instance Prod.isEmpty_right {α β} [IsEmpty β] : IsEmpty (α × β) :=
Function.isEmpty Prod.snd
instance Quot.instIsEmpty [IsEmpty α] {r : α → α → Prop} : IsEmpty (Quot r) :=
Function.Surjective.isEmpty Quot.exists_rep
instance Quotient.instIsEmpty [IsEmpty α] {s : Setoid α} : IsEmpty (Quotient s) :=
Quot.instIsEmpty
instance [IsEmpty α] [IsEmpty β] : IsEmpty (α ⊕' β) :=
⟨fun x ↦ PSum.rec IsEmpty.false IsEmpty.false x⟩
instance instIsEmptySum {α β} [IsEmpty α] [IsEmpty β] : IsEmpty (α ⊕ β) :=
⟨fun x ↦ Sum.rec IsEmpty.false IsEmpty.false x⟩
/-- subtypes of an empty type are empty -/
instance [IsEmpty α] (p : α → Prop) : IsEmpty (Subtype p) :=
⟨fun x ↦ IsEmpty.false x.1⟩
/-- subtypes by an all-false predicate are false. -/
theorem Subtype.isEmpty_of_false {p : α → Prop} (hp : ∀ a, ¬p a) : IsEmpty (Subtype p) :=
⟨fun x ↦ hp _ x.2⟩
/-- subtypes by false are false. -/
instance Subtype.isEmpty_false : IsEmpty { _a : α // False } :=
Subtype.isEmpty_of_false fun _ ↦ id
instance Sigma.isEmpty_left {α} [IsEmpty α] {E : α → Type v} : IsEmpty (Sigma E) :=
Function.isEmpty Sigma.fst
example [h : Nonempty α] [IsEmpty β] : IsEmpty (α → β) := by infer_instance
/-- Eliminate out of a type that `IsEmpty` (without using projection notation). -/
@[elab_as_elim]
def isEmptyElim [IsEmpty α] {p : α → Sort v} (a : α) : p a :=
(IsEmpty.false a).elim
theorem isEmpty_iff : IsEmpty α ↔ α → False :=
⟨@IsEmpty.false α, IsEmpty.mk⟩
namespace IsEmpty
open Function
/-- Eliminate out of a type that `IsEmpty` (using projection notation). -/
@[elab_as_elim]
protected def elim (_ : IsEmpty α) {p : α → Sort v} (a : α) : p a :=
isEmptyElim a
/-- Non-dependent version of `IsEmpty.elim`. Helpful if the elaborator cannot elaborate `h.elim a`
correctly. -/
protected def elim' (h : IsEmpty α) (a : α) : β :=
(h.false a).elim
protected theorem prop_iff {p : Prop} : IsEmpty p ↔ ¬p :=
isEmpty_iff
variable [IsEmpty α]
@[simp]
theorem forall_iff {p : α → Prop} : (∀ a, p a) ↔ True :=
iff_true_intro isEmptyElim
@[simp]
theorem exists_iff {p : α → Prop} : (∃ a, p a) ↔ False :=
iff_false_intro fun ⟨x, _⟩ ↦ IsEmpty.false x
-- see Note [lower instance priority]
instance (priority := 100) : Subsingleton α :=
⟨isEmptyElim⟩
end IsEmpty