303 then raw_nominal_decls dts bn_funs bn_eqs bclauses lthy |
303 then raw_nominal_decls dts bn_funs bn_eqs bclauses lthy |
304 else raise TEST lthy |
304 else raise TEST lthy |
305 |
305 |
306 val dtinfo = Datatype.the_info (ProofContext.theory_of lthy0) (hd raw_dt_names) |
306 val dtinfo = Datatype.the_info (ProofContext.theory_of lthy0) (hd raw_dt_names) |
307 val {descr, sorts, ...} = dtinfo |
307 val {descr, sorts, ...} = dtinfo |
308 val all_raw_tys = map (fn (_, (n, _, _)) => n) descr |
308 val all_raw_tys = all_dtyps descr sorts |
|
309 val all_raw_ty_names = map (fn (_, (n, _, _)) => n) descr |
309 val all_raw_constrs = |
310 val all_raw_constrs = |
310 flat (map (map (fn (c, _, _, _) => c)) (all_dtyp_constrs_types descr sorts)) |
311 flat (map (map (fn (c, _, _, _) => c)) (all_dtyp_constrs_types descr sorts)) |
311 |
312 |
312 val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy0)) all_raw_tys |
313 val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy0)) all_raw_ty_names |
313 val inject_thms = flat (map #inject dtinfos); |
314 val inject_thms = flat (map #inject dtinfos); |
314 val distinct_thms = flat (map #distinct dtinfos); |
315 val distinct_thms = flat (map #distinct dtinfos); |
315 val constr_thms = inject_thms @ distinct_thms |
316 val constr_thms = inject_thms @ distinct_thms |
316 val rel_dtinfos = List.take (dtinfos, (length dts)); |
317 val rel_dtinfos = List.take (dtinfos, (length dts)); |
317 val raw_constrs_distinct = (map #distinct rel_dtinfos); |
318 val raw_constrs_distinct = (map #distinct rel_dtinfos); |
318 val induct_thm = #induct dtinfo; |
319 val raw_induct_thm = #induct dtinfo; |
|
320 val raw_induct_thms = #inducts dtinfo; |
319 val exhaust_thms = map #exhaust dtinfos; |
321 val exhaust_thms = map #exhaust dtinfos; |
|
322 val raw_size_trms = map (fn ty => Const (@{const_name size}, ty --> @{typ nat})) all_raw_tys |
|
323 val raw_size_thms = Size.size_thms (ProofContext.theory_of lthy0) (hd raw_dt_names) |
|
324 |> `(fn thms => (length thms) div 2) |
|
325 |> (uncurry drop) |
|
326 |
320 |
327 |
321 (* definitions of raw permutations *) |
328 (* definitions of raw permutations *) |
322 val _ = warning "Definition of raw permutations"; |
329 val _ = warning "Definition of raw permutations"; |
323 val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2) = |
330 val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2) = |
324 if get_STEPS lthy0 > 1 |
331 if get_STEPS lthy0 > 1 |
325 then Local_Theory.theory_result (define_raw_perms descr sorts induct_thm (length dts)) lthy0 |
332 then Local_Theory.theory_result (define_raw_perms descr sorts raw_induct_thm (length dts)) lthy0 |
326 else raise TEST lthy0 |
333 else raise TEST lthy0 |
327 |
334 |
328 (* noting the raw permutations as eqvt theorems *) |
335 (* noting the raw permutations as eqvt theorems *) |
329 val eqvt_attrib = Attrib.internal (K Nominal_ThmDecls.eqvt_add) |
336 val eqvt_attrib = Attrib.internal (K Nominal_ThmDecls.eqvt_add) |
330 val (_, lthy2a) = Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_perm_simps) lthy2 |
337 val (_, lthy2a) = Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_perm_simps) lthy2 |
336 val _ = warning "Definition of raw fv-functions"; |
343 val _ = warning "Definition of raw fv-functions"; |
337 val lthy3 = Theory_Target.init NONE thy; |
344 val lthy3 = Theory_Target.init NONE thy; |
338 |
345 |
339 val (raw_bns, raw_bn_eqs, raw_bn_info, raw_bn_induct, lthy3a) = |
346 val (raw_bns, raw_bn_eqs, raw_bn_info, raw_bn_induct, lthy3a) = |
340 if get_STEPS lthy3 > 2 |
347 if get_STEPS lthy3 > 2 |
341 then raw_bn_decls all_raw_tys raw_dts raw_bn_funs raw_bn_eqs constr_thms lthy3 |
348 then raw_bn_decls all_raw_ty_names raw_dts raw_bn_funs raw_bn_eqs constr_thms lthy3 |
342 else raise TEST lthy3 |
349 else raise TEST lthy3 |
343 |
350 |
344 val (raw_fvs, raw_fv_bns, raw_fv_defs, raw_fv_bns_induct, lthy3b) = |
351 val (raw_fvs, raw_fv_bns, raw_fv_defs, raw_fv_bns_induct, lthy3b) = |
345 if get_STEPS lthy3a > 3 |
352 if get_STEPS lthy3a > 3 |
346 then define_raw_fvs descr sorts raw_bn_info raw_bclauses constr_thms lthy3a |
353 then define_raw_fvs descr sorts raw_bn_info raw_bclauses constr_thms lthy3a |
379 val lthy_tmp = snd (Local_Theory.note ((Binding.empty, [add_eqvt]), bn_eqvt) lthy4) |
386 val lthy_tmp = snd (Local_Theory.note ((Binding.empty, [add_eqvt]), bn_eqvt) lthy4) |
380 |
387 |
381 val fv_eqvt = |
388 val fv_eqvt = |
382 if get_STEPS lthy > 7 |
389 if get_STEPS lthy > 7 |
383 then raw_prove_eqvt (raw_fvs @ raw_fv_bns) raw_fv_bns_induct (raw_fv_defs @ raw_perm_simps) |
390 then raw_prove_eqvt (raw_fvs @ raw_fv_bns) raw_fv_bns_induct (raw_fv_defs @ raw_perm_simps) |
384 (Local_Theory.restore lthy_tmp) |
391 (Local_Theory.restore lthy_tmp) |
|
392 else raise TEST lthy4 |
|
393 |
|
394 val size_eqvt = |
|
395 if get_STEPS lthy > 8 |
|
396 then raw_prove_eqvt raw_size_trms raw_induct_thms (raw_size_thms @ raw_perm_simps) |
|
397 (Local_Theory.restore lthy_tmp) |
385 else raise TEST lthy4 |
398 else raise TEST lthy4 |
386 |
399 |
387 val lthy5 = snd (Local_Theory.note ((Binding.empty, [add_eqvt]), fv_eqvt) lthy_tmp) |
400 val lthy5 = snd (Local_Theory.note ((Binding.empty, [add_eqvt]), fv_eqvt) lthy_tmp) |
388 |
401 |
389 val (alpha_eqvt, lthy6) = |
402 val (alpha_eqvt, lthy6) = |
390 if get_STEPS lthy > 8 |
403 if get_STEPS lthy > 9 |
391 then Nominal_Eqvt.equivariance true (alpha_trms @ alpha_bn_trms) alpha_induct alpha_intros lthy5 |
404 then Nominal_Eqvt.equivariance true (alpha_trms @ alpha_bn_trms) alpha_induct alpha_intros lthy5 |
392 else raise TEST lthy4 |
405 else raise TEST lthy4 |
393 |
406 |
394 (* proving alpha equivalence *) |
407 (* proving alpha equivalence *) |
395 val _ = warning "Proving equivalence" |
408 val _ = warning "Proving equivalence" |
396 |
409 |
397 val alpha_refl_thms = |
410 val alpha_refl_thms = |
398 if get_STEPS lthy > 9 |
411 if get_STEPS lthy > 10 |
399 then raw_prove_refl alpha_trms alpha_bn_trms alpha_intros induct_thm lthy6 |
412 then raw_prove_refl alpha_trms alpha_bn_trms alpha_intros raw_induct_thm lthy6 |
400 else raise TEST lthy6 |
413 else raise TEST lthy6 |
401 |
414 |
402 val alpha_sym_thms = |
415 val alpha_sym_thms = |
403 if get_STEPS lthy > 10 |
416 if get_STEPS lthy > 11 |
404 then raw_prove_sym (alpha_trms @ alpha_bn_trms) alpha_intros alpha_induct lthy6 |
417 then raw_prove_sym (alpha_trms @ alpha_bn_trms) alpha_intros alpha_induct lthy6 |
405 else raise TEST lthy6 |
418 else raise TEST lthy6 |
406 |
419 |
407 val alpha_trans_thms = |
420 val alpha_trans_thms = |
408 if get_STEPS lthy > 11 |
421 if get_STEPS lthy > 12 |
409 then raw_prove_trans (alpha_trms @ alpha_bn_trms) (distinct_thms @ inject_thms) |
422 then raw_prove_trans (alpha_trms @ alpha_bn_trms) (distinct_thms @ inject_thms) |
410 alpha_intros alpha_induct alpha_cases lthy6 |
423 alpha_intros alpha_induct alpha_cases lthy6 |
411 else raise TEST lthy6 |
424 else raise TEST lthy6 |
412 |
425 |
413 val alpha_equivp_thms = |
426 val alpha_equivp_thms = |
414 if get_STEPS lthy > 12 |
427 if get_STEPS lthy > 13 |
415 then raw_prove_equivp alpha_trms alpha_refl_thms alpha_sym_thms alpha_trans_thms lthy6 |
428 then raw_prove_equivp alpha_trms alpha_refl_thms alpha_sym_thms alpha_trans_thms lthy6 |
416 else raise TEST lthy6 |
429 else raise TEST lthy6 |
417 |
430 |
418 (* proving alpha implies alpha_bn *) |
431 (* proving alpha implies alpha_bn *) |
419 val _ = warning "Proving alpha implies bn" |
432 val _ = warning "Proving alpha implies bn" |
420 |
433 |
421 val alpha_bn_imp_thms = |
434 val alpha_bn_imp_thms = |
422 if get_STEPS lthy > 13 |
435 if get_STEPS lthy > 14 |
423 then raw_prove_bn_imp alpha_trms alpha_bn_trms alpha_intros alpha_induct lthy6 |
436 then raw_prove_bn_imp alpha_trms alpha_bn_trms alpha_intros alpha_induct lthy6 |
424 else raise TEST lthy6 |
437 else raise TEST lthy6 |
425 |
438 |
426 (* auxiliary lemmas for respectfulness proofs *) |
439 (* auxiliary lemmas for respectfulness proofs *) |
427 (* HERE *) |
440 val raw_funs_rsp = raw_fv_bn_rsp_aux alpha_trms alpha_bn_trms raw_fvs |
428 |
441 raw_bns raw_fv_bns alpha_induct (raw_bn_eqs @ raw_fv_defs) lthy6 |
429 val test = raw_fv_bn_rsp_aux alpha_trms alpha_bn_trms raw_fvs raw_bns raw_fv_bns |
442 |
430 alpha_induct (raw_bn_eqs @ raw_fv_defs) lthy6 |
|
431 val _ = tracing ("goals\n" ^ cat_lines (map (Syntax.string_of_term lthy6 o prop_of) test)) |
|
432 |
443 |
433 (* defining the quotient type *) |
444 (* defining the quotient type *) |
434 val _ = warning "Declaring the quotient types" |
445 val _ = warning "Declaring the quotient types" |
435 val qty_descr = map (fn (vs, bind, mx, _) => (vs, bind, mx)) dts |
446 val qty_descr = map (fn (vs, bind, mx, _) => (vs, bind, mx)) dts |
436 val qty_binds = map (fn (_, bind, _, _) => bind) dts |
447 val qty_binds = map (fn (_, bind, _, _) => bind) dts |
437 val qty_names = map Name.of_binding qty_binds; |
448 val qty_names = map Name.of_binding qty_binds; |
438 val qty_full_names = map (Long_Name.qualify thy_name) qty_names (* not used *) |
449 val qty_full_names = map (Long_Name.qualify thy_name) qty_names (* not used *) |
439 |
450 |
440 val (qty_infos, lthy7) = |
451 val (qty_infos, lthy7) = |
441 if get_STEPS lthy > 14 |
452 if get_STEPS lthy > 15 |
442 then qtype_defs qty_descr alpha_tys alpha_trms alpha_equivp_thms lthy6 |
453 then qtype_defs qty_descr alpha_tys alpha_trms alpha_equivp_thms lthy6 |
443 else raise TEST lthy6 |
454 else raise TEST lthy6 |
444 |
455 |
445 val qtys = map #qtyp qty_infos |
456 val qtys = map #qtyp qty_infos |
446 |
457 |
477 val qbns = map #qconst qbns_info |
488 val qbns = map #qconst qbns_info |
478 val qfvs = map #qconst qfvs_info |
489 val qfvs = map #qconst qfvs_info |
479 val qfv_bns = map #qconst qfv_bns_info |
490 val qfv_bns = map #qconst qfv_bns_info |
480 val qalpha_bns = map #qconst qalpha_bns_info |
491 val qalpha_bns = map #qconst qalpha_bns_info |
481 |
492 |
482 (* HERE *) |
493 (* temporary theorem bindings *) |
483 |
494 |
484 val (_, lthy8') = lthy8 |
495 val (_, lthy8') = lthy8 |
485 |> Local_Theory.note ((@{binding "distinct"}, []), alpha_distincts) |
496 |> Local_Theory.note ((@{binding "distinct"}, []), alpha_distincts) |
486 ||>> Local_Theory.note ((@{binding "eq_iff"}, []), alpha_eq_iff) |
497 ||>> Local_Theory.note ((@{binding "eq_iff"}, []), alpha_eq_iff) |
487 ||>> Local_Theory.note ((@{binding "eq_iff_simps"}, []), alpha_eq_iff_simps) |
498 ||>> Local_Theory.note ((@{binding "eq_iff_simps"}, []), alpha_eq_iff_simps) |
488 ||>> Local_Theory.note ((@{binding "fv_defs"}, []), raw_fv_defs) |
499 ||>> Local_Theory.note ((@{binding "fv_defs"}, []), raw_fv_defs) |
489 ||>> Local_Theory.note ((@{binding "perm_simps"}, []), raw_perm_simps) |
500 ||>> Local_Theory.note ((@{binding "perm_simps"}, []), raw_perm_simps) |
490 ||>> Local_Theory.note ((@{binding "perm_laws"}, []), raw_perm_laws) |
501 ||>> Local_Theory.note ((@{binding "perm_laws"}, []), raw_perm_laws) |
491 ||>> Local_Theory.note ((@{binding "alpha_bn_imps"}, []), alpha_bn_imp_thms) |
502 ||>> Local_Theory.note ((@{binding "alpha_bn_imps"}, []), alpha_bn_imp_thms) |
|
503 ||>> Local_Theory.note ((@{binding "funs_rsp"}, []), raw_funs_rsp) |
|
504 ||>> Local_Theory.note ((@{binding "size_eqvt"}, []), size_eqvt) |
492 |
505 |
493 val _ = |
506 val _ = |
494 if get_STEPS lthy > 16 |
507 if get_STEPS lthy > 17 |
495 then true else raise TEST lthy8' |
508 then true else raise TEST lthy8' |
496 |
509 |
497 (* old stuff *) |
510 (* old stuff *) |
498 |
511 |
499 val _ = warning "Proving respects"; |
512 val _ = warning "Proving respects"; |
556 |
569 |
557 val q_name = space_implode "_" qty_names; |
570 val q_name = space_implode "_" qty_names; |
558 fun suffix_bind s = Binding.qualify true q_name (Binding.name s); |
571 fun suffix_bind s = Binding.qualify true q_name (Binding.name s); |
559 val _ = warning "Lifting induction"; |
572 val _ = warning "Lifting induction"; |
560 val constr_names = map (Long_Name.base_name o fst o dest_Const) qconstrs; |
573 val constr_names = map (Long_Name.base_name o fst o dest_Const) qconstrs; |
561 val q_induct = Rule_Cases.name constr_names (lift_thm qtys lthy13 induct_thm); |
574 val q_induct = Rule_Cases.name constr_names (lift_thm qtys lthy13 raw_induct_thm); |
562 fun note_suffix s th ctxt = |
575 fun note_suffix s th ctxt = |
563 snd (Local_Theory.note ((suffix_bind s, []), th) ctxt); |
576 snd (Local_Theory.note ((suffix_bind s, []), th) ctxt); |
564 fun note_simp_suffix s th ctxt = |
577 fun note_simp_suffix s th ctxt = |
565 snd (Local_Theory.note ((suffix_bind s, [Attrib.internal (K Simplifier.simp_add)]), th) ctxt); |
578 snd (Local_Theory.note ((suffix_bind s, [Attrib.internal (K Simplifier.simp_add)]), th) ctxt); |
566 val (_, lthy14) = Local_Theory.note ((suffix_bind "induct", |
579 val (_, lthy14) = Local_Theory.note ((suffix_bind "induct", |