src/Tools/quickcheck.ML
author bulwahn
Wed Jul 21 18:11:51 2010 +0200 (2010-07-21)
changeset 37912 247042107f93
parent 37911 8f99e3880864
child 37913 e85f5ad02a8f
permissions -rw-r--r--
using multiple default types in quickcheck
wenzelm@30824
     1
(*  Title:      Tools/quickcheck.ML
haftmann@28256
     2
    Author:     Stefan Berghofer, Florian Haftmann, TU Muenchen
haftmann@28256
     3
haftmann@28256
     4
Generic counterexample search engine.
haftmann@28256
     5
*)
haftmann@28256
     6
haftmann@28256
     7
signature QUICKCHECK =
haftmann@28256
     8
sig
bulwahn@37910
     9
  val setup: theory -> theory
bulwahn@37910
    10
  (* configuration *)
wenzelm@32740
    11
  val auto: bool Unsynchronized.ref
bulwahn@34948
    12
  val timing : bool Unsynchronized.ref
bulwahn@35378
    13
  datatype report = Report of
bulwahn@35378
    14
    { iterations : int, raised_match_errors : int,
bulwahn@35378
    15
      satisfied_assms : int list, positive_concl_tests : int }
bulwahn@37910
    16
  datatype test_params = Test_Params of
bulwahn@37910
    17
  { size: int, iterations: int, default_type: typ list, no_assms: bool, report: bool, quiet : bool};
bulwahn@37910
    18
  val test_params_of: theory -> test_params 
bulwahn@37910
    19
  val add_generator:
bulwahn@37910
    20
    string * (Proof.context -> bool -> term -> int -> term list option * (bool list * bool))
bulwahn@37910
    21
      -> theory -> theory
bulwahn@37910
    22
  (* testing terms and proof states *)
bulwahn@35378
    23
  val gen_test_term: Proof.context -> bool -> bool -> string option -> int -> int -> term ->
bulwahn@35380
    24
    (string * term) list option * ((string * int) list * ((int * report list) list) option)
wenzelm@30980
    25
  val test_term: Proof.context -> bool -> string option -> int -> int -> term ->
wenzelm@30980
    26
    (string * term) list option
bulwahn@37909
    27
  val quickcheck: (string * string list) list -> int -> Proof.state -> (string * term) list option
haftmann@28256
    28
end;
haftmann@28256
    29
haftmann@28256
    30
structure Quickcheck : QUICKCHECK =
haftmann@28256
    31
struct
haftmann@28256
    32
wenzelm@30980
    33
(* preferences *)
wenzelm@30980
    34
wenzelm@32740
    35
val auto = Unsynchronized.ref false;
wenzelm@30980
    36
bulwahn@34948
    37
val timing = Unsynchronized.ref false;
bulwahn@34948
    38
wenzelm@30980
    39
val _ =
wenzelm@30980
    40
  ProofGeneralPgip.add_preference Preferences.category_tracing
wenzelm@32966
    41
  (setmp_CRITICAL auto true (fn () =>
wenzelm@30980
    42
    Preferences.bool_pref auto
wenzelm@30980
    43
      "auto-quickcheck"
blanchet@33561
    44
      "Whether to run Quickcheck automatically.") ());
wenzelm@30980
    45
bulwahn@35378
    46
(* quickcheck report *)
bulwahn@35378
    47
bulwahn@35378
    48
datatype single_report = Run of bool list * bool | MatchExc
bulwahn@35378
    49
bulwahn@35378
    50
datatype report = Report of
bulwahn@35378
    51
  { iterations : int, raised_match_errors : int,
bulwahn@35378
    52
    satisfied_assms : int list, positive_concl_tests : int }
bulwahn@35378
    53
bulwahn@35378
    54
fun collect_single_report single_report
bulwahn@35378
    55
    (Report {iterations = iterations, raised_match_errors = raised_match_errors,
bulwahn@35378
    56
    satisfied_assms = satisfied_assms, positive_concl_tests = positive_concl_tests}) =
bulwahn@35378
    57
  case single_report
bulwahn@35378
    58
  of MatchExc =>
bulwahn@35378
    59
    Report {iterations = iterations + 1, raised_match_errors = raised_match_errors + 1,
bulwahn@35378
    60
      satisfied_assms = satisfied_assms, positive_concl_tests = positive_concl_tests}
bulwahn@35378
    61
   | Run (assms, concl) =>
