author | wenzelm |
Fri, 01 Sep 2000 00:31:08 +0200 | |
changeset 9772 | c07777210a69 |
parent 9591 | 590d36e059d1 |
child 9805 | 10b617bdd028 |
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 |
ID: $Id$ |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
3 |
Author: David von Oheimb, TU Muenchen |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
4 |
|
5219 | 5 |
Combination of classical reasoner and simplifier (depends on |
8469 | 6 |
simplifier.ML, 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
|
7 |
*) |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
8 |
|
5554 | 9 |
infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2 addsimps2 delsimps2; |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
10 |
infix 4 addSss addss; |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
11 |
|
5219 | 12 |
signature CLASIMP_DATA = |
13 |
sig |
|
14 |
structure Simplifier: SIMPLIFIER |
|
8469 | 15 |
structure Splitter: SPLITTER |
5219 | 16 |
structure Classical: CLASSICAL |
17 |
structure Blast: BLAST |
|
18 |
sharing type Classical.claset = Blast.claset |
|
19 |
end |
|
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 |
include CLASIMP_DATA |
24 |
type claset |
|
25 |
type simpset |
|
26 |
type clasimpset |
|
9772 | 27 |
val addSIs2 : clasimpset * thm list -> clasimpset |
28 |
val addSEs2 : clasimpset * thm list -> clasimpset |
|
29 |
val addSDs2 : clasimpset * thm list -> clasimpset |
|
30 |
val addIs2 : clasimpset * thm list -> clasimpset |
|
31 |
val addEs2 : clasimpset * thm list -> clasimpset |
|
32 |
val addDs2 : clasimpset * thm list -> clasimpset |
|
33 |
val addsimps2 : clasimpset * thm list -> clasimpset |
|
34 |
val delsimps2 : clasimpset * thm list -> clasimpset |
|
35 |
val addSss : claset * simpset -> claset |
|
36 |
val addss : claset * simpset -> claset |
|
5483 | 37 |
val CLASIMPSET :(clasimpset -> tactic) -> tactic |
38 |
val CLASIMPSET' :(clasimpset -> 'a -> tactic) -> 'a -> tactic |
|
39 |
val clarsimp_tac: clasimpset -> int -> tactic |
|
40 |
val Clarsimp_tac: int -> tactic |
|
41 |
val mk_auto_tac : clasimpset -> int -> int -> tactic |
|
9772 | 42 |
val auto_tac : clasimpset -> tactic |
43 |
val Auto_tac : tactic |
|
44 |
val auto : unit -> unit |
|
45 |
val force_tac : clasimpset -> int -> tactic |
|
46 |
val Force_tac : int -> tactic |
|
47 |
val force : int -> unit |
|
9591 | 48 |
val fast_simp_tac : clasimpset -> int -> tactic |
8639 | 49 |
val change_global_css: (clasimpset * thm list -> clasimpset) -> theory attribute |
50 |
val change_local_css: (clasimpset * thm list -> clasimpset) -> Proof.context attribute |
|
9506 | 51 |
val get_local_clasimpset: Proof.context -> clasimpset |
52 |
val clasimp_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list |
|
9772 | 53 |
val setup : (theory -> theory) list |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
54 |
end; |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
55 |
|
5219 | 56 |
functor ClasimpFun(Data: CLASIMP_DATA): CLASIMP = |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
57 |
struct |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
58 |
|
5219 | 59 |
open Data; |
60 |
||
61 |
type claset = Classical.claset; |
|
62 |
type simpset = Simplifier.simpset; |
|
63 |
type clasimpset = claset * simpset; |
|
64 |
||
65 |
||
66 |
(* clasimpset operations *) |
|
67 |
||
68 |
(*this interface for updating a clasimpset is rudimentary and just for |
|
69 |
convenience for the most common cases*) |
|
70 |
||
71 |
fun pair_upd1 f ((a,b),x) = (f(a,x), b); |
|
72 |
fun pair_upd2 f ((a,b),x) = (a, f(b,x)); |
|
73 |
||
74 |
fun op addSIs2 arg = pair_upd1 Classical.addSIs arg; |
|
75 |
fun op addSEs2 arg = pair_upd1 Classical.addSEs arg; |
|
76 |
fun op addSDs2 arg = pair_upd1 Classical.addSDs arg; |
|
77 |
fun op addIs2 arg = pair_upd1 Classical.addIs arg; |
|
78 |
fun op addEs2 arg = pair_upd1 Classical.addEs arg; |
|
79 |
fun op addDs2 arg = pair_upd1 Classical.addDs arg; |
|
80 |
fun op addsimps2 arg = pair_upd2 Simplifier.addsimps arg; |
|
81 |
fun op delsimps2 arg = pair_upd2 Simplifier.delsimps arg; |
|
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
82 |
|
9402 | 83 |
(*not totally safe: may instantiate unknowns that appear also in other subgoals*) |
84 |
val safe_asm_full_simp_tac = Simplifier.generic_simp_tac true (true,true,true); |
|
85 |
||
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
86 |
(*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
|
87 |
(*Caution: only one simpset added can be added by each of addSss and addss*) |
5567 | 88 |
fun cs addSss ss = Classical.addSaltern (cs, ("safe_asm_full_simp_tac", |
9772 | 89 |
CHANGED o safe_asm_full_simp_tac ss)); |
90 |
fun cs addss ss = Classical.addbefore (cs, ("asm_full_simp_tac", |
|
91 |
CHANGED o Simplifier.asm_full_simp_tac ss)); |
|
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
92 |
|
5219 | 93 |
(* tacticals *) |
94 |
||
95 |
fun CLASIMPSET tacf state = |
|
96 |
Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss))) state; |
|
97 |
||
98 |
fun CLASIMPSET' tacf i state = |
|
99 |
Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss) i)) state; |
|
4888 | 100 |
|
101 |
||
9402 | 102 |
fun clarsimp_tac (cs, ss) = safe_asm_full_simp_tac ss THEN_ALL_NEW |
9772 | 103 |
Classical.clarify_tac (cs addSss ss); |
5483 | 104 |
fun Clarsimp_tac i = clarsimp_tac (Classical.claset(), Simplifier.simpset()) i; |
105 |
||
106 |
||
5219 | 107 |
(* auto_tac *) |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
108 |
|
5219 | 109 |
fun blast_depth_tac cs m i thm = |
9772 | 110 |
Blast.depth_tac cs m i thm |
5554 | 111 |
handle Blast.TRANS s => (warning ("Blast_tac: " ^ s); Seq.empty); |
9772 | 112 |
|
113 |
(* a variant of depth_tac that avoids interference of the simplifier |
|
5219 | 114 |
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
|
115 |
local |
9772 | 116 |
fun slow_step_tac' cs = Classical.appWrappers cs |
117 |
(Classical.instp_step_tac cs APPEND' Classical.haz_step_tac cs); |
|
118 |
in fun nodup_depth_tac cs m i state = SELECT_GOAL |
|
119 |
(Classical.safe_steps_tac cs 1 THEN_ELSE |
|
120 |
(DEPTH_SOLVE (nodup_depth_tac cs m 1), |
|
121 |
Classical.inst0_step_tac cs 1 APPEND COND (K (m=0)) no_tac |
|
122 |
(slow_step_tac' cs 1 THEN DEPTH_SOLVE (nodup_depth_tac cs (m-1) 1)) |
|
5756
8ef5288c24b0
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5567
diff
changeset
|
123 |
)) i state; |
8ef5288c24b0
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5567
diff
changeset
|
124 |
end; |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
125 |
|
9402 | 126 |
(*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
|
127 |
in some of the subgoals*) |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
128 |
fun mk_auto_tac (cs, ss) m n = |
5219 | 129 |
let val cs' = cs addss ss |
9772 | 130 |
val maintac = |
131 |
blast_depth_tac cs m (* fast but can't use wrappers *) |
|
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
132 |
ORELSE' |
5756
8ef5288c24b0
corrected auto_tac (applications of unsafe wrappers)
oheimb
parents:
5567
diff
changeset
|
133 |
(CHANGED o nodup_depth_tac cs' n); (* slower but more general *) |
5219 | 134 |
in EVERY [ALLGOALS (Simplifier.asm_full_simp_tac ss), |
9772 | 135 |
TRY (Classical.safe_tac cs), |
136 |
REPEAT (FIRSTGOAL maintac), |
|
5219 | 137 |
TRY (Classical.safe_tac (cs addSss ss)), |
9772 | 138 |
prune_params_tac] |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
139 |
end; |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
140 |
|
9772 | 141 |
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
|
142 |
|
5219 | 143 |
fun Auto_tac st = auto_tac (Classical.claset(), Simplifier.simpset()) st; |
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
144 |
|
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
145 |
fun auto () = by Auto_tac; |
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
146 |
|
9772 | 147 |
|
5219 | 148 |
(* force_tac *) |
149 |
||
4659 | 150 |
(* aimed to solve the given subgoal totally, using whatever tools possible *) |
4717
1370ad043564
renamed smart_tac to force_tac, slight improvement of force_tac
oheimb
parents:
4659
diff
changeset
|
151 |
fun force_tac (cs,ss) = let val cs' = cs addss ss in SELECT_GOAL (EVERY [ |
9772 | 152 |
Classical.clarify_tac cs' 1, |
153 |
IF_UNSOLVED (Simplifier.asm_full_simp_tac ss 1), |
|
154 |
ALLGOALS (Classical.first_best_tac cs')]) end; |
|
5219 | 155 |
fun Force_tac i = force_tac (Classical.claset(), Simplifier.simpset()) i; |
4717
1370ad043564
renamed smart_tac to force_tac, slight improvement of force_tac
oheimb
parents:
4659
diff
changeset
|
156 |
fun force i = by (Force_tac i); |
4659 | 157 |
|
5219 | 158 |
|
9591 | 159 |
(* fast_simp_tac *) |
160 |
||
161 |
fun fast_simp_tac (cs, ss) = let val cs' = cs addss ss in Classical.fast_tac cs' end; |
|
162 |
||
163 |
||
9772 | 164 |
(* change clasimpset *) |
8639 | 165 |
|
166 |
fun change_global_css f (thy, th) = |
|
167 |
let |
|
168 |
val cs_ref = Classical.claset_ref_of thy; |
|
169 |
val ss_ref = Simplifier.simpset_ref_of thy; |
|
170 |
val (cs', ss') = f ((! cs_ref, ! ss_ref), [th]); |
|
171 |
in cs_ref := cs'; ss_ref := ss'; (thy, th) end; |
|
172 |
||
173 |
fun change_local_css f (ctxt, th) = |
|
174 |
let |
|
175 |
val cs = Classical.get_local_claset ctxt; |
|
176 |
val ss = Simplifier.get_local_simpset ctxt; |
|
177 |
val (cs', ss') = f ((cs, ss), [th]); |
|
178 |
val ctxt' = |
|
179 |
ctxt |
|
180 |
|> Classical.put_local_claset cs' |
|
181 |
|> Simplifier.put_local_simpset ss'; |
|
182 |
in (ctxt', th) end; |
|
183 |
||
184 |
||
5926 | 185 |
(* methods *) |
186 |
||
7153 | 187 |
fun get_local_clasimpset ctxt = |
188 |
(Classical.get_local_claset ctxt, Simplifier.get_local_simpset ctxt); |
|
5926 | 189 |
|
8469 | 190 |
val clasimp_modifiers = |
191 |
Simplifier.simp_modifiers @ Splitter.split_modifiers @ Classical.cla_modifiers; |
|
5926 | 192 |
|
7559 | 193 |
fun clasimp_meth tac prems ctxt = Method.METHOD (fn facts => |
194 |
ALLGOALS (Method.insert_tac (prems @ facts)) THEN tac (get_local_clasimpset ctxt)); |
|
7132 | 195 |
|
7559 | 196 |
fun clasimp_meth' tac prems ctxt = Method.METHOD (fn facts => |
8168 | 197 |
HEADGOAL (Method.insert_tac (prems @ facts) THEN' tac (get_local_clasimpset ctxt))); |
5926 | 198 |
|
7559 | 199 |
val clasimp_method = Method.bang_sectioned_args clasimp_modifiers o clasimp_meth; |
200 |
val clasimp_method' = Method.bang_sectioned_args clasimp_modifiers o clasimp_meth'; |
|
5926 | 201 |
|
202 |
||
9772 | 203 |
fun auto_args m = |
204 |
Method.bang_sectioned_args' clasimp_modifiers (Scan.lift (Scan.option (Args.nat -- Args.nat))) m; |
|
205 |
||
206 |
fun auto_meth None = clasimp_meth (CHANGED o auto_tac) |
|
207 |
| auto_meth (Some (m, n)) = clasimp_meth (CHANGED o (fn css => mk_auto_tac css m n)); |
|
208 |
||
209 |
||
210 |
(* theory setup *) |
|
211 |
||
5926 | 212 |
val setup = |
213 |
[Method.add_methods |
|
9591 | 214 |
[("fastsimp", clasimp_method' fast_simp_tac, "combined fast and simp"), |
215 |
("force", clasimp_method' force_tac, "force"), |
|
9772 | 216 |
("auto", auto_args auto_meth, "auto"), |
9591 | 217 |
("clarsimp", clasimp_method' (CHANGED oo clarsimp_tac), "clarify simplified goal")]]; |
5926 | 218 |
|
219 |
||
4652
d24cca140eeb
factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff
changeset
|
220 |
end; |