-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathSetoid.agda
175 lines (146 loc) · 6.83 KB
/
Setoid.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
171
172
173
174
175
------------------------------------------------------------------------
-- The Agda standard library
--
-- Sum combinators for setoid equality preserving functions
------------------------------------------------------------------------
{-# OPTIONS --cubical-compatible --safe #-}
module Data.Sum.Function.Setoid where
open import Data.Product.Base as Product using (_,_)
open import Data.Sum.Base as Sum
open import Data.Sum.Relation.Binary.Pointwise as Pointwise
open import Relation.Binary
open import Function.Base
open import Function.Bundles
open import Function.Definitions
open import Function.Definitions.Strict
open import Level
private
variable
a₁ a₂ b₁ b₂ c₁ c₂ d₁ d₂ : Level
a ℓ : Level
A B C D : Set a
≈₁ ≈₂ ≈₃ ≈₄ : Rel A ℓ
S T U V : Setoid a ℓ
------------------------------------------------------------------------
-- Combinators for equality preserving functions
inj₁ₛ : Func S (S ⊎ₛ T)
inj₁ₛ = record { to = inj₁ ; cong = inj₁ }
inj₂ₛ : Func T (S ⊎ₛ T)
inj₂ₛ = record { to = inj₂ ; cong = inj₂ }
[_,_]ₛ : Func S U → Func T U → Func (S ⊎ₛ T) U
[ f , g ]ₛ = record
{ to = [ to f , to g ]
; cong = λ where
(inj₁ x∼₁y) → cong f x∼₁y
(inj₂ x∼₂y) → cong g x∼₂y
} where open Func
swapₛ : Func (S ⊎ₛ T) (T ⊎ₛ S)
swapₛ = [ inj₂ₛ , inj₁ₛ ]ₛ
------------------------------------------------------------------------
-- Definitions
⊎-injective : ∀ {f g} →
Injective ≈₁ ≈₂ f →
Injective ≈₃ ≈₄ g →
Injective (Pointwise ≈₁ ≈₃) (Pointwise ≈₂ ≈₄) (Sum.map f g)
⊎-injective f-inj g-inj {inj₁ x} {inj₁ y} (inj₁ x∼₁y) = inj₁ (f-inj x∼₁y)
⊎-injective f-inj g-inj {inj₂ x} {inj₂ y} (inj₂ x∼₂y) = inj₂ (g-inj x∼₂y)
⊎-strictlySurjective : ∀ {f : A → B} {g : C → D} →
StrictlySurjective ≈₁ f →
StrictlySurjective ≈₂ g →
StrictlySurjective (Pointwise ≈₁ ≈₂) (Sum.map f g)
⊎-strictlySurjective f-sur g-sur =
[ Product.map inj₁ inj₁ ∘ f-sur
, Product.map inj₂ inj₂ ∘ g-sur
]
⊎-surjective : ∀ {f : A → B} {g : C → D} →
Surjective ≈₁ ≈₂ f →
Surjective ≈₃ ≈₄ g →
Surjective (Pointwise ≈₁ ≈₃) (Pointwise ≈₂ ≈₄) (Sum.map f g)
⊎-surjective f-sur g-sur =
[ Product.map inj₁ (λ { fwd (inj₁ x) → inj₁ (fwd x)}) ∘ f-sur
, Product.map inj₂ (λ { fwd (inj₂ y) → inj₂ (fwd y)}) ∘ g-sur
]
infixr 1 _⊎-equivalence_ _⊎-injection_ _⊎-left-inverse_
------------------------------------------------------------------------
-- Function bundles
_⊎-function_ : Func S T → Func U V → Func (S ⊎ₛ U) (T ⊎ₛ V)
S→T ⊎-function U→V = record
{ to = Sum.map (to S→T) (to U→V)
; cong = Pointwise.map (cong S→T) (cong U→V)
} where open Func
_⊎-equivalence_ : Equivalence S T → Equivalence U V →
Equivalence (S ⊎ₛ U) (T ⊎ₛ V)
S⇔T ⊎-equivalence U⇔V = record
{ to = Sum.map (to S⇔T) (to U⇔V)
; from = Sum.map (from S⇔T) (from U⇔V)
; to-cong = Pointwise.map (to-cong S⇔T) (to-cong U⇔V)
; from-cong = Pointwise.map (from-cong S⇔T) (from-cong U⇔V)
} where open Equivalence
_⊎-injection_ : Injection S T → Injection U V →
Injection (S ⊎ₛ U) (T ⊎ₛ V)
S↣T ⊎-injection U↣V = record
{ to = Sum.map (to S↣T) (to U↣V)
; cong = Pointwise.map (cong S↣T) (cong U↣V)
; injective = ⊎-injective (injective S↣T) (injective U↣V)
} where open Injection
infixr 1 _⊎-surjection_ _⊎-inverse_
_⊎-surjection_ : Surjection S T → Surjection U V →
Surjection (S ⊎ₛ U) (T ⊎ₛ V)
S↠T ⊎-surjection U↠V = record
{ to = Sum.map (to S↠T) (to U↠V)
; cong = Pointwise.map (cong S↠T) (cong U↠V)
; surjective = ⊎-surjective (surjective S↠T) (surjective U↠V)
} where open Surjection
_⊎-bijection_ : Bijection S T → Bijection U V →
Bijection (S ⊎ₛ U) (T ⊎ₛ V)
S⤖T ⊎-bijection U⤖V = record
{ to = Sum.map (to S⤖T) (to U⤖V)
; cong = Pointwise.map (cong S⤖T) (cong U⤖V)
; bijective = ⊎-injective (injective S⤖T) (injective U⤖V) ,
⊎-surjective (surjective S⤖T) (surjective U⤖V)
} where open Bijection
_⊎-leftInverse_ : LeftInverse S T → LeftInverse U V →
LeftInverse (S ⊎ₛ U) (T ⊎ₛ V)
S↩T ⊎-leftInverse U↩V = record
{ to = Sum.map (to S↩T) (to U↩V)
; from = Sum.map (from S↩T) (from U↩V)
; to-cong = Pointwise.map (to-cong S↩T) (to-cong U↩V)
; from-cong = Pointwise.map (from-cong S↩T) (from-cong U↩V)
; inverseˡ = λ { {inj₁ _} {.(inj₁ _)} (inj₁ x) → inj₁ (inverseˡ S↩T x)
; {inj₂ _} {.(inj₂ _)} (inj₂ x) → inj₂ (inverseˡ U↩V x)}
} where open LeftInverse
_⊎-rightInverse_ : RightInverse S T → RightInverse U V →
RightInverse (S ⊎ₛ U) (T ⊎ₛ V)
S↪T ⊎-rightInverse U↪V = record
{ to = Sum.map (to S↪T) (to U↪V)
; from = Sum.map (from S↪T) (from U↪V)
; to-cong = Pointwise.map (to-cong S↪T) (to-cong U↪V)
; from-cong = Pointwise.map (from-cong S↪T) (from-cong U↪V)
; inverseʳ = λ { {inj₁ _} (inj₁ x) → inj₁ (inverseʳ S↪T x)
; {inj₂ _} (inj₂ x) → inj₂ (inverseʳ U↪V x)
}
} where open RightInverse
_⊎-inverse_ : Inverse S T → Inverse U V →
Inverse (S ⊎ₛ U) (T ⊎ₛ V)
S↔T ⊎-inverse U↔V = record
{ to = Sum.map (to S↔T) (to U↔V)
; from = Sum.map (from S↔T) (from U↔V)
; to-cong = Pointwise.map (to-cong S↔T) (to-cong U↔V)
; from-cong = Pointwise.map (from-cong S↔T) (from-cong U↔V)
; inverse = (λ { {inj₁ _} (inj₁ x) → inj₁ (inverseˡ S↔T x)
; {inj₂ _} (inj₂ x) → inj₂ (inverseˡ U↔V x)}) ,
λ { {inj₁ _} (inj₁ x) → inj₁ (inverseʳ S↔T x)
; {inj₂ _} (inj₂ x) → inj₂ (inverseʳ U↔V x)
}
} where open Inverse
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 2.0
_⊎-left-inverse_ = _⊎-leftInverse_
{-# WARNING_ON_USAGE _⊎-left-inverse_
"Warning: _⊎-left-inverse_ was deprecated in v2.0.
Please use _⊎-leftInverse_ instead."
#-}