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