310 then raw_nominal_decls dts bn_funs bn_eqs bclauses lthy |
310 then raw_nominal_decls dts bn_funs bn_eqs bclauses lthy |
311 else raise TEST lthy |
311 else raise TEST lthy |
312 |
312 |
313 val dtinfo = Datatype.the_info (ProofContext.theory_of lthy0) (hd raw_dt_names) |
313 val dtinfo = Datatype.the_info (ProofContext.theory_of lthy0) (hd raw_dt_names) |
314 val {descr, sorts, ...} = dtinfo |
314 val {descr, sorts, ...} = dtinfo |
315 val all_raw_constrs = |
315 val raw_constrs = |
316 flat (map (map (fn (c, _, _, _) => c)) (all_dtyp_constrs_types descr sorts)) |
316 flat (map (map (fn (c, _, _, _) => c)) (all_dtyp_constrs_types descr sorts)) |
317 val all_raw_tys = all_dtyps descr sorts |
317 val raw_tys = all_dtyps descr sorts |
318 val all_raw_ty_names = map (fst o dest_Type) all_raw_tys |
318 val raw_full_ty_names = map (fst o dest_Type) raw_tys |
319 |
319 |
320 val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy0)) all_raw_ty_names |
320 val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy0)) raw_full_ty_names |
321 val inject_thms = flat (map #inject dtinfos) |
321 |
322 val distinct_thms = flat (map #distinct dtinfos) |
322 val raw_inject_thms = flat (map #inject dtinfos) |
323 val constr_thms = inject_thms @ distinct_thms |
323 val raw_distinct_thms = flat (map #distinct dtinfos) |
324 |
324 val raw_induct_thm = #induct dtinfo |
325 val raw_induct_thm = #induct dtinfo; |
325 val raw_induct_thms = #inducts dtinfo |
326 val raw_induct_thms = #inducts dtinfo; |
326 val raw_exhaust_thms = map #exhaust dtinfos |
327 val exhaust_thms = map #exhaust dtinfos; |
327 val raw_size_trms = map size_const raw_tys |
328 val raw_size_trms = map size_const all_raw_tys |
|
329 val raw_size_thms = Size.size_thms (ProofContext.theory_of lthy0) (hd raw_dt_names) |
328 val raw_size_thms = Size.size_thms (ProofContext.theory_of lthy0) (hd raw_dt_names) |
330 |> `(fn thms => (length thms) div 2) |
329 |> `(fn thms => (length thms) div 2) |
331 |> uncurry drop |
330 |> uncurry drop |
332 |
331 |
333 (* definitions of raw permutations *) |
332 (* definitions of raw permutations *) |
334 val _ = warning "Definition of raw permutations"; |
333 val _ = warning "Definition of raw permutations"; |
335 val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2) = |
334 val ((raw_perm_funs, raw_perm_simps, raw_perm_laws), lthy2) = |
336 if get_STEPS lthy0 > 1 |
335 if get_STEPS lthy0 > 1 |
337 then Local_Theory.theory_result |
336 then Local_Theory.theory_result |
338 (define_raw_perms all_raw_ty_names all_raw_tys all_raw_constrs raw_induct_thm) lthy0 |
337 (define_raw_perms raw_full_ty_names raw_tys raw_constrs raw_induct_thm) lthy0 |
339 else raise TEST lthy0 |
338 else raise TEST lthy0 |
340 val lthy2a = Named_Target.reinit lthy2 lthy2 |
339 val lthy2a = Named_Target.reinit lthy2 lthy2 |
341 |
340 |
342 (* noting the raw permutations as eqvt theorems *) |
341 (* noting the raw permutations as eqvt theorems *) |
343 val (_, lthy3) = Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_perm_simps) lthy2a |
342 val (_, lthy3) = Local_Theory.note ((Binding.empty, [eqvt_attrib]), raw_perm_simps) lthy2a |
344 |
343 |
345 (* definition of raw fv_functions *) |
344 (* definition of raw fv_functions *) |
346 val _ = warning "Definition of raw fv-functions"; |
345 val _ = warning "Definition of raw fv-functions"; |
347 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) = |
348 if get_STEPS lthy3 > 2 |
347 if get_STEPS lthy3 > 2 |
349 then raw_bn_decls all_raw_ty_names raw_dts raw_bn_funs raw_bn_eqs constr_thms lthy3 |
348 then raw_bn_decls raw_full_ty_names raw_dts raw_bn_funs raw_bn_eqs |
|
349 (raw_inject_thms @ raw_distinct_thms) lthy3 |
350 else raise TEST lthy3 |
350 else raise TEST lthy3 |
351 |
351 |
352 val (raw_fvs, raw_fv_bns, raw_fv_defs, raw_fv_bns_induct, lthy3b) = |
352 val (raw_fvs, raw_fv_bns, raw_fv_defs, raw_fv_bns_induct, lthy3b) = |
353 if get_STEPS lthy3a > 3 |
353 if get_STEPS lthy3a > 3 |
354 then define_raw_fvs descr sorts raw_bn_info raw_bclauses constr_thms lthy3a |
354 then define_raw_fvs descr sorts raw_bn_info raw_bclauses (raw_inject_thms @ raw_distinct_thms) lthy3a |
355 else raise TEST lthy3a |
355 else raise TEST lthy3a |
356 |
356 |
357 (* definition of raw alphas *) |
357 (* definition of raw alphas *) |
358 val _ = warning "Definition of alphas"; |
358 val _ = warning "Definition of alphas"; |
359 val (alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy4) = |
359 val (alpha_trms, alpha_bn_trms, alpha_intros, alpha_cases, alpha_induct, lthy4) = |
363 val alpha_tys = map (domain_type o fastype_of) alpha_trms |
363 val alpha_tys = map (domain_type o fastype_of) alpha_trms |
364 |
364 |
365 (* definition of alpha-distinct lemmas *) |
365 (* definition of alpha-distinct lemmas *) |
366 val _ = warning "Distinct theorems"; |
366 val _ = warning "Distinct theorems"; |
367 val alpha_distincts = |
367 val alpha_distincts = |
368 mk_alpha_distincts lthy4 alpha_cases distinct_thms alpha_trms all_raw_tys |
368 mk_alpha_distincts lthy4 alpha_cases raw_distinct_thms alpha_trms raw_tys |
369 |
369 |
370 (* definition of alpha_eq_iff lemmas *) |
370 (* definition of alpha_eq_iff lemmas *) |
371 (* they have a funny shape for the simplifier *) |
371 (* they have a funny shape for the simplifier *) |
372 val _ = warning "Eq-iff theorems"; |
372 val _ = warning "Eq-iff theorems"; |
373 val (alpha_eq_iff_simps, alpha_eq_iff) = |
373 val (alpha_eq_iff_simps, alpha_eq_iff) = |
374 if get_STEPS lthy > 5 |
374 if get_STEPS lthy > 5 |
375 then mk_alpha_eq_iff lthy4 alpha_intros distinct_thms inject_thms alpha_cases |
375 then mk_alpha_eq_iff lthy4 alpha_intros raw_distinct_thms raw_inject_thms alpha_cases |
376 else raise TEST lthy4 |
376 else raise TEST lthy4 |
377 |
377 |
378 (* proving equivariance lemmas for bns, fvs, size and alpha *) |
378 (* proving equivariance lemmas for bns, fvs, size and alpha *) |
379 val _ = warning "Proving equivariance"; |
379 val _ = warning "Proving equivariance"; |
380 val bn_eqvt = |
380 val bn_eqvt = |
460 else raise TEST lthy6 |
460 else raise TEST lthy6 |
461 |
461 |
462 (* defining the quotient type *) |
462 (* defining the quotient type *) |
463 val _ = warning "Declaring the quotient types" |
463 val _ = warning "Declaring the quotient types" |
464 val qty_descr = map (fn (vs, bind, mx, _) => (vs, bind, mx)) dts |
464 val qty_descr = map (fn (vs, bind, mx, _) => (vs, bind, mx)) dts |
465 val qty_binds = map (fn (_, bind, _, _) => bind) dts |
465 |
466 val qty_names = map Name.of_binding qty_binds; |
|
467 |
|
468 val (qty_infos, lthy7) = |
466 val (qty_infos, lthy7) = |
469 if get_STEPS lthy > 16 |
467 if get_STEPS lthy > 16 |
470 then qtype_defs qty_descr alpha_tys alpha_trms alpha_equivp_thms lthy6a |
468 then define_qtypes qty_descr alpha_tys alpha_trms alpha_equivp_thms lthy6a |
471 else raise TEST lthy6a |
469 else raise TEST lthy6a |
472 |
470 |
473 val qtys = map #qtyp qty_infos |
471 val qtys = map #qtyp qty_infos |
474 |
472 val qty_full_names = map (fst o dest_Type) qtys |
|
473 val qty_names = map Long_Name.base_name qty_full_names |
|
474 |
|
475 |
475 (* defining of quotient term-constructors, binding functions, free vars functions *) |
476 (* defining of quotient term-constructors, binding functions, free vars functions *) |
476 val _ = warning "Defining the quotient constants" |
477 val _ = warning "Defining the quotient constants" |
477 val qconstrs_descr = |
478 val qconstrs_descr = |
478 flat (map (fn (_, _, _, cs) => map (fn (b, _, mx) => (Name.of_binding b, mx)) cs) dts) |
479 flat (map (fn (_, _, _, cs) => map (fn (b, _, mx) => (Name.of_binding b, mx)) cs) dts) |
479 |> map2 (fn t => fn (b, mx) => (b, t, mx)) all_raw_constrs |
480 |> map2 (fn t => fn (b, mx) => (b, t, mx)) raw_constrs |
480 |
481 |
481 val qbns_descr = |
482 val qbns_descr = |
482 map2 (fn (b, _, mx) => fn t => (Name.of_binding b, t, mx)) bn_funs raw_bns |
483 map2 (fn (b, _, mx) => fn t => (Name.of_binding b, t, mx)) bn_funs raw_bns |
483 |
484 |
484 val qfvs_descr = |
485 val qfvs_descr = |
490 val qalpha_bns_descr = |
491 val qalpha_bns_descr = |
491 map2 (fn (b, _, _) => fn t => ("alpha_" ^ Name.of_binding b, t, NoSyn)) bn_funs alpha_bn_trms |
492 map2 (fn (b, _, _) => fn t => ("alpha_" ^ Name.of_binding b, t, NoSyn)) bn_funs alpha_bn_trms |
492 |
493 |
493 val qperm_descr = |
494 val qperm_descr = |
494 map2 (fn n => fn t => ("permute_" ^ n, t, NoSyn)) qty_names raw_perm_funs |
495 map2 (fn n => fn t => ("permute_" ^ n, t, NoSyn)) qty_names raw_perm_funs |
|
496 |
|
497 val qsize_descr = |
|
498 map2 (fn n => fn t => ("size_" ^ n, t, NoSyn)) qty_names raw_size_trms |
495 |
499 |
496 val (((((qconstrs_info, qbns_info), qfvs_info), qfv_bns_info), qalpha_bns_info), lthy8) = |
500 val (((((qconstrs_info, qbns_info), qfvs_info), qfv_bns_info), qalpha_bns_info), lthy8) = |
497 if get_STEPS lthy > 17 |
501 if get_STEPS lthy > 17 |
498 then |
502 then |
499 lthy7 |
503 lthy7 |
500 |> qconst_defs qtys qconstrs_descr |
504 |> define_qconsts qtys qconstrs_descr |
501 ||>> qconst_defs qtys qbns_descr |
505 ||>> define_qconsts qtys qbns_descr |
502 ||>> qconst_defs qtys qfvs_descr |
506 ||>> define_qconsts qtys qfvs_descr |
503 ||>> qconst_defs qtys qfv_bns_descr |
507 ||>> define_qconsts qtys qfv_bns_descr |
504 ||>> qconst_defs qtys qalpha_bns_descr |
508 ||>> define_qconsts qtys qalpha_bns_descr |
505 else raise TEST lthy7 |
509 else raise TEST lthy7 |
506 |
510 |
507 (*val _ = Local_Theory.theory_result |
511 (* definition of the quotient permfunctions and pt-class *) |
508 (qperm_defs qtys qty_full_names qperm_descr raw_perm_laws) lthy8*) |
512 val lthy9 = |
509 |
513 if get_STEPS lthy > 18 |
|
514 then Local_Theory.theory |
|
515 (define_qperms qtys qty_full_names qperm_descr raw_perm_laws) lthy8 |
|
516 else raise TEST lthy8 |
|
517 |
|
518 val lthy9' = |
|
519 if get_STEPS lthy > 19 |
|
520 then Local_Theory.theory |
|
521 (define_qsizes qtys qty_full_names qsize_descr) lthy9 |
|
522 else raise TEST lthy9 |
|
523 |
|
524 val lthy9a = Named_Target.reinit lthy9' lthy9' |
510 |
525 |
511 val qconstrs = map #qconst qconstrs_info |
526 val qconstrs = map #qconst qconstrs_info |
512 val qbns = map #qconst qbns_info |
527 val qbns = map #qconst qbns_info |
513 val qfvs = map #qconst qfvs_info |
528 val qfvs = map #qconst qfvs_info |
514 val qfv_bns = map #qconst qfv_bns_info |
529 val qfv_bns = map #qconst qfv_bns_info |
515 val qalpha_bns = map #qconst qalpha_bns_info |
530 val qalpha_bns = map #qconst qalpha_bns_info |
516 |
531 |
517 |
532 |
518 (* temporary theorem bindings *) |
533 (* temporary theorem bindings *) |
519 |
534 |
520 val (_, lthy8') = lthy8 |
535 val (_, lthy9') = lthy9a |
521 |> Local_Theory.note ((@{binding "distinct"}, []), alpha_distincts) |
536 |> Local_Theory.note ((@{binding "distinct"}, []), alpha_distincts) |
522 ||>> Local_Theory.note ((@{binding "eq_iff"}, []), alpha_eq_iff) |
537 ||>> Local_Theory.note ((@{binding "eq_iff"}, []), alpha_eq_iff) |
523 ||>> Local_Theory.note ((@{binding "eq_iff_simps"}, []), alpha_eq_iff_simps) |
538 ||>> Local_Theory.note ((@{binding "eq_iff_simps"}, []), alpha_eq_iff_simps) |
524 ||>> Local_Theory.note ((@{binding "fv_defs"}, []), raw_fv_defs) |
539 ||>> Local_Theory.note ((@{binding "fv_defs"}, []), raw_fv_defs) |
525 ||>> Local_Theory.note ((@{binding "perm_simps"}, []), raw_perm_simps) |
540 ||>> Local_Theory.note ((@{binding "perm_simps"}, []), raw_perm_simps) |
526 ||>> Local_Theory.note ((@{binding "perm_laws"}, []), raw_perm_laws) |
541 ||>> Local_Theory.note ((@{binding "perm_laws"}, []), raw_perm_laws) |
527 ||>> Local_Theory.note ((@{binding "alpha_bn_imps"}, []), alpha_bn_imp_thms) |
542 ||>> Local_Theory.note ((@{binding "alpha_bn_imps"}, []), alpha_bn_imp_thms) |
528 |
543 |
529 val _ = |
544 val _ = |
530 if get_STEPS lthy > 18 |
545 if get_STEPS lthy > 20 |
531 then true else raise TEST lthy8' |
546 then true else raise TEST lthy9' |
532 |
547 |
533 (* old stuff *) |
548 (* old stuff *) |
534 |
549 |
535 val thy = ProofContext.theory_of lthy8' |
550 val thy = ProofContext.theory_of lthy9' |
536 val thy_name = Context.theory_name thy |
551 val thy_name = Context.theory_name thy |
537 val qty_full_names = map (Long_Name.qualify thy_name) qty_names |
552 val qty_full_names = map (Long_Name.qualify thy_name) qty_names |
538 |
553 |
539 val _ = warning "Proving respects"; |
554 val _ = warning "Proving respects"; |
540 |
555 |
559 val fv_rsp = flat (map snd fv_rsp_pre); |
574 val fv_rsp = flat (map snd fv_rsp_pre); |
560 val (perms_rsp, lthy11) = prove_const_rsp qtys Binding.empty raw_perm_funs |
575 val (perms_rsp, lthy11) = prove_const_rsp qtys Binding.empty raw_perm_funs |
561 (fn _ => asm_simp_tac (HOL_ss addsimps alpha_eqvt) 1) lthy10; |
576 (fn _ => asm_simp_tac (HOL_ss addsimps alpha_eqvt) 1) lthy10; |
562 fun alpha_bn_rsp_tac _ = if !cheat_alpha_bn_rsp then Skip_Proof.cheat_tac thy |
577 fun alpha_bn_rsp_tac _ = if !cheat_alpha_bn_rsp then Skip_Proof.cheat_tac thy |
563 else |
578 else |
564 let val alpha_bn_rsp_pre = prove_alpha_bn_rsp alpha_trms alpha_induct (alpha_eq_iff @ alpha_distincts) alpha_equivp_thms exhaust_thms alpha_bn_trms lthy11 in asm_simp_tac (HOL_ss addsimps alpha_bn_rsp_pre) 1 end; |
579 let val alpha_bn_rsp_pre = prove_alpha_bn_rsp alpha_trms alpha_induct (alpha_eq_iff @ alpha_distincts) alpha_equivp_thms raw_exhaust_thms alpha_bn_trms lthy11 in asm_simp_tac (HOL_ss addsimps alpha_bn_rsp_pre) 1 end; |
565 val (alpha_bn_rsps, lthy11a) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst] |
580 val (alpha_bn_rsps, lthy11a) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst] |
566 alpha_bn_rsp_tac) alpha_bn_trms lthy11 |
581 alpha_bn_rsp_tac) alpha_bn_trms lthy11 |
567 fun const_rsp_tac _ = |
582 fun const_rsp_tac _ = |
568 let val alpha_alphabn = prove_alpha_alphabn alpha_trms alpha_induct alpha_eq_iff alpha_bn_trms lthy11a |
583 let val alpha_alphabn = prove_alpha_alphabn alpha_trms alpha_induct alpha_eq_iff alpha_bn_trms lthy11a |
569 in constr_rsp_tac alpha_eq_iff (fv_rsp @ bns_rsp @ alpha_refl_thms @ alpha_alphabn) 1 end |
584 in constr_rsp_tac alpha_eq_iff (fv_rsp @ bns_rsp @ alpha_refl_thms @ alpha_alphabn) 1 end |
570 val (const_rsps, lthy12) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst] |
585 val (const_rsps, lthy12) = fold_map (fn cnst => prove_const_rsp qtys Binding.empty [cnst] |
571 const_rsp_tac) all_raw_constrs lthy11a |
586 const_rsp_tac) raw_constrs lthy11a |
572 val qfv_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) (raw_fvs @ raw_fv_bns) |
587 val qfv_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) (raw_fvs @ raw_fv_bns) |
573 val dd = map2 (fn x => fn y => (x, y, NoSyn)) qfv_names (raw_fvs @ raw_fv_bns) |
588 val dd = map2 (fn x => fn y => (x, y, NoSyn)) qfv_names (raw_fvs @ raw_fv_bns) |
574 val (qfv_info, lthy12a) = qconst_defs qtys dd lthy12; |
589 val (qfv_info, lthy12a) = define_qconsts qtys dd lthy12; |
575 val qfv_ts = map #qconst qfv_info |
590 val qfv_ts = map #qconst qfv_info |
576 val qfv_defs = map #def qfv_info |
591 val qfv_defs = map #def qfv_info |
577 val (qfv_ts_nobn, qfv_ts_bn) = chop (length raw_perm_funs) qfv_ts; |
592 val (qfv_ts_nobn, qfv_ts_bn) = chop (length raw_perm_funs) qfv_ts; |
578 val qbn_names = map (fn (b, _ , _) => Name.of_binding b) bn_funs |
593 val qbn_names = map (fn (b, _ , _) => Name.of_binding b) bn_funs |
579 val dd = map2 (fn x => fn y => (x, y, NoSyn)) qbn_names raw_bns |
594 val dd = map2 (fn x => fn y => (x, y, NoSyn)) qbn_names raw_bns |
580 val (qbn_info, lthy12b) = qconst_defs qtys dd lthy12a; |
595 val (qbn_info, lthy12b) = define_qconsts qtys dd lthy12a; |
581 val qbn_ts = map #qconst qbn_info |
596 val qbn_ts = map #qconst qbn_info |
582 val qbn_defs = map #def qbn_info |
597 val qbn_defs = map #def qbn_info |
583 val qalpha_bn_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) alpha_bn_trms |
598 val qalpha_bn_names = map (unsuffix "_raw" o Long_Name.base_name o fst o dest_Const) alpha_bn_trms |
584 val dd = map2 (fn x => fn y => (x, y, NoSyn)) qalpha_bn_names alpha_bn_trms |
599 val dd = map2 (fn x => fn y => (x, y, NoSyn)) qalpha_bn_names alpha_bn_trms |
585 val (qalpha_info, lthy12c) = qconst_defs qtys dd lthy12b; |
600 val (qalpha_info, lthy12c) = define_qconsts qtys dd lthy12b; |
586 val qalpha_bn_trms = map #qconst qalpha_info |
601 val qalpha_bn_trms = map #qconst qalpha_info |
587 val qalphabn_defs = map #def qalpha_info |
602 val qalphabn_defs = map #def qalpha_info |
588 |
603 |
589 val _ = warning "Lifting permutations"; |
604 val _ = warning "Lifting permutations"; |
590 val thy = Local_Theory.exit_global lthy12c; |
605 val thy = Local_Theory.exit_global lthy12c; |
591 val perm_names = map (fn x => "permute_" ^ x) qty_names |
606 val perm_names = map (fn x => "permute_" ^ x) qty_names |
592 val dd = map2 (fn x => fn y => (x, y, NoSyn)) perm_names raw_perm_funs |
607 val dd = map2 (fn x => fn y => (x, y, NoSyn)) perm_names raw_perm_funs |
593 (* use Local_Theory.theory_result *) |
608 (* use Local_Theory.theory_result *) |
594 val thy' = qperm_defs qtys qty_full_names dd raw_perm_laws thy; |
609 val thy' = define_qperms qtys qty_full_names dd raw_perm_laws thy; |
595 val lthy13 = Named_Target.init "" thy'; |
610 val lthy13 = Named_Target.init "" thy'; |
596 |
611 |
597 val q_name = space_implode "_" qty_names; |
612 val q_name = space_implode "_" qty_names; |
598 fun suffix_bind s = Binding.qualify true q_name (Binding.name s); |
613 fun suffix_bind s = Binding.qualify true q_name (Binding.name s); |
599 val _ = warning "Lifting induction"; |
614 val _ = warning "Lifting induction"; |