src/HOL/Tools/ATP/atp_systems.ML
author blanchet
Sun May 01 18:37:25 2011 +0200 (2011-05-01)
changeset 42584 8121a31b6754
parent 42579 2552c09b1a72
child 42589 9f7c48463645
permissions -rw-r--r--
pick up GaveUp error on SystemOnTPTP
blanchet@38047
     1
(*  Title:      HOL/Tools/ATP/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@42577
    10
  type format = ATP_Problem.format
blanchet@42577
    11
  type formula_kind = ATP_Problem.formula_kind
blanchet@39491
    12
  type failure = ATP_Proof.failure
blanchet@38023
    13
blanchet@42579
    14
  datatype type_level = Sound | Half_Sound | Unsound
blanchet@42578
    15
  datatype type_system =
blanchet@42578
    16
    Many_Typed |
blanchet@42578
    17
    Mangled of type_level |
blanchet@42578
    18
    Args of bool * type_level |
blanchet@42579
    19
    Tags of bool * type_level |
blanchet@42579
    20
    No_Types
blanchet@42578
    21
blanchet@40059
    22
  type atp_config =
blanchet@42578
    23
    {exec : string * string,
blanchet@42578
    24
     required_execs : (string * string) list,
blanchet@42578
    25
     arguments : int -> Time.time -> (unit -> (string * real) list) -> string,
blanchet@42578
    26
     proof_delims : (string * string) list,
blanchet@42578
    27
     known_failures : (failure * string) list,
blanchet@42578
    28
     hypothesis_kind : formula_kind,
blanchet@42578
    29
     formats : format list,
blanchet@42578
    30
     best_slices : unit -> (real * (bool * int)) list,
blanchet@42578
    31
     best_type_systems : type_system list}
blanchet@38023
    32
blanchet@42443
    33
  datatype e_weight_method =
blanchet@42443
    34
    E_Slices | E_Auto | E_Fun_Weight | E_Sym_Offset_Weight
blanchet@41725
    35
blanchet@42579
    36
  val level_of_type_sys : type_system -> type_level
blanchet@41313
    37
  (* for experimentation purposes -- do not use in production code *)
blanchet@41725
    38
  val e_weight_method : e_weight_method Unsynchronized.ref
blanchet@41725
    39
  val e_default_fun_weight : real Unsynchronized.ref
blanchet@41725
    40
  val e_fun_weight_base : real Unsynchronized.ref
blanchet@41770
    41
  val e_fun_weight_span : real Unsynchronized.ref
blanchet@41725
    42
  val e_default_sym_offs_weight : real Unsynchronized.ref
blanchet@41725
    43
  val e_sym_offs_weight_base : real Unsynchronized.ref
blanchet@41770
    44
  val e_sym_offs_weight_span : real Unsynchronized.ref
blanchet@42579
    45
  (* end *)
blanchet@40059
    46
  val eN : string
blanchet@40059
    47
  val spassN : string
blanchet@40059
    48
  val vampireN : string
blanchet@42535
    49
  val tofof_eN : string
blanchet@40059
    50
  val sine_eN : string
blanchet@40059
    51
  val snarkN : string
blanchet@41738
    52
  val z3_atpN : string
blanchet@40060
    53
  val remote_prefix : string
blanchet@41738
    54
  val remote_atp :
blanchet@41738
    55
    string -> string -> string list -> (string * string) list
blanchet@42578
    56
    -> (failure * string) list -> formula_kind -> format list -> (unit -> int)
blanchet@42578
    57
    -> type_system list -> string * atp_config
blanchet@40059
    58
  val add_atp : string * atp_config -> theory -> theory
blanchet@40059
    59
  val get_atp : theory -> string -> atp_config
blanchet@41727
    60
  val supported_atps : theory -> string list
blanchet@40059
    61
  val is_atp_installed : theory -> string -> bool
blanchet@35867
    62
  val refresh_systems_on_tptp : unit -> unit
blanchet@35867
    63
  val setup : theory -> theory
wenzelm@28592
    64
end;
wenzelm@28592
    65
blanchet@36376
    66
structure ATP_Systems : ATP_SYSTEMS =
wenzelm@28592
    67
struct
wenzelm@28596
    68
blanchet@42577
    69
open ATP_Problem
blanchet@39491
    70
open ATP_Proof
boehmes@32864
    71
blanchet@40059
    72
(* ATP configuration *)
boehmes@32864
    73
blanchet@42579
    74
datatype type_level = Sound | Half_Sound | Unsound
blanchet@42578
    75
datatype type_system =
blanchet@42578
    76
  Many_Typed |
blanchet@42578
    77
  Mangled of type_level |
blanchet@42578
    78
  Args of bool * type_level |
blanchet@42579
    79
  Tags of bool * type_level |
blanchet@42579
    80
  No_Types
blanchet@42579
    81
blanchet@42579
    82
fun level_of_type_sys Many_Typed = Sound
blanchet@42579
    83
  | level_of_type_sys (Mangled level) = level
blanchet@42579
    84
  | level_of_type_sys (Args (_, level)) = level
blanchet@42579
    85
  | level_of_type_sys (Tags (_, level)) = level
blanchet@42579
    86
  | level_of_type_sys No_Types = Unsound
blanchet@42578
    87
blanchet@40059
    88
type atp_config =
blanchet@42578
    89
  {exec : string * string,
blanchet@42578
    90
   required_execs : (string * string) list,
blanchet@42578
    91
   arguments : int -> Time.time -> (unit -> (string * real) list) -> string,
blanchet@42578
    92
   proof_delims : (string * string) list,
blanchet@42578
    93
   known_failures : (failure * string) list,
blanchet@42578
    94
   hypothesis_kind : formula_kind,
blanchet@42578
    95
   formats : format list,
blanchet@42578
    96
   best_slices : unit -> (real * (bool * int)) list,
blanchet@42578
    97
   best_type_systems : type_system list}
wenzelm@28596
    98
blanchet@38061
    99
val known_perl_failures =
blanchet@38094
   100
  [(CantConnect, "HTTP error"),
blanchet@38094
   101
   (NoPerl, "env: perl"),
blanchet@38065
   102
   (NoLibwwwPerl, "Can't locate HTTP")]
wenzelm@28596
   103
blanchet@40059
   104
(* named ATPs *)
blanchet@40059
   105
blanchet@40059
   106
val eN = "e"
blanchet@40059
   107
val spassN = "spass"
blanchet@40059
   108
val vampireN = "vampire"
blanchet@41740
   109
val z3_atpN = "z3_atp"
blanchet@42535
   110
val tofof_eN = "tofof_e"
blanchet@40059
   111
val sine_eN = "sine_e"
blanchet@40059
   112
val snarkN = "snark"
blanchet@40060
   113
val remote_prefix = "remote_"
blanchet@38001
   114
blanchet@38023
   115
structure Data = Theory_Data
blanchet@38023
   116
(
blanchet@40059
   117
  type T = (atp_config * stamp) Symtab.table
blanchet@38023
   118
  val empty = Symtab.empty
blanchet@38023
   119
  val extend = I
blanchet@38023
   120
  fun merge data : T = Symtab.merge (eq_snd op =) data
blanchet@38023
   121
    handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@38023
   122
)
blanchet@38017
   123
blanchet@38737
   124
fun to_secs bonus time = (Time.toMilliseconds time + bonus + 999) div 1000
blanchet@36142
   125
blanchet@39491
   126
blanchet@40059
   127
(* E *)
wenzelm@28596
   128
blanchet@40344
   129
(* Give E an extra second to reconstruct the proof. Older versions even get two
blanchet@40344
   130
   seconds, because the "eproof" script wrongly subtracted an entire second to
blanchet@40344
   131
   account for the overhead of the script itself, which is in fact much
blanchet@40344
   132
   lower. *)
blanchet@38737
   133
fun e_bonus () =
blanchet@41334
   134
  if string_ord (getenv "E_VERSION", "1.1") = LESS then 2000 else 1000
blanchet@38737
   135
blanchet@36369
   136
val tstp_proof_delims =
blanchet@36369
   137
  ("# SZS output start CNFRefutation.", "# SZS output end CNFRefutation")
blanchet@36369
   138
blanchet@42443
   139
datatype e_weight_method =
blanchet@42443
   140
  E_Slices | E_Auto | E_Fun_Weight | E_Sym_Offset_Weight
blanchet@41725
   141
blanchet@42443
   142
val e_weight_method = Unsynchronized.ref E_Slices
blanchet@41770
   143
(* FUDGE *)
blanchet@41770
   144
val e_default_fun_weight = Unsynchronized.ref 20.0
blanchet@41725
   145
val e_fun_weight_base = Unsynchronized.ref 0.0
blanchet@41770
   146
val e_fun_weight_span = Unsynchronized.ref 40.0
blanchet@41770
   147
val e_default_sym_offs_weight = Unsynchronized.ref 1.0
blanchet@41770
   148
val e_sym_offs_weight_base = Unsynchronized.ref ~20.0
blanchet@41770
   149
val e_sym_offs_weight_span = Unsynchronized.ref 60.0
blanchet@41725
   150
blanchet@42443
   151
fun e_weight_method_case method fw sow =
blanchet@42443
   152
  case method of
blanchet@41725
   153
    E_Auto => raise Fail "Unexpected \"E_Auto\""
blanchet@41725
   154
  | E_Fun_Weight => fw
blanchet@41725
   155
  | E_Sym_Offset_Weight => sow
blanchet@41725
   156
blanchet@42443
   157
fun scaled_e_weight method w =
blanchet@42443
   158
  w * e_weight_method_case method (!e_fun_weight_span) (!e_sym_offs_weight_span)
blanchet@42443
   159
  + e_weight_method_case method (!e_fun_weight_base) (!e_sym_offs_weight_base)
blanchet@41725
   160
  |> Real.ceil |> signed_string_of_int
blanchet@41313
   161
blanchet@42443
   162
fun e_weight_arguments method weights =
blanchet@42443
   163
  if method = E_Auto then
blanchet@41725
   164
    "-xAutoDev"
blanchet@41725
   165
  else
blanchet@41314
   166
    "--split-clauses=4 --split-reuse-defs --simul-paramod --forward-context-sr \
blanchet@41314
   167
    \--destructive-er-aggressive --destructive-er --presat-simplify \
blanchet@41314
   168
    \--prefer-initial-clauses -tKBO6 -winvfreqrank -c1 -Ginvfreqconjmax -F1 \
blanchet@41314
   169
    \--delete-bad-limit=150000000 -WSelectMaxLComplexAvoidPosPred \
blanchet@42443
   170
    \-H'(4*" ^ e_weight_method_case method "FunWeight" "SymOffsetWeight" ^
blanchet@41725
   171
    "(SimulateSOS, " ^
blanchet@42443
   172
    (e_weight_method_case method (!e_default_fun_weight)
blanchet@42443
   173
                                 (!e_default_sym_offs_weight)
blanchet@41769
   174
     |> Real.ceil |> signed_string_of_int) ^
blanchet@41314
   175
    ",20,1.5,1.5,1" ^
blanchet@42443
   176
    (weights () |> map (fn (s, w) => "," ^ s ^ ":" ^ scaled_e_weight method w)
blanchet@41725
   177
                |> implode) ^
blanchet@41314
   178
    "),3*ConjectureGeneralSymbolWeight(PreferNonGoals,200,100,200,50,50,1,100,\
blanchet@41314
   179
    \1.5,1.5,1),1*Clauseweight(PreferProcessed,1,1,1),1*\
