src/HOL/Tools/Sledgehammer/sledgehammer_isar.ML
author blanchet
Mon Sep 05 14:42:31 2011 +0200 (2011-09-05 ago)
changeset 44720 f3a8c19708c8
parent 44651 5d6a11e166cf
child 44768 a7bc1bdb8bb4
permissions -rw-r--r--
fixed handling of "sledgehammer_params", so that "sledgehammer_params [e]" is really the same as "sledgehammer_params [provers = e]"
blanchet@36375
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_isar.ML
blanchet@35866
     2
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@35866
     3
blanchet@35866
     4
Adds "sledgehammer" and related commands to Isabelle/Isar's outer syntax.
blanchet@35866
     5
*)
blanchet@35866
     6
blanchet@35963
     7
signature SLEDGEHAMMER_ISAR =
blanchet@35963
     8
sig
blanchet@41087
     9
  type params = Sledgehammer_Provers.params
blanchet@35963
    10
blanchet@43020
    11
  val sledgehammerN : string
blanchet@39318
    12
  val auto : bool Unsynchronized.ref
blanchet@40059
    13
  val provers : string Unsynchronized.ref
blanchet@39318
    14
  val timeout : int Unsynchronized.ref
blanchet@40069
    15
  val default_params : Proof.context -> (string * string) list -> params
blanchet@39318
    16
  val setup : theory -> theory
blanchet@35963
    17
end;
blanchet@35963
    18
blanchet@35971
    19
structure Sledgehammer_Isar : SLEDGEHAMMER_ISAR =
blanchet@35866
    20
struct
blanchet@35866
    21
blanchet@38028
    22
open ATP_Systems
blanchet@43085
    23
open ATP_Translate
blanchet@35971
    24
open Sledgehammer_Util
blanchet@44462
    25
open Sledgehammer_Filter
blanchet@41087
    26
open Sledgehammer_Provers
blanchet@38988
    27
open Sledgehammer_Minimize
blanchet@41087
    28
open Sledgehammer_Run
blanchet@35866
    29
blanchet@43020
    30
val sledgehammerN = "sledgehammer"
blanchet@43020
    31
val sledgehammer_paramsN = "sledgehammer_params"
blanchet@43020
    32
blanchet@43020
    33
val runN = "run"
blanchet@43020
    34
val minN = "min"
blanchet@43020
    35
val messagesN = "messages"
blanchet@43020
    36
val supported_proversN = "supported_provers"
blanchet@43020
    37
val running_proversN = "running_provers"
blanchet@43020
    38
val kill_proversN = "kill_provers"
blanchet@43020
    39
val refresh_tptpN = "refresh_tptp"
blanchet@43020
    40
blanchet@39318
    41
val auto = Unsynchronized.ref false
blanchet@39318
    42
blanchet@39318
    43
val _ =
blanchet@39318
    44
  ProofGeneralPgip.add_preference Preferences.category_tracing
blanchet@39318
    45
      (Preferences.bool_pref auto "auto-sledgehammer"
blanchet@39327
    46
           "Run Sledgehammer automatically.")
blanchet@39318
    47
blanchet@36394
    48
(** Sledgehammer commands **)
blanchet@36394
    49
blanchet@39318
    50
fun add_relevance_override ns : relevance_override =
blanchet@35966
    51
  {add = ns, del = [], only = false}
blanchet@39318
    52
fun del_relevance_override ns : relevance_override =
blanchet@35966
    53
  {add = [], del = ns, only = false}
blanchet@35966
    54
fun only_relevance_override ns : relevance_override =
blanchet@35966
    55
  {add = ns, del = [], only = true}
blanchet@36003
    56
fun merge_relevance_override_pairwise (r1 : relevance_override)
blanchet@36003
    57
                                      (r2 : relevance_override) =
