src/HOL/Tools/ATP_Manager/atp_systems.ML
author blanchet
Tue Jul 27 18:33:10 2010 +0200 (2010-07-27)
changeset 38023 962b0a7f544b
parent 38022 d9c4d87838f3
child 38032 54448f5d151f
permissions -rw-r--r--
more refactoring
blanchet@36376
     1
(*  Title:      HOL/Tools/ATP_Manager/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@38023
    15
    {home_var: string,
blanchet@38023
    16
     executable: string,
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@36917
    42
  {home_var: string,
blanchet@36370
    43
   executable: string,
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@36917
    87
  {home_var = "E_HOME",
blanchet@36289
    88
   executable = "eproof",
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@37962
   111
  {home_var = "ISABELLE_ATP_MANAGER",
blanchet@37962
   112
   executable = "SPASS_TPTP",
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@37509
   135
  {home_var = "VAMPIRE_HOME",
blanchet@37509
   136
   executable = "vampire",
blanchet@37514
   137
   arguments = fn _ => fn timeout =>
blanchet@37509
   138
     "--output_syntax tptp --mode casc -t " ^
blanchet@37509
   139
     string_of_int (to_generous_secs timeout),
blanchet@37509
   140
   proof_delims =
blanchet@37509
   141
     [("=========== Refutation ==========",
blanchet@37509
   142
       "======= End of refutation ======="),
blanchet@37509
   143
      ("% SZS output start Refutation", "% SZS output end Refutation")],
blanchet@37509
   144
   known_failures =
blanchet@37509
   145
     [(Unprovable, "UNPROVABLE"),
blanchet@37509
   146
      (IncompleteUnprovable, "CANNOT PROVE"),
blanchet@37509
   147
      (Unprovable, "Satisfiability detected"),
blanchet@37509
   148
      (OutOfResources, "Refutation not found")],
blanchet@38009
   149
   max_new_relevant_facts_per_iter = 40 (* FIXME *),
blanchet@37994
   150
   prefers_theory_relevant = false,
blanchet@37994
   151
   explicit_forall = false}
blanchet@38023
   152
val vampire = ("vampire", vampire_config)
blanchet@37509
   153
blanchet@37509
   154
(* Remote prover invocation via SystemOnTPTP *)
wenzelm@28596
   155
blanchet@38023
   156
val systems = Synchronized.var "atp_systems" ([]: string list)
immler@31835
   157
immler@31835
   158
fun get_systems () =
blanchet@36370
   159
  case bash_output "\"$ISABELLE_ATP_MANAGER/SystemOnTPTP\" -w" of
blanchet@36370
   160
    (answer, 0) => split_lines answer
blanchet@36370
   161
  | (answer, _) =>
blanchet@37627
   162
    error ("Failed to get available systems at SystemOnTPTP:\n" ^
blanchet@37627
   163
           perhaps (try (unsuffix "\n")) answer)
immler@31835
   164
blanchet@35867
   165
fun refresh_systems_on_tptp () =
blanchet@37509
   166
  Synchronized.change systems (fn _ => get_systems ())
immler@31835
   167
immler@31835
   168
fun get_system prefix = Synchronized.change_result systems (fn systems =>
boehmes@32864
   169
  (if null systems then get_systems () else systems)
wenzelm@32942
   170
  |> `(find_first (String.isPrefix prefix)));
boehmes@32864
   171
wenzelm@32948
   172
fun the_system prefix =
boehmes@32864
   173
  (case get_system prefix of
blanchet@37509
   174
    NONE => error ("System " ^ quote prefix ^ " not available at SystemOnTPTP.")
wenzelm@32942
   175
  | SOME sys => sys);
immler@31835
   176
blanchet@36265
   177
val remote_known_failures =
blanchet@37627
   178
  [(CantConnect, "HTTP-Error"),
blanchet@37627
   179
   (TimedOut, "says Timeout"),
blanchet@36377
   180
   (MalformedOutput, "Remote script could not extract proof")]
blanchet@35865
   181
blanchet@37509
   182
fun remote_config atp_prefix args
blanchet@38009
   183
        ({proof_delims, known_failures, max_new_relevant_facts_per_iter,
blanchet@37994
   184
          prefers_theory_relevant, explicit_forall, ...} : prover_config)
blanchet@37994
   185
        : prover_config =
blanchet@36917
   186
  {home_var = "ISABELLE_ATP_MANAGER",
blanchet@36289
   187
   executable = "SystemOnTPTP",
blanchet@37514
   188
   arguments = fn _ => fn timeout =>
blanchet@36382
   189
     args ^ " -t " ^ string_of_int (to_generous_secs timeout) ^ " -s " ^
blanchet@36382
   190
     the_system atp_prefix,
blanchet@36369
   191
   proof_delims = insert (op =) tstp_proof_delims proof_delims,
blanchet@36265
   192
   known_failures = remote_known_failures @ known_failures,
blanchet@38009
   193
   max_new_relevant_facts_per_iter = max_new_relevant_facts_per_iter,
blanchet@37994
   194
   prefers_theory_relevant = prefers_theory_relevant,
blanchet@37994
   195
   explicit_forall = explicit_forall}
wenzelm@28596
   196
blanchet@38023
   197
val remote_name = prefix "remote_"
boehmes@32864
   198
blanchet@38023
   199
fun remote_prover prover atp_prefix args config =
blanchet@38023
   200
  (remote_name (fst prover), remote_config atp_prefix args config)
blanchet@38023
   201
blanchet@38023
   202
val remote_e = remote_prover e "EP---" "" e_config
blanchet@38023
   203
val remote_spass = remote_prover spass "SPASS---" "-x" spass_config
blanchet@38023
   204
val remote_vampire = remote_prover vampire "Vampire---9" "" vampire_config
wenzelm@28592
   205
blanchet@36917
   206
fun maybe_remote (name, _) ({home_var, ...} : prover_config) =
blanchet@38023
   207
  name |> getenv home_var = "" ? remote_name
blanchet@36371
   208
blanchet@36371
   209
fun default_atps_param_value () =
blanchet@36371
   210
  space_implode " " [maybe_remote e e_config, maybe_remote spass spass_config,
blanchet@38023
   211
                     remote_name (fst vampire)]
blanchet@36371
   212
blanchet@37509
   213
val provers = [e, spass, vampire, remote_e, remote_spass, remote_vampire]
blanchet@38023
   214
val setup = fold add_prover provers
blanchet@35867
   215
wenzelm@28592
   216
end;