src/HOL/ex/Quickcheck.thy
author haftmann
Mon Sep 22 08:00:26 2008 +0200 (2008-09-22)
changeset 28309 c24bc53c815c
parent 28228 7ebe8dc06cbb
child 28315 d3cf88fe77bc
permissions -rw-r--r--
some steps towards generic quickcheck framework
haftmann@26265
     1
(*  ID:         $Id$
haftmann@26265
     2
    Author:     Florian Haftmann, TU Muenchen
haftmann@26265
     3
*)
haftmann@26265
     4
haftmann@26265
     5
header {* A simple counterexample generator *}
haftmann@26265
     6
haftmann@26265
     7
theory Quickcheck
haftmann@28228
     8
imports Random Code_Eval
haftmann@26265
     9
begin
haftmann@26265
    10
haftmann@26265
    11
subsection {* The @{text random} class *}
haftmann@26265
    12
haftmann@26325
    13
class random = rtype +
haftmann@26325
    14
  fixes random :: "index \<Rightarrow> seed \<Rightarrow> ('a \<times> (unit \<Rightarrow> term)) \<times> seed"
haftmann@26265
    15
haftmann@26267
    16
text {* Type @{typ "'a itself"} *}
haftmann@26265
    17
haftmann@26325
    18
instantiation itself :: ("{type, rtype}") random
haftmann@26265
    19
begin
haftmann@26265
    20
haftmann@26265
    21
definition
haftmann@28228
    22
  "random _ = return (TYPE('a), \<lambda>u. Code_Eval.Const (STR ''TYPE'') RTYPE('a))"
haftmann@26265
    23
haftmann@26265
    24
instance ..
haftmann@26265
    25
haftmann@26265
    26
end
haftmann@26265
    27
haftmann@26267
    28
text {* Datatypes *}
haftmann@26267
    29
haftmann@28145
    30
definition
haftmann@28145
    31
  collapse :: "('a \<Rightarrow> ('a \<Rightarrow> 'b \<times> 'a) \<times> 'a) \<Rightarrow> 'a \<Rightarrow> 'b \<times> 'a" where
haftmann@28145
    32
  "collapse f = (do g \<leftarrow> f; g done)"
haftmann@28145
    33
haftmann@28145
    34
ML {*
haftmann@28145
    35
structure StateMonad =
haftmann@28145
    36
struct
haftmann@28145
    37
haftmann@28145
    38
fun liftT T sT = sT --> HOLogic.mk_prodT (T, sT);
haftmann@28145
    39
fun liftT' sT = sT --> sT;
haftmann@28145
    40
haftmann@28145
    41
fun return T sT x = Const (@{const_name return}, T --> liftT T sT) $ x;
haftmann@28145
    42
haftmann@28145
    43
fun scomp T1 T2 sT f g = Const (@{const_name scomp},
haftmann@28145
    44
  liftT T1 sT --> (T1 --> liftT T2 sT) --> liftT T2 sT) $ f $ g;
haftmann@28145
    45
haftmann@28145
    46
end;
haftmann@28145
    47
*}
haftmann@28145
    48
haftmann@26267
    49
lemma random'_if:
haftmann@26325
    50
  fixes random' :: "index \<Rightarrow> index \<Rightarrow> seed \<Rightarrow> ('a \<times> (unit \<Rightarrow> term)) \<times> seed"
haftmann@26265
    51
  assumes "random' 0 j = undefined"
haftmann@26265
    52
    and "\<And>i. random' (Suc_index i) j = rhs2 i"
haftmann@26265
    53
  shows "random' i j s = (if i = 0 then undefined else rhs2 (i - 1) s)"
haftmann@26265
    54
  by (cases i rule: index.exhaust) (insert assms, simp_all add: undefined_fun)
haftmann@26265
    55
haftmann@26265
    56
