src/HOL/Tools/Nitpick/nitpick_commands.ML
author wenzelm
Tue Sep 26 20:54:40 2017 +0200 (24 months ago)
changeset 66695 91500c024c7f
parent 63693 5b02f7757a4c
child 67399 eab6ce8368fa
permissions -rw-r--r--
tuned;
blanchet@55199
     1
(*  Title:      HOL/Tools/Nitpick/nitpick_commands.ML
blanchet@33192
     2
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@34982
     3
    Copyright   2008, 2009, 2010
blanchet@33192
     4
blanchet@33192
     5
Adds the "nitpick" and "nitpick_params" commands to Isabelle/Isar's outer
blanchet@33192
     6
syntax.
blanchet@33192
     7
*)
blanchet@33192
     8
blanchet@55199
     9
signature NITPICK_COMMANDS =
blanchet@33192
    10
sig
blanchet@33192
    11
  type params = Nitpick.params
blanchet@33192
    12
blanchet@43020
    13
  val nitpickN : string
blanchet@43020
    14
  val nitpick_paramsN : string
blanchet@33192
    15
  val default_params : theory -> (string * string) list -> params
blanchet@35866
    16
end;
blanchet@33192
    17
blanchet@55203
    18
structure Nitpick_Commands : NITPICK_COMMANDS =
blanchet@33192
    19
struct
blanchet@33192
    20
blanchet@33232
    21
open Nitpick_Util
blanchet@33232
    22
open Nitpick_HOL
blanchet@33232
    23
open Nitpick_Rep
blanchet@33232
    24
open Nitpick_Nut
blanchet@33192
    25
open Nitpick
blanchet@33192
    26
blanchet@43020
    27
val nitpickN = "nitpick"
blanchet@43020
    28
val nitpick_paramsN = "nitpick_params"
blanchet@43020
    29
blanchet@39344
    30
(* Maximum number of scopes for Auto Nitpick. Be frugal since it has to share
blanchet@39344
    31
   its time slot with several other automatic tools. *)
blanchet@43022
    32
val auto_try_max_scopes = 6
blanchet@39344
    33
blanchet@33192
    34
type raw_param = string * string list
blanchet@33192
    35
blanchet@33192
    36
val default_default_params =
blanchet@61569
    37
  [("card", "1-10"),
blanchet@38180
    38
   ("iter", "0,1,2,4,8,12,16,20,24,28"),
blanchet@61569
    39
   ("bits", "1-10"),
blanchet@38180
    40
   ("bisim_depth", "9"),
blanchet@35964
    41
   ("box", "smart"),
blanchet@35964
    42
   ("finitize", "smart"),
blanchet@35964
    43
   ("mono", "smart"),
blanchet@35964
    44
   ("wf", "smart"),
blanchet@35964
    45
   ("sat_solver", "smart"),
blanchet@35964
    46
   ("batch_size", "smart"),
blanchet@35964
    47
   ("falsify", "true"),
blanchet@35964
    48
   ("user_axioms", "smart"),
blanchet@35964
    49
   ("assms", "true"),
blanchet@35964
    50
   ("merge_type_vars", "false"),
blanchet@35964
    51
   ("binary_ints", "smart"),
blanchet@35964
    52
   ("destroy_constrs", "true"),
blanchet@35964
    53
   ("specialize", "true"),
blanchet@35964
    54
   ("star_linear_preds", "true"),
blanchet@41856
    55
   ("total_consts", "smart"),
blanchet@35964
    56
   ("peephole_optim", "true"),
blanchet@38127
    57
   ("datatype_sym_break", "5"),
blanchet@38127
    58
   ("kodkod_sym_break", "15"),
blanchet@40341
    59
   ("timeout", "30"),
blanchet@40341
    60
   ("tac_timeout", "0.5"),
blanchet@35964
    61
   ("max_threads", "0"),
blanchet@35964
    62
   ("debug", "false"),
blanchet@35964
    63
   ("verbose", "false"),
blanchet@35964
    64
   ("overlord", "false"),
blanchet@53802
    65
   ("spy", "false"),
blanchet@55889
    66
   ("show_types", "false"),
blanchet@41993
    67
   ("show_skolems", "true"),
blanchet@35964
    68
   ("show_consts", "false"),
blanchet@35964
    69
   ("format", "1"),
blanchet@35964
    70
   ("max_potential", "1"),
blanchet@60310
    71
   ("max_genuine", "1")]
