src/HOL/Quickcheck_Narrowing.thy
changeset 43316 3e274608f06b
parent 43315 893de45ac28d
child 43317 f9283eb3a4bf
equal deleted inserted replaced
43315:893de45ac28d 43316:3e274608f06b
    23 
    23 
    24 code_const Typerep.Typerep
    24 code_const Typerep.Typerep
    25   (Haskell_Quickcheck "Typerep")
    25   (Haskell_Quickcheck "Typerep")
    26 
    26 
    27 code_reserved Haskell_Quickcheck Typerep
    27 code_reserved Haskell_Quickcheck Typerep
    28 
       
    29 code_type char
       
    30   (Haskell_Quickcheck "Char")
       
    31 
       
    32 setup {*
       
    33   fold String_Code.add_literal_char ["Haskell_Quickcheck"] 
       
    34   #> String_Code.add_literal_list_string "Haskell_Quickcheck"
       
    35 *}
       
    36 
       
    37 code_instance char :: equal
       
    38   (Haskell_Quickcheck -)
       
    39 
       
    40 code_const "HOL.equal \<Colon> char \<Rightarrow> char \<Rightarrow> bool"
       
    41   (Haskell_Quickcheck infix 4 "==")
       
    42 
    28 
    43 subsubsection {* Type @{text "code_int"} for Haskell_Quickcheck's Int type *}
    29 subsubsection {* Type @{text "code_int"} for Haskell_Quickcheck's Int type *}
    44 
    30 
    45 typedef (open) code_int = "UNIV \<Colon> int set"
    31 typedef (open) code_int = "UNIV \<Colon> int set"
    46   morphisms int_of of_int by rule
    32   morphisms int_of of_int by rule
   246 
   232 
   247 consts toEnum :: "code_int => char"
   233 consts toEnum :: "code_int => char"
   248 
   234 
   249 code_const toEnum (Haskell_Quickcheck "toEnum")
   235 code_const toEnum (Haskell_Quickcheck "toEnum")
   250 
   236 
   251 consts map_index :: "(code_int * 'a => 'b) => 'a list => 'b list"  
   237 consts marker :: "char"
   252 
   238 
   253 consts split_At :: "code_int => 'a list => 'a list * 'a list"
   239 code_const marker (Haskell_Quickcheck "''\\0'")
   254  
   240 
   255 subsubsection {* Narrowing's basic operations *}
   241 subsubsection {* Narrowing's basic operations *}
   256 
   242 
   257 type_synonym 'a narrowing = "code_int => 'a cons"
   243 type_synonym 'a narrowing = "code_int => 'a cons"
   258 
   244 
   259 definition empty :: "'a narrowing"
   245 definition empty :: "'a narrowing"
   264 where
   250 where
   265   "cons a d = (C (SumOfProd [[]]) [(%_. a)])"
   251   "cons a d = (C (SumOfProd [[]]) [(%_. a)])"
   266 
   252 
   267 fun conv :: "(narrowing_term list => 'a) list => narrowing_term => 'a"
   253 fun conv :: "(narrowing_term list => 'a) list => narrowing_term => 'a"
   268 where
   254 where
   269   "conv cs (Var p _) = error (Char Nibble0 Nibble0 # map toEnum p)"
   255   "conv cs (Var p _) = error (marker # map toEnum p)"
   270 | "conv cs (Ctr i xs) = (nth cs i) xs"
   256 | "conv cs (Ctr i xs) = (nth cs i) xs"
   271 
   257 
   272 fun nonEmpty :: "narrowing_type => bool"
   258 fun nonEmpty :: "narrowing_type => bool"
   273 where
   259 where
   274   "nonEmpty (SumOfProd ps) = (\<not> (List.null ps))"
   260   "nonEmpty (SumOfProd ps) = (\<not> (List.null ps))"
   382 use "~~/src/HOL/Tools/Quickcheck/narrowing_generators.ML"
   368 use "~~/src/HOL/Tools/Quickcheck/narrowing_generators.ML"
   383 
   369 
   384 setup {* Narrowing_Generators.setup *}
   370 setup {* Narrowing_Generators.setup *}
   385 
   371 
   386 hide_type code_int narrowing_type narrowing_term cons property
   372 hide_type code_int narrowing_type narrowing_term cons property
   387 hide_const int_of of_int nth error toEnum map_index split_At empty
   373 hide_const int_of of_int nth error toEnum marker empty
   388   C cons conv nonEmpty "apply" sum ensure_testable all exists 
   374   C cons conv nonEmpty "apply" sum ensure_testable all exists 
   389 hide_fact empty_def cons_def conv.simps nonEmpty.simps apply_def sum_def ensure_testable_def all_def exists_def
   375 hide_fact empty_def cons_def conv.simps nonEmpty.simps apply_def sum_def ensure_testable_def all_def exists_def
   390 
   376 
   391 end
   377 end