src/HOL/ex/Predicate_Compile_Quickcheck_ex.thy
author bulwahn
Fri, 06 Nov 2009 08:11:58 +0100
changeset 33475 42fed8eac357
parent 33405 5c1928d5db38
child 34948 2d5f2a9f7601
permissions -rw-r--r--
improved handling of overloaded constants; examples with numerals
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
33475
42fed8eac357 improved handling of overloaded constants; examples with numerals
bulwahn
parents: 33405
diff changeset
    12
(* TODO: some error with doubled negation *)
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
    13
lemma "x \<in> {Suc 0, Suc (Suc 0)} ==> x \<noteq> Suc 0"
33475
42fed8eac357 improved handling of overloaded constants; examples with numerals
bulwahn
parents: 33405
diff changeset
    14
(*quickcheck[generator=predicate_compile]*)
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
    15
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
    16
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
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
    18
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
    19
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
    20
 
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
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
    22
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
    23
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
    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
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
    26
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
lemma
33475
42fed8eac357 improved handling of overloaded constants; examples with numerals
bulwahn
parents: 33405
diff changeset
    28
  "x \<in> {1, 2, (3::nat)} ==> x = 1 \<or> x = 2"
42fed8eac357 improved handling of overloaded constants; examples with numerals
bulwahn
parents: 33405
diff changeset
    29
quickcheck[generator=predicate_compile]
42fed8eac357 improved handling of overloaded constants; examples with numerals
bulwahn
parents: 33405
diff changeset
    30
oops
42fed8eac357 improved handling of overloaded constants; examples with numerals
bulwahn
parents: 33405
diff changeset
    31
42fed8eac357 improved handling of overloaded constants; examples with numerals
bulwahn
parents: 33405
diff changeset
    32
lemma "x \<in> {1, 2, (3::nat)} ==> x < 3"
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
    33
(*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
    34
oops
33475
42fed8eac357 improved handling of overloaded constants; examples with numerals
bulwahn
parents: 33405
diff changeset
    35
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
    36
lemma
33475
42fed8eac357 improved handling of overloaded constants; examples with numerals
bulwahn
parents: 33405
diff changeset
    37
  "x \<in> {1, 2} \<union> {3, 4} ==> x = (1::nat) \<or> x = (2::nat)"
42fed8eac357 improved handling of overloaded constants; examples with numerals
bulwahn
parents: 33405
diff changeset
    38
quickcheck[generator=predicate_compile]
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
    39
oops
33257
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    40
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    41
section {* Context Free Grammar *}
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    42
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    43
datatype alphabet = a | b
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    44
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    45
inductive_set S\<^isub>1 and A\<^isub>1 and B\<^isub>1 where
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    46
  "[] \<in> S\<^isub>1"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    47
| "w \<in> A\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    48
| "w \<in> B\<^isub>1 \<Longrightarrow> a # w \<in> S\<^isub>1"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    49
| "w \<in> S\<^isub>1 \<Longrightarrow> a # w \<in> A\<^isub>1"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    50
| "w \<in> S\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    51
| "\<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
    52
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    53
theorem S\<^isub>1_sound:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    54
"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
    55
(*quickcheck[generator=predicate_compile, size=15]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    56
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    57
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    58
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    59
inductive_set S\<^isub>2 and A\<^isub>2 and B\<^isub>2 where
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    60
  "[] \<in> S\<^isub>2"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    61
| "w \<in> A\<^isub>2 \<Longrightarrow> b # w \<in> S\<^isub>2"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    62
| "w \<in> B\<^isub>2 \<Longrightarrow> a # w \<in> S\<^isub>2"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    63
| "w \<in> S\<^isub>2 \<Longrightarrow> a # w \<in> A\<^isub>2"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    64
| "w \<in> S\<^isub>2 \<Longrightarrow> b # w \<in> B\<^isub>2"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    65
| "\<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
    66
33375
fd3e861f8d31 renamed rpred to random
bulwahn
parents: 33257
diff changeset
    67
code_pred [inductify, random] S\<^isub>2 .
fd3e861f8d31 renamed rpred to random
bulwahn
parents: 33257
diff changeset
    68
thm S\<^isub>2.random_equation
fd3e861f8d31 renamed rpred to random
bulwahn
parents: 33257
diff changeset
    69
thm A\<^isub>2.random_equation
fd3e861f8d31 renamed rpred to random
bulwahn
parents: 33257
diff changeset
    70
thm B\<^isub>2.random_equation
33257
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    71
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    72
values [random] 10 "{x. S\<^isub>2 x}"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    73
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    74
lemma "w \<in> S\<^isub>2 ==> w \<noteq> [] ==> w \<noteq> [b, a] ==> w \<in> {}"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    75
quickcheck[generator=predicate_compile]
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    76
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    77
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    78
lemma "[x <- w. x = a] = []"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    79
quickcheck[generator=predicate_compile]
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    80
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    81
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    82
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    83
lemma "length ([x \<leftarrow> w. x = a]) = (0::nat)"
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
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    89
lemma
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    90
"w \<in> S\<^isub>2 ==> length [x \<leftarrow> w. x = a] < Suc (Suc 0)"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    91
(*quickcheck[generator=predicate_compile]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    92
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    93
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    94
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    95
theorem S\<^isub>2_sound:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    96
"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
    97
(*quickcheck[generator=predicate_compile, size=15, iterations=100]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    98
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
    99
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   100
inductive_set S\<^isub>3 and A\<^isub>3 and B\<^isub>3 where
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   101
  "[] \<in> S\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   102
| "w \<in> A\<^isub>3 \<Longrightarrow> b # w \<in> S\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   103
| "w \<in> B\<^isub>3 \<Longrightarrow> a # w \<in> S\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   104
| "w \<in> S\<^isub>3 \<Longrightarrow> a # w \<in> A\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   105
| "w \<in> S\<^isub>3 \<Longrightarrow> b # w \<in> B\<^isub>3"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   106
| "\<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
   107
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   108
code_pred [inductify] S\<^isub>3 .
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   109
thm S\<^isub>3.equation
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   110
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   111
values 10 "{x. S\<^isub>3 x}"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   112
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   113
lemma S\<^isub>3_sound:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   114
"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
   115
(*quickcheck[generator=predicate_compile, size=10, iterations=1]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   116
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   117
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   118
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   119
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
   120
(*quickcheck[size=10, generator = pred_compile]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   121
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   122
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   123
theorem S\<^isub>3_complete:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   124
"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
   125
(*quickcheck[generator=SML]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   126
(*quickcheck[generator=predicate_compile, size=10, iterations=100]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   127
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   128
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   129
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   130
inductive_set S\<^isub>4 and A\<^isub>4 and B\<^isub>4 where
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   131
  "[] \<in> S\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   132
| "w \<in> A\<^isub>4 \<Longrightarrow> b # w \<in> S\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   133
| "w \<in> B\<^isub>4 \<Longrightarrow> a # w \<in> S\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   134
| "w \<in> S\<^isub>4 \<Longrightarrow> a # w \<in> A\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   135
| "\<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
   136
| "w \<in> S\<^isub>4 \<Longrightarrow> b # w \<in> B\<^isub>4"
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   137
| "\<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
   138
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   139
theorem S\<^isub>4_sound:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   140
"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
   141
(*quickcheck[generator = predicate_compile, size=2, iterations=1]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   142
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   143
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   144
theorem S\<^isub>4_complete:
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   145
"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
   146
(*quickcheck[generator = pred_compile, size=5, iterations=1]*)
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   147
oops
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   148
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   149
95186fb5653c added examples for quickcheck prototype
bulwahn
parents:
diff changeset
   150
end