Debian Codegraph @

src/Function/Equality.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- This module is DEPRECATED.
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Function.Equality where
10
11 {-# WARNING_ON_IMPORT
12 "Function.Equality was deprecated in v2.0.
13 Use the standard function hierarchy in Function/Function.Bundles instead."
14 #-}
15
16 import Function.Base as Fun
17 open import Level using (Level; _⊔_)
18 open import Relation.Binary.Bundles using (Setoid)
19 open import Relation.Binary.Indexed.Heterogeneous
20 using (IndexedSetoid; _=[_]⇒_)
21 import Relation.Binary.Indexed.Heterogeneous.Construct.Trivial
22 as Trivial
23 import Relation.Binary.PropositionalEquality.Core as ≡
24 import Relation.Binary.PropositionalEquality.Properties as ≡
25
26 ------------------------------------------------------------------------
27 -- Functions which preserve equality
28
29 record Π {f₁ f₂ t₁ t₂}
30 (From : Setoid f₁ f₂)
31 (To : IndexedSetoid (Setoid.Carrier From) t₁ t₂) :
32 Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where
33 infixl 5 _⟨$⟩_
34 field
35 _⟨$⟩_ : (x : Setoid.Carrier From) → IndexedSetoid.Carrier To x
36 cong : Setoid._≈_ From =[ _⟨$⟩_ ]⇒ IndexedSetoid._≈_ To
37 {-# WARNING_ON_USAGE Π
38 "Warning: Π was deprecated in v2.0.
39 Please use Function.Dependent.Bundles.Func instead."
40 #-}
41
42 open Π public
43
44 infixr 0 _⟶_
45
46 _⟶_ : ∀ {f₁ f₂ t₁ t₂} → Setoid f₁ f₂ → Setoid t₁ t₂ → Set _
47 From ⟶ To = Π From (Trivial.indexedSetoid To)
48 {-# WARNING_ON_USAGE _⟶_
49 "Warning: _⟶_ was deprecated in v2.0.
50 Please use Function.(Bundles.)Func instead."
51 #-}
52
53 ------------------------------------------------------------------------
54 -- Identity and composition.
55
56 id : ∀ {a₁ a₂} {A : Setoid a₁ a₂} → A ⟶ A
57 id = record { _⟨$⟩_ = Fun.id; cong = Fun.id }
58 {-# WARNING_ON_USAGE id
59 "Warning: id was deprecated in v2.0.
60 Please use Function.Construct.Identity.function instead."
61 #-}
62
63 infixr 9 _∘_
64
65 _∘_ : ∀ {a₁ a₂} {A : Setoid a₁ a₂}
66 {b₁ b₂} {B : Setoid b₁ b₂}
67 {c₁ c₂} {C : Setoid c₁ c₂} →
68 B ⟶ C → A ⟶ B → A ⟶ C
69 f ∘ g = record
70 { _⟨$⟩_ = Fun._∘_ (_⟨$⟩_ f) (_⟨$⟩_ g)
71 ; cong = Fun._∘_ (cong f) (cong g)
72 }
73 {-# WARNING_ON_USAGE _∘_
74 "Warning: _∘_ was deprecated in v2.0.
75 Please use Function.Construct.Composition.function instead."
76 #-}
77
78 -- Constant equality-preserving function.
79
80 const : ∀ {a₁ a₂} {A : Setoid a₁ a₂}
81 {b₁ b₂} {B : Setoid b₁ b₂} →
82 Setoid.Carrier B → A ⟶ B
83 const {B = B} b = record
84 { _⟨$⟩_ = Fun.const b
85 ; cong = Fun.const (Setoid.refl B)
86 }
87 {-# WARNING_ON_USAGE const
88 "Warning: const was deprecated in v2.0.
89 Please use Function.Construct.Constant.function instead."
90 #-}
91
92 ------------------------------------------------------------------------
93 -- Function setoids
94
95 -- Dependent.
96
97 setoid : ∀ {f₁ f₂ t₁ t₂}
98 (From : Setoid f₁ f₂) →
99 IndexedSetoid (Setoid.Carrier From) t₁ t₂ →
100 Setoid _ _
101 setoid From To = record
102 { Carrier = Π From To
103 ; _≈_ = λ f g → ∀ {x y} → x ≈₁ y → f ⟨$⟩ x ≈₂ g ⟨$⟩ y
104 ; isEquivalence = record
105 { refl = λ {f} → cong f
106 ; sym = λ f∼g x∼y → To.sym (f∼g (From.sym x∼y))
107 ; trans = λ f∼g g∼h x∼y → To.trans (f∼g From.refl) (g∼h x∼y)
108 }
109 }
110 where
111 open module From = Setoid From using () renaming (_≈_ to _≈₁_)
112 open module To = IndexedSetoid To using () renaming (_≈_ to _≈₂_)
113
114 -- Non-dependent.
115
116 infixr 0 _⇨_
117
118 _⇨_ : ∀ {f₁ f₂ t₁ t₂} → Setoid f₁ f₂ → Setoid t₁ t₂ → Setoid _ _
119 From ⇨ To = setoid From (Trivial.indexedSetoid To)
120
121 -- A variant of setoid which uses the propositional equality setoid
122 -- for the domain, and a more convenient definition of _≈_.
123
124 ≡-setoid : ∀ {f t₁ t₂} (From : Set f) → IndexedSetoid From t₁ t₂ → Setoid _ _
125 ≡-setoid From To = record
126 { Carrier = (x : From) → Carrier x
127 ; _≈_ = λ f g → ∀ x → f x ≈ g x
128 ; isEquivalence = record
129 { refl = λ {f} x → refl
130 ; sym = λ f∼g x → sym (f∼g x)
131 ; trans = λ f∼g g∼h x → trans (f∼g x) (g∼h x)
132 }
133 } where open IndexedSetoid To
134
135 -- Parameter swapping function.
136
137 flip : ∀ {a₁ a₂} {A : Setoid a₁ a₂}
138 {b₁ b₂} {B : Setoid b₁ b₂}
139 {c₁ c₂} {C : Setoid c₁ c₂} →
140 A ⟶ B ⇨ C → B ⟶ A ⇨ C
141 flip {B = B} f = record
142 { _⟨$⟩_ = λ b → record
143 { _⟨$⟩_ = λ a → f ⟨$⟩ a ⟨$⟩ b
144 ; cong = λ a₁≈a₂ → cong f a₁≈a₂ (Setoid.refl B) }
145 ; cong = λ b₁≈b₂ a₁≈a₂ → cong f a₁≈a₂ b₁≈b₂
146 }
147
148 →-to-⟶ : ∀ {a b ℓ} {A : Set a} {B : Setoid b ℓ} →
149 (A → Setoid.Carrier B) → ≡.setoid A ⟶ B
150 →-to-⟶ {B = B} to = record
151 { _⟨$⟩_ = to
152 ; cong = λ { ≡.refl → Setoid.refl B }
153 }