1 theory Quickcheck_Interfaces |
1 theory Quickcheck_Interfaces |
2 imports Main |
2 imports Main |
3 begin |
3 begin |
4 |
4 |
5 subsection {* Checking a single proposition (TODO) *} |
5 subsection \<open>Checking a single proposition (TODO)\<close> |
6 |
6 |
7 subsection {* Checking multiple propositions in one batch *} |
7 subsection \<open>Checking multiple propositions in one batch\<close> |
8 |
8 |
9 text {* |
9 text \<open> |
10 |
10 |
11 First, this requires to setup special generators for all datatypes via the following command. |
11 First, this requires to setup special generators for all datatypes via the following command. |
12 *} |
12 \<close> |
13 |
13 |
14 setup Exhaustive_Generators.setup_bounded_forall_datatype_interpretation |
14 setup Exhaustive_Generators.setup_bounded_forall_datatype_interpretation |
15 |
15 |
16 text {* |
16 text \<open> |
17 Now, the function Quickcheck.mk_batch_validator : Proof.context -> term list -> (int -> bool) list option |
17 Now, the function Quickcheck.mk_batch_validator : Proof.context -> term list -> (int -> bool) list option |
18 takes formulas of type bool with free variables, and returns a list of testing functions. |
18 takes formulas of type bool with free variables, and returns a list of testing functions. |
19 *} |
19 \<close> |
20 |
20 |
21 ML {* |
21 ML \<open> |
22 val SOME testers = Quickcheck.mk_batch_validator @{context} |
22 val SOME testers = Quickcheck.mk_batch_validator @{context} |
23 [@{term "x = (1 :: nat)"}, @{term "x = (0 :: nat)"}, @{term "x <= (5 :: nat)"}, @{term "0 \<le> (x :: nat)"}] |
23 [@{term "x = (1 :: nat)"}, @{term "x = (0 :: nat)"}, @{term "x <= (5 :: nat)"}, @{term "0 \<le> (x :: nat)"}] |
24 *} |
24 \<close> |
25 |
25 |
26 text {* |
26 text \<open> |
27 It is up to the user with which strategy the conjectures should be tested. |
27 It is up to the user with which strategy the conjectures should be tested. |
28 For example, one could check all conjectures up to a given size, and check the different conjectures in sequence. |
28 For example, one could check all conjectures up to a given size, and check the different conjectures in sequence. |
29 This is implemented by: |
29 This is implemented by: |
30 *} |
30 \<close> |
31 |
31 |
32 ML {* |
32 ML \<open> |
33 fun check_upto f i j = if i > j then true else f i andalso check_upto f (i + 1) j |
33 fun check_upto f i j = if i > j then true else f i andalso check_upto f (i + 1) j |
34 *} |
34 \<close> |
35 |
35 |
36 ML_val {* |
36 ML_val \<open> |
37 map (fn test => check_upto test 0 1) testers |
37 map (fn test => check_upto test 0 1) testers |
38 *} |
38 \<close> |
39 ML_val {* |
39 ML_val \<open> |
40 map (fn test => check_upto test 0 2) testers |
40 map (fn test => check_upto test 0 2) testers |
41 *} |
41 \<close> |
42 ML_val {* |
42 ML_val \<open> |
43 map (fn test => check_upto test 0 3) testers |
43 map (fn test => check_upto test 0 3) testers |
44 *} |
44 \<close> |
45 ML_val {* |
45 ML_val \<open> |
46 map (fn test => check_upto test 0 7) testers |
46 map (fn test => check_upto test 0 7) testers |
47 *} |
47 \<close> |
48 |
48 |
49 text {* Note that all conjectures must be executable to obtain the testers with the function above. *} |
49 text \<open>Note that all conjectures must be executable to obtain the testers with the function above.\<close> |
50 |
50 |
51 |
51 |
52 end |
52 end |