replacing naming of small by exhaustive
authorbulwahn
Fri Mar 11 15:21:13 2011 +0100 (2011-03-11)
changeset 41918d2ab869f8b0b
parent 41917 caa650526f98
child 41919 e180c2a9873b
replacing naming of small by exhaustive
src/HOL/Quickcheck_Exhaustive.thy
src/HOL/Tools/exhaustive_generators.ML
     1.1 --- a/src/HOL/Quickcheck_Exhaustive.thy	Fri Mar 11 15:21:13 2011 +0100
     1.2 +++ b/src/HOL/Quickcheck_Exhaustive.thy	Fri Mar 11 15:21:13 2011 +0100
     1.3 @@ -2,7 +2,7 @@
     1.4  
     1.5  header {* A simple counterexample generator performing exhaustive testing *}
     1.6  
     1.7 -theory Quickcheck_Exhautive
     1.8 +theory Quickcheck_Exhaustive
     1.9  imports Quickcheck
    1.10  uses ("Tools/exhaustive_generators.ML")
    1.11  begin
    1.12 @@ -368,9 +368,9 @@
    1.13  code_const catch_match 
    1.14    (SML "(_) handle Match => _")
    1.15  
    1.16 -use "Tools/smallvalue_generators.ML"
    1.17 +use "Tools/exhaustive_generators.ML"
    1.18  
    1.19 -setup {* Smallvalue_Generators.setup *}
    1.20 +setup {* Exhaustive_Generators.setup *}
    1.21  
    1.22  declare [[quickcheck_tester = exhaustive]]
    1.23  
     2.1 --- a/src/HOL/Tools/exhaustive_generators.ML	Fri Mar 11 15:21:13 2011 +0100
     2.2 +++ b/src/HOL/Tools/exhaustive_generators.ML	Fri Mar 11 15:21:13 2011 +0100
     2.3 @@ -1,10 +1,10 @@
     2.4 -(*  Title:      HOL/Tools/smallvalue_generators.ML
     2.5 +(*  Title:      HOL/Tools/exhaustive_generators.ML
     2.6      Author:     Lukas Bulwahn, TU Muenchen
     2.7  
     2.8 -Generators for small values for various types.
     2.9 +Exhaustive generators for various types.
    2.10  *)
    2.11  
    2.12 -signature SMALLVALUE_GENERATORS =
    2.13 +signature EXHAUSTIVE_GENERATORS =
    2.14  sig
    2.15    val compile_generator_expr:
    2.16      Proof.context -> term -> int -> term list option * Quickcheck.report option
    2.17 @@ -19,7 +19,7 @@
    2.18    val setup: theory -> theory
    2.19  end;
    2.20  
    2.21 -structure Smallvalue_Generators : SMALLVALUE_GENERATORS =
    2.22 +structure Exhaustive_Generators : EXHAUSTIVE_GENERATORS =
    2.23  struct
    2.24  
    2.25  (* static options *)
    2.26 @@ -70,48 +70,41 @@
    2.27    let
    2.28      val (T as Type(@{type_name "option"}, [T'])) = fastype_of x
    2.29    in
    2.30 -    Const (@{const_name "Smallcheck.orelse"}, T --> T --> T)
    2.31 +    Const (@{const_name "Quickcheck_Exhaustive.orelse"}, T --> T --> T)
    2.32        $ x $ y
    2.33    end
    2.34  
    2.35  (** datatypes **)
    2.36  
    2.37 -(* constructing smallvalue generator instances on datatypes *)
    2.38 +(* constructing exhaustive generator instances on datatypes *)
    2.39  
    2.40  exception FUNCTION_TYPE;
    2.41 -
    2.42 -val smallN = "small";
    2.43 +val exhaustiveN = "exhaustive";
    2.44  
    2.45 -fun smallT T = (T --> @{typ "Code_Evaluation.term list option"}) --> @{typ code_numeral}
    2.46 -  --> @{typ "Code_Evaluation.term list option"}
    2.47 -
    2.48 -val full_smallN = "full_small";
    2.49 -
    2.50 -fun full_smallT T = (termifyT T --> @{typ "Code_Evaluation.term list option"})
    2.51 +fun exhaustiveT T = (termifyT T --> @{typ "Code_Evaluation.term list option"})
    2.52    --> @{typ code_numeral} --> @{typ "Code_Evaluation.term list option"}
    2.53  
    2.54  fun check_allT T = (termifyT T --> @{typ "Code_Evaluation.term list option"})
    2.55    --> @{typ "Code_Evaluation.term list option"}
    2.56  
    2.57 -fun mk_equations thy descr vs tycos smalls (Ts, Us) =
    2.58 +fun mk_equations thy descr vs tycos exhaustives (Ts, Us) =
    2.59    let
    2.60 -    fun mk_small_call T =
    2.61 +    fun mk_call T =
    2.62        let
    2.63 -        val small = Const (@{const_name "Smallcheck.full_small_class.full_small"}, full_smallT T)        
    2.64 +        val exhaustive = Const (@{const_name "Quickcheck_Exhaustive.exhaustive_class.exhaustive"}, exhaustiveT T)        
    2.65        in
    2.66 -        (T, (fn t => small $
    2.67 +        (T, (fn t => exhaustive $
    2.68            (HOLogic.split_const (T, @{typ "unit => Code_Evaluation.term"}, @{typ "Code_Evaluation.term list option"})
    2.69            $ absdummy (T, absdummy (@{typ "unit => Code_Evaluation.term"}, t))) $ size_pred))
    2.70        end
    2.71 -    fun mk_small_aux_call fTs (k, _) (tyco, Ts) =
    2.72 +    fun mk_aux_call fTs (k, _) (tyco, Ts) =
    2.73        let
    2.74          val T = Type (tyco, Ts)
    2.75          val _ = if not (null fTs) then raise FUNCTION_TYPE else ()
    2.76 -        val small = nth smalls k
    2.77        in
    2.78 -       (T, (fn t => small $
    2.79 +       (T, (fn t => nth exhaustives k $
    2.80            (HOLogic.split_const (T, @{typ "unit => Code_Evaluation.term"}, @{typ "Code_Evaluation.term list option"})
    2.81 -            $ absdummy (T, absdummy (@{typ "unit => Code_Evaluation.term"}, t))) $ size_pred))  
    2.82 +            $ absdummy (T, absdummy (@{typ "unit => Code_Evaluation.term"}, t))) $ size_pred))
    2.83        end
    2.84      fun mk_consexpr simpleT (c, xs) =
    2.85        let
    2.86 @@ -132,11 +125,11 @@
    2.87              $ size_ge_zero $ (foldr1 mk_none_continuation exprs) $ @{term "None :: term list option"}
    2.88      val rhss =
    2.89        Datatype_Aux.interpret_construction descr vs
    2.90 -        { atyp = mk_small_call, dtyp = mk_small_aux_call }
    2.91 +        { atyp = mk_call, dtyp = mk_aux_call }
    2.92        |> (map o apfst) Type
    2.93        |> map (fn (T, cs) => map (mk_consexpr T) cs)
    2.94        |> map mk_rhs
    2.95 -    val lhss = map2 (fn t => fn T => t $ test_function T $ size) smalls (Ts @ Us);
    2.96 +    val lhss = map2 (fn t => fn T => t $ test_function T $ size) exhaustives (Ts @ Us);
    2.97      val eqs = map (HOLogic.mk_Trueprop o HOLogic.mk_eq) (lhss ~~ rhss)
    2.98    in
    2.99      eqs
   2.100 @@ -170,22 +163,22 @@
   2.101  
   2.102  (* creating the instances *)
   2.103  
   2.104 -fun instantiate_smallvalue_datatype config descr vs tycos prfx (names, auxnames) (Ts, Us) thy =
   2.105 +fun instantiate_exhaustive_datatype config descr vs tycos prfx (names, auxnames) (Ts, Us) thy =
   2.106    let
   2.107 -    val _ = Datatype_Aux.message config "Creating smallvalue generators ...";
   2.108 -    val smallsN = map (prefix (full_smallN ^ "_")) (names @ auxnames);
   2.109 +    val _ = Datatype_Aux.message config "Creating exhaustive generators ...";
   2.110 +    val exhaustivesN = map (prefix (exhaustiveN ^ "_")) (names @ auxnames);
   2.111    in
   2.112      thy
   2.113 -    |> Class.instantiation (tycos, vs, @{sort full_small})
   2.114 +    |> Class.instantiation (tycos, vs, @{sort exhaustive})
   2.115      |> (if define_foundationally then
   2.116        let
   2.117 -        val smalls = map2 (fn name => fn T => Free (name, full_smallT T)) smallsN (Ts @ Us)
   2.118 -        val eqs = mk_equations thy descr vs tycos smalls (Ts, Us)
   2.119 +        val exhaustives = map2 (fn name => fn T => Free (name, exhaustiveT T)) exhaustivesN (Ts @ Us)
   2.120 +        val eqs = mk_equations thy descr vs tycos exhaustives (Ts, Us)
   2.121        in
   2.122          Function.add_function
   2.123            (map (fn (name, T) =>
   2.124 -              Syntax.no_syn (Binding.conceal (Binding.name name), SOME (full_smallT T)))
   2.125 -                (smallsN ~~ (Ts @ Us)))
   2.126 +              Syntax.no_syn (Binding.conceal (Binding.name name), SOME (exhaustiveT T)))
   2.127 +                (exhaustivesN ~~ (Ts @ Us)))
   2.128              (map (pair (apfst Binding.conceal Attrib.empty_binding)) eqs)
   2.129            Function_Common.default_config pat_completeness_auto
   2.130          #> snd
   2.131 @@ -196,11 +189,11 @@
   2.132      else
   2.133        fold_map (fn (name, T) => Local_Theory.define
   2.134            ((Binding.conceal (Binding.name name), NoSyn),
   2.135 -            (apfst Binding.conceal Attrib.empty_binding, mk_undefined (full_smallT T)))
   2.136 -        #> apfst fst) (smallsN ~~ (Ts @ Us))
   2.137 -      #> (fn (smalls, lthy) =>
   2.138 +            (apfst Binding.conceal Attrib.empty_binding, mk_undefined (exhaustiveT T)))
   2.139 +        #> apfst fst) (exhaustivesN ~~ (Ts @ Us))
   2.140 +      #> (fn (exhaustives, lthy) =>
   2.141          let
   2.142 -          val eqs_t = mk_equations thy descr vs tycos smalls (Ts, Us)
   2.143 +          val eqs_t = mk_equations thy descr vs tycos exhaustives (Ts, Us)
   2.144            val eqs = map (fn eq => Goal.prove lthy ["f", "i"] [] eq
   2.145              (fn _ => Skip_Proof.cheat_tac (ProofContext.theory_of lthy))) eqs_t
   2.146          in
   2.147 @@ -208,12 +201,12 @@
   2.148            ((Binding.conceal (Binding.qualify true prfx
   2.149               (Binding.qualify true name (Binding.name "simps"))),
   2.150               Code.add_default_eqn_attrib :: map (Attrib.internal o K)
   2.151 -               [Simplifier.simp_add, Nitpick_Simps.add]), [eq]) #> snd) (smallsN ~~ eqs) lthy
   2.152 +               [Simplifier.simp_add, Nitpick_Simps.add]), [eq]) #> snd) (exhaustivesN ~~ eqs) lthy
   2.153          end))
   2.154      |> Class.prove_instantiation_exit (K (Class.intro_classes_tac []))
   2.155    end handle FUNCTION_TYPE =>
   2.156      (Datatype_Aux.message config
   2.157 -      "Creation of smallvalue generators failed because the datatype contains a function type";
   2.158 +      "Creation of exhaustivevalue generators failed because the datatype contains a function type";
   2.159      thy)
   2.160  
   2.161  (** building and compiling generator expressions **)
   2.162 @@ -250,19 +243,19 @@
   2.163        | strip_imp A = ([], A)
   2.164      val (assms, concl) = strip_imp (subst_bounds (rev frees, t'))
   2.165      val terms = HOLogic.mk_list @{typ term} (map (fn v => v $ @{term "()"}) term_vars)
   2.166 -    fun mk_small_closure (free as Free (_, T), term_var) t =
   2.167 +    fun mk_exhaustive_closure (free as Free (_, T), term_var) t =
   2.168        if Sign.of_sort thy (T, @{sort enum}) then
   2.169 -        Const (@{const_name "Smallcheck.check_all_class.check_all"}, check_allT T)
   2.170 +        Const (@{const_name "Quickcheck_Exhaustive.check_all_class.check_all"}, check_allT T)
   2.171            $ (HOLogic.split_const (T, @{typ "unit => term"}, @{typ "term list option"}) 
   2.172              $ lambda free (lambda term_var t))
   2.173        else
   2.174 -        Const (@{const_name "Smallcheck.full_small_class.full_small"}, full_smallT T)
   2.175 +        Const (@{const_name "Quickcheck_Exhaustive.exhaustive_class.exhaustive"}, exhaustiveT T)
   2.176            $ (HOLogic.split_const (T, @{typ "unit => term"}, @{typ "term list option"}) 
   2.177              $ lambda free (lambda term_var t)) $ depth
   2.178      fun lookup v = the (AList.lookup (op =) (names ~~ (frees ~~ term_vars)) v)
   2.179      val none_t = @{term "None :: term list option"}
   2.180      fun mk_safe_if (cond, then_t, else_t) =
   2.181 -      @{term "Smallcheck.catch_match :: term list option => term list option => term list option"} $
   2.182 +      @{term "Quickcheck_Exhaustive.catch_match :: term list option => term list option => term list option"} $
   2.183          (@{term "If :: bool => term list option => term list option => term list option"}
   2.184          $ cond $ then_t $ else_t) $ none_t;
   2.185      fun mk_test_term bound_vars assms =
   2.186 @@ -274,7 +267,7 @@
   2.187            | assm :: assms =>
   2.188              (vars_of assm, (assm, mk_test_term (union (op =) (vars_of assm) bound_vars) assms, none_t))
   2.189        in
   2.190 -        fold_rev mk_small_closure (map lookup vars) (mk_safe_if check)
   2.191 +        fold_rev mk_exhaustive_closure (map lookup vars) (mk_safe_if check)
   2.192        end
   2.193    in lambda depth (mk_test_term [] assms) end
   2.194  
   2.195 @@ -288,15 +281,15 @@
   2.196      val result = list_comb (t, map (fn (i, _, _, _) => Bound i) bounds);
   2.197      val terms = HOLogic.mk_list @{typ term} (map (fn (_, i, _, _) => Bound i $ @{term "()"}) bounds);
   2.198      val check =
   2.199 -      @{term "Smallcheck.catch_match :: term list option => term list option => term list option"} $
   2.200 +      @{term "Quickcheck_Exhaustive.catch_match :: term list option => term list option => term list option"} $
   2.201          (@{term "If :: bool => term list option => term list option => term list option"}
   2.202          $ result $ @{term "None :: term list option"} $ (@{term "Some :: term list => term list option"} $ terms))
   2.203        $ @{term "None :: term list option"};
   2.204 -    fun mk_small_closure (_, _, i, T) t =
   2.205 -      Const (@{const_name "Smallcheck.full_small_class.full_small"}, full_smallT T)
   2.206 +    fun mk_exhaustive_closure (_, _, i, T) t =
   2.207 +      Const (@{const_name "Quickcheck_Exhaustive.exhaustive_class.exhaustive"}, exhaustiveT T)
   2.208          $ (HOLogic.split_const (T, @{typ "unit => term"}, @{typ "term list option"}) 
   2.209          $ absdummy (T, absdummy (@{typ "unit => term"}, t))) $ Bound i
   2.210 -  in Abs ("d", @{typ code_numeral}, fold_rev mk_small_closure bounds check) end
   2.211 +  in Abs ("d", @{typ code_numeral}, fold_rev mk_exhaustive_closure bounds check) end
   2.212  
   2.213  (** post-processing of function terms **)
   2.214  
   2.215 @@ -376,7 +369,7 @@
   2.216        (if Config.get ctxt smart_quantifier then mk_smart_generator_expr else mk_generator_expr)
   2.217          ctxt t;
   2.218      val compile = Code_Runtime.dynamic_value_strict
   2.219 -      (Counterexample.get, put_counterexample, "Smallvalue_Generators.put_counterexample")
   2.220 +      (Counterexample.get, put_counterexample, "Exhaustive_Generators.put_counterexample")
   2.221        thy (SOME target) (fn proc => fn g => g #> (Option.map o map) proc) t' [];
   2.222    in
   2.223      fn size => rpair NONE (compile size |> 
   2.224 @@ -391,7 +384,7 @@
   2.225      val ts' = map (mk_generator_expr ctxt) ts;
   2.226      val compiles = Code_Runtime.dynamic_value_strict
   2.227        (Counterexample_Batch.get, put_counterexample_batch,
   2.228 -        "Smallvalue_Generators.put_counterexample_batch")
   2.229 +        "Exhaustive_Generators.put_counterexample_batch")
   2.230        thy (SOME target) (fn proc => map (fn g => g #> (Option.map o map) proc))
   2.231        (HOLogic.mk_list @{typ "code_numeral => term list option"} ts') [];
   2.232    in
   2.233 @@ -403,7 +396,7 @@
   2.234  
   2.235  val setup =
   2.236    Datatype.interpretation
   2.237 -    (Quickcheck_Generators.ensure_sort_datatype (@{sort full_small}, instantiate_smallvalue_datatype))
   2.238 +    (Quickcheck_Generators.ensure_sort_datatype (@{sort exhaustive}, instantiate_exhaustive_datatype))
   2.239    #> setup_smart_quantifier
   2.240    #> setup_quickcheck_pretty
   2.241    #> Context.theory_map (Quickcheck.add_generator ("exhaustive", compile_generator_expr))