blanchet@33192
    72
blanchet@33192
    73
val negated_params =
blanchet@33192
    74
  [("dont_box", "box"),
blanchet@35665
    75
   ("dont_finitize", "finitize"),
blanchet@33192
    76
   ("non_mono", "mono"),
blanchet@33192
    77
   ("non_wf", "wf"),
blanchet@33192
    78
   ("satisfy", "falsify"),
blanchet@33192
    79
   ("no_user_axioms", "user_axioms"),
blanchet@33192
    80
   ("no_assms", "assms"),
blanchet@33556
    81
   ("dont_merge_type_vars", "merge_type_vars"),
blanchet@34124
    82
   ("unary_ints", "binary_ints"),
blanchet@33192
    83
   ("dont_destroy_constrs", "destroy_constrs"),
blanchet@33192
    84
   ("dont_specialize", "specialize"),
blanchet@33192
    85
   ("dont_star_linear_preds", "star_linear_preds"),
blanchet@41856
    86
   ("partial_consts", "total_consts"),
blanchet@33192
    87
   ("no_peephole_optim", "peephole_optim"),
blanchet@35964
    88
   ("no_debug", "debug"),
blanchet@33192
    89
   ("quiet", "verbose"),
blanchet@33192
    90
   ("no_overlord", "overlord"),
blanchet@53802
    91
   ("dont_spy", "spy"),
blanchet@55889
    92
   ("hide_types", "show_types"),
blanchet@41993
    93
   ("hide_skolems", "show_skolems"),
blanchet@60310
    94
   ("hide_consts", "show_consts")]
blanchet@33192
    95
blanchet@33192
    96
fun is_known_raw_param s =
blanchet@34936
    97
  AList.defined (op =) default_default_params s orelse
blanchet@34936
    98
  AList.defined (op =) negated_params s orelse
blanchet@41876
    99
  member (op =) ["max", "show_all", "whack", "eval", "need", "atoms",
blanchet@41876
   100
                 "expect"] s orelse
blanchet@34936
   101
  exists (fn p => String.isPrefix (p ^ " ") s)
blanchet@35665
   102
         ["card", "max", "iter", "box", "dont_box", "finitize", "dont_finitize",
blanchet@55888
   103
          "mono", "non_mono", "wf", "non_wf", "format", "atoms"]
blanchet@33192
   104
blanchet@33192
   105
fun check_raw_param (s, _) =
blanchet@33192
   106
  if is_known_raw_param s then ()
blanchet@63693
   107
  else error ("Unknown parameter: " ^ quote s)
blanchet@33192
   108
blanchet@33192
   109
fun unnegate_param_name name =
blanchet@33192
   110
  case AList.lookup (op =) negated_params name of
blanchet@33192
   111
    NONE => if String.isPrefix "dont_" name then SOME (unprefix "dont_" name)
blanchet@33192
   112
            else if String.isPrefix "non_" name then SOME (unprefix "non_" name)
blanchet@33192
   113
            else NONE
blanchet@33192
   114
  | some_name => some_name
blanchet@55889
   115
blanchet@37169
   116
fun normalize_raw_param (name, value) =
blanchet@33192
   117
  case unnegate_param_name name of
blanchet@37169
   118
    SOME name' => [(name', case value of
blanchet@37169
   119
                             ["false"] => ["true"]
blanchet@37169
   120
                           | ["true"] => ["false"]
blanchet@37169
   121
                           | [] => ["false"]
