| author | wenzelm | 
| Sat, 14 May 2011 12:40:11 +0200 | |
| changeset 42800 | df2dc9406287 | 
| parent 42024 | 51df23535105 | 
| child 42980 | 859fe9cc0838 | 
| permissions | -rw-r--r-- | 
| 41905 | 1 | (* Author: Lukas Bulwahn, TU Muenchen *) | 
| 2 | ||
| 41930 
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
 bulwahn parents: 
41929diff
changeset | 3 | header {* Counterexample generator preforming narrowing-based testing *}
 | 
| 41905 | 4 | |
| 41930 
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
 bulwahn parents: 
41929diff
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: 
41961diff
changeset | 7 | uses | 
| 
27a61a3266d8
correcting names in Narrowing_Engine and example theory for Quickcheck_Narrowing
 bulwahn parents: 
41961diff
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: 
41908diff
changeset | 13 | subsubsection {* Code generation setup *}
 | 
| 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
 bulwahn parents: 
41908diff
changeset | 14 | |
| 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
 bulwahn parents: 
41908diff
changeset | 15 | code_type typerep | 
| 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
 bulwahn parents: 
41908diff
changeset | 16 |   ("Haskell" "Typerep")
 | 
| 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
 bulwahn parents: 
41908diff
changeset | 17 | |
| 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
 bulwahn parents: 
41908diff
changeset | 18 | code_const Typerep.Typerep | 
| 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
 bulwahn parents: 
41908diff
changeset | 19 |   ("Haskell" "Typerep")
 | 
| 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
 bulwahn parents: 
41908diff
changeset | 20 | |
| 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
 bulwahn parents: 
41908diff
changeset | 21 | code_reserved Haskell Typerep | 
| 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
 bulwahn parents: 
41908diff
changeset | 22 | |
| 41964 
13904699c859
tuned subsubsection names in Quickcheck_Narrowing
 bulwahn parents: 
