-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstlc.thm
More file actions
367 lines (304 loc) · 7.75 KB
/
Copy pathstlc.thm
File metadata and controls
367 lines (304 loc) · 7.75 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
Specification "stlc".
Close tm, ty.
Define step : tm -> tm -> prop by
step (app (lam S) U) (S U) ;
step (lam S) (lam S') := nabla x, step (S x) (S' x) ;
step (app T U) (app T' U) := (step T T') ;
step (app T U) (app T U') := (step U U').
Define sn : tm -> prop by
sn T := forall T', (step T T') -> sn T'.
Define neutral : tm -> prop by
neutral (app T U) ;
nabla x, neutral x.
Define red : ty -> tm -> prop by
red unit star ;
red (arr A B) (lam S) := forall U, (red A U) -> (red B (S U)) ;
red B T := neutral T /\ forall T', (step T T') -> (red B T'). %% CR3
Theorem red-var : forall A, nabla x, red A x.
intros. unfold. search. intros. case H1.
Theorem norm-lam : forall S, nabla x, sn (S x) -> (sn (lam S)).
induction on 1.
intros. case H1. unfold. intros.
case H3. backchain IH. backchain H2.
Theorem normalizability : forall T A, (red A T) -> (sn T).
induction on 1.
intros. case H1.
%% Case STAR
unfold. intros. case H2.
%% Case LAM
backchain norm-lam.
backchain IH with A = B.
backchain H2. backchain red-var.
%% Case NEU
unfold. intros. backchain IH with A = A. backchain H3.
Define freshlst : (list o) -> tm -> prop by
freshlst nil T ;
nabla x, freshlst (of x A :: Gamma) T := freshlst Gamma T.
Define subst : (list o) -> (list tm) -> prop by
subst nil nil ;
nabla x , subst (of x A :: Gamma) (U :: Subst) :=
subst Gamma Subst /\ freshlst Gamma U.
Define redlst : (list o) -> (list tm) -> ty -> tm -> prop by
redlst nil nil A T := red A T ;
nabla x , redlst (of x A1 :: Gamma) (U :: Subst) A (T x) :=
(red A1 U ->
redlst Gamma Subst A (T U)).
Theorem redlst-lam : forall Gamma Subst A B S,
(subst Gamma Subst)
-> (forall U, nabla x, freshlst Gamma U ->
redlst (of x A :: Gamma) (U :: Subst) B (S x))
-> (redlst Gamma Subst (arr A B) (lam S)).
induction on 1.
intros. case H1.
%% NIL Case
unfold. unfold. intros.
apply H2 to _ with U = U.
case H4. apply H5 to H3.
case H6. search.
%% CONS Case
unfold. intros.
backchain IH.
intros. unfold. intros.
apply H2 to _ with U1 = U1.
case H8. apply H9 to H7.
case H10.
backchain H11.
Theorem redlst-star : forall Gamma Subst,
(subst Gamma Subst)
-> (redlst Gamma Subst unit star).
induction on 1.
intros.
case H1.
%% NIL Case
search.
%% CONS Case
unfold. intros. backchain IH.
Theorem norm-step : forall T T', (sn T) -> (step T T') -> (sn T').
intros. case H1. apply H3 to H2. search.
Theorem step-subst : forall S S' U, nabla (x : tm), step (S x) (S' x) -> step (S U) (S' U).
induction on 1. intros. case H1.
search.
unfold. intros.
apply IH to H2 with S = (x \ S1 x n2), S' = (x \ S'1 x n2), U = U. search.
unfold. apply IH to H2 with U = U. search.
apply IH to H2 with U = U. search.
%% CR2
Theorem red-step : forall A T T', red A T -> (step T T') -> red A T'.
induction on 1.
intros. case H1.
%% Case STAR
case H2.
%% Case LAM
case H2. unfold.
intros.
backchain IH with T = (S U).
backchain H3.
apply step-subst to H4 with U = U. search.
%% Case NEU
backchain H4.
Theorem red-app : forall T U A B,
(red (arr A B) T)
-> (red A U)
-> (red B (app T U)).
intros.
apply normalizability to H1.
apply normalizability to H2.
clear -> H1 H2 H3 H4 A B U T.
induction on 2.
induction on 1.
intros. unfold. search.
intros. case H9.
%% Case (step (app (lam S) U) (S U))
case H8. backchain H10. case H10.
%% Case (step (app T U) (app T' U))
backchain IH. case H6. backchain H11.
backchain red-step.
%% Case (step (app T U) (app T U'))
case H5.
backchain IH1 with A = A. backchain H11.
backchain red-step.
Theorem redlst-app : forall Gamma Subst T U A B,
subst Gamma Subst -> (redlst Gamma Subst (arr A B) T)
-> (redlst Gamma Subst A U)
-> (redlst Gamma Subst B (app T U)).
induction on 1.
intros. case H1.
unfold. case H2. case H3.
backchain red-app.
unfold. intros.
case H2. case H3.
apply H7 to H6.
apply H8 to H6.
apply IH to H4 H9 _.
search.
Define fresh : tm -> A -> prop by
nabla x , fresh x T.
Define ctx : (list o) -> prop by
ctx nil ; nabla x , ctx (of x A :: Gamma) := {typ A} /\ ctx Gamma.
Theorem mem-ctx-fresh : forall Gamma F, nabla x ,
ctx Gamma -> member (F x) Gamma -> (fresh x (F x)).
induction on 1.
intros.
case H1. case H2.
case H2. search.
apply IH to H4 H5 with x = n1.
case H6. search.
Theorem mem-ctx : forall F Gamma, (ctx Gamma)
-> (member F Gamma) -> (exists T A, F = of T A).
induction on 1.
intros.
case H1. case H2.
case H2.
search. apply IH to H4 H5.
search.
Theorem typ-ctx : forall Gamma A, (ctx Gamma) -> {Gamma |- typ A} -> {typ A}.
induction on 2. intros. case H2.
search.
apply IH to H1 H3. apply IH to H1 H4. search.
apply mem-ctx to H1 H4. case H3.
Theorem redlst-mem-lem : forall Gamma Subst A U,
(subst Gamma Subst) ->
freshlst Gamma U ->
red A U -> redlst Gamma Subst A U.
induction on 1.
intros. case H1.
search.
case H2.
apply IH to H4 _ H3.
unfold.
search.
Theorem redlst-mem : forall Subst A T Gamma,
ctx Gamma ->
member (of T A) Gamma ->
subst Gamma Subst -> redlst Gamma Subst A T.
induction on 3.
intros.
case H3.
case H2.
case H2.
unfold. intros.
backchain redlst-mem-lem.
apply mem-ctx-fresh to _ H6. case H1. search.
case H7.
apply IH to _ H6 H4. case H1. search.
unfold.
search.
Theorem reducibility : forall Gamma T A Subst, (ctx Gamma) -> {typ A} ->
(subst Gamma Subst) -> {Gamma |- of T A} -> (redlst Gamma Subst A T).
induction on 4.
intros.
case H4.
% Case STAR
backchain redlst-star.
% Case LAM:
case H2.
backchain redlst-lam.
intros.
backchain IH.
% Case APP:
apply IH to _ _ H3 H6.
backchain typ-ctx.
apply IH to _ _ H3 H7.
backchain typ-ctx.
apply redlst-app to _ _ _.
search.
%% Case VAR
assert (ctx Gamma).
apply mem-ctx to _ H6.
apply redlst-mem to _ H6 _.
case H5.
search.
Define idsubst : (list o) -> (list tm) -> tm -> prop by
idsubst nil nil T ;
nabla x y, idsubst (of x A :: Gamma) (y :: Subst) (T x) :=
nabla x, idsubst Gamma Subst (T x).
Theorem idsubst-freshness-lemma : forall Subst Gamma T, nabla x,
idsubst Gamma (Subst x) (T x) -> fresh x (Subst x) \/ fresh x (T x).
induction on 1.
intros.
case H1. search.
apply IH to H2 with x = n1.
case H3. case H4.
search. case H4.
search. search.
Theorem freshlstvar : forall Gamma, nabla x,
ctx Gamma -> freshlst Gamma x.
induction on 1.
intros.
case H1.
search.
unfold.
backchain IH.
Theorem idsubst-ex : forall Gamma T,
ctx Gamma ->
exists Subst,
(subst Gamma Subst)
/\ (idsubst Gamma Subst T).
induction on 1.
intros.
case H1. search.
apply IH to H3 with T = (T n1).
apply idsubst-freshness-lemma to H5. case H6.
case H7.
witness (n2 :: T1).
split. unfold. search.
backchain freshlstvar.
search. case H7.
witness (n2 :: Subst n3).
split. unfold. search.
backchain freshlstvar.
unfold. search.
Define substtm : (list o) -> (list tm) -> tm -> tm -> prop by
substtm nil nil T T ;
nabla x y, substtm (of x A :: Gamma) (y :: Subst) (T x) (T' y) :=
nabla y, substtm Gamma Subst (T y) (T' y).
Theorem sn-lemma : forall T T' A Gamma Subst, (ctx Gamma) -> (idsubst Gamma Subst T)
-> {typ A} -> redlst Gamma Subst A T -> substtm Gamma Subst T T' -> sn T'.
induction on 2.
intros.
case H2.
case H4. case H5.
backchain normalizability.
case H4. case H5.
apply IH to _ H6 H3 _ H8.
permute (n1 n2) H7.
backchain H7.
case H1. backchain red-var.
case H1. search. search.
Theorem sn-renaming : forall T T' Gamma Subst,
idsubst Gamma Subst T
-> substtm Gamma Subst T T'
-> (sn T')
-> (sn T).
induction on 1.
intros.
case H1.
case H2. search.
case H2.
case H5. search.
case H4.
permute (n4 n2 n1) H3.
permute (n3 n2).
apply IH to H7 H6 H3.
search.
Theorem substtm-ex : forall T Gamma Subst,
(idsubst Gamma Subst T)
-> exists T', substtm Gamma Subst T T'.
induction on 1.
intros. case H1.
search.
apply IH to H2.
search.
Theorem strong-normalizability : forall T Gamma A,
{typ A}
-> (ctx Gamma)
-> {Gamma |- of T A}
-> (sn T).
intros.
apply idsubst-ex to H2 with T = T.
apply reducibility to H2 H1 H4 H3.
apply substtm-ex to H5.
apply sn-renaming to H5 H7 _.
apply sn-lemma to _ H5 _ H6 _.
search.
search.