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