blanchet@50138
|
1 |
(* Title: HOL/Codatatype/Tools/bnf_fp_sugar_tactics.ML
|
blanchet@50138
|
2 |
Author: Jasmin Blanchette, TU Muenchen
|
blanchet@50138
|
3 |
Copyright 2012
|
blanchet@50138
|
4 |
|
blanchet@50138
|
5 |
Tactics for the LFP/GFP sugar.
|
blanchet@50138
|
6 |
*)
|
blanchet@50138
|
7 |
|
blanchet@50138
|
8 |
signature BNF_FP_SUGAR_TACTICS =
|
blanchet@50138
|
9 |
sig
|
blanchet@50145
|
10 |
val mk_case_tac: Proof.context -> int -> int -> int -> thm -> thm -> thm -> tactic
|
blanchet@50241
|
11 |
val mk_coiter_like_tac: thm list -> thm list -> thm -> thm -> thm -> Proof.context -> tactic
|
blanchet@50176
|
12 |
val mk_exhaust_tac: Proof.context -> int -> thm list -> thm -> thm -> tactic
|
blanchet@50138
|
13 |
val mk_fld_iff_unf_tac: Proof.context -> ctyp option list -> cterm -> cterm -> thm -> thm
|
blanchet@50138
|
14 |
-> tactic
|
blanchet@50142
|
15 |
val mk_half_distinct_tac: Proof.context -> thm -> thm list -> tactic
|
blanchet@50383
|
16 |
val mk_induct_tac: Proof.context -> int list -> int list list -> int list list -> thm list ->
|
blanchet@50383
|
17 |
thm -> thm list list -> thm list -> tactic
|
blanchet@50141
|
18 |
val mk_inject_tac: Proof.context -> thm -> thm -> tactic
|
blanchet@50241
|
19 |
val mk_iter_like_tac: thm list -> thm list -> thm list -> thm -> thm -> Proof.context -> tactic
|
blanchet@50138
|
20 |
end;
|
blanchet@50138
|
21 |
|
blanchet@50138
|
22 |
structure BNF_FP_Sugar_Tactics : BNF_FP_SUGAR_TACTICS =
|
blanchet@50138
|
23 |
struct
|
blanchet@50138
|
24 |
|
blanchet@50140
|
25 |
open BNF_Tactics
|
blanchet@50138
|
26 |
open BNF_Util
|
blanchet@50279
|
27 |
open BNF_FP_Util
|
blanchet@50138
|
28 |
|
blanchet@50383
|
29 |
val meta_mp = @{thm meta_mp};
|
blanchet@50383
|
30 |
val meta_spec = @{thm meta_spec};
|
blanchet@50383
|
31 |
|
blanchet@50385
|
32 |
fun smash_spurious_fs lthy thm =
|
blanchet@50383
|
33 |
let
|
blanchet@50383
|
34 |
val spurious_fs =
|
blanchet@50383
|
35 |
Term.add_vars (prop_of thm) []
|
blanchet@50383
|
36 |
|> filter (fn (_, Type (@{type_name fun}, [_, T'])) => T' <> HOLogic.boolT | _ => false);
|
blanchet@50383
|
37 |
val cxs =
|
blanchet@50383
|
38 |
map (fn s as (_, T) =>
|
blanchet@50383
|
39 |
(certify lthy (Var s), certify lthy (id_abs (domain_type T)))) spurious_fs;
|
blanchet@50383
|
40 |
in
|
blanchet@50383
|
41 |
Drule.cterm_instantiate cxs thm
|
blanchet@50383
|
42 |
end;
|
blanchet@50383
|
43 |
|
blanchet@50385
|
44 |
val smash_spurious_fs_tac = PRIMITIVE o smash_spurious_fs;
|
blanchet@50383
|
45 |
|
blanchet@50145
|
46 |
fun mk_case_tac ctxt n k m case_def ctr_def unf_fld =
|
blanchet@50145
|
47 |
Local_Defs.unfold_tac ctxt [case_def, ctr_def, unf_fld] THEN
|
blanchet@50279
|
48 |
(rtac (mk_sum_casesN_balanced n k RS ssubst) THEN'
|
blanchet@50145
|
49 |
REPEAT_DETERM_N (Int.max (0, m - 1)) o rtac (@{thm split} RS ssubst) THEN'
|
blanchet@50145
|
50 |
rtac refl) 1;
|
blanchet@50145
|
51 |
|
blanchet@50176
|
52 |
fun mk_exhaust_tac ctxt n ctr_defs fld_iff_unf sumEN' =
|
blanchet@50278
|
53 |
Local_Defs.unfold_tac ctxt (fld_iff_unf :: ctr_defs) THEN rtac sumEN' 1 THEN
|
blanchet@50140
|
54 |
Local_Defs.unfold_tac ctxt @{thms all_prod_eq} THEN
|
blanchet@50383
|
55 |
EVERY' (maps (fn k => [select_prem_tac n (rotate_tac 1) k, REPEAT_DETERM o dtac meta_spec,
|
blanchet@50383
|
56 |
etac meta_mp, atac]) (1 upto n)) 1;
|
blanchet@50140
|
57 |
|
blanchet@50138
|
58 |
fun mk_fld_iff_unf_tac ctxt cTs cfld cunf fld_unf unf_fld =
|
blanchet@50138
|
59 |
(rtac iffI THEN'
|
blanchet@50138
|
60 |
EVERY' (map3 (fn cTs => fn cx => fn th =>
|
blanchet@50138
|
61 |
dtac (Drule.instantiate' cTs [NONE, NONE, SOME cx] arg_cong) THEN'
|
blanchet@50138
|
62 |
SELECT_GOAL (Local_Defs.unfold_tac ctxt [th]) THEN'
|
blanchet@50138
|
63 |
atac) [rev cTs, cTs] [cunf, cfld] [unf_fld, fld_unf])) 1;
|
blanchet@50138
|
64 |
|
blanchet@50142
|
65 |
fun mk_half_distinct_tac ctxt fld_inject ctr_defs =
|
blanchet@50142
|
66 |
Local_Defs.unfold_tac ctxt (fld_inject :: @{thms sum.inject} @ ctr_defs) THEN
|
blanchet@50142
|
67 |
rtac @{thm sum.distinct(1)} 1;
|
blanchet@50142
|
68 |
|
blanchet@50141
|
69 |
fun mk_inject_tac ctxt ctr_def fld_inject =
|
blanchet@50150
|
70 |
Local_Defs.unfold_tac ctxt [ctr_def] THEN rtac (fld_inject RS ssubst) 1 THEN
|
blanchet@50150
|
71 |
Local_Defs.unfold_tac ctxt @{thms sum.inject Pair_eq conj_assoc} THEN rtac refl 1;
|
blanchet@50141
|
72 |
|
blanchet@50226
|
73 |
val iter_like_thms =
|
blanchet@50248
|
74 |
@{thms case_unit comp_def convol_def id_apply map_pair_def sum.simps(5,6) sum_map.simps
|
blanchet@50248
|
75 |
split_conv};
|
blanchet@50220
|
76 |
|
blanchet@50244
|
77 |
fun mk_iter_like_tac pre_map_defs map_ids iter_like_defs fld_iter_like ctr_def ctxt =
|
blanchet@50244
|
78 |
Local_Defs.unfold_tac ctxt (ctr_def :: fld_iter_like :: iter_like_defs @ pre_map_defs @ map_ids @
|
blanchet@50247
|
79 |
iter_like_thms) THEN Local_Defs.unfold_tac ctxt @{thms id_def} THEN rtac refl 1;
|
blanchet@50220
|
80 |
|
blanchet@50228
|
81 |
val coiter_like_ss = ss_only @{thms if_True if_False};
|
blanchet@50291
|
82 |
val coiter_like_thms = @{thms id_apply map_pair_def sum_map.simps prod.cases};
|
blanchet@50228
|
83 |
|
blanchet@50244
|
84 |
fun mk_coiter_like_tac coiter_like_defs map_ids fld_unf_coiter_like pre_map_def ctr_def ctxt =
|
blanchet@50228
|
85 |
Local_Defs.unfold_tac ctxt (ctr_def :: coiter_like_defs) THEN
|
blanchet@50241
|
86 |
subst_tac ctxt [fld_unf_coiter_like] 1 THEN asm_simp_tac coiter_like_ss 1 THEN
|
blanchet@50247
|
87 |
Local_Defs.unfold_tac ctxt (pre_map_def :: coiter_like_thms @ map_ids) THEN
|
blanchet@50250
|
88 |
Local_Defs.unfold_tac ctxt @{thms id_def} THEN
|
blanchet@50377
|
89 |
TRY ((rtac refl ORELSE' subst_tac ctxt @{thms unit_eq} THEN' rtac refl) 1);
|
blanchet@50228
|
90 |
|
blanchet@50383
|
91 |
fun mk_induct_prelude_tac ctxt ctr_defs fld_induct' =
|
blanchet@50385
|
92 |
Local_Defs.unfold_tac ctxt ctr_defs THEN rtac fld_induct' 1 THEN smash_spurious_fs_tac ctxt;
|
blanchet@50383
|
93 |
|
blanchet@50383
|
94 |
fun mk_induct_prepare_prem_tac n m k =
|
blanchet@50383
|
95 |
EVERY' [select_prem_tac n (rotate_tac 1) k, rotate_tac ~1, hyp_subst_tac,
|
blanchet@50383
|
96 |
REPEAT_DETERM_N m o (dtac meta_spec THEN' rotate_tac ~1)] 1;
|
blanchet@50383
|
97 |
|
blanchet@50383
|
98 |
fun mk_induct_prepare_prem_prems_tac _ _ 0 = all_tac
|
blanchet@50383
|
99 |
| mk_induct_prepare_prem_prems_tac nn kk r =
|
blanchet@50383
|
100 |
REPEAT_DETERM_N r (rotate_tac (~1 + kk - nn) 1 THEN dtac meta_mp 1 THEN
|
blanchet@50383
|
101 |
defer_tac 2 THEN PRIMITIVE (Thm.permute_prems 0 ~1) THEN rotate_tac 1 1) THEN
|
blanchet@50383
|
102 |
PRIMITIVE Raw_Simplifier.norm_hhf;
|
blanchet@50383
|
103 |
|
blanchet@50383
|
104 |
val induct_prem_prem_thms =
|
blanchet@50383
|
105 |
@{thms SUP_empty Sup_empty Sup_insert UN_compreh_bex UN_insert Un_assoc[symmetric] Un_empty_left
|
blanchet@50383
|
106 |
Un_empty_right Union_Un_distrib collect_def[abs_def] fst_conv fsts_def[abs_def] image_def
|
blanchet@50383
|
107 |
map_pair_simp o_apply snd_conv snds_def[abs_def] sum.cases sum_map.simps sum_setl_def[abs_def]
|
blanchet@50383
|
108 |
sum_setr_def[abs_def] sup_bot_right};
|
blanchet@50383
|
109 |
|
blanchet@50383
|
110 |
fun mk_induct_discharge_prem_prems_tac ctxt r pre_set_defs set_natural's =
|
blanchet@50383
|
111 |
EVERY' (maps (fn i =>
|
blanchet@50383
|
112 |
[dtac meta_spec, rotate_tac ~1, etac meta_mp,
|
blanchet@50383
|
113 |
SELECT_GOAL (Local_Defs.unfold_tac ctxt
|
blanchet@50383
|
114 |
(set_natural's @ pre_set_defs @ induct_prem_prem_thms)),
|
blanchet@50383
|
115 |
rtac (mk_UnIN r i),
|
blanchet@50383
|
116 |
atac ORELSE'
|
blanchet@50383
|
117 |
rtac @{thm singletonI} ORELSE'
|
blanchet@50383
|
118 |
(REPEAT_DETERM o (atac ORELSE'
|
blanchet@50383
|
119 |
SELECT_GOAL (Local_Defs.unfold_tac ctxt @{thms Union_iff bex_simps(6)}) THEN'
|
blanchet@50383
|
120 |
etac @{thm induct_set_step}))]) (r downto 1)) 1;
|
blanchet@50383
|
121 |
|
blanchet@50383
|
122 |
fun mk_induct_discharge_prem_tac ctxt nn kk n m k r pre_set_defs set_natural's =
|
blanchet@50383
|
123 |
EVERY [mk_induct_prepare_prem_tac n m k,
|
blanchet@50383
|
124 |
mk_induct_prepare_prem_prems_tac nn kk r, atac 1,
|
blanchet@50383
|
125 |
mk_induct_discharge_prem_prems_tac ctxt r pre_set_defs set_natural's];
|
blanchet@50383
|
126 |
|
blanchet@50383
|
127 |
fun mk_induct_tac ctxt ns mss rss ctr_defs fld_induct' pre_set_defss set_natural's =
|
blanchet@50383
|
128 |
let
|
blanchet@50383
|
129 |
val nn = length ns;
|
blanchet@50383
|
130 |
val n = Integer.sum ns;
|
blanchet@50383
|
131 |
in
|
blanchet@50383
|
132 |
mk_induct_prelude_tac ctxt ctr_defs fld_induct' THEN
|
blanchet@50383
|
133 |
EVERY (map5 (fn kk => fn pre_set_defs =>
|
blanchet@50383
|
134 |
EVERY ooo map3 (fn m => fn k => fn r =>
|
blanchet@50383
|
135 |
mk_induct_discharge_prem_tac ctxt nn kk n m k r pre_set_defs set_natural's))
|
blanchet@50383
|
136 |
(1 upto nn) pre_set_defss mss (unflat mss (1 upto Integer.sum ns)) rss)
|
blanchet@50383
|
137 |
end;
|
blanchet@50383
|
138 |
|
blanchet@50138
|
139 |
end;
|