src/HOL/Tools/smallvalue_generators.ML
author bulwahn
Fri, 11 Mar 2011 08:13:00 +0100
changeset 41903 39fd77f0ae59
parent 41902 1941b3315952
child 41904 2ae19825f7b6
permissions -rw-r--r--
fixing postprocessing; adding a configuration to enable and disable pretty presentation of quickcheck's counterexample
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
     1
(*  Title:      HOL/Tools/smallvalue_generators.ML
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
     2
    Author:     Lukas Bulwahn, TU Muenchen
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
     3
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
     4
Generators for small values for various types.
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
     5
*)
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
     6
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
     7
signature SMALLVALUE_GENERATORS =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
     8
sig
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
     9
  val compile_generator_expr:
40911
7febf76e0a69 moving iteration of tests to the testers in quickcheck
bulwahn
parents: 40907
diff changeset
    10
    Proof.context -> term -> int -> term list option * Quickcheck.report option
41861
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
    11
  val compile_generator_exprs:
41862
a38536bf2736 adding function Quickcheck.test_terms to provide checking a batch of terms
bulwahn
parents: 41861
diff changeset
    12
    Proof.context -> term list -> (int -> term list option) list
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    13
  val put_counterexample: (unit -> int -> term list option)
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    14
    -> Proof.context -> Proof.context
41861
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
    15
  val put_counterexample_batch: (unit -> (int -> term list option) list)
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
    16
    -> Proof.context -> Proof.context
40907
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
    17
  val smart_quantifier : bool Config.T;
41903
39fd77f0ae59 fixing postprocessing; adding a configuration to enable and disable pretty presentation of quickcheck's counterexample
bulwahn
parents: 41902
diff changeset
    18
  val quickcheck_pretty : bool Config.T;
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    19
  val setup: theory -> theory
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    20
end;
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    21
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    22
structure Smallvalue_Generators : SMALLVALUE_GENERATORS =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    23
struct
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    24
40901
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
    25
(* static options *)
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
    26
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
    27
val define_foundationally = false
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
    28
40907
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
    29
(* dynamic options *)
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
    30
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
    31
val (smart_quantifier, setup_smart_quantifier) =
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
    32
  Attrib.config_bool "quickcheck_smart_quantifier" (K true)
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
    33
41903
39fd77f0ae59 fixing postprocessing; adding a configuration to enable and disable pretty presentation of quickcheck's counterexample
bulwahn
parents: 41902
diff changeset
    34
val (quickcheck_pretty, setup_quickcheck_pretty) =
39fd77f0ae59 fixing postprocessing; adding a configuration to enable and disable pretty presentation of quickcheck's counterexample
bulwahn
parents: 41902
diff changeset
    35
  Attrib.config_bool "quickcheck_pretty" (K true)
39fd77f0ae59 fixing postprocessing; adding a configuration to enable and disable pretty presentation of quickcheck's counterexample
bulwahn
parents: 41902
diff changeset
    36
 
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    37
(** general term functions **)
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    38
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    39
fun mk_measure f =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    40
  let
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    41
    val Type ("fun", [T, @{typ nat}]) = fastype_of f 
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    42
  in
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    43
    Const (@{const_name Wellfounded.measure},
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    44
      (T --> @{typ nat}) --> HOLogic.mk_prodT (T, T) --> @{typ bool})
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    45
    $ f
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    46
  end
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    47
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    48
fun mk_sumcases rT f (Type (@{type_name Sum_Type.sum}, [TL, TR])) =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    49
  let
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    50
    val lt = mk_sumcases rT f TL
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    51
    val rt = mk_sumcases rT f TR
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    52
  in
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    53
    SumTree.mk_sumcase TL TR rT lt rt
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    54
  end
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    55
  | mk_sumcases _ f T = f T
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    56
40901
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
    57
fun mk_undefined T = Const(@{const_name undefined}, T)
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
    58
  
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    59
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    60
(** abstract syntax **)
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    61
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
    62