blanchet@35966
    58
  {add = #add r1 @ #add r2, del = #del r1 @ #del r2,
blanchet@36183
    59
   only = #only r1 andalso #only r2}
blanchet@36188
    60
fun merge_relevance_overrides rs =
blanchet@36188
    61
  fold merge_relevance_override_pairwise rs (only_relevance_override [])
blanchet@35965
    62
blanchet@36371
    63
(*** parameters ***)
blanchet@36371
    64
blanchet@40059
    65
val provers = Unsynchronized.ref ""
blanchet@39335
    66
val timeout = Unsynchronized.ref 30
blanchet@36371
    67
blanchet@36371
    68
val _ =
blanchet@36371
    69
  ProofGeneralPgip.add_preference Preferences.category_proof
blanchet@40059
    70
      (Preferences.string_pref provers
blanchet@40059
    71
          "Sledgehammer: Provers"
blanchet@36371
    72
          "Default automatic provers (separated by whitespace)")
blanchet@36371
    73
blanchet@36371
    74
val _ =
blanchet@36371
    75
  ProofGeneralPgip.add_preference Preferences.category_proof
blanchet@36371
    76
      (Preferences.int_pref timeout
blanchet@36373
    77
          "Sledgehammer: Time Limit"
blanchet@36371
    78
          "ATPs will be interrupted after this time (in seconds)")
blanchet@36371
    79
blanchet@35963
    80
type raw_param = string * string list
blanchet@35963
    81
blanchet@35963
    82
val default_default_params =
blanchet@41208
    83
  [("debug", "false"),
blanchet@35963
    84
   ("verbose", "false"),
blanchet@36143
    85
   ("overlord", "false"),
blanchet@41208
    86
   ("blocking", "false"),
blanchet@43626
    87
   ("type_enc", "smart"),
blanchet@43572
    88
   ("sound", "false"),
blanchet@42180
    89
   ("relevance_thresholds", "0.45 0.85"),
blanchet@42180
    90
   ("max_relevant", "smart"),
blanchet@42783
    91
   ("max_mono_iters", "3"),
blanchet@43352
    92
   ("max_new_mono_instances", "200"),
blanchet@35963
    93
   ("isar_proof", "false"),
blanchet@42443
    94
   ("isar_shrink_factor", "1"),
blanchet@43011
    95
   ("slicing", "true"),
blanchet@43034
    96
   ("preplay_timeout", "4")]
blanchet@35963
    97
blanchet@36140
    98
val alias_params =
blanchet@43353
    99
  [("prover", "provers")]
blanchet@36140
   100
val negated_alias_params =
blanchet@41208
   101
  [("no_debug", "debug"),
blanchet@35963
   102
   ("quiet", "verbose"),
blanchet@36143
   103
   ("no_overlord", "overlord"),
blanchet@41208
   104
   ("non_blocking", "blocking"),
blanchet@43572
   105
   ("unsound", "sound"),
blanchet@42443
   106
   ("no_isar_proof", "isar_proof"),
blanchet@42443
   107
   ("no_slicing", "slicing")]
blanchet@35963
   108
blanchet@36281
   109
val params_for_minimize =
blanchet@43626
   110
  ["debug", "verbose", "overlord", "type_enc", "sound", "max_mono_iters",
blanchet@43259
   111
   "max_new_mono_instances", "isar_proof", "isar_shrink_factor", "timeout",
blanchet@43259
   112
   "preplay_timeout"]
blanchet@36281
   113
blanchet@43569
   114
val property_dependent_params = ["provers", "timeout"]
blanchet@35866
   115
blanchet@35963
   116
fun is_known_raw_param s =
blanchet@35963
   117
  AList.defined (op =) default_default_params s orelse
blanchet@36140
   118
  AList.defined (op =) alias_params s orelse
blanchet@36140
   119
  AList.defined (op =) negated_alias_params s orelse
blanchet@38985
   120
  member (op =) property_dependent_params s orelse s = "expect"
blanchet@35963
   121
blanchet@41258
   122
fun is_prover_list ctxt s =
blanchet@41258
   123
  case space_explode " " s of
blanchet@41727
   124
    ss as _ :: _ => forall (is_prover_supported ctxt) ss
blanchet@41258
   125
  | _ => false
blanchet@41258
   126
blanchet@36140
   127
fun unalias_raw_param (name, value) =
blanchet@36140
   128
  case AList.lookup (op =) alias_params name of
blanchet@36140
   129
    SOME name' => (name', value)
