author | wenzelm |
Thu, 22 Nov 2001 23:44:30 +0100 | |
changeset 12270 | 71534648d5d4 |
parent 12109 | bd6eb9194a5d |
child 12311 | ce5f9e61c037 |
permissions | -rw-r--r-- |
9938 | 1 |
(* Title: Provers/classical.ML |
0 | 2 |
ID: $Id$ |
9938 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
0 | 4 |
Copyright 1992 University of Cambridge |
5 |
||
6 |
Theorem prover for classical reasoning, including predicate calculus, set |
|
7 |
theory, etc. |
|
8 |
||
9563
216d053992a5
fixed classification of rules in atts and modifiers (final!?);
wenzelm
parents:
9513
diff
changeset
|
9 |
Rules must be classified as intro, elim, safe, hazardous (unsafe). |
0 | 10 |
|
11 |
A rule is unsafe unless it can be applied blindly without harmful results. |
|
12 |
For a rule to be safe, its premises and conclusion should be logically |
|
13 |
equivalent. There should be no variables in the premises that are not in |
|
14 |
the conclusion. |
|
15 |
*) |
|
16 |
||
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
17 |
(*higher precedence than := facilitates use of references*) |
10034 | 18 |
infix 4 addSIs addSEs addSDs addIs addEs addDs addXIs addXEs addXDs delrules |
4651 | 19 |
addSWrapper delSWrapper addWrapper delWrapper |
11181
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
20 |
addSbefore addSafter addbefore addafter |
5523 | 21 |
addD2 addE2 addSD2 addSE2; |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
22 |
|
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
23 |
|
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
24 |
(*should be a type abbreviation in signature CLASSICAL*) |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
25 |
type netpair = (int * (bool * thm)) Net.net * (int * (bool * thm)) Net.net; |
4651 | 26 |
type wrapper = (int -> tactic) -> (int -> tactic); |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
27 |
|
0 | 28 |
signature CLASSICAL_DATA = |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
29 |
sig |
9171 | 30 |
val make_elim : thm -> thm (* Tactic.make_elim or a classical version*) |
9938 | 31 |
val mp : thm (* [| P-->Q; P |] ==> Q *) |
32 |
val not_elim : thm (* [| ~P; P |] ==> R *) |
|
33 |
val classical : thm (* (~P ==> P) ==> P *) |
|
34 |
val sizef : thm -> int (* size function for BEST_FIRST *) |
|
0 | 35 |
val hyp_subst_tacs: (int -> tactic) list |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
36 |
end; |
0 | 37 |
|
5841 | 38 |
signature BASIC_CLASSICAL = |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
39 |
sig |
0 | 40 |
type claset |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
41 |
val empty_cs: claset |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
42 |
val print_cs: claset -> unit |
4380 | 43 |
val print_claset: theory -> unit |
4653 | 44 |
val rep_cs: (* BLAST_DATA in blast.ML dependent on this *) |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
45 |
claset -> {safeIs: thm list, safeEs: thm list, |
9938 | 46 |
hazIs: thm list, hazEs: thm list, |
47 |
xtraIs: thm list, xtraEs: thm list, |
|
10736 | 48 |
swrappers: (string * wrapper) list, |
9938 | 49 |
uwrappers: (string * wrapper) list, |
50 |
safe0_netpair: netpair, safep_netpair: netpair, |
|
51 |
haz_netpair: netpair, dup_netpair: netpair, xtra_netpair: netpair} |
|
52 |
val merge_cs : claset * claset -> claset |
|
53 |
val addDs : claset * thm list -> claset |
|
54 |
val addEs : claset * thm list -> claset |
|
55 |
val addIs : claset * thm list -> claset |
|
56 |
val addSDs : claset * thm list -> claset |
|
57 |
val addSEs : claset * thm list -> claset |
|
58 |
val addSIs : claset * thm list -> claset |
|
10034 | 59 |
val addXDs : claset * thm list -> claset |
60 |
val addXEs : claset * thm list -> claset |
|
61 |
val addXIs : claset * thm list -> claset |
|
9938 | 62 |
val delrules : claset * thm list -> claset |
63 |
val addSWrapper : claset * (string * wrapper) -> claset |
|
64 |
val delSWrapper : claset * string -> claset |
|
65 |
val addWrapper : claset * (string * wrapper) -> claset |
|
66 |
val delWrapper : claset * string -> claset |
|
67 |
val addSbefore : claset * (string * (int -> tactic)) -> claset |
|
11181
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
68 |
val addSafter : claset * (string * (int -> tactic)) -> claset |
9938 | 69 |
val addbefore : claset * (string * (int -> tactic)) -> claset |
11181
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
70 |
val addafter : claset * (string * (int -> tactic)) -> claset |
5523 | 71 |
val addD2 : claset * (string * thm) -> claset |
72 |
val addE2 : claset * (string * thm) -> claset |
|
73 |
val addSD2 : claset * (string * thm) -> claset |
|
74 |
val addSE2 : claset * (string * thm) -> claset |
|
9938 | 75 |
val appSWrappers : claset -> wrapper |
76 |
val appWrappers : claset -> wrapper |
|
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
77 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
78 |
val claset_ref_of_sg: Sign.sg -> claset ref |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
79 |
val claset_ref_of: theory -> claset ref |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
80 |
val claset_of_sg: Sign.sg -> claset |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
81 |
val claset_of: theory -> claset |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
82 |
val CLASET: (claset -> tactic) -> tactic |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
83 |
val CLASET': (claset -> 'a -> tactic) -> 'a -> tactic |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
84 |
val claset: unit -> claset |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
85 |
val claset_ref: unit -> claset ref |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
86 |
|
9938 | 87 |
val fast_tac : claset -> int -> tactic |
88 |
val slow_tac : claset -> int -> tactic |
|
89 |
val weight_ASTAR : int ref |
|
90 |
val astar_tac : claset -> int -> tactic |
|
91 |
val slow_astar_tac : claset -> int -> tactic |
|
92 |
val best_tac : claset -> int -> tactic |
|
93 |
val first_best_tac : claset -> int -> tactic |
|
94 |
val slow_best_tac : claset -> int -> tactic |
|
95 |
val depth_tac : claset -> int -> int -> tactic |
|
96 |
val deepen_tac : claset -> int -> int -> tactic |
|
1587
e7d8a4957bac
Now provides astar versions (thanks to Norbert Voelker)
paulson
parents:
1524
diff
changeset
|
97 |
|
9938 | 98 |
val contr_tac : int -> tactic |
99 |
val dup_elim : thm -> thm |
|
100 |
val dup_intr : thm -> thm |
|
101 |
val dup_step_tac : claset -> int -> tactic |
|
102 |
val eq_mp_tac : int -> tactic |
|
103 |
val haz_step_tac : claset -> int -> tactic |
|
104 |
val joinrules : thm list * thm list -> (bool * thm) list |
|
105 |
val mp_tac : int -> tactic |
|
106 |
val safe_tac : claset -> tactic |
|
107 |
val safe_steps_tac : claset -> int -> tactic |
|
108 |
val safe_step_tac : claset -> int -> tactic |
|
109 |
val clarify_tac : claset -> int -> tactic |
|
110 |
val clarify_step_tac : claset -> int -> tactic |
|
111 |
val step_tac : claset -> int -> tactic |
|
112 |
val slow_step_tac : claset -> int -> tactic |
|
113 |
val swap : thm (* ~P ==> (~Q ==> P) ==> Q *) |
|
114 |
val swapify : thm list -> thm list |
|
115 |
val swap_res_tac : thm list -> int -> tactic |
|
116 |
val inst_step_tac : claset -> int -> tactic |
|
117 |
val inst0_step_tac : claset -> int -> tactic |
|
118 |
val instp_step_tac : claset -> int -> tactic |
|
1724 | 119 |
|
9938 | 120 |
val AddDs : thm list -> unit |
121 |
val AddEs : thm list -> unit |
|
122 |
val AddIs : thm list -> unit |
|
123 |
val AddSDs : thm list -> unit |
|
124 |
val AddSEs : thm list -> unit |
|
125 |
val AddSIs : thm list -> unit |
|
126 |
val AddXDs : thm list -> unit |
|
127 |
val AddXEs : thm list -> unit |
|
128 |
val AddXIs : thm list -> unit |
|
129 |
val Delrules : thm list -> unit |
|
130 |
val Safe_tac : tactic |
|
131 |
val Safe_step_tac : int -> tactic |
|
132 |
val Clarify_tac : int -> tactic |
|
133 |
val Clarify_step_tac : int -> tactic |
|
134 |
val Step_tac : int -> tactic |
|
135 |
val Fast_tac : int -> tactic |
|
136 |
val Best_tac : int -> tactic |
|
137 |
val Slow_tac : int -> tactic |
|
2066 | 138 |
val Slow_best_tac : int -> tactic |
9938 | 139 |
val Deepen_tac : int -> int -> tactic |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
140 |
end; |
1724 | 141 |
|
5841 | 142 |
signature CLASSICAL = |
143 |
sig |
|
144 |
include BASIC_CLASSICAL |
|
145 |
val print_local_claset: Proof.context -> unit |
|
146 |
val get_local_claset: Proof.context -> claset |
|
147 |
val put_local_claset: claset -> Proof.context -> Proof.context |
|
148 |
val safe_dest_global: theory attribute |
|
149 |
val safe_elim_global: theory attribute |
|
150 |
val safe_intro_global: theory attribute |
|
6955 | 151 |
val haz_dest_global: theory attribute |
152 |
val haz_elim_global: theory attribute |
|
153 |
val haz_intro_global: theory attribute |
|
154 |
val xtra_dest_global: theory attribute |
|
155 |
val xtra_elim_global: theory attribute |
|
156 |
val xtra_intro_global: theory attribute |
|
9938 | 157 |
val rule_del_global: theory attribute |
6955 | 158 |
val safe_dest_local: Proof.context attribute |
159 |
val safe_elim_local: Proof.context attribute |
|
160 |
val safe_intro_local: Proof.context attribute |
|
5885 | 161 |
val haz_dest_local: Proof.context attribute |
162 |
val haz_elim_local: Proof.context attribute |
|
163 |
val haz_intro_local: Proof.context attribute |
|
6955 | 164 |
val xtra_dest_local: Proof.context attribute |
165 |
val xtra_elim_local: Proof.context attribute |
|
166 |
val xtra_intro_local: Proof.context attribute |
|
9938 | 167 |
val rule_del_local: Proof.context attribute |
7272 | 168 |
val cla_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list |
7559 | 169 |
val cla_meth: (claset -> tactic) -> thm list -> Proof.context -> Proof.method |
170 |
val cla_meth': (claset -> int -> tactic) -> thm list -> Proof.context -> Proof.method |
|
5927 | 171 |
val cla_method: (claset -> tactic) -> Args.src -> Proof.context -> Proof.method |
172 |
val cla_method': (claset -> int -> tactic) -> Args.src -> Proof.context -> Proof.method |
|
5841 | 173 |
val setup: (theory -> theory) list |
174 |
end; |
|
175 |
||
0 | 176 |
|
5927 | 177 |
functor ClassicalFun(Data: CLASSICAL_DATA): CLASSICAL = |
0 | 178 |
struct |
179 |
||
7354 | 180 |
local open Data in |
0 | 181 |
|
1800 | 182 |
(*** Useful tactics for classical reasoning ***) |
0 | 183 |
|
1524 | 184 |
val imp_elim = (*cannot use bind_thm within a structure!*) |
9938 | 185 |
store_thm ("imp_elim", Data.make_elim mp); |
0 | 186 |
|
10736 | 187 |
(*Prove goal that assumes both P and ~P. |
4392 | 188 |
No backtracking if it finds an equal assumption. Perhaps should call |
189 |
ematch_tac instead of eresolve_tac, but then cannot prove ZF/cantor.*) |
|
10736 | 190 |
val contr_tac = eresolve_tac [not_elim] THEN' |
4392 | 191 |
(eq_assume_tac ORELSE' assume_tac); |
0 | 192 |
|
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
193 |
(*Finds P-->Q and P in the assumptions, replaces implication by Q. |
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
194 |
Could do the same thing for P<->Q and P... *) |
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
195 |
fun mp_tac i = eresolve_tac [not_elim, imp_elim] i THEN assume_tac i; |
0 | 196 |
|
197 |
(*Like mp_tac but instantiates no variables*) |
|
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
198 |
fun eq_mp_tac i = ematch_tac [not_elim, imp_elim] i THEN eq_assume_tac i; |
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
199 |
|
1524 | 200 |
val swap = |
201 |
store_thm ("swap", rule_by_tactic (etac thin_rl 1) (not_elim RS classical)); |
|
0 | 202 |
|
203 |
(*Creates rules to eliminate ~A, from rules to introduce A*) |
|
204 |
fun swapify intrs = intrs RLN (2, [swap]); |
|
205 |
||
206 |
(*Uses introduction rules in the normal way, or on negated assumptions, |
|
207 |
trying rules in order. *) |
|
10736 | 208 |
fun swap_res_tac rls = |
54 | 209 |
let fun addrl (rl,brls) = (false, rl) :: (true, rl RSN (2,swap)) :: brls |
10736 | 210 |
in assume_tac ORELSE' |
211 |
contr_tac ORELSE' |
|
54 | 212 |
biresolve_tac (foldr addrl (rls,[])) |
0 | 213 |
end; |
214 |
||
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
215 |
(*Duplication of hazardous rules, for complete provers*) |
2689
6d3d893453de
dup_intr & dup_elim no longer call standard -- this
paulson
parents:
2630
diff
changeset
|
216 |
fun dup_intr th = zero_var_indexes (th RS classical); |
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
217 |
|
6967 | 218 |
fun dup_elim th = |
219 |
(case try |
|
220 |
(rule_by_tactic (TRYALL (etac revcut_rl))) |
|
221 |
(th RSN (2, revcut_rl) |> assumption 2 |> Seq.hd) of |
|
222 |
Some th' => th' |
|
223 |
| _ => error ("Bad format for elimination rule\n" ^ string_of_thm th)); |
|
0 | 224 |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
225 |
|
1800 | 226 |
(**** Classical rule sets ****) |
0 | 227 |
|
228 |
datatype claset = |
|
9938 | 229 |
CS of {safeIs : thm list, (*safe introduction rules*) |
230 |
safeEs : thm list, (*safe elimination rules*) |
|
231 |
hazIs : thm list, (*unsafe introduction rules*) |
|
232 |
hazEs : thm list, (*unsafe elimination rules*) |
|
233 |
xtraIs : thm list, (*extra introduction rules*) |
|
234 |
xtraEs : thm list, (*extra elimination rules*) |
|
235 |
swrappers : (string * wrapper) list, (*for transf. safe_step_tac*) |
|
236 |
uwrappers : (string * wrapper) list, (*for transforming step_tac*) |
|
237 |
safe0_netpair : netpair, (*nets for trivial cases*) |
|
238 |
safep_netpair : netpair, (*nets for >0 subgoals*) |
|
239 |
haz_netpair : netpair, (*nets for unsafe rules*) |
|
240 |
dup_netpair : netpair, (*nets for duplication*) |
|
241 |
xtra_netpair : netpair}; (*nets for extra rules*) |
|
0 | 242 |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
243 |
(*Desired invariants are |
9938 | 244 |
safe0_netpair = build safe0_brls, |
245 |
safep_netpair = build safep_brls, |
|
246 |
haz_netpair = build (joinrules(hazIs, hazEs)), |
|
10736 | 247 |
dup_netpair = build (joinrules(map dup_intr hazIs, |
9938 | 248 |
map dup_elim hazEs)), |
249 |
xtra_netpair = build (joinrules(xtraIs, xtraEs))} |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
250 |
|
10736 | 251 |
where build = build_netpair(Net.empty,Net.empty), |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
252 |
safe0_brls contains all brules that solve the subgoal, and |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
253 |
safep_brls contains all brules that generate 1 or more new subgoals. |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
254 |
The theorem lists are largely comments, though they are used in merge_cs and print_cs. |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
255 |
Nets must be built incrementally, to save space and time. |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
256 |
*) |
0 | 257 |
|
6502 | 258 |
val empty_netpair = (Net.empty, Net.empty); |
259 |
||
10736 | 260 |
val empty_cs = |
9938 | 261 |
CS{safeIs = [], |
262 |
safeEs = [], |
|
263 |
hazIs = [], |
|
264 |
hazEs = [], |
|
265 |
xtraIs = [], |
|
266 |
xtraEs = [], |
|
4651 | 267 |
swrappers = [], |
268 |
uwrappers = [], |
|
6502 | 269 |
safe0_netpair = empty_netpair, |
270 |
safep_netpair = empty_netpair, |
|
271 |
haz_netpair = empty_netpair, |
|
6955 | 272 |
dup_netpair = empty_netpair, |
273 |
xtra_netpair = empty_netpair}; |
|
0 | 274 |
|
6955 | 275 |
fun print_cs (CS {safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, ...}) = |
3546 | 276 |
let val pretty_thms = map Display.pretty_thm in |
9760 | 277 |
[Pretty.big_list "safe introduction rules (intro!):" (pretty_thms safeIs), |
278 |
Pretty.big_list "introduction rules (intro):" (pretty_thms hazIs), |
|
279 |
Pretty.big_list "extra introduction rules (intro?):" (pretty_thms xtraIs), |
|
280 |
Pretty.big_list "safe elimination rules (elim!):" (pretty_thms safeEs), |
|
281 |
Pretty.big_list "elimination rules (elim):" (pretty_thms hazEs), |
|
282 |
Pretty.big_list "extra elimination rules (elim?):" (pretty_thms xtraEs)] |
|
8727 | 283 |
|> Pretty.chunks |> Pretty.writeln |
3546 | 284 |
end; |
0 | 285 |
|
4653 | 286 |
fun rep_cs (CS args) = args; |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
287 |
|
10736 | 288 |
local |
4651 | 289 |
fun calc_wrap l tac = foldr (fn ((name,tacf),w) => tacf w) (l, tac); |
10736 | 290 |
in |
4651 | 291 |
fun appSWrappers (CS{swrappers,...}) = calc_wrap swrappers; |
292 |
fun appWrappers (CS{uwrappers,...}) = calc_wrap uwrappers; |
|
293 |
end; |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
294 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
295 |
|
1800 | 296 |
(*** Adding (un)safe introduction or elimination rules. |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
297 |
|
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
298 |
In case of overlap, new rules are tried BEFORE old ones!! |
1800 | 299 |
***) |
0 | 300 |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
301 |
(*For use with biresolve_tac. Combines intr rules with swap to handle negated |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
302 |
assumptions. Pairs elim rules with true. *) |
10736 | 303 |
fun joinrules (intrs,elims) = |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
304 |
(map (pair true) (elims @ swapify intrs) @ |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
305 |
map (pair false) intrs); |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
306 |
|
10736 | 307 |
(*Priority: prefer rules with fewest subgoals, |
1231 | 308 |
then rules added most recently (preferring the head of the list).*) |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
309 |
fun tag_brls k [] = [] |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
310 |
| tag_brls k (brl::brls) = |
10736 | 311 |
(1000000*subgoals_of_brl brl + k, brl) :: |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
312 |
tag_brls (k+1) brls; |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
313 |
|
10736 | 314 |
fun recover_order k = k mod 1000000; |
315 |
||
1800 | 316 |
fun insert_tagged_list kbrls netpr = foldr insert_tagged_brl (kbrls, netpr); |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
317 |
|
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
318 |
(*Insert into netpair that already has nI intr rules and nE elim rules. |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
319 |
Count the intr rules double (to account for swapify). Negate to give the |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
320 |
new insertions the lowest priority.*) |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
321 |
fun insert (nI,nE) = insert_tagged_list o (tag_brls (~(2*nI+nE))) o joinrules; |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
322 |
|
1800 | 323 |
fun delete_tagged_list brls netpr = foldr delete_tagged_brl (brls, netpr); |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
324 |
|
1800 | 325 |
val delete = delete_tagged_list o joinrules; |
326 |
||
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
327 |
val mem_thm = gen_mem eq_thm |
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
328 |
and rem_thm = gen_rem eq_thm; |
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
329 |
|
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
330 |
(*Warn if the rule is already present ELSEWHERE in the claset. The addition |
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
331 |
is still allowed.*) |
10736 | 332 |
fun warn_dup th (CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, ...}) = |
333 |
if mem_thm (th, safeIs) then |
|
9938 | 334 |
warning ("Rule already declared as safe introduction (intro!)\n" ^ string_of_thm th) |
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
335 |
else if mem_thm (th, safeEs) then |
9408 | 336 |
warning ("Rule already declared as safe elimination (elim!)\n" ^ string_of_thm th) |
10736 | 337 |
else if mem_thm (th, hazIs) then |
9760 | 338 |
warning ("Rule already declared as introduction (intro)\n" ^ string_of_thm th) |
10736 | 339 |
else if mem_thm (th, hazEs) then |
9760 | 340 |
warning ("Rule already declared as elimination (elim)\n" ^ string_of_thm th) |
10736 | 341 |
else if mem_thm (th, xtraIs) then |
9408 | 342 |
warning ("Rule already declared as extra introduction (intro?)\n" ^ string_of_thm th) |
10736 | 343 |
else if mem_thm (th, xtraEs) then |
9408 | 344 |
warning ("Rule already declared as extra elimination (elim?)\n" ^ string_of_thm th) |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
345 |
else (); |
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
346 |
|
1800 | 347 |
(*** Safe rules ***) |
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
348 |
|
10736 | 349 |
fun addSI (cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
9938 | 350 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}, |
351 |
th) = |
|
10736 | 352 |
if mem_thm (th, safeIs) then |
9938 | 353 |
(warning ("Ignoring duplicate safe introduction (intro!)\n" ^ string_of_thm th); |
354 |
cs) |
|
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
355 |
else |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
356 |
let val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*) |
7559 | 357 |
partition Thm.no_prems [th] |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
358 |
val nI = length safeIs + 1 |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
359 |
and nE = length safeEs |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
360 |
in warn_dup th cs; |
9938 | 361 |
CS{safeIs = th::safeIs, |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
362 |
safe0_netpair = insert (nI,nE) (safe0_rls, []) safe0_netpair, |
9938 | 363 |
safep_netpair = insert (nI,nE) (safep_rls, []) safep_netpair, |
364 |
safeEs = safeEs, |
|
365 |
hazIs = hazIs, |
|
366 |
hazEs = hazEs, |
|
367 |
xtraIs = xtraIs, |
|
368 |
xtraEs = xtraEs, |
|
369 |
swrappers = swrappers, |
|
370 |
uwrappers = uwrappers, |
|
371 |
haz_netpair = haz_netpair, |
|
372 |
dup_netpair = dup_netpair, |
|
373 |
xtra_netpair = xtra_netpair} |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
374 |
end; |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
375 |
|
10736 | 376 |
fun addSE (cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
9938 | 377 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}, |
378 |
th) = |
|
10736 | 379 |
if mem_thm (th, safeEs) then |
9938 | 380 |
(warning ("Ignoring duplicate safe elimination (elim!)\n" ^ string_of_thm th); |
381 |
cs) |
|
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
382 |
else |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
383 |
let val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*) |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
384 |
partition (fn rl => nprems_of rl=1) [th] |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
385 |
val nI = length safeIs |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
386 |
and nE = length safeEs + 1 |
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
387 |
in warn_dup th cs; |
9938 | 388 |
CS{safeEs = th::safeEs, |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
389 |
safe0_netpair = insert (nI,nE) ([], safe0_rls) safe0_netpair, |
9938 | 390 |
safep_netpair = insert (nI,nE) ([], safep_rls) safep_netpair, |
391 |
safeIs = safeIs, |
|
392 |
hazIs = hazIs, |
|
393 |
hazEs = hazEs, |
|
394 |
xtraIs = xtraIs, |
|
395 |
xtraEs = xtraEs, |
|
396 |
swrappers = swrappers, |
|
397 |
uwrappers = uwrappers, |
|
398 |
haz_netpair = haz_netpair, |
|
399 |
dup_netpair = dup_netpair, |
|
400 |
xtra_netpair = xtra_netpair} |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
401 |
end; |
0 | 402 |
|
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
403 |
fun rev_foldl f (e, l) = foldl f (e, rev l); |
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
404 |
|
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
405 |
val op addSIs = rev_foldl addSI; |
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
406 |
val op addSEs = rev_foldl addSE; |
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
407 |
|
9938 | 408 |
fun cs addSDs ths = cs addSEs (map Data.make_elim ths); |
0 | 409 |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
410 |
|
1800 | 411 |
(*** Hazardous (unsafe) rules ***) |
0 | 412 |
|
10736 | 413 |
fun addI (cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
9938 | 414 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}, |
415 |
th)= |
|
10736 | 416 |
if mem_thm (th, hazIs) then |
9938 | 417 |
(warning ("Ignoring duplicate introduction (intro)\n" ^ string_of_thm th); |
418 |
cs) |
|
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
419 |
else |
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
420 |
let val nI = length hazIs + 1 |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
421 |
and nE = length hazEs |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
422 |
in warn_dup th cs; |
9938 | 423 |
CS{hazIs = th::hazIs, |
424 |
haz_netpair = insert (nI,nE) ([th], []) haz_netpair, |
|
425 |
dup_netpair = insert (nI,nE) (map dup_intr [th], []) dup_netpair, |
|
10736 | 426 |
safeIs = safeIs, |
9938 | 427 |
safeEs = safeEs, |
428 |
hazEs = hazEs, |
|
429 |
xtraIs = xtraIs, |
|
430 |
xtraEs = xtraEs, |
|
431 |
swrappers = swrappers, |
|
432 |
uwrappers = uwrappers, |
|
433 |
safe0_netpair = safe0_netpair, |
|
434 |
safep_netpair = safep_netpair, |
|
435 |
xtra_netpair = xtra_netpair} |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
436 |
end; |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
437 |
|
10736 | 438 |
fun addE (cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
9938 | 439 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}, |
440 |
th) = |
|
10736 | 441 |
if mem_thm (th, hazEs) then |
9938 | 442 |
(warning ("Ignoring duplicate elimination (elim)\n" ^ string_of_thm th); |
443 |
cs) |
|
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
444 |
else |
10736 | 445 |
let val nI = length hazIs |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
446 |
and nE = length hazEs + 1 |
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
447 |
in warn_dup th cs; |
9938 | 448 |
CS{hazEs = th::hazEs, |
449 |
haz_netpair = insert (nI,nE) ([], [th]) haz_netpair, |
|
450 |
dup_netpair = insert (nI,nE) ([], map dup_elim [th]) dup_netpair, |
|
10736 | 451 |
safeIs = safeIs, |
9938 | 452 |
safeEs = safeEs, |
453 |
hazIs = hazIs, |
|
454 |
xtraIs = xtraIs, |
|
455 |
xtraEs = xtraEs, |
|
456 |
swrappers = swrappers, |
|
457 |
uwrappers = uwrappers, |
|
458 |
safe0_netpair = safe0_netpair, |
|
459 |
safep_netpair = safep_netpair, |
|
460 |
xtra_netpair = xtra_netpair} |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
461 |
end; |
0 | 462 |
|
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
463 |
val op addIs = rev_foldl addI; |
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
464 |
val op addEs = rev_foldl addE; |
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
465 |
|
9938 | 466 |
fun cs addDs ths = cs addEs (map Data.make_elim ths); |
0 | 467 |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
468 |
|
6955 | 469 |
(*** Extra (single step) rules ***) |
470 |
||
471 |
fun addXI (cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
|
9938 | 472 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}, |
473 |
th)= |
|
10736 | 474 |
if mem_thm (th, xtraIs) then |
9938 | 475 |
(warning ("Ignoring duplicate extra introduction (intro?)\n" ^ string_of_thm th); |
476 |
cs) |
|
6955 | 477 |
else |
478 |
let val nI = length xtraIs + 1 |
|
479 |
and nE = length xtraEs |
|
480 |
in warn_dup th cs; |
|
9938 | 481 |
CS{xtraIs = th::xtraIs, |
482 |
xtra_netpair = insert (nI,nE) ([th], []) xtra_netpair, |
|
10736 | 483 |
safeIs = safeIs, |
9938 | 484 |
safeEs = safeEs, |
485 |
hazIs = hazIs, |
|
486 |
hazEs = hazEs, |
|
487 |
xtraEs = xtraEs, |
|
488 |
swrappers = swrappers, |
|
489 |
uwrappers = uwrappers, |
|
490 |
safe0_netpair = safe0_netpair, |
|
491 |
safep_netpair = safep_netpair, |
|
492 |
haz_netpair = haz_netpair, |
|
493 |
dup_netpair = dup_netpair} |
|
6955 | 494 |
end; |
495 |
||
10736 | 496 |
fun addXE (cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
9938 | 497 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}, |
498 |
th) = |
|
6955 | 499 |
if mem_thm (th, xtraEs) then |
9938 | 500 |
(warning ("Ignoring duplicate extra elimination (elim?)\n" ^ string_of_thm th); |
501 |
cs) |
|
6955 | 502 |
else |
10736 | 503 |
let val nI = length xtraIs |
6955 | 504 |
and nE = length xtraEs + 1 |
505 |
in warn_dup th cs; |
|
9938 | 506 |
CS{xtraEs = th::xtraEs, |
507 |
xtra_netpair = insert (nI,nE) ([], [th]) xtra_netpair, |
|
10736 | 508 |
safeIs = safeIs, |
9938 | 509 |
safeEs = safeEs, |
510 |
hazIs = hazIs, |
|
511 |
hazEs = hazEs, |
|
512 |
xtraIs = xtraIs, |
|
513 |
swrappers = swrappers, |
|
514 |
uwrappers = uwrappers, |
|
515 |
safe0_netpair = safe0_netpair, |
|
516 |
safep_netpair = safep_netpair, |
|
517 |
haz_netpair = haz_netpair, |
|
518 |
dup_netpair = dup_netpair} |
|
6955 | 519 |
end; |
520 |
||
521 |
val op addXIs = rev_foldl addXI; |
|
522 |
val op addXEs = rev_foldl addXE; |
|
523 |
||
9938 | 524 |
fun cs addXDs ths = cs addXEs (map Data.make_elim ths); |
6955 | 525 |
|
526 |
||
10736 | 527 |
(*** Deletion of rules |
1800 | 528 |
Working out what to delete, requires repeating much of the code used |
9938 | 529 |
to insert. |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
530 |
Separate functions delSI, etc., are not exported; instead delrules |
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
531 |
searches in all the lists and chooses the relevant delXX functions. |
1800 | 532 |
***) |
533 |
||
10736 | 534 |
fun delSI th |
6955 | 535 |
(cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
9938 | 536 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) = |
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
537 |
if mem_thm (th, safeIs) then |
7559 | 538 |
let val (safe0_rls, safep_rls) = partition Thm.no_prems [th] |
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
539 |
in CS{safe0_netpair = delete (safe0_rls, []) safe0_netpair, |
9938 | 540 |
safep_netpair = delete (safep_rls, []) safep_netpair, |
541 |
safeIs = rem_thm (safeIs,th), |
|
542 |
safeEs = safeEs, |
|
543 |
hazIs = hazIs, |
|
544 |
hazEs = hazEs, |
|
545 |
xtraIs = xtraIs, |
|
546 |
xtraEs = xtraEs, |
|
547 |
swrappers = swrappers, |
|
548 |
uwrappers = uwrappers, |
|
549 |
haz_netpair = haz_netpair, |
|
550 |
dup_netpair = dup_netpair, |
|
551 |
xtra_netpair = xtra_netpair} |
|
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
552 |
end |
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
553 |
else cs; |
1800 | 554 |
|
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
555 |
fun delSE th |
10736 | 556 |
(cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
9938 | 557 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) = |
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
558 |
if mem_thm (th, safeEs) then |
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
559 |
let val (safe0_rls, safep_rls) = partition (fn rl => nprems_of rl=1) [th] |
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
560 |
in CS{safe0_netpair = delete ([], safe0_rls) safe0_netpair, |
9938 | 561 |
safep_netpair = delete ([], safep_rls) safep_netpair, |
562 |
safeIs = safeIs, |
|
563 |
safeEs = rem_thm (safeEs,th), |
|
564 |
hazIs = hazIs, |
|
565 |
hazEs = hazEs, |
|
566 |
xtraIs = xtraIs, |
|
567 |
xtraEs = xtraEs, |
|
568 |
swrappers = swrappers, |
|
569 |
uwrappers = uwrappers, |
|
570 |
haz_netpair = haz_netpair, |
|
571 |
dup_netpair = dup_netpair, |
|
572 |
xtra_netpair = xtra_netpair} |
|
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
573 |
end |
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
574 |
else cs; |
1800 | 575 |
|
576 |
||
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
577 |
fun delI th |
10736 | 578 |
(cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
9938 | 579 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) = |
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
580 |
if mem_thm (th, hazIs) then |
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
581 |
CS{haz_netpair = delete ([th], []) haz_netpair, |
9938 | 582 |
dup_netpair = delete ([dup_intr th], []) dup_netpair, |
10736 | 583 |
safeIs = safeIs, |
9938 | 584 |
safeEs = safeEs, |
585 |
hazIs = rem_thm (hazIs,th), |
|
586 |
hazEs = hazEs, |
|
587 |
xtraIs = xtraIs, |
|
588 |
xtraEs = xtraEs, |
|
589 |
swrappers = swrappers, |
|
590 |
uwrappers = uwrappers, |
|
591 |
safe0_netpair = safe0_netpair, |
|
592 |
safep_netpair = safep_netpair, |
|
593 |
xtra_netpair = xtra_netpair} |
|
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
594 |
else cs; |
1800 | 595 |
|
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
596 |
fun delE th |
10736 | 597 |
(cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
9938 | 598 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) = |
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
599 |
if mem_thm (th, hazEs) then |
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
600 |
CS{haz_netpair = delete ([], [th]) haz_netpair, |
9938 | 601 |
dup_netpair = delete ([], [dup_elim th]) dup_netpair, |
10736 | 602 |
safeIs = safeIs, |
9938 | 603 |
safeEs = safeEs, |
604 |
hazIs = hazIs, |
|
605 |
hazEs = rem_thm (hazEs,th), |
|
606 |
xtraIs = xtraIs, |
|
607 |
xtraEs = xtraEs, |
|
608 |
swrappers = swrappers, |
|
609 |
uwrappers = uwrappers, |
|
610 |
safe0_netpair = safe0_netpair, |
|
611 |
safep_netpair = safep_netpair, |
|
612 |
xtra_netpair = xtra_netpair} |
|
6955 | 613 |
else cs; |
614 |
||
615 |
||
616 |
fun delXI th |
|
10736 | 617 |
(cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
9938 | 618 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) = |
6955 | 619 |
if mem_thm (th, xtraIs) then |
620 |
CS{xtra_netpair = delete ([th], []) xtra_netpair, |
|
10736 | 621 |
safeIs = safeIs, |
9938 | 622 |
safeEs = safeEs, |
623 |
hazIs = hazIs, |
|
624 |
hazEs = hazEs, |
|
625 |
xtraIs = rem_thm (xtraIs,th), |
|
626 |
xtraEs = xtraEs, |
|
627 |
swrappers = swrappers, |
|
628 |
uwrappers = uwrappers, |
|
629 |
safe0_netpair = safe0_netpair, |
|
630 |
safep_netpair = safep_netpair, |
|
631 |
haz_netpair = haz_netpair, |
|
632 |
dup_netpair = dup_netpair} |
|
6955 | 633 |
else cs; |
634 |
||
635 |
fun delXE th |
|
10736 | 636 |
(cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
9938 | 637 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) = |
6955 | 638 |
if mem_thm (th, xtraEs) then |
639 |
CS{xtra_netpair = delete ([], [th]) xtra_netpair, |
|
10736 | 640 |
safeIs = safeIs, |
9938 | 641 |
safeEs = safeEs, |
642 |
hazIs = hazIs, |
|
643 |
hazEs = hazEs, |
|
644 |
xtraIs = xtraIs, |
|
645 |
xtraEs = rem_thm (xtraEs,th), |
|
646 |
swrappers = swrappers, |
|
647 |
uwrappers = uwrappers, |
|
648 |
safe0_netpair = safe0_netpair, |
|
649 |
safep_netpair = safep_netpair, |
|
650 |
haz_netpair = haz_netpair, |
|
651 |
dup_netpair = dup_netpair} |
|
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
652 |
else cs; |
1800 | 653 |
|
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
654 |
(*Delete ALL occurrences of "th" in the claset (perhaps from several lists)*) |
6955 | 655 |
fun delrule (cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, ...}, th) = |
9938 | 656 |
let val th' = Data.make_elim th in |
657 |
if mem_thm (th, safeIs) orelse mem_thm (th, safeEs) orelse |
|
658 |
mem_thm (th, hazIs) orelse mem_thm (th, hazEs) orelse |
|
659 |
mem_thm (th, xtraIs) orelse mem_thm (th, xtraEs) orelse |
|
660 |
mem_thm (th', safeEs) orelse mem_thm (th', hazEs) orelse mem_thm (th', xtraEs) |
|
661 |
then delSI th (delSE th (delI th (delE th (delXI th (delXE th |
|
662 |
(delSE th' (delE th' (delXE th' cs)))))))) |
|
663 |
else (warning ("Undeclared classical rule\n" ^ (string_of_thm th)); cs) |
|
664 |
end; |
|
1800 | 665 |
|
666 |
val op delrules = foldl delrule; |
|
667 |
||
668 |
||
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
669 |
(*** Modifying the wrapper tacticals ***) |
10736 | 670 |
fun update_swrappers |
671 |
(CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
|
6955 | 672 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) f = |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
673 |
CS{safeIs = safeIs, safeEs = safeEs, hazIs = hazIs, hazEs = hazEs, |
6955 | 674 |
xtraIs = xtraIs, xtraEs = xtraEs, |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
675 |
swrappers = f swrappers, uwrappers = uwrappers, |
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
676 |
safe0_netpair = safe0_netpair, safep_netpair = safep_netpair, |
6955 | 677 |
haz_netpair = haz_netpair, dup_netpair = dup_netpair, xtra_netpair = xtra_netpair}; |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
678 |
|
10736 | 679 |
fun update_uwrappers |
680 |
(CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, swrappers, uwrappers, |
|
6955 | 681 |
safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) f = |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
682 |
CS{safeIs = safeIs, safeEs = safeEs, hazIs = hazIs, hazEs = hazEs, |
6955 | 683 |
xtraIs = xtraIs, xtraEs = xtraEs, |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
684 |
swrappers = swrappers, uwrappers = f uwrappers, |
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
685 |
safe0_netpair = safe0_netpair, safep_netpair = safep_netpair, |
6955 | 686 |
haz_netpair = haz_netpair, dup_netpair = dup_netpair, xtra_netpair = xtra_netpair}; |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
687 |
|
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
688 |
|
4651 | 689 |
(*Add/replace a safe wrapper*) |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
690 |
fun cs addSWrapper new_swrapper = update_swrappers cs (fn swrappers => |
9721 | 691 |
overwrite_warn (swrappers, new_swrapper) |
692 |
("Overwriting safe wrapper " ^ fst new_swrapper)); |
|
4651 | 693 |
|
694 |
(*Add/replace an unsafe wrapper*) |
|
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
695 |
fun cs addWrapper new_uwrapper = update_uwrappers cs (fn uwrappers => |
9721 | 696 |
overwrite_warn (uwrappers, new_uwrapper) |
9938 | 697 |
("Overwriting unsafe wrapper "^fst new_uwrapper)); |
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
698 |
|
4651 | 699 |
(*Remove a safe wrapper*) |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
700 |
fun cs delSWrapper name = update_swrappers cs (fn swrappers => |
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
701 |
let val (del,rest) = partition (fn (n,_) => n=name) swrappers |
10736 | 702 |
in if null del then (warning ("No such safe wrapper in claset: "^ name); |
9938 | 703 |
swrappers) else rest end); |
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
704 |
|
4651 | 705 |
(*Remove an unsafe wrapper*) |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
706 |
fun cs delWrapper name = update_uwrappers cs (fn uwrappers => |
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
707 |
let val (del,rest) = partition (fn (n,_) => n=name) uwrappers |
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
708 |
in if null del then (warning ("No such unsafe wrapper in claset: " ^ name); |
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
709 |
uwrappers) else rest end); |
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
710 |
|
11168 | 711 |
(* compose a safe tactic alternatively before/after safe_step_tac *) |
10736 | 712 |
fun cs addSbefore (name, tac1) = |
5523 | 713 |
cs addSWrapper (name, fn tac2 => tac1 ORELSE' tac2); |
11181
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
714 |
fun cs addSafter (name, tac2) = |
5523 | 715 |
cs addSWrapper (name, fn tac1 => tac1 ORELSE' tac2); |
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
716 |
|
11168 | 717 |
(*compose a tactic alternatively before/after the step tactic *) |
10736 | 718 |
fun cs addbefore (name, tac1) = |
5523 | 719 |
cs addWrapper (name, fn tac2 => tac1 APPEND' tac2); |
11181
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
720 |
fun cs addafter (name, tac2) = |
5523 | 721 |
cs addWrapper (name, fn tac1 => tac1 APPEND' tac2); |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
722 |
|
10736 | 723 |
fun cs addD2 (name, thm) = |
11181
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
724 |
cs addafter (name, datac thm 1); |
10736 | 725 |
fun cs addE2 (name, thm) = |
11181
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
726 |
cs addafter (name, eatac thm 1); |
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
727 |
fun cs addSD2 (name, thm) = |
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
728 |
cs addSafter (name, dmatch_tac [thm] THEN' eq_assume_tac); |
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
729 |
fun cs addSE2 (name, thm) = |
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
730 |
cs addSafter (name, ematch_tac [thm] THEN' eq_assume_tac); |
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
731 |
|
1711 | 732 |
(*Merge works by adding all new rules of the 2nd claset into the 1st claset. |
733 |
Merging the term nets may look more efficient, but the rather delicate |
|
734 |
treatment of priority might get muddled up.*) |
|
735 |
fun merge_cs |
|
6955 | 736 |
(cs as CS{safeIs, safeEs, hazIs, hazEs, xtraIs, xtraEs, ...}, |
4765 | 737 |
CS{safeIs=safeIs2, safeEs=safeEs2, hazIs=hazIs2, hazEs=hazEs2, |
9938 | 738 |
xtraIs=xtraIs2, xtraEs=xtraEs2, swrappers, uwrappers, ...}) = |
1711 | 739 |
let val safeIs' = gen_rems eq_thm (safeIs2,safeIs) |
740 |
val safeEs' = gen_rems eq_thm (safeEs2,safeEs) |
|
2630 | 741 |
val hazIs' = gen_rems eq_thm ( hazIs2, hazIs) |
742 |
val hazEs' = gen_rems eq_thm ( hazEs2, hazEs) |
|
6955 | 743 |
val xtraIs' = gen_rems eq_thm (xtraIs2, xtraIs) |
744 |
val xtraEs' = gen_rems eq_thm (xtraEs2, xtraEs) |
|
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
745 |
val cs1 = cs addSIs safeIs' |
9938 | 746 |
addSEs safeEs' |
747 |
addIs hazIs' |
|
748 |
addEs hazEs' |
|
749 |
addXIs xtraIs' |
|
750 |
addXEs xtraEs' |
|
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
751 |
val cs2 = update_swrappers cs1 (fn ws => merge_alists ws swrappers); |
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
752 |
val cs3 = update_uwrappers cs2 (fn ws => merge_alists ws uwrappers); |
10736 | 753 |
in cs3 |
1711 | 754 |
end; |
755 |
||
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
756 |
|
1800 | 757 |
(**** Simple tactics for theorem proving ****) |
0 | 758 |
|
759 |
(*Attack subgoals using safe inferences -- matching, not resolution*) |
|
10736 | 760 |
fun safe_step_tac (cs as CS{safe0_netpair,safep_netpair,...}) = |
4651 | 761 |
appSWrappers cs (FIRST' [ |
9938 | 762 |
eq_assume_tac, |
763 |
eq_mp_tac, |
|
764 |
bimatch_from_nets_tac safe0_netpair, |
|
765 |
FIRST' hyp_subst_tacs, |
|
766 |
bimatch_from_nets_tac safep_netpair]); |
|
0 | 767 |
|
5757 | 768 |
(*Repeatedly attack a subgoal using safe inferences -- it's deterministic!*) |
10736 | 769 |
fun safe_steps_tac cs = REPEAT_DETERM1 o |
9938 | 770 |
(fn i => COND (has_fewer_prems i) no_tac (safe_step_tac cs i)); |
5757 | 771 |
|
0 | 772 |
(*Repeatedly attack subgoals using safe inferences -- it's deterministic!*) |
5757 | 773 |
fun safe_tac cs = REPEAT_DETERM1 (FIRSTGOAL (safe_steps_tac cs)); |
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
774 |
|
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
775 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
776 |
(*** Clarify_tac: do safe steps without causing branching ***) |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
777 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
778 |
fun nsubgoalsP n (k,brl) = (subgoals_of_brl brl = n); |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
779 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
780 |
(*version of bimatch_from_nets_tac that only applies rules that |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
781 |
create precisely n subgoals.*) |
10736 | 782 |
fun n_bimatch_from_nets_tac n = |
11783 | 783 |
biresolution_from_nets_tac (Tactic.orderlist o filter (nsubgoalsP n)) true; |
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
784 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
785 |
fun eq_contr_tac i = ematch_tac [not_elim] i THEN eq_assume_tac i; |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
786 |
val eq_assume_contr_tac = eq_assume_tac ORELSE' eq_contr_tac; |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
787 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
788 |
(*Two-way branching is allowed only if one of the branches immediately closes*) |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
789 |
fun bimatch2_tac netpair i = |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
790 |
n_bimatch_from_nets_tac 2 netpair i THEN |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
791 |
(eq_assume_contr_tac i ORELSE eq_assume_contr_tac (i+1)); |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
792 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
793 |
(*Attack subgoals using safe inferences -- matching, not resolution*) |
10736 | 794 |
fun clarify_step_tac (cs as CS{safe0_netpair,safep_netpair,...}) = |
4651 | 795 |
appSWrappers cs (FIRST' [ |
9938 | 796 |
eq_assume_contr_tac, |
797 |
bimatch_from_nets_tac safe0_netpair, |
|
798 |
FIRST' hyp_subst_tacs, |
|
799 |
n_bimatch_from_nets_tac 1 safep_netpair, |
|
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
800 |
bimatch2_tac safep_netpair]); |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
801 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
802 |
fun clarify_tac cs = SELECT_GOAL (REPEAT_DETERM (clarify_step_tac cs 1)); |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
803 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
804 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
805 |
(*** Unsafe steps instantiate variables or lose information ***) |
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
806 |
|
4066 | 807 |
(*Backtracking is allowed among the various these unsafe ways of |
808 |
proving a subgoal. *) |
|
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
809 |
fun inst0_step_tac (CS{safe0_netpair,safep_netpair,...}) = |
10736 | 810 |
assume_tac APPEND' |
811 |
contr_tac APPEND' |
|
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
812 |
biresolve_from_nets_tac safe0_netpair; |
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
813 |
|
4066 | 814 |
(*These unsafe steps could generate more subgoals.*) |
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
815 |
fun instp_step_tac (CS{safep_netpair,...}) = |
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
816 |
biresolve_from_nets_tac safep_netpair; |
0 | 817 |
|
818 |
(*These steps could instantiate variables and are therefore unsafe.*) |
|
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
819 |
fun inst_step_tac cs = inst0_step_tac cs APPEND' instp_step_tac cs; |
0 | 820 |
|
10736 | 821 |
fun haz_step_tac (CS{haz_netpair,...}) = |
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
822 |
biresolve_from_nets_tac haz_netpair; |
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
823 |
|
0 | 824 |
(*Single step for the prover. FAILS unless it makes progress. *) |
10736 | 825 |
fun step_tac cs i = safe_tac cs ORELSE appWrappers cs |
9938 | 826 |
(inst_step_tac cs ORELSE' haz_step_tac cs) i; |
0 | 827 |
|
828 |
(*Using a "safe" rule to instantiate variables is unsafe. This tactic |
|
829 |
allows backtracking from "safe" rules to "unsafe" rules here.*) |
|
10736 | 830 |
fun slow_step_tac cs i = safe_tac cs ORELSE appWrappers cs |
9938 | 831 |
(inst_step_tac cs APPEND' haz_step_tac cs) i; |
0 | 832 |
|
1800 | 833 |
(**** The following tactics all fail unless they solve one goal ****) |
0 | 834 |
|
835 |
(*Dumb but fast*) |
|
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
836 |
fun fast_tac cs = |
11754 | 837 |
ObjectLogic.atomize_tac THEN' SELECT_GOAL (DEPTH_SOLVE (step_tac cs 1)); |
0 | 838 |
|
839 |
(*Slower but smarter than fast_tac*) |
|
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
840 |
fun best_tac cs = |
11754 | 841 |
ObjectLogic.atomize_tac THEN' |
0 | 842 |
SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, sizef) (step_tac cs 1)); |
843 |
||
9402 | 844 |
(*even a bit smarter than best_tac*) |
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
845 |
fun first_best_tac cs = |
11754 | 846 |
ObjectLogic.atomize_tac THEN' |
9402 | 847 |
SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, sizef) (FIRSTGOAL (step_tac cs))); |
848 |
||
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
849 |
fun slow_tac cs = |
11754 | 850 |
ObjectLogic.atomize_tac THEN' |
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
851 |
SELECT_GOAL (DEPTH_SOLVE (slow_step_tac cs 1)); |
0 | 852 |
|
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
853 |
fun slow_best_tac cs = |
11754 | 854 |
ObjectLogic.atomize_tac THEN' |
0 | 855 |
SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, sizef) (slow_step_tac cs 1)); |
856 |
||
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
857 |
|
10736 | 858 |
(***ASTAR with weight weight_ASTAR, by Norbert Voelker*) |
859 |
val weight_ASTAR = ref 5; |
|
1587
e7d8a4957bac
Now provides astar versions (thanks to Norbert Voelker)
paulson
parents:
1524
diff
changeset
|
860 |
|
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
861 |
fun astar_tac cs = |
11754 | 862 |
ObjectLogic.atomize_tac THEN' |
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
863 |
SELECT_GOAL |
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
864 |
(ASTAR (has_fewer_prems 1, fn lev => fn thm => size_of_thm thm + !weight_ASTAR * lev) |
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
865 |
(step_tac cs 1)); |
1587
e7d8a4957bac
Now provides astar versions (thanks to Norbert Voelker)
paulson
parents:
1524
diff
changeset
|
866 |
|
10736 | 867 |
fun slow_astar_tac cs = |
11754 | 868 |
ObjectLogic.atomize_tac THEN' |
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
869 |
SELECT_GOAL |
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
870 |
(ASTAR (has_fewer_prems 1, fn lev => fn thm => size_of_thm thm + !weight_ASTAR * lev) |
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
871 |
(slow_step_tac cs 1)); |
1587
e7d8a4957bac
Now provides astar versions (thanks to Norbert Voelker)
paulson
parents:
1524
diff
changeset
|
872 |
|
1800 | 873 |
(**** Complete tactic, loosely based upon LeanTaP. This tactic is the outcome |
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
874 |
of much experimentation! Changing APPEND to ORELSE below would prove |
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
875 |
easy theorems faster, but loses completeness -- and many of the harder |
1800 | 876 |
theorems such as 43. ****) |
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
877 |
|
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
878 |
(*Non-deterministic! Could always expand the first unsafe connective. |
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
879 |
That's hard to implement and did not perform better in experiments, due to |
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
880 |
greater search depth required.*) |
10736 | 881 |
fun dup_step_tac (cs as (CS{dup_netpair,...})) = |
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
882 |
biresolve_from_nets_tac dup_netpair; |
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
883 |
|
5523 | 884 |
(*Searching to depth m. A variant called nodup_depth_tac appears in clasimp.ML*) |
5757 | 885 |
local |
10736 | 886 |
fun slow_step_tac' cs = appWrappers cs |
9938 | 887 |
(instp_step_tac cs APPEND' dup_step_tac cs); |
10736 | 888 |
in fun depth_tac cs m i state = SELECT_GOAL |
889 |
(safe_steps_tac cs 1 THEN_ELSE |
|
9938 | 890 |
(DEPTH_SOLVE (depth_tac cs m 1), |
891 |
inst0_step_tac cs 1 APPEND COND (K (m=0)) no_tac |
|
892 |
(slow_step_tac' cs 1 THEN DEPTH_SOLVE (depth_tac cs (m-1) 1)) |
|
5757 | 893 |
)) i state; |
894 |
end; |
|
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
895 |
|
10736 | 896 |
(*Search, with depth bound m. |
2173 | 897 |
This is the "entry point", which does safe inferences first.*) |
10736 | 898 |
fun safe_depth_tac cs m = |
899 |
SUBGOAL |
|
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
900 |
(fn (prem,i) => |
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
901 |
let val deti = |
9938 | 902 |
(*No Vars in the goal? No need to backtrack between goals.*) |
903 |
case term_vars prem of |
|
10736 | 904 |
[] => DETERM |
9938 | 905 |
| _::_ => I |
10736 | 906 |
in SELECT_GOAL (TRY (safe_tac cs) THEN |
9938 | 907 |
DEPTH_SOLVE (deti (depth_tac cs m 1))) i |
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
908 |
end); |
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
909 |
|
2868
17a23a62f82a
New DEEPEN allows giving an upper bound for deepen_tac
paulson
parents:
2813
diff
changeset
|
910 |
fun deepen_tac cs = DEEPEN (2,10) (safe_depth_tac cs); |
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
911 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
912 |
|
1724 | 913 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
914 |
(** claset theory data **) |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
915 |
|
7354 | 916 |
(* theory data kind 'Provers/claset' *) |
1724 | 917 |
|
7354 | 918 |
structure GlobalClasetArgs = |
919 |
struct |
|
920 |
val name = "Provers/claset"; |
|
921 |
type T = claset ref; |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
922 |
|
7354 | 923 |
val empty = ref empty_cs; |
924 |
fun copy (ref cs) = (ref cs): T; (*create new reference!*) |
|
12109 | 925 |
val finish = I; |
6556 | 926 |
val prep_ext = copy; |
7354 | 927 |
fun merge (ref cs1, ref cs2) = ref (merge_cs (cs1, cs2)); |
928 |
fun print _ (ref cs) = print_cs cs; |
|
929 |
end; |
|
1724 | 930 |
|
7354 | 931 |
structure GlobalClaset = TheoryDataFun(GlobalClasetArgs); |
932 |
val print_claset = GlobalClaset.print; |
|
933 |
val claset_ref_of_sg = GlobalClaset.get_sg; |
|
934 |
val claset_ref_of = GlobalClaset.get; |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
935 |
|
1724 | 936 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
937 |
(* access claset *) |
1724 | 938 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
939 |
val claset_of_sg = ! o claset_ref_of_sg; |
6391 | 940 |
val claset_of = claset_of_sg o Theory.sign_of; |
1800 | 941 |
|
6391 | 942 |
fun CLASET tacf state = tacf (claset_of_sg (Thm.sign_of_thm state)) state; |
943 |
fun CLASET' tacf i state = tacf (claset_of_sg (Thm.sign_of_thm state)) i state; |
|
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
944 |
|
5028 | 945 |
val claset = claset_of o Context.the_context; |
6391 | 946 |
val claset_ref = claset_ref_of_sg o Theory.sign_of o Context.the_context; |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
947 |
|
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
948 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
949 |
(* change claset *) |
1800 | 950 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
951 |
fun change_claset f x = claset_ref () := (f (claset (), x)); |
1724 | 952 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
953 |
val AddDs = change_claset (op addDs); |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
954 |
val AddEs = change_claset (op addEs); |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
955 |
val AddIs = change_claset (op addIs); |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
956 |
val AddSDs = change_claset (op addSDs); |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
957 |
val AddSEs = change_claset (op addSEs); |
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
958 |
val AddSIs = change_claset (op addSIs); |
6955 | 959 |
val AddXDs = change_claset (op addXDs); |
960 |
val AddXEs = change_claset (op addXEs); |
|
961 |
val AddXIs = change_claset (op addXIs); |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
962 |
val Delrules = change_claset (op delrules); |
3727
ed63c05d7992
Added Safe_tac; all other default claset tactics now dereference "claset"
paulson
parents:
3705
diff
changeset
|
963 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
964 |
|
5841 | 965 |
(* proof data kind 'Provers/claset' *) |
966 |
||
967 |
structure LocalClasetArgs = |
|
968 |
struct |
|
969 |
val name = "Provers/claset"; |
|
970 |
type T = claset; |
|
971 |
val init = claset_of; |
|
972 |
fun print _ cs = print_cs cs; |
|
973 |
end; |
|
974 |
||
975 |
structure LocalClaset = ProofDataFun(LocalClasetArgs); |
|
976 |
val print_local_claset = LocalClaset.print; |
|
977 |
val get_local_claset = LocalClaset.get; |
|
978 |
val put_local_claset = LocalClaset.put; |
|
979 |
||
980 |
||
5885 | 981 |
(* attributes *) |
982 |
||
983 |
fun change_global_cs f (thy, th) = |
|
984 |
let val r = claset_ref_of thy |
|
6096 | 985 |
in r := f (! r, [th]); (thy, th) end; |
5885 | 986 |
|
987 |
fun change_local_cs f (ctxt, th) = |
|
6096 | 988 |
let val cs = f (get_local_claset ctxt, [th]) |
5885 | 989 |
in (put_local_claset cs ctxt, th) end; |
990 |
||
991 |
val safe_dest_global = change_global_cs (op addSDs); |
|
992 |
val safe_elim_global = change_global_cs (op addSEs); |
|
993 |
val safe_intro_global = change_global_cs (op addSIs); |
|
6955 | 994 |
val haz_dest_global = change_global_cs (op addDs); |
995 |
val haz_elim_global = change_global_cs (op addEs); |
|
996 |
val haz_intro_global = change_global_cs (op addIs); |
|
997 |
val xtra_dest_global = change_global_cs (op addXDs); |
|
998 |
val xtra_elim_global = change_global_cs (op addXEs); |
|
999 |
val xtra_intro_global = change_global_cs (op addXIs); |
|
9938 | 1000 |
val rule_del_global = change_global_cs (op delrules); |
5885 | 1001 |
|
6955 | 1002 |
val safe_dest_local = change_local_cs (op addSDs); |
1003 |
val safe_elim_local = change_local_cs (op addSEs); |
|
1004 |
val safe_intro_local = change_local_cs (op addSIs); |
|
5885 | 1005 |
val haz_dest_local = change_local_cs (op addDs); |
1006 |
val haz_elim_local = change_local_cs (op addEs); |
|
1007 |
val haz_intro_local = change_local_cs (op addIs); |
|
6955 | 1008 |
val xtra_dest_local = change_local_cs (op addXDs); |
1009 |
val xtra_elim_local = change_local_cs (op addXEs); |
|
1010 |
val xtra_intro_local = change_local_cs (op addXIs); |
|
9938 | 1011 |
val rule_del_local = change_local_cs (op delrules); |
5885 | 1012 |
|
1013 |
||
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
1014 |
(* tactics referring to the implicit claset *) |
1800 | 1015 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
1016 |
(*the abstraction over the proof state delays the dereferencing*) |
9938 | 1017 |
fun Safe_tac st = safe_tac (claset()) st; |
1018 |
fun Safe_step_tac i st = safe_step_tac (claset()) i st; |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
1019 |
fun Clarify_step_tac i st = clarify_step_tac (claset()) i st; |
9938 | 1020 |
fun Clarify_tac i st = clarify_tac (claset()) i st; |
1021 |
fun Step_tac i st = step_tac (claset()) i st; |
|
1022 |
fun Fast_tac i st = fast_tac (claset()) i st; |
|
1023 |
fun Best_tac i st = best_tac (claset()) i st; |
|
1024 |
fun Slow_tac i st = slow_tac (claset()) i st; |
|
1025 |
fun Slow_best_tac i st = slow_best_tac (claset()) i st; |
|
1026 |
fun Deepen_tac m = deepen_tac (claset()) m; |
|
2066 | 1027 |
|
1800 | 1028 |
|
10736 | 1029 |
end; |
5841 | 1030 |
|
1031 |
||
1032 |
||
5885 | 1033 |
(** concrete syntax of attributes **) |
5841 | 1034 |
|
1035 |
(* add / del rules *) |
|
1036 |
||
1037 |
val introN = "intro"; |
|
1038 |
val elimN = "elim"; |
|
1039 |
val destN = "dest"; |
|
9938 | 1040 |
val ruleN = "rule"; |
5841 | 1041 |
|
6955 | 1042 |
fun cla_att change xtra haz safe = Attrib.syntax |
10034 | 1043 |
(Scan.lift ((Args.query >> K xtra || Args.bang >> K safe || Scan.succeed haz) >> change)); |
5841 | 1044 |
|
6955 | 1045 |
fun cla_attr f g h = (cla_att change_global_cs f g h, cla_att change_local_cs f g h); |
9938 | 1046 |
|
10034 | 1047 |
fun del_args att = Attrib.syntax (Scan.lift Args.del >> K att); |
9938 | 1048 |
val rule_del_attr = (del_args rule_del_global, del_args rule_del_local); |
5841 | 1049 |
|
1050 |
||
1051 |
(* setup_attrs *) |
|
1052 |
||
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9938
diff
changeset
|
1053 |
fun elim_format x = Attrib.no_args (Drule.rule_attribute (K Data.make_elim)) x; |
9184 | 1054 |
|
5841 | 1055 |
val setup_attrs = Attrib.add_attributes |
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9938
diff
changeset
|
1056 |
[("elim_format", (elim_format, elim_format), |
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9938
diff
changeset
|
1057 |
"destruct rule turned into elimination rule format (classical)"), |
9899 | 1058 |
(destN, cla_attr (op addXDs) (op addDs) (op addSDs), "declaration of destruction rule"), |
1059 |
(elimN, cla_attr (op addXEs) (op addEs) (op addSEs), "declaration of elimination rule"), |
|
1060 |
(introN, cla_attr (op addXIs) (op addIs) (op addSIs), "declaration of introduction rule"), |
|
9938 | 1061 |
(ruleN, rule_del_attr, "remove declaration of intro/elim/dest rule")]; |
5841 | 1062 |
|
1063 |
||
1064 |
||
7230 | 1065 |
(** proof methods **) |
1066 |
||
1067 |
(* get nets (appropriate order for semi-automatic methods) *) |
|
1068 |
||
1069 |
local |
|
1070 |
val not_elim_netpair = insert (0, 0) ([], [Data.not_elim]) empty_netpair; |
|
1071 |
in |
|
1072 |
fun get_nets (CS {safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair, ...}) = |
|
11723 | 1073 |
[safe0_netpair, safep_netpair, not_elim_netpair, haz_netpair, dup_netpair, xtra_netpair]; |
7230 | 1074 |
end; |
1075 |
||
1076 |
||
1077 |
(* METHOD_CLASET' *) |
|
5841 | 1078 |
|
8098 | 1079 |
fun METHOD_CLASET' tac ctxt = |
10394 | 1080 |
Method.METHOD (HEADGOAL o tac ctxt (get_local_claset ctxt)); |
7230 | 1081 |
|
1082 |
||
1083 |
local |
|
1084 |
||
10736 | 1085 |
fun order_rules xs = map snd (Tactic.orderlist (map (apfst recover_order) xs)); |
5841 | 1086 |
|
1087 |
fun find_erules [] _ = [] |
|
6955 | 1088 |
| find_erules (fact :: _) nets = |
5841 | 1089 |
let |
6502 | 1090 |
fun may_unify net = Net.unify_term net o Logic.strip_assums_concl o #prop o Thm.rep_thm; |
6955 | 1091 |
fun erules_of (_, enet) = order_rules (may_unify enet fact); |
6502 | 1092 |
in flat (map erules_of nets) end; |
5841 | 1093 |
|
11723 | 1094 |
fun find_rules concl nets = |
1095 |
let fun rules_of (inet, _) = order_rules (Net.unify_term inet concl) |
|
1096 |
in flat (map rules_of nets) end; |
|
1097 |
||
12053 | 1098 |
fun some_rule_tac ctxt cs facts = |
5841 | 1099 |
let |
7230 | 1100 |
val nets = get_nets cs; |
6492 | 1101 |
val erules = find_erules facts nets; |
5841 | 1102 |
|
1103 |
val tac = SUBGOAL (fn (goal, i) => |
|
1104 |
let |
|
1105 |
val irules = find_rules (Logic.strip_assums_concl goal) nets; |
|
1106 |
val rules = erules @ irules; |
|
7425 | 1107 |
val ruleq = Method.multi_resolves facts rules; |
12053 | 1108 |
in |
1109 |
Method.trace ctxt rules; |
|
1110 |
fn st => Seq.flat (Seq.map (fn rule => Tactic.rtac rule i st) ruleq) |
|
1111 |
end); |
|
5841 | 1112 |
in tac end; |
1113 |
||
10394 | 1114 |
fun rule_tac [] ctxt cs facts = |
12053 | 1115 |
Method.some_rule_tac [] ctxt facts APPEND' some_rule_tac ctxt cs facts |
10394 | 1116 |
| rule_tac rules _ _ facts = Method.rule_tac rules facts; |
7281 | 1117 |
|
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
1118 |
fun default_tac rules ctxt cs facts = |
10394 | 1119 |
rule_tac rules ctxt cs facts ORELSE' |
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
1120 |
AxClass.default_intro_classes_tac facts; |
10309 | 1121 |
|
7230 | 1122 |
in |
7281 | 1123 |
val rule = METHOD_CLASET' o rule_tac; |
10394 | 1124 |
val default = METHOD_CLASET' o default_tac; |
7230 | 1125 |
end; |
5841 | 1126 |
|
1127 |
||
7230 | 1128 |
(* intro / elim methods *) |
1129 |
||
1130 |
local |
|
1131 |
||
10394 | 1132 |
fun intro_elim_tac netpair_of res_tac rules _ cs facts = |
7329 | 1133 |
let |
8342 | 1134 |
val tac = |
9449 | 1135 |
if null rules then FIRST' (map (bimatch_from_nets_tac o netpair_of) (get_nets cs)) |
7329 | 1136 |
else res_tac rules; |
8342 | 1137 |
in Method.insert_tac facts THEN' REPEAT_ALL_NEW tac end; |
6502 | 1138 |
|
8699 | 1139 |
val intro_tac = intro_elim_tac (fn (inet, _) => (inet, Net.empty)) Tactic.match_tac; |
1140 |
val elim_tac = intro_elim_tac (fn (_, enet) => (Net.empty, enet)) Tactic.ematch_tac; |
|
7230 | 1141 |
|
1142 |
in |
|
1143 |
val intro = METHOD_CLASET' o intro_tac; |
|
1144 |
val elim = METHOD_CLASET' o elim_tac; |
|
1145 |
end; |
|
1146 |
||
1147 |
||
1148 |
(* contradiction method *) |
|
6502 | 1149 |
|
7425 | 1150 |
val contradiction = Method.rule [Data.not_elim, Data.not_elim COMP Drule.swap_prems_rl]; |
6502 | 1151 |
|
1152 |
||
1153 |
(* automatic methods *) |
|
5841 | 1154 |
|
5927 | 1155 |
val cla_modifiers = |
10034 | 1156 |
[Args.$$$ destN -- Args.query_colon >> K ((I, xtra_dest_local):Method.modifier), |
1157 |
Args.$$$ destN -- Args.bang_colon >> K (I, safe_dest_local), |
|
1158 |
Args.$$$ destN -- Args.colon >> K (I, haz_dest_local), |
|
1159 |
Args.$$$ elimN -- Args.query_colon >> K (I, xtra_elim_local), |
|
1160 |
Args.$$$ elimN -- Args.bang_colon >> K (I, safe_elim_local), |
|
1161 |
Args.$$$ elimN -- Args.colon >> K (I, haz_elim_local), |
|
1162 |
Args.$$$ introN -- Args.query_colon >> K (I, xtra_intro_local), |
|
1163 |
Args.$$$ introN -- Args.bang_colon >> K (I, safe_intro_local), |
|
1164 |
Args.$$$ introN -- Args.colon >> K (I, haz_intro_local), |
|
1165 |
Args.del -- Args.colon >> K (I, rule_del_local)]; |
|
5927 | 1166 |
|
7559 | 1167 |
fun cla_meth tac prems ctxt = Method.METHOD (fn facts => |
1168 |
ALLGOALS (Method.insert_tac (prems @ facts)) THEN tac (get_local_claset ctxt)); |
|
7132 | 1169 |
|
7559 | 1170 |
fun cla_meth' tac prems ctxt = Method.METHOD (fn facts => |
8168 | 1171 |
HEADGOAL (Method.insert_tac (prems @ facts) THEN' tac (get_local_claset ctxt))); |
5841 | 1172 |
|
7559 | 1173 |
val cla_method = Method.bang_sectioned_args cla_modifiers o cla_meth; |
1174 |
val cla_method' = Method.bang_sectioned_args cla_modifiers o cla_meth'; |
|
5841 | 1175 |
|
1176 |
||
1177 |
||
1178 |
(** setup_methods **) |
|
1179 |
||
1180 |
val setup_methods = Method.add_methods |
|
10309 | 1181 |
[("default", Method.thms_ctxt_args default, "apply some rule (classical)"), |
9441 | 1182 |
("rule", Method.thms_ctxt_args rule, "apply some rule (classical)"), |
6502 | 1183 |
("contradiction", Method.no_args contradiction, "proof by contradiction"), |
8098 | 1184 |
("intro", Method.thms_ctxt_args intro, "repeatedly apply introduction rules"), |
1185 |
("elim", Method.thms_ctxt_args elim, "repeatedly apply elimination rules"), |
|
10821 | 1186 |
("clarify", cla_method' (CHANGED_PROP oo clarify_tac), "repeatedly apply safe steps"), |
7004 | 1187 |
("fast", cla_method' fast_tac, "classical prover (depth-first)"), |
9806 | 1188 |
("slow", cla_method' slow_tac, "classical prover (slow depth-first)"), |
9773 | 1189 |
("best", cla_method' best_tac, "classical prover (best-first)"), |
10821 | 1190 |
("safe", cla_method (CHANGED_PROP o safe_tac), "classical prover (apply safe rules)")]; |
5841 | 1191 |
|
1192 |
||
1193 |
||
1194 |
(** theory setup **) |
|
1195 |
||
7354 | 1196 |
val setup = [GlobalClaset.init, LocalClaset.init, setup_attrs, setup_methods]; |
5841 | 1197 |
|
1198 |
||
8667 | 1199 |
|
1200 |
(** outer syntax **) |
|
1201 |
||
1202 |
val print_clasetP = |
|
1203 |
OuterSyntax.improper_command "print_claset" "print context of Classical Reasoner" |
|
1204 |
OuterSyntax.Keyword.diag |
|
9513 | 1205 |
(Scan.succeed (Toplevel.no_timing o Toplevel.unknown_context o (Toplevel.keep |
9010 | 1206 |
(Toplevel.node_case print_claset (print_local_claset o Proof.context_of))))); |
8667 | 1207 |
|
1208 |
val _ = OuterSyntax.add_parsers [print_clasetP]; |
|
1209 |
||
1210 |
||
5841 | 1211 |
end; |