Skip to content

Commit acdad6c

Browse files
Split Relation.Binary.PropositionalEquality into finer grained pieces that can be used internally to lower the weight of dragging in all of R.B.PE. (#1196)
1 parent 644fafe commit acdad6c

File tree

6 files changed

+211
-156
lines changed

6 files changed

+211
-156
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,20 @@ Other minor additions
305305
```agda
306306
_⇔_ : REL A B ℓ₁ → REL A B ℓ₂ → Set _
307307
```
308+
309+
Refactorings
310+
------------
311+
312+
These changes should be invisble to current users, but can be useful
313+
to authors of large libraries.
314+
315+
* `Relation.Binary.PropositionalEquality`
316+
was getting large and depended on a lot of other parts of the library,
317+
even though its basic functionality did
318+
not. `Relation.Binary.PropositionalEquality.Core` already
319+
existed. Added are
320+
```agda
321+
Relation.Binary.PropositionalEquality.Properties
322+
Relation.Binary.PropositionalEquality.Algebra
323+
```
324+
which factor out some of the dependencies.

src/Axiom/UniquenessOfIdentityProofs.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ open import Relation.Nullary hiding (Irrelevant)
1515
open import Relation.Binary.Core
1616
open import Relation.Binary.Definitions
1717
open import Relation.Binary.PropositionalEquality.Core
18+
open import Relation.Binary.PropositionalEquality.Properties
1819

1920
------------------------------------------------------------------------
2021
-- Definition

src/Relation/Binary/PropositionalEquality.agda

Lines changed: 5 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,15 @@
88

99
module Relation.Binary.PropositionalEquality where
1010

11-
open import Algebra
12-
open import Algebra.Structures
13-
open import Algebra.Definitions
1411
import Axiom.Extensionality.Propositional as Ext
1512
open import Axiom.UniquenessOfIdentityProofs
16-
open import Function.Base
13+
open import Function.Base using (id; _∘_)
1714
open import Function.Equality using (Π; _⟶_; ≡-setoid)
1815
open import Level using (Level; _⊔_)
1916
open import Data.Product using (∃)
2017

2118
open import Relation.Nullary using (yes ; no)
2219
open import Relation.Nullary.Decidable.Core
23-
open import Relation.Unary using (Pred)
2420
open import Relation.Binary
2521
open import Relation.Binary.Indexed.Heterogeneous
2622
using (IndexedSetoid)
@@ -35,69 +31,11 @@ private
3531
C : Set c
3632

3733
------------------------------------------------------------------------
38-
-- Re-export contents of core module
34+
-- Re-export contents modules that make up the parts
3935

4036
open import Relation.Binary.PropositionalEquality.Core public
41-
42-
------------------------------------------------------------------------
43-
-- Some properties
44-
45-
subst₂ : (_∼_ : REL A B ℓ) {x y u v} x ≡ y u ≡ v x ∼ u y ∼ v
46-
subst₂ _ refl refl p = p
47-
48-
cong-app : {A : Set a} {B : A Set b} {f g : (x : A) B x}
49-
f ≡ g (x : A) f x ≡ g x
50-
cong-app refl x = refl
51-
52-
cong₂ : (f : A B C) {x y u v} x ≡ y u ≡ v f x u ≡ f y v
53-
cong₂ f refl refl = refl
54-
55-
------------------------------------------------------------------------
56-
-- Structure of equality as a binary relation
57-
58-
isEquivalence : IsEquivalence {A = A} _≡_
59-
isEquivalence = record
60-
{ refl = refl
61-
; sym = sym
62-
; trans = trans
63-
}
64-
65-
isDecEquivalence : Decidable _≡_ IsDecEquivalence {A = A} _≡_
66-
isDecEquivalence _≟_ = record
67-
{ isEquivalence = isEquivalence
68-
; _≟_ = _≟_
69-
}
70-
71-
isPreorder : IsPreorder {A = A} _≡_ _≡_
72-
isPreorder = record
73-
{ isEquivalence = isEquivalence
74-
; reflexive = id
75-
; trans = trans
76-
}
77-
78-
------------------------------------------------------------------------
79-
-- Bundles for equality as a binary relation
80-
81-
setoid : Set a Setoid _ _
82-
setoid A = record
83-
{ Carrier = A
84-
; _≈_ = _≡_
85-
; isEquivalence = isEquivalence
86-
}
87-
88-
decSetoid : Decidable {A = A} _≡_ DecSetoid _ _
89-
decSetoid _≟_ = record
90-
{ _≈_ = _≡_
91-
; isDecEquivalence = isDecEquivalence _≟_
92-
}
93-
94-
preorder : Set a Preorder _ _ _
95-
preorder A = record
96-
{ Carrier = A
97-
; _≈_ = _≡_
98-
; _∼_ = _≡_
99-
; isPreorder = isPreorder
100-
}
37+
open import Relation.Binary.PropositionalEquality.Properties public
38+
open import Relation.Binary.PropositionalEquality.Algebra public
10139

10240
------------------------------------------------------------------------
10341
-- Pointwise equality
@@ -147,64 +85,7 @@ isPropositional : Set a → Set a
14785
isPropositional A = (a b : A) a ≡ b
14886

14987
------------------------------------------------------------------------
150-
-- Various equality rearrangement lemmas
151-
152-
trans-injectiveˡ : {x y z : A} {p₁ p₂ : x ≡ y} (q : y ≡ z)
153-
trans p₁ q ≡ trans p₂ q p₁ ≡ p₂
154-
trans-injectiveˡ refl = subst₂ _≡_ (trans-reflʳ _) (trans-reflʳ _)
155-
156-
trans-injectiveʳ : {x y z : A} (p : x ≡ y) {q₁ q₂ : y ≡ z}
157-
trans p q₁ ≡ trans p q₂ q₁ ≡ q₂
158-
trans-injectiveʳ refl eq = eq
159-
160-
cong-id : {x y : A} (p : x ≡ y) cong id p ≡ p
161-
cong-id refl = refl
162-
163-
cong-∘ : {x y : A} {f : B C} {g : A B} (p : x ≡ y)
164-
cong (f ∘ g) p ≡ cong f (cong g p)
165-
cong-∘ refl = refl
166-
167-
trans-cong : {x y z : A} {f : A B} (p : x ≡ y) {q : y ≡ z}
168-
trans (cong f p) (cong f q) ≡ cong f (trans p q)
169-
trans-cong refl = refl
170-
171-
cong₂-reflˡ : {_∙_ : A B C} {x u v} (p : u ≡ v)
172-
cong₂ _∙_ refl p ≡ cong (x ∙_) p
173-
cong₂-reflˡ refl = refl
174-
175-
cong₂-reflʳ : {_∙_ : A B C} {x y u} (p : x ≡ y)
176-
cong₂ _∙_ p refl ≡ cong (_∙ u) p
177-
cong₂-reflʳ refl = refl
178-
179-
module _ {P : Pred A p} {x y : A} where
180-
181-
subst-injective : (x≡y : x ≡ y) {p q : P x}
182-
subst P x≡y p ≡ subst P x≡y q p ≡ q
183-
subst-injective refl p≡q = p≡q
184-
185-
subst-subst : {z} (x≡y : x ≡ y) {y≡z : y ≡ z} {p : P x}
186-
subst P y≡z (subst P x≡y p) ≡ subst P (trans x≡y y≡z) p
187-
subst-subst refl = refl
188-
189-
subst-subst-sym : (x≡y : x ≡ y) {p : P y}
190-
subst P x≡y (subst P (sym x≡y) p) ≡ p
191-
subst-subst-sym refl = refl
192-
193-
subst-sym-subst : (x≡y : x ≡ y) {p : P x}
194-
subst P (sym x≡y) (subst P x≡y p) ≡ p
195-
subst-sym-subst refl = refl
196-
197-
subst-∘ : {x y : A} {P : Pred B p} {f : A B}
198-
(x≡y : x ≡ y) {p : P (f x)}
199-
subst (P ∘ f) x≡y p ≡ subst P (cong f x≡y) p
200-
subst-∘ refl = refl
201-
202-
subst-application : {a₁ a₂ b₁ b₂} {A₁ : Set a₁} {A₂ : Set a₂}
203-
(B₁ : A₁ Set b₁) {B₂ : A₂ Set b₂}
204-
{f : A₂ A₁} {x₁ x₂ : A₂} {y : B₁ (f x₁)}
205-
(g : x B₁ (f x) B₂ x) (eq : x₁ ≡ x₂)
206-
subst B₂ eq (g x₁ y) ≡ g x₂ (subst B₁ (cong f eq) y)
207-
subst-application _ _ refl = refl
88+
-- More complex rearrangement lemmas
20889

20990
-- A lemma that is very similar to Lemma 2.4.3 from the HoTT book.
21091

@@ -240,20 +121,6 @@ module _ (_≟_ : Decidable {A = A} _≡_) {x y : A} where
240121
≢-≟-identity : x ≢ y λ ¬eq x ≟ y ≡ no ¬eq
241122
≢-≟-identity ¬eq = dec-no (x ≟ y) ¬eq
242123

243-
------------------------------------------------------------------------
244-
-- Any operation forms a magma over _≡_
245-
246-
isMagma : (_∙_ : Op₂ A) IsMagma _≡_ _∙_
247-
isMagma _∙_ = record
248-
{ isEquivalence = isEquivalence
249-
; ∙-cong = cong₂ _∙_
250-
}
251-
252-
magma : (_∙_ : Op₂ A) Magma _ _
253-
magma _∙_ = record
254-
{ isMagma = isMagma _∙_
255-
}
256-
257124
------------------------------------------------------------------------
258125
-- DEPRECATED NAMES
259126
------------------------------------------------------------------------
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Propositional (intensional) equality - Algebraic structures
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K --safe #-}
8+
9+
module Relation.Binary.PropositionalEquality.Algebra where
10+
11+
open import Algebra
12+
open import Level
13+
open import Relation.Binary.PropositionalEquality.Core
14+
open import Relation.Binary.PropositionalEquality.Properties
15+
16+
private
17+
variable
18+
a : Level
19+
A : Set a
20+
21+
------------------------------------------------------------------------
22+
-- Any operation forms a magma over _≡_
23+
24+
isMagma : (_∙_ : Op₂ A) IsMagma _≡_ _∙_
25+
isMagma _∙_ = record
26+
{ isEquivalence = isEquivalence
27+
; ∙-cong = cong₂ _∙_
28+
}
29+
30+
magma : (_∙_ : Op₂ A) Magma _ _
31+
magma _∙_ = record
32+
{ isMagma = isMagma _∙_
33+
}

src/Relation/Binary/PropositionalEquality/Core.agda

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ open import Relation.Nullary using (¬_)
2121
private
2222
variable
2323
a b ℓ : Level
24-
A : Set a
25-
B : Set b
24+
A B C : Set a
2625

2726
------------------------------------------------------------------------
2827
-- Propositional equality
@@ -48,6 +47,16 @@ subst P refl p = p
4847
cong : (f : A B) {x y} x ≡ y f x ≡ f y
4948
cong f refl = refl
5049

50+
subst₂ : (_∼_ : REL A B ℓ) {x y u v} x ≡ y u ≡ v x ∼ u y ∼ v
51+
subst₂ _ refl refl p = p
52+
53+
cong-app : {A : Set a} {B : A Set b} {f g : (x : A) B x}
54+
f ≡ g (x : A) f x ≡ g x
55+
cong-app refl x = refl
56+
57+
cong₂ : (f : A B C) {x y u v} x ≡ y u ≡ v f x u ≡ f y v
58+
cong₂ f refl refl = refl
59+
5160
respˡ : (∼ : Rel A ℓ) ∼ Respectsˡ _≡_
5261
respˡ _∼_ refl x∼y = x∼y
5362

@@ -57,22 +66,6 @@ respʳ _∼_ refl x∼y = x∼y
5766
resp₂ : (∼ : Rel A ℓ) ∼ Respects₂ _≡_
5867
resp₂ _∼_ = respʳ _∼_ , respˡ _∼_
5968

60-
------------------------------------------------------------------------
61-
-- Various equality rearrangement lemmas
62-
63-
trans-reflʳ : {x y : A} (p : x ≡ y) trans p refl ≡ p
64-
trans-reflʳ refl = refl
65-
66-
trans-assoc : {x y z u : A} (p : x ≡ y) {q : y ≡ z} {r : z ≡ u}
67-
trans (trans p q) r ≡ trans p (trans q r)
68-
trans-assoc refl = refl
69-
70-
trans-symˡ : {x y : A} (p : x ≡ y) trans (sym p) p ≡ refl
71-
trans-symˡ refl = refl
72-
73-
trans-symʳ : {x y : A} (p : x ≡ y) trans p (sym p) ≡ refl
74-
trans-symʳ refl = refl
75-
7669
------------------------------------------------------------------------
7770
-- Properties of _≢_
7871

0 commit comments

Comments
 (0)