src/HOL/Tools/ATP_Manager/atp_systems.ML
author blanchet
Sat Jun 05 16:39:23 2010 +0200 (2010-06-05 ago)
changeset 37347 635425a442e8
parent 37346 cdba266f0383
child 37413 e856582fe9c4
permissions -rw-r--r--
show more respect for user-specified facts, even if they could lead to unsound proofs + don't throw away "unsound" theorems in "full_type" mode, since they are then sound
blanchet@36376
     1
(*  Title:      HOL/Tools/ATP_Manager/atp_systems.ML
wenzelm@28592
     2
    Author:     Fabian Immler, TU Muenchen
blanchet@36371
     3
    Author:     Jasmin Blanchette, TU Muenchen
wenzelm@28592
     4
blanchet@36376
     5
Setup for supported ATPs.
wenzelm@28592
     6
*)
wenzelm@28592
     7
blanchet@36376
     8
signature ATP_SYSTEMS =
wenzelm@28592
     9
sig
blanchet@35867
    10
  type prover = ATP_Manager.prover
boehmes@32864
    11
blanchet@35867
    12
  (* hooks for problem files *)
blanchet@36376
    13
  val dest_dir : string Config.T
blanchet@35867
    14
  val problem_prefix : string Config.T
blanchet@35867
    15
  val measure_runtime : bool Config.T
boehmes@32864
    16
blanchet@35867
    17
  val refresh_systems_on_tptp : unit -> unit
blanchet@36371
    18
  val default_atps_param_value : unit -> string
blanchet@35867
    19
  val setup : theory -> theory
wenzelm@28592
    20
end;
wenzelm@28592
    21
blanchet@36376
    22
structure ATP_Systems : ATP_SYSTEMS =
wenzelm@28592
    23
struct
wenzelm@28596
    24
blanchet@36187
    25
open Sledgehammer_Util
blanchet@35969
    26
open Sledgehammer_Fact_Preprocessor
blanchet@35865
    27
open Sledgehammer_HOL_Clause
blanchet@35865
    28
open Sledgehammer_Fact_Filter
blanchet@35865
    29
open Sledgehammer_Proof_Reconstruct
blanchet@35867
    30
open ATP_Manager
blanchet@35826
    31
blanchet@36376
    32
(** generic ATP **)
wenzelm@28596
    33
wenzelm@32944
    34
(* external problem files *)
boehmes@32864
    35
blanchet@36376
    36
