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