author  bulwahn 
Mon, 30 May 2011 13:57:59 +0200  
changeset 43047  26774ccb1c74 
parent 42980  859fe9cc0838 
child 43237  8f5c3c6c2909 
permissions  rwrr 
41905  1 
(* Author: Lukas Bulwahn, TU Muenchen *) 
2 

41930
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents:
41929
diff
changeset

3 
header {* Counterexample generator preforming narrowingbased testing *} 
41905  4 

41930
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents:
41929
diff
changeset

5 
theory Quickcheck_Narrowing 
41905  6 
imports Main "~~/src/HOL/Library/Code_Char" 
41962
27a61a3266d8
correcting names in Narrowing_Engine and example theory for Quickcheck_Narrowing
bulwahn
parents:
41961
diff
changeset

7 
uses 
27a61a3266d8
correcting names in Narrowing_Engine and example theory for Quickcheck_Narrowing
bulwahn
parents:
41961
diff
changeset

8 
("~~/src/HOL/Tools/Quickcheck/narrowing_generators.ML") 
41905  9 
begin 
10 

11 
subsection {* Counterexample generator *} 

12 

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

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

14 

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

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

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

17 

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

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

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

20 

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

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

22 

41964
13904699c859
tuned subsubsection names in Quickcheck_Narrowing
bulwahn
parents:
41962
diff
changeset

23 
subsubsection {* Type @{text "code_int"} for Haskell's Int type *} 
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

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

26 
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

27 

42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

28 
lemma of_int_int_of [simp]: 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

29 
"of_int (int_of k) = k" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

30 
by (rule int_of_inverse) 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

31 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

32 
lemma int_of_of_int [simp]: 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

33 
"int_of (of_int n) = n" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

34 
by (rule of_int_inverse) (rule UNIV_I) 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

35 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

36 
lemma code_int: 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

37 
"(\<And>n\<Colon>code_int. PROP P n) \<equiv> (\<And>n\<Colon>int. PROP P (of_int n))" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

38 
proof 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

39 
fix n :: int 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

40 
assume "\<And>n\<Colon>code_int. PROP P n" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

41 
then show "PROP P (of_int n)" . 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

42 
next 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

43 
fix n :: code_int 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

44 
assume "\<And>n\<Colon>int. PROP P (of_int n)" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

45 
then have "PROP P (of_int (int_of n))" . 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

46 
then show "PROP P n" by simp 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

47 
qed 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

48 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

49 

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

50 
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

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

52 
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

53 

42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

54 
lemma of_int_inject [simp]: 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

55 
"of_int n = of_int m \<longleftrightarrow> n = m" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

56 
by (rule of_int_inject) (rule UNIV_I)+ 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

57 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

58 
instantiation code_int :: equal 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

59 
begin 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

60 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

61 
definition 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

62 
"HOL.equal k l \<longleftrightarrow> HOL.equal (int_of k) (int_of l)" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

63 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

64 
instance proof 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

65 
qed (auto simp add: equal_code_int_def equal_int_def eq_int_refl) 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

66 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

67 
end 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

68 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

69 
instantiation code_int :: number 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

70 
begin 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

71 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

72 
definition 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

73 
"number_of = of_int" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

74 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

75 
instance .. 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

76 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

77 
end 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

78 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

79 
lemma int_of_number [simp]: 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

80 
"int_of (number_of k) = number_of k" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

81 
by (simp add: number_of_code_int_def number_of_is_id) 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

82 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

83 

41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

84 
definition nat_of :: "code_int => nat" 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

85 
where 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

86 
"nat_of i = nat (int_of i)" 
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

87 

42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

88 

43047
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

89 
code_datatype "number_of \<Colon> int \<Rightarrow> code_int" 
42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

90 

859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

91 

42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

92 
instantiation code_int :: "{minus, linordered_semidom, semiring_div, linorder}" 
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

93 
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

94 

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

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

97 

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

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

100 

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 
definition [simp, code del]: 
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

102 
"n + m = of_int (int_of n + int_of m)" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

103 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

104 
definition [simp, code del]: 
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

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

106 

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

107 
definition [simp, code del]: 
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

108 
"n * m = of_int (int_of n * int_of m)" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

109 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

110 
definition [simp, code del]: 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

111 
"n div m = of_int (int_of n div int_of m)" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

112 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

113 
definition [simp, code del]: 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

114 
"n mod m = of_int (int_of n mod int_of m)" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

115 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

116 
definition [simp, code del]: 
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

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

118 

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

119 
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

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

121 

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

122 

42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

123 
instance proof 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

124 
qed (auto simp add: code_int left_distrib zmult_zless_mono2) 
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

125 

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 
end 
42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

127 

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

128 
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

129 
"(0\<Colon>code_int) = Numeral0" 
42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

130 
by (simp add: number_of_code_int_def Pls_def) 
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

131 
lemma [code_post]: "Numeral0 = (0\<Colon>code_int)" 
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

132 
using zero_code_int_code .. 
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

133 

42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

134 
lemma one_code_int_code [code, code_unfold]: 
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

135 
"(1\<Colon>code_int) = Numeral1" 
42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

136 
by (simp add: number_of_code_int_def Pls_def Bit1_def) 
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

137 
lemma [code_post]: "Numeral1 = (1\<Colon>code_int)" 
42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

138 
using one_code_int_code .. 
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

139 

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

140 

42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

141 
definition div_mod_code_int :: "code_int \<Rightarrow> code_int \<Rightarrow> code_int \<times> code_int" where 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

142 
[code del]: "div_mod_code_int n m = (n div m, n mod m)" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

143 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

144 
lemma [code]: 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

145 
"div_mod_code_int n m = (if m = 0 then (0, n) else (n div m, n mod m))" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

146 
unfolding div_mod_code_int_def by auto 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

147 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

148 
lemma [code]: 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

149 
"n div m = fst (div_mod_code_int n m)" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

150 
unfolding div_mod_code_int_def by simp 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

151 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

152 
lemma [code]: 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

153 
"n mod m = snd (div_mod_code_int n m)" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

154 
unfolding div_mod_code_int_def by simp 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

155 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

156 
lemma int_of_code [code]: 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

157 
"int_of k = (if k = 0 then 0 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

158 
else (if k mod 2 = 0 then 2 * int_of (k div 2) else 2 * int_of (k div 2) + 1))" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

