author  bulwahn 
Fri, 11 Mar 2011 10:37:40 +0100  
changeset 41910  709c04e7b703 
parent 41909  383bbdad1650 
child 41912  1848775589e5 
permissions  rwrr 
41905  1 
(* Author: Lukas Bulwahn, TU Muenchen *) 
2 

3 
header {* Counterexample generator based on LazySmallCheck *} 

4 

5 
theory LSC 

6 
imports Main "~~/src/HOL/Library/Code_Char" 

7 
uses ("~~/src/HOL/Tools/LSC/lazysmallcheck.ML") 

8 
begin 

9 

10 
subsection {* Counterexample generator *} 

11 

41909
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset

12 
subsubsection {* Code generation setup *} 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset

13 

383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset

14 
code_type typerep 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset

15 
("Haskell" "Typerep") 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset

16 

383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset

17 
code_const Typerep.Typerep 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset

18 
("Haskell" "Typerep") 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset

19 

383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset

20 
code_reserved Haskell Typerep 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset

21 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

22 
subsubsection {* Type code_int for Haskell's Int type *} 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

23 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

24 
typedef (open) code_int = "UNIV \<Colon> int set" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

25 
morphisms int_of of_int by rule 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

26 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

27 
lemma int_of_inject [simp]: 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

28 
"int_of k = int_of l \<longleftrightarrow> k = l" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

29 
by (rule int_of_inject) 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

30 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

31 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

32 
instantiation code_int :: "{zero, one, minus, linorder}" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

33 
begin 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

34 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

35 
definition [simp, code del]: 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

36 
"0 = of_int 0" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

37 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

38 
definition [simp, code del]: 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

39 
"1 = of_int 1" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

40 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

41 
definition [simp, code del]: 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

42 
"n  m = of_int (int_of n  int_of m)" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

43 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

44 
definition [simp, code del]: 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

45 
"n \<le> m \<longleftrightarrow> int_of n \<le> int_of m" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

46 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

47 
definition [simp, code del]: 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

48 
"n < m \<longleftrightarrow> int_of n < int_of m" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

49 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

50 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

51 
instance proof qed (auto) 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

52 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

53 
end 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

54 
(* 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

55 
lemma zero_code_int_code [code, code_unfold]: 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

56 
"(0\<Colon>code_int) = Numeral0" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

57 
by (simp add: number_of_code_numeral_def Pls_def) 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

58 
lemma [code_post]: "Numeral0 = (0\<Colon>code_numeral)" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

59 
using zero_code_numeral_code .. 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

60 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

61 
lemma one_code_numeral_code [code, code_unfold]: 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

62 
"(1\<Colon>code_int) = Numeral1" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

63 
by (simp add: number_of_code_numeral_def Pls_def Bit1_def) 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

64 
lemma [code_post]: "Numeral1 = (1\<Colon>code_int)" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

65 
using one_code_numeral_code .. 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

66 
*) 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

67 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

68 
code_const "0 \<Colon> code_int" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

69 
(Haskell "0") 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

70 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

71 
code_const "1 \<Colon> code_int" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

72 
(Haskell "1") 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

73 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

74 
code_const "minus \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> code_int" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

75 
(Haskell "(_/ / _)") 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

76 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

77 
code_const "op \<le> \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> bool" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

78 
(Haskell infix 4 "<=") 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

79 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

80 
code_const "op < \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> bool" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

81 
(Haskell infix 4 "<") 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

82 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

83 
code_type code_int 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

84 
(Haskell "Int") 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

85 

41905  86 
subsubsection {* LSC's deep representation of types of terms *} 
87 

88 
datatype type = SumOfProd "type list list" 

89 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

90 
datatype "term" = Var "code_int list" type  Ctr code_int "term list" 
41905  91 

92 
datatype 'a cons = C type "(term list => 'a) list" 

93 

94 
subsubsection {* auxilary functions for LSC *} 

95 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

96 
consts nth :: "'a list => code_int => 'a" 
41905  97 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

98 
code_const nth ("Haskell" infixl 9 "!!") 
41905  99 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

100 
consts error :: "char list => 'a" 
41905  101 

102 
code_const error ("Haskell" "error") 

103 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

104 
consts toEnum :: "code_int => char" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

105 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

106 
code_const toEnum ("Haskell" "toEnum") 
41905  107 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

108 
consts map_index :: "(code_int * 'a => 'b) => 'a list => 'b list" 
41905  109 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

110 
consts split_At :: "code_int => 'a list => 'a list * 'a list" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

111 

41905  112 
subsubsection {* LSC's basic operations *} 
113 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

114 
type_synonym 'a series = "code_int => 'a cons" 
41905  115 

116 
definition empty :: "'a series" 

117 
where 

118 
"empty d = C (SumOfProd []) []" 

119 

120 
definition cons :: "'a => 'a series" 

121 
where 

122 
"cons a d = (C (SumOfProd [[]]) [(%_. a)])" 

123 

124 
fun conv :: "(term list => 'a) list => term => 'a" 

125 
where 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

126 
"conv cs (Var p _) = error (Char Nibble0 Nibble0 # map toEnum p)" 
41905  127 
 "conv cs (Ctr i xs) = (nth cs i) xs" 
128 

129 
fun nonEmpty :: "type => bool" 

130 
where 

131 
"nonEmpty (SumOfProd ps) = (\<not> (List.null ps))" 

132 

133 
definition "apply" :: "('a => 'b) series => 'a series => 'b series" 

134 
where 

135 
"apply f a d = 

136 
(case f d of C (SumOfProd ps) cfs => 

137 
case a (d  1) of C ta cas => 

138 
let 

139 
shallow = (d > 0 \<and> nonEmpty ta); 

140 
cs = [(%xs'. (case xs' of [] => undefined  x # xs => cf xs (conv cas x))). shallow, cf < cfs] 

141 
in C (SumOfProd [ta # p. shallow, p < ps]) cs)" 

142 

143 
definition sum :: "'a series => 'a series => 'a series" 

144 
where 

145 
"sum a b d = 

146 
(case a d of C (SumOfProd ssa) ca => 

147 
case b d of C (SumOfProd ssb) cb => 

148 
C (SumOfProd (ssa @ ssb)) (ca @ cb))" 

149 

150 
definition cons0 :: "'a => 'a series" 

151 
where 

152 
"cons0 f = cons f" 

153 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

154 
type_synonym pos = "code_int list" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

155 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

156 
subsubsection {* Term refinement *} 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

157 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

158 
definition new :: "pos => type list list => term list" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

159 
where 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

160 
"new p ps = map_index (%(c, ts). Ctr c (map_index (%(i, t). Var (p @ [i]) t) ts)) ps" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

161 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

162 
fun refine :: "term => pos => term list" and refineList :: "term list => pos => (term list) list" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

163 
where 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

164 
"refine (Var p (SumOfProd ss)) [] = new p ss" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

165 
 "refine (Ctr c xs) p = map (Ctr c) (refineList xs p)" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

166 
 "refineList xs (i # is) = (let (ls, xrs) = split_At i xs in (case xrs of x#rs => [ls @ y # rs. y < refine x is]))" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

167 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

168 
text {* Find total instantiations of a partial value *} 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

169 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

170 
function total :: "term => term list" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

171 
where 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

172 
"total (Ctr c xs) = [Ctr c ys. ys < map total xs]" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

173 
 "total (Var p (SumOfProd ss)) = [y. x < new p ss, y < total x]" 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

174 
by pat_completeness auto 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

175 

3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

176 
termination sorry 
41905  177 

178 
subsubsection {* LSC's type class for enumeration *} 

179 

180 
class serial = 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

181 
fixes series :: "code_int => 'a cons" 
41905  182 

183 
definition cons1 :: "('a::serial => 'b) => 'b series" 

184 
where 

185 
"cons1 f = apply (cons f) series" 

186 

187 
definition cons2 :: "('a :: serial => 'b :: serial => 'c) => 'c series" 

188 
where 

189 
"cons2 f = apply (apply (cons f) series) series" 

190 

191 
instantiation unit :: serial 

192 
begin 

193 

194 
definition 

195 
"series = cons0 ()" 

196 

197 
instance .. 

198 

199 
end 

200 

201 
instantiation bool :: serial 

202 
begin 

203 

204 
definition 

205 
"series = sum (cons0 True) (cons0 False)" 

206 

207 
instance .. 

208 

209 
end 

210 

211 
instantiation option :: (serial) serial 

212 
begin 

213 

214 
definition 

215 
"series = sum (cons0 None) (cons1 Some)" 

216 

217 
instance .. 

218 

219 
end 

220 

221 
instantiation sum :: (serial, serial) serial 

222 
begin 

223 

224 
definition 

225 
"series = sum (cons1 Inl) (cons1 Inr)" 

226 

227 
instance .. 

228 

229 
end 

230 

231 
instantiation list :: (serial) serial 

232 
begin 

233 

234 
function series_list :: "'a list series" 

235 
where 

236 
"series_list d = sum (cons []) (apply (apply (cons Cons) series) series_list) d" 

237 
by pat_completeness auto 

238 

239 
termination sorry 

240 

241 
instance .. 

242 

243 
end 

244 

245 
instantiation nat :: serial 

246 
begin 

247 

248 
function series_nat :: "nat series" 

249 
where 

250 
"series_nat d = sum (cons 0) (apply (cons Suc) series_nat) d" 

251 
by pat_completeness auto 

252 

253 
termination sorry 

254 

255 
instance .. 

256 

257 
end 

258 

259 
instantiation Enum.finite_1 :: serial 

260 
begin 

261 

262 
definition series_finite_1 :: "Enum.finite_1 series" 

263 
where 

264 
"series_finite_1 = cons (Enum.finite_1.a\<^isub>1 :: Enum.finite_1)" 

265 

266 
instance .. 

267 

268 
end 

269 

270 
instantiation Enum.finite_2 :: serial 

271 
begin 

272 

273 
definition series_finite_2 :: "Enum.finite_2 series" 

274 
where 

275 
"series_finite_2 = sum (cons (Enum.finite_2.a\<^isub>1 :: Enum.finite_2)) (cons (Enum.finite_2.a\<^isub>2 :: Enum.finite_2))" 

276 

277 
instance .. 

278 

279 
end 

280 

281 
instantiation Enum.finite_3 :: serial 

282 
begin 

283 

284 
definition series_finite_3 :: "Enum.finite_3 series" 

285 
where 

286 
"series_finite_3 = sum (cons (Enum.finite_3.a\<^isub>1 :: Enum.finite_3)) (sum (cons (Enum.finite_3.a\<^isub>2 :: Enum.finite_3)) (cons (Enum.finite_3.a\<^isub>3 :: Enum.finite_3)))" 

287 

288 
instance .. 

289 

290 
end 

291 

41910
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

292 
instantiation Enum.finite_4 :: serial 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

293 
begin 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

294 

709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

295 
definition series_finite_4 :: "Enum.finite_4 series" 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

296 
where 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

297 
"series_finite_4 = sum (cons Enum.finite_4.a\<^isub>1) (sum (cons Enum.finite_4.a\<^isub>2) (sum (cons Enum.finite_4.a\<^isub>3) (cons Enum.finite_4.a\<^isub>4)))" 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

298 

709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

299 
instance .. 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

300 

709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

301 
end 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

302 

41905  303 
subsubsection {* class is_testable *} 
304 

305 
text {* The class is_testable ensures that all necessary type instances are generated. *} 

306 

307 
class is_testable 

308 

309 
instance bool :: is_testable .. 

310 

311 
instance "fun" :: ("{term_of, serial}", is_testable) is_testable .. 

312 

313 
definition ensure_testable :: "'a :: is_testable => 'a :: is_testable" 

314 
where 

315 
"ensure_testable f = f" 

316 

41910
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

317 
declare simp_thms(17,19)[code del] 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

318 

41905  319 
subsubsection {* Setting up the counterexample generator *} 
320 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

321 
use "~~/src/HOL/Tools/LSC/lazysmallcheck.ML" 
41905  322 

323 
setup {* Lazysmallcheck.setup *} 

324 

41908
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

325 
hide_const (open) empty 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset

326 

41905  327 
end 