src/Pure/Isar/proof.ML
author wenzelm
Sat Jun 05 20:34:53 1999 +0200 (1999-06-05)
changeset 6790 0a39f22f847a
parent 6776 55f1e6b639a4
child 6798 f6bc583a5776
permissions -rw-r--r--
auto_bind_goal, auto_bind_facts;
varify_tfrees: no longer generalize types of free term variables;
let_thms: no bindings;
     1 (*  Title:      Pure/Isar/proof.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4 
     5 Proof states and methods.
     6 *)
     7 
     8 signature PROOF =
     9 sig
    10   type context
    11   type state
    12   exception STATE of string * state
    13   val context_of: state -> context
    14   val theory_of: state -> theory
    15   val sign_of: state -> Sign.sg
    16   val the_facts: state -> thm list
    17   val the_fact: state -> thm
    18   val goal_facts: (state -> thm list) -> state -> state
    19   val use_facts: state -> state
    20   val reset_facts: state -> state
    21   val assert_backward: state -> state
    22   val enter_forward: state -> state
    23   val verbose: bool ref
    24   val print_state: state -> unit
    25   val level: state -> int
    26   type method
    27   val method: (thm list -> thm ->
    28     (thm * (indexname * term) list * (string * thm list) list) Seq.seq) -> method
    29   val refine: (context -> method) -> state -> state Seq.seq
    30   val bind: (indexname * string) list -> state -> state
    31   val bind_i: (indexname * term) list -> state -> state
    32   val match_bind: (string list * string) list -> state -> state
    33   val match_bind_i: (term list * term) list -> state -> state
    34   val have_thmss: string -> context attribute list ->
    35     (thm list * context attribute list) list -> state -> state
    36   val assume: string -> context attribute list -> (string * string list) list -> state -> state
    37   val assume_i: string -> context attribute list -> (term * term list) list -> state -> state
    38   val fix: (string * string option) list -> state -> state
    39   val fix_i: (string * typ) list -> state -> state
    40   val theorem: bstring -> theory attribute list -> string * string list -> theory -> state
    41   val theorem_i: bstring -> theory attribute list -> term * term list -> theory -> state
    42   val lemma: bstring -> theory attribute list -> string * string list -> theory -> state
    43   val lemma_i: bstring -> theory attribute list -> term * term list -> theory -> state
    44   val chain: state -> state
    45   val from_facts: thm list -> state -> state
    46   val show: string -> context attribute list -> string * string list -> state -> state
    47   val show_i: string -> context attribute list -> term * term list -> state -> state
    48   val have: string -> context attribute list -> string * string list -> state -> state
    49   val have_i: string -> context attribute list -> term * term list -> state -> state
    50   val begin_block: state -> state
    51   val next_block: state -> state
    52   val end_block: state -> state
    53   val at_bottom: state -> bool
    54   val local_qed: (state -> state Seq.seq) -> ({kind: string, name: string, thm: thm} -> unit)
    55     -> state -> state Seq.seq
    56   val global_qed: (state -> state Seq.seq) -> bstring option
    57     -> theory attribute list option -> state -> theory * {kind: string, name: string, thm: thm}
    58 end;
    59 
    60 signature PROOF_PRIVATE =
    61 sig
    62   include PROOF
    63   val put_data: Object.kind -> ('a -> Object.T) -> 'a -> state -> state
    64 end;
    65 
    66 structure Proof: PROOF_PRIVATE =
    67 struct
    68 
    69 
    70 (** proof state **)
    71 
    72 type context = ProofContext.context;
    73 
    74 
    75 (* type goal *)
    76 
    77 datatype kind =
    78   Theorem of theory attribute list |    (*top-level theorem*)
    79   Lemma of theory attribute list |      (*top-level lemma*)
    80   Goal of context attribute list |      (*intermediate result, solving subgoal*)
    81   Aux of context attribute list ;       (*intermediate result*)
    82 
    83 val kind_name =
    84   fn Theorem _ => "theorem" | Lemma _ => "lemma" | Goal _ => "show" | Aux _ => "have";
    85 
    86 type goal =
    87  (kind *                (*result kind*)
    88   string *              (*result name*)
    89   cterm list *          (*result assumptions*)
    90   term) *               (*result statement*)
    91  (thm list *            (*use facts*)
    92   thm);                 (*goal: subgoals ==> statement*)
    93 
    94 
    95 (* type mode *)
    96 
    97 datatype mode = Forward | ForwardChain | Backward;
    98 
    99 val mode_name =
   100   fn Forward => "state" | ForwardChain => "chain" | Backward => "prove";
   101 
   102 
   103 (* type node *)
   104 
   105 type node =
   106  {context: context,
   107   facts: thm list option,
   108   mode: mode,
   109   goal: goal option};
   110 
   111 fun make_node (context, facts, mode, goal) =
   112   {context = context, facts = facts, mode = mode, goal = goal}: node;
   113 
   114 
   115 (* datatype state *)
   116 
   117 datatype state =
   118   State of
   119     node *              (*current*)
   120     node list;          (*parents wrt. block structure*)
   121 
   122 exception STATE of string * state;
   123 
   124 fun err_malformed name state =
   125   raise STATE (name ^ ": internal error -- malformed proof state", state);
   126 
   127 
   128 fun map_current f (State ({context, facts, mode, goal}, nodes)) =
   129   State (make_node (f (context, facts, mode, goal)), nodes);
   130 
   131 fun init_state thy =
   132   State (make_node (ProofContext.init thy, None, Forward, None), []);
   133 
   134 
   135 
   136 (** basic proof state operations **)
   137 
   138 (* context *)
   139 
   140 fun context_of (State ({context, ...}, _)) = context;
   141 val theory_of = ProofContext.theory_of o context_of;
   142 val sign_of = ProofContext.sign_of o context_of;
   143 
   144 fun map_context f = map_current (fn (ctxt, facts, mode, goal) => (f ctxt, facts, mode, goal));
   145 
   146 fun map_context_result f (state as State ({context, facts, mode, goal}, nodes)) =
   147   let val (context', result) = f context
   148   in (State (make_node (context', facts, mode, goal), nodes), result) end;
   149 
   150 
   151 fun put_data kind f = map_context o ProofContext.put_data kind f;
   152 val declare_term = map_context o ProofContext.declare_term;
   153 val add_binds = map_context o ProofContext.add_binds_i;
   154 val auto_bind_goal = map_context o ProofContext.auto_bind_goal;
   155 val auto_bind_facts = map_context o ProofContext.auto_bind_facts;
   156 val put_thms = map_context o ProofContext.put_thms;
   157 val put_thmss = map_context o ProofContext.put_thmss;
   158 
   159 
   160 (* bind statements *)
   161 
   162 (* FIXME
   163 fun bind_props bs state =
   164   state |> add_binds (flat (map ObjectLogic.statement_bindings bs)) end;
   165 
   166 fun bind_thms (name, thms) state =
   167   let
   168     val props = map (#prop o Thm.rep_thm) thms;
   169     val named_props =
   170       (case props of
   171         [prop] => [(name, prop)]
   172       | props => map2 (fn (i, t) => (name ^ string_of_int i, t)) (1 upto length props, props));
   173   in state |> bind_props named_props end;
   174 
   175 fun let_thms name_thms state =
   176   state
   177   |> put_thms name_thms
   178   |> bind_thms name_thms;
   179 *)
   180 
   181 (* FIXME elim (!?) *)
   182 
   183 fun let_thms name_thms state =
   184   state
   185   |> put_thms name_thms;
   186 
   187 
   188 (* facts *)
   189 
   190 fun the_facts (State ({facts = Some facts, ...}, _)) = facts
   191   | the_facts state = raise STATE ("No current facts available", state);
   192 
   193 fun the_fact state =
   194   (case the_facts state of
   195     [fact] => fact
   196   | _ => raise STATE ("Single fact expected", state));
   197 
   198 fun put_facts facts state =
   199   state
   200   |> map_current (fn (ctxt, _, mode, goal) => (ctxt, facts, mode, goal))
   201   |> let_thms ("facts", if_none facts []);
   202 
   203 val reset_facts = put_facts None;
   204 
   205 fun have_facts (name, facts) state =
   206   state
   207   |> put_facts (Some facts)
   208   |> let_thms (name, facts);
   209 
   210 fun these_facts (state, ths) = have_facts ths state;
   211 fun fetch_facts (State ({facts, ...}, _)) = put_facts facts;
   212 
   213 
   214 (* goal *)
   215 
   216 fun find_goal i (State ({goal = Some goal, ...}, _)) = (i, goal)
   217   | find_goal i (State ({goal = None, ...}, node :: nodes)) =
   218       find_goal (i + 1) (State (node, nodes))
   219   | find_goal _ (state as State (_, [])) = err_malformed "find_goal" state;
   220 
   221 fun put_goal goal = map_current (fn (ctxt, facts, mode, _) => (ctxt, facts, mode, goal));
   222 
   223 fun map_goal f (State ({context, facts, mode, goal = Some goal}, nodes)) =
   224       State (make_node (context, facts, mode, Some (f goal)), nodes)
   225   | map_goal f (State (nd, node :: nodes)) =
   226       let val State (node', nodes') = map_goal f (State (node, nodes))
   227       in State (nd, node' :: nodes') end
   228   | map_goal _ state = state;
   229 
   230 fun goal_facts get state =
   231   state
   232   |> map_goal (fn (result, (_, thm)) => (result, (get state, thm)));
   233 
   234 fun use_facts state =
   235   state
   236   |> goal_facts the_facts
   237   |> reset_facts;
   238 
   239 
   240 (* mode *)
   241 
   242 fun get_mode (State ({mode, ...}, _)) = mode;
   243 fun put_mode mode = map_current (fn (ctxt, facts, _, goal) => (ctxt, facts, mode, goal));
   244 
   245 val enter_forward = put_mode Forward;
   246 val enter_forward_chain = put_mode ForwardChain;
   247 val enter_backward = put_mode Backward;
   248 
   249 fun assert_mode pred state =
   250   let val mode = get_mode state in
   251     if pred mode then state
   252     else raise STATE ("Illegal application of proof command in " ^ mode_name mode ^ " mode", state)
   253   end;
   254 
   255 fun is_chain state = get_mode state = ForwardChain;
   256 val assert_forward = assert_mode (equal Forward);
   257 val assert_forward_or_chain = assert_mode (equal Forward orf equal ForwardChain);
   258 val assert_backward = assert_mode (equal Backward);
   259 
   260 
   261 (* blocks *)
   262 
   263 fun level (State (_, nodes)) = length nodes;
   264 
   265 fun open_block (State (node, nodes)) = State (node, node :: nodes);
   266 
   267 fun new_block state =
   268   state
   269   |> open_block
   270   |> put_goal None;
   271 
   272 fun close_block (State (_, node :: nodes)) = State (node, nodes)
   273   | close_block state = raise STATE ("Unbalanced block parentheses", state);
   274 
   275 
   276 
   277 (** print_state **)
   278 
   279 val verbose = ProofContext.verbose;
   280 
   281 fun print_facts _ None = ()
   282   | print_facts s (Some ths) =
   283       Pretty.writeln (Pretty.big_list (s ^ " facts:") (map Display.pretty_thm ths));
   284 
   285 fun print_state (state as State ({context, facts, mode, goal = _}, nodes)) =
   286   let
   287     val ref (_, _, begin_goal) = Goals.current_goals_markers;
   288 
   289     fun levels_up 0 = ""
   290       | levels_up i = " (" ^ string_of_int i ^ " levels up)";
   291 
   292     fun print_goal (i, ((kind, name, _, _), (goal_facts, thm))) =
   293       (print_facts "Using" (if null goal_facts then None else Some goal_facts);
   294         writeln (kind_name kind ^ " " ^ quote name ^ levels_up (i div 2) ^ ":");
   295         Locale.print_goals_marker begin_goal (! goals_limit) thm);
   296   in
   297     writeln ("Nesting level: " ^ string_of_int (length nodes div 2));
   298     writeln "";
   299     writeln (enclose "`" "'" (mode_name mode) ^ " mode");
   300     writeln "";
   301     if ! verbose orelse mode = Forward then
   302       (ProofContext.print_context context;
   303         writeln "";
   304         print_facts "Current" facts;
   305         print_goal (find_goal 0 state))
   306     else if mode = ForwardChain then print_facts "Picking" facts
   307     else print_goal (find_goal 0 state)
   308   end;
   309 
   310 
   311 
   312 (** proof steps **)
   313 
   314 (* datatype method *)
   315 
   316 datatype method = Method of
   317   thm list ->                           (*use facts*)
   318   thm                                   (*goal: subgoals ==> statement*)
   319     -> (thm *                           (*refined goal*)
   320        (indexname * term) list *        (*new bindings*)
   321        (string * thm list) list)        (*new thms*)
   322          Seq.seq;
   323 
   324 val method = Method;
   325 
   326 
   327 (* refine goal *)
   328 
   329 fun check_sign sg state =
   330   if Sign.subsig (sg, sign_of state) then state
   331   else raise STATE ("Bad signature of result: " ^ Sign.str_of_sg sg, state);
   332 
   333 fun refine meth_fun (state as State ({context, ...}, _)) =
   334       let
   335         val Method meth = meth_fun context;
   336         val (_, (result, (facts, thm))) = find_goal 0 state;
   337 
   338         fun refn (thm', new_binds, new_thms) =
   339           state
   340           |> check_sign (sign_of_thm thm')
   341           |> map_goal (K (result, (facts, thm')))
   342           |> add_binds new_binds
   343           |> put_thmss new_thms;
   344       in Seq.map refn (meth facts thm) end;
   345 
   346 
   347 (* prepare result *)
   348 
   349 fun varify_frees names thm =
   350   let
   351     fun get_free x (None, t as Free (y, _)) = if x = y then Some t else None
   352       | get_free _ (opt, _) = opt;
   353 
   354     fun find_free t x = foldl_aterms (get_free x) (None, t);
   355 
   356     val {sign, maxidx, prop, ...} = Thm.rep_thm thm;
   357     val frees = map (Thm.cterm_of sign) (mapfilter (find_free prop) names);
   358   in
   359     thm
   360     |> Drule.forall_intr_list frees
   361     |> Drule.forall_elim_vars (maxidx + 1)
   362   end;
   363 
   364 fun varify_tfrees thm =
   365   let
   366     val {hyps, prop, ...} = Thm.rep_thm thm;
   367     val frees = foldr Term.add_term_frees (prop :: hyps, []);
   368     val leave_tfrees = foldr Term.add_term_tfree_names (frees, []);
   369   in thm |> Thm.varifyT' leave_tfrees end;
   370 
   371 fun implies_elim_hyps thm =
   372   foldl (uncurry Thm.implies_elim) (thm, map Thm.assume (Drule.cprems_of thm));
   373 
   374 fun prep_result state asms t raw_thm =
   375   let
   376     val ctxt = context_of state;
   377     fun err msg = raise STATE (msg, state);
   378 
   379     val ngoals = Thm.nprems_of raw_thm;
   380     val _ =
   381       if ngoals = 0 then ()
   382       else (Locale.print_goals ngoals raw_thm; err (string_of_int ngoals ^ " unsolved goal(s)!"));
   383 
   384     val thm =
   385       raw_thm RS Drule.rev_triv_goal
   386       |> implies_elim_hyps
   387       |> Drule.implies_intr_list asms
   388       |> varify_frees (ProofContext.fixed_names ctxt)
   389       |> varify_tfrees;
   390 
   391     val {hyps, prop, sign, ...} = Thm.rep_thm thm;
   392     val tsig = Sign.tsig_of sign;
   393   in
   394 (* FIXME
   395     if not (Pattern.matches tsig (t, Logic.skip_flexpairs prop)) then
   396       warning ("Proved a different theorem: " ^ Sign.string_of_term sign prop)
   397     else ();
   398 *)
   399     if not (null hyps) then
   400       err ("Additional hypotheses:\n" ^ cat_lines (map (Sign.string_of_term sign) hyps))
   401 (* FIXME    else if not (Pattern.matches tsig (t, Logic.skip_flexpairs prop)) then
   402       err ("Proved a different theorem: " ^ Sign.string_of_term sign prop) *)
   403     else (thm, prop)
   404   end;
   405 
   406 
   407 (* prepare final result *)
   408 
   409 fun strip_flexflex thm =
   410   Seq.hd (Thm.flexflex_rule thm) handle THM _ => thm;
   411 
   412 fun final_result state pre_thm =
   413   let
   414     val thm =
   415       pre_thm
   416       |> strip_flexflex
   417       |> Thm.strip_shyps
   418       |> Drule.standard;
   419 
   420     val str_of_sort = Sign.str_of_sort (Thm.sign_of_thm thm);
   421     val xshyps = Thm.extra_shyps thm;
   422   in
   423     if not (null xshyps) then
   424       raise STATE ("Extra sort hypotheses: " ^ commas (map str_of_sort xshyps), state)
   425     else thm
   426   end;
   427 
   428 
   429 (* solve goal *)
   430 
   431 fun solve_goal rule state =
   432   let
   433     val (_, (result, (facts, thm))) = find_goal 0 state;
   434     val thms' = FIRSTGOAL (rtac rule THEN_ALL_NEW (TRY o assume_tac)) thm;
   435   in Seq.map (fn thm' => map_goal (K (result, (facts, thm'))) state) thms' end;
   436 
   437 
   438 
   439 (*** structured proof commands ***)
   440 
   441 (** context **)
   442 
   443 (* bind *)
   444 
   445 fun gen_bind f x state =
   446   state
   447   |> assert_forward
   448   |> map_context (f x)
   449   |> reset_facts;
   450 
   451 val bind = gen_bind ProofContext.add_binds;
   452 val bind_i = gen_bind ProofContext.add_binds_i;
   453 
   454 val match_bind = gen_bind ProofContext.match_binds;
   455 val match_bind_i = gen_bind ProofContext.match_binds_i;
   456 
   457 
   458 (* have_thmss *)
   459 
   460 fun have_thmss name atts ths_atts state =
   461   state
   462   |> assert_forward
   463   |> map_context_result (ProofContext.have_thmss (PureThy.default_name name) atts ths_atts)
   464   |> these_facts;
   465 
   466 
   467 (* fix *)
   468 
   469 fun gen_fix f xs state =
   470   state
   471   |> assert_forward
   472   |> map_context (f xs)
   473   |> reset_facts;
   474 
   475 val fix = gen_fix ProofContext.fix;
   476 val fix_i = gen_fix ProofContext.fix_i;
   477 
   478 
   479 (* assume *)
   480 
   481 fun gen_assume f name atts props state =
   482   state
   483   |> assert_forward
   484   |> map_context_result (f (PureThy.default_name name) atts props)
   485   |> these_facts
   486   |> (fn st => let_thms ("prems", ProofContext.assumptions (context_of st)) st);
   487 
   488 val assume = gen_assume ProofContext.assume;
   489 val assume_i = gen_assume ProofContext.assume_i;
   490 
   491 
   492 
   493 (** goals **)
   494 
   495 (* forward chaining *)
   496 
   497 fun chain state =
   498   state
   499   |> assert_forward
   500   |> enter_forward_chain;
   501 
   502 fun from_facts facts state =
   503   state
   504   |> put_facts (Some facts)
   505   |> chain;
   506 
   507 
   508 (* setup goals *)
   509 
   510 fun setup_goal opt_block prepp kind name atts raw_propp state =
   511   let
   512     val (state', concl) =
   513       state
   514       |> assert_forward_or_chain
   515       |> enter_forward
   516       |> opt_block
   517       |> map_context_result (fn c => prepp (c, raw_propp));
   518     val cterm_of = Thm.cterm_of (sign_of state);
   519 
   520     val casms = map (#prop o Thm.crep_thm) (ProofContext.assumptions (context_of state'));
   521     val cprems = map cterm_of (Logic.strip_imp_prems concl);
   522     val prop = Logic.list_implies (map Thm.term_of casms, concl);
   523     val cprop = cterm_of prop;
   524     val thm = Drule.mk_triv_goal cprop;
   525   in
   526     state'
   527     |> put_goal (Some ((kind atts, (PureThy.default_name name), casms @ cprems, prop), ([], thm)))
   528     |> auto_bind_goal prop
   529     |> (if is_chain state then use_facts else reset_facts)
   530     |> new_block
   531     |> enter_backward
   532   end;
   533 
   534 
   535 (*global goals*)
   536 fun global_goal prep kind name atts x thy =
   537   setup_goal I prep kind name atts x (init_state thy);
   538 
   539 val theorem = global_goal ProofContext.bind_propp Theorem;
   540 val theorem_i = global_goal ProofContext.bind_propp_i Theorem;
   541 val lemma = global_goal ProofContext.bind_propp Lemma;
   542 val lemma_i = global_goal ProofContext.bind_propp_i Lemma;
   543 
   544 
   545 (*local goals*)
   546 fun local_goal prep kind name atts x =
   547   setup_goal open_block prep kind name atts x;
   548 
   549 val show   = local_goal ProofContext.bind_propp Goal;
   550 val show_i = local_goal ProofContext.bind_propp_i Goal;
   551 val have   = local_goal ProofContext.bind_propp Aux;
   552 val have_i = local_goal ProofContext.bind_propp_i Aux;
   553 
   554 
   555 
   556 (** blocks **)
   557 
   558 (* begin_block *)
   559 
   560 fun begin_block state =
   561   state
   562   |> assert_forward
   563   |> new_block
   564   |> reset_facts
   565   |> open_block;
   566 
   567 
   568 (* next_block *)
   569 
   570 fun next_block state =
   571   state
   572   |> assert_forward
   573   |> close_block
   574   |> new_block;
   575 
   576 
   577 
   578 (** conclusions **)
   579 
   580 (* current goal *)
   581 
   582 fun current_goal (State ({goal = Some goal, ...}, _)) = goal
   583   | current_goal state = raise STATE ("No current goal!", state);
   584 
   585 fun assert_current_goal true (state as State ({goal = None, ...}, _)) =
   586       raise STATE ("No goal in this block!", state)
   587   | assert_current_goal false (state as State ({goal = Some _, ...}, _)) =
   588       raise STATE ("Goal present in this block!", state)
   589   | assert_current_goal _ state = state;
   590 
   591 fun assert_bottom true (state as State (_, _ :: _)) =
   592       raise STATE ("Not at bottom of proof!", state)
   593   | assert_bottom false (state as State (_, [])) =
   594       raise STATE ("Already at bottom of proof!", state)
   595   | assert_bottom _ state = state;
   596 
   597 val at_bottom = can (assert_bottom true o close_block);
   598 
   599 
   600 (* finish proof *)
   601 
   602 fun check_finished state states =
   603   (case Seq.pull states of
   604     None => raise STATE ("Failed to finish proof", state)
   605   | Some s_sq => Seq.cons s_sq);
   606 
   607 fun finish_proof bot finalize state =
   608   state
   609   |> assert_forward
   610   |> close_block
   611   |> assert_bottom bot
   612   |> assert_current_goal true
   613   |> finalize
   614   |> check_finished state;
   615 
   616 
   617 (* end_block *)
   618 
   619 fun end_block state =
   620   state
   621   |> assert_forward
   622   |> close_block
   623   |> assert_current_goal false
   624   |> close_block
   625   |> fetch_facts state;
   626 
   627 
   628 (* local_qed *)
   629 
   630 fun finish_local print_result state =
   631   let
   632     val ((kind, name, asms, t), (_, raw_thm)) = current_goal state;
   633     val (result, result_prop) = prep_result state asms t raw_thm;
   634     val (atts, opt_solve) =
   635       (case kind of
   636         Goal atts => (atts, solve_goal result)
   637       | Aux atts => (atts, Seq.single)
   638       | _ => raise STATE ("No local goal!", state));
   639   in
   640     print_result {kind = kind_name kind, name = name, thm = result};
   641     state
   642     |> close_block
   643     |> auto_bind_facts [result_prop]
   644     |> have_thmss name atts [Thm.no_attributes [result]]
   645     |> opt_solve
   646   end;
   647 
   648 fun local_qed finalize print_result state =
   649   state
   650   |> finish_proof false finalize
   651   |> (Seq.flat o Seq.map (finish_local print_result));
   652 
   653 
   654 (* global_qed *)
   655 
   656 fun finish_global alt_name alt_atts state =
   657   let
   658     val ((kind, def_name, asms, t), (_, raw_thm)) = current_goal state;
   659     val result = final_result state (#1 (prep_result state asms t raw_thm));
   660 
   661     val name = if_none alt_name def_name;
   662     val atts =
   663       (case kind of
   664         Theorem atts => if_none alt_atts atts
   665       | Lemma atts => (if_none alt_atts atts) @ [Drule.tag_lemma]
   666       | _ => raise STATE ("No global goal!", state));
   667 
   668     val (thy', result') = PureThy.store_thm ((name, result), atts) (theory_of state);
   669   in (thy', {kind = kind_name kind, name = name, thm = result'}) end;
   670 
   671 fun global_qed finalize alt_name alt_atts state =
   672   state
   673   |> finish_proof true finalize
   674   |> Seq.hd
   675   |> finish_global alt_name alt_atts;
   676 
   677 
   678 end;