author | bulwahn |
Thu, 09 Jun 2011 08:32:19 +0200 | |
changeset 43314 | a9090cabca14 |
parent 43312 | 7a31f9064f99 |
child 43315 | 893de45ac28d |
permissions | -rw-r--r-- |
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 narrowing-based testing *} |
41905 | 4 |
|
41930
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents:
41929
diff
changeset
|
5 |
theory Quickcheck_Narrowing |
43312
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
6 |
imports Quickcheck_Exhaustive |
41962
27a61a3266d8
correcting names in Narrowing_Engine and example theory for Quickcheck_Narrowing
bulwahn
parents:
41961
diff
changeset
|
7 |
uses |
43237
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
8 |
("~~/src/HOL/Tools/Quickcheck/PNF_Narrowing_Engine.hs") |
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
9 |
("~~/src/HOL/Tools/Quickcheck/Narrowing_Engine.hs") |
41962
27a61a3266d8
correcting names in Narrowing_Engine and example theory for Quickcheck_Narrowing
bulwahn
parents:
41961
diff
changeset
|
10 |
("~~/src/HOL/Tools/Quickcheck/narrowing_generators.ML") |
41905 | 11 |
begin |
12 |
||
13 |
subsection {* Counterexample generator *} |
|
14 |
||
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
15 |
text {* We create a new target for the necessary code generation setup. *} |
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
16 |
|
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
17 |
setup {* Code_Target.extend_target ("Haskell_Quickcheck", (Code_Haskell.target, K I)) *} |
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
18 |
|
41909
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset
|
19 |
subsubsection {* Code generation setup *} |
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_type typerep |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
22 |
(Haskell_Quickcheck "Typerep") |
41909
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset
|
23 |
|
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset
|
24 |
code_const Typerep.Typerep |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
25 |
(Haskell_Quickcheck "Typerep") |
41909
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset
|
26 |
|
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
27 |
code_reserved Haskell_Quickcheck Typerep |
41909
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents:
41908
diff
changeset
|
28 |
|
43312
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
29 |
code_type char |
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
30 |
(Haskell_Quickcheck "Char") |
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
31 |
|
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
32 |
setup {* |
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
33 |
fold String_Code.add_literal_char ["Haskell_Quickcheck"] |
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
34 |
#> String_Code.add_literal_list_string "Haskell_Quickcheck" |
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
35 |
*} |
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
36 |
|
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
37 |
code_instance char :: equal |
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
38 |
(Haskell_Quickcheck -) |
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
39 |
|
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
40 |
code_const "HOL.equal \<Colon> char \<Rightarrow> char \<Rightarrow> bool" |
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
41 |
(Haskell_Quickcheck infix 4 "==") |
7a31f9064f99
adapting Quickcheck_Narrowing: adding setup for characters; correcting import statement
bulwahn
parents:
43309
diff
changeset
|
42 |
|
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
43 |
subsubsection {* Type @{text "code_int"} for Haskell_Quickcheck'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
|
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 |
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
|
46 |
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
|
47 |
|
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
48 |
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
|
49 |
"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
|
50 |
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
|
51 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
52 |
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
|
53 |
"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
|
54 |
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
|
55 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
56 |
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
|
57 |
"(\<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
|
58 |
proof |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
next |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
qed |
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 |
|
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
|
70 |
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
|
71 |
"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
|
72 |
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
|
73 |
|
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
74 |
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
|
75 |
"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
|
76 |
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
|
77 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
78 |
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
|
79 |
begin |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
80 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
81 |
definition |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
82 |
"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
|
83 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
84 |
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
|
85 |
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
|
86 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
87 |
end |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
88 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
89 |
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
|
90 |
begin |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
91 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
92 |
definition |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
93 |
"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
|
94 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
95 |
instance .. |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
96 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
97 |
end |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
98 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
99 |
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
|
100 |
"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
|
101 |
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
|
102 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
103 |
|
41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset
|
104 |
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
|
105 |
where |
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset
|
106 |
"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
|
107 |
|
42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset
|
108 |
|
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
|
109 |
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
|
110 |
|
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset
|
111 |
|
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
112 |
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
|
113 |
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
|
114 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
115 |
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
|
116 |
"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
|
117 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases 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 |
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
|
119 |
"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
|
120 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases 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 |
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
|
122 |
"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
|
123 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
124 |
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
|
125 |
"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
|
126 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
127 |
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
|
128 |
"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
|
129 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
130 |
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
|
131 |
"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
|
132 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
133 |
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
|
134 |
"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
|
135 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
136 |
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
|
137 |
"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
|
138 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
139 |
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
|
140 |
"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
|
141 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
142 |
|
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
143 |
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
|
144 |
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
|
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 |
end |
42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset
|
147 |
|
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
|
148 |
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
|
149 |
"(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
|
150 |
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
|
151 |
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
|
152 |
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
|
153 |
|
42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset
|
154 |
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
|
155 |
"(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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
|
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
|
160 |
|
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
161 |
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
|
162 |
[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
|
163 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
164 |
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
|
165 |
"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
|
166 |
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
|
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 |
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
|
169 |
"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
|
170 |
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
|
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 |
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
|
173 |
"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
|
174 |
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
|
175 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
176 |
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
|
177 |
"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
|
178 |
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
|
179 |
proof - |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
qed |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
187 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
188 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
189 |
code_instance code_numeral :: equal |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
190 |
(Haskell_Quickcheck -) |
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
191 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
192 |
setup {* fold (Numeral.add_code @{const_name number_code_int_inst.number_of_code_int} |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
193 |
false Code_Printer.literal_numeral) ["Haskell_Quickcheck"] *} |
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
194 |
|
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
|
195 |
code_const "0 \<Colon> code_int" |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
196 |
(Haskell_Quickcheck "0") |
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
|
197 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases 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 |
code_const "1 \<Colon> code_int" |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
199 |
(Haskell_Quickcheck "1") |
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
|
200 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
201 |
code_const "minus \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> code_int" |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
202 |
(Haskell_Quickcheck "(_/ -/ _)") |
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
|
203 |
|
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
204 |
code_const div_mod_code_int |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
205 |
(Haskell_Quickcheck "divMod") |
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
206 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
207 |
code_const "HOL.equal \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> bool" |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
208 |
(Haskell_Quickcheck infix 4 "==") |
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
209 |
|
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
|
210 |
code_const "op \<le> \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> bool" |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
211 |
(Haskell_Quickcheck infix 4 "<=") |
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
|
212 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
213 |
code_const "op < \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> bool" |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
214 |
(Haskell_Quickcheck infix 4 "<") |
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
|
215 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
216 |
code_type code_int |
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
217 |
(Haskell_Quickcheck "Int") |
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
|
218 |
|
42021
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
219 |
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
|
220 |
|
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
221 |
subsubsection {* Narrowing's deep representation of types and terms *} |
41905 | 222 |
|
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
|
223 |
datatype narrowing_type = SumOfProd "narrowing_type list list" |
41905 | 224 |
|
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
|
225 |
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
|
226 |
datatype 'a cons = C narrowing_type "(narrowing_term list => 'a) list" |
41905 | 227 |
|
42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset
|
228 |
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
|
229 |
|
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset
|
230 |
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
|
231 |
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
|
232 |
|
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
|
233 |
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
|
234 |
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
|
235 |
|
42980
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents:
42024
diff
changeset
|
236 |
|
41964
13904699c859
tuned subsubsection names in Quickcheck_Narrowing
bulwahn
parents:
41962
diff
changeset
|
237 |
subsubsection {* Auxilary functions for Narrowing *} |
41905 | 238 |
|
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
|
239 |
consts nth :: "'a list => code_int => 'a" |
41905 | 240 |
|
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
241 |
code_const nth (Haskell_Quickcheck infixl 9 "!!") |
41905 | 242 |
|
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
|
243 |
consts error :: "char list => 'a" |
41905 | 244 |
|
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
245 |
code_const error (Haskell_Quickcheck "error") |
41905 | 246 |
|
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
|
247 |
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
|
248 |
|
43308
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents:
43237
diff
changeset
|
249 |
code_const toEnum (Haskell_Quickcheck "toEnum") |
41905 | 250 |
|
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
|
251 |
consts map_index :: "(code_int * 'a => 'b) => 'a list => 'b list" |
41905 | 252 |
|
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
|
253 |
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
|
254 |
|
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
255 |
subsubsection {* Narrowing's basic operations *} |
41905 | 256 |
|
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
257 |
type_synonym 'a narrowing = "code_int => 'a cons" |
41905 | 258 |
|
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
259 |
definition empty :: "'a narrowing" |
41905 | 260 |
where |
261 |
"empty d = C (SumOfProd []) []" |
|
262 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
263 |
definition cons :: "'a => 'a narrowing" |
41905 | 264 |
where |
265 |
"cons a d = (C (SumOfProd [[]]) [(%_. a)])" |
|
266 |
||
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
|
267 |
fun conv :: "(narrowing_term list => 'a) list => narrowing_term => 'a" |
41905 | 268 |
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
|
269 |
"conv cs (Var p _) = error (Char Nibble0 Nibble0 # map toEnum p)" |
41905 | 270 |
| "conv cs (Ctr i xs) = (nth cs i) xs" |
271 |
||
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
|
272 |
fun nonEmpty :: "narrowing_type => bool" |
41905 | 273 |
where |
274 |
"nonEmpty (SumOfProd ps) = (\<not> (List.null ps))" |
|
275 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
276 |
definition "apply" :: "('a => 'b) narrowing => 'a narrowing => 'b narrowing" |
41905 | 277 |
where |
278 |
"apply f a d = |
|
279 |
(case f d of C (SumOfProd ps) cfs => |
|
280 |
case a (d - 1) of C ta cas => |
|
281 |
let |
|
282 |
shallow = (d > 0 \<and> nonEmpty ta); |
|
283 |
cs = [(%xs'. (case xs' of [] => undefined | x # xs => cf xs (conv cas x))). shallow, cf <- cfs] |
|
284 |
in C (SumOfProd [ta # p. shallow, p <- ps]) cs)" |
|
285 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
286 |
definition sum :: "'a narrowing => 'a narrowing => 'a narrowing" |
41905 | 287 |
where |
288 |
"sum a b d = |
|
289 |
(case a d of C (SumOfProd ssa) ca => |
|
290 |
case b d of C (SumOfProd ssb) cb => |
|
291 |
C (SumOfProd (ssa @ ssb)) (ca @ cb))" |
|
292 |
||
41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset
|
293 |
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
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
|
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
proof - |
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset
|
303 |
note assms moreover |
41930
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents:
41929
diff
changeset
|
304 |
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
|
305 |
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
|
306 |
moreover |
41930
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents:
41929
diff
changeset
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
qed |
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset
|
312 |
|
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
|
313 |
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
|
314 |
(* |
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
|
315 |
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
|
316 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
317 |
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
|
318 |
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
|
319 |
"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
|
320 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
321 |
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
|
322 |
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
|
323 |
"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
|
324 |
| "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
|
325 |
| "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
|
326 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
327 |
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
|
328 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
329 |
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
|
330 |
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
|
331 |
"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
|
332 |
| "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
|
333 |
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
|
334 |
|
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents:
41905
diff
changeset
|
335 |
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
|
336 |
*) |
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
337 |
subsubsection {* Narrowing generator type class *} |
41905 | 338 |
|
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
339 |
class narrowing = |
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
340 |
fixes narrowing :: "code_int => 'a cons" |
41905 | 341 |
|
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
342 |
definition cons1 :: "('a::narrowing => 'b) => 'b narrowing" |
41905 | 343 |
where |
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
344 |
"cons1 f = apply (cons f) narrowing" |
41905 | 345 |
|
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
346 |
definition cons2 :: "('a :: narrowing => 'b :: narrowing => 'c) => 'c narrowing" |
41905 | 347 |
where |
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
348 |
"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
|
349 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
350 |
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
|
351 |
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
|
352 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
353 |
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
|
354 |
begin |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
355 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
356 |
definition |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
357 |
"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
|
358 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
359 |
instance .. |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
360 |
|
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
361 |
end |
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents:
41965
diff
changeset
|
362 |
|
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
363 |
instantiation unit :: 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 = cons ()" |
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 bool :: narrowing |
41905 | 374 |
begin |
375 |
||
376 |
definition |
|
41965
328371f4f927
removing definition of cons0; hiding constants in Quickcheck_Narrowing
bulwahn
parents:
41964
diff
changeset
|
377 |
"narrowing = sum (cons True) (cons False)" |
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 option :: (narrowing) narrowing |
41905 | 384 |
begin |
385 |
||
386 |
definition |
|
41965
328371f4f927
removing definition of cons0; hiding constants in Quickcheck_Narrowing
bulwahn
parents:
41964
diff
changeset
|
387 |
"narrowing = sum (cons None) (cons1 Some)" |
41905 | 388 |
|
389 |
instance .. |
|
390 |
||
391 |
end |
|
392 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
393 |
instantiation sum :: (narrowing, narrowing) narrowing |
41905 | 394 |
begin |
395 |
||
396 |
definition |
|
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
397 |
"narrowing = sum (cons1 Inl) (cons1 Inr)" |
41905 | 398 |
|
399 |
instance .. |
|
400 |
||
401 |
end |
|
402 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
403 |
instantiation list :: (narrowing) narrowing |
41905 | 404 |
begin |
405 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
406 |
function narrowing_list :: "'a list narrowing" |
41905 | 407 |
where |
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
408 |
"narrowing_list d = sum (cons []) (apply (apply (cons Cons) narrowing) narrowing_list) d" |
41905 | 409 |
by pat_completeness auto |
410 |
||
41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset
|
411 |
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
|
412 |
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
|
413 |
|
41905 | 414 |
instance .. |
415 |
||
416 |
end |
|
417 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
418 |
instantiation nat :: narrowing |
41905 | 419 |
begin |
420 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
421 |
function narrowing_nat :: "nat narrowing" |
41905 | 422 |
where |
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
423 |
"narrowing_nat d = sum (cons 0) (apply (cons Suc) narrowing_nat) d" |
41905 | 424 |
by pat_completeness auto |
425 |
||
41912
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents:
41910
diff
changeset
|
426 |
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
|
427 |
qed (auto simp add: of_int_inverse nat_of_def) |
41905 | 428 |
|
429 |
instance .. |
|
430 |
||
431 |
end |
|
432 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
433 |
instantiation Enum.finite_1 :: narrowing |
41905 | 434 |
begin |
435 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
436 |
definition narrowing_finite_1 :: "Enum.finite_1 narrowing" |
41905 | 437 |
where |
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
438 |
"narrowing_finite_1 = cons (Enum.finite_1.a\<^isub>1 :: Enum.finite_1)" |
41905 | 439 |
|
440 |
instance .. |
|
441 |
||
442 |
end |
|
443 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
444 |
instantiation Enum.finite_2 :: narrowing |
41905 | 445 |
begin |
446 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
447 |
definition narrowing_finite_2 :: "Enum.finite_2 narrowing" |
41905 | 448 |
where |
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
449 |
"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 | 450 |
|
451 |
instance .. |
|
452 |
||
453 |
end |
|
454 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
455 |
instantiation Enum.finite_3 :: narrowing |
41905 | 456 |
begin |
457 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
458 |
definition narrowing_finite_3 :: "Enum.finite_3 narrowing" |
41905 | 459 |
where |
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
460 |
"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 | 461 |
|
462 |
instance .. |
|
463 |
||
464 |
end |
|
465 |
||
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
466 |
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
|
467 |
begin |
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset
|
468 |
|
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
469 |
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
|
470 |
where |
41961
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents:
41943
diff
changeset
|
471 |
"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
|
472 |
|
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset
|
473 |
instance .. |
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset
|
474 |
|
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset
|
475 |
end |
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset
|
476 |
|
43237
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
477 |
datatype property = Universal narrowing_type "(narrowing_term => property)" "narrowing_term => Code_Evaluation.term" | Existential narrowing_type "(narrowing_term => property)" "narrowing_term => Code_Evaluation.term" | Property bool |
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
478 |
|
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
479 |
(* FIXME: hard-wired maximal depth of 100 here *) |
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
480 |
fun exists :: "('a :: {narrowing, partial_term_of} => property) => property" |
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
481 |
where |
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
482 |
"exists f = (case narrowing (100 :: code_int) of C ty cs => Existential ty (\<lambda> t. f (conv cs t)) (partial_term_of (TYPE('a))))" |
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
483 |
|
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
484 |
fun "all" :: "('a :: {narrowing, partial_term_of} => property) => property" |
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
485 |
where |
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
486 |
"all f = (case narrowing (100 :: code_int) of C ty cs => Universal ty (\<lambda>t. f (conv cs t)) (partial_term_of (TYPE('a))))" |
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
487 |
|
41943 | 488 |
subsubsection {* class @{text is_testable} *} |
41905 | 489 |
|
41943 | 490 |
text {* The class @{text is_testable} ensures that all necessary type instances are generated. *} |
41905 | 491 |
|
492 |
class is_testable |
|
493 |
||
494 |
instance bool :: is_testable .. |
|
495 |
||
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
|
496 |
instance "fun" :: ("{term_of, narrowing, partial_term_of}", is_testable) is_testable .. |
41905 | 497 |
|
498 |
definition ensure_testable :: "'a :: is_testable => 'a :: is_testable" |
|
499 |
where |
|
500 |
"ensure_testable f = f" |
|
501 |
||
41910
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents:
41909
diff
changeset
|
502 |
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
|
503 |
|
42022
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset
|
504 |
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
|
505 |
|
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset
|
506 |
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
|
507 |
|
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset
|
508 |
primrec eval_ffun :: "('a, 'b) ffun => 'a => 'b" |
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset
|
509 |
where |
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset
|
510 |
"eval_ffun (Constant c) x = c" |
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset
|
511 |
| "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
|
512 |
|
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset
|
513 |
hide_type (open) ffun |
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset
|
514 |
hide_const (open) Constant Update eval_ffun |
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset
|
515 |
|
42024
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset
|
516 |
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
|
517 |
|
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset
|
518 |
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
|
519 |
where |
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset
|
520 |
"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
|
521 |
|
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset
|
522 |
hide_type (open) cfun |
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset
|
523 |
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
|
524 |
|
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset
|
525 |
subsubsection {* Setting up the counterexample generator *} |
43237
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
526 |
|
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
527 |
setup {* Thy_Load.provide_file (Path.explode ("~~/src/HOL/Tools/Quickcheck/PNF_Narrowing_Engine.hs")) *} |
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
528 |
setup {* Thy_Load.provide_file (Path.explode ("~~/src/HOL/Tools/Quickcheck/Narrowing_Engine.hs")) *} |
42024
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset
|
529 |
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
|
530 |
|
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset
|
531 |
setup {* Narrowing_Generators.setup *} |
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents:
42022
diff
changeset
|
532 |
|
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
|
533 |
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
|
534 |
hide_const (open) int_of of_int nth error toEnum map_index split_At empty |
43237
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents:
43047
diff
changeset
|
535 |
C cons conv nonEmpty "apply" sum cons1 cons2 ensure_testable all exists |
43314
a9090cabca14
adding a nicer error message for quickcheck_narrowing; hiding fact empty_def
bulwahn
parents:
43312
diff
changeset
|
536 |
hide_fact empty_def |
42022
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents:
42021
diff
changeset
|
537 |
|
41905 | 538 |
end |