src/HOL/Tools/ATP/atp_systems.ML
author blanchet
Mon Aug 22 15:02:45 2011 +0200 (2011-08-22)
changeset 44391 7b4104df2be6
parent 44235 85e9dad3c187
child 44416 cabd06b69c18
permissions -rw-r--r--
gracefully handle empty SPASS problems
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@40059
    14
  type atp_config =
blanchet@42578
    15
    {exec : string * string,
blanchet@42578
    16
     required_execs : (string * string) list,
blanchet@42646
    17
     arguments :
blanchet@43473
    18
       Proof.context -> bool -> string -> Time.time
blanchet@43354
    19
       -> (unit -> (string * real) list) -> string,
blanchet@42578
    20
     proof_delims : (string * string) list,
blanchet@42578
    21
     known_failures : (failure * string) list,
blanchet@42709
    22
     conj_sym_kind : formula_kind,
blanchet@42709
    23
     prem_kind : formula_kind,
blanchet@42578
    24
     formats : format list,
blanchet@43473
    25
     best_slices :
blanchet@43569
    26
       Proof.context -> (real * (bool * (int * string * string))) list}
blanchet@38023
    27
blanchet@44099
    28
  val force_sos : bool Config.T
blanchet@43566
    29
  val e_smartN : string
blanchet@43566
    30
  val e_autoN : string
blanchet@43566
    31
  val e_fun_weightN : string
blanchet@43566
    32
  val e_sym_offset_weightN : string
blanchet@42646
    33
  val e_weight_method : string Config.T
blanchet@42646
    34
  val e_default_fun_weight : real Config.T
blanchet@42646
    35
  val e_fun_weight_base : real Config.T
blanchet@42646
    36
  val e_fun_weight_span : real Config.T
blanchet@42646
    37
  val e_default_sym_offs_weight : real Config.T
blanchet@42646
    38
  val e_sym_offs_weight_base : real Config.T
blanchet@42646
    39
  val e_sym_offs_weight_span : real Config.T
blanchet@40059
    40
  val eN : string
blanchet@40059
    41
  val spassN : string
blanchet@40059
    42
  val vampireN : string
blanchet@42962
    43
  val leo2N : string
blanchet@42962
    44
  val satallaxN : string
blanchet@44092
    45
  val e_sineN : string
blanchet@40059
    46
  val snarkN : string
blanchet@44092
    47
  val e_tofofN : string
blanchet@42938
    48
  val waldmeisterN : string
blanchet@41738
    49
  val z3_atpN : string
blanchet@40060
    50
  val remote_prefix : string
blanchet@41738
    51
  val remote_atp :
blanchet@41738
    52
    string -> string -> string list -> (string * string) list
blanchet@42709
    53
    -> (failure * string) list -> formula_kind -> formula_kind -> format list
blanchet@43569
    54
    -> (Proof.context -> int * string) -> string * atp_config
blanchet@40059
    55
  val add_atp : string * atp_config -> theory -> theory
blanchet@40059
    56
  val get_atp : theory -> string -> atp_config
blanchet@41727
    57
  val supported_atps : theory -> string list
blanchet@40059
    58
  val is_atp_installed : theory -> string -> bool
blanchet@35867
    59
  val refresh_systems_on_tptp : unit -> unit
blanchet@35867
    60
  val setup : theory -> theory
wenzelm@28592
    61
end;
wenzelm@28592
    62
blanchet@36376
    63
structure ATP_Systems : ATP_SYSTEMS =
wenzelm@28592
    64
struct
wenzelm@28596
    65
blanchet@42577
    66
open ATP_Problem
blanchet@39491
    67
open ATP_Proof
boehmes@32864
    68
blanchet@40059
    69
(* ATP configuration *)
boehmes@32864
    70
blanchet@40059
    71
type atp_config =
blanchet@42578
    72
  {exec : string * string,
blanchet@42578
    73
   required_execs : (string * string) list,
blanchet@42646
    74
   arguments :
blanchet@43473
    75
     Proof.context -> bool -> string -> Time.time
blanchet@43473
    76
     -> (unit -> (string * real) list) -> string,
blanchet@42578
    77
   proof_delims : (string * string) list,
blanchet@42578
    78
   known_failures : (failure * string) list,
blanchet@42709
    79
   conj_sym_kind : formula_kind,
blanchet@42709
    80
   prem_kind : formula_kind,
blanchet@42578
    81
   formats : format list,
blanchet@43473
    82
   best_slices :
blanchet@43569
    83
     Proof.context -> (real * (bool * (int * string * string))) list}
