src/HOL/Tools/atp_wrapper.ML
author wenzelm
Tue Oct 14 20:10:45 2008 +0200 (2008-10-14)
changeset 28596 fcd463a6b6de
parent 28592 824f8390aaa2
child 29587 96599d8d8268
permissions -rw-r--r--
tuned interfaces -- plain prover function, without thread;
misc tuning and simplification;
reduced NJ basis library stuff to bare minimum;
wenzelm@28592
     1
(*  Title:      HOL/Tools/atp_wrapper.ML
wenzelm@28592
     2
    ID:         $Id$
wenzelm@28592
     3
    Author:     Fabian Immler, TU Muenchen
wenzelm@28592
     4
wenzelm@28592
     5
Wrapper functions for external ATPs.
wenzelm@28592
     6
*)
wenzelm@28592
     7
wenzelm@28592
     8
signature ATP_WRAPPER =
wenzelm@28592
     9
sig
wenzelm@28592
    10
  val destdir: string ref
wenzelm@28592
    11
  val problem_name: string ref
wenzelm@28592
    12
  val external_prover:
wenzelm@28592
    13
    ((int -> Path.T) -> Proof.context * thm list * thm -> string list * ResHolClause.axiom_name Vector.vector list) ->
wenzelm@28592
    14
    Path.T * string ->
wenzelm@28592
    15
    (string * int -> bool) ->
wenzelm@28592
    16
    (string * string vector * Proof.context * thm * int -> string) ->
wenzelm@28596
    17
    AtpManager.prover
wenzelm@28596
    18
  val tptp_prover_opts_full: int -> bool -> bool -> Path.T * string -> AtpManager.prover
wenzelm@28596
    19
  val tptp_prover_opts: int -> bool -> Path.T * string -> AtpManager.prover
wenzelm@28596
    20
  val tptp_prover: Path.T * string -> AtpManager.prover
wenzelm@28596
    21
  val full_prover_opts: int -> bool -> Path.T * string -> AtpManager.prover
wenzelm@28596
    22
  val full_prover: Path.T * string  -> AtpManager.prover
wenzelm@28596
    23
  val vampire_opts: int -> bool -> AtpManager.prover
wenzelm@28596
    24
  val vampire: AtpManager.prover
wenzelm@28596
    25
  val vampire_opts_full: int -> bool -> AtpManager.prover
wenzelm@28596
    26
  val vampire_full: AtpManager.prover
wenzelm@28596
    27
  val eprover_opts: int -> bool  -> AtpManager.prover
wenzelm@28596
    28
  val eprover: AtpManager.prover
wenzelm@28596
    29
  val eprover_opts_full: int -> bool -> AtpManager.prover
wenzelm@28596
    30
  val eprover_full: AtpManager.prover
wenzelm@28596
    31
  val spass_opts: int -> bool  -> AtpManager.prover
wenzelm@28596
    32
  val spass: AtpManager.prover
wenzelm@28596
    33
  val remote_prover_opts: int -> bool -> string -> string -> AtpManager.prover
wenzelm@28596
    34
  val remote_prover: string -> string -> AtpManager.prover
wenzelm@28592
    35
end;
wenzelm@28592
    36
wenzelm@28592
    37
structure AtpWrapper: ATP_WRAPPER =
wenzelm@28592
    38
struct
wenzelm@28596
    39
wenzelm@28596
    40
(** generic ATP wrapper **)
wenzelm@28596
    41
wenzelm@28596
    42
(* global hooks for writing problemfiles *)
wenzelm@28596
    43
wenzelm@28596
    44
val destdir = ref "";   (*Empty means write files to /tmp*)
wenzelm@28596
    45
val problem_name = ref "prob";
wenzelm@28596
    46
wenzelm@28596
    47
wenzelm@28596
    48
(* basic template *)
wenzelm@28596
    49
wenzelm@28596
    50
fun external_prover write_problem_files (cmd, args) check_success produce_answer subgoalno state =
wenzelm@28596
    51
  let
