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