src/HOL/ex/Quickcheck_Examples.thy
author bulwahn
Mon, 22 Nov 2010 11:34:50 +0100
changeset 40645 03ce94672ee6
parent 37929 22e0797857e6
child 40654 a716071ec306
permissions -rw-r--r--
adding test cases for smallcheck and adding examples where exhaustive testing is more successful
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
     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
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
     4
*)
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
     5
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
     6
header {* Examples for the 'quickcheck' command *}
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
     7
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
     8
theory Quickcheck_Examples
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
     9
imports Main
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
    10
begin
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    11
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    12
text {*
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    13
The 'quickcheck' command allows to find counterexamples by evaluating
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    14
formulae under an assignment of free variables to random values.
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    15
In contrast to 'refute', it can deal with inductive datatypes,
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    16
but cannot handle quantifiers.
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    17
*}
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    18
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    19
subsection {* Lists *}
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    20
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    21
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
    22
  quickcheck[size = 3]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
    23
  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
    24
  quickcheck[generator = small, size = 3, iterations = 1, report = false, expect = no_counterexample]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    25
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    26
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    27
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
    28
  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
    29
  quickcheck[generator = small, report = false]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    30
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    31
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    32
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
    33
  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
    34
  quickcheck[generator = small, expect = no_counterexample, report = false]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    35
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    36
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    37
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
    38
  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
    39
  quickcheck[generator = random, expect = counterexample]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    40
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    41
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    42
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
    43
  quickcheck[expect = no_counterexample]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    44
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    45
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    46
theorem "rev xs = xs"
40645
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
    47
  quickcheck[generator = small]
37929
22e0797857e6 adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents: 37914
diff changeset
    48
  quickcheck[expect = counterexample]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    49
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    50
25891
1bd12187a96e New example involving functions.
berghofe
parents: 17388
diff changeset
    51
text {* An example involving functions inside other data structures *}
1bd12187a96e New example involving functions.
berghofe
parents: 17388
diff changeset
    52
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
    53
primrec app :: "('a \<Rightarrow> 'a) list \<Rightarrow> 'a \<Rightarrow> 'a" where
25891
1bd12187a96e New example involving functions.
berghofe
parents: 17388
diff changeset
    54
  "app [] x = x"
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
    55
  | "app (f # fs) x = app fs (f x)"
25891
1bd12187a96e New example involving functions.
berghofe
parents: 17388
diff changeset
    56
1bd12187a96e New example involving functions.
berghofe
parents: 17388
diff changeset
    57
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
    58
  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
    59
  quickcheck[generator = small, iterations = 1, size = 4, expect = no_counterexample]
25891
1bd12187a96e New example involving functions.
berghofe
parents: 17388
diff changeset
    60
  by (induct fs arbitrary: x) simp_all
1bd12187a96e New example involving functions.
berghofe
parents: 17388
diff changeset
    61
1bd12187a96e New example involving functions.
berghofe
parents: 17388
diff changeset
    62
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
    63
  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
    64
  quickcheck[generator = small, expect = counterexample]
25891
1bd12187a96e New example involving functions.
berghofe
parents: 17388
diff changeset
    65
  oops
1bd12187a96e New example involving functions.
berghofe
parents: 17388
diff changeset
    66
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
    67
primrec occurs :: "'a \<Rightarrow> 'a list \<Rightarrow> nat" where
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    68
  "occurs a [] = 0"
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
    69
  | "occurs a (x#xs) = (if (x=a) then Suc(occurs a xs) else occurs a xs)"
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    70
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
    71
primrec del1 :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list" where
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    72
  "del1 a [] = []"
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
    73
  | "del1 a (x#xs) = (if (x=a) then xs else (x#del1 a xs))"
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    74
25891
1bd12187a96e New example involving functions.
berghofe
parents: 17388
diff changeset
    75