bulwahn@35378
    62
    Report {iterations = iterations + 1, raised_match_errors = raised_match_errors,
bulwahn@35378
    63
      satisfied_assms =
bulwahn@35378
    64
        map2 (fn b => fn s => if b then s + 1 else s) assms
bulwahn@35378
    65
         (if null satisfied_assms then replicate (length assms) 0 else satisfied_assms),
bulwahn@35378
    66
      positive_concl_tests = if concl then positive_concl_tests + 1 else positive_concl_tests}
haftmann@30973
    67
haftmann@28315
    68
(* quickcheck configuration -- default parameters, test generators *)
haftmann@28315
    69
haftmann@28309
    70
datatype test_params = Test_Params of
bulwahn@37909
    71
  { size: int, iterations: int, default_type: typ list, no_assms: bool, report: bool, quiet : bool};
haftmann@28309
    72
bulwahn@35379
    73
fun dest_test_params (Test_Params { size, iterations, default_type, no_assms, report, quiet }) =
bulwahn@35379
    74
  ((size, iterations), ((default_type, no_assms), (report, quiet)));
bulwahn@35379
    75
fun make_test_params ((size, iterations), ((default_type, no_assms), (report, quiet))) =
blanchet@34128
    76
  Test_Params { size = size, iterations = iterations, default_type = default_type,
bulwahn@35379
    77
                no_assms = no_assms, report = report, quiet = quiet };
bulwahn@35379
    78
fun map_test_params f (Test_Params { size, iterations, default_type, no_assms, report, quiet }) =
bulwahn@35379
    79
  make_test_params (f ((size, iterations), ((default_type, no_assms), (report, quiet))));
blanchet@34128
    80
fun merge_test_params (Test_Params { size = size1, iterations = iterations1, default_type = default_type1,
bulwahn@35379
    81
                                     no_assms = no_assms1, report = report1, quiet = quiet1 },
blanchet@34128
    82
  Test_Params { size = size2, iterations = iterations2, default_type = default_type2,
bulwahn@35379
    83
                no_assms = no_assms2, report = report2, quiet = quiet2 }) =
haftmann@31599
    84
  make_test_params ((Int.max (size1, size2), Int.max (iterations1, iterations2)),
bulwahn@37911
    85
    ((merge (op =) (default_type1, default_type2), no_assms1 orelse no_assms2),
bulwahn@35379
    86
    (report1 orelse report2, quiet1 orelse quiet2)));
haftmann@28309
    87
wenzelm@33522
    88
structure Data = Theory_Data
wenzelm@33522
    89
(
bulwahn@35378
    90
  type T = (string * (Proof.context -> bool -> term -> int -> term list option * (bool list * bool))) list
haftmann@28309
    91
    * test_params;
bulwahn@35378
    92
  val empty = ([], Test_Params
bulwahn@37909
    93
    { size = 10, iterations = 100, default_type = [], no_assms = false, report = false, quiet = false});
haftmann@28256
    94
  val extend = I;
wenzelm@33522
    95
  fun merge ((generators1, params1), (generators2, params2)) : T =
wenzelm@33522
    96
    (AList.merge (op =) (K true) (generators1, generators2),
haftmann@28309
    97
      merge_test_params (params1, params2));
wenzelm@33522
    98
);
haftmann@28256
    99
bulwahn@37910
   100
val test_params_of = snd o Data.get;
bulwahn@37910
   101
haftmann@28309
   102
val add_generator = Data.map o apfst o AList.update (op =);
haftmann@28309
   103
haftmann@28315
   104
(* generating tests *)
haftmann@28315
   105
haftmann@28309
   106
fun mk_tester_select name ctxt =
haftmann@28309
   107
  case AList.lookup (op =) ((fst o Data.get o ProofContext.theory_of) ctxt) name
haftmann@28309
   108
   of NONE => error ("No such quickcheck generator: " ^ name)
haftmann@28309
   109
    | SOME generator => generator ctxt;
haftmann@28309
   110
bulwahn@35378
   111
fun mk_testers ctxt report t =
haftmann@28309
   112
  (map snd o fst o Data.get o ProofContext.theory_of) ctxt
bulwahn@35378
   113
  |> map_filter (fn generator => try (generator ctxt report) t);
haftmann@28309
   114
bulwahn@35378
   115
fun mk_testers_strict ctxt report t =
haftmann@28309
   116
  let
haftmann@28309
   117
    val generators = ((map snd o fst o Data.get o ProofContext.theory_of) ctxt)
