author | bulwahn |
Mon, 22 Nov 2010 14:19:03 +0100 | |
changeset 40660 | 86a1f61d260e |
parent 40655 | 5fb74f66efa4 |
child 40917 | c288fd2ead5a |
permissions | -rw-r--r-- |
14592 | 1 |
(* Title: HOL/ex/Quickcheck_Examples.thy |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
2 |
Author: Stefan Berghofer, Lukas Bulwahn |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
3 |
Copyright 2004 - 2010 TU Muenchen |
14592 | 4 |
*) |
5 |
||
6 |
header {* Examples for the 'quickcheck' command *} |
|
7 |
||
28314 | 8 |
theory Quickcheck_Examples |
9 |
imports Main |
|
10 |
begin |
|
14592 | 11 |
|
40660
86a1f61d260e
adding setup for exhaustive testing in example file
bulwahn
parents:
40655
diff
changeset
|
12 |
setup {* Smallvalue_Generators.setup *} |
86a1f61d260e
adding setup for exhaustive testing in example file
bulwahn
parents:
40655
diff
changeset
|
13 |
|
14592 | 14 |
text {* |
15 |
The 'quickcheck' command allows to find counterexamples by evaluating |
|
40654 | 16 |
formulae. |
17 |
Currently, there are two different exploration schemes: |
|
18 |
- random testing: this is incomplete, but explores the search space faster. |
|
19 |
- exhaustive testing: this is complete, but increasing the depth leads to |
|
20 |
exponentially many assignments. |
|
21 |
||
22 |
quickcheck can handle quantifiers on finite universes. |
|
23 |
||
14592 | 24 |
*} |
25 |
||
26 |
subsection {* Lists *} |
|
27 |
||
28 |
theorem "map g (map f xs) = map (g o f) xs" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
29 |
quickcheck[size = 3] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
30 |
quickcheck[generator = random, expect = no_counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
31 |
quickcheck[generator = small, size = 3, iterations = 1, report = false, expect = no_counterexample] |
14592 | 32 |
oops |
33 |
||
34 |
theorem "map g (map f xs) = map (f o g) xs" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
35 |
quickcheck[generator = random, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
36 |
quickcheck[generator = small, report = false] |
14592 | 37 |
oops |
38 |
||
39 |
theorem "rev (xs @ ys) = rev ys @ rev xs" |
|
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
40 |
quickcheck[expect = no_counterexample] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
41 |
quickcheck[generator = small, expect = no_counterexample, report = false] |
14592 | 42 |
oops |
43 |
||
44 |
theorem "rev (xs @ ys) = rev xs @ rev ys" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
45 |
quickcheck[generator = small, expect = counterexample, report = false] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
46 |
quickcheck[generator = random, expect = counterexample] |
14592 | 47 |
oops |
48 |
||
49 |
theorem "rev (rev xs) = xs" |
|
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
50 |
quickcheck[expect = no_counterexample] |
14592 | 51 |
oops |
52 |
||
53 |
theorem "rev xs = xs" |
|
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
54 |
quickcheck[generator = small, report = false] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
55 |
quickcheck[expect = counterexample] |
14592 | 56 |
oops |
57 |
||
25891 | 58 |
text {* An example involving functions inside other data structures *} |
59 |
||
28314 | 60 |
primrec app :: "('a \<Rightarrow> 'a) list \<Rightarrow> 'a \<Rightarrow> 'a" where |
25891 | 61 |
"app [] x = x" |
28314 | 62 |
| "app (f # fs) x = app fs (f x)" |
25891 | 63 |
|
64 |
lemma "app (fs @ gs) x = app gs (app fs x)" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
65 |
quickcheck[generator = random, expect = no_counterexample] |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
66 |
quickcheck[generator = small, iterations = 1, size = 4, report = false, expect = no_counterexample] |
25891 | 67 |
by (induct fs arbitrary: x) simp_all |
68 |
||
69 |
lemma "app (fs @ gs) x = app fs (app gs x)" |
|
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
70 |
quickcheck[generator = random, expect = counterexample] |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
71 |
quickcheck[generator = small, report = false, expect = counterexample] |
25891 | 72 |
oops |
73 |
||
28314 | 74 |
primrec occurs :: "'a \<Rightarrow> 'a list \<Rightarrow> nat" where |
14592 | 75 |
"occurs a [] = 0" |
28314 | 76 |
| "occurs a (x#xs) = (if (x=a) then Suc(occurs a xs) else occurs a xs)" |
14592 | 77 |
|
28314 | 78 |
primrec del1 :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list" where |
14592 | 79 |
"del1 a [] = []" |
28314 | 80 |
| "del1 a (x#xs) = (if (x=a) then xs else (x#del1 a xs))" |
14592 | 81 |
|
25891 | 82 |
text {* A lemma, you'd think to be true from our experience with delAll *} |
14592 | 83 |
lemma "Suc (occurs a (del1 a xs)) = occurs a xs" |
84 |
-- {* Wrong. Precondition needed.*} |
|
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
85 |
quickcheck[generator = small, report = false] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
86 |
quickcheck[expect = counterexample] |
14592 | 87 |
oops |
88 |
||
89 |
lemma "xs ~= [] \<longrightarrow> Suc (occurs a (del1 a xs)) = occurs a xs" |
|
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
90 |
quickcheck[generator = small, report = false] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
91 |
quickcheck[expect = counterexample] |
14592 | 92 |
-- {* Also wrong.*} |
93 |
oops |
|
94 |
||
95 |
lemma "0 < occurs a xs \<longrightarrow> Suc (occurs a (del1 a xs)) = occurs a xs" |
|
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
96 |
quickcheck[generator = small, report = false] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
97 |
quickcheck[expect = no_counterexample] |
28314 | 98 |
by (induct xs) auto |
14592 | 99 |
|
28314 | 100 |
primrec replace :: "'a \<Rightarrow> 'a \<Rightarrow> 'a list \<Rightarrow> 'a list" where |
14592 | 101 |
"replace a b [] = []" |
28314 | 102 |
| "replace a b (x#xs) = (if (x=a) then (b#(replace a b xs)) |
14592 | 103 |
else (x#(replace a b xs)))" |
104 |
||
105 |
lemma "occurs a xs = occurs b (replace a b xs)" |
|
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
106 |
quickcheck[generator = small, report = false] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
107 |
quickcheck[expect = counterexample] |
14592 | 108 |
-- {* Wrong. Precondition needed.*} |
109 |
oops |
|
110 |
||
111 |
lemma "occurs b xs = 0 \<or> a=b \<longrightarrow> occurs a xs = occurs b (replace a b xs)" |
|
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
112 |
quickcheck[expect = no_counterexample, report = false] |
28314 | 113 |
by (induct xs) simp_all |
14592 | 114 |
|
115 |
||
116 |
subsection {* Trees *} |
|
117 |
||
118 |
datatype 'a tree = Twig | Leaf 'a | Branch "'a tree" "'a tree" |
|
119 |
||
28314 | 120 |
primrec leaves :: "'a tree \<Rightarrow> 'a list" where |
14592 | 121 |
"leaves Twig = []" |
28314 | 122 |
| "leaves (Leaf a) = [a]" |
123 |
| "leaves (Branch l r) = (leaves l) @ (leaves r)" |
|
14592 | 124 |
|
28314 | 125 |
primrec plant :: "'a list \<Rightarrow> 'a tree" where |
14592 | 126 |
"plant [] = Twig " |
28314 | 127 |
| "plant (x#xs) = Branch (Leaf x) (plant xs)" |
14592 | 128 |
|
28314 | 129 |
primrec mirror :: "'a tree \<Rightarrow> 'a tree" where |
14592 | 130 |
"mirror (Twig) = Twig " |
28314 | 131 |
| "mirror (Leaf a) = Leaf a " |
132 |
| "mirror (Branch l r) = Branch (mirror r) (mirror l)" |
|
14592 | 133 |
|
134 |
theorem "plant (rev (leaves xt)) = mirror xt" |
|
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
135 |
quickcheck[expect = counterexample] |
14592 | 136 |
--{* Wrong! *} |
137 |
oops |
|
138 |
||
139 |
theorem "plant((leaves xt) @ (leaves yt)) = Branch xt yt" |
|
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
140 |
quickcheck[expect = counterexample] |
14592 | 141 |
--{* Wrong! *} |
142 |
oops |
|
143 |
||
144 |
datatype 'a ntree = Tip "'a" | Node "'a" "'a ntree" "'a ntree" |
|
145 |
||
28314 | 146 |
primrec inOrder :: "'a ntree \<Rightarrow> 'a list" where |
14592 | 147 |
"inOrder (Tip a)= [a]" |
28314 | 148 |
| "inOrder (Node f x y) = (inOrder x)@[f]@(inOrder y)" |
14592 | 149 |
|
28314 | 150 |
primrec root :: "'a ntree \<Rightarrow> 'a" where |
14592 | 151 |
"root (Tip a) = a" |
28314 | 152 |
| "root (Node f x y) = f" |
14592 | 153 |
|
28314 | 154 |
theorem "hd (inOrder xt) = root xt" |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
155 |
quickcheck[generator = small, report = false] |
37929
22e0797857e6
adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents:
37914
diff
changeset
|
156 |
quickcheck[expect = counterexample] |
14592 | 157 |
--{* Wrong! *} |
158 |
oops |
|
159 |
||
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
160 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
161 |
subsection {* Exhaustive Testing beats Random Testing *} |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
162 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
163 |
text {* Here are some examples from mutants from the List theory |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
164 |
where exhaustive testing beats random testing *} |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
165 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
166 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
167 |
"[] ~= xs ==> hd xs = last (x # xs)" |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
168 |
quickcheck[generator = random, report = false] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
169 |
quickcheck[generator = small, report = false, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
170 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
171 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
172 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
173 |
assumes "!!i. [| i < n; i < length xs |] ==> P (xs ! i)" "n < length xs ==> ~ P (xs ! n)" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
174 |
shows "drop n xs = takeWhile P xs" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
175 |
quickcheck[generator = random, iterations = 10000, report = false, quiet] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
176 |
quickcheck[generator = small, iterations = 1, report = false, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
177 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
178 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
179 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
180 |
"i < length (List.transpose (List.transpose xs)) ==> xs ! i = map (%xs. xs ! i) [ys<-xs. i < length ys]" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
181 |
quickcheck[generator = random, iterations = 10000, report = false, quiet] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
182 |
quickcheck[generator = small, iterations = 1, report = false, expect = counterexample] |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
183 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
184 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
185 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
186 |
"i < n - m ==> f (lcm m i) = map f [m..<n] ! i" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
187 |
quickcheck[generator = random, iterations = 10000, report = false, quiet] |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
188 |
quickcheck[generator = small, finite_types = false, report = false, expect = counterexample] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
189 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
190 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
191 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
192 |
"i < n - m ==> f (lcm m i) = map f [m..<n] ! i" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
193 |
quickcheck[generator = random, iterations = 1000, report = false, quiet] |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
194 |
quickcheck[generator = small, finite_types = false, report = false, expect = counterexample] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
195 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
196 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
197 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
198 |
"ns ! k < length ns ==> k <= listsum ns" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
199 |
quickcheck[generator = random, iterations = 10000, report = true, quiet] |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
200 |
quickcheck[generator = small, report = false, expect = counterexample] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
201 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
202 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
203 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
204 |
"[| ys = x # xs1; zs = xs1 @ xs |] ==> ys @ zs = x # xs" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
205 |
quickcheck[generator = random, iterations = 10000, report = true] |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
206 |
quickcheck[generator = small, report = false, expect = counterexample] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
207 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
208 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
209 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
210 |
"i < length xs ==> take (Suc i) xs = [] @ xs ! i # take i xs" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
211 |
quickcheck[generator = random] |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
212 |
quickcheck[generator = small, report = false, expect = counterexample] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
213 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
214 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
215 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
216 |
"i < length xs ==> take (Suc i) xs = (xs ! i # xs) @ take i []" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
217 |
quickcheck[generator = random] |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
218 |
quickcheck[generator = small, report = false, expect = counterexample] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
219 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
220 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
221 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
222 |
"[| sorted (rev (map length xs)); i < length xs |] ==> xs ! i = map (%ys. ys ! i) [ys<-remdups xs. i < length ys]" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
223 |
quickcheck[generator = random] |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
224 |
quickcheck[generator = small, report = false] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
225 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
226 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
227 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
228 |
"[| sorted (rev (map length xs)); i < length xs |] ==> xs ! i = map (%ys. ys ! i) [ys<-List.transpose xs. {..<i} (length ys)]" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
229 |
quickcheck[generator = random] |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
230 |
quickcheck[generator = small, report = false, expect = counterexample] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
231 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
232 |
|
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
233 |
lemma |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
234 |
"(ys = zs) = (xs @ ys = splice xs zs)" |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
235 |
quickcheck[generator = random] |
40655
5fb74f66efa4
adding temporary options to the quickcheck examples
bulwahn
parents:
40654
diff
changeset
|
236 |
quickcheck[generator = small, report = false, expect = counterexample] |
40645
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
237 |
oops |
03ce94672ee6
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents:
37929
diff
changeset
|
238 |
|
40654 | 239 |
section {* Examples with quantifiers *} |
240 |
||
241 |
text {* |
|
242 |
These examples show that we can handle quantifiers. |
|
243 |
*} |
|
244 |
||
245 |
lemma "(\<exists>x. P x) \<longrightarrow> (\<forall>x. P x)" |
|
246 |
quickcheck[expect = counterexample] |
|
247 |
oops |
|
248 |
||
249 |
lemma "(\<forall>x. \<exists>y. P x y) \<longrightarrow> (\<exists>y. \<forall>x. P x y)" |
|
250 |
quickcheck[expect = counterexample] |
|
251 |
oops |
|
252 |
||
253 |
lemma "(\<exists>x. P x) \<longrightarrow> (EX! x. P x)" |
|
254 |
quickcheck[expect = counterexample] |
|
255 |
oops |
|
256 |
||
14592 | 257 |
end |