src/HOL/ex/Predicate_Compile_Quickcheck_ex.thy
author bulwahn
Tue, 03 Nov 2009 10:36:20 +0100
changeset 33405 5c1928d5db38
parent 33375 fd3e861f8d31
child 33475 42fed8eac357
permissions -rw-r--r--
adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33257
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
     1
theory Predicate_Compile_Quickcheck_ex
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
     2
imports Predicate_Compile_Quickcheck
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
     3
  Predicate_Compile_Alternative_Defs
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
     4
begin
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
     5
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
     6
section {* Sets *}
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
     7
33405
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
     8
lemma "x \<in> {(1::nat)} ==> False"
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
     9
quickcheck[generator=predicate_compile]
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    10
oops
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    11
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    12
lemma "x \<in> {Suc 0, Suc (Suc 0)} ==> x \<noteq> Suc 0"
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    13
oops
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    14
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    15
lemma "x \<in> {Suc 0, Suc (Suc 0)} ==> x = Suc 0"
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    16
quickcheck[generator=predicate_compile]
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    17
oops
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    18
 
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    19
lemma "x \<in> {Suc 0, Suc (Suc 0)} ==> x <= Suc 0"
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    20
quickcheck[generator=predicate_compile]
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    21
oops
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    22
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    23
section {* Numerals *}
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    24
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    25
lemma
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    26
  "x \<in> {1, 2, (3::nat)} ==> x < 3"
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    27
(*quickcheck[generator=predicate_compile]*)
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    28
oops
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    29
lemma
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    30
  "x \<in> {1, 2} \<union> {3, 4} ==> x > 4"
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    31
(*quickcheck[generator=predicate_compile]*)
5c1928d5db38 adding testcases for code inlining, sets and numerals to the example files of the predicate compiler and its quickcheck prototype; disabling length example
bulwahn
parents: 33375
diff changeset
    32
oops
33257
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    33
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    34
section {* Context Free Grammar *}
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    35
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    36
datatype alphabet = a | b
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    37
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    38
inductive_set S\<^isub>1 and A\<^isub>1 and B\<^isub>1 where
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    39
  "[] \<in> S\<^isub>1"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    40
