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