blanchet@37169
   122
                           | _ => value)]
blanchet@37169
   123
  | NONE => if name = "show_all" then
blanchet@55889
   124
              [("show_types", value), ("show_skolems", value),
blanchet@41993
   125
               ("show_consts", value)]
blanchet@37169
   126
            else
blanchet@37169
   127
              [(name, value)]
blanchet@33192
   128
wenzelm@41472
   129
structure Data = Theory_Data
wenzelm@41472
   130
(
blanchet@35964
   131
  type T = raw_param list
blanchet@54546
   132
  val empty = default_default_params |> map (apsnd single)
blanchet@33192
   133
  val extend = I
wenzelm@41472
   134
  fun merge data = AList.merge (op =) (K true) data
wenzelm@41472
   135
)
blanchet@33192
   136
blanchet@37169
   137
val set_default_raw_param =
blanchet@37169
   138
  Data.map o fold (AList.update (op =)) o normalize_raw_param
blanchet@35964
   139
val default_raw_params = Data.get
blanchet@33192
   140
blanchet@61569
   141
fun is_punctuation s = (s = "," orelse s = "-")
blanchet@33192
   142
blanchet@33192
   143
fun stringify_raw_param_value [] = ""
blanchet@33192
   144
  | stringify_raw_param_value [s] = s
blanchet@33192
   145
  | stringify_raw_param_value (s1 :: s2 :: ss) =
blanchet@33192
   146
    s1 ^ (if is_punctuation s1 orelse is_punctuation s2 then "" else " ") ^
blanchet@33192
   147
    stringify_raw_param_value (s2 :: ss)
blanchet@33192
   148
blanchet@33192
   149
fun maxed_int_from_string min_int s = Int.max (min_int, the (Int.fromString s))
blanchet@33192
   150
blanchet@43022
   151
fun extract_params ctxt mode default_params override_params =
blanchet@33192
   152
  let
blanchet@37169
   153
    val override_params = maps normalize_raw_param override_params
blanchet@33192
   154
    val raw_params = rev override_params @ rev default_params
blanchet@37260
   155
    val raw_lookup = AList.lookup (op =) raw_params
blanchet@37260
   156
    val lookup = Option.map stringify_raw_param_value o raw_lookup
blanchet@35964
   157
    val lookup_string = the_default "" o lookup
blanchet@35964
   158
    fun general_lookup_bool option default_value name =
blanchet@35964
   159
      case lookup name of
blanchet@36380
   160
        SOME s => parse_bool_option option name s
blanchet@35964
   161
      | NONE => default_value
blanchet@35964
   162
    val lookup_bool = the o general_lookup_bool false (SOME false)
blanchet@35964
   163
    val lookup_bool_option = general_lookup_bool true NONE
blanchet@33192
   164
    fun do_int name value =
blanchet@33192
   165
      case value of
blanchet@33192
   166
        SOME s => (case Int.fromString s of
blanchet@33192
   167
                     SOME i => i
blanchet@33192
   168
                   | NONE => error ("Parameter " ^ quote name ^
blanchet@63693
   169
                                    " must be assigned an integer value"))
blanchet@33192
   170
      | NONE => 0
blanchet@33192
   171
    fun lookup_int name = do_int name (lookup name)
blanchet@33192
   172
    fun lookup_int_option name =
blanchet@33192
   173
      case lookup name of
blanchet@33192
   174
        SOME "smart" => NONE
blanchet@33192
   175
      | value => SOME (do_int name value)
blanchet@33192
   176
    fun int_range_from_string name min_int s =
blanchet@33192
   177
      let
blanchet@33192
   178
        val (k1, k2) =
blanchet@33192
   179
          (case space_explode "-" s of
blanchet@61569
   180
             [s] => (s, s)
blanchet@33192
   181
           | ["", s2] => ("-" ^ s2, "-" ^ s2)
blanchet@33192
   182
           | [s1, s2] => (s1, s2)
wenzelm@51930
   183
           | _ => raise Option.Option)
