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