|
1 (* Title: Substitutions/uterm.ML |
|
2 Author: Martin Coen, Cambridge University Computer Laboratory |
|
3 Copyright 1993 University of Cambridge |
|
4 |
|
5 Simple term structure for unifiation. |
|
6 Binary trees with leaves that are constants or variables. |
|
7 *) |
|
8 |
|
9 open UTerm; |
|
10 |
|
11 val uterm_con_defs = [VAR_def, CONST_def, COMB_def]; |
|
12 |
|
13 goal UTerm.thy "uterm(A) = A <+> A <+> (uterm(A) <*> uterm(A))"; |
|
14 let val rew = rewrite_rule uterm_con_defs in |
|
15 by (fast_tac (univ_cs addSIs (equalityI :: map rew uterm.intrs) |
|
16 addEs [rew uterm.elim]) 1) |
|
17 end; |
|
18 qed "uterm_unfold"; |
|
19 |
|
20 (** the uterm functional **) |
|
21 |
|
22 (*This justifies using uterm in other recursive type definitions*) |
|
23 goalw UTerm.thy uterm.defs "!!A B. A<=B ==> uterm(A) <= uterm(B)"; |
|
24 by (REPEAT (ares_tac (lfp_mono::basic_monos) 1)); |
|
25 qed "uterm_mono"; |
|
26 |
|
27 (** Type checking rules -- uterm creates well-founded sets **) |
|
28 |
|
29 goalw UTerm.thy (uterm_con_defs @ uterm.defs) "uterm(sexp) <= sexp"; |
|
30 by (rtac lfp_lowerbound 1); |
|
31 by (fast_tac (univ_cs addIs sexp.intrs@[sexp_In0I,sexp_In1I]) 1); |
|
32 qed "uterm_sexp"; |
|
33 |
|
34 (* A <= sexp ==> uterm(A) <= sexp *) |
|
35 bind_thm ("uterm_subset_sexp", ([uterm_mono, uterm_sexp] MRS subset_trans)); |
|
36 |
|
37 (** Induction **) |
|
38 |
|
39 (*Induction for the type 'a uterm *) |
|
40 val prems = goalw UTerm.thy [Var_def,Const_def,Comb_def] |
|
41 "[| !!x.P(Var(x)); !!x.P(Const(x)); \ |
|
42 \ !!u v. [| P(u); P(v) |] ==> P(Comb u v) |] ==> P(t)"; |
|
43 by (rtac (Rep_uterm_inverse RS subst) 1); (*types force good instantiation*) |
|
44 by (rtac (Rep_uterm RS uterm.induct) 1); |
|
45 by (REPEAT (ares_tac prems 1 |
|
46 ORELSE eresolve_tac [rangeE, ssubst, Abs_uterm_inverse RS subst] 1)); |
|
47 qed "uterm_induct"; |
|
48 |
|
49 (*Perform induction on xs. *) |
|
50 fun uterm_ind_tac a M = |
|
51 EVERY [res_inst_tac [("t",a)] uterm_induct M, |
|
52 rename_last_tac a ["1"] (M+1)]; |
|
53 |
|
54 |
|
55 (*** Isomorphisms ***) |
|
56 |
|
57 goal UTerm.thy "inj(Rep_uterm)"; |
|
58 by (rtac inj_inverseI 1); |
|
59 by (rtac Rep_uterm_inverse 1); |
|
60 qed "inj_Rep_uterm"; |
|
61 |
|
62 goal UTerm.thy "inj_onto Abs_uterm (uterm (range Leaf))"; |
|
63 by (rtac inj_onto_inverseI 1); |
|
64 by (etac Abs_uterm_inverse 1); |
|
65 qed "inj_onto_Abs_uterm"; |
|
66 |
|
67 (** Distinctness of constructors **) |
|
68 |
|
69 goalw UTerm.thy uterm_con_defs "~ CONST(c) = COMB u v"; |
|
70 by (rtac notI 1); |
|
71 by (etac (In1_inject RS (In0_not_In1 RS notE)) 1); |
|
72 qed "CONST_not_COMB"; |
|
73 bind_thm ("COMB_not_CONST", (CONST_not_COMB RS not_sym)); |
|
74 bind_thm ("CONST_neq_COMB", (CONST_not_COMB RS notE)); |
|
75 val COMB_neq_CONST = sym RS CONST_neq_COMB; |
|
76 |
|
77 goalw UTerm.thy uterm_con_defs "~ COMB u v = VAR(x)"; |
|
78 by (rtac In1_not_In0 1); |
|
79 qed "COMB_not_VAR"; |
|
80 bind_thm ("VAR_not_COMB", (COMB_not_VAR RS not_sym)); |
|
81 bind_thm ("COMB_neq_VAR", (COMB_not_VAR RS notE)); |
|
82 val VAR_neq_COMB = sym RS COMB_neq_VAR; |
|
83 |
|
84 goalw UTerm.thy uterm_con_defs "~ VAR(x) = CONST(c)"; |
|
85 by (rtac In0_not_In1 1); |
|
86 qed "VAR_not_CONST"; |
|
87 bind_thm ("CONST_not_VAR", (VAR_not_CONST RS not_sym)); |
|
88 bind_thm ("VAR_neq_CONST", (VAR_not_CONST RS notE)); |
|
89 val CONST_neq_VAR = sym RS VAR_neq_CONST; |
|
90 |
|
91 |
|
92 goalw UTerm.thy [Const_def,Comb_def] "~ Const(c) = Comb u v"; |
|
93 by (rtac (CONST_not_COMB RS (inj_onto_Abs_uterm RS inj_onto_contraD)) 1); |
|
94 by (REPEAT (resolve_tac (uterm.intrs @ [rangeI, Rep_uterm]) 1)); |
|
95 qed "Const_not_Comb"; |
|
96 bind_thm ("Comb_not_Const", (Const_not_Comb RS not_sym)); |
|
97 bind_thm ("Const_neq_Comb", (Const_not_Comb RS notE)); |
|
98 val Comb_neq_Const = sym RS Const_neq_Comb; |
|
99 |
|
100 goalw UTerm.thy [Comb_def,Var_def] "~ Comb u v = Var(x)"; |
|
101 by (rtac (COMB_not_VAR RS (inj_onto_Abs_uterm RS inj_onto_contraD)) 1); |
|
102 by (REPEAT (resolve_tac (uterm.intrs @ [rangeI, Rep_uterm]) 1)); |
|
103 qed "Comb_not_Var"; |
|
104 bind_thm ("Var_not_Comb", (Comb_not_Var RS not_sym)); |
|
105 bind_thm ("Comb_neq_Var", (Comb_not_Var RS notE)); |
|
106 val Var_neq_Comb = sym RS Comb_neq_Var; |
|
107 |
|
108 goalw UTerm.thy [Var_def,Const_def] "~ Var(x) = Const(c)"; |
|
109 by (rtac (VAR_not_CONST RS (inj_onto_Abs_uterm RS inj_onto_contraD)) 1); |
|
110 by (REPEAT (resolve_tac (uterm.intrs @ [rangeI, Rep_uterm]) 1)); |
|
111 qed "Var_not_Const"; |
|
112 bind_thm ("Const_not_Var", (Var_not_Const RS not_sym)); |
|
113 bind_thm ("Var_neq_Const", (Var_not_Const RS notE)); |
|
114 val Const_neq_Var = sym RS Var_neq_Const; |
|
115 |
|
116 |
|
117 (** Injectiveness of CONST and Const **) |
|
118 |
|
119 val inject_cs = HOL_cs addSEs [Scons_inject] |
|
120 addSDs [In0_inject,In1_inject]; |
|
121 |
|
122 goalw UTerm.thy [VAR_def] "(VAR(M)=VAR(N)) = (M=N)"; |
|
123 by (fast_tac inject_cs 1); |
|
124 qed "VAR_VAR_eq"; |
|
125 |
|
126 goalw UTerm.thy [CONST_def] "(CONST(M)=CONST(N)) = (M=N)"; |
|
127 by (fast_tac inject_cs 1); |
|
128 qed "CONST_CONST_eq"; |
|
129 |
|
130 goalw UTerm.thy [COMB_def] "(COMB K L = COMB M N) = (K=M & L=N)"; |
|
131 by (fast_tac inject_cs 1); |
|
132 qed "COMB_COMB_eq"; |
|
133 |
|
134 bind_thm ("VAR_inject", (VAR_VAR_eq RS iffD1)); |
|
135 bind_thm ("CONST_inject", (CONST_CONST_eq RS iffD1)); |
|
136 bind_thm ("COMB_inject", (COMB_COMB_eq RS iffD1 RS conjE)); |
|
137 |
|
138 |
|
139 (*For reasoning about abstract uterm constructors*) |
|
140 val uterm_cs = set_cs addIs uterm.intrs @ [Rep_uterm] |
|
141 addSEs [CONST_neq_COMB,COMB_neq_VAR,VAR_neq_CONST, |
|
142 COMB_neq_CONST,VAR_neq_COMB,CONST_neq_VAR, |
|
143 COMB_inject] |
|
144 addSDs [VAR_inject,CONST_inject, |
|
145 inj_onto_Abs_uterm RS inj_ontoD, |
|
146 inj_Rep_uterm RS injD, Leaf_inject]; |
|
147 |
|
148 goalw UTerm.thy [Var_def] "(Var(x)=Var(y)) = (x=y)"; |
|
149 by (fast_tac uterm_cs 1); |
|
150 qed "Var_Var_eq"; |
|
151 bind_thm ("Var_inject", (Var_Var_eq RS iffD1)); |
|
152 |
|
153 goalw UTerm.thy [Const_def] "(Const(x)=Const(y)) = (x=y)"; |
|
154 by (fast_tac uterm_cs 1); |
|
155 qed "Const_Const_eq"; |
|
156 bind_thm ("Const_inject", (Const_Const_eq RS iffD1)); |
|
157 |
|
158 goalw UTerm.thy [Comb_def] "(Comb u v =Comb x y) = (u=x & v=y)"; |
|
159 by (fast_tac uterm_cs 1); |
|
160 qed "Comb_Comb_eq"; |
|
161 bind_thm ("Comb_inject", (Comb_Comb_eq RS iffD1 RS conjE)); |
|
162 |
|
163 val [major] = goal UTerm.thy "VAR(M): uterm(A) ==> M : A"; |
|
164 by (rtac (major RS setup_induction) 1); |
|
165 by (etac uterm.induct 1); |
|
166 by (ALLGOALS (fast_tac uterm_cs)); |
|
167 qed "VAR_D"; |
|
168 |
|
169 val [major] = goal UTerm.thy "CONST(M): uterm(A) ==> M : A"; |
|
170 by (rtac (major RS setup_induction) 1); |
|
171 by (etac uterm.induct 1); |
|
172 by (ALLGOALS (fast_tac uterm_cs)); |
|
173 qed "CONST_D"; |
|
174 |
|
175 val [major] = goal UTerm.thy |
|
176 "COMB M N: uterm(A) ==> M: uterm(A) & N: uterm(A)"; |
|
177 by (rtac (major RS setup_induction) 1); |
|
178 by (etac uterm.induct 1); |
|
179 by (ALLGOALS (fast_tac uterm_cs)); |
|
180 qed "COMB_D"; |
|
181 |
|
182 (*Basic ss with constructors and their freeness*) |
|
183 val uterm_free_simps = uterm.intrs @ |
|
184 [Const_not_Comb,Comb_not_Var,Var_not_Const, |
|
185 Comb_not_Const,Var_not_Comb,Const_not_Var, |
|
186 Var_Var_eq,Const_Const_eq,Comb_Comb_eq, |
|
187 CONST_not_COMB,COMB_not_VAR,VAR_not_CONST, |
|
188 COMB_not_CONST,VAR_not_COMB,CONST_not_VAR, |
|
189 VAR_VAR_eq,CONST_CONST_eq,COMB_COMB_eq]; |
|
190 val uterm_free_ss = HOL_ss addsimps uterm_free_simps; |
|
191 |
|
192 goal UTerm.thy "!u. t~=Comb t u"; |
|
193 by (uterm_ind_tac "t" 1); |
|
194 by (rtac (Var_not_Comb RS allI) 1); |
|
195 by (rtac (Const_not_Comb RS allI) 1); |
|
196 by (asm_simp_tac uterm_free_ss 1); |
|
197 qed "t_not_Comb_t"; |
|
198 |
|
199 goal UTerm.thy "!t. u~=Comb t u"; |
|
200 by (uterm_ind_tac "u" 1); |
|
201 by (rtac (Var_not_Comb RS allI) 1); |
|
202 by (rtac (Const_not_Comb RS allI) 1); |
|
203 by (asm_simp_tac uterm_free_ss 1); |
|
204 qed "u_not_Comb_u"; |
|
205 |
|
206 |
|
207 (*** UTerm_rec -- by wf recursion on pred_sexp ***) |
|
208 |
|
209 val UTerm_rec_unfold = |
|
210 [UTerm_rec_def, wf_pred_sexp RS wf_trancl] MRS def_wfrec; |
|
211 |
|
212 (** conversion rules **) |
|
213 |
|
214 goalw UTerm.thy [VAR_def] "UTerm_rec (VAR x) b c d = b(x)"; |
|
215 by (rtac (UTerm_rec_unfold RS trans) 1); |
|
216 by (simp_tac (HOL_ss addsimps [Case_In0]) 1); |
|
217 qed "UTerm_rec_VAR"; |
|
218 |
|
219 goalw UTerm.thy [CONST_def] "UTerm_rec (CONST x) b c d = c(x)"; |
|
220 by (rtac (UTerm_rec_unfold RS trans) 1); |
|
221 by (simp_tac (HOL_ss addsimps [Case_In0,Case_In1]) 1); |
|
222 qed "UTerm_rec_CONST"; |
|
223 |
|
224 goalw UTerm.thy [COMB_def] |
|
225 "!!M N. [| M: sexp; N: sexp |] ==> \ |
|
226 \ UTerm_rec (COMB M N) b c d = \ |
|
227 \ d M N (UTerm_rec M b c d) (UTerm_rec N b c d)"; |
|
228 by (rtac (UTerm_rec_unfold RS trans) 1); |
|
229 by (simp_tac (HOL_ss addsimps [Split,Case_In1]) 1); |
|
230 by (asm_simp_tac (pred_sexp_ss addsimps [In1_def]) 1); |
|
231 qed "UTerm_rec_COMB"; |
|
232 |
|
233 (*** uterm_rec -- by UTerm_rec ***) |
|
234 |
|
235 val Rep_uterm_in_sexp = |
|
236 Rep_uterm RS (range_Leaf_subset_sexp RS uterm_subset_sexp RS subsetD); |
|
237 |
|
238 val uterm_rec_simps = |
|
239 uterm.intrs @ |
|
240 [UTerm_rec_VAR, UTerm_rec_CONST, UTerm_rec_COMB, |
|
241 Abs_uterm_inverse, Rep_uterm_inverse, |
|
242 Rep_uterm, rangeI, inj_Leaf, Inv_f_f, Rep_uterm_in_sexp]; |
|
243 val uterm_rec_ss = HOL_ss addsimps uterm_rec_simps; |
|
244 |
|
245 goalw UTerm.thy [uterm_rec_def, Var_def] "uterm_rec (Var x) b c d = b(x)"; |
|
246 by (simp_tac uterm_rec_ss 1); |
|
247 qed "uterm_rec_Var"; |
|
248 |
|
249 goalw UTerm.thy [uterm_rec_def, Const_def] "uterm_rec (Const x) b c d = c(x)"; |
|
250 by (simp_tac uterm_rec_ss 1); |
|
251 qed "uterm_rec_Const"; |
|
252 |
|
253 goalw UTerm.thy [uterm_rec_def, Comb_def] |
|
254 "uterm_rec (Comb u v) b c d = d u v (uterm_rec u b c d) (uterm_rec v b c d)"; |
|
255 by (simp_tac uterm_rec_ss 1); |
|
256 qed "uterm_rec_Comb"; |
|
257 |
|
258 val uterm_simps = [UTerm_rec_VAR, UTerm_rec_CONST, UTerm_rec_COMB, |
|
259 uterm_rec_Var, uterm_rec_Const, uterm_rec_Comb]; |
|
260 val uterm_ss = uterm_free_ss addsimps uterm_simps; |
|
261 |
|
262 |
|
263 (**********) |
|
264 |
|
265 val uterm_rews = [uterm_rec_Var,uterm_rec_Const,uterm_rec_Comb, |
|
266 t_not_Comb_t,u_not_Comb_u, |
|
267 Const_not_Comb,Comb_not_Var,Var_not_Const, |
|
268 Comb_not_Const,Var_not_Comb,Const_not_Var, |
|
269 Var_Var_eq,Const_Const_eq,Comb_Comb_eq]; |
|
270 |