text {* A lemma, you'd think to be true from our experience with delAll *}
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    76
lemma "Suc (occurs a (del1 a xs)) = occurs a xs"
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    77
  -- {* Wrong. Precondition needed.*}
40645
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
    78
  quickcheck[generator = small]
37929
22e0797857e6 adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents: 37914
diff changeset
    79
  quickcheck[expect = counterexample]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    80
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    81
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    82
lemma "xs ~= [] \<longrightarrow> Suc (occurs a (del1 a xs)) = occurs a xs"
40645
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
    83
  quickcheck[generator = small]
37929
22e0797857e6 adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents: 37914
diff changeset
    84
  quickcheck[expect = counterexample]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    85
    -- {* Also wrong.*}
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    86
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    87
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    88
lemma "0 < occurs a xs \<longrightarrow> Suc (occurs a (del1 a xs)) = occurs a xs"
40645
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
    89
  quickcheck[generator = small]
37929
22e0797857e6 adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents: 37914
diff changeset
    90
  quickcheck[expect = no_counterexample]
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
    91
  by (induct xs) auto
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    92
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
    93
primrec replace :: "'a \<Rightarrow> 'a \<Rightarrow> 'a list \<Rightarrow> 'a list" where
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    94
  "replace a b [] = []"
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
    95
  | "replace a b (x#xs) = (if (x=a) then (b#(replace a b xs)) 
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    96
                            else (x#(replace a b xs)))"
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    97
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
    98
lemma "occurs a xs = occurs b (replace a b xs)"
40645
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
    99
  quickcheck[generator = small]
37929
22e0797857e6 adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents: 37914
diff changeset
   100
  quickcheck[expect = counterexample]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   101
  -- {* Wrong. Precondition needed.*}
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   102
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   103
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   104
lemma "occurs b xs = 0 \<or> a=b \<longrightarrow> occurs a xs = occurs b (replace a b xs)"
37929
22e0797857e6 adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents: 37914
diff changeset
   105
  quickcheck[expect = no_counterexample]
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   106
  by (induct xs) simp_all
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   107
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   108
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   109
subsection {* Trees *}
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   110
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   111
datatype 'a tree = Twig |  Leaf 'a | Branch "'a tree" "'a tree"
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   112
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   113
primrec leaves :: "'a tree \<Rightarrow> 'a list" where
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   114
  "leaves Twig = []"
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   115
  | "leaves (Leaf a) = [a]"
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   116
  | "leaves (Branch l r) = (leaves l) @ (leaves r)"
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   117
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   118
primrec plant :: "'a list \<Rightarrow> 'a tree" where
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   119
  "plant [] = Twig "
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   120
  | "plant (x#xs) = Branch (Leaf x) (plant xs)"
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   121
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   122
primrec mirror :: "'a tree \<Rightarrow> 'a tree" where
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   123
  "mirror (Twig) = Twig "
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   124
  | "mirror (Leaf a) = Leaf a "
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   125
  | "mirror (Branch l r) = Branch (mirror r) (mirror l)"
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   126
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   127
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
   128
  quickcheck[expect = counterexample]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   129
    --{* Wrong! *} 
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   130
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   131
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   132
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
   133
  quickcheck[expect = counterexample]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   134
    --{* Wrong! *} 
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   135
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   136
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   137
datatype 'a ntree = Tip "'a" | Node "'a" "'a ntree" "'a ntree"
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   138
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   139
primrec inOrder :: "'a ntree \<Rightarrow> 'a list" where
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   140
  "inOrder (Tip a)= [a]"
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   141
  | "inOrder (Node f x y) = (inOrder x)@[f]@(inOrder y)"
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   142
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   143
primrec root :: "'a ntree \<Rightarrow> 'a" where
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   144
  "root (Tip a) = a"
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   145
  | "root (Node f x y) = f"
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   146
28314
053419cefd3c TEMPORARY: make batch run happy
haftmann
parents: 25891
diff changeset
   147
theorem "hd (inOrder xt) = root xt"
40645
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   148
  quickcheck[generator = small]
37929
22e0797857e6 adding checking of expected result for the tool quickcheck; annotated a few quickcheck examples
bulwahn
parents: 37914
diff changeset
   149
  quickcheck[expect = counterexample]
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   150
    --{* Wrong! *} 
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   151
  oops
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   152
40645
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   153
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   154
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
   155
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   156
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
   157
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
   158
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   159
lemma
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   160
  "[] ~= xs ==> hd xs = last (x # xs)"
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   161
quickcheck[generator = random]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   162
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
   163
oops
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   164
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   165
lemma
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   166
  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
   167
  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
   168
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
   169
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
   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
  "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
   174
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
   175
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
   176
oops
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   177
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   178
lemma
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   179
  "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
   180
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
   181
quickcheck[generator = small, expect = counterexample]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   182
oops
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   183
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   184
lemma
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   185
  "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
   186
quickcheck[generator = random, iterations = 1000, report = false, quiet]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   187
quickcheck[generator = small, expect = counterexample]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   188
oops
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   189
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   190
lemma
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   191
  "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
   192
quickcheck[generator = random, iterations = 10000, report = true, quiet]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   193
quickcheck[generator = small, expect = counterexample]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   194
oops
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   195
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   196
lemma
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   197
  "[| 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
   198
quickcheck[generator = random, iterations = 10000, report = true]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   199
quickcheck[generator = small, expect = counterexample]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   200
oops
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   201
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   202
lemma
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   203
"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
   204
quickcheck[generator = random]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   205
quickcheck[generator = small, expect = counterexample]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   206
oops
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   207
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   208
lemma
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   209
  "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
   210
quickcheck[generator = random]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   211
quickcheck[generator = small, expect = counterexample]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   212
oops
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   213
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   214
lemma
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   215
  "[| 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
   216
quickcheck[generator = random]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   217
quickcheck[generator = small]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   218
oops
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   219
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   220
lemma
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   221
  "[| 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
   222
quickcheck[generator = random]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   223
quickcheck[generator = small, expect = counterexample]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   224
oops
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   225
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   226
lemma
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   227
  "(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
   228
quickcheck[generator = random]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   229
quickcheck[generator = small, expect = counterexample]
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   230
oops
03ce94672ee6 adding test cases for smallcheck and adding examples where exhaustive testing is more successful
bulwahn
parents: 37929
diff changeset
   231
14592
dd1a2905ea73 Added theory with examples for quickcheck command.
berghofe
parents:
diff changeset
   232
end