wenzelm@59058
   184
          |> apply2 (maxed_int_from_string min_int)
blanchet@33192
   185
      in if k1 <= k2 then k1 upto k2 else k1 downto k2 end
blanchet@33192
   186
      handle Option.Option =>
blanchet@33192
   187
             error ("Parameter " ^ quote name ^
blanchet@63693
   188
                    " must be assigned a sequence of integers")
blanchet@33192
   189
    fun int_seq_from_string name min_int s =
blanchet@33192
   190
      maps (int_range_from_string name min_int) (space_explode "," s)
blanchet@33192
   191
    fun lookup_int_seq name min_int =
blanchet@33192
   192
      case lookup name of
blanchet@33192
   193
        SOME s => (case int_seq_from_string name min_int s of
blanchet@33192
   194
                     [] => [min_int]
blanchet@33192
   195
                   | value => value)
blanchet@33192
   196
      | NONE => [min_int]
blanchet@37260
   197
    fun lookup_assigns read prefix default convert =
blanchet@37260
   198
      (NONE, convert (the_default default (lookup prefix)))
blanchet@34982
   199
      :: map (fn (name, value) =>
blanchet@34982
   200
                 (SOME (read (String.extract (name, size prefix + 1, NONE))),
blanchet@37260
   201
                  convert (stringify_raw_param_value value)))
blanchet@34982
   202
             (filter (String.isPrefix (prefix ^ " ") o fst) raw_params)
blanchet@37260
   203
    fun lookup_ints_assigns read prefix min_int =
blanchet@37260
   204
      lookup_assigns read prefix (signed_string_of_int min_int)
blanchet@37260
   205
                     (int_seq_from_string prefix min_int)
blanchet@33192
   206
    fun lookup_bool_option_assigns read prefix =
blanchet@37260
   207
      lookup_assigns read prefix "" (parse_bool_option true prefix)
blanchet@37260
   208
    fun lookup_strings_assigns read prefix =
blanchet@37260
   209
      lookup_assigns read prefix "" (space_explode " ")
blanchet@33192
   210
    fun lookup_time name =
blanchet@33192
   211
      case lookup name of
blanchet@54816
   212
        SOME s => parse_time name s
blanchet@54816
   213
      | NONE => Time.zeroTime
blanchet@33192
   214
    val read_type_polymorphic =
blanchet@33192
   215
      Syntax.read_typ ctxt #> Logic.mk_type
blanchet@33192
   216
      #> singleton (Variable.polymorphic ctxt) #> Logic.dest_type
blanchet@33192
   217
    val read_term_polymorphic =
blanchet@33192
   218
      Syntax.read_term ctxt #> singleton (Variable.polymorphic ctxt)
blanchet@41876
   219
    val lookup_term_list_option_polymorphic =
blanchet@41876
   220
      AList.lookup (op =) raw_params #> Option.map (map read_term_polymorphic)
blanchet@33192
   221
    val read_const_polymorphic = read_term_polymorphic #> dest_Const
blanchet@43022
   222
    val cards_assigns =
blanchet@43022
   223
      lookup_ints_assigns read_type_polymorphic "card" 1
blanchet@43022
   224
      |> mode = Auto_Try ? map (apsnd (take auto_try_max_scopes))
blanchet@33192
   225
    val maxes_assigns = lookup_ints_assigns read_const_polymorphic "max" ~1
blanchet@33192
   226
    val iters_assigns = lookup_ints_assigns read_const_polymorphic "iter" 0
blanchet@34124
   227
    val bitss = lookup_int_seq "bits" 1
blanchet@33192
   228
    val bisim_depths = lookup_int_seq "bisim_depth" ~1
blanchet@35665
   229
    val boxes = lookup_bool_option_assigns read_type_polymorphic "box"
blanchet@35665
   230
    val finitizes = lookup_bool_option_assigns read_type_polymorphic "finitize"
