src/HOL/Tools/ATP_Manager/atp_systems.ML
author blanchet
Tue Jun 29 10:36:36 2010 +0200 (2010-06-29)
changeset 37627 1d1754ccd233
parent 37625 35eeb95c5bee
child 37628 78334f400ae6
permissions -rw-r--r--
more precise error message for remote ATPs
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@37623
    10
  val trace : bool Unsynchronized.ref
blanchet@36376
    11
  val dest_dir : string Config.T
blanchet@35867
    12
  val problem_prefix : string Config.T
blanchet@35867
    13
  val measure_runtime : bool Config.T
blanchet@35867
    14
  val refresh_systems_on_tptp : unit -> unit
blanchet@36371
    15
  val default_atps_param_value : unit -> string
blanchet@35867
    16
  val setup : theory -> theory
wenzelm@28592
    17
end;
wenzelm@28592
    18
blanchet@36376
    19
structure ATP_Systems : ATP_SYSTEMS =
wenzelm@28592
    20
struct
wenzelm@28596
    21
blanchet@37574
    22
open Clausifier
blanchet@37578
    23
open Metis_Clauses
blanchet@36187
    24
open Sledgehammer_Util
blanchet@35865
    25
open Sledgehammer_Fact_Filter
blanchet@37578
    26
open Sledgehammer_TPTP_Format
blanchet@35865
    27
open Sledgehammer_Proof_Reconstruct
blanchet@35867
    28
open ATP_Manager
blanchet@35826
    29
blanchet@37623
    30
val trace = Unsynchronized.ref false
blanchet@37623
    31
fun trace_msg msg = if !trace then tracing (msg ()) else ()
blanchet@37623
    32
blanchet@36376
    33
(** generic ATP **)
wenzelm@28596
    34
wenzelm@32944
    35
(* external problem files *)
boehmes@32864
    36
blanchet@36376
    37
