src/HOL/Tools/atp_wrapper.ML
changeset 31409 d8537ba165b5
parent 31368 763f4b0fd579
child 31410 c231efe693ce
equal deleted inserted replaced
31408:9f2ca03ae7b7 31409:d8537ba165b5
     6 
     6 
     7 signature ATP_WRAPPER =
     7 signature ATP_WRAPPER =
     8 sig
     8 sig
     9   val destdir: string ref
     9   val destdir: string ref
    10   val problem_name: string ref
    10   val problem_name: string ref
    11   val external_prover:
       
    12     (unit -> (thm * (string * int)) list) ->
       
    13     (Path.T -> thm -> int -> (thm * (string * int)) list -> theory -> string vector) ->
       
    14     Path.T * string -> (string -> string option) ->
       
    15     (string -> string * string vector * Proof.context * thm * int -> string) ->
       
    16     AtpManager.prover
       
    17   val tptp_prover_opts_full: int -> bool -> bool -> Path.T * string -> AtpManager.prover
    11   val tptp_prover_opts_full: int -> bool -> bool -> Path.T * string -> AtpManager.prover
    18   val tptp_prover_opts: int -> bool -> Path.T * string -> AtpManager.prover
    12   val tptp_prover_opts: int -> bool -> Path.T * string -> AtpManager.prover
    19   val tptp_prover: Path.T * string -> AtpManager.prover
    13   val tptp_prover: Path.T * string -> AtpManager.prover
    20   val full_prover_opts: int -> bool -> Path.T * string -> AtpManager.prover
    14   val full_prover_opts: int -> bool -> Path.T * string -> AtpManager.prover
    21   val full_prover: Path.T * string  -> AtpManager.prover
    15   val full_prover: Path.T * string  -> AtpManager.prover
    44 val problem_name = ref "prob";
    38 val problem_name = ref "prob";
    45 
    39 
    46 
    40 
    47 (* basic template *)
    41 (* basic template *)
    48 
    42 
    49 fun external_prover relevance_filter write_problem_file (cmd, args) find_failure produce_answer
    43 fun external_prover relevance_filter preparer writer (cmd, args) find_failure produce_answer
    50   timeout axiom_clauses name subgoalno goal =
    44   timeout axiom_clauses const_counts name subgoalno goal =
    51   let
    45   let
    52     (* path to unique problem file *)
    46     (* path to unique problem file *)
    53     val destdir' = ! destdir
    47     val destdir' = ! destdir
    54     val problem_name' = ! problem_name
    48     val problem_name' = ! problem_name
    55     fun prob_pathname nr =
    49     fun prob_pathname nr =
    64     val (ctxt, (chain_ths, th)) = goal
    58     val (ctxt, (chain_ths, th)) = goal
    65     val thy = ProofContext.theory_of ctxt
    59     val thy = ProofContext.theory_of ctxt
    66     val chain_ths = map (Thm.put_name_hint ResReconstruct.chained_hint) chain_ths
    60     val chain_ths = map (Thm.put_name_hint ResReconstruct.chained_hint) chain_ths
    67     val probfile = prob_pathname subgoalno
    61     val probfile = prob_pathname subgoalno
    68     val fname = File.platform_path probfile
    62     val fname = File.platform_path probfile
    69     val the_ax_clauses = case axiom_clauses of NONE => relevance_filter () | SOME axcls => axcls
    63     val goal_cls = #1 (ResAxioms.neg_conjecture_clauses th subgoalno)
    70     val thm_names = write_problem_file probfile th subgoalno the_ax_clauses thy
    64       handle THM ("assume: variables", _, _) =>
       
    65         error "Sledgehammer: Goal contains type variables (TVars)"
       
    66     val _ = app (fn th => Output.debug (fn _ => Display.string_of_thm th)) goal_cls
       
    67     val the_axiom_clauses =
       
    68       case axiom_clauses of
       
    69           NONE => relevance_filter goal goal_cls
       
    70         | SOME axcls => axcls
       
    71     val (thm_names, clauses) = preparer goal_cls the_axiom_clauses thy
       
    72     val the_const_counts = case const_counts of
       
    73       NONE =>
       
    74         ResHolClause.count_constants(
       
    75           case axiom_clauses of
       
    76             NONE => clauses
       
    77             | SOME axcls => #2(preparer goal_cls (relevance_filter goal goal_cls) thy)
       
    78           )
       
    79       | SOME ccs => ccs
       
    80     val _ = writer fname the_const_counts clauses
    71     val cmdline =
    81     val cmdline =
    72       if File.exists cmd then "exec " ^ File.shell_path cmd ^ " " ^ args
    82       if File.exists cmd then "exec " ^ File.shell_path cmd ^ " " ^ args
    73       else error ("Bad executable: " ^ Path.implode cmd)
    83       else error ("Bad executable: " ^ Path.implode cmd)
    74     val (proof, rc) = system_out (cmdline ^ " " ^ fname)
    84     val (proof, rc) = system_out (cmdline ^ " " ^ fname)
    75 
    85 
    90       else ()
   100       else ()
    91     val _ =
   101     val _ =
    92       if rc <> 0
   102       if rc <> 0
    93       then Output.debug (fn () => "Sledgehammer exited with return code " ^ string_of_int rc ^ ":\n" ^ proof)
   103       then Output.debug (fn () => "Sledgehammer exited with return code " ^ string_of_int rc ^ ":\n" ^ proof)
    94       else ()
   104       else ()
    95   in (success, message, proof, thm_names) end;
   105   in (success, message, proof, thm_names, the_const_counts) end;
    96 
   106 
    97 
   107 
    98 
   108 
    99 (** common provers **)
   109 (** common provers **)
   100 
   110 
   101 (* generic TPTP-based provers *)
   111 (* generic TPTP-based provers *)
   102 
   112 
   103 fun tptp_prover_opts_full max_new theory_const full command timeout ax_clauses name n goal =
   113 fun tptp_prover_opts_full max_new theory_const full command timeout ax_clauses ccs name n goal =
   104   external_prover
   114   external_prover
   105     (fn () => ResAtp.get_relevant max_new theory_const goal n)
   115   (ResAtp.get_relevant max_new theory_const)
   106     (ResAtp.write_problem_file false)
   116   (ResAtp.prepare_clauses false)
   107     command
   117   (ResHolClause.tptp_write_file)
   108     ResReconstruct.find_failure
   118   command
   109     (if full then ResReconstruct.structured_proof else ResReconstruct.lemma_list_tstp)
   119   ResReconstruct.find_failure
   110     timeout ax_clauses name n goal;
   120   (if full then ResReconstruct.structured_proof else ResReconstruct.lemma_list_tstp)
       
   121   timeout ax_clauses ccs name n goal;
   111 
   122 
   112 (*arbitrary ATP with TPTP input/output and problemfile as last argument*)
   123 (*arbitrary ATP with TPTP input/output and problemfile as last argument*)
   113 fun tptp_prover_opts max_new theory_const =
   124 fun tptp_prover_opts max_new theory_const =
   114   tptp_prover_opts_full max_new theory_const false;
   125   tptp_prover_opts_full max_new theory_const false;
   115 
   126 
   162 val eprover_full = eprover_opts_full 100 false;
   173 val eprover_full = eprover_opts_full 100 false;
   163 
   174 
   164 
   175 
   165 (* SPASS *)
   176 (* SPASS *)
   166 
   177 
   167 fun spass_opts max_new theory_const timeout ax_clauses name n goal = external_prover
   178 fun spass_opts max_new theory_const timeout ax_clauses ccs name n goal = external_prover
   168   (fn () => ResAtp.get_relevant max_new theory_const goal n)
   179   (ResAtp.get_relevant max_new theory_const)
   169   (ResAtp.write_problem_file true)
   180   (ResAtp.prepare_clauses true)
       
   181   ResHolClause.dfg_write_file
   170   (Path.explode "$SPASS_HOME/SPASS",
   182   (Path.explode "$SPASS_HOME/SPASS",
   171     "-Auto -SOS=1 -PGiven=0 -PProblem=0 -Splits=0 -FullRed=0 -DocProof -TimeLimit=" ^ string_of_int timeout)
   183     "-Auto -SOS=1 -PGiven=0 -PProblem=0 -Splits=0 -FullRed=0 -DocProof -TimeLimit=" ^ string_of_int timeout)
   172   ResReconstruct.find_failure
   184   ResReconstruct.find_failure
   173   ResReconstruct.lemma_list_dfg
   185   ResReconstruct.lemma_list_dfg
   174   timeout ax_clauses name n goal;
   186   timeout ax_clauses ccs name n goal;
   175 
   187 
   176 val spass = spass_opts 40 true;
   188 val spass = spass_opts 40 true;
   177 
   189 
   178 
   190 
   179 (* remote prover invocation via SystemOnTPTP *)
   191 (* remote prover invocation via SystemOnTPTP *)