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