src/HOL/hologic.ML
author wenzelm
Mon Oct 06 19:15:02 1997 +0200 (1997-10-06)
changeset 3794 d543bb9ab896
parent 2510 e3d0ac75c723
child 4294 7fe9723d579b
permissions -rw-r--r--
eliminated raise_term, raise_typ;
clasohm@923
     1
(*  Title:      HOL/hologic.ML
clasohm@923
     2
    ID:         $Id$
clasohm@923
     3
    Author:     Lawrence C Paulson and Markus Wenzel
clasohm@923
     4
clasohm@923
     5
Abstract syntax operations for HOL.
clasohm@923
     6
*)
clasohm@923
     7
clasohm@923
     8
signature HOLOGIC =
clasohm@923
     9
sig
clasohm@923
    10
  val termC: class
clasohm@923
    11
  val termS: sort
clasohm@923
    12
  val termTVar: typ
clasohm@923
    13
  val boolT: typ
clasohm@923
    14
  val mk_setT: typ -> typ
clasohm@923
    15
  val dest_setT: typ -> typ
clasohm@923
    16
  val mk_Trueprop: term -> term
clasohm@923
    17
  val dest_Trueprop: term -> term
clasohm@923
    18
  val conj: term
clasohm@923
    19
  val disj: term
clasohm@923
    20
  val imp: term
clasohm@923
    21
  val eq_const: typ -> term
clasohm@923
    22
  val all_const: typ -> term
clasohm@923
    23
  val exists_const: typ -> term
clasohm@923
    24
  val Collect_const: typ -> term
clasohm@923
    25
  val mk_eq: term * term -> term
clasohm@923
    26
  val mk_all: string * typ * term -> term
clasohm@923
    27
  val mk_exists: string * typ * term -> term
clasohm@923
    28
  val mk_Collect: string * typ * term -> term
clasohm@923
    29
  val mk_mem: term * term -> term
wenzelm@2510
    30
  val mk_binop: string -> term * term -> term
wenzelm@2510
    31
  val mk_binrel: string -> term * term -> term
wenzelm@2510
    32
  val dest_bin: string -> typ -> term -> term * term
wenzelm@2510
    33
  val natT: typ
wenzelm@2510
    34
  val zero: term
wenzelm@2510
    35
  val is_zero: term -> bool
wenzelm@2510
    36
  val mk_Suc: term -> term
wenzelm@2510
    37
  val dest_Suc: term -> term
wenzelm@2510
    38
  val mk_nat: int -> term
clasohm@923
    39
end;
clasohm@923
    40
wenzelm@2510
    41
clasohm@923
    42
structure HOLogic: HOLOGIC =
clasohm@923
    43
struct
clasohm@923
    44
wenzelm@2510
    45
(* basics *)
clasohm@923
    46
clasohm@923
    47
val termC: class = "term";
clasohm@923
    48
val termS: sort = [termC];
clasohm@923
    49
wenzelm@2510
    50
val termTVar = TVar (("'a", 0), termS);
clasohm@923
    51
clasohm@923
    52
wenzelm@2510
    53
(* bool and set *)
clasohm@923
    54
clasohm@923
    55
val boolT = Type ("bool", []);
clasohm@923
    56
clasohm@923
    57
fun mk_setT T = Type ("set", [T]);
clasohm@923
    58
clasohm@923
    59
fun dest_setT (Type ("set", [T])) = T
wenzelm@3794
    60
  | dest_setT T = raise TYPE ("dest_setT: set type expected", [T], []);
clasohm@923
    61
clasohm@923
    62
clasohm@923
    63
val Trueprop = Const ("Trueprop", boolT --> propT);
clasohm@923
    64
clasohm@923
    65
fun mk_Trueprop P = Trueprop $ P;
clasohm@923
    66
clasohm@923
    67
