author  bulwahn 
Fri, 08 Apr 2011 16:31:14 +0200  
changeset 42304  34366f39d32d 
parent 42274  50850486f8dc 
child 42305  494c31fdec95 
permissions  rwrr 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

1 
(* Author: Lukas Bulwahn, TU Muenchen *) 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

2 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

3 
header {* A simple counterexample generator performing exhaustive testing *} 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

4 

41918  5 
theory Quickcheck_Exhaustive 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

6 
imports Quickcheck 
41920
d4fb7a418152
moving exhaustive_generators.ML to Quickcheck directory
bulwahn
parents:
41918
diff
changeset

7 
uses ("Tools/Quickcheck/exhaustive_generators.ML") 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

8 
begin 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

9 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

10 
subsection {* basic operations for exhaustive generators *} 
41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

11 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

12 
definition orelse :: "'a option => 'a option => 'a option" (infixr "orelse" 55) 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

13 
where 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

14 
[code_unfold]: "x orelse y = (case x of Some x' => Some x'  None => y)" 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

15 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

16 
subsection {* exhaustive generator type classes *} 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

17 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

18 
class exhaustive = term_of + 
42304  19 
fixes exhaustive :: "('a \<Rightarrow> term list option) \<Rightarrow> code_numeral \<Rightarrow> term list option" 
20 
fixes full_exhaustive :: "('a * (unit => term) \<Rightarrow> term list option) \<Rightarrow> code_numeral \<Rightarrow> term list option" 

40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

21 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

22 
instantiation code_numeral :: exhaustive 
40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

23 
begin 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

24 

42304  25 
function full_exhaustive_code_numeral' :: "(code_numeral * (unit => term) => term list option) => code_numeral => code_numeral => term list option" 
26 
where "full_exhaustive_code_numeral' f d i = 

