src/HOL/Tools/res_atp_setup.ML
author haftmann
Fri Feb 10 09:09:07 2006 +0100 (2006-02-10)
changeset 19008 14c1b2f5dda4
parent 18920 7635e0060cd4
child 19160 c1b3aa0a6827
permissions -rw-r--r--
improved code generator devarification
     1 (* ID: $Id$ 
     2    Author: Jia Meng, NICTA
     3 
     4 *)
     5 structure ResAtpSetup =
     6 
     7 struct
     8 
     9 val keep_atp_input = ref false;
    10 val debug = ref true;
    11 
    12 val fol_keep_types = ResClause.keep_types;
    13 
    14 (* use them to set and find type levels of HOL clauses *)
    15 val hol_full_types = ResHolClause.full_types;
    16 val hol_partial_types = ResHolClause.partial_types;
    17 val hol_const_types_only = ResHolClause.const_types_only;
    18 val hol_no_types = ResHolClause.no_types;
    19 fun hol_typ_level () = ResHolClause.find_typ_level ();
    20 
    21 fun is_typed_hol () = 
    22     let val tp_level = hol_typ_level()
    23     in
    24 	not (tp_level = ResHolClause.T_NONE)
    25     end;
    26 
    27 val include_combS = ResHolClause.include_combS;
    28 val include_min_comb = ResHolClause.include_min_comb;
    29 
    30 
    31 
    32 (*******************************************************)
    33 (* set up the output paths                             *)
    34 (*******************************************************)
    35 fun full_typed_comb () =
    36     if !ResHolClause.include_combS then 
    37 	(ResAtp.helper_path "E_HOME" "additionals/full_comb_inclS"
    38 	 handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/full_comb_inclS")
    39     else 
    40 	(ResAtp.helper_path "E_HOME" "additionals/full_comb_noS"
    41 	 handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/full_comb_noS");
    42 
    43 fun partial_typed_comb () = 
    44     if !ResHolClause.include_combS then 
    45 	(ResAtp.helper_path "E_HOME" "additionals/par_comb_inclS"
    46 	 handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/par_comb_inclS")
    47     else 
    48 	(ResAtp.helper_path "E_HOME" "additionals/par_comb_noS"
    49 	 handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/par_comb_noS");
    50 
    51 fun const_typed_comb () =
    52     if !ResHolClause.include_combS then 
    53 	(ResAtp.helper_path "E_HOME" "additionals/const_comb_inclS"
    54 	 handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/const_comb_inclS")
    55     else 
    56 	(ResAtp.helper_path "E_HOME" "additionals/const_comb_noS"
    57 	 handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/const_comb_noS");
    58 	
    59 fun untyped_comb () = 
    60     if !ResHolClause.include_combS then 
    61 	(ResAtp.helper_path "E_HOME" "additionals/u_comb_inclS"
    62 	 handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/u_comb_inclS")
    63     else
    64 	(ResAtp.helper_path "E_HOME" "additionals/u_comb_noS"
    65 	 handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/u_comb_noS");
    66 
    67 
    68 fun full_typed_HOL_helper1 () =
    69     ResAtp.helper_path "E_HOME" "additionals/full_helper1"
    70     handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/full_helper1";
    71 
    72 fun partial_typed_HOL_helper1 () = 
    73     ResAtp.helper_path "E_HOME" "additionals/par_helper1"
    74     handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/par_helper1";
    75 
    76 fun const_typed_HOL_helper1 () = 
    77     ResAtp.helper_path "E_HOME" "additionals/const_helper1"
    78     handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/const_helper1";
    79 
    80 
    81 fun untyped_HOL_helper1 () = 
    82     ResAtp.helper_path "E_HOME" "additionals/u_helper1"
    83     handle _ => ResAtp.helper_path "VAMPIRE_HOME" "additionals/u_helper1";
    84 
    85 
    86 fun HOL_helper1 () =
    87     let val tp_level = !ResHolClause.typ_level
    88     in
    89 	case tp_level of ResHolClause.T_PARTIAL => (warning "Partial type helper"; partial_typed_HOL_helper1 ())
    90 		       | ResHolClause.T_FULL => (warning "Full type helper"; full_typed_HOL_helper1 ())
    91 		       | ResHolClause.T_CONST => (warning "Const type helper"; const_typed_HOL_helper1 ())
    92 		       | ResHolClause.T_NONE => (warning "Untyped helper"; untyped_HOL_helper1 ())
    93     end;
    94 
    95 
    96 fun HOL_comb () =
    97     let val tp_level = !ResHolClause.typ_level
    98     in
    99 	case tp_level of ResHolClause.T_FULL => (warning "Full type comb"; full_typed_comb ())
   100 		       | ResHolClause.T_PARTIAL => (warning "Partial type comb"; partial_typed_comb ())
   101 		       | ResHolClause.T_CONST => (warning "Const type comb"; const_typed_comb ())
   102 		       | ResHolClause.T_NONE => (warning "Untyped comb"; untyped_comb ())
   103     end;
   104 
   105 
   106 fun atp_input_file file =
   107     let val file' = !ResAtp.problem_name ^ "_" ^ file
   108     in
   109 	if !ResAtp.destdir = "" then File.platform_path (File.tmp_path (Path.basic file'))
   110 	else if File.exists (File.unpack_platform_path (!ResAtp.destdir))
   111 	then !ResAtp.destdir ^ "/" ^ file'
   112 	else error ("No such directory: " ^ !ResAtp.destdir)
   113     end;
   114 
   115 fun claset_file () = atp_input_file "claset";
   116 fun simpset_file () = atp_input_file "simp";
   117 fun local_lemma_file () = atp_input_file "locallemmas";
   118 fun hyps_file () = atp_input_file "hyps";
   119 fun prob_file _ = atp_input_file "";
   120 
   121 fun types_sorts_file () = atp_input_file "typesorts";
   122 
   123 
   124 
   125 (*******************************************************)
   126 (* operations on Isabelle theorems:                    *)
   127 (* retrieving from ProofContext,                       *)
   128 (* modifying local theorems,                           *)
   129 (* CNF                                                 *)
   130 (*******************************************************)
   131 
   132 val include_simpset = ref false;
   133 val include_claset = ref false; 
   134 
   135 val add_simpset = (fn () => include_simpset:=true);
   136 val add_claset = (fn () => include_claset:=true);
   137 val add_clasimp = (fn () => include_simpset:=true;include_claset:=true);
   138 val rm_simpset = (fn () => include_simpset:=false);
   139 val rm_claset = (fn () => include_claset:=false);
   140 val rm_clasimp = (fn () => include_simpset:=false;include_claset:=false);
   141 
   142 
   143 (******************************************************************)
   144 (* detect whether a given problem (clauses) is FOL/HOL/HOLC/HOLCS *)
   145 (******************************************************************)
   146 
   147 datatype logic = FOL | HOL | HOLC | HOLCS;
   148 
   149 fun string_of_logic FOL = "FOL"
   150   | string_of_logic HOL = "HOL"
   151   | string_of_logic HOLC = "HOLC"
   152   | string_of_logic HOLCS = "HOLCS";
   153 
   154 (*HOLCS will not occur here*)
   155 fun upgrade_lg HOLC _ = HOLC
   156   | upgrade_lg HOL HOLC = HOLC
   157   | upgrade_lg HOL _ = HOL
   158   | upgrade_lg FOL lg = lg; 
   159 
   160 (* check types *)
   161 fun has_bool (Type("bool",_)) = true
   162   | has_bool (Type(_, Ts)) = exists has_bool Ts
   163   | has_bool _ = false;
   164 
   165 fun has_bool_arg tp = 
   166     let val (targs,tr) = strip_type tp
   167     in
   168 	exists has_bool targs
   169     end;
   170 
   171 fun is_fn_tp (Type("fun",_)) = true
   172   | is_fn_tp _ = false;
   173 
   174 
   175 exception FN_LG of term;
   176 
   177 fun fn_lg (t as Const(f,tp)) (lg,seen) = 
   178     if has_bool tp then (upgrade_lg HOL lg, t ins seen) else (lg, t ins seen) 
   179   | fn_lg (t as Free(f,tp)) (lg,seen) = 
   180     if has_bool tp then (upgrade_lg HOL lg, t ins seen) else (lg, t ins seen) 
   181   | fn_lg (t as Var(f,tp)) (lg,seen) =
   182     if is_fn_tp tp orelse has_bool tp then (upgrade_lg HOL lg,t ins seen)
   183     else (lg,t ins seen)
   184   | fn_lg (t as Abs(_,_,_)) (lg,seen) = (upgrade_lg HOLC lg,t ins seen)
   185   | fn_lg f _ = raise FN_LG(f); 
   186 
   187 
   188 fun term_lg [] (lg,seen) = (lg,seen)
   189   | term_lg (tm::tms) (FOL,seen) =
   190     let val (f,args) = strip_comb tm
   191 	val (lg',seen') = if f mem seen then (FOL,seen) 
   192 			  else fn_lg f (FOL,seen)
   193 
   194 	 in
   195 	     term_lg (args@tms) (lg',seen')
   196     end
   197   | term_lg _ (lg,seen) = (lg,seen)
   198 
   199 exception PRED_LG of term;
   200 
   201 fun pred_lg (t as Const(P,tp)) (lg,seen)= 
   202     if has_bool_arg tp then (upgrade_lg HOL lg, t ins seen) else (lg,t ins seen) 
   203   | pred_lg (t as Free(P,tp)) (lg,seen) =
   204     if has_bool_arg tp then (upgrade_lg HOL lg, t ins seen) else (lg,t ins seen)
   205   | pred_lg (t as Var(_,_)) (lg,seen) = (upgrade_lg HOL lg, t ins seen)
   206   | pred_lg P _ = raise PRED_LG(P);
   207 
   208 
   209 fun lit_lg (Const("Not",_) $ P) (lg,seen) = lit_lg P (lg,seen)
   210   | lit_lg P (lg,seen) =
   211     let val (pred,args) = strip_comb P
   212 	val (lg',seen') = if pred mem seen then (lg,seen) 
   213 			  else pred_lg pred (lg,seen)
   214     in
   215 	term_lg args (lg',seen')
   216     end;
   217 
   218 fun lits_lg [] (lg,seen) = (lg,seen)
   219   | lits_lg (lit::lits) (FOL,seen) =
   220     lits_lg lits (lit_lg lit (FOL,seen))
   221   | lits_lg lits (lg,seen) = (lg,seen);
   222 
   223 
   224 fun logic_of_clause tm (lg,seen) =
   225     let val tm' = HOLogic.dest_Trueprop tm
   226 	val disjs = HOLogic.dest_disj tm'
   227     in
   228 	lits_lg disjs (lg,seen)
   229     end;
   230 
   231 fun lits_lg [] (lg,seen) = (lg,seen)
   232   | lits_lg (lit::lits) (FOL,seen) =
   233     lits_lg lits (lit_lg lit (FOL,seen))
   234   | lits_lg lits (lg,seen) = (lg,seen);
   235 
   236 
   237 fun logic_of_clause tm (lg,seen) =
   238     let val tm' = HOLogic.dest_Trueprop tm
   239 	val disjs = HOLogic.dest_disj tm'
   240     in
   241 	lits_lg disjs (lg,seen)
   242     end;
   243 
   244 fun logic_of_clauses [] (lg,seen) = (lg,seen)
   245   | logic_of_clauses (cls::clss) (FOL,seen) =
   246     logic_of_clauses clss (logic_of_clause cls (FOL,seen))
   247   | logic_of_clauses (cls::clss) (lg,seen) = (lg,seen);
   248 
   249 fun logic_of_nclauses [] (lg,seen) = (lg,seen)
   250   | logic_of_nclauses (cls::clss) (FOL,seen) =
   251     logic_of_nclauses clss (logic_of_clauses (snd cls) (FOL,seen))
   252   | logic_of_nclauses clss (lg,seen) = (lg,seen);
   253 
   254 
   255 
   256 fun problem_logic (conj_cls,hyp_cls,userR,claR,simpR) =
   257     let val (lg1,seen1) = logic_of_clauses conj_cls (FOL,[])
   258 	val (lg2,seen2) = logic_of_clauses hyp_cls (lg1,seen1)
   259 	val (lg3,seen3) = logic_of_nclauses userR (lg2,seen2)
   260 	val (lg4,seen4) = logic_of_nclauses claR (lg3,seen3)
   261 	val (lg5,seen5) = logic_of_nclauses simpR (lg4,seen4)
   262     in
   263 	lg5
   264     end;
   265 
   266 
   267 
   268 (***************************************************************)
   269 (* prover-specific output format:                              *)
   270 (* TPTP                                                        *)
   271 (***************************************************************)
   272 
   273 (**** CNF rules and hypothesis ****)
   274 fun cnf_rules_tms ctxt ths (include_claset,include_simpset) =
   275     let val local_claR = if include_claset then ResAxioms.claset_rules_of_ctxt ctxt else []
   276 	val (local_claR_cls,err1) = ResAxioms.cnf_rules2 local_claR []
   277 	val local_simpR = if include_simpset then ResAxioms.simpset_rules_of_ctxt ctxt else []
   278 	val (local_simpR_cls,err2) = ResAxioms.cnf_rules2 local_simpR []
   279 	val (user_ths_cls,err3) = ResAxioms.cnf_rules2 (map ResAxioms.pairname ths) []
   280 	val errs = err3 @ err2 @ err1
   281     in
   282 	(user_ths_cls,local_simpR_cls,local_claR_cls,errs)
   283     end;
   284 
   285 fun cnf_hyps_thms ctxt = 
   286     let val ths = ProofContext.prems_of ctxt
   287     in
   288 	ResClause.union_all (map ResAxioms.skolem_thm ths)
   289     end;
   290 
   291 (**** clausification ****)
   292 fun cls_axiom_fol _ _ [] = []
   293   | cls_axiom_fol name i (tm::tms) =
   294       case ResClause.make_axiom_clause tm (name,i) of 
   295           SOME cls => cls :: cls_axiom_fol name (i+1) tms
   296         | NONE => cls_axiom_fol name i tms;
   297 
   298 fun cls_axiom_hol  _ _ [] = []
   299   | cls_axiom_hol name i (tm::tms) =
   300    (ResHolClause.make_axiom_clause tm (name,i)) :: (cls_axiom_hol name (i+1) tms);
   301 
   302 
   303 fun filtered_tptp_axiom_fol name clss =
   304     (fst(ListPair.unzip (map ResClause.clause2tptp (filter (fn c => not (ResClause.isTaut c)) (cls_axiom_fol name 0 clss)))),[])
   305     handle _ => ([],[name]);
   306 
   307 fun filtered_tptp_axiom_hol name clss =
   308     (fst(ListPair.unzip (map ResHolClause.clause2tptp (filter (fn c => not (ResHolClause.isTaut c)) (cls_axiom_hol name 0 clss)))),[])
   309     handle _ => ([],[name]);
   310 
   311 fun tptp_axioms_g filt_ax_fn [] err = ([],err)
   312   | tptp_axioms_g filt_ax_fn ((name,clss)::nclss) err =
   313     let val (nclss1,err1) = tptp_axioms_g filt_ax_fn nclss err
   314 	val (clsstrs,err_name_list) = filt_ax_fn name clss
   315     in
   316 	case clsstrs of [] => (nclss1,err_name_list @ err1) 
   317 		      | _ => (clsstrs::nclss1,err1)
   318     end;
   319 		
   320 fun tptp_axioms_fol rules = tptp_axioms_g filtered_tptp_axiom_fol rules [];
   321 
   322 fun tptp_axioms_hol rules = tptp_axioms_g filtered_tptp_axiom_hol rules [];
   323 
   324 
   325 fun atp_axioms_g tptp_ax_fn rules file =
   326     let val out = TextIO.openOut file
   327 	val (clss,errs) = tptp_ax_fn rules
   328 	val clss' = ResClause.union_all clss
   329     in
   330 	ResClause.writeln_strs out clss';
   331 	TextIO.closeOut out;
   332 	([file],errs)
   333     end;
   334 
   335 
   336 fun atp_axioms_fol rules file = atp_axioms_g tptp_axioms_fol rules file;
   337 
   338 fun atp_axioms_hol rules file = atp_axioms_g tptp_axioms_hol rules file;
   339 
   340 
   341 fun filtered_tptp_conjectures_fol terms =
   342     let val clss = ResClause.make_conjecture_clauses terms
   343 	val clss' = filter (fn c => not (ResClause.isTaut c)) clss
   344     in
   345 	ListPair.unzip (map ResClause.clause2tptp clss')
   346     end;
   347 
   348 fun filtered_tptp_conjectures_hol terms =
   349     let val clss = ResHolClause.make_conjecture_clauses terms
   350 	val clss' = filter (fn c => not (ResHolClause.isTaut c)) clss
   351     in
   352 	ListPair.unzip (map ResHolClause.clause2tptp clss')
   353     end;
   354 
   355 fun atp_conjectures_h_g filt_conj_fn hyp_cls =
   356     let val (tptp_h_clss,tfree_litss) = filt_conj_fn hyp_cls
   357 	val tfree_lits = ResClause.union_all tfree_litss
   358 	val tfree_clss = map ResClause.tptp_tfree_clause tfree_lits 
   359 	val hypsfile = hyps_file ()
   360         val out = TextIO.openOut(hypsfile)
   361     in
   362         ResClause.writeln_strs out (tfree_clss @ tptp_h_clss);
   363         TextIO.closeOut out; warning hypsfile;
   364         ([hypsfile],tfree_lits)
   365     end;
   366 
   367 fun atp_conjectures_h_fol hyp_cls = atp_conjectures_h_g filtered_tptp_conjectures_fol hyp_cls;
   368 
   369 fun atp_conjectures_h_hol hyp_cls = atp_conjectures_h_g filtered_tptp_conjectures_hol hyp_cls;
   370 
   371 fun atp_conjectures_c_g filt_conj_fn conj_cls n tfrees =
   372     let val (tptp_c_clss,tfree_litss) = filt_conj_fn conj_cls
   373 	val tfree_clss = map ResClause.tptp_tfree_clause ((ResClause.union_all tfree_litss) \\ tfrees)
   374 	val probfile = prob_file n
   375 	val out = TextIO.openOut(probfile)		 	
   376     in
   377 	ResClause.writeln_strs out (tfree_clss @ tptp_c_clss);
   378 	TextIO.closeOut out;
   379 	warning probfile; 
   380 	probfile 
   381     end;
   382 
   383 fun atp_conjectures_c_fol conj_cls n tfrees = atp_conjectures_c_g filtered_tptp_conjectures_fol conj_cls n tfrees;
   384 
   385 fun atp_conjectures_c_hol conj_cls n tfrees = atp_conjectures_c_g filtered_tptp_conjectures_hol conj_cls n tfrees;
   386 
   387 
   388 fun atp_conjectures_g atp_conj_h_fn atp_conj_c_fn [] conj_cls n =
   389     let val probfile = atp_conj_c_fn conj_cls n []
   390     in
   391 	[probfile]
   392     end
   393   | atp_conjectures_g atp_conj_h_fn atp_conj_c_fn hyp_cls conj_cls n =
   394     let val (hypsfile,tfree_lits) = atp_conj_h_fn hyp_cls
   395 	val probfile = atp_conj_c_fn conj_cls n tfree_lits
   396     in
   397 	(probfile::hypsfile)
   398     end;
   399 
   400 fun atp_conjectures_fol hyp_cls conj_cls n = atp_conjectures_g atp_conjectures_h_fol atp_conjectures_c_fol hyp_cls conj_cls n;
   401 
   402 fun atp_conjectures_hol hyp_cls conj_cls n = atp_conjectures_g atp_conjectures_h_hol atp_conjectures_c_hol hyp_cls conj_cls n;
   403 
   404 
   405 (**** types and sorts ****)
   406 fun tptp_types_sorts thy = 
   407     let val classrel_clauses = ResClause.classrel_clauses_thy thy
   408 	val arity_clauses = ResClause.arity_clause_thy thy
   409 	val classrel_cls = map ResClause.tptp_classrelClause classrel_clauses
   410 	val arity_cls = map ResClause.tptp_arity_clause arity_clauses
   411 	fun write_ts () =
   412 	    let val tsfile = types_sorts_file ()
   413 		val out = TextIO.openOut(tsfile)
   414 	    in
   415 		ResClause.writeln_strs out (classrel_cls @ arity_cls);
   416 		TextIO.closeOut out;
   417 		[tsfile]
   418 	    end
   419     in
   420 	if (List.null arity_cls andalso List.null classrel_cls) then []
   421 	else
   422 	    write_ts ()
   423     end;
   424 
   425 
   426 (******* write to files ******)
   427 
   428 datatype mode = Auto | Fol | Hol;
   429 
   430 fun write_out_g logic atp_ax_fn atp_conj_fn (claR,simpR,userR,hyp_cls,conj_cls,n,err) =
   431     let val (files1,err1) = if (null claR) then ([],[]) else (atp_ax_fn claR (claset_file()))
   432 	val (files2,err2) = if (null simpR) then ([],[]) else (atp_ax_fn simpR (simpset_file ()))
   433 	val (files3,err3) = if (null userR) then ([],[]) else (atp_ax_fn userR (local_lemma_file ()))
   434 	val files4 = atp_conj_fn hyp_cls conj_cls n
   435 	val errs = err1 @ err2 @ err3 @ err
   436 	val logic' = if !include_combS then HOLCS 
   437 		     else 
   438 			 if !include_min_comb then HOLC else logic
   439 	val _ = warning ("Problems are " ^ (string_of_logic logic'))
   440 	val _ = if (null errs) then () else warning ("Can't clausify thms: " ^ (ResClause.paren_pack errs))
   441 	val helpers = case logic' of FOL => []
   442 				   | HOL => [HOL_helper1 ()]
   443 				   | _ => [HOL_helper1(),HOL_comb()] (*HOLC or HOLCS*)
   444     in
   445 	(helpers,files4 @ files1 @ files2 @ files3)
   446     end;
   447 
   448 fun write_out_fol (claR,simpR,userR,hyp_cls,conj_cls,n,err) = write_out_g FOL atp_axioms_fol atp_conjectures_fol (claR,simpR,userR,hyp_cls,conj_cls,n,err);
   449 
   450 fun write_out_hol (claR,simpR,userR,hyp_cls,conj_cls,n,err) = write_out_g HOL atp_axioms_hol atp_conjectures_hol (claR,simpR,userR,hyp_cls,conj_cls,n,err);
   451 
   452 fun write_out_fol_ts ctxt (claR,simpR,userR,hyp_cls,conj_cls,n,err) =  
   453     let val ts_file = if (!fol_keep_types) then tptp_types_sorts (ProofContext.theory_of ctxt) else []
   454 	val (helpers,files) = write_out_fol (claR,simpR,userR,hyp_cls,conj_cls,n,err) 
   455     in
   456 	(helpers,files@ts_file)
   457     end;
   458 
   459 fun write_out_hol_ts ctxt (claR,simpR,userR,hyp_cls,conj_cls,n,err) =  
   460     let val ts_file = if (is_typed_hol()) then tptp_types_sorts (ProofContext.theory_of ctxt) else []
   461 	val (helpers,files) = write_out_hol (claR,simpR,userR,hyp_cls,conj_cls,n,err)
   462     in
   463 	(helpers,files@ts_file)
   464     end;
   465 
   466 
   467 fun prep_atp_input mode ctxt conjectures user_thms n =
   468     let val conj_cls = map prop_of (make_clauses conjectures) 
   469 	val (userR,simpR,claR,errs) = cnf_rules_tms ctxt user_thms (!include_claset,!include_simpset) 
   470 	val hyp_cls = map prop_of (cnf_hyps_thms ctxt) 
   471 	val logic = case mode of Auto => problem_logic (conj_cls,hyp_cls,userR,claR,simpR)
   472 			       | Fol => FOL
   473 			       | Hol => HOL
   474     in
   475 	case logic of FOL => write_out_fol_ts ctxt (claR,simpR,userR,hyp_cls,conj_cls,n,errs)
   476 		    | _ => write_out_hol_ts ctxt (claR,simpR,userR,hyp_cls,conj_cls,n,errs)
   477 			   
   478     end;
   479 
   480 
   481 (***************************************************************)
   482 (* setup ATPs as Isabelle methods                              *)
   483 (***************************************************************)
   484 
   485 
   486 fun atp_meth' tac ths ctxt = 
   487     Method.SIMPLE_METHOD' HEADGOAL
   488     (tac ctxt ths);
   489 
   490 fun atp_meth tac ths ctxt = 
   491     let val thy = ProofContext.theory_of ctxt
   492 	val _ = ResClause.init thy
   493 	val _ = ResHolClause.init thy
   494     in
   495 	atp_meth' tac ths ctxt
   496     end;
   497 
   498 
   499 fun atp_method tac = Method.thms_ctxt_args (atp_meth tac);
   500 
   501 
   502 (*************Remove tmp files********************************)
   503 fun rm_tmp_files1 [] = ()
   504   | rm_tmp_files1 (f::fs) =
   505     (OS.FileSys.remove f; rm_tmp_files1 fs);
   506 
   507 fun cond_rm_tmp files = 
   508     if !keep_atp_input then warning "ATP input kept..." 
   509     else if !ResAtp.destdir <> "" then warning ("ATP input kept in directory " ^ (!ResAtp.destdir))
   510     else (warning "deleting ATP inputs..."; rm_tmp_files1 files);
   511 
   512 end