author | paulson <lp15@cam.ac.uk> |
Fri, 08 Aug 2025 16:46:03 +0100 | |
changeset 82969 | dedd9d13c79c |
parent 82872 | 898d3860a204 |
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 |
|
5219 | 8 |
signature CLASIMP_DATA = |
9 |
sig |
|
8469 | 10 |
structure Splitter: SPLITTER |
5219 | 11 |
structure Classical: CLASSICAL |
12 |
structure Blast: BLAST |
|
9860 | 13 |
val notE: thm |
14 |
val iffD1: thm |
|
15 |
val iffD2: thm |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
16 |
end; |
5219 | 17 |
|
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
18 |
signature CLASIMP = |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
19 |
sig |
42793 | 20 |
val addSss: Proof.context -> Proof.context |
21 |
val addss: Proof.context -> Proof.context |
|
22 |
val clarsimp_tac: Proof.context -> int -> tactic |
|
23 |
val mk_auto_tac: Proof.context -> int -> int -> tactic |
|
24 |
val auto_tac: Proof.context -> tactic |
|
25 |
val force_tac: Proof.context -> int -> tactic |
|
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
43331
diff
changeset
|
26 |
val fast_force_tac: Proof.context -> int -> tactic |
42793 | 27 |
val slow_simp_tac: Proof.context -> int -> tactic |
28 |
val best_simp_tac: Proof.context -> int -> tactic |
|
18728 | 29 |
val iff_add: attribute |
82870 | 30 |
val iff_add_pure: attribute |
18728 | 31 |
val iff_del: attribute |
30513 | 32 |
val iff_modifiers: Method.modifier parser list |
33 |
val clasimp_modifiers: Method.modifier parser list |
|
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
34 |
end; |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
35 |
|
42478 | 36 |
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
|
37 |
struct |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
38 |
|
42478 | 39 |
structure Splitter = Data.Splitter; |
40 |
structure Classical = Data.Classical; |
|
41 |
structure Blast = Data.Blast; |
|
5219 | 42 |
|
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26425
diff
changeset
|
43 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
44 |
(* simp as classical wrapper *) |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
45 |
|
42793 | 46 |
(*Caution: only one simpset added can be added by each of addSss and addss*) |
82872 | 47 |
local |
48 |
fun add_wrapper f name tac ctxt = f (ctxt, (name, fn _ => CHANGED o tac ctxt)); |
|
49 |
in |
|
50 |
val addSss = |
|
51 |
add_wrapper Classical.addSafter "safe_asm_full_simp_tac" Simplifier.safe_asm_full_simp_tac; |
|
52 |
val addss = |
|
53 |
add_wrapper Classical.addbefore "asm_full_simp_tac" Simplifier.asm_full_simp_tac; |
|
54 |
end; |
|
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
55 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
56 |
|
9860 | 57 |
(* iffs: addition of rules to simpsets and clasets simultaneously *) |
58 |
||
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
59 |
local |
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
60 |
|
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
61 |
val safe_atts = |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
62 |
{intro = Classical.safe_intro NONE, |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
63 |
elim = Classical.safe_elim NONE, |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
64 |
dest = Classical.safe_dest NONE}; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
65 |
|
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
66 |
val unsafe_atts = |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
67 |
{intro = Classical.unsafe_intro NONE, |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
68 |
elim = Classical.unsafe_elim NONE, |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
69 |
dest = Classical.unsafe_dest NONE}; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
70 |
|
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
71 |
val pure_atts = |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
72 |
{intro = Context_Rules.intro_query NONE, |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
73 |
elim = Context_Rules.elim_query NONE, |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
74 |
dest = Context_Rules.dest_query NONE}; |
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
75 |
|
82869 | 76 |
val del_atts = |
77 |
{intro = Classical.rule_del, |
|
78 |
elim = Classical.rule_del, |
|
79 |
dest = Classical.rule_del}; |
|
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 |
|
82869 | 87 |
fun iff_decl safe unsafe = |
60366 | 88 |
Thm.declaration_attribute (fn th => fn context => |
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
89 |
let |
59582 | 90 |
val n = Thm.nprems_of th; |
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
91 |
val {intro, elim, dest} = if n = 0 then safe else unsafe; |
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
92 |
val zero_rotate = zero_var_indexes o rotate_prems n; |
60366 | 93 |
val decls = |
94 |
[(intro, zero_rotate (th RS Data.iffD2)), |
|
82868
c2a88a1cd07d
explicit "dest" rules: no longer declare [elim_format, elim];
wenzelm
parents:
69593
diff
changeset
|
95 |
(dest, zero_rotate (th RS Data.iffD1))] |
60366 | 96 |
handle THM _ => [(elim, zero_rotate (th RS Data.notE))] |
97 |
handle THM _ => [(intro, th)]; |
|
98 |
in fold (uncurry Thm.attribute_declaration) decls context end); |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
99 |
|
9860 | 100 |
in |
101 |
||
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
102 |
val iff_add = |
45375
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents:
44890
diff
changeset
|
103 |
Thm.declaration_attribute (fn th => |
82869 | 104 |
Thm.attribute_declaration (iff_decl safe_atts unsafe_atts) th #> |
105 |
Thm.attribute_declaration Simplifier.simp_add th); |
|
10033
fc4e7432b2b1
added iff_add_global', iff_add_local' (syntax "iff?");
wenzelm
parents:
9952
diff
changeset
|
106 |
|
82870 | 107 |
val iff_add_pure = iff_decl pure_atts pure_atts; |
12375 | 108 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
109 |
val iff_del = |
45375
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents:
44890
diff
changeset
|
110 |
Thm.declaration_attribute (fn th => |
82869 | 111 |
Thm.attribute_declaration (iff_decl del_atts del_atts) th #> |
45375
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents:
44890
diff
changeset
|
112 |
Thm.attribute_declaration Simplifier.simp_del th); |
12375 | 113 |
|
9860 | 114 |
end; |
115 |
||
116 |
||
42478 | 117 |
(* tactics *) |
5219 | 118 |
|
42793 | 119 |
fun clarsimp_tac ctxt = |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
120 |
Simplifier.safe_asm_full_simp_tac ctxt THEN_ALL_NEW |
42793 | 121 |
Classical.clarify_tac (addSss ctxt); |
12375 | 122 |
|
5483 | 123 |
|
5219 | 124 |
(* auto_tac *) |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
125 |
|
9772 | 126 |
(* a variant of depth_tac that avoids interference of the simplifier |
5219 | 127 |
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
|
128 |
local |
42478 | 129 |
|
42793 | 130 |
fun slow_step_tac' ctxt = |
131 |
Classical.appWrappers ctxt |
|
60943 | 132 |
(Classical.instp_step_tac ctxt APPEND' Classical.unsafe_step_tac ctxt); |
42478 | 133 |
|
134 |
in |
|
135 |
||
42793 | 136 |
fun nodup_depth_tac ctxt m i st = |
42478 | 137 |
SELECT_GOAL |
42793 | 138 |
(Classical.safe_steps_tac ctxt 1 THEN_ELSE |
139 |
(DEPTH_SOLVE (nodup_depth_tac ctxt m 1), |
|
140 |
Classical.inst0_step_tac ctxt 1 APPEND COND (K (m = 0)) no_tac |
|
141 |
(slow_step_tac' ctxt 1 THEN DEPTH_SOLVE (nodup_depth_tac ctxt (m - 1) 1)))) i st; |
|
42479 | 142 |
|
5756
8ef5288c24b0
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5567
diff
changeset
|
143 |
end; |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
144 |
|
43331
01f051619eee
clarified raw_blast, which is not really a tactic since it operates directly on subgoal 1 without bounds check (cf. c46107e6714b);
wenzelm
parents:
42805
diff
changeset
|
145 |
(*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
|
146 |
in some of the subgoals*) |
42793 | 147 |
fun mk_auto_tac ctxt m n = |
42478 | 148 |
let |
149 |
val main_tac = |
|
43331
01f051619eee
clarified raw_blast, which is not really a tactic since it operates directly on subgoal 1 without bounds check (cf. c46107e6714b);
wenzelm
parents:
42805
diff
changeset
|
150 |
Blast.depth_tac ctxt m (* fast but can't use wrappers *) |
42478 | 151 |
ORELSE' |
42793 | 152 |
(CHANGED o nodup_depth_tac (addss ctxt) n); (* slower but more general *) |
42478 | 153 |
in |
58008 | 154 |
PARALLEL_ALLGOALS (Simplifier.asm_full_simp_tac ctxt) THEN |
42793 | 155 |
TRY (Classical.safe_tac ctxt) THEN |
42479 | 156 |
REPEAT_DETERM (FIRSTGOAL main_tac) THEN |
42793 | 157 |
TRY (Classical.safe_tac (addSss ctxt)) THEN |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
51717
diff
changeset
|
158 |
prune_params_tac ctxt |
42478 | 159 |
end; |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
160 |
|
42793 | 161 |
fun auto_tac ctxt = mk_auto_tac ctxt 4 2; |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
162 |
|
9772 | 163 |
|
5219 | 164 |
(* force_tac *) |
165 |
||
4659 | 166 |
(* aimed to solve the given subgoal totally, using whatever tools possible *) |
42793 | 167 |
fun force_tac ctxt = |
168 |
let val ctxt' = addss ctxt in |
|
42479 | 169 |
SELECT_GOAL |
42793 | 170 |
(Classical.clarify_tac ctxt' 1 THEN |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
171 |
IF_UNSOLVED (Simplifier.asm_full_simp_tac ctxt 1) THEN |
42793 | 172 |
ALLGOALS (Classical.first_best_tac ctxt')) |
42478 | 173 |
end; |
4659 | 174 |
|
5219 | 175 |
|
9805 | 176 |
(* basic combinations *) |
177 |
||
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
43331
diff
changeset
|
178 |
val fast_force_tac = Classical.fast_tac o addss; |
42793 | 179 |
val slow_simp_tac = Classical.slow_tac o addss; |
180 |
val best_simp_tac = Classical.best_tac o addss; |
|
9591 | 181 |
|
47967
c422128d3889
discontinued obsolete method fastsimp / tactic fast_simp_tac;
wenzelm
parents:
45375
diff
changeset
|
182 |
|
c422128d3889
discontinued obsolete method fastsimp / tactic fast_simp_tac;
wenzelm
parents:
45375
diff
changeset
|
183 |
|
42784
a2dca9a3d0da
simplified clasimpset declarations -- prefer attributes;
wenzelm
parents:
42479
diff
changeset
|
184 |
(** concrete syntax **) |
9860 | 185 |
|
186 |
(* attributes *) |
|
187 |
||
58826 | 188 |
val _ = |
189 |
Theory.setup |
|
69593 | 190 |
(Attrib.setup \<^binding>\<open>iff\<close> |
58826 | 191 |
(Scan.lift |
192 |
(Args.del >> K iff_del || |
|
82870 | 193 |
Scan.option Args.add -- Args.query >> K iff_add_pure || |
58826 | 194 |
Scan.option Args.add >> K iff_add)) |
195 |
"declaration of Simplifier / Classical rules"); |
|
9860 | 196 |
|
197 |
||
198 |
(* method modifiers *) |
|
199 |
||
82871 | 200 |
val iff_token = Args.$$$ "iff"; |
9860 | 201 |
|
202 |
val iff_modifiers = |
|
82871 | 203 |
[iff_token -- Scan.option Args.add -- Args.colon >> K (Method.modifier iff_add \<^here>), |
204 |
iff_token -- Scan.option Args.add -- Args.query_colon >> K (Method.modifier iff_add_pure \<^here>), |
|
205 |
iff_token -- Args.del -- Args.colon >> K (Method.modifier iff_del \<^here>)]; |
|
9860 | 206 |
|
8469 | 207 |
val clasimp_modifiers = |
9860 | 208 |
Simplifier.simp_modifiers @ Splitter.split_modifiers @ |
209 |
Classical.cla_modifiers @ iff_modifiers; |
|
210 |
||
211 |
||
212 |
(* methods *) |
|
5926 | 213 |
|
30541 | 214 |
fun clasimp_method' tac = |
42793 | 215 |
Method.sections clasimp_modifiers >> K (SIMPLE_METHOD' o tac); |
9772 | 216 |
|
30541 | 217 |
val auto_method = |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36601
diff
changeset
|
218 |
Scan.lift (Scan.option (Parse.nat -- Parse.nat)) --| |
35613 | 219 |
Method.sections clasimp_modifiers >> |
42793 | 220 |
(fn NONE => SIMPLE_METHOD o CHANGED_PROP o auto_tac |
221 |
| SOME (m, n) => (fn ctxt => SIMPLE_METHOD (CHANGED_PROP (mk_auto_tac ctxt m n)))); |
|
9772 | 222 |
|
58826 | 223 |
val _ = |
224 |
Theory.setup |
|
69593 | 225 |
(Method.setup \<^binding>\<open>fastforce\<close> (clasimp_method' fast_force_tac) "combined fast and simp" #> |
226 |
Method.setup \<^binding>\<open>slowsimp\<close> (clasimp_method' slow_simp_tac) "combined slow and simp" #> |
|
227 |
Method.setup \<^binding>\<open>bestsimp\<close> (clasimp_method' best_simp_tac) "combined best and simp" #> |
|
228 |
Method.setup \<^binding>\<open>force\<close> (clasimp_method' force_tac) "force" #> |
|
229 |
Method.setup \<^binding>\<open>auto\<close> auto_method "auto" #> |
|
230 |
Method.setup \<^binding>\<open>clarsimp\<close> (clasimp_method' (CHANGED_PROP oo clarsimp_tac)) |
|
58826 | 231 |
"clarify simplified goal"); |
5926 | 232 |
|
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
233 |
end; |