author | wenzelm |
Thu, 18 Jun 1998 10:52:34 +0200 | |
changeset 5047 | 585fa380df1a |
parent 4571 | 6b02fc8a97f6 |
child 5096 | 84b00be693b4 |
permissions | -rw-r--r-- |
923 | 1 |
(* Title: HOL/hologic.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson and Markus Wenzel |
|
4 |
||
5 |
Abstract syntax operations for HOL. |
|
6 |
*) |
|
7 |
||
8 |
signature HOLOGIC = |
|
9 |
sig |
|
10 |
val termC: class |
|
11 |
val termS: sort |
|
12 |
val termTVar: typ |
|
13 |
val boolT: typ |
|
14 |
val mk_setT: typ -> typ |
|
15 |
val dest_setT: typ -> typ |
|
16 |
val mk_Trueprop: term -> term |
|
17 |
val dest_Trueprop: term -> term |
|
18 |
val conj: term |
|
19 |
val disj: term |
|
20 |
val imp: term |
|
4571 | 21 |
val dest_imp: term -> term * term |
923 | 22 |
val eq_const: typ -> term |
23 |
val all_const: typ -> term |
|
24 |
val exists_const: typ -> term |
|
25 |
val Collect_const: typ -> term |
|
26 |
val mk_eq: term * term -> term |
|
27 |
val mk_all: string * typ * term -> term |
|
28 |
val mk_exists: string * typ * term -> term |
|
29 |
val mk_Collect: string * typ * term -> term |
|
30 |
val mk_mem: term * term -> term |
|
2510 | 31 |
val mk_binop: string -> term * term -> term |
32 |
val mk_binrel: string -> term * term -> term |
|
33 |
val dest_bin: string -> typ -> term -> term * term |
|
34 |
val natT: typ |
|
35 |
val zero: term |
|
36 |
val is_zero: term -> bool |
|
37 |
val mk_Suc: term -> term |
|
38 |
val dest_Suc: term -> term |
|
39 |
val mk_nat: int -> term |
|
4294 | 40 |
val dest_nat: term -> int |
4571 | 41 |
val unitT: typ |
42 |
val unit: term |
|
43 |
val is_unit: term -> bool |
|
44 |
val mk_prodT: typ * typ -> typ |
|
45 |
val dest_prodT: typ -> typ * typ |
|
46 |
val mk_prod: term * term -> term |
|
47 |
val dest_prod: term -> term * term |
|
48 |
val mk_fst: term -> term |
|
49 |
val mk_snd: term -> term |
|
923 | 50 |
end; |
51 |
||
2510 | 52 |
|
923 | 53 |
structure HOLogic: HOLOGIC = |
54 |
struct |
|
55 |
||
2510 | 56 |
(* basics *) |
923 | 57 |
|
58 |
val termC: class = "term"; |
|
59 |
val termS: sort = [termC]; |
|
60 |
||
2510 | 61 |
val termTVar = TVar (("'a", 0), termS); |
923 | 62 |
|
63 |
||
2510 | 64 |
(* bool and set *) |
923 | 65 |
|
66 |
val boolT = Type ("bool", []); |
|
67 |
||
68 |
fun mk_setT T = Type ("set", [T]); |
|
69 |
||
70 |
fun dest_setT (Type ("set", [T])) = T |
|
3794 | 71 |
| dest_setT T = raise TYPE ("dest_setT: set type expected", [T], []); |
923 | 72 |
|
73 |
||
74 |
val Trueprop = Const ("Trueprop", boolT --> propT); |
|
75 |
||
76 |
fun mk_Trueprop P = Trueprop $ P; |
|
77 |
||
78 |
fun dest_Trueprop (Const ("Trueprop", _) $ P) = P |
|
3794 | 79 |
| dest_Trueprop t = raise TERM ("dest_Trueprop", [t]); |
923 | 80 |
|
81 |
||
82 |
val conj = Const ("op &", [boolT, boolT] ---> boolT) |
|
83 |
and disj = Const ("op |", [boolT, boolT] ---> boolT) |
|
84 |
and imp = Const ("op -->", [boolT, boolT] ---> boolT); |
|
85 |
||
4466
305390f23734
Better equality handling in Blast_tac, usingd a new variant of hyp_subst_tac
paulson
parents:
4294
diff
changeset
|
86 |
fun dest_imp (Const("op -->",_) $ A $ B) = (A, B) |
305390f23734
Better equality handling in Blast_tac, usingd a new variant of hyp_subst_tac
paulson
parents:
4294
diff
changeset
|
87 |
| dest_imp t = raise TERM ("dest_imp", [t]); |
305390f23734
Better equality handling in Blast_tac, usingd a new variant of hyp_subst_tac
paulson
parents:
4294
diff
changeset
|
88 |
|
923 | 89 |
fun eq_const T = Const ("op =", [T, T] ---> boolT); |
90 |
fun mk_eq (t, u) = eq_const (fastype_of t) $ t $ u; |
|
91 |
||
92 |
fun all_const T = Const ("All", [T --> boolT] ---> boolT); |
|
93 |
fun mk_all (x, T, P) = all_const T $ absfree (x, T, P); |
|
94 |
||
95 |
fun exists_const T = Const ("Ex", [T --> boolT] ---> boolT); |
|
96 |
fun mk_exists (x, T, P) = exists_const T $ absfree (x, T, P); |
|
97 |
||
98 |
fun Collect_const T = Const ("Collect", [T --> boolT] ---> mk_setT T); |
|
99 |
fun mk_Collect (a, T, t) = Collect_const T $ absfree (a, T, t); |
|
100 |
||
101 |
fun mk_mem (x, A) = |
|
102 |
let val setT = fastype_of A in |
|
103 |
Const ("op :", [dest_setT setT, setT] ---> boolT) $ x $ A |
|
104 |
end; |
|
105 |
||
106 |
||
2510 | 107 |
(* binary oprations and relations *) |
108 |
||
109 |
fun mk_binop c (t, u) = |
|
110 |
let val T = fastype_of t in |
|
111 |
Const (c, [T, T] ---> T) $ t $ u |
|
112 |
end; |
|
113 |
||
114 |
fun mk_binrel c (t, u) = |
|
115 |
let val T = fastype_of t in |
|
116 |
Const (c, [T, T] ---> boolT) $ t $ u |
|
117 |
end; |
|
118 |
||
119 |
fun dest_bin c T (tm as Const (c', Type ("fun", [T', _])) $ t $ u) = |
|
120 |
if c = c' andalso T = T' then (t, u) |
|
3794 | 121 |
else raise TERM ("dest_bin " ^ c, [tm]) |
122 |
| dest_bin c _ tm = raise TERM ("dest_bin " ^ c, [tm]); |
|
2510 | 123 |
|
124 |
||
125 |
(* nat *) |
|
126 |
||
127 |
val natT = Type ("nat", []); |
|
128 |
||
4294 | 129 |
|
2510 | 130 |
val zero = Const ("0", natT); |
4294 | 131 |
|
132 |
fun is_zero (Const ("0", _)) = true |
|
133 |
| is_zero _ = false; |
|
134 |
||
2510 | 135 |
|
136 |
fun mk_Suc t = Const ("Suc", natT --> natT) $ t; |
|
137 |
||
138 |
fun dest_Suc (Const ("Suc", _) $ t) = t |
|
3794 | 139 |
| dest_Suc t = raise TERM ("dest_Suc", [t]); |
2510 | 140 |
|
4294 | 141 |
|
2510 | 142 |
fun mk_nat 0 = zero |
143 |
| mk_nat n = mk_Suc (mk_nat (n - 1)); |
|
144 |
||
4294 | 145 |
fun dest_nat (Const ("0", _)) = 0 |
146 |
| dest_nat (Const ("Suc", _) $ t) = dest_nat t + 1 |
|
147 |
| dest_nat t = raise TERM ("dest_nat", [t]); |
|
148 |
||
2510 | 149 |
|
4571 | 150 |
(* unit *) |
151 |
||
152 |
val unitT = Type ("unit", []); |
|
153 |
||
154 |
val unit = Const ("()", unitT); |
|
155 |
||
156 |
fun is_unit (Const ("()", _)) = true |
|
157 |
| is_unit _ = false; |
|
158 |
||
159 |
||
160 |
(* prod *) |
|
161 |
||
162 |
fun mk_prodT (T1, T2) = Type ("*", [T1, T2]); |
|
163 |
||
164 |
fun dest_prodT (Type ("*", [T1, T2])) = (T1, T2) |
|
165 |
| dest_prodT T = raise TYPE ("dest_prodT", [T], []); |
|
166 |
||
167 |
fun mk_prod (t1, t2) = |
|
168 |
let val T1 = fastype_of t1 and T2 = fastype_of t2 in |
|
169 |
Const ("Pair", [T1, T2] ---> mk_prodT (T1, T2)) $ t1 $ t2 |
|
170 |
end; |
|
171 |
||
172 |
fun dest_prod (Const ("Pair", _) $ t1 $ t2) = (t1, t2) |
|
173 |
| dest_prod t = raise TERM ("dest_prod", [t]); |
|
174 |
||
175 |
fun mk_fst p = |
|
176 |
let val pT = fastype_of p in |
|
177 |
Const ("fst", pT --> fst (dest_prodT pT)) $ p |
|
178 |
end; |
|
179 |
||
180 |
fun mk_snd p = |
|
181 |
let val pT = fastype_of p in |
|
182 |
Const ("snd", pT --> snd (dest_prodT pT)) $ p |
|
183 |
end; |
|
184 |
||
185 |
||
923 | 186 |
end; |