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