Debian Codegraph @

src/Relation/Binary/Bundles.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Bundles for homogeneous binary relations
5 ------------------------------------------------------------------------
6
7 -- The contents of this module should be accessed via `Relation.Binary`.
8
9 {-# OPTIONS --cubical-compatible --safe #-}
10
11 module Relation.Binary.Bundles where
12
13 open import Function.Base using (flip)
14 open import Level using (Level; suc; _⊔_)
15 open import Relation.Binary.Core using (Rel)
16 open import Relation.Binary.Bundles.Raw using (RawRelation; RawSetoid)
17 open import Relation.Binary.Structures -- most of it
18 open import Relation.Nullary.Negation.Core using (¬_)
19
20 ------------------------------------------------------------------------
21 -- Setoids
22 ------------------------------------------------------------------------
23
24 record PartialSetoid a ℓ : Set (suc (a ⊔ ℓ)) where
25 infix 4 _≈_
26 field
27 Carrier : Set a
28 _≈_ : Rel Carrier ℓ
29 isPartialEquivalence : IsPartialEquivalence _≈_
30
31 open IsPartialEquivalence isPartialEquivalence public
32
33 rawSetoid : RawSetoid _ _
34 rawSetoid = record { _≈_ = _≈_ }
35
36 open RawSetoid rawSetoid public
37 hiding (Carrier; _≈_ )
38
39
40 record Setoid c ℓ : Set (suc (c ⊔ ℓ)) where
41 infix 4 _≈_
42 field
43 Carrier : Set c
44 _≈_ : Rel Carrier ℓ
45 isEquivalence : IsEquivalence _≈_
46
47 open IsEquivalence isEquivalence public
48 using (refl; reflexive; isPartialEquivalence)
49
50 partialSetoid : PartialSetoid c ℓ
51 partialSetoid = record
52 { isPartialEquivalence = isPartialEquivalence
53 }
54
55 open PartialSetoid partialSetoid public
56 hiding (Carrier; _≈_; isPartialEquivalence)
57
58
59 record DecSetoid c ℓ : Set (suc (c ⊔ ℓ)) where
60 infix 4 _≈_
61 field
62 Carrier : Set c
63 _≈_ : Rel Carrier ℓ
64 isDecEquivalence : IsDecEquivalence _≈_
65
66 open IsDecEquivalence isDecEquivalence public
67 using (_≟_; isEquivalence)
68
69 setoid : Setoid c ℓ
70 setoid = record
71 { isEquivalence = isEquivalence
72 }
73
74 open Setoid setoid public
75 hiding (Carrier; _≈_; isEquivalence)
76
77 ------------------------------------------------------------------------
78 -- Preorders
79 ------------------------------------------------------------------------
80
81 record Preorder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
82 infix 4 _≈_ _≲_
83 field
84 Carrier : Set c
85 _≈_ : Rel Carrier ℓ₁ -- The underlying equality.
86 _≲_ : Rel Carrier ℓ₂ -- The relation.
87 isPreorder : IsPreorder _≈_ _≲_
88
89 open IsPreorder isPreorder public
90 hiding (module Eq)
91
92 module Eq where
93 setoid : Setoid c ℓ₁
94 setoid = record
95 { isEquivalence = isEquivalence
96 }
97
98 open Setoid setoid public
99
100 rawRelation : RawRelation _ _ _
101 rawRelation = record { _≈_ = _≈_ ; _∼_ = _≲_ }
102
103 open RawRelation rawRelation public
104 renaming (_≁_ to _⋦_; _∼ᵒ_ to _≳_; _≁ᵒ_ to _⋧_)
105 hiding (Carrier; _≈_)
106 -- Deprecated.
107 {-# WARNING_ON_USAGE _∼_
108 "Warning: _∼_ was deprecated in v2.0.
109 Please use _≲_ instead. "
110 #-}
111
112
113 record TotalPreorder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
114 infix 4 _≈_ _≲_
115 field
116 Carrier : Set c
117 _≈_ : Rel Carrier ℓ₁ -- The underlying equality.
118 _≲_ : Rel Carrier ℓ₂ -- The relation.
119 isTotalPreorder : IsTotalPreorder _≈_ _≲_
120
121 open IsTotalPreorder isTotalPreorder public
122 using (total; isPreorder)
123
124 preorder : Preorder c ℓ₁ ℓ₂
125 preorder = record
126 { isPreorder = isPreorder
127 }
128
129 open Preorder preorder public
130 hiding (Carrier; _≈_; _≲_; isPreorder)
131
132
133 record DecPreorder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
134 field
135 Carrier : Set c
136 _≈_ : Rel Carrier ℓ₁ -- The underlying equality.
137 _≲_ : Rel Carrier ℓ₂ -- The relation.
138 isDecPreorder : IsDecPreorder _≈_ _≲_
139
140 private module DPO = IsDecPreorder isDecPreorder
141
142 open DPO public
143 using (_≟_; _≲?_; isPreorder)
144
145 preorder : Preorder c ℓ₁ ℓ₂
146 preorder = record
147 { isPreorder = isPreorder
148 }
149
150 open Preorder preorder public
151 hiding (Carrier; _≈_; _≲_; isPreorder; module Eq)
152
153 module Eq where
154 decSetoid : DecSetoid c ℓ₁
155 decSetoid = record
156 { isDecEquivalence = DPO.Eq.isDecEquivalence
157 }
158
159 open DecSetoid decSetoid public
160
161
162 ------------------------------------------------------------------------
163 -- Partial orders
164 ------------------------------------------------------------------------
165
166 record Poset c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
167 infix 4 _≈_ _≤_
168 field
169 Carrier : Set c
170 _≈_ : Rel Carrier ℓ₁
171 _≤_ : Rel Carrier ℓ₂
172 isPartialOrder : IsPartialOrder _≈_ _≤_
173
174 open IsPartialOrder isPartialOrder public
175 using (antisym; isPreorder)
176
177 preorder : Preorder c ℓ₁ ℓ₂
178 preorder = record
179 { isPreorder = isPreorder
180 }
181
182 open Preorder preorder public
183 hiding (Carrier; _≈_; _≲_; isPreorder; _⋦_; _≳_; _⋧_)
184 renaming
185 ( ≲-respˡ-≈ to ≤-respˡ-≈
186 ; ≲-respʳ-≈ to ≤-respʳ-≈
187 ; ≲-resp-≈ to ≤-resp-≈
188 )
189
190 open RawRelation rawRelation public
191 renaming (_≁_ to _≰_; _∼ᵒ_ to _≥_; _≁ᵒ_ to _≱_)
192 hiding (Carrier; _≈_ ; _∼_; _≉_; rawSetoid)
193
194
195 record DecPoset c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
196 infix 4 _≈_ _≤_
197 field
198 Carrier : Set c
199 _≈_ : Rel Carrier ℓ₁
200 _≤_ : Rel Carrier ℓ₂
201 isDecPartialOrder : IsDecPartialOrder _≈_ _≤_
202
203 private module DPO = IsDecPartialOrder isDecPartialOrder
204
205 open DPO public
206 using (_≟_; _≤?_; isPartialOrder; isDecPreorder)
207
208 poset : Poset c ℓ₁ ℓ₂
209 poset = record
210 { isPartialOrder = isPartialOrder
211 }
212
213 open Poset poset public
214 hiding (Carrier; _≈_; _≤_; isPartialOrder; module Eq)
215
216 decPreorder : DecPreorder c ℓ₁ ℓ₂
217 decPreorder = record { isDecPreorder = isDecPreorder }
218
219 open DecPreorder decPreorder public
220 using (module Eq)
221
222
223 record StrictPartialOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
224 infix 4 _≈_ _<_
225 field
226 Carrier : Set c
227 _≈_ : Rel Carrier ℓ₁
228 _<_ : Rel Carrier ℓ₂
229 isStrictPartialOrder : IsStrictPartialOrder _≈_ _<_
230
231 open IsStrictPartialOrder isStrictPartialOrder public
232 hiding (module Eq)
233
234 module Eq where
235 setoid : Setoid c ℓ₁
236 setoid = record
237 { isEquivalence = isEquivalence
238 }
239
240 open Setoid setoid public
241
242 rawRelation : RawRelation _ _ _
243 rawRelation = record { _≈_ = _≈_ ; _∼_ = _<_ }
244
245 open RawRelation rawRelation public
246 renaming (_≁_ to _≮_; _∼ᵒ_ to _>_; _≁ᵒ_ to _≯_)
247 hiding (Carrier; _≈_ ; _∼_)
248
249
250 record DecStrictPartialOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
251 infix 4 _≈_ _<_
252 field
253 Carrier : Set c
254 _≈_ : Rel Carrier ℓ₁
255 _<_ : Rel Carrier ℓ₂
256 isDecStrictPartialOrder : IsDecStrictPartialOrder _≈_ _<_
257
258 private module DSPO = IsDecStrictPartialOrder isDecStrictPartialOrder
259
260 open DSPO public
261 using (_<?_; _≟_; isStrictPartialOrder)
262
263 strictPartialOrder : StrictPartialOrder c ℓ₁ ℓ₂
264 strictPartialOrder = record
265 { isStrictPartialOrder = isStrictPartialOrder
266 }
267
268 open StrictPartialOrder strictPartialOrder public
269 hiding (Carrier; _≈_; _<_; isStrictPartialOrder; module Eq)
270
271 module Eq where
272
273 decSetoid : DecSetoid c ℓ₁
274 decSetoid = record
275 { isDecEquivalence = DSPO.Eq.isDecEquivalence
276 }
277
278 open DecSetoid decSetoid public
279
280
281 ------------------------------------------------------------------------
282 -- Total orders
283 ------------------------------------------------------------------------
284
285 record TotalOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
286 infix 4 _≈_ _≤_
287 field
288 Carrier : Set c
289 _≈_ : Rel Carrier ℓ₁
290 _≤_ : Rel Carrier ℓ₂
291 isTotalOrder : IsTotalOrder _≈_ _≤_
292
293 open IsTotalOrder isTotalOrder public
294 using (total; isPartialOrder; isTotalPreorder)
295
296 poset : Poset c ℓ₁ ℓ₂
297 poset = record
298 { isPartialOrder = isPartialOrder
299 }
300
301 open Poset poset public
302 hiding (Carrier; _≈_; _≤_; isPartialOrder)
303
304 totalPreorder : TotalPreorder c ℓ₁ ℓ₂
305 totalPreorder = record
306 { isTotalPreorder = isTotalPreorder
307 }
308
309
310 record DecTotalOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
311 infix 4 _≈_ _≤_
312 field
313 Carrier : Set c
314 _≈_ : Rel Carrier ℓ₁
315 _≤_ : Rel Carrier ℓ₂
316 isDecTotalOrder : IsDecTotalOrder _≈_ _≤_
317
318 private module DTO = IsDecTotalOrder isDecTotalOrder
319
320 open DTO public
321 using (_≟_; _≤?_; isTotalOrder; isDecPartialOrder)
322
323 totalOrder : TotalOrder c ℓ₁ ℓ₂
324 totalOrder = record
325 { isTotalOrder = isTotalOrder
326 }
327
328 open TotalOrder totalOrder public
329 hiding (Carrier; _≈_; _≤_; isTotalOrder; module Eq)
330
331 decPoset : DecPoset c ℓ₁ ℓ₂
332 decPoset = record
333 { isDecPartialOrder = isDecPartialOrder
334 }
335
336 open DecPoset decPoset public
337 using (module Eq)
338
339
340 -- Note that these orders are decidable. The current implementation
341 -- of `Trichotomous` subsumes irreflexivity and asymmetry. Any reasonable
342 -- definition capturing these three properties implies decidability
343 -- as `Trichotomous` necessarily separates out the equality case.
344
345 record StrictTotalOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
346 infix 4 _≈_ _<_
347 field
348 Carrier : Set c
349 _≈_ : Rel Carrier ℓ₁
350 _<_ : Rel Carrier ℓ₂
351 isStrictTotalOrder : IsStrictTotalOrder _≈_ _<_
352
353 open IsStrictTotalOrder isStrictTotalOrder public
354 using
355 ( _≟_; _<?_; compare; isStrictPartialOrder
356 ; isDecStrictPartialOrder; isDecEquivalence
357 )
358
359 strictPartialOrder : StrictPartialOrder c ℓ₁ ℓ₂
360 strictPartialOrder = record
361 { isStrictPartialOrder = isStrictPartialOrder
362 }
363
364 open StrictPartialOrder strictPartialOrder public
365 hiding (Carrier; _≈_; _<_; isStrictPartialOrder; module Eq)
366
367 decStrictPartialOrder : DecStrictPartialOrder c ℓ₁ ℓ₂
368 decStrictPartialOrder = record
369 { isDecStrictPartialOrder = isDecStrictPartialOrder
370 }
371
372 open DecStrictPartialOrder decStrictPartialOrder public
373 using (module Eq)
374
375 decSetoid : DecSetoid c ℓ₁
376 decSetoid = record
377 { isDecEquivalence = Eq.isDecEquivalence
378 }
379 {-# WARNING_ON_USAGE decSetoid
380 "Warning: decSetoid was deprecated in v1.3.
381 Please use Eq.decSetoid instead."
382 #-}
383
384
385 record DenseLinearOrder c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
386 infix 4 _≈_ _<_
387 field
388 Carrier : Set c
389 _≈_ : Rel Carrier ℓ₁
390 _<_ : Rel Carrier ℓ₂
391 isDenseLinearOrder : IsDenseLinearOrder _≈_ _<_
392
393 open IsDenseLinearOrder isDenseLinearOrder public
394 using (isStrictTotalOrder; dense)
395
396 strictTotalOrder : StrictTotalOrder c ℓ₁ ℓ₂
397 strictTotalOrder = record
398 { isStrictTotalOrder = isStrictTotalOrder
399 }
400
401 open StrictTotalOrder strictTotalOrder public
402 hiding (Carrier; _≈_; _<_; isStrictTotalOrder)
403
404
405 ------------------------------------------------------------------------
406 -- Apartness relations
407 ------------------------------------------------------------------------
408
409 record ApartnessRelation c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
410 infix 4 _≈_ _#_
411 field
412 Carrier : Set c
413 _≈_ : Rel Carrier ℓ₁
414 _#_ : Rel Carrier ℓ₂
415 isApartnessRelation : IsApartnessRelation _≈_ _#_
416
417 open IsApartnessRelation isApartnessRelation public
418 hiding (_¬#_)
419
420 rawRelation : RawRelation _ _ _
421 rawRelation = record { _≈_ = _≈_ ; _∼_ = _#_ }
422
423 open RawRelation rawRelation public
424 renaming (_≁_ to _¬#_; _∼ᵒ_ to _#ᵒ_; _≁ᵒ_ to _¬#ᵒ_)
425 hiding (Carrier; _≈_ ; _∼_)
426