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