author | wenzelm |
Fri, 13 May 2011 13:45:20 +0200 | |
changeset 42784 | a2dca9a3d0da |
parent 42479 | b7c9f09d4d88 |
child 42793 | 88bee9f6eec7 |
permissions | -rw-r--r-- |
9772 | 1 |
(* Title: Provers/clasimp.ML |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
2 |
Author: David von Oheimb, TU Muenchen |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
3 |
|
5219 | 4 |
Combination of classical reasoner and simplifier (depends on |
16019 | 5 |
splitter.ML, classical.ML, blast.ML). |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
6 |
*) |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
7 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
8 |
infix 4 addSss addss addss'; |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
9 |
|
5219 | 10 |
signature CLASIMP_DATA = |
11 |
sig |
|
8469 | 12 |
structure Splitter: SPLITTER |
5219 | 13 |
structure Classical: CLASSICAL |
14 |
structure Blast: BLAST |
|
15 |
sharing type Classical.claset = Blast.claset |
|
9860 | 16 |
val notE: thm |
17 |
val iffD1: thm |
|
18 |
val iffD2: thm |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
19 |
end; |
5219 | 20 |
|
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
21 |
signature CLASIMP = |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
22 |
sig |
5219 | 23 |
type claset |
24 |
type clasimpset |
|
32148
253f6808dabe
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents:
30609
diff
changeset
|
25 |
val clasimpset_of: Proof.context -> clasimpset |
9860 | 26 |
val addSss: claset * simpset -> claset |
27 |
val addss: claset * simpset -> claset |
|
13603
57f364d1d3b2
Introduced addss', which adds asm_lr_simp_tac as a wrapper to the claset.
berghofe
parents:
13026
diff
changeset
|
28 |
val addss': claset * simpset -> claset |
5483 | 29 |
val clarsimp_tac: clasimpset -> int -> tactic |
9860 | 30 |
val mk_auto_tac: clasimpset -> int -> int -> tactic |
31 |
val auto_tac: clasimpset -> tactic |
|
32 |
val force_tac: clasimpset -> int -> tactic |
|
33 |
val fast_simp_tac: clasimpset -> int -> tactic |
|
34 |
val slow_simp_tac: clasimpset -> int -> tactic |
|
35 |
val best_simp_tac: clasimpset -> int -> tactic |
|
18728 | 36 |
val iff_add: attribute |
37 |
val iff_add': attribute |
|
38 |
val iff_del: attribute |
|
30513 | 39 |
val iff_modifiers: Method.modifier parser list |
40 |
val clasimp_modifiers: Method.modifier parser list |
|
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26425
diff
changeset
|
41 |
val clasimp_setup: theory -> theory |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
42 |
end; |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
43 |
|
42478 | 44 |
functor Clasimp(Data: CLASIMP_DATA): CLASIMP = |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
45 |
struct |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
46 |
|
42478 | 47 |
structure Splitter = Data.Splitter; |
48 |
structure Classical = Data.Classical; |
|
49 |
structure Blast = Data.Blast; |
|
5219 | 50 |
|
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26425
diff
changeset
|
51 |
|
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26425
diff
changeset
|
52 |
(* type clasimpset *) |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26425
diff
changeset
|
53 |
|
5219 | 54 |
type claset = Classical.claset; |
55 |
type clasimpset = claset * simpset; |
|
56 |
||
32148
253f6808dabe
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents:
30609
diff
changeset
|
57 |
fun clasimpset_of ctxt = (Classical.claset_of ctxt, Simplifier.simpset_of ctxt); |
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26425
diff
changeset
|
58 |
|
5219 | 59 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
60 |
(* simp as classical wrapper *) |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
61 |
|
9402 | 62 |
(*not totally safe: may instantiate unknowns that appear also in other subgoals*) |
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
63 |
val safe_asm_full_simp_tac = Simplifier.generic_simp_tac true (true, true, true); |
9402 | 64 |
|
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
65 |
(*Add a simpset to a classical set!*) |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
66 |
(*Caution: only one simpset added can be added by each of addSss and addss*) |
42478 | 67 |
fun cs addSss ss = |
68 |
Classical.addSafter (cs, ("safe_asm_full_simp_tac", CHANGED o safe_asm_full_simp_tac ss)); |
|
69 |
||
70 |
fun cs addss ss = |
|
71 |
Classical.addbefore (cs, ("asm_full_simp_tac", CHANGED o Simplifier.asm_full_simp_tac ss)); |
|
72 |
||
73 |
fun cs addss' ss = |
|
74 |
Classical.addbefore (cs, ("asm_full_simp_tac", CHANGED o Simplifier.asm_lr_simp_tac ss)); |
|
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
75 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
76 |
|
9860 | 77 |
(* iffs: addition of rules to simpsets and clasets simultaneously *) |
78 |
||
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
79 |
local |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
80 |
|
11344 | 81 |
(*Takes (possibly conditional) theorems of the form A<->B to |
9860 | 82 |
the Safe Intr rule B==>A and |
83 |
the Safe Destruct rule A==>B. |
|
84 |
Also ~A goes to the Safe Elim rule A ==> ?R |
|
11462 | 85 |
Failing other cases, A is added as a Safe Intr rule*) |
9860 | 86 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
87 |
fun app (att: attribute) th context = #1 (att (context, th)); |
9860 | 88 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
89 |
fun add_iff safe unsafe = |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
90 |
Thm.declaration_attribute (fn th => |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
91 |
let |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
92 |
val n = nprems_of th; |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
93 |
val (elim, intro) = if n = 0 then safe else unsafe; |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
94 |
val zero_rotate = zero_var_indexes o rotate_prems n; |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
95 |
in |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
96 |
app intro (zero_rotate (th RS Data.iffD2)) #> |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
97 |
app elim (Tactic.make_elim (zero_rotate (th RS Data.iffD1))) |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
98 |
handle THM _ => (app elim (zero_rotate (th RS Data.notE)) handle THM _ => app intro th) |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
99 |
end); |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
100 |
|
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
101 |
fun del_iff del = Thm.declaration_attribute (fn th => |
11902 | 102 |
let val zero_rotate = zero_var_indexes o rotate_prems (nprems_of th) in |
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
103 |
app del (zero_rotate (th RS Data.iffD2)) #> |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
104 |
app del (Tactic.make_elim (zero_rotate (th RS Data.iffD1))) |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
105 |
handle THM _ => (app del (zero_rotate (th RS Data.notE)) handle THM _ => app del th) |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
106 |
end); |
18630 | 107 |
|
9860 | 108 |
in |
109 |
||
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
110 |
val iff_add = |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
111 |
add_iff |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
112 |
(Classical.safe_elim NONE, Classical.safe_intro NONE) |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
113 |
(Classical.haz_elim NONE, Classical.haz_intro NONE) |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
114 |
#> Simplifier.simp_add; |
10033
fc4e7432b2b1
added iff_add_global', iff_add_local' (syntax "iff?");
wenzelm
parents:
9952
diff
changeset
|
115 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
116 |
val iff_add' = |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
117 |
add_iff |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
118 |
(Context_Rules.elim_query NONE, Context_Rules.intro_query NONE) |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
119 |
(Context_Rules.elim_query NONE, Context_Rules.intro_query NONE); |
12375 | 120 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
121 |
val iff_del = |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
122 |
del_iff Classical.rule_del #> |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
123 |
del_iff Context_Rules.rule_del #> |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
124 |
Simplifier.simp_del; |
12375 | 125 |
|
9860 | 126 |
end; |
127 |
||
128 |
||
42478 | 129 |
(* tactics *) |
5219 | 130 |
|
12375 | 131 |
fun clarsimp_tac (cs, ss) = |
132 |
safe_asm_full_simp_tac ss THEN_ALL_NEW |
|
133 |
Classical.clarify_tac (cs addSss ss); |
|
134 |
||
5483 | 135 |
|
5219 | 136 |
(* auto_tac *) |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
137 |
|
5219 | 138 |
fun blast_depth_tac cs m i thm = |
42478 | 139 |
Blast.depth_tac cs m i thm |
140 |
handle Blast.TRANS s => (warning ("Blast_tac: " ^ s); Seq.empty); |
|
9772 | 141 |
|
142 |
(* a variant of depth_tac that avoids interference of the simplifier |
|
5219 | 143 |
with dup_step_tac when they are combined by auto_tac *) |
5756
8ef5288c24b0
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5567
diff
changeset
|
144 |
local |
42478 | 145 |
|
146 |
fun slow_step_tac' cs = |
|
147 |
Classical.appWrappers cs |
|
148 |
(Classical.instp_step_tac cs APPEND' Classical.haz_step_tac cs); |
|
149 |
||
150 |
in |
|
151 |
||
42479 | 152 |
fun nodup_depth_tac cs m i st = |
42478 | 153 |
SELECT_GOAL |
154 |
(Classical.safe_steps_tac cs 1 THEN_ELSE |
|
155 |
(DEPTH_SOLVE (nodup_depth_tac cs m 1), |
|
156 |
Classical.inst0_step_tac cs 1 APPEND COND (K (m = 0)) no_tac |
|
42479 | 157 |
(slow_step_tac' cs 1 THEN DEPTH_SOLVE (nodup_depth_tac cs (m - 1) 1)))) i st; |
158 |
||
5756
8ef5288c24b0
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5567
diff
changeset
|
159 |
end; |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
160 |
|
9402 | 161 |
(*Designed to be idempotent, except if blast_depth_tac instantiates variables |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
162 |
in some of the subgoals*) |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
163 |
fun mk_auto_tac (cs, ss) m n = |
42478 | 164 |
let |
165 |
val cs' = cs addss ss; |
|
166 |
val main_tac = |
|
167 |
blast_depth_tac cs m (* fast but can't use wrappers *) |
|
168 |
ORELSE' |
|
169 |
(CHANGED o nodup_depth_tac cs' n); (* slower but more general *) |
|
170 |
in |
|
42479 | 171 |
PARALLEL_GOALS (ALLGOALS (Simplifier.asm_full_simp_tac ss)) THEN |
172 |
TRY (Classical.safe_tac cs) THEN |
|
173 |
REPEAT_DETERM (FIRSTGOAL main_tac) THEN |
|
174 |
TRY (Classical.safe_tac (cs addSss ss)) THEN |
|
175 |
prune_params_tac |
|
42478 | 176 |
end; |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
177 |
|
9772 | 178 |
fun auto_tac css = mk_auto_tac css 4 2; |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
179 |
|
9772 | 180 |
|
5219 | 181 |
(* force_tac *) |
182 |
||
4659 | 183 |
(* aimed to solve the given subgoal totally, using whatever tools possible *) |
42478 | 184 |
fun force_tac (cs, ss) = |
185 |
let val cs' = cs addss ss in |
|
42479 | 186 |
SELECT_GOAL |
187 |
(Classical.clarify_tac cs' 1 THEN |
|
188 |
IF_UNSOLVED (Simplifier.asm_full_simp_tac ss 1) THEN |
|
189 |
ALLGOALS (Classical.first_best_tac cs')) |
|
42478 | 190 |
end; |
4659 | 191 |
|
5219 | 192 |
|
9805 | 193 |
(* basic combinations *) |
194 |
||
195 |
fun ADDSS tac (cs, ss) = let val cs' = cs addss ss in tac cs' end; |
|
9591 | 196 |
|
9805 | 197 |
val fast_simp_tac = ADDSS Classical.fast_tac; |
198 |
val slow_simp_tac = ADDSS Classical.slow_tac; |
|
199 |
val best_simp_tac = ADDSS Classical.best_tac; |
|
9591 | 200 |
|
201 |
||
8639 | 202 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
203 |
(** concrete syntax **) |
9860 | 204 |
|
205 |
(* attributes *) |
|
206 |
||
30528 | 207 |
fun iff_att x = (Scan.lift |
18688 | 208 |
(Args.del >> K iff_del || |
209 |
Scan.option Args.add -- Args.query >> K iff_add' || |
|
30528 | 210 |
Scan.option Args.add >> K iff_add)) x; |
9860 | 211 |
|
212 |
||
213 |
(* method modifiers *) |
|
214 |
||
215 |
val iffN = "iff"; |
|
216 |
||
217 |
val iff_modifiers = |
|
18728 | 218 |
[Args.$$$ iffN -- Scan.option Args.add -- Args.colon >> K ((I, iff_add): Method.modifier), |
219 |
Args.$$$ iffN -- Scan.option Args.add -- Args.query_colon >> K (I, iff_add'), |
|
220 |
Args.$$$ iffN -- Args.del -- Args.colon >> K (I, iff_del)]; |
|
9860 | 221 |
|
8469 | 222 |
val clasimp_modifiers = |
9860 | 223 |
Simplifier.simp_modifiers @ Splitter.split_modifiers @ |
224 |
Classical.cla_modifiers @ iff_modifiers; |
|
225 |
||
226 |
||
227 |
(* methods *) |
|
5926 | 228 |
|
35613 | 229 |
fun clasimp_meth tac ctxt = METHOD (fn facts => |
230 |
ALLGOALS (Method.insert_tac facts) THEN tac (clasimpset_of ctxt)); |
|
7132 | 231 |
|
35613 | 232 |
fun clasimp_meth' tac ctxt = METHOD (fn facts => |
233 |
HEADGOAL (Method.insert_tac facts THEN' tac (clasimpset_of ctxt))); |
|
5926 | 234 |
|
235 |
||
30541 | 236 |
fun clasimp_method' tac = |
35613 | 237 |
Method.sections clasimp_modifiers >> K (clasimp_meth' tac); |
9772 | 238 |
|
30541 | 239 |
val auto_method = |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36601
diff
changeset
|
240 |
Scan.lift (Scan.option (Parse.nat -- Parse.nat)) --| |
35613 | 241 |
Method.sections clasimp_modifiers >> |
242 |
(fn NONE => clasimp_meth (CHANGED_PROP o auto_tac) |
|
243 |
| SOME (m, n) => clasimp_meth (CHANGED_PROP o (fn css => mk_auto_tac css m n))); |
|
9772 | 244 |
|
245 |
||
246 |
(* theory setup *) |
|
247 |
||
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26425
diff
changeset
|
248 |
val clasimp_setup = |
30541 | 249 |
Attrib.setup @{binding iff} iff_att "declaration of Simplifier / Classical rules" #> |
250 |
Method.setup @{binding fastsimp} (clasimp_method' fast_simp_tac) "combined fast and simp" #> |
|
251 |
Method.setup @{binding slowsimp} (clasimp_method' slow_simp_tac) "combined slow and simp" #> |
|
252 |
Method.setup @{binding bestsimp} (clasimp_method' best_simp_tac) "combined best and simp" #> |
|
253 |
Method.setup @{binding force} (clasimp_method' force_tac) "force" #> |
|
254 |
Method.setup @{binding auto} auto_method "auto" #> |
|
255 |
Method.setup @{binding clarsimp} (clasimp_method' (CHANGED_PROP oo clarsimp_tac)) |
|
256 |
"clarify simplified goal"; |
|
5926 | 257 |
|
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
258 |
end; |