Debian Codegraph @

src/Relation/Binary/Construct/Flip/Ord.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Many properties which hold for `∼` also hold for `flip ∼`. Unlike
5 -- the module `Relation.Binary.Construct.Flip.EqAndOrd` this module
6 -- flips both the relation and the underlying equality.
7 ------------------------------------------------------------------------
8
9 {-# OPTIONS --cubical-compatible --safe #-}
10
11 module Relation.Binary.Construct.Flip.Ord where
12
13 open import Data.Product.Base using (_,_)
14 open import Function.Base using (flip; _∘_)
15 open import Level using (Level)
16 open import Relation.Binary.Core using (Rel; REL; _⇒_)
17 open import Relation.Binary.Bundles
18 using (Setoid; DecSetoid; Preorder; Poset; TotalOrder; DecTotalOrder
19 ; StrictPartialOrder; StrictTotalOrder)
20 open import Relation.Binary.Structures
21 using (IsEquivalence; IsDecEquivalence; IsPreorder; IsPartialOrder
22 ; IsTotalOrder; IsDecTotalOrder; IsStrictPartialOrder
23 ; IsStrictTotalOrder)
24 open import Relation.Binary.Definitions
25 using (Reflexive; Symmetric; Transitive; Asymmetric; Total; _Respects_
26 ; _Respects₂_; Minimum; Maximum; Irreflexive; Antisymmetric
27 ; Trichotomous; Decidable)
28
29 private
30 variable
31 a b p ℓ ℓ₁ ℓ₂ : Level
32 A B : Set a
33 ≈ ∼ ≤ < : Rel A ℓ
34
35 ------------------------------------------------------------------------
36 -- Properties
37
38 module _ (∼ : Rel A ℓ) where
39
40 reflexive : Reflexive ∼ → Reflexive (flip ∼)
41 reflexive refl = refl
42
43 symmetric : Symmetric ∼ → Symmetric (flip ∼)
44 symmetric sym = sym
45
46 transitive : Transitive ∼ → Transitive (flip ∼)
47 transitive trans = flip trans
48
49 asymmetric : Asymmetric ∼ → Asymmetric (flip ∼)
50 asymmetric asym = asym
51
52 total : Total ∼ → Total (flip ∼)
53 total total x y = total y x
54
55 respects : ∀ (P : A → Set p) → Symmetric ∼ →
56 P Respects ∼ → P Respects flip ∼
57 respects _ sym resp ∼ = resp (sym ∼)
58
59 max : ∀ {⊥} → Minimum ∼ ⊥ → Maximum (flip ∼) ⊥
60 max min = min
61
62 min : ∀ {⊤} → Maximum ∼ ⊤ → Minimum (flip ∼) ⊤
63 min max = max
64
65 module _ (≈ : REL A B ℓ₁) (∼ : REL A B ℓ₂) where
66
67 implies : ≈ ⇒ ∼ → flip ≈ ⇒ flip ∼
68 implies impl = impl
69
70 irreflexive : Irreflexive ≈ ∼ → Irreflexive (flip ≈) (flip ∼)
71 irreflexive irrefl = irrefl
72
73 module _ (≈ : Rel A ℓ₁) (∼ : Rel A ℓ₂) where
74
75 antisymmetric : Antisymmetric ≈ ∼ → Antisymmetric (flip ≈) (flip ∼)
76 antisymmetric antisym = antisym
77
78 trichotomous : Trichotomous ≈ ∼ → Trichotomous (flip ≈) (flip ∼)
79 trichotomous compare x y = compare y x
80
81 module _ (∼₁ : Rel A ℓ₁) (∼₂ : Rel A ℓ₂) where
82
83 respects₂ : Symmetric ∼₂ → ∼₁ Respects₂ ∼₂ → flip ∼₁ Respects₂ flip ∼₂
84 respects₂ sym (resp₁ , resp₂) = (resp₂ ∘ sym , resp₁ ∘ sym)
85
86 module _ (∼ : REL A B ℓ) where
87
88 decidable : Decidable ∼ → Decidable (flip ∼)
89 decidable dec x y = dec y x
90
91 ------------------------------------------------------------------------
92 -- Structures
93
94 isEquivalence : IsEquivalence ≈ → IsEquivalence (flip ≈)
95 isEquivalence {≈ = ≈} eq = record
96 { refl = reflexive ≈ Eq.refl
97 ; sym = symmetric ≈ Eq.sym
98 ; trans = transitive ≈ Eq.trans
99 } where module Eq = IsEquivalence eq
100
101 isDecEquivalence : IsDecEquivalence ≈ → IsDecEquivalence (flip ≈)
102 isDecEquivalence {≈ = ≈} dec = record
103 { isEquivalence = isEquivalence Dec.isEquivalence
104 ; _≟_ = decidable ≈ Dec._≟_
105 } where module Dec = IsDecEquivalence dec
106
107 isPreorder : IsPreorder ≈ ∼ → IsPreorder (flip ≈) (flip ∼)
108 isPreorder {≈ = ≈} {∼ = ∼} O = record
109 { isEquivalence = isEquivalence O.isEquivalence
110 ; reflexive = implies ≈ ∼ O.reflexive
111 ; trans = transitive ∼ O.trans
112 } where module O = IsPreorder O
113
114 isPartialOrder : IsPartialOrder ≈ ≤ → IsPartialOrder (flip ≈) (flip ≤)
115 isPartialOrder {≈ = ≈} {≤ = ≤} O = record
116 { isPreorder = isPreorder O.isPreorder
117 ; antisym = antisymmetric ≈ ≤ O.antisym
118 } where module O = IsPartialOrder O
119
120 isTotalOrder : IsTotalOrder ≈ ≤ → IsTotalOrder (flip ≈) (flip ≤)
121 isTotalOrder {≈ = ≈} {≤ = ≤} O = record
122 { isPartialOrder = isPartialOrder O.isPartialOrder
123 ; total = total ≤ O.total
124 }
125 where module O = IsTotalOrder O
126
127 isDecTotalOrder : IsDecTotalOrder ≈ ≤ → IsDecTotalOrder (flip ≈) (flip ≤)
128 isDecTotalOrder {≈ = ≈} {≤ = ≤} O = record
129 { isTotalOrder = isTotalOrder O.isTotalOrder
130 ; _≟_ = decidable ≈ O._≟_
131 ; _≤?_ = decidable ≤ O._≤?_
132 } where module O = IsDecTotalOrder O
133
134 isStrictPartialOrder : IsStrictPartialOrder ≈ < →
135 IsStrictPartialOrder (flip ≈) (flip <)
136 isStrictPartialOrder {≈ = ≈} {< = <} O = record
137 { isEquivalence = isEquivalence O.isEquivalence
138 ; irrefl = irreflexive ≈ < O.irrefl
139 ; trans = transitive < O.trans
140 ; <-resp-≈ = respects₂ < ≈ O.Eq.sym O.<-resp-≈
141 } where module O = IsStrictPartialOrder O
142
143 isStrictTotalOrder : IsStrictTotalOrder ≈ < →
144 IsStrictTotalOrder (flip ≈) (flip <)
145 isStrictTotalOrder {≈ = ≈} {< = <} O = record
146 { isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder
147 ; compare = trichotomous ≈ < O.compare
148 } where module O = IsStrictTotalOrder O
149
150 ------------------------------------------------------------------------
151 -- Bundles
152
153 setoid : Setoid a ℓ → Setoid a ℓ
154 setoid S = record
155 { _≈_ = flip S._≈_
156 ; isEquivalence = isEquivalence S.isEquivalence
157 } where module S = Setoid S
158
159 decSetoid : DecSetoid a ℓ → DecSetoid a ℓ
160 decSetoid S = record
161 { _≈_ = flip S._≈_
162 ; isDecEquivalence = isDecEquivalence S.isDecEquivalence
163 } where module S = DecSetoid S
164
165 preorder : Preorder a ℓ₁ ℓ₂ → Preorder a ℓ₁ ℓ₂
166 preorder O = record
167 { isPreorder = isPreorder O.isPreorder
168 } where module O = Preorder O
169
170 poset : Poset a ℓ₁ ℓ₂ → Poset a ℓ₁ ℓ₂
171 poset O = record
172 { isPartialOrder = isPartialOrder O.isPartialOrder
173 } where module O = Poset O
174
175 totalOrder : TotalOrder a ℓ₁ ℓ₂ → TotalOrder a ℓ₁ ℓ₂
176 totalOrder O = record
177 { isTotalOrder = isTotalOrder O.isTotalOrder
178 } where module O = TotalOrder O
179
180 decTotalOrder : DecTotalOrder a ℓ₁ ℓ₂ → DecTotalOrder a ℓ₁ ℓ₂
181 decTotalOrder O = record
182 { isDecTotalOrder = isDecTotalOrder O.isDecTotalOrder
183 } where module O = DecTotalOrder O
184
185 strictPartialOrder : StrictPartialOrder a ℓ₁ ℓ₂ →
186 StrictPartialOrder a ℓ₁ ℓ₂
187 strictPartialOrder O = record
188 { isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder
189 } where module O = StrictPartialOrder O
190
191 strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂ →
192 StrictTotalOrder a ℓ₁ ℓ₂
193 strictTotalOrder O = record
194 { isStrictTotalOrder = isStrictTotalOrder O.isStrictTotalOrder
195 } where module O = StrictTotalOrder O