-
Notifications
You must be signed in to change notification settings - Fork 18
/
Lec6.agda
197 lines (168 loc) · 6.08 KB
/
Lec6.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
module Lec6 where
open import IxCon public
data Sort : Set where set prop : Sort
mutual
data TU : Sort -> Set where
Zero' One' : {s : Sort} -> TU s
Two' : TU set
Sg' : {s : Sort}(S : TU s)(T : <! S !>TU -> TU s) -> TU s
Pi' : {s : Sort}(S : TU set)(T : <! S !>TU -> TU s) -> TU s
Tree' : (I : TU set)
(F : <! I !>TU -> Sg (TU set) \ S ->
<! S !>TU -> Sg (TU set) \ P ->
<! P !>TU -> <! I !>TU )
(i : <! I !>TU) -> (TU set)
Prf' : TU prop -> TU set
<!_!>TU : forall {s} -> TU s -> Set
<! Zero' !>TU = Zero
<! One' !>TU = One
<! Two' !>TU = Two
<! Sg' S T !>TU = Sg <! S !>TU \ s -> <! T s !>TU
<! Pi' S T !>TU = (s : <! S !>TU) -> <! T s !>TU
<! Tree' I F i !>TU = ITree
( (\ i -> <! fst (F i) !>TU)
<i (\ i s -> <! fst (snd (F i) s) !>TU)
$ (\ i s p -> snd (snd (F i) s) p)
) i
<! Prf' P !>TU = <! P !>TU
data Favourite (f : Nat -> Nat) : Set where
favourite : (\ x -> zero +Nat x) == f -> Favourite f
plusZero : forall x -> x == x +Nat zero
plusZero zero = refl
plusZero (suc x) = cong suc (plusZero x)
closedFact : (\ x -> zero +Nat x) == (\ x -> x +Nat zero)
closedFact = extensionality _ _ plusZero
myTerm = subst closedFact Favourite (favourite refl)
help : Favourite (λ x → x +Nat 0)
help = favourite closedFact
-- remark on intensional predicates
-- remark on the need for a more type-based computation mechanism
_/\_ : TU prop -> TU prop -> TU prop
P /\ Q = Sg' P \ _ -> Q
_=>_ : TU prop -> TU prop -> TU prop
P => Q = Pi' (Prf' P) \ _ -> Q
mutual
EQ : (X Y : TU set) -> TU prop * (<! X !>TU -> <! Y !>TU -> TU prop)
_<->_ : TU set -> TU set -> TU prop
X <-> Y = fst (EQ X Y)
Eq : (X : TU set)(x : <! X !>TU) -> (Y : TU set)(y : <! Y !>TU) -> TU prop
Eq X x Y y = snd (EQ X Y) x y
EQ Zero' Zero' = One' , \ _ _ -> One'
EQ One' One' = One' , \ _ _ -> One'
EQ Two' Two' = One' , (\
{ tt tt -> One'
; ff ff -> One'
; _ _ -> Zero'
})
EQ (Sg' S T) (Sg' S' T')
= ((S <-> S') /\ Pi' S \ s -> Pi' S' \ s' -> Eq S s S' s' => (T s <-> T' s'))
, (\ { (s , t) (s' , t') -> Eq S s S' s' /\ Eq (T s) t (T' s') t' })
EQ (Pi' S T) (Pi' S' T')
= ((S' <-> S) /\ Pi' S' \ s' -> Pi' S \ s -> Eq S' s' S s => (T s <-> T' s'))
, (\ f f' -> Pi' S \ s -> Pi' S' \ s' -> Eq S s S' s' =>
Eq (T s) (f s) (T' s') (f' s'))
EQ (Tree' I F i) (Tree' I' F' i')
= ((I <-> I') /\ (Eq I i I' i' /\
Pi' I \ i -> Pi' I' \ i' -> Eq I i I' i' =>
let (S , k) = F i ; (S' , k') = F' i'
in (S <-> S') /\ Pi' S \ s -> Pi' S' \ s' -> Eq S s S' s' =>
let (P , r) = k s ; (P' , r') = k' s'
in (P' <-> P) /\ Pi' P' \ p' -> Pi' P \ p -> Eq P' p' P p =>
Eq I (r p) I' (r' p') ))
, teq i i' where
teq : (i : <! I !>TU)(i' : <! I' !>TU) ->
<! Tree' I F i !>TU -> <! Tree' I' F' i' !>TU -> TU prop
teq i i' <$ s , k $> <$ s' , k' $>
= let (S , K) = F i ; (S' , K') = F' i'
(P , r) = K s ; (P' , r') = K' s'
in Eq S s S' s' /\
Pi' P \ p -> Pi' P' \ p' -> Eq P p P' p' =>
teq (r p) (r' p') (k p) (k' p')
EQ _ _ = Zero' , \ _ _ -> One'
coe : (X Y : TU set) -> <! X <-> Y !>TU -> <! X !>TU -> <! Y !>TU
postulate
coh : (X Y : TU set)(Q : <! X <-> Y !>TU)(x : <! X !>TU) ->
<! Eq X x Y (coe X Y Q x) !>TU
coe Zero' Zero' <> x = x
coe Zero' One' () x
coe Zero' Two' () x
coe Zero' (Sg' Y T) () x
coe Zero' (Pi' Y T) () x
coe Zero' (Tree' Y F i) () x
coe Zero' (Prf' Y) () x
coe One' Zero' () x
coe One' One' <> x = x
coe One' Two' () x
coe One' (Sg' Y T) () x
coe One' (Pi' Y T) () x
coe One' (Tree' Y F i) () x
coe One' (Prf' Y) () x
coe Two' Zero' () x
coe Two' One' () x
coe Two' Two' <> x = x
coe Two' (Sg' Y T) () x
coe Two' (Pi' Y T) () x
coe Two' (Tree' Y F i) () x
coe Two' (Prf' Y) () x
coe (Sg' X T) Zero' () x
coe (Sg' X T) One' () x
coe (Sg' X T) Two' () x
coe (Sg' S T) (Sg' S' T') (SQ , TQ) (s , t)
= let s' = coe S S' SQ s
t' = coe (T s) (T' s') (TQ s s' (coh S S' SQ s)) t
in s' , t'
coe (Sg' X T) (Pi' Y T₁) () x
coe (Sg' X T) (Tree' Y F i) () x
coe (Sg' X T) (Prf' Y) () x
coe (Pi' X T) Zero' () x
coe (Pi' X T) One' () x
coe (Pi' X T) Two' () x
coe (Pi' X T) (Sg' Y T₁) () x
coe (Pi' S T) (Pi' S' T') (SQ , TQ) f = \ s' ->
let s = coe S' S SQ s'
t = f s
in coe (T s) (T' s') (TQ s' s (coh S' S SQ s')) t
coe (Pi' X T) (Tree' Y F i) () x
coe (Pi' X T) (Prf' Y) () x
coe (Tree' X F i) Zero' () x
coe (Tree' X F i) One' () x
coe (Tree' X F i) Two' () x
coe (Tree' X F i) (Sg' Y T) () x
coe (Tree' X F i) (Pi' Y T) () x
coe (Tree' I F i) (Tree' I' F' i') (IQ , (iq , FQ)) x = tcoe i i' iq x where
tcoe : (i : <! I !>TU)(i' : <! I' !>TU)(iq : <! Eq I i I' i' !>TU) ->
<! Tree' I F i !>TU -> <! Tree' I' F' i' !>TU
tcoe i i' iq <$ s , k $> = <$ (
let (S , K) = F i ; (S' , K') = F' i'
(SQ , KQ) = FQ i i' iq
s' = coe S S' SQ s ; sq = coh S S' SQ s
(P , r) = K s ; (P' , r') = K' s'
(PQ , rq) = KQ s s' sq
in s' , \ p' ->
let p = coe P' P PQ p' ; pq = coh P' P PQ p'
in tcoe (r p) (r' p') (rq p' p pq) (k p) ) $>
coe (Tree' X F i) (Prf' Y) () x
coe (Prf' X) Zero' () x
coe (Prf' X) One' () x
coe (Prf' X) Two' () x
coe (Prf' X) (Sg' Y T) () x
coe (Prf' X) (Pi' Y T) () x
coe (Prf' X) (Tree' Y F i) () x
coe (Prf' X) (Prf' Y) () x
postulate
reflTU : (X : TU set)(x : <! X !>TU) -> <! Eq X x X x !>TU
RespTU : (X : TU set)(P : <! X !>TU -> TU set)(x x' : <! X !>TU) ->
<! Eq X x X x' !>TU ->
<! P x <-> P x' !>TU
substTU : (X : TU set)(P : <! X !>TU -> TU set)(x x' : <! X !>TU) ->
(q : <! Eq X x X x' !>TU) ->
<! P x !>TU -> <! P x' !>TU
substTU X P x x' q = coe (P x) (P x') (RespTU X P x x' q)
-- in Coq one might try
data Rep : Set -> Set1 where
Zero' : Rep Zero
One' : Rep One
Sg' : forall {S T} -> Rep S -> ((s : S) -> Rep (T s)) -> Rep (Sg S T)
-- etc
-- PEQ : forall {X Y} -> Rep X -> Rep Y -> Prop * (X -> Y -> Prop
-- PEQ X Y = ?