blanchet@41314
   180
    \FIFOWeight(PreferProcessed))'"
blanchet@41313
   181
blanchet@42443
   182
fun is_old_e_version () = (string_ord (getenv "E_VERSION", "1.2w") = LESS)
blanchet@42443
   183
blanchet@42443
   184
fun effective_e_weight_method () =
blanchet@42443
   185
  if is_old_e_version () then E_Auto else !e_weight_method
blanchet@42443
   186
blanchet@42443
   187
(* The order here must correspond to the order in "e_config" below. *)
blanchet@42443
   188
fun method_for_slice slice =
blanchet@42443
   189
  case effective_e_weight_method () of
blanchet@42443
   190
    E_Slices => (case slice of
blanchet@42443
   191
                   0 => E_Sym_Offset_Weight
blanchet@42443
   192
                 | 1 => E_Auto
blanchet@42443
   193
                 | 2 => E_Fun_Weight
blanchet@42443
   194
                 | _ => raise Fail "no such slice")
blanchet@42443
   195
  | method => method
blanchet@42443
   196
blanchet@40059
   197
val e_config : atp_config =
blanchet@38092
   198
  {exec = ("E_HOME", "eproof"),
blanchet@38092
   199
   required_execs = [],
blanchet@42443
   200
   arguments = fn slice => fn timeout => fn weights =>
blanchet@42443
   201
     "--tstp-in --tstp-out -l5 " ^
blanchet@42443
   202
     e_weight_arguments (method_for_slice slice) weights ^
blanchet@42443
   203
     " -tAutoDev --silent --cpu-limit=" ^
blanchet@42443
   204
     string_of_int (to_secs (e_bonus ()) timeout),
blanchet@36369
   205
   proof_delims = [tstp_proof_delims],
blanchet@36265
   206
   known_failures =
blanchet@37995
   207
     [(Unprovable, "SZS status: CounterSatisfiable"),
blanchet@37995
   208
      (Unprovable, "SZS status CounterSatisfiable"),
blanchet@36370
   209
      (TimedOut, "Failure: Resource limit exceeded (time)"),
blanchet@36370
   210
      (TimedOut, "time limit exceeded"),
blanchet@36370
   211
      (OutOfResources,
blanchet@36370
   212
       "# Cannot determine problem status within resource limit"),
blanchet@36370
   213
      (OutOfResources, "SZS status: ResourceOut"),
blanchet@36370
   214
      (OutOfResources, "SZS status ResourceOut")],
blanchet@42577
   215
   hypothesis_kind = Conjecture,
blanchet@42578
   216
   formats = [Fof],
blanchet@42578
   217
   best_slices = fn () =>
blanchet@42578
   218
     if effective_e_weight_method () = E_Slices then
blanchet@42578
   219
       [(0.33333, (true, 100 (* FUDGE *))) (* E_Sym_Offset_Weight *),
blanchet@42578
   220
        (0.33333, (true, 1000 (* FUDGE *))) (* E_Auto *),
blanchet@42578
   221
        (0.33334, (true, 200 (* FUDGE *))) (* E_Fun_Weight *)]
blanchet@42578
   222
     else
blanchet@42578
   223
       [(1.0, (true, 250 (* FUDGE *)))],
blanchet@42578
   224
   best_type_systems = []}
