| author | wenzelm |
| Mon, 22 Jun 2009 22:51:08 +0200 | |
| changeset 31757 | c1262feb61c7 |
| parent 31304 | 00a9c674cf40 |
| child 32091 | 30e2ffbba718 |
| 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 |
|
| 11731 | 11 |
val trace_rules: bool 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 |
|
25957
2cfb703fa8d8
improved apply: handle thread position, apply to context here;
wenzelm
parents:
25699
diff
changeset
|
18 |
val apply: Position.T -> (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 = |
| 23349 | 58 |
Basic of (Proof.context -> method) * Position.T | |
| 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 |
| 23349 | 72 |
val finish_text: text option * bool -> Position.T -> 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 |
|
|
25957
2cfb703fa8d8
improved apply: handle thread position, apply to context here;
wenzelm
parents:
25699
diff
changeset
|
109 |
fun apply pos meth_fun ctxt facts goal = Position.setmp_thread_data_seq pos |
|
2cfb703fa8d8
improved apply: handle thread position, apply to context here;
wenzelm
parents:
25699
diff
changeset
|
110 |
(fn () => let val Meth meth = meth_fun ctxt in meth facts goal end) (); |
| 11731 | 111 |
|
| 17756 | 112 |
val RAW_METHOD_CASES = Meth; |
| 11731 | 113 |
|
| 17110 | 114 |
fun RAW_METHOD tac = RAW_METHOD_CASES (NO_CASES o tac); |
| 12144 | 115 |
|
| 17110 | 116 |
fun METHOD_CASES tac = RAW_METHOD_CASES (fn facts => |
| 21687 | 117 |
Seq.THEN (ALLGOALS Goal.conjunction_tac, tac facts)); |
| 8372 | 118 |
|
| 21687 | 119 |
fun METHOD tac = RAW_METHOD (fn facts => ALLGOALS Goal.conjunction_tac THEN tac facts); |
| 5824 | 120 |
|
121 |
val fail = METHOD (K no_tac); |
|
122 |
val succeed = METHOD (K all_tac); |
|
123 |
||
124 |
||
| 17110 | 125 |
(* insert facts *) |
| 7419 | 126 |
|
127 |
local |
|
| 5824 | 128 |
|
| 21579 | 129 |
fun cut_rule_tac rule = |
130 |
Tactic.rtac (Drule.forall_intr_vars rule COMP_INCR revcut_rl); |
|
| 6981 | 131 |
|
| 7419 | 132 |
in |
| 5824 | 133 |
|
| 7419 | 134 |
fun insert_tac [] i = all_tac |
135 |
| insert_tac facts i = EVERY (map (fn th => cut_rule_tac th i) facts); |
|
| 6981 | 136 |
|
| 7555 | 137 |
val insert_facts = METHOD (ALLGOALS o insert_tac); |
| 7664 | 138 |
fun insert thms = METHOD (fn _ => ALLGOALS (insert_tac thms)); |
| 7419 | 139 |
|
| 9706 | 140 |
fun SIMPLE_METHOD tac = METHOD (fn facts => ALLGOALS (insert_tac facts) THEN tac); |
| 21592 | 141 |
fun SIMPLE_METHOD'' quant tac = METHOD (fn facts => quant (insert_tac facts THEN' tac)); |
142 |
val SIMPLE_METHOD' = SIMPLE_METHOD'' HEADGOAL; |
|
| 9706 | 143 |
|
|
12324
5db4b4596d1a
rule context and attributes moved to rule_context.ML;
wenzelm
parents:
12311
diff
changeset
|
144 |
end; |
|
5db4b4596d1a
rule context and attributes moved to rule_context.ML;
wenzelm
parents:
12311
diff
changeset
|
145 |
|
| 9706 | 146 |
|
| 17110 | 147 |
(* shuffle subgoals *) |
148 |
||
149 |
fun prefer i = METHOD (K (Tactic.defer_tac i THEN PRIMITIVE (Thm.permute_prems 0 ~1))); |
|
| 18939 | 150 |
fun defer opt_i = METHOD (K (Tactic.defer_tac (the_default 1 opt_i))); |
| 17110 | 151 |
|
152 |
||
|
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
153 |
(* cheating *) |
|
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
154 |
|
|
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
155 |
fun cheating int ctxt = METHOD (K (setmp quick_and_dirty (int orelse ! quick_and_dirty) |
|
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
156 |
(SkipProof.cheat_tac (ProofContext.theory_of ctxt)))); |
|
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
157 |
|
|
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
158 |
|
| 17110 | 159 |
(* unfold intro/elim rules *) |
160 |
||
| 21592 | 161 |
fun intro ths = SIMPLE_METHOD' (CHANGED_PROP o REPEAT_ALL_NEW (Tactic.match_tac ths)); |
162 |
fun elim ths = SIMPLE_METHOD' (CHANGED_PROP o REPEAT_ALL_NEW (Tactic.ematch_tac ths)); |
|
| 17110 | 163 |
|
164 |
||
| 12384 | 165 |
(* unfold/fold definitions *) |
166 |
||
| 18877 | 167 |
fun unfold_meth ths ctxt = SIMPLE_METHOD (CHANGED_PROP (LocalDefs.unfold_tac ctxt ths)); |
168 |
fun fold_meth ths ctxt = SIMPLE_METHOD (CHANGED_PROP (LocalDefs.fold_tac ctxt ths)); |
|
| 6532 | 169 |
|
| 12384 | 170 |
|
| 12829 | 171 |
(* atomize rule statements *) |
172 |
||
|
23590
ad95084a5c63
renamed ObjectLogic.atomize_tac to ObjectLogic.atomize_prems_tac;
wenzelm
parents:
23577
diff
changeset
|
173 |
fun atomize false = SIMPLE_METHOD' (CHANGED_PROP o ObjectLogic.atomize_prems_tac) |
| 12829 | 174 |
| atomize true = RAW_METHOD (K (HEADGOAL (CHANGED_PROP o ObjectLogic.full_atomize_tac))); |
175 |
||
176 |
||
| 18039 | 177 |
(* this -- resolve facts directly *) |
| 12384 | 178 |
|
| 17110 | 179 |
val this = METHOD (EVERY o map (HEADGOAL o Tactic.rtac)); |
| 9484 | 180 |
|
181 |
||
| 18039 | 182 |
(* fact -- composition by facts from context *) |
183 |
||
| 21592 | 184 |
fun fact [] ctxt = SIMPLE_METHOD' (ProofContext.some_fact_tac ctxt) |
185 |
| fact rules _ = SIMPLE_METHOD' (ProofContext.fact_tac rules); |
|
| 18039 | 186 |
|
187 |
||
| 17110 | 188 |
(* assumption *) |
| 7419 | 189 |
|
190 |
local |
|
191 |
||
| 19778 | 192 |
fun cond_rtac cond rule = SUBGOAL (fn (prop, i) => |
193 |
if cond (Logic.strip_assums_concl prop) |
|
194 |
then Tactic.rtac rule i else no_tac); |
|
| 7419 | 195 |
|
|
29857
2cc976ed8a3c
FindTheorems: add solves feature; tidy up const name subsettin; patch by Timothy Bourke
kleing
parents:
29301
diff
changeset
|
196 |
in |
|
2cc976ed8a3c
FindTheorems: add solves feature; tidy up const name subsettin; patch by Timothy Bourke
kleing
parents:
29301
diff
changeset
|
197 |
|
|
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
|
198 |
fun assm_tac ctxt = |
| 17110 | 199 |
assume_tac APPEND' |
| 23349 | 200 |
Goal.assume_rule_tac ctxt APPEND' |
| 19778 | 201 |
cond_rtac (can Logic.dest_equals) Drule.reflexive_thm APPEND' |
202 |
cond_rtac (can Logic.dest_term) Drule.termI; |
|
| 17110 | 203 |
|
|
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
|
204 |
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
|
205 |
|
| 23349 | 206 |
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
|
207 |
(fn [] => assm_tac ctxt |
| 23349 | 208 |
| [fact] => solve_tac [fact] |
209 |
| _ => K no_tac)); |
|
210 |
||
|
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
211 |
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
|
212 |
(FILTER Thm.no_prems ((if immed then all_assm_tac ctxt else all_tac) THEN flexflex_tac))); |
| 7419 | 213 |
|
214 |
end; |
|
215 |
||
216 |
||
| 17110 | 217 |
(* rule etc. -- single-step refinements *) |
| 12347 | 218 |
|
| 17110 | 219 |
val trace_rules = ref false; |
| 12347 | 220 |
|
| 17110 | 221 |
fun trace ctxt rules = |
| 21962 | 222 |
if ! trace_rules andalso not (null rules) then |
| 17110 | 223 |
Pretty.big_list "rules:" (map (ProofContext.pretty_thm ctxt) rules) |
| 21962 | 224 |
|> Pretty.string_of |> tracing |
225 |
else (); |
|
| 12347 | 226 |
|
227 |
local |
|
228 |
||
| 18841 | 229 |
fun gen_rule_tac tac rules facts = |
230 |
(fn i => fn st => |
|
231 |
if null facts then tac rules i st |
|
232 |
else Seq.maps (fn rule => (tac o single) rule i st) (Drule.multi_resolves facts rules)) |
|
| 21687 | 233 |
THEN_ALL_NEW Goal.norm_hhf_tac; |
| 7130 | 234 |
|
| 10744 | 235 |
fun gen_arule_tac tac j rules facts = |
236 |
EVERY' (gen_rule_tac tac rules facts :: replicate j Tactic.assume_tac); |
|
237 |
||
| 11785 | 238 |
fun gen_some_rule_tac tac arg_rules ctxt facts = SUBGOAL (fn (goal, i) => |
239 |
let |
|
240 |
val rules = |
|
241 |
if not (null arg_rules) then arg_rules |
|
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19307
diff
changeset
|
242 |
else flat (ContextRules.find_rules false facts goal ctxt) |
| 12055 | 243 |
in trace ctxt rules; tac rules facts i end); |
| 10309 | 244 |
|
| 10744 | 245 |
fun meth tac x = METHOD (HEADGOAL o tac x); |
246 |
fun meth' tac x y = METHOD (HEADGOAL o tac x y); |
|
| 8220 | 247 |
|
| 7419 | 248 |
in |
249 |
||
| 10744 | 250 |
val rule_tac = gen_rule_tac Tactic.resolve_tac; |
251 |
val rule = meth rule_tac; |
|
252 |
val some_rule_tac = gen_some_rule_tac rule_tac; |
|
253 |
val some_rule = meth' some_rule_tac; |
|
254 |
||
255 |
val erule = meth' (gen_arule_tac Tactic.eresolve_tac); |
|
256 |
val drule = meth' (gen_arule_tac Tactic.dresolve_tac); |
|
257 |
val frule = meth' (gen_arule_tac Tactic.forward_tac); |
|
| 5824 | 258 |
|
| 7419 | 259 |
end; |
260 |
||
261 |
||
| 25270 | 262 |
(* intros_tac -- pervasive search spanned by intro rules *) |
263 |
||
264 |
fun intros_tac intros facts = |
|
265 |
ALLGOALS (insert_tac facts THEN' |
|
266 |
REPEAT_ALL_NEW (resolve_tac intros)) |
|
267 |
THEN Tactic.distinct_subgoals_tac; |
|
268 |
||
269 |
||
| 8351 | 270 |
(* ML tactics *) |
271 |
||
|
26472
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
272 |
structure TacticData = ProofDataFun |
|
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
273 |
( |
| 27235 | 274 |
type T = thm list -> tactic; |
|
26472
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
275 |
fun init _ = undefined; |
|
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
276 |
); |
|
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 |
val set_tactic = TacticData.put; |
| 8351 | 279 |
|
|
26472
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
280 |
fun ml_tactic (txt, pos) ctxt = |
|
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
281 |
let |
|
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
282 |
val ctxt' = ctxt |> Context.proof_map |
| 27235 | 283 |
(ML_Context.expression pos |
284 |
"fun tactic (facts: thm list) : tactic" |
|
|
26472
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
285 |
"Context.map_proof (Method.set_tactic tactic)" txt); |
| 27235 | 286 |
in Context.setmp_thread_data (SOME (Context.Proof ctxt)) (TacticData.get ctxt') end; |
| 23425 | 287 |
|
288 |
fun tactic txt ctxt = METHOD (ml_tactic txt ctxt); |
|
289 |
fun raw_tactic txt ctxt = RAW_METHOD (ml_tactic txt ctxt); |
|
| 8351 | 290 |
|
291 |
||
| 5824 | 292 |
|
| 17110 | 293 |
(** method syntax **) |
294 |
||
295 |
(* method text *) |
|
296 |
||
297 |
type src = Args.src; |
|
| 5824 | 298 |
|
| 17110 | 299 |
datatype text = |
| 23349 | 300 |
Basic of (Proof.context -> method) * Position.T | |
| 17110 | 301 |
Source of src | |
| 20030 | 302 |
Source_i of src | |
| 17110 | 303 |
Then of text list | |
304 |
Orelse of text list | |
|
305 |
Try of text | |
|
| 19186 | 306 |
Repeat1 of text | |
307 |
SelectGoals of int * text; |
|
| 17110 | 308 |
|
| 23349 | 309 |
fun primitive_text r = Basic (K (SIMPLE_METHOD (PRIMITIVE r)), Position.none); |
310 |
val succeed_text = Basic (K succeed, Position.none); |
|
| 17110 | 311 |
val default_text = Source (Args.src (("default", []), Position.none));
|
| 23349 | 312 |
val this_text = Basic (K this, Position.none); |
313 |
val done_text = Basic (K (SIMPLE_METHOD all_tac), Position.none); |
|
314 |
fun sorry_text int = Basic (cheating int, Position.none); |
|
| 17110 | 315 |
|
| 23349 | 316 |
fun finish_text (NONE, immed) pos = Basic (close immed, pos) |
317 |
| finish_text (SOME txt, immed) pos = Then [txt, Basic (close immed, pos)]; |
|
| 17110 | 318 |
|
319 |
||
320 |
(* method definitions *) |
|
| 5824 | 321 |
|
| 24116 | 322 |
structure Methods = TheoryDataFun |
| 22846 | 323 |
( |
| 20289 | 324 |
type T = (((src -> Proof.context -> method) * string) * stamp) NameSpace.table; |
| 16347 | 325 |
val empty = NameSpace.empty_table; |
| 6546 | 326 |
val copy = I; |
| 16448 | 327 |
val extend = I; |
|
23655
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
wenzelm
parents:
23590
diff
changeset
|
328 |
fun merge _ tables : T = NameSpace.merge_tables (eq_snd (op =)) tables handle Symtab.DUP dup => |
|
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
wenzelm
parents:
23590
diff
changeset
|
329 |
error ("Attempt to merge different versions of method " ^ quote dup);
|
| 22846 | 330 |
); |
| 5824 | 331 |
|
| 22846 | 332 |
fun print_methods thy = |
333 |
let |
|
| 24116 | 334 |
val meths = Methods.get thy; |
| 22846 | 335 |
fun prt_meth (name, ((_, comment), _)) = Pretty.block |
336 |
[Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment]; |
|
337 |
in |
|
338 |
[Pretty.big_list "methods:" (map prt_meth (NameSpace.extern_table meths))] |
|
339 |
|> Pretty.chunks |> Pretty.writeln |
|
340 |
end; |
|
| 7611 | 341 |
|
| 31304 | 342 |
fun add_method name meth comment thy = thy |> Methods.map (fn meths => |
343 |
#2 (NameSpace.define (Sign.naming_of thy) (name, ((meth, comment), stamp ())) meths) |
|
344 |
handle Symtab.DUP dup => error ("Duplicate declaration of method " ^ quote dup));
|
|
345 |
||
| 5824 | 346 |
|
347 |
(* get methods *) |
|
348 |
||
| 26892 | 349 |
val intern = NameSpace.intern o #1 o Methods.get; |
350 |
val defined = Symtab.defined o #2 o Methods.get; |
|
351 |
||
| 20030 | 352 |
fun method_i thy = |
| 5824 | 353 |
let |
| 24116 | 354 |
val meths = #2 (Methods.get thy); |
| 5884 | 355 |
fun meth src = |
| 20030 | 356 |
let val ((name, _), pos) = Args.dest_src src in |
| 17412 | 357 |
(case Symtab.lookup meths name of |
| 15531 | 358 |
NONE => error ("Unknown proof method: " ^ quote name ^ Position.str_of pos)
|
| 27751 | 359 |
| SOME ((mth, _), _) => (Position.report (Markup.method name) pos; mth src)) |
| 5824 | 360 |
end; |
361 |
in meth end; |
|
362 |
||
| 24116 | 363 |
fun method thy = method_i thy o Args.map_name (NameSpace.intern (#1 (Methods.get thy))); |
| 20030 | 364 |
|
| 5824 | 365 |
|
| 30512 | 366 |
(* method setup *) |
367 |
||
368 |
fun syntax scan = Args.context_syntax "method" scan; |
|
369 |
||
| 31304 | 370 |
fun setup name scan = |
371 |
add_method name |
|
372 |
(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
|
373 |
|
|
26385
ae7564661e76
ML runtime compilation: pass position, tuned signature;
wenzelm
parents:
26291
diff
changeset
|
374 |
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
|
375 |
Context.theory_map (ML_Context.expression pos |
| 30544 | 376 |
"val (name, scan, comment): binding * (Proof.context -> Proof.method) context_parser * string" |
377 |
"Context.map_theory (Method.setup name scan comment)" |
|
378 |
("(" ^ 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
|
379 |
|
|
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
380 |
|
| 5884 | 381 |
|
| 17110 | 382 |
(** concrete syntax **) |
| 5824 | 383 |
|
|
27813
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
384 |
structure P = OuterParse; |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
385 |
|
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
386 |
|
| 5884 | 387 |
(* sections *) |
| 5824 | 388 |
|
| 20289 | 389 |
type modifier = (Proof.context -> Proof.context) * attribute; |
| 7268 | 390 |
|
391 |
local |
|
392 |
||
|
24010
2ef318813e1a
method section scanners: added [[declaration]] syntax, ignore sid-effects of thms;
wenzelm
parents:
23937
diff
changeset
|
393 |
fun thms ss = Scan.repeat (Scan.unless (Scan.lift (Scan.first ss)) Attrib.multi_thm) >> flat; |
| 30190 | 394 |
fun app (f, att) (context, ths) = Library.foldl_map att (Context.map_proof f context, ths); |
| 5824 | 395 |
|
| 30540 | 396 |
in |
397 |
||
| 24022 | 398 |
fun section ss = Scan.depend (fn context => (Scan.first ss -- Scan.pass context (thms ss)) :|-- |
399 |
(fn (m, ths) => Scan.succeed (app m (context, ths)))); |
|
| 5884 | 400 |
|
| 30540 | 401 |
fun sections ss = Scan.repeat (section ss); |
| 5824 | 402 |
|
| 7268 | 403 |
end; |
404 |
||
| 5824 | 405 |
|
| 30515 | 406 |
(* extra rule methods *) |
407 |
||
408 |
fun xrule_meth m = |
|
409 |
Scan.lift (Scan.optional (Args.parens OuterParse.nat) 0) -- Attrib.thms >> |
|
410 |
(fn (n, ths) => K (m n ths)); |
|
411 |
||
412 |
||
|
27813
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
413 |
(* outer parser *) |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
414 |
|
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
415 |
fun is_symid_meth s = |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
416 |
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
|
417 |
|
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
418 |
local |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
419 |
|
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
420 |
fun meth4 x = |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
421 |
(P.position (P.xname >> rpair []) >> (Source o Args.src) || |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
422 |
P.$$$ "(" |-- P.!!! (meth0 --| P.$$$ ")")) x
|
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
423 |
and meth3 x = |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
424 |
(meth4 --| P.$$$ "?" >> Try || |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
425 |
meth4 --| P.$$$ "+" >> Repeat1 || |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
426 |
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
|
427 |
meth4) x |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
428 |
and meth2 x = |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
429 |
(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
|
430 |
meth3) x |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
431 |
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
|
432 |
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
|
433 |
|
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
434 |
in val parse = meth3 end; |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
435 |
|
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
436 |
|
| 18708 | 437 |
(* theory setup *) |
| 5824 | 438 |
|
| 26463 | 439 |
val _ = Context.>> (Context.map_theory |
| 30515 | 440 |
(setup (Binding.name "fail") (Scan.succeed (K fail)) "force failure" #> |
441 |
setup (Binding.name "succeed") (Scan.succeed (K succeed)) "succeed" #> |
|
442 |
setup (Binding.name "-") (Scan.succeed (K insert_facts)) |
|
443 |
"do nothing (insert current facts only)" #> |
|
444 |
setup (Binding.name "insert") (Attrib.thms >> (K o insert)) |
|
445 |
"insert theorems, ignoring facts (improper)" #> |
|
446 |
setup (Binding.name "intro") (Attrib.thms >> (K o intro)) |
|
447 |
"repeatedly apply introduction rules" #> |
|
448 |
setup (Binding.name "elim") (Attrib.thms >> (K o elim)) |
|
449 |
"repeatedly apply elimination rules" #> |
|
450 |
setup (Binding.name "unfold") (Attrib.thms >> unfold_meth) "unfold definitions" #> |
|
451 |
setup (Binding.name "fold") (Attrib.thms >> fold_meth) "fold definitions" #> |
|
452 |
setup (Binding.name "atomize") (Args.mode "full" >> (K o atomize)) |
|
453 |
"present local premises as object-level statements" #> |
|
454 |
setup (Binding.name "rule") (Attrib.thms >> some_rule) "apply some intro/elim rule" #> |
|
455 |
setup (Binding.name "erule") (xrule_meth erule) "apply rule in elimination manner (improper)" #> |
|
456 |
setup (Binding.name "drule") (xrule_meth drule) "apply rule in destruct manner (improper)" #> |
|
457 |
setup (Binding.name "frule") (xrule_meth frule) "apply rule in forward manner (improper)" #> |
|
458 |
setup (Binding.name "this") (Scan.succeed (K this)) "apply current facts as rules" #> |
|
459 |
setup (Binding.name "fact") (Attrib.thms >> fact) "composition by facts from context" #> |
|
460 |
setup (Binding.name "assumption") (Scan.succeed assumption) |
|
461 |
"proof by assumption, preferring facts" #> |
|
462 |
setup (Binding.name "rename_tac") (Args.goal_spec -- Scan.lift (Scan.repeat1 Args.name) >> |
|
463 |
(fn (quant, xs) => K (SIMPLE_METHOD'' quant (Tactic.rename_tac xs)))) |
|
464 |
"rename parameters of goal" #> |
|
465 |
setup (Binding.name "rotate_tac") (Args.goal_spec -- Scan.lift (Scan.optional P.int 1) >> |
|
466 |
(fn (quant, i) => K (SIMPLE_METHOD'' quant (Tactic.rotate_tac i)))) |
|
467 |
"rotate assumptions of goal" #> |
|
468 |
setup (Binding.name "tactic") (Scan.lift (P.position Args.name) >> tactic) |
|
469 |
"ML tactic as proof method" #> |
|
470 |
setup (Binding.name "raw_tactic") (Scan.lift (P.position Args.name) >> raw_tactic) |
|
471 |
"ML tactic as raw proof method")); |
|
| 5824 | 472 |
|
473 |
||
| 16145 | 474 |
(*final declarations of this structure!*) |
475 |
val unfold = unfold_meth; |
|
476 |
val fold = fold_meth; |
|
477 |
||
| 5824 | 478 |
end; |
479 |
||
480 |
structure BasicMethod: BASIC_METHOD = Method; |
|
481 |
open BasicMethod; |
|
|
30508
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
482 |
|
|
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
483 |
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
|
484 |
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
|
485 |
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
|
486 |
val METHOD = Method.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 |
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
|
490 |