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