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