| author | haftmann | 
| Wed, 12 May 2010 12:09:28 +0200 | |
| changeset 36853 | c8e4102b08aa | 
| parent 36176 | 3fe7e97ccca8 | 
| child 37751 | 89e16802b6cc | 
| permissions | -rw-r--r-- | 
| 29132 | 1 | (* Author: Florian Haftmann, TU Muenchen *) | 
| 26265 | 2 | |
| 3 | header {* A simple counterexample generator *}
 | |
| 4 | ||
| 5 | theory Quickcheck | |
| 32657 | 6 | imports Random Code_Evaluation | 
| 31260 | 7 | uses ("Tools/quickcheck_generators.ML")
 | 
| 26265 | 8 | begin | 
| 9 | ||
| 31179 | 10 | notation fcomp (infixl "o>" 60) | 
| 11 | notation scomp (infixl "o\<rightarrow>" 60) | |
| 12 | ||
| 13 | ||
| 26265 | 14 | subsection {* The @{text random} class *}
 | 
| 15 | ||
| 28335 | 16 | class random = typerep + | 
| 31205 
98370b26c2ce
String.literal replaces message_string, code_numeral replaces (code_)index
 haftmann parents: 
31203diff
changeset | 17 |   fixes random :: "code_numeral \<Rightarrow> Random.seed \<Rightarrow> ('a \<times> (unit \<Rightarrow> term)) \<times> Random.seed"
 | 
| 26265 | 18 | |
| 26267 
ba710daf77a7
added combinator for interpretation of construction of datatype
 haftmann parents: 
26265diff
changeset | 19 | |
| 31260 | 20 | subsection {* Fundamental and numeric types*}
 | 
| 31179 | 21 | |
| 22 | instantiation bool :: random | |
| 23 | begin | |
| 24 | ||
| 25 | definition | |
| 31985 | 26 | "random i = Random.range 2 o\<rightarrow> | 
| 32657 | 27 | (\<lambda>k. Pair (if k = 0 then Code_Evaluation.valtermify False else Code_Evaluation.valtermify True))" | 
| 31179 | 28 | |
| 29 | instance .. | |
| 30 | ||
| 31 | end | |
| 32 | ||
| 33 | instantiation itself :: (typerep) random | |
| 34 | begin | |
| 35 | ||
| 31205 
98370b26c2ce
String.literal replaces message_string, code_numeral replaces (code_)index
 haftmann parents: 
31203diff
changeset | 36 | definition random_itself :: "code_numeral \<Rightarrow> Random.seed \<Rightarrow> ('a itself \<times> (unit \<Rightarrow> term)) \<times> Random.seed" where
 | 
| 32657 | 37 |   "random_itself _ = Pair (Code_Evaluation.valtermify TYPE('a))"
 | 
| 31179 | 38 | |
| 39 | instance .. | |
| 40 | ||
| 41 | end | |
| 42 | ||
| 31483 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 43 | instantiation char :: random | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 44 | begin | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 45 | |
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 46 | definition | 
| 32657 | 47 | "random _ = Random.select chars o\<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: 
31267diff
changeset | 48 | |
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 49 | instance .. | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 50 | |
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 51 | end | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 52 | |
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 53 | instantiation String.literal :: random | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 54 | begin | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 55 | |
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 56 | definition | 
| 32657 | 57 | "random _ = Pair (STR '''', \<lambda>u. Code_Evaluation.term_of (STR ''''))" | 
| 31483 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 58 | |
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 59 | instance .. | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 60 | |
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 61 | end | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 62 | |
| 31179 | 63 | instantiation nat :: random | 
| 64 | begin | |
| 65 | ||
| 32657 | 66 | definition random_nat :: "code_numeral \<Rightarrow> Random.seed \<Rightarrow> (nat \<times> (unit \<Rightarrow> Code_Evaluation.term)) \<times> Random.seed" where | 
| 31194 | 67 | "random_nat i = Random.range (i + 1) o\<rightarrow> (\<lambda>k. Pair ( | 
| 31205 
98370b26c2ce
String.literal replaces message_string, code_numeral replaces (code_)index
 haftmann parents: 
