author | panny |
Wed, 18 Sep 2013 22:59:11 +0200 | |
changeset 54857 | 03fac7082137 |
parent 54843 | 9e28c41e3595 |
child 54859 | e176d6d3345f |
permissions | -rw-r--r-- |
blanchet@54440 | 1 |
(* Title: HOL/BNF/Tools/bnf_fp_rec_sugar_tactics.ML |
blanchet@54440 | 2 |
Author: Jasmin Blanchette, TU Muenchen |
blanchet@54440 | 3 |
Copyright 2013 |
blanchet@54440 | 4 |
|
blanchet@54440 | 5 |
Tactics for recursor and corecursor sugar. |
blanchet@54440 | 6 |
*) |
blanchet@54440 | 7 |
|
blanchet@54440 | 8 |
signature BNF_FP_REC_SUGAR_TACTICS = |
blanchet@54440 | 9 |
sig |
blanchet@54839 | 10 |
val mk_primcorec_assumption_tac: Proof.context -> tactic |
blanchet@54830 | 11 |
val mk_primcorec_code_tac: Proof.context -> thm -> thm list -> tactic |
blanchet@54836 | 12 |
val mk_primcorec_code_of_ctr_tac: Proof.context -> int list -> thm list -> tactic |
blanchet@54829 | 13 |
val mk_primcorec_ctr_of_dtr_tac: Proof.context -> int -> thm -> thm -> thm list -> tactic |
blanchet@54829 | 14 |
val mk_primcorec_ctr_or_sel_tac: Proof.context -> thm list -> thm -> int -> int -> |
blanchet@54829 | 15 |
thm list list list -> thm list -> thm list -> thm list -> tactic |
blanchet@54843 | 16 |
val mk_primcorec_disc_of_ctr_tac: thm -> thm -> tactic; |
blanchet@54830 | 17 |
val mk_primcorec_disc_tac: Proof.context -> thm list -> thm -> int -> int -> thm list list list -> |
blanchet@54830 | 18 |
tactic |
blanchet@54843 | 19 |
val mk_primcorec_sel_of_ctr_tac: thm -> thm -> tactic; |
blanchet@54440 | 20 |
val mk_primrec_tac: Proof.context -> int -> thm list -> thm list -> thm list -> thm -> tactic |
blanchet@54440 | 21 |
end; |
blanchet@54440 | 22 |
|
blanchet@54440 | 23 |
structure BNF_FP_Rec_Sugar_Tactics : BNF_FP_REC_SUGAR_TACTICS = |
blanchet@54440 | 24 |
struct |
blanchet@54440 | 25 |
|
blanchet@54440 | 26 |
open BNF_Util |
blanchet@54440 | 27 |
open BNF_Tactics |
blanchet@54440 | 28 |
|
blanchet@54466 | 29 |
fun mk_primrec_tac ctxt num_extra_args map_idents map_comps fun_defs recx = |
blanchet@54440 | 30 |
unfold_thms_tac ctxt fun_defs THEN |
blanchet@54440 | 31 |
HEADGOAL (rtac (funpow num_extra_args (fn thm => thm RS fun_cong) recx RS trans)) THEN |
blanchet@54466 | 32 |
unfold_thms_tac ctxt (@{thms id_def split o_def fst_conv snd_conv} @ map_comps @ map_idents) THEN |
blanchet@54440 | 33 |
HEADGOAL (rtac refl); |
blanchet@54440 | 34 |
|
blanchet@54836 | 35 |
fun mk_primcorec_assumption_tac ctxt = |
blanchet@54836 | 36 |
HEADGOAL (blast_tac (put_claset (claset_of @{theory_context HOL}) ctxt)); |
blanchet@54440 | 37 |
|
blanchet@54440 | 38 |
fun mk_primcorec_same_case_tac m = |
blanchet@54440 | 39 |
HEADGOAL (if m = 0 then rtac TrueI |
blanchet@54440 | 40 |
else REPEAT_DETERM_N (m - 1) o (rtac conjI THEN' atac) THEN' atac); |
blanchet@54440 | 41 |
|
blanchet@54440 | 42 |
fun mk_primcorec_different_case_tac ctxt excl = |
blanchet@54440 | 43 |
unfold_thms_tac ctxt @{thms not_not not_False_eq_True} THEN |
blanchet@54836 | 44 |
HEADGOAL (rtac excl THEN_ALL_NEW SELECT_GOAL (mk_primcorec_assumption_tac ctxt)); |
blanchet@54440 | 45 |
|
blanchet@54440 | 46 |
fun mk_primcorec_cases_tac ctxt k m exclsss = |
blanchet@54440 | 47 |
let val n = length exclsss in |
blanchet@54440 | 48 |
EVERY (map (fn [] => if k = n then all_tac else mk_primcorec_same_case_tac m |
blanchet@54440 | 49 |
| [excl] => mk_primcorec_different_case_tac ctxt excl) |
blanchet@54440 | 50 |
(take k (nth exclsss (k - 1)))) |
blanchet@54440 | 51 |
end; |
blanchet@54440 | 52 |
|
blanchet@54440 | 53 |
fun mk_primcorec_prelude ctxt defs thm = |
blanchet@54440 | 54 |
unfold_thms_tac ctxt defs THEN HEADGOAL (rtac thm) THEN unfold_thms_tac ctxt @{thms split}; |
blanchet@54440 | 55 |
|
blanchet@54843 | 56 |
fun mk_primcorec_disc_tac ctxt defs disc_corec k m exclsss = |
blanchet@54843 | 57 |
mk_primcorec_prelude ctxt defs disc_corec THEN mk_primcorec_cases_tac ctxt k m exclsss; |
blanchet@54440 | 58 |
|
blanchet@54843 | 59 |
fun mk_primcorec_ctr_or_sel_tac ctxt defs f_eq k m exclsss maps map_idents map_comps = |
blanchet@54843 | 60 |
mk_primcorec_prelude ctxt defs (f_eq RS trans) THEN |
blanchet@54830 | 61 |
mk_primcorec_cases_tac ctxt k m exclsss THEN |
blanchet@54830 | 62 |
unfold_thms_tac ctxt (@{thms if_if_True if_if_False if_True if_False if_cancel[of _ True] |
blanchet@54830 | 63 |
if_cancel[of _ False] o_def split_def sum.cases} @ maps @ map_comps @ map_idents) THEN |
blanchet@54830 | 64 |
HEADGOAL (rtac refl); |
blanchet@54440 | 65 |
|
blanchet@54843 | 66 |
fun mk_primcorec_ctr_of_dtr_tac ctxt m collapse disc_f sel_fs = |
panny@54857 | 67 |
HEADGOAL (rtac ((if null sel_fs then collapse else collapse RS sym) RS trans) THEN' |
panny@54857 | 68 |
rtac disc_f THEN' REPEAT_DETERM_N m o atac) THEN |
blanchet@54843 | 69 |
unfold_thms_tac ctxt sel_fs THEN HEADGOAL (rtac refl); |
blanchet@54440 | 70 |
|
blanchet@54843 | 71 |
fun mk_primcorec_disc_of_ctr_tac discI f_ctr = |
blanchet@54843 | 72 |
HEADGOAL (rtac discI THEN' rtac f_ctr) THEN ALLGOALS atac; |
blanchet@54843 | 73 |
|
blanchet@54843 | 74 |
fun mk_primcorec_sel_of_ctr_tac sel f_ctr = |
blanchet@54843 | 75 |
HEADGOAL (etac (f_ctr RS arg_cong RS trans) THEN' rtac sel); |
blanchet@54843 | 76 |
|
blanchet@54843 | 77 |
fun mk_primcorec_code_of_ctr_case_tac ctxt m f_ctr = |
blanchet@54830 | 78 |
HEADGOAL (REPEAT o rtac @{thm eq_ifI}) THEN |
blanchet@54843 | 79 |
mk_primcorec_prelude ctxt [] (f_ctr RS trans) THEN |
blanchet@54836 | 80 |
REPEAT_DETERM_N m (mk_primcorec_assumption_tac ctxt) THEN |
blanchet@54836 | 81 |
HEADGOAL (asm_simp_tac (ss_only @{thms if_True if_False not_False_eq_True} ctxt)); |
blanchet@54830 | 82 |
|
blanchet@54836 | 83 |
fun mk_primcorec_code_of_ctr_tac ctxt ms ctr_thms = |
blanchet@54836 | 84 |
EVERY (map2 (mk_primcorec_code_of_ctr_case_tac ctxt) ms ctr_thms); |
blanchet@54830 | 85 |
|
blanchet@54830 | 86 |
fun mk_primcorec_code_tac ctxt raw collapses = |
blanchet@54830 | 87 |
HEADGOAL (rtac (raw RS trans)) THEN unfold_thms_tac ctxt @{thms split_ifs} THEN |
blanchet@54830 | 88 |
Method.intros_tac @{thms conjI impI} [] THEN |
blanchet@54830 | 89 |
REPEAT (HEADGOAL (rtac refl ORELSE' (etac notE THEN' atac) ORELSE' |
blanchet@54830 | 90 |
eresolve_tac (maps (fn thm => [thm, thm RS sym]) collapses))); |
blanchet@54830 | 91 |
|
blanchet@54440 | 92 |
end; |