src/HOL/hologic.ML
author paulson
Tue Dec 23 11:39:03 1997 +0100 (1997-12-23)
changeset 4466 305390f23734
parent 4294 7fe9723d579b
child 4571 6b02fc8a97f6
permissions -rw-r--r--
Better equality handling in Blast_tac, usingd a new variant of hyp_subst_tac
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
paulson@4466
    21
  val dest_imp	       : term -> term*term
clasohm@923
    22
  val eq_const: typ -> term
clasohm@923
    23
  val all_const: typ -> term
clasohm@923
    24
  val exists_const: typ -> term
clasohm@923
    25
  val Collect_const: typ -> term
clasohm@923
    26
  val mk_eq: term * term -> term
clasohm@923
    27
  val mk_all: string * typ * term -> term
clasohm@923
    28
  val mk_exists: string * typ * term -> term
clasohm@923
    29
  val mk_Collect: string * typ * term -> term
clasohm@923
    30
  val mk_mem: term * term -> term
wenzelm@2510
    31
  val mk_binop: string -> term * term -> term
wenzelm@2510
    32
  val mk_binrel: string -> term * term -> term
wenzelm@2510
    33
  val dest_bin: string -> typ -> term -> term * term
wenzelm@2510
    34
  val natT: typ
wenzelm@2510
    35
  val zero: term
wenzelm@2510
    36
  val is_zero: term -> bool
wenzelm@2510
    37
  val mk_Suc: term -> term
wenzelm@2510
    38
  val dest_Suc: term -> term
wenzelm@2510
    39
  val mk_nat: int -> term
wenzelm@4294
    40
  val dest_nat: term -> int
clasohm@923
    41
end;
clasohm@923
    42
wenzelm@2510
    43
clasohm@923
    44
structure HOLogic: HOLOGIC =
clasohm@923
    45
struct
clasohm@923
    46
wenzelm@2510
    47
(* basics *)
clasohm@923
    48
clasohm@923
    49
val termC: class = "term";
clasohm@923
    50
val termS: sort = [termC];
clasohm@923
    51
wenzelm@2510
    52
val termTVar = TVar (("'a", 0), termS);
clasohm@923
    53
clasohm@923
    54
wenzelm@2510
    55
(* bool and set *)
clasohm@923
    56
clasohm@923
    57
val boolT = Type ("bool", []);
clasohm@923
    58
clasohm@923
    59
fun mk_setT T = Type ("set", [T]);
clasohm@923
    60
clasohm@923
    61
fun dest_setT (Type ("set", [T])) = T
wenzelm@3794
    62
  | dest_setT T = raise TYPE ("dest_setT: set type expected", [T], []);
clasohm@923
    63
clasohm@923
    64
clasohm@923
    65
val Trueprop = Const ("Trueprop", boolT --> propT);
clasohm@923
    66
clasohm@923
    67
fun mk_Trueprop P = Trueprop $ P;
clasohm@923
    68
clasohm@923
    69
fun dest_Trueprop (Const ("Trueprop", _) $ P) = P
wenzelm@3794
    70
  | dest_Trueprop t = raise TERM ("dest_Trueprop", [t]);
clasohm@923
    71
clasohm@923
    72
clasohm@923
    73
val conj = Const ("op &", [boolT, boolT] ---> boolT)
clasohm@923
    74
and disj = Const ("op |", [boolT, boolT] ---> boolT)
clasohm@923
    75
and imp = Const ("op -->", [boolT, boolT] ---> boolT);
clasohm@923
    76
paulson@4466
    77
fun dest_imp (Const("op -->",_) $ A $ B) = (A, B)
paulson@4466
    78
  | dest_imp  t = raise TERM ("dest_imp", [t]);
paulson@4466
    79
clasohm@923
    80
fun eq_const T = Const ("op =", [T, T] ---> boolT);
clasohm@923
    81
fun mk_eq (t, u) = eq_const (fastype_of t) $ t $ u;
clasohm@923
    82
clasohm@923
    83
fun all_const T = Const ("All", [T --> boolT] ---> boolT);
clasohm@923
    84
fun mk_all (x, T, P) = all_const T $ absfree (x, T, P);
clasohm@923
    85
clasohm@923
    86
fun exists_const T = Const ("Ex", [T --> boolT] ---> boolT);
clasohm@923
    87
fun mk_exists (x, T, P) = exists_const T $ absfree (x, T, P);
clasohm@923
    88
clasohm@923
    89
fun Collect_const T = Const ("Collect", [T --> boolT] ---> mk_setT T);
clasohm@923
    90
fun mk_Collect (a, T, t) = Collect_const T $ absfree (a, T, t);
clasohm@923
    91
clasohm@923
    92
fun mk_mem (x, A) =
clasohm@923
    93
  let val setT = fastype_of A in
clasohm@923
    94
    Const ("op :", [dest_setT setT, setT] ---> boolT) $ x $ A
clasohm@923
    95
  end;
clasohm@923
    96
clasohm@923
    97
wenzelm@2510
    98
(* binary oprations and relations *)
wenzelm@2510
    99
wenzelm@2510
   100
fun mk_binop c (t, u) =
wenzelm@2510
   101
  let val T = fastype_of t in
wenzelm@2510
   102
    Const (c, [T, T] ---> T) $ t $ u
wenzelm@2510
   103
  end;
wenzelm@2510
   104
wenzelm@2510
   105
fun mk_binrel c (t, u) =
wenzelm@2510
   106
  let val T = fastype_of t in
wenzelm@2510
   107
    Const (c, [T, T] ---> boolT) $ t $ u
wenzelm@2510
   108
  end;
wenzelm@2510
   109
wenzelm@2510
   110
fun dest_bin c T (tm as Const (c', Type ("fun", [T', _])) $ t $ u) =
wenzelm@2510
   111
      if c = c' andalso T = T' then (t, u)
wenzelm@3794
   112
      else raise TERM ("dest_bin " ^ c, [tm])
wenzelm@3794
   113
  | dest_bin c _ tm = raise TERM ("dest_bin " ^ c, [tm]);
wenzelm@2510
   114
wenzelm@2510
   115
wenzelm@2510
   116
(* nat *)
wenzelm@2510
   117
wenzelm@2510
   118
val natT = Type ("nat", []);
wenzelm@2510
   119
wenzelm@4294
   120
wenzelm@2510
   121
val zero = Const ("0", natT);
wenzelm@4294
   122
wenzelm@4294
   123
fun is_zero (Const ("0", _)) = true
wenzelm@4294
   124
  | is_zero _ = false;
wenzelm@4294
   125
wenzelm@2510
   126
wenzelm@2510
   127
fun mk_Suc t = Const ("Suc", natT --> natT) $ t;
wenzelm@2510
   128
wenzelm@2510
   129
fun dest_Suc (Const ("Suc", _) $ t) = t
wenzelm@3794
   130
  | dest_Suc t = raise TERM ("dest_Suc", [t]);
wenzelm@2510
   131
wenzelm@4294
   132
wenzelm@2510
   133
fun mk_nat 0 = zero
wenzelm@2510
   134
  | mk_nat n = mk_Suc (mk_nat (n - 1));
wenzelm@2510
   135
wenzelm@4294
   136
fun dest_nat (Const ("0", _)) = 0
wenzelm@4294
   137
  | dest_nat (Const ("Suc", _) $ t) = dest_nat t + 1
wenzelm@4294
   138
  | dest_nat t = raise TERM ("dest_nat", [t]);
wenzelm@4294
   139
wenzelm@2510
   140
clasohm@923
   141
end;