val (dest_dir, dest_dir_setup) = Attrib.config_string "atp_dest_dir" (K "");
boehmes@32864
    38
  (*Empty string means create files in Isabelle's temporary files directory.*)
boehmes@32864
    39
boehmes@32864
    40
val (problem_prefix, problem_prefix_setup) =
wenzelm@36001
    41
  Attrib.config_string "atp_problem_prefix" (K "prob");
boehmes@32864
    42
boehmes@33247
    43
val (measure_runtime, measure_runtime_setup) =
wenzelm@36001
    44
  Attrib.config_bool "atp_measure_runtime" (K false);
boehmes@33247
    45
boehmes@32864
    46
blanchet@35867
    47
(* prover configuration *)
boehmes@32864
    48
wenzelm@32941
    49
type prover_config =
blanchet@36917
    50
  {home_var: string,
blanchet@36370
    51
   executable: string,
blanchet@37514
    52
   arguments: bool -> Time.time -> string,
blanchet@36370
    53
   proof_delims: (string * string) list,
blanchet@36370
    54
   known_failures: (failure * string) list,
blanchet@36382
    55
   max_axiom_clauses: int,
blanchet@36370
    56
   prefers_theory_relevant: bool};
wenzelm@28596
    57
wenzelm@28596
    58
wenzelm@28596
    59
(* basic template *)
wenzelm@28596
    60
blanchet@36370
    61
val remotify = prefix "remote_"
blanchet@36370
    62
boehmes@32458
    63
fun with_path cleanup after f path =
boehmes@32458
    64
  Exn.capture f path
boehmes@32458
    65
  |> tap (fn _ => cleanup path)
boehmes@32458
    66
  |> Exn.release
blanchet@36369
    67
  |> tap (after path)
blanchet@36369
    68
blanchet@36369
    69
(* Splits by the first possible of a list of delimiters. *)
blanchet@36369
    70
fun extract_proof delims output =
blanchet@36369
    71
  case pairself (find_first (fn s => String.isSubstring s output))
blanchet@36369
    72
                (ListPair.unzip delims) of
blanchet@36369
    73
    (SOME begin_delim, SOME end_delim) =>
blanchet@36549
    74
    (output |> first_field begin_delim |> the |> snd
blanchet@36549
    75
            |> first_field end_delim |> the |> fst
blanchet@36549
    76
            |> first_field "\n" |> the |> snd
blanchet@36549
    77
     handle Option.Option => "")
blanchet@36369
    78
  | _ => ""
boehmes@32458
    79
blanchet@37514
    80
fun extract_proof_and_outcome complete res_code proof_delims known_failures
blanchet@37514
    81
                              output =
blanchet@36370
    82
  case map_filter (fn (failure, pattern) =>
blanchet@36370
    83
                      if String.isSubstring pattern output then SOME failure
blanchet@36370
    84
                      else NONE) known_failures of
blanchet@36369
    85
    [] => (case extract_proof proof_delims output of
blanchet@36370
    86
             "" => ("", SOME UnknownError)
blanchet@36370
    87
           | proof => if res_code = 0 then (proof, NONE)
blanchet@36370
    88
                      else ("", SOME UnknownError))
blanchet@37514
    89
  | (failure :: _) =>
blanchet@37514
    90
    ("", SOME (if failure = IncompleteUnprovable andalso complete then
blanchet@37514
    91
                 Unprovable
blanchet@37514
    92
               else
blanchet@37514
    93
                 failure))
blanchet@36370
    94
blanchet@36370
    95
fun string_for_failure Unprovable = "The ATP problem is unprovable."
blanchet@37413
    96
  | string_for_failure IncompleteUnprovable =
blanchet@37413
    97
    "The ATP cannot prove the problem."
blanchet@37627
    98
  | string_for_failure CantConnect = "Can't connect to remote ATP."
blanchet@36370
    99
  | string_for_failure TimedOut = "Timed out."
blanchet@36370
   100
  | string_for_failure OutOfResources = "The ATP ran out of resources."
blanchet@36370
   101
  | string_for_failure OldSpass =
blanchet@36393
   102
    (* FIXME: Change the error message below to point to the Isabelle download
blanchet@36393
   103
       page once the package is there (around the Isabelle2010 release). *)
blanchet@36370
   104
    "Warning: Sledgehammer requires a more recent version of SPASS with \
blanchet@36370
   105
    \support for the TPTP syntax. To install it, download and untar the \
blanchet@36370
   106
    \package \"http://isabelle.in.tum.de/~blanchet/spass-3.7.tgz\" and add the \
blanchet@36370
   107
    \\"spass-3.7\" directory's full path to \"" ^
blanchet@36370
   108
    Path.implode (Path.expand (Path.appends
blanchet@36370
   109
        (Path.variable "ISABELLE_HOME_USER" ::
blanchet@36370
   110
         map Path.basic ["etc", "components"]))) ^
blanchet@36370
   111
    "\" on a line of its own."
blanchet@36965
   112
  | string_for_failure MalformedInput =
blanchet@36965
   113
    "Internal Sledgehammer error: The ATP problem is malformed. Please report \
blanchet@36965
   114
    \this to the Isabelle developers."
blanchet@36370
   115
  | string_for_failure MalformedOutput = "Error: The ATP output is malformed."
blanchet@36370
   116
  | string_for_failure UnknownError = "Error: An unknown ATP error occurred."
blanchet@35865
   117
blanchet@36400
   118
fun shape_of_clauses _ [] = []
blanchet@36400
   119
  | shape_of_clauses j ([] :: clauses) = [] :: shape_of_clauses j clauses
blanchet@37498
   120
  | shape_of_clauses j ((_ :: lits) :: clauses) =
blanchet@36400
   121
    let val shape = shape_of_clauses (j + 1) (lits :: clauses) in
blanchet@36400
   122
      (j :: hd shape) :: tl shape
blanchet@36400
   123
    end
blanchet@36400
   124
blanchet@37623
   125
blanchet@37623
   126
(* Clause preparation *)
blanchet@37623
   127
blanchet@37623
   128
fun make_clause_table xs =
blanchet@37623
   129
  fold (Termtab.update o `(prop_of o snd)) xs Termtab.empty
blanchet@37623
   130
blanchet@37623
   131
(* Remove existing axiom clauses from the conjecture clauses, as this can
blanchet@37623
   132
   dramatically boost an ATP's performance (for some reason). *)
blanchet@37623
   133
fun subtract_cls ax_clauses =
blanchet@37623
   134
  filter_out (Termtab.defined (make_clause_table ax_clauses) o prop_of)
blanchet@37623
   135
blanchet@37623
   136
fun is_false_literal (Literal (pos, CombConst ((c, _), _, _))) =
blanchet@37623
   137
      (pos andalso c = "c_False") orelse (not pos andalso c = "c_True")
blanchet@37623
   138
  | is_false_literal _ = false
blanchet@37623
   139
fun is_true_literal (Literal (pol, CombConst ((c, _), _, _))) =
blanchet@37623
   140
      (pol andalso c = "c_True") orelse
blanchet@37623
   141
      (not pol andalso c = "c_False")
blanchet@37623
   142
  | is_true_literal _ = false;
blanchet@37623
   143
fun is_tautology (HOLClause {literals,...}) = exists is_true_literal literals
blanchet@37623
   144
blanchet@37623
   145
(* making axiom and conjecture clauses *)
blanchet@37625
   146
fun make_clause thy (clause_id, axiom_name, kind, th) skolems =
blanchet@37623
   147
  let
blanchet@37625
   148
    val (skolems, t) = th |> prop_of |> conceal_skolem_terms clause_id skolems
blanchet@37623
   149
    val (lits, ctypes_sorts) = literals_of_term thy t
blanchet@37623
   150
  in
blanchet@37623
   151
    if forall is_false_literal lits then
blanchet@37623
   152
      raise TRIVIAL ()
blanchet@37623
   153
    else
blanchet@37625
   154
      (skolems,
blanchet@37623
   155
       HOLClause {clause_id = clause_id, axiom_name = axiom_name, th = th,
blanchet@37623
   156
                  kind = kind, literals = lits, ctypes_sorts = ctypes_sorts})
blanchet@37623
   157
  end
blanchet@37623
   158
blanchet@37625
   159
fun add_axiom_clause thy ((name, k), th) (skolems, clss) =
blanchet@37623
   160
  let
blanchet@37625
   161
    val (skolems, cls) = make_clause thy (k, name, Axiom, th) skolems
blanchet@37625
   162
  in (skolems, clss |> not (is_tautology cls) ? cons (name, cls)) end
blanchet@37623
   163
blanchet@37623
   164
fun make_axiom_clauses thy clauses =
blanchet@37623
   165
  ([], []) |> fold_rev (add_axiom_clause thy) clauses |> snd
blanchet@37623
   166
blanchet@37623
   167
fun make_conjecture_clauses thy =
blanchet@37623
   168
  let
blanchet@37623
   169
    fun aux _ _ [] = []
blanchet@37625
   170
      | aux n skolems (th :: ths) =
blanchet@37623
   171
        let
blanchet@37625
   172
          val (skolems, cls) =
blanchet@37625
   173
            make_clause thy (n, "conjecture", Conjecture, th) skolems
blanchet@37625
   174
        in cls :: aux (n + 1) skolems ths end
blanchet@37623
   175
  in aux 0 [] end
blanchet@37623
   176
blanchet@37623
   177
(** Helper clauses **)
blanchet@37623
   178
blanchet@37623
   179
fun count_combterm (CombConst ((c, _), _, _)) =
blanchet@37623
   180
    Symtab.map_entry c (Integer.add 1)
blanchet@37623
   181
  | count_combterm (CombVar _) = I
blanchet@37623
   182
  | count_combterm (CombApp (t1, t2)) = count_combterm t1 #> count_combterm t2
blanchet@37623
   183
fun count_literal (Literal (_, t)) = count_combterm t
blanchet@37623
   184
fun count_clause (HOLClause {literals, ...}) = fold count_literal literals
blanchet@37623
   185
blanchet@37623
   186
fun cnf_helper_thms thy raw =
blanchet@37623
   187
  map (`Thm.get_name_hint)
blanchet@37623
   188
  #> (if raw then  map (apfst (rpair 0)) else cnf_rules_pairs thy)
blanchet@37623
   189
blanchet@37623
   190
val optional_helpers =
blanchet@37623
   191
  [(["c_COMBI", "c_COMBK"], (false, @{thms COMBI_def COMBK_def})),
blanchet@37623
   192
   (["c_COMBB", "c_COMBC"], (false, @{thms COMBB_def COMBC_def})),
blanchet@37623
   193
   (["c_COMBS"], (false, @{thms COMBS_def}))]
blanchet@37623
   194
val optional_typed_helpers =
blanchet@37623
   195
  [(["c_True", "c_False"], (true, @{thms True_or_False})),
blanchet@37623
   196
   (["c_If"], (true, @{thms if_True if_False True_or_False}))]
blanchet@37623
   197
val mandatory_helpers = @{thms fequal_imp_equal equal_imp_fequal}
blanchet@37623
   198
blanchet@37623
   199
val init_counters =
blanchet@37623
   200
  Symtab.make (maps (maps (map (rpair 0) o fst))
blanchet@37623
   201
                    [optional_helpers, optional_typed_helpers])
blanchet@37623
   202
blanchet@37623
   203
fun get_helper_clauses thy is_FO full_types conjectures axcls =
blanchet@37623
   204
  let
blanchet@37623
   205
    val axclauses = map snd (make_axiom_clauses thy axcls)
blanchet@37623
   206
    val ct = fold (fold count_clause) [conjectures, axclauses] init_counters
blanchet@37623
   207
    fun is_needed c = the (Symtab.lookup ct c) > 0
blanchet@37623
   208
    val cnfs =
blanchet@37623
   209
      (optional_helpers
blanchet@37623
   210
       |> full_types ? append optional_typed_helpers
blanchet@37623
   211
       |> maps (fn (ss, (raw, ths)) =>
blanchet@37623
   212
                   if exists is_needed ss then cnf_helper_thms thy raw ths
blanchet@37623
   213
                   else []))
blanchet@37623
   214
      @ (if is_FO then [] else cnf_helper_thms thy false mandatory_helpers)
blanchet@37623
   215
  in map snd (make_axiom_clauses thy cnfs) end
blanchet@37623
   216
blanchet@37623
   217
(* prepare for passing to writer,
blanchet@37623
   218
   create additional clauses based on the information from extra_cls *)
blanchet@37623
   219
fun prepare_clauses full_types goal_cls axcls extra_cls thy =
blanchet@37623
   220
  let
blanchet@37623
   221
    val is_FO = forall (Meson.is_fol_term thy o prop_of) goal_cls
blanchet@37623
   222
    val ccls = subtract_cls extra_cls goal_cls
blanchet@37623
   223
    val _ = app (fn th => trace_msg (fn _ => Display.string_of_thm_global thy th)) ccls
blanchet@37623
   224
    val ccltms = map prop_of ccls
blanchet@37623
   225
    and axtms = map (prop_of o snd) extra_cls
blanchet@37623
   226
    val subs = tfree_classes_of_terms ccltms
blanchet@37623
   227
    and supers = tvar_classes_of_terms axtms
blanchet@37623
   228
    and tycons = type_consts_of_terms thy (ccltms @ axtms)
blanchet@37623
   229
    (*TFrees in conjecture clauses; TVars in axiom clauses*)
blanchet@37623
   230
    val conjectures = make_conjecture_clauses thy ccls
blanchet@37623
   231
    val (_, extra_clauses) = ListPair.unzip (make_axiom_clauses thy extra_cls)
blanchet@37623
   232
    val (clnames, axiom_clauses) = ListPair.unzip (make_axiom_clauses thy axcls)
blanchet@37623
   233
    val helper_clauses =
blanchet@37623
   234
      get_helper_clauses thy is_FO full_types conjectures extra_cls
blanchet@37623
   235
    val (supers', arity_clauses) = make_arity_clauses thy tycons supers
blanchet@37623
   236
    val classrel_clauses = make_classrel_clauses thy subs supers'
blanchet@37623
   237
  in
blanchet@37623
   238
    (Vector.fromList clnames,
blanchet@37623
   239
      (conjectures, axiom_clauses, extra_clauses, helper_clauses, classrel_clauses, arity_clauses))
blanchet@37623
   240
  end
blanchet@37623
   241
blanchet@37623
   242
blanchet@37499
   243
(* generic TPTP-based provers *)
blanchet@37499
   244
blanchet@37499
   245
fun generic_tptp_prover
blanchet@37499
   246
        (name, {home_var, executable, arguments, proof_delims, known_failures,
blanchet@37499
   247
                max_axiom_clauses, prefers_theory_relevant})
blanchet@37580
   248
        ({debug, overlord, full_types, explicit_apply, relevance_threshold,
blanchet@37580
   249
          relevance_convergence, theory_relevant, defs_relevant, isar_proof,
blanchet@37580
   250
          isar_shrink_factor, ...} : params)
blanchet@37499
   251
        minimize_command timeout
blanchet@35969
   252
        ({subgoal, goal, relevance_override, axiom_clauses, filtered_clauses}
blanchet@35969
   253
         : problem) =
wenzelm@28596
   254
  let
immler@31750
   255
    (* get clauses and prepare them for writing *)
blanchet@37498
   256
    val (ctxt, (_, th)) = goal;
wenzelm@32942
   257
    val thy = ProofContext.theory_of ctxt;
blanchet@36400
   258
    val goal_clss = #1 (neg_conjecture_clauses ctxt th subgoal)
blanchet@36400
   259
    val goal_cls = List.concat goal_clss
immler@31752
   260
    val the_filtered_clauses =
blanchet@37621
   261
      case filtered_clauses of
blanchet@37621
   262
        SOME fcls => fcls
blanchet@37621
   263
      | NONE => relevant_facts full_types relevance_threshold
blanchet@37499
   264
                    relevance_convergence defs_relevant max_axiom_clauses
blanchet@37499
   265
                    (the_default prefers_theory_relevant theory_relevant)
blanchet@37499
   266
                    relevance_override goal goal_cls
blanchet@37621
   267
                |> cnf_rules_pairs thy
blanchet@37506
   268
    val the_axiom_clauses = axiom_clauses |> the_default the_filtered_clauses
blanchet@35969
   269
    val (internal_thm_names, clauses) =
blanchet@37499
   270
      prepare_clauses full_types goal_cls the_axiom_clauses the_filtered_clauses
blanchet@37499
   271
                      thy
immler@31750
   272
boehmes@32864
   273
    (* path to unique problem file *)
blanchet@36376
   274
    val the_dest_dir = if overlord then getenv "ISABELLE_HOME_USER"
blanchet@36376
   275
                       else Config.get ctxt dest_dir;
blanchet@36376
   276
    val the_problem_prefix = Config.get ctxt problem_prefix;
boehmes@32864
   277
    fun prob_pathname nr =
blanchet@36143
   278
      let
blanchet@36143
   279
        val probfile =
blanchet@36568
   280
          Path.basic ((if overlord then "prob_" ^ name
blanchet@36568
   281
                       else the_problem_prefix ^ serial_string ())
blanchet@36143
   282
                      ^ "_" ^ string_of_int nr)
wenzelm@32942
   283
      in
blanchet@36376
   284
        if the_dest_dir = "" then File.tmp_path probfile
blanchet@36376
   285
        else if File.exists (Path.explode the_dest_dir)
blanchet@36376
   286
        then Path.append (Path.explode the_dest_dir) probfile
blanchet@36376
   287
        else error ("No such directory: " ^ the_dest_dir ^ ".")
wenzelm@32942
   288
      end;
boehmes@32864
   289
blanchet@36917
   290
    val home = getenv home_var
blanchet@36289
   291
    val command = Path.explode (home ^ "/" ^ executable)
immler@31750
   292
    (* write out problem file and call prover *)
blanchet@37514
   293
    fun command_line complete probfile =
blanchet@37514
   294
      let
blanchet@37514
   295
        val core = File.shell_path command ^ " " ^ arguments complete timeout ^
blanchet@37514
   296
                   " " ^ File.shell_path probfile
blanchet@37514
   297
      in
blanchet@37514
   298
        (if Config.get ctxt measure_runtime then
blanchet@37514
   299
           "TIMEFORMAT='%3U'; { time " ^ core ^ " ; }"
blanchet@37514
   300
         else
blanchet@37514
   301
           "exec " ^ core) ^ " 2>&1" ^
blanchet@37514
   302
        (if overlord then
blanchet@37514
   303
           " | sed 's/,/, /g' \
blanchet@37514
   304
           \| sed 's/\\([^!=<]\\)\\([=|]\\)\\([^=>]\\)/\\1 \\2 \\3/g' \
blanchet@37514
   305
           \| sed 's/  / /g' | sed 's/| |/||/g' \
blanchet@37514
   306
           \| sed 's/ = = =/===/g' \
blanchet@37514
   307
           \| sed 's/= = /== /g'"
blanchet@37514
   308
         else
blanchet@37514
   309
           "")
blanchet@37514
   310
      end
boehmes@32510
   311
    fun split_time s =
boehmes@32510
   312
      let
wenzelm@32942
   313
        val split = String.tokens (fn c => str c = "\n");
blanchet@36369
   314
        val (output, t) = s |> split |> split_last |> apfst cat_lines;
wenzelm@32942
   315
        fun as_num f = f >> (fst o read_int);
wenzelm@32942
   316
        val num = as_num (Scan.many1 Symbol.is_ascii_digit);
wenzelm@32942
   317
        val digit = Scan.one Symbol.is_ascii_digit;
wenzelm@32942
   318
        val num3 = as_num (digit ::: digit ::: (digit >> single));
wenzelm@32942
   319
        val time = num --| Scan.$$ "." -- num3 >> (fn (a, b) => a * 1000 + b);
wenzelm@32942
   320
        val as_time = the_default 0 o Scan.read Symbol.stopper time o explode;
blanchet@36369
   321
      in (output, as_time t) end;
boehmes@32458
   322
    fun run_on probfile =
blanchet@36289
   323
      if File.exists command then
blanchet@37514
   324
        let
blanchet@37514
   325
          fun do_run complete =
blanchet@37514
   326
            let
blanchet@37514
   327
              val command = command_line complete probfile
blanchet@37514
   328
              val ((output, msecs), res_code) =
blanchet@37514
   329
                bash_output command
blanchet@37514
   330
                |>> (if overlord then
blanchet@37514
   331
                       prefix ("% " ^ command ^ "\n% " ^ timestamp () ^ "\n")
blanchet@37514
   332
                     else
blanchet@37514
   333
                       I)
blanchet@37514
   334
                |>> (if Config.get ctxt measure_runtime then split_time
blanchet@37514
   335
                     else rpair 0)
blanchet@37514
   336
              val (proof, outcome) =
blanchet@37514
   337
                extract_proof_and_outcome complete res_code proof_delims
blanchet@37514
   338
                                          known_failures output
blanchet@37514
   339
            in (output, msecs, proof, outcome) end
blanchet@37514
   340
          val (pool, conjecture_offset) =
blanchet@37514
   341
            write_tptp_file (debug andalso overlord) full_types explicit_apply
blanchet@37514
   342
                            probfile clauses
blanchet@37514
   343
          val conjecture_shape = shape_of_clauses (conjecture_offset + 1) goal_clss
blanchet@37514
   344
          val result =
blanchet@37514
   345
            do_run false
blanchet@37550
   346
            |> (fn (_, msecs0, _, SOME _) =>
blanchet@37514
   347
                   do_run true
blanchet@37514
   348
                   |> (fn (output, msecs, proof, outcome) =>
blanchet@37514
   349
                          (output, msecs0 + msecs, proof, outcome))
blanchet@37514
   350
                 | result => result)
blanchet@37514
   351
        in ((pool, conjecture_shape), result) end
blanchet@36917
   352
      else if home = "" then
blanchet@36917
   353
        error ("The environment variable " ^ quote home_var ^ " is not set.")
blanchet@36382
   354
      else
blanchet@36382
   355
        error ("Bad executable: " ^ Path.implode command ^ ".");
wenzelm@28592
   356
blanchet@36167
   357
    (* If the problem file has not been exported, remove it; otherwise, export
blanchet@36167
   358
       the proof file too. *)
blanchet@36376
   359
    fun cleanup probfile =
blanchet@36376
   360
      if the_dest_dir = "" then try File.rm probfile else NONE
blanchet@37514
   361
    fun export probfile (_, (output, _, _, _)) =
blanchet@36376
   362
      if the_dest_dir = "" then
blanchet@36187
   363
        ()
blanchet@36187
   364
      else
blanchet@37514
   365
        File.write (Path.explode (Path.implode probfile ^ "_proof")) output
wenzelm@32257
   366
blanchet@37514
   367
    val ((pool, conjecture_shape), (output, msecs, proof, outcome)) =
blanchet@37514
   368
      with_path cleanup export run_on (prob_pathname subgoal)
blanchet@37514
   369
blanchet@35969
   370
    val (message, relevant_thm_names) =
blanchet@36370
   371
      case outcome of
blanchet@36400
   372
        NONE =>
blanchet@36400
   373
        proof_text isar_proof
blanchet@37480
   374
            (pool, debug, isar_shrink_factor, ctxt, conjecture_shape)
blanchet@37480
   375
            (full_types, minimize_command, proof, internal_thm_names, th,
blanchet@37480
   376
             subgoal)
blanchet@36370
   377
      | SOME failure => (string_for_failure failure ^ "\n", [])
boehmes@32864
   378
  in
blanchet@36393
   379
    {outcome = outcome, message = message, pool = pool,
blanchet@37514
   380
     relevant_thm_names = relevant_thm_names, atp_run_time_in_msecs = msecs,
blanchet@37514
   381
     output = output, proof = proof, internal_thm_names = internal_thm_names,
blanchet@36400
   382
     conjecture_shape = conjecture_shape,
blanchet@35969
   383
     filtered_clauses = the_filtered_clauses}
blanchet@37499
   384
  end
wenzelm@28596
   385
blanchet@35969
   386
fun tptp_prover name p = (name, generic_tptp_prover (name, p));
wenzelm@28596
   387
blanchet@36382
   388
fun to_generous_secs time = (Time.toMilliseconds time + 999) div 1000
blanchet@36142
   389
wenzelm@28596
   390
(* E prover *)
wenzelm@28596
   391
blanchet@36369
   392
val tstp_proof_delims =
blanchet@36369
   393
  ("# SZS output start CNFRefutation.", "# SZS output end CNFRefutation")
blanchet@36369
   394
blanchet@35969
   395
val e_config : prover_config =
blanchet@36917
   396
  {home_var = "E_HOME",
blanchet@36289
   397
   executable = "eproof",
blanchet@37514
   398
   arguments = fn _ => fn timeout =>
blanchet@36382
   399
     "--tstp-in --tstp-out -l5 -xAutoDev -tAutoDev --silent --cpu-limit=" ^
blanchet@36382
   400
     string_of_int (to_generous_secs timeout),
blanchet@36369
   401
   proof_delims = [tstp_proof_delims],
blanchet@36265
   402
   known_failures =
blanchet@36370
   403
     [(Unprovable, "SZS status: Satisfiable"),
blanchet@36370
   404
      (Unprovable, "SZS status Satisfiable"),
blanchet@36370
   405
      (TimedOut, "Failure: Resource limit exceeded (time)"),
blanchet@36370
   406
      (TimedOut, "time limit exceeded"),
blanchet@36370
   407
      (OutOfResources,
blanchet@36370
   408
       "# Cannot determine problem status within resource limit"),
blanchet@36370
   409
      (OutOfResources, "SZS status: ResourceOut"),
blanchet@36370
   410
      (OutOfResources, "SZS status ResourceOut")],
blanchet@36382
   411
   max_axiom_clauses = 100,
blanchet@36289
   412
   prefers_theory_relevant = false}
blanchet@35969
   413
val e = tptp_prover "e" e_config
wenzelm@28596
   414
wenzelm@28596
   415
blanchet@36219
   416
(* The "-VarWeight=3" option helps the higher-order problems, probably by
blanchet@36219
   417
   counteracting the presence of "hAPP". *)
blanchet@37498
   418
val spass_config : prover_config =
blanchet@36917
   419
  {home_var = "SPASS_HOME",
blanchet@36289
   420
   executable = "SPASS",
blanchet@37550
   421
   (* "div 2" accounts for the fact that SPASS is often run twice. *)
blanchet@37514
   422
   arguments = fn complete => fn timeout =>
blanchet@37514
   423
     ("-TPTP -Auto -PGiven=0 -PProblem=0 -Splits=0 -FullRed=0 -DocProof \
blanchet@37550
   424
      \-VarWeight=3 -TimeLimit=" ^
blanchet@37550
   425
      string_of_int (to_generous_secs timeout div 2))
blanchet@37514
   426
     |> not complete ? prefix "-SOS=1 ",
blanchet@36369
   427
   proof_delims = [("Here is a proof", "Formulae used in the proof")],
blanchet@36289
   428
   known_failures =
blanchet@37413
   429
     [(IncompleteUnprovable, "SPASS beiseite: Completion found"),
blanchet@36370
   430
      (TimedOut, "SPASS beiseite: Ran out of time"),
blanchet@36965
   431
      (OutOfResources, "SPASS beiseite: Maximal number of loops exceeded"),
blanchet@37413
   432
      (MalformedInput, "Undefined symbol"),
blanchet@37414
   433
      (MalformedInput, "Free Variable"),
blanchet@37414
   434
      (OldSpass, "unrecognized option `-TPTP'"),
blanchet@37414
   435
      (OldSpass, "Unrecognized option TPTP")],
blanchet@36382
   436
   max_axiom_clauses = 40,
blanchet@36289
   437
   prefers_theory_relevant = true}
blanchet@37414
   438
val spass = tptp_prover "spass" spass_config
wenzelm@28596
   439
blanchet@37509
   440
(* Vampire *)
blanchet@37509
   441
blanchet@37509
   442
val vampire_config : prover_config =
blanchet@37509
   443
  {home_var = "VAMPIRE_HOME",
blanchet@37509
   444
   executable = "vampire",
blanchet@37514
   445
   arguments = fn _ => fn timeout =>
blanchet@37509
   446
     "--output_syntax tptp --mode casc -t " ^
blanchet@37509
   447
     string_of_int (to_generous_secs timeout),
blanchet@37509
   448
   proof_delims =
blanchet@37509
   449
     [("=========== Refutation ==========",
blanchet@37509
   450
       "======= End of refutation ======="),
blanchet@37509
   451
      ("% SZS output start Refutation", "% SZS output end Refutation")],
blanchet@37509
   452
   known_failures =
blanchet@37509
   453
     [(Unprovable, "UNPROVABLE"),
blanchet@37509
   454
      (IncompleteUnprovable, "CANNOT PROVE"),
blanchet@37509
   455
      (Unprovable, "Satisfiability detected"),
blanchet@37509
   456
      (OutOfResources, "Refutation not found")],
blanchet@37509
   457
   max_axiom_clauses = 60,
blanchet@37509
   458
   prefers_theory_relevant = false}
blanchet@37509
   459
val vampire = tptp_prover "vampire" vampire_config
blanchet@37509
   460
blanchet@37509
   461
(* Remote prover invocation via SystemOnTPTP *)
wenzelm@28596
   462
blanchet@36376
   463
val systems = Synchronized.var "atp_systems" ([]: string list);
immler@31835
   464
immler@31835
   465
fun get_systems () =
blanchet@36370
   466
  case bash_output "\"$ISABELLE_ATP_MANAGER/SystemOnTPTP\" -w" of
blanchet@36370
   467
    (answer, 0) => split_lines answer
blanchet@36370
   468
  | (answer, _) =>
blanchet@37627
   469
    error ("Failed to get available systems at SystemOnTPTP:\n" ^
blanchet@37627
   470
           perhaps (try (unsuffix "\n")) answer)
immler@31835
   471
blanchet@35867
   472
fun refresh_systems_on_tptp () =
blanchet@37509
   473
  Synchronized.change systems (fn _ => get_systems ())
immler@31835
   474
immler@31835
   475
fun get_system prefix = Synchronized.change_result systems (fn systems =>
boehmes@32864
   476
  (if null systems then get_systems () else systems)
wenzelm@32942
   477
  |> `(find_first (String.isPrefix prefix)));
boehmes@32864
   478
wenzelm@32948
   479
fun the_system prefix =
boehmes@32864
   480
  (case get_system prefix of
blanchet@37509
   481
    NONE => error ("System " ^ quote prefix ^ " not available at SystemOnTPTP.")
wenzelm@32942
   482
  | SOME sys => sys);
immler@31835
   483
blanchet@36265
   484
val remote_known_failures =
blanchet@37627
   485
  [(CantConnect, "HTTP-Error"),
blanchet@37627
   486
   (TimedOut, "says Timeout"),
blanchet@36377
   487
   (MalformedOutput, "Remote script could not extract proof")]
blanchet@35865
   488
blanchet@37509
   489
fun remote_config atp_prefix args
blanchet@36382
   490
        ({proof_delims, known_failures, max_axiom_clauses,
blanchet@36369
   491
          prefers_theory_relevant, ...} : prover_config) : prover_config =
blanchet@36917
   492
  {home_var = "ISABELLE_ATP_MANAGER",
blanchet@36289
   493
   executable = "SystemOnTPTP",
blanchet@37514
   494
   arguments = fn _ => fn timeout =>
blanchet@36382
   495
     args ^ " -t " ^ string_of_int (to_generous_secs timeout) ^ " -s " ^
blanchet@36382
   496
     the_system atp_prefix,
blanchet@36369
   497
   proof_delims = insert (op =) tstp_proof_delims proof_delims,
blanchet@36265
   498
   known_failures = remote_known_failures @ known_failures,
blanchet@36382
   499
   max_axiom_clauses = max_axiom_clauses,
blanchet@36289
   500
   prefers_theory_relevant = prefers_theory_relevant}
wenzelm@28596
   501
blanchet@37509
   502
fun remote_tptp_prover prover atp_prefix args config =
blanchet@37509
   503
  tptp_prover (remotify (fst prover)) (remote_config atp_prefix args config)
boehmes@32864
   504
blanchet@37509
   505
val remote_e = remote_tptp_prover e "EP---" "" e_config
blanchet@37509
   506
val remote_spass = remote_tptp_prover spass "SPASS---" "-x" spass_config
blanchet@37509
   507
val remote_vampire = remote_tptp_prover vampire "Vampire---9" "" vampire_config
wenzelm@28592
   508
blanchet@36917
   509
fun maybe_remote (name, _) ({home_var, ...} : prover_config) =
blanchet@36917
   510
  name |> getenv home_var = "" ? remotify
blanchet@36371
   511
blanchet@36371
   512
fun default_atps_param_value () =
blanchet@36371
   513
  space_implode " " [maybe_remote e e_config, maybe_remote spass spass_config,
blanchet@36371
   514
                     remotify (fst vampire)]
blanchet@36371
   515
blanchet@37509
   516
val provers = [e, spass, vampire, remote_e, remote_spass, remote_vampire]
blanchet@35867
   517
val prover_setup = fold add_prover provers
blanchet@35867
   518
blanchet@35867
   519
val setup =
blanchet@36376
   520
  dest_dir_setup
blanchet@35867
   521
  #> problem_prefix_setup
blanchet@35867
   522
  #> measure_runtime_setup
blanchet@36371
   523
  #> prover_setup
blanchet@35867
   524
wenzelm@28592
   525
end;