110 let |
110 let |
111 val f_ty = fastype_of f_trm |
111 val f_ty = fastype_of f_trm |
112 val arg_ty = domain_type f_ty |
112 val arg_ty = domain_type f_ty |
113 in |
113 in |
114 Const (@{const_name eqvt_at}, [f_ty, arg_ty] ---> @{typ bool}) $ f_trm $ arg_trm |
114 Const (@{const_name eqvt_at}, [f_ty, arg_ty] ---> @{typ bool}) $ f_trm $ arg_trm |
|
115 |> HOLogic.mk_Trueprop |
|
116 end |
|
117 |
|
118 fun mk_eqvt trm = |
|
119 let |
|
120 val ty = fastype_of trm |
|
121 in |
|
122 Const (@{const_name eqvt}, ty --> @{typ bool}) $ trm |
115 |> HOLogic.mk_Trueprop |
123 |> HOLogic.mk_Trueprop |
116 end |
124 end |
117 |
125 |
118 (* nominal *) |
126 (* nominal *) |
119 fun find_calls2 f t = |
127 fun find_calls2 f t = |
494 |> Thm.implies_intr (cterm_of thy (HOLogic.mk_Trueprop (mk_acc domT R $ x))) |
502 |> Thm.implies_intr (cterm_of thy (HOLogic.mk_Trueprop (mk_acc domT R $ x))) |
495 |> Thm.forall_intr (cterm_of thy x) |
503 |> Thm.forall_intr (cterm_of thy x) |
496 |> (fn it => Drule.compose_single (it, 2, acc_induct_rule)) (* "EX! y. (?x,y):G" *) |
504 |> (fn it => Drule.compose_single (it, 2, acc_induct_rule)) (* "EX! y. (?x,y):G" *) |
497 |> (fn it => fold (Thm.forall_intr o cterm_of thy o Var) (Term.add_vars (prop_of it) []) it) |
505 |> (fn it => fold (Thm.forall_intr o cterm_of thy o Var) (Term.add_vars (prop_of it) []) it) |
498 |
506 |
499 val goalstate = Conjunction.intr graph_is_function complete |
507 val goalstate = |
|
508 Conjunction.intr (Conjunction.intr graph_is_function complete) G_eqvt |
500 |> Thm.close_derivation |
509 |> Thm.close_derivation |
501 |> Goal.protect |
510 |> Goal.protect |
502 |> fold_rev (Thm.implies_intr o cprop_of) compat |
511 |> fold_rev (Thm.implies_intr o cprop_of) compat |
503 |> Thm.implies_intr (cprop_of complete) |
512 |> Thm.implies_intr (cprop_of complete) |
|
513 |> Thm.implies_intr (cprop_of G_eqvt) |
504 in |
514 in |
505 (goalstate, values) |
515 (goalstate, values) |
506 end |
516 end |
507 |
517 |
508 (* nominal *) |
|
509 (* wrapper -- restores quantifiers in rule specifications *) |
518 (* wrapper -- restores quantifiers in rule specifications *) |
510 fun inductive_def eqvt_flag (binding as ((R, T), _)) intrs lthy = |
519 fun inductive_def (binding as ((R, T), _)) intrs lthy = |
511 let |
520 let |
512 val ({intrs = intrs_gen, elims = [elim_gen], preds = [ Rdef ], induct, raw_induct, ...}, lthy) = |
521 val ({intrs = intrs_gen, elims = [elim_gen], preds = [ Rdef ], induct, raw_induct, ...}, lthy) = |
513 lthy |
522 lthy |
514 |> Local_Theory.conceal |
523 |> Local_Theory.conceal |
515 |> Inductive.add_inductive_i |
524 |> Inductive.add_inductive_i |
525 [] (* no parameters *) |
534 [] (* no parameters *) |
526 (map (fn t => (Attrib.empty_binding, t)) intrs) (* intro rules *) |
535 (map (fn t => (Attrib.empty_binding, t)) intrs) (* intro rules *) |
527 [] (* no special monos *) |
536 [] (* no special monos *) |
528 ||> Local_Theory.restore_naming lthy |
537 ||> Local_Theory.restore_naming lthy |
529 |
538 |
530 val eqvt_thm' = |
|
531 if eqvt_flag = false then NONE |
|
532 else |
|
533 let |
|
534 (* val _ = tracing ("intrs:\n" ^ cat_lines (map @{make_string} intrs_gen)) *) |
|
535 val ([eqvt_thm], lthy) = Nominal_Eqvt.raw_equivariance false [Rdef] raw_induct intrs_gen lthy |
|
536 in |
|
537 SOME ((Nominal_ThmDecls.eqvt_transform lthy eqvt_thm) RS @{thm eqvtI}) |
|
538 end |
|
539 |
|
540 val cert = cterm_of (ProofContext.theory_of lthy) |
539 val cert = cterm_of (ProofContext.theory_of lthy) |
541 fun requantify orig_intro thm = |
540 fun requantify orig_intro thm = |
542 let |
541 let |
543 val (qs, t) = dest_all_all orig_intro |
542 val (qs, t) = dest_all_all orig_intro |
544 val frees = frees_in_term lthy t |> remove (op =) (Binding.name_of R, T) |
543 val frees = frees_in_term lthy t |> remove (op =) (Binding.name_of R, T) |
548 in |
547 in |
549 fold_rev (fn Free (n, T) => |
548 fold_rev (fn Free (n, T) => |
550 forall_intr_rename (n, cert (Var (varmap (n, T), T)))) qs thm |
549 forall_intr_rename (n, cert (Var (varmap (n, T), T)))) qs thm |
551 end |
550 end |
552 in |
551 in |
553 ((Rdef, map2 requantify intrs intrs_gen, forall_intr_vars elim_gen, induct, eqvt_thm'), lthy) |
552 ((Rdef, map2 requantify intrs intrs_gen, forall_intr_vars elim_gen, induct), lthy) |
554 end |
553 end |
555 |
554 |
556 (* nominal *) |
555 (* nominal *) |
557 fun define_graph Gname fvar domT ranT clauses RCss lthy = |
556 fun define_graph Gname fvar domT ranT clauses RCss lthy = |
558 let |
557 let |
572 |> fold_rev Logic.all (fvar :: qs) |
571 |> fold_rev Logic.all (fvar :: qs) |
573 end |
572 end |
574 |
573 |
575 val G_intros = map2 mk_GIntro clauses RCss |
574 val G_intros = map2 mk_GIntro clauses RCss |
576 in |
575 in |
577 inductive_def true ((Binding.name n, T), NoSyn) G_intros lthy |
576 inductive_def ((Binding.name n, T), NoSyn) G_intros lthy |
578 end |
577 end |
579 |
578 |
580 fun define_function fdefname (fname, mixfix) domT ranT G default lthy = |
579 fun define_function fdefname (fname, mixfix) domT ranT G default lthy = |
581 let |
580 let |
582 val f_def = |
581 val f_def = |
603 |> fold_rev mk_forall_rename (map fst oqs ~~ qs) |
602 |> fold_rev mk_forall_rename (map fst oqs ~~ qs) |
604 (* "!!qs xs. CS ==> G => (r, lhs) : R" *) |
603 (* "!!qs xs. CS ==> G => (r, lhs) : R" *) |
605 |
604 |
606 val R_intross = map2 (map o mk_RIntro) (clauses ~~ qglrs) RCss |
605 val R_intross = map2 (map o mk_RIntro) (clauses ~~ qglrs) RCss |
607 |
606 |
608 val ((R, RIntro_thms, R_elim, _, _), lthy) = |
607 val ((R, RIntro_thms, R_elim, _), lthy) = |
609 inductive_def false ((Binding.name n, T), NoSyn) (flat R_intross) lthy |
608 inductive_def ((Binding.name n, T), NoSyn) (flat R_intross) lthy |
610 in |
609 in |
611 ((R, Library.unflat R_intross RIntro_thms, R_elim), lthy) |
610 ((R, Library.unflat R_intross RIntro_thms, R_elim), lthy) |
612 end |
611 end |
613 |
612 |
614 |
613 |
986 Function_Ctx_Tree.mk_tree (fname, fT) h ctxt rhs |
985 Function_Ctx_Tree.mk_tree (fname, fT) h ctxt rhs |
987 |
986 |
988 val trees = map build_tree clauses |
987 val trees = map build_tree clauses |
989 val RCss = map find_calls trees |
988 val RCss = map find_calls trees |
990 |
989 |
991 val ((G, GIntro_thms, G_elim, G_induct, SOME G_eqvt), lthy) = |
990 val ((G, GIntro_thms, G_elim, G_induct), lthy) = |
992 PROFILE "def_graph" (define_graph (graph_name defname) fvar domT ranT clauses RCss) lthy |
991 PROFILE "def_graph" (define_graph (graph_name defname) fvar domT ranT clauses RCss) lthy |
993 |
992 |
994 val ((f, (_, f_defthm)), lthy) = |
993 val ((f, (_, f_defthm)), lthy) = |
995 PROFILE "def_fun" (define_function (defname ^ "_sumC_def") (fname, mixfix) domT ranT G default) lthy |
994 PROFILE "def_fun" (define_function (defname ^ "_sumC_def") (fname, mixfix) domT ranT G default) lthy |
996 |
995 |
1017 |
1016 |
1018 val compat = |
1017 val compat = |
1019 mk_compat_proof_obligations domT ranT fvar f abstract_qglrs |
1018 mk_compat_proof_obligations domT ranT fvar f abstract_qglrs |
1020 |> map (cert #> Thm.assume) |
1019 |> map (cert #> Thm.assume) |
1021 |
1020 |
|
1021 val G_eqvt = mk_eqvt G |> cert |> Thm.assume |
|
1022 |
1022 val compat_store = store_compat_thms n compat |
1023 val compat_store = store_compat_thms n compat |
1023 |
1024 |
1024 val (goalstate, values) = PROFILE "prove_stuff" |
1025 val (goalstate, values) = PROFILE "prove_stuff" |
1025 (prove_stuff lthy globals G f R xclauses complete compat |
1026 (prove_stuff lthy globals G f R xclauses complete compat |
1026 compat_store G_elim G_eqvt) f_defthm |
1027 compat_store G_elim G_eqvt) f_defthm |
1030 |
1031 |
1031 fun mk_partial_rules provedgoal = |
1032 fun mk_partial_rules provedgoal = |
1032 let |
1033 let |
1033 val newthy = theory_of_thm provedgoal (*FIXME*) |
1034 val newthy = theory_of_thm provedgoal (*FIXME*) |
1034 |
1035 |
1035 val (graph_is_function, complete_thm) = |
1036 val ((graph_is_function, complete_thm), _) = |
1036 provedgoal |
1037 provedgoal |
1037 |> Conjunction.elim |
1038 |> Conjunction.elim |
1038 |> apfst (Thm.forall_elim_vars 0) |
1039 |>> Conjunction.elim |
|
1040 |>> apfst (Thm.forall_elim_vars 0) |
1039 |
1041 |
1040 val f_iff = graph_is_function RS (f_defthm RS ex1_implies_iff) |
1042 val f_iff = graph_is_function RS (f_defthm RS ex1_implies_iff) |
1041 |
1043 |
1042 val psimps = PROFILE "Proving simplification rules" |
1044 val psimps = PROFILE "Proving simplification rules" |
1043 (mk_psimps newthy globals R xclauses values f_iff) graph_is_function |
1045 (mk_psimps newthy globals R xclauses values f_iff) graph_is_function |