wenzelm@28596
    84
blanchet@42723
    85
(* "best_slices" must be found empirically, taking a wholistic approach since
blanchet@42723
    86
   the ATPs are run in parallel. The "real" components give the faction of the
blanchet@43569
    87
   time available given to the slice and should add up to 1.0. The "bool"
blanchet@42723
    88
   component indicates whether the slice's strategy is complete; the "int", the
blanchet@43569
    89
   preferred number of facts to pass; the first "string", the preferred type
blanchet@43575
    90
   system (which should be sound or quasi-sound); the second "string", extra
blanchet@43575
    91
   information to the prover (e.g., SOS or no SOS).
blanchet@42723
    92
blanchet@42723
    93
   The last slice should be the most "normal" one, because it will get all the
blanchet@43569
    94
   time available if the other slices fail early and also because it is used if
blanchet@43569
    95
   slicing is disabled (e.g., by the minimizer). *)
blanchet@42710
    96
blanchet@38061
    97
val known_perl_failures =
blanchet@38094
    98
  [(CantConnect, "HTTP error"),
blanchet@38094
    99
   (NoPerl, "env: perl"),
blanchet@38065
   100
   (NoLibwwwPerl, "Can't locate HTTP")]
wenzelm@28596
   101
blanchet@40059
   102
(* named ATPs *)
blanchet@40059
   103
blanchet@40059
   104
val eN = "e"
blanchet@44099
   105
val leo2N = "leo2"
blanchet@44099
   106
val satallaxN = "satallax"
blanchet@40059
   107
val spassN = "spass"
blanchet@40059
   108
val vampireN = "vampire"
blanchet@41740
   109
val z3_atpN = "z3_atp"
blanchet@44092
   110
val e_sineN = "e_sine"
blanchet@40059
   111
val snarkN = "snark"
blanchet@44092
   112
val e_tofofN = "e_tofof"
blanchet@42938
   113
val waldmeisterN = "waldmeister"
blanchet@40060
   114
val remote_prefix = "remote_"
blanchet@38001
   115
blanchet@38023
   116
structure Data = Theory_Data
blanchet@38023
   117
(
blanchet@40059
   118
  type T = (atp_config * stamp) Symtab.table
blanchet@38023
   119
  val empty = Symtab.empty
blanchet@38023
   120
  val extend = I
blanchet@38023
   121
  fun merge data : T = Symtab.merge (eq_snd op =) data
blanchet@38023
   122
    handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@38023
   123
)
blanchet@38017
   124
blanchet@43981
   125
fun to_secs min time = Int.max (min, (Time.toMilliseconds time + 999) div 1000)
blanchet@36142
   126
blanchet@43473
   127
val sosN = "sos"
blanchet@43473
   128
val no_sosN = "no_sos"
blanchet@43473
   129
blanchet@44099
   130
val force_sos = Attrib.setup_config_bool @{binding atp_force_sos} (K false)
blanchet@44099
   131
blanchet@39491
   132
blanchet@40059
   133
(* E *)
wenzelm@28596
   134
blanchet@36369
   135
val tstp_proof_delims =
blanchet@42962
   136
  [("# SZS output start CNFRefutation.", "# SZS output end CNFRefutation"),
blanchet@42962
   137
   ("% SZS output start CNFRefutation", "% SZS output end CNFRefutation")]
blanchet@36369
   138
blanchet@43473
   139
val e_smartN = "smart"
blanchet@42646
   140
val e_autoN = "auto"
blanchet@42646
   141
val e_fun_weightN = "fun_weight"
blanchet@42646
   142
val e_sym_offset_weightN = "sym_offset_weight"
blanchet@41725
   143
blanchet@42646
   144
val e_weight_method =
blanchet@43473
   145
  Attrib.setup_config_string @{binding atp_e_weight_method} (K e_smartN)
blanchet@41770
   146
(* FUDGE *)
blanchet@42646
   147
val e_default_fun_weight =
blanchet@42646
   148
  Attrib.setup_config_real @{binding atp_e_default_fun_weight} (K 20.0)
blanchet@42646
   149
val e_fun_weight_base =
blanchet@42646
   150
  Attrib.setup_config_real @{binding atp_e_fun_weight_base} (K 0.0)
