src/HOL/Tools/ATP/atp_systems.ML
author blanchet
Tue Mar 20 00:44:30 2012 +0100 (2012-03-20)
changeset 47029 72802e2edda4
parent 46643 a88bccd2b567
child 47030 7e80e14247fc
permissions -rw-r--r--
renamed E weight attribute
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@45301
    10
  type atp_format = ATP_Problem.atp_format
blanchet@42577
    11
  type formula_kind = ATP_Problem.formula_kind
blanchet@39491
    12
  type failure = ATP_Proof.failure
blanchet@38023
    13
blanchet@46409
    14
  type slice_spec = int * atp_format * string * string * bool
blanchet@40059
    15
  type atp_config =
blanchet@42578
    16
    {exec : string * string,
blanchet@42578
    17
     required_execs : (string * string) list,
blanchet@42646
    18
     arguments :
blanchet@43473
    19
       Proof.context -> bool -> string -> Time.time
blanchet@43354
    20
       -> (unit -> (string * real) list) -> string,
blanchet@42578
    21
     proof_delims : (string * string) list,
blanchet@42578
    22
     known_failures : (failure * string) list,
blanchet@42709
    23
     conj_sym_kind : formula_kind,
blanchet@42709
    24
     prem_kind : formula_kind,
blanchet@43473
    25
     best_slices :
blanchet@46409
    26
       Proof.context -> (real * (bool * (slice_spec * 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@47029
    33
  val e_selection_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@46643
    40
  val alt_ergoN : string
blanchet@46643
    41
  val dummy_thfN : string
blanchet@40059
    42
  val eN : string
blanchet@44590
    43
  val e_sineN : string
blanchet@44590
    44
  val e_tofofN : string
blanchet@45338
    45
  val iproverN : string
blanchet@45338
    46
  val iprover_eqN : string
blanchet@44590
    47
  val leo2N : string
blanchet@44590
    48
  val satallaxN : string
blanchet@44590
    49
  val snarkN : string
blanchet@40059
    50
  val spassN : string
blanchet@45301
    51
  val spass_newN : string
blanchet@40059
    52
  val vampireN : string
blanchet@42938
    53
  val waldmeisterN : string
blanchet@44423
    54
  val z3_tptpN : string
blanchet@40060
    55
  val remote_prefix : string
blanchet@41738
    56
  val remote_atp :
blanchet@41738
    57
    string -> string -> string list -> (string * string) list
blanchet@44416
    58
    -> (failure * string) list -> formula_kind -> formula_kind
blanchet@46409
    59
    -> (Proof.context -> slice_spec) -> string * atp_config
blanchet@40059
    60
  val add_atp : string * atp_config -> theory -> theory
blanchet@40059
    61
  val get_atp : theory -> string -> atp_config
blanchet@41727
    62
  val supported_atps : theory -> string list
blanchet@40059
    63
  val is_atp_installed : theory -> string -> bool
blanchet@35867
    64
  val refresh_systems_on_tptp : unit -> unit
blanchet@35867
    65
  val setup : theory -> theory
wenzelm@28592
    66
end;
wenzelm@28592
    67
blanchet@36376
    68
structure ATP_Systems : ATP_SYSTEMS =
wenzelm@28592
    69
struct
wenzelm@28596
    70
blanchet@42577
    71
open ATP_Problem
blanchet@39491
    72
open ATP_Proof
blanchet@46320
    73
open ATP_Problem_Generate
boehmes@32864
    74
blanchet@40059
    75
(* ATP configuration *)
boehmes@32864
    76
blanchet@46409
    77
type slice_spec = int * atp_format * string * string * bool
blanchet@46409
    78
blanchet@40059
    79
type atp_config =
blanchet@42578
    80
  {exec : string * string,
blanchet@42578
    81
   required_execs : (string * string) list,
blanchet@42646
    82
   arguments :
blanchet@43473
    83
     Proof.context -> bool -> string -> Time.time
blanchet@43473
    84
     -> (unit -> (string * real) list) -> string,
blanchet@42578
    85
   proof_delims : (string * string) list,
blanchet@42578
    86
   known_failures : (failure * string) list,
blanchet@42709
    87
   conj_sym_kind : formula_kind,
blanchet@42709
    88
   prem_kind : formula_kind,
blanchet@46409
    89
   best_slices : Proof.context -> (real * (bool * (slice_spec * string))) list}
wenzelm@28596
    90
blanchet@42723
    91
(* "best_slices" must be found empirically, taking a wholistic approach since
blanchet@46407
    92
   the ATPs are run in parallel. The "real" component gives the faction of the
blanchet@46409
    93
   time available given to the slice and should add up to 1.0. The first "bool"
blanchet@42723
    94
   component indicates whether the slice's strategy is complete; the "int", the
blanchet@43569
    95
   preferred number of facts to pass; the first "string", the preferred type
blanchet@45521
    96
   system (which should be sound or quasi-sound); the second "string", the
blanchet@46409
    97
   preferred lambda translation scheme; the second "bool", whether uncurried
blanchet@46409
    98
   aliased should be generated; the third "string", extra information to
blanchet@45521
    99
   the prover (e.g., SOS or no SOS).
blanchet@42723
   100
blanchet@42723
   101
   The last slice should be the most "normal" one, because it will get all the
blanchet@43569
   102
   time available if the other slices fail early and also because it is used if
blanchet@43569
   103
   slicing is disabled (e.g., by the minimizer). *)
blanchet@42710
   104
blanchet@38061
   105
val known_perl_failures =
blanchet@38094
   106
  [(CantConnect, "HTTP error"),
blanchet@38094
   107
   (NoPerl, "env: perl"),
blanchet@38065
   108
   (NoLibwwwPerl, "Can't locate HTTP")]
wenzelm@28596
   109
blanchet@45203
   110
fun known_szs_failures wrap =
blanchet@45203
   111
  [(Unprovable, wrap "CounterSatisfiable"),
blanchet@45203
   112
   (Unprovable, wrap "Satisfiable"),
blanchet@45203
   113
   (GaveUp, wrap "GaveUp"),
blanchet@45203
   114
   (GaveUp, wrap "Unknown"),
blanchet@45203
   115
   (GaveUp, wrap "Incomplete"),
blanchet@45203
   116
   (ProofMissing, wrap "Theorem"),
blanchet@45203
   117
   (ProofMissing, wrap "Unsatisfiable"),
blanchet@45203
   118
   (TimedOut, wrap "Timeout"),
blanchet@45203
   119
   (Inappropriate, wrap "Inappropriate"),
blanchet@45203
   120
   (OutOfResources, wrap "ResourceOut"),
blanchet@45203
   121
   (OutOfResources, wrap "MemoryOut"),
blanchet@45203
   122
   (Interrupted, wrap "Forced"),
blanchet@45203
   123
   (Interrupted, wrap "User")]
blanchet@45203
   124
blanchet@45203
   125
val known_szs_status_failures = known_szs_failures (prefix "SZS status ")
blanchet@45203
   126
val known_says_failures = known_szs_failures (prefix " says ")
blanchet@45203
   127
blanchet@40059
   128
(* named ATPs *)
blanchet@40059
   129
blanchet@46643
   130
val alt_ergoN = "alt_ergo"
blanchet@46643
   131
val dummy_thfN = "dummy_thf" (* experimental *)
blanchet@40059
   132
val eN = "e"
blanchet@44590
   133
val e_sineN = "e_sine"
blanchet@44590
   134
val e_tofofN = "e_tofof"
blanchet@45338
   135
val iproverN = "iprover"
blanchet@45338
   136
val iprover_eqN = "iprover_eq"
blanchet@44099
   137
val leo2N = "leo2"
blanchet@44099
   138
val satallaxN = "satallax"
blanchet@44590
   139
val snarkN = "snark"
blanchet@40059
   140
val spassN = "spass"
blanchet@45365
   141
val spass_newN = "spass_new" (* experimental *)
blanchet@40059
   142
val vampireN = "vampire"
blanchet@44590
   143
val waldmeisterN = "waldmeister"
blanchet@44423
   144
val z3_tptpN = "z3_tptp"
blanchet@40060
   145
val remote_prefix = "remote_"
blanchet@38001
   146
blanchet@38023
   147
structure Data = Theory_Data
blanchet@38023
   148
(
blanchet@40059
   149
  type T = (atp_config * stamp) Symtab.table
blanchet@38023
   150
  val empty = Symtab.empty
blanchet@38023
   151
  val extend = I
blanchet@46407
   152
  fun merge data : T =
blanchet@46407
   153
    Symtab.merge (eq_snd (op =)) data
blanchet@38023
   154
    handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@38023
   155
)
blanchet@38017
   156
blanchet@43981
   157
fun to_secs min time = Int.max (min, (Time.toMilliseconds time + 999) div 1000)
blanchet@36142
   158
blanchet@43473
   159
val sosN = "sos"
blanchet@43473
   160
val no_sosN = "no_sos"
blanchet@43473
   161
blanchet@44099
   162
val force_sos = Attrib.setup_config_bool @{binding atp_force_sos} (K false)
blanchet@44099
   163
blanchet@39491
   164
blanchet@46643
   165
(* Alt-Ergo *)
blanchet@46643
   166
blanchet@46643
   167
val alt_ergo_tff1 = TFF (TPTP_Polymorphic, TPTP_Explicit)
blanchet@46643
   168
blanchet@46643
   169
val alt_ergo_config : atp_config =
blanchet@46643
   170
  {exec = ("WHY3_HOME", "why3"),
blanchet@46643
   171
   required_execs = [],
blanchet@46643
   172
   arguments =
blanchet@46643
   173
     fn _ => fn _ => fn _ => fn timeout => fn _ =>
blanchet@46643
   174
        "--format tff1 --prover alt-ergo --timelimit " ^
blanchet@46643
   175
        string_of_int (to_secs 1 timeout),
blanchet@46643
   176
   proof_delims = [],
blanchet@46643
   177
   known_failures =
blanchet@46643
   178
     [(ProofMissing, ": Valid"),
blanchet@46643
   179
      (TimedOut, ": Timeout"),
blanchet@46643
   180
      (GaveUp, ": Unknown")],
blanchet@46643
   181
   conj_sym_kind = Hypothesis,
blanchet@46643
   182
   prem_kind = Hypothesis,
blanchet@46643
   183
   best_slices = fn _ =>
blanchet@46643
   184
     (* FUDGE *)
blanchet@46643
   185
     [(1.0, (false, ((100, alt_ergo_tff1, "poly_native", liftingN, false), "")))]}
blanchet@46643
   186
blanchet@46643
   187
val alt_ergo = (alt_ergoN, alt_ergo_config)
blanchet@46643
   188
blanchet@46643
   189
blanchet@40059
   190
(* E *)
wenzelm@28596
   191
blanchet@44420
   192
fun is_old_e_version () = (string_ord (getenv "E_VERSION", "1.2w") = LESS)
blanchet@44420
   193
blanchet@36369
   194
val tstp_proof_delims =
blanchet@42962
   195
  [("# SZS output start CNFRefutation.", "# SZS output end CNFRefutation"),
blanchet@42962
   196
   ("% SZS output start CNFRefutation", "% SZS output end CNFRefutation")]
blanchet@36369
   197
blanchet@43473
   198
val e_smartN = "smart"
blanchet@42646
   199
val e_autoN = "auto"
blanchet@42646
   200
val e_fun_weightN = "fun_weight"
blanchet@42646
   201
val e_sym_offset_weightN = "sym_offset_weight"
blanchet@41725
   202
blanchet@47029
   203
val e_selection_weight_method =
blanchet@47029
   204
  Attrib.setup_config_string @{binding atp_e_selection_weight_method} (K e_smartN)
blanchet@41770
   205
(* FUDGE *)
blanchet@42646
   206
val e_default_fun_weight =
blanchet@42646
   207
  Attrib.setup_config_real @{binding atp_e_default_fun_weight} (K 20.0)
blanchet@42646
   208
val e_fun_weight_base =
blanchet@42646
   209
  Attrib.setup_config_real @{binding atp_e_fun_weight_base} (K 0.0)
blanchet@42646
   210
val e_fun_weight_span =
blanchet@42646
   211
  Attrib.setup_config_real @{binding atp_e_fun_weight_span} (K 40.0)
blanchet@42646
   212
val e_default_sym_offs_weight =
blanchet@42646
   213
  Attrib.setup_config_real @{binding atp_e_default_sym_offs_weight} (K 1.0)
blanchet@42646
   214
val e_sym_offs_weight_base =
blanchet@42646
   215
  Attrib.setup_config_real @{binding atp_e_sym_offs_weight_base} (K ~20.0)
blanchet@42646
   216
val e_sym_offs_weight_span =
blanchet@42646
   217
  Attrib.setup_config_real @{binding atp_e_sym_offs_weight_span} (K 60.0)
blanchet@41725
   218
blanchet@47029
   219
fun e_selection_weight_method_case method fw sow =
blanchet@42646
   220
  if method = e_fun_weightN then fw
blanchet@42646
   221
  else if method = e_sym_offset_weightN then sow
blanchet@43478
   222
  else raise Fail ("unexpected " ^ quote method)
blanchet@41725
   223
blanchet@47029
   224
fun scaled_e_selection_weight ctxt method w =
blanchet@47029
   225
  w * Config.get ctxt (e_selection_weight_method_case method
blanchet@47029
   226
                           e_fun_weight_span e_sym_offs_weight_span)
blanchet@47029
   227
  + Config.get ctxt (e_selection_weight_method_case method
blanchet@47029
   228
                         e_fun_weight_base e_sym_offs_weight_base)
blanchet@41725
   229
  |> Real.ceil |> signed_string_of_int
blanchet@41313
   230
blanchet@47029
   231
fun e_selection_weight_arguments ctxt method weights =
blanchet@42646
   232
  if method = e_autoN then
blanchet@41725
   233
    "-xAutoDev"
blanchet@41725
   234
  else
blanchet@43622
   235
    (* supplied by Stephan Schulz *)
blanchet@41314
   236
    "--split-clauses=4 --split-reuse-defs --simul-paramod --forward-context-sr \
blanchet@41314
   237
    \--destructive-er-aggressive --destructive-er --presat-simplify \
blanchet@41314
   238
    \--prefer-initial-clauses -tKBO6 -winvfreqrank -c1 -Ginvfreqconjmax -F1 \
blanchet@41314
   239
    \--delete-bad-limit=150000000 -WSelectMaxLComplexAvoidPosPred \
blanchet@47029
   240
    \-H'(4*" ^
blanchet@47029
   241
    e_selection_weight_method_case method "FunWeight" "SymOffsetWeight" ^
blanchet@41725
   242
    "(SimulateSOS, " ^
blanchet@47029
   243
    (e_selection_weight_method_case method
blanchet@47029
   244
         e_default_fun_weight e_default_sym_offs_weight
blanchet@42646
   245
     |> Config.get ctxt |> Real.ceil |> signed_string_of_int) ^
blanchet@41314
   246
    ",20,1.5,1.5,1" ^
blanchet@42646
   247
    (weights ()
blanchet@47029
   248
     |> map (fn (s, w) => "," ^ s ^ ":" ^
blanchet@47029
   249
                          scaled_e_selection_weight ctxt method w)
blanchet@42646
   250
     |> implode) ^
blanchet@41314
   251
    "),3*ConjectureGeneralSymbolWeight(PreferNonGoals,200,100,200,50,50,1,100,\
blanchet@41314
   252
    \1.5,1.5,1),1*Clauseweight(PreferProcessed,1,1,1),1*\
blanchet@41314
   253
    \FIFOWeight(PreferProcessed))'"
blanchet@41313
   254
blanchet@47029
   255
fun effective_e_selection_weight_method ctxt =
blanchet@47029
   256
  if is_old_e_version () then e_autoN
blanchet@47029
   257
  else Config.get ctxt e_selection_weight_method
blanchet@42443
   258
blanchet@40059
   259
val e_config : atp_config =
blanchet@38092
   260
  {exec = ("E_HOME", "eproof"),
blanchet@38092
   261
   required_execs = [],
blanchet@43354
   262
   arguments =
blanchet@43567
   263
     fn ctxt => fn _ => fn method => fn timeout => fn weights =>
blanchet@47029
   264
        "--tstp-in --tstp-out -l5 " ^
blanchet@47029
   265
        e_selection_weight_arguments ctxt method weights ^
blanchet@43981
   266
        " -tAutoDev --silent --cpu-limit=" ^ string_of_int (to_secs 2 timeout),
blanchet@42962
   267
   proof_delims = tstp_proof_delims,
blanchet@36265
   268
   known_failures =
blanchet@45203
   269
     known_szs_status_failures @
blanchet@45203
   270
     [(TimedOut, "Failure: Resource limit exceeded (time)"),
blanchet@36370
   271
      (TimedOut, "time limit exceeded"),
blanchet@45203
   272
      (OutOfResources, "# Cannot determine problem status")],
blanchet@43466
   273
   conj_sym_kind = Hypothesis,
blanchet@42709
   274
   prem_kind = Conjecture,
blanchet@42646
   275
   best_slices = fn ctxt =>
blanchet@47029
   276
     let val method = effective_e_selection_weight_method ctxt in
blanchet@43474
   277
       (* FUDGE *)
blanchet@43473
   278
       if method = e_smartN then
blanchet@46449
   279
         [(0.333, (true, ((500, FOF, "mono_tags??", combsN, false), e_fun_weightN))),
blanchet@46449
   280
          (0.334, (true, ((50, FOF, "mono_guards??", combsN, false), e_fun_weightN))),
blanchet@46449
   281
          (0.333, (true, ((1000, FOF, "mono_tags??", combsN, false), e_sym_offset_weightN)))]
blanchet@43473
   282
       else
blanchet@46409
   283
         [(1.0, (true, ((500, FOF, "mono_tags??", combsN, false), method)))]
blanchet@43473
   284
     end}
blanchet@38454
   285
blanchet@40059
   286
val e = (eN, e_config)
wenzelm@28596
   287
wenzelm@28596
   288
blanchet@44099
   289
(* LEO-II *)
blanchet@44099
   290
blanchet@44754
   291
val leo2_thf0 = THF (TPTP_Monomorphic, TPTP_Explicit, THF_Without_Choice)
blanchet@44754
   292
blanchet@44099
   293
val leo2_config : atp_config =
blanchet@44099
   294
  {exec = ("LEO2_HOME", "leo"),
blanchet@44099
   295
   required_execs = [],
blanchet@44099
   296
   arguments =
blanchet@44099
   297
     fn _ => fn _ => fn sos => fn timeout => fn _ =>
blanchet@45300
   298
        "--proofoutput 1 --timeout " ^ string_of_int (to_secs 1 timeout)
blanchet@44099
   299
        |> sos = sosN ? prefix "--sos ",
blanchet@44099
   300
   proof_delims = tstp_proof_delims,
blanchet@45207
   301
   known_failures =
blanchet@45207
   302
     known_szs_status_failures @
blanchet@46481
   303
     [(TimedOut, "CPU time limit exceeded, terminating"),
blanchet@46481
   304
      (GaveUp, "No.of.Axioms")],
blanchet@44099
   305
   conj_sym_kind = Axiom,
blanchet@44099
   306
   prem_kind = Hypothesis,
blanchet@44099
   307
   best_slices = fn ctxt =>
blanchet@44099
   308
     (* FUDGE *)
blanchet@46449
   309
     [(0.667, (false, ((150, leo2_thf0, "mono_native_higher", liftingN, false), sosN))),
blanchet@46449
   310
      (0.333, (true, ((50, leo2_thf0, "mono_native_higher", liftingN, false), no_sosN)))]
blanchet@44099
   311
     |> (if Config.get ctxt force_sos then hd #> apfst (K 1.0) #> single
blanchet@44099
   312
         else I)}
blanchet@39491
   313
blanchet@44099
   314
val leo2 = (leo2N, leo2_config)
blanchet@44099
   315
blanchet@44099
   316
blanchet@44099
   317
(* Satallax *)
blanchet@44099
   318
blanchet@44754
   319
val satallax_thf0 = THF (TPTP_Monomorphic, TPTP_Explicit, THF_With_Choice)
blanchet@44754
   320
blanchet@44099
   321
val satallax_config : atp_config =
blanchet@44099
   322
  {exec = ("SATALLAX_HOME", "satallax"),
blanchet@44099
   323
   required_execs = [],
blanchet@44099
   324
   arguments =
blanchet@44099
   325
     fn _ => fn _ => fn _ => fn timeout => fn _ =>
blanchet@45162
   326
        "-p hocore -t " ^ string_of_int (to_secs 1 timeout),
blanchet@45162
   327
   proof_delims =
blanchet@45162
   328
     [("% Higher-Order Unsat Core BEGIN", "% Higher-Order Unsat Core END")],
blanchet@45203
   329
   known_failures = known_szs_status_failures,
blanchet@44099
   330
   conj_sym_kind = Axiom,
blanchet@44099
   331
   prem_kind = Hypothesis,
blanchet@44416
   332
   best_slices =
blanchet@44754
   333
     (* FUDGE *)
blanchet@46449
   334
     K [(1.0, (true, ((100, satallax_thf0, "mono_native_higher", keep_lamsN, false), "")))]}
blanchet@44099
   335
blanchet@44099
   336
val satallax = (satallaxN, satallax_config)
blanchet@44099
   337
blanchet@44099
   338
blanchet@44099
   339
(* SPASS *)
blanchet@42725
   340
blanchet@36219
   341
(* The "-VarWeight=3" option helps the higher-order problems, probably by
blanchet@44450
   342
   counteracting the presence of explicit application operators. *)
blanchet@40059
   343
val spass_config : atp_config =
blanchet@38092
   344
  {exec = ("ISABELLE_ATP", "scripts/spass"),
blanchet@39002
   345
   required_execs = [("SPASS_HOME", "SPASS"), ("SPASS_HOME", "tptp2dfg")],
blanchet@43569
   346
   arguments = fn _ => fn _ => fn sos => fn timeout => fn _ =>
blanchet@37962
   347
     ("-Auto -PGiven=0 -PProblem=0 -Splits=0 -FullRed=0 -DocProof \
blanchet@43981
   348
      \-VarWeight=3 -TimeLimit=" ^ string_of_int (to_secs 1 timeout))
blanchet@43473
   349
     |> sos = sosN ? prefix "-SOS=1 ",
blanchet@36369
   350
   proof_delims = [("Here is a proof", "Formulae used in the proof")],
blanchet@36289
   351
   known_failures =
blanchet@38061
   352
     known_perl_failures @
blanchet@43050
   353
     [(GaveUp, "SPASS beiseite: Completion found"),
blanchet@36370
   354
      (TimedOut, "SPASS beiseite: Ran out of time"),
blanchet@36965
   355
      (OutOfResources, "SPASS beiseite: Maximal number of loops exceeded"),
blanchet@37413
   356
      (MalformedInput, "Undefined symbol"),
blanchet@37414
   357
      (MalformedInput, "Free Variable"),
blanchet@44391
   358
      (Unprovable, "No formulae and clauses found in input file"),
blanchet@39263
   359
      (InternalError, "Please report this error")],
blanchet@43466
   360
   conj_sym_kind = Hypothesis,
blanchet@42709
   361
   prem_kind = Conjecture,
blanchet@42725
   362
   best_slices = fn ctxt =>
blanchet@42723
   363
     (* FUDGE *)
blanchet@46449
   364
     [(0.333, (false, ((150, DFG DFG_Unsorted, "mono_tags??", liftingN, false), sosN))),
blanchet@46449
   365
      (0.333, (false, ((300, DFG DFG_Unsorted, "poly_tags??", liftingN, false), sosN))),
blanchet@46449
   366
      (0.334, (false, ((50, DFG DFG_Unsorted, "mono_tags??", liftingN, false), no_sosN)))]
blanchet@46449
   367
     |> (if Config.get ctxt force_sos then hd #> apfst (K 1.0) #> single else I)}
blanchet@38454
   368
blanchet@40059
   369
val spass = (spassN, spass_config)
wenzelm@28596
   370
blanchet@46449
   371
val spass_new_H2 = "-Heuristic=2"
blanchet@46455
   372
val spass_new_H2SOS = "-Heuristic=2 -SOS"
blanchet@46455
   373
val spass_new_H2NuVS0 = "-Heuristic=2 -RNuV=1 -Sorts=0"
blanchet@46455
   374
val spass_new_H2NuVS0Red2 =
blanchet@46455
   375
  "-Heuristic=2 -RNuV=1 -Sorts=0 -RFRew=2 -RBRew=2 -RTaut=2"
blanchet@46449
   376
blanchet@45301
   377
(* Experimental *)
blanchet@45301
   378
val spass_new_config : atp_config =
blanchet@46428
   379
  {exec = ("SPASS_NEW_HOME", "SPASS"),
blanchet@46428
   380
   required_execs = [],
blanchet@46444
   381
   arguments = fn _ => fn _ => fn extra_options => fn timeout => fn _ =>
blanchet@46429
   382
     ("-Isabelle=1 -TimeLimit=" ^ string_of_int (to_secs 1 timeout))
blanchet@46444
   383
     |> extra_options <> "" ? prefix (extra_options ^ " "),
blanchet@45301
   384
   proof_delims = #proof_delims spass_config,
blanchet@45301
   385
   known_failures = #known_failures spass_config,
blanchet@45301
   386
   conj_sym_kind = #conj_sym_kind spass_config,
blanchet@45301
   387
   prem_kind = #prem_kind spass_config,
blanchet@46381
   388
   best_slices = fn _ =>
blanchet@45301
   389
     (* FUDGE *)
blanchet@46455
   390
     [(0.1667, (false, ((150, DFG DFG_Sorted, "mono_native", combsN, true), ""))),
blanchet@46455
   391
      (0.1667, (false, ((500, DFG DFG_Sorted, "mono_native", liftingN, true), spass_new_H2SOS))),
blanchet@46455
   392
      (0.1666, (false, ((50, DFG DFG_Sorted,  "mono_native", liftingN, true), spass_new_H2))),
blanchet@46455
   393
      (0.1000, (false, ((250, DFG DFG_Sorted, "mono_native", combsN, true), spass_new_H2NuVS0))),
blanchet@46455
   394
      (0.1000, (false, ((100, DFG DFG_Sorted, "mono_native", combs_and_liftingN, true), spass_new_H2NuVS0))),
blanchet@46455
   395
      (0.1000, (false, ((300, DFG DFG_Sorted, "mono_native", combsN, true), spass_new_H2SOS))),
blanchet@46455
   396
      (0.1000, (false, ((150, DFG DFG_Sorted, "poly_guards??", liftingN, false), spass_new_H2NuVS0Red2))),
blanchet@46455
   397
      (0.1000, (false, ((400, DFG DFG_Sorted, "mono_native", liftingN, true), spass_new_H2)))]}
blanchet@45301
   398
blanchet@45301
   399
val spass_new = (spass_newN, spass_new_config)
blanchet@45301
   400
blanchet@38454
   401
blanchet@37509
   402
(* Vampire *)
blanchet@37509
   403
blanchet@44507
   404
(* Vampire 1.8 has TFF support, but it's buggy and therefore disabled on
blanchet@44507
   405
   SystemOnTPTP. *)
blanchet@44420
   406
fun is_old_vampire_version () =
blanchet@44507
   407
  string_ord (getenv "VAMPIRE_VERSION", "1.8") <> GREATER
blanchet@44420
   408
blanchet@44754
   409
val vampire_tff0 = TFF (TPTP_Monomorphic, TPTP_Implicit)
blanchet@44589
   410
blanchet@40059
   411
val vampire_config : atp_config =
blanchet@38092
   412
  {exec = ("VAMPIRE_HOME", "vampire"),
blanchet@38092
   413
   required_execs = [],
blanchet@43569
   414
   arguments = fn _ => fn _ => fn sos => fn timeout => fn _ =>
blanchet@44417
   415
     "--mode casc -t " ^ string_of_int (to_secs 1 timeout) ^
blanchet@45234
   416
     " --proof tptp --output_axiom_names on\
blanchet@45234
   417
     \ --forced_options propositional_to_bdd=off\
blanchet@44417
   418
     \ --thanks \"Andrei and Krystof\" --input_file"
blanchet@43473
   419
     |> sos = sosN ? prefix "--sos on ",
blanchet@37509
   420
   proof_delims =
blanchet@37509
   421
     [("=========== Refutation ==========",
blanchet@37509
   422
       "======= End of refutation ======="),
blanchet@38033
   423
      ("% SZS output start Refutation", "% SZS output end Refutation"),
blanchet@38033
   424
      ("% SZS output start Proof", "% SZS output end Proof")],
blanchet@37509
   425
   known_failures =
blanchet@45203
   426
     known_szs_status_failures @
blanchet@43050
   427
     [(GaveUp, "UNPROVABLE"),
blanchet@43050
   428
      (GaveUp, "CANNOT PROVE"),
blanchet@37509
   429
      (Unprovable, "Satisfiability detected"),
blanchet@38647
   430
      (Unprovable, "Termination reason: Satisfiable"),
blanchet@39263
   431
      (Interrupted, "Aborted by signal SIGINT")],
blanchet@43466
   432
   conj_sym_kind = Conjecture,
blanchet@42709
   433
   prem_kind = Conjecture,
blanchet@42725
   434
   best_slices = fn ctxt =>
blanchet@42723
   435
     (* FUDGE *)
blanchet@44420
   436
     (if is_old_vampire_version () then
blanchet@46449
   437
        [(0.333, (false, ((150, FOF, "poly_guards??", combs_or_liftingN, false), sosN))),
blanchet@46449
   438
         (0.333, (false, ((500, FOF, "mono_tags??", combs_or_liftingN, false), sosN))),
blanchet@46449
   439
         (0.334, (true, ((50, FOF, "mono_guards??", combs_or_liftingN, false), no_sosN)))]
blanchet@44420
   440
      else
blanchet@46449
   441
        [(0.333, (false, ((150, vampire_tff0, "poly_guards??", combs_or_liftingN, false), sosN))),
blanchet@46449
   442
         (0.333, (false, ((500, vampire_tff0, "mono_native", combs_or_liftingN, false), sosN))),
blanchet@46449
   443
         (0.334, (true, ((50, vampire_tff0, "mono_native", combs_or_liftingN, false), no_sosN)))])
blanchet@44099
   444
     |> (if Config.get ctxt force_sos then hd #> apfst (K 1.0) #> single
blanchet@42725
   445
         else I)}
blanchet@38454
   446
blanchet@40059
   447
val vampire = (vampireN, vampire_config)
blanchet@37509
   448
blanchet@38454
   449
blanchet@41740
   450
(* Z3 with TPTP syntax *)
blanchet@41740
   451
blanchet@44754
   452
val z3_tff0 = TFF (TPTP_Monomorphic, TPTP_Implicit)
blanchet@44589
   453
blanchet@44423
   454
val z3_tptp_config : atp_config =
blanchet@41740
   455
  {exec = ("Z3_HOME", "z3"),
blanchet@41740
   456
   required_execs = [],
blanchet@43354
   457
   arguments = fn _ => fn _ => fn _ => fn timeout => fn _ =>
blanchet@44420
   458
     "MBQI=true -tptp -t:" ^ string_of_int (to_secs 1 timeout),
blanchet@41740
   459
   proof_delims = [],
blanchet@45203
   460
   known_failures = known_szs_status_failures,
blanchet@42709
   461
   conj_sym_kind = Hypothesis,
blanchet@42709
   462
   prem_kind = Hypothesis,
blanchet@42723
   463
   best_slices =
blanchet@44423
   464
     (* FUDGE *)
blanchet@46435
   465
     K [(0.5, (false, ((250, z3_tff0, "mono_native", combsN, false), ""))),
blanchet@46435
   466
        (0.25, (false, ((125, z3_tff0, "mono_native", combsN, false), ""))),
blanchet@46435
   467
        (0.125, (false, ((62, z3_tff0, "mono_native", combsN, false), ""))),
blanchet@46435
   468
        (0.125, (false, ((31, z3_tff0, "mono_native", combsN, false), "")))]}
blanchet@41740
   469
blanchet@44423
   470
val z3_tptp = (z3_tptpN, z3_tptp_config)
blanchet@41740
   471
blanchet@44590
   472
blanchet@44754
   473
(* Not really a prover: Experimental Polymorphic TFF and THF output *)
blanchet@44590
   474
blanchet@44754
   475
fun dummy_config format type_enc : atp_config =
blanchet@44596
   476
  {exec = ("ISABELLE_ATP", "scripts/dummy_atp"),
blanchet@44590
   477
   required_execs = [],
blanchet@44590
   478
   arguments = K (K (K (K (K "")))),
blanchet@44590
   479
   proof_delims = [],
blanchet@45203
   480
   known_failures = known_szs_status_failures,
blanchet@44590
   481
   conj_sym_kind = Hypothesis,
blanchet@44590
   482
   prem_kind = Hypothesis,
blanchet@45521
   483
   best_slices =
blanchet@46407
   484
     K [(1.0, (false, ((200, format, type_enc,
blanchet@46407
   485
                        if is_format_higher_order format then keep_lamsN
blanchet@46409
   486
                        else combsN, false), "")))]}
blanchet@44590
   487
blanchet@45365
   488
val dummy_thf_format = THF (TPTP_Polymorphic, TPTP_Explicit, THF_With_Choice)
blanchet@46435
   489
val dummy_thf_config = dummy_config dummy_thf_format "poly_native_higher"
blanchet@45365
   490
val dummy_thf = (dummy_thfN, dummy_thf_config)
blanchet@44754
   491
blanchet@41740
   492
blanchet@40059
   493
(* Remote ATP invocation via SystemOnTPTP *)
wenzelm@28596
   494
blanchet@38061
   495
val systems = Synchronized.var "atp_systems" ([] : string list)
immler@31835
   496
immler@31835
   497
fun get_systems () =
blanchet@44589
   498
  case Isabelle_System.bash_output
blanchet@44589
   499
           "\"$ISABELLE_ATP/scripts/remote_atp\" -w 2>&1" of
blanchet@39491
   500
    (output, 0) => split_lines output
blanchet@39491
   501
  | (output, _) =>
blanchet@39491
   502
    error (case extract_known_failure known_perl_failures output of
blanchet@41744
   503
             SOME failure => string_for_failure failure
blanchet@39491
   504
           | NONE => perhaps (try (unsuffix "\n")) output ^ ".")
immler@31835
   505
blanchet@42537
   506
fun find_system name [] systems =
blanchet@42537
   507
    find_first (String.isPrefix (name ^ "---")) systems
blanchet@38690
   508
  | find_system name (version :: versions) systems =
blanchet@38690
   509
    case find_first (String.isPrefix (name ^ "---" ^ version)) systems of
blanchet@38690
   510
      NONE => find_system name versions systems
blanchet@38690
   511
    | res => res
blanchet@38690
   512
blanchet@38690
   513
fun get_system name versions =
blanchet@38589
   514
  Synchronized.change_result systems
blanchet@38589
   515
      (fn systems => (if null systems then get_systems () else systems)
blanchet@42955
   516
                     |> `(`(find_system name versions)))
boehmes@32864
   517
blanchet@38690
   518
fun the_system name versions =
blanchet@38690
   519
  case get_system name versions of
blanchet@42955
   520
    (SOME sys, _) => sys
blanchet@46480
   521
  | (NONE, []) => error ("SystemOnTPTP is not available.")
blanchet@42955
   522
  | (NONE, syss) =>
blanchet@46480
   523
    case syss |> filter_out (String.isPrefix "%")
blanchet@46480
   524
              |> filter_out (curry (op =) "") of
blanchet@46480
   525
      [] => error ("SystemOnTPTP is not available.")
blanchet@46480
   526
    | [msg] => error ("SystemOnTPTP is not available: " ^ msg ^ ".")
blanchet@46480
   527
    | syss =>
blanchet@46480
   528
      error ("System " ^ quote name ^ " is not available at SystemOnTPTP.\n" ^
blanchet@46480
   529
             "(Available systems: " ^ commas_quote syss ^ ".)")
immler@31835
   530
blanchet@41148
   531
val max_remote_secs = 240 (* give Geoff Sutcliffe's servers a break *)
blanchet@41148
   532
blanchet@38690
   533
fun remote_config system_name system_versions proof_delims known_failures
blanchet@44416
   534
                  conj_sym_kind prem_kind best_slice : atp_config =
blanchet@38092
   535
  {exec = ("ISABELLE_ATP", "scripts/remote_atp"),
blanchet@38092
   536
   required_execs = [],
blanchet@43354
   537
   arguments = fn _ => fn _ => fn _ => fn timeout => fn _ =>
blanchet@46409
   538
     "-t " ^ string_of_int (Int.min (max_remote_secs, to_secs 1 timeout)) ^
blanchet@46409
   539
     " -s " ^ the_system system_name system_versions,
blanchet@42962
   540
   proof_delims = union (op =) tstp_proof_delims proof_delims,
blanchet@45203
   541
   known_failures = known_failures @ known_perl_failures @ known_says_failures,
blanchet@42709
   542
   conj_sym_kind = conj_sym_kind,
blanchet@42709
   543
   prem_kind = prem_kind,
blanchet@46409
   544
   best_slices = fn ctxt => [(1.0, (false, (best_slice ctxt, "")))]}
blanchet@42443
   545
blanchet@43500
   546
fun remotify_config system_name system_versions best_slice
blanchet@44416
   547
        ({proof_delims, known_failures, conj_sym_kind, prem_kind, ...}
blanchet@43500
   548
         : atp_config) : atp_config =
blanchet@38690
   549
  remote_config system_name system_versions proof_delims known_failures
blanchet@44416
   550
                conj_sym_kind prem_kind best_slice
blanchet@38023
   551
blanchet@40059
   552
fun remote_atp name system_name system_versions proof_delims known_failures
blanchet@44416
   553
               conj_sym_kind prem_kind best_slice =
blanchet@40060
   554
  (remote_prefix ^ name,
blanchet@38690
   555
   remote_config system_name system_versions proof_delims known_failures
blanchet@44416
   556
                 conj_sym_kind prem_kind best_slice)
blanchet@43500
   557
fun remotify_atp (name, config) system_name system_versions best_slice =
blanchet@43500
   558
  (remote_prefix ^ name,
blanchet@43500
   559
   remotify_config system_name system_versions best_slice config)
wenzelm@28592
   560
blanchet@44754
   561
val explicit_tff0 = TFF (TPTP_Monomorphic, TPTP_Explicit)
blanchet@44589
   562
blanchet@43500
   563
val remote_e =
blanchet@43500
   564
  remotify_atp e "EP" ["1.0", "1.1", "1.2"]
blanchet@46409
   565
      (K (750, FOF, "mono_tags??", combsN, false) (* FUDGE *))
blanchet@44099
   566
val remote_leo2 =
blanchet@44099
   567
  remotify_atp leo2 "LEO-II" ["1.2.8", "1.2.6"]
blanchet@46435
   568
      (K (100, leo2_thf0, "mono_native_higher", liftingN, false) (* FUDGE *))
blanchet@44099
   569
val remote_satallax =
blanchet@44099
   570
  remotify_atp satallax "Satallax" ["2.1", "2.0", "2"]
blanchet@46435
   571
      (K (100, satallax_thf0, "mono_native_higher", keep_lamsN, false)
blanchet@46409
   572
         (* FUDGE *))
blanchet@43500
   573
val remote_vampire =
blanchet@44499
   574
  remotify_atp vampire "Vampire" ["1.8"]
blanchet@46409
   575
      (K (250, FOF, "mono_guards??", combs_or_liftingN, false) (* FUDGE *))
blanchet@44423
   576
val remote_z3_tptp =
blanchet@44754
   577
  remotify_atp z3_tptp "Z3" ["3.0"]
blanchet@46435
   578
      (K (250, z3_tff0, "mono_native", combsN, false) (* FUDGE *))
blanchet@44092
   579
val remote_e_sine =
blanchet@44092
   580
  remote_atp e_sineN "SInE" ["0.4"] [] (#known_failures e_config) Axiom
blanchet@46409
   581
      Conjecture (K (500, FOF, "mono_guards??", combsN, false) (* FUDGE *))
blanchet@45338
   582
val remote_iprover =
blanchet@45338
   583
  remote_atp iproverN "iProver" [] [] [] Axiom Conjecture
blanchet@46409
   584
      (K (150, FOF, "mono_guards??", liftingN, false) (* FUDGE *))
blanchet@45338
   585
val remote_iprover_eq =
blanchet@45338
   586
  remote_atp iprover_eqN "iProver-Eq" [] [] [] Axiom Conjecture
blanchet@46409
   587
      (K (150, FOF, "mono_guards??", liftingN, false) (* FUDGE *))
blanchet@41740
   588
val remote_snark =
blanchet@42939
   589
  remote_atp snarkN "SNARK" ["20080805r029", "20080805r024"]
blanchet@45521
   590
      [("refutation.", "end_refutation.")] [] Hypothesis Hypothesis
blanchet@46435
   591
      (K (100, explicit_tff0, "mono_native", liftingN, false) (* FUDGE *))
blanchet@44092
   592
val remote_e_tofof =
blanchet@44589
   593
  remote_atp e_tofofN "ToFoF" ["0.1"] [] (#known_failures e_config) Axiom
blanchet@45521
   594
      Hypothesis
blanchet@46435
   595
      (K (150, explicit_tff0, "mono_native", liftingN, false) (* FUDGE *))
blanchet@42938
   596
val remote_waldmeister =
blanchet@42938
   597
  remote_atp waldmeisterN "Waldmeister" ["710"]
blanchet@45521
   598
      [("#START OF PROOF", "Proved Goals:")]
blanchet@45521
   599
      [(OutOfResources, "Too many function symbols"),
blanchet@45521
   600
       (Crashed, "Unrecoverable Segmentation Fault")]
blanchet@45521
   601
      Hypothesis Hypothesis
blanchet@46409
   602
      (K (50, CNF_UEQ, "mono_tags??", combsN, false) (* FUDGE *))
blanchet@38454
   603
blanchet@38454
   604
(* Setup *)
blanchet@38454
   605
blanchet@40059
   606
fun add_atp (name, config) thy =
blanchet@40059
   607
  Data.map (Symtab.update_new (name, (config, stamp ()))) thy
blanchet@40059
   608
  handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@40059
   609
blanchet@40059
   610
fun get_atp thy name =
blanchet@40059
   611
  the (Symtab.lookup (Data.get thy) name) |> fst
blanchet@40059
   612
  handle Option.Option => error ("Unknown ATP: " ^ name ^ ".")
blanchet@40059
   613
blanchet@41727
   614
val supported_atps = Symtab.keys o Data.get
blanchet@36371
   615
blanchet@40059
   616
fun is_atp_installed thy name =
blanchet@40059
   617
  let val {exec, required_execs, ...} = get_atp thy name in
blanchet@40059
   618
    forall (curry (op <>) "" o getenv o fst) (exec :: required_execs)
blanchet@40059
   619
  end
blanchet@36371
   620
blanchet@40059
   621
fun refresh_systems_on_tptp () =
blanchet@40059
   622
  Synchronized.change systems (fn _ => get_systems ())
blanchet@40059
   623
blanchet@42962
   624
val atps =
blanchet@46643
   625
  [alt_ergo, e, leo2, dummy_thf, satallax, spass, spass_new, vampire, z3_tptp,
blanchet@45365
   626
   remote_e, remote_e_sine, remote_e_tofof, remote_iprover, remote_iprover_eq,
blanchet@45339
   627
   remote_leo2, remote_satallax, remote_vampire, remote_z3_tptp, remote_snark,
blanchet@45339
   628
   remote_waldmeister]
blanchet@40059
   629
val setup = fold add_atp atps
blanchet@35867
   630
wenzelm@28592
   631
end;