blanchet@36140
   130
  | NONE =>
blanchet@36140
   131
    case AList.lookup (op =) negated_alias_params name of
blanchet@36140
   132
      SOME name' => (name', case value of
blanchet@36140
   133
                              ["false"] => ["true"]
blanchet@36140
   134
                            | ["true"] => ["false"]
blanchet@36140
   135
                            | [] => ["false"]
blanchet@36140
   136
                            | _ => value)
blanchet@36140
   137
    | NONE => (name, value)
blanchet@35963
   138
blanchet@44720
   139
(* "provers =" and "type_enc =" can be left out. The latter is a secret
blanchet@44720
   140
   feature. *)
blanchet@44720
   141
fun normalize_raw_param ctxt =
blanchet@44720
   142
  unalias_raw_param
blanchet@44720
   143
  #> (fn (name, value) =>
blanchet@44720
   144
         if is_known_raw_param name then
blanchet@44720
   145
           (name, value)
blanchet@44720
   146
         else if is_prover_list ctxt name andalso null value then
blanchet@44720
   147
           ("provers", [name])
blanchet@44720
   148
         else if can (type_enc_from_string Sound) name andalso null value then
blanchet@44720
   149
           ("type_enc", [name])
blanchet@44720
   150
         else
blanchet@44720
   151
           error ("Unknown parameter: " ^ quote name ^ "."))
blanchet@44720
   152
blanchet@44720
   153
blanchet@44591
   154
(* Ensure that type systems such as "mono_simple!" and "mono_guards?" are
blanchet@44591
   155
   handled correctly. *)
blanchet@43009
   156
fun implode_param [s, "?"] = s ^ "?"
blanchet@43009
   157
  | implode_param [s, "!"] = s ^ "!"
blanchet@43009
   158
  | implode_param ss = space_implode " " ss
blanchet@43009
   159
wenzelm@41472
   160
structure Data = Theory_Data
wenzelm@41472
   161
(
blanchet@35963
   162
  type T = raw_param list
blanchet@35963
   163
  val empty = default_default_params |> map (apsnd single)
blanchet@35963
   164
  val extend = I
wenzelm@41472
   165
  fun merge data : T = AList.merge (op =) (K true) data
wenzelm@41472
   166
)
blanchet@35866
   167
blanchet@41727
   168
fun remotify_prover_if_supported_and_not_already_remote ctxt name =
blanchet@40072
   169
  if String.isPrefix remote_prefix name then
blanchet@40072
   170
    SOME name
blanchet@40072
   171
  else
blanchet@40072
   172
    let val remote_name = remote_prefix ^ name in
blanchet@41727
   173
      if is_prover_supported ctxt remote_name then SOME remote_name else NONE
blanchet@40072
   174
    end
blanchet@40072
   175
blanchet@40072
   176
fun remotify_prover_if_not_installed ctxt name =
blanchet@41727
   177
  if is_prover_supported ctxt name andalso is_prover_installed ctxt name then
blanchet@40941
   178
    SOME name
blanchet@40941
   179
  else
blanchet@41727
   180
    remotify_prover_if_supported_and_not_already_remote ctxt name
blanchet@40072
   181
blanchet@43009
   182
fun avoid_too_many_threads _ _ [] = []
blanchet@43009
   183
  | avoid_too_many_threads _ (0, 0) _ = []
blanchet@43009
   184
  | avoid_too_many_threads ctxt (0, max_remote) provers =
blanchet@43009
   185
    provers
blanchet@43009
   186
    |> map_filter (remotify_prover_if_supported_and_not_already_remote ctxt)
blanchet@43009
   187
    |> take max_remote
blanchet@43009
   188
  | avoid_too_many_threads _ (max_local, 0) provers =
blanchet@43009
   189
    provers
blanchet@43009
   190
    |> filter_out (String.isPrefix remote_prefix)
blanchet@43009
   191
    |> take max_local
