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