| author | boehmes | 
| Sun, 19 Jan 2014 23:02:00 +0100 | |
| changeset 55050 | de68c9c3e454 | 
| parent 52435 | 6646bb548c6b | 
| child 55147 | bce3dbc11f95 | 
| permissions | -rw-r--r-- | 
| 41922 | 1  | 
(* Author: Florian Haftmann & Lukas Bulwahn, TU Muenchen *)  | 
| 26265 | 2  | 
|
| 41922 | 3  | 
header {* A simple counterexample generator performing random testing *}
 | 
| 26265 | 4  | 
|
| 
51126
 
df86080de4cb
reform of predicate compiler / quickcheck theories:
 
haftmann 
parents: 
50046 
diff
changeset
 | 
5  | 
theory Quickcheck_Random  | 
| 
40650
 
d40b347d5b0b
adding Enum to HOL-Main image and removing it from HOL-Library
 
bulwahn 
parents: 
38857 
diff
changeset
 | 
6  | 
imports Random Code_Evaluation Enum  | 
| 26265 | 7  | 
begin  | 
8  | 
||
| 37751 | 9  | 
notation fcomp (infixl "\<circ>>" 60)  | 
10  | 
notation scomp (infixl "\<circ>\<rightarrow>" 60)  | 
|
| 31179 | 11  | 
|
| 
45718
 
8979b2463fc8
quickcheck random can also find potential counterexamples;
 
bulwahn 
parents: 
45178 
diff
changeset
 | 
12  | 
setup {* Code_Target.extend_target ("Quickcheck", (Code_Runtime.target, K I)) *}
 | 
| 
 
8979b2463fc8
quickcheck random can also find potential counterexamples;
 
bulwahn 
parents: 
45178 
diff
changeset
 | 
13  | 
|
| 
 
8979b2463fc8
quickcheck random can also find potential counterexamples;
 
bulwahn 
parents: 
45178 
diff
changeset
 | 
14  | 
subsection {* Catching Match exceptions *}
 | 
| 
 
8979b2463fc8
quickcheck random can also find potential counterexamples;
 
bulwahn 
parents: 
45178 
diff
changeset
 | 
15  | 
|
| 
45801
 
5616fbda86e6
hiding definitional facts in Quickcheck; introducing catch_match more honestly
 
bulwahn 
parents: 
45733 
diff
changeset
 | 
16  | 
axiomatization catch_match :: "'a => 'a => 'a"  | 
| 
45718
 
8979b2463fc8
quickcheck random can also find potential counterexamples;
 
bulwahn 
parents: 
45178 
diff
changeset
 | 
17  | 
|
| 
52435
 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 
haftmann 
parents: 
51143 
diff
changeset
 | 
18  | 
code_printing  | 
| 
 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 
haftmann 
parents: 
51143 
diff
changeset
 | 
19  | 
constant catch_match \<rightharpoonup> (Quickcheck) "((_) handle Match => _)"  | 
| 31179 | 20  | 
|
| 26265 | 21  | 
subsection {* The @{text random} class *}
 | 
22  | 
||
| 28335 | 23  | 
class random = typerep +  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
24  | 
  fixes random :: "natural \<Rightarrow> Random.seed \<Rightarrow> ('a \<times> (unit \<Rightarrow> term)) \<times> Random.seed"
 | 
| 26265 | 25  | 
|
| 
26267
 
ba710daf77a7
added combinator for interpretation of construction of datatype
 
haftmann 
parents: 
26265 
diff
changeset
 | 
26  | 
|
| 31260 | 27  | 
subsection {* Fundamental and numeric types*}
 | 
