forked from agda/agda-stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNonStrict.agda
170 lines (133 loc) · 7.17 KB
/
NonStrict.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
------------------------------------------------------------------------
-- The Agda standard library
--
-- The lifting of a non-strict order to incorporate a new infimum
------------------------------------------------------------------------
{-# OPTIONS --cubical-compatible --safe #-}
-- This module is designed to be used with
-- Relation.Nullary.Construct.Add.Infimum
open import Relation.Binary.Core using (Rel; _⇒_)
module Relation.Binary.Construct.Add.Infimum.NonStrict
{a ℓ} {A : Set a} (_≤_ : Rel A ℓ) where
open import Level using (_⊔_)
open import Data.Sum.Base as Sum using (inj₁; inj₂)
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong)
import Relation.Binary.PropositionalEquality.Properties as ≡
using (isEquivalence)
import Relation.Binary.Construct.Add.Infimum.Equality as Equality
using (_≈₋_; ⊥₋≈⊥₋; ≈₋-isEquivalence; ≈₋-isDecEquivalence; ≈₋-refl; ≈₋-dec
; [_])
open import Relation.Binary.Structures
using (IsPreorder; IsPartialOrder; IsDecPartialOrder; IsTotalOrder
; IsDecTotalOrder)
open import Relation.Binary.Definitions
using (Minimum; Transitive; Total; Decidable; Irrelevant; Antisymmetric)
open import Relation.Nullary.Construct.Add.Infimum using (⊥₋; [_]; _₋; ≡-dec)
open import Relation.Nullary.Decidable.Core using (yes; no; map′)
import Relation.Nullary.Decidable.Core as Dec using (map′)
------------------------------------------------------------------------
-- Definition
infix 5 _≤₋_
data _≤₋_ : Rel (A ₋) (a ⊔ ℓ) where
⊥₋≤_ : (l : A ₋) → ⊥₋ ≤₋ l
[_] : {k l : A} → k ≤ l → [ k ] ≤₋ [ l ]
------------------------------------------------------------------------
-- Relational properties
[≤]-injective : ∀ {k l} → [ k ] ≤₋ [ l ] → k ≤ l
[≤]-injective [ p ] = p
≤₋-trans : Transitive _≤_ → Transitive _≤₋_
≤₋-trans ≤-trans (⊥₋≤ l) q = ⊥₋≤ _
≤₋-trans ≤-trans [ p ] [ q ] = [ ≤-trans p q ]
≤₋-minimum : Minimum _≤₋_ ⊥₋
≤₋-minimum = ⊥₋≤_
≤₋-dec : Decidable _≤_ → Decidable _≤₋_
≤₋-dec _≤?_ ⊥₋ l = yes (⊥₋≤ l)
≤₋-dec _≤?_ [ k ] ⊥₋ = no (λ ())
≤₋-dec _≤?_ [ k ] [ l ] = Dec.map′ [_] [≤]-injective (k ≤? l)
≤₋-total : Total _≤_ → Total _≤₋_
≤₋-total ≤-total ⊥₋ l = inj₁ (⊥₋≤ l)
≤₋-total ≤-total k ⊥₋ = inj₂ (⊥₋≤ k)
≤₋-total ≤-total [ k ] [ l ] = Sum.map [_] [_] (≤-total k l)
≤₋-irrelevant : Irrelevant _≤_ → Irrelevant _≤₋_
≤₋-irrelevant ≤-irr (⊥₋≤ k) (⊥₋≤ k) = refl
≤₋-irrelevant ≤-irr [ p ] [ q ] = cong _ (≤-irr p q)
------------------------------------------------------------------------
-- Relational properties + propositional equality
≤₋-reflexive-≡ : (_≡_ ⇒ _≤_) → (_≡_ ⇒ _≤₋_)
≤₋-reflexive-≡ ≤-reflexive {[ x ]} refl = [ ≤-reflexive refl ]
≤₋-reflexive-≡ ≤-reflexive {⊥₋} refl = ⊥₋≤ ⊥₋
≤₋-antisym-≡ : Antisymmetric _≡_ _≤_ → Antisymmetric _≡_ _≤₋_
≤₋-antisym-≡ antisym (⊥₋≤ _) (⊥₋≤ _) = refl
≤₋-antisym-≡ antisym [ p ] [ q ] = cong [_] (antisym p q)
------------------------------------------------------------------------
-- Relational properties + setoid equality
module _ {e} {_≈_ : Rel A e} where
open Equality _≈_
≤₋-reflexive : (_≈_ ⇒ _≤_) → (_≈₋_ ⇒ _≤₋_)
≤₋-reflexive ≤-reflexive ⊥₋≈⊥₋ = ⊥₋≤ ⊥₋
≤₋-reflexive ≤-reflexive [ p ] = [ ≤-reflexive p ]
≤₋-antisym : Antisymmetric _≈_ _≤_ → Antisymmetric _≈₋_ _≤₋_
≤₋-antisym ≤≥⇒≈ (⊥₋≤ _) (⊥₋≤ _) = ⊥₋≈⊥₋
≤₋-antisym ≤≥⇒≈ [ p ] [ q ] = [ ≤≥⇒≈ p q ]
------------------------------------------------------------------------
-- Structures + propositional equality
≤₋-isPreorder-≡ : IsPreorder _≡_ _≤_ → IsPreorder _≡_ _≤₋_
≤₋-isPreorder-≡ ≤-isPreorder = record
{ isEquivalence = ≡.isEquivalence
; reflexive = ≤₋-reflexive-≡ reflexive
; trans = ≤₋-trans trans
} where open IsPreorder ≤-isPreorder
≤₋-isPartialOrder-≡ : IsPartialOrder _≡_ _≤_ → IsPartialOrder _≡_ _≤₋_
≤₋-isPartialOrder-≡ ≤-isPartialOrder = record
{ isPreorder = ≤₋-isPreorder-≡ isPreorder
; antisym = ≤₋-antisym-≡ antisym
} where open IsPartialOrder ≤-isPartialOrder
≤₋-isDecPartialOrder-≡ : IsDecPartialOrder _≡_ _≤_ → IsDecPartialOrder _≡_ _≤₋_
≤₋-isDecPartialOrder-≡ ≤-isDecPartialOrder = record
{ isPartialOrder = ≤₋-isPartialOrder-≡ isPartialOrder
; _≟_ = ≡-dec _≟_
; _≤?_ = ≤₋-dec _≤?_
} where open IsDecPartialOrder ≤-isDecPartialOrder
≤₋-isTotalOrder-≡ : IsTotalOrder _≡_ _≤_ → IsTotalOrder _≡_ _≤₋_
≤₋-isTotalOrder-≡ ≤-isTotalOrder = record
{ isPartialOrder = ≤₋-isPartialOrder-≡ isPartialOrder
; total = ≤₋-total total
} where open IsTotalOrder ≤-isTotalOrder
≤₋-isDecTotalOrder-≡ : IsDecTotalOrder _≡_ _≤_ → IsDecTotalOrder _≡_ _≤₋_
≤₋-isDecTotalOrder-≡ ≤-isDecTotalOrder = record
{ isTotalOrder = ≤₋-isTotalOrder-≡ isTotalOrder
; _≟_ = ≡-dec _≟_
; _≤?_ = ≤₋-dec _≤?_
} where open IsDecTotalOrder ≤-isDecTotalOrder
------------------------------------------------------------------------
-- Structures + setoid equality
module _ {e} {_≈_ : Rel A e} where
open Equality _≈_
≤₋-isPreorder : IsPreorder _≈_ _≤_ → IsPreorder _≈₋_ _≤₋_
≤₋-isPreorder ≤-isPreorder = record
{ isEquivalence = ≈₋-isEquivalence isEquivalence
; reflexive = ≤₋-reflexive reflexive
; trans = ≤₋-trans trans
} where open IsPreorder ≤-isPreorder
≤₋-isPartialOrder : IsPartialOrder _≈_ _≤_ → IsPartialOrder _≈₋_ _≤₋_
≤₋-isPartialOrder ≤-isPartialOrder = record
{ isPreorder = ≤₋-isPreorder isPreorder
; antisym = ≤₋-antisym antisym
} where open IsPartialOrder ≤-isPartialOrder
≤₋-isDecPartialOrder : IsDecPartialOrder _≈_ _≤_ → IsDecPartialOrder _≈₋_ _≤₋_
≤₋-isDecPartialOrder ≤-isDecPartialOrder = record
{ isPartialOrder = ≤₋-isPartialOrder isPartialOrder
; _≟_ = ≈₋-dec _≟_
; _≤?_ = ≤₋-dec _≤?_
} where open IsDecPartialOrder ≤-isDecPartialOrder
≤₋-isTotalOrder : IsTotalOrder _≈_ _≤_ → IsTotalOrder _≈₋_ _≤₋_
≤₋-isTotalOrder ≤-isTotalOrder = record
{ isPartialOrder = ≤₋-isPartialOrder isPartialOrder
; total = ≤₋-total total
} where open IsTotalOrder ≤-isTotalOrder
≤₋-isDecTotalOrder : IsDecTotalOrder _≈_ _≤_ → IsDecTotalOrder _≈₋_ _≤₋_
≤₋-isDecTotalOrder ≤-isDecTotalOrder = record
{ isTotalOrder = ≤₋-isTotalOrder isTotalOrder
; _≟_ = ≈₋-dec _≟_
; _≤?_ = ≤₋-dec _≤?_
} where open IsDecTotalOrder ≤-isDecTotalOrder