definition random_nat :: "natural ==> Random.seed ==> (nat × (unit ==> Code_Evaluation.term)) × Random.seed" where "random_nat i = Random.range (i + 1) ∘→ (λk. Pair ( let n = nat_of_natural k in (n, λ_. 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 ≥ i then int (nat_of_natural (k - i)) else - (int (nat_of_natural (i - k)))) in (j, λ_. Code_Evaluation.term_of j)))"
instance ..
end
end
instantiation natural :: random begin
context includes state_combinator_syntax begin
definition random_natural :: "natural ==> Random.seed ==> (natural × (unit ==> Code_Evaluation.term)) × 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 ==> (integer × (unit ==> Code_Evaluation.term)) × Random.seed" where "random_integer i = Random.range (2 * i + 1) ∘→ (λk. Pair ( let j = (if k ≥ i then integer_of_natural (k - i) else - (integer_of_natural (i - k))) in (j, λ_. 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 ∘→ (%x. random_aux_set i j ∘→ (%s. Pair (valtermify_insert x s))))])"
lemma [code]: "random_aux_set i j = collapse (Random.select_weight [(1, Pair valterm_emptyset), (i, random j ∘→ (%x. random_aux_set (i - 1) j ∘→ (%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 ⇀ (Quickcheck) "Random'_Generators.random'_fun" 🍋‹With enough criminal energy this can be abused to derive 🍋‹False›; for this reason we use a distinguished target ‹Quickcheck› not spoiling the regular trusted code generation›
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 und die Messung sind noch experimentell.