blanchet@38454
   225
blanchet@40059
   226
val e = (eN, e_config)
wenzelm@28596
   227
wenzelm@28596
   228
blanchet@39491
   229
(* SPASS *)
blanchet@39491
   230
blanchet@36219
   231
(* The "-VarWeight=3" option helps the higher-order problems, probably by
blanchet@36219
   232
   counteracting the presence of "hAPP". *)
blanchet@40059
   233
val spass_config : atp_config =
blanchet@38092
   234
  {exec = ("ISABELLE_ATP", "scripts/spass"),
blanchet@39002
   235
   required_execs = [("SPASS_HOME", "SPASS"), ("SPASS_HOME", "tptp2dfg")],
blanchet@42443
   236
   arguments = fn slice => fn timeout => fn _ =>
blanchet@37962
   237
     ("-Auto -PGiven=0 -PProblem=0 -Splits=0 -FullRed=0 -DocProof \
blanchet@38737
   238
      \-VarWeight=3 -TimeLimit=" ^ string_of_int (to_secs 0 timeout))
blanchet@42443
   239
     |> slice = 0 ? prefix "-SOS=1 ",
blanchet@36369
   240
   proof_delims = [("Here is a proof", "Formulae used in the proof")],
blanchet@36289
   241
   known_failures =
blanchet@38061
   242
     known_perl_failures @
blanchet@37413
   243
     [(IncompleteUnprovable, "SPASS beiseite: Completion found"),
blanchet@36370
   244
      (TimedOut, "SPASS beiseite: Ran out of time"),
blanchet@36965
   245
      (OutOfResources, "SPASS beiseite: Maximal number of loops exceeded"),
blanchet@37413
   246
      (MalformedInput, "Undefined symbol"),
blanchet@37414
   247
      (MalformedInput, "Free Variable"),
blanchet@39263
   248
      (SpassTooOld, "tptp2dfg"),
blanchet@39263
   249
      (InternalError, "Please report this error")],
blanchet@42577
   250
   hypothesis_kind = Conjecture,
blanchet@42578
   251
   formats = [Fof],
blanchet@42578
   252
   best_slices =
blanchet@42578
   253
     K [(0.66667, (false, 150 (* FUDGE *))) (* with SOS *),
blanchet@42578
   254
        (0.33333, (true, 150 (* FUDGE *))) (* without SOS *)],
blanchet@42578
   255
   best_type_systems = []}
blanchet@38454
   256
blanchet@40059
   257
val spass = (spassN, spass_config)
wenzelm@28596
   258
blanchet@38454
   259
blanchet@37509
   260
(* Vampire *)
blanchet@37509
   261
blanchet@40059
   262
val vampire_config : atp_config =
blanchet@38092
   263
  {exec = ("VAMPIRE_HOME", "vampire"),
blanchet@38092
   264
   required_execs = [],
blanchet@42443
   265
   arguments = fn slice => fn timeout => fn _ =>
blanchet@41203
   266
     (* This would work too but it's less tested: "--proof tptp " ^ *)
blanchet@41203
   267
     "--mode casc -t " ^ string_of_int (to_secs 0 timeout) ^
blanchet@41203
   268
     " --thanks \"Andrei and Krystof\" --input_file"
blanchet@42443
   269
     |> slice = 0 ? prefix "--sos on ",
blanchet@37509
   270
   proof_delims =
blanchet@37509
   271
     [("=========== Refutation ==========",
blanchet@37509
   272
       "======= End of refutation ======="),
blanchet@38033
   273
      ("% SZS output start Refutation", "% SZS output end Refutation"),
blanchet@38033
   274
      ("% SZS output start Proof", "% SZS output end Proof")],
blanchet@37509
   275
   known_failures =
blanchet@37509
   276
     [(Unprovable, "UNPROVABLE"),
blanchet@37509
   277
      (IncompleteUnprovable, "CANNOT PROVE"),
blanchet@42449
   278
      (IncompleteUnprovable, "SZS status GaveUp"),
blanchet@42332
   279
      (ProofMissing, "[predicate definition introduction]"),
blanchet@42332
   280
      (ProofMissing, "predicate_definition_introduction,[]"), (* TSTP *)
blanchet@38092
   281
      (TimedOut, "SZS status Timeout"),
blanchet@37509
   282
      (Unprovable, "Satisfiability detected"),
blanchet@38647
   283
      (Unprovable, "Termination reason: Satisfiable"),
blanchet@39263
   284
      (VampireTooOld, "not a valid option"),
blanchet@39263
   285
      (Interrupted, "Aborted by signal SIGINT")],
blanchet@42577
   286
   hypothesis_kind = Conjecture,
blanchet@42578
   287
   formats = [Fof],
blanchet@42578
   288
   best_slices =
blanchet@42578
   289
     K [(0.66667, (false, 450 (* FUDGE *))) (* with SOS *),
blanchet@42578
   290
        (0.33333, (true, 450 (* FUDGE *))) (* without SOS *)],
blanchet@42578
   291
   best_type_systems = []}
blanchet@38454
   292
blanchet@40059
   293
val vampire = (vampireN, vampire_config)
blanchet@37509
   294
blanchet@38454
   295
blanchet@41740
   296
(* Z3 with TPTP syntax *)
blanchet@41740
   297
blanchet@41740
   298
val z3_atp_config : atp_config =
blanchet@41740
   299
  {exec = ("Z3_HOME", "z3"),
blanchet@41740
   300
   required_execs = [],
blanchet@41740
   301
   arguments = fn _ => fn timeout => fn _ =>
blanchet@41766
   302
     "MBQI=true -p -t:" ^ string_of_int (to_secs 0 timeout),
blanchet@41740
   303
   proof_delims = [],
blanchet@41740
   304
   known_failures =
blanchet@41742
   305
     [(Unprovable, "\nsat"),
blanchet@41742
   306
      (IncompleteUnprovable, "\nunknown"),
blanchet@42443
   307
      (IncompleteUnprovable, "SZS status Satisfiable"),
blanchet@42443
   308
      (ProofMissing, "\nunsat"),
blanchet@42443
   309
      (ProofMissing, "SZS status Unsatisfiable")],
blanchet@42577
   310
   hypothesis_kind = Hypothesis,
blanchet@42578
   311
   formats = [Fof],
blanchet@42578
   312
   best_slices = K [(1.0, (false, 250 (* FUDGE *)))],
blanchet@42578
   313
   best_type_systems = []}
blanchet@41740
   314
blanchet@41740
   315
val z3_atp = (z3_atpN, z3_atp_config)
blanchet@41740
   316
blanchet@41740
   317
blanchet@40059
   318
(* Remote ATP invocation via SystemOnTPTP *)
wenzelm@28596
   319
blanchet@38061
   320
val systems = Synchronized.var "atp_systems" ([] : string list)
immler@31835
   321
immler@31835
   322
fun get_systems () =
blanchet@38061
   323
  case bash_output "\"$ISABELLE_ATP/scripts/remote_atp\" -w 2>&1" of
blanchet@39491
   324
    (output, 0) => split_lines output
blanchet@39491
   325
  | (output, _) =>
blanchet@39491
   326
    error (case extract_known_failure known_perl_failures output of
blanchet@41744
   327
             SOME failure => string_for_failure failure
blanchet@39491
   328
           | NONE => perhaps (try (unsuffix "\n")) output ^ ".")
immler@31835
   329
blanchet@42537
   330
fun find_system name [] systems =
blanchet@42537
   331
    find_first (String.isPrefix (name ^ "---")) systems
blanchet@38690
   332
  | find_system name (version :: versions) systems =
blanchet@38690
   333
    case find_first (String.isPrefix (name ^ "---" ^ version)) systems of
blanchet@38690
   334
      NONE => find_system name versions systems
blanchet@38690
   335
    | res => res
blanchet@38690
   336
blanchet@38690
   337
fun get_system name versions =
blanchet@38589
   338
  Synchronized.change_result systems
blanchet@38589
   339
      (fn systems => (if null systems then get_systems () else systems)
blanchet@38690
   340
                     |> `(find_system name versions))
boehmes@32864
   341
blanchet@38690
   342
fun the_system name versions =
blanchet@38690
   343
  case get_system name versions of
blanchet@39010
   344
    SOME sys => sys
blanchet@41269
   345
  | NONE => error ("System " ^ quote name ^
blanchet@41269
   346
                   " is not available at SystemOnTPTP.")
immler@31835
   347
blanchet@41148
   348
val max_remote_secs = 240 (* give Geoff Sutcliffe's servers a break *)
blanchet@41148
   349
blanchet@38690
   350
fun remote_config system_name system_versions proof_delims known_failures
blanchet@42578
   351
                  hypothesis_kind formats best_max_relevant best_type_systems
blanchet@42578
   352
                  : atp_config =
blanchet@38092
   353
  {exec = ("ISABELLE_ATP", "scripts/remote_atp"),
blanchet@38092
   354
   required_execs = [],
blanchet@41313
   355
   arguments = fn _ => fn timeout => fn _ =>
blanchet@41148
   356
     " -t " ^ string_of_int (Int.min (max_remote_secs, (to_secs 0 timeout)))
blanchet@41148
   357
     ^ " -s " ^ the_system system_name system_versions,
blanchet@36369
   358
   proof_delims = insert (op =) tstp_proof_delims proof_delims,
blanchet@38061
   359
   known_failures =
blanchet@38061
   360
     known_failures @ known_perl_failures @
blanchet@42571
   361
     [(IncompleteUnprovable, "says Unknown"),
blanchet@42584
   362
      (IncompleteUnprovable, "says GaveUp"),
blanchet@42571
   363
      (TimedOut, "says Timeout")],
blanchet@42577
   364
   hypothesis_kind = hypothesis_kind,
blanchet@42578
   365
   formats = formats,
blanchet@42578
   366
   best_slices = fn () => [(1.0, (false, best_max_relevant ()))],
blanchet@42578
   367
   best_type_systems = best_type_systems}
wenzelm@28596
   368
blanchet@42443
   369
fun int_average f xs = fold (Integer.add o f) xs 0 div length xs
blanchet@42443
   370
blanchet@38690
   371
fun remotify_config system_name system_versions
blanchet@42578
   372
                    ({proof_delims, known_failures, hypothesis_kind, formats,
blanchet@42578
   373
                      best_slices, best_type_systems, ...} : atp_config)
blanchet@42578
   374
                    : atp_config =
blanchet@38690
   375
  remote_config system_name system_versions proof_delims known_failures
blanchet@42578
   376
                hypothesis_kind formats
blanchet@42578
   377
                (int_average (snd o snd) o best_slices) best_type_systems
blanchet@38023
   378
blanchet@40059
   379
fun remote_atp name system_name system_versions proof_delims known_failures
blanchet@42578
   380
               hypothesis_kind formats best_max_relevant best_type_systems =
blanchet@40060
   381
  (remote_prefix ^ name,
blanchet@38690
   382
   remote_config system_name system_versions proof_delims known_failures
blanchet@42578
   383
                 hypothesis_kind formats best_max_relevant best_type_systems)
blanchet@40059
   384
fun remotify_atp (name, config) system_name system_versions =
blanchet@40060
   385
  (remote_prefix ^ name, remotify_config system_name system_versions config)
wenzelm@28592
   386
blanchet@40059
   387
val remote_e = remotify_atp e "EP" ["1.0", "1.1", "1.2"]
blanchet@40059
   388
val remote_vampire = remotify_atp vampire "Vampire" ["0.6", "9.0", "1.0"]
blanchet@42537
   389
val remote_z3_atp = remotify_atp z3_atp "Z3" ["2.18"]
blanchet@42535
   390
val remote_tofof_e =
blanchet@42559
   391
  remote_atp tofof_eN "ToFoF" ["0.1"] [] (#known_failures e_config)
blanchet@42578
   392
             Conjecture [Tff] (K 200 (* FUDGE *)) []
blanchet@41740
   393
val remote_sine_e =
blanchet@42578
   394
  remote_atp sine_eN "SInE" ["0.4"] [] [] Conjecture [Fof] (K 500 (* FUDGE *))
blanchet@42578
   395
                     []
blanchet@41740
   396
val remote_snark =
blanchet@42537
   397
  remote_atp snarkN "SNARK" ["20080805r024"]
blanchet@42578
   398
             [("refutation.", "end_refutation.")] [] Conjecture [Tff, Fof]
blanchet@42578
   399
             (K 250 (* FUDGE *)) []
blanchet@38454
   400
blanchet@38454
   401
(* Setup *)
blanchet@38454
   402
blanchet@40059
   403
fun add_atp (name, config) thy =
blanchet@40059
   404
  Data.map (Symtab.update_new (name, (config, stamp ()))) thy
blanchet@40059
   405
  handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@40059
   406
blanchet@40059
   407
fun get_atp thy name =
blanchet@40059
   408
  the (Symtab.lookup (Data.get thy) name) |> fst
blanchet@40059
   409
  handle Option.Option => error ("Unknown ATP: " ^ name ^ ".")
blanchet@40059
   410
blanchet@41727
   411
val supported_atps = Symtab.keys o Data.get
blanchet@36371
   412
blanchet@40059
   413
fun is_atp_installed thy name =
blanchet@40059
   414
  let val {exec, required_execs, ...} = get_atp thy name in
blanchet@40059
   415
    forall (curry (op <>) "" o getenv o fst) (exec :: required_execs)
blanchet@40059
   416
  end
blanchet@36371
   417
blanchet@40059
   418
fun refresh_systems_on_tptp () =
blanchet@40059
   419
  Synchronized.change systems (fn _ => get_systems ())
blanchet@40059
   420
blanchet@41740
   421
val atps = [e, spass, vampire, z3_atp, remote_e, remote_vampire, remote_z3_atp,
blanchet@42535
   422
            remote_tofof_e, remote_sine_e, remote_snark]
blanchet@40059
   423
val setup = fold add_atp atps
blanchet@35867
   424
wenzelm@28592
   425
end;