458 else |
458 else |
459 sel)) (1 upto m) o pad_list Binding.empty m) ctrs0 ms raw_sel_bindingss; |
459 sel)) (1 upto m) o pad_list Binding.empty m) ctrs0 ms raw_sel_bindingss; |
460 |
460 |
461 val case_Ts = map (fn Ts => Ts ---> B) ctr_Tss; |
461 val case_Ts = map (fn Ts => Ts ---> B) ctr_Tss; |
462 |
462 |
463 val ((((((((([exh_y], (xss, xss')), yss), fs), gs), [h]), [u', v']), [w]), (p, p')), |
463 val (((((((((exh_y, xss), yss), fs), gs), u), v), w), (p, p'))) = |
464 names_lthy) = |
|
465 no_defs_lthy |
464 no_defs_lthy |
466 |> mk_Frees "y" [fcT] (* for compatibility with "datatype_realizer.ML" *) |
465 |> yield_singleton (mk_Frees "y") fcT (* for compatibility with "datatype_realizer.ML" *) |
467 ||>> mk_Freess' "x" ctr_Tss |
466 ||>> mk_Freess "x" ctr_Tss |
468 ||>> mk_Freess "y" ctr_Tss |
467 ||>> mk_Freess "y" ctr_Tss |
469 ||>> mk_Frees "f" case_Ts |
468 ||>> mk_Frees "f" case_Ts |
470 ||>> mk_Frees "g" case_Ts |
469 ||>> mk_Frees "g" case_Ts |
471 ||>> mk_Frees "h" [B --> C] |
470 ||>> yield_singleton (mk_Frees fc_b_name) fcT |
472 ||>> (apfst (map (rpair fcT)) oo Variable.variant_fixes) [fc_b_name, fc_b_name ^ "'"] |
471 ||>> yield_singleton (mk_Frees (fc_b_name ^ "'")) fcT |
473 ||>> mk_Frees "z" [B] |
472 ||>> yield_singleton (mk_Frees "z") B |
474 ||>> yield_singleton (apfst (op ~~) oo mk_Frees' "P") HOLogic.boolT; |
473 ||>> yield_singleton (apfst (op ~~) oo mk_Frees' "P") HOLogic.boolT |
475 |
474 |> fst; |
476 val u = Free u'; |
475 |
477 val v = Free v'; |
|
478 val q = Free (fst p', mk_pred1T B); |
476 val q = Free (fst p', mk_pred1T B); |
479 |
477 |
480 val xctrs = map2 (curry Term.list_comb) ctrs xss; |
478 val xctrs = map2 (curry Term.list_comb) ctrs xss; |
481 val yctrs = map2 (curry Term.list_comb) ctrs yss; |
479 val yctrs = map2 (curry Term.list_comb) ctrs yss; |
482 |
480 |
516 val case0 = Morphism.term phi raw_case; |
514 val case0 = Morphism.term phi raw_case; |
517 val casex = mk_case As B case0; |
515 val casex = mk_case As B case0; |
518 val casexC = mk_case As C case0; |
516 val casexC = mk_case As C case0; |
519 val casexBool = mk_case As HOLogic.boolT case0; |
517 val casexBool = mk_case As HOLogic.boolT case0; |
520 |
518 |
521 val fcase = Term.list_comb (casex, fs); |
|
522 |
|
523 val ufcase = fcase $ u; |
|
524 val vfcase = fcase $ v; |
|
525 |
|
526 val eta_fcase = Term.list_comb (casex, eta_fs); |
|
527 val eta_gcase = Term.list_comb (casex, eta_gs); |
|
528 |
|
529 val eta_ufcase = eta_fcase $ u; |
|
530 val eta_vgcase = eta_gcase $ v; |
|
531 |
|
532 fun mk_uu_eq () = HOLogic.mk_eq (u, u); |
519 fun mk_uu_eq () = HOLogic.mk_eq (u, u); |
533 |
|
534 val uv_eq = mk_Trueprop_eq (u, v); |
|
535 |
520 |
536 val exist_xs_u_eq_ctrs = |
521 val exist_xs_u_eq_ctrs = |
537 map2 (fn xctr => fn xs => list_exists_free xs (HOLogic.mk_eq (u, xctr))) xctrs xss; |
522 map2 (fn xctr => fn xs => list_exists_free xs (HOLogic.mk_eq (u, xctr))) xctrs xss; |
538 |
523 |
539 val unique_disc_no_def = TrueI; (*arbitrary marker*) |
524 val unique_disc_no_def = TrueI; (*arbitrary marker*) |
683 |
668 |
684 val goalss = [exhaust_goal] :: inject_goalss @ half_distinct_goalss; |
669 val goalss = [exhaust_goal] :: inject_goalss @ half_distinct_goalss; |
685 |
670 |
686 fun after_qed ([exhaust_thm] :: thmss) lthy = |
671 fun after_qed ([exhaust_thm] :: thmss) lthy = |
687 let |
672 let |
|
673 val ((((((((xss, xss'), fs), gs), h), (u, u')), v), p), names_lthy) = |
|
674 lthy |
|
675 |> mk_Freess' "x" ctr_Tss |
|
676 ||>> mk_Frees "f" case_Ts |
|
677 ||>> mk_Frees "g" case_Ts |
|
678 ||>> yield_singleton (mk_Frees "h") (B --> C) |
|
679 ||>> yield_singleton (apfst (op ~~) oo mk_Frees' fc_b_name) fcT |
|
680 ||>> yield_singleton (mk_Frees (fc_b_name ^ "'")) fcT |
|
681 ||>> yield_singleton (mk_Frees "P") HOLogic.boolT; |
|
682 |
|
683 val xfs = map2 (curry Term.list_comb) fs xss; |
|
684 val xgs = map2 (curry Term.list_comb) gs xss; |
|
685 |
|
686 val fcase = Term.list_comb (casex, fs); |
|
687 |
|
688 val ufcase = fcase $ u; |
|
689 val vfcase = fcase $ v; |
|
690 |
|
691 val eta_fcase = Term.list_comb (casex, eta_fs); |
|
692 val eta_gcase = Term.list_comb (casex, eta_gs); |
|
693 |
|
694 val eta_ufcase = eta_fcase $ u; |
|
695 val eta_vgcase = eta_gcase $ v; |
|
696 |
|
697 fun mk_uu_eq () = HOLogic.mk_eq (u, u); |
|
698 |
|
699 val uv_eq = mk_Trueprop_eq (u, v); |
|
700 |
688 val ((inject_thms, inject_thmss), half_distinct_thmss) = chop n thmss |>> `flat; |
701 val ((inject_thms, inject_thmss), half_distinct_thmss) = chop n thmss |>> `flat; |
689 |
702 |
690 val rho_As = |
703 val rho_As = |
691 map (fn (T, U) => (dest_TVar T, Thm.ctyp_of lthy U)) |
704 map (fn (T, U) => (dest_TVar T, Thm.ctyp_of lthy U)) |
692 (map Logic.varifyT_global As ~~ As); |
705 (map Logic.varifyT_global As ~~ As); |
741 in |
754 in |
742 (Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} => |
755 (Goal.prove_sorry lthy [] [] goal (fn {context = ctxt, prems = _} => |
743 mk_case_cong_tac ctxt uexhaust_thm case_thms), |
756 mk_case_cong_tac ctxt uexhaust_thm case_thms), |
744 Goal.prove_sorry lthy [] [] weak_goal (fn {context = ctxt, prems = _} => |
757 Goal.prove_sorry lthy [] [] weak_goal (fn {context = ctxt, prems = _} => |
745 etac ctxt arg_cong 1)) |
758 etac ctxt arg_cong 1)) |
746 |> apply2 (singleton (Proof_Context.export names_lthy lthy) #> |
759 |> apply2 (Thm.close_derivation #> singleton (Proof_Context.export names_lthy lthy)) |
747 Thm.close_derivation) |
|
748 end; |
760 end; |
749 |
761 |
750 val split_lhs = q $ ufcase; |
762 val split_lhs = q $ ufcase; |
751 |
763 |
752 fun mk_split_conjunct xctr xs f_xs = |
764 fun mk_split_conjunct xctr xs f_xs = |