src/HOL/Quickcheck_Narrowing.thy
changeset 58350 919149921e46
parent 58334 7553a1bcecb7
child 58400 d0d3c30806b4
equal deleted inserted replaced
58349:107341a15946 58350:919149921e46
    24 code_reserved Haskell_Quickcheck Typerep
    24 code_reserved Haskell_Quickcheck Typerep
    25 
    25 
    26 
    26 
    27 subsubsection {* Narrowing's deep representation of types and terms *}
    27 subsubsection {* Narrowing's deep representation of types and terms *}
    28 
    28 
    29 datatype (plugins only: code) narrowing_type =
    29 datatype (plugins only: code extraction) narrowing_type =
    30   Narrowing_sum_of_products "narrowing_type list list"
    30   Narrowing_sum_of_products "narrowing_type list list"
    31 
    31 
    32 datatype (plugins only: code) narrowing_term =
    32 datatype (plugins only: code extraction) narrowing_term =
    33   Narrowing_variable "integer list" narrowing_type
    33   Narrowing_variable "integer list" narrowing_type
    34 | Narrowing_constructor integer "narrowing_term list"
    34 | Narrowing_constructor integer "narrowing_term list"
    35 
    35 
    36 datatype (plugins only: code) (dead 'a) narrowing_cons =
    36 datatype (plugins only: code extraction) (dead 'a) narrowing_cons =
    37   Narrowing_cons narrowing_type "(narrowing_term list \<Rightarrow> 'a) list"
    37   Narrowing_cons narrowing_type "(narrowing_term list \<Rightarrow> 'a) list"
    38 
    38 
    39 primrec map_cons :: "('a => 'b) => 'a narrowing_cons => 'b narrowing_cons"
    39 primrec map_cons :: "('a => 'b) => 'a narrowing_cons => 'b narrowing_cons"
    40 where
    40 where
    41   "map_cons f (Narrowing_cons ty cs) = Narrowing_cons ty (map (\<lambda>c. f o c) cs)"
    41   "map_cons f (Narrowing_cons ty cs) = Narrowing_cons ty (map (\<lambda>c. f o c) cs)"
   125 subsubsection {* Narrowing generator type class *}
   125 subsubsection {* Narrowing generator type class *}
   126 
   126 
   127 class narrowing =
   127 class narrowing =
   128   fixes narrowing :: "integer => 'a narrowing_cons"
   128   fixes narrowing :: "integer => 'a narrowing_cons"
   129 
   129 
   130 datatype (plugins only: code) property =
   130 datatype (plugins only: code extraction) property =
   131   Universal narrowing_type "(narrowing_term => property)" "narrowing_term => Code_Evaluation.term"
   131   Universal narrowing_type "(narrowing_term => property)" "narrowing_term => Code_Evaluation.term"
   132 | Existential narrowing_type "(narrowing_term => property)" "narrowing_term => Code_Evaluation.term"
   132 | Existential narrowing_type "(narrowing_term => property)" "narrowing_term => Code_Evaluation.term"
   133 | Property bool
   133 | Property bool
   134 
   134 
   135 (* FIXME: hard-wired maximal depth of 100 here *)
   135 (* FIXME: hard-wired maximal depth of 100 here *)
   156   "ensure_testable f = f"
   156   "ensure_testable f = f"
   157 
   157 
   158 
   158 
   159 subsubsection {* Defining a simple datatype to represent functions in an incomplete and redundant way *}
   159 subsubsection {* Defining a simple datatype to represent functions in an incomplete and redundant way *}
   160 
   160 
   161 datatype (plugins only: code quickcheck_narrowing) (dead 'a, dead 'b) ffun =
   161 datatype (plugins only: code quickcheck_narrowing extraction) (dead 'a, dead 'b) ffun =
   162   Constant 'b
   162   Constant 'b
   163 | Update 'a 'b "('a, 'b) ffun"
   163 | Update 'a 'b "('a, 'b) ffun"
   164 
   164 
   165 primrec eval_ffun :: "('a, 'b) ffun => 'a => 'b"
   165 primrec eval_ffun :: "('a, 'b) ffun => 'a => 'b"
   166 where
   166 where
   168 | "eval_ffun (Update x' y f) x = (if x = x' then y else eval_ffun f x)"
   168 | "eval_ffun (Update x' y f) x = (if x = x' then y else eval_ffun f x)"
   169 
   169 
   170 hide_type (open) ffun
   170 hide_type (open) ffun
   171 hide_const (open) Constant Update eval_ffun
   171 hide_const (open) Constant Update eval_ffun
   172 
   172 
   173 datatype (plugins only: code quickcheck_narrowing) (dead 'b) cfun = Constant 'b
   173 datatype (plugins only: code quickcheck_narrowing extraction) (dead 'b) cfun = Constant 'b
   174 
   174 
   175 primrec eval_cfun :: "'b cfun => 'a => 'b"
   175 primrec eval_cfun :: "'b cfun => 'a => 'b"
   176 where
   176 where
   177   "eval_cfun (Constant c) y = c"
   177   "eval_cfun (Constant c) y = c"
   178 
   178