blanchet@43009
   192
  | avoid_too_many_threads ctxt max_local_and_remote (prover :: provers) =
blanchet@43009
   193
    let
blanchet@43009
   194
      val max_local_and_remote =
blanchet@43009
   195
        max_local_and_remote
blanchet@43009
   196
        |> (if String.isPrefix remote_prefix prover then apsnd else apfst)
blanchet@43009
   197
              (Integer.add ~1)
blanchet@43009
   198
    in prover :: avoid_too_many_threads ctxt max_local_and_remote provers end
blanchet@40059
   199
blanchet@43009
   200
val max_default_remote_threads = 4
blanchet@42688
   201
blanchet@40059
   202
(* The first ATP of the list is used by Auto Sledgehammer. Because of the low
blanchet@40059
   203
   timeout, it makes sense to put SPASS first. *)
blanchet@40069
   204
fun default_provers_param_value ctxt =
blanchet@44092
   205
  [spassN, eN, vampireN, SMT_Solver.solver_name_of ctxt, e_sineN, waldmeisterN]
blanchet@40941
   206
  |> map_filter (remotify_prover_if_not_installed ctxt)
blanchet@43009
   207
  |> avoid_too_many_threads ctxt (Multithreading.max_threads_value (),
blanchet@43009
   208
                                  max_default_remote_threads)
blanchet@42776
   209
  |> implode_param
blanchet@40059
   210
blanchet@44720
   211
fun set_default_raw_param param thy =
blanchet@44720
   212
  let val ctxt = Proof_Context.init_global thy in
blanchet@44720
   213
    thy |> Data.map (AList.update (op =) (normalize_raw_param ctxt param))
blanchet@44720
   214
  end
blanchet@40069
   215
fun default_raw_params ctxt =
wenzelm@42361
   216
  let val thy = Proof_Context.theory_of ctxt in
blanchet@40069
   217
    Data.get thy
blanchet@40069
   218
    |> fold (AList.default (op =))
blanchet@40069
   219
            [("provers", [case !provers of
blanchet@40069
   220
                            "" => default_provers_param_value ctxt
blanchet@40069
   221
                          | s => s]),
blanchet@40069
   222
             ("timeout", let val timeout = !timeout in
blanchet@40069
   223
                           [if timeout <= 0 then "none"
blanchet@40341
   224
                            else string_of_int timeout]
blanchet@40069
   225
                         end)]
blanchet@40069
   226
  end
blanchet@35963
   227
blanchet@35963
   228
val infinity_time_in_secs = 60 * 60 * 24 * 365
blanchet@35963
   229
val the_timeout = the_default (Time.fromSeconds infinity_time_in_secs)
blanchet@35866
   230
blanchet@43021
   231
fun extract_params mode default_params override_params =
blanchet@35963
   232
  let
blanchet@35963
   233
    val raw_params = rev override_params @ rev default_params
blanchet@42776
   234
    val lookup = Option.map implode_param o AList.lookup (op =) raw_params
blanchet@35963
   235
    val lookup_string = the_default "" o lookup
blanchet@35963
   236
    fun general_lookup_bool option default_value name =
blanchet@35963
   237
      case lookup name of
blanchet@35970
   238
        SOME s => parse_bool_option option name s
blanchet@35963
   239
      | NONE => default_value
blanchet@35963
   240
    val lookup_bool = the o general_lookup_bool false (SOME false)
blanchet@35963
   241
    fun lookup_time name =
blanchet@39318
   242
      case lookup name of
blanchet@39318
   243
        SOME s => parse_time_option name s
blanchet@39318
   244
      | NONE => NONE
blanchet@35966
   245
    fun lookup_int name =
blanchet@35963
   246
      case lookup name of
blanchet@35966
   247
        NONE => 0
blanchet@35966
   248
      | SOME s => case Int.fromString s of
blanchet@35966
   249
                    SOME n => n
blanchet@35966
   250
                  | NONE => error ("Parameter " ^ quote name ^
blanchet@35966
   251
                                   " must be assigned an integer value.")
