-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathEquality.agda
153 lines (127 loc) · 4.96 KB
/
Equality.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
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED.
------------------------------------------------------------------------
{-# OPTIONS --cubical-compatible --safe #-}
module Function.Equality where
{-# WARNING_ON_IMPORT
"Function.Equality was deprecated in v2.0.
Use the standard function hierarchy in Function/Function.Bundles instead."
#-}
import Function.Base as Fun
open import Level using (Level; _⊔_)
open import Relation.Binary.Bundles using (Setoid)
open import Relation.Binary.Indexed.Heterogeneous
using (IndexedSetoid; _=[_]⇒_)
import Relation.Binary.Indexed.Heterogeneous.Construct.Trivial
as Trivial
import Relation.Binary.PropositionalEquality.Core as ≡
import Relation.Binary.PropositionalEquality.Properties as ≡
------------------------------------------------------------------------
-- Functions which preserve equality
record Π {f₁ f₂ t₁ t₂}
(From : Setoid f₁ f₂)
(To : IndexedSetoid (Setoid.Carrier From) t₁ t₂) :
Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where
infixl 5 _⟨$⟩_
field
_⟨$⟩_ : (x : Setoid.Carrier From) → IndexedSetoid.Carrier To x
cong : Setoid._≈_ From =[ _⟨$⟩_ ]⇒ IndexedSetoid._≈_ To
{-# WARNING_ON_USAGE Π
"Warning: Π was deprecated in v2.0.
Please use Function.Dependent.Bundles.Func instead."
#-}
open Π public
infixr 0 _⟶_
_⟶_ : ∀ {f₁ f₂ t₁ t₂} → Setoid f₁ f₂ → Setoid t₁ t₂ → Set _
From ⟶ To = Π From (Trivial.indexedSetoid To)
{-# WARNING_ON_USAGE _⟶_
"Warning: _⟶_ was deprecated in v2.0.
Please use Function.(Bundles.)Func instead."
#-}
------------------------------------------------------------------------
-- Identity and composition.
id : ∀ {a₁ a₂} {A : Setoid a₁ a₂} → A ⟶ A
id = record { _⟨$⟩_ = Fun.id; cong = Fun.id }
{-# WARNING_ON_USAGE id
"Warning: id was deprecated in v2.0.
Please use Function.Construct.Identity.function instead."
#-}
infixr 9 _∘_
_∘_ : ∀ {a₁ a₂} {A : Setoid a₁ a₂}
{b₁ b₂} {B : Setoid b₁ b₂}
{c₁ c₂} {C : Setoid c₁ c₂} →
B ⟶ C → A ⟶ B → A ⟶ C
f ∘ g = record
{ _⟨$⟩_ = Fun._∘_ (_⟨$⟩_ f) (_⟨$⟩_ g)
; cong = Fun._∘_ (cong f) (cong g)
}
{-# WARNING_ON_USAGE _∘_
"Warning: _∘_ was deprecated in v2.0.
Please use Function.Construct.Composition.function instead."
#-}
-- Constant equality-preserving function.
const : ∀ {a₁ a₂} {A : Setoid a₁ a₂}
{b₁ b₂} {B : Setoid b₁ b₂} →
Setoid.Carrier B → A ⟶ B
const {B = B} b = record
{ _⟨$⟩_ = Fun.const b
; cong = Fun.const (Setoid.refl B)
}
{-# WARNING_ON_USAGE const
"Warning: const was deprecated in v2.0.
Please use Function.Construct.Constant.function instead."
#-}
------------------------------------------------------------------------
-- Function setoids
-- Dependent.
setoid : ∀ {f₁ f₂ t₁ t₂}
(From : Setoid f₁ f₂) →
IndexedSetoid (Setoid.Carrier From) t₁ t₂ →
Setoid _ _
setoid From To = record
{ Carrier = Π From To
; _≈_ = λ f g → ∀ {x y} → x ≈₁ y → f ⟨$⟩ x ≈₂ g ⟨$⟩ y
; isEquivalence = record
{ refl = λ {f} → cong f
; sym = λ f∼g x∼y → To.sym (f∼g (From.sym x∼y))
; trans = λ f∼g g∼h x∼y → To.trans (f∼g From.refl) (g∼h x∼y)
}
}
where
open module From = Setoid From using () renaming (_≈_ to _≈₁_)
open module To = IndexedSetoid To using () renaming (_≈_ to _≈₂_)
-- Non-dependent.
infixr 0 _⇨_
_⇨_ : ∀ {f₁ f₂ t₁ t₂} → Setoid f₁ f₂ → Setoid t₁ t₂ → Setoid _ _
From ⇨ To = setoid From (Trivial.indexedSetoid To)
-- A variant of setoid which uses the propositional equality setoid
-- for the domain, and a more convenient definition of _≈_.
≡-setoid : ∀ {f t₁ t₂} (From : Set f) → IndexedSetoid From t₁ t₂ → Setoid _ _
≡-setoid From To = record
{ Carrier = (x : From) → Carrier x
; _≈_ = λ f g → ∀ x → f x ≈ g x
; isEquivalence = record
{ refl = λ {f} x → refl
; sym = λ f∼g x → sym (f∼g x)
; trans = λ f∼g g∼h x → trans (f∼g x) (g∼h x)
}
} where open IndexedSetoid To
-- Parameter swapping function.
flip : ∀ {a₁ a₂} {A : Setoid a₁ a₂}
{b₁ b₂} {B : Setoid b₁ b₂}
{c₁ c₂} {C : Setoid c₁ c₂} →
A ⟶ B ⇨ C → B ⟶ A ⇨ C
flip {B = B} f = record
{ _⟨$⟩_ = λ b → record
{ _⟨$⟩_ = λ a → f ⟨$⟩ a ⟨$⟩ b
; cong = λ a₁≈a₂ → cong f a₁≈a₂ (Setoid.refl B) }
; cong = λ b₁≈b₂ a₁≈a₂ → cong f a₁≈a₂ b₁≈b₂
}
→-to-⟶ : ∀ {a b ℓ} {A : Set a} {B : Setoid b ℓ} →
(A → Setoid.Carrier B) → ≡.setoid A ⟶ B
→-to-⟶ {B = B} to = record
{ _⟨$⟩_ = to
; cong = λ { ≡.refl → Setoid.refl B }
}