Debian Codegraph @

src/Relation/Binary/Construct/FromPred.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Every respectful unary relation induces a preorder. No claim is
5 -- made that this preorder is unique.
6 ------------------------------------------------------------------------
7
8 {-# OPTIONS --cubical-compatible --safe #-}
9
10 open import Relation.Binary.Core using (Rel; _⇒_)
11 open import Relation.Binary.Bundles using (Setoid; Preorder)
12 open import Relation.Binary.Structures using (IsPreorder)
13 open import Relation.Binary.Definitions using (_Respects_; Reflexive; Transitive)
14 open import Relation.Unary using (Pred)
15
16 module Relation.Binary.Construct.FromPred
17 {s₁ s₂} (S : Setoid s₁ s₂) -- The underlying equality
18 {p} (P : Pred (Setoid.Carrier S) p) -- The predicate
19 where
20
21 open import Function.Base
22
23 open module Eq = Setoid S using (_≈_) renaming (Carrier to A)
24
25 ------------------------------------------------------------------------
26 -- Definition
27
28 Resp : Rel A p
29 Resp x y = P x → P y
30
31 ------------------------------------------------------------------------
32 -- Properties
33
34 reflexive : P Respects _≈_ → _≈_ ⇒ Resp
35 reflexive resp = resp
36
37 refl : P Respects _≈_ → Reflexive Resp
38 refl resp = resp Eq.refl
39
40 trans : Transitive Resp
41 trans x⇒y y⇒z = y⇒z ∘ x⇒y
42
43 isPreorder : P Respects _≈_ → IsPreorder _≈_ Resp
44 isPreorder resp = record
45 { isEquivalence = Eq.isEquivalence
46 ; reflexive = reflexive resp
47 ; trans = flip _∘′_
48 }
49
50 preorder : P Respects _≈_ → Preorder _ _ _
51 preorder resp = record
52 { isPreorder = isPreorder resp
53 }