src/HOL/Tools/BNF/bnf_lfp_util.ML
author blanchet
Wed Apr 23 10:23:26 2014 +0200 (2014-04-23)
changeset 56638 092a306bcc3d
parent 56262 251f60be62a7
child 58315 6d8458bc6e27
permissions -rw-r--r--
generate size instances for new-style datatypes
     1 (*  Title:      HOL/Tools/BNF/bnf_lfp_util.ML
     2     Author:     Dmitriy Traytel, TU Muenchen
     3     Author:     Jasmin Blanchette, TU Muenchen
     4     Copyright   2012
     5 
     6 Library for the new-style datatype construction.
     7 *)
     8 
     9 signature BNF_LFP_UTIL =
    10 sig
    11   val mk_bij_betw: term -> term -> term -> term
    12   val mk_cardSuc: term -> term
    13   val mk_not_empty: term -> term
    14   val mk_not_eq: term -> term -> term
    15   val mk_rapp: term -> typ -> term
    16   val mk_relChain: term -> term -> term
    17   val mk_underS: term -> term
    18   val mk_worec: term -> term -> term
    19 end;
    20 
    21 structure BNF_LFP_Util : BNF_LFP_UTIL =
    22 struct
    23 
    24 open BNF_Util
    25 
    26 (*reverse application*)
    27 fun mk_rapp arg T = Term.absdummy (fastype_of arg --> T) (Bound 0 $ arg);
    28 
    29 fun mk_underS r =
    30   let val T = fst (dest_relT (fastype_of r));
    31   in Const (@{const_name underS}, mk_relT (T, T) --> T --> HOLogic.mk_setT T) $ r end;
    32 
    33 fun mk_worec r f =
    34   let val (A, AB) = apfst domain_type (dest_funT (fastype_of f));
    35   in Const (@{const_name wo_rel.worec}, mk_relT (A, A) --> (AB --> AB) --> AB) $ r $ f end;
    36 
    37 fun mk_relChain r f =
    38   let val (A, AB) = `domain_type (fastype_of f);
    39   in Const (@{const_name relChain}, mk_relT (A, A) --> AB --> HOLogic.boolT) $ r $ f end;
    40 
    41 fun mk_cardSuc r =
    42   let val T = fst (dest_relT (fastype_of r));
    43   in Const (@{const_name cardSuc}, mk_relT (T, T) --> mk_relT (`I (HOLogic.mk_setT T))) $ r end;
    44 
    45 fun mk_bij_betw f A B =
    46  Const (@{const_name bij_betw},
    47    fastype_of f --> fastype_of A --> fastype_of B --> HOLogic.boolT) $ f $ A $ B;
    48 
    49 fun mk_not_eq x y = HOLogic.mk_not (HOLogic.mk_eq (x, y));
    50 
    51 fun mk_not_empty B = mk_not_eq B (HOLogic.mk_set (HOLogic.dest_setT (fastype_of B)) []);
    52 
    53 end;