src/HOL/Library/Quickcheck_Narrowing.thy
author bulwahn
Mon, 14 Mar 2011 12:34:09 +0100
changeset 41962 27a61a3266d8
parent 41961 fdd37cfcd4a3
child 41964 13904699c859
permissions -rw-r--r--
correcting names in Narrowing_Engine and example theory for Quickcheck_Narrowing
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
41930
1e008cc4883a renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents: 41929
diff changeset
     3
header {* Counterexample generator preforming 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
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
     6
imports Main "~~/src/HOL/Library/Code_Char"
41962
27a61a3266d8 correcting names in Narrowing_Engine and example theory for Quickcheck_Narrowing
bulwahn
parents: 41961
diff changeset
     7
uses
27a61a3266d8 correcting names in Narrowing_Engine and example theory for Quickcheck_Narrowing
bulwahn
parents: 41961
diff changeset
     8
  ("~~/src/HOL/Tools/Quickcheck/narrowing_generators.ML")
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
     9
begin
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    10
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    11
subsection {* Counterexample generator *}
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    12
41909
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    13
subsubsection {* Code generation setup *}
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    14
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    15
code_type typerep
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    16
  ("Haskell" "Typerep")
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    17
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    18
code_const Typerep.Typerep
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    19
  ("Haskell" "Typerep")
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    20
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    21
code_reserved Haskell Typerep
383bbdad1650 replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
bulwahn
parents: 41908
diff changeset
    22
41943
12f24ad566ea fixed document;
wenzelm
parents: 41930
diff changeset
    23
subsubsection {* Type @{text code_int} for Haskell's Int type *}
41908
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    24
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    25
typedef (open) code_int = "UNIV \<Colon> int set"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    26
  morphisms int_of of_int by rule
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    27
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    28
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
    29
  "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
    30
  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
    31
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
    32
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
    33
where
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
    34
  "nat_of i = nat (int_of i)"
41908
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    35
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    36
instantiation code_int :: "{zero, one, minus, linorder}"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    37
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
    38
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    39
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
    40
  "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
    41
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    42
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
    43
  "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
    44
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    45
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
    46
  "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
    47
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    48
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
    49
  "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
    50
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    51
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
    52
  "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
    53
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    54
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    55
instance proof qed (auto)
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    56
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    57
end
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    58
(*
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases 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
lemma zero_code_int_code [code, code_unfold]:
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    60
  "(0\<Colon>code_int) = Numeral0"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    61
  by (simp add: number_of_code_numeral_def Pls_def)
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    62
lemma [code_post]: "Numeral0 = (0\<Colon>code_numeral)"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    63
  using zero_code_numeral_code ..
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    64
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    65
lemma one_code_numeral_code [code, code_unfold]:
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    66
  "(1\<Colon>code_int) = Numeral1"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    67
  by (simp add: number_of_code_numeral_def Pls_def Bit1_def)
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    68
lemma [code_post]: "Numeral1 = (1\<Colon>code_int)"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    69
  using one_code_numeral_code ..
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    70
*)
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    71
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    72
code_const "0 \<Colon> code_int"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    73
  (Haskell "0")
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    74
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    75
code_const "1 \<Colon> code_int"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    76
  (Haskell "1")
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    77
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    78
code_const "minus \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> code_int"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    79
  (Haskell "(_/ -/ _)")
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    80
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    81
code_const "op \<le> \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> bool"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    82
  (Haskell infix 4 "<=")
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    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
code_const "op < \<Colon> code_int \<Rightarrow> code_int \<Rightarrow> bool"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    85
  (Haskell infix 4 "<")
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    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
code_type code_int
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    88
  (Haskell "Int")
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    89
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
    90
subsubsection {* Narrowing's deep representation of types and terms *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    91
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    92
datatype type = SumOfProd "type list list"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    93
41908
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
    94
datatype "term" = Var "code_int list" type | Ctr code_int "term list"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    95
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    96
datatype 'a cons = C type "(term list => 'a) list"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    97
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
    98
subsubsection {* auxilary functions for Narrowing *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
    99
41908
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   100
consts nth :: "'a list => code_int => 'a"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   101
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
   102
code_const nth ("Haskell" infixl 9  "!!")
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   103
41908
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   104
consts error :: "char list => 'a"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   105
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   106
code_const error ("Haskell" "error")
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   107
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
   108
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
   109
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases 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
code_const toEnum ("Haskell" "toEnum")
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   111
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
   112
consts map_index :: "(code_int * 'a => 'b) => 'a list => 'b list"  
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   113
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
   114
consts split_At :: "code_int => 'a list => 'a list * 'a list"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   115
 
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   116
subsubsection {* Narrowing's basic operations *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   117
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   118
type_synonym 'a narrowing = "code_int => 'a cons"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   119
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   120
definition empty :: "'a narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   121
where
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   122
  "empty d = C (SumOfProd []) []"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   123
  
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   124
definition cons :: "'a => 'a narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   125
where
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   126
  "cons a d = (C (SumOfProd [[]]) [(%_. a)])"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   127
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   128
fun conv :: "(term list => 'a) list => term => 'a"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   129
where
41908
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   130
  "conv cs (Var p _) = error (Char Nibble0 Nibble0 # map toEnum p)"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   131
| "conv cs (Ctr i xs) = (nth cs i) xs"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   132
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   133
fun nonEmpty :: "type => bool"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   134
where
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   135
  "nonEmpty (SumOfProd ps) = (\<not> (List.null ps))"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   136
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   137
definition "apply" :: "('a => 'b) narrowing => 'a narrowing => 'b narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   138
where
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   139
  "apply f a d =
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   140
     (case f d of C (SumOfProd ps) cfs =>
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   141
       case a (d - 1) of C ta cas =>
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   142
       let
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   143
         shallow = (d > 0 \<and> nonEmpty ta);
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   144
         cs = [(%xs'. (case xs' of [] => undefined | x # xs => cf xs (conv cas x))). shallow, cf <- cfs]
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   145
       in C (SumOfProd [ta # p. shallow, p <- ps]) cs)"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   146
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   147
definition sum :: "'a narrowing => 'a narrowing => 'a narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   148
where
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   149
  "sum a b d =
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   150
    (case a d of C (SumOfProd ssa) ca => 
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   151
      case b d of C (SumOfProd ssb) cb =>
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   152
      C (SumOfProd (ssa @ ssb)) (ca @ cb))"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   153
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   154
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
   155
  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
   156
  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: 41910
diff changeset
   157
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: 41910
diff changeset
   158
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   159
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
   160
  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
   161
  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
   162
  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
   163
proof -
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   164
  note assms moreover
41930
1e008cc4883a renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents: 41929
diff changeset
   165
  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
   166
    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
   167
  moreover
41930
1e008cc4883a renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents: 41929
diff changeset
   168
  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
   169
    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
   170
  ultimately show ?thesis
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   171
    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: 41910
diff changeset
   172
qed
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   173
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   174
definition cons0 :: "'a => 'a narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   175
where
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   176
  "cons0 f = cons f"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   177
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
   178
type_synonym pos = "code_int list"
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   179
(*
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
   180
subsubsection {* Term refinement *}
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   181
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases 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
definition new :: "pos => type list list => term list"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   183
where
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   184
  "new p ps = map_index (%(c, ts). Ctr c (map_index (%(i, t). Var (p @ [i]) t) ts)) ps"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   185
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   186
fun refine :: "term => pos => term list" and refineList :: "term list => pos => (term list) list"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   187
where
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   188
  "refine (Var p (SumOfProd ss)) [] = new p ss"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   189
| "refine (Ctr c xs) p = map (Ctr c) (refineList xs p)"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   190
| "refineList xs (i # is) = (let (ls, xrs) = split_At i xs in (case xrs of x#rs => [ls @ y # rs. y <- refine x is]))"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   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: 41905
diff changeset
   192
text {* Find total instantiations of a partial value *}
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   193
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases 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
function total :: "term => term list"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   195
where
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   196
  "total (Ctr c xs) = [Ctr c ys. ys <- map total xs]"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   197
| "total (Var p (SumOfProd ss)) = [y. x <- new p ss, y <- total x]"
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   198
by pat_completeness auto
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   199
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   200
termination sorry
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   201
*)
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   202
subsubsection {* Narrowing generator type class *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   203
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   204
class narrowing =
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   205
  fixes narrowing :: "code_int => 'a cons"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   206
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   207
definition cons1 :: "('a::narrowing => 'b) => 'b narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   208
where
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   209
  "cons1 f = apply (cons f) narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   210
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   211
definition cons2 :: "('a :: narrowing => 'b :: narrowing => 'c) => 'c narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   212
where
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   213
  "cons2 f = apply (apply (cons f) narrowing) narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   214
  
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   215
instantiation unit :: narrowing
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   216
begin
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   217
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   218
definition
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   219
  "narrowing = cons0 ()"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   220
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   221
instance ..
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   222
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   223
end
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   224
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   225
instantiation bool :: narrowing
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   226
begin
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   227
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   228
definition
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   229
  "narrowing = sum (cons0 True) (cons0 False)" 
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   230
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   231
instance ..
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   232
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   233
end
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   234
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   235
instantiation option :: (narrowing) narrowing
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   236
begin
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   237
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   238
definition
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   239
  "narrowing = sum (cons0 None) (cons1 Some)"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   240
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   241
instance ..
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   242
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   243
end
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   244
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   245
instantiation sum :: (narrowing, narrowing) narrowing
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   246
begin
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   247
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   248
definition
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   249
  "narrowing = sum (cons1 Inl) (cons1 Inr)"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   250
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   251
instance ..
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   252
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   253
end
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   254
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   255
instantiation list :: (narrowing) narrowing
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   256
begin
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   257
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   258
function narrowing_list :: "'a list narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   259
where
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   260
  "narrowing_list d = sum (cons []) (apply (apply (cons Cons) narrowing) narrowing_list) d"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   261
by pat_completeness auto
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   262
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   263
termination proof (relation "measure nat_of")
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   264
qed (auto simp add: of_int_inverse nat_of_def)
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   265
    
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   266
instance ..
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   267
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   268
end
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   269
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   270
instantiation nat :: narrowing
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   271
begin
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   272
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   273
function narrowing_nat :: "nat narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   274
where
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   275
  "narrowing_nat d = sum (cons 0) (apply (cons Suc) narrowing_nat) d"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   276
by pat_completeness auto
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   277
41912
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   278
termination proof (relation "measure nat_of")
1848775589e5 adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
bulwahn
parents: 41910
diff changeset
   279
qed (auto simp add: of_int_inverse nat_of_def)
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   280
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   281
instance ..
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   282
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   283
end
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   284
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   285
instantiation Enum.finite_1 :: narrowing
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   286
begin
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   287
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   288
definition narrowing_finite_1 :: "Enum.finite_1 narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   289
where
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   290
  "narrowing_finite_1 = cons (Enum.finite_1.a\<^isub>1 :: Enum.finite_1)"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   291
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   292
instance ..
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   293
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   294
end
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   295
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   296
instantiation Enum.finite_2 :: narrowing
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   297
begin
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   298
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   299
definition narrowing_finite_2 :: "Enum.finite_2 narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   300
where
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   301
  "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
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   302
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   303
instance ..
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   304
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   305
end
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   306
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   307
instantiation Enum.finite_3 :: narrowing
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   308
begin
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   309
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   310
definition narrowing_finite_3 :: "Enum.finite_3 narrowing"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   311
where
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   312
  "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
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   313
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   314
instance ..
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   315
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   316
end
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   317
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   318
instantiation Enum.finite_4 :: narrowing
41910
709c04e7b703 adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents: 41909
diff changeset
   319
begin
709c04e7b703 adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents: 41909
diff changeset
   320
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   321
definition narrowing_finite_4 :: "Enum.finite_4 narrowing"
41910
709c04e7b703 adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents: 41909
diff changeset
   322
where
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   323
  "narrowing_finite_4 = sum (cons Enum.finite_4.a\<^isub>1) (sum (cons Enum.finite_4.a\<^isub>2) (sum (cons Enum.finite_4.a\<^isub>3) (cons Enum.finite_4.a\<^isub>4)))"
41910
709c04e7b703 adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents: 41909
diff changeset
   324
709c04e7b703 adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents: 41909
diff changeset
   325
instance ..
709c04e7b703 adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents: 41909
diff changeset
   326
709c04e7b703 adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents: 41909
diff changeset
   327
end
709c04e7b703 adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents: 41909
diff changeset
   328
41943
12f24ad566ea fixed document;
wenzelm
parents: 41930
diff changeset
   329
subsubsection {* class @{text is_testable} *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   330
41943
12f24ad566ea fixed document;
wenzelm
parents: 41930
diff changeset
   331
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
   332
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   333
class is_testable
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   334
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   335
instance bool :: is_testable ..
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   336
41961
fdd37cfcd4a3 renaming series and serial to narrowing in Quickcheck_Narrowing
bulwahn
parents: 41943
diff changeset
   337
instance "fun" :: ("{term_of, narrowing}", is_testable) is_testable ..
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   338
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   339
definition ensure_testable :: "'a :: is_testable => 'a :: is_testable"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   340
where
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   341
  "ensure_testable f = f"
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   342
41910
709c04e7b703 adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents: 41909
diff changeset
   343
declare simp_thms(17,19)[code del]
709c04e7b703 adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
bulwahn
parents: 41909
diff changeset
   344
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   345
subsubsection {* Setting up the counterexample generator *}
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   346
  
41930
1e008cc4883a renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents: 41929
diff changeset
   347
use "~~/src/HOL/Tools/Quickcheck/narrowing_generators.ML"
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   348
41930
1e008cc4883a renaming lazysmallcheck ML file to Quickcheck_Narrowing
bulwahn
parents: 41929
diff changeset
   349
setup {* Narrowing_Generators.setup *}
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   350
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
   351
hide_const (open) empty
3bd9a21366d2 changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
bulwahn
parents: 41905
diff changeset
   352
41905
e2611bc96022 adding files for prototype of lazysmallcheck
bulwahn
parents:
diff changeset
   353
end