equal
deleted
inserted
replaced
3 *) |
3 *) |
4 |
4 |
5 header {* A simple counterexample generator *} |
5 header {* A simple counterexample generator *} |
6 |
6 |
7 theory Quickcheck |
7 theory Quickcheck |
8 imports Random Eval |
8 imports Random Code_Eval |
9 begin |
9 begin |
10 |
10 |
11 subsection {* The @{text random} class *} |
11 subsection {* The @{text random} class *} |
12 |
12 |
13 class random = rtype + |
13 class random = rtype + |
17 |
17 |
18 instantiation itself :: ("{type, rtype}") random |
18 instantiation itself :: ("{type, rtype}") random |
19 begin |
19 begin |
20 |
20 |
21 definition |
21 definition |
22 "random _ = return (TYPE('a), \<lambda>u. Eval.Const (STR ''TYPE'') RTYPE('a))" |
22 "random _ = return (TYPE('a), \<lambda>u. Code_Eval.Const (STR ''TYPE'') RTYPE('a))" |
23 |
23 |
24 instance .. |
24 instance .. |
25 |
25 |
26 end |
26 end |
27 |
27 |
171 |
171 |
172 definition |
172 definition |
173 "random n = (do |
173 "random n = (do |
174 (b, _) \<leftarrow> random n; |
174 (b, _) \<leftarrow> random n; |
175 (m, t) \<leftarrow> random n; |
175 (m, t) \<leftarrow> random n; |
176 return (if b then (int m, \<lambda>u. Eval.App (Eval.Const (STR ''Int.int'') RTYPE(nat \<Rightarrow> int)) (t ())) |
176 return (if b then (int m, \<lambda>u. Code_Eval.App (Code_Eval.Const (STR ''Int.int'') RTYPE(nat \<Rightarrow> int)) (t ())) |
177 else (- int m, \<lambda>u. Eval.App (Eval.Const (STR ''HOL.uminus_class.uminus'') RTYPE(int \<Rightarrow> int)) |
177 else (- int m, \<lambda>u. Code_Eval.App (Code_Eval.Const (STR ''HOL.uminus_class.uminus'') RTYPE(int \<Rightarrow> int)) |
178 (Eval.App (Eval.Const (STR ''Int.int'') RTYPE(nat \<Rightarrow> int)) (t ())))) |
178 (Code_Eval.App (Code_Eval.Const (STR ''Int.int'') RTYPE(nat \<Rightarrow> int)) (t ())))) |
179 done)" |
179 done)" |
180 |
180 |
181 instance .. |
181 instance .. |
182 |
182 |
183 end |
183 end |
227 |
227 |
228 instantiation "fun" :: ("{eq, term_of}", "{type, random}") random |
228 instantiation "fun" :: ("{eq, term_of}", "{type, random}") random |
229 begin |
229 begin |
230 |
230 |
231 definition random_fun :: "index \<Rightarrow> seed \<Rightarrow> (('a \<Rightarrow> 'b) \<times> (unit \<Rightarrow> term)) \<times> seed" where |
231 definition random_fun :: "index \<Rightarrow> seed \<Rightarrow> (('a \<Rightarrow> 'b) \<times> (unit \<Rightarrow> term)) \<times> seed" where |
232 "random n = random_fun_aux RTYPE('a) RTYPE('b) (op =) Eval.term_of (random n) split_seed" |
232 "random n = random_fun_aux RTYPE('a) RTYPE('b) (op =) Code_Eval.term_of (random n) split_seed" |
233 |
233 |
234 instance .. |
234 instance .. |
235 |
235 |
236 end |
236 end |
237 |
237 |