blanchet@43022
   231
    val monos = if mode = Auto_Try then [(NONE, SOME true)]
blanchet@39316
   232
                else lookup_bool_option_assigns read_type_polymorphic "mono"
blanchet@33192
   233
    val wfs = lookup_bool_option_assigns read_const_polymorphic "wf"
blanchet@33192
   234
    val sat_solver = lookup_string "sat_solver"
blanchet@33192
   235
    val falsify = lookup_bool "falsify"
blanchet@43022
   236
    val debug = (mode <> Auto_Try andalso lookup_bool "debug")
blanchet@43022
   237
    val verbose = debug orelse (mode <> Auto_Try andalso lookup_bool "verbose")
blanchet@33192
   238
    val overlord = lookup_bool "overlord"
blanchet@54546
   239
    val spy = getenv "NITPICK_SPY" = "yes" orelse lookup_bool "spy"
blanchet@33192
   240
    val user_axioms = lookup_bool_option "user_axioms"
blanchet@33192
   241
    val assms = lookup_bool "assms"
blanchet@41876
   242
    val whacks = lookup_term_list_option_polymorphic "whack" |> these
blanchet@33556
   243
    val merge_type_vars = lookup_bool "merge_type_vars"
blanchet@34124
   244
    val binary_ints = lookup_bool_option "binary_ints"
blanchet@33192
   245
    val destroy_constrs = lookup_bool "destroy_constrs"
blanchet@33192
   246
    val specialize = lookup_bool "specialize"
blanchet@33192
   247
    val star_linear_preds = lookup_bool "star_linear_preds"
blanchet@41856
   248
    val total_consts = lookup_bool_option "total_consts"
blanchet@41876
   249
    val needs = lookup_term_list_option_polymorphic "need"
blanchet@33192
   250
    val peephole_optim = lookup_bool "peephole_optim"
blanchet@38124
   251
    val datatype_sym_break = lookup_int "datatype_sym_break"
blanchet@38124
   252
    val kodkod_sym_break = lookup_int "kodkod_sym_break"
blanchet@54816
   253
    val timeout = lookup_time "timeout"
blanchet@33192
   254
    val tac_timeout = lookup_time "tac_timeout"
blanchet@43022
   255
    val max_threads =
blanchet@43022
   256
      if mode = Normal then Int.max (0, lookup_int "max_threads") else 1
blanchet@55889
   257
    val show_types = debug orelse lookup_bool "show_types"
blanchet@41993
   258
    val show_skolems = debug orelse lookup_bool "show_skolems"
blanchet@37169
   259
    val show_consts = debug orelse lookup_bool "show_consts"
blanchet@41876
   260
    val evals = lookup_term_list_option_polymorphic "eval" |> these
blanchet@33192
   261
    val formats = lookup_ints_assigns read_term_polymorphic "format" 0
blanchet@37260
   262
    val atomss = lookup_strings_assigns read_type_polymorphic "atoms"
blanchet@33561
   263
    val max_potential =
blanchet@43032
   264
      if mode = Normal then Int.max (0, lookup_int "max_potential") else 0
blanchet@33192
   265
    val max_genuine = Int.max (0, lookup_int "max_genuine")
blanchet@36390
   266
    val batch_size =
blanchet@36390
   267
      case lookup_int_option "batch_size" of
blanchet@36390
   268
        SOME n => Int.max (1, n)
blanchet@38180
   269
      | NONE => if debug then 1 else 50
blanchet@33192
   270
    val expect = lookup_string "expect"
blanchet@33192
   271
  in
