src/HOL/Tools/res_atp.ML
changeset 17502 8836793df947
parent 17488 67376a311a2b
child 17525 ae5bb6001afb
equal deleted inserted replaced
17501:acbebb72e85a 17502:8836793df947
    58 
    58 
    59 (* a special version of repeat_RS *)
    59 (* a special version of repeat_RS *)
    60 fun repeat_someI_ex thm = repeat_RS thm someI_ex;
    60 fun repeat_someI_ex thm = repeat_RS thm someI_ex;
    61 
    61 
    62 
    62 
    63 (*********************************************************************)
    63 (* write out a subgoal as tptp clauses to the file "xxxx_N"*)
    64 (* write out a subgoal as tptp clauses to the file "probN"           *)
       
    65 (* where N is the number of this subgoal                             *)
       
    66 (*********************************************************************)
       
    67 
       
    68 fun tptp_inputs_tfrees thms n axclauses =
    64 fun tptp_inputs_tfrees thms n axclauses =
    69     let
    65     let
    70       val _ = debug ("in tptp_inputs_tfrees 0")
    66       val _ = debug ("in tptp_inputs_tfrees 0")
    71       val clss = map (ResClause.make_conjecture_clause_thm) thms
    67       val clss = map (ResClause.make_conjecture_clause_thm) thms
    72       val _ = debug ("in tptp_inputs_tfrees 1")
    68       val _ = debug ("in tptp_inputs_tfrees 1")
    81       ResLib.writeln_strs out (tfree_clss @ tptp_clss);
    77       ResLib.writeln_strs out (tfree_clss @ tptp_clss);
    82       TextIO.closeOut out;
    78       TextIO.closeOut out;
    83       debug probfile
    79       debug probfile
    84     end;
    80     end;
    85 
    81 
    86 
    82 (* write out a subgoal in DFG format to the file "xxxx_N"*)
    87 (*********************************************************************)
       
    88 (* write out a subgoal as DFG clauses to the file "probN"           *)
       
    89 (* where N is the number of this subgoal                             *)
       
    90 (*********************************************************************)
       
    91 
       
    92 fun dfg_inputs_tfrees thms n axclauses = 
    83 fun dfg_inputs_tfrees thms n axclauses = 
    93     let val clss = map (ResClause.make_conjecture_clause_thm) thms
    84     let val clss = map (ResClause.make_conjecture_clause_thm) thms
    94         val probfile = prob_pathname() ^ "_" ^ (string_of_int n)
    85         val probfile = prob_pathname() ^ "_" ^ (string_of_int n)
    95         val _ = debug ("about to write out dfg prob file " ^ probfile)
    86         val _ = debug ("about to write out dfg prob file " ^ probfile)
    96         val probN = ResClause.clauses2dfg clss ("prob" ^ (string_of_int n)) 
    87         val probN = ResClause.clauses2dfg clss (!problem_name ^ "_" ^ string_of_int n)
    97                         axclauses [] [] []    
    88                         axclauses [] [] []    
    98 	val out = TextIO.openOut(probfile)
    89 	val out = TextIO.openOut(probfile)
    99     in
    90     in
   100 	(ResLib.writeln_strs out [probN]; TextIO.closeOut out; debug probfile )
    91 	(ResLib.writeln_strs out [probN]; TextIO.closeOut out; debug probfile )
   101 (* (ResLib.writeln_strs out (tfree_clss @ dfg_clss); *)
       
   102     end;
    92     end;
   103 
    93 
   104 
    94 
   105 (*********************************************************************)
    95 (*********************************************************************)
   106 (* call prover with settings and problem file for the current subgoal *)
    96 (* call prover with settings and problem file for the current subgoal *)
   113           let
   103           let
   114             val goalstring = proofstring (Sign.string_of_term sign sg_term)
   104             val goalstring = proofstring (Sign.string_of_term sign sg_term)
   115             val _ = debug ("goalstring in make_atp_lists is " ^ goalstring)
   105             val _ = debug ("goalstring in make_atp_lists is " ^ goalstring)
   116 
   106 
   117             val probfile = prob_pathname() ^ "_" ^ string_of_int n
   107             val probfile = prob_pathname() ^ "_" ^ string_of_int n
   118             val _ = debug ("prob file in watcher_call_provers is " ^ probfile)
   108             val _ = debug ("problem file in watcher_call_provers is " ^ probfile)
   119           in
   109           in
   120             (*Avoid command arguments containing spaces: Poly/ML and SML/NJ
   110             (*Avoid command arguments containing spaces: Poly/ML and SML/NJ
   121               versions of Unix.execute treat them differently!*)
   111               versions of Unix.execute treat them differently!*)
   122             if !prover = "spass"
   112             if !prover = "spass"
   123             then
   113             then
   173              else tptp_inputs_tfrees (make_clauses negs) n axclauses;
   163              else tptp_inputs_tfrees (make_clauses negs) n axclauses;
   174              write_problem_files axclauses thm (n-1); 
   164              write_problem_files axclauses thm (n-1); 
   175              all_tac))]) n thm;
   165              all_tac))]) n thm;
   176         ());
   166         ());
   177 
   167 
   178 
   168 val last_watcher_pid = ref (NONE : Posix.Process.pid option);
   179 (*FIXME: WHAT IS THMS FOR????*)
       
   180 
   169 
   181 (******************************************************************)
   170 (******************************************************************)
   182 (* called in Isar automatically                                   *)
   171 (* called in Isar automatically                                   *)
   183 (* writes out the current clasimpset to a tptp file               *)
   172 (* writes out the current clasimpset to a tptp file               *)
   184 (* turns off xsymbol at start of function, restoring it at end    *)
   173 (* turns off xsymbol at start of function, restoring it at end    *)
   185 (******************************************************************)
   174 (******************************************************************)
   186 (*FIX changed to clasimp_file *)
   175 (*FIX changed to clasimp_file *)
   187 val isar_atp = setmp print_mode [] 
   176 val isar_atp = setmp print_mode [] 
   188  (fn (ctxt, thms, thm) =>
   177  (fn (ctxt, thm) =>
   189   if Thm.no_prems thm then ()
   178   if Thm.no_prems thm then ()
   190   else
   179   else
   191     let
   180     let
   192       val _= debug ("in isar_atp")
   181       val _= debug ("in isar_atp")
   193       val thy = ProofContext.theory_of ctxt
   182       val thy = ProofContext.theory_of ctxt
   194       val prems = Thm.prems_of thm
   183       val prems = Thm.prems_of thm
   195       val thms_string = Meson.concat_with_and (map string_of_thm thms)
       
   196       val prems_string = Meson.concat_with_and (map (Sign.string_of_term thy) prems)
   184       val prems_string = Meson.concat_with_and (map (Sign.string_of_term thy) prems)
   197 
   185 
       
   186       val _ = (case !last_watcher_pid of NONE => ()
       
   187                | SOME pid => (*FIXME: should kill ATP processes too; at least they time out*)
       
   188                   (debug ("Killing old watcher, pid = " ^ 
       
   189                           Int.toString (ResLib.intOfPid pid));
       
   190                    Watcher.killWatcher pid))
       
   191               handle OS.SysErr _ => debug "Attempt to kill watcher failed";
   198       (*set up variables for writing out the clasimps to a tptp file*)
   192       (*set up variables for writing out the clasimps to a tptp file*)
   199       val (clause_arr, axclauses) = ResClasimp.get_clasimp_lemmas ctxt (hd prems) 
   193       val (clause_arr, axclauses) = ResClasimp.get_clasimp_lemmas ctxt (hd prems) 
   200               (*FIXME: hack!! need to consider relevance for all prems*)
   194               (*FIXME: hack!! need to consider relevance for all prems*)
   201       val _ = debug ("claset and simprules total clauses = " ^ 
   195       val _ = debug ("claset and simprules total clauses = " ^ 
   202                      string_of_int (Array.length clause_arr))
   196                      string_of_int (Array.length clause_arr))
   203       val (childin, childout, pid) = Watcher.createWatcher (thm, clause_arr)
   197       val (childin, childout, pid) = Watcher.createWatcher (thm, clause_arr)
   204     in
   198     in
   205       debug ("initial thms: " ^ thms_string);
   199       last_watcher_pid := SOME pid;
   206       debug ("subgoals: " ^ prems_string);
   200       debug ("subgoals: " ^ prems_string);
   207       debug ("pid: " ^ Int.toString (ResLib.intOfPid pid));
   201       debug ("pid: " ^ Int.toString (ResLib.intOfPid pid));
   208       write_problem_files axclauses thm (length prems);
   202       write_problem_files axclauses thm (length prems);
   209       watcher_call_provers (sign_of_thm thm) (Thm.prems_of thm) (childin, childout, pid)
   203       watcher_call_provers (sign_of_thm thm) (Thm.prems_of thm) (childin, childout, pid)
   210     end);
   204     end);
   211 
   205 
   212 val isar_atp_writeonly = setmp print_mode [] 
   206 val isar_atp_writeonly = setmp print_mode [] 
   213  (fn (ctxt, thms: thm list, thm) =>
   207  (fn (ctxt, thm) =>
   214   if Thm.no_prems thm then ()
   208   if Thm.no_prems thm then ()
   215   else
   209   else
   216     let val prems = Thm.prems_of thm
   210     let val prems = Thm.prems_of thm
   217         val (_, axclauses) = ResClasimp.get_clasimp_lemmas ctxt (hd prems) 
   211         val (_, axclauses) = ResClasimp.get_clasimp_lemmas ctxt (hd prems) 
   218     in
   212     in
   219       write_problem_files axclauses thm (length prems)
   213       write_problem_files axclauses thm (length prems)
   220     end);
   214     end);
   221 
       
   222 
       
   223 (* convert locally declared rules to axiom clauses: UNUSED *)
       
   224 
       
   225 fun subtract_simpset thy ctxt =
       
   226   let
       
   227     val rules1 = #rules (#1 (rep_ss (simpset_of thy)));
       
   228     val rules2 = #rules (#1 (rep_ss (local_simpset_of ctxt)));
       
   229   in map #thm (Net.subtract MetaSimplifier.eq_rrule rules1 rules2) end;
       
   230 
       
   231 fun subtract_claset thy ctxt =
       
   232   let
       
   233     val (netI1, netE1) = #xtra_netpair (rep_cs (claset_of thy));
       
   234     val (netI2, netE2) = #xtra_netpair (rep_cs (local_claset_of ctxt));
       
   235     val subtract = map (#2 o #2) oo Net.subtract Tactic.eq_kbrl;
       
   236   in subtract netI1 netI2 @ subtract netE1 netE2 end;
       
   237 
       
   238 
   215 
   239 
   216 
   240 (** the Isar toplevel hook **)
   217 (** the Isar toplevel hook **)
   241 
   218 
   242 val invoke_atp = Toplevel.unknown_proof o Toplevel.keep (fn state =>
   219 val invoke_atp = Toplevel.unknown_proof o Toplevel.keep (fn state =>
   254     debug ("number of subgoals in isar_atp: " ^ string_of_int (Thm.nprems_of goal));
   231     debug ("number of subgoals in isar_atp: " ^ string_of_int (Thm.nprems_of goal));
   255     debug ("current theory: " ^ Context.theory_name thy);
   232     debug ("current theory: " ^ Context.theory_name thy);
   256     hook_count := !hook_count +1;
   233     hook_count := !hook_count +1;
   257     debug ("in hook for time: " ^(string_of_int (!hook_count)) );
   234     debug ("in hook for time: " ^(string_of_int (!hook_count)) );
   258     ResClause.init thy;
   235     ResClause.init thy;
   259     if !destdir = "" then isar_atp (ctxt, ProofContext.prems_of ctxt, goal)
   236     if !destdir = "" then isar_atp (ctxt, goal)
   260     else isar_atp_writeonly (ctxt, ProofContext.prems_of ctxt, goal)
   237     else isar_atp_writeonly (ctxt, goal)
   261   end);
   238   end);
   262 
   239 
   263 val call_atpP =
   240 val call_atpP =
   264   OuterSyntax.improper_command 
   241   OuterSyntax.improper_command 
   265     "ProofGeneral.call_atp" 
   242     "ProofGeneral.call_atp"