src/HOL/Tools/ATP_Manager/atp_wrapper.ML
changeset 32941 72d48e333b77
parent 32936 9491bec20595
child 32942 b6711ec9de26
equal deleted inserted replaced
32940:51d450f278ce 32941:72d48e333b77
    10   val destdir: string Config.T
    10   val destdir: string Config.T
    11   val problem_prefix: string Config.T
    11   val problem_prefix: string Config.T
    12   val setup: theory -> theory
    12   val setup: theory -> theory
    13 
    13 
    14   (*prover configuration, problem format, and prover result*)
    14   (*prover configuration, problem format, and prover result*)
    15   datatype prover_config = Prover_Config of {
    15   type prover_config =
    16     command: Path.T,
    16    {command: Path.T,
    17     arguments: int -> string,
    17     arguments: int -> string,
    18     max_new_clauses: int,
    18     max_new_clauses: int,
    19     insert_theory_const: bool,
    19     insert_theory_const: bool,
    20     emit_structured_proof: bool }
    20     emit_structured_proof: bool}
    21   datatype atp_problem = ATP_Problem of {
    21   type atp_problem =
    22     with_full_types: bool,
    22    {with_full_types: bool,
    23     subgoal: int,
    23     subgoal: int,
    24     goal: Proof.context * (thm list * thm),
    24     goal: Proof.context * (thm list * thm),
    25     axiom_clauses: (thm * (string * int)) list option,
    25     axiom_clauses: (thm * (string * int)) list option,
    26     filtered_clauses: (thm * (string * int)) list option }
    26     filtered_clauses: (thm * (string * int)) list option}
    27   val atp_problem_of_goal: bool -> int -> Proof.context * (thm list * thm) ->
    27   val atp_problem_of_goal: bool -> int -> Proof.context * (thm list * thm) -> atp_problem
    28     atp_problem
    28   type prover_result =
    29   datatype prover_result = Prover_Result of {
    29    {success: bool,
    30     success: bool,
       
    31     message: string,
    30     message: string,
    32     theorem_names: string list,
    31     theorem_names: string list,
    33     runtime: int,
    32     runtime: int,
    34     proof: string,
    33     proof: string,
    35     internal_thm_names: string Vector.vector,
    34     internal_thm_names: string Vector.vector,
    36     filtered_clauses: (thm * (string * int)) list }
    35     filtered_clauses: (thm * (string * int)) list}
    37   type prover = atp_problem -> int -> prover_result
    36   type prover = atp_problem -> int -> prover_result
    38 
    37 
    39   (*common provers*)
    38   (*common provers*)
    40   val vampire: string * prover
    39   val vampire: string * prover
    41   val vampire_full: string * prover
    40   val vampire_full: string * prover
    65 val setup = destdir_setup #> problem_prefix_setup;
    64 val setup = destdir_setup #> problem_prefix_setup;
    66 
    65 
    67 
    66 
    68 (* prover configuration, problem format, and prover result *)
    67 (* prover configuration, problem format, and prover result *)
    69 
    68 
    70 datatype prover_config = Prover_Config of {
    69 type prover_config =
    71   command: Path.T,
    70  {command: Path.T,
    72   arguments: int -> string,
    71   arguments: int -> string,
    73   max_new_clauses: int,
    72   max_new_clauses: int,
    74   insert_theory_const: bool,
    73   insert_theory_const: bool,
    75   emit_structured_proof: bool }
    74   emit_structured_proof: bool};
    76 
    75 
    77 datatype atp_problem = ATP_Problem of {
    76 type atp_problem =
    78   with_full_types: bool,
    77  {with_full_types: bool,
    79   subgoal: int,
    78   subgoal: int,
    80   goal: Proof.context * (thm list * thm),
    79   goal: Proof.context * (thm list * thm),
    81   axiom_clauses: (thm * (string * int)) list option,
    80   axiom_clauses: (thm * (string * int)) list option,
    82   filtered_clauses: (thm * (string * int)) list option }
    81   filtered_clauses: (thm * (string * int)) list option};
    83 
    82 
    84 fun atp_problem_of_goal with_full_types subgoal goal = ATP_Problem {
    83 fun atp_problem_of_goal with_full_types subgoal goal : atp_problem =
    85   with_full_types = with_full_types,
    84  {with_full_types = with_full_types,
    86   subgoal = subgoal,
    85   subgoal = subgoal,
    87   goal = goal,
    86   goal = goal,
    88   axiom_clauses = NONE,
    87   axiom_clauses = NONE,
    89   filtered_clauses = NONE }
    88   filtered_clauses = NONE};
    90 
    89 
    91 datatype prover_result = Prover_Result of {
    90 type prover_result =
    92   success: bool,
    91  {success: bool,
    93   message: string,
    92   message: string,
    94   theorem_names: string list,  (* relevant theorems *)
    93   theorem_names: string list,  (*relevant theorems*)
    95   runtime: int,  (* user time of the ATP, in milliseconds *)
    94   runtime: int,  (*user time of the ATP, in milliseconds*)
    96   proof: string,
    95   proof: string,
    97   internal_thm_names: string Vector.vector,
    96   internal_thm_names: string Vector.vector,
    98   filtered_clauses: (thm * (string * int)) list }
    97   filtered_clauses: (thm * (string * int)) list};
    99 
    98 
   100 type prover = atp_problem -> int -> prover_result
    99 type prover = atp_problem -> int -> prover_result;
   101 
   100 
   102 
   101 
   103 (* basic template *)
   102 (* basic template *)
   104 
   103 
   105 fun with_path cleanup after f path =
   104 fun with_path cleanup after f path =
   106   Exn.capture f path
   105   Exn.capture f path
   107   |> tap (fn _ => cleanup path)
   106   |> tap (fn _ => cleanup path)
   108   |> Exn.release
   107   |> Exn.release
   109   |> tap (after path)
   108   |> tap (after path);
   110 
   109 
   111 fun external_prover relevance_filter preparer writer cmd args find_failure produce_answer
   110 fun external_prover relevance_filter preparer writer cmd args find_failure produce_answer
   112   axiom_clauses filtered_clauses name subgoalno goal =
   111   axiom_clauses filtered_clauses name subgoalno goal =
   113   let
   112   let
   114     (* get clauses and prepare them for writing *)
   113     (* get clauses and prepare them for writing *)
   176       else if rc <> 0 then ("External prover failed: " ^ proof, [])
   175       else if rc <> 0 then ("External prover failed: " ^ proof, [])
   177       else apfst (fn s => "Try this command: " ^ s)
   176       else apfst (fn s => "Try this command: " ^ s)
   178         (produce_answer name (proof, thm_names, conj_pos, ctxt, th, subgoalno))
   177         (produce_answer name (proof, thm_names, conj_pos, ctxt, th, subgoalno))
   179     val _ = Output.debug (fn () => "Sledgehammer response (rc = " ^ string_of_int rc ^ "):\n" ^ proof)
   178     val _ = Output.debug (fn () => "Sledgehammer response (rc = " ^ string_of_int rc ^ "):\n" ^ proof)
   180   in
   179   in
   181     Prover_Result {success=success, message=message,
   180     {success = success, message = message,
   182       theorem_names=real_thm_names, runtime=time, proof=proof,
   181       theorem_names = real_thm_names, runtime = time, proof = proof,
   183       internal_thm_names = thm_names, filtered_clauses=the_filtered_clauses}
   182       internal_thm_names = thm_names, filtered_clauses = the_filtered_clauses}
   184   end
   183   end
   185 
   184 
   186 
   185 
   187 (* generic TPTP-based provers *)
   186 (* generic TPTP-based provers *)
   188 
   187 
   189 fun gen_tptp_prover (name, prover_config) problem timeout =
   188 fun gen_tptp_prover (name, prover_config) problem timeout =
   190   let
   189   let
   191     val Prover_Config {max_new_clauses, insert_theory_const,
   190     val {max_new_clauses, insert_theory_const, emit_structured_proof, command, arguments} =
   192       emit_structured_proof, command, arguments} = prover_config
   191       prover_config
   193     val ATP_Problem {with_full_types, subgoal, goal, axiom_clauses,
   192     val {with_full_types, subgoal, goal, axiom_clauses, filtered_clauses} = problem
   194       filtered_clauses} = problem
       
   195   in
   193   in
   196     external_prover
   194     external_prover
   197       (ResAtp.get_relevant max_new_clauses insert_theory_const)
   195       (ResAtp.get_relevant max_new_clauses insert_theory_const)
   198       (ResAtp.prepare_clauses false)
   196       (ResAtp.prepare_clauses false)
   199       (ResHolClause.tptp_write_file with_full_types)
   197       (ResHolClause.tptp_write_file with_full_types)
   200       command
   198       command
   201       (arguments timeout)
   199       (arguments timeout)
   202       ResReconstruct.find_failure
   200       ResReconstruct.find_failure
   203       (if emit_structured_proof then ResReconstruct.structured_proof
   201       (if emit_structured_proof then ResReconstruct.structured_proof
   204         else ResReconstruct.lemma_list false)
   202        else ResReconstruct.lemma_list false)
   205       axiom_clauses
   203       axiom_clauses
   206       filtered_clauses
   204       filtered_clauses
   207       name
   205       name
   208       subgoal
   206       subgoal
   209       goal
   207       goal
   210   end
   208   end
   211 
   209 
   212 fun tptp_prover (name, config) = (name, gen_tptp_prover (name, config))
   210 fun tptp_prover (name, config) = (name, gen_tptp_prover (name, config))
   213 
   211 
   214 
   212 
       
   213 
   215 (** common provers **)
   214 (** common provers **)
   216 
   215 
   217 (* Vampire *)
   216 (* Vampire *)
   218 
   217 
   219 (*NB: Vampire does not work without explicit timelimit*)
   218 (*NB: Vampire does not work without explicit timelimit*)
   220 
   219 
   221 val vampire_max_new_clauses = 60
   220 val vampire_max_new_clauses = 60
   222 val vampire_insert_theory_const = false
   221 val vampire_insert_theory_const = false
   223 
   222 
   224 fun vampire_prover_config full = Prover_Config {
   223 fun vampire_prover_config full : prover_config =
   225   command = Path.explode "$VAMPIRE_HOME/vampire",
   224  {command = Path.explode "$VAMPIRE_HOME/vampire",
   226   arguments = (fn timeout => "--output_syntax tptp --mode casc" ^
   225   arguments = (fn timeout => "--output_syntax tptp --mode casc" ^
   227     " -t " ^ string_of_int timeout),
   226     " -t " ^ string_of_int timeout),
   228   max_new_clauses = vampire_max_new_clauses,
   227   max_new_clauses = vampire_max_new_clauses,
   229   insert_theory_const = vampire_insert_theory_const,
   228   insert_theory_const = vampire_insert_theory_const,
   230   emit_structured_proof = full }
   229   emit_structured_proof = full}
   231 
   230 
   232 val vampire = tptp_prover ("vampire", vampire_prover_config false)
   231 val vampire = tptp_prover ("vampire", vampire_prover_config false)
   233 val vampire_full = tptp_prover ("vampire_full", vampire_prover_config true)
   232 val vampire_full = tptp_prover ("vampire_full", vampire_prover_config true)
   234 
   233 
   235 
   234 
   236 (* E prover *)
   235 (* E prover *)
   237 
   236 
   238 val eprover_max_new_clauses = 100
   237 val eprover_max_new_clauses = 100
   239 val eprover_insert_theory_const = false
   238 val eprover_insert_theory_const = false
   240 
   239 
   241 fun eprover_config full = Prover_Config {
   240 fun eprover_config full : prover_config =
   242   command = Path.explode "$E_HOME/eproof",
   241  {command = Path.explode "$E_HOME/eproof",
   243   arguments = (fn timeout => "--tstp-in --tstp-out -l5 -xAutoDev -tAutoDev" ^
   242   arguments = (fn timeout => "--tstp-in --tstp-out -l5 -xAutoDev -tAutoDev" ^
   244     " --silent --cpu-limit=" ^ string_of_int timeout),
   243     " --silent --cpu-limit=" ^ string_of_int timeout),
   245   max_new_clauses = eprover_max_new_clauses,
   244   max_new_clauses = eprover_max_new_clauses,
   246   insert_theory_const = eprover_insert_theory_const,
   245   insert_theory_const = eprover_insert_theory_const,
   247   emit_structured_proof = full }
   246   emit_structured_proof = full}
   248 
   247 
   249 val eprover = tptp_prover ("e", eprover_config false)
   248 val eprover = tptp_prover ("e", eprover_config false)
   250 val eprover_full = tptp_prover ("e_full", eprover_config true)
   249 val eprover_full = tptp_prover ("e_full", eprover_config true)
   251 
   250 
   252 
   251 
   253 (* SPASS *)
   252 (* SPASS *)
   254 
   253 
   255 val spass_max_new_clauses = 40
   254 val spass_max_new_clauses = 40
   256 val spass_insert_theory_const = true
   255 val spass_insert_theory_const = true
   257 
   256 
   258 fun spass_config insert_theory_const = Prover_Config {
   257 fun spass_config insert_theory_const: prover_config =
   259   command = Path.explode "$SPASS_HOME/SPASS",
   258  {command = Path.explode "$SPASS_HOME/SPASS",
   260   arguments = (fn timeout => "-Auto -SOS=1 -PGiven=0 -PProblem=0 -Splits=0" ^
   259   arguments = (fn timeout => "-Auto -SOS=1 -PGiven=0 -PProblem=0 -Splits=0" ^
   261     " -FullRed=0 -DocProof -TimeLimit=" ^ string_of_int timeout),
   260     " -FullRed=0 -DocProof -TimeLimit=" ^ string_of_int timeout),
   262   max_new_clauses = spass_max_new_clauses,
   261   max_new_clauses = spass_max_new_clauses,
   263   insert_theory_const = insert_theory_const,
   262   insert_theory_const = insert_theory_const,
   264   emit_structured_proof = false }
   263   emit_structured_proof = false}
   265 
   264 
   266 fun gen_dfg_prover (name, prover_config) problem timeout =
   265 fun gen_dfg_prover (name, prover_config) problem timeout =
   267   let
   266   let
   268     val Prover_Config {max_new_clauses, insert_theory_const,
   267     val {max_new_clauses, insert_theory_const, emit_structured_proof, command, arguments} =
   269       emit_structured_proof, command, arguments} = prover_config
   268       prover_config
   270     val ATP_Problem {with_full_types, subgoal, goal, axiom_clauses,
   269     val {with_full_types, subgoal, goal, axiom_clauses, filtered_clauses} = problem
   271       filtered_clauses} = problem
       
   272   in
   270   in
   273     external_prover
   271     external_prover
   274       (ResAtp.get_relevant max_new_clauses insert_theory_const)
   272       (ResAtp.get_relevant max_new_clauses insert_theory_const)
   275       (ResAtp.prepare_clauses true)
   273       (ResAtp.prepare_clauses true)
   276       (ResHolClause.dfg_write_file with_full_types)
   274       (ResHolClause.dfg_write_file with_full_types)
   314 fun get_the_system prefix =
   312 fun get_the_system prefix =
   315   (case get_system prefix of
   313   (case get_system prefix of
   316     NONE => error ("No system like " ^ quote prefix ^ " at SystemOnTPTP")
   314     NONE => error ("No system like " ^ quote prefix ^ " at SystemOnTPTP")
   317   | SOME sys => sys)
   315   | SOME sys => sys)
   318 
   316 
   319 fun remote_prover_config prover_prefix args max_new insert_tc = Prover_Config {
   317 fun remote_prover_config prover_prefix args max_new insert_tc: prover_config =
   320   command = Path.explode "$ISABELLE_ATP_MANAGER/SystemOnTPTP",
   318  {command = Path.explode "$ISABELLE_ATP_MANAGER/SystemOnTPTP",
   321   arguments = (fn timeout => args ^ " -t " ^ string_of_int timeout ^ " -s " ^
   319   arguments = (fn timeout => args ^ " -t " ^ string_of_int timeout ^ " -s " ^
   322     get_the_system prover_prefix),
   320     get_the_system prover_prefix),
   323   max_new_clauses = max_new,
   321   max_new_clauses = max_new,
   324   insert_theory_const = insert_tc,
   322   insert_theory_const = insert_tc,
   325   emit_structured_proof = false }
   323   emit_structured_proof = false}
   326 
   324 
   327 val remote_vampire = tptp_prover ("remote_vampire", remote_prover_config
   325 val remote_vampire = tptp_prover ("remote_vampire", remote_prover_config
   328   "Vampire---9" "" vampire_max_new_clauses vampire_insert_theory_const)
   326   "Vampire---9" "" vampire_max_new_clauses vampire_insert_theory_const)
   329 
   327 
   330 val remote_eprover = tptp_prover ("remote_e", remote_prover_config
   328 val remote_eprover = tptp_prover ("remote_e", remote_prover_config