159 
proof  
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

160 
have 1: "(int_of k div 2) * 2 + int_of k mod 2 = int_of k" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

161 
by (rule mod_div_equality) 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

162 
have "int_of k mod 2 = 0 \<or> int_of k mod 2 = 1" by auto 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

163 
from this show ?thesis 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

164 
apply auto 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

165 
apply (insert 1) by (auto simp add: mult_ac) 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

166 
qed 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

167 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

168 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

169 
code_instance code_numeral :: equal 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

170 
(Haskell ) 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

171 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

172 
setup {* fold (Numeral.add_code @{const_name number_code_int_inst.number_of_code_int} 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

173 
false Code_Printer.literal_numeral) ["Haskell"] *} 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

174 

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

175 
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

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

177 

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

178 
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

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

180 

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

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

183 

42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

184 
code_const div_mod_code_int 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

185 
(Haskell "divMod") 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

186 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

187 
code_const "HOL.equal \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> bool" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

188 
(Haskell infix 4 "==") 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

189 

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

190 
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

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

192 

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

193 
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

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

195 

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

196 
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

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

198 

42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

199 
code_abort of_int 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

200 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

201 
subsubsection {* Narrowing's deep representation of types and terms *} 
41905  202 

43047
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

203 
datatype narrowing_type = SumOfProd "narrowing_type list list" 
41905  204 

43047
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

205 
datatype narrowing_term = Var "code_int list" narrowing_type  Ctr code_int "narrowing_term list" 
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

206 
datatype 'a cons = C narrowing_type "(narrowing_term list => 'a) list" 
41905  207 

