-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPSFOLD.lean
More file actions
371 lines (331 loc) Β· 22.1 KB
/
Copy pathPSFOLD.lean
File metadata and controls
371 lines (331 loc) Β· 22.1 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
367
368
369
370
371
inductive Typ
| arr (Οβ Οβ : Typ)
| unit
| prod (Οβ Οβ : Typ)
| void
| sum (Οβ Οβ : Typ)
/-
inductive Exp''
| var (x : Nat)
| lam (eβ : Exp'')
| ap (e eβ : Exp'')
| triv
| pair (eβ eβ : Exp'')
| prl (e : Exp'')
| prr (e : Exp'')
| abort (e : Exp'')
| inl (e : Exp'')
| inr (e : Exp'')
| case (e eβ eβ : Exp'')
inductive Exp''.HasType.Var (Ο : Typ) : (Ξ : List Typ) β (x : Nat) β Type
| head : Var Ο (Ο :: Ξ) .zero
| tail : Var Ο Ξ n β Var Ο (Ο' :: Ξ) n.succ
inductive Exp''.HasType : (Ξ : List Typ) β (e : Exp'') β (Ο : Typ) β Type
| var : HasType.Var Ο Ξ x β HasType Ξ (var x) Ο
| lam : HasType (Οβ :: Ξ) eβ Οβ β HasType Ξ (lam eβ) (.arr Οβ Οβ)
| ap : HasType Ξ e (.arr Οβ Οβ) β HasType Ξ eβ Οβ β HasType Ξ (ap e eβ) Οβ
| triv : HasType Ξ triv .unit
| pair : HasType Ξ eβ Οβ β HasType Ξ eβ Οβ β HasType Ξ (pair eβ eβ) (.prod Οβ Οβ)
| prl : HasType Ξ e (.prod Οβ Οβ) β HasType Ξ (prl e) Οβ
| prr : HasType Ξ e (.prod Οβ Οβ) β HasType Ξ (prr e) Οβ
| abort : HasType Ξ e .void β HasType Ξ (abort e) Ο
| inl : HasType Ξ e Οβ β HasType Ξ (inl e) (.sum Οβ Οβ)
| inr : HasType Ξ e Οβ β HasType Ξ (inr e) (.sum Οβ Οβ)
| case : HasType Ξ e (.sum Οβ Οβ) β HasType (Οβ :: Ξ) eβ Ο β HasType (Οβ :: Ξ) eβ Ο β HasType Ξ (case e eβ eβ) Ο
inductive Exp' : (Ο : Typ) β Type
| var (x : Nat) : Exp' Ο
| lam (eβ : Exp' Οβ) : Exp' (.arr Οβ Οβ)
| ap (e : Exp' (.arr Οβ Οβ)) (eβ : Exp' Οβ) : Exp' Οβ
| triv : Exp' .unit
| pair (eβ : Exp' Οβ) (eβ : Exp' Οβ) : Exp' (.prod Οβ Οβ)
| prl (e : Exp' (.prod Οβ Οβ)) : Exp' Οβ
| prr (e : Exp' (.prod Οβ Οβ)) : Exp' Οβ
| abort (e : Exp' .void) : Exp' Ο
| inl (e : Exp' Οβ) : Exp' (.sum Οβ Οβ)
| inr (e : Exp' Οβ) : Exp' (.sum Οβ Οβ)
| case (e : Exp' (.sum Οβ Οβ)) (eβ : Exp' Ο) (eβ : Exp' Ο) : Exp' Ο
inductive Exp'.HasType : (Ξ : List Typ) β (e : Exp' Ο) β Type
| var : Exp''.HasType.Var Ο Ξ x β HasType Ξ (var (Ο := Ο) x)
| lam : HasType (Οβ :: Ξ) eβ β HasType Ξ (lam (Οβ := Οβ) eβ)
| ap : HasType Ξ e β HasType Ξ eβ β HasType Ξ (ap e eβ)
| triv : HasType Ξ triv
| pair : HasType Ξ eβ β HasType Ξ eβ β HasType Ξ (pair eβ eβ)
| prl : HasType Ξ e β HasType Ξ (prl e)
| prr : HasType Ξ e β HasType Ξ (prr e)
| abort : HasType Ξ e β HasType Ξ (abort e)
| inl : HasType Ξ e β HasType Ξ (inl e)
| inr : HasType Ξ e β HasType Ξ (inr e)
| case : HasType (Ο := .sum Οβ Οβ) Ξ e β HasType (Οβ :: Ξ) eβ β HasType (Οβ :: Ξ) eβ β HasType Ξ (case e eβ eβ)
-/
inductive Exp.Var (Ο : Typ) : (Ξ : List Typ) β Type
| head : Var Ο (Ο :: Ξ)
| tail (x : Var Ο Ξ) : Var Ο (Ο' :: Ξ)
inductive Exp : (Ξ : List Typ) β (Ο : Typ) β Type
| var (x : Exp.Var Ο Ξ) : Exp Ξ Ο
| lam (eβ : Exp (Οβ :: Ξ) Οβ) : Exp Ξ (.arr Οβ Οβ)
| ap (e : Exp Ξ (.arr Οβ Οβ)) (eβ : Exp Ξ Οβ) : Exp Ξ Οβ
| triv : Exp Ξ .unit
| pair (eβ : Exp Ξ Οβ) (eβ : Exp Ξ Οβ) : Exp Ξ (.prod Οβ Οβ)
| prl (e : Exp Ξ (.prod Οβ Οβ)) : Exp Ξ Οβ
| prr (e : Exp Ξ (.prod Οβ Οβ)) : Exp Ξ Οβ
| abort (e : Exp Ξ .void) : Exp Ξ Ο
| inl (e : Exp Ξ Οβ) : Exp Ξ (.sum Οβ Οβ)
| inr (e : Exp Ξ Οβ) : Exp Ξ (.sum Οβ Οβ)
| case (e : Exp Ξ (.sum Οβ Οβ)) (eβ : Exp (Οβ :: Ξ) Ο) (eβ : Exp (Οβ :: Ξ) Ο) : Exp Ξ Ο
namespace Exp
@[simp]
def Var.cast : β {Ξ'} (eq : Ξ = Ξ') (x : Var Ο Ξ), Var Ο Ξ'
| _ :: _, eq, head => (List.cons.inj eq).left βΈ head
| _ :: _, eq, tail x => tail (x.cast (List.cons.inj eq).right)
@[simp]
def cast (eq : Ξ = Ξ') : (e : Exp Ξ Ο) β Exp Ξ' Ο
| var x => var (x.cast eq)
| lam eβ => lam (eβ.cast (eq βΈ rfl))
| ap e eβ => ap (e.cast eq) (eβ.cast eq)
| triv => triv
| pair eβ eβ => pair (eβ.cast eq) (eβ.cast eq)
| prl e => prl (e.cast eq)
| prr e => prr (e.cast eq)
| abort e => abort (e.cast eq)
| inl e => inl (e.cast eq)
| inr e => inr (e.cast eq)
| case e eβ eβ => case (e.cast eq) (eβ.cast (eq βΈ rfl)) (eβ.cast (eq βΈ rfl))
@[simp] theorem Var.cast_rfl : cast rfl x = x := by induction x <;> simp [*]
@[simp] theorem cast_rfl : cast rfl e = e := by induction e <;> simp [*]
@[simp]
def Var.weaken : β {Ξβ} (x : Var Ο (Ξβ ++ Ξβ)), Var Ο (Ξβ ++ Ο' :: Ξβ)
| [], x => tail x
| _ :: _, head => head
| _ :: _, tail x => tail x.weaken
@[simp]
def weaken : (e : Exp (Ξβ ++ Ξβ) Ο) β Exp (Ξβ ++ Ο' :: Ξβ) Ο
| var x => var x.weaken
| lam eβ => lam (eβ.weaken (Ξβ := _ :: _))
| ap e eβ => ap e.weaken eβ.weaken
| triv => triv
| pair eβ eβ => pair eβ.weaken eβ.weaken
| prl e => prl e.weaken
| prr e => prr e.weaken
| abort e => abort e.weaken
| inl e => inl e.weaken
| inr e => inr e.weaken
| case e eβ eβ => case e.weaken (eβ.weaken (Ξβ := _ :: _)) (eβ.weaken (Ξβ := _ :: _))
@[simp]
def weakenβ : (e : Exp Ξ Ο) β Exp (Ο' :: Ξ) Ο := weaken (Ξβ := [])
@[simp]
def Var.subst : β {Ξβ Ο'} (x : Var Ο (Ξβ ++ Ο' :: Ξβ)), Var Ο (Ξβ ++ Ξβ) β' Ο = Ο'
| [], _, head => .inr rfl
| [], _, tail x => .inl x
| _ :: _, _, head => .inl head
| _ :: _, _, tail x => match subst x with
| .inl x => .inl x.tail
| .inr eq => .inr eq
@[simp]
def subst (e' : Exp (Ξβ ++ Ξβ) Ο') : (e : Exp (Ξβ ++ Ο' :: Ξβ) Ο) β Exp (Ξβ ++ Ξβ) Ο
| var x => match x.subst with
| .inl x => var x
| .inr rfl => e'
| lam eβ => lam (subst (Ξβ := _ :: _) e'.weakenβ eβ)
| ap e eβ => ap (subst e' e) (subst e' eβ)
| triv => triv
| pair eβ eβ => pair (subst e' eβ) (subst e' eβ)
| prl e => prl (subst e' e)
| prr e => prr (subst e' e)
| abort e => abort (subst e' e)
| inl e => inl (subst e' e)
| inr e => inr (subst e' e)
| case e eβ eβ => case (subst e' e) (subst (Ξβ := _ :: _) e'.weakenβ eβ) (subst (Ξβ := _ :: _) e'.weakenβ eβ)
@[simp]
def substβ : (e' : Exp Ξ Ο') β (e : Exp (Ο' :: Ξ) Ο) β Exp Ξ Ο := subst (Ξβ := [])
theorem weaken_weaken_var_Lββ : β {Ξβ Ξ Ξβ} (x : Var Ο (Ξβ ++ Ξ ++ Ξβ)), (Var.cast (List.append_assoc Ξβ (Ο' :: Ξ) (Ο'' :: Ξβ)) <| @Var.weaken Ο Ξβ Ο'' (Ξβ ++ Ο' :: Ξ) <| Var.cast (List.append_assoc Ξβ (Ο' :: Ξ) Ξβ).symm <| @Var.weaken Ο (Ξ ++ Ξβ) Ο' Ξβ <| Var.cast (List.append_assoc Ξβ Ξ Ξβ) x) = (@Var.weaken Ο (Ξ ++ Ο'' :: Ξβ) Ο' Ξβ <| Var.cast (List.append_assoc Ξβ Ξ (Ο'' :: Ξβ)) <| @Var.weaken Ο Ξβ Ο'' (Ξβ ++ Ξ) x)
| _ :: _, _, _, .head => by simp
| _ :: _, _, _, .tail x => by simp; exact weaken_weaken_var_Lββ x
| [], _ :: _, _, _ => by simp
| [], [], _, _ => by simp
/-
theorem weaken_weaken_Lββ : (e : Exp (Ξβ ++ Ξ ++ Ξβ) Ο) β (cast (List.append_assoc Ξβ (Ο' :: Ξ) (Ο'' :: Ξβ)) <| @weaken (Ξβ ++ Ο' :: Ξ) Ξβ Ο Ο'' <| cast (List.append_assoc Ξβ (Ο' :: Ξ) Ξβ).symm <| @weaken Ξβ (Ξ ++ Ξβ) Ο Ο' <| cast (List.append_assoc Ξβ Ξ Ξβ) e) = (@weaken Ξβ (Ξ ++ Ο'' :: Ξβ) Ο Ο' <| cast (List.append_assoc Ξβ Ξ (Ο'' :: Ξβ)) <| @weaken (Ξβ ++ Ξ) Ξβ Ο Ο'' e)
| var x => by simp; exact weaken_weaken_var_Lββ x
| lam eβ => by simp; exact weaken_weaken_Lββ (Ξβ := _ :: _) eβ
| ap e eβ => by simp; exact β¨weaken_weaken_Lββ e, weaken_weaken_Lββ eββ©
| triv => by simp
| pair eβ eβ => by simp; exact β¨weaken_weaken_Lββ eβ, weaken_weaken_Lββ eββ©
| prl e => by simp; exact weaken_weaken_Lββ e
| prr e => by simp; exact weaken_weaken_Lββ e
| abort e => by simp; exact weaken_weaken_Lββ e
| inl e => by simp; exact weaken_weaken_Lββ e
| inr e => by simp; exact weaken_weaken_Lββ e
| case e eβ eβ => by simp; exact β¨weaken_weaken_Lββ e, weaken_weaken_Lββ (Ξβ := _ :: _) eβ, weaken_weaken_Lββ (Ξβ := _ :: _) eββ©
theorem weaken_weaken_Lββ : (e : Exp (Ξβ ++ (Ξ ++ Ξβ)) Ο) β (cast (List.append_assoc Ξβ (Ο' :: Ξ) (Ο'' :: Ξβ)) <| @weaken (Ξβ ++ Ο' :: Ξ) Ξβ Ο Ο'' <| cast (List.append_assoc Ξβ (Ο' :: Ξ) Ξβ).symm <| @weaken Ξβ (Ξ ++ Ξβ) Ο Ο' e) = (@weaken Ξβ (Ξ ++ Ο'' :: Ξβ) Ο Ο' <| cast (List.append_assoc Ξβ Ξ (Ο'' :: Ξβ)) <| @weaken (Ξβ ++ Ξ) Ξβ Ο Ο'' <| cast (List.append_assoc Ξβ Ξ Ξβ).symm e)
| var x => sorry
| lam eβ => by simp; exact weaken_weaken_Lββ (Ξβ := _ :: _) eβ
| ap e eβ => by simp; exact β¨weaken_weaken_Lββ e, weaken_weaken_Lββ eββ©
| triv => by simp
| pair eβ eβ => by simp; exact β¨weaken_weaken_Lββ eβ, weaken_weaken_Lββ eββ©
| prl e => by simp; exact weaken_weaken_Lββ e
| prr e => by simp; exact weaken_weaken_Lββ e
| abort e => by simp; exact weaken_weaken_Lββ e
| inl e => by simp; exact weaken_weaken_Lββ e
| inr e => by simp; exact weaken_weaken_Lββ e
| case e eβ eβ => by simp; exact β¨weaken_weaken_Lββ e, weaken_weaken_Lββ (Ξβ := _ :: _) eβ, weaken_weaken_Lββ (Ξβ := _ :: _) eββ©
theorem weaken_weaken_Lββ : (e : Exp (Ξβ ++ Ξ ++ Ξβ) Ο) β (@weaken (Ξβ ++ Ο' :: Ξ) Ξβ Ο Ο'' <| cast (List.append_assoc Ξβ (Ο' :: Ξ) Ξβ).symm <| @weaken Ξβ (Ξ ++ Ξβ) Ο Ο' <| cast (List.append_assoc Ξβ Ξ Ξβ) e) = (cast (List.append_assoc Ξβ (Ο' :: Ξ) (Ο'' :: Ξβ)).symm <| @weaken Ξβ (Ξ ++ Ο'' :: Ξβ) Ο Ο' <| cast (List.append_assoc Ξβ Ξ (Ο'' :: Ξβ)) <| @weaken (Ξβ ++ Ξ) Ξβ Ο Ο'' e)
| var x => sorry
| lam eβ => by simp; exact weaken_weaken_Lββ (Ξβ := _ :: _) eβ
| ap e eβ => by simp; exact β¨weaken_weaken_Lββ e, weaken_weaken_Lββ eββ©
| triv => by simp
| pair eβ eβ => by simp; exact β¨weaken_weaken_Lββ eβ, weaken_weaken_Lββ eββ©
| prl e => by simp; exact weaken_weaken_Lββ e
| prr e => by simp; exact weaken_weaken_Lββ e
| abort e => by simp; exact weaken_weaken_Lββ e
| inl e => by simp; exact weaken_weaken_Lββ e
| inr e => by simp; exact weaken_weaken_Lββ e
| case e eβ eβ => by simp; exact β¨weaken_weaken_Lββ e, weaken_weaken_Lββ (Ξβ := _ :: _) eβ, weaken_weaken_Lββ (Ξβ := _ :: _) eββ©
theorem weaken_weaken_Lββ : (e : Exp (Ξβ ++ (Ξ ++ Ξβ)) Ο) β (@weaken (Ξβ ++ Ο' :: Ξ) Ξβ Ο Ο'' <| cast (List.append_assoc Ξβ (Ο' :: Ξ) Ξβ).symm <| @weaken Ξβ (Ξ ++ Ξβ) Ο Ο' e) = (cast (List.append_assoc Ξβ (Ο' :: Ξ) (Ο'' :: Ξβ)).symm <| @weaken Ξβ (Ξ ++ Ο'' :: Ξβ) Ο Ο' <| cast (List.append_assoc Ξβ Ξ (Ο'' :: Ξβ)) <| @weaken (Ξβ ++ Ξ) Ξβ Ο Ο'' <| cast (List.append_assoc Ξβ Ξ Ξβ).symm e)
| var x => sorry
| lam eβ => by simp; exact weaken_weaken_Lββ (Ξβ := _ :: _) eβ
| ap e eβ => by simp; exact β¨weaken_weaken_Lββ e, weaken_weaken_Lββ eββ©
| triv => by simp
| pair eβ eβ => by simp; exact β¨weaken_weaken_Lββ eβ, weaken_weaken_Lββ eββ©
| prl e => by simp; exact weaken_weaken_Lββ e
| prr e => by simp; exact weaken_weaken_Lββ e
| abort e => by simp; exact weaken_weaken_Lββ e
| inl e => by simp; exact weaken_weaken_Lββ e
| inr e => by simp; exact weaken_weaken_Lββ e
| case e eβ eβ => by simp; exact β¨weaken_weaken_Lββ e, weaken_weaken_Lββ (Ξβ := _ :: _) eβ, weaken_weaken_Lββ (Ξβ := _ :: _) eββ©
theorem weaken_weaken_Rββ : (e : Exp (Ξβ ++ Ξ ++ Ξβ) Ο) β (cast (List.append_assoc Ξβ (Ο'' :: Ξ) (Ο' :: Ξβ)).symm <| @weaken Ξβ (Ξ ++ Ο' :: Ξβ) Ο Ο'' <| cast (List.append_assoc Ξβ Ξ (Ο' :: Ξβ)) <| @weaken (Ξβ ++ Ξ) Ξβ Ο Ο' e) = (@weaken (Ξβ ++ Ο'' :: Ξ) Ξβ Ο Ο' <| cast (List.append_assoc Ξβ (Ο'' :: Ξ) Ξβ).symm <| @weaken Ξβ (Ξ ++ Ξβ) Ο Ο'' <| cast (List.append_assoc Ξβ Ξ Ξβ) e)
| var x => sorry
| lam eβ => by simp; exact weaken_weaken_Rββ (Ξβ := _ :: _) eβ
| ap e eβ => by simp; exact β¨weaken_weaken_Rββ e, weaken_weaken_Rββ eββ©
| triv => by simp
| pair eβ eβ => by simp; exact β¨weaken_weaken_Rββ eβ, weaken_weaken_Rββ eββ©
| prl e => by simp; exact weaken_weaken_Rββ e
| prr e => by simp; exact weaken_weaken_Rββ e
| abort e => by simp; exact weaken_weaken_Rββ e
| inl e => by simp; exact weaken_weaken_Rββ e
| inr e => by simp; exact weaken_weaken_Rββ e
| case e eβ eβ => by simp; exact β¨weaken_weaken_Rββ e, weaken_weaken_Rββ (Ξβ := _ :: _) eβ, weaken_weaken_Rββ (Ξβ := _ :: _) eββ©
theorem weaken_weaken_Rββ : (e : Exp (Ξβ ++ (Ξ ++ Ξβ)) Ο) β (cast (List.append_assoc Ξβ (Ο'' :: Ξ) (Ο' :: Ξβ)).symm <| @weaken Ξβ (Ξ ++ Ο' :: Ξβ) Ο Ο'' <| cast (List.append_assoc Ξβ Ξ (Ο' :: Ξβ)) <| @weaken (Ξβ ++ Ξ) Ξβ Ο Ο' <| cast (List.append_assoc Ξβ Ξ Ξβ).symm e) = (@weaken (Ξβ ++ Ο'' :: Ξ) Ξβ Ο Ο' <| cast (List.append_assoc Ξβ (Ο'' :: Ξ) Ξβ).symm <| @weaken Ξβ (Ξ ++ Ξβ) Ο Ο'' e)
| var x => sorry
| lam eβ => by simp; exact weaken_weaken_Rββ (Ξβ := _ :: _) eβ
| ap e eβ => by simp; exact β¨weaken_weaken_Rββ e, weaken_weaken_Rββ eββ©
| triv => by simp
| pair eβ eβ => by simp; exact β¨weaken_weaken_Rββ eβ, weaken_weaken_Rββ eββ©
| prl e => by simp; exact weaken_weaken_Rββ e
| prr e => by simp; exact weaken_weaken_Rββ e
| abort e => by simp; exact weaken_weaken_Rββ e
| inl e => by simp; exact weaken_weaken_Rββ e
| inr e => by simp; exact weaken_weaken_Rββ e
| case e eβ eβ => by simp; exact β¨weaken_weaken_Rββ e, weaken_weaken_Rββ (Ξβ := _ :: _) eβ, weaken_weaken_Rββ (Ξβ := _ :: _) eββ©
theorem weaken_weaken_Rββ : (e : Exp (Ξβ ++ Ξ ++ Ξβ) Ο) β (@weaken Ξβ (Ξ ++ Ο' :: Ξβ) Ο Ο'' <| cast (List.append_assoc Ξβ Ξ (Ο' :: Ξβ)) <| @weaken (Ξβ ++ Ξ) Ξβ Ο Ο' e) = (cast (List.append_assoc Ξβ (Ο'' :: Ξ) (Ο' :: Ξβ)) <| @weaken (Ξβ ++ Ο'' :: Ξ) Ξβ Ο Ο' <| cast (List.append_assoc Ξβ (Ο'' :: Ξ) Ξβ).symm <| @weaken Ξβ (Ξ ++ Ξβ) Ο Ο'' <| cast (List.append_assoc Ξβ Ξ Ξβ) e)
| var x => sorry
| lam eβ => by simp; exact weaken_weaken_Rββ (Ξβ := _ :: _) eβ
| ap e eβ => by simp; exact β¨weaken_weaken_Rββ e, weaken_weaken_Rββ eββ©
| triv => by simp
| pair eβ eβ => by simp; exact β¨weaken_weaken_Rββ eβ, weaken_weaken_Rββ eββ©
| prl e => by simp; exact weaken_weaken_Rββ e
| prr e => by simp; exact weaken_weaken_Rββ e
| abort e => by simp; exact weaken_weaken_Rββ e
| inl e => by simp; exact weaken_weaken_Rββ e
| inr e => by simp; exact weaken_weaken_Rββ e
| case e eβ eβ => by simp; exact β¨weaken_weaken_Rββ e, weaken_weaken_Rββ (Ξβ := _ :: _) eβ, weaken_weaken_Rββ (Ξβ := _ :: _) eββ©
theorem weaken_weaken_Rββ : (e : Exp (Ξβ ++ (Ξ ++ Ξβ)) Ο) β (@weaken Ξβ (Ξ ++ Ο' :: Ξβ) Ο Ο'' <| cast (List.append_assoc Ξβ Ξ (Ο' :: Ξβ)) <| @weaken (Ξβ ++ Ξ) Ξβ Ο Ο' <| cast (List.append_assoc Ξβ Ξ Ξβ).symm e) = (cast (List.append_assoc Ξβ (Ο'' :: Ξ) (Ο' :: Ξβ)) <| @weaken (Ξβ ++ Ο'' :: Ξ) Ξβ Ο Ο' <| cast (List.append_assoc Ξβ (Ο'' :: Ξ) Ξβ).symm <| @weaken Ξβ (Ξ ++ Ξβ) Ο Ο'' e)
| var x => sorry
| lam eβ => by simp; exact weaken_weaken_Rββ (Ξβ := _ :: _) eβ
| ap e eβ => by simp; exact β¨weaken_weaken_Rββ e, weaken_weaken_Rββ eββ©
| triv => by simp
| pair eβ eβ => by simp; exact β¨weaken_weaken_Rββ eβ, weaken_weaken_Rββ eββ©
| prl e => by simp; exact weaken_weaken_Rββ e
| prr e => by simp; exact weaken_weaken_Rββ e
| abort e => by simp; exact weaken_weaken_Rββ e
| inl e => by simp; exact weaken_weaken_Rββ e
| inr e => by simp; exact weaken_weaken_Rββ e
| case e eβ eβ => by simp; exact β¨weaken_weaken_Rββ e, weaken_weaken_Rββ (Ξβ := _ :: _) eβ, weaken_weaken_Rββ (Ξβ := _ :: _) eββ©
-/
/-
-- TODO: arg names
inductive Eq : Exp Ξ Ο β Exp Ξ Ο β Prop
-- equivalence
| refl : Eq e e
| sym : Eq e e' β Eq e' e
| trans : Eq e e' β Eq e' e'' β Eq e e''
-- congruence
| lam : Eq eβ eβ' β Eq (lam eβ) (lam eβ')
| ap : Eq e e' β Eq eβ eβ' β Eq (ap e eβ) (ap e' eβ')
| triv : Eq triv triv
| pair : Eq eβ eβ' β Eq eβ eβ' β Eq (pair eβ eβ) (pair eβ' eβ')
| prl : Eq e e' β Eq (prl e) (prl e')
| prr : Eq e e' β Eq (prr e) (prr e')
| abort : Eq e e' β Eq (abort e) (abort e')
| inl : Eq e e' β Eq (inl e) (inl e')
| inr : Eq e e' β Eq (inr e) (inr e')
| case : Eq e e' β Eq eβ eβ' β Eq eβ eβ' β Eq (case e eβ eβ) (case e' eβ' eβ')
-- beta
| ap_lam : Eq (ap (lam eβ) eβ) (eβ.substβ eβ)
| prl_pair : Eq (prl (pair eβ eβ)) eβ
| prr_pair : Eq (prr (pair eβ eβ)) eβ
| case_inl : Eq (case (inl e) eβ eβ) (e.substβ eβ)
| case_inr : Eq (case (inr e) eβ eβ) (e.substβ eβ)
-- eta
| arr : Eq e (lam (ap e.weakenβ (var head)))
| unit : Eq e triv
| prod : Eq e (pair (prl e) (prr e))
| void : Eq (e'.substβ e) (abort e')
| sum : Eq (e'.substβ e) (case e' ((inl (var head)).subst (Ξβ := _ :: []) e.weakenβ) ((inr (var head)).substβ (e.weaken (Ξβ := _ :: [])))) -- TODO
def InterpTyp : (Ο : Typ) β Type
| arr Οβ Οβ => InterpTyp Οβ β InterpTyp Οβ
| unit => Unit
| prod Οβ Οβ => InterpTyp Οβ Γ InterpTyp Οβ
| void => Empty
| sum Οβ Οβ => InterpTyp Οβ β InterpTyp Οβ
def InterpCtx : (Ξ : List Typ) β Type
| [] => Unit
| Ο :: Ξ => InterpTyp Ο Γ InterpCtx Ξ
def InterpVar : (m : Var Ο Ξ) β (Ο : InterpCtx Ξ) β InterpTyp Ο
| head, (x, Ο) => x
| tail m, (x, Ο) => InterpVar m Ο
def InterpExp : (e : Exp Ξ Ο) β (Ο : InterpCtx Ξ) β InterpTyp Ο
| var m, Ο => InterpVar m Ο
| lam eβ, Ο => Ξ» x => InterpExp eβ (x, Ο)
| ap e eβ, Ο => InterpExp e Ο (InterpExp eβ Ο)
| triv, Ο => ()
| pair eβ eβ, Ο => (InterpExp eβ Ο, InterpExp eβ Ο)
| prl e, Ο => InterpExp e Ο |>.fst
| prr e, Ο => InterpExp e Ο |>.snd
| abort e, Ο => nomatch InterpExp e Ο
| inl e, Ο => .inl (InterpExp e Ο)
| inr e, Ο => .inr (InterpExp e Ο)
| case e eβ eβ, Ο => match InterpExp e Ο with
| .inl xβ => InterpExp eβ (xβ, Ο)
| .inr xβ => InterpExp eβ (xβ, Ο)
-/
/-
def LiftableExp (Ξ : List Typ) (Ο : Typ) : Type :=
β Ξ', Exp (.reverseAux Ξ' Ξ) Ο
def LiftableExp.lift (e : LiftableExp Ξ Ο) : LiftableExp (Ο' :: Ξ) Ο
| Ξ' => e (Ο' :: Ξ')
def LiftableExp.var (m : Exp.Var Ο Ξ) : LiftableExp Ξ Ο
| [] => .var m
| _ :: Ξ' => var m.tail Ξ'
def LiftCtx (Ξ Ξ' : List Typ) : Type :=
β {Ο} (m : Exp.Var Ο Ξ), LiftableExp Ξ' Ο
def LiftCtx.lift (Ο : LiftCtx Ξ Ξ') : LiftCtx (Ο :: Ξ) (Ο :: Ξ')
| _, .head => LiftableExp.var .head
| _, .tail m => (Ο m).lift
def Exp.substAll (Ο : LiftCtx Ξ Ξ') : (e : Exp Ξ Ο) β Exp Ξ' Ο
| var m => Ο m []
| lam eβ => lam (eβ.substAll Ο.lift)
| ap e eβ => ap (e.substAll Ο) (eβ.substAll Ο)
| triv => triv
| pair eβ eβ => pair (eβ.substAll Ο) (eβ.substAll Ο)
| prl e => prl (e.substAll Ο)
| prr e => prr (e.substAll Ο)
| abort e => abort (e.substAll Ο)
| inl e => inl (e.substAll Ο)
| inr e => inr (e.substAll Ο)
| case e eβ eβ => case (e.substAll Ο) (eβ.substAll Ο.lift) (eβ.substAll Ο.lift)
def Exp.weaken.ctx : β {Ξβ}, LiftCtx (Ξβ ++ Ξβ) (Ξβ ++ Ο' :: Ξβ)
| [], _, m => LiftableExp.var m.tail
| _ :: _, _, .head => LiftableExp.var .head
| _ :: _, _, .tail m => (ctx m).lift
def Exp.weaken : (e : Exp (Ξβ ++ Ξβ) Ο) β Exp (Ξβ ++ Ο' :: Ξβ) Ο :=
substAll weaken.ctx
-/