src/Pure/Isar/method.ML
author wenzelm
Sat Jul 28 20:40:27 2007 +0200 (2007-07-28)
changeset 24022 ab76c73b3b58
parent 24010 2ef318813e1a
child 24116 9915c39e0820
permissions -rw-r--r--
tuned;
     1 (*  Title:      Pure/Isar/method.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4 
     5 Isar proof methods.
     6 *)
     7 
     8 signature BASIC_METHOD =
     9 sig
    10   val FINDGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
    11   val HEADGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
    12   type method
    13   val trace_rules: bool ref
    14   val print_methods: theory -> unit
    15 end;
    16 
    17 signature METHOD =
    18 sig
    19   include BASIC_METHOD
    20   val apply: method -> thm list -> cases_tactic
    21   val RAW_METHOD_CASES: (thm list -> cases_tactic) -> method
    22   val RAW_METHOD: (thm list -> tactic) -> method
    23   val METHOD_CASES: (thm list -> cases_tactic) -> method
    24   val METHOD: (thm list -> tactic) -> method
    25   val fail: method
    26   val succeed: method
    27   val insert_tac: thm list -> int -> tactic
    28   val insert: thm list -> method
    29   val insert_facts: method
    30   val SIMPLE_METHOD: tactic -> method
    31   val SIMPLE_METHOD': (int -> tactic) -> method
    32   val SIMPLE_METHOD'': ((int -> tactic) -> tactic) -> (int -> tactic) -> method
    33   val defer: int option -> method
    34   val prefer: int -> method
    35   val cheating: bool -> Proof.context -> method
    36   val intro: thm list -> method
    37   val elim: thm list -> method
    38   val unfold: thm list -> Proof.context -> method
    39   val fold: thm list -> Proof.context -> method
    40   val atomize: bool -> method
    41   val this: method
    42   val fact: thm list -> Proof.context -> method
    43   val assumption: Proof.context -> method
    44   val close: bool -> Proof.context -> method
    45   val trace: Proof.context -> thm list -> unit
    46   val rule_tac: thm list -> thm list -> int -> tactic
    47   val some_rule_tac: thm list -> Proof.context -> thm list -> int -> tactic
    48   val rule: thm list -> method
    49   val erule: int -> thm list -> method
    50   val drule: int -> thm list -> method
    51   val frule: int -> thm list -> method
    52   val iprover_tac: Proof.context -> int option -> int -> tactic
    53   val set_tactic: (Proof.context -> thm list -> tactic) -> unit
    54   val tactic: string -> Proof.context -> method
    55   type src
    56   datatype text =
    57     Basic of (Proof.context -> method) * Position.T |
    58     Source of src |
    59     Source_i of src |
    60     Then of text list |
    61     Orelse of text list |
    62     Try of text |
    63     Repeat1 of text |
    64     SelectGoals of int * text
    65   val primitive_text: (thm -> thm) -> text
    66   val succeed_text: text
    67   val default_text: text
    68   val this_text: text
    69   val done_text: text
    70   val sorry_text: bool -> text
    71   val finish_text: text option * bool -> Position.T -> text
    72   val method: theory -> src -> Proof.context -> method
    73   val method_i: theory -> src -> Proof.context -> method
    74   val add_methods: (bstring * (src -> Proof.context -> method) * string) list
    75     -> theory -> theory
    76   val add_method: bstring * (src -> Proof.context -> method) * string
    77     -> theory -> theory
    78   val method_setup: bstring * string * string -> theory -> theory
    79   val syntax: (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list))
    80     -> src -> Proof.context -> 'a * Proof.context
    81   val simple_args: (Args.T list -> 'a * Args.T list)
    82     -> ('a -> Proof.context -> method) -> src -> Proof.context -> method
    83   val ctxt_args: (Proof.context -> method) -> src -> Proof.context -> method
    84   val no_args: method -> src -> Proof.context -> method
    85   type modifier
    86   val sectioned_args: (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list)) ->
    87     (Args.T list -> modifier * Args.T list) list ->
    88     ('a -> Proof.context -> 'b) -> src -> Proof.context -> 'b
    89   val bang_sectioned_args:
    90     (Args.T list -> modifier * Args.T list) list ->
    91     (thm list -> Proof.context -> 'a) -> src -> Proof.context -> 'a
    92   val bang_sectioned_args':
    93     (Args.T list -> modifier * Args.T list) list ->
    94     (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list)) ->
    95     ('a -> thm list -> Proof.context -> 'b) -> src -> Proof.context -> 'b
    96   val only_sectioned_args:
    97     (Args.T list -> modifier * Args.T list) list ->
    98     (Proof.context -> 'a) -> src -> Proof.context -> 'a
    99   val thms_ctxt_args: (thm list -> Proof.context -> 'a) -> src ->
   100     Proof.context -> 'a
   101   val thms_args: (thm list -> 'a) -> src -> Proof.context -> 'a
   102   val thm_args: (thm -> 'a) -> src -> Proof.context -> 'a
   103   val goal_args: (Args.T list -> 'a * Args.T list) -> ('a -> int -> tactic)
   104     -> src -> Proof.context -> method
   105   val goal_args': (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list))
   106     -> ('a -> int -> tactic) -> src -> Proof.context -> method
   107   val goal_args_ctxt: (Args.T list -> 'a * Args.T list) ->
   108     (Proof.context -> 'a -> int -> tactic) -> src -> Proof.context -> method
   109   val goal_args_ctxt': (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list)) ->
   110     (Proof.context -> 'a -> int -> tactic) -> src -> Proof.context -> method
   111   val parse: OuterLex.token list -> text * OuterLex.token list
   112 end;
   113 
   114 structure Method: METHOD =
   115 struct
   116 
   117 (** generic tools **)
   118 
   119 (* goal addressing *)
   120 
   121 fun FINDGOAL tac st =
   122   let fun find i n = if i > n then Seq.fail else Seq.APPEND (tac i, find (i + 1) n)
   123   in find 1 (Thm.nprems_of st) st end;
   124 
   125 fun HEADGOAL tac = tac 1;
   126 
   127 
   128 
   129 (** proof methods **)
   130 
   131 (* datatype method *)
   132 
   133 datatype method = Meth of thm list -> cases_tactic;
   134 
   135 fun apply (Meth m) = m;
   136 
   137 val RAW_METHOD_CASES = Meth;
   138 
   139 fun RAW_METHOD tac = RAW_METHOD_CASES (NO_CASES o tac);
   140 
   141 fun METHOD_CASES tac = RAW_METHOD_CASES (fn facts =>
   142   Seq.THEN (ALLGOALS Goal.conjunction_tac, tac facts));
   143 
   144 fun METHOD tac = RAW_METHOD (fn facts => ALLGOALS Goal.conjunction_tac THEN tac facts);
   145 
   146 val fail = METHOD (K no_tac);
   147 val succeed = METHOD (K all_tac);
   148 
   149 
   150 (* insert facts *)
   151 
   152 local
   153 
   154 fun cut_rule_tac rule =
   155   Tactic.rtac (Drule.forall_intr_vars rule COMP_INCR revcut_rl);
   156 
   157 in
   158 
   159 fun insert_tac [] i = all_tac
   160   | insert_tac facts i = EVERY (map (fn th => cut_rule_tac th i) facts);
   161 
   162 val insert_facts = METHOD (ALLGOALS o insert_tac);
   163 fun insert thms = METHOD (fn _ => ALLGOALS (insert_tac thms));
   164 
   165 fun SIMPLE_METHOD tac = METHOD (fn facts => ALLGOALS (insert_tac facts) THEN tac);
   166 fun SIMPLE_METHOD'' quant tac = METHOD (fn facts => quant (insert_tac facts THEN' tac));
   167 val SIMPLE_METHOD' = SIMPLE_METHOD'' HEADGOAL;
   168 
   169 end;
   170 
   171 
   172 (* shuffle subgoals *)
   173 
   174 fun prefer i = METHOD (K (Tactic.defer_tac i THEN PRIMITIVE (Thm.permute_prems 0 ~1)));
   175 fun defer opt_i = METHOD (K (Tactic.defer_tac (the_default 1 opt_i)));
   176 
   177 
   178 (* cheating *)
   179 
   180 fun cheating int ctxt = METHOD (K (setmp quick_and_dirty (int orelse ! quick_and_dirty)
   181     (SkipProof.cheat_tac (ProofContext.theory_of ctxt))));
   182 
   183 
   184 (* unfold intro/elim rules *)
   185 
   186 fun intro ths = SIMPLE_METHOD' (CHANGED_PROP o REPEAT_ALL_NEW (Tactic.match_tac ths));
   187 fun elim ths = SIMPLE_METHOD' (CHANGED_PROP o REPEAT_ALL_NEW (Tactic.ematch_tac ths));
   188 
   189 
   190 (* unfold/fold definitions *)
   191 
   192 fun unfold_meth ths ctxt = SIMPLE_METHOD (CHANGED_PROP (LocalDefs.unfold_tac ctxt ths));
   193 fun fold_meth ths ctxt = SIMPLE_METHOD (CHANGED_PROP (LocalDefs.fold_tac ctxt ths));
   194 
   195 
   196 (* atomize rule statements *)
   197 
   198 fun atomize false = SIMPLE_METHOD' (CHANGED_PROP o ObjectLogic.atomize_prems_tac)
   199   | atomize true = RAW_METHOD (K (HEADGOAL (CHANGED_PROP o ObjectLogic.full_atomize_tac)));
   200 
   201 
   202 (* this -- resolve facts directly *)
   203 
   204 val this = METHOD (EVERY o map (HEADGOAL o Tactic.rtac));
   205 
   206 
   207 (* fact -- composition by facts from context *)
   208 
   209 fun fact [] ctxt = SIMPLE_METHOD' (ProofContext.some_fact_tac ctxt)
   210   | fact rules _ = SIMPLE_METHOD' (ProofContext.fact_tac rules);
   211 
   212 
   213 (* assumption *)
   214 
   215 local
   216 
   217 fun cond_rtac cond rule = SUBGOAL (fn (prop, i) =>
   218   if cond (Logic.strip_assums_concl prop)
   219   then Tactic.rtac rule i else no_tac);
   220 
   221 fun legacy_tac ctxt st =
   222   (legacy_feature ("implicit use of prems in assumption proof" ^ ContextPosition.str_of ctxt);
   223     all_tac st);
   224 
   225 fun assm_tac ctxt =
   226   assume_tac APPEND'
   227   Goal.assume_rule_tac ctxt APPEND'
   228   (CHANGED o solve_tac (Assumption.prems_of ctxt) THEN' K (legacy_tac ctxt)) APPEND'
   229   cond_rtac (can Logic.dest_equals) Drule.reflexive_thm APPEND'
   230   cond_rtac (can Logic.dest_term) Drule.termI;
   231 
   232 in
   233 
   234 fun assumption ctxt = METHOD (HEADGOAL o
   235   (fn [] => assm_tac ctxt
   236     | [fact] => solve_tac [fact]
   237     | _ => K no_tac));
   238 
   239 fun close immed ctxt = METHOD (K
   240   (FILTER Thm.no_prems
   241     ((if immed then ALLGOALS (assm_tac ctxt) else all_tac) THEN flexflex_tac)));
   242 
   243 end;
   244 
   245 
   246 (* rule etc. -- single-step refinements *)
   247 
   248 val trace_rules = ref false;
   249 
   250 fun trace ctxt rules =
   251   if ! trace_rules andalso not (null rules) then
   252     Pretty.big_list "rules:" (map (ProofContext.pretty_thm ctxt) rules)
   253     |> Pretty.string_of |> tracing
   254   else ();
   255 
   256 local
   257 
   258 fun gen_rule_tac tac rules facts =
   259   (fn i => fn st =>
   260     if null facts then tac rules i st
   261     else Seq.maps (fn rule => (tac o single) rule i st) (Drule.multi_resolves facts rules))
   262   THEN_ALL_NEW Goal.norm_hhf_tac;
   263 
   264 fun gen_arule_tac tac j rules facts =
   265   EVERY' (gen_rule_tac tac rules facts :: replicate j Tactic.assume_tac);
   266 
   267 fun gen_some_rule_tac tac arg_rules ctxt facts = SUBGOAL (fn (goal, i) =>
   268   let
   269     val rules =
   270       if not (null arg_rules) then arg_rules
   271       else flat (ContextRules.find_rules false facts goal ctxt)
   272   in trace ctxt rules; tac rules facts i end);
   273 
   274 fun meth tac x = METHOD (HEADGOAL o tac x);
   275 fun meth' tac x y = METHOD (HEADGOAL o tac x y);
   276 
   277 in
   278 
   279 val rule_tac = gen_rule_tac Tactic.resolve_tac;
   280 val rule = meth rule_tac;
   281 val some_rule_tac = gen_some_rule_tac rule_tac;
   282 val some_rule = meth' some_rule_tac;
   283 
   284 val erule = meth' (gen_arule_tac Tactic.eresolve_tac);
   285 val drule = meth' (gen_arule_tac Tactic.dresolve_tac);
   286 val frule = meth' (gen_arule_tac Tactic.forward_tac);
   287 
   288 end;
   289 
   290 
   291 (* iprover -- intuitionistic proof search *)
   292 
   293 local
   294 
   295 val remdups_tac = SUBGOAL (fn (g, i) =>
   296   let val prems = Logic.strip_assums_hyp g in
   297     REPEAT_DETERM_N (length prems - length (distinct op aconv prems))
   298     (Tactic.ematch_tac [Drule.remdups_rl] i THEN Tactic.eq_assume_tac i)
   299   end);
   300 
   301 fun REMDUPS tac = tac THEN_ALL_NEW remdups_tac;
   302 
   303 val bires_tac = Tactic.biresolution_from_nets_tac ContextRules.orderlist;
   304 
   305 fun safe_step_tac ctxt =
   306   ContextRules.Swrap ctxt
   307    (eq_assume_tac ORELSE'
   308     bires_tac true (ContextRules.netpair_bang ctxt));
   309 
   310 fun unsafe_step_tac ctxt =
   311   ContextRules.wrap ctxt
   312    (assume_tac APPEND'
   313     bires_tac false (ContextRules.netpair_bang ctxt) APPEND'
   314     bires_tac false (ContextRules.netpair ctxt));
   315 
   316 fun step_tac ctxt i =
   317   REPEAT_DETERM1 (REMDUPS (safe_step_tac ctxt) i) ORELSE
   318   REMDUPS (unsafe_step_tac ctxt) i;
   319 
   320 fun intprover_tac ctxt gs d lim = SUBGOAL (fn (g, i) => if d > lim then no_tac else
   321   let
   322     val ps = Logic.strip_assums_hyp g;
   323     val c = Logic.strip_assums_concl g;
   324   in
   325     if member (fn ((ps1, c1), (ps2, c2)) =>
   326         c1 aconv c2 andalso
   327         length ps1 = length ps2 andalso
   328         gen_eq_set (op aconv) (ps1, ps2)) gs (ps, c) then no_tac
   329     else (step_tac ctxt THEN_ALL_NEW intprover_tac ctxt ((ps, c) :: gs) (d + 1) lim) i
   330   end);
   331 
   332 in
   333 
   334 fun iprover_tac ctxt opt_lim =
   335   SELECT_GOAL (DEEPEN (2, the_default 20 opt_lim) (intprover_tac ctxt [] 0) 4 1);
   336 
   337 end;
   338 
   339 
   340 (* ML tactics *)
   341 
   342 val tactic_ref = ref ((fn _ => raise Match): Proof.context -> thm list -> tactic);
   343 fun set_tactic f = tactic_ref := f;
   344 
   345 fun ml_tactic txt ctxt = CRITICAL (fn () =>
   346   (ML_Context.use_mltext
   347     ("let fun tactic (ctxt: Proof.context) (facts: thm list) : tactic =\n"
   348       ^ txt ^ "\nin Method.set_tactic tactic end") false (SOME (Context.Proof ctxt));
   349     ML_Context.setmp (SOME (Context.Proof ctxt)) (! tactic_ref ctxt)));
   350 
   351 fun tactic txt ctxt = METHOD (ml_tactic txt ctxt);
   352 fun raw_tactic txt ctxt = RAW_METHOD (ml_tactic txt ctxt);
   353 
   354 
   355 
   356 (** method syntax **)
   357 
   358 (* method text *)
   359 
   360 type src = Args.src;
   361 
   362 datatype text =
   363   Basic of (Proof.context -> method) * Position.T |
   364   Source of src |
   365   Source_i of src |
   366   Then of text list |
   367   Orelse of text list |
   368   Try of text |
   369   Repeat1 of text |
   370   SelectGoals of int * text;
   371 
   372 fun primitive_text r = Basic (K (SIMPLE_METHOD (PRIMITIVE r)), Position.none);
   373 val succeed_text = Basic (K succeed, Position.none);
   374 val default_text = Source (Args.src (("default", []), Position.none));
   375 val this_text = Basic (K this, Position.none);
   376 val done_text = Basic (K (SIMPLE_METHOD all_tac), Position.none);
   377 fun sorry_text int = Basic (cheating int, Position.none);
   378 
   379 fun finish_text (NONE, immed) pos = Basic (close immed, pos)
   380   | finish_text (SOME txt, immed) pos = Then [txt, Basic (close immed, pos)];
   381 
   382 
   383 (* method definitions *)
   384 
   385 structure MethodsData = TheoryDataFun
   386 (
   387   type T = (((src -> Proof.context -> method) * string) * stamp) NameSpace.table;
   388   val empty = NameSpace.empty_table;
   389   val copy = I;
   390   val extend = I;
   391   fun merge _ tables : T = NameSpace.merge_tables (eq_snd (op =)) tables handle Symtab.DUP dup =>
   392     error ("Attempt to merge different versions of method " ^ quote dup);
   393 );
   394 
   395 fun print_methods thy =
   396   let
   397     val meths = MethodsData.get thy;
   398     fun prt_meth (name, ((_, comment), _)) = Pretty.block
   399       [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment];
   400   in
   401     [Pretty.big_list "methods:" (map prt_meth (NameSpace.extern_table meths))]
   402     |> Pretty.chunks |> Pretty.writeln
   403   end;
   404 
   405 
   406 (* get methods *)
   407 
   408 fun method_i thy =
   409   let
   410     val meths = #2 (MethodsData.get thy);
   411     fun meth src =
   412       let val ((name, _), pos) = Args.dest_src src in
   413         (case Symtab.lookup meths name of
   414           NONE => error ("Unknown proof method: " ^ quote name ^ Position.str_of pos)
   415         | SOME ((mth, _), _) => mth src)
   416       end;
   417   in meth end;
   418 
   419 fun method thy = method_i thy o Args.map_name (NameSpace.intern (#1 (MethodsData.get thy)));
   420 
   421 
   422 (* add method *)
   423 
   424 fun add_methods raw_meths thy =
   425   let
   426     val new_meths = raw_meths |> map (fn (name, f, comment) =>
   427       (name, ((f, comment), stamp ())));
   428 
   429     fun add meths = NameSpace.extend_table (Sign.naming_of thy) new_meths meths
   430       handle Symtab.DUP dup => error ("Duplicate declaration of method " ^ quote dup);
   431   in MethodsData.map add thy end;
   432 
   433 val add_method = add_methods o Library.single;
   434 
   435 
   436 (* method_setup *)
   437 
   438 fun method_setup (name, txt, cmt) =
   439   ML_Context.use_let
   440     "val method: bstring * (Method.src -> Proof.context -> Proof.method) * string"
   441     "Context.map_theory (Method.add_method method)"
   442     ("(" ^ quote name ^ ", " ^ txt ^ ", " ^ quote cmt ^ ")")
   443   |> Context.theory_map;
   444 
   445 
   446 
   447 (** concrete syntax **)
   448 
   449 (* basic *)
   450 
   451 fun syntax scan = Args.context_syntax "method" scan;
   452 
   453 fun simple_args scan f src ctxt : method =
   454   fst (syntax (Scan.lift (scan >> (fn x => f x ctxt))) src ctxt);
   455 
   456 fun ctxt_args (f: Proof.context -> method) src ctxt =
   457   fst (syntax (Scan.succeed (f ctxt)) src ctxt);
   458 
   459 fun no_args m = ctxt_args (K m);
   460 
   461 
   462 (* sections *)
   463 
   464 type modifier = (Proof.context -> Proof.context) * attribute;
   465 
   466 local
   467 
   468 fun thms ss = Scan.repeat (Scan.unless (Scan.lift (Scan.first ss)) Attrib.multi_thm) >> flat;
   469 fun app (f, att) (context, ths) = foldl_map att (Context.map_proof f context, ths);
   470 
   471 fun section ss = Scan.depend (fn context => (Scan.first ss -- Scan.pass context (thms ss)) :|--
   472   (fn (m, ths) => Scan.succeed (app m (context, ths))));
   473 
   474 fun sectioned args ss = args -- Scan.repeat (section ss);
   475 
   476 in
   477 
   478 fun sectioned_args args ss f src ctxt =
   479   let val ((x, _), ctxt') = syntax (sectioned args ss) src ctxt
   480   in f x ctxt' end;
   481 
   482 fun bang_sectioned_args ss f = sectioned_args Args.bang_facts ss f;
   483 fun bang_sectioned_args' ss scan f =
   484   sectioned_args (Args.bang_facts -- scan >> swap) ss (uncurry f);
   485 fun only_sectioned_args ss f = sectioned_args (Scan.succeed ()) ss (fn () => f);
   486 
   487 fun thms_ctxt_args f = sectioned_args (thms []) [] f;
   488 fun thms_args f = thms_ctxt_args (K o f);
   489 fun thm_args f = thms_args (fn [thm] => f thm | _ => error "Single theorem expected");
   490 
   491 end;
   492 
   493 
   494 (* iprover syntax *)
   495 
   496 local
   497 
   498 val introN = "intro";
   499 val elimN = "elim";
   500 val destN = "dest";
   501 val ruleN = "rule";
   502 
   503 fun modifier name kind kind' att =
   504   Args.$$$ name |-- (kind >> K NONE || kind' |-- Args.nat --| Args.colon >> SOME)
   505     >> (pair (I: Proof.context -> Proof.context) o att);
   506 
   507 val iprover_modifiers =
   508  [modifier destN Args.bang_colon Args.bang ContextRules.dest_bang,
   509   modifier destN Args.colon (Scan.succeed ()) ContextRules.dest,
   510   modifier elimN Args.bang_colon Args.bang ContextRules.elim_bang,
   511   modifier elimN Args.colon (Scan.succeed ()) ContextRules.elim,
   512   modifier introN Args.bang_colon Args.bang ContextRules.intro_bang,
   513   modifier introN Args.colon (Scan.succeed ()) ContextRules.intro,
   514   Args.del -- Args.colon >> K (I, ContextRules.rule_del)];
   515 
   516 in
   517 
   518 val iprover_meth =
   519   bang_sectioned_args' iprover_modifiers (Scan.lift (Scan.option Args.nat))
   520     (fn n => fn prems => fn ctxt => METHOD (fn facts =>
   521       HEADGOAL (insert_tac (prems @ facts) THEN'
   522       ObjectLogic.atomize_prems_tac THEN' iprover_tac ctxt n)));
   523 
   524 end;
   525 
   526 
   527 (* tactic syntax *)
   528 
   529 fun nat_thms_args f = uncurry f oo
   530   (fst oo syntax (Scan.lift (Scan.optional (Args.parens Args.nat) 0) -- Attrib.thms));
   531 
   532 fun goal_args' args tac src ctxt = fst (syntax (Args.goal_spec HEADGOAL -- args >>
   533   (fn (quant, s) => SIMPLE_METHOD'' quant (tac s))) src ctxt);
   534 
   535 fun goal_args args tac = goal_args' (Scan.lift args) tac;
   536 
   537 fun goal_args_ctxt' args tac src ctxt =
   538   fst (syntax (Args.goal_spec HEADGOAL -- args >>
   539   (fn (quant, s) => SIMPLE_METHOD'' quant (tac ctxt s))) src ctxt);
   540 
   541 fun goal_args_ctxt args tac = goal_args_ctxt' (Scan.lift args) tac;
   542 
   543 
   544 (* theory setup *)
   545 
   546 val _ = Context.add_setup (add_methods
   547  [("fail", no_args fail, "force failure"),
   548   ("succeed", no_args succeed, "succeed"),
   549   ("-", no_args insert_facts, "do nothing (insert current facts only)"),
   550   ("insert", thms_args insert, "insert theorems, ignoring facts (improper)"),
   551   ("intro", thms_args intro, "repeatedly apply introduction rules"),
   552   ("elim", thms_args elim, "repeatedly apply elimination rules"),
   553   ("unfold", thms_ctxt_args unfold_meth, "unfold definitions"),
   554   ("fold", thms_ctxt_args fold_meth, "fold definitions"),
   555   ("atomize", (atomize o fst) oo syntax (Args.mode "full"),
   556     "present local premises as object-level statements"),
   557   ("iprover", iprover_meth, "intuitionistic proof search"),
   558   ("rule", thms_ctxt_args some_rule, "apply some intro/elim rule"),
   559   ("erule", nat_thms_args erule, "apply rule in elimination manner (improper)"),
   560   ("drule", nat_thms_args drule, "apply rule in destruct manner (improper)"),
   561   ("frule", nat_thms_args frule, "apply rule in forward manner (improper)"),
   562   ("this", no_args this, "apply current facts as rules"),
   563   ("fact", thms_ctxt_args fact, "composition by facts from context"),
   564   ("assumption", ctxt_args assumption, "proof by assumption, preferring facts"),
   565   ("rename_tac", goal_args (Scan.repeat1 Args.name) Tactic.rename_params_tac,
   566     "rename parameters of goal"),
   567   ("rotate_tac", goal_args (Scan.optional Args.int 1) Tactic.rotate_tac,
   568     "rotate assumptions of goal"),
   569   ("tactic", simple_args Args.name tactic, "ML tactic as proof method"),
   570   ("raw_tactic", simple_args Args.name raw_tactic, "ML tactic as raw proof method")]);
   571 
   572 
   573 (* outer parser *)
   574 
   575 local
   576 
   577 structure T = OuterLex;
   578 structure P = OuterParse;
   579 
   580 fun is_symid_meth s =
   581   s <> "|" andalso s <> "?" andalso s <> "+" andalso T.is_sid s;
   582 
   583 fun meth4 x =
   584  (P.position (P.xname >> rpair []) >> (Source o Args.src) ||
   585   P.$$$ "(" |-- P.!!! (meth0 --| P.$$$ ")")) x
   586 and meth3 x =
   587  (meth4 --| P.$$$ "?" >> Try ||
   588   meth4 --| P.$$$ "+" >> Repeat1 ||
   589   meth4 -- (P.$$$ "[" |-- Scan.optional P.nat 1 --| P.$$$ "]") >> (SelectGoals o swap) ||
   590   meth4) x
   591 and meth2 x =
   592  (P.position (P.xname -- P.args1 is_symid_meth false) >> (Source o Args.src) ||
   593   meth3) x
   594 and meth1 x = (P.enum1 "," meth2 >> (fn [m] => m | ms => Then ms)) x
   595 and meth0 x = (P.enum1 "|" meth1 >> (fn [m] => m | ms => Orelse ms)) x;
   596 
   597 in val parse = meth3 end;
   598 
   599 
   600 (*final declarations of this structure!*)
   601 val unfold = unfold_meth;
   602 val fold = fold_meth;
   603 
   604 end;
   605 
   606 structure BasicMethod: BASIC_METHOD = Method;
   607 open BasicMethod;