definition random_nat :: "natural \ Random.seed \<Rightarrow> (nat \<times> (unit \<Rightarrow> Code_Evaluation.term)) \<times> Random.seed" where "random_nat i = Random.range (i + 1) \\ (\k. Pair ( let n = nat_of_natural k in (n, \<lambda>_. Code_Evaluation.term_of n)))"
instance ..
end
end
instantiation int :: random begin
context includes state_combinator_syntax begin
definition "random i = Random.range (2 * i + 1) \\ (\k. Pair ( let j = (if k \<ge> i then int (nat_of_natural (k - i)) else - (int (nat_of_natural (i - k)))) in (j, \<lambda>_. Code_Evaluation.term_of j)))"
instance ..
end
end
instantiation natural :: random begin
context includes state_combinator_syntax begin
definition random_natural :: "natural \ Random.seed \<Rightarrow> (natural \<times> (unit \<Rightarrow> Code_Evaluation.term)) \<times> Random.seed" where "random_natural i = Random.range (i + 1) \\ (\n. Pair (n, \_. Code_Evaluation.term_of n))"
instance ..
end
end
instantiation integer :: random begin
context includes state_combinator_syntax begin
definition random_integer :: "natural \ Random.seed \<Rightarrow> (integer \<times> (unit \<Rightarrow> Code_Evaluation.term)) \<times> Random.seed" where "random_integer i = Random.range (2 * i + 1) \\ (\k. Pair ( let j = (if k \<ge> i then integer_of_natural (k - i) else - (integer_of_natural (i - k))) in (j, \<lambda>_. Code_Evaluation.term_of j)))"
definition [code_unfold]: "valtermify_insert x s = Code_Evaluation.valtermify insert {\} (x :: ('a :: typerep * _)) {\} s"
end
instantiation set :: (random) random begin
context includes state_combinator_syntax begin
fun random_aux_set where "random_aux_set 0 j = collapse (Random.select_weight [(1, Pair valterm_emptyset)])"
| "random_aux_set (Code_Numeral.Suc i) j =
collapse (Random.select_weight
[(1, Pair valterm_emptyset),
(Code_Numeral.Suc i,
random j \<circ>\<rightarrow> (%x. random_aux_set i j \<circ>\<rightarrow> (%s. Pair (valtermify_insert x s))))])"
lemma [code]: "random_aux_set i j =
collapse (Random.select_weight [(1, Pair valterm_emptyset),
(i, random j \<circ>\<rightarrow> (%x. random_aux_set (i - 1) j \<circ>\<rightarrow> (%s. Pair (valtermify_insert x s))))])" proof (induct i rule: natural.induct) case zero show ?caseby (subst select_weight_drop_zero [symmetric])
(simp add: random_aux_set.simps [simplified] less_natural_def) next case (Suc i) show ?caseby (simp only: random_aux_set.simps(2) [of "i"] Suc_natural_minus_one) qed
code_printing
constant random_fun_aux \<rightharpoonup> (Quickcheck) "Random'_Generators.random'_fun" \<comment> \<open>With enough criminal energy this can be abused to derive \<^prop>\<open>False\<close>; for this reason we use a distinguished target \<open>Quickcheck\<close>
not spoiling the regular trusted code generation\<close>
code_reserved
(Quickcheck) Random_Generators
hide_const (open) catch_match random collapse beyond random_fun_aux random_fun_lift
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.