42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

208 
subsubsection {* From narrowing's deep representation of terms to Code_Evaluation's terms *} 
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

209 

859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

210 
class partial_term_of = typerep + 
43047
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

211 
fixes partial_term_of :: "'a itself => narrowing_term => Code_Evaluation.term" 
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

212 

26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

213 
lemma partial_term_of_anything: "partial_term_of x nt \<equiv> t" 
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

214 
by (rule eq_reflection) (cases "partial_term_of x nt", cases t, simp) 
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

215 

42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset

216 

41964
13904699c859
tuned subsubsection names in Quickcheck_Narrowing
bulwahn
parents:
41962
diff
changeset

217 
subsubsection {* Auxilary functions for Narrowing *} 
41905  218 

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

219 
consts nth :: "'a list => code_int => 'a" 
41905  220 

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

221 
code_const nth ("Haskell" infixl 9 "!!") 
41905  222 

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

223 
consts error :: "char list => 'a" 
41905  224 

225 
code_const error ("Haskell" "error") 

226 

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

227 
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

228 

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

229 
code_const toEnum ("Haskell" "toEnum") 
41905  230 

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

231 
consts map_index :: "(code_int * 'a => 'b) => 'a list => 'b list" 
41905  232 

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

233 
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

234 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

235 
subsubsection {* Narrowing's basic operations *} 
41905  236 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

237 
type_synonym 'a narrowing = "code_int => 'a cons" 
41905  238 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

239 
definition empty :: "'a narrowing" 
41905  240 
where 
241 
"empty d = C (SumOfProd []) []" 

242 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

243 
definition cons :: "'a => 'a narrowing" 
41905  244 
where 
245 
"cons a d = (C (SumOfProd [[]]) [(%_. a)])" 

246 

43047
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

247 
fun conv :: "(narrowing_term list => 'a) list => narrowing_term => 'a" 
41905  248 
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

249 
"conv cs (Var p _) = error (Char Nibble0 Nibble0 # map toEnum p)" 
41905  250 
 "conv cs (Ctr i xs) = (nth cs i) xs" 
251 

43047
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

252 
fun nonEmpty :: "narrowing_type => bool" 
41905  253 
where 
254 
"nonEmpty (SumOfProd ps) = (\<not> (List.null ps))" 

255 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

256 
definition "apply" :: "('a => 'b) narrowing => 'a narrowing => 'b narrowing" 
41905  257 
where 
258 
"apply f a d = 

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

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

261 
let 

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

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

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

265 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

266 
definition sum :: "'a narrowing => 'a narrowing => 'a narrowing" 
41905  267 
where 
268 
"sum a b d = 

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

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

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

272 

41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

273 
lemma [fundef_cong]: 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

274 
assumes "a d = a' d" "b d = b' d" "d = d'" 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

275 
shows "sum a b d = sum a' b' d'" 
43047
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

276 
using assms unfolding sum_def by (auto split: cons.split narrowing_type.split) 
41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

277 

1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

278 
lemma [fundef_cong]: 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

279 
assumes "f d = f' d" "(\<And>d'. 0 <= d' & d' < d ==> a d' = a' d')" 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

280 
assumes "d = d'" 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

281 
shows "apply f a d = apply f' a' d'" 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

282 
proof  
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

283 
note assms moreover 
41930
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents:
41929
diff
changeset

284 
have "int_of (of_int 0) < int_of d' ==> int_of (of_int 0) <= int_of (of_int (int_of d'  int_of (of_int 1)))" 
41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

285 
by (simp add: of_int_inverse) 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

286 
moreover 
41930
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents:
41929
diff
changeset

287 
have "int_of (of_int (int_of d'  int_of (of_int 1))) < int_of d'" 
41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

288 
by (simp add: of_int_inverse) 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

289 
ultimately show ?thesis 
43047
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

290 
unfolding apply_def by (auto split: cons.split narrowing_type.split simp add: Let_def) 
41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

291 
qed 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

292 

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

293 
type_synonym pos = "code_int list" 
41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

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

295 
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

296 

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

297 
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

298 
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

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

300 

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

301 
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

302 
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

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

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

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

306 

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

307 
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

308 

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

309 
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

310 
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

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

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

313 
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

314 

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

315 
termination sorry 
41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

316 
*) 
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