blanchet@55888
   272
    {cards_assigns = cards_assigns, maxes_assigns = maxes_assigns,
blanchet@55888
   273
     iters_assigns = iters_assigns, bitss = bitss, bisim_depths = bisim_depths,
blanchet@55888
   274
     boxes = boxes, finitizes = finitizes, monos = monos, wfs = wfs,
blanchet@61315
   275
     sat_solver = sat_solver, falsify = falsify, debug = debug,
blanchet@61315
   276
     verbose = verbose, overlord = overlord, spy = spy,
blanchet@55888
   277
     user_axioms = user_axioms, assms = assms, whacks = whacks,
blanchet@55888
   278
     merge_type_vars = merge_type_vars, binary_ints = binary_ints,
blanchet@55888
   279
     destroy_constrs = destroy_constrs, specialize = specialize,
blanchet@55888
   280
     star_linear_preds = star_linear_preds, total_consts = total_consts,
blanchet@55888
   281
     needs = needs, peephole_optim = peephole_optim,
blanchet@55888
   282
     datatype_sym_break = datatype_sym_break,
blanchet@55888
   283
     kodkod_sym_break = kodkod_sym_break, timeout = timeout,
blanchet@55888
   284
     tac_timeout = tac_timeout, max_threads = max_threads,
blanchet@55889
   285
     show_types = show_types, show_skolems = show_skolems,
blanchet@55888
   286
     show_consts = show_consts, evals = evals, formats = formats,
blanchet@55888
   287
     atomss = atomss, max_potential = max_potential, max_genuine = max_genuine,
blanchet@55888
   288
     batch_size = batch_size, expect = expect}
blanchet@33192
   289
  end
blanchet@33192
   290
blanchet@33192
   291
fun default_params thy =
blanchet@43022
   292
  extract_params (Proof_Context.init_global thy) Normal (default_raw_params thy)
blanchet@33192
   293
  o map (apsnd single)
blanchet@33192
   294
wenzelm@63136
   295
val parse_key = Scan.repeat1 Parse.embedded >> space_implode " "
blanchet@35964
   296
val parse_value =
wenzelm@61476
   297
  Scan.repeats1 (Parse.minus >> single
blanchet@40341
   298
                || Scan.repeat1 (Scan.unless Parse.minus
blanchet@40341
   299
                                             (Parse.name || Parse.float_number))
wenzelm@46949
   300
                || @{keyword ","} |-- Parse.number >> prefix "," >> single)
wenzelm@46949
   301
val parse_param = parse_key -- Scan.optional (@{keyword "="} |-- parse_value) []
blanchet@35968
   302
val parse_params =
wenzelm@46949
   303
  Scan.optional (@{keyword "["} |-- Parse.list parse_param --| @{keyword "]"}) []
blanchet@33192
   304
blanchet@33192
   305
fun handle_exceptions ctxt f x =
blanchet@33192
   306
  f x
blanchet@33192
   307
  handle ARG (loc, details) =>
blanchet@63693
   308
         error ("Bad argument(s) to " ^ quote loc ^ ": " ^ details)
blanchet@33192
   309
       | BAD (loc, details) =>
blanchet@63693
   310
         error ("Internal error (" ^ quote loc ^ "): " ^ details)
blanchet@33192
   311
       | NOT_SUPPORTED details =>
blanchet@63693
   312
         (warning ("Unsupported case: " ^ details); x)
blanchet@33192
   313
       | NUT (loc, us) =>
blanchet@33192
   314
         error ("Invalid intermediate term" ^ plural_s_for_list us ^
blanchet@33192
   315
                " (" ^ quote loc ^ "): " ^
blanchet@63693
   316
                commas (map (string_for_nut ctxt) us))
blanchet@33192
   317
       | REP (loc, Rs) =>
blanchet@33192
   318
         error ("Invalid representation" ^ plural_s_for_list Rs ^
blanchet@63693
   319
                " (" ^ quote loc ^ "): " ^ commas (map string_for_rep Rs))
blanchet@33192
   320
       | TERM (loc, ts) =>
blanchet@33192
   321
         error ("Invalid term" ^ plural_s_for_list ts ^
blanchet@33192
   322
                " (" ^ quote loc ^ "): " ^
blanchet@63693
   323
                commas (map (Syntax.string_of_term ctxt) ts))
blanchet@33192
   324
       | TYPE (loc, Ts, ts) =>
