Debian Codegraph @

src/Relation/Unary/Properties.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties of constructions over unary relations
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Relation.Unary.Properties where
10
11 open import Data.Product.Base as Product using (_×_; _,_; swap; proj₁; zip′)
12 open import Data.Sum.Base using (inj₁; inj₂)
13 open import Data.Unit.Base using (tt)
14 open import Function.Base using (id; _$_; _∘_; _∘₂_)
15 open import Level using (Level)
16 open import Relation.Binary.Core as Binary
17 open import Relation.Binary.Definitions
18 hiding (Decidable; Universal; Irrelevant; Empty)
19 open import Relation.Binary.PropositionalEquality.Core using (refl; _≗_)
20 open import Relation.Nullary.Decidable as Dec
21 using (yes; no; _⊎-dec_; _×-dec_; ¬?; map′; does)
22 open import Relation.Nullary.Negation.Core using (¬_)
23 open import Relation.Unary
24
25 private
26 variable
27 a b ℓ ℓ₁ ℓ₂ ℓ₃ : Level
28 A : Set a
29 B : Set b
30
31 ------------------------------------------------------------------------
32 -- The empty set
33
34 ∅? : Decidable {A = A} ∅
35 ∅? _ = no λ()
36
37 ∅-Empty : Empty {A = A} ∅
38 ∅-Empty x ()
39
40 ∁∅-Universal : Universal {A = A} (∁ ∅)
41 ∁∅-Universal = λ x x∈∅ → x∈∅
42
43 ------------------------------------------------------------------------
44 -- The universe
45
46 U? : Decidable {A = A} U
47 U? _ = yes tt
48
49 U-Universal : Universal {A = A} U
50 U-Universal = λ _ → _
51
52 ∁U-Empty : Empty {A = A} (∁ U)
53 ∁U-Empty = λ x x∈∁U → x∈∁U _
54
55 ------------------------------------------------------------------------
56 -- Subset properties
57
58 ∅-⊆ : (P : Pred A ℓ) → ∅ ⊆ P
59 ∅-⊆ P ()
60
61 ⊆-U : (P : Pred A ℓ) → P ⊆ U
62 ⊆-U P _ = _
63
64 ⊆-refl : Reflexive {A = Pred A ℓ} _⊆_
65 ⊆-refl x∈P = x∈P
66
67 ⊆-reflexive : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _≐_ _⊆_
68 ⊆-reflexive (P⊆Q , Q⊆P) = P⊆Q
69
70 ⊆-trans : Trans {A = Pred A ℓ₁} {B = Pred A ℓ₂} {C = Pred A ℓ₃} _⊆_ _⊆_ _⊆_
71 ⊆-trans P⊆Q Q⊆R x∈P = Q⊆R (P⊆Q x∈P)
72
73 ⊆-antisym : Antisymmetric {A = Pred A ℓ} _≐_ _⊆_
74 ⊆-antisym = _,_
75
76 ⊆-min : Min {B = Pred A ℓ} _⊆_ ∅
77 ⊆-min = ∅-⊆
78
79 ⊆-max : Max {A = Pred A ℓ} _⊆_ U
80 ⊆-max = ⊆-U
81
82 ⊂⇒⊆ : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊂_ _⊆_
83 ⊂⇒⊆ = proj₁
84
85 ⊂-trans : Trans {A = Pred A ℓ₁} {B = Pred A ℓ₂} {C = Pred A ℓ₃} _⊂_ _⊂_ _⊂_
86 ⊂-trans (P⊆Q , Q⊈P) (Q⊆R , R⊈Q) = (λ x∈P → Q⊆R (P⊆Q x∈P)) , (λ R⊆P → R⊈Q (λ x∈R → P⊆Q (R⊆P x∈R)))
87
88 ⊂-⊆-trans : Trans {A = Pred A ℓ₁} {B = Pred A ℓ₂} {C = Pred A ℓ₃} _⊂_ _⊆_ _⊂_
89 ⊂-⊆-trans (P⊆Q , Q⊈P) Q⊆R = (λ x∈P → Q⊆R (P⊆Q x∈P)) , (λ R⊆P → Q⊈P (λ x∈Q → R⊆P (Q⊆R x∈Q)))
90
91 ⊆-⊂-trans : Trans {A = Pred A ℓ₁} {B = Pred A ℓ₂} {C = Pred A ℓ₃} _⊆_ _⊂_ _⊂_
92 ⊆-⊂-trans P⊆Q (Q⊆R , R⊈Q) = (λ x∈P → Q⊆R (P⊆Q x∈P)) , (λ R⊆P → R⊈Q (λ R⊆Q → P⊆Q (R⊆P R⊆Q)))
93
94 ⊂-respʳ-≐ : _Respectsʳ_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊂_ _≐_
95 ⊂-respʳ-≐ (Q⊆R , _) P⊂Q = ⊂-⊆-trans P⊂Q Q⊆R
96
97 ⊂-respˡ-≐ : _Respectsˡ_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊂_ _≐_
98 ⊂-respˡ-≐ (_ , R⊆Q) P⊂Q = ⊆-⊂-trans R⊆Q P⊂Q
99
100 ⊂-resp-≐ : _Respects₂_ {A = Pred A ℓ} _⊂_ _≐_
101 ⊂-resp-≐ = ⊂-respʳ-≐ , ⊂-respˡ-≐
102
103 ⊂-irrefl : Irreflexive {A = Pred A ℓ₁} {B = Pred A ℓ₂} _≐_ _⊂_
104 ⊂-irrefl (_ , Q⊆P) (_ , Q⊈P) = Q⊈P Q⊆P
105
106 ⊂-antisym : Antisymmetric {A = Pred A ℓ} _≐_ _⊂_
107 ⊂-antisym (P⊆Q , _) (Q⊆P , _) = ⊆-antisym P⊆Q Q⊆P
108
109 ⊂-asym : Asymmetric {A = Pred A ℓ} _⊂_
110 ⊂-asym (_ , Q⊈P) = Q⊈P ∘ proj₁
111
112 ∅-⊆′ : (P : Pred A ℓ) → ∅ ⊆′ P
113 ∅-⊆′ _ _ = λ ()
114
115 ⊆′-U : (P : Pred A ℓ) → P ⊆′ U
116 ⊆′-U _ _ _ = _
117
118 ⊆′-refl : Reflexive {A = Pred A ℓ} _⊆′_
119 ⊆′-refl x x∈P = x∈P
120
121 ⊆′-reflexive : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _≐′_ _⊆′_
122 ⊆′-reflexive (P⊆Q , Q⊆P) = P⊆Q
123
124 ⊆′-trans : Trans {A = Pred A ℓ₁} {B = Pred A ℓ₂} {C = Pred A ℓ₃} _⊆′_ _⊆′_ _⊆′_
125 ⊆′-trans P⊆Q Q⊆R x x∈P = Q⊆R x (P⊆Q x x∈P)
126
127 ⊆′-antisym : Antisymmetric {A = Pred A ℓ} _≐′_ _⊆′_
128 ⊆′-antisym = _,_
129
130 ⊆′-min : Min {B = Pred A ℓ} _⊆′_ ∅
131 ⊆′-min = ∅-⊆′
132
133 ⊆′-max : Max {A = Pred A ℓ} _⊆′_ U
134 ⊆′-max = ⊆′-U
135
136 ⊂′⇒⊆′ : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊂′_ _⊆′_
137 ⊂′⇒⊆′ = proj₁
138
139 ⊂′-trans : Trans {A = Pred A ℓ₁} {B = Pred A ℓ₂} {C = Pred A ℓ₃} _⊂′_ _⊂′_ _⊂′_
140 ⊂′-trans (P⊆Q , Q⊈P) (Q⊆R , R⊈Q) = ⊆′-trans P⊆Q Q⊆R , λ R⊆P → R⊈Q (⊆′-trans R⊆P P⊆Q)
141
142 ⊂′-⊆′-trans : Trans {A = Pred A ℓ₁} {B = Pred A ℓ₂} {C = Pred A ℓ₃} _⊂′_ _⊆′_ _⊂′_
143 ⊂′-⊆′-trans (P⊆Q , Q⊈P) Q⊆R = ⊆′-trans P⊆Q Q⊆R , λ R⊆P → Q⊈P (⊆′-trans Q⊆R R⊆P)
144
145 ⊆′-⊂′-trans : Trans {A = Pred A ℓ₁} {B = Pred A ℓ₂} {C = Pred A ℓ₃} _⊆′_ _⊂′_ _⊂′_
146 ⊆′-⊂′-trans P⊆Q (Q⊆R , R⊈Q) = ⊆′-trans P⊆Q Q⊆R , λ R⊆P → R⊈Q (⊆′-trans R⊆P P⊆Q)
147
148 ⊂′-respʳ-≐′ : _Respectsʳ_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊂′_ _≐′_
149 ⊂′-respʳ-≐′ (Q⊆R , _) P⊂Q = ⊂′-⊆′-trans P⊂Q Q⊆R
150
151 ⊂′-respˡ-≐′ : _Respectsˡ_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊂′_ _≐′_
152 ⊂′-respˡ-≐′ (_ , R⊆Q) P⊂Q = ⊆′-⊂′-trans R⊆Q P⊂Q
153
154 ⊂′-resp-≐′ : _Respects₂_ {A = Pred A ℓ₁} _⊂′_ _≐′_
155 ⊂′-resp-≐′ = ⊂′-respʳ-≐′ , ⊂′-respˡ-≐′
156
157 ⊂′-irrefl : Irreflexive {A = Pred A ℓ₁} {B = Pred A ℓ₂} _≐′_ _⊂′_
158 ⊂′-irrefl (_ , Q⊆P) (_ , Q⊈P) = Q⊈P Q⊆P
159
160 ⊂′-antisym : Antisymmetric {A = Pred A ℓ} _≐′_ _⊂′_
161 ⊂′-antisym (P⊆Q , _) (Q⊆P , _) = ⊆′-antisym P⊆Q Q⊆P
162
163 ⊆⇒⊆′ : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊆_ _⊆′_
164 ⊆⇒⊆′ P⊆Q _ x∈P = P⊆Q x∈P
165
166 ⊆′⇒⊆ : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊆′_ _⊆_
167 ⊆′⇒⊆ P⊆Q x∈P = P⊆Q _ x∈P
168
169 ⊂⇒⊂′ : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊂_ _⊂′_
170 ⊂⇒⊂′ = Product.map ⊆⇒⊆′ (_∘ ⊆′⇒⊆)
171
172 ⊂′⇒⊂ : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊂′_ _⊂_
173 ⊂′⇒⊂ = Product.map ⊆′⇒⊆ (_∘ ⊆⇒⊆′)
174
175 ------------------------------------------------------------------------
176 -- Equality properties
177
178 ≐-refl : Reflexive {A = Pred A ℓ} _≐_
179 ≐-refl = id , id
180
181 ≐-sym : Sym {A = Pred A ℓ₁} {B = Pred A ℓ₂} _≐_ _≐_
182 ≐-sym = swap
183
184 ≐-trans : Trans {A = Pred A ℓ₁} {B = Pred A ℓ₂} {C = Pred A ℓ₃} _≐_ _≐_ _≐_
185 ≐-trans = zip′ (λ P⊆Q Q⊆R x∈P → Q⊆R (P⊆Q x∈P)) (λ Q⊆P R⊆Q x∈R → Q⊆P (R⊆Q x∈R))
186
187 ≐′-refl : Reflexive {A = Pred A ℓ} _≐′_
188 ≐′-refl = (λ _ → id) , (λ _ → id)
189
190 ≐′-sym : Sym {A = Pred A ℓ₁} {B = Pred A ℓ₂} _≐′_ _≐′_
191 ≐′-sym = swap
192
193 ≐′-trans : Trans {A = Pred A ℓ₁} {B = Pred A ℓ₂} {C = Pred A ℓ₃} _≐′_ _≐′_ _≐′_
194 ≐′-trans = zip′ (λ P⊆Q Q⊆R x x∈P → Q⊆R x (P⊆Q x x∈P)) λ Q⊆P R⊆Q x x∈R → Q⊆P x (R⊆Q x x∈R)
195
196 ≐⇒≐′ : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _≐_ _≐′_
197 ≐⇒≐′ = Product.map ⊆⇒⊆′ ⊆⇒⊆′
198
199 ≐′⇒≐ : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _≐′_ _≐_
200 ≐′⇒≐ = Product.map ⊆′⇒⊆ ⊆′⇒⊆
201
202 ------------------------------------------------------------------------
203 -- Between/Disjoint properties
204
205 ≬-symmetric : Sym {A = Pred A ℓ₁} {B = Pred A ℓ₂} _≬_ _≬_
206 ≬-symmetric = Product.map₂ swap
207
208 ⊥-symmetric : Sym {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊥_ _⊥_
209 ⊥-symmetric = _∘ swap
210
211 ≬-sym : Symmetric {A = Pred A ℓ₁} _≬_
212 ≬-sym = ≬-symmetric
213
214 ⊥-sym : Symmetric {A = Pred A ℓ₁} _⊥_
215 ⊥-sym = ⊥-symmetric
216
217 ≬⇒¬⊥ : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _≬_ (¬_ ∘₂ _⊥_)
218 ≬⇒¬⊥ P≬Q ¬P⊥Q = ¬P⊥Q (Product.proj₂ P≬Q)
219
220 ⊥⇒¬≬ : Binary._⇒_ {A = Pred A ℓ₁} {B = Pred A ℓ₂} _⊥_ (¬_ ∘₂ _≬_)
221 ⊥⇒¬≬ P⊥Q = P⊥Q ∘ Product.proj₂
222
223 ------------------------------------------------------------------------
224 -- Decidability properties
225
226 map : {P : Pred A ℓ₁} {Q : Pred A ℓ₂} →
227 P ≐ Q → Decidable P → Decidable Q
228 map (P⊆Q , Q⊆P) P? x = map′ P⊆Q Q⊆P (P? x)
229
230 ∁? : {P : Pred A ℓ} → Decidable P → Decidable (∁ P)
231 ∁? P? x = ¬? (P? x)
232
233 infix 2 _×?_ _⊙?_
234 infix 10 _~?
235 infixr 1 _⊎?_
236 infixr 7 _∩?_
237 infixr 6 _∪?_
238
239 _∪?_ : {P : Pred A ℓ₁} {Q : Pred A ℓ₂} →
240 Decidable P → Decidable Q → Decidable (P ∪ Q)
241 _∪?_ P? Q? x = (P? x) ⊎-dec (Q? x)
242
243 _∩?_ : {P : Pred A ℓ₁} {Q : Pred A ℓ₂} →
244 Decidable P → Decidable Q → Decidable (P ∩ Q)
245 _∩?_ P? Q? x = (P? x) ×-dec (Q? x)
246
247 _×?_ : {P : Pred A ℓ₁} {Q : Pred B ℓ₂} →
248 Decidable P → Decidable Q → Decidable (P ⟨×⟩ Q)
249 _×?_ P? Q? (a , b) = (P? a) ×-dec (Q? b)
250
251 _⊙?_ : {P : Pred A ℓ₁} {Q : Pred B ℓ₂} →
252 Decidable P → Decidable Q → Decidable (P ⟨⊙⟩ Q)
253 _⊙?_ P? Q? (a , b) = (P? a) ⊎-dec (Q? b)
254
255 _⊎?_ : {P : Pred A ℓ} {Q : Pred B ℓ} →
256 Decidable P → Decidable Q → Decidable (P ⟨⊎⟩ Q)
257 _⊎?_ P? Q? (inj₁ a) = P? a
258 _⊎?_ P? Q? (inj₂ b) = Q? b
259
260 _~? : {P : Pred (A × B) ℓ} → Decidable P → Decidable (P ~)
261 _~? P? = P? ∘ swap
262
263 does-≡ : {P : Pred A ℓ} → (P? P?′ : Decidable P) →
264 does ∘ P? ≗ does ∘ P?′
265 does-≡ P? P?′ x = Dec.does-≡ (P? x) (P?′ x)
266
267 does-≐ : {P : Pred A ℓ₁} {Q : Pred A ℓ₂} → P ≐ Q →
268 (P? : Decidable P) → (Q? : Decidable Q) →
269 does ∘ P? ≗ does ∘ Q?
270 does-≐ P≐Q P? = does-≡ (map P≐Q P?)
271
272 ------------------------------------------------------------------------
273 -- Irrelevant properties
274
275 U-irrelevant : Irrelevant {A = A} U
276 U-irrelevant a b = refl
277
278 ∁-irrelevant : (P : Pred A ℓ) → Irrelevant (∁ P)
279 ∁-irrelevant P a b = refl