| "w \<in> A\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    41
| "w \<in> B\<^isub>1 \<Longrightarrow> a # w \<in> S\<^isub>1"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    42
| "w \<in> S\<^isub>1 \<Longrightarrow> a # w \<in> A\<^isub>1"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    43
| "w \<in> S\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    44
| "\<lbrakk>v \<in> B\<^isub>1; v \<in> B\<^isub>1\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>1"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    45
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    46
theorem S\<^isub>1_sound:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    47
"w \<in> S\<^isub>1p \<Longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    48
(*quickcheck[generator=predicate_compile, size=15]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    49
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    50
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    51
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    52
inductive_set S\<^isub>2 and A\<^isub>2 and B\<^isub>2 where
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    53
  "[] \<in> S\<^isub>2"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    54
| "w \<in> A\<^isub>2 \<Longrightarrow> b # w \<in> S\<^isub>2"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    55
| "w \<in> B\<^isub>2 \<Longrightarrow> a # w \<in> S\<^isub>2"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    56
| "w \<in> S\<^isub>2 \<Longrightarrow> a # w \<in> A\<^isub>2"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    57
| "w \<in> S\<^isub>2 \<Longrightarrow> b # w \<in> B\<^isub>2"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    58
| "\<lbrakk>v \<in> B\<^isub>2; v \<in> B\<^isub>2\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>2"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    59
33375
fd3e861f8d31 renamed rpred to random
bulwahn
parents: 33257
diff changeset
    60
code_pred [inductify, random] S\<^isub>2 .
fd3e861f8d31 renamed rpred to random
bulwahn
parents: 33257
diff changeset
    61
thm S\<^isub>2.random_equation
fd3e861f8d31 renamed rpred to random
bulwahn
parents: 33257
diff changeset
    62
thm A\<^isub>2.random_equation
fd3e861f8d31 renamed rpred to random
bulwahn
parents: 33257
diff changeset
    63
thm B\<^isub>2.random_equation
33257
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    64
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    65
values [random] 10 "{x. S\<^isub>2 x}"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    66
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    67
lemma "w \<in> S\<^isub>2 ==> w \<noteq> [] ==> w \<noteq> [b, a] ==> w \<in> {}"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    68
quickcheck[generator=predicate_compile]
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    69
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    70
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    71
lemma "[x <- w. x = a] = []"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    72
quickcheck[generator=predicate_compile]
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    73
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    74
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    75
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    76
lemma "length ([x \<leftarrow> w. x = a]) = (0::nat)"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    77
(*quickcheck[generator=predicate_compile]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    78
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    79
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    80
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    81
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    82
lemma
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    83
"w \<in> S\<^isub>2 ==> length [x \<leftarrow> w. x = a] < Suc (Suc 0)"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    84
(*quickcheck[generator=predicate_compile]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    85
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    86
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    87
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    88
theorem S\<^isub>2_sound:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    89
"w \<in> S\<^isub>2 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    90
(*quickcheck[generator=predicate_compile, size=15, iterations=100]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    91
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    92
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    93
inductive_set S\<^isub>3 and A\<^isub>3 and B\<^isub>3 where
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    94
  "[] \<in> S\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    95
| "w \<in> A\<^isub>3 \<Longrightarrow> b # w \<in> S\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    96
| "w \<in> B\<^isub>3 \<Longrightarrow> a # w \<in> S\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    97
| "w \<in> S\<^isub>3 \<Longrightarrow> a # w \<in> A\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    98
| "w \<in> S\<^isub>3 \<Longrightarrow> b # w \<in> B\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    99
| "\<lbrakk>v \<in> B\<^isub>3; w \<in> B\<^isub>3\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   100
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   101
code_pred [inductify] S\<^isub>3 .
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   102
thm S\<^isub>3.equation
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   103
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   104
values 10 "{x. S\<^isub>3 x}"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   105
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   106
lemma S\<^isub>3_sound:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   107
"w \<in> S\<^isub>3 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   108
(*quickcheck[generator=predicate_compile, size=10, iterations=1]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   109
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   110
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   111
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   112
lemma "\<not> (length w > 2) \<or> \<not> (length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b])"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   113
(*quickcheck[size=10, generator = pred_compile]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   114
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   115
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   116
theorem S\<^isub>3_complete:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   117
"length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. b = x] \<longrightarrow> w \<in> S\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   118
(*quickcheck[generator=SML]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   119
(*quickcheck[generator=predicate_compile, size=10, iterations=100]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   120
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   121
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   122
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   123
inductive_set S\<^isub>4 and A\<^isub>4 and B\<^isub>4 where
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   124
  "[] \<in> S\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   125
| "w \<in> A\<^isub>4 \<Longrightarrow> b # w \<in> S\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   126
| "w \<in> B\<^isub>4 \<Longrightarrow> a # w \<in> S\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   127
| "w \<in> S\<^isub>4 \<Longrightarrow> a # w \<in> A\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   128
| "\<lbrakk>v \<in> A\<^isub>4; w \<in> A\<^isub>4\<rbrakk> \<Longrightarrow> b # v @ w \<in> A\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   129
| "w \<in> S\<^isub>4 \<Longrightarrow> b # w \<in> B\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   130
| "\<lbrakk>v \<in> B\<^isub>4; w \<in> B\<^isub>4\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   131
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   132
theorem S\<^isub>4_sound:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   133
"w \<in> S\<^isub>4 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   134
(*quickcheck[generator = predicate_compile, size=2, iterations=1]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   135
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   136
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   137
theorem S\<^isub>4_complete:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   138
"length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   139
(*quickcheck[generator = pred_compile, size=5, iterations=1]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   140
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   141
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   142
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   143
end