src/HOL/Quickcheck_Narrowing.thy
author wenzelm
Sat, 07 Apr 2012 16:41:59 +0200
changeset 47389 e8552cba702d
parent 47108 2a1953f0d20d
child 48253 4410a709913c
permissions -rw-r--r--
explicit checks stable_finished_theory/stable_command allow parallel asynchronous command transactions; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
     1
(* Author: Lukas Bulwahn, TU Muenchen *)
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
     2
43356
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
     3
header {* Counterexample generator performing narrowing-based testing *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
     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
46950
d0181abdbdac declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents: 46758
diff changeset
     7
keywords "find_unused_assms" :: diag
41962
27a61a3266d8 correcting names in Narrowing_Engine and example theory for Quickcheck_Narrowing
bulwahn
parents: 41961
diff changeset
     8
uses
43702
24fb44c1086a more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents: 43562
diff changeset
     9
  ("Tools/Quickcheck/PNF_Narrowing_Engine.hs")
24fb44c1086a more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents: 43562
diff changeset
    10
  ("Tools/Quickcheck/Narrowing_Engine.hs")
24fb44c1086a more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents: 43562
diff changeset
    11
  ("Tools/Quickcheck/narrowing_generators.ML")
46589
689311986778 adding new command "find_unused_assms"
bulwahn
parents: 46308
diff changeset
    12
  ("Tools/Quickcheck/find_unused_assms.ML")
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    13
begin
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    14
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    15
subsection {* Counterexample generator *}
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    16
43308
fd6cc1378fec compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents: 43237
diff changeset
    17
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
    18
fd6cc1378fec compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents: 43237
diff changeset
    19
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
    20
41909
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    21
subsubsection {* Code generation setup *}
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    22
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    23
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
    24
  (Haskell_Quickcheck "Typerep")
41909
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    25
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    26
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
    27
  (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
43308
fd6cc1378fec compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents: 43237
diff changeset
    29
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
    30
43341
acdac535c7fa fixed document generation for HOL
hoelzl
parents: 43317
diff changeset
    31
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
    32
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    33
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
    34
  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
    35
42021
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    36
lemma 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
    37
  "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
    38
  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
    39
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    40
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
    41
  "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
    42
  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
    43
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    44
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
    45
  "(\<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
    46
proof
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    47
  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
    48
  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
    49
  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
    50
next
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    51
  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
    52
  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
    53
  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
    54
  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
    55
qed
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    56
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    57
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
    58
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
    59
  "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
    60
  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
    61
42021
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    62
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
    63
  "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
    64
  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
    65
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    66
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
    67
begin
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
definition
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    70
  "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
    71
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    72
instance proof
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
    73
qed (auto simp add: equal_code_int_def equal_int_def equal_int_refl)
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
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    75
end
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    76
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
    77
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
    78
where
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
    79
  "nat_of i = nat (int_of i)"
42980
859fe9cc0838 improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents: 42024
diff changeset
    80
  
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
    81
instantiation code_int :: "{minus, linordered_semidom, semiring_div, neg_numeral, 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
    82
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
    83
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    84
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
    85
  "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
    86
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    87
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
    88
  "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
    89
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    90
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
    91
  "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
    92
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
    93
definition [simp, code del]:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
    94
  "- n = of_int (- int_of n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
    95
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
    96
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
    97
  "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
    98
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    99
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
   100
  "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
   101
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   102
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
   103
  "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
   104
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   105
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
   106
  "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
   107
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   108
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
   109
  "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
   110
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   111
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
   112
  "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
   113
42021
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   114
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
   115
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
   116
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases 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
end
42980
859fe9cc0838 improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents: 42024
diff changeset
   118
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   119
lemma int_of_numeral [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   120
  "int_of (numeral k) = numeral k"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   121
  by (induct k) (simp_all only: numeral.simps plus_code_int_def
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   122
    one_code_int_def of_int_inverse UNIV_I)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   123
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   124
definition Num :: "num \<Rightarrow> code_int"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   125
  where [code_abbrev]: "Num = numeral"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   126
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   127
lemma [code_abbrev]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   128
  "- numeral k = (neg_numeral k :: code_int)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   129
  by (unfold neg_numeral_def) simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   130
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   131
code_datatype "0::code_int" Num
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
   132
42980
859fe9cc0838 improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents: 42024
diff changeset
   133
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
   134
  "(1\<Colon>code_int) = Numeral1"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   135
  by (simp only: numeral.simps)
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
   136
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   137
definition div_mod :: "code_int \<Rightarrow> code_int \<Rightarrow> code_int \<times> code_int" where
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   138
  [code del]: "div_mod n m = (n div m, n mod m)"
42021
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   139
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   140
lemma [code]:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   141
  "div_mod n m = (if m = 0 then (0, n) else (n div m, n mod m))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   142
  unfolding div_mod_def by auto
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
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   144
lemma [code]:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   145
  "n div m = fst (div_mod n m)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   146
  unfolding div_mod_def by simp
42021
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   147
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   148
lemma [code]:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   149
  "n mod m = snd (div_mod n m)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   150
  unfolding div_mod_def by simp
42021
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   151
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   152
lemma 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
   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: 41965
diff 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: 41965
diff changeset
   155
proof -
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff 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: 41965
diff 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: 41965
diff 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: 41965
diff 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: 41965
diff changeset
   160
    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
   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: 41965
diff changeset
   162
qed
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
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   165
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
   166
  (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
   167
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   168
setup {* fold (Numeral.add_code @{const_name Num}
43308
fd6cc1378fec compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents: 43237
diff changeset
   169
  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
   170
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   171
code_type code_int
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   172
  (Haskell_Quickcheck "Int")
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   173
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
   174
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
   175
  (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
   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: 41905
diff changeset
   177
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
   178
  (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
   179
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   180
code_const "minus \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> code_int"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   181
  (Haskell_Quickcheck infixl 6 "-")
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
   182
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   183
code_const div_mod
43308
fd6cc1378fec compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents: 43237
diff changeset
   184
  (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
   185
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   186
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
   187
  (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
   188
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   189
code_const "less_eq \<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
   190
  (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
   191
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   192
code_const "less \<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
   193
  (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
   194
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   195
code_abort of_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
   196
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46950
diff changeset
   197
hide_const (open) Num div_mod
42021
52551c0a3374 extending code_int type more; adding narrowing instance for type int; added test case for int instance
bulwahn
parents: 41965
diff changeset
   198
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   199
subsubsection {* Narrowing's deep representation of types and terms *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   200
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   201
datatype narrowing_type = Narrowing_sum_of_products "narrowing_type list list"
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   202
datatype narrowing_term = Narrowing_variable "code_int list" narrowing_type | Narrowing_constructor code_int "narrowing_term list"
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   203
datatype 'a narrowing_cons = Narrowing_cons narrowing_type "(narrowing_term list => 'a) list"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   204
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   205
primrec map_cons :: "('a => 'b) => 'a narrowing_cons => 'b narrowing_cons"
43356
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   206
where
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   207
  "map_cons f (Narrowing_cons ty cs) = Narrowing_cons ty (map (%c. f o c) cs)"
43356
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   208
43341
acdac535c7fa fixed document generation for HOL
hoelzl
parents: 43317
diff changeset
   209
subsubsection {* From narrowing's deep representation of terms to @{theory Code_Evaluation}'s terms *}
42980
859fe9cc0838 improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents: 42024
diff changeset
   210
859fe9cc0838 improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
bulwahn
parents: 42024
diff changeset
   211
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
   212
  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
   213
26774ccb1c74 automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents: 42980
diff changeset
   214
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
   215
  by (rule eq_reflection) (cases "partial_term_of x nt", cases t, simp)
43356
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   216
 
41964
13904699c859 tuned subsubsection names in Quickcheck_Narrowing
bulwahn
parents: 41962
diff changeset
   217
subsubsection {* Auxilary functions for Narrowing *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   218
41908
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   219
consts nth :: "'a list => code_int => 'a"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   220
43308
fd6cc1378fec compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents: 43237
diff changeset
   221
code_const nth (Haskell_Quickcheck infixl 9  "!!")
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   222
41908
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   223
consts error :: "char list => 'a"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   224
43308
fd6cc1378fec compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents: 43237
diff changeset
   225
code_const error (Haskell_Quickcheck "error")
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   226
41908
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   227
consts toEnum :: "code_int => char"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   228
43308
fd6cc1378fec compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
bulwahn
parents: 43237
diff changeset
   229
code_const toEnum (Haskell_Quickcheck "toEnum")
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   230
43316
3e274608f06b removing char setup
bulwahn
parents: 43315
diff changeset
   231
consts marker :: "char"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   232
43316
3e274608f06b removing char setup
bulwahn
parents: 43315
diff changeset
   233
code_const marker (Haskell_Quickcheck "''\\0'")
3e274608f06b removing char setup
bulwahn
parents: 43315
diff changeset
   234
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   235
subsubsection {* Narrowing's basic operations *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   236
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   237
type_synonym 'a narrowing = "code_int => 'a narrowing_cons"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   238
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   239
definition empty :: "'a narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   240
where
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   241
  "empty d = Narrowing_cons (Narrowing_sum_of_products []) []"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   242
  
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   243
definition cons :: "'a => 'a narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   244
where
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   245
  "cons a d = (Narrowing_cons (Narrowing_sum_of_products [[]]) [(%_. a)])"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   246
43047
26774ccb1c74 automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
bulwahn
parents: 42980
diff changeset
   247
fun conv :: "(narrowing_term list => 'a) list => narrowing_term => 'a"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   248
where
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   249
  "conv cs (Narrowing_variable p _) = error (marker # map toEnum p)"
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   250
| "conv cs (Narrowing_constructor i xs) = (nth cs i) xs"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   251
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   252
fun non_empty :: "narrowing_type => bool"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   253
where
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   254
  "non_empty (Narrowing_sum_of_products ps) = (\<not> (List.null ps))"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   255
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   256
definition "apply" :: "('a => 'b) narrowing => 'a narrowing => 'b narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   257
where
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   258
  "apply f a d =
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   259
     (case f d of Narrowing_cons (Narrowing_sum_of_products ps) cfs =>
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   260
       case a (d - 1) of Narrowing_cons ta cas =>
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   261
       let
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   262
         shallow = (d > 0 \<and> non_empty ta);
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   263
         cs = [(%xs'. (case xs' of [] => undefined | x # xs => cf xs (conv cas x))). shallow, cf <- cfs]
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   264
       in Narrowing_cons (Narrowing_sum_of_products [ta # p. shallow, p <- ps]) cs)"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   265
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   266
definition sum :: "'a narrowing => 'a narrowing => 'a narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   267
where
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   268
  "sum a b d =
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   269
    (case a d of Narrowing_cons (Narrowing_sum_of_products ssa) ca => 
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   270
      case b d of Narrowing_cons (Narrowing_sum_of_products ssb) cb =>
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   271
      Narrowing_cons (Narrowing_sum_of_products (ssa @ ssb)) (ca @ cb))"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   272
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   273
lemma [fundef_cong]:
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   274
  assumes "a d = a' d" "b d = b' d" "d = d'"
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   275
  shows "sum a b d = sum a' b' d'"
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   276
using assms unfolding sum_def by (auto split: narrowing_cons.split narrowing_type.split)
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   277
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   278
lemma [fundef_cong]:
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   279
  assumes "f d = f' d" "(\<And>d'. 0 <= d' & d' < d ==> a d' = a' d')"
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   280
  assumes "d = d'"
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   281
  shows "apply f a d = apply f' a' d'"
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   282
proof -
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   283
  note assms moreover
41930
1e008cc4883a renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents: 41929
diff changeset
   284
  have "int_of (of_int 0) < int_of d' ==> int_of (of_int 0) <= int_of (of_int (int_of d' - int_of (of_int 1)))"
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   285
    by (simp add: of_int_inverse)
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   286
  moreover
41930
1e008cc4883a renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents: 41929
diff changeset
   287
  have "int_of (of_int (int_of d' - int_of (of_int 1))) < int_of d'"
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   288
    by (simp add: of_int_inverse)
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   289
  ultimately show ?thesis
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   290
    unfolding apply_def by (auto split: narrowing_cons.split narrowing_type.split simp add: Let_def)
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   291
qed
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   292
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   293
subsubsection {* Narrowing generator type class *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   294
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   295
class narrowing =
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   296
  fixes narrowing :: "code_int => 'a narrowing_cons"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   297
43237
8f5c3c6c2909 adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents: 43047
diff changeset
   298
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
   299
8f5c3c6c2909 adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents: 43047
diff changeset
   300
(* FIXME: hard-wired maximal depth of 100 here *)
43315
893de45ac28d removing unneccessary manual instantiations and dead definitions; hiding more constants and facts
bulwahn
parents: 43314
diff changeset
   301
definition exists :: "('a :: {narrowing, partial_term_of} => property) => property"
43237
8f5c3c6c2909 adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents: 43047
diff changeset
   302
where
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   303
  "exists f = (case narrowing (100 :: code_int) of Narrowing_cons ty cs => Existential ty (\<lambda> t. f (conv cs t)) (partial_term_of (TYPE('a))))"
43237
8f5c3c6c2909 adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents: 43047
diff changeset
   304
43315
893de45ac28d removing unneccessary manual instantiations and dead definitions; hiding more constants and facts
bulwahn
parents: 43314
diff changeset
   305
definition "all" :: "('a :: {narrowing, partial_term_of} => property) => property"
43237
8f5c3c6c2909 adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents: 43047
diff changeset
   306
where
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   307
  "all f = (case narrowing (100 :: code_int) of Narrowing_cons ty cs => Universal ty (\<lambda>t. f (conv cs t)) (partial_term_of (TYPE('a))))"
43237
8f5c3c6c2909 adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents: 43047
diff changeset
   308
41943
12f24ad566ea fixed document;
wenzelm
parents: 41930
diff changeset
   309
subsubsection {* class @{text is_testable} *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   310
41943
12f24ad566ea fixed document;
wenzelm
parents: 41930
diff changeset
   311
text {* The class @{text is_testable} ensures that all necessary type instances are generated. *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   312
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   313
class is_testable
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   314
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   315
instance bool :: is_testable ..
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   316
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
   317
instance "fun" :: ("{term_of, narrowing, partial_term_of}", is_testable) is_testable ..
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   318
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   319
definition ensure_testable :: "'a :: is_testable => 'a :: is_testable"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   320
where
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   321
  "ensure_testable f = f"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   322
41910
709c04e7b703 adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents: 41909
diff changeset
   323
42022
101ce92333f4 adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents: 42021
diff changeset
   324
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
   325
101ce92333f4 adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents: 42021
diff changeset
   326
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
   327
101ce92333f4 adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents: 42021
diff changeset
   328
primrec eval_ffun :: "('a, 'b) ffun => 'a => 'b"
101ce92333f4 adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents: 42021
diff changeset
   329
where
101ce92333f4 adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents: 42021
diff changeset
   330
  "eval_ffun (Constant c) x = c"
101ce92333f4 adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents: 42021
diff changeset
   331
| "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
   332
101ce92333f4 adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents: 42021
diff changeset
   333
hide_type (open) ffun
101ce92333f4 adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents: 42021
diff changeset
   334
hide_const (open) Constant Update eval_ffun
101ce92333f4 adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents: 42021
diff changeset
   335
42024
51df23535105 handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents: 42022
diff changeset
   336
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
   337
51df23535105 handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents: 42022
diff changeset
   338
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
   339
where
51df23535105 handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents: 42022
diff changeset
   340
  "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
   341
51df23535105 handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents: 42022
diff changeset
   342
hide_type (open) cfun
45734
1024dd30da42 hide quickcheck constants Abs_cfun and Rep_cfun, to avoid clash with HOLCF
huffman
parents: 45001
diff changeset
   343
hide_const (open) Constant eval_cfun Abs_cfun Rep_cfun
42024
51df23535105 handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents: 42022
diff changeset
   344
51df23535105 handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents: 42022
diff changeset
   345
subsubsection {* Setting up the counterexample generator *}
43237
8f5c3c6c2909 adding compilation that allows existentials in Quickcheck_Narrowing
bulwahn
parents: 43047
diff changeset
   346
43702
24fb44c1086a more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents: 43562
diff changeset
   347
use "Tools/Quickcheck/narrowing_generators.ML"
42024
51df23535105 handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents: 42022
diff changeset
   348
51df23535105 handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents: 42022
diff changeset
   349
setup {* Narrowing_Generators.setup *}
51df23535105 handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
bulwahn
parents: 42022
diff changeset
   350
45001
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   351
definition narrowing_dummy_partial_term_of :: "('a :: partial_term_of) itself => narrowing_term => term"
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   352
where
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   353
  "narrowing_dummy_partial_term_of = partial_term_of"
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   354
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   355
definition narrowing_dummy_narrowing :: "code_int => ('a :: narrowing) narrowing_cons"
45001
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   356
where
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   357
  "narrowing_dummy_narrowing = narrowing"
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   358
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   359
lemma [code]:
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   360
  "ensure_testable f =
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   361
    (let
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   362
      x = narrowing_dummy_narrowing :: code_int => bool narrowing_cons;
45001
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   363
      y = narrowing_dummy_partial_term_of :: bool itself => narrowing_term => term;
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   364
      z = (conv :: _ => _ => unit)  in f)"
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   365
unfolding Let_def ensure_testable_def ..
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   366
46308
e5abbec2697a adding narrowing instance for sets
bulwahn
parents: 46032
diff changeset
   367
subsection {* Narrowing for sets *}
e5abbec2697a adding narrowing instance for sets
bulwahn
parents: 46032
diff changeset
   368
e5abbec2697a adding narrowing instance for sets
bulwahn
parents: 46032
diff changeset
   369
instantiation set :: (narrowing) narrowing
e5abbec2697a adding narrowing instance for sets
bulwahn
parents: 46032
diff changeset
   370
begin
e5abbec2697a adding narrowing instance for sets
bulwahn
parents: 46032
diff changeset
   371
e5abbec2697a adding narrowing instance for sets
bulwahn
parents: 46032
diff changeset
   372
definition "narrowing_set = Quickcheck_Narrowing.apply (Quickcheck_Narrowing.cons set) narrowing"
e5abbec2697a adding narrowing instance for sets
bulwahn
parents: 46032
diff changeset
   373
e5abbec2697a adding narrowing instance for sets
bulwahn
parents: 46032
diff changeset
   374
instance ..
e5abbec2697a adding narrowing instance for sets
bulwahn
parents: 46032
diff changeset
   375
e5abbec2697a adding narrowing instance for sets
bulwahn
parents: 46032
diff changeset
   376
end
45001
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   377
  
43356
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   378
subsection {* Narrowing for integers *}
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   379
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   380
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   381
definition drawn_from :: "'a list => 'a narrowing_cons"
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   382
where "drawn_from xs = Narrowing_cons (Narrowing_sum_of_products (map (%_. []) xs)) (map (%x y. x) xs)"
43356
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   383
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   384
function around_zero :: "int => int list"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   385
where
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   386
  "around_zero i = (if i < 0 then [] else (if i = 0 then [0] else around_zero (i - 1) @ [i, -i]))"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   387
by pat_completeness auto
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   388
termination by (relation "measure nat") auto
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   389
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   390
declare around_zero.simps[simp del]
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   391
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   392
lemma length_around_zero:
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   393
  assumes "i >= 0" 
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   394
  shows "length (around_zero i) = 2 * nat i + 1"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   395
proof (induct rule: int_ge_induct[OF assms])
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   396
  case 1
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   397
  from 1 show ?case by (simp add: around_zero.simps)
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   398
next
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   399
  case (2 i)
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   400
  from 2 show ?case
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   401
    by (simp add: around_zero.simps[of "i + 1"])
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   402
qed
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   403
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   404
instantiation int :: narrowing
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   405
begin
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   406
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   407
definition
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   408
  "narrowing_int d = (let (u :: _ => _ => unit) = conv; i = Quickcheck_Narrowing.int_of d in drawn_from (around_zero i))"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   409
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   410
instance ..
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   411
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   412
end
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   413
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   414
lemma [code, code del]: "partial_term_of (ty :: int itself) t == undefined"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   415
by (rule partial_term_of_anything)+
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   416
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   417
lemma [code]:
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   418
  "partial_term_of (ty :: int itself) (Narrowing_variable p t) == Code_Evaluation.Free (STR ''_'') (Typerep.Typerep (STR ''Int.int'') [])"
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   419
  "partial_term_of (ty :: int itself) (Narrowing_constructor i []) == (if i mod 2 = 0 then
43356
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   420
     Code_Evaluation.term_of (- (int_of i) div 2) else Code_Evaluation.term_of ((int_of i + 1) div 2))"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   421
by (rule partial_term_of_anything)+
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   422
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   423
text {* Defining integers by positive and negative copy of naturals *}
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   424
(*
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   425
datatype simple_int = Positive nat | Negative nat
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   426
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   427
primrec int_of_simple_int :: "simple_int => int"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   428
where
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   429
  "int_of_simple_int (Positive n) = int n"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   430
| "int_of_simple_int (Negative n) = (-1 - int n)"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   431
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   432
instantiation int :: narrowing
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   433
begin
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   434
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   435
definition narrowing_int :: "code_int => int cons"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   436
where
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   437
  "narrowing_int d = map_cons int_of_simple_int ((narrowing :: simple_int narrowing) d)"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   438
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   439
instance ..
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   440
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   441
end
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   442
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   443
text {* printing the partial terms *}
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   444
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   445
lemma [code]:
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   446
  "partial_term_of (ty :: int itself) t == Code_Evaluation.App (Code_Evaluation.Const (STR ''Quickcheck_Narrowing.int_of_simple_int'')
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   447
     (Typerep.Typerep (STR ''fun'') [Typerep.Typerep (STR ''Quickcheck_Narrowing.simple_int'') [], Typerep.Typerep (STR ''Int.int'') []])) (partial_term_of (TYPE(simple_int)) t)"
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   448
by (rule partial_term_of_anything)
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   449
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   450
*)
2dee03f192b7 adding another narrowing strategy for integers
bulwahn
parents: 43341
diff changeset
   451
46589
689311986778 adding new command "find_unused_assms"
bulwahn
parents: 46308
diff changeset
   452
subsection {* The @{text find_unused_assms} command *}
689311986778 adding new command "find_unused_assms"
bulwahn
parents: 46308
diff changeset
   453
689311986778 adding new command "find_unused_assms"
bulwahn
parents: 46308
diff changeset
   454
use "Tools/Quickcheck/find_unused_assms.ML"
689311986778 adding new command "find_unused_assms"
bulwahn
parents: 46308
diff changeset
   455
689311986778 adding new command "find_unused_assms"
bulwahn
parents: 46308
diff changeset
   456
subsection {* Closing up *}
689311986778 adding new command "find_unused_assms"
bulwahn
parents: 46308
diff changeset
   457
46758
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   458
hide_type code_int narrowing_type narrowing_term narrowing_cons property
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   459
hide_const int_of of_int nat_of map_cons nth error toEnum marker empty Narrowing_cons conv non_empty ensure_testable all exists drawn_from around_zero
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   460
hide_const (open) Narrowing_variable Narrowing_constructor "apply" sum cons
4106258260b3 choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
bulwahn
parents: 46589
diff changeset
   461
hide_fact empty_def cons_def conv.simps non_empty.simps apply_def sum_def ensure_testable_def all_def exists_def
42022
101ce92333f4 adding a simple datatype for representing functions in Quickcheck_Narrowing
bulwahn
parents: 42021
diff changeset
   462
45001
5c8d7d6db682 ensuring that some constants are generated in the source code by adding calls in ensure_testable
bulwahn
parents: 43887
diff changeset
   463
end