Debian Codegraph @

src/Relation/Binary/Construct/Add/Supremum/Strict.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- The lifting of a strict order to incorporate a new supremum
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 -- This module is designed to be used with
10 -- Relation.Nullary.Construct.Add.Supremum
11
12 open import Relation.Binary.Core using (Rel)
13
14 module Relation.Binary.Construct.Add.Supremum.Strict
15 {a r} {A : Set a} (_<_ : Rel A r) where
16
17 open import Data.Product.Base using (_,_; map)
18 open import Function.Base using (_∘_)
19 open import Level using (_⊔_)
20 open import Relation.Binary.Definitions
21 using (Asymmetric; Transitive; Decidable; Irrelevant; Irreflexive; Trans
22 ; Trichotomous; tri≈; tri>; tri<; _Respectsˡ_; _Respectsʳ_; _Respects₂_)
23 open import Relation.Nullary.Construct.Add.Supremum
24 using (⊤⁺; _⁺; [_]; ≡-dec; []-injective)
25 import Relation.Binary.Construct.Add.Supremum.Equality as Equality
26 using (_≈⁺_; ⊤⁺≈⊤⁺; ≈⁺-isEquivalence; ≈⁺-dec; [≈]-injective; [_])
27 import Relation.Binary.Construct.Add.Supremum.NonStrict as NonStrict
28 open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong; subst)
29 import Relation.Binary.PropositionalEquality.Properties as ≡
30 open import Relation.Binary.Structures
31 using (IsStrictPartialOrder; IsDecStrictPartialOrder; IsStrictTotalOrder)
32 open import Relation.Nullary.Negation.Core using (¬_)
33 open import Relation.Nullary.Decidable.Core using (yes; no)
34 import Relation.Nullary.Decidable as Dec using (map′)
35
36 ------------------------------------------------------------------------
37 -- Definition
38
39 infix 4 _<⁺_
40
41 data _<⁺_ : Rel (A ⁺) (a ⊔ r) where
42 [_] : {k l : A} → k < l → [ k ] <⁺ [ l ]
43 [_]<⊤⁺ : (k : A) → [ k ] <⁺ ⊤⁺
44
45 ------------------------------------------------------------------------
46 -- Relational properties
47
48 [<]-injective : ∀ {k l} → [ k ] <⁺ [ l ] → k < l
49 [<]-injective [ p ] = p
50
51 <⁺-asym : Asymmetric _<_ → Asymmetric _<⁺_
52 <⁺-asym <-asym [ p ] [ q ] = <-asym p q
53
54 <⁺-trans : Transitive _<_ → Transitive _<⁺_
55 <⁺-trans <-trans [ p ] [ q ] = [ <-trans p q ]
56 <⁺-trans <-trans [ p ] [ k ]<⊤⁺ = [ _ ]<⊤⁺
57
58 <⁺-dec : Decidable _<_ → Decidable _<⁺_
59 <⁺-dec _<?_ [ k ] [ l ] = Dec.map′ [_] [<]-injective (k <? l)
60 <⁺-dec _<?_ [ k ] ⊤⁺ = yes [ k ]<⊤⁺
61 <⁺-dec _<?_ ⊤⁺ [ l ] = no (λ ())
62 <⁺-dec _<?_ ⊤⁺ ⊤⁺ = no (λ ())
63
64 <⁺-irrelevant : Irrelevant _<_ → Irrelevant _<⁺_
65 <⁺-irrelevant <-irr [ p ] [ q ] = cong _ (<-irr p q)
66 <⁺-irrelevant <-irr [ k ]<⊤⁺ [ k ]<⊤⁺ = refl
67
68
69 module _ {r} {_≤_ : Rel A r} where
70
71 open NonStrict _≤_
72
73 <⁺-transʳ : Trans _≤_ _<_ _<_ → Trans _≤⁺_ _<⁺_ _<⁺_
74 <⁺-transʳ <-transʳ [ p ] [ q ] = [ <-transʳ p q ]
75 <⁺-transʳ <-transʳ [ p ] [ k ]<⊤⁺ = [ _ ]<⊤⁺
76
77 <⁺-transˡ : Trans _<_ _≤_ _<_ → Trans _<⁺_ _≤⁺_ _<⁺_
78 <⁺-transˡ <-transˡ [ p ] [ q ] = [ <-transˡ p q ]
79 <⁺-transˡ <-transˡ [ p ] ([ _ ] ≤⊤⁺) = [ _ ]<⊤⁺
80 <⁺-transˡ <-transˡ [ k ]<⊤⁺ (⊤⁺ ≤⊤⁺) = [ k ]<⊤⁺
81
82 ------------------------------------------------------------------------
83 -- Relational properties + propositional equality
84
85 <⁺-cmp-≡ : Trichotomous _≡_ _<_ → Trichotomous _≡_ _<⁺_
86 <⁺-cmp-≡ <-cmp ⊤⁺ ⊤⁺ = tri≈ (λ ()) refl (λ ())
87 <⁺-cmp-≡ <-cmp ⊤⁺ [ l ] = tri> (λ ()) (λ ()) [ l ]<⊤⁺
88 <⁺-cmp-≡ <-cmp [ k ] ⊤⁺ = tri< [ k ]<⊤⁺ (λ ()) (λ ())
89 <⁺-cmp-≡ <-cmp [ k ] [ l ] with <-cmp k l
90 ... | tri< a ¬b ¬c = tri< [ a ] (¬b ∘ []-injective) (¬c ∘ [<]-injective)
91 ... | tri≈ ¬a refl ¬c = tri≈ (¬a ∘ [<]-injective) refl (¬c ∘ [<]-injective)
92 ... | tri> ¬a ¬b c = tri> (¬a ∘ [<]-injective) (¬b ∘ []-injective) [ c ]
93
94 <⁺-irrefl-≡ : Irreflexive _≡_ _<_ → Irreflexive _≡_ _<⁺_
95 <⁺-irrefl-≡ <-irrefl refl [ x ] = <-irrefl refl x
96
97 <⁺-respˡ-≡ : _<⁺_ Respectsˡ _≡_
98 <⁺-respˡ-≡ = subst (_<⁺ _)
99
100 <⁺-respʳ-≡ : _<⁺_ Respectsʳ _≡_
101 <⁺-respʳ-≡ = subst (_ <⁺_)
102
103 <⁺-resp-≡ : _<⁺_ Respects₂ _≡_
104 <⁺-resp-≡ = <⁺-respʳ-≡ , <⁺-respˡ-≡
105
106 ------------------------------------------------------------------------
107 -- Relational properties + setoid equality
108
109 module _ {e} {_≈_ : Rel A e} where
110
111 open Equality _≈_
112
113 <⁺-cmp : Trichotomous _≈_ _<_ → Trichotomous _≈⁺_ _<⁺_
114 <⁺-cmp <-cmp ⊤⁺ ⊤⁺ = tri≈ (λ ()) ⊤⁺≈⊤⁺ (λ ())
115 <⁺-cmp <-cmp ⊤⁺ [ l ] = tri> (λ ()) (λ ()) [ l ]<⊤⁺
116 <⁺-cmp <-cmp [ k ] ⊤⁺ = tri< [ k ]<⊤⁺ (λ ()) (λ ())
117 <⁺-cmp <-cmp [ k ] [ l ] with <-cmp k l
118 ... | tri< a ¬b ¬c = tri< [ a ] (¬b ∘ [≈]-injective) (¬c ∘ [<]-injective)
119 ... | tri≈ ¬a b ¬c = tri≈ (¬a ∘ [<]-injective) [ b ] (¬c ∘ [<]-injective)
120 ... | tri> ¬a ¬b c = tri> (¬a ∘ [<]-injective) (¬b ∘ [≈]-injective) [ c ]
121
122 <⁺-irrefl : Irreflexive _≈_ _<_ → Irreflexive _≈⁺_ _<⁺_
123 <⁺-irrefl <-irrefl [ p ] [ q ] = <-irrefl p q
124
125 <⁺-respˡ-≈⁺ : _<_ Respectsˡ _≈_ → _<⁺_ Respectsˡ _≈⁺_
126 <⁺-respˡ-≈⁺ <-respˡ-≈ [ p ] [ q ] = [ <-respˡ-≈ p q ]
127 <⁺-respˡ-≈⁺ <-respˡ-≈ [ p ] ([ l ]<⊤⁺) = [ _ ]<⊤⁺
128 <⁺-respˡ-≈⁺ <-respˡ-≈ ⊤⁺≈⊤⁺ q = q
129
130 <⁺-respʳ-≈⁺ : _<_ Respectsʳ _≈_ → _<⁺_ Respectsʳ _≈⁺_
131 <⁺-respʳ-≈⁺ <-respʳ-≈ [ p ] [ q ] = [ <-respʳ-≈ p q ]
132 <⁺-respʳ-≈⁺ <-respʳ-≈ ⊤⁺≈⊤⁺ q = q
133
134 <⁺-resp-≈⁺ : _<_ Respects₂ _≈_ → _<⁺_ Respects₂ _≈⁺_
135 <⁺-resp-≈⁺ = map <⁺-respʳ-≈⁺ <⁺-respˡ-≈⁺
136
137 ------------------------------------------------------------------------
138 -- Structures + propositional equality
139
140 <⁺-isStrictPartialOrder-≡ : IsStrictPartialOrder _≡_ _<_ →
141 IsStrictPartialOrder _≡_ _<⁺_
142 <⁺-isStrictPartialOrder-≡ strict = record
143 { isEquivalence = ≡.isEquivalence
144 ; irrefl = <⁺-irrefl-≡ irrefl
145 ; trans = <⁺-trans trans
146 ; <-resp-≈ = <⁺-resp-≡
147 } where open IsStrictPartialOrder strict
148
149 <⁺-isDecStrictPartialOrder-≡ : IsDecStrictPartialOrder _≡_ _<_ →
150 IsDecStrictPartialOrder _≡_ _<⁺_
151 <⁺-isDecStrictPartialOrder-≡ dectot = record
152 { isStrictPartialOrder = <⁺-isStrictPartialOrder-≡ isStrictPartialOrder
153 ; _≟_ = ≡-dec _≟_
154 ; _<?_ = <⁺-dec _<?_
155 } where open IsDecStrictPartialOrder dectot
156
157 <⁺-isStrictTotalOrder-≡ : IsStrictTotalOrder _≡_ _<_ →
158 IsStrictTotalOrder _≡_ _<⁺_
159 <⁺-isStrictTotalOrder-≡ strictot = record
160 { isStrictPartialOrder = <⁺-isStrictPartialOrder-≡ isStrictPartialOrder
161 ; compare = <⁺-cmp-≡ compare
162 } where open IsStrictTotalOrder strictot
163
164 ------------------------------------------------------------------------
165 -- Structures + setoid equality
166
167 module _ {e} {_≈_ : Rel A e} where
168
169 open Equality _≈_
170
171 <⁺-isStrictPartialOrder : IsStrictPartialOrder _≈_ _<_ →
172 IsStrictPartialOrder _≈⁺_ _<⁺_
173 <⁺-isStrictPartialOrder strict = record
174 { isEquivalence = ≈⁺-isEquivalence isEquivalence
175 ; irrefl = <⁺-irrefl irrefl
176 ; trans = <⁺-trans trans
177 ; <-resp-≈ = <⁺-resp-≈⁺ <-resp-≈
178 } where open IsStrictPartialOrder strict
179
180 <⁺-isDecStrictPartialOrder : IsDecStrictPartialOrder _≈_ _<_ →
181 IsDecStrictPartialOrder _≈⁺_ _<⁺_
182 <⁺-isDecStrictPartialOrder dectot = record
183 { isStrictPartialOrder = <⁺-isStrictPartialOrder isStrictPartialOrder
184 ; _≟_ = ≈⁺-dec _≟_
185 ; _<?_ = <⁺-dec _<?_
186 } where open IsDecStrictPartialOrder dectot
187
188 <⁺-isStrictTotalOrder : IsStrictTotalOrder _≈_ _<_ →
189 IsStrictTotalOrder _≈⁺_ _<⁺_
190 <⁺-isStrictTotalOrder strictot = record
191 { isStrictPartialOrder = <⁺-isStrictPartialOrder isStrictPartialOrder
192 ; compare = <⁺-cmp compare
193 } where open IsStrictTotalOrder strictot
194