fun dest_Trueprop (Const ("Trueprop", _) $ P) = P
wenzelm@3794
    68
  | dest_Trueprop t = raise TERM ("dest_Trueprop", [t]);
clasohm@923
    69
clasohm@923
    70
clasohm@923
    71
val conj = Const ("op &", [boolT, boolT] ---> boolT)
clasohm@923
    72
and disj = Const ("op |", [boolT, boolT] ---> boolT)
clasohm@923
    73
and imp = Const ("op -->", [boolT, boolT] ---> boolT);
clasohm@923
    74
clasohm@923
    75
fun eq_const T = Const ("op =", [T, T] ---> boolT);
clasohm@923
    76
fun mk_eq (t, u) = eq_const (fastype_of t) $ t $ u;
clasohm@923
    77
clasohm@923
    78
fun all_const T = Const ("All", [T --> boolT] ---> boolT);
clasohm@923
    79
fun mk_all (x, T, P) = all_const T $ absfree (x, T, P);
clasohm@923
    80
clasohm@923
    81
fun exists_const T = Const ("Ex", [T --> boolT] ---> boolT);
clasohm@923
    82
fun mk_exists (x, T, P) = exists_const T $ absfree (x, T, P);
clasohm@923
    83
clasohm@923
    84
fun Collect_const T = Const ("Collect", [T --> boolT] ---> mk_setT T);
clasohm@923
    85
fun mk_Collect (a, T, t) = Collect_const T $ absfree (a, T, t);
clasohm@923
    86
clasohm@923
    87
fun mk_mem (x, A) =
clasohm@923
    88
  let val setT = fastype_of A in
clasohm@923
    89
    Const ("op :", [dest_setT setT, setT] ---> boolT) $ x $ A
clasohm@923
    90
  end;
clasohm@923
    91
clasohm@923
    92
wenzelm@2510
    93
(* binary oprations and relations *)
wenzelm@2510
    94
wenzelm@2510
    95
fun mk_binop c (t, u) =
wenzelm@2510
    96
  let val T = fastype_of t in
wenzelm@2510
    97
    Const (c, [T, T] ---> T) $ t $ u
wenzelm@2510
    98
  end;
wenzelm@2510
    99
wenzelm@2510
   100
fun mk_binrel c (t, u) =
wenzelm@2510
   101
  let val T = fastype_of t in
wenzelm@2510
   102
    Const (c, [T, T] ---> boolT) $ t $ u
wenzelm@2510
   103
  end;
wenzelm@2510
   104
wenzelm@2510
   105
fun dest_bin c T (tm as Const (c', Type ("fun", [T', _])) $ t $ u) =
wenzelm@2510
   106
      if c = c' andalso T = T' then (t, u)
wenzelm@3794
   107
      else raise TERM ("dest_bin " ^ c, [tm])
wenzelm@3794
   108
  | dest_bin c _ tm = raise TERM ("dest_bin " ^ c, [tm]);
wenzelm@2510
   109
wenzelm@2510
   110
wenzelm@2510
   111
(* nat *)
wenzelm@2510
   112
wenzelm@2510
   113
val natT = Type ("nat", []);
wenzelm@2510
   114
wenzelm@2510
   115
val zero = Const ("0", natT);
wenzelm@2510
   116
fun is_zero t = t = zero;
wenzelm@2510
   117
wenzelm@2510
   118
fun mk_Suc t = Const ("Suc", natT --> natT) $ t;
wenzelm@2510
   119
wenzelm@2510
   120
fun dest_Suc (Const ("Suc", _) $ t) = t
wenzelm@3794
   121
  | dest_Suc t = raise TERM ("dest_Suc", [t]);
wenzelm@2510
   122
wenzelm@2510
   123
fun mk_nat 0 = zero
wenzelm@2510
   124
  | mk_nat n = mk_Suc (mk_nat (n - 1));
wenzelm@2510
   125
wenzelm@2510
   126
clasohm@923
   127
end;