317 
subsubsection {* Narrowing generator type class *} 
41905  318 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

319 
class narrowing = 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

320 
fixes narrowing :: "code_int => 'a cons" 
41905  321 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

322 
definition cons1 :: "('a::narrowing => 'b) => 'b narrowing" 
41905  323 
where 
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

324 
"cons1 f = apply (cons f) narrowing" 
41905  325 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

326 
definition cons2 :: "('a :: narrowing => 'b :: narrowing => 'c) => 'c narrowing" 
41905  327 
where 
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

328 
"cons2 f = apply (apply (cons f) narrowing) narrowing" 
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

329 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

330 
definition drawn_from :: "'a list => 'a cons" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

331 
where "drawn_from xs = C (SumOfProd (map (%_. []) xs)) (map (%x y. x) xs)" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

332 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

333 
instantiation int :: narrowing 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

334 
begin 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

335 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

336 
definition 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

337 
"narrowing_int d = (let i = Quickcheck_Narrowing.int_of d in drawn_from [i .. i])" 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

338 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

339 
instance .. 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

340 

52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

341 
end 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset

342 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

343 
instantiation unit :: narrowing 
41905  344 
begin 
345 

346 
definition 

41965
328371f4f927
removing definition of cons0; hiding constants in Quickcheck_Narrowing
bulwahn
parents:
41964
diff
changeset

347 
"narrowing = cons ()" 
41905  348 

349 
instance .. 

350 

351 
end 

352 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

353 
instantiation bool :: narrowing 
41905  354 
begin 
355 

356 
definition 

41965
328371f4f927
removing definition of cons0; hiding constants in Quickcheck_Narrowing
bulwahn
parents:
41964
diff
changeset

357 
"narrowing = sum (cons True) (cons False)" 
41905  358 

359 
instance .. 

360 

361 
end 

362 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

363 
instantiation option :: (narrowing) narrowing 
41905  364 
begin 
365 

366 
definition 

41965
328371f4f927
removing definition of cons0; hiding constants in Quickcheck_Narrowing
bulwahn
parents:
41964
diff
changeset

367 
"narrowing = sum (cons None) (cons1 Some)" 
41905  368 

369 
instance .. 

370 

371 
end 

372 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

373 
instantiation sum :: (narrowing, narrowing) narrowing 
41905  374 
begin 
375 

376 
definition 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

377 
"narrowing = sum (cons1 Inl) (cons1 Inr)" 
41905  378 

379 
instance .. 

380 

381 
end 

382 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

383 
instantiation list :: (narrowing) narrowing 
41905  384 
begin 
385 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

386 
function narrowing_list :: "'a list narrowing" 
41905  387 
where 
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

388 
"narrowing_list d = sum (cons []) (apply (apply (cons Cons) narrowing) narrowing_list) d" 
41905  389 
by pat_completeness auto 
390 

41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

391 
termination proof (relation "measure nat_of") 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

392 
qed (auto simp add: of_int_inverse nat_of_def) 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

393 

41905  394 
instance .. 
395 

396 
end 

397 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

398 
instantiation nat :: narrowing 
41905  399 
begin 
400 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

401 
function narrowing_nat :: "nat narrowing" 
41905  402 
where 
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

403 
"narrowing_nat d = sum (cons 0) (apply (cons Suc) narrowing_nat) d" 
41905  404 
by pat_completeness auto 
405 

