src/HOL/Tools/ATP/atp_systems.ML
author blanchet
Wed Jul 28 19:04:59 2010 +0200 (2010-07-28)
changeset 38047 9033c03cc214
parent 38046 6659c15e7421
child 38049 327705ac4759
permissions -rw-r--r--
consequence of directory renaming
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@38023
    11
    Unprovable | IncompleteUnprovable | CantConnect | TimedOut |
blanchet@38023
    12
    OutOfResources | OldSpass | MalformedInput | MalformedOutput | UnknownError
blanchet@38023
    13
blanchet@38023
    14
  type prover_config =
blanchet@38032
    15
    {executable: string * string,
blanchet@38032
    16
     required_executables: (string * string) list,
blanchet@38023
    17
     arguments: bool -> Time.time -> string,
blanchet@38023
    18
     proof_delims: (string * string) list,
blanchet@38023
    19
     known_failures: (failure * string) list,
blanchet@38023
    20
     max_new_relevant_facts_per_iter: int,
blanchet@38023
    21
     prefers_theory_relevant: bool,
blanchet@38023
    22
     explicit_forall: bool}
blanchet@38023
    23
blanchet@38023
    24
  val add_prover: string * prover_config -> theory -> theory
blanchet@38023
    25
  val get_prover: theory -> string -> prover_config
blanchet@38023
    26
  val available_atps: theory -> unit
blanchet@35867
    27
  val refresh_systems_on_tptp : unit -> unit
blanchet@36371
    28
  val default_atps_param_value : unit -> string
blanchet@35867
    29
  val setup : theory -> theory
wenzelm@28592
    30
end;
wenzelm@28592
    31
blanchet@36376
    32
structure ATP_Systems : ATP_SYSTEMS =
wenzelm@28592
    33
struct
wenzelm@28596
    34
blanchet@38023
    35
(* prover configuration *)
boehmes@32864
    36
blanchet@38023
    37
datatype failure =
blanchet@38023
    38
  Unprovable | IncompleteUnprovable | CantConnect | TimedOut | OutOfResources |
blanchet@38023
    39
  OldSpass | MalformedInput | MalformedOutput | UnknownError
boehmes@32864
    40
wenzelm@32941
    41
type prover_config =
blanchet@38032
    42
  {executable: string * string,
blanchet@38032
    43
   required_executables: (string * string) list,
blanchet@37514
    44
   arguments: bool -> Time.time -> string,
blanchet@36370
    45
   proof_delims: (string * string) list,
blanchet@36370
    46
   known_failures: (failure * string) list,
blanchet@38009
    47
   max_new_relevant_facts_per_iter: int,
blanchet@37994
    48
   prefers_theory_relevant: bool,
blanchet@37994
    49
   explicit_forall: bool}
wenzelm@28596
    50
wenzelm@28596
    51
blanchet@38023
    52
(* named provers *)
blanchet@38001
    53
blanchet@38023
    54
structure Data = Theory_Data
blanchet@38023
    55
(
blanchet@38023
    56
  type T = (prover_config * stamp) Symtab.table
blanchet@38023
    57
  val empty = Symtab.empty
blanchet@38023
    58
  val extend = I
blanchet@38023
    59
  fun merge data : T = Symtab.merge (eq_snd op =) data
blanchet@38023
    60
    handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@38023
    61
)
blanchet@38017
    62
blanchet@38023
    63
fun add_prover (name, config) thy =
blanchet@38023
    64
  Data.map (Symtab.update_new (name, (config, stamp ()))) thy
blanchet@38023
    65
  handle Symtab.DUP name => error ("Duplicate ATP: " ^ quote name ^ ".")
blanchet@38017
    66
blanchet@38023
    67
fun get_prover thy name =
blanchet@38023
    68
  the (Symtab.lookup (Data.get thy) name) |> fst
blanchet@38023
    69
  handle Option.Option => error ("Unknown ATP: " ^ name ^ ".")
blanchet@37962
    70
blanchet@38023
    71
fun available_atps thy =
blanchet@38023
    72
  priority ("Available ATPs: " ^
blanchet@38023
    73
            commas (sort_strings (Symtab.keys (Data.get thy))) ^ ".")
boehmes@32864
    74
blanchet@38023
    75
fun available_atps thy =
blanchet@38023
    76
  priority ("Available ATPs: " ^
blanchet@38023
    77
            commas (sort_strings (Symtab.keys (Data.get thy))) ^ ".")
wenzelm@28596
    78
blanchet@36382
    79
fun to_generous_secs time = (Time.toMilliseconds time + 999) div 1000
blanchet@36142
    80
wenzelm@28596
    81
(* E prover *)
wenzelm@28596
    82
blanchet@36369
    83
val tstp_proof_delims =
blanchet@36369
    84
  ("# SZS output start CNFRefutation.", "# SZS output end CNFRefutation")