blanchet@40343
   252
    fun lookup_real_pair name =
blanchet@38745
   253
      case lookup name of
blanchet@40343
   254
        NONE => (0.0, 0.0)
blanchet@40343
   255
      | SOME s => case s |> space_explode " " |> map Real.fromString of
blanchet@40343
   256
                    [SOME r1, SOME r2] => (r1, r2)
blanchet@38745
   257
                  | _ => error ("Parameter " ^ quote name ^
blanchet@40343
   258
                                "must be assigned a pair of floating-point \
blanchet@40343
   259
                                \values (e.g., \"0.6 0.95\")")
blanchet@43064
   260
    fun lookup_option lookup' name =
blanchet@38589
   261
      case lookup name of
blanchet@38589
   262
        SOME "smart" => NONE
blanchet@43064
   263
      | _ => SOME (lookup' name)
blanchet@43021
   264
    val debug = mode <> Auto_Try andalso lookup_bool "debug"
blanchet@43021
   265
    val verbose = debug orelse (mode <> Auto_Try andalso lookup_bool "verbose")
blanchet@36143
   266
    val overlord = lookup_bool "overlord"
blanchet@42995
   267
    val blocking =
blanchet@43021
   268
      Isabelle_Process.is_active () orelse mode <> Normal orelse debug orelse
blanchet@42995
   269
      lookup_bool "blocking"
blanchet@40059
   270
    val provers = lookup_string "provers" |> space_explode " "
blanchet@43021
   271
                  |> mode = Auto_Try ? single o hd
blanchet@43626
   272
    val type_enc =
blanchet@43021
   273
      if mode = Auto_Try then
blanchet@43569
   274
        NONE
blanchet@43626
   275
      else case lookup_string "type_enc" of
blanchet@43569
   276
        "smart" => NONE
blanchet@44397
   277
      | s => (type_enc_from_string Sound s; SOME s)
blanchet@43572
   278
    val sound = mode = Auto_Try orelse lookup_bool "sound"
blanchet@42180
   279
    val relevance_thresholds = lookup_real_pair "relevance_thresholds"
blanchet@43064
   280
    val max_relevant = lookup_option lookup_int "max_relevant"
blanchet@42724
   281
    val max_mono_iters = lookup_int "max_mono_iters"
blanchet@42740
   282
    val max_new_mono_instances = lookup_int "max_new_mono_instances"
blanchet@35963
   283
    val isar_proof = lookup_bool "isar_proof"
blanchet@36924
   284
    val isar_shrink_factor = Int.max (1, lookup_int "isar_shrink_factor")
blanchet@43021
   285
    val slicing = mode <> Auto_Try andalso lookup_bool "slicing"
blanchet@43021
   286
    val timeout =
blanchet@43021
   287
      (if mode = Auto_Try then NONE else lookup_time "timeout") |> the_timeout
blanchet@43015
   288
    val preplay_timeout =
blanchet@43021
   289
      if mode = Auto_Try then Time.zeroTime
blanchet@43015
   290
      else lookup_time "preplay_timeout" |> the_timeout
blanchet@38985
   291
    val expect = lookup_string "expect"
blanchet@35963
   292
  in
blanchet@41208
   293
    {debug = debug, verbose = verbose, overlord = overlord, blocking = blocking,
blanchet@42180
   294
     provers = provers, relevance_thresholds = relevance_thresholds,
blanchet@42724
   295
     max_relevant = max_relevant, max_mono_iters = max_mono_iters,
blanchet@43626
   296
     max_new_mono_instances = max_new_mono_instances, type_enc = type_enc,
blanchet@43572
   297
     sound = sound, isar_proof = isar_proof,
blanchet@43572
   298
     isar_shrink_factor = isar_shrink_factor, slicing = slicing,
blanchet@43572
   299
     timeout = timeout, preplay_timeout = preplay_timeout, expect = expect}
blanchet@35963
   300
  end
blanchet@35866
   301
blanchet@44720
   302
fun get_params mode = extract_params mode o default_raw_params
blanchet@43021
   303
fun default_params thy = get_params Normal thy o map (apsnd single)
blanchet@35866
   304
blanchet@36373
   305
(* Sledgehammer the given subgoal *)
blanchet@36373
   306
blanchet@44651
   307
val default_minimize_prover = Metis_Tactic.metisN
blanchet@43051
   308
blanchet@44720
   309
fun is_raw_param_relevant_for_minimize (name, _) =
blanchet@44720
   310
  member (op =) params_for_minimize name
blanchet@36281
   311
fun string_for_raw_param (key, values) =
blanchet@42776
   312
  key ^ (case implode_param values of "" => "" | value => " = " ^ value)
blanchet@36281
   313
blanchet@40059
   314
fun minimize_command override_params i prover_name fact_names =
blanchet@43057
   315
  let
blanchet@43057
   316
    val params =
blanchet@43057
   317
      override_params
blanchet@43057
   318
      |> filter is_raw_param_relevant_for_minimize
blanchet@43057
   319
      |> map string_for_raw_param
blanchet@43057
   320
      |> (if prover_name = default_minimize_prover then I else cons prover_name)
blanchet@43057
   321
      |> space_implode ", "
blanchet@43057
   322
  in
blanchet@43057
   323
    sledgehammerN ^ " " ^ minN ^
blanchet@43057
   324
    (if params = "" then "" else enclose " [" "]" params) ^
blanchet@43057
   325
    " (" ^ space_implode " " fact_names ^ ")" ^
blanchet@43057
   326
    (if i = 1 then "" else " " ^ string_of_int i)
blanchet@43057
   327
  end
blanchet@36281
   328
blanchet@35966
   329
fun hammer_away override_params subcommand opt_i relevance_override state =
blanchet@35963
   330
  let
blanchet@40069
   331
    val ctxt = Proof.context_of state
blanchet@44720
   332
    val override_params = override_params |> map (normalize_raw_param ctxt)
blanchet@35965
   333
  in
blanchet@35965
   334
    if subcommand = runN then
blanchet@36281
   335
      let val i = the_default 1 opt_i in
blanchet@43021
   336
        run_sledgehammer (get_params Normal ctxt override_params) Normal i
blanchet@39318
   337
                         relevance_override (minimize_command override_params i)
blanchet@39318
   338
                         state
blanchet@39318
   339
        |> K ()
blanchet@36281
   340
      end
blanchet@43008
   341
    else if subcommand = minN then
blanchet@43051
   342
      run_minimize (get_params Minimize ctxt
blanchet@43051
   343
                               (("provers", [default_minimize_prover]) ::
blanchet@43051
   344
                                override_params))
blanchet@43021
   345
                   (the_default 1 opt_i) (#add relevance_override) state
blanchet@35965
   346
    else if subcommand = messagesN then
blanchet@35965
   347
      messages opt_i
blanchet@41727
   348
    else if subcommand = supported_proversN then
blanchet@41727
   349
      supported_provers ctxt
blanchet@40059
   350
    else if subcommand = running_proversN then
blanchet@40059
   351
      running_provers ()
blanchet@40059
   352
    else if subcommand = kill_proversN then
blanchet@40059
   353
      kill_provers ()
blanchet@35965
   354
    else if subcommand = refresh_tptpN then
blanchet@35965
   355
      refresh_systems_on_tptp ()
blanchet@35965
   356
    else
blanchet@35965
   357
      error ("Unknown subcommand: " ^ quote subcommand ^ ".")
blanchet@35965
   358
  end
blanchet@35963
   359
blanchet@35966
   360
fun sledgehammer_trans (((subcommand, params), relevance_override), opt_i) =
blanchet@35966
   361
  Toplevel.keep (hammer_away params subcommand opt_i relevance_override
blanchet@35966
   362
                 o Toplevel.proof_of)
blanchet@35963
   363
blanchet@42776
   364
fun string_for_raw_param (name, value) = name ^ " = " ^ implode_param value
blanchet@35963
   365
blanchet@35965
   366
fun sledgehammer_params_trans params =
blanchet@35963
   367
  Toplevel.theory
blanchet@35965
   368
      (fold set_default_raw_param params
blanchet@39318
   369
       #> tap (fn thy =>
wenzelm@42361
   370
                  let val ctxt = Proof_Context.init_global thy in
blanchet@40069
   371
                    writeln ("Default parameters for Sledgehammer:\n" ^
blanchet@40069
   372
                             (case default_raw_params ctxt |> rev of
blanchet@40069
   373
                                [] => "none"
blanchet@40069
   374
                              | params =>
blanchet@44720
   375
                                params |> map string_for_raw_param
blanchet@41258
   376
                                       |> sort_strings |> cat_lines))
blanchet@40069
   377
                  end))
blanchet@35963
   378
blanchet@42776
   379
val parse_key =
blanchet@42776
   380
  Scan.repeat1 (Parse.typ_group || Parse.$$$ "?" || Parse.$$$ "!")
blanchet@43100
   381
  >> implode_param
blanchet@42581
   382
val parse_value =
blanchet@42589
   383
  Scan.repeat1 (Parse.xname || Parse.float_number || Parse.$$$ "?"
blanchet@42581
   384
                || Parse.$$$ "!")
wenzelm@36960
   385
val parse_param = parse_key -- Scan.optional (Parse.$$$ "=" |-- parse_value) []
wenzelm@36960
   386
val parse_params = Scan.optional (Args.bracks (Parse.list parse_param)) []
blanchet@35965
   387
val parse_fact_refs =
blanchet@38996
   388
  Scan.repeat1 (Scan.unless (Parse.name -- Args.colon) Parse_Spec.xthm)
blanchet@35966
   389
val parse_relevance_chunk =
blanchet@39318
   390
  (Args.add |-- Args.colon |-- parse_fact_refs >> add_relevance_override)
blanchet@39318
   391
  || (Args.del |-- Args.colon |-- parse_fact_refs >> del_relevance_override)
blanchet@36188
   392
  || (parse_fact_refs >> only_relevance_override)
blanchet@35966
   393
val parse_relevance_override =
blanchet@36188
   394
  Scan.optional (Args.parens (Scan.repeat parse_relevance_chunk
blanchet@36188
   395
                              >> merge_relevance_overrides))
blanchet@39318
   396
                no_relevance_override
blanchet@35963
   397
val parse_sledgehammer_command =
blanchet@37399
   398
  (Scan.optional Parse.short_ident runN -- parse_params
blanchet@37399
   399
   -- parse_relevance_override -- Scan.option Parse.nat) #>> sledgehammer_trans
blanchet@35963
   400
val parse_sledgehammer_params_command =
blanchet@35963
   401
  parse_params #>> sledgehammer_params_trans
blanchet@35963
   402
blanchet@35963
   403
val _ =
wenzelm@36960
   404
  Outer_Syntax.improper_command sledgehammerN
wenzelm@36960
   405
      "search for first-order proof using automatic theorem provers" Keyword.diag
blanchet@36394
   406
      parse_sledgehammer_command
blanchet@35963
   407
val _ =
wenzelm@36960
   408
  Outer_Syntax.command sledgehammer_paramsN
wenzelm@36960
   409
      "set and display the default parameters for Sledgehammer" Keyword.thy_decl
blanchet@36394
   410
      parse_sledgehammer_params_command
blanchet@36394
   411
blanchet@43020
   412
fun try_sledgehammer auto state =
blanchet@43020
   413
  let
blanchet@43020
   414
    val ctxt = Proof.context_of state
blanchet@43021
   415
    val mode = if auto then Auto_Try else Try
blanchet@43020
   416
    val i = 1
blanchet@43020
   417
  in
blanchet@43021
   418
    run_sledgehammer (get_params mode ctxt []) mode i no_relevance_override
blanchet@43020
   419
                     (minimize_command [] i) state
blanchet@40931
   420
  end
blanchet@39318
   421
blanchet@43024
   422
val setup = Try.register_tool (sledgehammerN, (40, auto, try_sledgehammer))
blanchet@39318
   423
blanchet@35866
   424
end;