41962diff
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: 
41905diff
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: 
41905diff
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: 
41905diff
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: 
41905diff
changeset | 27 | |
| 42021 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
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: 
41965diff
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: 
41965diff
changeset | 31 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
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: 
41965diff
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: 
41965diff
changeset | 35 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
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: 
41965diff
changeset | 38 | proof | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
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: 
41965diff
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: 
41965diff
changeset | 42 | next | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
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: 
41965diff
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: 
41965diff
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: 
41965diff
changeset | 47 | qed | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 48 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41905diff
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: 
41905diff
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: 
41905diff
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: 
41905diff
changeset | 53 | |
| 42021 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
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: 
41965diff
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: 
41965diff
changeset | 57 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
changeset | 59 | begin | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 60 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 61 | definition | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
changeset | 63 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 64 | instance proof | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
changeset | 66 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 67 | end | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 68 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
changeset | 70 | begin | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 71 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 72 | definition | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
changeset | 74 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 75 | instance .. | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 76 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 77 | end | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 78 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
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: 
41965diff
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: 
41965diff
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: 
41965diff
changeset | 82 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 83 | |
| 41912 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
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: 
41910diff
changeset | 85 | where | 
| 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
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: 
41905diff
changeset | 87 | |
| 42021 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 88 | 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: 
41905diff
changeset | 89 | 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: 
41905diff
changeset | 90 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 91 | 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: 
41905diff
changeset | 92 | "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: 
41905diff
changeset | 93 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 94 | 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: 
41905diff
changeset | 95 | "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: 
41905diff
changeset | 96 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 97 | 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: 
41965diff
changeset | 98 | "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: 
41965diff
changeset | 99 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 100 | 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: 
41905diff
changeset | 101 | "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: 
41905diff
changeset | 102 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 103 | 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: 
41965diff
changeset | 104 | "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: 
41965diff
changeset | 105 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 106 | definition [simp, code del]: | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 107 | "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: 
41965diff
changeset | 108 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 109 | definition [simp, code del]: | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 110 | "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: 
41965diff
changeset | 111 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 112 | 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: 
41905diff
changeset | 113 | "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: 
41905diff
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: 
41905diff
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: 
41905diff
changeset | 116 | "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: 
41905diff
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: 
41905diff
changeset | 118 | |
| 42021 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 119 | instance proof | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 120 | 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: 
41905diff
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: 
41905diff
changeset | 122 | end | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 123 | (* | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 124 | 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: 
41905diff
changeset | 125 | "(0\<Colon>code_int) = Numeral0" | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 126 | by (simp add: number_of_code_numeral_def Pls_def) | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 127 | lemma [code_post]: "Numeral0 = (0\<Colon>code_numeral)" | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 128 | using zero_code_numeral_code .. | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 129 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 130 | lemma one_code_numeral_code [code, code_unfold]: | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 131 | "(1\<Colon>code_int) = Numeral1" | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 132 | by (simp add: number_of_code_numeral_def Pls_def Bit1_def) | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 133 | lemma [code_post]: "Numeral1 = (1\<Colon>code_int)" | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 134 | using one_code_numeral_code .. | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 135 | *) | 
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 136 | |
| 42021 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 137 | 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: 
41965diff
changeset | 138 | [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: 
41965diff
changeset | 139 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 140 | lemma [code]: | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 141 | "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: 
41965diff
changeset | 142 | 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: 
41965diff
changeset | 143 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 144 | lemma [code]: | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 145 | "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: 
41965diff
changeset | 146 | 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: 
41965diff
changeset | 147 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 148 | lemma [code]: | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 149 | "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: 
41965diff
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: 
41965diff
changeset | 151 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 152 | 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: 
41965diff
changeset | 153 | "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: 
41965diff
changeset | 154 | 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: 
41965diff
changeset | 155 | proof - | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 156 | 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: 
41965diff
changeset | 157 | 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: 
41965diff
changeset | 158 | 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: 
41965diff
changeset | 159 | from this show ?thesis | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 160 | apply auto | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 161 | 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: 
41965diff
changeset | 162 | qed | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 163 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 164 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 165 | 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: 
41965diff
changeset | 166 | (Haskell -) | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 167 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 168 | 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: 
41965diff
changeset | 169 | 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: 
41965diff
changeset | 170 | |
| 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: 
41905diff
changeset | 171 | 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: 
41905diff
changeset | 172 | (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: 
41905diff
changeset | 173 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 174 | 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: 
41905diff
changeset | 175 | (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: 
41905diff
changeset | 176 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 177 | 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: 
41905diff
changeset | 178 | (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: 
41905diff
changeset | 179 | |
| 42021 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 180 | 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: 
41965diff
changeset | 181 | (Haskell "divMod") | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 182 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 183 | 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: 
41965diff
changeset | 184 | (Haskell infix 4 "==") | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 185 | |
| 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: 
41905diff
changeset | 186 | 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: 
41905diff
changeset | 187 | (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: 
41905diff
changeset | 188 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 189 | 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: 
41905diff
changeset | 190 | (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: 
41905diff
changeset | 191 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 192 | 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: 
41905diff
changeset | 193 | (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: 
41905diff
changeset | 194 | |
| 42021 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 195 | code_abort of_int | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 196 | |
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 197 | subsubsection {* Narrowing's deep representation of types and terms *}
 | 
| 41905 | 198 | |
| 199 | datatype type = SumOfProd "type list list" | |
| 200 | ||
| 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: 
41905diff
changeset | 201 | datatype "term" = Var "code_int list" type | Ctr code_int "term list" | 
| 41905 | 202 | |
| 203 | datatype 'a cons = C type "(term list => 'a) list" | |
| 204 | ||
| 41964 
13904699c859
tuned subsubsection names in Quickcheck_Narrowing
 bulwahn parents: 
41962diff
changeset | 205 | subsubsection {* Auxilary functions for Narrowing *}
 | 
| 41905 | 206 | |
| 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: 
41905diff
changeset | 207 | consts nth :: "'a list => code_int => 'a" | 
| 41905 | 208 | |
| 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: 
41905diff
changeset | 209 | code_const nth ("Haskell" infixl 9  "!!")
 | 
| 41905 | 210 | |
| 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: 
41905diff
changeset | 211 | consts error :: "char list => 'a" | 
| 41905 | 212 | |
| 213 | code_const error ("Haskell" "error")
 | |
| 214 | ||
| 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: 
41905diff
changeset | 215 | 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: 
41905diff
changeset | 216 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 217 | code_const toEnum ("Haskell" "toEnum")
 | 
| 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: 
41905diff
changeset | 219 | consts map_index :: "(code_int * 'a => 'b) => 'a list => 'b list" | 
| 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: 
41905diff
changeset | 221 | 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: 
41905diff
changeset | 222 | |
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 223 | subsubsection {* Narrowing's basic operations *}
 | 
| 41905 | 224 | |
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 225 | type_synonym 'a narrowing = "code_int => 'a cons" | 
| 41905 | 226 | |
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 227 | definition empty :: "'a narrowing" | 
| 41905 | 228 | where | 
| 229 | "empty d = C (SumOfProd []) []" | |
| 230 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 231 | definition cons :: "'a => 'a narrowing" | 
| 41905 | 232 | where | 
| 233 | "cons a d = (C (SumOfProd [[]]) [(%_. a)])" | |
| 234 | ||
| 235 | fun conv :: "(term list => 'a) list => term => 'a" | |
| 236 | 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: 
41905diff
changeset | 237 | "conv cs (Var p _) = error (Char Nibble0 Nibble0 # map toEnum p)" | 
| 41905 | 238 | | "conv cs (Ctr i xs) = (nth cs i) xs" | 
| 239 | ||
| 240 | fun nonEmpty :: "type => bool" | |
| 241 | where | |
| 242 | "nonEmpty (SumOfProd ps) = (\<not> (List.null ps))" | |
| 243 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 244 | definition "apply" :: "('a => 'b) narrowing => 'a narrowing => 'b narrowing"
 | 
| 41905 | 245 | where | 
| 246 | "apply f a d = | |
| 247 | (case f d of C (SumOfProd ps) cfs => | |
| 248 | case a (d - 1) of C ta cas => | |
| 249 | let | |
| 250 | shallow = (d > 0 \<and> nonEmpty ta); | |
| 251 | cs = [(%xs'. (case xs' of [] => undefined | x # xs => cf xs (conv cas x))). shallow, cf <- cfs] | |
| 252 | in C (SumOfProd [ta # p. shallow, p <- ps]) cs)" | |
| 253 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 254 | definition sum :: "'a narrowing => 'a narrowing => 'a narrowing" | 
| 41905 | 255 | where | 
| 256 | "sum a b d = | |
| 257 | (case a d of C (SumOfProd ssa) ca => | |
| 258 | case b d of C (SumOfProd ssb) cb => | |
| 259 | C (SumOfProd (ssa @ ssb)) (ca @ cb))" | |
| 260 | ||
| 41912 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 261 | lemma [fundef_cong]: | 
| 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 262 | 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: 
41910diff
changeset | 263 | shows "sum a b d = sum a' b' d'" | 
| 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 264 | using assms unfolding sum_def by (auto split: cons.split type.split) | 
| 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 265 | |
| 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 266 | lemma [fundef_cong]: | 
| 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 267 | 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: 
41910diff
changeset | 268 | assumes "d = d'" | 
| 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 269 | 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: 
41910diff
changeset | 270 | proof - | 
| 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 271 | note assms moreover | 
| 41930 
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
 bulwahn parents: 
41929diff
changeset | 272 | 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: 
41910diff
changeset | 273 | 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: 
41910diff
changeset | 274 | moreover | 
| 41930 
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
 bulwahn parents: 
41929diff
changeset | 275 | 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: 
41910diff
changeset | 276 | 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: 
41910diff
changeset | 277 | ultimately show ?thesis | 
| 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 278 | unfolding apply_def by (auto split: cons.split type.split simp add: Let_def) | 
| 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 279 | qed | 
| 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 280 | |
| 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: 
41905diff
changeset | 281 | 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: 
41910diff
changeset | 282 | (* | 
| 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: 
41905diff
changeset | 283 | 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: 
41905diff
changeset | 284 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 285 | 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: 
41905diff
changeset | 286 | 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: 
41905diff
changeset | 287 | "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: 
41905diff
changeset | 288 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 289 | 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: 
41905diff
changeset | 290 | 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: 
41905diff
changeset | 291 | "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: 
41905diff
changeset | 292 | | "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: 
41905diff
changeset | 293 | | "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: 
41905diff
changeset | 294 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 295 | 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: 
41905diff
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: 
41905diff
changeset | 297 | 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: 
41905diff
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: 
41905diff
changeset | 299 | "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: 
41905diff
changeset | 300 | | "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: 
41905diff
changeset | 301 | 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: 
41905diff
changeset | 302 | |
| 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 bulwahn parents: 
41905diff
changeset | 303 | termination sorry | 
| 41912 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 304 | *) | 
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 305 | subsubsection {* Narrowing generator type class *}
 | 
| 41905 | 306 | |
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 307 | class narrowing = | 
| 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 308 | fixes narrowing :: "code_int => 'a cons" | 
| 41905 | 309 | |
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 310 | definition cons1 :: "('a::narrowing => 'b) => 'b narrowing"
 | 
| 41905 | 311 | where | 
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 312 | "cons1 f = apply (cons f) narrowing" | 
| 41905 | 313 | |
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 314 | definition cons2 :: "('a :: narrowing => 'b :: narrowing => 'c) => 'c narrowing"
 | 
| 41905 | 315 | where | 
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 316 | "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: 
41965diff
changeset | 317 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 318 | 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: 
41965diff
changeset | 319 | 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: 
41965diff
changeset | 320 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 321 | instantiation int :: narrowing | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 322 | begin | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 323 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 324 | definition | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 325 | "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: 
41965diff
changeset | 326 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 327 | instance .. | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 328 | |
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 329 | end | 
| 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 bulwahn parents: 
41965diff
changeset | 330 | |
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 331 | instantiation unit :: narrowing | 
| 41905 | 332 | begin | 
| 333 | ||
| 334 | definition | |
| 41965 
328371f4f927
removing definition of cons0; hiding constants in Quickcheck_Narrowing
 bulwahn parents: 
41964diff
changeset | 335 | "narrowing = cons ()" | 
| 41905 | 336 | |
| 337 | instance .. | |
| 338 | ||
| 339 | end | |
| 340 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 341 | instantiation bool :: narrowing | 
| 41905 | 342 | begin | 
| 343 | ||
| 344 | definition | |
| 41965 
328371f4f927
removing definition of cons0; hiding constants in Quickcheck_Narrowing
 bulwahn parents: 
41964diff
changeset | 345 | "narrowing = sum (cons True) (cons False)" | 
| 41905 | 346 | |
| 347 | instance .. | |
| 348 | ||
| 349 | end | |
| 350 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 351 | instantiation option :: (narrowing) narrowing | 
| 41905 | 352 | begin | 
| 353 | ||
| 354 | definition | |
| 41965 
328371f4f927
removing definition of cons0; hiding constants in Quickcheck_Narrowing
 bulwahn parents: 
41964diff
changeset | 355 | "narrowing = sum (cons None) (cons1 Some)" | 
| 41905 | 356 | |
| 357 | instance .. | |
| 358 | ||
| 359 | end | |
| 360 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 361 | instantiation sum :: (narrowing, narrowing) narrowing | 
| 41905 | 362 | begin | 
| 363 | ||
| 364 | definition | |
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 365 | "narrowing = sum (cons1 Inl) (cons1 Inr)" | 
| 41905 | 366 | |
| 367 | instance .. | |
| 368 | ||
| 369 | end | |
| 370 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 371 | instantiation list :: (narrowing) narrowing | 
| 41905 | 372 | begin | 
| 373 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 374 | function narrowing_list :: "'a list narrowing" | 
| 41905 | 375 | where | 
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 376 | "narrowing_list d = sum (cons []) (apply (apply (cons Cons) narrowing) narrowing_list) d" | 
| 41905 | 377 | by pat_completeness auto | 
| 378 | ||
| 41912 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 379 | 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: 
41910diff
changeset | 380 | 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: 
41910diff
changeset | 381 | |
| 41905 | 382 | instance .. | 
| 383 | ||
| 384 | end | |
| 385 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 386 | instantiation nat :: narrowing | 
| 41905 | 387 | begin | 
| 388 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 389 | function narrowing_nat :: "nat narrowing" | 
| 41905 | 390 | where | 
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 391 | "narrowing_nat d = sum (cons 0) (apply (cons Suc) narrowing_nat) d" | 
| 41905 | 392 | by pat_completeness auto | 
| 393 | ||
| 41912 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 bulwahn parents: 
41910diff
changeset | 394 | 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: 
41910diff
changeset | 395 | qed (auto simp add: of_int_inverse nat_of_def) | 
| 41905 | 396 | |
| 397 | instance .. | |
| 398 | ||
| 399 | end | |
| 400 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 401 | instantiation Enum.finite_1 :: narrowing | 
| 41905 | 402 | begin | 
| 403 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 404 | definition narrowing_finite_1 :: "Enum.finite_1 narrowing" | 
| 41905 | 405 | where | 
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 406 | "narrowing_finite_1 = cons (Enum.finite_1.a\<^isub>1 :: Enum.finite_1)" | 
| 41905 | 407 | |
| 408 | instance .. | |
| 409 | ||
| 410 | end | |
| 411 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 412 | instantiation Enum.finite_2 :: narrowing | 
| 41905 | 413 | begin | 
| 414 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 415 | definition narrowing_finite_2 :: "Enum.finite_2 narrowing" | 
| 41905 | 416 | where | 
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 417 | "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 | 418 | |
| 419 | instance .. | |
| 420 | ||
| 421 | end | |
| 422 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 423 | instantiation Enum.finite_3 :: narrowing | 
| 41905 | 424 | begin | 
| 425 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 426 | definition narrowing_finite_3 :: "Enum.finite_3 narrowing" | 
| 41905 | 427 | where | 
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 428 | "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 | 429 | |
| 430 | instance .. | |
| 431 | ||
| 432 | end | |
| 433 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 434 | instantiation Enum.finite_4 :: narrowing | 
| 41910 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
 bulwahn parents: 
41909diff
changeset | 435 | begin | 
| 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
 bulwahn parents: 
41909diff
changeset | 436 | |
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 437 | 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: 
41909diff
changeset | 438 | where | 
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 439 | "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: 
41909diff
changeset | 440 | |
| 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
 bulwahn parents: 
41909diff
changeset | 441 | instance .. | 
| 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
 bulwahn parents: 
41909diff
changeset | 442 | |
| 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
 bulwahn parents: 
41909diff
changeset | 443 | end | 
| 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
 bulwahn parents: 
41909diff
changeset | 444 | |
| 41943 | 445 | subsubsection {* class @{text is_testable} *}
 | 
| 41905 | 446 | |
| 41943 | 447 | text {* The class @{text is_testable} ensures that all necessary type instances are generated. *}
 | 
| 41905 | 448 | |
| 449 | class is_testable | |
| 450 | ||
| 451 | instance bool :: is_testable .. | |
| 452 | ||
| 41961 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 bulwahn parents: 
41943diff
changeset | 453 | instance "fun" :: ("{term_of, narrowing}", is_testable) is_testable ..
 | 
| 41905 | 454 | |
| 455 | definition ensure_testable :: "'a :: is_testable => 'a :: is_testable" | |
| 456 | where | |
| 457 | "ensure_testable f = f" | |
| 458 | ||
| 41910 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
 bulwahn parents: 
41909diff
changeset | 459 | declare simp_thms(17,19)[code del] | 
| 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
 bulwahn parents: 
41909diff
changeset | 460 | |
| 42022 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 bulwahn parents: 
42021diff
changeset | 461 | 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: 
42021diff
changeset | 462 | |
| 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 bulwahn parents: 
42021diff
changeset | 463 | 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: 
42021diff
changeset | 464 | |
| 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 bulwahn parents: 
42021diff
changeset | 465 | primrec eval_ffun :: "('a, 'b) ffun => 'a => 'b"
 | 
| 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 bulwahn parents: 
42021diff
changeset | 466 | where | 
| 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 bulwahn parents: 
42021diff
changeset | 467 | "eval_ffun (Constant c) x = c" | 
| 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 bulwahn parents: 
42021diff
changeset | 468 | | "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: 
42021diff
changeset | 469 | |
| 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 bulwahn parents: 
42021diff
changeset | 470 | hide_type (open) ffun | 
| 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 bulwahn parents: 
42021diff
changeset | 471 | hide_const (open) Constant Update eval_ffun | 
| 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 bulwahn parents: 
42021diff
changeset | 472 | |
| 42024 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 473 | datatype 'b cfun = Constant 'b | 
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 474 | |
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 475 | primrec eval_cfun :: "'b cfun => 'a => 'b" | 
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 476 | where | 
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 477 | "eval_cfun (Constant c) y = c" | 
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 478 | |
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 479 | hide_type (open) cfun | 
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 480 | hide_const (open) Constant eval_cfun | 
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 481 | |
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 482 | subsubsection {* Setting up the counterexample generator *}
 | 
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 483 | |
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 484 | 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: 
42022diff
changeset | 485 | |
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 486 | setup {* Narrowing_Generators.setup *}
 | 
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 487 | |
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 488 | hide_type (open) code_int type "term" cons | 
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 489 | hide_const (open) int_of of_int nth error toEnum map_index split_At empty | 
| 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 bulwahn parents: 
42022diff
changeset | 490 | cons conv nonEmpty "apply" sum cons1 cons2 ensure_testable | 
| 42022 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 bulwahn parents: 
42021diff
changeset | 491 | |
| 41905 | 492 | end |