27 
(if d < i then None 

28 
else (f (i, %_. Code_Evaluation.term_of i)) orelse (full_exhaustive_code_numeral' f d (i + 1)))" 

29 
by pat_completeness auto 

30 

31 
termination 

32 
by (relation "measure (%(_, d, i). Code_Numeral.nat_of (d + 1  i))") auto 

33 

34 
definition "full_exhaustive f d = full_exhaustive_code_numeral' f d 0" 

35 

36 
function exhaustive_code_numeral' :: "(code_numeral => term list option) => code_numeral => code_numeral => term list option" 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

37 
where "exhaustive_code_numeral' f d i = 
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

38 
(if d < i then None 
42304  39 
else (f i orelse exhaustive_code_numeral' f d (i + 1)))" 
41231
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

40 
by pat_completeness auto 
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

41 

42304  42 
termination 
41231
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

43 
by (relation "measure (%(_, d, i). Code_Numeral.nat_of (d + 1  i))") auto 
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

44 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

45 
definition "exhaustive f d = exhaustive_code_numeral' f d 0" 
41231
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

46 

42304  47 

41231
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

48 
instance .. 
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

49 

2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

50 
end 
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

51 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

52 
instantiation nat :: exhaustive 
41231
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

53 
begin 
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

54 

42304  55 
definition "exhaustive f d = exhaustive (%x. f (Code_Numeral.nat_of x)) d" 
56 

57 
definition "full_exhaustive f d = full_exhaustive (%(x, xt). f (Code_Numeral.nat_of x, %_. Code_Evaluation.term_of (Code_Numeral.nat_of x))) d" 

41231
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

58 

2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

59 
instance .. 
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

60 

2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

61 
end 
2e901158675e
adding exhaustive tester instances for numeric types: code_numeral, nat, rat and real
bulwahn
parents:
41178
diff
changeset

62 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

63 
instantiation int :: exhaustive 
40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

64 
begin 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

65 

42304  66 
function exhaustive' :: "(int => term list option) => int => int => term list option" 
67 
where "exhaustive' f d i = (if d < i then None else (f i orelse exhaustive' f d (i + 1)))" 

40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

68 
by pat_completeness auto 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

69 

f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

70 
termination 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

71 
by (relation "measure (%(_, d, i). nat (d + 1  i))") auto 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

72 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

73 
definition "exhaustive f d = exhaustive' f (Code_Numeral.int_of d) ( (Code_Numeral.int_of d))" 
40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

74 

42304  75 
function full_exhaustive' :: "(int * (unit => term) => term list option) => int => int => term list option" 
76 
where "full_exhaustive' f d i = (if d < i then None else (case f (i, %_. Code_Evaluation.term_of i) of Some t => Some t  None => full_exhaustive' f d (i + 1)))" 

77 
by pat_completeness auto 

78 

79 
termination 

80 
by (relation "measure (%(_, d, i). nat (d + 1  i))") auto 

81 

82 
definition "full_exhaustive f d = full_exhaustive' f (Code_Numeral.int_of d) ( (Code_Numeral.int_of d))" 

83 

40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

84 
instance .. 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

85 

f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

86 
end 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

87 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

88 
instantiation prod :: (exhaustive, exhaustive) exhaustive 
40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

89 
begin 
40899
ef6fde932f4c
improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents:
40639
diff
changeset

90 

40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

91 
definition 
42304  92 
"exhaustive f d = exhaustive (%x. exhaustive (%y. f ((x, y))) d) d" 
93 

94 
definition 

95 
"full_exhaustive f d = full_exhaustive (%(x, t1). full_exhaustive (%(y, t2). f ((x, y), 

41719
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

96 
%u. let T1 = (Typerep.typerep (TYPE('a))); 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

97 
T2 = (Typerep.typerep (TYPE('b))) 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

98 
in Code_Evaluation.App (Code_Evaluation.App ( 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

99 
Code_Evaluation.Const (STR ''Product_Type.Pair'') 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

100 
(Typerep.Typerep (STR ''fun'') [T1, Typerep.Typerep (STR ''fun'') [T2, Typerep.Typerep (STR ''Product_Type.prod'') [T1, T2]]])) 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

101 
(t1 ())) (t2 ()))) d) d" 
40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

102 

f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

103 
instance .. 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

104 

f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

105 
end 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

106 

41916
80060d5f864a
renaming constants in Quickcheck_Exhaustive theory
bulwahn
parents:
41915
diff
changeset

107 
instantiation "fun" :: ("{equal, exhaustive}", exhaustive) exhaustive 
40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

108 
begin 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

109 

42304  110 
fun exhaustive_fun' :: "(('a => 'b) => term list option) => code_numeral => code_numeral => term list option" 
111 
where 

112 
"exhaustive_fun' f i d = (exhaustive (%b. f (%_. b)) d) 

113 
orelse (if i > 1 then 

114 
exhaustive_fun' (%g. exhaustive (%a. exhaustive (%b. 

115 
f (g(a := b))) d) d) (i  1) d else None)" 

116 

117 
definition exhaustive_fun :: "(('a => 'b) => term list option) => code_numeral => term list option" 

40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

118 
where 
42304  119 
"exhaustive_fun f d = exhaustive_fun' f d d" 
120 

121 

122 
fun full_exhaustive_fun' :: "(('a => 'b) * (unit => term) => term list option) => code_numeral => code_numeral => term list option" 

123 
where 

124 
"full_exhaustive_fun' f i d = (full_exhaustive (%(b, t). f (%_. b, %_. Code_Evaluation.Abs (STR ''x'') (Typerep.typerep TYPE('a)) (t ()))) d) 

42117
306713ec55c3
changing iteration scheme of functions to use minimal number of function updates for exhaustive testing
bulwahn
parents:
41920
diff
changeset

125 
orelse (if i > 1 then 
42304  126 
full_exhaustive_fun' (%(g, gt). full_exhaustive (%(a, at). full_exhaustive (%(b, bt). 
42117
306713ec55c3
changing iteration scheme of functions to use minimal number of function updates for exhaustive testing
bulwahn
parents:
41920
diff
changeset

127 
f (g(a := b), 
306713ec55c3
changing iteration scheme of functions to use minimal number of function updates for exhaustive testing
bulwahn
parents:
41920
diff
changeset

128 
(%_. let A = (Typerep.typerep (TYPE('a))); 
306713ec55c3
changing iteration scheme of functions to use minimal number of function updates for exhaustive testing
bulwahn
parents:
41920
diff
changeset

129 
B = (Typerep.typerep (TYPE('b))); 
306713ec55c3
changing iteration scheme of functions to use minimal number of function updates for exhaustive testing
bulwahn
parents:
41920
diff
changeset

130 
fun = (%T U. Typerep.Typerep (STR ''fun'') [T, U]) 
306713ec55c3
changing iteration scheme of functions to use minimal number of function updates for exhaustive testing
bulwahn
parents:
41920
diff
changeset

131 
in 
306713ec55c3
changing iteration scheme of functions to use minimal number of function updates for exhaustive testing
bulwahn
parents:
41920
diff
changeset

132 
Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.App 
306713ec55c3
changing iteration scheme of functions to use minimal number of function updates for exhaustive testing
bulwahn
parents:
41920
diff
changeset

133 
(Code_Evaluation.Const (STR ''Fun.fun_upd'') (fun (fun A B) (fun A (fun B (fun A B))))) 
306713ec55c3
changing iteration scheme of functions to use minimal number of function updates for exhaustive testing
bulwahn
parents:
41920
diff
changeset

134 
(gt ())) (at ())) (bt ())))) d) d) (i  1) d else None)" 
40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

135 

42304  136 
definition full_exhaustive_fun :: "(('a => 'b) * (unit => term) => term list option) => code_numeral => term list option" 
40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

137 
where 
42304  138 
"full_exhaustive_fun f d = full_exhaustive_fun' f d d" 
40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

139 

f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

140 
instance .. 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

141 

f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

142 
end 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

143 

41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

144 
subsubsection {* A smarter enumeration scheme for functions over finite datatypes *} 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

145 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

146 
class check_all = enum + term_of + 
41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

147 
fixes check_all :: "('a * (unit \<Rightarrow> term) \<Rightarrow> term list option) \<Rightarrow> term list option" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

148 
fixes enum_term_of :: "'a itself \<Rightarrow> unit \<Rightarrow> term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

149 

41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

150 
fun check_all_n_lists :: "(('a :: check_all) list * (unit \<Rightarrow> term list) \<Rightarrow> term list option) \<Rightarrow> code_numeral \<Rightarrow> term list option" 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

151 
where 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

152 
"check_all_n_lists f n = 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

153 
(if n = 0 then f ([], (%_. [])) else check_all (%(x, xt). check_all_n_lists (%(xs, xst). f ((x # xs), (%_. (xt () # xst ())))) (n  1)))" 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

154 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

155 
definition mk_map_term :: " (unit \<Rightarrow> typerep) \<Rightarrow> (unit \<Rightarrow> typerep) \<Rightarrow> (unit \<Rightarrow> term list) \<Rightarrow> (unit \<Rightarrow> term list) \<Rightarrow> unit \<Rightarrow> term" 
41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

156 
where 
41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

157 
"mk_map_term T1 T2 domm rng = 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

158 
(%_. let T1 = T1 (); 
41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

159 
T2 = T2 (); 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

160 
update_term = (%g (a, b). 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

161 
Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.App 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

162 
(Code_Evaluation.Const (STR ''Fun.fun_upd'') 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

163 
(Typerep.Typerep (STR ''fun'') [Typerep.Typerep (STR ''fun'') [T1, T2], 
41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

164 
Typerep.Typerep (STR ''fun'') [T1, 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

165 
Typerep.Typerep (STR ''fun'') [T2, Typerep.Typerep (STR ''fun'') [T1, T2]]]])) 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

166 
g) a) b) 
41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

167 
in 
41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

168 
List.foldl update_term (Code_Evaluation.Abs (STR ''x'') T1 (Code_Evaluation.Const (STR ''HOL.undefined'') T2)) (zip (domm ()) (rng ())))" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

169 

810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

170 
instantiation "fun" :: ("{equal, check_all}", check_all) check_all 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

171 
begin 
41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

172 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

173 
definition 
41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

174 
"check_all f = 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

175 
(let 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

176 
mk_term = mk_map_term (%_. Typerep.typerep (TYPE('a))) (%_. Typerep.typerep (TYPE('b))) (enum_term_of (TYPE('a))); 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

177 
enum = (Enum.enum :: 'a list) 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

178 
in check_all_n_lists (\<lambda>(ys, yst). f (the o map_of (zip enum ys), mk_term yst)) (Code_Numeral.of_nat (length enum)))" 
41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

179 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

180 
definition enum_term_of_fun :: "('a => 'b) itself => unit => term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

181 
where 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

182 
"enum_term_of_fun = (%_ _. let 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

183 
enum_term_of_a = enum_term_of (TYPE('a)); 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

184 
mk_term = mk_map_term (%_. Typerep.typerep (TYPE('a))) (%_. Typerep.typerep (TYPE('b))) enum_term_of_a 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

185 
in map (%ys. mk_term (%_. ys) ()) (Enum.n_lists (length (enum_term_of_a ())) (enum_term_of (TYPE('b)) ())))" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

186 

41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

187 
instance .. 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

188 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

189 
end 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

190 

41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

191 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

192 
instantiation unit :: check_all 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

193 
begin 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

194 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

195 
definition 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

196 
"check_all f = f (Code_Evaluation.valtermify ())" 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

197 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

198 
definition enum_term_of_unit :: "unit itself => unit => term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

199 
where 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

200 
"enum_term_of_unit = (%_ _. [Code_Evaluation.term_of ()])" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

201 

41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

202 
instance .. 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

203 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

204 
end 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

205 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

206 

41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

207 
instantiation bool :: check_all 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

208 
begin 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

209 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

210 
definition 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

211 
"check_all f = (case f (Code_Evaluation.valtermify False) of Some x' \<Rightarrow> Some x'  None \<Rightarrow> f (Code_Evaluation.valtermify True))" 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

212 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

213 
definition enum_term_of_bool :: "bool itself => unit => term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

214 
where 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

215 
"enum_term_of_bool = (%_ _. map Code_Evaluation.term_of (Enum.enum :: bool list))" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

216 

41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

217 
instance .. 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

218 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

219 
end 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

220 

41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

221 

41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

222 
instantiation prod :: (check_all, check_all) check_all 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

223 
begin 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

224 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

225 
definition 
41719
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

226 
"check_all f = check_all (%(x, t1). check_all (%(y, t2). f ((x, y), 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

227 
%u. let T1 = (Typerep.typerep (TYPE('a))); 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

228 
T2 = (Typerep.typerep (TYPE('b))) 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

229 
in Code_Evaluation.App (Code_Evaluation.App ( 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

230 
Code_Evaluation.Const (STR ''Product_Type.Pair'') 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

231 
(Typerep.Typerep (STR ''fun'') [T1, Typerep.Typerep (STR ''fun'') [T2, Typerep.Typerep (STR ''Product_Type.prod'') [T1, T2]]])) 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

232 
(t1 ())) (t2 ()))))" 
41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

233 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

234 
definition enum_term_of_prod :: "('a * 'b) itself => unit => term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

235 
where 
41719
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

236 
"enum_term_of_prod = (%_ _. map (%(x, y). 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

237 
let T1 = (Typerep.typerep (TYPE('a))); 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

238 
T2 = (Typerep.typerep (TYPE('b))) 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

239 
in Code_Evaluation.App (Code_Evaluation.App ( 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

240 
Code_Evaluation.Const (STR ''Product_Type.Pair'') 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

241 
(Typerep.Typerep (STR ''fun'') [T1, Typerep.Typerep (STR ''fun'') [T2, Typerep.Typerep (STR ''Product_Type.prod'') [T1, T2]]])) x) y) 
91c2510e19c5
improving term construction of product types in Smallcheck which enables correct presentation of counterexamples
bulwahn
parents:
41231
diff
changeset

242 
(Enum.product (enum_term_of (TYPE('a)) ()) (enum_term_of (TYPE('b)) ()))) " 
41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

243 

41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

244 
instance .. 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

245 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

246 
end 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

247 

41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

248 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

249 
instantiation sum :: (check_all, check_all) check_all 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

250 
begin 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

251 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

252 
definition 
41722
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

253 
"check_all f = (case check_all (%(a, t). f (Inl a, %_. 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

254 
let T1 = (Typerep.typerep (TYPE('a))); 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

255 
T2 = (Typerep.typerep (TYPE('b))) 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

256 
in Code_Evaluation.App (Code_Evaluation.Const (STR ''Sum_Type.Inl'') 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

257 
(Typerep.Typerep (STR ''fun'') [T1, Typerep.Typerep (STR ''Sum_Type.sum'') [T1, T2]])) (t ()))) of Some x' => Some x' 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

258 
 None => check_all (%(b, t). f (Inr b, %_. let 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

259 
T1 = (Typerep.typerep (TYPE('a))); 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

260 
T2 = (Typerep.typerep (TYPE('b))) 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

261 
in Code_Evaluation.App (Code_Evaluation.Const (STR ''Sum_Type.Inr'') 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

262 
(Typerep.Typerep (STR ''fun'') [T2, Typerep.Typerep (STR ''Sum_Type.sum'') [T1, T2]])) (t ()))))" 
41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

263 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

264 
definition enum_term_of_sum :: "('a + 'b) itself => unit => term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

265 
where 
41722
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

266 
"enum_term_of_sum = (%_ _. 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

267 
let 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

268 
T1 = (Typerep.typerep (TYPE('a))); 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

269 
T2 = (Typerep.typerep (TYPE('b))) 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

270 
in 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

271 
map (Code_Evaluation.App (Code_Evaluation.Const (STR ''Sum_Type.Inl'') 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

272 
(Typerep.Typerep (STR ''fun'') [T1, Typerep.Typerep (STR ''Sum_Type.sum'') [T1, T2]]))) 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

273 
(enum_term_of (TYPE('a)) ()) @ 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

274 
map (Code_Evaluation.App (Code_Evaluation.Const (STR ''Sum_Type.Inr'') 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

275 
(Typerep.Typerep (STR ''fun'') [T2, Typerep.Typerep (STR ''Sum_Type.sum'') [T1, T2]]))) 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

276 
(enum_term_of (TYPE('b)) ()))" 
41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

277 

41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

278 
instance .. 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

279 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

280 
end 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

281 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

282 
instantiation nibble :: check_all 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

283 
begin 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

284 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

285 
definition 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

286 
"check_all f = 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

287 
f (Code_Evaluation.valtermify Nibble0) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

288 
f (Code_Evaluation.valtermify Nibble1) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

289 
f (Code_Evaluation.valtermify Nibble2) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

290 
f (Code_Evaluation.valtermify Nibble3) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

291 
f (Code_Evaluation.valtermify Nibble4) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

292 
f (Code_Evaluation.valtermify Nibble5) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

293 
f (Code_Evaluation.valtermify Nibble6) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

294 
f (Code_Evaluation.valtermify Nibble7) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

295 
f (Code_Evaluation.valtermify Nibble8) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

296 
f (Code_Evaluation.valtermify Nibble9) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

297 
f (Code_Evaluation.valtermify NibbleA) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

298 
f (Code_Evaluation.valtermify NibbleB) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

299 
f (Code_Evaluation.valtermify NibbleC) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

300 
f (Code_Evaluation.valtermify NibbleD) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

301 
f (Code_Evaluation.valtermify NibbleE) orelse 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

302 
f (Code_Evaluation.valtermify NibbleF)" 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

303 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

304 
definition enum_term_of_nibble :: "nibble itself => unit => term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

305 
where 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

306 
"enum_term_of_nibble = (%_ _. map Code_Evaluation.term_of (Enum.enum :: nibble list))" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

307 

41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

308 
instance .. 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

309 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

310 
end 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

311 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

312 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

313 
instantiation char :: check_all 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

314 
begin 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

315 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

316 
definition 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

317 
"check_all f = check_all (%(x, t1). check_all (%(y, t2). f (Char x y, %_. Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.term_of Char) (t1 ())) (t2 ()))))" 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

318 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

319 
definition enum_term_of_char :: "char itself => unit => term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

320 
where 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

321 
"enum_term_of_char = (%_ _. map Code_Evaluation.term_of (Enum.enum :: char list))" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

322 

41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

323 
instance .. 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

324 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

325 
end 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

326 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

327 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

328 
instantiation option :: (check_all) check_all 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

329 
begin 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

330 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

331 
definition 
41178
f4d3acf0c4cc
adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents:
41177
diff
changeset

332 
"check_all f = f (Code_Evaluation.valtermify (None :: 'a option)) orelse check_all (%(x, t). f (Some x, %_. Code_Evaluation.App 
f4d3acf0c4cc
adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents:
41177
diff
changeset

333 
(Code_Evaluation.Const (STR ''Option.option.Some'') 
f4d3acf0c4cc
adding postprocessing for maps in term construction of quickcheck; fixed check_all_option definition
bulwahn
parents:
41177
diff
changeset

334 
(Typerep.Typerep (STR ''fun'') [Typerep.typerep TYPE('a), Typerep.Typerep (STR ''Option.option'') [Typerep.typerep TYPE('a)]])) (t ())))" 
41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

335 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

336 
definition enum_term_of_option :: "'a option itself => unit => term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

337 
where 
41722
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

338 
"enum_term_of_option = (% _ _. (Code_Evaluation.term_of (None :: 'a option)) # (map (Code_Evaluation.App (Code_Evaluation.Const (STR ''Option.option.Some'') 
9575694d2da5
improving sum type and option type term constructions for correct presentation in Smallcheck
bulwahn
parents:
41719
diff
changeset

339 
(Typerep.Typerep (STR ''fun'') [Typerep.typerep TYPE('a), Typerep.Typerep (STR ''Option.option'') [Typerep.typerep TYPE('a)]]))) (enum_term_of (TYPE('a)) ())))" 
41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

340 

41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

341 
instance .. 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

342 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

343 
end 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

344 

a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

345 

41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

346 
instantiation Enum.finite_1 :: check_all 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

347 
begin 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

348 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

349 
definition 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

350 
"check_all f = f (Code_Evaluation.valtermify Enum.finite_1.a\<^isub>1)" 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

351 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

352 
definition enum_term_of_finite_1 :: "Enum.finite_1 itself => unit => term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

353 
where 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

354 
"enum_term_of_finite_1 = (%_ _. [Code_Evaluation.term_of Enum.finite_1.a\<^isub>1])" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

355 

41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

356 
instance .. 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

357 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

358 
end 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

359 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

360 
instantiation Enum.finite_2 :: check_all 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

361 
begin 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

362 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

363 
definition 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

364 
"check_all f = (case f (Code_Evaluation.valtermify Enum.finite_2.a\<^isub>1) of Some x' \<Rightarrow> Some x'  None \<Rightarrow> f (Code_Evaluation.valtermify Enum.finite_2.a\<^isub>2))" 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

365 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

366 
definition enum_term_of_finite_2 :: "Enum.finite_2 itself => unit => term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

367 
where 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

368 
"enum_term_of_finite_2 = (%_ _. map Code_Evaluation.term_of (Enum.enum :: Enum.finite_2 list))" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

369 

41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

370 
instance .. 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

371 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

372 
end 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

373 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

374 
instantiation Enum.finite_3 :: check_all 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

375 
begin 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

376 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

377 
definition 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

378 
"check_all f = (case f (Code_Evaluation.valtermify Enum.finite_3.a\<^isub>1) of Some x' \<Rightarrow> Some x'  None \<Rightarrow> (case f (Code_Evaluation.valtermify Enum.finite_3.a\<^isub>2) of Some x' \<Rightarrow> Some x'  None \<Rightarrow> f (Code_Evaluation.valtermify Enum.finite_3.a\<^isub>3)))" 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

379 

41177
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

380 
definition enum_term_of_finite_3 :: "Enum.finite_3 itself => unit => term list" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

381 
where 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

382 
"enum_term_of_finite_3 = (%_ _. map Code_Evaluation.term_of (Enum.enum :: Enum.finite_3 list))" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

383 

41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

384 
instance .. 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

385 

a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

386 
end 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

387 

42195
1e7b62c93f5d
adding an exhaustive validator for quickcheck's batch validating; moving strip_imp; minimal setup for bounded_forall
bulwahn
parents:
42117
diff
changeset

388 
subsection {* Bounded universal quantifiers *} 
41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

389 

42195
1e7b62c93f5d
adding an exhaustive validator for quickcheck's batch validating; moving strip_imp; minimal setup for bounded_forall
bulwahn
parents:
42117
diff
changeset

390 
class bounded_forall = 
1e7b62c93f5d
adding an exhaustive validator for quickcheck's batch validating; moving strip_imp; minimal setup for bounded_forall
bulwahn
parents:
42117
diff
changeset

391 
fixes bounded_forall :: "('a \<Rightarrow> bool) \<Rightarrow> code_numeral \<Rightarrow> bool" 
1e7b62c93f5d
adding an exhaustive validator for quickcheck's batch validating; moving strip_imp; minimal setup for bounded_forall
bulwahn
parents:
42117
diff
changeset

392 

40620  393 
subsection {* Defining combinators for any firstorder data type *} 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

394 

552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

395 
definition catch_match :: "term list option => term list option => term list option" 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

396 
where 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

397 
[code del]: "catch_match t1 t2 = (SOME t. t = t1 \<or> t = t2)" 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

398 

552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

399 
code_const catch_match 
41920
d4fb7a418152
moving exhaustive_generators.ML to Quickcheck directory
bulwahn
parents:
41918
diff
changeset

400 
(Quickcheck "(_) handle Match => _") 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

401 

41920
d4fb7a418152
moving exhaustive_generators.ML to Quickcheck directory
bulwahn
parents:
41918
diff
changeset

402 
use "Tools/Quickcheck/exhaustive_generators.ML" 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

403 

41918  404 
setup {* Exhaustive_Generators.setup *} 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

405 

40915
a4c956d1f91f
declaring quickcheck testers as default after their setup
bulwahn
parents:
40914
diff
changeset

406 
declare [[quickcheck_tester = exhaustive]] 
a4c956d1f91f
declaring quickcheck testers as default after their setup
bulwahn
parents:
40914
diff
changeset

407 

40899
ef6fde932f4c
improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents:
40639
diff
changeset

408 
hide_fact orelse_def catch_match_def 
41105
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

409 
no_notation orelse (infixr "orelse" 55) 
41085
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

410 
hide_const (open) orelse catch_match mk_map_term check_all_n_lists 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

411 

552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

412 
end 