src/Tools/quickcheck.ML
author wenzelm
Sun Mar 20 21:28:11 2011 +0100 (2011-03-20 ago)
changeset 42012 2c3fe3cbebae
parent 41862 a38536bf2736
child 42014 75417ef605ba
permissions -rw-r--r--
structure Timing: covers former start_timing/end_timing and Output.timeit etc;
explicit Timing.message function;
eliminated Output.timing flag, cf. Toplevel.timing;
tuned;
     1 (*  Title:      Tools/quickcheck.ML
     2     Author:     Stefan Berghofer, Florian Haftmann, Lukas Bulwahn, TU Muenchen
     3 
     4 Generic counterexample search engine.
     5 *)
     6 
     7 signature QUICKCHECK =
     8 sig
     9   val setup: theory -> theory
    10   (* configuration *)
    11   val auto: bool Unsynchronized.ref
    12   val timing : bool Unsynchronized.ref
    13   val tester : string Config.T
    14   val size : int Config.T
    15   val iterations : int Config.T
    16   val no_assms : bool Config.T
    17   val report : bool Config.T
    18   val quiet : bool Config.T
    19   val timeout : real Config.T
    20   val finite_types : bool Config.T
    21   val finite_type_size : int Config.T
    22   datatype report = Report of
    23     { iterations : int, raised_match_errors : int,
    24       satisfied_assms : int list, positive_concl_tests : int }
    25   datatype expectation = No_Expectation | No_Counterexample | Counterexample;
    26   datatype test_params = Test_Params of {default_type: typ list, expect : expectation};
    27   val test_params_of : Proof.context -> test_params
    28   val map_test_params : (typ list * expectation -> typ list * expectation)
    29     -> Context.generic -> Context.generic
    30   val add_generator:
    31     string * (Proof.context -> term -> int -> term list option * report option)
    32       -> Context.generic -> Context.generic
    33   val add_batch_generator:
    34     string * (Proof.context -> term list -> (int -> term list option) list)
    35       -> Context.generic -> Context.generic
    36   (* testing terms and proof states *)
    37   val test_term: Proof.context -> bool * bool -> term ->
    38     (string * term) list option * ((string * int) list * ((int * report) list) option)
    39   val test_goal_terms:
    40     Proof.context -> bool * bool -> (string * typ) list -> term list
    41       -> (string * term) list option * ((string * int) list * ((int * report) list) option) list
    42   val quickcheck: (string * string list) list -> int -> Proof.state -> (string * term) list option
    43   (* testing a batch of terms *)
    44   val test_terms: Proof.context -> term list -> (string * term) list option list option
    45 end;
    46 
    47 structure Quickcheck : QUICKCHECK =
    48 struct
    49 
    50 (* preferences *)
    51 
    52 val auto = Unsynchronized.ref false;
    53 
    54 val timing = Unsynchronized.ref false;
    55 
    56 val _ =
    57   ProofGeneralPgip.add_preference Preferences.category_tracing
    58   (Unsynchronized.setmp auto true (fn () =>
    59     Preferences.bool_pref auto
    60       "auto-quickcheck"
    61       "Run Quickcheck automatically.") ());
    62 
    63 (* quickcheck report *)
    64 
    65 datatype report = Report of
    66   { iterations : int, raised_match_errors : int,
    67     satisfied_assms : int list, positive_concl_tests : int }
    68 
    69 (* expectation *)
    70 
    71 datatype expectation = No_Expectation | No_Counterexample | Counterexample;
    72 
    73 fun merge_expectation (expect1, expect2) =
    74   if expect1 = expect2 then expect1 else No_Expectation
    75 
    76 (* quickcheck configuration -- default parameters, test generators *)
    77 val (tester, setup_tester) = Attrib.config_string "quickcheck_tester" (K "")
    78 val (size, setup_size) = Attrib.config_int "quickcheck_size" (K 10)
    79 val (iterations, setup_iterations) = Attrib.config_int "quickcheck_iterations" (K 100)
    80 val (no_assms, setup_no_assms) = Attrib.config_bool "quickcheck_no_assms" (K false)
    81 val (report, setup_report) = Attrib.config_bool "quickcheck_report" (K true)
    82 val (quiet, setup_quiet) = Attrib.config_bool "quickcheck_quiet" (K false)
    83 val (timeout, setup_timeout) = Attrib.config_real "quickcheck_timeout" (K 30.0)
    84 val (finite_types, setup_finite_types) = Attrib.config_bool "quickcheck_finite_types" (K true)
    85 val (finite_type_size, setup_finite_type_size) =
    86   Attrib.config_int "quickcheck_finite_type_size" (K 3)
    87 
    88 val setup_config =
    89   setup_tester #> setup_size #> setup_iterations #> setup_no_assms #> setup_report #> setup_quiet
    90     #> setup_timeout #> setup_finite_types #> setup_finite_type_size
    91 
    92 datatype test_params = Test_Params of
    93   {default_type: typ list, expect : expectation};
    94 
    95 fun dest_test_params (Test_Params {default_type, expect}) = (default_type, expect);
    96 
    97 fun make_test_params (default_type, expect) =
    98   Test_Params {default_type = default_type, expect = expect};
    99 
   100 fun map_test_params' f (Test_Params {default_type, expect}) =
   101   make_test_params (f (default_type, expect));
   102 
   103 fun merge_test_params
   104   (Test_Params {default_type = default_type1, expect = expect1},
   105     Test_Params {default_type = default_type2, expect = expect2}) =
   106   make_test_params
   107     (merge (op =) (default_type1, default_type2), merge_expectation (expect1, expect2));
   108 
   109 structure Data = Generic_Data
   110 (
   111   type T =
   112     ((string * (Proof.context -> term -> int -> term list option * report option)) list
   113       * (string * (Proof.context -> term list -> (int -> term list option) list)) list)
   114       * test_params;
   115   val empty = (([], []), Test_Params {default_type = [], expect = No_Expectation});
   116   val extend = I;
   117   fun merge (((generators1, batch_generators1), params1), ((generators2, batch_generators2), params2)) : T =
   118     ((AList.merge (op =) (K true) (generators1, generators2),
   119     AList.merge (op =) (K true) (batch_generators1, batch_generators2)),
   120       merge_test_params (params1, params2));
   121 );
   122 
   123 val test_params_of = snd o Data.get o Context.Proof;
   124 
   125 val default_type = fst o dest_test_params o test_params_of
   126 
   127 val expect = snd o dest_test_params o test_params_of
   128 
   129 val map_test_params = Data.map o apsnd o map_test_params'
   130 
   131 val add_generator = Data.map o apfst o apfst o AList.update (op =);
   132 
   133 val add_batch_generator = Data.map o apfst o apsnd o AList.update (op =);
   134 
   135 (* generating tests *)
   136 
   137 fun gen_mk_tester lookup ctxt v =
   138   let
   139     val name = Config.get ctxt tester
   140     val tester = case lookup ctxt name
   141       of NONE => error ("No such quickcheck tester: " ^ name)
   142       | SOME tester => tester ctxt;
   143   in
   144     if Config.get ctxt quiet then
   145       try tester v
   146     else
   147       let
   148         val tester = Exn.interruptible_capture tester v
   149       in case Exn.get_result tester of
   150           NONE => SOME (Exn.release tester)
   151         | SOME tester => SOME tester
   152       end
   153   end
   154 
   155 val mk_tester = gen_mk_tester (fn ctxt =>
   156   AList.lookup (op =) ((fst o fst o Data.get o Context.Proof) ctxt))
   157 val mk_batch_tester = gen_mk_tester (fn ctxt => AList.lookup (op =) ((snd o fst o Data.get o Context.Proof) ctxt))
   158   
   159 (* testing propositions *)
   160 
   161 fun prep_test_term t =
   162   let
   163     val _ = (null (Term.add_tvars t []) andalso null (Term.add_tfrees t [])) orelse
   164       error "Term to be tested contains type variables";
   165     val _ = null (Term.add_vars t []) orelse
   166       error "Term to be tested contains schematic variables";
   167     val frees = Term.add_frees t [];
   168   in (frees, list_abs_free (frees, t)) end
   169 
   170 fun cpu_time description f =  (* FIXME !? *)
   171   let
   172     val start = Timing.start ()
   173     val result = Exn.capture f ()
   174     val time = Time.toMilliseconds (#cpu (Timing.result start))
   175   in (Exn.release result, (description, time)) end
   176 
   177 fun limit ctxt (limit_time, is_interactive) f exc () =
   178   if limit_time then
   179       TimeLimit.timeLimit (seconds (Config.get ctxt timeout)) f ()
   180     handle TimeLimit.TimeOut =>
   181       if is_interactive then exc () else raise TimeLimit.TimeOut
   182   else
   183     f ()
   184 
   185 fun test_term ctxt (limit_time, is_interactive) t =
   186   let
   187     val (names, t') = apfst (map fst) (prep_test_term t);
   188     val current_size = Unsynchronized.ref 0
   189     fun excipit s =
   190       "Quickcheck " ^ s ^ " while testing at size " ^ string_of_int (!current_size)
   191     val (test_fun, comp_time) = cpu_time "quickcheck compilation" (fn () => mk_tester ctxt t');
   192     fun with_size test_fun k reports =
   193       if k > Config.get ctxt size then
   194         (NONE, reports)
   195       else
   196         let
   197           val _ = if Config.get ctxt quiet then () else Output.urgent_message
   198             ("Test data size: " ^ string_of_int k)
   199           val _ = current_size := k
   200           val ((result, new_report), timing) =
   201             cpu_time ("size " ^ string_of_int k) (fn () => test_fun (k - 1))
   202           val reports = case new_report of NONE => reports | SOME rep => (k, rep) :: reports
   203         in
   204           case result of NONE => with_size test_fun (k + 1) reports | SOME q => (SOME q, reports)
   205         end;
   206   in
   207     case test_fun of NONE => (NONE, ([comp_time], NONE))
   208       | SOME test_fun =>
   209         limit ctxt (limit_time, is_interactive) (fn () =>
   210           let
   211             val ((result, reports), exec_time) =
   212               cpu_time "quickcheck execution" (fn () => with_size test_fun 1 [])
   213           in
   214             (case result of NONE => NONE | SOME ts => SOME (names ~~ ts),
   215               ([exec_time, comp_time],
   216                if Config.get ctxt report andalso not (null reports) then SOME reports else NONE))
   217           end) (fn () => error (excipit "ran out of time")) ()
   218   end;
   219 
   220 fun test_terms ctxt ts =
   221   let
   222     val (namess, ts') = split_list (map (fn t => apfst (map fst) (prep_test_term t)) ts)
   223     val test_funs = mk_batch_tester ctxt ts'
   224     fun with_size tester k =
   225       if k > Config.get ctxt size then NONE
   226       else case tester k of SOME ts => SOME ts | NONE => with_size tester (k + 1)
   227     val results =
   228       Option.map (map (fn test_fun => TimeLimit.timeLimit (seconds (Config.get ctxt timeout))
   229             (fn () => with_size test_fun 1)  ()
   230            handle TimeLimit.TimeOut => NONE)) test_funs
   231   in
   232     Option.map (map2 (fn names => Option.map (fn ts => names ~~ ts)) namess) results
   233   end
   234 
   235 (* FIXME: this function shows that many assumptions are made upon the generation *)
   236 (* In the end there is probably no generic quickcheck interface left... *)
   237 
   238 fun test_term_with_increasing_cardinality ctxt (limit_time, is_interactive) ts =
   239   let
   240     val thy = ProofContext.theory_of ctxt
   241     val (freess, ts') = split_list (map prep_test_term ts)
   242     val Ts = map snd (hd freess)
   243     val (test_funs, comp_time) = cpu_time "quickcheck compilation"
   244       (fn () => map (mk_tester ctxt) ts')
   245     fun test_card_size (card, size) =
   246       (* FIXME: why decrement size by one? *)
   247       case fst (the (nth test_funs (card - 1)) (size - 1)) of
   248         SOME ts => SOME (map fst (nth freess (card - 1)) ~~ ts)
   249       | NONE => NONE
   250     val enumeration_card_size =
   251       if forall (fn T => Sign.of_sort thy (T,  ["Enum.enum"])) Ts then
   252         (* size does not matter *)
   253         map (rpair 0) (1 upto (length ts))
   254       else
   255         (* size does matter *)
   256         map_product pair (1 upto (length ts)) (1 upto (Config.get ctxt size))
   257         |> sort (fn ((c1, s1), (c2, s2)) => int_ord ((c1 + s1), (c2 + s2)))
   258     in
   259       if (forall is_none test_funs) then
   260         (NONE, ([comp_time], NONE))
   261       else if (forall is_some test_funs) then
   262         limit ctxt (limit_time, is_interactive) (fn () =>
   263           (get_first test_card_size enumeration_card_size, ([comp_time], NONE)))
   264           (fn () => error "Quickcheck ran out of time") ()
   265       else
   266         error "Unexpectedly, testers of some cardinalities are executable but others are not"
   267     end
   268 
   269 fun get_finite_types ctxt =
   270   fst (chop (Config.get ctxt finite_type_size)
   271     (map (Type o rpair []) ["Enum.finite_1", "Enum.finite_2", "Enum.finite_3",
   272      "Enum.finite_4", "Enum.finite_5"]))
   273 
   274 exception WELLSORTED of string
   275 
   276 fun monomorphic_term thy insts default_T =
   277   let
   278     fun subst (T as TFree (v, S)) =
   279       let
   280         val T' = AList.lookup (op =) insts v
   281           |> the_default default_T
   282       in if Sign.of_sort thy (T', S) then T'
   283         else raise (WELLSORTED ("For instantiation with default_type " ^
   284           Syntax.string_of_typ_global thy default_T ^
   285           ":\n" ^ Syntax.string_of_typ_global thy T' ^
   286           " to be substituted for variable " ^
   287           Syntax.string_of_typ_global thy T ^ " does not have sort " ^
   288           Syntax.string_of_sort_global thy S))
   289       end
   290       | subst T = T;
   291   in (map_types o map_atyps) subst end;
   292 
   293 datatype wellsorted_error = Wellsorted_Error of string | Term of term
   294 
   295 fun test_goal_terms lthy (limit_time, is_interactive) insts check_goals =
   296   let
   297     val thy = ProofContext.theory_of lthy
   298     val default_insts =
   299       if Config.get lthy finite_types then (get_finite_types lthy) else (default_type lthy)
   300     val inst_goals =
   301       map (fn check_goal =>
   302         if not (null (Term.add_tfree_names check_goal [])) then
   303           map (fn T =>
   304             (pair (SOME T) o Term o Object_Logic.atomize_term thy o monomorphic_term thy insts T)
   305               check_goal
   306               handle WELLSORTED s => (SOME T, Wellsorted_Error s)) default_insts
   307         else
   308           [(NONE, Term (Object_Logic.atomize_term thy check_goal))]) check_goals
   309     val error_msg =
   310       cat_lines
   311         (maps (map_filter (fn (_, Term t) => NONE | (_, Wellsorted_Error s) => SOME s)) inst_goals)
   312     fun is_wellsorted_term (T, Term t) = SOME (T, t)
   313       | is_wellsorted_term (_, Wellsorted_Error s) = NONE
   314     val correct_inst_goals =
   315       case map (map_filter is_wellsorted_term) inst_goals of
   316         [[]] => error error_msg
   317       | xs => xs
   318     val _ = if Config.get lthy quiet then () else warning error_msg
   319     fun collect_results f reports [] = (NONE, rev reports)
   320       | collect_results f reports (t :: ts) =
   321         case f t of
   322           (SOME res, report) => (SOME res, rev (report :: reports))
   323         | (NONE, report) => collect_results f (report :: reports) ts
   324     fun test_term' goal =
   325       case goal of
   326         [(NONE, t)] => test_term lthy (limit_time, is_interactive) t
   327       | ts => test_term_with_increasing_cardinality lthy (limit_time, is_interactive) (map snd ts)
   328   in
   329     if Config.get lthy finite_types then
   330       collect_results test_term' [] correct_inst_goals
   331     else
   332       collect_results (test_term lthy (limit_time, is_interactive)) [] (maps (map snd) correct_inst_goals)
   333   end;
   334 
   335 fun test_goal (time_limit, is_interactive) insts i state =
   336   let
   337     val lthy = Proof.context_of state;
   338     val thy = Proof.theory_of state;
   339     fun strip (Const ("all", _) $ Abs (_, _, t)) = strip t
   340       | strip t = t;
   341     val {goal = st, ...} = Proof.raw_goal state;
   342     val (gi, frees) = Logic.goal_params (prop_of st) i;
   343     val some_locale = case (Option.map #target o Named_Target.peek) lthy
   344      of NONE => NONE
   345       | SOME "" => NONE
   346       | SOME locale => SOME locale;
   347     val assms = if Config.get lthy no_assms then [] else case some_locale
   348      of NONE => Assumption.all_assms_of lthy
   349       | SOME locale => Assumption.local_assms_of lthy (Locale.init locale thy);
   350     val proto_goal = Logic.list_implies (map Thm.term_of assms, subst_bounds (frees, strip gi));
   351     val check_goals = case some_locale
   352      of NONE => [proto_goal]
   353       | SOME locale => map (fn (_, phi) => Morphism.term phi proto_goal)
   354         (Locale.registrations_of (Context.Theory thy) (*FIXME*) locale);
   355   in
   356     test_goal_terms lthy (time_limit, is_interactive) insts check_goals
   357   end
   358 
   359 (* pretty printing *)
   360 
   361 fun tool_name auto = (if auto then "Auto " else "") ^ "Quickcheck"
   362 
   363 fun pretty_counterex ctxt auto NONE = Pretty.str (tool_name auto ^ " found no counterexample.")
   364   | pretty_counterex ctxt auto (SOME cex) =
   365       Pretty.chunks (Pretty.str (tool_name auto ^ " found a counterexample:\n") ::
   366         map (fn (s, t) =>
   367           Pretty.block [Pretty.str (s ^ " ="), Pretty.brk 1, Syntax.pretty_term ctxt t]) (rev cex));
   368 
   369 fun pretty_report (Report {iterations = iterations, raised_match_errors = raised_match_errors,
   370     satisfied_assms = satisfied_assms, positive_concl_tests = positive_concl_tests}) =
   371   let
   372     fun pretty_stat s i = Pretty.block ([Pretty.str (s ^ ": " ^ string_of_int i)])
   373   in
   374      ([pretty_stat "iterations" iterations,
   375      pretty_stat "match exceptions" raised_match_errors]
   376      @ map_index
   377        (fn (i, n) => pretty_stat ("satisfied " ^ string_of_int (i + 1) ^ ". assumption") n)
   378        satisfied_assms
   379      @ [pretty_stat "positive conclusion tests" positive_concl_tests])
   380   end
   381 
   382 fun pretty_reports ctxt (SOME reports) =
   383   Pretty.chunks (Pretty.fbrk :: Pretty.str "Quickcheck report:" ::
   384     maps (fn (size, report) =>
   385       Pretty.str ("size " ^ string_of_int size ^ ":") :: pretty_report report @ [Pretty.brk 1])
   386       (rev reports))
   387   | pretty_reports ctxt NONE = Pretty.str ""
   388 
   389 fun pretty_counterex_and_reports ctxt auto (cex, timing_and_reports) =
   390   Pretty.chunks (pretty_counterex ctxt auto cex ::
   391     map (pretty_reports ctxt) (map snd timing_and_reports))
   392 
   393 (* automatic testing *)
   394 
   395 fun auto_quickcheck state =
   396   let
   397     val ctxt = Proof.context_of state;
   398     val res =
   399       state
   400       |> Proof.map_context (Config.put report false #> Config.put quiet true)
   401       |> try (test_goal (false, false) [] 1);
   402   in
   403     case res of
   404       NONE => (false, state)
   405     | SOME (NONE, report) => (false, state)
   406     | SOME (cex, report) => (true, Proof.goal_message (K (Pretty.chunks [Pretty.str "",
   407         Pretty.mark Markup.hilite (pretty_counterex ctxt true cex)])) state)
   408   end
   409 
   410 val setup = Auto_Tools.register_tool (auto, auto_quickcheck)
   411   #> setup_config
   412 
   413 (* Isar commands *)
   414 
   415 fun read_nat s = case (Library.read_int o Symbol.explode) s
   416  of (k, []) => if k >= 0 then k
   417       else error ("Not a natural number: " ^ s)
   418   | (_, _ :: _) => error ("Not a natural number: " ^ s);
   419 
   420 fun read_bool "false" = false
   421   | read_bool "true" = true
   422   | read_bool s = error ("Not a Boolean value: " ^ s)
   423 
   424 fun read_real s =
   425   case (Real.fromString s) of
   426     SOME s => s
   427   | NONE => error ("Not a real number: " ^ s)
   428 
   429 fun read_expectation "no_expectation" = No_Expectation
   430   | read_expectation "no_counterexample" = No_Counterexample
   431   | read_expectation "counterexample" = Counterexample
   432   | read_expectation s = error ("Not an expectation value: " ^ s)
   433 
   434 fun valid_tester_name genctxt = AList.defined (op =) (fst (fst (Data.get genctxt)))
   435 
   436 fun parse_tester name genctxt =
   437   if valid_tester_name genctxt name then
   438     Config.put_generic tester name genctxt
   439   else
   440     error ("Unknown tester: " ^ name)
   441 
   442 fun parse_test_param ("tester", [arg]) = parse_tester arg
   443   | parse_test_param ("size", [arg]) = Config.put_generic size (read_nat arg)
   444   | parse_test_param ("iterations", [arg]) = Config.put_generic iterations (read_nat arg)
   445   | parse_test_param ("default_type", arg) = (fn gen_ctxt =>
   446     map_test_params
   447       ((apfst o K) (map (ProofContext.read_typ (Context.proof_of gen_ctxt)) arg)) gen_ctxt)
   448   | parse_test_param ("no_assms", [arg]) = Config.put_generic no_assms (read_bool arg)
   449   | parse_test_param ("expect", [arg]) = map_test_params ((apsnd o K) (read_expectation arg))
   450   | parse_test_param ("report", [arg]) = Config.put_generic report (read_bool arg)
   451   | parse_test_param ("quiet", [arg]) = Config.put_generic quiet (read_bool arg)
   452   | parse_test_param ("timeout", [arg]) = Config.put_generic timeout (read_real arg)
   453   | parse_test_param ("finite_types", [arg]) = Config.put_generic finite_types (read_bool arg)
   454   | parse_test_param ("finite_type_size", [arg]) =
   455     Config.put_generic finite_type_size (read_nat arg)
   456   | parse_test_param (name, _) = fn genctxt =>
   457     if valid_tester_name genctxt name then
   458       Config.put_generic tester name genctxt
   459     else error ("Unknown tester or test parameter: " ^ name);
   460 
   461 fun parse_test_param_inst (name, arg) (insts, ctxt) =
   462       case try (ProofContext.read_typ ctxt) name
   463        of SOME (TFree (v, _)) => (apfst o AList.update (op =))
   464               (v, ProofContext.read_typ ctxt (the_single arg)) (insts, ctxt)
   465         | _ => (apsnd o Context.proof_map o parse_test_param) (name, arg) (insts, ctxt);
   466 
   467 fun quickcheck_params_cmd args = Context.theory_map (fold parse_test_param args);
   468 
   469 fun gen_quickcheck args i state =
   470   state
   471   |> Proof.map_context_result (fn ctxt => fold parse_test_param_inst args ([], ctxt))
   472   |> (fn (insts, state') => test_goal (true, true) insts i state'
   473   |> tap (fn (SOME x, _) => if expect (Proof.context_of state') = No_Counterexample then
   474                error ("quickcheck expected to find no counterexample but found one") else ()
   475            | (NONE, _) => if expect (Proof.context_of state') = Counterexample then
   476                error ("quickcheck expected to find a counterexample but did not find one") else ()))
   477 
   478 fun quickcheck args i state = fst (gen_quickcheck args i state);
   479 
   480 fun quickcheck_cmd args i state =
   481   gen_quickcheck args i (Toplevel.proof_of state)
   482   |> Pretty.writeln o pretty_counterex_and_reports (Toplevel.context_of state) false;
   483 
   484 val parse_arg =
   485   Parse.name --
   486     (Scan.optional (Parse.$$$ "=" |--
   487       (((Parse.name || Parse.float_number) >> single) ||
   488         (Parse.$$$ "[" |-- Parse.list1 Parse.name --| Parse.$$$ "]"))) ["true"]);
   489 
   490 val parse_args =
   491   Parse.$$$ "[" |-- Parse.list1 parse_arg --| Parse.$$$ "]" || Scan.succeed [];
   492 
   493 val _ =
   494   Outer_Syntax.command "quickcheck_params" "set parameters for random testing" Keyword.thy_decl
   495     (parse_args >> (fn args => Toplevel.theory (quickcheck_params_cmd args)));
   496 
   497 val _ =
   498   Outer_Syntax.improper_command "quickcheck" "try to find counterexample for subgoal" Keyword.diag
   499     (parse_args -- Scan.optional Parse.nat 1
   500       >> (fn (args, i) => Toplevel.no_timing o Toplevel.keep (quickcheck_cmd args i)));
   501 
   502 end;
   503 
   504 
   505 val auto_quickcheck = Quickcheck.auto;