src/HOL/Tools/ATP/atp_systems.ML
author blanchet
Mon Aug 16 13:59:04 2010 +0200 (2010-08-16)
changeset 38454 9043eefe8d71
parent 38433 1e28e2e1c2fb
child 38465 1f51486da674
child 38487 1b460d6a9d58
permissions -rw-r--r--
detect old Vampire and give a nicer error message
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@38023
    10
  datatype failure =
blanchet@38454
    11
    Unprovable | IncompleteUnprovable | MalformedOutput | UnknownError
blanchet@38023
    12
blanchet@38023
    13
  type prover_config =
blanchet@38092
    14
    {exec: string * string,
blanchet@38092
    15
     required_execs: (string * string) list,
blanchet@38023
    16
     arguments: bool -> Time.time -> string,
blanchet@38023
    17
     proof_delims: (string * string) list,
blanchet@38023
    18
     known_failures: (failure * string) list,
blanchet@38023
    19
     max_new_relevant_facts_per_iter: int,
blanchet@38023
    20
     prefers_theory_relevant: bool,
blanchet@38023
    21
     explicit_forall: bool}
blanchet@38023
    22
blanchet@38061
    23
  val string_for_failure : failure -> string
blanchet@38061
    24
  val known_failure_in_output :
blanchet@38061
    25
    string -> (failure * string) list -> failure option
blanchet@38023
    26
  val add_prover: string * prover_config -> theory -> theory
blanchet@38023
    27
  val get_prover: theory -> string -> prover_config
blanchet@38023
    28
  val available_atps: theory -> unit
blanchet@35867
    29
  val refresh_systems_on_tptp : unit -> unit
blanchet@36371
    30
  val default_atps_param_value : unit -> string
blanchet@35867
    31
  val setup : theory -> theory
wenzelm@28592
    32
end;
wenzelm@28592
    33
blanchet@36376
    34
structure ATP_Systems : ATP_SYSTEMS =
wenzelm@28592
    35
struct
wenzelm@28596
    36
blanchet@38023
    37
(* prover configuration *)
boehmes@32864
    38
blanchet@38023
    39
datatype failure =
blanchet@38454
    40
  Unprovable | IncompleteUnprovable | CantConnect | TimedOut | OutOfResources |
blanchet@38454
    41
  OldSpass | OldVampire | NoPerl | NoLibwwwPerl | MalformedInput |
blanchet@38454
    42
  MalformedOutput | UnknownError
boehmes@32864
    43
wenzelm@32941
    44
type prover_config =
blanchet@38092
    45
  {exec: string * string,
blanchet@38092
    46
   required_execs: (string * string) list,
blanchet@37514
    47
   arguments: bool -> Time.time -> string,
blanchet@36370
    48
   proof_delims: (string * string) list,
blanchet@36370
    49
   known_failures: (failure * string) list,
blanchet@38009
    50
   max_new_relevant_facts_per_iter: int,
blanchet@37994
    51
   prefers_theory_relevant: bool,
blanchet@37994
    52
   explicit_forall: bool}
wenzelm@28596
    53
blanchet@38061
    54
val missing_message_tail =
blanchet@38061
    55
  " appears to be missing. You will need to install it if you want to run \
blanchet@38061
    56
  \ATPs remotely."
blanchet@38061
    57
blanchet@38061
    58
fun string_for_failure Unprovable = "The ATP problem is unprovable."
blanchet@38061
    59
  | string_for_failure IncompleteUnprovable =
blanchet@38061
    60
    "The ATP cannot prove the problem."
blanchet@38094
    61
  | string_for_failure CantConnect = "Can't connect to remote server."
blanchet@38061
    62
  | string_for_failure TimedOut = "Timed out."
blanchet@38061
    63
  | string_for_failure OutOfResources = "The ATP ran out of resources."
blanchet@38061
    64
  | string_for_failure OldSpass =
blanchet@38096
    65
    "Isabelle requires a more recent version of SPASS with support for the \
blanchet@38096
    66
    \TPTP syntax. To install it, download and extract the package \
blanchet@38096
    67
    \\"http://isabelle.in.tum.de/dist/contrib/spass-3.7.tar.gz\" and add the \
blanchet@38096
    68
    \\"spass-3.7\" directory's absolute path to " ^
blanchet@38061
    69
    quote (Path.implode (Path.expand (Path.appends
blanchet@38061
    70
               (Path.variable "ISABELLE_HOME_USER" ::
blanchet@38061
    71
                map Path.basic ["etc", "components"])))) ^
