author | wenzelm |
Sun, 01 Nov 2009 15:44:26 +0100 | |
changeset 33369 | 470a7b233ee5 |
parent 33159 | 369da293bbd4 |
child 33519 | e31a85f92ce9 |
permissions | -rw-r--r-- |
5824 | 1 |
(* Title: Pure/Isar/method.ML |
2 |
Author: Markus Wenzel, TU Muenchen |
|
3 |
||
17110 | 4 |
Isar proof methods. |
5824 | 5 |
*) |
6 |
||
7 |
signature BASIC_METHOD = |
|
8 |
sig |
|
17110 | 9 |
val FINDGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq |
10 |
val HEADGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq |
|
32738 | 11 |
val trace_rules: bool Unsynchronized.ref |
5824 | 12 |
end; |
13 |
||
14 |
signature METHOD = |
|
15 |
sig |
|
16 |
include BASIC_METHOD |
|
30508
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
17 |
type method |
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
18 |
val apply: (Proof.context -> method) -> Proof.context -> thm list -> cases_tactic |
18227 | 19 |
val RAW_METHOD_CASES: (thm list -> cases_tactic) -> method |
17110 | 20 |
val RAW_METHOD: (thm list -> tactic) -> method |
18227 | 21 |
val METHOD_CASES: (thm list -> cases_tactic) -> method |
17110 | 22 |
val METHOD: (thm list -> tactic) -> method |
23 |
val fail: method |
|
24 |
val succeed: method |
|
25 |
val insert_tac: thm list -> int -> tactic |
|
26 |
val insert: thm list -> method |
|
27 |
val insert_facts: method |
|
28 |
val SIMPLE_METHOD: tactic -> method |
|
21592 | 29 |
val SIMPLE_METHOD': (int -> tactic) -> method |
30 |
val SIMPLE_METHOD'': ((int -> tactic) -> tactic) -> (int -> tactic) -> method |
|
17110 | 31 |
val defer: int option -> method |
32 |
val prefer: int -> method |
|
20289 | 33 |
val cheating: bool -> Proof.context -> method |
17110 | 34 |
val intro: thm list -> method |
35 |
val elim: thm list -> method |
|
20289 | 36 |
val unfold: thm list -> Proof.context -> method |
37 |
val fold: thm list -> Proof.context -> method |
|
17110 | 38 |
val atomize: bool -> method |
39 |
val this: method |
|
20289 | 40 |
val fact: thm list -> Proof.context -> method |
30234
7dd251bce291
renamed Method.assumption_tac back to Method.assm_tac -- as assumption_tac it would have to be exactly the tactic behind the assumption method (with facts);
wenzelm
parents:
30190
diff
changeset
|
41 |
val assm_tac: Proof.context -> int -> tactic |
30567
cd8e20f86795
close/all_assm_tac: finish all subgoals from left to right (cf. Proof.goal_tac a28d83e903ce) -- NB: ALLGOALS/THEN_ALL_NEW operate from right to left;
wenzelm
parents:
30544
diff
changeset
|
42 |
val all_assm_tac: Proof.context -> tactic |
20289 | 43 |
val assumption: Proof.context -> method |
44 |
val close: bool -> Proof.context -> method |
|
45 |
val trace: Proof.context -> thm list -> unit |
|
6091 | 46 |
val rule_tac: thm list -> thm list -> int -> tactic |
20289 | 47 |
val some_rule_tac: thm list -> Proof.context -> thm list -> int -> tactic |
25270 | 48 |
val intros_tac: thm list -> thm list -> tactic |
17110 | 49 |
val rule: thm list -> method |
50 |
val erule: int -> thm list -> method |
|
51 |
val drule: int -> thm list -> method |
|
52 |
val frule: int -> thm list -> method |
|
27235 | 53 |
val set_tactic: (thm list -> tactic) -> Proof.context -> Proof.context |
26385
ae7564661e76
ML runtime compilation: pass position, tuned signature;
wenzelm
parents:
26291
diff
changeset
|
54 |
val tactic: string * Position.T -> Proof.context -> method |
27235 | 55 |
val raw_tactic: string * Position.T -> Proof.context -> method |
27729 | 56 |
type src = Args.src |
5824 | 57 |
datatype text = |
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
58 |
Basic of Proof.context -> method | |
15703 | 59 |
Source of src | |
20030 | 60 |
Source_i of src | |
5824 | 61 |
Then of text list | |
62 |
Orelse of text list | |
|
63 |
Try of text | |
|
19186 | 64 |
Repeat1 of text | |
65 |
SelectGoals of int * text |
|
17857 | 66 |
val primitive_text: (thm -> thm) -> text |
67 |
val succeed_text: text |
|
17110 | 68 |
val default_text: text |
69 |
val this_text: text |
|
70 |
val done_text: text |
|
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
71 |
val sorry_text: bool -> text |
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
72 |
val finish_text: text option * bool -> text |
27729 | 73 |
val print_methods: theory -> unit |
26892 | 74 |
val intern: theory -> xstring -> string |
75 |
val defined: theory -> string -> bool |
|
20289 | 76 |
val method: theory -> src -> Proof.context -> method |
77 |
val method_i: theory -> src -> Proof.context -> method |
|
30512 | 78 |
val syntax: 'a context_parser -> src -> Proof.context -> 'a * Proof.context |
79 |
val setup: binding -> (Proof.context -> method) context_parser -> string -> theory -> theory |
|
30575 | 80 |
val method_setup: bstring * Position.T -> Symbol_Pos.text * Position.T -> string -> |
81 |
theory -> theory |
|
30540 | 82 |
type modifier = (Proof.context -> Proof.context) * attribute |
83 |
val section: modifier parser list -> thm list context_parser |
|
84 |
val sections: modifier parser list -> thm list list context_parser |
|
30512 | 85 |
val parse: text parser |
5824 | 86 |
end; |
87 |
||
88 |
structure Method: METHOD = |
|
89 |
struct |
|
90 |
||
17110 | 91 |
(** generic tools **) |
92 |
||
93 |
(* goal addressing *) |
|
94 |
||
95 |
fun FINDGOAL tac st = |
|
96 |
let fun find i n = if i > n then Seq.fail else Seq.APPEND (tac i, find (i + 1) n) |
|
97 |
in find 1 (Thm.nprems_of st) st end; |
|
98 |
||
99 |
fun HEADGOAL tac = tac 1; |
|
100 |
||
101 |
||
5824 | 102 |
|
12324
5db4b4596d1a
rule context and attributes moved to rule_context.ML;
wenzelm
parents:
12311
diff
changeset
|
103 |
(** proof methods **) |
5db4b4596d1a
rule context and attributes moved to rule_context.ML;
wenzelm
parents:
12311
diff
changeset
|
104 |
|
17110 | 105 |
(* datatype method *) |
11731 | 106 |
|
18227 | 107 |
datatype method = Meth of thm list -> cases_tactic; |
11731 | 108 |
|
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
109 |
fun apply meth ctxt = let val Meth m = meth ctxt in m end; |
11731 | 110 |
|
17756 | 111 |
val RAW_METHOD_CASES = Meth; |
11731 | 112 |
|
17110 | 113 |
fun RAW_METHOD tac = RAW_METHOD_CASES (NO_CASES o tac); |
12144 | 114 |
|
17110 | 115 |
fun METHOD_CASES tac = RAW_METHOD_CASES (fn facts => |
21687 | 116 |
Seq.THEN (ALLGOALS Goal.conjunction_tac, tac facts)); |
8372 | 117 |
|
21687 | 118 |
fun METHOD tac = RAW_METHOD (fn facts => ALLGOALS Goal.conjunction_tac THEN tac facts); |
5824 | 119 |
|
120 |
val fail = METHOD (K no_tac); |
|
121 |
val succeed = METHOD (K all_tac); |
|
122 |
||
123 |
||
17110 | 124 |
(* insert facts *) |
7419 | 125 |
|
126 |
local |
|
5824 | 127 |
|
21579 | 128 |
fun cut_rule_tac rule = |
129 |
Tactic.rtac (Drule.forall_intr_vars rule COMP_INCR revcut_rl); |
|
6981 | 130 |
|
7419 | 131 |
in |
5824 | 132 |
|
7419 | 133 |
fun insert_tac [] i = all_tac |
134 |
| insert_tac facts i = EVERY (map (fn th => cut_rule_tac th i) facts); |
|
6981 | 135 |
|
7555 | 136 |
val insert_facts = METHOD (ALLGOALS o insert_tac); |
7664 | 137 |
fun insert thms = METHOD (fn _ => ALLGOALS (insert_tac thms)); |
7419 | 138 |
|
9706 | 139 |
fun SIMPLE_METHOD tac = METHOD (fn facts => ALLGOALS (insert_tac facts) THEN tac); |
21592 | 140 |
fun SIMPLE_METHOD'' quant tac = METHOD (fn facts => quant (insert_tac facts THEN' tac)); |
141 |
val SIMPLE_METHOD' = SIMPLE_METHOD'' HEADGOAL; |
|
9706 | 142 |
|
12324
5db4b4596d1a
rule context and attributes moved to rule_context.ML;
wenzelm
parents:
12311
diff
changeset
|
143 |
end; |
5db4b4596d1a
rule context and attributes moved to rule_context.ML;
wenzelm
parents:
12311
diff
changeset
|
144 |
|
9706 | 145 |
|
17110 | 146 |
(* shuffle subgoals *) |
147 |
||
148 |
fun prefer i = METHOD (K (Tactic.defer_tac i THEN PRIMITIVE (Thm.permute_prems 0 ~1))); |
|
18939 | 149 |
fun defer opt_i = METHOD (K (Tactic.defer_tac (the_default 1 opt_i))); |
17110 | 150 |
|
151 |
||
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
152 |
(* cheating *) |
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
153 |
|
32969 | 154 |
fun cheating int ctxt = |
155 |
if int orelse ! quick_and_dirty then |
|
156 |
METHOD (K (Skip_Proof.cheat_tac (ProofContext.theory_of ctxt))) |
|
157 |
else error "Cheating requires quick_and_dirty mode!"; |
|
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
158 |
|
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
159 |
|
17110 | 160 |
(* unfold intro/elim rules *) |
161 |
||
21592 | 162 |
fun intro ths = SIMPLE_METHOD' (CHANGED_PROP o REPEAT_ALL_NEW (Tactic.match_tac ths)); |
163 |
fun elim ths = SIMPLE_METHOD' (CHANGED_PROP o REPEAT_ALL_NEW (Tactic.ematch_tac ths)); |
|
17110 | 164 |
|
165 |
||
12384 | 166 |
(* unfold/fold definitions *) |
167 |
||
18877 | 168 |
fun unfold_meth ths ctxt = SIMPLE_METHOD (CHANGED_PROP (LocalDefs.unfold_tac ctxt ths)); |
169 |
fun fold_meth ths ctxt = SIMPLE_METHOD (CHANGED_PROP (LocalDefs.fold_tac ctxt ths)); |
|
6532 | 170 |
|
12384 | 171 |
|
12829 | 172 |
(* atomize rule statements *) |
173 |
||
23590
ad95084a5c63
renamed ObjectLogic.atomize_tac to ObjectLogic.atomize_prems_tac;
wenzelm
parents:
23577
diff
changeset
|
174 |
fun atomize false = SIMPLE_METHOD' (CHANGED_PROP o ObjectLogic.atomize_prems_tac) |
12829 | 175 |
| atomize true = RAW_METHOD (K (HEADGOAL (CHANGED_PROP o ObjectLogic.full_atomize_tac))); |
176 |
||
177 |
||
18039 | 178 |
(* this -- resolve facts directly *) |
12384 | 179 |
|
17110 | 180 |
val this = METHOD (EVERY o map (HEADGOAL o Tactic.rtac)); |
9484 | 181 |
|
182 |
||
18039 | 183 |
(* fact -- composition by facts from context *) |
184 |
||
21592 | 185 |
fun fact [] ctxt = SIMPLE_METHOD' (ProofContext.some_fact_tac ctxt) |
186 |
| fact rules _ = SIMPLE_METHOD' (ProofContext.fact_tac rules); |
|
18039 | 187 |
|
188 |
||
17110 | 189 |
(* assumption *) |
7419 | 190 |
|
191 |
local |
|
192 |
||
19778 | 193 |
fun cond_rtac cond rule = SUBGOAL (fn (prop, i) => |
194 |
if cond (Logic.strip_assums_concl prop) |
|
195 |
then Tactic.rtac rule i else no_tac); |
|
7419 | 196 |
|
29857
2cc976ed8a3c
FindTheorems: add solves feature; tidy up const name subsettin; patch by Timothy Bourke
kleing
parents:
29301
diff
changeset
|
197 |
in |
2cc976ed8a3c
FindTheorems: add solves feature; tidy up const name subsettin; patch by Timothy Bourke
kleing
parents:
29301
diff
changeset
|
198 |
|
30234
7dd251bce291
renamed Method.assumption_tac back to Method.assm_tac -- as assumption_tac it would have to be exactly the tactic behind the assumption method (with facts);
wenzelm
parents:
30190
diff
changeset
|
199 |
fun assm_tac ctxt = |
17110 | 200 |
assume_tac APPEND' |
23349 | 201 |
Goal.assume_rule_tac ctxt APPEND' |
19778 | 202 |
cond_rtac (can Logic.dest_equals) Drule.reflexive_thm APPEND' |
203 |
cond_rtac (can Logic.dest_term) Drule.termI; |
|
17110 | 204 |
|
30567
cd8e20f86795
close/all_assm_tac: finish all subgoals from left to right (cf. Proof.goal_tac a28d83e903ce) -- NB: ALLGOALS/THEN_ALL_NEW operate from right to left;
wenzelm
parents:
30544
diff
changeset
|
205 |
fun all_assm_tac ctxt st = EVERY1 (replicate (Thm.nprems_of st) (assm_tac ctxt)) st; |
cd8e20f86795
close/all_assm_tac: finish all subgoals from left to right (cf. Proof.goal_tac a28d83e903ce) -- NB: ALLGOALS/THEN_ALL_NEW operate from right to left;
wenzelm
parents:
30544
diff
changeset
|
206 |
|
23349 | 207 |
fun assumption ctxt = METHOD (HEADGOAL o |
30234
7dd251bce291
renamed Method.assumption_tac back to Method.assm_tac -- as assumption_tac it would have to be exactly the tactic behind the assumption method (with facts);
wenzelm
parents:
30190
diff
changeset
|
208 |
(fn [] => assm_tac ctxt |
23349 | 209 |
| [fact] => solve_tac [fact] |
210 |
| _ => K no_tac)); |
|
211 |
||
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
212 |
fun close immed ctxt = METHOD (K |
30567
cd8e20f86795
close/all_assm_tac: finish all subgoals from left to right (cf. Proof.goal_tac a28d83e903ce) -- NB: ALLGOALS/THEN_ALL_NEW operate from right to left;
wenzelm
parents:
30544
diff
changeset
|
213 |
(FILTER Thm.no_prems ((if immed then all_assm_tac ctxt else all_tac) THEN flexflex_tac))); |
7419 | 214 |
|
215 |
end; |
|
216 |
||
217 |
||
17110 | 218 |
(* rule etc. -- single-step refinements *) |
12347 | 219 |
|
32738 | 220 |
val trace_rules = Unsynchronized.ref false; |
12347 | 221 |
|
17110 | 222 |
fun trace ctxt rules = |
21962 | 223 |
if ! trace_rules andalso not (null rules) then |
32091
30e2ffbba718
proper context for Display.pretty_thm etc. or old-style versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
wenzelm
parents:
31304
diff
changeset
|
224 |
Pretty.big_list "rules:" (map (Display.pretty_thm ctxt) rules) |
21962 | 225 |
|> Pretty.string_of |> tracing |
226 |
else (); |
|
12347 | 227 |
|
228 |
local |
|
229 |
||
18841 | 230 |
fun gen_rule_tac tac rules facts = |
231 |
(fn i => fn st => |
|
232 |
if null facts then tac rules i st |
|
233 |
else Seq.maps (fn rule => (tac o single) rule i st) (Drule.multi_resolves facts rules)) |
|
21687 | 234 |
THEN_ALL_NEW Goal.norm_hhf_tac; |
7130 | 235 |
|
10744 | 236 |
fun gen_arule_tac tac j rules facts = |
237 |
EVERY' (gen_rule_tac tac rules facts :: replicate j Tactic.assume_tac); |
|
238 |
||
11785 | 239 |
fun gen_some_rule_tac tac arg_rules ctxt facts = SUBGOAL (fn (goal, i) => |
240 |
let |
|
241 |
val rules = |
|
242 |
if not (null arg_rules) then arg_rules |
|
33369 | 243 |
else flat (Context_Rules.find_rules false facts goal ctxt) |
12055 | 244 |
in trace ctxt rules; tac rules facts i end); |
10309 | 245 |
|
10744 | 246 |
fun meth tac x = METHOD (HEADGOAL o tac x); |
247 |
fun meth' tac x y = METHOD (HEADGOAL o tac x y); |
|
8220 | 248 |
|
7419 | 249 |
in |
250 |
||
10744 | 251 |
val rule_tac = gen_rule_tac Tactic.resolve_tac; |
252 |
val rule = meth rule_tac; |
|
253 |
val some_rule_tac = gen_some_rule_tac rule_tac; |
|
254 |
val some_rule = meth' some_rule_tac; |
|
255 |
||
256 |
val erule = meth' (gen_arule_tac Tactic.eresolve_tac); |
|
257 |
val drule = meth' (gen_arule_tac Tactic.dresolve_tac); |
|
258 |
val frule = meth' (gen_arule_tac Tactic.forward_tac); |
|
5824 | 259 |
|
7419 | 260 |
end; |
261 |
||
262 |
||
25270 | 263 |
(* intros_tac -- pervasive search spanned by intro rules *) |
264 |
||
265 |
fun intros_tac intros facts = |
|
266 |
ALLGOALS (insert_tac facts THEN' |
|
267 |
REPEAT_ALL_NEW (resolve_tac intros)) |
|
268 |
THEN Tactic.distinct_subgoals_tac; |
|
269 |
||
270 |
||
8351 | 271 |
(* ML tactics *) |
272 |
||
26472
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
273 |
structure TacticData = ProofDataFun |
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
274 |
( |
27235 | 275 |
type T = thm list -> tactic; |
26472
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
276 |
fun init _ = undefined; |
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
277 |
); |
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
278 |
|
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
279 |
val set_tactic = TacticData.put; |
8351 | 280 |
|
26472
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
281 |
fun ml_tactic (txt, pos) ctxt = |
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
282 |
let |
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
283 |
val ctxt' = ctxt |> Context.proof_map |
27235 | 284 |
(ML_Context.expression pos |
285 |
"fun tactic (facts: thm list) : tactic" |
|
26472
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
286 |
"Context.map_proof (Method.set_tactic tactic)" txt); |
27235 | 287 |
in Context.setmp_thread_data (SOME (Context.Proof ctxt)) (TacticData.get ctxt') end; |
23425 | 288 |
|
289 |
fun tactic txt ctxt = METHOD (ml_tactic txt ctxt); |
|
290 |
fun raw_tactic txt ctxt = RAW_METHOD (ml_tactic txt ctxt); |
|
8351 | 291 |
|
292 |
||
5824 | 293 |
|
17110 | 294 |
(** method syntax **) |
295 |
||
296 |
(* method text *) |
|
297 |
||
298 |
type src = Args.src; |
|
5824 | 299 |
|
17110 | 300 |
datatype text = |
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
301 |
Basic of Proof.context -> method | |
17110 | 302 |
Source of src | |
20030 | 303 |
Source_i of src | |
17110 | 304 |
Then of text list | |
305 |
Orelse of text list | |
|
306 |
Try of text | |
|
19186 | 307 |
Repeat1 of text | |
308 |
SelectGoals of int * text; |
|
17110 | 309 |
|
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
310 |
fun primitive_text r = Basic (K (SIMPLE_METHOD (PRIMITIVE r))); |
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
311 |
val succeed_text = Basic (K succeed); |
17110 | 312 |
val default_text = Source (Args.src (("default", []), Position.none)); |
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
313 |
val this_text = Basic (K this); |
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
314 |
val done_text = Basic (K (SIMPLE_METHOD all_tac)); |
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
315 |
fun sorry_text int = Basic (cheating int); |
17110 | 316 |
|
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
317 |
fun finish_text (NONE, immed) = Basic (close immed) |
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
318 |
| finish_text (SOME txt, immed) = Then [txt, Basic (close immed)]; |
17110 | 319 |
|
320 |
||
321 |
(* method definitions *) |
|
5824 | 322 |
|
24116 | 323 |
structure Methods = TheoryDataFun |
22846 | 324 |
( |
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33092
diff
changeset
|
325 |
type T = ((src -> Proof.context -> method) * string) Name_Space.table; |
33159 | 326 |
val empty : T = Name_Space.empty_table "method"; |
6546 | 327 |
val copy = I; |
16448 | 328 |
val extend = I; |
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33092
diff
changeset
|
329 |
fun merge _ tables : T = Name_Space.merge_tables tables; |
22846 | 330 |
); |
5824 | 331 |
|
22846 | 332 |
fun print_methods thy = |
333 |
let |
|
24116 | 334 |
val meths = Methods.get thy; |
33092
c859019d3ac5
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
wenzelm
parents:
32969
diff
changeset
|
335 |
fun prt_meth (name, (_, comment)) = Pretty.block |
22846 | 336 |
[Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment]; |
337 |
in |
|
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33092
diff
changeset
|
338 |
[Pretty.big_list "methods:" (map prt_meth (Name_Space.extern_table meths))] |
22846 | 339 |
|> Pretty.chunks |> Pretty.writeln |
340 |
end; |
|
7611 | 341 |
|
33092
c859019d3ac5
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
wenzelm
parents:
32969
diff
changeset
|
342 |
fun add_method name meth comment thy = thy |
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33092
diff
changeset
|
343 |
|> Methods.map (#2 o Name_Space.define true (Sign.naming_of thy) (name, (meth, comment))); |
31304 | 344 |
|
5824 | 345 |
|
346 |
(* get methods *) |
|
347 |
||
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33092
diff
changeset
|
348 |
val intern = Name_Space.intern o #1 o Methods.get; |
26892 | 349 |
val defined = Symtab.defined o #2 o Methods.get; |
350 |
||
20030 | 351 |
fun method_i thy = |
5824 | 352 |
let |
24116 | 353 |
val meths = #2 (Methods.get thy); |
5884 | 354 |
fun meth src = |
20030 | 355 |
let val ((name, _), pos) = Args.dest_src src in |
17412 | 356 |
(case Symtab.lookup meths name of |
15531 | 357 |
NONE => error ("Unknown proof method: " ^ quote name ^ Position.str_of pos) |
33092
c859019d3ac5
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
wenzelm
parents:
32969
diff
changeset
|
358 |
| SOME (mth, _) => (Position.report (Markup.method name) pos; mth src)) |
5824 | 359 |
end; |
360 |
in meth end; |
|
361 |
||
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33092
diff
changeset
|
362 |
fun method thy = method_i thy o Args.map_name (Name_Space.intern (#1 (Methods.get thy))); |
20030 | 363 |
|
5824 | 364 |
|
30512 | 365 |
(* method setup *) |
366 |
||
367 |
fun syntax scan = Args.context_syntax "method" scan; |
|
368 |
||
31304 | 369 |
fun setup name scan = |
370 |
add_method name |
|
371 |
(fn src => fn ctxt => let val (m, ctxt') = syntax scan src ctxt in m ctxt' end); |
|
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
372 |
|
26385
ae7564661e76
ML runtime compilation: pass position, tuned signature;
wenzelm
parents:
26291
diff
changeset
|
373 |
fun method_setup name (txt, pos) cmt = |
26472
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
374 |
Context.theory_map (ML_Context.expression pos |
30544 | 375 |
"val (name, scan, comment): binding * (Proof.context -> Proof.method) context_parser * string" |
376 |
"Context.map_theory (Method.setup name scan comment)" |
|
377 |
("(" ^ ML_Syntax.make_binding name ^ ", " ^ txt ^ ", " ^ ML_Syntax.print_string cmt ^ ")")); |
|
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
378 |
|
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
379 |
|
5884 | 380 |
|
17110 | 381 |
(** concrete syntax **) |
5824 | 382 |
|
27813
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
383 |
structure P = OuterParse; |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
384 |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
385 |
|
5884 | 386 |
(* sections *) |
5824 | 387 |
|
20289 | 388 |
type modifier = (Proof.context -> Proof.context) * attribute; |
7268 | 389 |
|
390 |
local |
|
391 |
||
24010
2ef318813e1a
method section scanners: added [[declaration]] syntax, ignore sid-effects of thms;
wenzelm
parents:
23937
diff
changeset
|
392 |
fun thms ss = Scan.repeat (Scan.unless (Scan.lift (Scan.first ss)) Attrib.multi_thm) >> flat; |
30190 | 393 |
fun app (f, att) (context, ths) = Library.foldl_map att (Context.map_proof f context, ths); |
5824 | 394 |
|
30540 | 395 |
in |
396 |
||
24022 | 397 |
fun section ss = Scan.depend (fn context => (Scan.first ss -- Scan.pass context (thms ss)) :|-- |
398 |
(fn (m, ths) => Scan.succeed (app m (context, ths)))); |
|
5884 | 399 |
|
30540 | 400 |
fun sections ss = Scan.repeat (section ss); |
5824 | 401 |
|
7268 | 402 |
end; |
403 |
||
5824 | 404 |
|
30515 | 405 |
(* extra rule methods *) |
406 |
||
407 |
fun xrule_meth m = |
|
408 |
Scan.lift (Scan.optional (Args.parens OuterParse.nat) 0) -- Attrib.thms >> |
|
409 |
(fn (n, ths) => K (m n ths)); |
|
410 |
||
411 |
||
27813
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
412 |
(* outer parser *) |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
413 |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
414 |
fun is_symid_meth s = |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
415 |
s <> "|" andalso s <> "?" andalso s <> "+" andalso OuterLex.ident_or_symbolic s; |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
416 |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
417 |
local |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
418 |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
419 |
fun meth4 x = |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
420 |
(P.position (P.xname >> rpair []) >> (Source o Args.src) || |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
421 |
P.$$$ "(" |-- P.!!! (meth0 --| P.$$$ ")")) x |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
422 |
and meth3 x = |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
423 |
(meth4 --| P.$$$ "?" >> Try || |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
424 |
meth4 --| P.$$$ "+" >> Repeat1 || |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
425 |
meth4 -- (P.$$$ "[" |-- Scan.optional P.nat 1 --| P.$$$ "]") >> (SelectGoals o swap) || |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
426 |
meth4) x |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
427 |
and meth2 x = |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
428 |
(P.position (P.xname -- Args.parse1 is_symid_meth) >> (Source o Args.src) || |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
429 |
meth3) x |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
430 |
and meth1 x = (P.enum1 "," meth2 >> (fn [m] => m | ms => Then ms)) x |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
431 |
and meth0 x = (P.enum1 "|" meth1 >> (fn [m] => m | ms => Orelse ms)) x; |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
432 |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
433 |
in val parse = meth3 end; |
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
434 |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
435 |
|
18708 | 436 |
(* theory setup *) |
5824 | 437 |
|
26463 | 438 |
val _ = Context.>> (Context.map_theory |
30515 | 439 |
(setup (Binding.name "fail") (Scan.succeed (K fail)) "force failure" #> |
440 |
setup (Binding.name "succeed") (Scan.succeed (K succeed)) "succeed" #> |
|
441 |
setup (Binding.name "-") (Scan.succeed (K insert_facts)) |
|
442 |
"do nothing (insert current facts only)" #> |
|
443 |
setup (Binding.name "insert") (Attrib.thms >> (K o insert)) |
|
444 |
"insert theorems, ignoring facts (improper)" #> |
|
445 |
setup (Binding.name "intro") (Attrib.thms >> (K o intro)) |
|
446 |
"repeatedly apply introduction rules" #> |
|
447 |
setup (Binding.name "elim") (Attrib.thms >> (K o elim)) |
|
448 |
"repeatedly apply elimination rules" #> |
|
449 |
setup (Binding.name "unfold") (Attrib.thms >> unfold_meth) "unfold definitions" #> |
|
450 |
setup (Binding.name "fold") (Attrib.thms >> fold_meth) "fold definitions" #> |
|
451 |
setup (Binding.name "atomize") (Args.mode "full" >> (K o atomize)) |
|
452 |
"present local premises as object-level statements" #> |
|
453 |
setup (Binding.name "rule") (Attrib.thms >> some_rule) "apply some intro/elim rule" #> |
|
454 |
setup (Binding.name "erule") (xrule_meth erule) "apply rule in elimination manner (improper)" #> |
|
455 |
setup (Binding.name "drule") (xrule_meth drule) "apply rule in destruct manner (improper)" #> |
|
456 |
setup (Binding.name "frule") (xrule_meth frule) "apply rule in forward manner (improper)" #> |
|
457 |
setup (Binding.name "this") (Scan.succeed (K this)) "apply current facts as rules" #> |
|
458 |
setup (Binding.name "fact") (Attrib.thms >> fact) "composition by facts from context" #> |
|
459 |
setup (Binding.name "assumption") (Scan.succeed assumption) |
|
460 |
"proof by assumption, preferring facts" #> |
|
461 |
setup (Binding.name "rename_tac") (Args.goal_spec -- Scan.lift (Scan.repeat1 Args.name) >> |
|
462 |
(fn (quant, xs) => K (SIMPLE_METHOD'' quant (Tactic.rename_tac xs)))) |
|
463 |
"rename parameters of goal" #> |
|
464 |
setup (Binding.name "rotate_tac") (Args.goal_spec -- Scan.lift (Scan.optional P.int 1) >> |
|
465 |
(fn (quant, i) => K (SIMPLE_METHOD'' quant (Tactic.rotate_tac i)))) |
|
466 |
"rotate assumptions of goal" #> |
|
467 |
setup (Binding.name "tactic") (Scan.lift (P.position Args.name) >> tactic) |
|
468 |
"ML tactic as proof method" #> |
|
469 |
setup (Binding.name "raw_tactic") (Scan.lift (P.position Args.name) >> raw_tactic) |
|
470 |
"ML tactic as raw proof method")); |
|
5824 | 471 |
|
472 |
||
16145 | 473 |
(*final declarations of this structure!*) |
474 |
val unfold = unfold_meth; |
|
475 |
val fold = fold_meth; |
|
476 |
||
5824 | 477 |
end; |
478 |
||
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
479 |
structure Basic_Method: BASIC_METHOD = Method; |
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
480 |
open Basic_Method; |
30508
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
481 |
|
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
482 |
val RAW_METHOD_CASES = Method.RAW_METHOD_CASES; |
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
483 |
val RAW_METHOD = Method.RAW_METHOD; |
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
484 |
val METHOD_CASES = Method.METHOD_CASES; |
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
485 |
val METHOD = Method.METHOD; |
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
486 |
val SIMPLE_METHOD = Method.SIMPLE_METHOD; |
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
487 |
val SIMPLE_METHOD' = Method.SIMPLE_METHOD'; |
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
488 |
val SIMPLE_METHOD'' = Method.SIMPLE_METHOD''; |
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
489 |