wenzelm@28596
    52
    (* path to unique problem file *)
wenzelm@28592
    53
    val destdir' = ! destdir
wenzelm@28592
    54
    val problem_name' = ! problem_name
wenzelm@28592
    55
    fun prob_pathname nr =
wenzelm@28596
    56
      let val probfile = Path.basic (problem_name' ^ serial_string () ^ "_" ^ string_of_int nr)
wenzelm@28592
    57
      in if destdir' = "" then File.tmp_path probfile
wenzelm@28592
    58
        else if File.exists (Path.explode (destdir'))
wenzelm@28592
    59
        then Path.append  (Path.explode (destdir')) probfile
wenzelm@28592
    60
        else error ("No such directory: " ^ destdir')
wenzelm@28592
    61
      end
wenzelm@28596
    62
wenzelm@28592
    63
    (* write out problem file and call prover *)
wenzelm@28596
    64
    val (ctxt, (chain_ths, goal)) = Proof.get_goal state
wenzelm@28596
    65
    val chain_ths = map (Thm.put_name_hint ResReconstruct.chained_hint) chain_ths
wenzelm@28596
    66
    val (filenames, thm_names_list) = write_problem_files prob_pathname (ctxt, chain_ths, goal)
wenzelm@28596
    67
    val thm_names = nth thm_names_list (subgoalno - 1)
wenzelm@28596
    68
wenzelm@28596
    69
    val cmdline =
wenzelm@28596
    70
      if File.exists cmd then File.shell_path cmd ^ " " ^ args
wenzelm@28596
    71
      else error ("Bad executable: " ^ Path.implode cmd)
wenzelm@28596
    72
    val (proof, rc) = system_out (cmdline ^ " " ^ nth filenames (subgoalno - 1))
wenzelm@28596
    73
    val _ =
wenzelm@28596
    74
      if rc <> 0 then
wenzelm@28596
    75
        warning ("Sledgehammer prover exited with return code " ^ string_of_int rc ^ "\n" ^ cmdline)
wenzelm@28596
    76
      else ()
wenzelm@28592
    77
wenzelm@28596
    78
    (* remove *temporary* files *)
wenzelm@28596
    79
    val _ = if destdir' = "" then List.app OS.FileSys.remove filenames else ()
wenzelm@28592
    80
wenzelm@28596
    81
    val success = check_success (proof, rc)
wenzelm@28596
    82
    val message =
wenzelm@28596
    83
      if success
wenzelm@28596
    84
      then "Try this command: " ^ produce_answer (proof, thm_names, ctxt, goal, subgoalno)
wenzelm@28596
    85
      else "Failed."
wenzelm@28596
    86
  in (success, message) end;
wenzelm@28596
    87
wenzelm@28592
    88
wenzelm@28596
    89
wenzelm@28596
    90
(** common provers **)
wenzelm@28596
    91
wenzelm@28596
    92
(* generic TPTP-based provers *)
wenzelm@28596
    93
wenzelm@28596
    94
fun tptp_prover_opts_full max_new theory_const full command =
wenzelm@28596
    95
  external_prover
wenzelm@28592
    96
    (ResAtp.write_problem_files ResHolClause.tptp_write_file max_new theory_const)
wenzelm@28592
    97
    command
wenzelm@28592
    98
    ResReconstruct.check_success_e_vamp_spass
wenzelm@28596
    99
    (if full then ResReconstruct.structured_proof else ResReconstruct.lemma_list_tstp);
wenzelm@28596
   100
wenzelm@28596
   101
(*arbitrary ATP with TPTP input/output and problemfile as last argument*)
wenzelm@28596
   102
fun tptp_prover_opts max_new theory_const =
wenzelm@28596
   103
  tptp_prover_opts_full max_new theory_const false;
wenzelm@28596
   104
wenzelm@28596
   105
val tptp_prover = tptp_prover_opts 60 true;
wenzelm@28596
   106
wenzelm@28596
   107
(*for structured proofs: prover must support TSTP*)
wenzelm@28596
   108
fun full_prover_opts max_new theory_const =
wenzelm@28596
   109
  tptp_prover_opts_full max_new theory_const true;
wenzelm@28596
   110
wenzelm@28596
   111
val full_prover = full_prover_opts 60 true;
wenzelm@28596
   112
wenzelm@28592
   113
wenzelm@28596
   114
(* Vampire *)
wenzelm@28596
   115
wenzelm@28596
   116
(*NB: Vampire does not work without explicit timelimit*)
wenzelm@28596
   117
wenzelm@28596
   118
fun vampire_opts max_new theory_const = tptp_prover_opts
wenzelm@28596
   119
  max_new theory_const
wenzelm@28596
   120
  (Path.explode "$VAMPIRE_HOME/vampire", "--output_syntax tptp --mode casc -t 3600");
wenzelm@28596
   121
wenzelm@28596
   122
val vampire = vampire_opts 60 false;
wenzelm@28596
   123
wenzelm@28596
   124
fun vampire_opts_full max_new theory_const = full_prover_opts
wenzelm@28596
   125
  max_new theory_const
wenzelm@28596
   126
  (Path.explode "$VAMPIRE_HOME/vampire", "--output_syntax tptp --mode casc -t 3600");
wenzelm@28596
   127
wenzelm@28596
   128
val vampire_full = vampire_opts 60 false;
wenzelm@28596
   129
wenzelm@28592
   130
wenzelm@28596
   131
(* E prover *)
wenzelm@28596
   132
wenzelm@28596
   133
fun eprover_opts max_new theory_const = tptp_prover_opts
wenzelm@28596
   134
  max_new theory_const
wenzelm@28596
   135
  (Path.explode "$E_HOME/eproof", "--tstp-in --tstp-out -l5 -xAutoDev -tAutoDev --silent");
wenzelm@28596
   136
wenzelm@28596
   137
val eprover = eprover_opts 100 false;
wenzelm@28596
   138
wenzelm@28596
   139
fun eprover_opts_full max_new theory_const = full_prover_opts
wenzelm@28596
   140
  max_new theory_const
wenzelm@28596
   141
  (Path.explode "$E_HOME/eproof", "--tstp-in --tstp-out -l5 -xAutoDev -tAutoDev --silent");
wenzelm@28596
   142
wenzelm@28596
   143
val eprover_full = eprover_opts_full 100 false;
wenzelm@28596
   144
wenzelm@28596
   145
wenzelm@28596
   146
(* SPASS *)
wenzelm@28592
   147
wenzelm@28596
   148
fun spass_opts max_new theory_const = external_prover
wenzelm@28596
   149
  (ResAtp.write_problem_files ResHolClause.dfg_write_file max_new theory_const)
wenzelm@28596
   150
  (Path.explode "$SPASS_HOME/SPASS", "-Auto -SOS=1 -PGiven=0 -PProblem=0 -Splits=0 -FullRed=0 -DocProof")
wenzelm@28596
   151
  ResReconstruct.check_success_e_vamp_spass
wenzelm@28596
   152
  ResReconstruct.lemma_list_dfg;
wenzelm@28596
   153
wenzelm@28596
   154
val spass = spass_opts 40 true;
wenzelm@28592
   155
wenzelm@28596
   156
wenzelm@28596
   157
(* remote prover invocation via SystemOnTPTP *)
wenzelm@28596
   158
wenzelm@28596
   159
fun remote_prover_opts max_new theory_const name command =
wenzelm@28596
   160
  tptp_prover_opts max_new theory_const
wenzelm@28596
   161
  (Path.explode "$ISABELLE_HOME/contrib/SystemOnTPTP/remote", name ^ " " ^ command);
wenzelm@28596
   162
wenzelm@28596
   163
val remote_prover = remote_prover_opts 60 false;
wenzelm@28592
   164
wenzelm@28592
   165
end;