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