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