bulwahn@35378
   118
    val testers = map (fn generator => Exn.capture (generator ctxt report) t) generators;
haftmann@28309
   119
  in if forall (is_none o Exn.get_result) testers
haftmann@28309
   120
    then [(Exn.release o snd o split_last) testers]
haftmann@28309
   121
    else map_filter Exn.get_result testers
haftmann@28309
   122
  end;
haftmann@28309
   123
haftmann@28315
   124
haftmann@28315
   125
(* testing propositions *)
haftmann@28315
   126
haftmann@28309
   127
fun prep_test_term t =
haftmann@28309
   128
  let
wenzelm@29266
   129
    val _ = (null (Term.add_tvars t []) andalso null (Term.add_tfrees t [])) orelse
haftmann@28309
   130
      error "Term to be tested contains type variables";
wenzelm@29266
   131
    val _ = null (Term.add_vars t []) orelse
haftmann@28309
   132
      error "Term to be tested contains schematic variables";
haftmann@31138
   133
    val frees = Term.add_frees t [];
haftmann@28309
   134
  in (map fst frees, list_abs_free (frees, t)) end
haftmann@28256
   135
bulwahn@35324
   136
fun cpu_time description f =
bulwahn@35324
   137
  let
bulwahn@35324
   138
    val start = start_timing ()
bulwahn@35324
   139
    val result = Exn.capture f ()