blanchet@36369
    85
blanchet@35969
    86
val e_config : prover_config =
blanchet@38032
    87
  {executable = ("E_HOME", "eproof"),
blanchet@38032
    88
   required_executables = [],
blanchet@37514
    89
   arguments = fn _ => fn timeout =>
blanchet@36382
    90
     "--tstp-in --tstp-out -l5 -xAutoDev -tAutoDev --silent --cpu-limit=" ^
blanchet@36382
    91
     string_of_int (to_generous_secs timeout),
blanchet@36369
    92
   proof_delims = [tstp_proof_delims],
blanchet@36265
    93
   known_failures =
blanchet@37995
    94
     [(Unprovable, "SZS status: CounterSatisfiable"),
blanchet@37995
    95
      (Unprovable, "SZS status CounterSatisfiable"),
blanchet@36370
    96
      (TimedOut, "Failure: Resource limit exceeded (time)"),
blanchet@36370
    97
      (TimedOut, "time limit exceeded"),
blanchet@36370
    98
      (OutOfResources,
blanchet@36370
    99
       "# Cannot determine problem status within resource limit"),
blanchet@36370
   100
      (OutOfResources, "SZS status: ResourceOut"),
blanchet@36370
   101
      (OutOfResources, "SZS status ResourceOut")],
blanchet@38009
   102
   max_new_relevant_facts_per_iter = 80 (* FIXME *),
blanchet@37994
   103
   prefers_theory_relevant = false,
blanchet@37994
   104
   explicit_forall = false}
blanchet@38023
   105
val e = ("e", e_config)
wenzelm@28596
   106
wenzelm@28596
   107
blanchet@36219
   108
(* The "-VarWeight=3" option helps the higher-order problems, probably by
blanchet@36219
   109
   counteracting the presence of "hAPP". *)
blanchet@37498
   110
val spass_config : prover_config =
blanchet@38041
   111
  {executable = ("ISABELLE_ATP_MANAGER", "scripts/spass"),
blanchet@38032
   112
   required_executables = [("SPASS_HOME", "SPASS")],
blanchet@37550
   113
   (* "div 2" accounts for the fact that SPASS is often run twice. *)
blanchet@37514
   114
   arguments = fn complete => fn timeout =>
blanchet@37962
   115
     ("-Auto -PGiven=0 -PProblem=0 -Splits=0 -FullRed=0 -DocProof \
blanchet@37550
   116
      \-VarWeight=3 -TimeLimit=" ^
blanchet@37550
   117
      string_of_int (to_generous_secs timeout div 2))
blanchet@37514
   118
     |> not complete ? prefix "-SOS=1 ",
blanchet@36369
   119
   proof_delims = [("Here is a proof", "Formulae used in the proof")],
blanchet@36289
   120
   known_failures =
blanchet@37413
   121
     [(IncompleteUnprovable, "SPASS beiseite: Completion found"),
blanchet@36370
   122
      (TimedOut, "SPASS beiseite: Ran out of time"),
blanchet@36965
   123
      (OutOfResources, "SPASS beiseite: Maximal number of loops exceeded"),
blanchet@37413
   124
      (MalformedInput, "Undefined symbol"),
blanchet@37414
   125
      (MalformedInput, "Free Variable"),
blanchet@37962
   126
      (OldSpass, "tptp2dfg")],
blanchet@38009
   127
   max_new_relevant_facts_per_iter = 26 (* FIXME *),
blanchet@37994
   128
   prefers_theory_relevant = true,
blanchet@37994
   129
   explicit_forall = true}
blanchet@38023
   130
val spass = ("spass", spass_config)
wenzelm@28596
   131
blanchet@37509
   132
(* Vampire *)
blanchet@37509
   133
blanchet@37509
   134
val vampire_config : prover_config =
blanchet@38032
   135
  {executable = ("VAMPIRE_HOME", "vampire"),
blanchet@38032
   136
   required_executables = [],
blanchet@37514
   137
   arguments = fn _ => fn timeout =>
blanchet@38033
   138
     "--mode casc -t " ^ string_of_int (to_generous_secs timeout) ^
blanchet@38033
   139
     " --input_file ",
blanchet@37509
   140
   proof_delims =
blanchet@37509
   141
     [("=========== Refutation ==========",
blanchet@37509
   142
       "======= End of refutation ======="),
blanchet@38033
   143
      ("% SZS output start Refutation", "% SZS output end Refutation"),
blanchet@38033
   144
      ("% SZS output start Proof", "% SZS output end Proof")],
blanchet@37509
   145
   known_failures =
blanchet@37509
   146
     [(Unprovable, "UNPROVABLE"),
blanchet@37509
   147
      (IncompleteUnprovable, "CANNOT PROVE"),
blanchet@37509
   148
      (Unprovable, "Satisfiability detected"),
blanchet@37509
   149
      (OutOfResources, "Refutation not found")],
blanchet@38009
   150
   max_new_relevant_facts_per_iter = 40 (* FIXME *),
blanchet@37994
   151
   prefers_theory_relevant = false,
blanchet@37994
   152
   explicit_forall = false}