41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

406 
termination proof (relation "measure nat_of") 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset

407 
qed (auto simp add: of_int_inverse nat_of_def) 
41905  408 

409 
instance .. 

410 

411 
end 

412 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

413 
instantiation Enum.finite_1 :: narrowing 
41905  414 
begin 
415 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

416 
definition narrowing_finite_1 :: "Enum.finite_1 narrowing" 
41905  417 
where 
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

418 
"narrowing_finite_1 = cons (Enum.finite_1.a\<^isub>1 :: Enum.finite_1)" 
41905  419 

420 
instance .. 

421 

422 
end 

423 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

424 
instantiation Enum.finite_2 :: narrowing 
41905  425 
begin 
426 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

427 
definition narrowing_finite_2 :: "Enum.finite_2 narrowing" 
41905  428 
where 
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

429 
"narrowing_finite_2 = sum (cons (Enum.finite_2.a\<^isub>1 :: Enum.finite_2)) (cons (Enum.finite_2.a\<^isub>2 :: Enum.finite_2))" 
41905  430 

431 
instance .. 

432 

433 
end 

434 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

435 
instantiation Enum.finite_3 :: narrowing 
41905  436 
begin 
437 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

438 
definition narrowing_finite_3 :: "Enum.finite_3 narrowing" 
41905  439 
where 
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

440 
"narrowing_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)))" 
41905  441 

442 
instance .. 

443 

444 
end 

445 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

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

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

448 

41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

449 
definition narrowing_finite_4 :: "Enum.finite_4 narrowing" 
41910
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

450 
where 
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset

451 
"narrowing_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)))" 
41910
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset

452 

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

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

454 

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

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

456 

41943  457 
subsubsection {* class @{text is_testable} *} 
41905  458 

41943  459 
text {* The class @{text is_testable} ensures that all necessary type instances are generated. *} 
41905  460 

461 
class is_testable 

462 

463 
instance bool :: is_testable .. 

464 

43047
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

465 
instance "fun" :: ("{term_of, narrowing, partial_term_of}", is_testable) is_testable .. 
41905  466 

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

468 
where 

469 
"ensure_testable f = f" 

470 

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

471 
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

472 

42022
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

473 
subsubsection {* Defining a simple datatype to represent functions in an incomplete and redundant way *} 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

474 

101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

475 
datatype ('a, 'b) ffun = Constant 'b  Update 'a 'b "('a, 'b) ffun" 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

476 

101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

477 
primrec eval_ffun :: "('a, 'b) ffun => 'a => 'b" 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

478 
where 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

479 
"eval_ffun (Constant c) x = c" 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

480 
 "eval_ffun (Update x' y f) x = (if x = x' then y else eval_ffun f x)" 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

481 

101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

482 
hide_type (open) ffun 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

483 
hide_const (open) Constant Update eval_ffun 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

484 

42024
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

485 
datatype 'b cfun = Constant 'b 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

486 

51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

487 
primrec eval_cfun :: "'b cfun => 'a => 'b" 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

488 
where 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

489 
"eval_cfun (Constant c) y = c" 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

490 

51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

491 
hide_type (open) cfun 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

492 
hide_const (open) Constant eval_cfun 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

493 

51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

494 
subsubsection {* Setting up the counterexample generator *} 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

495 

51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

496 
use "~~/src/HOL/Tools/Quickcheck/narrowing_generators.ML" 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

497 

51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

498 
setup {* Narrowing_Generators.setup *} 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

499 

43047
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

500 
hide_type (open) code_int narrowing_type narrowing_term cons 
42024
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset

501 
hide_const (open) int_of of_int nth error toEnum map_index split_At empty 
43047
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents:
42980
diff
changeset

502 
C cons conv nonEmpty "apply" sum cons1 cons2 ensure_testable 
42022
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset

503 

41905  504 
end 