author  bulwahn 
Wed, 15 Dec 2010 17:46:46 +0100  
changeset 41178  f4d3acf0c4cc 
parent 41177  810a885decee 
child 41231  2e901158675e 
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 

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

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

4 

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

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

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

7 
uses ("Tools/smallvalue_generators.ML") 
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 

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

10 
subsection {* basic operations for generators *} 
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 

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

17 

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

18 
class small = term_of + 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

19 
fixes small :: "('a \<Rightarrow> term list option) \<Rightarrow> code_numeral \<Rightarrow> term list option" 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

20 

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

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

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

23 

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

24 
definition "small f d = f ()" 
40420
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

25 

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

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

27 

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

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

29 

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

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

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

32 

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

33 
function small' :: "(int => term list option) => int => int => term list option" 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

34 
where "small' f d i = (if d < i then None else (case f i of Some t => Some t  None => small' f d (i + 1)))" 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

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

36 

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

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

38 
by (relation "measure (%(_, d, i). nat (d + 1  i))") auto 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

39 

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

40 
definition "small f d = small' f (Code_Numeral.int_of d) ( (Code_Numeral.int_of d))" 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

41 

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

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

43 

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

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

45 

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

46 
instantiation prod :: (small, small) small 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

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

48 

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

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

50 
"small f d = small (%x. small (%y. f (x, y)) d) d" 
552563ea3304
adding code and theory for smallvalue generators, but do not setup the interpretation yet
bulwahn
parents:
diff
changeset

51 

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

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

53 

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

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

55 

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

56 
subsection {* full small value generator type classes *} 
40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

57 

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

58 
class full_small = term_of + 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

59 
fixes full_small :: "('a * (unit => term) \<Rightarrow> term list option) \<Rightarrow> code_numeral \<Rightarrow> term list option" 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

60 

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

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

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

63 

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

64 
definition "full_small f d = f (Code_Evaluation.valtermify ())" 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

65 

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

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

67 

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

68 
end 
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 
instantiation int :: full_small 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

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

72 

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

73 
function full_small' :: "(int * (unit => term) => term list option) => int => int => term list option" 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

74 
where "full_small' f d i = (if d < i then None else (case f (i, %_. Code_Evaluation.term_of i) of Some t => Some t  None => full_small' f d (i + 1)))" 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

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

76 

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

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

78 
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

79 

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

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

81 

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

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

83 

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

84 
end 
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 
instantiation prod :: (full_small, full_small) full_small 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

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

88 

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

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

90 
"full_small f d = full_small (%(x, t1). full_small (%(y, t2). f ((x, y), 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

91 
%u. Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.term_of (Pair :: 'a => 'b => ('a * 'b))) (t1 ())) (t2 ()))) d) d" 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

92 

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

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

94 

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

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

96 

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

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

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

99 

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

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

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

102 
"full_small_fun' f i d = (if i > 1 then 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