| 31179 | 28  | 
|
29  | 
instantiation bool :: random  | 
|
30  | 
begin  | 
|
31  | 
||
32  | 
definition  | 
|
| 37751 | 33  | 
"random i = Random.range 2 \<circ>\<rightarrow>  | 
| 32657 | 34  | 
(\<lambda>k. Pair (if k = 0 then Code_Evaluation.valtermify False else Code_Evaluation.valtermify True))"  | 
| 31179 | 35  | 
|
36  | 
instance ..  | 
|
37  | 
||
38  | 
end  | 
|
39  | 
||
40  | 
instantiation itself :: (typerep) random  | 
|
41  | 
begin  | 
|
42  | 
||
| 46975 | 43  | 
definition  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
44  | 
  random_itself :: "natural \<Rightarrow> Random.seed \<Rightarrow> ('a itself \<times> (unit \<Rightarrow> term)) \<times> Random.seed"
 | 
| 46975 | 45  | 
where "random_itself _ = Pair (Code_Evaluation.valtermify TYPE('a))"
 | 
| 31179 | 46  | 
|
47  | 
instance ..  | 
|
48  | 
||
49  | 
end  | 
|
50  | 
||
| 
31483
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
51  | 
instantiation char :: random  | 
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
52  | 
begin  | 
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
53  | 
|
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
54  | 
definition  | 
| 
49972
 
f11f8905d9fd
incorporated constant chars into instantiation proof for enum;
 
haftmann 
parents: 
48891 
diff
changeset
 | 
55  | 
"random _ = Random.select (Enum.enum :: char list) \<circ>\<rightarrow> (\<lambda>c. Pair (c, \<lambda>u. Code_Evaluation.term_of c))"  | 
| 
31483
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
56  | 
|
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
57  | 
instance ..  | 
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
58  | 
|
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
59  | 
end  | 
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
60  | 
|
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
61  | 
instantiation String.literal :: random  | 
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
62  | 
begin  | 
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
63  | 
|
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
64  | 
definition  | 
| 32657 | 65  | 
"random _ = Pair (STR '''', \<lambda>u. Code_Evaluation.term_of (STR ''''))"  | 
| 
31483
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
66  | 
|
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
67  | 
instance ..  | 
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
68  | 
|
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
69  | 
end  | 
| 
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
70  | 
|
| 31179 | 71  | 
instantiation nat :: random  | 
72  | 
begin  | 
|
73  | 
||
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
74  | 
definition random_nat :: "natural \<Rightarrow> Random.seed  | 
| 46975 | 75  | 
\<Rightarrow> (nat \<times> (unit \<Rightarrow> Code_Evaluation.term)) \<times> Random.seed"  | 
76  | 
where  | 
|
| 37751 | 77  | 
"random_nat i = Random.range (i + 1) \<circ>\<rightarrow> (\<lambda>k. Pair (  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
78  | 
let n = nat_of_natural k  | 
| 32657 | 79  | 
in (n, \<lambda>_. Code_Evaluation.term_of n)))"  | 
| 31194 | 80  | 
|
81  | 
instance ..  | 
|
82  | 
||
83  | 
end  | 
|
84  | 
||
85  | 
instantiation int :: random  | 
|
86  | 
begin  | 
|
87  | 
||
88  | 
definition  | 
|
| 37751 | 89  | 
"random i = Random.range (2 * i + 1) \<circ>\<rightarrow> (\<lambda>k. Pair (  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
90  | 
let j = (if k \<ge> i then int (nat_of_natural (k - i)) else - (int (nat_of_natural (i - k))))  | 
| 32657 | 91  | 
in (j, \<lambda>_. Code_Evaluation.term_of j)))"  | 
| 31179 | 92  | 
|
93  | 
instance ..  | 
|
94  | 
||
| 30945 | 95  | 
end  | 
| 31179 | 96  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
97  | 
instantiation natural :: random  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
98  | 
begin  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
99  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
100  | 
definition random_natural :: "natural \<Rightarrow> Random.seed  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
101  | 
\<Rightarrow> (natural \<times> (unit \<Rightarrow> Code_Evaluation.term)) \<times> Random.seed"  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
102  | 
where  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
103  | 
"random_natural i = Random.range (i + 1) \<circ>\<rightarrow> (\<lambda>n. Pair (n, \<lambda>_. Code_Evaluation.term_of n))"  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
104  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
105  | 
instance ..  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
106  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
107  | 
end  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
108  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
109  | 
instantiation integer :: random  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
110  | 
begin  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
111  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
112  | 
definition random_integer :: "natural \<Rightarrow> Random.seed  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
113  | 
\<Rightarrow> (integer \<times> (unit \<Rightarrow> Code_Evaluation.term)) \<times> Random.seed"  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
114  | 
where  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
115  | 
"random_integer i = Random.range (2 * i + 1) \<circ>\<rightarrow> (\<lambda>k. Pair (  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
116  | 
let j = (if k \<ge> i then integer_of_natural (k - i) else - (integer_of_natural (i - k)))  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
117  | 
in (j, \<lambda>_. Code_Evaluation.term_of j)))"  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
118  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
119  | 
instance ..  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
120  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
121  | 
end  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
122  | 
|
| 31260 | 123  | 
|
124  | 
subsection {* Complex generators *}
 | 