bulwahn@35324
   140
    val time = Time.toMilliseconds (#cpu (end_timing start))
bulwahn@35324
   141
  in (Exn.release result, (description, time)) end
bulwahn@35324
   142
bulwahn@35378
   143
fun gen_test_term ctxt quiet report generator_name size i t =
haftmann@28309
   144
  let
haftmann@28309
   145
    val (names, t') = prep_test_term t;
bulwahn@35324
   146
    val (testers, comp_time) = cpu_time "quickcheck compilation"
bulwahn@35324
   147
      (fn () => (case generator_name
bulwahn@35378
   148
       of NONE => if quiet then mk_testers ctxt report t' else mk_testers_strict ctxt report t'
bulwahn@35378
   149
        | SOME name => [mk_tester_select name ctxt report t']));
bulwahn@35378
   150
    fun iterate f 0 report = (NONE, report)
bulwahn@35378
   151
      | iterate f j report =
bulwahn@35378
   152
        let
bulwahn@35378
   153
          val (test_result, single_report) = apsnd Run (f ()) handle Match => (if quiet then ()
bulwahn@35378
   154
             else warning "Exception Match raised during quickcheck"; (NONE, MatchExc))
bulwahn@35378
   155
          val report = collect_single_report single_report report
bulwahn@35378
   156
        in
bulwahn@35378
   157
          case test_result of NONE => iterate f (j - 1) report | SOME q => (SOME q, report)
bulwahn@35378
   158
        end
bulwahn@35378
   159
    val empty_report = Report { iterations = 0, raised_match_errors = 0,
bulwahn@35378
   160
      satisfied_assms = [], positive_concl_tests = 0 }
bulwahn@35378
   161
    fun with_testers k [] = (NONE, [])
haftmann@28309
   162
      | with_testers k (tester :: testers) =
bulwahn@35378
   163
          case iterate (fn () => tester (k - 1)) i empty_report
bulwahn@35378
   164
           of (NONE, report) => apsnd (cons report) (with_testers k testers)
bulwahn@35378
   165
            | (SOME q, report) => (SOME q, [report]);
bulwahn@35378
   166
    fun with_size k reports = if k > size then (NONE, reports)
haftmann@28309
   167
      else (if quiet then () else priority ("Test data size: " ^ string_of_int k);
bulwahn@35378
   168
        let
bulwahn@35378
   169
          val (result, new_report) = with_testers k testers
bulwahn@35378
   170
          val reports = ((k, new_report) :: reports)
bulwahn@35378
   171
        in case result of NONE => with_size (k + 1) reports | SOME q => (SOME q, reports) end);
bulwahn@35378
   172
    val ((result, reports), exec_time) = cpu_time "quickcheck execution"
bulwahn@35378
   173
      (fn () => apfst
bulwahn@35378
   174
         (fn result => case result of NONE => NONE
bulwahn@35378
   175
        | SOME ts => SOME (names ~~ ts)) (with_size 1 []))
bulwahn@34948
   176
  in
bulwahn@35380
   177
    (result, ([exec_time, comp_time], if report then SOME reports else NONE))
haftmann@28309
   178
  end;
haftmann@28309
   179
bulwahn@35324
   180
fun test_term ctxt quiet generator_name size i t =
bulwahn@35378
   181
  fst (gen_test_term ctxt quiet false generator_name size i t)
bulwahn@35324
   182
haftmann@28309
   183
fun monomorphic_term thy insts default_T = 
haftmann@28309
   184
  let
haftmann@28309
   185
    fun subst (T as TFree (v, S)) =
haftmann@28309
   186
          let
haftmann@28309
   187
            val T' = AList.lookup (op =) insts v
bulwahn@37912
   188
              |> the_default default_T
haftmann@28315
   189
          in if Sign.of_sort thy (T, S) then T'
haftmann@28309
   190
            else error ("Type " ^ Syntax.string_of_typ_global thy T ^
haftmann@28309
   191
              " to be substituted for variable " ^
haftmann@28309
   192
              Syntax.string_of_typ_global thy T ^ "\ndoes not have sort " ^
haftmann@28309
   193
              Syntax.string_of_sort_global thy S)
haftmann@28309
   194
          end
haftmann@28309
   195
      | subst T = T;
haftmann@28309
   196
  in (map_types o map_atyps) subst end;
haftmann@28309
   197
bulwahn@35378
   198
fun test_goal quiet report generator_name size iterations default_T no_assms insts i assms state =
haftmann@28309
   199
  let
haftmann@28309
   200
    val ctxt = Proof.context_of state;
haftmann@28309
   201
    val thy = Proof.theory_of state;
haftmann@28309
   202
    fun strip (Const ("all", _) $ Abs (_, _, t)) = strip t
haftmann@28309
   203
      | strip t = t;
wenzelm@33291
   204
    val {goal = st, ...} = Proof.raw_goal state;
haftmann@28309
   205
    val (gi, frees) = Logic.goal_params (prop_of st) i;
bulwahn@37912
   206
    val gis' = Logic.list_implies (if no_assms then [] else assms,
blanchet@34128
   207
                                  subst_bounds (frees, strip gi))
bulwahn@37912
   208
      |> (fn t => map (fn T => monomorphic_term thy insts T t) default_T)  
bulwahn@37912
   209
      |> map (Object_Logic.atomize_term thy);
bulwahn@37912
   210
    fun collect_results f reports [] = (NONE, rev reports)
bulwahn@37912
   211
      | collect_results f reports (t :: ts) =
bulwahn@37912
   212
        case f t of
bulwahn@37912
   213
          (SOME res, report) => (SOME res, rev (report :: reports))
bulwahn@37912
   214
        | (NONE, report) => collect_results f (report :: reports) ts
bulwahn@37912
   215
  in (collect_results (gen_test_term ctxt quiet report generator_name size iterations) [] gis') end;
bulwahn@37912
   216
bulwahn@37912
   217
(* pretty printing *)
haftmann@28315
   218
blanchet@35077
   219
fun pretty_counterex ctxt NONE = Pretty.str "Quickcheck found no counterexample."
haftmann@28315
   220
  | pretty_counterex ctxt (SOME cex) =
blanchet@35077
   221
      Pretty.chunks (Pretty.str "Quickcheck found a counterexample:\n" ::
haftmann@28315
   222
        map (fn (s, t) =>
haftmann@28315
   223
          Pretty.block [Pretty.str (s ^ " ="), Pretty.brk 1, Syntax.pretty_term ctxt t]) cex);
haftmann@28315
   224
bulwahn@35378
   225
fun pretty_report (Report {iterations = iterations, raised_match_errors = raised_match_errors,
bulwahn@35378
   226
    satisfied_assms = satisfied_assms, positive_concl_tests = positive_concl_tests}) =
bulwahn@35378
   227
  let
bulwahn@35378
   228
    fun pretty_stat s i = Pretty.block ([Pretty.str (s ^ ": " ^ string_of_int i)])
bulwahn@35378
   229
  in
bulwahn@35378
   230
     ([pretty_stat "iterations" iterations,
bulwahn@35378
   231
     pretty_stat "match exceptions" raised_match_errors]
bulwahn@35378
   232
     @ map_index (fn (i, n) => pretty_stat ("satisfied " ^ string_of_int (i + 1) ^ ". assumption") n)
bulwahn@35378
   233
       satisfied_assms
bulwahn@35378
   234
     @ [pretty_stat "positive conclusion tests" positive_concl_tests])
bulwahn@35378
   235
  end
bulwahn@35378
   236
bulwahn@35378
   237
fun pretty_reports' [report] = [Pretty.chunks (pretty_report report)]
bulwahn@35378
   238
  | pretty_reports' reports =
bulwahn@35378
   239
  map_index (fn (i, report) =>
bulwahn@35378
   240
    Pretty.chunks (Pretty.str (string_of_int (i + 1) ^ ". generator:\n") :: pretty_report report))
bulwahn@35378
   241
    reports
bulwahn@35378
   242
bulwahn@35380
   243
fun pretty_reports ctxt (SOME reports) =
bulwahn@35378
   244
  Pretty.chunks (Pretty.str "Quickcheck report:" ::
bulwahn@35378
   245
    maps (fn (size, reports) =>
bulwahn@35378
   246
      Pretty.str ("size " ^ string_of_int size ^ ":") :: pretty_reports' reports @ [Pretty.brk 1])
bulwahn@35378
   247
      (rev reports))
bulwahn@35380
   248
  | pretty_reports ctxt NONE = Pretty.str ""
bulwahn@35378
   249
bulwahn@37912
   250
fun pretty_counterex_and_reports ctxt (cex, timing_and_reports) =
bulwahn@37912
   251
  Pretty.chunks (pretty_counterex ctxt cex :: map (pretty_reports ctxt) (map snd timing_and_reports))
haftmann@28315
   252
haftmann@28315
   253
(* automatic testing *)
haftmann@28309
   254
blanchet@33561
   255
fun auto_quickcheck state =
blanchet@33561
   256
  if not (!auto) then
blanchet@33561
   257
    (false, state)
blanchet@33561
   258
  else
blanchet@33561
   259
    let
blanchet@33561
   260
      val ctxt = Proof.context_of state;
blanchet@33561
   261
      val assms = map term_of (Assumption.all_assms_of ctxt);
bulwahn@35379
   262
      val Test_Params { size, iterations, default_type, no_assms, report, quiet } =
blanchet@33561
   263
        (snd o Data.get o Proof.theory_of) state;
blanchet@33561
   264
      val res =
bulwahn@35378
   265
        try (test_goal true false NONE size iterations default_type no_assms [] 1 assms) state;
blanchet@33561
   266
    in
blanchet@33561
   267
      case res of
blanchet@33561
   268
        NONE => (false, state)
bulwahn@35378
   269
      | SOME (NONE, report) => (false, state)
bulwahn@35378
   270
      | SOME (cex, report) => (true, Proof.goal_message (K (Pretty.chunks [Pretty.str "",
blanchet@33561
   271
          Pretty.mark Markup.hilite (pretty_counterex ctxt cex)])) state)
blanchet@33561
   272
    end
blanchet@33561
   273
blanchet@33561
   274
val setup = Auto_Counterexample.register_tool ("quickcheck", auto_quickcheck)
haftmann@28315
   275
haftmann@28315
   276
wenzelm@30980
   277
(* Isar commands *)
haftmann@28315
   278
haftmann@28336
   279
fun read_nat s = case (Library.read_int o Symbol.explode) s
haftmann@28336
   280
 of (k, []) => if k >= 0 then k
haftmann@28336
   281
      else error ("Not a natural number: " ^ s)
haftmann@28336
   282
  | (_, _ :: _) => error ("Not a natural number: " ^ s);
bulwahn@37909
   283
blanchet@34128
   284
fun read_bool "false" = false
blanchet@34128
   285
  | read_bool "true" = true
blanchet@34128
   286
  | read_bool s = error ("Not a Boolean value: " ^ s)
haftmann@28315
   287
bulwahn@37909
   288
fun parse_test_param ctxt ("size", [arg]) =
haftmann@28336
   289
      (apfst o apfst o K) (read_nat arg)
bulwahn@37909
   290
  | parse_test_param ctxt ("iterations", [arg]) =
haftmann@28336
   291
      (apfst o apsnd o K) (read_nat arg)
haftmann@28336
   292
  | parse_test_param ctxt ("default_type", arg) =
bulwahn@37909
   293
      (apsnd o apfst o apfst o K) (map (ProofContext.read_typ ctxt) arg)
bulwahn@37909
   294
  | parse_test_param ctxt ("no_assms", [arg]) =
bulwahn@35378
   295
      (apsnd o apfst o apsnd o K) (read_bool arg)
bulwahn@37909
   296
  | parse_test_param ctxt ("report", [arg]) =
bulwahn@35379
   297
      (apsnd o apsnd o apfst o K) (read_bool arg)
bulwahn@37909
   298
  | parse_test_param ctxt ("quiet", [arg]) =
bulwahn@35379
   299
      (apsnd o apsnd o apsnd o K) (read_bool arg)
haftmann@28336
   300
  | parse_test_param ctxt (name, _) =
blanchet@34128
   301
      error ("Unknown test parameter: " ^ name);
haftmann@28315
   302
bulwahn@37909
   303
fun parse_test_param_inst ctxt ("generator", [arg]) =
haftmann@28336
   304
      (apsnd o apfst o K o SOME) arg
haftmann@28336
   305
  | parse_test_param_inst ctxt (name, arg) =
haftmann@28336
   306
      case try (ProofContext.read_typ ctxt) name
haftmann@28336
   307
       of SOME (TFree (v, _)) => (apsnd o apsnd o AList.update (op =))
bulwahn@37909
   308
              (v, ProofContext.read_typ ctxt (the_single arg))
haftmann@28336
   309
        | _ => (apfst o parse_test_param ctxt) (name, arg);
haftmann@28309
   310
haftmann@28336
   311
fun quickcheck_params_cmd args thy =
haftmann@28315
   312
  let
wenzelm@36610
   313
    val ctxt = ProofContext.init_global thy;
haftmann@28336
   314
    val f = fold (parse_test_param ctxt) args;
haftmann@28315
   315
  in
haftmann@28315
   316
    thy
haftmann@28336
   317
    |> (Data.map o apsnd o map_test_params) f
haftmann@28315
   318
  end;
haftmann@28315
   319
bulwahn@35378
   320
fun gen_quickcheck args i state =
haftmann@28315
   321
  let
boehmes@32297
   322
    val thy = Proof.theory_of state;
boehmes@32297
   323
    val ctxt = Proof.context_of state;
blanchet@34128
   324
    val assms = map term_of (Assumption.all_assms_of ctxt);
haftmann@28315
   325
    val default_params = (dest_test_params o snd o Data.get) thy;
haftmann@28336
   326
    val f = fold (parse_test_param_inst ctxt) args;
bulwahn@35379
   327
    val (((size, iterations), ((default_type, no_assms), (report, quiet))), (generator_name, insts)) =
haftmann@28336
   328
      f (default_params, (NONE, []));
boehmes@32297
   329
  in
bulwahn@35379
   330
    test_goal quiet report generator_name size iterations default_type no_assms insts i assms state
boehmes@32297
   331
  end;
boehmes@32297
   332
wenzelm@36960
   333
fun quickcheck args i state = fst (gen_quickcheck args i state);
bulwahn@35378
   334
boehmes@32297
   335
fun quickcheck_cmd args i state =
bulwahn@35378
   336
  gen_quickcheck args i (Toplevel.proof_of state)
bulwahn@35378
   337
  |> Pretty.writeln o pretty_counterex_and_reports (Toplevel.context_of state);
haftmann@28309
   338
bulwahn@37909
   339
val parse_arg = Parse.name -- (Scan.optional (Parse.$$$ "=" |-- 
bulwahn@37909
   340
  ((Parse.name >> single) || (Parse.$$$ "[" |-- Parse.list1 Parse.name --| Parse.$$$ "]"))) ["true"]);
haftmann@28309
   341
wenzelm@36960
   342
val parse_args = Parse.$$$ "[" |-- Parse.list1 parse_arg --| Parse.$$$ "]"
haftmann@28336
   343
  || Scan.succeed [];
haftmann@28336
   344
wenzelm@36960
   345
val _ =
wenzelm@36960
   346
  Outer_Syntax.command "quickcheck_params" "set parameters for random testing" Keyword.thy_decl
wenzelm@36960
   347
    (parse_args >> (fn args => Toplevel.theory (quickcheck_params_cmd args)));
haftmann@28309
   348
wenzelm@36960
   349
val _ =
wenzelm@36960
   350
  Outer_Syntax.improper_command "quickcheck" "try to find counterexample for subgoal" Keyword.diag
wenzelm@36960
   351
    (parse_args -- Scan.optional Parse.nat 1
wenzelm@36960
   352
      >> (fn (args, i) => Toplevel.no_timing o Toplevel.keep (quickcheck_cmd args i)));
haftmann@28309
   353
haftmann@28315
   354
end;
haftmann@28309
   355
haftmann@28309
   356
haftmann@28315
   357
val auto_quickcheck = Quickcheck.auto;