val (dest_dir, dest_dir_setup) = Attrib.config_string "atp_dest_dir" (K "");
boehmes@32864
    37
  (*Empty string means create files in Isabelle's temporary files directory.*)
boehmes@32864
    38
boehmes@32864
    39
val (problem_prefix, problem_prefix_setup) =
wenzelm@36001
    40
  Attrib.config_string "atp_problem_prefix" (K "prob");
boehmes@32864
    41
boehmes@33247
    42
val (measure_runtime, measure_runtime_setup) =
wenzelm@36001
    43
  Attrib.config_bool "atp_measure_runtime" (K false);
boehmes@33247
    44
boehmes@32864
    45
blanchet@35867
    46
(* prover configuration *)
boehmes@32864
    47
wenzelm@32941
    48
type prover_config =
blanchet@36917
    49
  {home_var: string,
blanchet@36370
    50
   executable: string,
blanchet@36370
    51
   arguments: Time.time -> string,
blanchet@36370
    52
   proof_delims: (string * string) list,
blanchet@36370
    53
   known_failures: (failure * string) list,
blanchet@36382
    54
   max_axiom_clauses: int,
blanchet@36370
    55
   prefers_theory_relevant: bool};
wenzelm@28596
    56
wenzelm@28596
    57
wenzelm@28596
    58
(* basic template *)
wenzelm@28596
    59
blanchet@36370
    60
val remotify = prefix "remote_"
blanchet@36370
    61
boehmes@32458
    62
fun with_path cleanup after f path =
boehmes@32458
    63
  Exn.capture f path
boehmes@32458
    64
  |> tap (fn _ => cleanup path)
boehmes@32458
    65
  |> Exn.release
blanchet@36369
    66
  |> tap (after path)
blanchet@36369
    67
blanchet@36369
    68
(* Splits by the first possible of a list of delimiters. *)
blanchet@36369
    69
fun extract_proof delims output =
blanchet@36369
    70
  case pairself (find_first (fn s => String.isSubstring s output))
blanchet@36369
    71
                (ListPair.unzip delims) of
blanchet@36369
    72
    (SOME begin_delim, SOME end_delim) =>
blanchet@36549
    73
    (output |> first_field begin_delim |> the |> snd
blanchet@36549
    74
            |> first_field end_delim |> the |> fst
blanchet@36549
    75
            |> first_field "\n" |> the |> snd
blanchet@36549
    76
     handle Option.Option => "")
blanchet@36369
    77
  | _ => ""
boehmes@32458
    78
blanchet@36370
    79
fun extract_proof_and_outcome res_code proof_delims known_failures output =
blanchet@36370
    80
  case map_filter (fn (failure, pattern) =>
blanchet@36370
    81
                      if String.isSubstring pattern output then SOME failure
blanchet@36370
    82
                      else NONE) known_failures of
blanchet@36369
    83
    [] => (case extract_proof proof_delims output of
blanchet@36370
    84
             "" => ("", SOME UnknownError)
blanchet@36370
    85
           | proof => if res_code = 0 then (proof, NONE)
blanchet@36370
    86
                      else ("", SOME UnknownError))
blanchet@36370
    87
  | (failure :: _) => ("", SOME failure)
blanchet@36370
    88
blanchet@36370
    89
fun string_for_failure Unprovable = "The ATP problem is unprovable."
blanchet@36370
    90
  | string_for_failure TimedOut = "Timed out."
blanchet@36370
    91
  | string_for_failure OutOfResources = "The ATP ran out of resources."
blanchet@36370
    92
  | string_for_failure OldSpass =
blanchet@36393
    93
    (* FIXME: Change the error message below to point to the Isabelle download
blanchet@36393
    94
       page once the package is there (around the Isabelle2010 release). *)
blanchet@36370
    95
    "Warning: Sledgehammer requires a more recent version of SPASS with \
blanchet@36370
    96
    \support for the TPTP syntax. To install it, download and untar the \
blanchet@36370
    97
    \package \"http://isabelle.in.tum.de/~blanchet/spass-3.7.tgz\" and add the \
blanchet@36370
    98
    \\"spass-3.7\" directory's full path to \"" ^
blanchet@36370
    99
    Path.implode (Path.expand (Path.appends
blanchet@36370
   100
        (Path.variable "ISABELLE_HOME_USER" ::
blanchet@36370
   101
         map Path.basic ["etc", "components"]))) ^
blanchet@36370
   102
    "\" on a line of its own."
blanchet@36965
   103
  | string_for_failure MalformedInput =
blanchet@36965
   104
    "Internal Sledgehammer error: The ATP problem is malformed. Please report \
blanchet@36965
   105
    \this to the Isabelle developers."
blanchet@36370
   106
  | string_for_failure MalformedOutput = "Error: The ATP output is malformed."
blanchet@36370
   107
  | string_for_failure UnknownError = "Error: An unknown ATP error occurred."
blanchet@35865
   108
blanchet@36400
   109
fun shape_of_clauses _ [] = []
blanchet@36400
   110
  | shape_of_clauses j ([] :: clauses) = [] :: shape_of_clauses j clauses
blanchet@36400
   111
  | shape_of_clauses j ((lit :: lits) :: clauses) =
blanchet@36400
   112
    let val shape = shape_of_clauses (j + 1) (lits :: clauses) in
blanchet@36400
   113
      (j :: hd shape) :: tl shape
blanchet@36400
   114
    end
blanchet@36400
   115
blanchet@36917
   116
fun generic_prover overlord get_facts prepare write_file home_var executable
blanchet@36917
   117
        args proof_delims known_failures name
blanchet@36924
   118
        ({debug, full_types, explicit_apply, isar_proof, isar_shrink_factor,
blanchet@36924
   119
         ...} : params) minimize_command
blanchet@35969
   120
        ({subgoal, goal, relevance_override, axiom_clauses, filtered_clauses}
blanchet@35969
   121
         : problem) =
wenzelm@28596
   122
  let
immler@31750
   123
    (* get clauses and prepare them for writing *)
blanchet@37171
   124
    val (ctxt, (chained_ths, th)) = goal;
wenzelm@32942
   125
    val thy = ProofContext.theory_of ctxt;
blanchet@36400
   126
    val goal_clss = #1 (neg_conjecture_clauses ctxt th subgoal)
blanchet@36400
   127
    val goal_cls = List.concat goal_clss
immler@31752
   128
    val the_filtered_clauses =
wenzelm@32942
   129
      (case filtered_clauses of
blanchet@35969
   130
        NONE => get_facts relevance_override goal goal_cls
wenzelm@32942
   131
      | SOME fcls => fcls);
immler@31409
   132
    val the_axiom_clauses =
wenzelm@32942
   133
      (case axiom_clauses of
wenzelm@32942
   134
        NONE => the_filtered_clauses
wenzelm@32942
   135
      | SOME axcls => axcls);
blanchet@35969
   136
    val (internal_thm_names, clauses) =
blanchet@37171
   137
      prepare goal_cls chained_ths the_axiom_clauses the_filtered_clauses thy;
immler@31750
   138
boehmes@32864
   139
    (* path to unique problem file *)
blanchet@36376
   140
    val the_dest_dir = if overlord then getenv "ISABELLE_HOME_USER"
blanchet@36376
   141
                       else Config.get ctxt dest_dir;
blanchet@36376
   142
    val the_problem_prefix = Config.get ctxt problem_prefix;
boehmes@32864
   143
    fun prob_pathname nr =
blanchet@36143
   144
      let
blanchet@36143
   145
        val probfile =
blanchet@36568
   146
          Path.basic ((if overlord then "prob_" ^ name
blanchet@36568
   147
                       else the_problem_prefix ^ serial_string ())
blanchet@36143
   148
                      ^ "_" ^ string_of_int nr)
wenzelm@32942
   149
      in
blanchet@36376
   150
        if the_dest_dir = "" then File.tmp_path probfile
blanchet@36376
   151
        else if File.exists (Path.explode the_dest_dir)
blanchet@36376
   152
        then Path.append (Path.explode the_dest_dir) probfile
blanchet@36376
   153
        else error ("No such directory: " ^ the_dest_dir ^ ".")
wenzelm@32942
   154
      end;
boehmes@32864
   155
blanchet@36917
   156
    val home = getenv home_var
blanchet@36289
   157
    val command = Path.explode (home ^ "/" ^ executable)
immler@31750
   158
    (* write out problem file and call prover *)
blanchet@36289
   159
    fun command_line probfile =
blanchet@36284
   160
      (if Config.get ctxt measure_runtime then
blanchet@36289
   161
         "TIMEFORMAT='%3U'; { time " ^
blanchet@36289
   162
         space_implode " " [File.shell_path command, args,
blanchet@36289
   163
                            File.shell_path probfile] ^ " ; } 2>&1"
blanchet@36284
   164
       else
blanchet@36289
   165
         space_implode " " ["exec", File.shell_path command, args,
blanchet@36289
   166
                            File.shell_path probfile, "2>&1"]) ^
blanchet@36284
   167
      (if overlord then
blanchet@36286
   168
         " | sed 's/,/, /g' \
blanchet@36485
   169
         \| sed 's/\\([^!=<]\\)\\([=|]\\)\\([^=>]\\)/\\1 \\2 \\3/g' \
blanchet@36286
   170
         \| sed 's/  / /g' | sed 's/| |/||/g' \
blanchet@36286
   171
         \| sed 's/ = = =/===/g' \
blanchet@36286
   172
         \| sed 's/= = /== /g'"
blanchet@36284
   173
       else
blanchet@36284
   174
         "")
boehmes@32510
   175
    fun split_time s =
boehmes@32510
   176
      let
wenzelm@32942
   177
        val split = String.tokens (fn c => str c = "\n");
blanchet@36369
   178
        val (output, t) = s |> split |> split_last |> apfst cat_lines;
wenzelm@32942
   179
        fun as_num f = f >> (fst o read_int);
wenzelm@32942
   180
        val num = as_num (Scan.many1 Symbol.is_ascii_digit);
wenzelm@32942
   181
        val digit = Scan.one Symbol.is_ascii_digit;
wenzelm@32942
   182
        val num3 = as_num (digit ::: digit ::: (digit >> single));
wenzelm@32942
   183
        val time = num --| Scan.$$ "." -- num3 >> (fn (a, b) => a * 1000 + b);
wenzelm@32942
   184
        val as_time = the_default 0 o Scan.read Symbol.stopper time o explode;
blanchet@36369
   185
      in (output, as_time t) end;
boehmes@33247
   186
    fun split_time' s =
boehmes@33247
   187
      if Config.get ctxt measure_runtime then split_time s else (s, 0)
boehmes@32458
   188
    fun run_on probfile =
blanchet@36289
   189
      if File.exists command then
blanchet@36235
   190
        write_file full_types explicit_apply probfile clauses
blanchet@36289
   191
        |> pair (apfst split_time' (bash_output (command_line probfile)))
blanchet@36917
   192
      else if home = "" then
blanchet@36917
   193
        error ("The environment variable " ^ quote home_var ^ " is not set.")
blanchet@36382
   194
      else
blanchet@36382
   195
        error ("Bad executable: " ^ Path.implode command ^ ".");
wenzelm@28592
   196
blanchet@36167
   197
    (* If the problem file has not been exported, remove it; otherwise, export
blanchet@36167
   198
       the proof file too. *)
blanchet@36376
   199
    fun cleanup probfile =
blanchet@36376
   200
      if the_dest_dir = "" then try File.rm probfile else NONE
blanchet@36369
   201
    fun export probfile (((output, _), _), _) =
blanchet@36376
   202
      if the_dest_dir = "" then
blanchet@36187
   203
        ()
blanchet@36187
   204
      else
blanchet@36187
   205
        File.write (Path.explode (Path.implode probfile ^ "_proof"))
blanchet@36282
   206
                   ((if overlord then
blanchet@36289
   207
                       "% " ^ command_line probfile ^ "\n% " ^ timestamp () ^
blanchet@36289
   208
                       "\n"
blanchet@36282
   209
                     else
blanchet@36400
   210
                       "") ^ output)
wenzelm@32257
   211
blanchet@36400
   212
    val (((output, atp_run_time_in_msecs), res_code),
blanchet@36400
   213
         (pool, conjecture_offset)) =
wenzelm@35570
   214
      with_path cleanup export run_on (prob_pathname subgoal);
blanchet@36400
   215
    val conjecture_shape = shape_of_clauses (conjecture_offset + 1) goal_clss
blanchet@36167
   216
    (* Check for success and print out some information on failure. *)
blanchet@36370
   217
    val (proof, outcome) =
blanchet@36370
   218
      extract_proof_and_outcome res_code proof_delims known_failures output
blanchet@35969
   219
    val (message, relevant_thm_names) =
blanchet@36370
   220
      case outcome of
blanchet@36400
   221
        NONE =>
blanchet@36400
   222
        proof_text isar_proof
blanchet@36924
   223
            (pool, debug, full_types, isar_shrink_factor, ctxt,
blanchet@36924
   224
             conjecture_shape)
blanchet@36910
   225
            (minimize_command, proof, internal_thm_names, th, subgoal)
blanchet@36370
   226
      | SOME failure => (string_for_failure failure ^ "\n", [])
boehmes@32864
   227
  in
blanchet@36393
   228
    {outcome = outcome, message = message, pool = pool,
blanchet@35969
   229
     relevant_thm_names = relevant_thm_names,
blanchet@36369
   230
     atp_run_time_in_msecs = atp_run_time_in_msecs, output = output,
blanchet@36369
   231
     proof = proof, internal_thm_names = internal_thm_names,
blanchet@36400
   232
     conjecture_shape = conjecture_shape,
blanchet@35969
   233
     filtered_clauses = the_filtered_clauses}
wenzelm@32942
   234
  end;
wenzelm@28592
   235
wenzelm@28596
   236
wenzelm@28596
   237
(* generic TPTP-based provers *)
wenzelm@28596
   238
blanchet@35865
   239
fun generic_tptp_prover
blanchet@36917
   240
        (name, {home_var, executable, arguments, proof_delims, known_failures,
blanchet@36382
   241
                max_axiom_clauses, prefers_theory_relevant})
blanchet@37347
   242
        (params as {debug, overlord, full_types, respect_no_atp,
blanchet@37347
   243
                    relevance_threshold, relevance_convergence, theory_relevant,
blanchet@37347
   244
                    defs_relevant, isar_proof, ...})
blanchet@36281
   245
        minimize_command timeout =
blanchet@36143
   246
  generic_prover overlord
blanchet@37347
   247
      (relevant_facts full_types respect_no_atp relevance_threshold
blanchet@37347
   248
                      relevance_convergence defs_relevant max_axiom_clauses
blanchet@37347
   249
                      (the_default prefers_theory_relevant theory_relevant))
blanchet@36473
   250
      (prepare_clauses false)
blanchet@36917
   251
      (write_tptp_file (debug andalso overlord)) home_var
blanchet@36369
   252
      executable (arguments timeout) proof_delims known_failures name params
blanchet@36369
   253
      minimize_command
wenzelm@28596
   254
blanchet@35969
   255
fun tptp_prover name p = (name, generic_tptp_prover (name, p));
wenzelm@28596
   256
wenzelm@32941
   257
boehmes@32864
   258
(** common provers **)
wenzelm@28592
   259
blanchet@36382
   260
fun to_generous_secs time = (Time.toMilliseconds time + 999) div 1000
blanchet@36142
   261
wenzelm@28596
   262
(* Vampire *)
wenzelm@28596
   263
blanchet@36289
   264
(* Vampire requires an explicit time limit. *)
wenzelm@28596
   265
blanchet@35969
   266
val vampire_config : prover_config =
blanchet@36917
   267
  {home_var = "VAMPIRE_HOME",
blanchet@36289
   268
   executable = "vampire",
blanchet@36382
   269
   arguments = fn timeout =>
blanchet@36382
   270
     "--output_syntax tptp --mode casc -t " ^
blanchet@36382
   271
     string_of_int (to_generous_secs timeout),
blanchet@36548
   272
   proof_delims =
blanchet@36548
   273
     [("=========== Refutation ==========",
blanchet@36548
   274
       "======= End of refutation ======="),
blanchet@36548
   275
      ("% SZS output start Refutation", "% SZS output end Refutation")],
blanchet@36265
   276
   known_failures =
blanchet@36370
   277
     [(Unprovable, "Satisfiability detected"),
blanchet@37331
   278
      (Unprovable, "UNPROVABLE"),
blanchet@37346
   279
      (Unprovable, "CANNOT PROVE"),
blanchet@36370
   280
      (OutOfResources, "Refutation not found")],
blanchet@36382
   281
   max_axiom_clauses = 60,
blanchet@36289
   282
   prefers_theory_relevant = false}
blanchet@35969
   283
val vampire = tptp_prover "vampire" vampire_config
wenzelm@28596
   284
wenzelm@28592
   285
wenzelm@28596
   286
(* E prover *)
wenzelm@28596
   287
blanchet@36369
   288
val tstp_proof_delims =
blanchet@36369
   289
  ("# SZS output start CNFRefutation.", "# SZS output end CNFRefutation")
blanchet@36369
   290
blanchet@35969
   291
val e_config : prover_config =
blanchet@36917
   292
  {home_var = "E_HOME",
blanchet@36289
   293
   executable = "eproof",
blanchet@36382
   294
   arguments = fn timeout =>
blanchet@36382
   295
     "--tstp-in --tstp-out -l5 -xAutoDev -tAutoDev --silent --cpu-limit=" ^
blanchet@36382
   296
     string_of_int (to_generous_secs timeout),
blanchet@36369
   297
   proof_delims = [tstp_proof_delims],
blanchet@36265
   298
   known_failures =
blanchet@36370
   299
     [(Unprovable, "SZS status: Satisfiable"),
blanchet@36370
   300
      (Unprovable, "SZS status Satisfiable"),
blanchet@36370
   301
      (TimedOut, "Failure: Resource limit exceeded (time)"),
blanchet@36370
   302
      (TimedOut, "time limit exceeded"),
blanchet@36370
   303
      (OutOfResources,
blanchet@36370
   304
       "# Cannot determine problem status within resource limit"),
blanchet@36370
   305
      (OutOfResources, "SZS status: ResourceOut"),
blanchet@36370
   306
      (OutOfResources, "SZS status ResourceOut")],
blanchet@36382
   307
   max_axiom_clauses = 100,
blanchet@36289
   308
   prefers_theory_relevant = false}
blanchet@35969
   309
val e = tptp_prover "e" e_config
wenzelm@28596
   310
wenzelm@28596
   311
wenzelm@28596
   312
(* SPASS *)
wenzelm@28592
   313
blanchet@35865
   314
fun generic_dfg_prover
blanchet@36917
   315
        (name, {home_var, executable, arguments, proof_delims, known_failures,
blanchet@36382
   316
                max_axiom_clauses, prefers_theory_relevant})
blanchet@37347
   317
        (params as {overlord, full_types, respect_no_atp, relevance_threshold,
blanchet@36922
   318
                    relevance_convergence, theory_relevant, defs_relevant, ...})
blanchet@36281
   319
        minimize_command timeout =
blanchet@36143
   320
  generic_prover overlord
blanchet@37347
   321
      (relevant_facts full_types respect_no_atp relevance_threshold
blanchet@37347
   322
                      relevance_convergence defs_relevant max_axiom_clauses
blanchet@37347
   323
                      (the_default prefers_theory_relevant theory_relevant))
blanchet@36917
   324
      (prepare_clauses true) write_dfg_file home_var executable
blanchet@36369
   325
      (arguments timeout) proof_delims known_failures name params
blanchet@36369
   326
      minimize_command
boehmes@32869
   327
blanchet@36264
   328
fun dfg_prover name p = (name, generic_dfg_prover (name, p))
boehmes@32869
   329
blanchet@36219
   330
(* The "-VarWeight=3" option helps the higher-order problems, probably by
blanchet@36219
   331
   counteracting the presence of "hAPP". *)
blanchet@36059
   332
val spass_config : prover_config =
blanchet@36917
   333
  {home_var = "SPASS_HOME",
blanchet@36289
   334
   executable = "SPASS",
blanchet@36382
   335
   arguments = fn timeout =>
blanchet@36382
   336
     "-Auto -SOS=1 -PGiven=0 -PProblem=0 -Splits=0 -FullRed=0 -DocProof \
blanchet@36382
   337
     \-VarWeight=3 -TimeLimit=" ^ string_of_int (to_generous_secs timeout),
blanchet@36369
   338
   proof_delims = [("Here is a proof", "Formulae used in the proof")],
blanchet@36289
   339
   known_failures =
blanchet@36370
   340
     [(Unprovable, "SPASS beiseite: Completion found"),
blanchet@36370
   341
      (TimedOut, "SPASS beiseite: Ran out of time"),
blanchet@36965
   342
      (OutOfResources, "SPASS beiseite: Maximal number of loops exceeded"),
blanchet@36965
   343
      (MalformedInput, "Undefined symbol")],
blanchet@36382
   344
   max_axiom_clauses = 40,
blanchet@36289
   345
   prefers_theory_relevant = true}
blanchet@36264
   346
val spass = dfg_prover "spass" spass_config
blanchet@36264
   347
blanchet@36264
   348
(* SPASS 3.7 supports both the DFG and the TPTP syntax, whereas SPASS 3.0
blanchet@36264
   349
   supports only the DFG syntax. As soon as all Isabelle repository/snapshot
blanchet@36264
   350
   users have upgraded to 3.7, we can kill "spass" (and all DFG support in
blanchet@36264
   351
   Sledgehammer) and rename "spass_tptp" "spass". *)
blanchet@35969
   352
blanchet@36264
   353
val spass_tptp_config =
blanchet@36917
   354
  {home_var = #home_var spass_config,
blanchet@36289
   355
   executable = #executable spass_config,
blanchet@36264
   356
   arguments = prefix "-TPTP " o #arguments spass_config,
blanchet@36369
   357
   proof_delims = #proof_delims spass_config,
blanchet@36265
   358
   known_failures =
blanchet@36265
   359
     #known_failures spass_config @
blanchet@36370
   360
     [(OldSpass, "unrecognized option `-TPTP'"),
blanchet@36370
   361
      (OldSpass, "Unrecognized option TPTP")],
blanchet@36382
   362
   max_axiom_clauses = #max_axiom_clauses spass_config,
blanchet@36289
   363
   prefers_theory_relevant = #prefers_theory_relevant spass_config}
blanchet@36264
   364
val spass_tptp = tptp_prover "spass_tptp" spass_tptp_config
wenzelm@28596
   365
wenzelm@28596
   366
(* remote prover invocation via SystemOnTPTP *)
wenzelm@28596
   367
blanchet@36376
   368
val systems = Synchronized.var "atp_systems" ([]: string list);
immler@31835
   369
immler@31835
   370
fun get_systems () =
blanchet@36370
   371
  case bash_output "\"$ISABELLE_ATP_MANAGER/SystemOnTPTP\" -w" of
blanchet@36370
   372
    (answer, 0) => split_lines answer
blanchet@36370
   373
  | (answer, _) =>
blanchet@36370
   374
    error ("Failed to get available systems at SystemOnTPTP:\n" ^ answer)
immler@31835
   375
blanchet@35867
   376
fun refresh_systems_on_tptp () =
blanchet@35867
   377
  Synchronized.change systems (fn _ => get_systems ());
immler@31835
   378
immler@31835
   379
fun get_system prefix = Synchronized.change_result systems (fn systems =>
boehmes@32864
   380
  (if null systems then get_systems () else systems)
wenzelm@32942
   381
  |> `(find_first (String.isPrefix prefix)));
boehmes@32864
   382
wenzelm@32948
   383
fun the_system prefix =
boehmes@32864
   384
  (case get_system prefix of
blanchet@36370
   385
    NONE => error ("System " ^ quote prefix ^
blanchet@36370
   386
                   " not available at SystemOnTPTP.")
wenzelm@32942
   387
  | SOME sys => sys);
immler@31835
   388
blanchet@36265
   389
val remote_known_failures =
blanchet@36370
   390
  [(TimedOut, "says Timeout"),
blanchet@36377
   391
   (MalformedOutput, "Remote script could not extract proof")]
blanchet@35865
   392
blanchet@36382
   393
fun remote_prover_config atp_prefix args
blanchet@36382
   394
        ({proof_delims, known_failures, max_axiom_clauses,
blanchet@36369
   395
          prefers_theory_relevant, ...} : prover_config) : prover_config =
blanchet@36917
   396
  {home_var = "ISABELLE_ATP_MANAGER",
blanchet@36289
   397
   executable = "SystemOnTPTP",
blanchet@36382
   398
   arguments = fn timeout =>
blanchet@36382
   399
     args ^ " -t " ^ string_of_int (to_generous_secs timeout) ^ " -s " ^
blanchet@36382
   400
     the_system atp_prefix,
blanchet@36369
   401
   proof_delims = insert (op =) tstp_proof_delims proof_delims,
blanchet@36265
   402
   known_failures = remote_known_failures @ known_failures,
blanchet@36382
   403
   max_axiom_clauses = max_axiom_clauses,
blanchet@36289
   404
   prefers_theory_relevant = prefers_theory_relevant}
wenzelm@28596
   405
blanchet@35969
   406
val remote_vampire =
blanchet@36289
   407
  tptp_prover (remotify (fst vampire))
blanchet@36552
   408
              (remote_prover_config "Vampire---9" "" vampire_config)
boehmes@32864
   409
blanchet@35969
   410
val remote_e =
blanchet@36289
   411
  tptp_prover (remotify (fst e))
blanchet@36289
   412
              (remote_prover_config "EP---" "" e_config)
boehmes@32864
   413
blanchet@35969
   414
val remote_spass =
blanchet@36289
   415
  tptp_prover (remotify (fst spass))
blanchet@36289
   416
              (remote_prover_config "SPASS---" "-x" spass_config)
wenzelm@28592
   417
blanchet@36917
   418
fun maybe_remote (name, _) ({home_var, ...} : prover_config) =
blanchet@36917
   419
  name |> getenv home_var = "" ? remotify
blanchet@36371
   420
blanchet@36371
   421
fun default_atps_param_value () =
blanchet@36371
   422
  space_implode " " [maybe_remote e e_config, maybe_remote spass spass_config,
blanchet@36371
   423
                     remotify (fst vampire)]
blanchet@36371
   424
blanchet@36289
   425
val provers =
blanchet@36289
   426
  [spass, spass_tptp, vampire, e, remote_vampire, remote_spass, remote_e]
blanchet@35867
   427
val prover_setup = fold add_prover provers
blanchet@35867
   428
blanchet@35867
   429
val setup =
blanchet@36376
   430
  dest_dir_setup
blanchet@35867
   431
  #> problem_prefix_setup
blanchet@35867
   432
  #> measure_runtime_setup
blanchet@36371
   433
  #> prover_setup
blanchet@35867
   434
wenzelm@28592
   435
end;