src/HOL/Quickcheck_Exhaustive.thy
changeset 45724 1f5fc44254d7
parent 45722 63b42a7db003
child 45732 ac5775bbc748
equal deleted inserted replaced
45723:75691bcc2c0f 45724:1f5fc44254d7
    14   [code_unfold]: "x orelse y = (case x of Some x' => Some x' | None => y)"
    14   [code_unfold]: "x orelse y = (case x of Some x' => Some x' | None => y)"
    15 
    15 
    16 subsection {* exhaustive generator type classes *}
    16 subsection {* exhaustive generator type classes *}
    17 
    17 
    18 class exhaustive = term_of +
    18 class exhaustive = term_of +
    19   fixes exhaustive :: "('a \<Rightarrow> term list option) \<Rightarrow> code_numeral \<Rightarrow> term list option"
    19   fixes exhaustive :: "('a \<Rightarrow> (bool * term list) option) \<Rightarrow> code_numeral \<Rightarrow> (bool * term list) option"
    20   
    20   
    21 class full_exhaustive = term_of +
    21 class full_exhaustive = term_of +
    22   fixes full_exhaustive :: "('a * (unit => term) \<Rightarrow> (bool * term list) option) \<Rightarrow> code_numeral \<Rightarrow> (bool * term list) option"
    22   fixes full_exhaustive :: "('a * (unit => term) \<Rightarrow> (bool * term list) option) \<Rightarrow> code_numeral \<Rightarrow> (bool * term list) option"
    23 
    23 
    24 instantiation code_numeral :: full_exhaustive
    24 instantiation code_numeral :: full_exhaustive
    40 end
    40 end
    41 
    41 
    42 instantiation code_numeral :: exhaustive
    42 instantiation code_numeral :: exhaustive
    43 begin
    43 begin
    44 
    44 
    45 function exhaustive_code_numeral' :: "(code_numeral => term list option) => code_numeral => code_numeral => term list option"
    45 function exhaustive_code_numeral' :: "(code_numeral => (bool * term list) option) => code_numeral => code_numeral => (bool * term list) option"
    46   where "exhaustive_code_numeral' f d i =
    46   where "exhaustive_code_numeral' f d i =
    47     (if d < i then None
    47     (if d < i then None
    48     else (f i orelse exhaustive_code_numeral' f d (i + 1)))"
    48     else (f i orelse exhaustive_code_numeral' f d (i + 1)))"
    49 by pat_completeness auto
    49 by pat_completeness auto
    50 
    50 
    76 end
    76 end
    77 
    77 
    78 instantiation int :: exhaustive
    78 instantiation int :: exhaustive
    79 begin
    79 begin
    80 
    80 
    81 function exhaustive' :: "(int => term list option) => int => int => term list option"
    81 function exhaustive' :: "(int => (bool * term list) option) => int => int => (bool * term list) option"
    82   where "exhaustive' f d i = (if d < i then None else (f i orelse exhaustive' f d (i + 1)))"
    82   where "exhaustive' f d i = (if d < i then None else (f i orelse exhaustive' f d (i + 1)))"
    83 by pat_completeness auto
    83 by pat_completeness auto
    84 
    84 
    85 termination 
    85 termination 
    86   by (relation "measure (%(_, d, i). nat (d + 1 - i))") auto
    86   by (relation "measure (%(_, d, i). nat (d + 1 - i))") auto
   134 end
   134 end
   135 
   135 
   136 instantiation "fun" :: ("{equal, exhaustive}", exhaustive) exhaustive
   136 instantiation "fun" :: ("{equal, exhaustive}", exhaustive) exhaustive
   137 begin
   137 begin
   138 
   138 
   139 fun exhaustive_fun' :: "(('a => 'b) => term list option) => code_numeral => code_numeral => term list option"
   139 fun exhaustive_fun' :: "(('a => 'b) => (bool * term list) option) => code_numeral => code_numeral => (bool * term list) option"
   140 where
   140 where
   141   "exhaustive_fun' f i d = (exhaustive (%b. f (%_. b)) d)
   141   "exhaustive_fun' f i d = (exhaustive (%b. f (%_. b)) d)
   142    orelse (if i > 1 then
   142    orelse (if i > 1 then
   143      exhaustive_fun' (%g. exhaustive (%a. exhaustive (%b.
   143      exhaustive_fun' (%g. exhaustive (%a. exhaustive (%b.
   144        f (g(a := b))) d) d) (i - 1) d else None)"
   144        f (g(a := b))) d) d) (i - 1) d else None)"
   145 
   145 
   146 definition exhaustive_fun :: "(('a => 'b) => term list option) => code_numeral => term list option"
   146 definition exhaustive_fun :: "(('a => 'b) => (bool * term list) option) => code_numeral => (bool * term list) option"
   147 where
   147 where
   148   "exhaustive_fun f d = exhaustive_fun' f d d" 
   148   "exhaustive_fun f d = exhaustive_fun' f d d" 
   149 
   149 
   150 instance ..
   150 instance ..
   151 
   151