src/HOL/Smallcheck.thy
author huffman
Wed Nov 17 11:39:44 2010 -0800 (2010-11-17)
changeset 40620 7a9278de19ad
parent 40420 552563ea3304
child 40639 f1f0e6adca0a
permissions -rw-r--r--
section -> subsection
bulwahn@40420
     1
(* Author: Lukas Bulwahn, TU Muenchen *)
bulwahn@40420
     2
bulwahn@40420
     3
header {* Another simple counterexample generator *}
bulwahn@40420
     4
bulwahn@40420
     5
theory Smallcheck
bulwahn@40420
     6
imports Quickcheck
bulwahn@40420
     7
uses ("Tools/smallvalue_generators.ML")
bulwahn@40420
     8
begin
bulwahn@40420
     9
bulwahn@40420
    10
huffman@40620
    11
subsection {* small value generator type classes *}
bulwahn@40420
    12
bulwahn@40420
    13
class small = term_of +
bulwahn@40420
    14
fixes small :: "('a \<Rightarrow> term list option) \<Rightarrow> code_numeral \<Rightarrow> term list option"
bulwahn@40420
    15
bulwahn@40420
    16
instantiation unit :: small
bulwahn@40420
    17
begin
bulwahn@40420
    18
bulwahn@40420
    19
definition "find_first f d = f ()"
bulwahn@40420
    20
bulwahn@40420
    21
instance ..
bulwahn@40420
    22
bulwahn@40420
    23
end
bulwahn@40420
    24
bulwahn@40420
    25
instantiation int :: small
bulwahn@40420
    26
begin
bulwahn@40420
    27
bulwahn@40420
    28
function small' :: "(int => term list option) => int => int => term list option"
bulwahn@40420
    29
where "small' f d i = (if d < i then None else (case f i of Some t => Some t | None => small' f d (i + 1)))"
bulwahn@40420
    30
by pat_completeness auto
bulwahn@40420
    31
bulwahn@40420
    32
termination 
bulwahn@40420
    33
  by (relation "measure (%(_, d, i). nat (d + 1 - i))") auto
bulwahn@40420
    34
bulwahn@40420
    35
definition "small f d = small' f (Code_Numeral.int_of d) (- (Code_Numeral.int_of d))"
bulwahn@40420
    36
bulwahn@40420
    37
instance ..
bulwahn@40420
    38
bulwahn@40420
    39
end
bulwahn@40420
    40
bulwahn@40420
    41
instantiation prod :: (small, small) small
bulwahn@40420
    42
begin
bulwahn@40420
    43
bulwahn@40420
    44
definition
bulwahn@40420
    45
  "small f d = small (%x. small (%y. f (x, y)) d) d"
bulwahn@40420
    46
bulwahn@40420
    47
instance ..
bulwahn@40420
    48
bulwahn@40420
    49
end
bulwahn@40420
    50
huffman@40620
    51
subsection {* Defining combinators for any first-order data type *}
bulwahn@40420
    52
bulwahn@40420
    53
definition catch_match :: "term list option => term list option => term list option"
bulwahn@40420
    54
where
bulwahn@40420
    55
  [code del]: "catch_match t1 t2 = (SOME t. t = t1 \<or> t = t2)"
bulwahn@40420
    56
bulwahn@40420
    57
code_const catch_match 
bulwahn@40420
    58
  (SML "(_) handle Match => _")
bulwahn@40420
    59
bulwahn@40420
    60
use "Tools/smallvalue_generators.ML"
bulwahn@40420
    61
bulwahn@40420
    62
(* We do not activate smallcheck yet. 
bulwahn@40420
    63
setup {* Smallvalue_Generators.setup *}
bulwahn@40420
    64
*)
bulwahn@40420
    65
bulwahn@40420
    66
hide_fact catch_match_def
bulwahn@40420
    67
hide_const (open) catch_match
bulwahn@40420
    68
bulwahn@40420
    69
end