blanchet@42646
   151
val e_fun_weight_span =
blanchet@42646
   152
  Attrib.setup_config_real @{binding atp_e_fun_weight_span} (K 40.0)
blanchet@42646
   153
val e_default_sym_offs_weight =
blanchet@42646
   154
  Attrib.setup_config_real @{binding atp_e_default_sym_offs_weight} (K 1.0)
blanchet@42646
   155
val e_sym_offs_weight_base =
blanchet@42646
   156
  Attrib.setup_config_real @{binding atp_e_sym_offs_weight_base} (K ~20.0)
blanchet@42646
   157
val e_sym_offs_weight_span =
blanchet@42646
   158
  Attrib.setup_config_real @{binding atp_e_sym_offs_weight_span} (K 60.0)
blanchet@41725
   159
blanchet@42443
   160
fun e_weight_method_case method fw sow =
blanchet@42646
   161
  if method = e_fun_weightN then fw
blanchet@42646
   162
  else if method = e_sym_offset_weightN then sow
blanchet@43478
   163
  else raise Fail ("unexpected " ^ quote method)
blanchet@41725
   164
blanchet@42646
   165
fun scaled_e_weight ctxt method w =
blanchet@42646
   166
  w * Config.get ctxt
blanchet@42646
   167
          (e_weight_method_case method e_fun_weight_span e_sym_offs_weight_span)
blanchet@42646
   168
  + Config.get ctxt
blanchet@42646
   169
        (e_weight_method_case method e_fun_weight_base e_sym_offs_weight_base)
blanchet@41725
   170
  |> Real.ceil |> signed_string_of_int
blanchet@41313
   171
blanchet@42646
   172
fun e_weight_arguments ctxt method weights =
blanchet@42646
   173
  if method = e_autoN then
blanchet@41725
   174
    "-xAutoDev"
blanchet@41725
   175
  else
blanchet@43622
   176
    (* supplied by Stephan Schulz *)
blanchet@41314
   177
    "--split-clauses=4 --split-reuse-defs --simul-paramod --forward-context-sr \
blanchet@41314
   178
    \--destructive-er-aggressive --destructive-er --presat-simplify \
blanchet@41314
   179
    \--prefer-initial-clauses -tKBO6 -winvfreqrank -c1 -Ginvfreqconjmax -F1 \
blanchet@41314
   180
    \--delete-bad-limit=150000000 -WSelectMaxLComplexAvoidPosPred \
blanchet@42443
   181
    \-H'(4*" ^ e_weight_method_case method "FunWeight" "SymOffsetWeight" ^
blanchet@41725
   182
    "(SimulateSOS, " ^
blanchet@42646
   183
    (e_weight_method_case method e_default_fun_weight e_default_sym_offs_weight
blanchet@42646
   184
     |> Config.get ctxt |> Real.ceil |> signed_string_of_int) ^
blanchet@41314
   185
    ",20,1.5,1.5,1" ^
blanchet@42646
   186
    (weights ()
blanchet@42646
   187
     |> map (fn (s, w) => "," ^ s ^ ":" ^ scaled_e_weight ctxt method w)
blanchet@42646
   188
     |> implode) ^
blanchet@41314
   189
    "),3*ConjectureGeneralSymbolWeight(PreferNonGoals,200,100,200,50,50,1,100,\
blanchet@41314
   190
    \1.5,1.5,1),1*Clauseweight(PreferProcessed,1,1,1),1*\
blanchet@41314
   191
    \FIFOWeight(PreferProcessed))'"
blanchet@41313
   192
blanchet@42443
   193
fun is_old_e_version () = (string_ord (getenv "E_VERSION", "1.2w") = LESS)
blanchet@42443
   194
blanchet@42646
   195
fun effective_e_weight_method ctxt =
blanchet@42646
   196
  if is_old_e_version () then e_autoN else Config.get ctxt e_weight_method
blanchet@42443
   197
blanchet@40059
   198
