src/HOL/Tools/ATP_Manager/atp_wrapper.ML
changeset 35865 2f8fb5242799
parent 35826 1590abc3d42a
child 35867 16279c4c7a33
equal deleted inserted replaced
35843:23908b4dbc2f 35865:2f8fb5242799
    14 
    14 
    15   (*prover configuration, problem format, and prover result*)
    15   (*prover configuration, problem format, and prover result*)
    16   type prover_config =
    16   type prover_config =
    17    {command: Path.T,
    17    {command: Path.T,
    18     arguments: int -> string,
    18     arguments: int -> string,
       
    19     failure_strs: string list,
    19     max_new_clauses: int,
    20     max_new_clauses: int,
    20     insert_theory_const: bool,
    21     insert_theory_const: bool,
    21     emit_structured_proof: bool}
    22     emit_structured_proof: bool}
    22   type problem =
    23   type problem =
    23    {with_full_types: bool,
    24    {with_full_types: bool,
    47   val remote_eprover: string * prover
    48   val remote_eprover: string * prover
    48   val remote_spass: string * prover
    49   val remote_spass: string * prover
    49   val refresh_systems: unit -> unit
    50   val refresh_systems: unit -> unit
    50 end;
    51 end;
    51 
    52 
    52 structure ATP_Wrapper: ATP_WRAPPER =
    53 structure ATP_Wrapper : ATP_WRAPPER =
    53 struct
    54 struct
    54 
    55 
    55 structure SFF = Sledgehammer_Fact_Filter
    56 open Sledgehammer_HOL_Clause
    56 structure SPR = Sledgehammer_Proof_Reconstruct
    57 open Sledgehammer_Fact_Filter
       
    58 open Sledgehammer_Proof_Reconstruct
    57 
    59 
    58 (** generic ATP wrapper **)
    60 (** generic ATP wrapper **)
    59 
    61 
    60 (* external problem files *)
    62 (* external problem files *)
    61 
    63 
    74 (* prover configuration, problem format, and prover result *)
    76 (* prover configuration, problem format, and prover result *)
    75 
    77 
    76 type prover_config =
    78 type prover_config =
    77  {command: Path.T,
    79  {command: Path.T,
    78   arguments: int -> string,
    80   arguments: int -> string,
       
    81   failure_strs: string list,
    79   max_new_clauses: int,
    82   max_new_clauses: int,
    80   insert_theory_const: bool,
    83   insert_theory_const: bool,
    81   emit_structured_proof: bool};
    84   emit_structured_proof: bool};
    82 
    85 
    83 type problem =
    86 type problem =
   112   Exn.capture f path
   115   Exn.capture f path
   113   |> tap (fn _ => cleanup path)
   116   |> tap (fn _ => cleanup path)
   114   |> Exn.release
   117   |> Exn.release
   115   |> tap (after path);
   118   |> tap (after path);
   116 
   119 
   117 fun external_prover relevance_filter prepare write cmd args produce_answer name
   120 fun find_failure strs proof =
   118     ({with_full_types, subgoal, goal, axiom_clauses, filtered_clauses}: problem) =
   121   case filter (fn s => String.isSubstring s proof) strs of
       
   122     [] => if is_proof_well_formed proof then NONE
       
   123           else SOME "Ill-formed ATP output"
       
   124   | (failure :: _) => SOME failure
       
   125 
       
   126 fun external_prover relevance_filter prepare write cmd args failure_strs
       
   127         produce_answer name ({with_full_types, subgoal, goal, axiom_clauses,
       
   128                               filtered_clauses}: problem) =
   119   let
   129   let
   120     (* get clauses and prepare them for writing *)
   130     (* get clauses and prepare them for writing *)
   121     val (ctxt, (chain_ths, th)) = goal;
   131     val (ctxt, (chain_ths, th)) = goal;
   122     val thy = ProofContext.theory_of ctxt;
   132     val thy = ProofContext.theory_of ctxt;
   123     val chain_ths = map (Thm.put_name_hint SPR.chained_hint) chain_ths;
   133     val chain_ths = map (Thm.put_name_hint chained_hint) chain_ths;
   124     val goal_cls = #1 (Sledgehammer_Fact_Preprocessor.neg_conjecture_clauses ctxt th subgoal);
   134     val goal_cls = #1 (Sledgehammer_Fact_Preprocessor.neg_conjecture_clauses ctxt th subgoal);
   125     val the_filtered_clauses =
   135     val the_filtered_clauses =
   126       (case filtered_clauses of
   136       (case filtered_clauses of
   127         NONE => relevance_filter goal goal_cls
   137         NONE => relevance_filter goal goal_cls
   128       | SOME fcls => fcls);
   138       | SOME fcls => fcls);
   182 
   192 
   183     val (((proof, time), rc), conj_pos) =
   193     val (((proof, time), rc), conj_pos) =
   184       with_path cleanup export run_on (prob_pathname subgoal);
   194       with_path cleanup export run_on (prob_pathname subgoal);
   185 
   195 
   186     (* check for success and print out some information on failure *)
   196     (* check for success and print out some information on failure *)
   187     val failure = SPR.find_failure proof;
   197     val failure = find_failure failure_strs proof;
   188     val success = rc = 0 andalso is_none failure;
   198     val success = rc = 0 andalso is_none failure;
   189     val (message, real_thm_names) =
   199     val (message, real_thm_names) =
   190       if is_some failure then ("External prover failed.", [])
   200       if is_some failure then ("External prover failed.", [])
   191       else if rc <> 0 then ("External prover failed: " ^ proof, [])
   201       else if rc <> 0 then ("External prover failed: " ^ proof, [])
   192       else apfst (fn s => "Try this command: " ^ s)
   202       else apfst (fn s => "Try this command: " ^ s)
   198   end;
   208   end;
   199 
   209 
   200 
   210 
   201 (* generic TPTP-based provers *)
   211 (* generic TPTP-based provers *)
   202 
   212 
   203 fun gen_tptp_prover (name, prover_config) timeout problem =
   213 fun generic_tptp_prover
   204   let
   214         (name, {command, arguments, failure_strs, max_new_clauses,
   205     val {max_new_clauses, insert_theory_const, emit_structured_proof, command, arguments} =
   215                 insert_theory_const, emit_structured_proof}) timeout =
   206       prover_config;
   216   external_prover (get_relevant_facts max_new_clauses insert_theory_const)
   207   in
   217       (prepare_clauses false) write_tptp_file command (arguments timeout)
   208     external_prover
   218       failure_strs
   209       (SFF.get_relevant max_new_clauses insert_theory_const)
   219       (if emit_structured_proof then structured_isar_proof
   210       (SFF.prepare_clauses false)
   220        else metis_lemma_list false) name;
   211       Sledgehammer_HOL_Clause.tptp_write_file
   221 
   212       command
   222 fun tptp_prover (name, p) = (name, generic_tptp_prover (name, p));
   213       (arguments timeout)
       
   214       (if emit_structured_proof then SPR.structured_proof
       
   215        else SPR.lemma_list false)
       
   216       name
       
   217       problem
       
   218   end;
       
   219 
       
   220 fun tptp_prover (name, config) = (name, gen_tptp_prover (name, config));
       
   221 
       
   222 
   223 
   223 
   224 
   224 (** common provers **)
   225 (** common provers **)
   225 
   226 
   226 (* Vampire *)
   227 (* Vampire *)
   227 
   228 
   228 (*NB: Vampire does not work without explicit timelimit*)
   229 (*NB: Vampire does not work without explicit timelimit*)
   229 
   230 
       
   231 val vampire_failure_strs =
       
   232   ["Satisfiability detected", "Refutation not found", "CANNOT PROVE"];
   230 val vampire_max_new_clauses = 60;
   233 val vampire_max_new_clauses = 60;
   231 val vampire_insert_theory_const = false;
   234 val vampire_insert_theory_const = false;
   232 
   235 
   233 fun vampire_prover_config full : prover_config =
   236 fun vampire_prover_config full : prover_config =
   234  {command = Path.explode "$VAMPIRE_HOME/vampire",
   237  {command = Path.explode "$VAMPIRE_HOME/vampire",
   235   arguments = (fn timeout => "--output_syntax tptp --mode casc" ^
   238   arguments = (fn timeout => "--output_syntax tptp --mode casc" ^
   236     " -t " ^ string_of_int timeout),
   239     " -t " ^ string_of_int timeout),
       
   240   failure_strs = vampire_failure_strs,
   237   max_new_clauses = vampire_max_new_clauses,
   241   max_new_clauses = vampire_max_new_clauses,
   238   insert_theory_const = vampire_insert_theory_const,
   242   insert_theory_const = vampire_insert_theory_const,
   239   emit_structured_proof = full};
   243   emit_structured_proof = full};
   240 
   244 
   241 val vampire = tptp_prover ("vampire", vampire_prover_config false);
   245 val vampire = tptp_prover ("vampire", vampire_prover_config false);
   242 val vampire_full = tptp_prover ("vampire_full", vampire_prover_config true);
   246 val vampire_full = tptp_prover ("vampire_full", vampire_prover_config true);
   243 
   247 
   244 
   248 
   245 (* E prover *)
   249 (* E prover *)
   246 
   250 
       
   251 val eprover_failure_strs =
       
   252   ["SZS status: Satisfiable", "SZS status Satisfiable",
       
   253    "SZS status: ResourceOut", "SZS status ResourceOut",
       
   254    "# Cannot determine problem status"];
   247 val eprover_max_new_clauses = 100;
   255 val eprover_max_new_clauses = 100;
   248 val eprover_insert_theory_const = false;
   256 val eprover_insert_theory_const = false;
   249 
   257 
   250 fun eprover_config full : prover_config =
   258 fun eprover_config full : prover_config =
   251  {command = Path.explode "$E_HOME/eproof",
   259  {command = Path.explode "$E_HOME/eproof",
   252   arguments = (fn timeout => "--tstp-in --tstp-out -l5 -xAutoDev -tAutoDev" ^
   260   arguments = (fn timeout => "--tstp-in --tstp-out -l5 -xAutoDev -tAutoDev" ^
   253     " --silent --cpu-limit=" ^ string_of_int timeout),
   261     " --silent --cpu-limit=" ^ string_of_int timeout),
       
   262   failure_strs = eprover_failure_strs,
   254   max_new_clauses = eprover_max_new_clauses,
   263   max_new_clauses = eprover_max_new_clauses,
   255   insert_theory_const = eprover_insert_theory_const,
   264   insert_theory_const = eprover_insert_theory_const,
   256   emit_structured_proof = full};
   265   emit_structured_proof = full};
   257 
   266 
   258 val eprover = tptp_prover ("e", eprover_config false);
   267 val eprover = tptp_prover ("e", eprover_config false);
   259 val eprover_full = tptp_prover ("e_full", eprover_config true);
   268 val eprover_full = tptp_prover ("e_full", eprover_config true);
   260 
   269 
   261 
   270 
   262 (* SPASS *)
   271 (* SPASS *)
   263 
   272 
       
   273 val spass_failure_strs =
       
   274   ["SPASS beiseite: Completion found.", "SPASS beiseite: Ran out of time.",
       
   275    "SPASS beiseite: Maximal number of loops exceeded."];
   264 val spass_max_new_clauses = 40;
   276 val spass_max_new_clauses = 40;
   265 val spass_insert_theory_const = true;
   277 val spass_insert_theory_const = true;
   266 
   278 
   267 fun spass_config insert_theory_const: prover_config =
   279 fun spass_config insert_theory_const: prover_config =
   268  {command = Path.explode "$SPASS_HOME/SPASS",
   280  {command = Path.explode "$SPASS_HOME/SPASS",
   269   arguments = (fn timeout => "-Auto -SOS=1 -PGiven=0 -PProblem=0 -Splits=0" ^
   281   arguments = (fn timeout => "-Auto -SOS=1 -PGiven=0 -PProblem=0 -Splits=0" ^
   270     " -FullRed=0 -DocProof -TimeLimit=" ^ string_of_int timeout),
   282     " -FullRed=0 -DocProof -TimeLimit=" ^ string_of_int timeout),
       
   283   failure_strs = spass_failure_strs,
   271   max_new_clauses = spass_max_new_clauses,
   284   max_new_clauses = spass_max_new_clauses,
   272   insert_theory_const = insert_theory_const,
   285   insert_theory_const = insert_theory_const,
   273   emit_structured_proof = false};
   286   emit_structured_proof = false};
   274 
   287 
   275 fun gen_dfg_prover (name, prover_config: prover_config) timeout problem =
   288 fun generic_dfg_prover
   276   let
   289         (name, ({command, arguments, failure_strs, max_new_clauses,
   277     val {max_new_clauses, insert_theory_const, command, arguments, ...} = prover_config;
   290                  insert_theory_const, ...} : prover_config)) timeout =
   278   in
   291   external_prover
   279     external_prover
   292     (get_relevant_facts max_new_clauses insert_theory_const)
   280       (SFF.get_relevant max_new_clauses insert_theory_const)
   293     (prepare_clauses true)
   281       (SFF.prepare_clauses true)
   294     write_dfg_file
   282       Sledgehammer_HOL_Clause.dfg_write_file
   295     command
   283       command
   296     (arguments timeout)
   284       (arguments timeout)
   297     failure_strs
   285       (SPR.lemma_list true)
   298     (metis_lemma_list true)
   286       name
   299     name;
   287       problem
   300 
   288   end;
   301 fun dfg_prover (name, p) = (name, generic_dfg_prover (name, p));
   289 
       
   290 fun dfg_prover (name, config) = (name, gen_dfg_prover (name, config));
       
   291 
   302 
   292 val spass = dfg_prover ("spass", spass_config spass_insert_theory_const);
   303 val spass = dfg_prover ("spass", spass_config spass_insert_theory_const);
   293 val spass_no_tc = dfg_prover ("spass_no_tc", spass_config false);
   304 val spass_no_tc = dfg_prover ("spass_no_tc", spass_config false);
   294 
   305 
   295 
   306 
   314 fun the_system prefix =
   325 fun the_system prefix =
   315   (case get_system prefix of
   326   (case get_system prefix of
   316     NONE => error ("System " ^ quote prefix ^ " not available at SystemOnTPTP")
   327     NONE => error ("System " ^ quote prefix ^ " not available at SystemOnTPTP")
   317   | SOME sys => sys);
   328   | SOME sys => sys);
   318 
   329 
       
   330 val remote_failure_strs = ["Remote-script could not extract proof"];
       
   331 
   319 fun remote_prover_config prover_prefix args max_new insert_tc: prover_config =
   332 fun remote_prover_config prover_prefix args max_new insert_tc: prover_config =
   320  {command = Path.explode "$ISABELLE_ATP_MANAGER/SystemOnTPTP",
   333  {command = Path.explode "$ISABELLE_ATP_MANAGER/SystemOnTPTP",
   321   arguments =
   334   arguments = (fn timeout =>
   322     (fn timeout => args ^ " -t " ^ string_of_int timeout ^ " -s " ^ the_system prover_prefix),
   335     args ^ " -t " ^ string_of_int timeout ^ " -s " ^ the_system prover_prefix),
       
   336   failure_strs = remote_failure_strs,
   323   max_new_clauses = max_new,
   337   max_new_clauses = max_new,
   324   insert_theory_const = insert_tc,
   338   insert_theory_const = insert_tc,
   325   emit_structured_proof = false};
   339   emit_structured_proof = false};
   326 
   340 
   327 val remote_vampire = tptp_prover ("remote_vampire", remote_prover_config
   341 val remote_vampire = tptp_prover ("remote_vampire", remote_prover_config