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