src/HOL/Tools/ATP/atp_systems.ML
author blanchet
Thu Sep 09 16:27:36 2010 +0200 (2010-09-09)
changeset 39263 e2a3c435334b
parent 39262 bdfcf2434601
child 39319 da4e98cb2005
permissions -rw-r--r--
more precise error messages when Vampire is interrupted or SPASS runs into an internal bug
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@38519
    11
    Unprovable | IncompleteUnprovable | CantConnect | TimedOut |
blanchet@38519
    12
    OutOfResources | SpassTooOld | VampireTooOld | NoPerl | NoLibwwwPerl |
blanchet@39263
    13
    MalformedInput | MalformedOutput | Interrupted | InternalError |
blanchet@39263
    14
    UnknownError
blanchet@38023
    15
blanchet@38023
    16
  type prover_config =
blanchet@38092
    17
    {exec: string * string,
blanchet@38092
    18
     required_execs: (string * string) list,
blanchet@38023
    19
     arguments: bool -> Time.time -> string,
blanchet@38645
    20
     has_incomplete_mode: bool,
blanchet@38023
    21
     proof_delims: (string * string) list,
blanchet@38023
    22
     known_failures: (failure * string) list,
blanchet@38744
    23
     default_max_relevant: int,
blanchet@38631
    24
     explicit_forall: bool,
blanchet@38631
    25
     use_conjecture_for_hypotheses: bool}
blanchet@38023
    26
blanchet@38061
    27
  val string_for_failure : failure -> string
blanchet@38061
    28
  val known_failure_in_output :
blanchet@38061
    29
    string -> (failure * string) list -> failure option
blanchet@38023
    30
  val add_prover: string * prover_config -> theory -> theory
blanchet@38023
    31
  val get_prover: theory -> string -> prover_config
blanchet@38023
    32
  val available_atps: theory -> unit
blanchet@35867
    33
  val refresh_systems_on_tptp : unit -> unit
blanchet@36371
    34
  val default_atps_param_value : unit -> string
blanchet@35867
    35
  val setup : theory -> theory
wenzelm@28592
    36
end;
wenzelm@28592
    37
blanchet@36376
    38
structure ATP_Systems : ATP_SYSTEMS =
wenzelm@28592
    39
struct
wenzelm@28596
    40
blanchet@38023
    41
(* prover configuration *)
boehmes@32864
    42
blanchet@38023
    43
datatype failure =
blanchet@38454
    44
  Unprovable | IncompleteUnprovable | CantConnect | TimedOut | OutOfResources |
blanchet@38519
    45
  SpassTooOld | VampireTooOld | NoPerl | NoLibwwwPerl | MalformedInput |
blanchet@39263
    46
  MalformedOutput | Interrupted | InternalError | UnknownError
boehmes@32864
    47
wenzelm@32941
    48
type prover_config =
blanchet@38092
    49
  {exec: string * string,
blanchet@38092
    50
   required_execs: (string * string) list,
blanchet@37514
    51
   arguments: bool -> Time.time -> string,
blanchet@38645
    52
   has_incomplete_mode: bool,
blanchet@36370
    53
   proof_delims: (string * string) list,
blanchet@36370
    54
   known_failures: (failure * string) list,
blanchet@38744
    55
   default_max_relevant: int,
blanchet@38631
    56
   explicit_forall: bool,
blanchet@38631
    57
   use_conjecture_for_hypotheses: bool}
wenzelm@28596
    58
blanchet@38061
    59
val missing_message_tail =
blanchet@38061
    60
  " appears to be missing. You will need to install it if you want to run \
blanchet@38061
    61
  \ATPs remotely."
blanchet@38061
    62
blanchet@38061
    63
fun string_for_failure Unprovable = "The ATP problem is unprovable."
blanchet@38061
    64
  | string_for_failure IncompleteUnprovable =
blanchet@38061
    65
    "The ATP cannot prove the problem."
blanchet@38094
    66
  | string_for_failure CantConnect = "Can't connect to remote server."
blanchet@38061
    67
  | string_for_failure TimedOut = "Timed out."
blanchet@38061
    68
  | string_for_failure OutOfResources = "The ATP ran out of resources."
blanchet@38519
    69
  | string_for_failure SpassTooOld =
blanchet@38096
    70
    "Isabelle requires a more recent version of SPASS with support for the \
blanchet@38096
    71
    \TPTP syntax. To install it, download and extract the package \