31203diff
changeset | 68 | let n = Code_Numeral.nat_of k | 
| 32657 | 69 | in (n, \<lambda>_. Code_Evaluation.term_of n)))" | 
| 31194 | 70 | |
| 71 | instance .. | |
| 72 | ||
| 73 | end | |
| 74 | ||
| 75 | instantiation int :: random | |
| 76 | begin | |
| 77 | ||
| 78 | definition | |
| 79 | "random i = Random.range (2 * i + 1) o\<rightarrow> (\<lambda>k. Pair ( | |
| 31205 
98370b26c2ce
String.literal replaces message_string, code_numeral replaces (code_)index
 haftmann parents: 
31203diff
changeset | 80 | let j = (if k \<ge> i then Code_Numeral.int_of (k - i) else - Code_Numeral.int_of (i - k)) | 
| 32657 | 81 | in (j, \<lambda>_. Code_Evaluation.term_of j)))" | 
| 31179 | 82 | |
| 83 | instance .. | |
| 84 | ||
| 30945 | 85 | end | 
| 31179 | 86 | |
| 31260 | 87 | |
| 88 | subsection {* Complex generators *}
 | |
| 89 | ||
| 31603 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 90 | text {* Towards @{typ "'a \<Rightarrow> 'b"} *}
 | 
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 91 | |
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 92 | axiomatization random_fun_aux :: "typerep \<Rightarrow> typerep \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> term)
 | 
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 93 |   \<Rightarrow> (Random.seed \<Rightarrow> ('b \<times> (unit \<Rightarrow> term)) \<times> Random.seed) \<Rightarrow> (Random.seed \<Rightarrow> Random.seed \<times> Random.seed)
 | 
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 94 |   \<Rightarrow> Random.seed \<Rightarrow> (('a \<Rightarrow> 'b) \<times> (unit \<Rightarrow> term)) \<times> Random.seed"
 | 
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 95 | |
| 31622 | 96 | definition random_fun_lift :: "(Random.seed \<Rightarrow> ('b \<times> (unit \<Rightarrow> term)) \<times> Random.seed)
 | 
| 97 |   \<Rightarrow> Random.seed \<Rightarrow> (('a\<Colon>term_of \<Rightarrow> 'b\<Colon>typerep) \<times> (unit \<Rightarrow> term)) \<times> Random.seed" where
 | |
| 32657 | 98 |   "random_fun_lift f = 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: 
31483diff
changeset | 99 | |
| 31985 | 100 | instantiation "fun" :: ("{eq, term_of}", random) random
 | 
| 31603 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 101 | begin | 
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 102 | |
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 103 | definition random_fun :: "code_numeral \<Rightarrow> Random.seed \<Rightarrow> (('a \<Rightarrow> 'b) \<times> (unit \<Rightarrow> term)) \<times> Random.seed" where
 | 
| 31622 | 104 | "random i = random_fun_lift (random i)" | 
| 31603 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 105 | |
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 106 | instance .. | 
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 107 | |
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 108 | end | 
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 109 | |
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 110 | text {* Towards type copies and datatypes *}
 | 
| 
fa30cd74d7d6
revised interpretation combinator for datatype constructions
 haftmann parents: 
31483diff
changeset | 111 | |
| 31260 | 112 | definition collapse :: "('a \<Rightarrow> ('a \<Rightarrow> 'b \<times> 'a) \<times> 'a) \<Rightarrow> 'a \<Rightarrow> 'b \<times> 'a" where
 | 
| 113 | "collapse f = (f o\<rightarrow> id)" | |
| 31223 
87bde6b5f793
re-added corrected version of type copy quickcheck generator
 haftmann parents: 
31211diff
changeset | 114 | |
| 31260 | 115 | definition beyond :: "code_numeral \<Rightarrow> code_numeral \<Rightarrow> code_numeral" where | 
| 116 | "beyond k l = (if l > k then l else 0)" | |
| 117 | ||
| 31267 | 118 | lemma beyond_zero: | 
| 119 | "beyond k 0 = 0" | |
| 120 | by (simp add: beyond_def) | |
| 121 | ||
| 31483 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 122 | lemma random_aux_rec: | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 123 | fixes random_aux :: "code_numeral \<Rightarrow> 'a" | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 124 | assumes "random_aux 0 = rhs 0" | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 125 | and "\<And>k. random_aux (Suc_code_numeral k) = rhs (Suc_code_numeral k)" | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 126 | shows "random_aux k = rhs k" | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 127 | using assms by (rule code_numeral.induct) | 
| 
88210717bfc8
added generator for char and trivial generator for String.literal
 haftmann parents: 
31267diff
changeset | 128 | |
| 34968 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 129 | use "Tools/quickcheck_generators.ML" | 
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 130 | setup Quickcheck_Generators.setup | 
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 131 | |
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 132 | |
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 133 | subsection {* Code setup *}
 | 
| 33561 
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
 blanchet parents: 
32657diff
changeset | 134 | |
| 34968 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 135 | code_const random_fun_aux (Quickcheck "Quickcheck'_Generators.random'_fun") | 
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 136 |   -- {* 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: 
33562diff
changeset | 137 |   for this reason we use a distinguished target @{text Quickcheck}
 | 
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 138 | not spoiling the regular trusted code generation *} | 
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 139 | |
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 140 | code_reserved Quickcheck Quickcheck_Generators | 
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 141 | |
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 142 | no_notation fcomp (infixl "o>" 60) | 
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 143 | no_notation scomp (infixl "o\<rightarrow>" 60) | 
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 144 | |
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 145 | |
| 
ceeffca32eb0
tuned structure; moved non-related quickcheck.setup to Code_Generator.thy
 haftmann parents: 
33562diff
changeset | 146 | subsection {* The Random-Predicate Monad *} 
 | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 147 | |
| 35880 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 148 | fun iter' :: | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 149 |   "'a itself => code_numeral => code_numeral => code_numeral * code_numeral => ('a::random) Predicate.pred"
 | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 150 | where | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 151 | "iter' T nrandom sz seed = (if nrandom = 0 then bot_class.bot else | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 152 | let ((x, _), seed') = random sz seed | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 153 | in Predicate.Seq (%u. Predicate.Insert x (iter' T (nrandom - 1) sz seed')))" | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 154 | |
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 155 | definition iter :: "code_numeral => code_numeral => code_numeral * code_numeral => ('a::random) Predicate.pred"
 | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 156 | where | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 157 |   "iter nrandom sz seed = iter' (TYPE('a)) nrandom sz seed"
 | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 158 | |
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 159 | lemma [code]: | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 160 | "iter nrandom sz seed = (if nrandom = 0 then bot_class.bot else | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 161 | let ((x, _), seed') = random sz seed | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 162 | in Predicate.Seq (%u. Predicate.Insert x (iter (nrandom - 1) sz seed')))" | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 163 | unfolding iter_def iter'.simps[of _ nrandom] .. | 
| 
2623b23e41fc
a new simpler random compilation for the predicate compiler
 bulwahn parents: 
35028diff
changeset | 164 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 165 | types 'a randompred = "Random.seed \<Rightarrow> ('a Predicate.pred \<times> Random.seed)"
 | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 166 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 167 | definition empty :: "'a randompred" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 168 | where "empty = Pair (bot_class.bot)" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 169 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 170 | definition single :: "'a => 'a randompred" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 171 | where "single x = Pair (Predicate.single x)" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 172 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 173 | definition bind :: "'a randompred \<Rightarrow> ('a \<Rightarrow> 'b randompred) \<Rightarrow> 'b randompred"
 | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 174 | where | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 175 | "bind R f = (\<lambda>s. let | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 176 | (P, s') = R s; | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 177 | (s1, s2) = Random.split_seed s' | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 178 | in (Predicate.bind P (%a. fst (f a s1)), s2))" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 179 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 180 | definition union :: "'a randompred \<Rightarrow> 'a randompred \<Rightarrow> 'a randompred" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 181 | where | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 182 | "union R1 R2 = (\<lambda>s. let | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 183 | (P1, s') = R1 s; (P2, s'') = R2 s' | 
| 35028 
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
 haftmann parents: 
34968diff
changeset | 184 | in (semilattice_sup_class.sup P1 P2, s''))" | 
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 185 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 186 | definition if_randompred :: "bool \<Rightarrow> unit randompred" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 187 | where | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 188 | "if_randompred b = (if b then single () else empty)" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 189 | |
| 36049 
0ce5b7a5c2fd
adding iterate_upto interface in compilations and iterate_upto functions in Isabelle theories for arithmetic setup of the predicate compiler
 bulwahn parents: 
35880diff
changeset | 190 | definition iterate_upto :: "(code_numeral => 'a) => code_numeral => code_numeral => 'a randompred" | 
| 
0ce5b7a5c2fd
adding iterate_upto interface in compilations and iterate_upto functions in Isabelle theories for arithmetic setup of the predicate compiler
 bulwahn parents: 
35880diff
changeset | 191 | where | 
| 
0ce5b7a5c2fd
adding iterate_upto interface in compilations and iterate_upto functions in Isabelle theories for arithmetic setup of the predicate compiler
 bulwahn parents: 
35880diff
changeset | 192 | "iterate_upto f n m = Pair (Code_Numeral.iterate_upto f n m)" | 
| 
0ce5b7a5c2fd
adding iterate_upto interface in compilations and iterate_upto functions in Isabelle theories for arithmetic setup of the predicate compiler
 bulwahn parents: 
35880diff
changeset | 193 | |
| 33250 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 194 | definition not_randompred :: "unit randompred \<Rightarrow> unit randompred" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 195 | where | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 196 | "not_randompred P = (\<lambda>s. let | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 197 | (P', s') = P s | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 198 | in if Predicate.eval P' () then (Orderings.bot, s') else (Predicate.single (), s'))" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 199 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 200 | definition Random :: "(Random.seed \<Rightarrow> ('a \<times> (unit \<Rightarrow> term)) \<times> Random.seed) \<Rightarrow> 'a randompred"
 | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 201 | where "Random g = scomp g (Pair o (Predicate.single o fst))" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 202 | |
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 203 | definition map :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a randompred \<Rightarrow> 'b randompred)"
 | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 204 | where "map f P = bind P (single o f)" | 
| 
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
 bulwahn parents: 
32657diff
changeset | 205 | |
| 36176 
3fe7e97ccca8
replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
 wenzelm parents: 
36049diff
changeset | 206 | hide_fact (open) iter'.simps iter_def empty_def single_def bind_def union_def if_randompred_def iterate_upto_def not_randompred_def Random_def map_def | 
| 
3fe7e97ccca8
replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
 wenzelm parents: 
36049diff
changeset | 207 | hide_type (open) randompred | 
| 
3fe7e97ccca8
replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
 wenzelm parents: 
36049diff
changeset | 208 | hide_const (open) random collapse beyond random_fun_aux random_fun_lift | 
| 36049 
0ce5b7a5c2fd
adding iterate_upto interface in compilations and iterate_upto functions in Isabelle theories for arithmetic setup of the predicate compiler
 bulwahn parents: 
35880diff
changeset | 209 | iter' iter empty single bind union if_randompred iterate_upto not_randompred Random map | 
| 31267 | 210 | |
| 31179 | 211 | end |