fun termifyT T = HOLogic.mk_prodT (T, @{typ "unit => Code_Evaluation.term"});
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
    63
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    64
val size = @{term "i :: code_numeral"}
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    65
val size_pred = @{term "(i :: code_numeral) - 1"}
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    66
val size_ge_zero = @{term "(i :: code_numeral) > 0"}
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
    67
fun test_function T = Free ("f", termifyT T --> @{typ "term list option"})
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    68
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    69
fun mk_none_continuation (x, y) =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    70
  let
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    71
    val (T as Type(@{type_name "option"}, [T'])) = fastype_of x
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    72
  in
40899
ef6fde932f4c improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents: 40845
diff changeset
    73
    Const (@{const_name "Smallcheck.orelse"}, T --> T --> T)
ef6fde932f4c improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents: 40845
diff changeset
    74
      $ x $ y
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    75
  end
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    76
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    77
(** datatypes **)
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    78
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    79
(* constructing smallvalue generator instances on datatypes *)
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    80
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    81
exception FUNCTION_TYPE;
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    82
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    83
val smallN = "small";
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    84
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    85
fun smallT T = (T --> @{typ "Code_Evaluation.term list option"}) --> @{typ code_numeral}
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    86
  --> @{typ "Code_Evaluation.term list option"}
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    87
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
    88
val full_smallN = "full_small";
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
    89
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
    90
fun full_smallT T = (termifyT T --> @{typ "Code_Evaluation.term list option"})
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
    91
  --> @{typ code_numeral} --> @{typ "Code_Evaluation.term list option"}
41085
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
    92
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
    93
fun check_allT T = (termifyT T --> @{typ "Code_Evaluation.term list option"})
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
    94
  --> @{typ "Code_Evaluation.term list option"}
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
    95
40901
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
    96
fun mk_equations thy descr vs tycos smalls (Ts, Us) =
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    97
  let
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    98
    fun mk_small_call T =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
    99
      let
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   100
        val small = Const (@{const_name "Smallcheck.full_small_class.full_small"}, full_smallT T)        
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   101
      in
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   102
        (T, (fn t => small $
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   103
          (HOLogic.split_const (T, @{typ "unit => Code_Evaluation.term"}, @{typ "Code_Evaluation.term list option"})
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   104
          $ absdummy (T, absdummy (@{typ "unit => Code_Evaluation.term"}, t))) $ size_pred))
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   105
      end
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   106
    fun mk_small_aux_call fTs (k, _) (tyco, Ts) =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   107
      let
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   108
        val T = Type (tyco, Ts)
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   109
        val _ = if not (null fTs) then raise FUNCTION_TYPE else ()
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   110
        val small = nth smalls k
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   111
      in
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   112
       (T, (fn t => small $
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   113
          (HOLogic.split_const (T, @{typ "unit => Code_Evaluation.term"}, @{typ "Code_Evaluation.term list option"})
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   114
            $ absdummy (T, absdummy (@{typ "unit => Code_Evaluation.term"}, t))) $ size_pred))  
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   115
      end
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   116
    fun mk_consexpr simpleT (c, xs) =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   117
      let
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   118
        val (Ts, fns) = split_list xs
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   119
        val constr = Const (c, Ts ---> simpleT)
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   120
        val bounds = map (fn x => Bound (2 * x + 1)) (((length xs) - 1) downto 0)
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   121
        val term_bounds = map (fn x => Bound (2 * x)) (((length xs) - 1) downto 0)
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   122
        val Eval_App = Const ("Code_Evaluation.App", HOLogic.termT --> HOLogic.termT --> HOLogic.termT)
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   123
        val Eval_Const = Const ("Code_Evaluation.Const", HOLogic.literalT --> @{typ typerep} --> HOLogic.termT)
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   124
        val term = fold (fn u => fn t => Eval_App $ t $ (u $ @{term "()"}))
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   125
          bounds (Eval_Const $ HOLogic.mk_literal c $ HOLogic.mk_typerep (Ts ---> simpleT))
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   126
        val start_term = test_function simpleT $ 
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   127
        (HOLogic.pair_const simpleT @{typ "unit => Code_Evaluation.term"}
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   128
          $ (list_comb (constr, bounds)) $ absdummy (@{typ unit}, term))
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   129
      in fold_rev (fn f => fn t => f t) fns start_term end
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   130
    fun mk_rhs exprs =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   131
        @{term "If :: bool => term list option => term list option => term list option"}
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   132
            $ size_ge_zero $ (foldr1 mk_none_continuation exprs) $ @{term "None :: term list option"}
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   133
    val rhss =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   134
      Datatype_Aux.interpret_construction descr vs
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   135
        { atyp = mk_small_call, dtyp = mk_small_aux_call }
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   136
      |> (map o apfst) Type
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   137
      |> map (fn (T, cs) => map (mk_consexpr T) cs)
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   138
      |> map mk_rhs
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   139
    val lhss = map2 (fn t => fn T => t $ test_function T $ size) smalls (Ts @ Us);
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   140
    val eqs = map (HOLogic.mk_Trueprop o HOLogic.mk_eq) (lhss ~~ rhss)
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   141
  in
40901
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   142
    eqs
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   143
  end
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   144
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   145
(* foundational definition with the function package *)
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   146
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   147
val less_int_pred = @{lemma "i > 0 ==> Code_Numeral.nat_of ((i :: code_numeral) - 1) < Code_Numeral.nat_of i" by auto}
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   148
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   149
fun mk_single_measure T = HOLogic.mk_comp (@{term "Code_Numeral.nat_of"},
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   150
    Const (@{const_name "Product_Type.snd"}, T --> @{typ "code_numeral"}))
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   151
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   152
fun mk_termination_measure T =
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   153
  let
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   154
    val T' = fst (HOLogic.dest_prodT (HOLogic.dest_setT T))
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   155
  in
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   156
    mk_measure (mk_sumcases @{typ nat} mk_single_measure T')
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   157
  end
40901
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   158
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   159
fun termination_tac ctxt = 
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   160
  Function_Relation.relation_tac ctxt mk_termination_measure 1
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   161
  THEN rtac @{thm wf_measure} 1
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   162
  THEN (REPEAT_DETERM (Simplifier.asm_full_simp_tac 
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   163
    (HOL_basic_ss addsimps [@{thm in_measure}, @{thm o_def}, @{thm snd_conv},
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   164
     @{thm nat_mono_iff}, less_int_pred] @ @{thms sum.cases}) 1))
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   165
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   166
fun pat_completeness_auto ctxt =
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   167
  Pat_Completeness.pat_completeness_tac ctxt 1
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   168
  THEN auto_tac (clasimpset_of ctxt)    
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   169
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   170
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   171
(* creating the instances *)
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   172
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   173
fun instantiate_smallvalue_datatype config descr vs tycos prfx (names, auxnames) (Ts, Us) thy =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   174
  let
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   175
    val _ = Datatype_Aux.message config "Creating smallvalue generators ...";
40901
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   176
    val smallsN = map (prefix (full_smallN ^ "_")) (names @ auxnames);
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   177
  in
40641
5615cc557120 moving the error handling to the right scope in smallvalue_generators
bulwahn
parents: 40640
diff changeset
   178
    thy
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   179
    |> Class.instantiation (tycos, vs, @{sort full_small})
40901
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   180
    |> (if define_foundationally then
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   181
      let
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   182
        val smalls = map2 (fn name => fn T => Free (name, full_smallT T)) smallsN (Ts @ Us)
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   183
        val eqs = mk_equations thy descr vs tycos smalls (Ts, Us)
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   184
      in
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   185
        Function.add_function
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   186
          (map (fn (name, T) =>
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   187
              Syntax.no_syn (Binding.conceal (Binding.name name), SOME (full_smallT T)))
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   188
                (smallsN ~~ (Ts @ Us)))
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   189
            (map (pair (apfst Binding.conceal Attrib.empty_binding)) eqs)
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   190
          Function_Common.default_config pat_completeness_auto
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   191
        #> snd
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   192
        #> Local_Theory.restore
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   193
        #> (fn lthy => Function.prove_termination NONE (termination_tac lthy) lthy)
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   194
        #> snd
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   195
      end
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   196
    else
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   197
      fold_map (fn (name, T) => Local_Theory.define
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   198
          ((Binding.conceal (Binding.name name), NoSyn),
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   199
            (apfst Binding.conceal Attrib.empty_binding, mk_undefined (full_smallT T)))
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   200
        #> apfst fst) (smallsN ~~ (Ts @ Us))
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   201
      #> (fn (smalls, lthy) =>
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   202
        let
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   203
          val eqs_t = mk_equations thy descr vs tycos smalls (Ts, Us)
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   204
          val eqs = map (fn eq => Goal.prove lthy ["f", "i"] [] eq
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   205
            (fn _ => Skip_Proof.cheat_tac (ProofContext.theory_of lthy))) eqs_t
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   206
        in
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   207
          fold (fn (name, eq) => Local_Theory.note
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   208
          ((Binding.conceal (Binding.qualify true prfx
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   209
             (Binding.qualify true name (Binding.name "simps"))),
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   210
             Code.add_default_eqn_attrib :: map (Attrib.internal o K)
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   211
               [Simplifier.simp_add, Nitpick_Simps.add]), [eq]) #> snd) (smallsN ~~ eqs) lthy
8fdfa9c4e7ed smallvalue_generator are defined quick via oracle or sound via function package
bulwahn
parents: 40899
diff changeset
   212
        end))
40641
5615cc557120 moving the error handling to the right scope in smallvalue_generators
bulwahn
parents: 40640
diff changeset
   213
    |> Class.prove_instantiation_exit (K (Class.intro_classes_tac []))
5615cc557120 moving the error handling to the right scope in smallvalue_generators
bulwahn
parents: 40640
diff changeset
   214
  end handle FUNCTION_TYPE =>
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   215
    (Datatype_Aux.message config
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   216
      "Creation of smallvalue generators failed because the datatype contains a function type";
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   217
    thy)
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   218
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   219
(** building and compiling generator expressions **)
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   220
41472
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 41178
diff changeset
   221
structure Counterexample = Proof_Data
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 41178
diff changeset
   222
(
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   223
  type T = unit -> int -> term list option
41472
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 41178
diff changeset
   224
  (* FIXME avoid user error with non-user text *)
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   225
  fun init _ () = error "Counterexample"
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   226
);
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   227
val put_counterexample = Counterexample.put;
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   228
41861
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   229
structure Counterexample_Batch = Proof_Data
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   230
(
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   231
  type T = unit -> (int -> term list option) list
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   232
  (* FIXME avoid user error with non-user text *)
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   233
  fun init _ () = error "Counterexample"
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   234
);
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   235
val put_counterexample_batch = Counterexample_Batch.put;
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   236
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   237
val target = "Quickcheck";
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   238
40907
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   239
fun mk_smart_generator_expr ctxt t =
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   240
  let
41085
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
   241
    val thy = ProofContext.theory_of ctxt
40907
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   242
    val ((vnames, Ts), t') = apfst split_list (strip_abs t)
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   243
    val ([depth_name], ctxt') = Variable.variant_fixes ["depth"] ctxt
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   244
    val (names, ctxt'') = Variable.variant_fixes vnames ctxt'
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   245
    val (term_names, ctxt''') = Variable.variant_fixes (map (prefix "t_") vnames) ctxt''
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   246
    val depth = Free (depth_name, @{typ code_numeral})
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   247
    val frees = map2 (curry Free) names Ts
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   248
    val term_vars = map (fn n => Free (n, @{typ "unit => term"})) term_names 
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   249
    fun strip_imp (Const(@{const_name HOL.implies},_) $ A $ B) = apfst (cons A) (strip_imp B)
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   250
      | strip_imp A = ([], A)
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   251
    val (assms, concl) = strip_imp (subst_bounds (rev frees, t'))
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   252
    val terms = HOLogic.mk_list @{typ term} (map (fn v => v $ @{term "()"}) term_vars)
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   253
    fun mk_small_closure (free as Free (_, T), term_var) t =
41085
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
   254
      if Sign.of_sort thy (T, @{sort enum}) then
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
   255
        Const (@{const_name "Smallcheck.check_all_class.check_all"}, check_allT T)
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
   256
          $ (HOLogic.split_const (T, @{typ "unit => term"}, @{typ "term list option"}) 
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
   257
            $ lambda free (lambda term_var t))
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
   258
      else
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
   259
        Const (@{const_name "Smallcheck.full_small_class.full_small"}, full_smallT T)
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
   260
          $ (HOLogic.split_const (T, @{typ "unit => term"}, @{typ "term list option"}) 
a549ff1d4070 adding a smarter enumeration scheme for finite functions
bulwahn
parents: 40913
diff changeset
   261
            $ lambda free (lambda term_var t)) $ depth
40907
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   262
    fun lookup v = the (AList.lookup (op =) (names ~~ (frees ~~ term_vars)) v)
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   263
    val none_t = @{term "None :: term list option"}
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   264
    fun mk_safe_if (cond, then_t, else_t) =
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   265
      @{term "Smallcheck.catch_match :: term list option => term list option => term list option"} $
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   266
        (@{term "If :: bool => term list option => term list option => term list option"}
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   267
        $ cond $ then_t $ else_t) $ none_t;
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   268
    fun mk_test_term bound_vars assms =
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   269
      let
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   270
        fun vars_of t = subtract (op =) bound_vars (Term.add_free_names t [])
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   271
        val (vars, check) =
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   272
          case assms of [] =>
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   273
            (vars_of concl, (concl, none_t, @{term "Some :: term list => term list option"} $ terms))
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   274
          | assm :: assms =>
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   275
            (vars_of assm, (assm, mk_test_term (union (op =) (vars_of assm) bound_vars) assms, none_t))
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   276
      in
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   277
        fold_rev mk_small_closure (map lookup vars) (mk_safe_if check)
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   278
      end
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   279
  in lambda depth (mk_test_term [] assms) end
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   280
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   281
fun mk_generator_expr ctxt t =
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   282
  let
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   283
    val Ts = (map snd o fst o strip_abs) t;
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   284
    val thy = ProofContext.theory_of ctxt
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   285
    val bound_max = length Ts - 1;
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   286
    val bounds = map_index (fn (i, ty) =>
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   287
      (2 * (bound_max - i) + 1, 2 * (bound_max - i), 2 * i, ty)) Ts;
40907
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   288
    val result = list_comb (t, map (fn (i, _, _, _) => Bound i) bounds);
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   289
    val terms = HOLogic.mk_list @{typ term} (map (fn (_, i, _, _) => Bound i $ @{term "()"}) bounds);
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   290
    val check =
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   291
      @{term "Smallcheck.catch_match :: term list option => term list option => term list option"} $
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   292
        (@{term "If :: bool => term list option => term list option => term list option"}
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   293
        $ result $ @{term "None :: term list option"} $ (@{term "Some :: term list => term list option"} $ terms))
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   294
      $ @{term "None :: term list option"};
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   295
    fun mk_small_closure (_, _, i, T) t =
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   296
      Const (@{const_name "Smallcheck.full_small_class.full_small"}, full_smallT T)
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   297
        $ (HOLogic.split_const (T, @{typ "unit => term"}, @{typ "term list option"}) 
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   298
        $ absdummy (T, absdummy (@{typ "unit => term"}, t))) $ Bound i
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   299
  in Abs ("d", @{typ code_numeral}, fold_rev mk_small_closure bounds check) end
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   300
41178
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   301
(** post-processing of function terms **)
41176
ede546773fd6 adding postprocessing for sets in term construction of quickcheck
bulwahn
parents: 41085
diff changeset
   302
ede546773fd6 adding postprocessing for sets in term construction of quickcheck
bulwahn
parents: 41085
diff changeset
   303
fun dest_fun_upd (Const (@{const_name fun_upd}, _) $ t0 $ t1 $ t2) = (t0, (t1, t2))
ede546773fd6 adding postprocessing for sets in term construction of quickcheck
bulwahn
parents: 41085
diff changeset
   304
  | dest_fun_upd t = raise TERM ("dest_fun_upd", [t])
ede546773fd6 adding postprocessing for sets in term construction of quickcheck
bulwahn
parents: 41085
diff changeset
   305
41177
810a885decee added enum_term_of to correct present nested functions
bulwahn
parents: 41176
diff changeset
   306
fun mk_fun_upd T1 T2 (t1, t2) t = 
810a885decee added enum_term_of to correct present nested functions
bulwahn
parents: 41176
diff changeset
   307
  Const (@{const_name fun_upd}, (T1 --> T2) --> T1 --> T2 --> T1 --> T2) $ t $ t1 $ t2
810a885decee added enum_term_of to correct present nested functions
bulwahn
parents: 41176
diff changeset
   308
41902
1941b3315952 renaming dest_plain_fun to dest_fun_upds and adding handling of undefined for postprocessing of quickcheck
bulwahn
parents: 41901
diff changeset
   309
fun dest_fun_upds t =
41177
810a885decee added enum_term_of to correct present nested functions
bulwahn
parents: 41176
diff changeset
   310
  case try dest_fun_upd t of
41176
ede546773fd6 adding postprocessing for sets in term construction of quickcheck
bulwahn
parents: 41085
diff changeset
   311
    NONE =>
41177
810a885decee added enum_term_of to correct present nested functions
bulwahn
parents: 41176
diff changeset
   312
      (case t of
41901
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   313
        Abs (_, _, _) => ([], t) 
41902
1941b3315952 renaming dest_plain_fun to dest_fun_upds and adding handling of undefined for postprocessing of quickcheck
bulwahn
parents: 41901
diff changeset
   314
      | _ => raise TERM ("dest_fun_upds", [t]))
1941b3315952 renaming dest_plain_fun to dest_fun_upds and adding handling of undefined for postprocessing of quickcheck
bulwahn
parents: 41901
diff changeset
   315
  | SOME (t0, (t1, t2)) => apfst (cons (t1, t2)) (dest_fun_upds t0)
41176
ede546773fd6 adding postprocessing for sets in term construction of quickcheck
bulwahn
parents: 41085
diff changeset
   316
41902
1941b3315952 renaming dest_plain_fun to dest_fun_upds and adding handling of undefined for postprocessing of quickcheck
bulwahn
parents: 41901
diff changeset
   317
fun make_fun_upds T1 T2 (tps, t) = fold_rev (mk_fun_upd T1 T2) tps t
41178
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   318
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   319
fun make_set T1 [] = Const (@{const_abbrev Set.empty}, T1 --> @{typ bool})
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   320
  | make_set T1 ((_, @{const False}) :: tps) = make_set T1 tps
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   321
  | make_set T1 ((t1, @{const True}) :: tps) =
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   322
    Const (@{const_name insert}, T1 --> (T1 --> @{typ bool}) --> T1 --> @{typ bool})
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   323
      $ t1 $ (make_set T1 tps)
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   324
  | make_set T1 ((_, t) :: tps) = raise TERM ("make_set", [t])
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   325
41901
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   326
fun make_coset T [] = Const (@{const_abbrev UNIV}, T --> @{typ bool})
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   327
  | make_coset T tps = 
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   328
    let
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   329
      val U = T --> @{typ bool}
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   330
      fun invert @{const False} = @{const True}
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   331
        | invert @{const True} = @{const False}
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   332
    in
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   333
      Const (@{const_name "Groups.minus_class.minus"}, U --> U --> U)
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   334
        $ Const (@{const_abbrev UNIV}, U) $ make_set T (map (apsnd invert) tps)
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   335
    end
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   336
41178
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   337
fun make_map T1 T2 [] = Const (@{const_abbrev Map.empty}, T1 --> T2)
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   338
  | make_map T1 T2 ((_, Const (@{const_name None}, _)) :: tps) = make_map T1 T2 tps
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   339
  | make_map T1 T2 ((t1, t2) :: tps) = mk_fun_upd T1 T2 (t1, t2) (make_map T1 T2 tps)
41177
810a885decee added enum_term_of to correct present nested functions
bulwahn
parents: 41176
diff changeset
   340
  
41176
ede546773fd6 adding postprocessing for sets in term construction of quickcheck
bulwahn
parents: 41085
diff changeset
   341
fun post_process_term t =
41901
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   342
  let
41903
39fd77f0ae59 fixing postprocessing; adding a configuration to enable and disable pretty presentation of quickcheck's counterexample
bulwahn
parents: 41902
diff changeset
   343
    val _ = tracing (Syntax.string_of_term @{context} t)
41901
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   344
    fun map_Abs f t =
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   345
      case t of Abs (x, T, t') => Abs (x, T, f t') | _ => raise TERM ("map_Abs", [t]) 
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   346
    fun process_args t = case strip_comb t of
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   347
      (c as Const (_, _), ts) => list_comb (c, map post_process_term ts) 
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   348
  in
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   349
    case fastype_of t of
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   350
      Type (@{type_name fun}, [T1, T2]) =>
41902
1941b3315952 renaming dest_plain_fun to dest_fun_upds and adding handling of undefined for postprocessing of quickcheck
bulwahn
parents: 41901
diff changeset
   351
        (case try dest_fun_upds t of
41901
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   352
          SOME (tps, t) =>
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   353
            (map (pairself post_process_term) tps, map_Abs post_process_term t)
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   354
            |> (case T2 of
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   355
              @{typ bool} => 
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   356
                (case t of
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   357
                   Abs(_, _, @{const True}) => fst #> rev #> make_set T1
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   358
                 | Abs(_, _, @{const False}) => fst #> rev #> make_coset T1
41902
1941b3315952 renaming dest_plain_fun to dest_fun_upds and adding handling of undefined for postprocessing of quickcheck
bulwahn
parents: 41901
diff changeset
   359
                 | Abs(_, _, Const (@{const_name undefined}, _)) => fst #> rev #> make_set T1
41901
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   360
                 | _ => raise TERM ("post_process_term", [t]))
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   361
            | Type (@{type_name option}, _) =>
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   362
                (case t of
41902
1941b3315952 renaming dest_plain_fun to dest_fun_upds and adding handling of undefined for postprocessing of quickcheck
bulwahn
parents: 41901
diff changeset
   363
                  Abs(_, _, Const(@{const_name None}, _)) => fst #> make_map T1 T2
1941b3315952 renaming dest_plain_fun to dest_fun_upds and adding handling of undefined for postprocessing of quickcheck
bulwahn
parents: 41901
diff changeset
   364
                | Abs(_, _, Const (@{const_name undefined}, _)) => fst #> make_map T1 T2
1941b3315952 renaming dest_plain_fun to dest_fun_upds and adding handling of undefined for postprocessing of quickcheck
bulwahn
parents: 41901
diff changeset
   365
                | _ => make_fun_upds T1 T2) 
1941b3315952 renaming dest_plain_fun to dest_fun_upds and adding handling of undefined for postprocessing of quickcheck
bulwahn
parents: 41901
diff changeset
   366
            | _ => make_fun_upds T1 T2)
41903
39fd77f0ae59 fixing postprocessing; adding a configuration to enable and disable pretty presentation of quickcheck's counterexample
bulwahn
parents: 41902
diff changeset
   367
        | NONE => process_args t)
41901
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   368
    | _ => process_args t
45a79edbe73b improving term postprocessing for counterexample presentation in quickcheck
bulwahn
parents: 41900
diff changeset
   369
  end
41176
ede546773fd6 adding postprocessing for sets in term construction of quickcheck
bulwahn
parents: 41085
diff changeset
   370
41178
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   371
(** generator compiliation **)
f4d3acf0c4cc adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents: 41177
diff changeset
   372
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   373
fun compile_generator_expr ctxt t =
40911
7febf76e0a69 moving iteration of tests to the testers in quickcheck
bulwahn
parents: 40907
diff changeset
   374
  let
7febf76e0a69 moving iteration of tests to the testers in quickcheck
bulwahn
parents: 40907
diff changeset
   375
    val thy = ProofContext.theory_of ctxt
7febf76e0a69 moving iteration of tests to the testers in quickcheck
bulwahn
parents: 40907
diff changeset
   376
    val t' =
7febf76e0a69 moving iteration of tests to the testers in quickcheck
bulwahn
parents: 40907
diff changeset
   377
      (if Config.get ctxt smart_quantifier then mk_smart_generator_expr else mk_generator_expr)
7febf76e0a69 moving iteration of tests to the testers in quickcheck
bulwahn
parents: 40907
diff changeset
   378
        ctxt t;
7febf76e0a69 moving iteration of tests to the testers in quickcheck
bulwahn
parents: 40907
diff changeset
   379
    val compile = Code_Runtime.dynamic_value_strict
7febf76e0a69 moving iteration of tests to the testers in quickcheck
bulwahn
parents: 40907
diff changeset
   380
      (Counterexample.get, put_counterexample, "Smallvalue_Generators.put_counterexample")
7febf76e0a69 moving iteration of tests to the testers in quickcheck
bulwahn
parents: 40907
diff changeset
   381
      thy (SOME target) (fn proc => fn g => g #> (Option.map o map) proc) t' [];
41176
ede546773fd6 adding postprocessing for sets in term construction of quickcheck
bulwahn
parents: 41085
diff changeset
   382
  in
41903
39fd77f0ae59 fixing postprocessing; adding a configuration to enable and disable pretty presentation of quickcheck's counterexample
bulwahn
parents: 41902
diff changeset
   383
    fn size => rpair NONE (compile size |> 
39fd77f0ae59 fixing postprocessing; adding a configuration to enable and disable pretty presentation of quickcheck's counterexample
bulwahn
parents: 41902
diff changeset
   384
      (if Config.get ctxt quickcheck_pretty then Option.map (map post_process_term) else I))
41176
ede546773fd6 adding postprocessing for sets in term construction of quickcheck
bulwahn
parents: 41085
diff changeset
   385
  end;
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   386
41861
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   387
fun compile_generator_exprs ctxt ts =
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   388
  let
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   389
    val thy = ProofContext.theory_of ctxt
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   390
    val mk_generator_expr =
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   391
      if Config.get ctxt smart_quantifier then mk_smart_generator_expr else mk_generator_expr
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   392
    val ts' = map (mk_generator_expr ctxt) ts;
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   393
    val compiles = Code_Runtime.dynamic_value_strict
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   394
      (Counterexample_Batch.get, put_counterexample_batch,
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   395
        "Smallvalue_Generators.put_counterexample_batch")
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   396
      thy (SOME target) (fn proc => map (fn g => g #> (Option.map o map) proc))
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   397
      (HOLogic.mk_list @{typ "code_numeral => term list option"} ts') [];
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   398
  in
41862
a38536bf2736 adding function Quickcheck.test_terms to provide checking a batch of terms
bulwahn
parents: 41861
diff changeset
   399
    map (fn compile => fn size => compile size |> Option.map (map post_process_term)) compiles
41861
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   400
  end;
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   401
  
77d87dc50e5a adding a function to compile a batch of terms for quickcheck with one code generation invocation
bulwahn
parents: 41472
diff changeset
   402
  
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   403
(** setup **)
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   404
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   405
val setup =
40639
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   406
  Datatype.interpretation
f1f0e6adca0a adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents: 40420
diff changeset
   407
    (Quickcheck_Generators.ensure_sort_datatype (@{sort full_small}, instantiate_smallvalue_datatype))
40907
45ba9f05583a adding smart quantifiers to exhaustive testing
bulwahn
parents: 40901
diff changeset
   408
  #> setup_smart_quantifier
41903
39fd77f0ae59 fixing postprocessing; adding a configuration to enable and disable pretty presentation of quickcheck's counterexample
bulwahn
parents: 41902
diff changeset
   409
  #> setup_quickcheck_pretty
41900
bulwahn
parents: 41862
diff changeset
   410
  #> Context.theory_map (Quickcheck.add_generator ("exhaustive", compile_generator_expr))
bulwahn
parents: 41862
diff changeset
   411
  #> Context.theory_map (Quickcheck.add_batch_generator ("exhaustive", compile_generator_exprs));
40420
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   412
552563ea3304 adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff changeset
   413
end;