val e_config : atp_config =
blanchet@38092
   199
  {exec = ("E_HOME", "eproof"),
blanchet@38092
   200
   required_execs = [],
blanchet@43354
   201
   arguments =
blanchet@43567
   202
     fn ctxt => fn _ => fn method => fn timeout => fn weights =>
blanchet@43473
   203
        "--tstp-in --tstp-out -l5 " ^ e_weight_arguments ctxt method weights ^
blanchet@43981
   204
        " -tAutoDev --silent --cpu-limit=" ^ string_of_int (to_secs 2 timeout),
blanchet@42962
   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@42844
   209
      (ProofMissing, "SZS status Theorem"),
blanchet@36370
   210
      (TimedOut, "Failure: Resource limit exceeded (time)"),
blanchet@36370
   211
      (TimedOut, "time limit exceeded"),
blanchet@43467
   212
      (OutOfResources, "# Cannot determine problem status"),
blanchet@36370
   213
      (OutOfResources, "SZS status: ResourceOut"),
blanchet@36370
   214
      (OutOfResources, "SZS status ResourceOut")],
blanchet@43466
   215
   conj_sym_kind = Hypothesis,
blanchet@42709
   216
   prem_kind = Conjecture,
blanchet@42937
   217
   formats = [FOF],
blanchet@42646
   218
   best_slices = fn ctxt =>
blanchet@43473
   219
     let val method = effective_e_weight_method ctxt in
blanchet@43474
   220
       (* FUDGE *)
blanchet@43473
   221
       if method = e_smartN then
blanchet@43569
   222
         [(0.333, (true, (500, "mangled_tags?", e_fun_weightN))),
blanchet@43989
   223
          (0.334, (true, (50, "mangled_guards?", e_fun_weightN))),
blanchet@43569
   224
          (0.333, (true, (1000, "mangled_tags?", e_sym_offset_weightN)))]
blanchet@43473
   225
       else
blanchet@43569
   226
         [(1.0, (true, (500, "mangled_tags?", method)))]
blanchet@43473
   227
     end}
blanchet@38454
   228
blanchet@40059
   229
val e = (eN, e_config)
wenzelm@28596
   230
wenzelm@28596
   231
blanchet@44099
   232
(* LEO-II *)
blanchet@44099
   233
blanchet@44099
   234
val leo2_config : atp_config =
blanchet@44099
   235
  {exec = ("LEO2_HOME", "leo"),
blanchet@44099
   236
   required_execs = [],
blanchet@44099
   237
   arguments =
blanchet@44099
   238
     fn _ => fn _ => fn sos => fn timeout => fn _ =>
blanchet@44099
   239
        "--proofoutput --timeout " ^ string_of_int (to_secs 1 timeout)
blanchet@44099
   240
        |> sos = sosN ? prefix "--sos ",
blanchet@44099
   241
   proof_delims = tstp_proof_delims,
blanchet@44099
   242
   known_failures = [],
blanchet@44099
   243
   conj_sym_kind = Axiom,
blanchet@44099
   244
   prem_kind = Hypothesis,
blanchet@44235
   245
   formats = [THF Without_Choice, FOF],
blanchet@44099
   246
   best_slices = fn ctxt =>
blanchet@44099
   247
     (* FUDGE *)
blanchet@44099
   248
     [(0.667, (false, (150, "simple_higher", sosN))),
blanchet@44099
   249
      (0.333, (true, (50, "simple_higher", no_sosN)))]
blanchet@44099
   250
     |> (if Config.get ctxt force_sos then hd #> apfst (K 1.0) #> single
blanchet@44099
   251
         else I)}
blanchet@39491
   252
blanchet@44099
   253
val leo2 = (leo2N, leo2_config)
blanchet@44099
   254
blanchet@44099
   255
blanchet@44099
   256
(* Satallax *)
blanchet@44099
   257
blanchet@44099
   258
val satallax_config : atp_config =
blanchet@44099
   259
  {exec = ("SATALLAX_HOME", "satallax"),
blanchet@44099
   260
   required_execs = [],
blanchet@44099
   261
   arguments =
blanchet@44099
   262
     fn _ => fn _ => fn _ => fn timeout => fn _ =>
blanchet@44099
   263
        "-t " ^ string_of_int (to_secs 1 timeout),
blanchet@44099
   264
   proof_delims = tstp_proof_delims,
blanchet@44099
   265
   known_failures = [(ProofMissing, "SZS status Theorem")],
blanchet@44099
   266
   conj_sym_kind = Axiom,
blanchet@44099
   267
   prem_kind = Hypothesis,
blanchet@44235
   268
   formats = [THF With_Choice],
blanchet@44099
   269
   best_slices = K [(1.0, (true, (100, "simple_higher", "")))] (* FUDGE *)}
