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