author  bulwahn 
Fri, 11 Mar 2011 10:37:37 +0100  
changeset 41908  3bd9a21366d2 
parent 41905  e2611bc96022 
child 41909  383bbdad1650 
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 

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

12 
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

13 

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

14 
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

15 
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

16 

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

17 
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

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

19 
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

20 

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

21 

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

23 
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

24 

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

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

27 

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

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

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

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

33 

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

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

36 

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

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

39 

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

42 

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

44 
(* 
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 
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

46 
"(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

47 
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

48 
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

49 
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

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

52 
"(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

53 
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

54 
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

55 
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

56 
*) 
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 

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

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

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

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

63 

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

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

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

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

69 

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

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

72 

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

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

75 

41905  76 
subsubsection {* LSC's deep representation of types of terms *} 
77 

78 
datatype type = SumOfProd "type list list" 

79 

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

80 
datatype "term" = Var "code_int list" type  Ctr code_int "term list" 
41905  81 

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

83 

84 
subsubsection {* auxilary functions for LSC *} 

85 

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

86 
consts nth :: "'a list => code_int => 'a" 
41905  87 

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

88 
code_const nth ("Haskell" infixl 9 "!!") 
41905  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 
consts error :: "char list => 'a" 
41905  91 

92 
code_const error ("Haskell" "error") 

93 

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

94 
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

95 

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 
code_const toEnum ("Haskell" "toEnum") 
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 
consts map_index :: "(code_int * 'a => 'b) => 'a list => 'b list" 
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 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

101 

41905  102 
subsubsection {* LSC's basic operations *} 
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 
type_synonym 'a series = "code_int => 'a cons" 
41905  105 

106 
definition empty :: "'a series" 

107 
where 

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

109 

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

111 
where 

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

113 

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

115 
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

116 
"conv cs (Var p _) = error (Char Nibble0 Nibble0 # map toEnum p)" 
41905  117 
 "conv cs (Ctr i xs) = (nth cs i) xs" 
118 

119 
fun nonEmpty :: "type => bool" 

120 
where 

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

122 

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

124 
where 

125 
"apply f a d = 

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

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

128 
let 

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

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

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

132 

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

134 
where 

135 
"sum a b d = 

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

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

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

139 

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

141 
where 

142 
"cons0 f = cons f" 

143 

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

144 
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

145 

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

146 
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

147 

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

148 
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

149 
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

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

151 

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

152 
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

153 
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

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

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

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

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

159 

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

161 
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

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

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

164 
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

165 

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 
termination sorry 
41905  167 

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

169 

170 
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

171 
fixes series :: "code_int => 'a cons" 
41905  172 

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

174 
where 

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

176 

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

178 
where 

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

180 

181 
instantiation unit :: serial 

182 
begin 

183 

184 
definition 

185 
"series = cons0 ()" 

186 

187 
instance .. 

188 

189 
end 

190 

191 
instantiation bool :: serial 

192 
begin 

193 

194 
definition 

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

196 

197 
instance .. 

198 

199 
end 

200 

201 
instantiation option :: (serial) serial 

202 
begin 

203 

204 
definition 

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

206 

207 
instance .. 

208 

209 
end 

210 

211 
instantiation sum :: (serial, serial) serial 

212 
begin 

213 

214 
definition 

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

216 

217 
instance .. 

218 

219 
end 

220 

221 
instantiation list :: (serial) serial 

222 
begin 

223 

224 
function series_list :: "'a list series" 

225 
where 

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

227 
by pat_completeness auto 

228 

229 
termination sorry 

230 

231 
instance .. 

232 

233 
end 

234 

235 
instantiation nat :: serial 

236 
begin 

237 

238 
function series_nat :: "nat series" 

239 
where 

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

241 
by pat_completeness auto 

242 

243 
termination sorry 

244 

245 
instance .. 

246 

247 
end 

248 

249 
instantiation Enum.finite_1 :: serial 

250 
begin 

251 

252 
definition series_finite_1 :: "Enum.finite_1 series" 

253 
where 

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

255 

256 
instance .. 

257 

258 
end 

259 

260 
instantiation Enum.finite_2 :: serial 

261 
begin 

262 

263 
definition series_finite_2 :: "Enum.finite_2 series" 

264 
where 

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

266 

267 
instance .. 

268 

269 
end 

270 

271 
instantiation Enum.finite_3 :: serial 

272 
begin 

273 

274 
definition series_finite_3 :: "Enum.finite_3 series" 

275 
where 

276 
"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)))" 

277 

278 
instance .. 

279 

280 
end 

281 

282 
subsubsection {* class is_testable *} 

283 

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

285 

286 
class is_testable 

287 

288 
instance bool :: is_testable .. 

289 

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

291 

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

293 
where 

294 
"ensure_testable f = f" 

295 

296 
subsubsection {* Setting up the counterexample generator *} 

297 

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

298 
use "~~/src/HOL/Tools/LSC/lazysmallcheck.ML" 
41905  299 

300 
setup {* Lazysmallcheck.setup *} 

301 

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

302 
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

303 

41905  304 
end 