author | desharna |
Tue, 11 Nov 2014 12:30:37 +0100 | |
changeset 58968 | d09bbd2642e2 |
parent 58966 | 0297e1277ed2 |
child 59269 | 8713bd81017d |
permissions | -rw-r--r-- |
55061 | 1 |
(* Title: HOL/Tools/BNF/bnf_fp_def_sugar_tactics.ML |
49123
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
2 |
Author: Jasmin Blanchette, TU Muenchen |
57668 | 3 |
Author: Martin Desharnais, TU Muenchen |
4 |
Copyright 2012, 2013, 2014 |
|
49123
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
5 |
|
49389 | 6 |
Tactics for datatype and codatatype sugar. |
49123
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
7 |
*) |
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
8 |
|
49636 | 9 |
signature BNF_FP_DEF_SUGAR_TACTICS = |
49123
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
10 |
sig |
55966 | 11 |
val sumprod_thms_map: thm list |
12 |
val sumprod_thms_set: thm list |
|
57891 | 13 |
val basic_sumprod_thms_set: thm list |
55966 | 14 |
val sumprod_thms_rel: thm list |
49585
5c4a12550491
generate high-level "maps", "sets", and "rels" properties
blanchet
parents:
49542
diff
changeset
|
15 |
|
58093 | 16 |
val mk_case_transfer_tac: Proof.context -> thm -> thm list -> tactic |
49591
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49590
diff
changeset
|
17 |
val mk_coinduct_tac: Proof.context -> thm list -> int -> int list -> thm -> thm list -> |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
18 |
thm list -> thm list -> thm list -> thm list -> thm list list -> thm list list list -> |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
19 |
thm list list list -> tactic |
55867 | 20 |
val mk_corec_tac: thm list -> thm list -> thm -> thm -> thm -> thm -> Proof.context -> tactic |
57983
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
21 |
val mk_corec_disc_iff_tac: thm list -> thm list -> thm list -> Proof.context -> tactic |
58734 | 22 |
val mk_co_rec_o_map_tac: Proof.context -> thm -> thm list -> thm list -> thm list -> thm -> thm -> |
23 |
thm Seq.seq |
|
58448 | 24 |
val mk_corec_transfer_tac: Proof.context -> cterm list -> cterm list -> thm list -> thm list -> |
25 |
thm list -> thm list -> thm list -> ''a list -> ''a list list -> ''a list list list list -> |
|
26 |
''a list list list list -> tactic |
|
49501 | 27 |
val mk_ctor_iff_dtor_tac: Proof.context -> ctyp option list -> cterm -> cterm -> thm -> thm -> |
28 |
tactic |
|
58327 | 29 |
val mk_ctr_transfer_tac: Proof.context -> thm list -> thm list -> tactic |
58179 | 30 |
val mk_disc_transfer_tac: thm -> thm -> thm list -> tactic |
49161
a8e74375d971
fixed (n + 1)st bug in "mk_exhaust_tac" -- arose with uncurried constructors
blanchet
parents:
49160
diff
changeset
|
31 |
val mk_exhaust_tac: Proof.context -> int -> thm list -> thm -> thm -> tactic |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
32 |
val mk_half_distinct_tac: Proof.context -> thm -> thm -> thm list -> tactic |
49590 | 33 |
val mk_induct_tac: Proof.context -> int -> int list -> int list list -> int list list list -> |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
34 |
thm list -> thm -> thm list -> thm list -> thm list -> thm list list -> tactic |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
35 |
val mk_inject_tac: Proof.context -> thm -> thm -> thm -> tactic |
57983
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
36 |
val mk_map_disc_iff_tac: Proof.context -> cterm -> thm -> thm list -> thm list -> tactic |
58326
7e142efcee1a
make 'rel_sel' and 'map_sel' tactics more robust
desharna
parents:
58181
diff
changeset
|
37 |
val mk_map_sel_tac: Proof.context -> cterm -> thm -> thm list -> thm list -> thm list -> |
7e142efcee1a
make 'rel_sel' and 'map_sel' tactics more robust
desharna
parents:
58181
diff
changeset
|
38 |
thm list -> tactic |
55867 | 39 |
val mk_rec_tac: thm list -> thm list -> thm list -> thm -> thm -> thm -> thm -> Proof.context -> |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
40 |
tactic |
58446 | 41 |
val mk_rec_transfer_tac: Proof.context -> int -> int list -> cterm list -> cterm list -> |
58966 | 42 |
term list list list list -> thm list -> thm list -> thm list -> thm list -> tactic |
57525 | 43 |
val mk_rel_cases_tac: Proof.context -> cterm -> cterm -> thm -> thm list -> thm list -> |
57824
615223745d4e
made tactic more robust w.r.t. dead variables; tuned;
desharna
parents:
57670
diff
changeset
|
44 |
thm list -> thm list -> thm list -> tactic |
57301
7b997028aaac
generate 'rel_coinduct0' theorem for codatatypes
desharna
parents:
57152
diff
changeset
|
45 |
val mk_rel_coinduct0_tac: Proof.context -> thm -> cterm list -> thm list -> thm list -> |
7b997028aaac
generate 'rel_coinduct0' theorem for codatatypes
desharna
parents:
57152
diff
changeset
|
46 |
thm list list -> thm list list -> thm list list -> thm list -> thm list -> thm list -> |
57471 | 47 |
thm list -> thm list -> thm list -> tactic |
48 |
val mk_rel_induct0_tac: Proof.context -> thm -> thm list -> cterm list -> thm list -> |
|
49 |
thm list list -> thm list -> thm list -> thm list -> thm list -> tactic |
|
57563 | 50 |
val mk_rel_sel_tac: Proof.context -> cterm -> cterm -> thm -> thm list -> thm list -> thm list -> |
58326
7e142efcee1a
make 'rel_sel' and 'map_sel' tactics more robust
desharna
parents:
58181
diff
changeset
|
51 |
thm list -> thm list -> thm list -> tactic |
58676 | 52 |
val mk_sel_transfer_tac: Proof.context -> int -> thm list -> thm -> tactic |
57893 | 53 |
val mk_set_cases_tac: Proof.context -> cterm -> thm list -> thm -> thm list -> tactic |
57700 | 54 |
val mk_set_induct0_tac: Proof.context -> cterm list -> thm list -> thm list -> thm list -> |
55 |
thm list -> thm list -> thm list -> thm list -> tactic |
|
57891 | 56 |
val mk_set_intros_tac: Proof.context -> thm list -> tactic |
57983
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
57 |
val mk_set_sel_tac: Proof.context -> cterm -> thm -> thm list -> thm list -> thm list -> tactic |
49123
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
58 |
end; |
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
59 |
|
49636 | 60 |
structure BNF_FP_Def_Sugar_Tactics : BNF_FP_DEF_SUGAR_TACTICS = |
49123
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
61 |
struct |
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
62 |
|
56991
8e9ca31e9b8e
generate 'disc_map_iff[simp]' theorem for (co)datatypes
desharna
parents:
56990
diff
changeset
|
63 |
open Ctr_Sugar_Util |
49125 | 64 |
open BNF_Tactics |
49123
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
65 |
open BNF_Util |
51850
106afdf5806c
renamed a few FP-related files, to make it clear that these are not the sum of LFP + GFP but rather shared basic libraries
blanchet
parents:
51843
diff
changeset
|
66 |
open BNF_FP_Util |
49123
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
67 |
|
58446 | 68 |
val case_sum_transfer = @{thm case_sum_transfer}; |
69 |
val case_sum_transfer_eq = @{thm case_sum_transfer[of "op =" _ "op =", unfolded sum.rel_eq]}; |
|
70 |
val case_prod_transfer = @{thm case_prod_transfer}; |
|
71 |
val case_prod_transfer_eq = @{thm case_prod_transfer[of "op =" "op =", unfolded prod.rel_eq]}; |
|
72 |
||
49590 | 73 |
val basic_simp_thms = @{thms simp_thms(7,8,12,14,22,24)}; |
74 |
val more_simp_thms = basic_simp_thms @ @{thms simp_thms(11,15,16,21)}; |
|
57303 | 75 |
val simp_thms' = @{thms simp_thms(6,7,8,11,12,15,16,22,24)}; |
49590 | 76 |
|
55966 | 77 |
val sumprod_thms_map = @{thms id_apply map_prod_simp prod.case sum.case map_sum.simps}; |
57891 | 78 |
val basic_sumprod_thms_set = |
79 |
@{thms UN_empty UN_insert UN_iff Un_empty_left Un_empty_right Un_iff Union_Un_distrib |
|
80 |
o_apply map_prod_simp mem_Collect_eq prod_set_simps map_sum.simps sum_set_simps}; |
|
81 |
val sumprod_thms_set = @{thms UN_simps(10) image_iff} @ basic_sumprod_thms_set; |
|
56765 | 82 |
val sumprod_thms_rel = @{thms rel_sum_simps rel_prod_apply prod.inject id_apply conj_assoc}; |
49368 | 83 |
|
58359
3782c7b0d1cc
avoid 'subst_tac' when possible (it is suspected of not helping 'HOL-Proofs')
blanchet
parents:
58353
diff
changeset
|
84 |
fun is_def_looping def = |
3782c7b0d1cc
avoid 'subst_tac' when possible (it is suspected of not helping 'HOL-Proofs')
blanchet
parents:
58353
diff
changeset
|
85 |
(case Thm.prop_of def of |
3782c7b0d1cc
avoid 'subst_tac' when possible (it is suspected of not helping 'HOL-Proofs')
blanchet
parents:
58353
diff
changeset
|
86 |
Const (@{const_name Pure.eq}, _) $ lhs $ rhs => Term.exists_subterm (curry (op =) lhs) rhs |
3782c7b0d1cc
avoid 'subst_tac' when possible (it is suspected of not helping 'HOL-Proofs')
blanchet
parents:
58353
diff
changeset
|
87 |
| _ => false); |
3782c7b0d1cc
avoid 'subst_tac' when possible (it is suspected of not helping 'HOL-Proofs')
blanchet
parents:
58353
diff
changeset
|
88 |
|
49668 | 89 |
fun hhf_concl_conv cv ctxt ct = |
90 |
(case Thm.term_of ct of |
|
56245 | 91 |
Const (@{const_name Pure.all}, _) $ Abs _ => |
49668 | 92 |
Conv.arg_conv (Conv.abs_conv (hhf_concl_conv cv o snd) ctxt) ct |
93 |
| _ => Conv.concl_conv ~1 cv ct); |
|
94 |
||
54922 | 95 |
fun co_induct_inst_as_projs ctxt k thm = |
49368 | 96 |
let |
54922 | 97 |
val fs = Term.add_vars (prop_of thm) [] |
49368 | 98 |
|> filter (fn (_, Type (@{type_name fun}, [_, T'])) => T' <> HOLogic.boolT | _ => false); |
54923
ffed2452f5f6
instantiate schematics as projections to avoid HOU trouble
blanchet
parents:
54922
diff
changeset
|
99 |
fun mk_cfp (f as (_, T)) = |
ffed2452f5f6
instantiate schematics as projections to avoid HOU trouble
blanchet
parents:
54922
diff
changeset
|
100 |
(certify ctxt (Var f), certify ctxt (mk_proj T (num_binder_types T) k)); |
ffed2452f5f6
instantiate schematics as projections to avoid HOU trouble
blanchet
parents:
54922
diff
changeset
|
101 |
val cfps = map mk_cfp fs; |
49368 | 102 |
in |
54923
ffed2452f5f6
instantiate schematics as projections to avoid HOU trouble
blanchet
parents:
54922
diff
changeset
|
103 |
Drule.cterm_instantiate cfps thm |
49368 | 104 |
end; |
105 |
||
54922 | 106 |
val co_induct_inst_as_projs_tac = PRIMITIVE oo co_induct_inst_as_projs; |
49368 | 107 |
|
58093 | 108 |
fun mk_case_transfer_tac ctxt rel_cases cases = |
109 |
let |
|
110 |
val n = length (tl (prems_of rel_cases)); |
|
111 |
in |
|
58446 | 112 |
REPEAT_DETERM (HEADGOAL (rtac rel_funI)) THEN |
58093 | 113 |
HEADGOAL (etac rel_cases) THEN |
114 |
ALLGOALS (hyp_subst_tac ctxt) THEN |
|
115 |
unfold_thms_tac ctxt cases THEN |
|
58455 | 116 |
ALLGOALS (fn k => (select_prem_tac n (dtac asm_rl) k) k) THEN |
58676 | 117 |
ALLGOALS (REPEAT_DETERM o (rotate_tac ~1 THEN' dtac rel_funD THEN' |
58455 | 118 |
(atac THEN' etac thin_rl ORELSE' rtac refl)) THEN' atac) |
58093 | 119 |
end; |
120 |
||
58327 | 121 |
fun mk_ctr_transfer_tac ctxt rel_intros rel_eqs = |
58095 | 122 |
HEADGOAL Goal.conjunction_tac THEN |
58446 | 123 |
ALLGOALS (REPEAT o (resolve_tac (rel_funI :: rel_intros) THEN' |
124 |
TRY o (REPEAT_DETERM1 o (atac ORELSE' |
|
125 |
K (unfold_thms_tac ctxt rel_eqs) THEN' hyp_subst_tac ctxt THEN' rtac refl)))); |
|
58095 | 126 |
|
58179 | 127 |
fun mk_disc_transfer_tac rel_sel exhaust_disc distinct_disc= |
58095 | 128 |
let |
129 |
fun last_disc_tac iffD = |
|
130 |
HEADGOAL (rtac (rotate_prems ~1 exhaust_disc) THEN' atac THEN' |
|
131 |
REPEAT_DETERM o (rotate_tac ~1 THEN' dtac (rotate_prems 1 iffD) THEN' atac THEN' |
|
132 |
rotate_tac ~1 THEN' etac (rotate_prems 1 notE) THEN' eresolve_tac distinct_disc)); |
|
133 |
in |
|
134 |
HEADGOAL Goal.conjunction_tac THEN |
|
58446 | 135 |
REPEAT_DETERM (HEADGOAL (rtac rel_funI THEN' dtac (rel_sel RS iffD1) THEN' |
58095 | 136 |
REPEAT_DETERM o (etac conjE) THEN' (atac ORELSE' rtac iffI))) THEN |
137 |
TRY (last_disc_tac iffD2) THEN TRY (last_disc_tac iffD1) |
|
138 |
end; |
|
139 |
||
49501 | 140 |
fun mk_exhaust_tac ctxt n ctr_defs ctor_iff_dtor sumEN' = |
52324 | 141 |
unfold_thms_tac ctxt (ctor_iff_dtor :: ctr_defs) THEN HEADGOAL (rtac sumEN') THEN |
142 |
HEADGOAL (EVERY' (maps (fn k => [select_prem_tac n (rotate_tac 1) k, |
|
143 |
REPEAT_DETERM o dtac meta_spec, etac meta_mp, atac]) (1 upto n))); |
|
49125 | 144 |
|
49501 | 145 |
fun mk_ctor_iff_dtor_tac ctxt cTs cctor cdtor ctor_dtor dtor_ctor = |
52324 | 146 |
HEADGOAL (rtac iffI THEN' |
58634
9f10d82e8188
added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents:
58507
diff
changeset
|
147 |
EVERY' (@{map 3} (fn cTs => fn cx => fn th => |
52324 | 148 |
dtac (Drule.instantiate' cTs [NONE, NONE, SOME cx] arg_cong) THEN' |
149 |
SELECT_GOAL (unfold_thms_tac ctxt [th]) THEN' |
|
150 |
atac) [rev cTs, cTs] [cdtor, cctor] [dtor_ctor, ctor_dtor])); |
|
49123
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
151 |
|
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
152 |
fun mk_half_distinct_tac ctxt ctor_inject abs_inject ctr_defs = |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
153 |
unfold_thms_tac ctxt (ctor_inject :: abs_inject :: @{thms sum.inject} @ ctr_defs) THEN |
52324 | 154 |
HEADGOAL (rtac @{thm sum.distinct(1)}); |
49127 | 155 |
|
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
156 |
fun mk_inject_tac ctxt ctr_def ctor_inject abs_inject = |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
157 |
unfold_thms_tac ctxt [ctr_def] THEN |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
158 |
HEADGOAL (rtac (ctor_inject RS ssubst)) THEN |
56765 | 159 |
unfold_thms_tac ctxt (abs_inject :: @{thms sum.inject prod.inject conj_assoc}) THEN |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
160 |
HEADGOAL (rtac refl); |
49126 | 161 |
|
55867 | 162 |
val rec_unfold_thms = |
55414
eab03e9cee8a
renamed '{prod,sum,bool,unit}_case' to 'case_...'
blanchet
parents:
55083
diff
changeset
|
163 |
@{thms comp_def convol_def fst_conv id_def case_prod_Pair_iden snd_conv split_conv |
55966 | 164 |
case_unit_Unity} @ sumprod_thms_map; |
49205 | 165 |
|
58734 | 166 |
fun mk_co_rec_o_map_tac ctxt co_rec_def pre_map_defs map_ident0s abs_inverses xtor_co_rec_o_map = |
58732 | 167 |
let |
58734 | 168 |
val rec_o_map_simps = @{thms o_def[abs_def] id_def case_prod_app case_sum_map_sum map_sum.simps |
169 |
case_prod_map_prod id_bnf_def map_prod_simp map_sum_if_distrib_then map_sum_if_distrib_else |
|
170 |
if_distrib[THEN sym]}; |
|
58732 | 171 |
in |
58734 | 172 |
HEADGOAL (subst_tac @{context} (SOME [1, 2]) [co_rec_def] THEN' |
173 |
rtac (xtor_co_rec_o_map RS trans) THEN' |
|
58732 | 174 |
CONVERSION Thm.eta_long_conversion THEN' |
175 |
asm_simp_tac (ss_only (pre_map_defs @ distinct Thm.eq_thm_prop (map_ident0s @ abs_inverses) @ |
|
176 |
rec_o_map_simps) ctxt)) |
|
177 |
end; |
|
178 |
||
57399 | 179 |
fun mk_rec_tac pre_map_defs map_ident0s rec_defs ctor_rec fp_abs_inverse abs_inverse ctr_def ctxt = |
58359
3782c7b0d1cc
avoid 'subst_tac' when possible (it is suspected of not helping 'HOL-Proofs')
blanchet
parents:
58353
diff
changeset
|
180 |
HEADGOAL ((if is_def_looping ctr_def then subst_tac ctxt NONE |
3782c7b0d1cc
avoid 'subst_tac' when possible (it is suspected of not helping 'HOL-Proofs')
blanchet
parents:
58353
diff
changeset
|
181 |
else SELECT_GOAL o unfold_thms_tac ctxt) [ctr_def]) THEN |
58352
37745650a3f4
register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
58327
diff
changeset
|
182 |
unfold_thms_tac ctxt (ctor_rec :: fp_abs_inverse :: abs_inverse :: rec_defs @ |
57399 | 183 |
pre_map_defs @ map_ident0s @ rec_unfold_thms) THEN HEADGOAL (rtac refl); |
49205 | 184 |
|
58966 | 185 |
fun mk_rec_transfer_tac ctxt nn ns actives passives xssss rec_defs ctor_rec_transfers rel_pre_T_defs |
58446 | 186 |
rel_eqs = |
187 |
let |
|
188 |
val ctor_rec_transfers' = |
|
58507 | 189 |
map (cterm_instantiate_pos (map SOME (passives @ actives))) ctor_rec_transfers; |
190 |
val total_n = Integer.sum ns; |
|
58966 | 191 |
val True = @{term True}; |
192 |
fun magic eq xs xs' = Subgoal.FOCUS (fn {prems, ...} => |
|
193 |
let |
|
194 |
val thm = prems |
|
195 |
|> Ctr_Sugar_Util.permute_like eq xs xs' |
|
196 |
|> Library.foldl1 (fn (acc, elem) => elem RS (acc RS @{thm rel_funD})) |
|
197 |
in HEADGOAL (rtac thm) end) |
|
58446 | 198 |
in |
199 |
HEADGOAL Goal.conjunction_tac THEN |
|
200 |
EVERY (map (fn ctor_rec_transfer => |
|
201 |
REPEAT_DETERM (HEADGOAL (rtac rel_funI)) THEN |
|
202 |
unfold_thms_tac ctxt rec_defs THEN |
|
203 |
HEADGOAL (etac (mk_rel_funDN_rotated (nn + 1) ctor_rec_transfer)) THEN |
|
204 |
unfold_thms_tac ctxt rel_pre_T_defs THEN |
|
58966 | 205 |
EVERY (fst (@{fold_map 2} (fn k => fn xsss => fn acc => |
206 |
rpair (k + acc) |
|
58446 | 207 |
(HEADGOAL (rtac (mk_rel_funDN_rotated 2 @{thm comp_transfer})) THEN |
208 |
HEADGOAL (rtac @{thm vimage2p_rel_fun}) THEN |
|
209 |
unfold_thms_tac ctxt rel_eqs THEN |
|
58966 | 210 |
EVERY (@{map 2} (fn n => fn xss => |
211 |
REPEAT_DETERM (HEADGOAL (resolve_tac |
|
212 |
[mk_rel_funDN 2 case_sum_transfer_eq, mk_rel_funDN 2 case_sum_transfer])) THEN |
|
58507 | 213 |
HEADGOAL (select_prem_tac total_n (dtac asm_rl) (acc + n)) THEN |
58446 | 214 |
HEADGOAL (SELECT_GOAL (HEADGOAL |
58966 | 215 |
(REPEAT_DETERM o (atac ORELSE' resolve_tac |
216 |
[mk_rel_funDN 1 case_prod_transfer_eq, |
|
217 |
mk_rel_funDN 1 case_prod_transfer, |
|
218 |
rel_funI]) THEN_ALL_NEW |
|
219 |
(Subgoal.FOCUS (fn {prems, ...} => |
|
220 |
let val thm = prems |
|
221 |
|> permute_like (op =) (True :: flat xss) (True :: flat_rec_arg_args xss) |
|
222 |
|> Library.foldl1 (fn (acc, elem) => elem RS (acc RS rel_funD)) |
|
223 |
in HEADGOAL (rtac thm) end) ctxt))))) |
|
224 |
(1 upto k) xsss))) |
|
225 |
ns xssss 0))) |
|
58446 | 226 |
ctor_rec_transfers') |
227 |
end; |
|
228 |
||
55966 | 229 |
val corec_unfold_thms = @{thms id_def} @ sumprod_thms_map; |
49683 | 230 |
|
57399 | 231 |
fun mk_corec_tac corec_defs map_ident0s ctor_dtor_corec pre_map_def abs_inverse ctr_def ctxt = |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
232 |
let |
57399 | 233 |
val ss = ss_only (pre_map_def :: abs_inverse :: map_ident0s @ corec_unfold_thms @ |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
234 |
@{thms o_apply vimage2p_def if_True if_False}) ctxt; |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
235 |
in |
55867 | 236 |
unfold_thms_tac ctxt (ctr_def :: corec_defs) THEN |
237 |
HEADGOAL (rtac (ctor_dtor_corec RS trans) THEN' asm_simp_tac ss) THEN_MAYBE |
|
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
238 |
HEADGOAL (rtac refl ORELSE' rtac (@{thm unit_eq} RS arg_cong)) |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
239 |
end; |
49213 | 240 |
|
57983
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
241 |
fun mk_corec_disc_iff_tac case_splits' corecs discs ctxt = |
58634
9f10d82e8188
added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents:
58507
diff
changeset
|
242 |
EVERY (@{map 3} (fn case_split_tac => fn corec_thm => fn disc => |
55867 | 243 |
HEADGOAL case_split_tac THEN unfold_thms_tac ctxt [corec_thm] THEN |
52324 | 244 |
HEADGOAL (asm_simp_tac (ss_only basic_simp_thms ctxt)) THEN |
245 |
(if is_refl disc then all_tac else HEADGOAL (rtac disc))) |
|
55867 | 246 |
(map rtac case_splits' @ [K all_tac]) corecs discs); |
49482 | 247 |
|
58448 | 248 |
fun mk_corec_transfer_tac ctxt actives passives type_definitions corec_defs dtor_corec_transfers |
249 |
rel_pre_T_defs rel_eqs pgs pss qssss gssss = |
|
250 |
let |
|
251 |
val num_pgs = length pgs; |
|
252 |
fun prem_no_of x = 1 + find_index (curry (op =) x) pgs; |
|
253 |
||
58968 | 254 |
val Inl_Inr_Pair_tac = REPEAT_DETERM o (resolve_tac |
255 |
[mk_rel_funDN 1 @{thm Inl_transfer}, |
|
256 |
mk_rel_funDN 1 @{thm Inl_transfer[of "op =" "op =", unfolded sum.rel_eq]}, |
|
257 |
mk_rel_funDN 1 @{thm Inr_transfer}, |
|
258 |
mk_rel_funDN 1 @{thm Inr_transfer[of "op =" "op =", unfolded sum.rel_eq]}, |
|
259 |
mk_rel_funDN 2 @{thm Pair_transfer}, |
|
260 |
mk_rel_funDN 2 @{thm Pair_transfer[of "op =" "op =", unfolded prod.rel_eq]}]); |
|
58448 | 261 |
|
262 |
fun mk_unfold_If_tac total pos = |
|
263 |
HEADGOAL (Inl_Inr_Pair_tac THEN' |
|
264 |
rtac (mk_rel_funDN 3 @{thm If_transfer}) THEN' |
|
265 |
select_prem_tac total (dtac asm_rl) pos THEN' |
|
266 |
dtac rel_funD THEN' atac THEN' atac); |
|
267 |
||
268 |
fun mk_unfold_Inl_Inr_Pair_tac total pos = |
|
269 |
HEADGOAL (Inl_Inr_Pair_tac THEN' |
|
270 |
select_prem_tac total (dtac asm_rl) pos THEN' |
|
271 |
dtac rel_funD THEN' atac THEN' atac); |
|
272 |
||
273 |
fun mk_unfold_arg_tac qs gs = |
|
274 |
EVERY (map (mk_unfold_If_tac num_pgs o prem_no_of) qs) THEN |
|
275 |
EVERY (map (mk_unfold_Inl_Inr_Pair_tac num_pgs o prem_no_of) gs); |
|
276 |
||
277 |
fun mk_unfold_ctr_tac type_definition qss gss = |
|
278 |
HEADGOAL (rtac (mk_rel_funDN 1 (@{thm Abs_transfer} OF |
|
279 |
[type_definition, type_definition])) THEN' Inl_Inr_Pair_tac) THEN |
|
280 |
(case (qss, gss) of |
|
281 |
([], []) => HEADGOAL (rtac refl) |
|
282 |
| _ => EVERY (map2 mk_unfold_arg_tac qss gss)); |
|
283 |
||
284 |
fun mk_unfold_type_tac type_definition ps qsss gsss = |
|
285 |
let |
|
286 |
val p_tacs = map (mk_unfold_If_tac num_pgs o prem_no_of) ps; |
|
287 |
val qg_tacs = map2 (mk_unfold_ctr_tac type_definition) qsss gsss; |
|
288 |
fun mk_unfold_ty [] [qg_tac] = qg_tac |
|
289 |
| mk_unfold_ty (p_tac :: p_tacs) (qg_tac :: qg_tacs) = |
|
290 |
p_tac THEN qg_tac THEN mk_unfold_ty p_tacs qg_tacs |
|
291 |
in |
|
292 |
HEADGOAL (rtac rel_funI) THEN mk_unfold_ty p_tacs qg_tacs |
|
293 |
end; |
|
294 |
||
295 |
fun mk_unfold_corec_type_tac dtor_corec_transfer corec_def = |
|
296 |
let |
|
297 |
val active :: actives' = actives; |
|
298 |
val dtor_corec_transfer' = cterm_instantiate_pos |
|
299 |
(SOME active :: map SOME passives @ map SOME actives') dtor_corec_transfer; |
|
300 |
in |
|
301 |
HEADGOAL Goal.conjunction_tac THEN |
|
302 |
REPEAT_DETERM (HEADGOAL (rtac rel_funI)) THEN |
|
303 |
unfold_thms_tac ctxt [corec_def] THEN |
|
304 |
HEADGOAL (etac (mk_rel_funDN_rotated (1 + length actives) dtor_corec_transfer')) THEN |
|
305 |
unfold_thms_tac ctxt (rel_pre_T_defs @ rel_eqs) |
|
306 |
end; |
|
307 |
||
308 |
fun mk_unfold_prop_tac dtor_corec_transfer corec_def = |
|
309 |
mk_unfold_corec_type_tac dtor_corec_transfer corec_def THEN |
|
58634
9f10d82e8188
added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents:
58507
diff
changeset
|
310 |
EVERY (@{map 4} mk_unfold_type_tac type_definitions pss qssss gssss); |
58448 | 311 |
in |
312 |
HEADGOAL Goal.conjunction_tac THEN |
|
313 |
EVERY (map2 mk_unfold_prop_tac dtor_corec_transfers corec_defs) |
|
314 |
end; |
|
315 |
||
51798 | 316 |
fun solve_prem_prem_tac ctxt = |
49429
64ac3471005a
cleaner way of dealing with the set functions of sums and products
blanchet
parents:
49428
diff
changeset
|
317 |
REPEAT o (eresolve_tac @{thms bexE rev_bexI} ORELSE' rtac @{thm rev_bexI[OF UNIV_I]} ORELSE' |
51798 | 318 |
hyp_subst_tac ctxt ORELSE' resolve_tac @{thms disjI1 disjI2}) THEN' |
49429
64ac3471005a
cleaner way of dealing with the set functions of sums and products
blanchet
parents:
49428
diff
changeset
|
319 |
(rtac refl ORELSE' atac ORELSE' rtac @{thm singletonI}); |
49426 | 320 |
|
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
321 |
fun mk_induct_leverage_prem_prems_tac ctxt nn kks fp_abs_inverses abs_inverses set_maps |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
322 |
pre_set_defs = |
52324 | 323 |
HEADGOAL (EVERY' (maps (fn kk => [select_prem_tac nn (dtac meta_spec) kk, etac meta_mp, |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
324 |
SELECT_GOAL (unfold_thms_tac ctxt (pre_set_defs @ fp_abs_inverses @ abs_inverses @ set_maps @ |
55966 | 325 |
sumprod_thms_set)), |
52324 | 326 |
solve_prem_prem_tac ctxt]) (rev kks))); |
49368 | 327 |
|
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
328 |
fun mk_induct_discharge_prem_tac ctxt nn n fp_abs_inverses abs_inverses set_maps pre_set_defs m k |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
329 |
kks = |
49429
64ac3471005a
cleaner way of dealing with the set functions of sums and products
blanchet
parents:
49428
diff
changeset
|
330 |
let val r = length kks in |
52324 | 331 |
HEADGOAL (EVERY' [select_prem_tac n (rotate_tac 1) k, rotate_tac ~1, hyp_subst_tac ctxt, |
332 |
REPEAT_DETERM_N m o (dtac meta_spec THEN' rotate_tac ~1)]) THEN |
|
49391 | 333 |
EVERY [REPEAT_DETERM_N r |
52324 | 334 |
(HEADGOAL (rotate_tac ~1 THEN' dtac meta_mp THEN' rotate_tac 1) THEN prefer_tac 2), |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54241
diff
changeset
|
335 |
if r > 0 then ALLGOALS (Goal.norm_hhf_tac ctxt) else all_tac, HEADGOAL atac, |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
336 |
mk_induct_leverage_prem_prems_tac ctxt nn kks fp_abs_inverses abs_inverses set_maps |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
337 |
pre_set_defs] |
49391 | 338 |
end; |
49368 | 339 |
|
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
340 |
fun mk_induct_tac ctxt nn ns mss kkss ctr_defs ctor_induct' fp_abs_inverses abs_inverses set_maps |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
341 |
pre_set_defss = |
49590 | 342 |
let val n = Integer.sum ns in |
58359
3782c7b0d1cc
avoid 'subst_tac' when possible (it is suspected of not helping 'HOL-Proofs')
blanchet
parents:
58353
diff
changeset
|
343 |
(if exists is_def_looping ctr_defs then |
3782c7b0d1cc
avoid 'subst_tac' when possible (it is suspected of not helping 'HOL-Proofs')
blanchet
parents:
58353
diff
changeset
|
344 |
EVERY (map (fn def => HEADGOAL (subst_asm_tac ctxt NONE [def])) ctr_defs) |
3782c7b0d1cc
avoid 'subst_tac' when possible (it is suspected of not helping 'HOL-Proofs')
blanchet
parents:
58353
diff
changeset
|
345 |
else |
3782c7b0d1cc
avoid 'subst_tac' when possible (it is suspected of not helping 'HOL-Proofs')
blanchet
parents:
58353
diff
changeset
|
346 |
unfold_thms_tac ctxt ctr_defs) THEN |
58352
37745650a3f4
register 'prod' and 'sum' as datatypes, to allow N2M through them
blanchet
parents:
58327
diff
changeset
|
347 |
HEADGOAL (rtac ctor_induct') THEN co_induct_inst_as_projs_tac ctxt 0 THEN |
58634
9f10d82e8188
added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents:
58507
diff
changeset
|
348 |
EVERY (@{map 4} (EVERY oooo @{map 3} o |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
349 |
mk_induct_discharge_prem_tac ctxt nn n fp_abs_inverses abs_inverses set_maps) |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
350 |
pre_set_defss mss (unflat mss (1 upto n)) kkss) |
49368 | 351 |
end; |
352 |
||
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
353 |
fun mk_coinduct_same_ctr_tac ctxt rel_eqs pre_rel_def fp_abs_inverse abs_inverse dtor_ctor ctr_def |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
354 |
discs sels = |
51798 | 355 |
hyp_subst_tac ctxt THEN' |
49665 | 356 |
CONVERSION (hhf_concl_conv |
357 |
(Conv.top_conv (K (Conv.try_conv (Conv.rewr_conv ctr_def))) ctxt) ctxt) THEN' |
|
49642
9f884142334c
fixed simplification of prod and sum relators to avoid issues with e.g. codata ('a, 'b) k = K "'a + 'b"
blanchet
parents:
49639
diff
changeset
|
358 |
SELECT_GOAL (unfold_thms_tac ctxt (pre_rel_def :: dtor_ctor :: sels)) THEN' |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
359 |
SELECT_GOAL (unfold_thms_tac ctxt (pre_rel_def :: fp_abs_inverse :: abs_inverse :: dtor_ctor :: |
55966 | 360 |
sels @ sumprod_thms_rel @ @{thms o_apply vimage2p_def})) THEN' |
49591
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49590
diff
changeset
|
361 |
(atac ORELSE' REPEAT o etac conjE THEN' |
56765 | 362 |
full_simp_tac (ss_only (no_refl discs @ rel_eqs @ more_simp_thms) ctxt) THEN' |
54241 | 363 |
REPEAT o etac conjE THEN_MAYBE' REPEAT o hyp_subst_tac ctxt THEN' |
364 |
REPEAT o (resolve_tac [refl, conjI] ORELSE' atac)); |
|
49590 | 365 |
|
52966 | 366 |
fun mk_coinduct_distinct_ctrs_tac ctxt discs discs' = |
54198
4fadf746f2d5
got rid of annoying duplicate rewrite rule warnings
blanchet
parents:
53690
diff
changeset
|
367 |
let |
4fadf746f2d5
got rid of annoying duplicate rewrite rule warnings
blanchet
parents:
53690
diff
changeset
|
368 |
val discs'' = map (perhaps (try (fn th => th RS @{thm notnotD}))) (discs @ discs') |
4fadf746f2d5
got rid of annoying duplicate rewrite rule warnings
blanchet
parents:
53690
diff
changeset
|
369 |
|> distinct Thm.eq_thm_prop; |
4fadf746f2d5
got rid of annoying duplicate rewrite rule warnings
blanchet
parents:
53690
diff
changeset
|
370 |
in |
4fadf746f2d5
got rid of annoying duplicate rewrite rule warnings
blanchet
parents:
53690
diff
changeset
|
371 |
hyp_subst_tac ctxt THEN' REPEAT o etac conjE THEN' |
4fadf746f2d5
got rid of annoying duplicate rewrite rule warnings
blanchet
parents:
53690
diff
changeset
|
372 |
full_simp_tac (ss_only (refl :: no_refl discs'' @ basic_simp_thms) ctxt) |
4fadf746f2d5
got rid of annoying duplicate rewrite rule warnings
blanchet
parents:
53690
diff
changeset
|
373 |
end; |
49590 | 374 |
|
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
375 |
fun mk_coinduct_discharge_prem_tac ctxt rel_eqs' nn kk n pre_rel_def fp_abs_inverse abs_inverse |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
376 |
dtor_ctor exhaust ctr_defs discss selss = |
49590 | 377 |
let val ks = 1 upto n in |
54837 | 378 |
EVERY' ([rtac allI, rtac allI, rtac impI, select_prem_tac nn (dtac meta_spec) kk, |
54923
ffed2452f5f6
instantiate schematics as projections to avoid HOU trouble
blanchet
parents:
54922
diff
changeset
|
379 |
dtac meta_spec, dtac meta_mp, atac, rtac exhaust, K (co_induct_inst_as_projs_tac ctxt 0), |
51798 | 380 |
hyp_subst_tac ctxt] @ |
58634
9f10d82e8188
added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents:
58507
diff
changeset
|
381 |
@{map 4} (fn k => fn ctr_def => fn discs => fn sels => |
54923
ffed2452f5f6
instantiate schematics as projections to avoid HOU trouble
blanchet
parents:
54922
diff
changeset
|
382 |
EVERY' ([rtac exhaust, K (co_induct_inst_as_projs_tac ctxt 1)] @ |
49591
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49590
diff
changeset
|
383 |
map2 (fn k' => fn discs' => |
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49590
diff
changeset
|
384 |
if k' = k then |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
385 |
mk_coinduct_same_ctr_tac ctxt rel_eqs' pre_rel_def fp_abs_inverse abs_inverse |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
386 |
dtor_ctor ctr_def discs sels |
49591
91b228e26348
generate high-level "coinduct" and "strong_coinduct" properties
blanchet
parents:
49590
diff
changeset
|
387 |
else |
52966 | 388 |
mk_coinduct_distinct_ctrs_tac ctxt discs discs') ks discss)) ks ctr_defs discss selss) |
49590 | 389 |
end; |
390 |
||
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
391 |
fun mk_coinduct_tac ctxt rel_eqs' nn ns dtor_coinduct' pre_rel_defs fp_abs_inverses abs_inverses |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
392 |
dtor_ctors exhausts ctr_defss discsss selsss = |
52324 | 393 |
HEADGOAL (rtac dtor_coinduct' THEN' |
58634
9f10d82e8188
added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents:
58507
diff
changeset
|
394 |
EVERY' (@{map 10} (mk_coinduct_discharge_prem_tac ctxt rel_eqs' nn) |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
395 |
(1 upto nn) ns pre_rel_defs fp_abs_inverses abs_inverses dtor_ctors exhausts ctr_defss discsss |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55642
diff
changeset
|
396 |
selsss)); |
49590 | 397 |
|
57983
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
398 |
fun mk_map_disc_iff_tac ctxt ct exhaust discs maps = |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
399 |
TRYALL Goal.conjunction_tac THEN |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
400 |
ALLGOALS (rtac (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
401 |
REPEAT_DETERM o hyp_subst_tac ctxt) THEN |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
402 |
unfold_thms_tac ctxt maps THEN |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
403 |
unfold_thms_tac ctxt (map (fn thm => thm RS eqFalseI |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
404 |
handle THM _ => thm RS eqTrueI) discs) THEN |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
405 |
ALLGOALS (rtac refl ORELSE' rtac TrueI); |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
406 |
|
58326
7e142efcee1a
make 'rel_sel' and 'map_sel' tactics more robust
desharna
parents:
58181
diff
changeset
|
407 |
fun mk_map_sel_tac ctxt ct exhaust discs maps sels map_id0s = |
57983
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
408 |
TRYALL Goal.conjunction_tac THEN |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
409 |
ALLGOALS (rtac (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
410 |
REPEAT_DETERM o hyp_subst_tac ctxt) THEN |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
411 |
unfold_thms_tac ctxt ((discs RL [eqTrueI, eqFalseI]) @ |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
412 |
@{thms not_True_eq_False not_False_eq_True}) THEN |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
413 |
TRYALL (etac FalseE ORELSE' etac @{thm TrueE}) THEN |
58326
7e142efcee1a
make 'rel_sel' and 'map_sel' tactics more robust
desharna
parents:
58181
diff
changeset
|
414 |
unfold_thms_tac ctxt (@{thm id_apply} :: maps @ sels @ map_id0s) THEN |
57983
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
415 |
ALLGOALS (rtac refl); |
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
416 |
|
57824
615223745d4e
made tactic more robust w.r.t. dead variables; tuned;
desharna
parents:
57670
diff
changeset
|
417 |
fun mk_rel_cases_tac ctxt ct1 ct2 exhaust injects rel_injects distincts rel_distincts rel_eqs= |
57525 | 418 |
HEADGOAL (rtac (cterm_instantiate_pos [SOME ct1] exhaust) THEN_ALL_NEW |
419 |
rtac (cterm_instantiate_pos [SOME ct2] exhaust) THEN_ALL_NEW |
|
420 |
hyp_subst_tac ctxt) THEN |
|
57824
615223745d4e
made tactic more robust w.r.t. dead variables; tuned;
desharna
parents:
57670
diff
changeset
|
421 |
unfold_thms_tac ctxt (rel_eqs @ injects @ rel_injects @ @{thms conj_imp_eq_imp_imp simp_thms(6) |
57525 | 422 |
True_implies_equals conj_imp_eq_imp_imp} @ |
57529 | 423 |
map (fn thm => thm RS eqFalseI) (distincts @ rel_distincts) @ |
424 |
map (fn thm => thm RS eqTrueI) rel_injects) THEN |
|
57562 | 425 |
TRYALL (atac ORELSE' etac FalseE ORELSE' |
426 |
(REPEAT_DETERM o dtac @{thm meta_spec} THEN' |
|
427 |
TRY o filter_prems_tac |
|
428 |
(forall (curry (op <>) (HOLogic.mk_Trueprop @{term False})) o Logic.strip_imp_prems) THEN' |
|
429 |
REPEAT_DETERM o (dtac @{thm meta_mp} THEN' rtac refl) THEN' Goal.assume_rule_tac ctxt)); |
|
57525 | 430 |
|
57301
7b997028aaac
generate 'rel_coinduct0' theorem for codatatypes
desharna
parents:
57152
diff
changeset
|
431 |
fun mk_rel_coinduct0_tac ctxt dtor_rel_coinduct cts assms exhausts discss selss ctor_defss |
57558
6bb3dd7f8097
took out 'rel_cases' for now because of failing tactic
blanchet
parents:
57529
diff
changeset
|
432 |
dtor_ctors ctor_injects abs_injects rel_pre_defs abs_inverses nesting_rel_eqs = |
57301
7b997028aaac
generate 'rel_coinduct0' theorem for codatatypes
desharna
parents:
57152
diff
changeset
|
433 |
rtac dtor_rel_coinduct 1 THEN |
58634
9f10d82e8188
added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents:
58507
diff
changeset
|
434 |
EVERY (@{map 11} (fn ct => fn assm => fn exhaust => fn discs => fn sels => fn ctor_defs => |
57670 | 435 |
fn dtor_ctor => fn ctor_inject => fn abs_inject => fn rel_pre_def => fn abs_inverse => |
436 |
(rtac exhaust THEN_ALL_NEW (rtac exhaust THEN_ALL_NEW |
|
58093 | 437 |
(dtac (rotate_prems ~1 (cterm_instantiate_pos [NONE, NONE, NONE, NONE, SOME ct] |
57670 | 438 |
@{thm arg_cong2} RS iffD1)) THEN' |
439 |
atac THEN' atac THEN' hyp_subst_tac ctxt THEN' dtac assm THEN' |
|
440 |
REPEAT_DETERM o etac conjE))) 1 THEN |
|
57668 | 441 |
unfold_thms_tac ctxt ((discs RL [eqTrueI, eqFalseI]) @ sels @ simp_thms') THEN |
57528 | 442 |
unfold_thms_tac ctxt (dtor_ctor :: rel_pre_def :: abs_inverse :: ctor_inject :: |
58128 | 443 |
abs_inject :: ctor_defs @ nesting_rel_eqs @ simp_thms' @ |
58353 | 444 |
@{thms id_bnf_def rel_sum_simps rel_prod_apply vimage2p_def Inl_Inr_False |
445 |
iffD2[OF eq_False Inr_not_Inl] sum.inject prod.inject}) THEN |
|
57301
7b997028aaac
generate 'rel_coinduct0' theorem for codatatypes
desharna
parents:
57152
diff
changeset
|
446 |
REPEAT_DETERM (HEADGOAL ((REPEAT_DETERM o etac conjE) THEN' (REPEAT_DETERM o rtac conjI) THEN' |
7b997028aaac
generate 'rel_coinduct0' theorem for codatatypes
desharna
parents:
57152
diff
changeset
|
447 |
(rtac refl ORELSE' atac)))) |
7b997028aaac
generate 'rel_coinduct0' theorem for codatatypes
desharna
parents:
57152
diff
changeset
|
448 |
cts assms exhausts discss selss ctor_defss dtor_ctors ctor_injects abs_injects rel_pre_defs |
7b997028aaac
generate 'rel_coinduct0' theorem for codatatypes
desharna
parents:
57152
diff
changeset
|
449 |
abs_inverses); |
7b997028aaac
generate 'rel_coinduct0' theorem for codatatypes
desharna
parents:
57152
diff
changeset
|
450 |
|
57471 | 451 |
fun mk_rel_induct0_tac ctxt ctor_rel_induct assms cterms exhausts ctor_defss ctor_injects |
452 |
rel_pre_list_defs Abs_inverses nesting_rel_eqs = |
|
58634
9f10d82e8188
added parameterized ML antiquotations @{map N}, @{fold N}, @{fold_map N}, @{split_list N};
wenzelm
parents:
58507
diff
changeset
|
453 |
rtac ctor_rel_induct 1 THEN EVERY (@{map 6} (fn cterm => fn exhaust => fn ctor_defs => |
57471 | 454 |
fn ctor_inject => fn rel_pre_list_def => fn Abs_inverse => |
455 |
HEADGOAL (rtac exhaust THEN_ALL_NEW (rtac exhaust THEN_ALL_NEW |
|
456 |
(rtac (cterm_instantiate_pos (replicate 4 NONE @ [SOME cterm]) @{thm arg_cong2} RS iffD2) |
|
457 |
THEN' atac THEN' atac THEN' TRY o resolve_tac assms))) THEN |
|
57700 | 458 |
unfold_thms_tac ctxt (ctor_inject :: rel_pre_list_def :: ctor_defs @ nesting_rel_eqs @ |
58353 | 459 |
@{thms id_bnf_def vimage2p_def}) THEN |
57471 | 460 |
TRYALL (hyp_subst_tac ctxt) THEN |
57824
615223745d4e
made tactic more robust w.r.t. dead variables; tuned;
desharna
parents:
57670
diff
changeset
|
461 |
unfold_thms_tac ctxt (Abs_inverse :: @{thms rel_sum_simps rel_prod_apply Inl_Inr_False |
57471 | 462 |
Inr_Inl_False sum.inject prod.inject}) THEN |
58020 | 463 |
TRYALL (rtac refl ORELSE' etac FalseE ORELSE' (REPEAT_DETERM o etac conjE) THEN' atac)) |
57471 | 464 |
cterms exhausts ctor_defss ctor_injects rel_pre_list_defs Abs_inverses); |
465 |
||
58326
7e142efcee1a
make 'rel_sel' and 'map_sel' tactics more robust
desharna
parents:
58181
diff
changeset
|
466 |
fun mk_rel_sel_tac ctxt ct1 ct2 exhaust discs sels rel_injects distincts rel_distincts rel_eqs = |
57563 | 467 |
HEADGOAL (rtac (cterm_instantiate_pos [SOME ct1] exhaust) THEN_ALL_NEW |
468 |
rtac (cterm_instantiate_pos [SOME ct2] exhaust) THEN_ALL_NEW |
|
469 |
hyp_subst_tac ctxt) THEN |
|
58326
7e142efcee1a
make 'rel_sel' and 'map_sel' tactics more robust
desharna
parents:
58181
diff
changeset
|
470 |
unfold_thms_tac ctxt (sels @ rel_injects @ rel_eqs @ @{thms simp_thms(6,7,8,11,12,15,16,21,22,24)} @ |
57563 | 471 |
((discs @ distincts) RL @{thms iffD2[OF eq_True] iffD2[OF eq_False]}) @ |
472 |
(rel_injects RL @{thms iffD2[OF eq_True]}) @ |
|
473 |
(rel_distincts RL @{thms iffD2[OF eq_False]})) THEN |
|
474 |
TRYALL (resolve_tac [TrueI, refl]); |
|
475 |
||
58676 | 476 |
fun mk_sel_transfer_tac ctxt n sel_defs case_transfer = |
477 |
TRYALL Goal.conjunction_tac THEN |
|
478 |
unfold_thms_tac ctxt (map (Drule.abs_def o Local_Defs.meta_rewrite_rule ctxt) sel_defs) THEN |
|
479 |
ALLGOALS (rtac (mk_rel_funDN n case_transfer) THEN_ALL_NEW |
|
480 |
REPEAT_DETERM o (atac ORELSE' rtac rel_funI)); |
|
481 |
||
57983
6edc3529bb4e
reordered some (co)datatype property names for more consistency
blanchet
parents:
57893
diff
changeset
|
482 |
fun mk_set_sel_tac ctxt ct exhaust discs sels sets = |
57152 | 483 |
TRYALL Goal.conjunction_tac THEN |
484 |
ALLGOALS (rtac (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW |
|
485 |
REPEAT_DETERM o hyp_subst_tac ctxt) THEN |
|
57529 | 486 |
unfold_thms_tac ctxt ((discs RL [eqTrueI, eqFalseI]) @ |
57152 | 487 |
@{thms not_True_eq_False not_False_eq_True}) THEN |
488 |
TRYALL (etac FalseE ORELSE' etac @{thm TrueE}) THEN |
|
57528 | 489 |
unfold_thms_tac ctxt (sels @ sets) THEN |
57558
6bb3dd7f8097
took out 'rel_cases' for now because of failing tactic
blanchet
parents:
57529
diff
changeset
|
490 |
ALLGOALS (REPEAT o (resolve_tac @{thms UnI1 UnI2 imageI} ORELSE' |
57152 | 491 |
eresolve_tac @{thms UN_I UN_I[rotated] imageE} ORELSE' |
492 |
hyp_subst_tac ctxt) THEN' |
|
493 |
(rtac @{thm singletonI} ORELSE' atac)); |
|
494 |
||
57893 | 495 |
fun mk_set_cases_tac ctxt ct assms exhaust sets = |
496 |
HEADGOAL (rtac (cterm_instantiate_pos [SOME ct] exhaust) THEN_ALL_NEW hyp_subst_tac ctxt) THEN |
|
497 |
unfold_thms_tac ctxt sets THEN |
|
498 |
REPEAT_DETERM (HEADGOAL |
|
499 |
(eresolve_tac @{thms FalseE emptyE singletonE UnE UN_E insertE} ORELSE' |
|
500 |
hyp_subst_tac ctxt ORELSE' |
|
501 |
SELECT_GOAL (SOLVE (HEADGOAL (eresolve_tac assms THEN' REPEAT_DETERM o atac))))); |
|
502 |
||
57891 | 503 |
fun mk_set_intros_tac ctxt sets = |
504 |
TRYALL Goal.conjunction_tac THEN |
|
505 |
unfold_thms_tac ctxt sets THEN |
|
506 |
TRYALL (REPEAT o |
|
57893 | 507 |
(resolve_tac @{thms UnI1 UnI2} ORELSE' |
508 |
eresolve_tac @{thms UN_I UN_I[rotated]}) THEN' (rtac @{thm singletonI} ORELSE' atac)); |
|
57891 | 509 |
|
57700 | 510 |
fun mk_set_induct0_tac ctxt cts assms dtor_set_inducts exhausts set_pre_defs ctor_defs dtor_ctors |
511 |
Abs_pre_inverses = |
|
512 |
let |
|
58417
fa50722ad6cb
make 'set_induct0' tactic more robust w.r.t multiple arguments constructors
desharna
parents:
58359
diff
changeset
|
513 |
val assms_tac = |
fa50722ad6cb
make 'set_induct0' tactic more robust w.r.t multiple arguments constructors
desharna
parents:
58359
diff
changeset
|
514 |
let val assms' = map (unfold_thms ctxt (@{thm id_bnf_def} :: ctor_defs)) assms in |
fa50722ad6cb
make 'set_induct0' tactic more robust w.r.t multiple arguments constructors
desharna
parents:
58359
diff
changeset
|
515 |
fold (curry (op ORELSE')) (map (fn thm => |
fa50722ad6cb
make 'set_induct0' tactic more robust w.r.t multiple arguments constructors
desharna
parents:
58359
diff
changeset
|
516 |
funpow (length (prems_of thm)) (fn tac => tac THEN' atac) (rtac thm)) assms') |
fa50722ad6cb
make 'set_induct0' tactic more robust w.r.t multiple arguments constructors
desharna
parents:
58359
diff
changeset
|
517 |
(etac FalseE) |
fa50722ad6cb
make 'set_induct0' tactic more robust w.r.t multiple arguments constructors
desharna
parents:
58359
diff
changeset
|
518 |
end; |
57700 | 519 |
val exhausts' = map (fn thm => thm RS @{thm asm_rl[of "P x y" for P x y]}) exhausts |
520 |
|> map2 (fn ct => cterm_instantiate_pos [NONE, SOME ct]) cts; |
|
521 |
in |
|
522 |
ALLGOALS (resolve_tac dtor_set_inducts) THEN |
|
523 |
TRYALL (resolve_tac exhausts' THEN_ALL_NEW |
|
524 |
(resolve_tac (map (fn ct => refl RS |
|
525 |
cterm_instantiate_pos (replicate 4 NONE @ [SOME ct]) @{thm arg_cong2} RS iffD2) cts) |
|
526 |
THEN' atac THEN' hyp_subst_tac ctxt)) THEN |
|
527 |
unfold_thms_tac ctxt (Abs_pre_inverses @ dtor_ctors @ set_pre_defs @ ctor_defs @ |
|
58353 | 528 |
@{thms id_bnf_def o_apply sum_set_simps prod_set_simps UN_empty UN_insert Un_empty_left |
529 |
Un_empty_right empty_iff singleton_iff}) THEN |
|
58417
fa50722ad6cb
make 'set_induct0' tactic more robust w.r.t multiple arguments constructors
desharna
parents:
58359
diff
changeset
|
530 |
REPEAT (HEADGOAL (hyp_subst_tac ctxt ORELSE' eresolve_tac @{thms UN_E UnE singletonE} ORELSE' |
fa50722ad6cb
make 'set_induct0' tactic more robust w.r.t multiple arguments constructors
desharna
parents:
58359
diff
changeset
|
531 |
assms_tac)) |
57700 | 532 |
end; |
533 |
||
49123
263b0e330d8b
more work on sugar + simplify Trueprop + eq idiom everywhere
blanchet
parents:
diff
changeset
|
534 |
end; |