improvements for problem generation
authorpaulson
Thu Sep 29 12:45:04 2005 +0200 (2005-09-29)
changeset 177177c6a96cbc966
parent 17716 89932e53f31d
child 17718 9dab1e491d10
improvements for problem generation
src/HOL/Tools/res_atp.ML
     1.1 --- a/src/HOL/Tools/res_atp.ML	Thu Sep 29 12:44:25 2005 +0200
     1.2 +++ b/src/HOL/Tools/res_atp.ML	Thu Sep 29 12:45:04 2005 +0200
     1.3 @@ -29,12 +29,14 @@
     1.4  val destdir = ref "";   (*Empty means write files to /tmp*)
     1.5  val problem_name = ref "prob";
     1.6  
     1.7 -fun prob_pathname() = 
     1.8 +fun probfile_nosuffix _ = 
     1.9    if !destdir = "" then File.platform_path (File.tmp_path (Path.basic (!problem_name)))
    1.10    else if File.exists (File.unpack_platform_path (!destdir))
    1.11    then !destdir ^ "/" ^ !problem_name
    1.12    else error ("No such directory: " ^ !destdir);
    1.13  
    1.14 +fun prob_pathname n = probfile_nosuffix n ^ "_" ^ Int.toString n;
    1.15 +
    1.16  
    1.17  (**** for Isabelle/ML interface  ****)
    1.18  
    1.19 @@ -58,37 +60,33 @@
    1.20      end;
    1.21  
    1.22  (* a special version of repeat_RS *)
    1.23 -fun repeat_someI_ex thm = repeat_RS thm someI_ex;
    1.24 +fun repeat_someI_ex th = repeat_RS th someI_ex;
    1.25  
    1.26  
    1.27  (* write out a subgoal as tptp clauses to the file "xxxx_N"*)
    1.28 -fun tptp_inputs_tfrees thms n (axclauses,classrel_clauses,arity_clauses) =
    1.29 +fun tptp_inputs_tfrees thms pf n (axclauses,classrel_clauses,arity_clauses) =
    1.30      let
    1.31        val clss = map (ResClause.make_conjecture_clause_thm) thms
    1.32        val (tptp_clss,tfree_litss) = ListPair.unzip (map ResClause.clause2tptp clss)
    1.33        val tfree_clss = map ResClause.tfree_clause (ResLib.flat_noDup tfree_litss)
    1.34        val classrel_cls = map ResClause.tptp_classrelClause classrel_clauses
    1.35        val arity_cls = map ResClause.tptp_arity_clause arity_clauses
    1.36 -      val probfile = prob_pathname() ^ "_" ^ Int.toString n
    1.37 -      val out = TextIO.openOut(probfile)
    1.38 +      val out = TextIO.openOut(pf n)
    1.39      in
    1.40        ResLib.writeln_strs out (List.concat (map ResClause.tptp_clause axclauses));
    1.41        ResLib.writeln_strs out (tfree_clss @ tptp_clss @ classrel_cls @ arity_cls);
    1.42 -      TextIO.closeOut out;
    1.43 -      debug probfile
    1.44 +      TextIO.closeOut out
    1.45      end;
    1.46  
    1.47  (* write out a subgoal in DFG format to the file "xxxx_N"*)
    1.48 -fun dfg_inputs_tfrees thms n (axclauses,classrel_clauses,arity_clauses) = 
    1.49 +fun dfg_inputs_tfrees thms pf n (axclauses,classrel_clauses,arity_clauses) = 
    1.50      let val clss = map (ResClause.make_conjecture_clause_thm) thms
    1.51 -        val probfile = prob_pathname() ^ "_" ^ (Int.toString n)
    1.52          (*FIXME: classrel_clauses and arity_clauses*)
    1.53 -        val _ = debug ("about to write out dfg prob file " ^ probfile)
    1.54          val probN = ResClause.clauses2dfg clss (!problem_name ^ "_" ^ Int.toString n)
    1.55                          axclauses [] [] []    
    1.56 -	val out = TextIO.openOut(probfile)
    1.57 +	val out = TextIO.openOut(pf n)
    1.58      in
    1.59 -	(ResLib.writeln_strs out [probN]; TextIO.closeOut out; debug probfile )
    1.60 +	ResLib.writeln_strs out [probN]; TextIO.closeOut out
    1.61      end;
    1.62  
    1.63  
    1.64 @@ -99,12 +97,11 @@
    1.65  fun watcher_call_provers sign sg_terms (childin, childout,pid) =
    1.66    let
    1.67      fun make_atp_list [] n = []
    1.68 -      | make_atp_list ((sg_term)::xs) n =
    1.69 +      | make_atp_list (sg_term::xs) n =
    1.70            let
    1.71              val goalstring = proofstring (Sign.string_of_term sign sg_term)
    1.72              val _ = debug ("goalstring in make_atp_lists is " ^ goalstring)
    1.73 -
    1.74 -            val probfile = prob_pathname() ^ "_" ^ Int.toString n
    1.75 +            val probfile = prob_pathname n
    1.76              val time = Int.toString (!time_limit)
    1.77              val _ = debug ("problem file in watcher_call_provers is " ^ probfile)
    1.78            in
    1.79 @@ -153,19 +150,32 @@
    1.80      debug "Sent commands to watcher!"
    1.81    end
    1.82  
    1.83 -(*We write out problem files for each subgoal*)
    1.84 -fun write_problem_files clause thm n =
    1.85 -    if n=0 then ()
    1.86 -     else
    1.87 -       (SELECT_GOAL
    1.88 -        (EVERY1 [rtac ccontr, ObjectLogic.atomize_tac, skolemize_tac, 
    1.89 -          METAHYPS(fn negs => 
    1.90 -            (if !prover = "spass" 
    1.91 -             then dfg_inputs_tfrees (make_clauses negs) n clause
    1.92 -             else tptp_inputs_tfrees (make_clauses negs) n clause;
    1.93 -             write_problem_files clause thm (n-1); 
    1.94 -             all_tac))]) n thm;
    1.95 -        ());
    1.96 +(*We write out problem files for each subgoal. Argument pf generates filenames,
    1.97 +  and allows the suppression of the suffix "_1" in problem-generation mode.*)
    1.98 +fun write_problem_files pf (ctxt,th)  =
    1.99 +  let val prems = Thm.prems_of th
   1.100 +      val (clause_arr, axclauses) = ResClasimp.get_clasimp_lemmas ctxt (hd prems) 
   1.101 +              (*FIXME: hack!! need to consider relevance for all prems*)
   1.102 +      val _ = debug ("claset and simprules total clauses = " ^ 
   1.103 +                     Int.toString (Array.length clause_arr))
   1.104 +      val thy = ProofContext.theory_of ctxt
   1.105 +      val classrel_clauses = ResTypesSorts.classrel_clauses_thy thy
   1.106 +      val _ = debug ("classrel clauses = " ^ Int.toString (length classrel_clauses))
   1.107 +      val arity_clauses = ResTypesSorts.arity_clause_thy thy
   1.108 +      val _ = debug ("arity clauses = " ^ Int.toString (length arity_clauses))
   1.109 +      val write = if !prover = "spass" then dfg_inputs_tfrees else tptp_inputs_tfrees
   1.110 +      fun writenext n =
   1.111 +	if n=0 then ()
   1.112 +	 else
   1.113 +	   (SELECT_GOAL
   1.114 +	    (EVERY1 [rtac ccontr, ObjectLogic.atomize_tac, skolemize_tac, 
   1.115 +	      METAHYPS(fn negs => 
   1.116 +		(write (make_clauses negs) pf n 
   1.117 +		       (axclauses,classrel_clauses,arity_clauses);
   1.118 +		 writenext (n-1); 
   1.119 +		 all_tac))]) n th;
   1.120 +	    ())
   1.121 +      in writenext (length prems); clause_arr end;
   1.122  
   1.123  val last_watcher_pid = ref (NONE : Posix.Process.pid option);
   1.124  
   1.125 @@ -173,52 +183,32 @@
   1.126  (*writes out the current clasimpset to a tptp file;
   1.127    turns off xsymbol at start of function, restoring it at end    *)
   1.128  val isar_atp = setmp print_mode [] 
   1.129 - (fn (ctxt, thm) =>
   1.130 -  if Thm.no_prems thm then ()
   1.131 + (fn (ctxt, th) =>
   1.132 +  if Thm.no_prems th then ()
   1.133    else
   1.134      let
   1.135 -      val _= debug "in isar_atp"
   1.136 -      val thy = ProofContext.theory_of ctxt
   1.137 -      val prems = Thm.prems_of thm
   1.138 -      val prems_string = Meson.concat_with_and (map (Sign.string_of_term thy) prems)
   1.139 -
   1.140        val _ = (case !last_watcher_pid of NONE => ()
   1.141                 | SOME pid => (*FIXME: should kill ATP processes too; at least they time out*)
   1.142                    (debug ("Killing old watcher, pid = " ^ 
   1.143                            Int.toString (ResLib.intOfPid pid));
   1.144                     Watcher.killWatcher pid))
   1.145                handle OS.SysErr _ => debug "Attempt to kill watcher failed";
   1.146 -      (*set up variables for writing out the clasimps to a tptp file*)
   1.147 -      val (clause_arr, axclauses) = ResClasimp.get_clasimp_lemmas ctxt (hd prems) 
   1.148 -              (*FIXME: hack!! need to consider relevance for all prems*)
   1.149 -      val _ = debug ("claset and simprules total clauses = " ^ 
   1.150 -                     Int.toString (Array.length clause_arr))
   1.151 -      val classrel_clauses = ResTypesSorts.classrel_clauses_thy thy
   1.152 -      val _ = debug ("classrel clauses = " ^ Int.toString (length classrel_clauses))
   1.153 -      val arity_clauses = ResTypesSorts.arity_clause_thy thy
   1.154 -      val _ = debug ("arity clauses = " ^ Int.toString (length arity_clauses))
   1.155 -      val (childin, childout, pid) = Watcher.createWatcher (thm, clause_arr)
   1.156 +      val clause_arr = write_problem_files prob_pathname (ctxt,th)
   1.157 +      val (childin, childout, pid) = Watcher.createWatcher (th, clause_arr)
   1.158      in
   1.159        last_watcher_pid := SOME pid;
   1.160 -      debug ("subgoals: " ^ prems_string);
   1.161 +      debug ("proof state: " ^ string_of_thm th);
   1.162        debug ("pid: " ^ Int.toString (ResLib.intOfPid pid));
   1.163 -      write_problem_files (axclauses,classrel_clauses,arity_clauses) thm (length prems);
   1.164 -      watcher_call_provers (sign_of_thm thm) (Thm.prems_of thm) (childin, childout, pid)
   1.165 +      watcher_call_provers (sign_of_thm th) (Thm.prems_of th) (childin, childout, pid)
   1.166      end);
   1.167  
   1.168  val isar_atp_writeonly = setmp print_mode [] 
   1.169 - (fn (ctxt, thm) =>
   1.170 -  if Thm.no_prems thm then ()
   1.171 -  else
   1.172 -    let 
   1.173 -      val prems = Thm.prems_of thm
   1.174 -      val (_, axclauses) = ResClasimp.get_clasimp_lemmas ctxt (hd prems) 
   1.175 -      val thy = ProofContext.theory_of ctxt
   1.176 -      val classrel_clauses = ResTypesSorts.classrel_clauses_thy thy
   1.177 -      val arity_clauses = ResTypesSorts.arity_clause_thy thy
   1.178 -    in
   1.179 -      write_problem_files (axclauses,classrel_clauses,arity_clauses) thm (length prems)
   1.180 -    end);
   1.181 +      (fn (ctxt,th) =>
   1.182 +       if Thm.no_prems th then ()
   1.183 +       else 
   1.184 +         let val pf = if Thm.nprems_of th = 1 then probfile_nosuffix 
   1.185 +         	      else prob_pathname
   1.186 +         in ignore (write_problem_files pf (ctxt,th)) end);
   1.187  
   1.188  
   1.189  (** the Isar toplevel hook **)
   1.190 @@ -238,7 +228,7 @@
   1.191      debug ("number of subgoals in isar_atp: " ^ Int.toString (Thm.nprems_of goal));
   1.192      debug ("current theory: " ^ Context.theory_name thy);
   1.193      hook_count := !hook_count +1;
   1.194 -    debug ("in hook for time: " ^(Int.toString (!hook_count)) );
   1.195 +    debug ("in hook for time: " ^ Int.toString (!hook_count));
   1.196      ResClause.init thy;
   1.197      if !destdir = "" andalso !time_limit > 0 then isar_atp (ctxt, goal)
   1.198      else isar_atp_writeonly (ctxt, goal)