-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHedberg.agda
151 lines (134 loc) · 5.76 KB
/
Hedberg.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
{-# OPTIONS --without-K #-}
open import Agda.Primitive
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; module ≡-Reasoning)
renaming (isPropositional to isProp; sym to _⁻¹; trans to infixr 9 _∘_;
subst to transport; cong to ap {- ; dcong to apd-})
open ≡-Reasoning
open import Data.Empty
open import Data.Product
open import Relation.Nullary
open import Function.Base using (_$_)
variable
ℓ ℓ' : Level
A X : Set ℓ
B C : A → Set ℓ
a b c x y : A
{- Some properties of equality -}
-- dependent ap (should be `dcong` in Properties)
apd : (f : (x : A) → B x) → (p : a ≡ b) → transport B p (f a) ≡ f b
apd _ refl = refl
-- left inverse on the left
p⁻¹∘p≡refl : (p : a ≡ b) → p ⁻¹ ∘ p ≡ refl
p⁻¹∘p≡refl refl = refl
-- right identity on the left
p∘refl≡p : (p : a ≡ b) → p ∘ refl ≡ p
p∘refl≡p refl = refl
-- left identity on the right
q≡refl∘q : (q : a ≡ b) → q ≡ refl ∘ q
q≡refl∘q refl = refl
-- left whisker
infixr 9 _◁_
_◁_ : ∀ {p q : b ≡ c} → (r : a ≡ b) → p ≡ q → r ∘ p ≡ r ∘ q
_ ◁ refl = refl
-- negations are mere propositions up to function extensionality
isProp¬P : isProp (¬ A)
isProp¬P ¬P _ = funext (λ p → ⊥-elim (¬P p))
where postulate
funext : ∀ {f g : A → X} → (∀ a → f a ≡ g a) → f ≡ g
{- Lemma 2.9.6
If f ≡ g across p:
p
B x → C x ═══ B y → C y
Then ∀ b, f b ≡ g b across p:
f
B x ┄──╼ C x
┊ ┊
p │ │ p
╽ ╽
B y ┄──╼ C y
g
-}
lem2·9·6 : (p : x ≡ y) → (f : B x → C x) → (g : B y → C y) →
transport (λ y → B y → C y) p f ≡ g →
∀ b → transport C p (f b) ≡ g (transport B p b)
lem2·9·6 refl _ _ refl _ = refl
{- Specialization of lem2·9·6:
Given an identity path p : x ≡ x,
applying f first then transporting across p is equal to
transporting across p first then applying f.
f x
B x ┄──╼ C x
┊ ┊
p │ │ p
╽ ╽
B x ┄──╼ C x
f x
Note that this can't be proven directly by pattern-matching on p to refl
because that would require axiom K.
-}
lem2·9·6' : ∀ x → (p : x ≡ x) → (f : ∀ x → B x → C x) →
∀ b → transport C p (f x b) ≡ f x (transport B p b)
lem2·9·6' x p f = lem2·9·6 p (f x) (f x) (apd f p)
{- Hedberg's theorem (Theorem 7.2.2)
If there is some relation R on elements of X where
* R is a mere relation;
* R is reflexive; and
* R implies equality,
then identities on elements of X are equal to refl.
(Consequently, equalities on elements of X satisfy UIP.)
-}
hedberg : ∀ (R : X → X → Set ℓ) →
(rel : ∀ {x y} → isProp (R x y)) →
(ρ : ∀ {x} → R x x) →
(f : ∀ x y → R x y → x ≡ y) →
∀ (x : X) → (p : x ≡ x) → p ≡ refl
hedberg R rel ρ f x p = p∘q≡p→q≡refl _ _ $
begin f x x ρ ∘ p
≡⟨ q∘p≡p*q p (f x x ρ) ⟩ transport _ p (f x x ρ)
≡⟨ lem2·9·6' x p (f x) ρ ⟩ f x x (transport (R x) p ρ)
≡⟨ ap (f x x) (rel (transport (R x) p ρ) ρ) ⟩ f x x ρ ∎
where
q∘p≡p*q : (p : a ≡ b) → (q : a ≡ a) → q ∘ p ≡ transport (λ y → a ≡ y) p q
q∘p≡p*q refl q = p∘refl≡p q
p∘q≡p→q≡refl : (p : a ≡ b) → (q : b ≡ b) → p ∘ q ≡ p → q ≡ refl
p∘q≡p→q≡refl refl q refl∘q≡refl = (q≡refl∘q q) ∘ refl∘q≡refl
-- If X is discrete (i.e. has decidable equality), then all identities of X are equal to refl.
-- This instantiates Hedberg's theorem with the reflexive mere relation of irrefutability of equality;
-- discreteness implies separability (i.e. has stable equality, i.e. where irrefutability implies inhabitance).
hedbergDiscrete : (∀ (x y : X) → Dec (x ≡ y)) → ∀ (x : X) → (p : x ≡ x) → p ≡ refl
hedbergDiscrete {X = X} dec = hedberg (λ x y → ¬ ¬ x ≡ y) isProp¬P (λ ¬x≡x → ¬x≡x refl) dne
where
dne : ∀ (x y : X) → ¬ ¬ x ≡ y → x ≡ y
dne x y ¬¬x≡y with dec x y
... | yes x≡y = x≡y
... | no ¬x≡y = ⊥-elim (¬¬x≡y ¬x≡y)
{- Hedberg's theorem (https://www.cs.bham.ac.uk/~mhe/GeneralizedHedberg/html/GeneralizedHedberg.html)
If X is path-collapsible, i.e. for elements x, y of X
there is a constant endofunction x ≡ y → x ≡ y,
then identities on elements of X are equal to refl.
(Consequently, equalities on elements of X satisfy UIP.)
-}
hedberg' : (∀ (x y : X) → Σ[ f ∈ (x ≡ y → x ≡ y) ] ∀ p q → f p ≡ f q) →
∀ (x : X) → (p : x ≡ x) → p ≡ refl
hedberg' pathColl x p =
begin p
≡⟨ p≡frefl⁻¹∘fp p ⟩ (f refl)⁻¹ ∘ f p
≡⟨ (f refl)⁻¹ ◁ h p refl ⟩ (f refl)⁻¹ ∘ f refl
≡⟨ p⁻¹∘p≡refl (f refl) ⟩ refl ∎
where
f = λ {y} → proj₁ (pathColl x y)
h = λ {y} → proj₂ (pathColl x y)
p≡frefl⁻¹∘fp : (p : x ≡ y) → p ≡ (f refl)⁻¹ ∘ f p
p≡frefl⁻¹∘fp refl = (p⁻¹∘p≡refl (f refl))⁻¹
-- If X is discrete (i.e. has decidable equality), then all identities of X are equal to refl.
-- This uses the fact that if X is discrete then X is path-collapsible.
-- Curiously, this method does not rely on function extensionality,
-- where it was previously needed to show that irrefutability is a mere relation.
hedbergDiscrete' : (∀ (x y : X) → Dec (x ≡ y)) → ∀ (x : X) → (p : x ≡ x) → p ≡ refl
hedbergDiscrete' {X = X} dec = hedberg' pathColl
where
pathColl : ∀ (x y : X) → Σ[ f ∈ (x ≡ y → x ≡ y) ] ∀ p q → f p ≡ f q
pathColl x y with dec x y
... | yes x≡y = (λ _ → x≡y) , (λ _ _ → refl)
... | no ¬x≡y = (λ x≡y → ⊥-elim (¬x≡y x≡y)) , (λ p q → ⊥-elim (¬x≡y p))