5 *) |
5 *) |
6 |
6 |
7 signature RANDOM_GENERATORS = |
7 signature RANDOM_GENERATORS = |
8 sig |
8 sig |
9 type seed = Random_Engine.seed |
9 type seed = Random_Engine.seed |
10 val random_fun: typ -> typ -> ('a -> 'a -> bool) -> ('a -> term) |
10 val random_fun: typ -> typ -> ('a -> 'a -> bool) -> ('a -> term) -> |
11 -> (seed -> ('b * (unit -> term)) * seed) -> (seed -> seed * seed) |
11 (seed -> ('b * (unit -> term)) * seed) -> (seed -> seed * seed) -> |
12 -> seed -> (('a -> 'b) * (unit -> term)) * seed |
12 seed -> (('a -> 'b) * (unit -> term)) * seed |
13 val compile_generator_expr: |
13 val compile_generator_expr: Proof.context -> (term * term list) list -> bool -> int list -> |
14 Proof.context -> (term * term list) list -> bool -> int list -> (bool * term list) option * Quickcheck.report option |
14 (bool * term list) option * Quickcheck.report option |
15 val put_counterexample: (unit -> Code_Numeral.natural -> bool -> Code_Numeral.natural -> seed -> (bool * term list) option * seed) |
15 val put_counterexample: (unit -> Code_Numeral.natural -> bool -> Code_Numeral.natural -> |
16 -> Proof.context -> Proof.context |
16 seed -> (bool * term list) option * seed) -> Proof.context -> Proof.context |
17 val put_counterexample_report: (unit -> Code_Numeral.natural -> bool -> Code_Numeral.natural -> seed -> ((bool * term list) option * (bool list * bool)) * seed) |
17 val put_counterexample_report: (unit -> Code_Numeral.natural -> bool -> |
18 -> Proof.context -> Proof.context |
18 Code_Numeral.natural -> seed -> ((bool * term list) option * (bool list * bool)) * seed) -> |
|
19 Proof.context -> Proof.context |
19 val instantiate_random_datatype : Old_Datatype_Aux.config -> Old_Datatype_Aux.descr -> |
20 val instantiate_random_datatype : Old_Datatype_Aux.config -> Old_Datatype_Aux.descr -> |
20 (string * sort) list -> string list -> string -> string list * string list -> typ list * typ list -> theory -> theory |
21 (string * sort) list -> string list -> string -> string list * string list -> |
|
22 typ list * typ list -> theory -> theory |
21 end; |
23 end; |
22 |
24 |
23 structure Random_Generators : RANDOM_GENERATORS = |
25 structure Random_Generators : RANDOM_GENERATORS = |
24 struct |
26 struct |
25 |
27 |
26 (** abstract syntax **) |
28 (** abstract syntax **) |
27 |
29 |
28 fun termifyT T = HOLogic.mk_prodT (T, @{typ "unit => term"}) |
30 fun termifyT T = HOLogic.mk_prodT (T, @{typ "unit \<Rightarrow> term"}) |
29 val size = @{term "i::natural"}; |
31 val size = @{term "i::natural"}; |
30 val size_pred = @{term "(i::natural) - 1"}; |
32 val size_pred = @{term "(i::natural) - 1"}; |
31 val size' = @{term "j::natural"}; |
33 val size' = @{term "j::natural"}; |
32 val seed = @{term "s::Random.seed"}; |
34 val seed = @{term "s::Random.seed"}; |
33 |
35 |
34 val resultT = @{typ "(bool * term list) option"}; |
36 val resultT = @{typ "(bool \<times> term list) option"}; |
35 |
37 |
36 (** typ "'a => 'b" **) |
38 |
|
39 (** typ "'a \<Rightarrow> 'b" **) |
37 |
40 |
38 type seed = Random_Engine.seed; |
41 type seed = Random_Engine.seed; |
39 |
42 |
40 fun random_fun T1 T2 eq term_of random random_split seed = |
43 fun random_fun T1 T2 eq term_of random random_split seed = |
41 let |
44 let |
42 val fun_upd = Const (@{const_name fun_upd}, |
45 val fun_upd = Const (@{const_name fun_upd}, (T1 --> T2) --> T1 --> T2 --> T1 --> T2); |
43 (T1 --> T2) --> T1 --> T2 --> T1 --> T2); |
|
44 val ((_, t2), seed') = random seed; |
46 val ((_, t2), seed') = random seed; |
45 val (seed'', seed''') = random_split seed'; |
47 val (seed'', seed''') = random_split seed'; |
46 |
48 |
47 val state = Unsynchronized.ref (seed'', [], fn () => Abs ("x", T1, t2 ())); |
49 val state = Unsynchronized.ref (seed'', [], fn () => Abs ("x", T1, t2 ())); |
48 fun random_fun' x = |
50 fun random_fun' x = |