blanchet@38096
    72
    \\"http://isabelle.in.tum.de/dist/contrib/spass-3.7.tar.gz\" and add the \
blanchet@38096
    73
    \\"spass-3.7\" directory's absolute path to " ^
blanchet@38061
    74
    quote (Path.implode (Path.expand (Path.appends
blanchet@38061
    75
               (Path.variable "ISABELLE_HOME_USER" ::
blanchet@38061
    76
                map Path.basic ["etc", "components"])))) ^
blanchet@38061
    77
    " on a line of its own."
blanchet@38519
    78
  | string_for_failure VampireTooOld =
blanchet@38454
    79
    "Isabelle requires a more recent version of Vampire. To install it, follow \
blanchet@38454
    80
    \the instructions from the Sledgehammer manual (\"isabelle doc\
blanchet@38454
    81
    \ sledgehammer\")."
blanchet@38061
    82
  | string_for_failure NoPerl = "Perl" ^ missing_message_tail
blanchet@38061
    83
  | string_for_failure NoLibwwwPerl =
blanchet@38061
    84
    "The Perl module \"libwww-perl\"" ^ missing_message_tail
blanchet@38061
    85
  | string_for_failure MalformedInput =
blanchet@38096
    86
    "The ATP problem is malformed. Please report this to the Isabelle \
blanchet@38096
    87
    \developers."
blanchet@38096
    88
  | string_for_failure MalformedOutput = "The ATP output is malformed."
blanchet@39262
    89
  | string_for_failure Interrupted = "The ATP was interrupted."
blanchet@39263
    90
  | string_for_failure InternalError = "An internal ATP error occurred."
blanchet@38096
    91
  | string_for_failure UnknownError = "An unknown ATP error occurred."
blanchet@38061
    92
blanchet@38061
    93
fun known_failure_in_output output =
blanchet@38061
    94
  find_first (fn (_, pattern) => String.isSubstring pattern output)
blanchet@38061
    95
  #> Option.map fst
blanchet@38061
    96
blanchet@38061
    97
val known_perl_failures =
blanchet@38094
    98
  [(CantConnect, "HTTP error"),
blanchet@38094
    99
   (NoPerl, "env: perl"),
blanchet@38065
   100
   (NoLibwwwPerl, "Can't locate HTTP")]
wenzelm@28596
   101
blanchet@38023
   102
(* named provers *)
blanchet@38001
   103
blanchet@38023
   104
structure Data = Theory_Data
blanchet@38023
   105
(
blanchet@38023
   106
  type T = (prover_config * stamp) Symtab.table
blanchet@38023
   107
  val empty = Symtab.empty
blanchet@38023
   108
  val extend = I
blanchet@38023
   109
  fun merge data : T = Symtab.merge (eq_snd op =) data
blanchet@38023
   110
    handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@38023
   111
)
blanchet@38017
   112
blanchet@38023
   113
fun add_prover (name, config) thy =
blanchet@38023
   114
  Data.map (Symtab.update_new (name, (config, stamp ()))) thy
blanchet@38023
   115
  handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@38017
   116
blanchet@38023
   117
fun get_prover thy name =
blanchet@38023
   118
  the (Symtab.lookup (Data.get thy) name) |> fst
blanchet@38023
   119
  handle Option.Option => error ("Unknown ATP: " ^ name ^ ".")
blanchet@37962
   120
blanchet@38023
   121
fun available_atps thy =
blanchet@38023
   122
  priority ("Available ATPs: " ^
blanchet@38023
   123
            commas (sort_strings (Symtab.keys (Data.get thy))) ^ ".")
boehmes@32864
   124
blanchet@38023
   125
fun available_atps thy =
blanchet@38023
   126
  priority ("Available ATPs: " ^
blanchet@38023
   127
            commas (sort_strings (Symtab.keys (Data.get thy))) ^ ".")
wenzelm@28596
   128
blanchet@38737
   129
fun to_secs bonus time = (Time.toMilliseconds time + bonus + 999) div 1000
blanchet@36142
   130
wenzelm@28596
   131
(* E prover *)
wenzelm@28596
   132
blanchet@38737
   133
(* Give older versions of E an extra second, because the "eproof" script wrongly
blanchet@38737
   134
   subtracted an entire second to account for the overhead of the script
blanchet@38737
   135
   itself, which is in fact much lower. *)
blanchet@38737
   136
fun e_bonus () =
blanchet@38737
   137
  case getenv "E_VERSION" of
blanchet@38737
   138
    "" => 1000
blanchet@38737
   139
  | version =>
blanchet@38737
   140
    if exists (fn s => String.isPrefix s version) ["0.9", "1.0"] then 1000
blanchet@38737
   141
    else 0
blanchet@38737
   142
blanchet@36369
   143
val tstp_proof_delims =
blanchet@36369
   144
  ("# SZS output start CNFRefutation.", "# SZS output end CNFRefutation")
blanchet@36369
   145
blanchet@35969
   146
val e_config : prover_config =
blanchet@38092
   147
  {exec = ("E_HOME", "eproof"),
blanchet@38092
   148
   required_execs = [],
blanchet@37514
   149
   arguments = fn _ => fn timeout =>
blanchet@38691
   150
     "--tstp-in --tstp-out -l5 -xAutoDev -tAutoDev --silent \
blanchet@38737
   151
     \--cpu-limit=" ^ string_of_int (to_secs (e_bonus ()) timeout),
blanchet@38645
   152
   has_incomplete_mode = false,
blanchet@36369
   153
   proof_delims = [tstp_proof_delims],
blanchet@36265
   154
   known_failures =
blanchet@37995
   155
     [(Unprovable, "SZS status: CounterSatisfiable"),
blanchet@37995
   156
      (Unprovable, "SZS status CounterSatisfiable"),
blanchet@36370
   157
      (TimedOut, "Failure: Resource limit exceeded (time)"),
blanchet@36370
   158
      (TimedOut, "time limit exceeded"),
blanchet@36370
   159
      (OutOfResources,
blanchet@36370
   160
       "# Cannot determine problem status within resource limit"),
blanchet@36370
   161
      (OutOfResources, "SZS status: ResourceOut"),
blanchet@36370
   162
      (OutOfResources, "SZS status ResourceOut")],
blanchet@38744
   163
   default_max_relevant = 500 (* FUDGE *),
blanchet@38631
   164
   explicit_forall = false,
blanchet@38631
   165
   use_conjecture_for_hypotheses = true}
blanchet@38454
   166
blanchet@38023
   167
val e = ("e", e_config)
wenzelm@28596
   168
wenzelm@28596
   169
blanchet@36219
   170
(* The "-VarWeight=3" option helps the higher-order problems, probably by
blanchet@36219
   171
   counteracting the presence of "hAPP". *)
blanchet@37498
   172
val spass_config : prover_config =
blanchet@38092
   173
  {exec = ("ISABELLE_ATP", "scripts/spass"),
blanchet@39002
   174
   required_execs = [("SPASS_HOME", "SPASS"), ("SPASS_HOME", "tptp2dfg")],
blanchet@37514
   175
   arguments = fn complete => fn timeout =>
blanchet@37962
   176
     ("-Auto -PGiven=0 -PProblem=0 -Splits=0 -FullRed=0 -DocProof \
blanchet@38737
   177
      \-VarWeight=3 -TimeLimit=" ^ string_of_int (to_secs 0 timeout))
blanchet@37514
   178
     |> not complete ? prefix "-SOS=1 ",
blanchet@38645
   179
   has_incomplete_mode = true,
blanchet@36369
   180
   proof_delims = [("Here is a proof", "Formulae used in the proof")],
blanchet@36289
   181
   known_failures =
blanchet@38061
   182
     known_perl_failures @
blanchet@37413
   183
     [(IncompleteUnprovable, "SPASS beiseite: Completion found"),
blanchet@36370
   184
      (TimedOut, "SPASS beiseite: Ran out of time"),
blanchet@36965
   185
      (OutOfResources, "SPASS beiseite: Maximal number of loops exceeded"),
blanchet@37413
   186
      (MalformedInput, "Undefined symbol"),
blanchet@37414
   187
      (MalformedInput, "Free Variable"),
blanchet@39263
   188
      (SpassTooOld, "tptp2dfg"),
blanchet@39263
   189
      (InternalError, "Please report this error")],
blanchet@38744
   190
   default_max_relevant = 350 (* FUDGE *),
blanchet@38631
   191
   explicit_forall = true,
blanchet@38631
   192
   use_conjecture_for_hypotheses = true}
blanchet@38454
   193
blanchet@38023
   194
val spass = ("spass", spass_config)
wenzelm@28596
   195
blanchet@38454
   196
blanchet@37509
   197
(* Vampire *)
blanchet@37509
   198
blanchet@37509
   199
val vampire_config : prover_config =
blanchet@38092
   200
  {exec = ("VAMPIRE_HOME", "vampire"),
blanchet@38092
   201
   required_execs = [],
blanchet@38744
   202
   arguments = fn complete => fn timeout =>
blanchet@38744
   203
     ("--mode casc -t " ^ string_of_int (to_secs 0 timeout) ^
blanchet@38744
   204
      " --thanks Andrei --input_file")
blanchet@38744
   205
     |> not complete ? prefix "--sos on ",
blanchet@38744
   206
   has_incomplete_mode = true,
blanchet@37509
   207
   proof_delims =
blanchet@37509
   208
     [("=========== Refutation ==========",
blanchet@37509
   209
       "======= End of refutation ======="),
blanchet@38033
   210
      ("% SZS output start Refutation", "% SZS output end Refutation"),
blanchet@38033
   211
      ("% SZS output start Proof", "% SZS output end Proof")],
blanchet@37509
   212
   known_failures =
blanchet@37509
   213
     [(Unprovable, "UNPROVABLE"),
blanchet@37509
   214
      (IncompleteUnprovable, "CANNOT PROVE"),
blanchet@38092
   215
      (TimedOut, "SZS status Timeout"),
blanchet@37509
   216
      (Unprovable, "Satisfiability detected"),
blanchet@38647
   217
      (Unprovable, "Termination reason: Satisfiable"),
blanchet@39263
   218
      (VampireTooOld, "not a valid option"),
blanchet@39263
   219
      (Interrupted, "Aborted by signal SIGINT")],
blanchet@38744
   220
   default_max_relevant = 400 (* FUDGE *),
blanchet@38631
   221
   explicit_forall = false,
blanchet@38680
   222
   use_conjecture_for_hypotheses = true}
blanchet@38454
   223
blanchet@38023
   224
val vampire = ("vampire", vampire_config)
blanchet@37509
   225
blanchet@38454
   226
blanchet@37509
   227
(* Remote prover invocation via SystemOnTPTP *)
wenzelm@28596
   228
blanchet@38061
   229
val systems = Synchronized.var "atp_systems" ([] : string list)
immler@31835
   230
immler@31835
   231
fun get_systems () =
blanchet@38061
   232
  case bash_output "\"$ISABELLE_ATP/scripts/remote_atp\" -w 2>&1" of
blanchet@36370
   233
    (answer, 0) => split_lines answer
blanchet@36370
   234
  | (answer, _) =>
blanchet@38065
   235
    error (case known_failure_in_output answer known_perl_failures of
blanchet@38065
   236
             SOME failure => string_for_failure failure
blanchet@38065
   237
           | NONE => perhaps (try (unsuffix "\n")) answer ^ ".")
immler@31835
   238
blanchet@35867
   239
fun refresh_systems_on_tptp () =
blanchet@37509
   240
  Synchronized.change systems (fn _ => get_systems ())
immler@31835
   241
blanchet@38690
   242
fun find_system name [] systems = find_first (String.isPrefix name) systems
blanchet@38690
   243
  | find_system name (version :: versions) systems =
blanchet@38690
   244
    case find_first (String.isPrefix (name ^ "---" ^ version)) systems of
blanchet@38690
   245
      NONE => find_system name versions systems
blanchet@38690
   246
    | res => res
blanchet@38690
   247
blanchet@38690
   248
fun get_system name versions =
blanchet@38589
   249
  Synchronized.change_result systems
blanchet@38589
   250
      (fn systems => (if null systems then get_systems () else systems)
blanchet@38690
   251
                     |> `(find_system name versions))
boehmes@32864
   252
blanchet@38690
   253
fun the_system name versions =
blanchet@38690
   254
  case get_system name versions of
blanchet@39010
   255
    SOME sys => sys
blanchet@39010
   256
  | NONE => error ("System " ^ quote name ^ " not available at SystemOnTPTP.")
immler@31835
   257
blanchet@38690
   258
fun remote_config system_name system_versions proof_delims known_failures
blanchet@38997
   259
                  default_max_relevant use_conjecture_for_hypotheses
blanchet@38997
   260
                  : prover_config =
blanchet@38092
   261
  {exec = ("ISABELLE_ATP", "scripts/remote_atp"),
blanchet@38092
   262
   required_execs = [],
blanchet@37514
   263
   arguments = fn _ => fn timeout =>
blanchet@38737
   264
     " -t " ^ string_of_int (to_secs 0 timeout) ^ " -s " ^
blanchet@38690
   265
     the_system system_name system_versions,
blanchet@38645
   266
   has_incomplete_mode = false,
blanchet@36369
   267
   proof_delims = insert (op =) tstp_proof_delims proof_delims,
blanchet@38061
   268
   known_failures =
blanchet@38061
   269
     known_failures @ known_perl_failures @
blanchet@38094
   270
     [(TimedOut, "says Timeout")],
blanchet@38744
   271
   default_max_relevant = default_max_relevant,
blanchet@38631
   272
   explicit_forall = true,
blanchet@38631
   273
   use_conjecture_for_hypotheses = use_conjecture_for_hypotheses}
wenzelm@28596
   274
blanchet@38690
   275
fun remotify_config system_name system_versions
blanchet@38744
   276
        ({proof_delims, known_failures, default_max_relevant,
blanchet@38997
   277
          use_conjecture_for_hypotheses, ...} : prover_config) : prover_config =
blanchet@38690
   278
  remote_config system_name system_versions proof_delims known_failures
blanchet@38997
   279
                default_max_relevant use_conjecture_for_hypotheses
blanchet@38023
   280
blanchet@38598
   281
val remotify_name = prefix "remote_"
blanchet@38690
   282
fun remote_prover name system_name system_versions proof_delims known_failures
blanchet@38997
   283
                  default_max_relevant use_conjecture_for_hypotheses =
blanchet@38598
   284
  (remotify_name name,
blanchet@38690
   285
   remote_config system_name system_versions proof_delims known_failures
blanchet@38997
   286
                 default_max_relevant use_conjecture_for_hypotheses)
blanchet@38690
   287
fun remotify_prover (name, config) system_name system_versions =
blanchet@38690
   288
  (remotify_name name, remotify_config system_name system_versions config)
wenzelm@28592
   289
blanchet@38690
   290
val remote_e = remotify_prover e "EP" ["1.0", "1.1", "1.2"]
blanchet@38817
   291
val remote_vampire = remotify_prover vampire "Vampire" ["9.0", "1.0", "0.6"]
blanchet@38603
   292
val remote_sine_e =
blanchet@39257
   293
  remote_prover "sine_e" "SInE" [] [] [(IncompleteUnprovable, "says Unknown")]
blanchet@38999
   294
                800 (* FUDGE *) true
blanchet@38598
   295
val remote_snark =
blanchet@38690
   296
  remote_prover "snark" "SNARK---" [] [("refutation.", "end_refutation.")] []
blanchet@39011
   297
                250 (* FUDGE *) true
blanchet@38454
   298
blanchet@38454
   299
(* Setup *)
blanchet@38454
   300
blanchet@38092
   301
fun is_installed ({exec, required_execs, ...} : prover_config) =
blanchet@38092
   302
  forall (curry (op <>) "" o getenv o fst) (exec :: required_execs)
blanchet@38041
   303
fun maybe_remote (name, config) =
blanchet@38598
   304
  name |> not (is_installed config) ? remotify_name
blanchet@36371
   305
blanchet@36371
   306
fun default_atps_param_value () =
blanchet@38041
   307
  space_implode " " ([maybe_remote e] @
blanchet@38041
   308
                     (if is_installed (snd spass) then [fst spass] else []) @
blanchet@38603
   309
                     [if forall (is_installed o snd) [e, spass] then
blanchet@38603
   310
                        remotify_name (fst vampire)
blanchet@38603
   311
                      else
blanchet@38603
   312
                        maybe_remote vampire,
blanchet@38603
   313
                      fst remote_sine_e])
blanchet@36371
   314
blanchet@38598
   315
val provers = [e, spass, vampire, remote_e, remote_vampire, remote_sine_e,
blanchet@38598
   316
               remote_snark]
blanchet@38023
   317
val setup = fold add_prover provers
blanchet@35867
   318
wenzelm@28592
   319
end;