blanchet@33192
   325
         error ("Invalid type" ^ plural_s_for_list Ts ^
blanchet@33192
   326
                (if null ts then
blanchet@33192
   327
                   ""
blanchet@33192
   328
                 else
blanchet@33192
   329
                   " for term" ^ plural_s_for_list ts ^ " " ^
blanchet@33192
   330
                   commas (map (quote o Syntax.string_of_term ctxt) ts)) ^
blanchet@33192
   331
                " (" ^ quote loc ^ "): " ^
blanchet@63693
   332
                commas (map (Syntax.string_of_typ ctxt) Ts))
blanchet@33192
   333
blanchet@43022
   334
fun pick_nits override_params mode i step state =
blanchet@33192
   335
  let
blanchet@33192
   336
    val thy = Proof.theory_of state
blanchet@33192
   337
    val ctxt = Proof.context_of state
blanchet@33192
   338
    val _ = List.app check_raw_param override_params
blanchet@61315
   339
    val params as {debug, ...} =
blanchet@43022
   340
      extract_params ctxt mode (default_raw_params thy) override_params
blanchet@33192
   341
    fun go () =
wenzelm@58892
   342
      (unknownN, [])
blanchet@43022
   343
      |> (if mode = Auto_Try then perhaps o try
blanchet@33561
   344
          else if debug then fn f => fn x => f x
blanchet@33561
   345
          else handle_exceptions ctxt)
wenzelm@58892
   346
         (fn _ => pick_nits_in_subgoal state params mode i step)
blanchet@61315
   347
  in go () end
blanchet@43020
   348
  |> `(fn (outcome_code, _) => outcome_code = genuineN)
blanchet@33192
   349
blanchet@33192
   350
fun string_for_raw_param (name, value) =
blanchet@33192
   351
  name ^ " = " ^ stringify_raw_param_value value
blanchet@33192
   352
blanchet@35968
   353
fun nitpick_params_trans params =
blanchet@33192
   354
  Toplevel.theory
blanchet@35968
   355
      (fold set_default_raw_param params
blanchet@39316
   356
       #> tap (fn thy =>
blanchet@33561
   357
                  writeln ("Default parameters for Nitpick:\n" ^
blanchet@33561
   358
                           (case rev (default_raw_params thy) of
blanchet@33561
   359
                              [] => "none"
blanchet@33561
   360
                            | params =>
blanchet@33561
   361
                              (map check_raw_param params;
blanchet@33561
   362
                               params |> map string_for_raw_param
blanchet@33561
   363
                                      |> sort_strings |> cat_lines)))))
blanchet@33192
   364
wenzelm@46961
   365
val _ =
wenzelm@59936
   366
  Outer_Syntax.command @{command_keyword nitpick}
wenzelm@46961
   367
    "try to find a counterexample for a given subgoal using Nitpick"
wenzelm@51557
   368
    (parse_params -- Scan.optional Parse.nat 1 >> (fn (params, i) =>
wenzelm@60190
   369
      Toplevel.keep_proof (fn state =>
wenzelm@51557
   370
        ignore (pick_nits params Normal i (Toplevel.proof_position_of state)
wenzelm@51557
   371
          (Toplevel.proof_of state)))))
blanchet@33192
   372
wenzelm@46961
   373
val _ =
wenzelm@59936
   374
  Outer_Syntax.command @{command_keyword nitpick_params}
wenzelm@46961
   375
    "set and display the default parameters for Nitpick"
wenzelm@46961
   376
    (parse_params #>> nitpick_params_trans)
blanchet@33192
   377
blanchet@43022
   378
fun try_nitpick auto = pick_nits [] (if auto then Auto_Try else Try) 1 0
blanchet@33561
   379
wenzelm@56467
   380
val _ = Try.tool_setup (nitpickN, (50, @{system_option auto_nitpick}, try_nitpick))
blanchet@33561
   381
blanchet@33192
   382
end;