setup {*
haftmann@26265
    57
let
haftmann@26267
    58
  exception REC of string;
haftmann@26267
    59
  fun mk_collapse thy ty = Sign.mk_const thy
haftmann@26267
    60
    (@{const_name collapse}, [@{typ seed}, ty]);
haftmann@26325
    61
  fun term_ty ty = HOLogic.mk_prodT (ty, @{typ "unit \<Rightarrow> term"});
haftmann@26325
    62
  fun mk_split thy ty ty' = Sign.mk_const thy
haftmann@26325
    63
    (@{const_name split}, [ty, @{typ "unit \<Rightarrow> term"}, StateMonad.liftT (term_ty ty') @{typ seed}]);
haftmann@26589
    64
  fun mk_scomp_split thy ty ty' t t' =
haftmann@26589
    65
    StateMonad.scomp (term_ty ty) (term_ty ty') @{typ seed} t
haftmann@26325
    66
      (mk_split thy ty ty' $ Abs ("", ty, Abs ("", @{typ "unit \<Rightarrow> term"}, t')))
haftmann@26325
    67
  fun mk_cons thy this_ty (c, args) =
haftmann@26265
    68
    let
haftmann@26267
    69
      val tys = map (fst o fst) args;
haftmann@26325
    70
      val c_ty = tys ---> this_ty;
haftmann@26325
    71
      val c = Const (c, tys ---> this_ty);
haftmann@26325
    72
      val t_indices = map (curry ( op * ) 2) (length tys - 1 downto 0);
haftmann@26325
    73
      val c_indices = map (curry ( op + ) 1) t_indices;
haftmann@26325
    74
      val c_t = list_comb (c, map Bound c_indices);
haftmann@26325
    75
      val t_t = Abs ("", @{typ unit}, Eval.mk_term Free RType.rtype
haftmann@26325
    76
        (list_comb (c, map (fn k => Bound (k + 1)) t_indices))
haftmann@26325
    77
        |> map_aterms (fn t as Bound _ => t $ @{term "()"} | t => t));
haftmann@26325
    78
      val return = StateMonad.return (term_ty this_ty) @{typ seed}
haftmann@26325
    79
        (HOLogic.mk_prod (c_t, t_t));
haftmann@26325
    80
      val t = fold_rev (fn ((ty, _), random) =>
haftmann@26589
    81
        mk_scomp_split thy ty this_ty random)
haftmann@26267
    82
          args return;
haftmann@26267
    83
      val is_rec = exists (snd o fst) args;
haftmann@28145
    84
    in (is_rec, t) end;
haftmann@26267
    85
  fun mk_conss thy ty [] = NONE
haftmann@26267
    86
    | mk_conss thy ty [(_, t)] = SOME t
haftmann@26325
    87
    | mk_conss thy ty ts = SOME (mk_collapse thy (term_ty ty) $
haftmann@26325
    88
          (Sign.mk_const thy (@{const_name select}, [StateMonad.liftT (term_ty ty) @{typ seed}]) $
haftmann@26325
    89
            HOLogic.mk_list (StateMonad.liftT (term_ty ty) @{typ seed}) (map snd ts)));
haftmann@26267
    90
  fun mk_clauses thy ty (tyco, (ts_rec, ts_atom)) = 
haftmann@26267
    91
    let
haftmann@26267
    92
      val SOME t_atom = mk_conss thy ty ts_atom;
haftmann@26267
    93
    in case mk_conss thy ty ts_rec
haftmann@26325
    94
     of SOME t_rec => mk_collapse thy (term_ty ty) $
haftmann@26325
    95
          (Sign.mk_const thy (@{const_name select_default}, [StateMonad.liftT (term_ty ty) @{typ seed}]) $
haftmann@26267
    96
             @{term "i\<Colon>index"} $ t_rec $ t_atom)
haftmann@26267
    97
      | NONE => t_atom
haftmann@26267
    98
    end;
haftmann@26325
    99
  fun mk_random_eqs thy vs tycos =
haftmann@26267
   100
    let
haftmann@26267
   101
      val this_ty = Type (hd tycos, map TFree vs);
haftmann@26325
   102
      val this_ty' = StateMonad.liftT (term_ty this_ty) @{typ seed};
haftmann@26267
   103
      val random_name = NameSpace.base @{const_name random};
haftmann@26267
   104
      val random'_name = random_name ^ "_" ^ Class.type_name (hd tycos) ^ "'";
haftmann@26267
   105
      fun random ty = Sign.mk_const thy (@{const_name random}, [ty]);
haftmann@26267
   106
      val random' = Free (random'_name,
haftmann@26267
   107
        @{typ index} --> @{typ index} --> this_ty');
haftmann@26267
   108
      fun atom ty = ((ty, false), random ty $ @{term "j\<Colon>index"});
haftmann@26267
   109
      fun dtyp tyco = ((this_ty, true), random' $ @{term "i\<Colon>index"} $ @{term "j\<Colon>index"});
haftmann@26267
   110
      fun rtyp tyco tys = raise REC
haftmann@26267
   111
        ("Will not generate random elements for mutual recursive type " ^ quote (hd tycos));
haftmann@26267
   112
      val rhss = DatatypePackage.construction_interpretation thy
haftmann@26267
   113
            { atom = atom, dtyp = dtyp, rtyp = rtyp } vs tycos
haftmann@26325
   114
        |> (map o apsnd o map) (mk_cons thy this_ty) 
haftmann@26267
   115
        |> (map o apsnd) (List.partition fst)
haftmann@26267
   116
        |> map (mk_clauses thy this_ty)
haftmann@26267
   117
      val eqss = map ((apsnd o map) (HOLogic.mk_Trueprop o HOLogic.mk_eq) o (fn rhs => ((this_ty, random'), [
haftmann@26267
   118
          (random' $ @{term "0\<Colon>index"} $ @{term "j\<Colon>index"}, Const (@{const_name undefined}, this_ty')),
haftmann@26267
   119
          (random' $ @{term "Suc_index i"} $ @{term "j\<Colon>index"}, rhs)
haftmann@26267
   120
        ]))) rhss;
haftmann@26267
   121
    in eqss end;
haftmann@26267
   122
  fun random_inst [tyco] thy =
haftmann@26265
   123
        let
haftmann@26267
   124
          val (raw_vs, _) = DatatypePackage.the_datatype_spec thy tyco;
haftmann@26267
   125
          val vs = (map o apsnd)
haftmann@26267
   126
            (curry (Sorts.inter_sort (Sign.classes_of thy)) @{sort random}) raw_vs;
haftmann@26267
   127
          val { descr, index, ... } = DatatypePackage.the_datatype thy tyco;
haftmann@26325
   128
          val ((this_ty, random'), eqs') = singleton (mk_random_eqs thy vs) tyco;
haftmann@26267
   129
          val eq = (HOLogic.mk_Trueprop o HOLogic.mk_eq)
haftmann@26267
   130
            (Sign.mk_const thy (@{const_name random}, [this_ty]) $ @{term "i\<Colon>index"},
haftmann@26267
   131
               random' $ @{term "i\<Colon>index"} $ @{term "i\<Colon>index"})
haftmann@26267
   132
          val del_func = Attrib.internal (fn _ => Thm.declaration_attribute
haftmann@26267
   133
            (fn thm => Context.mapping (Code.del_func thm) I));
haftmann@26267
   134
          fun add_code simps lthy =
haftmann@26267
   135
            let
haftmann@26267
   136
              val thy = ProofContext.theory_of lthy;
haftmann@26267
   137
              val thm = @{thm random'_if}
haftmann@26267
   138
                |> Drule.instantiate' [SOME (Thm.ctyp_of thy this_ty)] [SOME (Thm.cterm_of thy random')]
haftmann@26267
   139
                |> (fn thm => thm OF simps)
haftmann@26267
   140
                |> singleton (ProofContext.export lthy (ProofContext.init thy))
haftmann@26267
   141
            in
haftmann@26267
   142
              lthy
wenzelm@27865
   143
              |> LocalTheory.theory (PureThy.add_thm ((fst (dest_Free random') ^ "_code", thm), [Thm.kind_internal])
haftmann@26267
   144
                   #-> Code.add_func)
haftmann@26267
   145
            end;
haftmann@26265
   146
        in
haftmann@26267
   147
          thy
haftmann@26267
   148
          |> TheoryTarget.instantiation ([tyco], vs, @{sort random})
haftmann@26267
   149
          |> PrimrecPackage.add_primrec
wenzelm@28083
   150
               [(Name.binding (fst (dest_Free random')), SOME (snd (dest_Free random')), NoSyn)]
wenzelm@28083
   151
                 (map (fn eq => ((Name.no_binding, [del_func]), eq)) eqs')
haftmann@26267
   152
          |-> add_code
haftmann@26267
   153
          |> `(fn lthy => Syntax.check_term lthy eq)
wenzelm@28084
   154
          |-> (fn eq => Specification.definition (NONE, (Attrib.no_binding, eq)))
haftmann@26267
   155
          |> snd
haftmann@26267
   156
          |> Class.prove_instantiation_instance (K (Class.intro_classes_tac []))
haftmann@26267
   157
          |> LocalTheory.exit
haftmann@26267
   158
          |> ProofContext.theory_of
haftmann@26267
   159
        end
haftmann@26267
   160
    | random_inst tycos thy = raise REC
haftmann@26267
   161
        ("Will not generate random elements for mutual recursive type(s) " ^ commas (map quote tycos));
haftmann@26267
   162
  fun add_random_inst tycos thy = random_inst tycos thy
haftmann@26267
   163
     handle REC msg => (warning msg; thy);
haftmann@26265
   164
in DatatypePackage.interpretation add_random_inst end
haftmann@26265
   165
*}
haftmann@26265
   166
haftmann@26267
   167
text {* Type @{typ int} *}
haftmann@26267
   168
haftmann@26265
   169
instantiation int :: random
haftmann@26265
   170
begin
haftmann@26265
   171
haftmann@26265
   172
definition
haftmann@26265
   173
  "random n = (do
haftmann@26325
   174
     (b, _) \<leftarrow> random n;
haftmann@26325
   175
     (m, t) \<leftarrow> random n;
haftmann@28228
   176
     return (if b then (int m, \<lambda>u. Code_Eval.App (Code_Eval.Const (STR ''Int.int'') RTYPE(nat \<Rightarrow> int)) (t ()))
haftmann@28228
   177
       else (- int m, \<lambda>u. Code_Eval.App (Code_Eval.Const (STR ''HOL.uminus_class.uminus'') RTYPE(int \<Rightarrow> int))
haftmann@28228
   178
         (Code_Eval.App (Code_Eval.Const (STR ''Int.int'') RTYPE(nat \<Rightarrow> int)) (t ()))))
haftmann@26265
   179
   done)"
haftmann@26265
   180
haftmann@26265
   181
instance ..
haftmann@26265
   182
haftmann@26265
   183
end
haftmann@26265
   184
haftmann@26267
   185
text {* Type @{typ "'a \<Rightarrow> 'b"} *}
haftmann@26267
   186
haftmann@26267
   187
ML {*
haftmann@26267
   188
structure Random_Engine =
haftmann@26267
   189
struct
haftmann@26267
   190
haftmann@26267
   191
open Random_Engine;
haftmann@26267
   192
haftmann@26325
   193
fun random_fun (T1 : typ) (T2 : typ) (eq : 'a -> 'a -> bool) (term_of : 'a -> term)
haftmann@26325
   194
    (random : Random_Engine.seed -> ('b * (unit -> term)) * Random_Engine.seed)
haftmann@26267
   195
    (random_split : Random_Engine.seed -> Random_Engine.seed * Random_Engine.seed)
haftmann@26267
   196
    (seed : Random_Engine.seed) =
haftmann@26267
   197
  let
haftmann@26267
   198
    val (seed', seed'') = random_split seed;
haftmann@26325
   199
    val state = ref (seed', [], Const (@{const_name arbitrary}, T1 --> T2));
haftmann@26325
   200
    val fun_upd = Const (@{const_name fun_upd},
haftmann@26325
   201
      (T1 --> T2) --> T1 --> T2 --> T1 --> T2);
haftmann@26267
   202
    fun random_fun' x =
haftmann@26267
   203
      let
haftmann@26325
   204
        val (seed, fun_map, f_t) = ! state;
haftmann@26267
   205
      in case AList.lookup (uncurry eq) fun_map x
haftmann@26267
   206
       of SOME y => y
haftmann@26267
   207
        | NONE => let
haftmann@26325
   208
              val t1 = term_of x;
haftmann@26325
   209
              val ((y, t2), seed') = random seed;
haftmann@26325
   210
              val fun_map' = (x, y) :: fun_map;
haftmann@26325
   211
              val f_t' = fun_upd $ f_t $ t1 $ t2 ();
haftmann@26325
   212
              val _ = state := (seed', fun_map', f_t');
haftmann@26267
   213
            in y end
haftmann@26267
   214
      end;
haftmann@26325
   215
    fun term_fun' () = #3 (! state);
haftmann@26325
   216
  in ((random_fun', term_fun'), seed'') end;
haftmann@26267
   217
haftmann@26267
   218
end
haftmann@26267
   219
*}
haftmann@26267
   220
haftmann@26267
   221
axiomatization
haftmann@26325
   222
  random_fun_aux :: "rtype \<Rightarrow> rtype \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> term)
haftmann@26325
   223
    \<Rightarrow> (seed \<Rightarrow> ('b \<times> (unit \<Rightarrow> term)) \<times> seed) \<Rightarrow> (seed \<Rightarrow> seed \<times> seed)
haftmann@26325
   224
    \<Rightarrow> seed \<Rightarrow> (('a \<Rightarrow> 'b) \<times> (unit \<Rightarrow> term)) \<times> seed"
haftmann@26267
   225
haftmann@26267
   226
code_const random_fun_aux (SML "Random'_Engine.random'_fun")
haftmann@26267
   227
haftmann@26325
   228
instantiation "fun" :: ("{eq, term_of}", "{type, random}") random
haftmann@26267
   229
begin
haftmann@26267
   230
haftmann@26325
   231
definition random_fun :: "index \<Rightarrow> seed \<Rightarrow> (('a \<Rightarrow> 'b) \<times> (unit \<Rightarrow> term)) \<times> seed" where
haftmann@28228
   232
  "random n = random_fun_aux RTYPE('a) RTYPE('b) (op =) Code_Eval.term_of (random n) split_seed"
haftmann@26267
   233
haftmann@26267
   234
instance ..
haftmann@26267
   235
haftmann@26267
   236
end
haftmann@26267
   237
haftmann@26267
   238
code_reserved SML Random_Engine
haftmann@26265
   239
haftmann@26265
   240
haftmann@26265
   241
subsection {* Quickcheck generator *}
haftmann@26265
   242
haftmann@26265
   243
ML {*
haftmann@26265
   244
structure Quickcheck =
haftmann@26265
   245
struct
haftmann@26265
   246
haftmann@28309
   247
open Quickcheck;
haftmann@28309
   248
haftmann@26265
   249
val eval_ref : (unit -> int -> int * int -> term list option * (int * int)) option ref = ref NONE;
haftmann@26265
   250
haftmann@26325
   251
fun mk_generator_expr thy prop tys =
haftmann@26265
   252
  let
haftmann@26325
   253
    val bound_max = length tys - 1;
haftmann@26325
   254
    val bounds = map_index (fn (i, ty) =>
haftmann@26325
   255
      (2 * (bound_max - i) + 1, 2 * (bound_max - i), 2 * i, ty)) tys;
haftmann@26325
   256
    val result = list_comb (prop, map (fn (i, _, _, _) => Bound i) bounds);
haftmann@26325
   257
    val terms = HOLogic.mk_list @{typ term} (map (fn (_, i, _, _) => Bound i $ @{term "()"}) bounds);
haftmann@26265
   258
    val check = @{term "If \<Colon> bool \<Rightarrow> term list option \<Rightarrow> term list option \<Rightarrow> term list option"}
haftmann@26325
   259
      $ result $ @{term "None \<Colon> term list option"} $ (@{term "Some \<Colon> term list \<Rightarrow> term list option "} $ terms);
haftmann@26265
   260
    val return = @{term "Pair \<Colon> term list option \<Rightarrow> seed \<Rightarrow> term list option \<times> seed"};
haftmann@26325
   261
    fun mk_termtyp ty = HOLogic.mk_prodT (ty, @{typ "unit \<Rightarrow> term"});
haftmann@26325
   262
    fun mk_split ty = Sign.mk_const thy
haftmann@26325
   263
      (@{const_name split}, [ty, @{typ "unit \<Rightarrow> term"}, StateMonad.liftT @{typ "term list option"} @{typ seed}]);
haftmann@26589
   264
    fun mk_scomp_split ty t t' =
haftmann@26589
   265
      StateMonad.scomp (mk_termtyp ty) @{typ "term list option"} @{typ seed} t (*FIXME*)
haftmann@26325
   266
        (mk_split ty $ Abs ("", ty, Abs ("", @{typ "unit \<Rightarrow> term"}, t')));
haftmann@26589
   267
    fun mk_bindclause (_, _, i, ty) = mk_scomp_split ty
haftmann@26325
   268
      (Sign.mk_const thy (@{const_name random}, [ty]) $ Bound i)
haftmann@26265
   269
    val t = fold_rev mk_bindclause bounds (return $ check);
haftmann@26265
   270
  in Abs ("n", @{typ index}, t) end;
haftmann@26265
   271
haftmann@28309
   272
fun compile_generator_expr thy t =
haftmann@26265
   273
  let
haftmann@28309
   274
    val tys = (map snd o fst o strip_abs) t;
haftmann@28309
   275
    val t' = mk_generator_expr thy t tys;
haftmann@28309
   276
    val f = Code_ML.eval_term ("Quickcheck.eval_ref", eval_ref) thy t' [];
haftmann@28309
   277
  in f #> Random_Engine.run #> (Option.map o map) (Code.postprocess_term thy) end;
haftmann@26265
   278
haftmann@26265
   279
end
haftmann@26265
   280
*}
haftmann@26265
   281
haftmann@28309
   282
setup {*
haftmann@28309
   283
  Quickcheck.add_generator ("code", Quickcheck.compile_generator_expr o ProofContext.theory_of)
haftmann@28309
   284
*}
haftmann@28309
   285
haftmann@26267
   286
subsection {* Examples *}
haftmann@26267
   287
haftmann@28309
   288
(*lemma
haftmann@28309
   289
  fixes n m :: nat
haftmann@28309
   290
  shows "n + m \<le> n * m"
haftmann@28309
   291
;test_goal [code];
haftmann@28309
   292
oops*)
haftmann@26325
   293
haftmann@26265
   294
ML {* val f = Quickcheck.compile_generator_expr @{theory}
haftmann@28309
   295
  @{term "\<lambda>(n::nat) (m::nat) (q::nat). n = m + q + 1"} *}
haftmann@26265
   296
wenzelm@26944
   297
ML {* f 5 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   298
ML {* f 5 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   299
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   300
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   301
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   302
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   303
ML {* f 25 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   304
ML {* f 1 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   305
ML {* f 1 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   306
ML {* f 2 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   307
ML {* f 2 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
haftmann@26265
   308
haftmann@26265
   309
ML {* val f = Quickcheck.compile_generator_expr @{theory}
haftmann@28309
   310
  @{term "\<lambda>(n::int) (m::int) (q::int). n = m + q + 1"} *}
haftmann@26265
   311
wenzelm@26944
   312
ML {* f 5 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   313
ML {* f 5 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   314
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   315
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   316
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   317
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   318
ML {* f 25 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   319
ML {* f 1 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   320
ML {* f 1 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   321
ML {* f 2 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   322
ML {* f 2 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   323
ML {* f 3 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   324
ML {* f 4 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   325
ML {* f 4 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
haftmann@26265
   326
haftmann@26265
   327
ML {* val f = Quickcheck.compile_generator_expr @{theory}
haftmann@28309
   328
  @{term "\<lambda>(xs\<Colon>int list) ys. rev (xs @ ys) = rev xs @ rev ys"} *}
haftmann@26265
   329
wenzelm@26944
   330
ML {* f 15 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   331
ML {* f 5 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   332
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   333
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   334
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   335
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   336
ML {* f 25 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   337
ML {* f 1 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   338
ML {* f 1 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   339
ML {* f 2 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   340
ML {* f 2 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   341
ML {* f 4 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   342
ML {* f 4 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   343
ML {* f 5 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   344
ML {* f 8 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   345
ML {* f 8 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   346
ML {* f 8 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   347
ML {* f 88 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
haftmann@26265
   348
wenzelm@26944
   349
ML {* f 1 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   350
ML {* f 2 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   351
ML {* f 3 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   352
ML {* f 4 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   353
ML {* f 5 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   354
ML {* f 6 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   355
ML {* f 10 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   356
ML {* f 10 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
haftmann@26265
   357
haftmann@26265
   358
ML {* val f = Quickcheck.compile_generator_expr @{theory}
haftmann@28309
   359
  @{term "\<lambda>(s \<Colon> string). s \<noteq> rev s"} *}
haftmann@26265
   360
wenzelm@26944
   361
ML {* f 4 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   362
ML {* f 4 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   363
ML {* f 4 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   364
ML {* f 4 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   365
ML {* f 10 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   366
ML {* f 10 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   367
ML {* f 10 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   368
ML {* f 10 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   369
ML {* f 10 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   370
ML {* f 8 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   371
ML {* f 8 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
haftmann@26265
   372
haftmann@26325
   373
ML {* val f = Quickcheck.compile_generator_expr @{theory}
haftmann@28309
   374
  @{term "\<lambda>f k. int (f k) = k"} *}
haftmann@26325
   375
wenzelm@26944
   376
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   377
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   378
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   379
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   380
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
wenzelm@26944
   381
ML {* f 20 |> (Option.map o map) (Syntax.string_of_term @{context}) *}
haftmann@26325
   382
haftmann@26265
   383
end