Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 130 lines (96 sloc) 4.727 kB
22b6027 @favonia Dramatic changes from the previous version
authored
1 ------------------------------------------------------------------------
2 -- Path
3 ------------------------------------------------------------------------
4
5 -- Copyright (c) 2012 Favonia
6 -- Copyright (c) 2011-2012 Nils Anders Danielsson
7
8 {-# OPTIONS --without-K #-}
9
10 module Path where
11
12 open import Prelude
13
14 ------------------------------------------------------------------------
15 -- Formation and introduction
16
17 private
8b6fbff @favonia Pi1(S1) = Z and other cleanups
authored
18 data Path′ {ℓ} {A : Set ℓ} (x : A) : A → Set ℓ where
19 refl′ : Path′ x x
22b6027 @favonia Dramatic changes from the previous version
authored
20
21 infix 4 _≡_
22
23 _≡_ : {ℓ} {A : Set ℓ} (x : A) A Set ℓ
8b6fbff @favonia Pi1(S1) = Z and other cleanups
authored
24 _≡_ = Path′
22b6027 @favonia Dramatic changes from the previous version
authored
25
8b6fbff @favonia Pi1(S1) = Z and other cleanups
authored
26 Path : {ℓ} {A : Set ℓ} (x : A) A Set ℓ
27 Path = Path′
22b6027 @favonia Dramatic changes from the previous version
authored
28
29 refl : {ℓ} {A : Set ℓ} (x : A) x ≡ x
30 refl _ = refl′
31
32 ------------------------------------------------------------------------
33 -- Elimination and computation
34
35 -- I think dependent pattern matching is fine, because it seems that
8b6fbff @favonia Pi1(S1) = Z and other cleanups
authored
36 -- we can construct another equality with its destructor exposed and
37 -- show two equalities are equivalent. However the destructor is still
38 -- hidden so that people need to write elim explicitly (at least for
39 -- this datatype).
22b6027 @favonia Dramatic changes from the previous version
authored
40
41 elim : {ℓ₁ ℓ₂} {A : Set ℓ₁} (P : {x y : A} x ≡ y Set ℓ₂)
42 (∀ x P (refl x))
43 {x y} (x≡y : x ≡ y) P x≡y
44 elim P r refl′ = r _
45
46 ------------------------------------------------------------------------
d691d6c @favonia A short proof of abelianness of Omega2(A).
authored
47 -- Alternative elimination/computation rules
8b6fbff @favonia Pi1(S1) = Z and other cleanups
authored
48
49 elim′ : {ℓ₁ ℓ₂} {A : Set ℓ₁} {x : A} (P : {y : A} x ≡ y Set ℓ₂)
50 P (refl x) {y} (x≡y : x ≡ y) P x≡y
51 -- elim′ P r refl′ = r
52 elim′ {ℓ₂ = ℓ₂} {A = A} P r p =
53 elim
54 (λ {x y} p (P : {y : A} x ≡ y Set ℓ₂) P (refl x) P p)
55 (λ x P r r)
56 p P r
57
d691d6c @favonia A short proof of abelianness of Omega2(A).
authored
58 elim″ : {ℓ₁ ℓ₂} {A : Set ℓ₁} {y : A} (P : {x : A} x ≡ y Set ℓ₂)
59 P (refl y) {x} (x≡y : x ≡ y) P x≡y
60 -- elim′ P r refl′ = r
61 elim″ {ℓ₂ = ℓ₂} {A = A} P r p =
62 elim
63 (λ {x y} p (P : {x : A} x ≡ y Set ℓ₂) P (refl y) P p)
64 (λ x P r r)
65 p P r
66
8b6fbff @favonia Pi1(S1) = Z and other cleanups
authored
67 ------------------------------------------------------------------------
22b6027 @favonia Dramatic changes from the previous version
authored
68 -- Congruence (respect or map) and substitutivity (tranport)
69
70 cong : {ℓ₁ ℓ₂} {A : Set ℓ₁} {B : Set ℓ₂}
71 (f : A B) {x y : A} x ≡ y f x ≡ f y
72 cong f = elim (λ {u v} _ f u ≡ f v) (λ x refl (f x))
73
74 subst : {ℓ₁ ℓ₂} {A : Set ℓ₁} (P : A Set ℓ₂) {x y : A}
75 x ≡ y P x P y
76 subst P = elim (λ {u v} _ P u P v) (λ x p p)
77
78 ------------------------------------------------------------------------
79 -- Transitivity and symmetry
80
81 -- Here we makes "trans (refl _) p" definitionally equal to "p".
82 -- The reason is that we usually need to deal with "trans (refl (trans ...))"
83 -- in a complex proof of equivalence between paths.
84 -- (This is different from the intension of Nils' original code.)
85
86 trans : {ℓ} {A : Set ℓ} {x y z : A} x ≡ y y ≡ z x ≡ z
87 trans {x = x} {y} {z} x≡y =
88 elim
89 (λ {x y} x≡y y ≡ z x ≡ z)
90 (λ _ id)
91 x≡y
92
93 sym : {ℓ} {A : Set ℓ} {x y : A} x ≡ y y ≡ x
94 sym {x = x} x≡y = subst (λ z x ≡ z z ≡ x) x≡y id x≡y
95
96 ------------------------------------------------------------------------
97 -- A must-have for beautiful proofs
98
99 infix 0 finally
100 infixr 0 _≡⟨_⟩_
101
102 _≡⟨_⟩_ : {a} {A : Set a} x {y z : A} x ≡ y y ≡ z x ≡ z
103 _ ≡⟨ x≡y ⟩ y≡z = trans x≡y y≡z
104
105 finally : {a} {A : Set a} (x y : A) x ≡ y x ≡ y
106 finally _ _ x≡y = x≡y
107
108 syntax finally x y x≡y = x ≡⟨ x≡y ⟩∎ y ∎
109
110 ------------------------------------------------------------------------
111 -- Some terminologies
112
113 -- A type is contractible if it is inhabited and all elements are
114 -- equal.
115 Contractible : {ℓ} Set ℓ Set ℓ
116 Contractible A =λ (x : A) y x ≡ y
e3ee59b @favonia Significant refactoring.
authored
117
118 -- Singleton x is a set which contains all elements which are equal
119 -- to x.
120 Singleton : {ℓ} {A : Set ℓ} A Set ℓ
121 Singleton x =λ y y ≡ x
122
123 -- Extensionality for (non-dependent) functions of a certain type.
124 Extensionality : {ℓ₁ ℓ₂} Set ℓ₁ Set ℓ₂ Set (ℓ₁ ⊔ ℓ₂)
125 Extensionality A B = {f g : A B} (∀ x f x ≡ g x) f ≡ g
126
127 -- Extensionality for dependent functions of a certain type.
128 Extensionality[dep] : {ℓ₁ ℓ₂} (A : Set ℓ₁) (A Set ℓ₂) Set (ℓ₁ ⊔ ℓ₂)
129 Extensionality[dep] A B = {f g : (x : A) B x} (∀ x f x ≡ g x) f ≡ g
Something went wrong with that request. Please try again.