src/HOL/BNF/Tools/bnf_lfp_util.ML
author blanchet
Fri Jun 07 09:30:13 2013 +0200 (2013-06-07)
changeset 52334 705bc4f5fc70
parent 49510 ba50d204095e
child 53032 953534445ab6
permissions -rw-r--r--
tuning
blanchet@49509
     1
(*  Title:      HOL/BNF/Tools/bnf_lfp_util.ML
blanchet@48975
     2
    Author:     Dmitriy Traytel, TU Muenchen
blanchet@48975
     3
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@48975
     4
    Copyright   2012
blanchet@48975
     5
blanchet@48975
     6
Library for the datatype construction.
blanchet@48975
     7
*)
blanchet@48975
     8
blanchet@48975
     9
signature BNF_LFP_UTIL =
blanchet@48975
    10
sig
blanchet@48975
    11
  val HOL_arg_cong: cterm -> thm
blanchet@48975
    12
blanchet@48975
    13
  val mk_bij_betw: term -> term -> term -> term
blanchet@48975
    14
  val mk_cardSuc: term -> term
blanchet@48975
    15
  val mk_convol: term * term -> term
blanchet@48975
    16
  val mk_cpow: term -> term
blanchet@48975
    17
  val mk_inver: term -> term -> term -> term
blanchet@48975
    18
  val mk_not_empty: term -> term
blanchet@48975
    19
  val mk_not_eq: term -> term -> term
blanchet@48975
    20
  val mk_rapp: term -> typ -> term
blanchet@48975
    21
  val mk_relChain: term -> term -> term
blanchet@48975
    22
  val mk_underS: term -> term
blanchet@48975
    23
  val mk_worec: term -> term -> term
blanchet@48975
    24
end;
blanchet@48975
    25
blanchet@48975
    26
structure BNF_LFP_Util : BNF_LFP_UTIL =
blanchet@48975
    27
struct
blanchet@48975
    28
blanchet@48975
    29
open BNF_Util
blanchet@48975
    30
blanchet@48975
    31
fun HOL_arg_cong ct = Drule.instantiate'
blanchet@48975
    32
  (map SOME (Thm.dest_ctyp (Thm.ctyp_of_term ct))) [NONE, NONE, SOME ct] arg_cong;
blanchet@48975
    33
blanchet@48975
    34
(*reverse application*)
blanchet@48975
    35
fun mk_rapp arg T = Term.absdummy (fastype_of arg --> T) (Bound 0 $ arg);
blanchet@48975
    36
blanchet@48975
    37
fun mk_underS r =
blanchet@48975
    38
  let val T = fst (dest_relT (fastype_of r));
blanchet@48975
    39
  in Const (@{const_name rel.underS}, mk_relT (T, T) --> T --> HOLogic.mk_setT T) $ r end;
blanchet@48975
    40
blanchet@48975
    41
fun mk_worec r f =
blanchet@48975
    42
  let val (A, AB) = apfst domain_type (dest_funT (fastype_of f));
blanchet@48975
    43
  in Const (@{const_name wo_rel.worec}, mk_relT (A, A) --> (AB --> AB) --> AB) $ r $ f end;
blanchet@48975
    44
blanchet@48975
    45
fun mk_relChain r f =
blanchet@48975
    46
  let val (A, AB) = `domain_type (fastype_of f);
blanchet@48975
    47
  in Const (@{const_name relChain}, mk_relT (A, A) --> AB --> HOLogic.boolT) $ r $ f end;
blanchet@48975
    48
blanchet@48975
    49
fun mk_cardSuc r =
blanchet@48975
    50
  let val T = fst (dest_relT (fastype_of r));
blanchet@48975
    51
  in Const (@{const_name cardSuc}, mk_relT (T, T) --> mk_relT (`I (HOLogic.mk_setT T))) $ r end;
blanchet@48975
    52
blanchet@48975
    53
fun mk_cpow r =
blanchet@48975
    54
  let val T = fst (dest_relT (fastype_of r));
blanchet@48975
    55
  in Const (@{const_name cpow}, mk_relT (T, T) --> mk_relT (`I (HOLogic.mk_setT T))) $ r end;
blanchet@48975
    56
blanchet@48975
    57
fun mk_bij_betw f A B =
blanchet@48975
    58
 Const (@{const_name bij_betw},
blanchet@48975
    59
   fastype_of f --> fastype_of A --> fastype_of B --> HOLogic.boolT) $ f $ A $ B;
blanchet@48975
    60
blanchet@48975
    61
fun mk_inver f g A =
blanchet@48975
    62
 Const (@{const_name inver}, fastype_of f --> fastype_of g --> fastype_of A --> HOLogic.boolT) $
blanchet@48975
    63
   f $ g $ A;
blanchet@48975
    64
blanchet@48975
    65
fun mk_not_eq x y = HOLogic.mk_not (HOLogic.mk_eq (x, y));
blanchet@48975
    66
blanchet@48975
    67
fun mk_not_empty B = mk_not_eq B (HOLogic.mk_set (HOLogic.dest_setT (fastype_of B)) []);
blanchet@48975
    68
blanchet@48975
    69
fun mk_convol (f, g) =
blanchet@48975
    70
  let
blanchet@48975
    71
    val (fU, fTU) = `range_type (fastype_of f);
blanchet@48975
    72
    val ((gT, gU), gTU) = `dest_funT (fastype_of g);
blanchet@48975
    73
    val convolT = fTU --> gTU --> gT --> HOLogic.mk_prodT (fU, gU);
blanchet@48975
    74
  in Const (@{const_name convol}, convolT) $ f $ g end;
blanchet@48975
    75
blanchet@48975
    76
end;