103 
full_small (%(a, at). full_small (%(b, bt). 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

104 
full_small_fun' (%(g, gt). f (g(a := b), 
40899
ef6fde932f4c
improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents:
40639
diff
changeset

105 
(%_. let T1 = (Typerep.typerep (TYPE('a))); 
ef6fde932f4c
improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents:
40639
diff
changeset

106 
T2 = (Typerep.typerep (TYPE('b))) 
ef6fde932f4c
improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents:
40639
diff
changeset

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

108 
Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.App 
ef6fde932f4c
improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents:
40639
diff
changeset

109 
(Code_Evaluation.Const (STR ''Fun.fun_upd'') 
ef6fde932f4c
improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents:
40639
diff
changeset

110 
(Typerep.Typerep (STR ''fun'') [Typerep.Typerep (STR ''fun'') [T1, T2], 
ef6fde932f4c
improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents:
40639
diff
changeset

111 
Typerep.Typerep (STR ''fun'') [T1, Typerep.Typerep (STR ''fun'') [T2, Typerep.Typerep (STR ''fun'') [T1, T2]]]])) 
ef6fde932f4c
improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents:
40639
diff
changeset

112 
(gt ())) (at ())) (bt ())))) (i  1) d) d) d 
ef6fde932f4c
improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents:
40639
diff
changeset

113 
else (if i > 0 then 
ef6fde932f4c
improving readability of Smallcheck theory; adding constant orelse to improve performance of the function package
bulwahn
parents:
40639
diff
changeset

114 
full_small (%(b, t). f (%_. b, %_. Code_Evaluation.Abs (STR ''x'') (Typerep.typerep TYPE('a)) (t ()))) d else None))" 
40639
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

115 

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

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

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

118 
"full_small_fun f d = full_small_fun' f d d" 
f1f0e6adca0a
adding function generation to SmallCheck; activating exhaustive search space testing
bulwahn
parents:
40620
diff
changeset

119 

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

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

121 

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

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

123 

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

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

125 

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

126 

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

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

128 
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

129 
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

130 

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

131 
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

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

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

134 
(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

135 

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

136 
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

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

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

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

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

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

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

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

144 
(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

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

146 
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

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

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

149 
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

150 

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

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

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

153 

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

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

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

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

157 
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

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

159 
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

160 

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

161 
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

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

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

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

165 
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

166 
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

167 

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

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

169 

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

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

171 

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

172 

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

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

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

175 

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

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

177 
"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

178 

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

179 
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

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

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

182 

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

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

184 

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

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

186 

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

187 

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

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

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

190 

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

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

192 
"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

193 

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

194 
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

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

196 
"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

197 

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

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

199 

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

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

201 

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

202 

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

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

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

205 

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

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

207 
"check_all f = check_all (%(x, t1). check_all (%(y, t2). f ((x, y), %_. Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.term_of (Pair :: 'a => 'b => ('a * 'b))) (t1 ())) (t2 ()))))" 
a549ff1d4070
adding a smarter enumeration scheme for finite functions
bulwahn
parents:
40915
diff
changeset

208 

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

209 
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

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

211 
"enum_term_of_prod = (%_ _. map (%(x, y). Code_Evaluation.App (Code_Evaluation.App (Code_Evaluation.term_of (Pair :: 'a => 'b => ('a * 'b))) x) y) (Enum.product (enum_term_of (TYPE('a)) ()) (enum_term_of (TYPE('b)) ())))" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

212 

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

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

214 

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

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

216 

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

217 

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

218 
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

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

220 

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

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

222 
"check_all f = (case check_all (%(a, t). f (Inl a, %_. Code_Evaluation.App (Code_Evaluation.term_of (Inl :: 'a => 'a + 'b)) (t ()))) of Some x' => Some x' 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

223 
 None => check_all (%(b, t). f (Inr b, %_. Code_Evaluation.App (Code_Evaluation.term_of (Inr :: 'b => 'a + 'b)) (t ()))))" 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

224 

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

225 
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

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

227 
"enum_term_of_sum = (%_ _. map (Code_Evaluation.App (Code_Evaluation.term_of (Inl :: 'a => ('a + 'b)))) (enum_term_of (TYPE('a)) ()) @ 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

228 
map (Code_Evaluation.App (Code_Evaluation.term_of (Inr :: 'b => ('a + 'b)))) (enum_term_of (TYPE('b)) ()))" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

229 

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

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

231 

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

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

233 

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

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

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

236 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

255 

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

256 
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

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

258 
"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

259 

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

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

261 

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

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

263 

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

264 

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

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

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

267 

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

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

269 
"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

270 

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

271 
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

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

273 
"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

274 

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

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

276 

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

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

278 

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 
instantiation option :: (check_all) check_all 
a76ee71c3313
adding check_all instances for a few more finite types in smallcheck
bulwahn
parents:
41104
diff
changeset

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

282 

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

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

284 
"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

285 
(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

286 
(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

287 

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

288 
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

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

290 
"enum_term_of_option = (% _ _. (Code_Evaluation.term_of (None :: 'a option)) # (map (Code_Evaluation.App (Code_Evaluation.term_of (Some :: 'a => 'a option))) (enum_term_of (TYPE('a)) ())))" 
810a885decee
added enum_term_of to correct present nested functions
bulwahn
parents:
41105
diff
changeset

291 

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

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

293 

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

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

295 

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

296 

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

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

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

299 

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

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

301 
"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

302 

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

303 
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

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

305 
"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

306 

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

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

308 

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

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

310 

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

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

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

313 

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

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

315 
"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

316 

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

317 
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

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

319 
"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

320 

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

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

322 

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

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

324 

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

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

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

327 

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

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

329 
"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

330 

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

331 
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

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

333 
"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

334 

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

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

336 

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

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

338 

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

339 

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

340 

40620  341 
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

342 

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

343 
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

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

345 
[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

346 

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

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

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

349 

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

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

351 

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

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

353 

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

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

355 

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

356 
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

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

358 
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

359 

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

360 
end 