src/Pure/Isar/method.ML
author wenzelm
Sat Jul 01 19:45:23 2000 +0200 (2000-07-01)
changeset 9222 92ad2341179d
parent 9194 a57987e0250b
child 9294 9ecb78a8d471
permissions -rw-r--r--
removed help_methods;
tuned print_methods;
     1 (*  Title:      Pure/Isar/method.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4     License:    GPL (GNU GENERAL PUBLIC LICENSE)
     5 
     6 Proof methods.
     7 *)
     8 
     9 signature BASIC_METHOD =
    10 sig
    11   val print_methods: theory -> unit
    12   val Method: bstring -> (Args.src -> Proof.context -> Proof.method) -> string -> unit
    13 end;
    14 
    15 signature METHOD =
    16 sig
    17   include BASIC_METHOD
    18   val print_global_rules: theory -> unit
    19   val print_local_rules: Proof.context -> unit
    20   val dest_global: theory attribute
    21   val elim_global: theory attribute
    22   val intro_global: theory attribute
    23   val delrule_global: theory attribute
    24   val dest_local: Proof.context attribute
    25   val elim_local: Proof.context attribute
    26   val intro_local: Proof.context attribute
    27   val delrule_local: Proof.context attribute
    28   val METHOD: (thm list -> tactic) -> Proof.method
    29   val METHOD_CASES:
    30     (thm list -> thm -> (thm * (string * RuleCases.T) list) Seq.seq) -> Proof.method
    31   val METHOD0: tactic -> Proof.method
    32   val fail: Proof.method
    33   val succeed: Proof.method
    34   val defer: int option -> Proof.method
    35   val prefer: int -> Proof.method
    36   val insert_tac: thm list -> int -> tactic
    37   val insert: thm list -> Proof.method
    38   val insert_facts: Proof.method
    39   val unfold: thm list -> Proof.method
    40   val fold: thm list -> Proof.method
    41   val multi_resolve: thm list -> thm -> thm Seq.seq
    42   val multi_resolves: thm list -> thm list -> thm Seq.seq
    43   val resolveq_tac: thm Seq.seq -> int -> tactic
    44   val resolveq_cases_tac: (thm * string list) Seq.seq
    45     -> int -> thm -> (thm * (string * RuleCases.T) list) Seq.seq
    46   val rule_tac: thm list -> thm list -> int -> tactic
    47   val rule: thm list -> Proof.method
    48   val erule: thm list -> Proof.method
    49   val drule: thm list -> Proof.method
    50   val frule: thm list -> Proof.method
    51   val this: Proof.method
    52   val assumption: Proof.context -> Proof.method
    53   val set_tactic: (Proof.context -> thm list -> tactic) -> unit
    54   val tactic: string -> Proof.context -> Proof.method
    55   exception METHOD_FAIL of (string * Position.T) * exn
    56   val method: theory -> Args.src -> Proof.context -> Proof.method
    57   val add_method: bstring * (Args.src -> Proof.context -> Proof.method) * string -> theory -> theory
    58   val add_methods: (bstring * (Args.src -> Proof.context -> Proof.method) * string) list
    59     -> theory -> theory
    60   val syntax: (Proof.context * Args.T list -> 'a * (Proof.context * Args.T list)) ->
    61     Args.src -> Proof.context -> Proof.context * 'a
    62   val simple_args: (Args.T list -> 'a * Args.T list)
    63     -> ('a -> Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    64   val ctxt_args: (Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    65   val no_args: Proof.method -> Args.src -> Proof.context -> Proof.method
    66   type modifier
    67   val sectioned_args: (Proof.context * Args.T list -> 'a * (Proof.context * Args.T list)) ->
    68     (Args.T list -> modifier * Args.T list) list ->
    69     ('a -> Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    70   val bang_sectioned_args:
    71     (Args.T list -> modifier * Args.T list) list ->
    72     (thm list -> Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    73   val only_sectioned_args:
    74     (Args.T list -> modifier * Args.T list) list ->
    75     (Proof.context -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    76   val thms_ctxt_args: (thm list -> Proof.context -> Proof.method)
    77     -> Args.src -> Proof.context -> Proof.method
    78   val thms_args: (thm list -> Proof.method) -> Args.src -> Proof.context -> Proof.method
    79   datatype text =
    80     Basic of (Proof.context -> Proof.method) |
    81     Source of Args.src |
    82     Then of text list |
    83     Orelse of text list |
    84     Try of text |
    85     Repeat1 of text
    86   val refine: text -> Proof.state -> Proof.state Seq.seq
    87   val refine_end: text -> Proof.state -> Proof.state Seq.seq
    88   val proof: text option -> Proof.state -> Proof.state Seq.seq
    89   val local_qed: bool -> text option
    90     -> ({kind: string, name: string, thm: thm} -> unit) * (thm -> unit)
    91     -> Proof.state -> Proof.state Seq.seq
    92   val local_terminal_proof: text * text option
    93     -> ({kind: string, name: string, thm: thm} -> unit) * (thm -> unit)
    94     -> Proof.state -> Proof.state Seq.seq
    95   val local_default_proof: ({kind: string, name: string, thm: thm} -> unit) * (thm -> unit)
    96     -> Proof.state -> Proof.state Seq.seq
    97   val local_immediate_proof: ({kind: string, name: string, thm: thm} -> unit) * (thm -> unit)
    98     -> Proof.state -> Proof.state Seq.seq
    99   val local_done_proof: ({kind: string, name: string, thm: thm} -> unit) * (thm -> unit)
   100     -> Proof.state -> Proof.state Seq.seq
   101   val global_qed: bool -> text option
   102     -> Proof.state -> theory * {kind: string, name: string, thm: thm}
   103   val global_terminal_proof: text * text option
   104     -> Proof.state -> theory * {kind: string, name: string, thm: thm}
   105   val global_default_proof: Proof.state -> theory * {kind: string, name: string, thm: thm}
   106   val global_immediate_proof: Proof.state -> theory * {kind: string, name: string, thm: thm}
   107   val global_done_proof: Proof.state -> theory * {kind: string, name: string, thm: thm}
   108   val setup: (theory -> theory) list
   109 end;
   110 
   111 structure Method: METHOD =
   112 struct
   113 
   114 
   115 (** global and local rule data **)
   116 
   117 fun prt_rules kind ths =
   118   Pretty.writeln (Pretty.big_list ("standard " ^ kind ^ " rules:") (map Display.pretty_thm ths));
   119 
   120 fun print_rules (intro, elim) =
   121   (prt_rules "introduction" intro; prt_rules "elimination" elim);
   122 
   123 fun merge_rules (ths1, ths2) = Library.generic_merge Thm.eq_thm I I ths1 ths2;
   124 
   125 
   126 (* theory data kind 'Isar/rules' *)
   127 
   128 structure GlobalRulesArgs =
   129 struct
   130   val name = "Isar/rules";
   131   type T = thm list * thm list;
   132 
   133   val empty = ([], []);
   134   val copy = I;
   135   val prep_ext = I;
   136   fun merge ((intro1, elim1), (intro2, elim2)) =
   137     (merge_rules (intro1, intro2), merge_rules (elim1, elim2));
   138   fun print _ = print_rules;
   139 end;
   140 
   141 structure GlobalRules = TheoryDataFun(GlobalRulesArgs);
   142 val print_global_rules = GlobalRules.print;
   143 
   144 
   145 (* proof data kind 'Isar/rules' *)
   146 
   147 structure LocalRulesArgs =
   148 struct
   149   val name = "Isar/rules";
   150   type T = thm list * thm list;
   151 
   152   val init = GlobalRules.get;
   153   fun print _ = print_rules;
   154 end;
   155 
   156 structure LocalRules = ProofDataFun(LocalRulesArgs);
   157 val print_local_rules = LocalRules.print;
   158 
   159 
   160 
   161 (** attributes **)
   162 
   163 (* add rules *)
   164 
   165 local
   166 
   167 fun add_rule thm rules = Library.gen_ins Thm.eq_thm (thm, rules);
   168 fun del_rule thm rules = Library.gen_rem Thm.eq_thm (rules, thm);
   169 
   170 fun add_dest thm (intro, elim) = (intro, add_rule (Tactic.make_elim thm) elim);
   171 fun add_elim thm (intro, elim) = (intro, add_rule thm elim);
   172 fun add_intro thm (intro, elim) = (add_rule thm intro, elim);
   173 fun delrule thm (intro, elim) = (del_rule thm intro, del_rule thm elim);
   174 
   175 fun mk_att f g (x, thm) = (f (g thm) x, thm);
   176 
   177 in
   178 
   179 val dest_global = mk_att GlobalRules.map add_dest;
   180 val elim_global = mk_att GlobalRules.map add_elim;
   181 val intro_global = mk_att GlobalRules.map add_intro;
   182 val delrule_global = mk_att GlobalRules.map delrule;
   183 
   184 val dest_local = mk_att LocalRules.map add_dest;
   185 val elim_local = mk_att LocalRules.map add_elim;
   186 val intro_local = mk_att LocalRules.map add_intro;
   187 val delrule_local = mk_att LocalRules.map delrule;
   188 
   189 end;
   190 
   191 
   192 (* concrete syntax *)
   193 
   194 val rule_atts =
   195  [("dest", (Attrib.no_args dest_global, Attrib.no_args dest_local), "declare destruction rule"),
   196   ("elim", (Attrib.no_args elim_global, Attrib.no_args elim_local), "declare elimination rule"),
   197   ("intro", (Attrib.no_args intro_global, Attrib.no_args intro_local), "declare introduction rule"),
   198   ("delrule", (Attrib.no_args delrule_global, Attrib.no_args delrule_local), "undeclare rule")];
   199 
   200 
   201 
   202 (** proof methods **)
   203 
   204 (* make methods *)
   205 
   206 val METHOD = Proof.method;
   207 val METHOD_CASES = Proof.method_cases;
   208 
   209 fun METHOD0 tac = METHOD (fn [] => tac | _ => error "Cannot handle current facts");
   210 
   211 
   212 (* primitive *)
   213 
   214 val fail = METHOD (K no_tac);
   215 val succeed = METHOD (K all_tac);
   216 
   217 
   218 (* shuffle *)
   219 
   220 fun prefer i = METHOD (K (Tactic.defer_tac i THEN PRIMITIVE (Thm.permute_prems 0 ~1)));
   221 fun defer opt_i = METHOD (K (Tactic.defer_tac (if_none opt_i 1)));
   222 
   223 
   224 (* insert *)
   225 
   226 local
   227 
   228 fun cut_rule_tac raw_rule =
   229   let
   230     val rule = Drule.forall_intr_vars raw_rule;
   231     val revcut_rl = Drule.incr_indexes_wrt [] [] [] [rule] Drule.revcut_rl;
   232   in Tactic.rtac (rule COMP revcut_rl) end;
   233 
   234 in
   235 
   236 fun insert_tac [] i = all_tac
   237   | insert_tac facts i = EVERY (map (fn th => cut_rule_tac th i) facts);
   238 
   239 val insert_facts = METHOD (ALLGOALS o insert_tac);
   240 fun insert thms = METHOD (fn _ => ALLGOALS (insert_tac thms));
   241 
   242 end;
   243 
   244 
   245 (* unfold / fold definitions *)
   246 
   247 fun unfold thms = METHOD (fn facts => ALLGOALS (insert_tac facts) THEN rewrite_goals_tac thms);
   248 fun fold thms = METHOD (fn facts => ALLGOALS (insert_tac facts) THEN fold_goals_tac thms);
   249 
   250 
   251 (* multi_resolve *)
   252 
   253 local
   254 
   255 fun res th i rule =
   256   Thm.biresolution false [(false, th)] i rule handle THM _ => Seq.empty;
   257 
   258 fun multi_res _ [] rule = Seq.single rule
   259   | multi_res i (th :: ths) rule = Seq.flat (Seq.map (res th i) (multi_res (i + 1) ths rule));
   260 
   261 in
   262 
   263 val multi_resolve = multi_res 1;
   264 fun multi_resolves facts rules = Seq.flat (Seq.map (multi_resolve facts) (Seq.of_list rules));
   265 
   266 end;
   267 
   268 
   269 (* general rule *)
   270 
   271 fun gen_resolveq_tac tac rules i st =
   272   Seq.flat (Seq.map (fn rule => tac rule i st) rules);
   273 
   274 val resolveq_tac = gen_resolveq_tac Tactic.rtac;
   275 
   276 val resolveq_cases_tac = gen_resolveq_tac (fn (rule, cases) => fn i => fn st =>
   277   Seq.map (rpair (RuleCases.make rule cases)) (Tactic.rtac rule i st));
   278 
   279 
   280 (* simple rule *)
   281 
   282 local
   283 
   284 fun gen_rule_tac tac rules [] = tac rules
   285   | gen_rule_tac tac erules facts = gen_resolveq_tac (tac o single) (multi_resolves facts erules);
   286 
   287 fun gen_rule tac rules = METHOD (HEADGOAL o tac rules);
   288 
   289 fun gen_rule' tac arg_rules ctxt = METHOD (fn facts =>
   290   let val rules =
   291     if not (null arg_rules) then arg_rules
   292     else if null facts then #1 (LocalRules.get ctxt)
   293     else op @ (LocalRules.get ctxt);
   294   in HEADGOAL (tac rules facts) end);
   295 
   296 fun setup raw_tac =
   297   let val tac = gen_rule_tac raw_tac
   298   in (tac, gen_rule tac, gen_rule' tac) end;
   299 
   300 in
   301 
   302 val (rule_tac, rule, some_rule) = setup Tactic.resolve_tac;
   303 val (erule_tac, erule, some_erule) = setup Tactic.eresolve_tac;
   304 val (drule_tac, drule, some_drule) = setup Tactic.dresolve_tac;
   305 val (frule_tac, frule, some_frule) = setup Tactic.forward_tac;
   306 
   307 end;
   308 
   309 
   310 (* this *)
   311 
   312 val this = METHOD (EVERY o map (HEADGOAL o Tactic.rtac));
   313 
   314 
   315 (* assumption *)
   316 
   317 fun assm_tac ctxt =
   318   assume_tac APPEND' resolve_tac (filter Thm.no_prems (ProofContext.prems_of ctxt));
   319 
   320 fun assumption_tac ctxt [] = assm_tac ctxt
   321   | assumption_tac _ [fact] = resolve_tac [fact]
   322   | assumption_tac _ _ = K no_tac;
   323 
   324 fun assumption ctxt = METHOD (HEADGOAL o assumption_tac ctxt);
   325 
   326 
   327 (* res_inst_tac emulations *)
   328 
   329 (*Note: insts refer to the implicit (!) goal context; use at your own risk*)
   330 fun gen_res_inst tac (quant, (insts, thm)) =
   331   METHOD (fn facts => (quant (insert_tac facts THEN' tac insts thm)));
   332 
   333 val res_inst = gen_res_inst Tactic.res_inst_tac;
   334 val eres_inst = gen_res_inst Tactic.eres_inst_tac;
   335 val dres_inst = gen_res_inst Tactic.dres_inst_tac;
   336 val forw_inst = gen_res_inst Tactic.forw_inst_tac;
   337 
   338 
   339 (* simple Prolog interpreter *)
   340 
   341 fun prolog_tac rules facts =
   342   DEPTH_SOLVE_1 (HEADGOAL (Tactic.assume_tac APPEND' Tactic.resolve_tac (facts @ rules)));
   343 
   344 val prolog = METHOD o prolog_tac;
   345 
   346 
   347 (* ML tactics *)
   348 
   349 val tactic_ref = ref ((fn _ => raise Match): Proof.context -> thm list -> tactic);
   350 fun set_tactic f = tactic_ref := f;
   351 
   352 fun tactic txt ctxt = METHOD (fn facts =>
   353  (Context.use_mltext
   354    ("let fun tactic (ctxt: PureIsar.Proof.context) (facts: thm list) : tactic = \
   355     \let val thm = PureIsar.ProofContext.get_thm ctxt and thms = PureIsar.ProofContext.get_thms ctxt in\n"
   356     ^ txt ^
   357     "\nend in PureIsar.Method.set_tactic tactic end")
   358   false (Some (ProofContext.theory_of ctxt)); ! tactic_ref ctxt facts));
   359 
   360 
   361 
   362 (** methods theory data **)
   363 
   364 (* data kind 'Isar/methods' *)
   365 
   366 structure MethodsDataArgs =
   367 struct
   368   val name = "Isar/methods";
   369   type T =
   370     {space: NameSpace.T,
   371      meths: (((Args.src -> Proof.context -> Proof.method) * string) * stamp) Symtab.table};
   372 
   373   val empty = {space = NameSpace.empty, meths = Symtab.empty};
   374   val copy = I;
   375   val prep_ext = I;
   376   fun merge ({space = space1, meths = meths1}, {space = space2, meths = meths2}) =
   377     {space = NameSpace.merge (space1, space2),
   378       meths = Symtab.merge eq_snd (meths1, meths2) handle Symtab.DUPS dups =>
   379         error ("Attempt to merge different versions of methods " ^ commas_quote dups)};
   380 
   381   fun print _ {space, meths} =
   382     let
   383       fun prt_meth (name, ((_, comment), _)) = Pretty.block
   384         [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment];
   385     in
   386       [Pretty.big_list "methods:" (map prt_meth (NameSpace.cond_extern_table space meths))]
   387       |> Pretty.chunks |> Pretty.writeln
   388     end;
   389 end;
   390 
   391 structure MethodsData = TheoryDataFun(MethodsDataArgs);
   392 val print_methods = MethodsData.print;
   393 
   394 
   395 (* get methods *)
   396 
   397 exception METHOD_FAIL of (string * Position.T) * exn;
   398 
   399 fun method thy =
   400   let
   401     val {space, meths} = MethodsData.get thy;
   402 
   403     fun meth src =
   404       let
   405         val ((raw_name, _), pos) = Args.dest_src src;
   406         val name = NameSpace.intern space raw_name;
   407       in
   408         (case Symtab.lookup (meths, name) of
   409           None => error ("Unknown proof method: " ^ quote name ^ Position.str_of pos)
   410         | Some ((mth, _), _) => transform_failure (curry METHOD_FAIL (name, pos)) (mth src))
   411       end;
   412   in meth end;
   413 
   414 
   415 (* add_method(s) *)
   416 
   417 fun add_methods raw_meths thy =
   418   let
   419     val full = Sign.full_name (Theory.sign_of thy);
   420     val new_meths =
   421       map (fn (name, f, comment) => (full name, ((f, comment), stamp ()))) raw_meths;
   422 
   423     val {space, meths} = MethodsData.get thy;
   424     val space' = NameSpace.extend (space, map fst new_meths);
   425     val meths' = Symtab.extend (meths, new_meths) handle Symtab.DUPS dups =>
   426       error ("Duplicate declaration of method(s) " ^ commas_quote dups);
   427   in
   428     thy |> MethodsData.put {space = space', meths = meths'}
   429   end;
   430 
   431 val add_method = add_methods o Library.single;
   432 
   433 (*implicit version*)
   434 fun Method name meth cmt = Context.>> (add_methods [(name, meth, cmt)]);
   435 
   436 
   437 
   438 (** method syntax **)
   439 
   440 (* basic *)
   441 
   442 fun syntax (scan: (Proof.context * Args.T list -> 'a * (Proof.context * Args.T list))) =
   443   Args.syntax "method" scan;
   444 
   445 fun simple_args scan f src ctxt : Proof.method =
   446   #2 (syntax (Scan.lift (scan >> (fn x => f x ctxt))) src ctxt);
   447 
   448 fun ctxt_args (f: Proof.context -> Proof.method) src ctxt =
   449   #2 (syntax (Scan.succeed (f ctxt)) src ctxt);
   450 
   451 fun no_args m = ctxt_args (K m);
   452 
   453 
   454 
   455 (* sections *)
   456 
   457 type modifier = (Proof.context -> Proof.context) * Proof.context attribute;
   458 
   459 local
   460 
   461 fun sect ss = Scan.first (map Scan.lift ss);
   462 fun thms ss = Scan.unless (sect ss) Attrib.local_thms;
   463 fun thmss ss = Scan.repeat (thms ss) >> flat;
   464 
   465 fun apply (f, att) (ctxt, ths) = Thm.applys_attributes ((f ctxt, ths), [att]);
   466 
   467 fun section ss = (sect ss -- thmss ss) :-- (fn (m, ths) => Scan.depend (fn ctxt =>
   468   Scan.succeed (apply m (ctxt, ths)))) >> #2;
   469 
   470 fun sectioned args ss = args -- Scan.repeat (section ss);
   471 
   472 in
   473 
   474 fun sectioned_args args ss f src ctxt =
   475   let val (ctxt', (x, _)) = syntax (sectioned args ss) src ctxt
   476   in f x ctxt' end;
   477 
   478 fun bang_sectioned_args ss f = sectioned_args Args.bang_facts ss f;
   479 fun only_sectioned_args ss f = sectioned_args (Scan.succeed ()) ss (fn () => f);
   480 
   481 fun thms_ctxt_args f = sectioned_args (thmss []) [] f;
   482 fun thms_args f = thms_ctxt_args (K o f);
   483 
   484 end;
   485 
   486 
   487 (* insts *)
   488 
   489 val insts =
   490   Args.enum1 "and" (Scan.lift (Args.name -- Args.!!! (Args.$$$ "=" |-- Args.name))) --
   491     (Scan.lift (Args.$$$ "in") |-- Attrib.local_thm);
   492 
   493 fun inst_args f = f oo (#2 oo syntax (Args.goal_spec HEADGOAL -- insts));
   494 
   495 
   496 (* subgoal *)
   497 
   498 fun subgoal x = (Args.goal_spec HEADGOAL -- Scan.lift Args.name >>
   499   (fn (quant, s) => METHOD (fn facts => quant (insert_tac facts THEN' Tactic.subgoal_tac s)))) x;
   500 
   501 val subgoal_meth = #2 oo syntax subgoal;
   502 
   503 
   504 
   505 (** method text **)
   506 
   507 (* datatype text *)
   508 
   509 datatype text =
   510   Basic of (Proof.context -> Proof.method) |
   511   Source of Args.src |
   512   Then of text list |
   513   Orelse of text list |
   514   Try of text |
   515   Repeat1 of text;
   516 
   517 
   518 (* refine *)
   519 
   520 fun gen_refine f text state =
   521   let
   522     val thy = Proof.theory_of state;
   523 
   524     fun eval (Basic mth) = f mth
   525       | eval (Source src) = f (method thy src)
   526       | eval (Then txts) = Seq.EVERY (map eval txts)
   527       | eval (Orelse txts) = Seq.FIRST (map eval txts)
   528       | eval (Try txt) = Seq.TRY (eval txt)
   529       | eval (Repeat1 txt) = Seq.REPEAT1 (eval txt);
   530   in eval text state end;
   531 
   532 val refine = gen_refine Proof.refine;
   533 val refine_end = gen_refine Proof.refine_end;
   534 
   535 
   536 (* structured proof steps *)
   537 
   538 val default_text = Source (Args.src (("default", []), Position.none));
   539 val this_text = Basic (K this);
   540 val done_text = Basic (K (METHOD0 all_tac));
   541 
   542 fun close_text asm = Basic (fn ctxt => METHOD (K
   543   (FILTER Thm.no_prems ((if asm then ALLGOALS (assm_tac ctxt) else all_tac) THEN flexflex_tac))));
   544 
   545 fun finish_text asm None = close_text asm
   546   | finish_text asm (Some txt) = Then [txt, close_text asm];
   547 
   548 fun proof opt_text state =
   549   state
   550   |> Proof.assert_backward
   551   |> refine (if_none opt_text default_text)
   552   |> Seq.map (Proof.goal_facts (K []))
   553   |> Seq.map Proof.enter_forward;
   554 
   555 fun local_qed asm opt_text = Proof.local_qed (refine (finish_text asm opt_text));
   556 fun local_terminal_proof (text, opt_text) pr =
   557   Seq.THEN (proof (Some text), local_qed true opt_text pr);
   558 val local_default_proof = local_terminal_proof (default_text, None);
   559 val local_immediate_proof = local_terminal_proof (this_text, None);
   560 fun local_done_proof pr = Seq.THEN (proof (Some done_text), local_qed false None pr);
   561 
   562 
   563 fun global_qeds asm opt_text = Proof.global_qed (refine (finish_text asm opt_text));
   564 
   565 fun global_qed asm opt_text state =
   566   state
   567   |> global_qeds asm opt_text
   568   |> Proof.check_result "Failed to finish proof" state
   569   |> Seq.hd;
   570 
   571 fun global_term_proof asm (text, opt_text) state =
   572   state
   573   |> proof (Some text)
   574   |> Proof.check_result "Terminal proof method failed" state
   575   |> (Seq.flat o Seq.map (global_qeds asm opt_text))
   576   |> Proof.check_result "Failed to finish proof (after successful terminal method)" state
   577   |> Seq.hd;
   578 
   579 val global_terminal_proof = global_term_proof true;
   580 val global_default_proof = global_terminal_proof (default_text, None);
   581 val global_immediate_proof = global_terminal_proof (this_text, None);
   582 val global_done_proof = global_term_proof false (done_text, None);
   583 
   584 
   585 (** theory setup **)
   586 
   587 (* pure_methods *)
   588 
   589 val pure_methods =
   590  [("fail", no_args fail, "force failure"),
   591   ("succeed", no_args succeed, "succeed"),
   592   ("-", no_args insert_facts, "do nothing, inserting current facts only"),
   593   ("insert", thms_args insert, "insert theorems, ignoring facts (improper!)"),
   594   ("unfold", thms_args unfold, "unfold definitions"),
   595   ("fold", thms_args fold, "fold definitions"),
   596   ("default", thms_ctxt_args some_rule, "apply some rule"),
   597   ("rule", thms_ctxt_args some_rule, "apply some rule"),
   598   ("erule", thms_ctxt_args some_erule, "apply some rule in elimination manner (improper!)"),
   599   ("drule", thms_ctxt_args some_drule, "apply some rule in destruct manner (improper!)"),
   600   ("frule", thms_ctxt_args some_frule, "apply some rule in forward manner (improper!)"),
   601   ("this", no_args this, "apply current facts as rules"),
   602   ("assumption", ctxt_args assumption, "proof by assumption, preferring facts"),
   603   ("res_inst_tac", inst_args res_inst, "res_inst_tac emulation (dynamic instantiation!)"),
   604   ("eres_inst_tac", inst_args eres_inst, "eres_inst_tac emulation (dynamic instantiation!)"),
   605   ("dres_inst_tac", inst_args dres_inst, "dres_inst_tac emulation (dynamic instantiation!)"),
   606   ("forw_inst_tac", inst_args forw_inst, "forw_inst_tac emulation (dynamic instantiation!)"),
   607   ("subgoal_tac", subgoal_meth, "subgoal_tac emulation (dynamic instantiation!)"),
   608   ("prolog", thms_args prolog, "simple prolog interpreter"),
   609   ("tactic", simple_args Args.name tactic, "ML tactic as proof method")];
   610 
   611 
   612 (* setup *)
   613 
   614 val setup =
   615  [GlobalRules.init, LocalRules.init, Attrib.add_attributes rule_atts,
   616   MethodsData.init, add_methods pure_methods];
   617 
   618 
   619 end;
   620 
   621 
   622 structure BasicMethod: BASIC_METHOD = Method;
   623 open BasicMethod;