blanchet@38023
   153
val vampire = ("vampire", vampire_config)
blanchet@37509
   154
blanchet@37509
   155
(* Remote prover invocation via SystemOnTPTP *)
wenzelm@28596
   156
blanchet@38023
   157
val systems = Synchronized.var "atp_systems" ([]: string list)
immler@31835
   158
immler@31835
   159
fun get_systems () =
blanchet@38041
   160
  case bash_output "\"$ISABELLE_ATP_MANAGER/scripts/remote_atp\" -w" of
blanchet@36370
   161
    (answer, 0) => split_lines answer
blanchet@36370
   162
  | (answer, _) =>
blanchet@37627
   163
    error ("Failed to get available systems at SystemOnTPTP:\n" ^
blanchet@37627
   164
           perhaps (try (unsuffix "\n")) answer)
immler@31835
   165
blanchet@35867
   166
fun refresh_systems_on_tptp () =
blanchet@37509
   167
  Synchronized.change systems (fn _ => get_systems ())
immler@31835
   168
immler@31835
   169
fun get_system prefix = Synchronized.change_result systems (fn systems =>
boehmes@32864
   170
  (if null systems then get_systems () else systems)
wenzelm@32942
   171
  |> `(find_first (String.isPrefix prefix)));
boehmes@32864
   172
wenzelm@32948
   173
fun the_system prefix =
boehmes@32864
   174
  (case get_system prefix of
blanchet@37509
   175
    NONE => error ("System " ^ quote prefix ^ " not available at SystemOnTPTP.")
wenzelm@32942
   176
  | SOME sys => sys);
immler@31835
   177
blanchet@36265
   178
val remote_known_failures =
blanchet@37627
   179
  [(CantConnect, "HTTP-Error"),
blanchet@37627
   180
   (TimedOut, "says Timeout"),
blanchet@36377
   181
   (MalformedOutput, "Remote script could not extract proof")]
blanchet@35865
   182
blanchet@38041
   183
fun remote_config atp_prefix
blanchet@38009
   184
        ({proof_delims, known_failures, max_new_relevant_facts_per_iter,
blanchet@37994
   185
          prefers_theory_relevant, explicit_forall, ...} : prover_config)
blanchet@37994
   186
        : prover_config =
blanchet@38041
   187
  {executable = ("ISABELLE_ATP_MANAGER", "scripts/remote_atp"),
blanchet@38032
   188
   required_executables = [],
blanchet@37514
   189
   arguments = fn _ => fn timeout =>
blanchet@38041
   190
     " -t " ^ string_of_int (to_generous_secs timeout) ^ " -s " ^
blanchet@36382
   191
     the_system atp_prefix,
blanchet@36369
   192
   proof_delims = insert (op =) tstp_proof_delims proof_delims,
blanchet@36265
   193
   known_failures = remote_known_failures @ known_failures,
blanchet@38009
   194
   max_new_relevant_facts_per_iter = max_new_relevant_facts_per_iter,
blanchet@37994
   195
   prefers_theory_relevant = prefers_theory_relevant,
blanchet@37994
   196
   explicit_forall = explicit_forall}
wenzelm@28596
   197
blanchet@38023
   198
val remote_name = prefix "remote_"
boehmes@32864
   199
blanchet@38041
   200
fun remote_prover (name, config) atp_prefix =
blanchet@38041
   201
  (remote_name name, remote_config atp_prefix config)
blanchet@38023
   202
blanchet@38041
   203
val remote_e = remote_prover e "EP---"
blanchet@38041
   204
val remote_vampire = remote_prover vampire "Vampire---9"
wenzelm@28592
   205
blanchet@38041
   206
fun is_installed ({executable, required_executables, ...} : prover_config) =
blanchet@38041
   207
  forall (curry (op <>) "" o getenv o fst) (executable :: required_executables)
blanchet@38041
   208
fun maybe_remote (name, config) =
blanchet@38041
   209
  name |> not (is_installed config) ? remote_name
blanchet@36371
   210
blanchet@36371
   211
fun default_atps_param_value () =
blanchet@38041
   212
  space_implode " " ([maybe_remote e] @
blanchet@38041
   213
                     (if is_installed (snd spass) then [fst spass] else []) @
blanchet@38041
   214
                     [remote_name (fst vampire)])
blanchet@36371
   215
blanchet@38041
   216
val provers = [e, spass, vampire, remote_e, remote_vampire]
blanchet@38023
   217
val setup = fold add_prover provers
blanchet@35867
   218
wenzelm@28592
   219
end;