src/HOL/Tools/res_atp.ML
author paulson
Wed Apr 19 10:41:37 2006 +0200 (2006-04-19 ago)
changeset 19445 da75577642a9
parent 19442 ad8bb8346e51
child 19450 651d949776f8
permissions -rw-r--r--
tidying; ATP options including CASC mode for Vampire
     1 (*  Author: Jia Meng, Cambridge University Computer Laboratory, NICTA
     2     ID: $Id$
     3     Copyright 2004 University of Cambridge
     4 
     5 ATPs with TPTP format input.
     6 *)
     7 
     8 signature RES_ATP =
     9 sig
    10   val prover: string ref
    11   val custom_spass: string list ref
    12   val destdir: string ref
    13   val helper_path: string -> string -> string
    14   val problem_name: string ref
    15   val time_limit: int ref
    16    
    17   datatype mode = Auto | Fol | Hol
    18   val write_subgoal_file: mode -> Proof.context -> thm list -> thm list -> int -> string
    19   val vampire_time: int ref
    20   val eprover_time: int ref
    21   val run_vampire: int -> unit
    22   val run_eprover: int -> unit
    23   val vampireLimit: unit -> int
    24   val eproverLimit: unit -> int
    25   val atp_method: (ProofContext.context -> thm list -> int -> Tactical.tactic) ->
    26 		  Method.src -> ProofContext.context -> Method.method
    27   val cond_rm_tmp: string -> unit
    28   val keep_atp_input: bool ref
    29   val fol_keep_types: bool ref
    30   val hol_full_types: unit -> unit
    31   val hol_partial_types: unit -> unit
    32   val hol_const_types_only: unit -> unit
    33   val hol_no_types: unit -> unit
    34   val hol_typ_level: unit -> ResHolClause.type_level
    35   val run_relevance_filter: bool ref
    36   val invoke_atp_ml : ProofContext.context * thm -> unit
    37   val add_claset : unit -> unit
    38   val add_simpset : unit -> unit
    39   val add_clasimp : unit -> unit
    40   val add_atpset : unit -> unit
    41   val rm_claset : unit -> unit
    42   val rm_simpset : unit -> unit
    43   val rm_atpset : unit -> unit
    44   val rm_clasimp : unit -> unit
    45 end;
    46 
    47 structure ResAtp : RES_ATP =
    48 struct
    49 
    50 (********************************************************************)
    51 (* some settings for both background automatic ATP calling procedure*)
    52 (* and also explicit ATP invocation methods                         *)
    53 (********************************************************************)
    54 
    55 (*** background linkup ***)
    56 val call_atp = ref false; 
    57 val hook_count = ref 0;
    58 val time_limit = ref 30;
    59 val prover = ref "E";   (* use E as the default prover *)
    60 val custom_spass =   (*specialized options for SPASS*)
    61       ref ["-Auto=0","-FullRed=0","-IORe","-IOFc","-RTaut","-RFSub","-RBSub"];
    62 val destdir = ref "";   (*Empty means write files to /tmp*)
    63 val problem_name = ref "prob";
    64 
    65 (*Return the path to a "helper" like SPASS or tptp2X, first checking that
    66   it exists.  FIXME: modify to use Path primitives and move to some central place.*)  
    67 fun helper_path evar base =
    68   case getenv evar of
    69       "" => error  ("Isabelle environment variable " ^ evar ^ " not defined")
    70     | home => 
    71         let val path = home ^ "/" ^ base
    72         in  if File.exists (File.unpack_platform_path path) then path 
    73 	    else error ("Could not find the file " ^ path)
    74 	end;  
    75 
    76 fun probfile_nosuffix _ = 
    77   if !destdir = "" then File.platform_path (File.tmp_path (Path.basic (!problem_name)))
    78   else if File.exists (File.unpack_platform_path (!destdir))
    79   then !destdir ^ "/" ^ !problem_name
    80   else error ("No such directory: " ^ !destdir);
    81 
    82 fun prob_pathname n = probfile_nosuffix n ^ "_" ^ Int.toString n;
    83 
    84 
    85 (*** ATP methods ***)
    86 val vampire_time = ref 60;
    87 val eprover_time = ref 60;
    88 fun run_vampire time =  
    89     if (time >0) then vampire_time:= time
    90     else vampire_time:=60;
    91 
    92 fun run_eprover time = 
    93     if (time > 0) then eprover_time:= time
    94     else eprover_time:=60;
    95 
    96 fun vampireLimit () = !vampire_time;
    97 fun eproverLimit () = !eprover_time;
    98 
    99 val keep_atp_input = ref false;
   100 val fol_keep_types = ResClause.keep_types;
   101 val hol_full_types = ResHolClause.full_types;
   102 val hol_partial_types = ResHolClause.partial_types;
   103 val hol_const_types_only = ResHolClause.const_types_only;
   104 val hol_no_types = ResHolClause.no_types;
   105 fun hol_typ_level () = ResHolClause.find_typ_level ();
   106 fun is_typed_hol () = 
   107     let val tp_level = hol_typ_level()
   108     in
   109 	not (tp_level = ResHolClause.T_NONE)
   110     end;
   111 val include_combS = ResHolClause.include_combS;
   112 val include_min_comb = ResHolClause.include_min_comb;
   113 
   114 fun atp_input_file () =
   115     let val file = !problem_name 
   116     in
   117 	if !destdir = "" then File.platform_path (File.tmp_path (Path.basic file))
   118 	else if File.exists (File.unpack_platform_path (!destdir))
   119 	then !destdir ^ "/" ^ file
   120 	else error ("No such directory: " ^ !destdir)
   121     end;
   122 
   123 val include_simpset = ref false;
   124 val include_claset = ref false; 
   125 val include_atpset = ref true;
   126 val add_simpset = (fn () => include_simpset:=true);
   127 val add_claset = (fn () => include_claset:=true);
   128 val add_clasimp = (fn () => (include_simpset:=true;include_claset:=true));
   129 val add_atpset = (fn () => include_atpset:=true);
   130 val rm_simpset = (fn () => include_simpset:=false);
   131 val rm_claset = (fn () => include_claset:=false);
   132 val rm_clasimp = (fn () => (include_simpset:=false;include_claset:=false));
   133 val rm_atpset = (fn () => include_atpset:=false);
   134 
   135 (*** paths for HOL helper files ***)
   136 fun full_typed_comb_inclS () =
   137     helper_path "E_HOME" "additionals/full_comb_inclS"
   138     handle _ => helper_path "VAMPIRE_HOME" "additionals/full_comb_inclS";
   139 
   140 fun full_typed_comb_noS () =
   141     helper_path "E_HOME" "additionals/full_comb_noS"
   142     handle _ => helper_path "VAMPIRE_HOME" "additionals/full_comb_noS";
   143 									      
   144 fun partial_typed_comb_inclS () =
   145     helper_path "E_HOME" "additionals/par_comb_inclS"
   146     handle _ => helper_path "VAMPIRE_HOME" "additionals/par_comb_inclS";
   147 
   148 fun partial_typed_comb_noS () =
   149     helper_path "E_HOME" "additionals/par_comb_noS"
   150     handle _ => helper_path "VAMPIRE_HOME" "additionals/par_comb_noS";
   151 
   152 fun const_typed_comb_inclS () =
   153     helper_path "E_HOME" "additionals/const_comb_inclS"
   154     handle _ => helper_path "VAMPIRE_HOME" "additionals/const_comb_inclS";
   155 
   156 fun const_typed_comb_noS () =
   157     helper_path "E_HOME" "additionals/const_comb_noS"
   158     handle _ => helper_path "VAMPIRE_HOME" "additionals/const_comb_noS";
   159 
   160 fun untyped_comb_inclS () =
   161     helper_path "E_HOME" "additionals/u_comb_inclS"
   162     handle _ => helper_path "VAMPIRE_HOME" "additionals/u_comb_inclS";
   163 
   164 fun untyped_comb_noS () =
   165     helper_path "E_HOME" "additionals/u_comb_noS"
   166     handle _ => helper_path "VAMPIRE_HOME" "additionals/u_comb_noS";
   167 
   168 fun full_typed_HOL_helper1 () =
   169     helper_path "E_HOME" "additionals/full_helper1"
   170     handle _ => helper_path "VAMPIRE_HOME" "additionals/full_helper1";
   171 
   172 fun partial_typed_HOL_helper1 () = 
   173     helper_path "E_HOME" "additionals/par_helper1"
   174     handle _ => helper_path "VAMPIRE_HOME" "additionals/par_helper1";
   175 
   176 fun const_typed_HOL_helper1 () = 
   177     helper_path "E_HOME" "additionals/const_helper1"
   178     handle _ => helper_path "VAMPIRE_HOME" "additionals/const_helper1";
   179 
   180 fun untyped_HOL_helper1 () = 
   181     helper_path "E_HOME" "additionals/u_helper1"
   182     handle _ => helper_path "VAMPIRE_HOME" "additionals/u_helper1";
   183 
   184 fun get_full_typed_helpers () =
   185     (full_typed_HOL_helper1 (), full_typed_comb_noS (), full_typed_comb_inclS ());
   186 
   187 fun get_partial_typed_helpers () =
   188     (partial_typed_HOL_helper1 (), partial_typed_comb_noS (), partial_typed_comb_inclS ());
   189 
   190 fun get_const_typed_helpers () =
   191     (const_typed_HOL_helper1 (), const_typed_comb_noS (), const_typed_comb_inclS ());
   192 
   193 fun get_untyped_helpers () =
   194     (untyped_HOL_helper1 (), untyped_comb_noS (), untyped_comb_inclS ());
   195 
   196 fun get_all_helpers () =
   197     (get_full_typed_helpers (), get_partial_typed_helpers (), get_const_typed_helpers (), get_untyped_helpers ());
   198 
   199 
   200 (**** relevance filter ****)
   201 val run_relevance_filter = ref true;
   202 
   203 (******************************************************************)
   204 (* detect whether a given problem (clauses) is FOL/HOL/HOLC/HOLCS *)
   205 (******************************************************************)
   206 
   207 datatype logic = FOL | HOL | HOLC | HOLCS;
   208 
   209 fun string_of_logic FOL = "FOL"
   210   | string_of_logic HOL = "HOL"
   211   | string_of_logic HOLC = "HOLC"
   212   | string_of_logic HOLCS = "HOLCS";
   213 
   214 
   215 fun is_fol_logic FOL = true
   216   | is_fol_logic  _ = false
   217 
   218 
   219 (*HOLCS will not occur here*)
   220 fun upgrade_lg HOLC _ = HOLC
   221   | upgrade_lg HOL HOLC = HOLC
   222   | upgrade_lg HOL _ = HOL
   223   | upgrade_lg FOL lg = lg; 
   224 
   225 (* check types *)
   226 fun has_bool (Type("bool",_)) = true
   227   | has_bool (Type(_, Ts)) = exists has_bool Ts
   228   | has_bool _ = false;
   229 
   230 fun has_bool_arg tp = 
   231     let val (targs,tr) = strip_type tp
   232     in
   233 	exists has_bool targs
   234     end;
   235 
   236 fun is_fn_tp (Type("fun",_)) = true
   237   | is_fn_tp _ = false;
   238 
   239 
   240 exception FN_LG of term;
   241 
   242 fun fn_lg (t as Const(f,tp)) (lg,seen) = 
   243     if has_bool tp then (upgrade_lg HOL lg, t ins seen) else (lg, t ins seen) 
   244   | fn_lg (t as Free(f,tp)) (lg,seen) = 
   245     if has_bool tp then (upgrade_lg HOL lg, t ins seen) else (lg, t ins seen) 
   246   | fn_lg (t as Var(f,tp)) (lg,seen) =
   247     if is_fn_tp tp orelse has_bool tp then (upgrade_lg HOL lg,t ins seen)
   248     else (lg,t ins seen)
   249   | fn_lg (t as Abs(_,_,_)) (lg,seen) = (upgrade_lg HOLC lg,t ins seen)
   250   | fn_lg f _ = raise FN_LG(f); 
   251 
   252 
   253 fun term_lg [] (lg,seen) = (lg,seen)
   254   | term_lg (tm::tms) (FOL,seen) =
   255     let val (f,args) = strip_comb tm
   256 	val (lg',seen') = if f mem seen then (FOL,seen) 
   257 			  else fn_lg f (FOL,seen)
   258 
   259 	 in
   260 	     term_lg (args@tms) (lg',seen')
   261     end
   262   | term_lg _ (lg,seen) = (lg,seen)
   263 
   264 exception PRED_LG of term;
   265 
   266 fun pred_lg (t as Const(P,tp)) (lg,seen)= 
   267     if has_bool_arg tp then (upgrade_lg HOL lg, t ins seen) else (lg,t ins seen) 
   268   | pred_lg (t as Free(P,tp)) (lg,seen) =
   269     if has_bool_arg tp then (upgrade_lg HOL lg, t ins seen) else (lg,t ins seen)
   270   | pred_lg (t as Var(_,_)) (lg,seen) = (upgrade_lg HOL lg, t ins seen)
   271   | pred_lg P _ = raise PRED_LG(P);
   272 
   273 
   274 fun lit_lg (Const("Not",_) $ P) (lg,seen) = lit_lg P (lg,seen)
   275   | lit_lg P (lg,seen) =
   276     let val (pred,args) = strip_comb P
   277 	val (lg',seen') = if pred mem seen then (lg,seen) 
   278 			  else pred_lg pred (lg,seen)
   279 	val _ = if is_fol_logic lg' then () else warning ("Found a HOL predicate: " ^ (Term.str_of_term pred))
   280     in
   281 	term_lg args (lg',seen')
   282     end;
   283 
   284 fun lits_lg [] (lg,seen) = (lg,seen)
   285   | lits_lg (lit::lits) (FOL,seen) =
   286     let val (lg,seen') = lit_lg lit (FOL,seen)
   287 	val _ =  if is_fol_logic lg then () else warning ("Found a HOL literal: " ^ (Term.str_of_term lit))
   288     in
   289 	lits_lg lits (lg,seen')
   290     end
   291   | lits_lg lits (lg,seen) = (lg,seen);
   292 
   293 
   294 fun dest_disj_aux (Const ("op |", _) $ t $ t') disjs = 
   295     dest_disj_aux t (dest_disj_aux t' disjs)
   296   | dest_disj_aux t disjs = t::disjs;
   297 
   298 fun dest_disj t = dest_disj_aux t [];
   299 
   300 fun logic_of_clause tm (lg,seen) =
   301     let val tm' = HOLogic.dest_Trueprop tm
   302 	val disjs = dest_disj tm'
   303     in
   304 	lits_lg disjs (lg,seen)
   305     end;
   306 
   307 fun logic_of_clauses [] (lg,seen) = (lg,seen)
   308   | logic_of_clauses (cls::clss) (FOL,seen) =
   309     let val (lg,seen') = logic_of_clause cls (FOL,seen)
   310 	val _ = if is_fol_logic lg then () else warning ("Found a HOL clause: " ^ (Term.str_of_term cls))
   311     in
   312 	logic_of_clauses clss (lg,seen')
   313     end
   314   | logic_of_clauses (cls::clss) (lg,seen) = (lg,seen);
   315 
   316 fun problem_logic_goals_aux [] (lg,seen) = lg
   317   | problem_logic_goals_aux (subgoal::subgoals) (lg,seen) = 
   318     problem_logic_goals_aux subgoals (logic_of_clauses subgoal (lg,seen));
   319     
   320 fun problem_logic_goals subgoals = problem_logic_goals_aux subgoals (FOL,[]);
   321 
   322 
   323 (***************************************************************)
   324 (* ATP invocation methods setup                                *)
   325 (***************************************************************)
   326 
   327 
   328 (**** prover-specific format: TPTP ****)
   329 
   330 
   331 fun cnf_hyps_thms ctxt = 
   332     let val ths = ProofContext.prems_of ctxt
   333     in
   334 	ResClause.union_all (map ResAxioms.skolem_thm ths)
   335     end;
   336 
   337 
   338 (**** write to files ****)
   339 
   340 datatype mode = Auto | Fol | Hol;
   341 
   342 val linkup_logic_mode = ref Fol;
   343 
   344 fun tptp_writer logic goals filename (axioms,classrels,arities) =
   345     if is_fol_logic logic 
   346     then ResClause.tptp_write_file goals filename (axioms, classrels, arities)
   347     else ResHolClause.tptp_write_file goals filename (axioms, classrels, arities) 
   348 	   (get_all_helpers());
   349 
   350 (*2006-04-07: not working: goals has type thm list (not term list as above) and
   351   axioms has type ResClause.clause list (not (thm * (string * int)) list as above)*)
   352 fun dfg_writer logic goals filename (axioms,classrels,arities) =
   353     if is_fol_logic logic 
   354     then ResClause.dfg_write_file goals filename (axioms, classrels, arities)
   355     else error "DFG output for higher-order translations is not implemented"
   356 
   357 
   358 fun write_subgoal_file mode ctxt conjectures user_thms n =
   359     let val conj_cls = make_clauses conjectures 
   360 	val hyp_cls = cnf_hyps_thms ctxt
   361 	val goal_cls = conj_cls@hyp_cls
   362 	val user_rules = map ResAxioms.pairname user_thms
   363 	val (names_arr,axclauses_as_thms) = ResClasimp.get_clasimp_atp_lemmas ctxt (map prop_of goal_cls) user_rules (!include_claset,!include_simpset,!include_atpset) (!run_relevance_filter)  
   364 	val thy = ProofContext.theory_of ctxt
   365 	val prob_logic = case mode of Auto => problem_logic_goals [map prop_of goal_cls]
   366 				    | Fol => FOL
   367 				    | Hol => HOL
   368 	val keep_types = if is_fol_logic prob_logic then !fol_keep_types else is_typed_hol ()
   369 	val classrel_clauses = if keep_types then ResClause.classrel_clauses_thy thy else []
   370 	val arity_clauses = if keep_types then ResClause.arity_clause_thy thy else []
   371         val writer = (*if !prover = "spass" then dfg_writer else*) tptp_writer 
   372 	val file = atp_input_file()
   373     in
   374 	(writer prob_logic goal_cls file (axclauses_as_thms,classrel_clauses,arity_clauses);
   375 	 warning ("Writing to " ^ file);
   376 	 file)
   377     end;
   378 
   379 
   380 (**** remove tmp files ****)
   381 fun cond_rm_tmp file = 
   382     if !keep_atp_input then warning "ATP input kept..." 
   383     else if !destdir <> "" then warning ("ATP input kept in directory " ^ (!destdir))
   384     else (warning "deleting ATP inputs..."; OS.FileSys.remove file);
   385 
   386 
   387 (****** setup ATPs as Isabelle methods ******)
   388 fun atp_meth' tac ths ctxt = 
   389     Method.SIMPLE_METHOD' HEADGOAL
   390     (tac ctxt ths);
   391 
   392 fun atp_meth tac ths ctxt = 
   393     let val thy = ProofContext.theory_of ctxt
   394 	val _ = ResClause.init thy
   395 	val _ = ResHolClause.init thy
   396     in
   397 	atp_meth' tac ths ctxt
   398     end;
   399 
   400 fun atp_method tac = Method.thms_ctxt_args (atp_meth tac);
   401 
   402 (***************************************************************)
   403 (* automatic ATP invocation                                    *)
   404 (***************************************************************)
   405 
   406 (* call prover with settings and problem file for the current subgoal *)
   407 fun watcher_call_provers sign sg_terms (childin, childout, pid) =
   408   let
   409     fun make_atp_list [] n = []
   410       | make_atp_list (sg_term::xs) n =
   411           let
   412             val probfile = prob_pathname n
   413             val time = Int.toString (!time_limit)
   414           in
   415             Output.debug ("problem file in watcher_call_provers is " ^ probfile);
   416             (*options are separated by Watcher.setting_sep, currently #"%"*)
   417             if !prover = "spass"
   418             then
   419               let val spass = helper_path "SPASS_HOME" "SPASS"
   420                   val sopts =
   421    "-Auto%-SOS=1%-PGiven=0%-PProblem=0%-Splits=0%-FullRed=0%-DocProof%-TimeLimit=" ^ time
   422               in 
   423                   ("spass", spass, sopts, probfile) :: make_atp_list xs (n+1)
   424               end
   425             else if !prover = "vampire"
   426 	    then 
   427               let val vampire = helper_path "VAMPIRE_HOME" "vampire"
   428                   val casc = if !time_limit > 70 then "--mode casc%" else ""
   429                   val vopts = casc ^ "-m 100000%-t " ^ time
   430               in
   431                   ("vampire", vampire, vopts, probfile) :: make_atp_list xs (n+1)
   432               end
   433       	     else if !prover = "E"
   434       	     then
   435 	       let val Eprover = helper_path "E_HOME" "eproof"
   436 	       in
   437 		  ("E", Eprover, 
   438 		     "--tptp-in%-l5%-xAuto%-tAuto%--cpu-limit=" ^ time, probfile) ::
   439 		   make_atp_list xs (n+1)
   440 	       end
   441 	     else error ("Invalid prover name: " ^ !prover)
   442           end
   443 
   444     val atp_list = make_atp_list sg_terms 1
   445   in
   446     Watcher.callResProvers(childout,atp_list);
   447     Output.debug "Sent commands to watcher!"
   448   end
   449 
   450 (*We write out problem files for each subgoal. Argument pf generates filenames,
   451   and allows the suppression of the suffix "_1" in problem-generation mode.
   452   FIXME: does not cope with &&, and it isn't easy because one could have multiple
   453   subgoals, each involving &&.*)
   454 fun write_problem_files pf (ctxt,th)  =
   455   let val goals = Thm.prems_of th
   456       val _ = Output.debug ("number of subgoals = " ^ Int.toString (length goals))
   457       val (names_arr, axclauses) = ResClasimp.get_clasimp_atp_lemmas ctxt goals [] (true,true,true) (!run_relevance_filter) (* no user supplied rules here, because no user invocation *)
   458       val _ = Output.debug ("claset, simprules and atprules total clauses = " ^ 
   459                      Int.toString (Array.length names_arr))
   460       val thy = ProofContext.theory_of ctxt
   461       fun get_neg_subgoals n =
   462 	  if n=0 then []
   463 	  else
   464 	      let val st = Seq.hd (EVERY'
   465 				       [rtac ccontr, ObjectLogic.atomize_tac, skolemize_tac] n th)
   466 		  val negs = Option.valOf (metahyps_thms n st)
   467 		  val negs_clauses = make_clauses negs
   468 	      in
   469 		  negs_clauses::(get_neg_subgoals (n - 1))
   470 	      end
   471       val neg_subgoals = get_neg_subgoals (length goals) 
   472       val goals_logic = case !linkup_logic_mode of Auto => problem_logic_goals (map (map prop_of) neg_subgoals)
   473 						 | Fol => FOL
   474 						 | Hol => HOL
   475       val keep_types = if is_fol_logic goals_logic then !ResClause.keep_types else is_typed_hol ()
   476       val classrel_clauses = if keep_types then ResClause.classrel_clauses_thy thy else []
   477       val _ = Output.debug ("classrel clauses = " ^ Int.toString (length classrel_clauses))
   478       val arity_clauses = if keep_types then ResClause.arity_clause_thy thy else []
   479       val _ = Output.debug ("arity clauses = " ^ Int.toString (length arity_clauses))
   480       val writer = (*if !prover = "spass" then dfg_writer else*) tptp_writer 
   481       fun write_all [] _ = []
   482 	| write_all (subgoal::subgoals) k =
   483 	  (writer goals_logic subgoal (pf k) (axclauses,classrel_clauses,arity_clauses); pf k):: (write_all subgoals (k - 1))
   484   in
   485       (write_all neg_subgoals (length goals), names_arr)
   486   end;
   487 
   488 val last_watcher_pid = ref (NONE : (TextIO.instream * TextIO.outstream * 
   489                                     Posix.Process.pid * string list) option);
   490 
   491 fun kill_last_watcher () =
   492     (case !last_watcher_pid of 
   493          NONE => ()
   494        | SOME (_, _, pid, files) => 
   495 	  (Output.debug ("Killing old watcher, pid = " ^ string_of_pid pid);
   496 	   Watcher.killWatcher pid;  
   497 	   ignore (map (try OS.FileSys.remove) files)))
   498      handle OS.SysErr _ => Output.debug "Attempt to kill watcher failed";
   499 
   500 (*writes out the current clasimpset to a tptp file;
   501   turns off xsymbol at start of function, restoring it at end    *)
   502 val isar_atp = setmp print_mode [] 
   503  (fn (ctxt, th) =>
   504   if Thm.no_prems th then ()
   505   else
   506     let
   507       val _ = kill_last_watcher()
   508       val (files,names_arr) = write_problem_files prob_pathname (ctxt,th)
   509       val (childin, childout, pid) = Watcher.createWatcher (th, names_arr)
   510     in
   511       last_watcher_pid := SOME (childin, childout, pid, files);
   512       Output.debug ("problem files: " ^ space_implode ", " files); 
   513       Output.debug ("pid: " ^ string_of_pid pid);
   514       watcher_call_provers (sign_of_thm th) (Thm.prems_of th) (childin, childout, pid)
   515     end);
   516 
   517 val isar_atp_writeonly = setmp print_mode [] 
   518       (fn (ctxt,th) =>
   519        if Thm.no_prems th then ()
   520        else 
   521          let val pf = if Thm.nprems_of th = 1 then probfile_nosuffix 
   522          	      else prob_pathname
   523          in ignore (write_problem_files pf (ctxt,th)) end);
   524 
   525 
   526 (** the Isar toplevel hook **)
   527 
   528 fun invoke_atp_ml (ctxt, goal) =
   529   let val thy = ProofContext.theory_of ctxt;
   530   in
   531     Output.debug ("subgoals in isar_atp:\n" ^ 
   532 		  Pretty.string_of (ProofContext.pretty_term ctxt
   533 		    (Logic.mk_conjunction_list (Thm.prems_of goal))));
   534     Output.debug ("current theory: " ^ Context.theory_name thy);
   535     hook_count := !hook_count +1;
   536     Output.debug ("in hook for time: " ^ Int.toString (!hook_count));
   537     ResClause.init thy;
   538     ResHolClause.init thy;
   539     if !destdir = "" andalso !time_limit > 0 then isar_atp (ctxt, goal)
   540     else isar_atp_writeonly (ctxt, goal)
   541   end;
   542 
   543 val invoke_atp = Toplevel.no_timing o Toplevel.unknown_proof o Toplevel.keep
   544  (fn state =>
   545   let val (ctxt, (_, goal)) = Proof.get_goal (Toplevel.proof_of state)
   546   in  invoke_atp_ml (ctxt, goal)  end);
   547 
   548 val call_atpP =
   549   OuterSyntax.command 
   550     "ProofGeneral.call_atp" 
   551     "call automatic theorem provers" 
   552     OuterKeyword.diag
   553     (Scan.succeed invoke_atp);
   554 
   555 val _ = OuterSyntax.add_parsers [call_atpP];
   556 
   557 end;