--- a/src/HOL/ex/Quickcheck_Examples.thy Fri Dec 03 08:40:47 2010 +0100
+++ b/src/HOL/ex/Quickcheck_Examples.thy Fri Dec 03 08:40:47 2010 +0100
@@ -9,8 +9,6 @@
imports Main
begin
-setup {* Smallvalue_Generators.setup *}
-
text {*
The 'quickcheck' command allows to find counterexamples by evaluating
formulae.
@@ -26,33 +24,33 @@
subsection {* Lists *}
theorem "map g (map f xs) = map (g o f) xs"
- quickcheck[size = 3]
- quickcheck[generator = random, expect = no_counterexample]
- quickcheck[generator = small, size = 3, iterations = 1, report = false, expect = no_counterexample]
+ quickcheck[random, expect = no_counterexample]
+ quickcheck[exhaustive, size = 3, expect = no_counterexample]
oops
theorem "map g (map f xs) = map (f o g) xs"
- quickcheck[generator = random, expect = counterexample]
- quickcheck[generator = small, report = false]
+ quickcheck[random, expect = counterexample]
+ quickcheck[exhaustive, expect = counterexample]
oops
theorem "rev (xs @ ys) = rev ys @ rev xs"
- quickcheck[expect = no_counterexample]
- quickcheck[generator = small, expect = no_counterexample, report = false]
+ quickcheck[random, expect = no_counterexample]
+ quickcheck[exhaustive, expect = no_counterexample]
oops
theorem "rev (xs @ ys) = rev xs @ rev ys"
- quickcheck[generator = small, expect = counterexample, report = false]
- quickcheck[generator = random, expect = counterexample]
+ quickcheck[random, expect = counterexample]
+ quickcheck[exhaustive, expect = counterexample]
oops
theorem "rev (rev xs) = xs"
- quickcheck[expect = no_counterexample]
+ quickcheck[random, expect = no_counterexample]
+ quickcheck[exhaustive, expect = no_counterexample]
oops
theorem "rev xs = xs"
- quickcheck[generator = small, report = false]
- quickcheck[expect = counterexample]
+ quickcheck[random, expect = counterexample]
+ quickcheck[exhaustive, expect = counterexample]
oops
text {* An example involving functions inside other data structures *}
@@ -62,13 +60,13 @@
| "app (f # fs) x = app fs (f x)"
lemma "app (fs @ gs) x = app gs (app fs x)"
- quickcheck[generator = random, expect = no_counterexample]
- quickcheck[generator = small, iterations = 1, size = 4, report = false, expect = no_counterexample]
+ quickcheck[random, expect = no_counterexample]
+ quickcheck[exhaustive, size = 4, expect = no_counterexample]
by (induct fs arbitrary: x) simp_all
lemma "app (fs @ gs) x = app fs (app gs x)"
- quickcheck[generator = random, expect = counterexample]
- quickcheck[generator = small, report = false, expect = counterexample]
+ quickcheck[random, expect = counterexample]
+ quickcheck[exhaustive, expect = counterexample]
oops
primrec occurs :: "'a \<Rightarrow> 'a list \<Rightarrow> nat" where
@@ -82,19 +80,19 @@
text {* A lemma, you'd think to be true from our experience with delAll *}
lemma "Suc (occurs a (del1 a xs)) = occurs a xs"
-- {* Wrong. Precondition needed.*}
- quickcheck[generator = small, report = false]
- quickcheck[expect = counterexample]
+ quickcheck[random, expect = counterexample]
+ quickcheck[exhaustive, expect = counterexample]
oops
lemma "xs ~= [] \<longrightarrow> Suc (occurs a (del1 a xs)) = occurs a xs"
- quickcheck[generator = small, report = false]
- quickcheck[expect = counterexample]
+ quickcheck[random, expect = counterexample]
+ quickcheck[exhaustive, expect = counterexample]
-- {* Also wrong.*}
oops
lemma "0 < occurs a xs \<longrightarrow> Suc (occurs a (del1 a xs)) = occurs a xs"
- quickcheck[generator = small, report = false]
- quickcheck[expect = no_counterexample]
+ quickcheck[random, expect = no_counterexample]
+ quickcheck[exhaustive, expect = no_counterexample]
by (induct xs) auto
primrec replace :: "'a \<Rightarrow> 'a \<Rightarrow> 'a list \<Rightarrow> 'a list" where
@@ -103,13 +101,14 @@
else (x#(replace a b xs)))"
lemma "occurs a xs = occurs b (replace a b xs)"
- quickcheck[generator = small, report = false]
- quickcheck[expect = counterexample]
+ quickcheck[random, expect = counterexample]
+ quickcheck[exhaustive, expect = counterexample]
-- {* Wrong. Precondition needed.*}
oops
lemma "occurs b xs = 0 \<or> a=b \<longrightarrow> occurs a xs = occurs b (replace a b xs)"
- quickcheck[expect = no_counterexample, report = false]
+ quickcheck[random, expect = no_counterexample]
+ quickcheck[exhaustive, expect = no_counterexample]
by (induct xs) simp_all
@@ -132,12 +131,14 @@
| "mirror (Branch l r) = Branch (mirror r) (mirror l)"
theorem "plant (rev (leaves xt)) = mirror xt"
- quickcheck[expect = counterexample]
+ quickcheck[random, expect = counterexample]
+ quickcheck[exhaustive, expect = counterexample]
--{* Wrong! *}
oops
theorem "plant((leaves xt) @ (leaves yt)) = Branch xt yt"
- quickcheck[expect = counterexample]
+ quickcheck[random, expect = counterexample]
+ quickcheck[exhaustive, expect = counterexample]
--{* Wrong! *}
oops
@@ -152,9 +153,9 @@
| "root (Node f x y) = f"
theorem "hd (inOrder xt) = root xt"
- quickcheck[generator = small, report = false]
- quickcheck[expect = counterexample]
- --{* Wrong! *}
+ quickcheck[random, expect = counterexample]
+ quickcheck[exhaustive, expect = counterexample]
+ --{* Wrong! *}
oops
@@ -165,75 +166,75 @@
lemma
"[] ~= xs ==> hd xs = last (x # xs)"
-quickcheck[generator = random, report = false]
-quickcheck[generator = small, report = false, expect = counterexample]
+quickcheck[random]
+quickcheck[exhaustive, expect = counterexample]
oops
lemma
assumes "!!i. [| i < n; i < length xs |] ==> P (xs ! i)" "n < length xs ==> ~ P (xs ! n)"
shows "drop n xs = takeWhile P xs"
-quickcheck[generator = random, iterations = 10000, report = false, quiet]
-quickcheck[generator = small, iterations = 1, report = false, expect = counterexample]
+quickcheck[random, iterations = 10000, quiet]
+quickcheck[exhaustive, expect = counterexample]
oops
lemma
"i < length (List.transpose (List.transpose xs)) ==> xs ! i = map (%xs. xs ! i) [ys<-xs. i < length ys]"
-quickcheck[generator = random, iterations = 10000, report = false, quiet]
-quickcheck[generator = small, iterations = 1, report = false, expect = counterexample]
+quickcheck[random, iterations = 10000]
+quickcheck[exhaustive, expect = counterexample]
oops
lemma
"i < n - m ==> f (lcm m i) = map f [m..<n] ! i"
-quickcheck[generator = random, iterations = 10000, report = false, quiet]
-quickcheck[generator = small, finite_types = false, report = false, expect = counterexample]
+quickcheck[random, iterations = 10000, finite_types = false]
+quickcheck[exhaustive, finite_types = false, expect = counterexample]
oops
lemma
"i < n - m ==> f (lcm m i) = map f [m..<n] ! i"
-quickcheck[generator = random, iterations = 1000, report = false, quiet]
-quickcheck[generator = small, finite_types = false, report = false, expect = counterexample]
+quickcheck[random, iterations = 10000, finite_types = false]
+quickcheck[exhaustive, finite_types = false, expect = counterexample]
oops
lemma
"ns ! k < length ns ==> k <= listsum ns"
-quickcheck[generator = random, iterations = 10000, report = true, quiet]
-quickcheck[generator = small, report = false, expect = counterexample]
+quickcheck[random, iterations = 10000, finite_types = false, quiet]
+quickcheck[exhaustive, finite_types = false, expect = counterexample]
oops
lemma
"[| ys = x # xs1; zs = xs1 @ xs |] ==> ys @ zs = x # xs"
-quickcheck[generator = random, iterations = 10000, report = true]
-quickcheck[generator = small, report = false, expect = counterexample]
+quickcheck[random, iterations = 10000]
+quickcheck[exhaustive, expect = counterexample]
oops
lemma
"i < length xs ==> take (Suc i) xs = [] @ xs ! i # take i xs"
-quickcheck[generator = random]
-quickcheck[generator = small, report = false, expect = counterexample]
+quickcheck[random, iterations = 10000]
+quickcheck[exhaustive, expect = counterexample]
oops
lemma
"i < length xs ==> take (Suc i) xs = (xs ! i # xs) @ take i []"
-quickcheck[generator = random]
-quickcheck[generator = small, report = false, expect = counterexample]
+quickcheck[random, iterations = 10000]
+quickcheck[exhaustive, expect = counterexample]
oops
lemma
"[| sorted (rev (map length xs)); i < length xs |] ==> xs ! i = map (%ys. ys ! i) [ys<-remdups xs. i < length ys]"
-quickcheck[generator = random]
-quickcheck[generator = small, report = false]
+quickcheck[random]
+quickcheck[exhaustive, expect = counterexample]
oops
lemma
"[| sorted (rev (map length xs)); i < length xs |] ==> xs ! i = map (%ys. ys ! i) [ys<-List.transpose xs. {..<i} (length ys)]"
-quickcheck[generator = random]
-quickcheck[generator = small, report = false, expect = counterexample]
+quickcheck[random]
+quickcheck[exhaustive, expect = counterexample]
oops
lemma
"(ys = zs) = (xs @ ys = splice xs zs)"
-quickcheck[generator = random]
-quickcheck[generator = small, report = false, expect = counterexample]
+quickcheck[random]
+quickcheck[exhaustive, expect = counterexample]
oops
section {* Examples with quantifiers *}
@@ -243,14 +244,17 @@
*}
lemma "(\<exists>x. P x) \<longrightarrow> (\<forall>x. P x)"
- quickcheck[expect = counterexample]
+ quickcheck[random, expect = counterexample]
+ quickcheck[exhaustive, expect = counterexample]
oops
lemma "(\<forall>x. \<exists>y. P x y) \<longrightarrow> (\<exists>y. \<forall>x. P x y)"
+ quickcheck[random, expect = counterexample]
quickcheck[expect = counterexample]
oops
lemma "(\<exists>x. P x) \<longrightarrow> (EX! x. P x)"
+ quickcheck[random, expect = counterexample]
quickcheck[expect = counterexample]
oops