src/HOL/Tools/res_atp.ML
changeset 17306 5cde710a8a23
parent 17305 6cef3aedd661
child 17317 3f12de2e2e6e
equal deleted inserted replaced
17305:6cef3aedd661 17306:5cde710a8a23
     6 *)
     6 *)
     7 
     7 
     8 signature RES_ATP =
     8 signature RES_ATP =
     9 sig
     9 sig
    10   val axiom_file : Path.T
    10   val axiom_file : Path.T
    11   val full_spass: bool ref
    11   val prover: string ref
    12   val spass: bool ref
       
    13   val vampire: bool ref
       
    14   val custom_spass: string list ref
    12   val custom_spass: string list ref
    15   val hook_count: int ref
    13   val hook_count: int ref
    16 end;
    14 end;
    17 
    15 
    18 structure ResAtp: RES_ATP =
    16 structure ResAtp: RES_ATP =
    22 val call_atp = ref false;
    20 val call_atp = ref false;
    23 val hook_count = ref 0;
    21 val hook_count = ref 0;
    24 
    22 
    25 fun debug_tac tac = (debug "testing"; tac);
    23 fun debug_tac tac = (debug "testing"; tac);
    26 
    24 
    27 val vampire = ref false;   (* use Vampire as default prover? *)
    25 val prover = ref "spass";   (* use spass as default prover *)
    28 val spass = ref true;      (* use spass as default prover *)
       
    29 val full_spass = ref true;  (*specifies Auto mode: SPASS can use all inference rules*)
       
    30 val custom_spass =   (*specialized options for SPASS*)
    26 val custom_spass =   (*specialized options for SPASS*)
    31       ref ["Auto=0","-IORe","-IOFc","-RTaut","-RFSub","-RBSub",
    27       ref ["Auto=0","-IORe","-IOFc","-RTaut","-RFSub","-RBSub",
    32            "-DocProof","-TimeLimit=60"];
    28            "-DocProof","-TimeLimit=60"];
    33 
    29 
    34 val axiom_file = File.tmp_path (Path.basic "axioms");
    30 val axiom_file = File.tmp_path (Path.basic "axioms");
   128 (* (ResLib.writeln_strs out (tfree_clss @ dfg_clss); *)
   124 (* (ResLib.writeln_strs out (tfree_clss @ dfg_clss); *)
   129     end;
   125     end;
   130 
   126 
   131 
   127 
   132 (*********************************************************************)
   128 (*********************************************************************)
   133 (* call SPASS with settings and problem file for the current subgoal *)
   129 (* call prover with settings and problem file for the current subgoal *)
   134 (* should be modified to allow other provers to be called            *)
       
   135 (*********************************************************************)
   130 (*********************************************************************)
   136 (* now passing in list of skolemized thms and list of sgterms to go with them *)
   131 (* now passing in list of skolemized thms and list of sgterms to go with them *)
   137 fun call_resolve_tac  (thms: thm list list)  sign (sg_terms:  term list) (childin, childout,pid) n  =
   132 fun call_resolve_tac  (thms: thm list list)  sign (sg_terms:  term list) (childin, childout,pid) n  =
   138   let
   133   let
   139     val axfile = (File.platform_path axiom_file)
   134     val axfile = (File.platform_path axiom_file)
   150             val _ = debug ("goalstring in make_atp_lists is " ^ goalstring)
   145             val _ = debug ("goalstring in make_atp_lists is " ^ goalstring)
   151 
   146 
   152             val probfile = File.platform_path prob_file ^ "_" ^ (string_of_int n)
   147             val probfile = File.platform_path prob_file ^ "_" ^ (string_of_int n)
   153             val _ = debug ("prob file in call_resolve_tac is " ^ probfile)
   148             val _ = debug ("prob file in call_resolve_tac is " ^ probfile)
   154           in
   149           in
   155             if !spass
   150             if !prover = "spass"
   156             then
   151             then
   157               let val optionline = (*Custom SPASS options, or default?*)
   152               let val optionline = 
   158 		      if !full_spass (*Auto mode: all SPASS inference rules*)
   153 		      if !SpassComm.reconstruct 
   159                       then "-DocProof%-TimeLimit=60%-SOS"
   154 		          (*Proof reconstruction works for only a limited set of 
   160                       else "-" ^ space_implode "%-" (!custom_spass)
   155 		            inference rules*)
       
   156                       then "-" ^ space_implode "%-" (!custom_spass)
       
   157                       else "-DocProof%-TimeLimit=60%-SOS" (*Auto mode*)
   161                   val _ = debug ("SPASS option string is " ^ optionline)
   158                   val _ = debug ("SPASS option string is " ^ optionline)
   162                   val _ = ResLib.helper_path "SPASS_HOME" "SPASS"
   159                   val _ = ResLib.helper_path "SPASS_HOME" "SPASS"
   163                     (*We've checked that SPASS is there for ATP/spassshell to run.*)
   160                     (*We've checked that SPASS is there for ATP/spassshell to run.*)
   164               in 
   161               in 
   165                   ([("spass", thmstr, goalstring,
   162                   ([("spass", thmstr, goalstring,
   166                      getenv "ISABELLE_HOME" ^ "/src/HOL/Tools/ATP/spassshell",
   163                      getenv "ISABELLE_HOME" ^ "/src/HOL/Tools/ATP/spassshell",
   167                      optionline, axfile, hypsfile, probfile)] @ 
   164                      optionline, axfile, hypsfile, probfile)] @ 
   168                   (make_atp_list xs sign (n+1)))
   165                   (make_atp_list xs sign (n+1)))
   169               end
   166               end
   170             else if !vampire 
   167             else if !prover = "vampire"
   171 	    then 
   168 	    then 
   172               let val vampire = ResLib.helper_path "VAMPIRE_HOME" "vkernel"
   169               let val vampire = ResLib.helper_path "VAMPIRE_HOME" "vkernel"
   173               in
   170               in
   174                 ([("vampire", thmstr, goalstring, vampire, "-t 60%-m 100000",
   171                 ([("vampire", thmstr, goalstring, vampire, "-t 60%-m 100000",
   175                    axfile, hypsfile, probfile)] @
   172                    axfile, hypsfile, probfile)] @
   176                  (make_atp_list xs sign (n+1)))
   173                  (make_atp_list xs sign (n+1)))
   177               end
   174               end
   178       	     else
   175       	     else if !prover = "E"
   179              let val Eprover = ResLib.helper_path "E_HOME" "eproof"
   176       	     then
   180               in
   177 	       let val Eprover = ResLib.helper_path "E_HOME" "eproof"
   181                 ([("E", thmstr, goalstring, Eprover, "--tptp-in -l5",
   178 	       in
   182                    axfile, hypsfile, probfile)] @
   179 		  ([("E", thmstr, goalstring, Eprover, 
   183                  (make_atp_list xs sign (n+1)))
   180 		     "--tptp-in%-l5%-xAuto%-tAuto%--soft-cpu-limit=60",
   184               end
   181 		     axfile, hypsfile, probfile)] @
   185 
   182 		   (make_atp_list xs sign (n+1)))
       
   183 	       end
       
   184 	     else error ("Invalid prover name: " ^ !prover)
   186           end
   185           end
   187 
   186 
   188     val atp_list = make_atp_list (ListPair.zip (thms, sg_terms)) sign 1
   187     val atp_list = make_atp_list (ListPair.zip (thms, sg_terms)) sign 1
   189   in
   188   in
   190     Watcher.callResProvers(childout,atp_list);
   189     Watcher.callResProvers(childout,atp_list);
   203        (call_resolve_tac  (rev sko_thms)
   202        (call_resolve_tac  (rev sko_thms)
   204         sign  sg_terms (childin, childout, pid) (List.length sg_terms);
   203         sign  sg_terms (childin, childout, pid) (List.length sg_terms);
   205         all_tac thm)
   204         all_tac thm)
   206      else
   205      else
   207 	
   206 	
   208      ( SELECT_GOAL
   207       (SELECT_GOAL
   209         (EVERY1 [rtac ccontr, ResLib.atomize_tac, skolemize_tac, 
   208         (EVERY1 [rtac ccontr, ResLib.atomize_tac, skolemize_tac, 
   210           METAHYPS(fn negs => 
   209           METAHYPS(fn negs => 
   211             (if !spass 
   210             (if !prover = "spass" 
   212              then dfg_inputs_tfrees (make_clauses negs) n tfrees axclauses
   211              then dfg_inputs_tfrees (make_clauses negs) n tfrees axclauses
   213              else tptp_inputs_tfrees (make_clauses negs) n tfrees axclauses;
   212              else tptp_inputs_tfrees (make_clauses negs) n tfrees axclauses;
   214              get_sko_thms tfrees sign sg_terms (childin, childout, pid) 
   213              get_sko_thms tfrees sign sg_terms (childin, childout, pid) 
   215                           thm  (n -1) (negs::sko_thms) axclauses; 
   214                           thm (n-1) (negs::sko_thms) axclauses; 
   216              all_tac))]) n thm )
   215              all_tac))]) n thm)
   217 
   216 
   218 
   217 
   219 
   218 
   220 (**********************************************)
   219 (**********************************************)
   221 (* recursively call atp_tac_g on all subgoals *)
   220 (* recursively call atp_tac_g on all subgoals *)
   222 (* sg_term is the nth subgoal as a term - used*)
   221 (* sg_term is the nth subgoal as a term - used*)
   223 (* in proof reconstruction                    *)
   222 (* in proof reconstruction                    *)
   224 (**********************************************)
   223 (**********************************************)
   225 
   224 
   226 fun isar_atp_goal' thm n tfree_lits (childin, childout, pid)  axclauses =
   225 fun isar_atp_aux thms thm n_subgoals  (childin, childout, pid) axclauses =
   227   let
   226   let val tfree_lits = isar_atp_h thms
   228     val prems = Thm.prems_of thm
   227       val prems = Thm.prems_of thm
   229     (*val sg_term = get_nth k prems*)
   228       val sign = sign_of_thm thm
   230     val sign = sign_of_thm thm
   229       val thmstring = string_of_thm thm
   231     val thmstring = string_of_thm thm
       
   232   in
   230   in
   233     debug("in isar_atp_goal'");
   231     debug ("in isar_atp_aux");
   234     debug("thmstring in isar_atp_goal': " ^ thmstring);
   232     debug("thmstring in isar_atp_goal': " ^ thmstring);
   235     (* go and call callResProvers with this subgoal *)
   233     (* go and call callResProvers with this subgoal *)
   236     (* isar_atp_g tfree_lits  sg_term (childin, childout, pid) k thm; *)
   234     (* isar_atp_g tfree_lits  sg_term (childin, childout, pid) k thm; *)
   237     (* recursive call to pick up the remaining subgoals *)
   235     (* recursive call to pick up the remaining subgoals *)
   238     (* isar_atp_goal' thm (k+1) n tfree_lits  (childin, childout, pid) *)
   236     (* isar_atp_goal' thm (k+1) n tfree_lits  (childin, childout, pid) *)
   239     get_sko_thms tfree_lits sign prems (childin, childout, pid) thm n []  axclauses
   237     get_sko_thms tfree_lits sign prems (childin, childout, pid) 
   240   end;
   238                  thm n_subgoals []  axclauses
   241 
       
   242 
       
   243 (**************************************************)
       
   244 (* convert clauses from "assume" to conjecture.   *)
       
   245 (* i.e. apply make_clauses and then get tptp for  *)
       
   246 (* any hypotheses in the goal produced by assume  *)
       
   247 (* statements;                                    *)
       
   248 (* write to file "hyps"                           *)
       
   249 (**************************************************)
       
   250 
       
   251 fun isar_atp_aux thms thm n_subgoals  (childin, childout, pid) axclauses =
       
   252   let val tfree_lits = isar_atp_h thms
       
   253   in
       
   254     debug ("in isar_atp_aux");
       
   255     isar_atp_goal' thm n_subgoals tfree_lits (childin, childout, pid)  axclauses
       
   256   end;
   239   end;
   257 
   240 
   258 (******************************************************************)
   241 (******************************************************************)
   259 (* called in Isar automatically                                   *)
   242 (* called in Isar automatically                                   *)
   260 (* writes out the current clasimpset to a tptp file               *)
   243 (* writes out the current clasimpset to a tptp file               *)
   268     let
   251     let
   269       val _= debug ("in isar_atp'")
   252       val _= debug ("in isar_atp'")
   270       val thy = ProofContext.theory_of ctxt
   253       val thy = ProofContext.theory_of ctxt
   271       val prems = Thm.prems_of thm
   254       val prems = Thm.prems_of thm
   272       val thms_string = Meson.concat_with_and (map string_of_thm thms)
   255       val thms_string = Meson.concat_with_and (map string_of_thm thms)
   273       val thm_string = string_of_thm thm
       
   274       val prems_string = Meson.concat_with_and (map (Sign.string_of_term thy) prems)
   256       val prems_string = Meson.concat_with_and (map (Sign.string_of_term thy) prems)
   275 
   257 
   276       (*set up variables for writing out the clasimps to a tptp file*)
   258       (*set up variables for writing out the clasimps to a tptp file*)
   277       val (clause_arr, num_of_clauses, axclauses) =
   259       val (clause_arr, num_of_clauses, axclauses) =
   278         ResClasimp.get_clasimp_lemmas thy (hd prems) (*FIXME: hack!! need to do all prems*)
   260         ResClasimp.get_clasimp_lemmas thy (hd prems) (*FIXME: hack!! need to do all prems*)
   280       val (childin, childout, pid) = Watcher.createWatcher (thm, clause_arr, num_of_clauses)
   262       val (childin, childout, pid) = Watcher.createWatcher (thm, clause_arr, num_of_clauses)
   281       val pid_string =
   263       val pid_string =
   282         string_of_int (Word.toInt (Word.fromLargeWord (Posix.Process.pidToWord pid)))
   264         string_of_int (Word.toInt (Word.fromLargeWord (Posix.Process.pidToWord pid)))
   283     in
   265     in
   284       debug ("initial thms: " ^ thms_string);
   266       debug ("initial thms: " ^ thms_string);
   285       debug ("initial thm: " ^ thm_string);
       
   286       debug ("subgoals: " ^ prems_string);
   267       debug ("subgoals: " ^ prems_string);
   287       debug ("pid: "^ pid_string);
   268       debug ("pid: "^ pid_string);
   288       isar_atp_aux thms thm (length prems) (childin, childout, pid) axclauses;
   269       isar_atp_aux thms thm (length prems) (childin, childout, pid) axclauses;
   289       ()
   270       ()
   290     end);
   271     end);