blanchet@44099
   270
blanchet@44099
   271
val satallax = (satallaxN, satallax_config)
blanchet@44099
   272
blanchet@44099
   273
blanchet@44099
   274
(* SPASS *)
blanchet@42725
   275
blanchet@36219
   276
(* The "-VarWeight=3" option helps the higher-order problems, probably by
blanchet@36219
   277
   counteracting the presence of "hAPP". *)
blanchet@40059
   278
val spass_config : atp_config =
blanchet@38092
   279
  {exec = ("ISABELLE_ATP", "scripts/spass"),
blanchet@39002
   280
   required_execs = [("SPASS_HOME", "SPASS"), ("SPASS_HOME", "tptp2dfg")],
blanchet@43569
   281
   arguments = fn _ => fn _ => fn sos => fn timeout => fn _ =>
blanchet@37962
   282
     ("-Auto -PGiven=0 -PProblem=0 -Splits=0 -FullRed=0 -DocProof \
blanchet@43981
   283
      \-VarWeight=3 -TimeLimit=" ^ string_of_int (to_secs 1 timeout))
blanchet@43473
   284
     |> sos = sosN ? prefix "-SOS=1 ",
blanchet@36369
   285
   proof_delims = [("Here is a proof", "Formulae used in the proof")],
blanchet@36289
   286
   known_failures =
blanchet@38061
   287
     known_perl_failures @
blanchet@43050
   288
     [(GaveUp, "SPASS beiseite: Completion found"),
blanchet@36370
   289
      (TimedOut, "SPASS beiseite: Ran out of time"),
blanchet@36965
   290
      (OutOfResources, "SPASS beiseite: Maximal number of loops exceeded"),
blanchet@37413
   291
      (MalformedInput, "Undefined symbol"),
blanchet@37414
   292
      (MalformedInput, "Free Variable"),
blanchet@44391
   293
      (Unprovable, "No formulae and clauses found in input file"),
blanchet@39263
   294
      (SpassTooOld, "tptp2dfg"),
blanchet@39263
   295
      (InternalError, "Please report this error")],
blanchet@43466
   296
   conj_sym_kind = Hypothesis,
blanchet@42709
   297
   prem_kind = Conjecture,
blanchet@42937
   298
   formats = [FOF],
blanchet@42725
   299
   best_slices = fn ctxt =>
blanchet@42723
   300
     (* FUDGE *)
blanchet@43569
   301
     [(0.333, (false, (150, "mangled_tags", sosN))),
blanchet@43569
   302
      (0.333, (false, (300, "poly_tags?", sosN))),
blanchet@43569
   303
      (0.334, (true, (50, "mangled_tags?", no_sosN)))]
blanchet@44099
   304
     |> (if Config.get ctxt force_sos then hd #> apfst (K 1.0) #> single
blanchet@42725
   305
         else I)}
blanchet@38454
   306
blanchet@40059
   307
val spass = (spassN, spass_config)
wenzelm@28596
   308
blanchet@38454
   309
blanchet@37509
   310
(* Vampire *)
blanchet@37509
   311
blanchet@40059
   312
val vampire_config : atp_config =
blanchet@38092
   313
  {exec = ("VAMPIRE_HOME", "vampire"),
blanchet@38092
   314
   required_execs = [],
blanchet@43569
   315
   arguments = fn _ => fn _ => fn sos => fn timeout => fn _ =>
blanchet@43981
   316
     "--proof tptp --mode casc -t " ^ string_of_int (to_secs 1 timeout) ^
blanchet@41203
   317
     " --thanks \"Andrei and Krystof\" --input_file"
blanchet@43473
   318
     |> sos = sosN ? prefix "--sos on ",
blanchet@37509
   319
   proof_delims =
blanchet@37509
   320
     [("=========== Refutation ==========",
blanchet@37509
   321
       "======= End of refutation ======="),
blanchet@38033
   322
      ("% SZS output start Refutation", "% SZS output end Refutation"),
blanchet@38033
   323
      ("% SZS output start Proof", "% SZS output end Proof")],
blanchet@37509
   324
   known_failures =
blanchet@43050
   325
     [(GaveUp, "UNPROVABLE"),
blanchet@43050
   326
      (GaveUp, "CANNOT PROVE"),
blanchet@43050
   327
      (GaveUp, "SZS status GaveUp"),
blanchet@42882
   328
      (ProofIncomplete, "predicate_definition_introduction,[]"),
blanchet@38092
   329
      (TimedOut, "SZS status Timeout"),
blanchet@37509
   330
      (Unprovable, "Satisfiability detected"),
blanchet@38647
   331
      (Unprovable, "Termination reason: Satisfiable"),
blanchet@39263
   332
      (VampireTooOld, "not a valid option"),
blanchet@39263
   333
      (Interrupted, "Aborted by signal SIGINT")],
blanchet@43466
   334
   conj_sym_kind = Conjecture,
blanchet@42709
   335
   prem_kind = Conjecture,
blanchet@42937
   336
   formats = [FOF],
blanchet@42725
   337
   best_slices = fn ctxt =>
blanchet@42723
   338
     (* FUDGE *)
blanchet@43989
   339
     [(0.333, (false, (150, "poly_guards", sosN))),
blanchet@43989
   340
      (0.334, (true, (50, "mangled_guards?", no_sosN))),
blanchet@43569
   341
      (0.333, (false, (500, "mangled_tags?", sosN)))]
blanchet@44099
   342
     |> (if Config.get ctxt force_sos then hd #> apfst (K 1.0) #> single
blanchet@42725
   343
         else I)}
blanchet@38454
   344
blanchet@40059
   345
val vampire = (vampireN, vampire_config)
blanchet@37509
   346
blanchet@38454
   347
blanchet@41740
   348
(* Z3 with TPTP syntax *)
blanchet@41740
   349
blanchet@41740
   350
val z3_atp_config : atp_config =
blanchet@41740
   351
  {exec = ("Z3_HOME", "z3"),
blanchet@41740
   352
   required_execs = [],
blanchet@43354
   353
   arguments = fn _ => fn _ => fn _ => fn timeout => fn _ =>
blanchet@43981
   354
     "MBQI=true -p -t:" ^ string_of_int (to_secs 1 timeout),
blanchet@41740
   355
   proof_delims = [],
blanchet@41740
   356
   known_failures =
blanchet@41742
   357
     [(Unprovable, "\nsat"),
blanchet@43050
   358
      (GaveUp, "\nunknown"),
blanchet@43050
   359
      (GaveUp, "SZS status Satisfiable"),
blanchet@42443
   360
      (ProofMissing, "\nunsat"),
blanchet@42443
   361
      (ProofMissing, "SZS status Unsatisfiable")],
blanchet@42709
   362
   conj_sym_kind = Hypothesis,
blanchet@42709
   363
   prem_kind = Hypothesis,
blanchet@42937
   364
   formats = [FOF],
blanchet@42723
   365
   best_slices =
blanchet@42723
   366
     (* FUDGE (FIXME) *)
blanchet@43989
   367
     K [(0.5, (false, (250, "mangled_guards?", ""))),
blanchet@43989
   368
        (0.25, (false, (125, "mangled_guards?", ""))),
blanchet@43989
   369
        (0.125, (false, (62, "mangled_guards?", ""))),
blanchet@43989
   370
        (0.125, (false, (31, "mangled_guards?", "")))]}
blanchet@41740
   371
blanchet@41740
   372
val z3_atp = (z3_atpN, z3_atp_config)
blanchet@41740
   373
blanchet@41740
   374
blanchet@40059
   375
(* Remote ATP invocation via SystemOnTPTP *)
wenzelm@28596
   376
blanchet@38061
   377
val systems = Synchronized.var "atp_systems" ([] : string list)
immler@31835
   378
immler@31835
   379
fun get_systems () =
wenzelm@43850
   380
  case Isabelle_System.bash_output "\"$ISABELLE_ATP/scripts/remote_atp\" -w 2>&1" of
blanchet@39491
   381
    (output, 0) => split_lines output
blanchet@39491
   382
  | (output, _) =>
blanchet@39491
   383
    error (case extract_known_failure known_perl_failures output of
blanchet@41744
   384
             SOME failure => string_for_failure failure
blanchet@39491
   385
           | NONE => perhaps (try (unsuffix "\n")) output ^ ".")
immler@31835
   386
blanchet@42537
   387
fun find_system name [] systems =
blanchet@42537
   388
    find_first (String.isPrefix (name ^ "---")) systems
blanchet@38690
   389
  | find_system name (version :: versions) systems =
blanchet@38690
   390
    case find_first (String.isPrefix (name ^ "---" ^ version)) systems of
blanchet@38690
   391
      NONE => find_system name versions systems
blanchet@38690
   392
    | res => res
blanchet@38690
   393
blanchet@38690
   394
fun get_system name versions =
blanchet@38589
   395
  Synchronized.change_result systems
blanchet@38589
   396
      (fn systems => (if null systems then get_systems () else systems)
blanchet@42955
   397
                     |> `(`(find_system name versions)))