blanchet@38061
    72
    " on a line of its own."
blanchet@38454
    73
  | string_for_failure OldVampire =
blanchet@38454
    74
    "Isabelle requires a more recent version of Vampire. To install it, follow \
blanchet@38454
    75
    \the instructions from the Sledgehammer manual (\"isabelle doc\
blanchet@38454
    76
    \ sledgehammer\")."
blanchet@38061
    77
  | string_for_failure NoPerl = "Perl" ^ missing_message_tail
blanchet@38061
    78
  | string_for_failure NoLibwwwPerl =
blanchet@38061
    79
    "The Perl module \"libwww-perl\"" ^ missing_message_tail
blanchet@38061
    80
  | string_for_failure MalformedInput =
blanchet@38096
    81
    "The ATP problem is malformed. Please report this to the Isabelle \
blanchet@38096
    82
    \developers."
blanchet@38096
    83
  | string_for_failure MalformedOutput = "The ATP output is malformed."
blanchet@38096
    84
  | string_for_failure UnknownError = "An unknown ATP error occurred."
blanchet@38061
    85
blanchet@38061
    86
fun known_failure_in_output output =
blanchet@38061
    87
  find_first (fn (_, pattern) => String.isSubstring pattern output)
blanchet@38061
    88
  #> Option.map fst
blanchet@38061
    89
blanchet@38061
    90
val known_perl_failures =
blanchet@38094
    91
  [(CantConnect, "HTTP error"),
blanchet@38094
    92
   (NoPerl, "env: perl"),
blanchet@38065
    93
   (NoLibwwwPerl, "Can't locate HTTP")]
wenzelm@28596
    94
blanchet@38023
    95
(* named provers *)
blanchet@38001
    96
blanchet@38023
    97
structure Data = Theory_Data
blanchet@38023
    98
(
blanchet@38023
    99
  type T = (prover_config * stamp) Symtab.table
blanchet@38023
   100
  val empty = Symtab.empty
blanchet@38023
   101
  val extend = I
blanchet@38023
   102
  fun merge data : T = Symtab.merge (eq_snd op =) data
blanchet@38023
   103
    handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@38023
   104
)
blanchet@38017
   105
blanchet@38023
   106
fun add_prover (name, config) thy =
blanchet@38023
   107
  Data.map (Symtab.update_new (name, (config, stamp ()))) thy
blanchet@38023
   108
  handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@38017
   109
blanchet@38023
   110
fun get_prover thy name =
blanchet@38023
   111
  the (Symtab.lookup (Data.get thy) name) |> fst
blanchet@38023
   112
  handle Option.Option => error ("Unknown ATP: " ^ name ^ ".")
blanchet@37962
   113
blanchet@38023
   114
fun available_atps thy =
blanchet@38023
   115
  priority ("Available ATPs: " ^
blanchet@38023
   116
            commas (sort_strings (Symtab.keys (Data.get thy))) ^ ".")
boehmes@32864
   117
blanchet@38023
   118
fun available_atps thy =
blanchet@38023
   119
  priority ("Available ATPs: " ^
blanchet@38023
   120
            commas (sort_strings (Symtab.keys (Data.get thy))) ^ ".")
wenzelm@28596
   121
blanchet@36382
   122
fun to_generous_secs time = (Time.toMilliseconds time + 999) div 1000
blanchet@36142
   123
wenzelm@28596
   124
(* E prover *)
wenzelm@28596
   125
blanchet@36369
   126
val tstp_proof_delims =
blanchet@36369
   127
  ("# SZS output start CNFRefutation.", "# SZS output end CNFRefutation")
blanchet@36369
   128
blanchet@35969
   129
val e_config : prover_config =
blanchet@38092
   130
  {exec = ("E_HOME", "eproof"),
blanchet@38092
   131
   required_execs = [],
blanchet@37514
   132
   arguments = fn _ => fn timeout =>
blanchet@36382
   133
     "--tstp-in --tstp-out -l5 -xAutoDev -tAutoDev --silent --cpu-limit=" ^
blanchet@36382
   134
     string_of_int (to_generous_secs timeout),
blanchet@36369
   135
   proof_delims = [tstp_proof_delims],
blanchet@36265
   136
   known_failures =
blanchet@37995
   137
     [(Unprovable, "SZS status: CounterSatisfiable"),
blanchet@37995
   138
      (Unprovable, "SZS status CounterSatisfiable"),
blanchet@36370
   139
      (TimedOut, "Failure: Resource limit exceeded (time)"),
blanchet@36370
   140
      (TimedOut, "time limit exceeded"),
blanchet@36370
   141
      (OutOfResources,
blanchet@36370
   142
       "# Cannot determine problem status within resource limit"),
blanchet@36370
   143
      (OutOfResources, "SZS status: ResourceOut"),
blanchet@36370
   144
      (OutOfResources, "SZS status ResourceOut")],
blanchet@38281
   145
   max_new_relevant_facts_per_iter = 60 (* FIXME *),
blanchet@37994
   146
   prefers_theory_relevant = false,
blanchet@37994
   147
   explicit_forall = false}
blanchet@38454
   148
blanchet@38023
   149
val e = ("e", e_config)
wenzelm@28596
   150
wenzelm@28596
   151
blanchet@36219
   152
(* The "-VarWeight=3" option helps the higher-order problems, probably by
blanchet@36219
   153
   counteracting the presence of "hAPP". *)
blanchet@37498
   154
val spass_config : prover_config =
blanchet@38092
   155
  {exec = ("ISABELLE_ATP", "scripts/spass"),
blanchet@38092
   156
   required_execs = [("SPASS_HOME", "SPASS")],
blanchet@37550
   157
   (* "div 2" accounts for the fact that SPASS is often run twice. *)
blanchet@37514
   158
   arguments = fn complete => fn timeout =>
blanchet@37962
   159
     ("-Auto -PGiven=0 -PProblem=0 -Splits=0 -FullRed=0 -DocProof \
blanchet@37550
   160
      \-VarWeight=3 -TimeLimit=" ^
blanchet@38094
   161
      string_of_int ((to_generous_secs timeout + 1) div 2))
blanchet@37514
   162
     |> not complete ? prefix "-SOS=1 ",
blanchet@36369
   163
   proof_delims = [("Here is a proof", "Formulae used in the proof")],
blanchet@36289
   164
   known_failures =
blanchet@38061
   165
     known_perl_failures @
blanchet@37413
   166
     [(IncompleteUnprovable, "SPASS beiseite: Completion found"),
blanchet@36370
   167
      (TimedOut, "SPASS beiseite: Ran out of time"),
blanchet@36965
   168
      (OutOfResources, "SPASS beiseite: Maximal number of loops exceeded"),
blanchet@37413
   169
      (MalformedInput, "Undefined symbol"),
blanchet@37414
   170
      (MalformedInput, "Free Variable"),
blanchet@37962
   171
      (OldSpass, "tptp2dfg")],
blanchet@38090
   172
   max_new_relevant_facts_per_iter = 35 (* FIXME *),
blanchet@37994
   173
   prefers_theory_relevant = true,
blanchet@37994
   174
   explicit_forall = true}
blanchet@38454
   175
blanchet@38023
   176
val spass = ("spass", spass_config)
wenzelm@28596
   177
blanchet@38454
   178
blanchet@37509
   179
(* Vampire *)
blanchet@37509
   180
blanchet@37509
   181
val vampire_config : prover_config =
blanchet@38092
   182
  {exec = ("VAMPIRE_HOME", "vampire"),
blanchet@38092
   183
   required_execs = [],
blanchet@37514
   184
   arguments = fn _ => fn timeout =>
blanchet@38033
   185
     "--mode casc -t " ^ string_of_int (to_generous_secs timeout) ^
blanchet@38033
   186
     " --input_file ",
blanchet@37509
   187
   proof_delims =
blanchet@37509
   188
     [("=========== Refutation ==========",
blanchet@37509
   189
       "======= End of refutation ======="),
blanchet@38033
   190
      ("% SZS output start Refutation", "% SZS output end Refutation"),
blanchet@38033
   191
      ("% SZS output start Proof", "% SZS output end Proof")],
blanchet@37509
   192
   known_failures =
blanchet@37509
   193
     [(Unprovable, "UNPROVABLE"),
blanchet@37509
   194
      (IncompleteUnprovable, "CANNOT PROVE"),
blanchet@38092
   195
      (TimedOut, "SZS status Timeout"),
blanchet@37509
   196
      (Unprovable, "Satisfiability detected"),
blanchet@38454
   197
      (OutOfResources, "Refutation not found"),
blanchet@38454
   198
      (OldVampire, "input_file")],
blanchet@38090
   199
   max_new_relevant_facts_per_iter = 50 (* FIXME *),
blanchet@37994
   200
   prefers_theory_relevant = false,
blanchet@37994
   201
   explicit_forall = false}
blanchet@38454
   202
blanchet@38023
   203
val vampire = ("vampire", vampire_config)
blanchet@37509
   204
blanchet@38454
   205
blanchet@37509
   206
(* Remote prover invocation via SystemOnTPTP *)
wenzelm@28596
   207
blanchet@38061
   208
val systems = Synchronized.var "atp_systems" ([] : string list)
immler@31835
   209
immler@31835
   210
fun get_systems () =
blanchet@38061
   211
  case bash_output "\"$ISABELLE_ATP/scripts/remote_atp\" -w 2>&1" of
blanchet@36370
   212
    (answer, 0) => split_lines answer
blanchet@36370
   213
  | (answer, _) =>
blanchet@38065
   214
    error (case known_failure_in_output answer known_perl_failures of
blanchet@38065
   215
             SOME failure => string_for_failure failure
blanchet@38065
   216
           | NONE => perhaps (try (unsuffix "\n")) answer ^ ".")
immler@31835
   217
blanchet@35867
   218
fun refresh_systems_on_tptp () =
blanchet@37509
   219
  Synchronized.change systems (fn _ => get_systems ())
immler@31835
   220
immler@31835
   221
fun get_system prefix = Synchronized.change_result systems (fn systems =>
boehmes@32864
   222
  (if null systems then get_systems () else systems)
wenzelm@32942
   223
  |> `(find_first (String.isPrefix prefix)));
boehmes@32864
   224
wenzelm@32948
   225
fun the_system prefix =
boehmes@32864
   226
  (case get_system prefix of
blanchet@37509
   227
    NONE => error ("System " ^ quote prefix ^ " not available at SystemOnTPTP.")
wenzelm@32942
   228
  | SOME sys => sys);
immler@31835
   229
blanchet@38041
   230
fun remote_config atp_prefix
blanchet@38009
   231
        ({proof_delims, known_failures, max_new_relevant_facts_per_iter,
blanchet@38433
   232
          prefers_theory_relevant, ...} : prover_config) : prover_config =
blanchet@38092
   233
  {exec = ("ISABELLE_ATP", "scripts/remote_atp"),
blanchet@38092
   234
   required_execs = [],
blanchet@37514
   235
   arguments = fn _ => fn timeout =>
blanchet@38041
   236
     " -t " ^ string_of_int (to_generous_secs timeout) ^ " -s " ^
blanchet@36382
   237
     the_system atp_prefix,
blanchet@36369
   238
   proof_delims = insert (op =) tstp_proof_delims proof_delims,
blanchet@38061
   239
   known_failures =
blanchet@38061
   240
     known_failures @ known_perl_failures @
blanchet@38094
   241
     [(TimedOut, "says Timeout")],
blanchet@38009
   242
   max_new_relevant_facts_per_iter = max_new_relevant_facts_per_iter,
blanchet@37994
   243
   prefers_theory_relevant = prefers_theory_relevant,
blanchet@38433
   244
   explicit_forall = true}
wenzelm@28596
   245
blanchet@38023
   246
val remote_name = prefix "remote_"
blanchet@38041
   247
fun remote_prover (name, config) atp_prefix =
blanchet@38041
   248
  (remote_name name, remote_config atp_prefix config)
blanchet@38023
   249
blanchet@38041
   250
val remote_e = remote_prover e "EP---"
blanchet@38041
   251
val remote_vampire = remote_prover vampire "Vampire---9"
wenzelm@28592
   252
blanchet@38454
   253
blanchet@38454
   254
(* Setup *)
blanchet@38454
   255
blanchet@38092
   256
fun is_installed ({exec, required_execs, ...} : prover_config) =
blanchet@38092
   257
  forall (curry (op <>) "" o getenv o fst) (exec :: required_execs)
blanchet@38041
   258
fun maybe_remote (name, config) =
blanchet@38041
   259
  name |> not (is_installed config) ? remote_name
blanchet@36371
   260
blanchet@36371
   261
fun default_atps_param_value () =
blanchet@38041
   262
  space_implode " " ([maybe_remote e] @
blanchet@38041
   263
                     (if is_installed (snd spass) then [fst spass] else []) @
blanchet@38041
   264
                     [remote_name (fst vampire)])
blanchet@36371
   265
blanchet@38041
   266
val provers = [e, spass, vampire, remote_e, remote_vampire]
blanchet@38023
   267
val setup = fold add_prover provers
blanchet@35867
   268
wenzelm@28592
   269
end;