|
125  | 
||
| 
31603
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
126  | 
text {* Towards @{typ "'a \<Rightarrow> 'b"} *}
 | 
| 
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
127  | 
|
| 
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
128  | 
axiomatization random_fun_aux :: "typerep \<Rightarrow> typerep \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> term)
 | 
| 46975 | 129  | 
  \<Rightarrow> (Random.seed \<Rightarrow> ('b \<times> (unit \<Rightarrow> term)) \<times> Random.seed)
 | 
130  | 
\<Rightarrow> (Random.seed \<Rightarrow> Random.seed \<times> Random.seed)  | 
|
| 
31603
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
131  | 
  \<Rightarrow> Random.seed \<Rightarrow> (('a \<Rightarrow> 'b) \<times> (unit \<Rightarrow> term)) \<times> Random.seed"
 | 
| 
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
132  | 
|
| 31622 | 133  | 
definition random_fun_lift :: "(Random.seed \<Rightarrow> ('b \<times> (unit \<Rightarrow> term)) \<times> Random.seed)
 | 
| 46975 | 134  | 
  \<Rightarrow> Random.seed \<Rightarrow> (('a\<Colon>term_of \<Rightarrow> 'b\<Colon>typerep) \<times> (unit \<Rightarrow> term)) \<times> Random.seed"
 | 
135  | 
where  | 
|
136  | 
"random_fun_lift f =  | 
|
137  | 
    random_fun_aux TYPEREP('a) TYPEREP('b) (op =) Code_Evaluation.term_of f Random.split_seed"
 | 
|
| 
31603
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
138  | 
|
| 
38857
 
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
 
haftmann 
parents: 
37751 
diff
changeset
 | 
139  | 
instantiation "fun" :: ("{equal, term_of}", random) random
 | 
| 
31603
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
140  | 
begin  | 
| 
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
141  | 
|
| 46975 | 142  | 
definition  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
143  | 
  random_fun :: "natural \<Rightarrow> Random.seed \<Rightarrow> (('a \<Rightarrow> 'b) \<times> (unit \<Rightarrow> term)) \<times> Random.seed"
 | 
| 46975 | 144  | 
where "random i = random_fun_lift (random i)"  | 
| 
31603
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
145  | 
|
| 
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
146  | 
instance ..  | 
| 
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
147  | 
|
| 
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
148  | 
end  | 
| 
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
149  | 
|
| 
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
150  | 
text {* Towards type copies and datatypes *}
 | 
| 
 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 
haftmann 
parents: 
31483 
diff
changeset
 | 
151  | 
|
| 46975 | 152  | 
definition collapse :: "('a \<Rightarrow> ('a \<Rightarrow> 'b \<times> 'a) \<times> 'a) \<Rightarrow> 'a \<Rightarrow> 'b \<times> 'a"
 | 
153  | 
where "collapse f = (f \<circ>\<rightarrow> id)"  | 
|
| 
31223
 
87bde6b5f793
re-added corrected version of type copy quickcheck generator
 
haftmann 
parents: 
31211 
diff
changeset
 | 
154  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
155  | 
definition beyond :: "natural \<Rightarrow> natural \<Rightarrow> natural"  | 
| 46975 | 156  | 
where "beyond k l = (if l > k then l else 0)"  | 
| 31260 | 157  | 
|
| 46975 | 158  | 
lemma beyond_zero: "beyond k 0 = 0"  | 
| 31267 | 159  | 
by (simp add: beyond_def)  | 
160  | 
||
| 46311 | 161  | 
|
| 46975 | 162  | 
definition (in term_syntax) [code_unfold]:  | 
163  | 
  "valterm_emptyset = Code_Evaluation.valtermify ({} :: ('a :: typerep) set)"
 | 
|
164  | 
||
165  | 
definition (in term_syntax) [code_unfold]:  | 
|
166  | 
  "valtermify_insert x s = Code_Evaluation.valtermify insert {\<cdot>} (x :: ('a :: typerep * _)) {\<cdot>} s"
 | 
|
| 46311 | 167  | 
|
168  | 
instantiation set :: (random) random  | 
|
169  | 
begin  | 
|
170  | 
||
171  | 
primrec random_aux_set  | 
|
172  | 
where  | 
|
173  | 
"random_aux_set 0 j = collapse (Random.select_weight [(1, Pair valterm_emptyset)])"  | 
|
| 46975 | 174  | 
| "random_aux_set (Code_Numeral.Suc i) j =  | 
175  | 
collapse (Random.select_weight  | 
|
176  | 
[(1, Pair valterm_emptyset),  | 
|
177  | 
(Code_Numeral.Suc i,  | 
|
178  | 
random j \<circ>\<rightarrow> (%x. random_aux_set i j \<circ>\<rightarrow> (%s. Pair (valtermify_insert x s))))])"  | 
|
| 46311 | 179  | 
|
180  | 
lemma [code]:  | 
|
| 46975 | 181  | 
"random_aux_set i j =  | 
182  | 
collapse (Random.select_weight [(1, Pair valterm_emptyset),  | 
|
183  | 
(i, random j \<circ>\<rightarrow> (%x. random_aux_set (i - 1) j \<circ>\<rightarrow> (%s. Pair (valtermify_insert x s))))])"  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
184  | 
proof (induct i rule: natural.induct)  | 
| 46311 | 185  | 
case zero  | 
| 50046 | 186  | 
show ?case by (subst select_weight_drop_zero [symmetric])  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
187  | 
(simp add: random_aux_set.simps [simplified] less_natural_def)  | 
| 46311 | 188  | 
next  | 
| 
46547
 
d1dcb91a512e
use qualified constant names instead of suffixes (from Florian Haftmann)
 
huffman 
parents: 
46311 
diff
changeset
 | 
189  | 
case (Suc i)  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
190  | 
show ?case by (simp only: random_aux_set.simps(2) [of "i"] Suc_natural_minus_one)  | 
| 46311 | 191  | 
qed  | 
192  | 
||
| 46975 | 193  | 
definition "random_set i = random_aux_set i i"  | 
| 46311 | 194  | 
|
195  | 
instance ..  | 
|
196  | 
||
197  | 
end  | 
|
198  | 
||
| 
31483
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
199  | 
lemma random_aux_rec:  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
200  | 
fixes random_aux :: "natural \<Rightarrow> 'a"  | 
| 
31483
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
201  | 
assumes "random_aux 0 = rhs 0"  | 
| 
46547
 
d1dcb91a512e
use qualified constant names instead of suffixes (from Florian Haftmann)
 
huffman 
parents: 
46311 
diff
changeset
 | 
202  | 
and "\<And>k. random_aux (Code_Numeral.Suc k) = rhs (Code_Numeral.Suc k)"  | 
| 
31483
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
203  | 
shows "random_aux k = rhs k"  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
51126 
diff
changeset
 | 
204  | 
using assms by (rule natural.induct)  | 
| 
31483
 
88210717bfc8
added generator for char and trivial generator for String.literal
 
haftmann 
parents: 
31267 
diff
changeset
 | 
205  | 
|
| 
45718
 
8979b2463fc8
quickcheck random can also find potential counterexamples;
 
bulwahn 
parents: 
45178 
diff
changeset
 | 
206  | 
subsection {* Deriving random generators for datatypes *}
 | 
| 
 
8979b2463fc8
quickcheck random can also find potential counterexamples;
 
bulwahn 
parents: 
45178 
diff
changeset
 | 
207  | 
|
| 48891 | 208  | 
ML_file "Tools/Quickcheck/quickcheck_common.ML"  | 
209  | 
ML_file "Tools/Quickcheck/random_generators.ML"  | 
|
| 
41923
 
f05fc0711bc7
renaming signatures and structures; correcting header
 
bulwahn 
parents: 
41922 
diff
changeset
 | 
210  | 
setup Random_Generators.setup  | 
| 
34968
 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 
haftmann 
parents: 
33562 
diff
changeset
 | 
211  | 
|
| 
 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 
haftmann 
parents: 
33562 
diff
changeset
 | 
212  | 
|
| 
 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 
haftmann 
parents: 
33562 
diff
changeset
 | 
213  | 
subsection {* Code setup *}
 | 
| 
33561
 
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
 
blanchet 
parents: 
32657 
diff
changeset
 | 
214  | 
|
| 
52435
 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 
haftmann 
parents: 
51143 
diff
changeset
 | 
215  | 
code_printing  | 
| 
 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 
haftmann 
parents: 
51143 
diff
changeset
 | 
216  | 
constant random_fun_aux \<rightharpoonup> (Quickcheck) "Random'_Generators.random'_fun"  | 
| 
34968
 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 
haftmann 
parents: 
33562 
diff
changeset
 | 
217  | 
  -- {* With enough criminal energy this can be abused to derive @{prop False};
 | 
| 
 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 
haftmann 
parents: 
33562 
diff
changeset
 | 
218  | 
  for this reason we use a distinguished target @{text Quickcheck}
 | 
| 
 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 
haftmann 
parents: 
33562 
diff
changeset
 | 
219  | 
not spoiling the regular trusted code generation *}  | 
| 
 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 
haftmann 
parents: 
33562 
diff
changeset
 | 
220  | 
|
| 
41935
 
d786a8a3dc47
minor corrections for renaming; moved postprocessing of terms to Quickcheck_Common
 
bulwahn 
parents: 
41928 
diff
changeset
 | 
221  | 
code_reserved Quickcheck Random_Generators  | 
| 
34968
 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 
haftmann 
parents: 
33562 
diff
changeset
 | 
222  | 
|
| 37751 | 223  | 
no_notation fcomp (infixl "\<circ>>" 60)  | 
224  | 
no_notation scomp (infixl "\<circ>\<rightarrow>" 60)  | 
|
| 
51126
 
df86080de4cb
reform of predicate compiler / quickcheck theories:
 
haftmann 
parents: 
50046 
diff
changeset
 | 
225  | 
|
| 
45801
 
5616fbda86e6
hiding definitional facts in Quickcheck; introducing catch_match more honestly
 
bulwahn 
parents: 
45733 
diff
changeset
 | 
226  | 
hide_const (open) catch_match random collapse beyond random_fun_aux random_fun_lift  | 
| 
 
5616fbda86e6
hiding definitional facts in Quickcheck; introducing catch_match more honestly
 
bulwahn 
parents: 
45733 
diff
changeset
 | 
227  | 
|
| 
51126
 
df86080de4cb
reform of predicate compiler / quickcheck theories:
 
haftmann 
parents: 
50046 
diff
changeset
 | 
228  | 
hide_fact (open) collapse_def beyond_def random_fun_lift_def  | 
| 31267 | 229  | 
|
| 31179 | 230  | 
end  | 
| 
49972
 
f11f8905d9fd
incorporated constant chars into instantiation proof for enum;
 
haftmann 
parents: 
48891 
diff
changeset
 | 
231  |