235 text {* In the current version of the nominal datatype package even simple |
235 text {* In the current version of the nominal datatype package even simple |
236 functions (such as size of types and capture-avoiding substitution) can |
236 functions (such as size of types and capture-avoiding substitution) can |
237 only be defined manually via some laborious proof constructions. Therefore |
237 only be defined manually via some laborious proof constructions. Therefore |
238 we just assume them here. Cheat! *} |
238 we just assume them here. Cheat! *} |
239 |
239 |
240 consts size_ty :: "ty \<Rightarrow> nat" |
240 types 'a f1_ty = "tyvrs\<Rightarrow>('a::pt_tyvrs)" |
|
241 'a f2_ty = "('a::pt_tyvrs)" |
|
242 'a f3_ty = "ty\<Rightarrow>ty\<Rightarrow>'a\<Rightarrow>'a\<Rightarrow>('a::pt_tyvrs)" |
|
243 'a f4_ty = "tyvrs\<Rightarrow>ty\<Rightarrow>ty\<Rightarrow>'a\<Rightarrow>'a\<Rightarrow>('a::pt_tyvrs)" |
|
244 |
|
245 constdefs |
|
246 rfun :: "'a f1_ty \<Rightarrow> 'a f2_ty \<Rightarrow> 'a f3_ty \<Rightarrow> 'a f4_ty \<Rightarrow> ty \<Rightarrow> ('a::pt_tyvrs)" |
|
247 "rfun f1 f2 f3 f4 T \<equiv> (THE r. (T,r) \<in> ty_rec_set f1 f2 f3 f4)" |
|
248 |
|
249 lemma rfun_Tvar: |
|
250 assumes f1: "finite ((supp f1)::tyvrs set)" |
|
251 and f2: "finite ((supp f2)::tyvrs set)" |
|
252 and f3: "finite ((supp f3)::tyvrs set)" |
|
253 and f4: "finite ((supp f4)::tyvrs set)" |
|
254 and fcb: "\<And>X T1 T2 r1 r2. \<lbrakk>X\<sharp>f4; X\<sharp>T2; X\<sharp>r2\<rbrakk> \<Longrightarrow> X\<sharp>f4 X T1 T2 r1 r2" |
|
255 shows "rfun f1 f2 f3 f4 (Tvar X) = (f1 X)" |
|
256 apply(simp add: rfun_def) |
|
257 apply(rule trans) |
|
258 apply(rule the1_equality) |
|
259 apply(rule ty.rec_unique[where P="\<lambda>_. True"]) |
|
260 apply(simp_all add: f1 f2 f3 f4 fcb) |
|
261 apply(rule ty_rec_set.intros) |
|
262 done |
|
263 |
|
264 lemma rfun_Top: |
|
265 assumes f1: "finite ((supp f1)::tyvrs set)" |
|
266 and f2: "finite ((supp f2)::tyvrs set)" |
|
267 and f3: "finite ((supp f3)::tyvrs set)" |
|
268 and f4: "finite ((supp f4)::tyvrs set)" |
|
269 and fcb: "\<And>X T1 T2 r1 r2. \<lbrakk>X\<sharp>f4; X\<sharp>T2; X\<sharp>r2\<rbrakk> \<Longrightarrow> X\<sharp>f4 X T1 T2 r1 r2" |
|
270 shows "rfun f1 f2 f3 f4 (Top) = f2" |
|
271 apply(simp add: rfun_def) |
|
272 apply(rule trans) |
|
273 apply(rule the1_equality) |
|
274 apply(rule ty.rec_unique[where P="\<lambda>_. True"]) |
|
275 apply(simp_all add: f1 f2 f3 f4 fcb) |
|
276 apply(rule ty_rec_set.intros) |
|
277 done |
|
278 |
|
279 lemma rfun_Fun: |
|
280 assumes f1: "finite ((supp f1)::tyvrs set)" |
|
281 and f2: "finite ((supp f2)::tyvrs set)" |
|
282 and f3: "finite ((supp f3)::tyvrs set)" |
|
283 and f4: "finite ((supp f4)::tyvrs set)" |
|
284 and fcb: "\<And>X T1 T2 r1 r2. \<lbrakk>X\<sharp>f4; X\<sharp>T2; X\<sharp>r2\<rbrakk> \<Longrightarrow> X\<sharp>f4 X T1 T2 r1 r2" |
|
285 shows "rfun f1 f2 f3 f4 (T1\<rightarrow>T2) = f3 T1 T2 (rfun f1 f2 f3 f4 T1) (rfun f1 f2 f3 f4 T2)" |
|
286 apply(simp add: rfun_def) |
|
287 apply(rule trans) |
|
288 apply(rule the1_equality) |
|
289 apply(rule ty.rec_unique[where P="\<lambda>_. True"]) |
|
290 apply(simp_all add: f1 f2 f3 f4 fcb) |
|
291 apply(rule ty_rec_set.intros) |
|
292 apply(rule theI') |
|
293 apply(rule ty.rec_unique[where P="\<lambda>_. True"]) |
|
294 apply(simp_all add: f1 f2 f3 f4 fcb) |
|
295 apply(rule theI') |
|
296 apply(rule ty.rec_unique[where P="\<lambda>_. True"]) |
|
297 apply(simp_all add: f1 f2 f3 f4 fcb) |
|
298 done |
|
299 |
|
300 lemma rfun_All: |
|
301 assumes f1: "finite ((supp f1)::tyvrs set)" |
|
302 and f2: "finite ((supp f2)::tyvrs set)" |
|
303 and f3: "finite ((supp f3)::tyvrs set)" |
|
304 and f4: "finite ((supp f4)::tyvrs set)" |
|
305 and fcb: "\<And>X T1 T2 r1 r2. \<lbrakk>X\<sharp>f4; X\<sharp>T2; X\<sharp>r2\<rbrakk> \<Longrightarrow> X\<sharp>f4 X T1 T2 r1 r2" |
|
306 and fr: "X\<sharp>f1" "X\<sharp>f2" "X\<sharp>f3" "X\<sharp>f4" "X\<sharp>T2" |
|
307 shows "rfun f1 f2 f3 f4 (\<forall>[X<:T2].T1) = f4 X T1 T2 (rfun f1 f2 f3 f4 T1) (rfun f1 f2 f3 f4 T2)" |
|
308 apply(simp add: rfun_def) |
|
309 apply(rule trans) |
|
310 apply(rule the1_equality) |
|
311 apply(rule ty.rec_unique[where P="\<lambda>_. True"]) |
|
312 apply(simp_all add: f1 f2 f3 f4 fcb) |
|
313 apply(rule ty_rec_set.intros) |
|
314 apply(simp_all add: fr) |
|
315 apply(rule theI') |
|
316 apply(rule ty.rec_unique[where P="\<lambda>_. True"]) |
|
317 apply(simp_all add: f1 f2 f3 f4 fcb) |
|
318 apply(rule theI') |
|
319 apply(rule ty.rec_unique[where P="\<lambda>_. True"]) |
|
320 apply(simp_all add: f1 f2 f3 f4 fcb) |
|
321 done |
|
322 |
|
323 constdefs |
|
324 size_ty_Tvar :: "tyvrs \<Rightarrow> nat" |
|
325 "size_ty_Tvar \<equiv> \<lambda>_. 1" |
|
326 |
|
327 size_ty_Top :: "nat" |
|
328 "size_ty_Top \<equiv> 1" |
|
329 |
|
330 size_ty_Fun :: "ty \<Rightarrow> ty \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" |
|
331 "size_ty_Fun \<equiv> \<lambda>_ _ r1 r2. r1 + r2 + 1" |
|
332 |
|
333 size_ty_All :: "tyvrs \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" |
|
334 "size_ty_All \<equiv> \<lambda>_ _ _ r1 r2. r1 + r2 + 1" |
|
335 |
|
336 size_ty :: "ty \<Rightarrow> nat" |
|
337 "size_ty \<equiv> rfun size_ty_Tvar size_ty_Top size_ty_Fun size_ty_All" |
|
338 |
|
339 lemma fin_size_ty: |
|
340 shows "finite ((supp size_ty_Tvar)::tyvrs set)" |
|
341 and "finite ((supp size_ty_Top)::tyvrs set)" |
|
342 and "finite ((supp size_ty_Fun)::tyvrs set)" |
|
343 and "finite ((supp size_ty_All)::tyvrs set)" |
|
344 by (finite_guess add: size_ty_Tvar_def size_ty_Top_def size_ty_Fun_def size_ty_All_def perm_nat_def)+ |
|
345 |
|
346 lemma fcb_size_ty_All: |
|
347 assumes "X\<sharp>size_ty_All" "X\<sharp>T2" "X\<sharp>r2" |
|
348 shows "X\<sharp>(size_ty_All X T1 T2 r1 r2)" |
|
349 by (simp add: fresh_def supp_nat) |
241 |
350 |
242 lemma size_ty[simp]: |
351 lemma size_ty[simp]: |
243 shows "size_ty (Tvar X) = 1" |
352 shows "size_ty (Tvar X) = 1" |
244 and "size_ty (Top) = 1" |
353 and "size_ty (Top) = 1" |
245 and "\<lbrakk>size_ty T\<^isub>1 = m; size_ty T\<^isub>2 = n\<rbrakk> \<Longrightarrow> size_ty (T\<^isub>1 \<rightarrow> T\<^isub>2) = m + n + 1" |
354 and "size_ty (T1 \<rightarrow> T2) = (size_ty T1) + (size_ty T2) + 1" |
246 and "\<lbrakk>size_ty T\<^isub>1 = m; size_ty T\<^isub>2 = n\<rbrakk> \<Longrightarrow> size_ty (\<forall>[X<:T\<^isub>1].T\<^isub>2) = m + n + 1" |
355 and "X\<sharp>T1 \<Longrightarrow> size_ty (\<forall>[X<:T1].T2) = (size_ty T1) + (size_ty T2) + 1" |
247 sorry |
356 apply(unfold size_ty_def) |
248 |
357 apply(rule trans, rule rfun_Tvar) |
249 consts subst_ty :: "ty \<Rightarrow> tyvrs \<Rightarrow> ty \<Rightarrow> ty" ("_[_:=_]\<^isub>t\<^isub>y" [100,100,100] 100) |
358 apply(simp_all add: fin_size_ty fcb_size_ty_All) |
|
359 apply(simp add: size_ty_Tvar_def) |
|
360 apply(rule trans, rule rfun_Top) |
|
361 apply(simp_all add: fin_size_ty fcb_size_ty_All) |
|
362 apply(simp add: size_ty_Top_def) |
|
363 apply(rule trans, rule rfun_Fun) |
|
364 apply(simp_all add: fin_size_ty fcb_size_ty_All) |
|
365 apply(simp add: size_ty_Fun_def) |
|
366 apply(rule trans, rule rfun_All) |
|
367 apply(simp_all add: fin_size_ty fcb_size_ty_All) |
|
368 apply(fresh_guess add: perm_nat_def size_ty_Tvar_def size_ty_Top_def size_ty_Fun_def size_ty_All_def)+ |
|
369 apply(simp add: size_ty_All_def) |
|
370 done |
|
371 |
|
372 constdefs |
|
373 subst_Tvar :: "tyvrs \<Rightarrow>ty \<Rightarrow> tyvrs \<Rightarrow> ty" |
|
374 "subst_Tvar X T \<equiv> \<lambda>Y. (if Y=X then T else (Tvar Y))" |
|
375 |
|
376 subst_Top :: "tyvrs \<Rightarrow> ty \<Rightarrow> ty" |
|
377 "subst_Top X T \<equiv> Top" |
|
378 |
|
379 subst_Fun :: "tyvrs \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty" |
|
380 "subst_Fun X T \<equiv> \<lambda>_ _ r1 r2. r1 \<rightarrow> r2" |
|
381 |
|
382 subst_All :: "tyvrs \<Rightarrow> ty \<Rightarrow> tyvrs \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty" |
|
383 "subst_All X T \<equiv> \<lambda>Y _ _ r1 r2. \<forall>[Y<:r2].r1" |
|
384 |
|
385 subst_ty :: "tyvrs \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> ty" |
|
386 "subst_ty X T \<equiv> rfun (subst_Tvar X T) (subst_Top X T) (subst_Fun X T) (subst_All X T)" |
|
387 |
|
388 lemma supports_subst_Tvar: |
|
389 shows "((supp (X,T))::tyvrs set) supports (subst_Tvar X T)" |
|
390 apply(supports_simp add: subst_Tvar_def) |
|
391 apply(rule impI) |
|
392 apply(drule pt_bij1[OF pt_tyvrs_inst, OF at_tyvrs_inst]) |
|
393 apply(perm_simp) |
|
394 done |
|
395 |
|
396 lemma supports_subst_Top: |
|
397 shows "((supp (X,T))::tyvrs set) supports subst_Top X T" |
|
398 by (supports_simp add: subst_Top_def) |
|
399 |
|
400 lemma supports_subst_Fun: |
|
401 shows "((supp (X,T))::tyvrs set) supports subst_Fun X T" |
|
402 by (supports_simp add: subst_Fun_def) |
|
403 |
|
404 lemma supports_subst_All: |
|
405 shows "((supp (X,T))::tyvrs set) supports subst_All X T" |
|
406 apply(supports_simp add: subst_All_def) |
|
407 apply(perm_full_simp) |
|
408 done |
|
409 |
|
410 lemma fin_supp_subst: |
|
411 shows "finite ((supp (subst_Tvar X T))::tyvrs set)" |
|
412 and "finite ((supp (subst_Top X T))::tyvrs set)" |
|
413 and "finite ((supp (subst_Fun X T))::tyvrs set)" |
|
414 and "finite ((supp (subst_All X T))::tyvrs set)" |
|
415 apply - |
|
416 apply(rule supports_finite) |
|
417 apply(rule supports_subst_Tvar) |
|
418 apply(simp add: fs_tyvrs1) |
|
419 apply(finite_guess add: subst_Top_def subst_Fun_def subst_All_def fs_tyvrs1)+ |
|
420 apply(perm_full_simp) |
|
421 done |
|
422 |
|
423 lemma fcb_subst_All: |
|
424 assumes fr: "X\<sharp>(subst_All Y T)" "X\<sharp>T2" "X\<sharp>r2" |
|
425 shows "X\<sharp>(subst_All Y T) X T1 T2 r1 r2" |
|
426 apply (simp add: subst_All_def abs_fresh fr) |
|
427 done |
|
428 |
|
429 syntax |
|
430 subst_ty_syn :: "ty \<Rightarrow> tyvrs \<Rightarrow> ty \<Rightarrow> ty" ("_[_:=_]\<^isub>t\<^isub>y" [100,100,100] 100) |
|
431 |
|
432 translations |
|
433 "T1[Y:=T2]\<^isub>t\<^isub>y" \<rightleftharpoons> "subst_ty Y T2 T1" |
250 |
434 |
251 lemma subst_ty[simp]: |
435 lemma subst_ty[simp]: |
252 shows "(Tvar X)[Y:=T]\<^isub>t\<^isub>y = (if X=Y then T else (Tvar X))" |
436 shows "(Tvar X)[Y:=T]\<^isub>t\<^isub>y= (if X=Y then T else (Tvar X))" |
253 and "(Top)[Y:=T]\<^isub>t\<^isub>y = Top" |
437 and "(Top)[Y:=T]\<^isub>t\<^isub>y = Top" |
254 and "(T\<^isub>1 \<rightarrow> T\<^isub>2)[Y:=T]\<^isub>t\<^isub>y = (T\<^isub>1[Y:=T]\<^isub>t\<^isub>y) \<rightarrow> (T\<^isub>2[Y:=T]\<^isub>t\<^isub>y)" |
438 and "(T\<^isub>1 \<rightarrow> T\<^isub>2)[Y:=T]\<^isub>t\<^isub>y = (T\<^isub>1[Y:=T]\<^isub>t\<^isub>y) \<rightarrow> (T\<^isub>2[Y:=T]\<^isub>t\<^isub>y)" |
255 and "X\<sharp>(Y,T) \<Longrightarrow> (\<forall>[X<:T\<^isub>1].T\<^isub>2)[Y:=T]\<^isub>t\<^isub>y = (\<forall>[X<:(T\<^isub>1[Y:=T]\<^isub>t\<^isub>y)].(T\<^isub>2[Y:=T]\<^isub>t\<^isub>y))" |
439 and "\<lbrakk>X\<sharp>(Y,T); X\<sharp>T\<^isub>1\<rbrakk> \<Longrightarrow> (\<forall>[X<:T\<^isub>1].T\<^isub>2)[Y:=T]\<^isub>t\<^isub>y = (\<forall>[X<:(T\<^isub>1[Y:=T]\<^isub>t\<^isub>y)].(T\<^isub>2[Y:=T]\<^isub>t\<^isub>y))" |
256 and "\<lbrakk>X\<sharp>Y; X\<sharp>T\<rbrakk> \<Longrightarrow> (\<forall>[X<:T\<^isub>1].T\<^isub>2)[Y:=T]\<^isub>t\<^isub>y = (\<forall>[X<:(T\<^isub>1[Y:=T]\<^isub>t\<^isub>y)].(T\<^isub>2[Y:=T]\<^isub>t\<^isub>y))" |
440 apply - |
257 sorry |
441 apply(unfold subst_ty_def) |
|
442 apply(rule trans) |
|
443 apply(rule rfun_Tvar[OF fin_supp_subst, OF fcb_subst_All]) |
|
444 apply(assumption)+ |
|
445 apply(simp add: subst_Tvar_def) |
|
446 apply(rule trans) |
|
447 apply(rule rfun_Top[OF fin_supp_subst, OF fcb_subst_All]) |
|
448 apply(assumption)+ |
|
449 apply(simp add: subst_Top_def) |
|
450 apply(rule trans) |
|
451 apply(rule rfun_Fun[OF fin_supp_subst, OF fcb_subst_All]) |
|
452 apply(assumption)+ |
|
453 apply(simp add: subst_Fun_def) |
|
454 apply(rule trans) |
|
455 apply(rule rfun_All[OF fin_supp_subst, OF fcb_subst_All]) |
|
456 apply(assumption)+ |
|
457 apply(rule supports_fresh) |
|
458 apply(rule supports_subst_Tvar) |
|
459 apply(simp add: fs_tyvrs1, simp add: fresh_def) |
|
460 apply(fresh_guess add: fresh_prod subst_Top_def fs_tyvrs1) |
|
461 apply(fresh_guess add: fresh_prod subst_Fun_def fs_tyvrs1) |
|
462 apply(fresh_guess add: fresh_prod subst_All_def fs_tyvrs1) |
|
463 apply(perm_full_simp) |
|
464 apply(assumption) |
|
465 apply(simp add: subst_All_def) |
|
466 done |
258 |
467 |
259 consts subst_tyc :: "ty_context \<Rightarrow> tyvrs \<Rightarrow> ty \<Rightarrow> ty_context" ("_[_:=_]\<^isub>t\<^isub>y\<^isub>c" [100,100,100] 100) |
468 consts subst_tyc :: "ty_context \<Rightarrow> tyvrs \<Rightarrow> ty \<Rightarrow> ty_context" ("_[_:=_]\<^isub>t\<^isub>y\<^isub>c" [100,100,100] 100) |
260 primrec |
469 primrec |
261 "([])[Y:=T]\<^isub>t\<^isub>y\<^isub>c= []" |
470 "([])[Y:=T]\<^isub>t\<^isub>y\<^isub>c= []" |
262 "(XT#\<Gamma>)[Y:=T]\<^isub>t\<^isub>y\<^isub>c = (fst XT,(snd XT)[Y:=T]\<^isub>t\<^isub>y)#(\<Gamma>[Y:=T]\<^isub>t\<^isub>y\<^isub>c)" |
471 "(XT#\<Gamma>)[Y:=T]\<^isub>t\<^isub>y\<^isub>c = (fst XT,(snd XT)[Y:=T]\<^isub>t\<^isub>y)#(\<Gamma>[Y:=T]\<^isub>t\<^isub>y\<^isub>c)" |