boehmes@32864
   398
blanchet@38690
   399
fun the_system name versions =
blanchet@38690
   400
  case get_system name versions of
blanchet@42955
   401
    (SOME sys, _) => sys
blanchet@42955
   402
  | (NONE, []) => error ("SystemOnTPTP is currently not available.")
blanchet@42955
   403
  | (NONE, syss) =>
blanchet@42955
   404
    error ("System " ^ quote name ^ " is not available at SystemOnTPTP.\n" ^
blanchet@42955
   405
           "(Available systems: " ^ commas_quote syss ^ ".)")
immler@31835
   406
blanchet@41148
   407
val max_remote_secs = 240 (* give Geoff Sutcliffe's servers a break *)
blanchet@41148
   408
blanchet@38690
   409
fun remote_config system_name system_versions proof_delims known_failures
blanchet@42723
   410
                  conj_sym_kind prem_kind formats best_slice : atp_config =
blanchet@38092
   411
  {exec = ("ISABELLE_ATP", "scripts/remote_atp"),
blanchet@38092
   412
   required_execs = [],
blanchet@43354
   413
   arguments = fn _ => fn _ => fn _ => fn timeout => fn _ =>
blanchet@43981
   414
     "-t " ^ string_of_int (Int.min (max_remote_secs, to_secs 1 timeout))
blanchet@41148
   415
     ^ " -s " ^ the_system system_name system_versions,
blanchet@42962
   416
   proof_delims = union (op =) tstp_proof_delims proof_delims,
blanchet@42965
   417
   known_failures = known_failures @ known_perl_failures @
blanchet@42941
   418
     [(Unprovable, "says Satisfiable"),
blanchet@42999
   419
      (Unprovable, "says CounterSatisfiable"),
blanchet@43050
   420
      (GaveUp, "says Unknown"),
blanchet@43050
   421
      (GaveUp, "says GaveUp"),
blanchet@42965
   422
      (ProofMissing, "says Theorem"),
blanchet@42999
   423
      (ProofMissing, "says Unsatisfiable"),
blanchet@42953
   424
      (TimedOut, "says Timeout"),
blanchet@42953
   425
      (Inappropriate, "says Inappropriate")],
blanchet@42709
   426
   conj_sym_kind = conj_sym_kind,
blanchet@42709
   427
   prem_kind = prem_kind,
blanchet@42578
   428
   formats = formats,
blanchet@43473
   429
   best_slices = fn ctxt =>
blanchet@43626
   430
     let val (max_relevant, type_enc) = best_slice ctxt in
blanchet@43626
   431
       [(1.0, (false, (max_relevant, type_enc, "")))]
blanchet@43473
   432
     end}
blanchet@42443
   433
blanchet@43500
   434
fun remotify_config system_name system_versions best_slice
blanchet@43500
   435
        ({proof_delims, known_failures, conj_sym_kind, prem_kind, formats, ...}
blanchet@43500
   436
         : atp_config) : atp_config =
blanchet@38690
   437
  remote_config system_name system_versions proof_delims known_failures
blanchet@43500
   438
                conj_sym_kind prem_kind formats best_slice
blanchet@38023
   439
blanchet@40059
   440
fun remote_atp name system_name system_versions proof_delims known_failures
blanchet@42723
   441
        conj_sym_kind prem_kind formats best_slice =
blanchet@40060
   442
  (remote_prefix ^ name,
blanchet@38690
   443
   remote_config system_name system_versions proof_delims known_failures
blanchet@42723
   444
                 conj_sym_kind prem_kind formats best_slice)
blanchet@43500
   445
fun remotify_atp (name, config) system_name system_versions best_slice =
blanchet@43500
   446
  (remote_prefix ^ name,
blanchet@43500
   447
   remotify_config system_name system_versions best_slice config)
wenzelm@28592
   448
blanchet@43500
   449
val remote_e =
blanchet@43500
   450
  remotify_atp e "EP" ["1.0", "1.1", "1.2"]
blanchet@43569
   451
               (K (750, "mangled_tags?") (* FUDGE *))
blanchet@44099
   452
val remote_leo2 =
blanchet@44099
   453
  remotify_atp leo2 "LEO-II" ["1.2.8", "1.2.6"]
blanchet@44099
   454
               (K (100, "simple_higher") (* FUDGE *))
blanchet@44099
   455
val remote_satallax =
blanchet@44099
   456
  remotify_atp satallax "Satallax" ["2.1", "2.0", "2"]
blanchet@44099
   457
               (K (100, "simple_higher") (* FUDGE *))
blanchet@43500
   458
val remote_vampire =
blanchet@43500
   459
  remotify_atp vampire "Vampire" ["0.6", "9.0", "1.0"]
blanchet@43989
   460
               (K (200, "mangled_guards?") (* FUDGE *))
blanchet@43500
   461
val remote_z3_atp =
blanchet@43989
   462
  remotify_atp z3_atp "Z3" ["2.18"] (K (250, "mangled_guards?") (* FUDGE *))
blanchet@44092
   463
val remote_e_sine =
blanchet@44092
   464
  remote_atp e_sineN "SInE" ["0.4"] [] (#known_failures e_config) Axiom
blanchet@43989
   465
             Conjecture [FOF] (K (500, "mangled_guards?") (* FUDGE *))
blanchet@41740
   466
val remote_snark =
blanchet@42939
   467
  remote_atp snarkN "SNARK" ["20080805r029", "20080805r024"]
blanchet@42962
   468
             [("refutation.", "end_refutation.")] [] Hypothesis Hypothesis
blanchet@43569
   469
             [TFF, FOF] (K (100, "simple") (* FUDGE *))
blanchet@44092
   470
val remote_e_tofof =
blanchet@44092
   471
  remote_atp e_tofofN "ToFoF" ["0.1"] [] (#known_failures e_config)
blanchet@43569
   472
             Axiom Hypothesis [TFF] (K (150, "simple") (* FUDGE *))
blanchet@42938
   473
val remote_waldmeister =
blanchet@42938
   474
  remote_atp waldmeisterN "Waldmeister" ["710"]
blanchet@42944
   475
             [("#START OF PROOF", "Proved Goals:")]
blanchet@42953
   476
             [(OutOfResources, "Too many function symbols"),
blanchet@42953
   477
              (Crashed, "Unrecoverable Segmentation Fault")]
blanchet@42953
   478
             Hypothesis Hypothesis [CNF_UEQ]
blanchet@43569
   479
             (K (50, "mangled_tags?") (* FUDGE *))
blanchet@38454
   480
blanchet@38454
   481
(* Setup *)
blanchet@38454
   482
blanchet@40059
   483
fun add_atp (name, config) thy =
blanchet@40059
   484
  Data.map (Symtab.update_new (name, (config, stamp ()))) thy
blanchet@40059
   485
  handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@40059
   486
blanchet@40059
   487
fun get_atp thy name =
blanchet@40059
   488
  the (Symtab.lookup (Data.get thy) name) |> fst
blanchet@40059
   489
  handle Option.Option => error ("Unknown ATP: " ^ name ^ ".")
blanchet@40059
   490
blanchet@41727
   491
val supported_atps = Symtab.keys o Data.get
blanchet@36371
   492
blanchet@40059
   493
fun is_atp_installed thy name =
blanchet@40059
   494
  let val {exec, required_execs, ...} = get_atp thy name in
blanchet@40059
   495
    forall (curry (op <>) "" o getenv o fst) (exec :: required_execs)
blanchet@40059
   496
  end
blanchet@36371
   497
blanchet@40059
   498
fun refresh_systems_on_tptp () =
blanchet@40059
   499
  Synchronized.change systems (fn _ => get_systems ())
blanchet@40059
   500
blanchet@42962
   501
val atps =
blanchet@44099
   502
  [e, leo2, satallax, spass, vampire, z3_atp, remote_e, remote_leo2,
blanchet@44099
   503
   remote_satallax, remote_vampire, remote_z3_atp, remote_e_sine, remote_snark,
blanchet@44099
   504
   remote_e_tofof, remote_waldmeister]
blanchet@40059
   505
val setup = fold add_atp atps
blanchet@35867
   506
wenzelm@28592
   507
end;