author | wenzelm |
Sun, 16 Aug 2015 14:48:37 +0200 | |
changeset 60945 | 88aaecbaf61e |
parent 60944 | bb75b61dba5d |
child 60946 | 46ec72073dc1 |
permissions | -rw-r--r-- |
9938 | 1 |
(* Title: Provers/classical.ML |
2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
0 | 3 |
|
4 |
Theorem prover for classical reasoning, including predicate calculus, set |
|
5 |
theory, etc. |
|
6 |
||
60943 | 7 |
Rules must be classified as intro, elim, safe, unsafe. |
0 | 8 |
|
9 |
A rule is unsafe unless it can be applied blindly without harmful results. |
|
10 |
For a rule to be safe, its premises and conclusion should be logically |
|
11 |
equivalent. There should be no variables in the premises that are not in |
|
12 |
the conclusion. |
|
13 |
*) |
|
14 |
||
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
15 |
(*higher precedence than := facilitates use of references*) |
12376
480303e3fa08
simplified (and clarified) integration with Pure/ContextRules;
wenzelm
parents:
12362
diff
changeset
|
16 |
infix 4 addSIs addSEs addSDs addIs addEs addDs delrules |
4651 | 17 |
addSWrapper delSWrapper addWrapper delWrapper |
11181
d04f57b91166
renamed addaltern to addafter, addSaltern to addSafter
oheimb
parents:
11168
diff
changeset
|
18 |
addSbefore addSafter addbefore addafter |
5523 | 19 |
addD2 addE2 addSD2 addSE2; |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
20 |
|
0 | 21 |
signature CLASSICAL_DATA = |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
22 |
sig |
42790 | 23 |
val imp_elim: thm (* P --> Q ==> (~ R ==> P) ==> (Q ==> R) ==> R *) |
24 |
val not_elim: thm (* ~P ==> P ==> R *) |
|
25 |
val swap: thm (* ~ P ==> (~ R ==> P) ==> R *) |
|
26 |
val classical: thm (* (~ P ==> P) ==> P *) |
|
50062 | 27 |
val sizef: thm -> int (* size function for BEST_FIRST, typically size_of_thm *) |
51798 | 28 |
val hyp_subst_tacs: (Proof.context -> int -> tactic) list (* optional tactics for |
29 |
substitution in the hypotheses; assumed to be safe! *) |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
30 |
end; |
0 | 31 |
|
5841 | 32 |
signature BASIC_CLASSICAL = |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
33 |
sig |
42812 | 34 |
type wrapper = (int -> tactic) -> int -> tactic |
0 | 35 |
type claset |
42793 | 36 |
val print_claset: Proof.context -> unit |
37 |
val addDs: Proof.context * thm list -> Proof.context |
|
38 |
val addEs: Proof.context * thm list -> Proof.context |
|
39 |
val addIs: Proof.context * thm list -> Proof.context |
|
40 |
val addSDs: Proof.context * thm list -> Proof.context |
|
41 |
val addSEs: Proof.context * thm list -> Proof.context |
|
42 |
val addSIs: Proof.context * thm list -> Proof.context |
|
43 |
val delrules: Proof.context * thm list -> Proof.context |
|
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
44 |
val addSWrapper: Proof.context * (string * (Proof.context -> wrapper)) -> Proof.context |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
45 |
val delSWrapper: Proof.context * string -> Proof.context |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
46 |
val addWrapper: Proof.context * (string * (Proof.context -> wrapper)) -> Proof.context |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
47 |
val delWrapper: Proof.context * string -> Proof.context |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
48 |
val addSbefore: Proof.context * (string * (Proof.context -> int -> tactic)) -> Proof.context |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
49 |
val addSafter: Proof.context * (string * (Proof.context -> int -> tactic)) -> Proof.context |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
50 |
val addbefore: Proof.context * (string * (Proof.context -> int -> tactic)) -> Proof.context |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
51 |
val addafter: Proof.context * (string * (Proof.context -> int -> tactic)) -> Proof.context |
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
52 |
val addD2: Proof.context * (string * thm) -> Proof.context |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
53 |
val addE2: Proof.context * (string * thm) -> Proof.context |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
54 |
val addSD2: Proof.context * (string * thm) -> Proof.context |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
55 |
val addSE2: Proof.context * (string * thm) -> Proof.context |
42793 | 56 |
val appSWrappers: Proof.context -> wrapper |
57 |
val appWrappers: Proof.context -> wrapper |
|
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
58 |
|
42790 | 59 |
val claset_of: Proof.context -> claset |
42793 | 60 |
val put_claset: claset -> Proof.context -> Proof.context |
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
61 |
|
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
62 |
val map_theory_claset: (Proof.context -> Proof.context) -> theory -> theory |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
63 |
|
42793 | 64 |
val fast_tac: Proof.context -> int -> tactic |
65 |
val slow_tac: Proof.context -> int -> tactic |
|
66 |
val astar_tac: Proof.context -> int -> tactic |
|
67 |
val slow_astar_tac: Proof.context -> int -> tactic |
|
68 |
val best_tac: Proof.context -> int -> tactic |
|
69 |
val first_best_tac: Proof.context -> int -> tactic |
|
70 |
val slow_best_tac: Proof.context -> int -> tactic |
|
71 |
val depth_tac: Proof.context -> int -> int -> tactic |
|
72 |
val deepen_tac: Proof.context -> int -> int -> tactic |
|
1587
e7d8a4957bac
Now provides astar versions (thanks to Norbert Voelker)
paulson
parents:
1524
diff
changeset
|
73 |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58958
diff
changeset
|
74 |
val contr_tac: Proof.context -> int -> tactic |
59970 | 75 |
val dup_elim: Proof.context -> thm -> thm |
42790 | 76 |
val dup_intr: thm -> thm |
42793 | 77 |
val dup_step_tac: Proof.context -> int -> tactic |
58957 | 78 |
val eq_mp_tac: Proof.context -> int -> tactic |
60943 | 79 |
val unsafe_step_tac: Proof.context -> int -> tactic |
42790 | 80 |
val joinrules: thm list * thm list -> (bool * thm) list |
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58958
diff
changeset
|
81 |
val mp_tac: Proof.context -> int -> tactic |
42793 | 82 |
val safe_tac: Proof.context -> tactic |
83 |
val safe_steps_tac: Proof.context -> int -> tactic |
|
84 |
val safe_step_tac: Proof.context -> int -> tactic |
|
85 |
val clarify_tac: Proof.context -> int -> tactic |
|
86 |
val clarify_step_tac: Proof.context -> int -> tactic |
|
87 |
val step_tac: Proof.context -> int -> tactic |
|
88 |
val slow_step_tac: Proof.context -> int -> tactic |
|
42790 | 89 |
val swapify: thm list -> thm list |
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58958
diff
changeset
|
90 |
val swap_res_tac: Proof.context -> thm list -> int -> tactic |
42793 | 91 |
val inst_step_tac: Proof.context -> int -> tactic |
92 |
val inst0_step_tac: Proof.context -> int -> tactic |
|
93 |
val instp_step_tac: Proof.context -> int -> tactic |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
94 |
end; |
1724 | 95 |
|
5841 | 96 |
signature CLASSICAL = |
97 |
sig |
|
98 |
include BASIC_CLASSICAL |
|
59970 | 99 |
val classical_rule: Proof.context -> thm -> thm |
60945 | 100 |
type rule = thm * thm * thm |
42812 | 101 |
type netpair = (int * (bool * thm)) Net.net * (int * (bool * thm)) Net.net |
102 |
val rep_cs: claset -> |
|
60945 | 103 |
{safeIs: rule Item_Net.T, |
104 |
safeEs: rule Item_Net.T, |
|
105 |
unsafeIs: rule Item_Net.T, |
|
106 |
unsafeEs: rule Item_Net.T, |
|
42812 | 107 |
swrappers: (string * (Proof.context -> wrapper)) list, |
108 |
uwrappers: (string * (Proof.context -> wrapper)) list, |
|
109 |
safe0_netpair: netpair, |
|
110 |
safep_netpair: netpair, |
|
60943 | 111 |
unsafe_netpair: netpair, |
42812 | 112 |
dup_netpair: netpair, |
60942 | 113 |
extra_netpair: Context_Rules.netpair} |
24021 | 114 |
val get_cs: Context.generic -> claset |
115 |
val map_cs: (claset -> claset) -> Context.generic -> Context.generic |
|
18728 | 116 |
val safe_dest: int option -> attribute |
117 |
val safe_elim: int option -> attribute |
|
118 |
val safe_intro: int option -> attribute |
|
60943 | 119 |
val unsafe_dest: int option -> attribute |
120 |
val unsafe_elim: int option -> attribute |
|
121 |
val unsafe_intro: int option -> attribute |
|
18728 | 122 |
val rule_del: attribute |
30513 | 123 |
val cla_modifiers: Method.modifier parser list |
42793 | 124 |
val cla_method: |
125 |
(Proof.context -> tactic) -> (Proof.context -> Proof.method) context_parser |
|
126 |
val cla_method': |
|
127 |
(Proof.context -> int -> tactic) -> (Proof.context -> Proof.method) context_parser |
|
5841 | 128 |
end; |
129 |
||
0 | 130 |
|
42799 | 131 |
functor Classical(Data: CLASSICAL_DATA): CLASSICAL = |
0 | 132 |
struct |
133 |
||
18534
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
134 |
(** classical elimination rules **) |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
135 |
|
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
136 |
(* |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
137 |
Classical reasoning requires stronger elimination rules. For |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
138 |
instance, make_elim of Pure transforms the HOL rule injD into |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
139 |
|
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
140 |
[| inj f; f x = f y; x = y ==> PROP W |] ==> PROP W |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
141 |
|
26938 | 142 |
Such rules can cause fast_tac to fail and blast_tac to report "PROOF |
59119 | 143 |
FAILED"; classical_rule will strengthen this to |
18534
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
144 |
|
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
145 |
[| inj f; ~ W ==> f x = f y; x = y ==> W |] ==> W |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
146 |
*) |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
147 |
|
59970 | 148 |
fun classical_rule ctxt rule = |
149 |
if is_some (Object_Logic.elim_concl ctxt rule) then |
|
18534
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
150 |
let |
60817 | 151 |
val thy = Proof_Context.theory_of ctxt; |
42792 | 152 |
val rule' = rule RS Data.classical; |
18534
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
153 |
val concl' = Thm.concl_of rule'; |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
154 |
fun redundant_hyp goal = |
19257 | 155 |
concl' aconv Logic.strip_assums_concl goal orelse |
18534
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
156 |
(case Logic.strip_assums_hyp goal of |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
157 |
hyp :: hyps => exists (fn t => t aconv hyp) hyps |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
158 |
| _ => false); |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
159 |
val rule'' = |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
160 |
rule' |> ALLGOALS (SUBGOAL (fn (goal, i) => |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
161 |
if i = 1 orelse redundant_hyp goal |
60757 | 162 |
then eresolve_tac ctxt [thin_rl] i |
18534
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
163 |
else all_tac)) |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
164 |
|> Seq.hd |
21963 | 165 |
|> Drule.zero_var_indexes; |
60817 | 166 |
in if Thm.equiv_thm thy (rule, rule'') then rule else rule'' end |
18534
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
167 |
else rule; |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
168 |
|
23594
e65e466dda01
renamed ObjectLogic.atomize_tac to ObjectLogic.atomize_prems_tac;
wenzelm
parents:
23178
diff
changeset
|
169 |
(*flatten nested meta connectives in prems*) |
59970 | 170 |
fun flat_rule ctxt = |
171 |
Conv.fconv_rule (Conv.prems_conv ~1 (Object_Logic.atomize_prems ctxt)); |
|
18534
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
172 |
|
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
173 |
|
1800 | 174 |
(*** Useful tactics for classical reasoning ***) |
0 | 175 |
|
10736 | 176 |
(*Prove goal that assumes both P and ~P. |
4392 | 177 |
No backtracking if it finds an equal assumption. Perhaps should call |
178 |
ematch_tac instead of eresolve_tac, but then cannot prove ZF/cantor.*) |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58958
diff
changeset
|
179 |
fun contr_tac ctxt = |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
180 |
eresolve_tac ctxt [Data.not_elim] THEN' (eq_assume_tac ORELSE' assume_tac ctxt); |
0 | 181 |
|
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
182 |
(*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
|
183 |
Could do the same thing for P<->Q and P... *) |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
184 |
fun mp_tac ctxt i = |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
185 |
eresolve_tac ctxt [Data.not_elim, Data.imp_elim] i THEN assume_tac ctxt i; |
0 | 186 |
|
187 |
(*Like mp_tac but instantiates no variables*) |
|
58957 | 188 |
fun eq_mp_tac ctxt i = ematch_tac ctxt [Data.not_elim, Data.imp_elim] i THEN eq_assume_tac i; |
0 | 189 |
|
190 |
(*Creates rules to eliminate ~A, from rules to introduce A*) |
|
26412
0918f5c0bbca
pass imp_elim (instead of mp) and swap explicitly -- avoids store_thm;
wenzelm
parents:
24867
diff
changeset
|
191 |
fun swapify intrs = intrs RLN (2, [Data.swap]); |
30528 | 192 |
val swapped = Thm.rule_attribute (fn _ => fn th => th RSN (2, Data.swap)); |
0 | 193 |
|
194 |
(*Uses introduction rules in the normal way, or on negated assumptions, |
|
195 |
trying rules in order. *) |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58958
diff
changeset
|
196 |
fun swap_res_tac ctxt rls = |
42792 | 197 |
let fun addrl rl brls = (false, rl) :: (true, rl RSN (2, Data.swap)) :: brls in |
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58958
diff
changeset
|
198 |
assume_tac ctxt ORELSE' |
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58958
diff
changeset
|
199 |
contr_tac ctxt ORELSE' |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
200 |
biresolve_tac ctxt (fold_rev addrl rls []) |
42792 | 201 |
end; |
0 | 202 |
|
60943 | 203 |
(*Duplication of unsafe rules, for complete provers*) |
42792 | 204 |
fun dup_intr th = zero_var_indexes (th RS Data.classical); |
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
205 |
|
59970 | 206 |
fun dup_elim ctxt th = |
207 |
let val rl = (th RSN (2, revcut_rl)) |> Thm.assumption (SOME ctxt) 2 |> Seq.hd; |
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
208 |
in rule_by_tactic ctxt (TRYALL (eresolve_tac ctxt [revcut_rl])) rl end; |
36546 | 209 |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
210 |
|
1800 | 211 |
(**** Classical rule sets ****) |
0 | 212 |
|
60945 | 213 |
type rule = thm * thm * thm; (*external form vs. internal forms*) |
42812 | 214 |
type netpair = (int * (bool * thm)) Net.net * (int * (bool * thm)) Net.net; |
215 |
type wrapper = (int -> tactic) -> int -> tactic; |
|
216 |
||
0 | 217 |
datatype claset = |
42793 | 218 |
CS of |
60945 | 219 |
{safeIs: rule Item_Net.T, (*safe introduction rules*) |
220 |
safeEs: rule Item_Net.T, (*safe elimination rules*) |
|
221 |
unsafeIs: rule Item_Net.T, (*unsafe introduction rules*) |
|
222 |
unsafeEs: rule Item_Net.T, (*unsafe elimination rules*) |
|
223 |
swrappers: (string * (Proof.context -> wrapper)) list, (*for transforming safe_step_tac*) |
|
224 |
uwrappers: (string * (Proof.context -> wrapper)) list, (*for transforming step_tac*) |
|
225 |
safe0_netpair: netpair, (*nets for trivial cases*) |
|
226 |
safep_netpair: netpair, (*nets for >0 subgoals*) |
|
227 |
unsafe_netpair: netpair, (*nets for unsafe rules*) |
|
228 |
dup_netpair: netpair, (*nets for duplication*) |
|
229 |
extra_netpair: Context_Rules.netpair}; (*nets for extra rules*) |
|
230 |
||
231 |
val empty_rules: rule Item_Net.T = |
|
232 |
Item_Net.init (Thm.eq_thm_prop o apply2 #1) (single o Thm.full_prop_of o #1); |
|
0 | 233 |
|
6502 | 234 |
val empty_netpair = (Net.empty, Net.empty); |
235 |
||
10736 | 236 |
val empty_cs = |
42793 | 237 |
CS |
60945 | 238 |
{safeIs = empty_rules, |
239 |
safeEs = empty_rules, |
|
240 |
unsafeIs = empty_rules, |
|
241 |
unsafeEs = empty_rules, |
|
42793 | 242 |
swrappers = [], |
243 |
uwrappers = [], |
|
244 |
safe0_netpair = empty_netpair, |
|
245 |
safep_netpair = empty_netpair, |
|
60943 | 246 |
unsafe_netpair = empty_netpair, |
42793 | 247 |
dup_netpair = empty_netpair, |
60942 | 248 |
extra_netpair = empty_netpair}; |
0 | 249 |
|
4653 | 250 |
fun rep_cs (CS args) = args; |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
251 |
|
4079
9df5e4f22d96
new implicit claset mechanism based on Sign.sg anytype data;
wenzelm
parents:
4066
diff
changeset
|
252 |
|
1800 | 253 |
(*** Adding (un)safe introduction or elimination rules. |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
254 |
|
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
255 |
In case of overlap, new rules are tried BEFORE old ones!! |
1800 | 256 |
***) |
0 | 257 |
|
12376
480303e3fa08
simplified (and clarified) integration with Pure/ContextRules;
wenzelm
parents:
12362
diff
changeset
|
258 |
(*For use with biresolve_tac. Combines intro rules with swap to handle negated |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
259 |
assumptions. Pairs elim rules with true. *) |
12376
480303e3fa08
simplified (and clarified) integration with Pure/ContextRules;
wenzelm
parents:
12362
diff
changeset
|
260 |
fun joinrules (intrs, elims) = |
18557
60a0f9caa0a2
Provers/classical: stricter checks to ensure that supplied intro, dest and
paulson
parents:
18534
diff
changeset
|
261 |
(map (pair true) (elims @ swapify intrs)) @ map (pair false) intrs; |
12376
480303e3fa08
simplified (and clarified) integration with Pure/ContextRules;
wenzelm
parents:
12362
diff
changeset
|
262 |
|
12401 | 263 |
fun joinrules' (intrs, elims) = |
18557
60a0f9caa0a2
Provers/classical: stricter checks to ensure that supplied intro, dest and
paulson
parents:
18534
diff
changeset
|
264 |
map (pair true) elims @ map (pair false) intrs; |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
265 |
|
10736 | 266 |
(*Priority: prefer rules with fewest subgoals, |
1231 | 267 |
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
|
268 |
fun tag_brls k [] = [] |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
269 |
| tag_brls k (brl::brls) = |
10736 | 270 |
(1000000*subgoals_of_brl brl + k, brl) :: |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
271 |
tag_brls (k+1) brls; |
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
272 |
|
12401 | 273 |
fun tag_brls' _ _ [] = [] |
274 |
| tag_brls' w k (brl::brls) = ((w, k), brl) :: tag_brls' w (k + 1) brls; |
|
10736 | 275 |
|
23178 | 276 |
fun insert_tagged_list rls = fold_rev Tactic.insert_tagged_brl rls; |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
277 |
|
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
278 |
(*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
|
279 |
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
|
280 |
new insertions the lowest priority.*) |
12376
480303e3fa08
simplified (and clarified) integration with Pure/ContextRules;
wenzelm
parents:
12362
diff
changeset
|
281 |
fun insert (nI, nE) = insert_tagged_list o (tag_brls (~(2*nI+nE))) o joinrules; |
12401 | 282 |
fun insert' w (nI, nE) = insert_tagged_list o tag_brls' w (~(nI + nE)) o joinrules'; |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
283 |
|
23178 | 284 |
fun delete_tagged_list rls = fold_rev Tactic.delete_tagged_brl rls; |
12362 | 285 |
fun delete x = delete_tagged_list (joinrules x); |
12401 | 286 |
fun delete' x = delete_tagged_list (joinrules' x); |
1800 | 287 |
|
60945 | 288 |
fun bad_thm ctxt msg th = error (msg ^ "\n" ^ Display.string_of_thm ctxt th); |
42793 | 289 |
|
60945 | 290 |
fun make_elim ctxt th = |
291 |
if has_fewer_prems 1 th then bad_thm ctxt "Ill-formed destruction rule" th |
|
42793 | 292 |
else Tactic.make_elim th; |
42790 | 293 |
|
60945 | 294 |
fun warn_thm ctxt msg th = |
295 |
if Context_Position.is_really_visible ctxt |
|
296 |
then warning (msg ^ Display.string_of_thm ctxt th) else (); |
|
42793 | 297 |
|
60945 | 298 |
fun warn_rules ctxt msg rules (r: rule) = |
299 |
Item_Net.member rules r andalso (warn_thm ctxt msg (#1 r); true); |
|
42807
e639d91d9073
more precise warnings: observe context visibility;
wenzelm
parents:
42799
diff
changeset
|
300 |
|
60945 | 301 |
fun warn_claset ctxt r (CS {safeIs, safeEs, unsafeIs, unsafeEs, ...}) = |
302 |
warn_rules ctxt "Rule already declared as safe introduction (intro!)\n" safeIs r orelse |
|
303 |
warn_rules ctxt "Rule already declared as safe elimination (elim!)\n" safeEs r orelse |
|
304 |
warn_rules ctxt "Rule already declared as introduction (intro)\n" unsafeIs r orelse |
|
305 |
warn_rules ctxt "Rule already declared as elimination (elim)\n" unsafeEs r; |
|
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
306 |
|
12376
480303e3fa08
simplified (and clarified) integration with Pure/ContextRules;
wenzelm
parents:
12362
diff
changeset
|
307 |
|
1800 | 308 |
(*** Safe rules ***) |
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
309 |
|
60945 | 310 |
fun add_safe_intro w r |
60943 | 311 |
(cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, |
312 |
safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) = |
|
60945 | 313 |
if Item_Net.member safeIs r then cs |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
314 |
else |
42790 | 315 |
let |
60945 | 316 |
val (th, th', _) = r; |
23594
e65e466dda01
renamed ObjectLogic.atomize_tac to ObjectLogic.atomize_prems_tac;
wenzelm
parents:
23178
diff
changeset
|
317 |
val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*) |
42790 | 318 |
List.partition Thm.no_prems [th']; |
42810
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
319 |
val nI = Item_Net.length safeIs + 1; |
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
320 |
val nE = Item_Net.length safeEs; |
42790 | 321 |
in |
322 |
CS |
|
60945 | 323 |
{safeIs = Item_Net.update r safeIs, |
60944 | 324 |
safe0_netpair = insert (nI, nE) (safe0_rls, []) safe0_netpair, |
325 |
safep_netpair = insert (nI, nE) (safep_rls, []) safep_netpair, |
|
42790 | 326 |
safeEs = safeEs, |
60943 | 327 |
unsafeIs = unsafeIs, |
328 |
unsafeEs = unsafeEs, |
|
42790 | 329 |
swrappers = swrappers, |
330 |
uwrappers = uwrappers, |
|
60943 | 331 |
unsafe_netpair = unsafe_netpair, |
42790 | 332 |
dup_netpair = dup_netpair, |
60944 | 333 |
extra_netpair = insert' (the_default 0 w) (nI, nE) ([th], []) extra_netpair} |
42790 | 334 |
end; |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
335 |
|
60945 | 336 |
fun add_safe_elim w r |
60943 | 337 |
(cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, |
338 |
safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) = |
|
60945 | 339 |
if Item_Net.member safeEs r then cs |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
340 |
else |
42790 | 341 |
let |
60945 | 342 |
val (th, th', _) = r; |
18534
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
343 |
val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*) |
60945 | 344 |
List.partition (fn rl => Thm.nprems_of rl = 1) [th']; |
42810
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
345 |
val nI = Item_Net.length safeIs; |
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
346 |
val nE = Item_Net.length safeEs + 1; |
42790 | 347 |
in |
348 |
CS |
|
60945 | 349 |
{safeEs = Item_Net.update r safeEs, |
60944 | 350 |
safe0_netpair = insert (nI, nE) ([], safe0_rls) safe0_netpair, |
351 |
safep_netpair = insert (nI, nE) ([], safep_rls) safep_netpair, |
|
42790 | 352 |
safeIs = safeIs, |
60943 | 353 |
unsafeIs = unsafeIs, |
354 |
unsafeEs = unsafeEs, |
|
42790 | 355 |
swrappers = swrappers, |
356 |
uwrappers = uwrappers, |
|
60943 | 357 |
unsafe_netpair = unsafe_netpair, |
42790 | 358 |
dup_netpair = dup_netpair, |
60944 | 359 |
extra_netpair = insert' (the_default 0 w) (nI, nE) ([], [th]) extra_netpair} |
42790 | 360 |
end; |
0 | 361 |
|
60945 | 362 |
fun addSI w ctxt th (cs as CS {safeIs, ...}) = |
363 |
let |
|
364 |
val th' = flat_rule ctxt th; |
|
365 |
val r = (th, th', th'); |
|
366 |
val _ = |
|
367 |
warn_rules ctxt "Ignoring duplicate safe introduction (intro!)\n" safeIs r orelse |
|
368 |
warn_claset ctxt r cs; |
|
369 |
in add_safe_intro w r cs end; |
|
370 |
||
371 |
fun addSE w ctxt th (cs as CS {safeEs, ...}) = |
|
372 |
let |
|
373 |
val _ = has_fewer_prems 1 th andalso bad_thm ctxt "Ill-formed elimination rule" th; |
|
374 |
val th' = classical_rule ctxt (flat_rule ctxt th); |
|
375 |
val r = (th, th', th'); |
|
376 |
val _ = |
|
377 |
warn_rules ctxt "Ignoring duplicate safe elimination (elim!)\n" safeEs r orelse |
|
378 |
warn_claset ctxt r cs; |
|
379 |
in add_safe_elim w r cs end; |
|
380 |
||
381 |
fun addSD w ctxt th = addSE w ctxt (make_elim ctxt th); |
|
42793 | 382 |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
383 |
|
60945 | 384 |
(*** Unsafe rules ***) |
0 | 385 |
|
60945 | 386 |
fun add_unsafe_intro w r |
60943 | 387 |
(cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, |
388 |
safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) = |
|
60945 | 389 |
if Item_Net.member unsafeIs r then cs |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
390 |
else |
42790 | 391 |
let |
60945 | 392 |
val (th, th', th'') = r; |
60943 | 393 |
val nI = Item_Net.length unsafeIs + 1; |
394 |
val nE = Item_Net.length unsafeEs; |
|
42790 | 395 |
in |
396 |
CS |
|
60945 | 397 |
{unsafeIs = Item_Net.update r unsafeIs, |
60943 | 398 |
unsafe_netpair = insert (nI, nE) ([th'], []) unsafe_netpair, |
60945 | 399 |
dup_netpair = insert (nI, nE) ([th''], []) dup_netpair, |
42790 | 400 |
safeIs = safeIs, |
401 |
safeEs = safeEs, |
|
60943 | 402 |
unsafeEs = unsafeEs, |
42790 | 403 |
swrappers = swrappers, |
404 |
uwrappers = uwrappers, |
|
9938 | 405 |
safe0_netpair = safe0_netpair, |
406 |
safep_netpair = safep_netpair, |
|
60942 | 407 |
extra_netpair = insert' (the_default 1 w) (nI, nE) ([th], []) extra_netpair} |
60945 | 408 |
end; |
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
409 |
|
60945 | 410 |
fun add_unsafe_elim w r |
60943 | 411 |
(cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, |
412 |
safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) = |
|
60945 | 413 |
if Item_Net.member unsafeEs r then cs |
1927
6f97cb16e453
New classical reasoner: warns of, and ignores, redundant rules.
paulson
parents:
1814
diff
changeset
|
414 |
else |
42790 | 415 |
let |
60945 | 416 |
val (th, th', th'') = r; |
60943 | 417 |
val nI = Item_Net.length unsafeIs; |
418 |
val nE = Item_Net.length unsafeEs + 1; |
|
42790 | 419 |
in |
420 |
CS |
|
60945 | 421 |
{unsafeEs = Item_Net.update r unsafeEs, |
60943 | 422 |
unsafe_netpair = insert (nI, nE) ([], [th']) unsafe_netpair, |
60945 | 423 |
dup_netpair = insert (nI, nE) ([], [th'']) dup_netpair, |
42790 | 424 |
safeIs = safeIs, |
425 |
safeEs = safeEs, |
|
60943 | 426 |
unsafeIs = unsafeIs, |
42790 | 427 |
swrappers = swrappers, |
428 |
uwrappers = uwrappers, |
|
9938 | 429 |
safe0_netpair = safe0_netpair, |
430 |
safep_netpair = safep_netpair, |
|
60942 | 431 |
extra_netpair = insert' (the_default 1 w) (nI, nE) ([], [th]) extra_netpair} |
42790 | 432 |
end; |
0 | 433 |
|
60945 | 434 |
fun addI w ctxt th (cs as CS {unsafeIs, ...}) = |
435 |
let |
|
436 |
val th' = flat_rule ctxt th; |
|
437 |
val th'' = dup_intr th' handle THM _ => bad_thm ctxt "Ill-formed introduction rule" th; |
|
438 |
val r = (th, th', th''); |
|
439 |
val _ = |
|
440 |
warn_rules ctxt "Ignoring duplicate introduction (intro)\n" unsafeIs r orelse |
|
441 |
warn_claset ctxt r cs; |
|
442 |
in add_unsafe_intro w r cs end; |
|
42793 | 443 |
|
60945 | 444 |
fun addE w ctxt th (cs as CS {unsafeEs, ...}) = |
445 |
let |
|
446 |
val _ = has_fewer_prems 1 th andalso bad_thm ctxt "Ill-formed elimination rule" th; |
|
447 |
val th' = classical_rule ctxt (flat_rule ctxt th); |
|
448 |
val th'' = dup_elim ctxt th' handle THM _ => bad_thm ctxt "Ill-formed elimination rule" th; |
|
449 |
val r = (th, th', th''); |
|
450 |
val _ = |
|
451 |
warn_rules ctxt "Ignoring duplicate elimination (elim)\n" unsafeEs r orelse |
|
452 |
warn_claset ctxt r cs; |
|
453 |
in add_unsafe_elim w r cs end; |
|
454 |
||
455 |
fun addD w ctxt th = addE w ctxt (make_elim ctxt th); |
|
0 | 456 |
|
1073
b3f190995bc9
Recoded addSIs, etc., so that nets are built incrementally
lcp
parents:
1010
diff
changeset
|
457 |
|
10736 | 458 |
(*** Deletion of rules |
1800 | 459 |
Working out what to delete, requires repeating much of the code used |
9938 | 460 |
to insert. |
1800 | 461 |
***) |
462 |
||
60945 | 463 |
fun delSI ctxt th |
60943 | 464 |
(cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, |
465 |
safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) = |
|
60945 | 466 |
if Item_Net.member safeIs (th, th, th) then |
18534
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
467 |
let |
59970 | 468 |
val th' = flat_rule ctxt th; |
60945 | 469 |
val r = (th, th', th'); |
42790 | 470 |
val (safe0_rls, safep_rls) = List.partition Thm.no_prems [th']; |
471 |
in |
|
472 |
CS |
|
473 |
{safe0_netpair = delete (safe0_rls, []) safe0_netpair, |
|
474 |
safep_netpair = delete (safep_rls, []) safep_netpair, |
|
60945 | 475 |
safeIs = Item_Net.remove r safeIs, |
42790 | 476 |
safeEs = safeEs, |
60943 | 477 |
unsafeIs = unsafeIs, |
478 |
unsafeEs = unsafeEs, |
|
42790 | 479 |
swrappers = swrappers, |
480 |
uwrappers = uwrappers, |
|
60943 | 481 |
unsafe_netpair = unsafe_netpair, |
42790 | 482 |
dup_netpair = dup_netpair, |
60942 | 483 |
extra_netpair = delete' ([th], []) extra_netpair} |
18534
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
484 |
end |
6799b38ed872
added classical_rule, which replaces Data.make_elim;
wenzelm
parents:
18374
diff
changeset
|
485 |
else cs; |
1800 | 486 |
|
60945 | 487 |
fun delSE ctxt th |
60943 | 488 |
(cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, |
489 |
safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) = |
|
60945 | 490 |
if Item_Net.member safeEs (th, th, th) then |
42790 | 491 |
let |
59970 | 492 |
val th' = classical_rule ctxt (flat_rule ctxt th); |
60945 | 493 |
val r = (th, th', th'); |
59582 | 494 |
val (safe0_rls, safep_rls) = List.partition (fn rl => Thm.nprems_of rl = 1) [th']; |
42790 | 495 |
in |
496 |
CS |
|
497 |
{safe0_netpair = delete ([], safe0_rls) safe0_netpair, |
|
498 |
safep_netpair = delete ([], safep_rls) safep_netpair, |
|
499 |
safeIs = safeIs, |
|
60945 | 500 |
safeEs = Item_Net.remove r safeEs, |
60943 | 501 |
unsafeIs = unsafeIs, |
502 |
unsafeEs = unsafeEs, |
|
42790 | 503 |
swrappers = swrappers, |
504 |
uwrappers = uwrappers, |
|
60943 | 505 |
unsafe_netpair = unsafe_netpair, |
42790 | 506 |
dup_netpair = dup_netpair, |
60942 | 507 |
extra_netpair = delete' ([], [th]) extra_netpair} |
42790 | 508 |
end |
509 |
else cs; |
|
1800 | 510 |
|
60945 | 511 |
fun delI ctxt th |
60943 | 512 |
(cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, |
513 |
safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) = |
|
60945 | 514 |
if Item_Net.member unsafeIs (th, th, th) then |
59970 | 515 |
let |
516 |
val th' = flat_rule ctxt th; |
|
60945 | 517 |
val th'' = dup_intr th'; |
518 |
val r = (th, th', th''); |
|
59970 | 519 |
in |
42790 | 520 |
CS |
60943 | 521 |
{unsafe_netpair = delete ([th'], []) unsafe_netpair, |
60945 | 522 |
dup_netpair = delete ([th''], []) dup_netpair, |
42790 | 523 |
safeIs = safeIs, |
524 |
safeEs = safeEs, |
|
60945 | 525 |
unsafeIs = Item_Net.remove r unsafeIs, |
60943 | 526 |
unsafeEs = unsafeEs, |
42790 | 527 |
swrappers = swrappers, |
528 |
uwrappers = uwrappers, |
|
9938 | 529 |
safe0_netpair = safe0_netpair, |
530 |
safep_netpair = safep_netpair, |
|
60942 | 531 |
extra_netpair = delete' ([th], []) extra_netpair} |
23594
e65e466dda01
renamed ObjectLogic.atomize_tac to ObjectLogic.atomize_prems_tac;
wenzelm
parents:
23178
diff
changeset
|
532 |
end |
60945 | 533 |
else cs; |
1800 | 534 |
|
60945 | 535 |
fun delE ctxt th |
60943 | 536 |
(cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, |
537 |
safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) = |
|
60945 | 538 |
if Item_Net.member unsafeEs (th, th, th) then |
59970 | 539 |
let |
540 |
val th' = classical_rule ctxt (flat_rule ctxt th); |
|
60945 | 541 |
val th'' = dup_elim ctxt th'; |
542 |
val r = (th, th', th''); |
|
59970 | 543 |
in |
42790 | 544 |
CS |
60943 | 545 |
{unsafe_netpair = delete ([], [th']) unsafe_netpair, |
60945 | 546 |
dup_netpair = delete ([], [th'']) dup_netpair, |
42790 | 547 |
safeIs = safeIs, |
548 |
safeEs = safeEs, |
|
60943 | 549 |
unsafeIs = unsafeIs, |
60945 | 550 |
unsafeEs = Item_Net.remove r unsafeEs, |
42790 | 551 |
swrappers = swrappers, |
552 |
uwrappers = uwrappers, |
|
9938 | 553 |
safe0_netpair = safe0_netpair, |
554 |
safep_netpair = safep_netpair, |
|
60942 | 555 |
extra_netpair = delete' ([], [th]) extra_netpair} |
42790 | 556 |
end |
557 |
else cs; |
|
1800 | 558 |
|
2813
cc4c816dafdc
delrules now deletes ALL occurrences of a rule, since it may appear in any of
paulson
parents:
2689
diff
changeset
|
559 |
(*Delete ALL occurrences of "th" in the claset (perhaps from several lists)*) |
60945 | 560 |
fun delrule ctxt th (cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, ...}) = |
561 |
let |
|
562 |
val th' = Tactic.make_elim th; |
|
563 |
val r = (th, th, th); |
|
564 |
val r' = (th', th', th'); |
|
565 |
in |
|
566 |
if Item_Net.member safeIs r orelse Item_Net.member safeEs r orelse |
|
567 |
Item_Net.member unsafeIs r orelse Item_Net.member unsafeEs r orelse |
|
568 |
Item_Net.member safeEs r' orelse Item_Net.member unsafeEs r' |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52732
diff
changeset
|
569 |
then |
60942 | 570 |
cs |
60945 | 571 |
|> delE ctxt th' |
572 |
|> delSE ctxt th' |
|
573 |
|> delE ctxt th |
|
574 |
|> delI ctxt th |
|
575 |
|> delSE ctxt th |
|
576 |
|> delSI ctxt th |
|
577 |
else (warn_thm ctxt "Undeclared classical rule\n" th; cs) |
|
9938 | 578 |
end; |
1800 | 579 |
|
580 |
||
42793 | 581 |
|
582 |
(** claset data **) |
|
42790 | 583 |
|
42793 | 584 |
(* wrappers *) |
42790 | 585 |
|
22674 | 586 |
fun map_swrappers f |
60943 | 587 |
(CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, |
588 |
safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) = |
|
589 |
CS {safeIs = safeIs, safeEs = safeEs, unsafeIs = unsafeIs, unsafeEs = unsafeEs, |
|
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
590 |
swrappers = f swrappers, uwrappers = uwrappers, |
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
591 |
safe0_netpair = safe0_netpair, safep_netpair = safep_netpair, |
60943 | 592 |
unsafe_netpair = unsafe_netpair, dup_netpair = dup_netpair, extra_netpair = extra_netpair}; |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
593 |
|
22674 | 594 |
fun map_uwrappers f |
60943 | 595 |
(CS {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, |
596 |
safe0_netpair, safep_netpair, unsafe_netpair, dup_netpair, extra_netpair}) = |
|
597 |
CS {safeIs = safeIs, safeEs = safeEs, unsafeIs = unsafeIs, unsafeEs = unsafeEs, |
|
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
598 |
swrappers = swrappers, uwrappers = f uwrappers, |
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
599 |
safe0_netpair = safe0_netpair, safep_netpair = safep_netpair, |
60943 | 600 |
unsafe_netpair = unsafe_netpair, dup_netpair = dup_netpair, extra_netpair = extra_netpair}; |
4767
b9f3468c6ee2
introduced functions for updating the wrapper lists
oheimb
parents:
4765
diff
changeset
|
601 |
|
22674 | 602 |
|
42793 | 603 |
(* merge_cs *) |
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
604 |
|
42810
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
605 |
(*Merge works by adding all new rules of the 2nd claset into the 1st claset, |
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
606 |
in order to preserve priorities reliably.*) |
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
607 |
|
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
608 |
fun merge_thms add thms1 thms2 = |
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
609 |
fold_rev (fn thm => if Item_Net.member thms1 thm then I else add thm) (Item_Net.content thms2); |
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
610 |
|
60943 | 611 |
fun merge_cs (cs as CS {safeIs, safeEs, unsafeIs, unsafeEs, ...}, |
612 |
cs' as CS {safeIs = safeIs2, safeEs = safeEs2, unsafeIs = unsafeIs2, unsafeEs = unsafeEs2, |
|
22674 | 613 |
swrappers, uwrappers, ...}) = |
24358 | 614 |
if pointer_eq (cs, cs') then cs |
615 |
else |
|
42810
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
616 |
cs |
60945 | 617 |
|> merge_thms (add_safe_intro NONE) safeIs safeIs2 |
618 |
|> merge_thms (add_safe_elim NONE) safeEs safeEs2 |
|
619 |
|> merge_thms (add_unsafe_intro NONE) unsafeIs unsafeIs2 |
|
620 |
|> merge_thms (add_unsafe_elim NONE) unsafeEs unsafeEs2 |
|
42810
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
621 |
|> map_swrappers (fn ws => AList.merge (op =) (K true) (ws, swrappers)) |
2425068fe13a
slightly more efficient claset operations, using Item_Net to maintain rules in canonical order;
wenzelm
parents:
42807
diff
changeset
|
622 |
|> map_uwrappers (fn ws => AList.merge (op =) (K true) (ws, uwrappers)); |
42793 | 623 |
|
624 |
||
625 |
(* data *) |
|
626 |
||
627 |
structure Claset = Generic_Data |
|
628 |
( |
|
629 |
type T = claset; |
|
630 |
val empty = empty_cs; |
|
631 |
val extend = I; |
|
632 |
val merge = merge_cs; |
|
633 |
); |
|
634 |
||
635 |
val claset_of = Claset.get o Context.Proof; |
|
636 |
val rep_claset_of = rep_cs o claset_of; |
|
637 |
||
638 |
val get_cs = Claset.get; |
|
639 |
val map_cs = Claset.map; |
|
640 |
||
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
641 |
fun map_theory_claset f thy = |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
642 |
let |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
643 |
val ctxt' = f (Proof_Context.init_global thy); |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
644 |
val thy' = Proof_Context.theory_of ctxt'; |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
645 |
in Context.theory_map (Claset.map (K (claset_of ctxt'))) thy' end; |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
646 |
|
42793 | 647 |
fun map_claset f = Context.proof_map (map_cs f); |
648 |
fun put_claset cs = map_claset (K cs); |
|
649 |
||
650 |
fun print_claset ctxt = |
|
651 |
let |
|
60943 | 652 |
val {safeIs, safeEs, unsafeIs, unsafeEs, swrappers, uwrappers, ...} = rep_claset_of ctxt; |
60945 | 653 |
val pretty_thms = map (Display.pretty_thm_item ctxt o #1) o Item_Net.content; |
42793 | 654 |
in |
655 |
[Pretty.big_list "safe introduction rules (intro!):" (pretty_thms safeIs), |
|
60943 | 656 |
Pretty.big_list "introduction rules (intro):" (pretty_thms unsafeIs), |
42793 | 657 |
Pretty.big_list "safe elimination rules (elim!):" (pretty_thms safeEs), |
60943 | 658 |
Pretty.big_list "elimination rules (elim):" (pretty_thms unsafeEs), |
42793 | 659 |
Pretty.strs ("safe wrappers:" :: map #1 swrappers), |
660 |
Pretty.strs ("unsafe wrappers:" :: map #1 uwrappers)] |
|
56334
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
wenzelm
parents:
54742
diff
changeset
|
661 |
|> Pretty.writeln_chunks |
42793 | 662 |
end; |
663 |
||
664 |
||
665 |
(* old-style declarations *) |
|
666 |
||
60945 | 667 |
fun decl f (ctxt, ths) = map_claset (fold_rev (f ctxt) ths) ctxt; |
42793 | 668 |
|
669 |
val op addSIs = decl (addSI NONE); |
|
670 |
val op addSEs = decl (addSE NONE); |
|
671 |
val op addSDs = decl (addSD NONE); |
|
672 |
val op addIs = decl (addI NONE); |
|
673 |
val op addEs = decl (addE NONE); |
|
674 |
val op addDs = decl (addD NONE); |
|
675 |
val op delrules = decl delrule; |
|
676 |
||
677 |
||
678 |
||
679 |
(*** Modifying the wrapper tacticals ***) |
|
680 |
||
681 |
fun appSWrappers ctxt = fold (fn (_, w) => w ctxt) (#swrappers (rep_claset_of ctxt)); |
|
682 |
fun appWrappers ctxt = fold (fn (_, w) => w ctxt) (#uwrappers (rep_claset_of ctxt)); |
|
683 |
||
684 |
fun update_warn msg (p as (key : string, _)) xs = |
|
685 |
(if AList.defined (op =) xs key then warning msg else (); AList.update (op =) p xs); |
|
686 |
||
687 |
fun delete_warn msg (key : string) xs = |
|
688 |
if AList.defined (op =) xs key then AList.delete (op =) key xs |
|
689 |
else (warning msg; xs); |
|
690 |
||
691 |
(*Add/replace a safe wrapper*) |
|
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
692 |
fun ctxt addSWrapper new_swrapper = ctxt |> map_claset |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
693 |
(map_swrappers (update_warn ("Overwriting safe wrapper " ^ fst new_swrapper) new_swrapper)); |
42793 | 694 |
|
695 |
(*Add/replace an unsafe wrapper*) |
|
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
696 |
fun ctxt addWrapper new_uwrapper = ctxt |> map_claset |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
697 |
(map_uwrappers (update_warn ("Overwriting unsafe wrapper " ^ fst new_uwrapper) new_uwrapper)); |
42793 | 698 |
|
699 |
(*Remove a safe wrapper*) |
|
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
700 |
fun ctxt delSWrapper name = ctxt |> map_claset |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
701 |
(map_swrappers (delete_warn ("No such safe wrapper in claset: " ^ name) name)); |
42793 | 702 |
|
703 |
(*Remove an unsafe wrapper*) |
|
51703
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
704 |
fun ctxt delWrapper name = ctxt |> map_claset |
f2e92fc0c8aa
modifiers for classical wrappers operate on Proof.context instead of claset;
wenzelm
parents:
51688
diff
changeset
|
705 |
(map_uwrappers (delete_warn ("No such unsafe wrapper in claset: " ^ name) name)); |
42793 | 706 |
|
707 |
(* compose a safe tactic alternatively before/after safe_step_tac *) |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
708 |
fun ctxt addSbefore (name, tac1) = |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
709 |
ctxt addSWrapper (name, fn ctxt => fn tac2 => tac1 ctxt ORELSE' tac2); |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
710 |
fun ctxt addSafter (name, tac2) = |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
711 |
ctxt addSWrapper (name, fn ctxt => fn tac1 => tac1 ORELSE' tac2 ctxt); |
42793 | 712 |
|
713 |
(*compose a tactic alternatively before/after the step tactic *) |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
714 |
fun ctxt addbefore (name, tac1) = |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
715 |
ctxt addWrapper (name, fn ctxt => fn tac2 => tac1 ctxt APPEND' tac2); |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
716 |
fun ctxt addafter (name, tac2) = |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
51703
diff
changeset
|
717 |
ctxt addWrapper (name, fn ctxt => fn tac1 => tac1 APPEND' tac2 ctxt); |
42793 | 718 |
|
58957 | 719 |
fun ctxt addD2 (name, thm) = |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
720 |
ctxt addafter (name, fn ctxt' => dresolve_tac ctxt' [thm] THEN' assume_tac ctxt'); |
58957 | 721 |
fun ctxt addE2 (name, thm) = |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
722 |
ctxt addafter (name, fn ctxt' => eresolve_tac ctxt' [thm] THEN' assume_tac ctxt'); |
58957 | 723 |
fun ctxt addSD2 (name, thm) = |
724 |
ctxt addSafter (name, fn ctxt' => dmatch_tac ctxt' [thm] THEN' eq_assume_tac); |
|
725 |
fun ctxt addSE2 (name, thm) = |
|
726 |
ctxt addSafter (name, fn ctxt' => ematch_tac ctxt' [thm] THEN' eq_assume_tac); |
|
42793 | 727 |
|
1711 | 728 |
|
982
4fe0b642b7d5
Addition of wrappers for integration with the simplifier.
lcp
parents:
747
diff
changeset
|
729 |
|
1800 | 730 |
(**** Simple tactics for theorem proving ****) |
0 | 731 |
|
732 |
(*Attack subgoals using safe inferences -- matching, not resolution*) |
|
42793 | 733 |
fun safe_step_tac ctxt = |
734 |
let val {safe0_netpair, safep_netpair, ...} = rep_claset_of ctxt in |
|
735 |
appSWrappers ctxt |
|
736 |
(FIRST' |
|
737 |
[eq_assume_tac, |
|
58957 | 738 |
eq_mp_tac ctxt, |
59164 | 739 |
bimatch_from_nets_tac ctxt safe0_netpair, |
51798 | 740 |
FIRST' (map (fn tac => tac ctxt) Data.hyp_subst_tacs), |
59164 | 741 |
bimatch_from_nets_tac ctxt safep_netpair]) |
42793 | 742 |
end; |
0 | 743 |
|
5757 | 744 |
(*Repeatedly attack a subgoal using safe inferences -- it's deterministic!*) |
42793 | 745 |
fun safe_steps_tac ctxt = |
746 |
REPEAT_DETERM1 o (fn i => COND (has_fewer_prems i) no_tac (safe_step_tac ctxt i)); |
|
5757 | 747 |
|
0 | 748 |
(*Repeatedly attack subgoals using safe inferences -- it's deterministic!*) |
42793 | 749 |
fun safe_tac ctxt = REPEAT_DETERM1 (FIRSTGOAL (safe_steps_tac ctxt)); |
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
750 |
|
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
751 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
752 |
(*** 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
|
753 |
|
42790 | 754 |
fun nsubgoalsP n (k, brl) = (subgoals_of_brl brl = n); |
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
755 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
756 |
(*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
|
757 |
create precisely n subgoals.*) |
59164 | 758 |
fun n_bimatch_from_nets_tac ctxt n = |
759 |
biresolution_from_nets_tac ctxt (order_list o filter (nsubgoalsP n)) true; |
|
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
760 |
|
58957 | 761 |
fun eq_contr_tac ctxt i = ematch_tac ctxt [Data.not_elim] i THEN eq_assume_tac i; |
762 |
fun eq_assume_contr_tac ctxt = eq_assume_tac ORELSE' eq_contr_tac ctxt; |
|
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
763 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
764 |
(*Two-way branching is allowed only if one of the branches immediately closes*) |
58957 | 765 |
fun bimatch2_tac ctxt netpair i = |
59164 | 766 |
n_bimatch_from_nets_tac ctxt 2 netpair i THEN |
58957 | 767 |
(eq_assume_contr_tac ctxt i ORELSE eq_assume_contr_tac ctxt (i + 1)); |
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
768 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
769 |
(*Attack subgoals using safe inferences -- matching, not resolution*) |
42793 | 770 |
fun clarify_step_tac ctxt = |
771 |
let val {safe0_netpair, safep_netpair, ...} = rep_claset_of ctxt in |
|
772 |
appSWrappers ctxt |
|
773 |
(FIRST' |
|
58957 | 774 |
[eq_assume_contr_tac ctxt, |
59164 | 775 |
bimatch_from_nets_tac ctxt safe0_netpair, |
51798 | 776 |
FIRST' (map (fn tac => tac ctxt) Data.hyp_subst_tacs), |
59164 | 777 |
n_bimatch_from_nets_tac ctxt 1 safep_netpair, |
58957 | 778 |
bimatch2_tac ctxt safep_netpair]) |
42793 | 779 |
end; |
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
780 |
|
42793 | 781 |
fun clarify_tac ctxt = SELECT_GOAL (REPEAT_DETERM (clarify_step_tac ctxt 1)); |
3705
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
782 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
783 |
|
76f3b2803982
Addition of clarify_tac, clarify_step_tac, Clarify_tac, Clarify_step_tac
paulson
parents:
3546
diff
changeset
|
784 |
(*** 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
|
785 |
|
4066 | 786 |
(*Backtracking is allowed among the various these unsafe ways of |
787 |
proving a subgoal. *) |
|
42793 | 788 |
fun inst0_step_tac ctxt = |
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58958
diff
changeset
|
789 |
assume_tac ctxt APPEND' |
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58958
diff
changeset
|
790 |
contr_tac ctxt APPEND' |
59164 | 791 |
biresolve_from_nets_tac ctxt (#safe0_netpair (rep_claset_of ctxt)); |
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
792 |
|
4066 | 793 |
(*These unsafe steps could generate more subgoals.*) |
42793 | 794 |
fun instp_step_tac ctxt = |
59164 | 795 |
biresolve_from_nets_tac ctxt (#safep_netpair (rep_claset_of ctxt)); |
0 | 796 |
|
797 |
(*These steps could instantiate variables and are therefore unsafe.*) |
|
42793 | 798 |
fun inst_step_tac ctxt = inst0_step_tac ctxt APPEND' instp_step_tac ctxt; |
0 | 799 |
|
60943 | 800 |
fun unsafe_step_tac ctxt = |
801 |
biresolve_from_nets_tac ctxt (#unsafe_netpair (rep_claset_of ctxt)); |
|
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
802 |
|
0 | 803 |
(*Single step for the prover. FAILS unless it makes progress. *) |
42793 | 804 |
fun step_tac ctxt i = |
60943 | 805 |
safe_tac ctxt ORELSE appWrappers ctxt (inst_step_tac ctxt ORELSE' unsafe_step_tac ctxt) i; |
0 | 806 |
|
807 |
(*Using a "safe" rule to instantiate variables is unsafe. This tactic |
|
808 |
allows backtracking from "safe" rules to "unsafe" rules here.*) |
|
42793 | 809 |
fun slow_step_tac ctxt i = |
60943 | 810 |
safe_tac ctxt ORELSE appWrappers ctxt (inst_step_tac ctxt APPEND' unsafe_step_tac ctxt) i; |
0 | 811 |
|
42791
36f787ae5f70
eliminated weight_ASTAR: int Unsynchronized.ref (astar_tac appears to be obsolete anyway);
wenzelm
parents:
42790
diff
changeset
|
812 |
|
1800 | 813 |
(**** The following tactics all fail unless they solve one goal ****) |
0 | 814 |
|
815 |
(*Dumb but fast*) |
|
42793 | 816 |
fun fast_tac ctxt = |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52732
diff
changeset
|
817 |
Object_Logic.atomize_prems_tac ctxt THEN' SELECT_GOAL (DEPTH_SOLVE (step_tac ctxt 1)); |
0 | 818 |
|
819 |
(*Slower but smarter than fast_tac*) |
|
42793 | 820 |
fun best_tac ctxt = |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52732
diff
changeset
|
821 |
Object_Logic.atomize_prems_tac ctxt THEN' |
42793 | 822 |
SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, Data.sizef) (step_tac ctxt 1)); |
0 | 823 |
|
9402 | 824 |
(*even a bit smarter than best_tac*) |
42793 | 825 |
fun first_best_tac ctxt = |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52732
diff
changeset
|
826 |
Object_Logic.atomize_prems_tac ctxt THEN' |
42793 | 827 |
SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, Data.sizef) (FIRSTGOAL (step_tac ctxt))); |
9402 | 828 |
|
42793 | 829 |
fun slow_tac ctxt = |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52732
diff
changeset
|
830 |
Object_Logic.atomize_prems_tac ctxt THEN' |
42793 | 831 |
SELECT_GOAL (DEPTH_SOLVE (slow_step_tac ctxt 1)); |
0 | 832 |
|
42793 | 833 |
fun slow_best_tac ctxt = |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52732
diff
changeset
|
834 |
Object_Logic.atomize_prems_tac ctxt THEN' |
42793 | 835 |
SELECT_GOAL (BEST_FIRST (has_fewer_prems 1, Data.sizef) (slow_step_tac ctxt 1)); |
0 | 836 |
|
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
837 |
|
10736 | 838 |
(***ASTAR with weight weight_ASTAR, by Norbert Voelker*) |
42791
36f787ae5f70
eliminated weight_ASTAR: int Unsynchronized.ref (astar_tac appears to be obsolete anyway);
wenzelm
parents:
42790
diff
changeset
|
839 |
|
36f787ae5f70
eliminated weight_ASTAR: int Unsynchronized.ref (astar_tac appears to be obsolete anyway);
wenzelm
parents:
42790
diff
changeset
|
840 |
val weight_ASTAR = 5; |
1587
e7d8a4957bac
Now provides astar versions (thanks to Norbert Voelker)
paulson
parents:
1524
diff
changeset
|
841 |
|
42793 | 842 |
fun astar_tac ctxt = |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52732
diff
changeset
|
843 |
Object_Logic.atomize_prems_tac ctxt THEN' |
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
844 |
SELECT_GOAL |
52462
a241826ed003
actually use Data.sizef, not hardwired size_of_thm;
wenzelm
parents:
51798
diff
changeset
|
845 |
(ASTAR (has_fewer_prems 1, fn lev => fn thm => Data.sizef thm + weight_ASTAR * lev) |
42793 | 846 |
(step_tac ctxt 1)); |
1587
e7d8a4957bac
Now provides astar versions (thanks to Norbert Voelker)
paulson
parents:
1524
diff
changeset
|
847 |
|
42793 | 848 |
fun slow_astar_tac ctxt = |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52732
diff
changeset
|
849 |
Object_Logic.atomize_prems_tac ctxt THEN' |
10382
1fb807260ff1
atomize: all automated tactics that "solve" goals;
wenzelm
parents:
10309
diff
changeset
|
850 |
SELECT_GOAL |
52462
a241826ed003
actually use Data.sizef, not hardwired size_of_thm;
wenzelm
parents:
51798
diff
changeset
|
851 |
(ASTAR (has_fewer_prems 1, fn lev => fn thm => Data.sizef thm + weight_ASTAR * lev) |
42793 | 852 |
(slow_step_tac ctxt 1)); |
1587
e7d8a4957bac
Now provides astar versions (thanks to Norbert Voelker)
paulson
parents:
1524
diff
changeset
|
853 |
|
42790 | 854 |
|
1800 | 855 |
(**** 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
|
856 |
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
|
857 |
easy theorems faster, but loses completeness -- and many of the harder |
1800 | 858 |
theorems such as 43. ****) |
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
859 |
|
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
860 |
(*Non-deterministic! Could always expand the first unsafe connective. |
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
861 |
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
|
862 |
greater search depth required.*) |
42793 | 863 |
fun dup_step_tac ctxt = |
59164 | 864 |
biresolve_from_nets_tac ctxt (#dup_netpair (rep_claset_of ctxt)); |
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
865 |
|
5523 | 866 |
(*Searching to depth m. A variant called nodup_depth_tac appears in clasimp.ML*) |
5757 | 867 |
local |
42793 | 868 |
fun slow_step_tac' ctxt = appWrappers ctxt (instp_step_tac ctxt APPEND' dup_step_tac ctxt); |
42790 | 869 |
in |
42793 | 870 |
fun depth_tac ctxt m i state = SELECT_GOAL |
871 |
(safe_steps_tac ctxt 1 THEN_ELSE |
|
872 |
(DEPTH_SOLVE (depth_tac ctxt m 1), |
|
873 |
inst0_step_tac ctxt 1 APPEND COND (K (m = 0)) no_tac |
|
874 |
(slow_step_tac' ctxt 1 THEN DEPTH_SOLVE (depth_tac ctxt (m - 1) 1)))) i state; |
|
5757 | 875 |
end; |
747
bdc066781063
deepen_tac: modified due to outcome of experiments. Its
lcp
parents:
681
diff
changeset
|
876 |
|
10736 | 877 |
(*Search, with depth bound m. |
2173 | 878 |
This is the "entry point", which does safe inferences first.*) |
42793 | 879 |
fun safe_depth_tac ctxt m = SUBGOAL (fn (prem, i) => |
880 |
let |
|
881 |
val deti = (*No Vars in the goal? No need to backtrack between goals.*) |
|
882 |
if exists_subterm (fn Var _ => true | _ => false) prem then DETERM else I; |
|
42790 | 883 |
in |
42793 | 884 |
SELECT_GOAL (TRY (safe_tac ctxt) THEN DEPTH_SOLVE (deti (depth_tac ctxt m 1))) i |
42790 | 885 |
end); |
681
9b02474744ca
Provers/classical: now takes theorem "classical" as argument, proves "swap"
lcp
parents:
469
diff
changeset
|
886 |
|
42793 | 887 |
fun deepen_tac ctxt = DEEPEN (2, 10) (safe_depth_tac ctxt); |
24021 | 888 |
|
889 |
||
5885 | 890 |
(* attributes *) |
891 |
||
42793 | 892 |
fun attrib f = |
60945 | 893 |
Thm.declaration_attribute (fn th => fn context => |
894 |
map_cs (f (Context.proof_of context) th) context); |
|
5885 | 895 |
|
18691 | 896 |
val safe_elim = attrib o addSE; |
897 |
val safe_intro = attrib o addSI; |
|
42793 | 898 |
val safe_dest = attrib o addSD; |
60943 | 899 |
val unsafe_elim = attrib o addE; |
900 |
val unsafe_intro = attrib o addI; |
|
901 |
val unsafe_dest = attrib o addD; |
|
45375
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents:
42817
diff
changeset
|
902 |
|
7fe19930dfc9
more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents:
42817
diff
changeset
|
903 |
val rule_del = |
60945 | 904 |
Thm.declaration_attribute (fn th => fn context => |
905 |
context |
|
906 |
|> map_cs (delrule (Context.proof_of context) th) |
|
907 |
|> Thm.attribute_declaration Context_Rules.rule_del th); |
|
5885 | 908 |
|
909 |
||
5841 | 910 |
|
5885 | 911 |
(** concrete syntax of attributes **) |
5841 | 912 |
|
913 |
val introN = "intro"; |
|
914 |
val elimN = "elim"; |
|
915 |
val destN = "dest"; |
|
916 |
||
58826 | 917 |
val _ = |
918 |
Theory.setup |
|
919 |
(Attrib.setup @{binding swapped} (Scan.succeed swapped) |
|
920 |
"classical swap of introduction rule" #> |
|
60943 | 921 |
Attrib.setup @{binding dest} (Context_Rules.add safe_dest unsafe_dest Context_Rules.dest_query) |
58826 | 922 |
"declaration of Classical destruction rule" #> |
60943 | 923 |
Attrib.setup @{binding elim} (Context_Rules.add safe_elim unsafe_elim Context_Rules.elim_query) |
58826 | 924 |
"declaration of Classical elimination rule" #> |
60943 | 925 |
Attrib.setup @{binding intro} (Context_Rules.add safe_intro unsafe_intro Context_Rules.intro_query) |
58826 | 926 |
"declaration of Classical introduction rule" #> |
927 |
Attrib.setup @{binding rule} (Scan.lift Args.del >> K rule_del) |
|
928 |
"remove declaration of intro/elim/dest rule"); |
|
5841 | 929 |
|
930 |
||
931 |
||
7230 | 932 |
(** proof methods **) |
933 |
||
934 |
local |
|
935 |
||
30609
983e8b6e4e69
Disposed old declarations, tactics, tactic combinators that refer to the simpset or claset of an implicit theory;
wenzelm
parents:
30558
diff
changeset
|
936 |
fun some_rule_tac ctxt facts = SUBGOAL (fn (goal, i) => |
5841 | 937 |
let |
33369 | 938 |
val [rules1, rules2, rules4] = Context_Rules.find_rules false facts goal ctxt; |
60942 | 939 |
val {extra_netpair, ...} = rep_claset_of ctxt; |
940 |
val rules3 = Context_Rules.find_rules_netpair true facts goal extra_netpair; |
|
12376
480303e3fa08
simplified (and clarified) integration with Pure/ContextRules;
wenzelm
parents:
12362
diff
changeset
|
941 |
val rules = rules1 @ rules2 @ rules3 @ rules4; |
58950
d07464875dd4
optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents:
58893
diff
changeset
|
942 |
val ruleq = Drule.multi_resolves (SOME ctxt) facts rules; |
52732 | 943 |
val _ = Method.trace ctxt rules; |
12376
480303e3fa08
simplified (and clarified) integration with Pure/ContextRules;
wenzelm
parents:
12362
diff
changeset
|
944 |
in |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
945 |
fn st => Seq.maps (fn rule => resolve_tac ctxt [rule] i st) ruleq |
18834 | 946 |
end) |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52732
diff
changeset
|
947 |
THEN_ALL_NEW Goal.norm_hhf_tac ctxt; |
5841 | 948 |
|
30609
983e8b6e4e69
Disposed old declarations, tactics, tactic combinators that refer to the simpset or claset of an implicit theory;
wenzelm
parents:
30558
diff
changeset
|
949 |
in |
7281 | 950 |
|
30609
983e8b6e4e69
Disposed old declarations, tactics, tactic combinators that refer to the simpset or claset of an implicit theory;
wenzelm
parents:
30558
diff
changeset
|
951 |
fun rule_tac ctxt [] facts = some_rule_tac ctxt facts |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
52732
diff
changeset
|
952 |
| rule_tac ctxt rules facts = Method.rule_tac ctxt rules facts; |
30609
983e8b6e4e69
Disposed old declarations, tactics, tactic combinators that refer to the simpset or claset of an implicit theory;
wenzelm
parents:
30558
diff
changeset
|
953 |
|
60619
7512716f03db
no arguments for "standard" (or old "default") methods;
wenzelm
parents:
60618
diff
changeset
|
954 |
fun standard_tac ctxt facts = |
7512716f03db
no arguments for "standard" (or old "default") methods;
wenzelm
parents:
60618
diff
changeset
|
955 |
HEADGOAL (some_rule_tac ctxt facts) ORELSE |
60618
4c79543cc376
renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents:
60097
diff
changeset
|
956 |
Class.standard_intro_classes_tac ctxt facts; |
4c79543cc376
renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents:
60097
diff
changeset
|
957 |
|
60619
7512716f03db
no arguments for "standard" (or old "default") methods;
wenzelm
parents:
60618
diff
changeset
|
958 |
fun default_tac ctxt facts st = |
60618
4c79543cc376
renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents:
60097
diff
changeset
|
959 |
(if Method.detect_closure_state st then |
4c79543cc376
renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents:
60097
diff
changeset
|
960 |
legacy_feature |
4c79543cc376
renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents:
60097
diff
changeset
|
961 |
("Old method \"default\"; use \"standard\" instead" ^ Position.here (Position.thread_data ())) |
4c79543cc376
renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents:
60097
diff
changeset
|
962 |
else (); |
60619
7512716f03db
no arguments for "standard" (or old "default") methods;
wenzelm
parents:
60618
diff
changeset
|
963 |
standard_tac ctxt facts st); |
10309 | 964 |
|
7230 | 965 |
end; |
5841 | 966 |
|
967 |
||
6502 | 968 |
(* automatic methods *) |
5841 | 969 |
|
5927 | 970 |
val cla_modifiers = |
58048
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
57859
diff
changeset
|
971 |
[Args.$$$ destN -- Args.bang_colon >> K (Method.modifier (safe_dest NONE) @{here}), |
60943 | 972 |
Args.$$$ destN -- Args.colon >> K (Method.modifier (unsafe_dest NONE) @{here}), |
58048
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
57859
diff
changeset
|
973 |
Args.$$$ elimN -- Args.bang_colon >> K (Method.modifier (safe_elim NONE) @{here}), |
60943 | 974 |
Args.$$$ elimN -- Args.colon >> K (Method.modifier (unsafe_elim NONE) @{here}), |
58048
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
57859
diff
changeset
|
975 |
Args.$$$ introN -- Args.bang_colon >> K (Method.modifier (safe_intro NONE) @{here}), |
60943 | 976 |
Args.$$$ introN -- Args.colon >> K (Method.modifier (unsafe_intro NONE) @{here}), |
58048
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
57859
diff
changeset
|
977 |
Args.del -- Args.colon >> K (Method.modifier rule_del @{here})]; |
5927 | 978 |
|
42793 | 979 |
fun cla_method tac = Method.sections cla_modifiers >> K (SIMPLE_METHOD o tac); |
980 |
fun cla_method' tac = Method.sections cla_modifiers >> K (SIMPLE_METHOD' o tac); |
|
5841 | 981 |
|
982 |
||
983 |
||
58826 | 984 |
(** method setup **) |
5841 | 985 |
|
58826 | 986 |
val _ = |
987 |
Theory.setup |
|
60619
7512716f03db
no arguments for "standard" (or old "default") methods;
wenzelm
parents:
60618
diff
changeset
|
988 |
(Method.setup @{binding standard} (Scan.succeed (METHOD o standard_tac)) |
60618
4c79543cc376
renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents:
60097
diff
changeset
|
989 |
"standard proof step: classical intro/elim rule or class introduction" #> |
60619
7512716f03db
no arguments for "standard" (or old "default") methods;
wenzelm
parents:
60618
diff
changeset
|
990 |
Method.setup @{binding default} (Scan.succeed (METHOD o default_tac)) |
60618
4c79543cc376
renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents:
60097
diff
changeset
|
991 |
"standard proof step: classical intro/elim rule or class introduction (legacy)" #> |
58826 | 992 |
Method.setup @{binding rule} |
993 |
(Attrib.thms >> (fn rules => fn ctxt => METHOD (HEADGOAL o rule_tac ctxt rules))) |
|
994 |
"apply some intro/elim rule (potentially classical)" #> |
|
995 |
Method.setup @{binding contradiction} |
|
996 |
(Scan.succeed (fn ctxt => Method.rule ctxt [Data.not_elim, Drule.rotate_prems 1 Data.not_elim])) |
|
997 |
"proof by contradiction" #> |
|
998 |
Method.setup @{binding clarify} (cla_method' (CHANGED_PROP oo clarify_tac)) |
|
999 |
"repeatedly apply safe steps" #> |
|
1000 |
Method.setup @{binding fast} (cla_method' fast_tac) "classical prover (depth-first)" #> |
|
1001 |
Method.setup @{binding slow} (cla_method' slow_tac) "classical prover (slow depth-first)" #> |
|
1002 |
Method.setup @{binding best} (cla_method' best_tac) "classical prover (best-first)" #> |
|
1003 |
Method.setup @{binding deepen} |
|
1004 |
(Scan.lift (Scan.optional Parse.nat 4) --| Method.sections cla_modifiers |
|
1005 |
>> (fn n => fn ctxt => SIMPLE_METHOD' (deepen_tac ctxt n))) |
|
1006 |
"classical prover (iterative deepening)" #> |
|
1007 |
Method.setup @{binding safe} (cla_method (CHANGED_PROP o safe_tac)) |
|
1008 |
"classical prover (apply safe rules)" #> |
|
1009 |
Method.setup @{binding safe_step} (cla_method' safe_step_tac) |
|
1010 |
"single classical step (safe rules)" #> |
|
1011 |
Method.setup @{binding inst_step} (cla_method' inst_step_tac) |
|
1012 |
"single classical step (safe rules, allow instantiations)" #> |
|
1013 |
Method.setup @{binding step} (cla_method' step_tac) |
|
1014 |
"single classical step (safe and unsafe rules)" #> |
|
1015 |
Method.setup @{binding slow_step} (cla_method' slow_step_tac) |
|
1016 |
"single classical step (safe and unsafe rules, allow backtracking)" #> |
|
1017 |
Method.setup @{binding clarify_step} (cla_method' clarify_step_tac) |
|
1018 |
"single classical step (safe rules, without splitting)"); |
|
5841 | 1019 |
|
8667 | 1020 |
|
1021 |
(** outer syntax **) |
|
1022 |
||
24867 | 1023 |
val _ = |
59936
b8ffc3dc9e24
@{command_spec} is superseded by @{command_keyword};
wenzelm
parents:
59582
diff
changeset
|
1024 |
Outer_Syntax.command @{command_keyword print_claset} "print context of Classical Reasoner" |
60097
d20ca79d50e4
discontinued pointless warnings: commands are only defined inside a theory context;
wenzelm
parents:
59970
diff
changeset
|
1025 |
(Scan.succeed (Toplevel.keep (print_claset o Toplevel.context_of))); |
8667 | 1026 |
|
5841 | 1027 |
end; |