author | haftmann |
Fri, 24 Aug 2007 14:14:20 +0200 | |
changeset 24423 | ae9cd0e92423 |
parent 24219 | e558fe311376 |
child 24624 | b8383b1bbae3 |
permissions | -rw-r--r-- |
24219 | 1 |
(* Title: Pure/Isar/code_unit.ML |
2 |
ID: $Id$ |
|
3 |
Author: Florian Haftmann, TU Muenchen |
|
4 |
||
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
5 |
Basic units of code generation. Auxiliary. |
24219 | 6 |
*) |
7 |
||
8 |
signature CODE_UNIT = |
|
9 |
sig |
|
10 |
val string_of_typ: theory -> typ -> string |
|
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
11 |
val string_of_const: theory -> string -> string |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
12 |
val no_args: theory -> string -> int |
24219 | 13 |
val read_bare_const: theory -> string -> string * typ |
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
14 |
val read_const: theory -> string -> string |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
15 |
val read_const_exprs: theory -> (string list -> string list) |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
16 |
-> string list -> bool * string list |
24219 | 17 |
|
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
18 |
val constrset_of_consts: theory -> (string * typ) list |
24219 | 19 |
-> string * ((string * sort) list * (string * typ list) list) |
20 |
val typ_sort_inst: Sorts.algebra -> typ * sort |
|
21 |
-> sort Vartab.table -> sort Vartab.table |
|
22 |
||
23 |
val assert_rew: thm -> thm |
|
24 |
val mk_rew: thm -> thm |
|
25 |
val mk_func: thm -> thm |
|
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
26 |
val head_func: thm -> string * typ |
24219 | 27 |
val bad_thm: string -> 'a |
28 |
val error_thm: (thm -> thm) -> thm -> thm |
|
29 |
val warning_thm: (thm -> thm) -> thm -> thm option |
|
30 |
||
31 |
val inst_thm: sort Vartab.table -> thm -> thm |
|
32 |
val expand_eta: int -> thm -> thm |
|
33 |
val rewrite_func: thm list -> thm -> thm |
|
34 |
val norm_args: thm list -> thm list |
|
35 |
val norm_varnames: (string -> string) -> (string -> string) -> thm list -> thm list |
|
36 |
end; |
|
37 |
||
38 |
structure CodeUnit: CODE_UNIT = |
|
39 |
struct |
|
40 |
||
41 |
||
42 |
(* auxiliary *) |
|
43 |
||
44 |
exception BAD_THM of string; |
|
45 |
fun bad_thm msg = raise BAD_THM msg; |
|
46 |
fun error_thm f thm = f thm handle BAD_THM msg => error msg; |
|
47 |
fun warning_thm f thm = SOME (f thm) handle BAD_THM msg |
|
48 |
=> (warning ("code generator: " ^ msg); NONE); |
|
49 |
||
50 |
fun string_of_typ thy = setmp show_sorts true (Sign.string_of_typ thy); |
|
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
51 |
fun string_of_const thy c = case Class.param_const thy c |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
52 |
of SOME (c, tyco) => Sign.extern_const thy c ^ " " ^ enclose "[" "]" (Sign.extern_type thy tyco) |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
53 |
| NONE => Sign.extern_const thy c; |
24219 | 54 |
|
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
55 |
fun no_args thy = length o fst o strip_type o Sign.the_const_type thy; |
24219 | 56 |
|
57 |
(* reading constants as terms and wildcards pattern *) |
|
58 |
||
59 |
fun read_bare_const thy raw_t = |
|
60 |
let |
|
61 |
val t = Sign.read_term thy raw_t; |
|
62 |
in case try dest_Const t |
|
63 |
of SOME c_ty => c_ty |
|
64 |
| NONE => error ("Not a constant: " ^ Sign.string_of_term thy t) |
|
65 |
end; |
|
66 |
||
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
67 |
fun read_const thy = Class.unoverload_const thy o read_bare_const thy; |
24219 | 68 |
|
69 |
local |
|
70 |
||
71 |
fun consts_of thy some_thyname = |
|
72 |
let |
|
73 |
val this_thy = Option.map theory some_thyname |> the_default thy; |
|
74 |
val cs = Symtab.fold (fn (c, (_, NONE)) => cons c | _ => I) |
|
75 |
((snd o #constants o Consts.dest o #consts o Sign.rep_sg) this_thy) []; |
|
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
76 |
fun belongs_here thyname c = |
24219 | 77 |
not (exists (fn thy' => Sign.declared_const thy' c) (Theory.parents_of this_thy)) |
78 |
in case some_thyname |
|
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
79 |
of NONE => cs |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
80 |
| SOME thyname => filter (belongs_here thyname) cs |
24219 | 81 |
end; |
82 |
||
83 |
fun read_const_expr thy "*" = ([], consts_of thy NONE) |
|
84 |
| read_const_expr thy s = if String.isSuffix ".*" s |
|
85 |
then ([], consts_of thy (SOME (unsuffix ".*" s))) |
|
86 |
else ([read_const thy s], []); |
|
87 |
||
88 |
in |
|
89 |
||
90 |
fun read_const_exprs thy select exprs = |
|
91 |
case (pairself flat o split_list o map (read_const_expr thy)) exprs |
|
92 |
of (consts, []) => (false, consts) |
|
93 |
| (consts, consts') => (true, consts @ select consts'); |
|
94 |
||
95 |
end; (*local*) |
|
96 |
||
97 |
||
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
98 |
(* constructor sets *) |
24219 | 99 |
|
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
100 |
fun constrset_of_consts thy cs = |
24219 | 101 |
let |
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
102 |
fun no_constr (c, ty) = error ("Not a datatype constructor: " ^ string_of_const thy c |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
103 |
^ " :: " ^ string_of_typ thy ty); |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
104 |
fun last_typ c_ty ty = |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
105 |
let |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
106 |
val frees = typ_tfrees ty; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
107 |
val (tyco, vs) = ((apsnd o map) (dest_TFree) o dest_Type o snd o strip_type) ty |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
108 |
handle TYPE _ => no_constr c_ty |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
109 |
val _ = if has_duplicates (eq_fst (op =)) vs then no_constr c_ty else (); |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
110 |
val _ = if length frees <> length vs then no_constr c_ty else (); |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
111 |
in (tyco, vs) end; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
112 |
fun ty_sorts (c, ty) = |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
113 |
let |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
114 |
val ty_decl = (Logic.unvarifyT o Sign.the_const_type thy) c; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
115 |
val (tyco, vs_decl) = last_typ (c, ty) ty_decl; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
116 |
val (_, vs) = last_typ (c, ty) ty; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
117 |
in ((tyco, map snd vs), (c, (map fst vs, ty_decl))) end; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
118 |
fun add ((tyco', sorts'), c) ((tyco, sorts), cs) = |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
119 |
let |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
120 |
val _ = if tyco' <> tyco |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
121 |
then error "Different type constructors in constructor set" |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
122 |
else (); |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
123 |
val sorts'' = map2 (curry (Sorts.inter_sort (Sign.classes_of thy))) sorts' sorts |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
124 |
in ((tyco, sorts), c :: cs) end; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
125 |
fun inst vs' (c, (vs, ty)) = |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
126 |
let |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
127 |
val the_v = the o AList.lookup (op =) (vs ~~ vs'); |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
128 |
val ty' = map_atyps (fn TFree (v, _) => TFree (the_v v)) ty; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
129 |
in (c, (fst o strip_type) ty') end; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
130 |
val c' :: cs' = map ty_sorts cs; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
131 |
val ((tyco, sorts), cs'') = fold add cs' (apsnd single c'); |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
132 |
val vs = Name.names Name.context "'a" sorts; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
133 |
val cs''' = map (inst vs) cs''; |
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
134 |
in (tyco, (vs, cs''')) end; |
24219 | 135 |
|
136 |
||
137 |
(* dictionary values *) |
|
138 |
||
139 |
fun typ_sort_inst algebra = |
|
140 |
let |
|
141 |
val inters = Sorts.inter_sort algebra; |
|
142 |
fun match _ [] = I |
|
143 |
| match (TVar (v, S)) S' = Vartab.map_default (v, []) (fn S'' => inters (S, inters (S', S''))) |
|
144 |
| match (Type (a, Ts)) S = |
|
145 |
fold2 match Ts (Sorts.mg_domain algebra a S) |
|
146 |
in uncurry match end; |
|
147 |
||
148 |
||
149 |
(* making rewrite theorems *) |
|
150 |
||
151 |
fun assert_rew thm = |
|
152 |
let |
|
153 |
val (lhs, rhs) = (Logic.dest_equals o Thm.plain_prop_of) thm |
|
154 |
handle TERM _ => bad_thm ("Not an equation: " ^ Display.string_of_thm thm) |
|
155 |
| THM _ => bad_thm ("Not an equation: " ^ Display.string_of_thm thm); |
|
156 |
fun vars_of t = fold_aterms |
|
157 |
(fn Var (v, _) => insert (op =) v |
|
158 |
| Free _ => bad_thm ("Illegal free variable in rewrite theorem\n" |
|
159 |
^ Display.string_of_thm thm) |
|
160 |
| _ => I) t []; |
|
161 |
fun tvars_of t = fold_term_types |
|
162 |
(fn _ => fold_atyps (fn TVar (v, _) => insert (op =) v |
|
163 |
| TFree _ => bad_thm |
|
164 |
("Illegal free type variable in rewrite theorem\n" ^ Display.string_of_thm thm))) t []; |
|
165 |
val lhs_vs = vars_of lhs; |
|
166 |
val rhs_vs = vars_of rhs; |
|
167 |
val lhs_tvs = tvars_of lhs; |
|
168 |
val rhs_tvs = tvars_of lhs; |
|
169 |
val _ = if null (subtract (op =) lhs_vs rhs_vs) |
|
170 |
then () |
|
171 |
else bad_thm ("Free variables on right hand side of rewrite theorem\n" |
|
172 |
^ Display.string_of_thm thm); |
|
173 |
val _ = if null (subtract (op =) lhs_tvs rhs_tvs) |
|
174 |
then () |
|
175 |
else bad_thm ("Free type variables on right hand side of rewrite theorem\n" |
|
176 |
^ Display.string_of_thm thm) |
|
177 |
in thm end; |
|
178 |
||
179 |
fun mk_rew thm = |
|
180 |
let |
|
181 |
val thy = Thm.theory_of_thm thm; |
|
182 |
val ctxt = ProofContext.init thy; |
|
183 |
in |
|
184 |
thm |
|
185 |
|> LocalDefs.meta_rewrite_rule ctxt |
|
186 |
|> assert_rew |
|
187 |
end; |
|
188 |
||
189 |
||
190 |
(* making defining equations *) |
|
191 |
||
192 |
fun assert_func thm = |
|
193 |
let |
|
194 |
val thy = Thm.theory_of_thm thm; |
|
195 |
val (head, args) = (strip_comb o fst o Logic.dest_equals |
|
196 |
o ObjectLogic.drop_judgment thy o Thm.plain_prop_of) thm; |
|
197 |
val _ = case head of Const _ => () | _ => |
|
198 |
bad_thm ("Equation not headed by constant\n" ^ Display.string_of_thm thm); |
|
199 |
val _ = |
|
200 |
if has_duplicates (op =) |
|
201 |
((fold o fold_aterms) (fn Var (v, _) => cons v |
|
202 |
| _ => I |
|
203 |
) args []) |
|
204 |
then bad_thm ("Duplicated variables on left hand side of equation\n" |
|
205 |
^ Display.string_of_thm thm) |
|
206 |
else () |
|
207 |
fun check _ (Abs _) = bad_thm |
|
208 |
("Abstraction on left hand side of equation\n" |
|
209 |
^ Display.string_of_thm thm) |
|
210 |
| check 0 (Var _) = () |
|
211 |
| check _ (Var _) = bad_thm |
|
212 |
("Variable with application on left hand side of defining equation\n" |
|
213 |
^ Display.string_of_thm thm) |
|
214 |
| check n (t1 $ t2) = (check (n+1) t1; check 0 t2) |
|
215 |
| check n (Const (_, ty)) = if n <> (length o fst o strip_type) ty |
|
216 |
then bad_thm |
|
217 |
("Partially applied constant on left hand side of equation\n" |
|
218 |
^ Display.string_of_thm thm) |
|
219 |
else (); |
|
220 |
val _ = map (check 0) args; |
|
221 |
in thm end; |
|
222 |
||
223 |
val mk_func = assert_func o mk_rew; |
|
224 |
||
225 |
fun head_func thm = |
|
226 |
let |
|
227 |
val thy = Thm.theory_of_thm thm; |
|
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
228 |
val Const (c, ty) = (fst o strip_comb o fst o Logic.dest_equals |
24219 | 229 |
o ObjectLogic.drop_judgment thy o Thm.plain_prop_of) thm; |
24423
ae9cd0e92423
overloaded definitions accompanied by explicit constants
haftmann
parents:
24219
diff
changeset
|
230 |
in (c, ty) end; |
24219 | 231 |
|
232 |
||
233 |
(* utilities *) |
|
234 |
||
235 |
fun inst_thm tvars' thm = |
|
236 |
let |
|
237 |
val thy = Thm.theory_of_thm thm; |
|
238 |
val tvars = (Term.add_tvars o Thm.prop_of) thm []; |
|
239 |
fun mk_inst (tvar as (v, _)) = case Vartab.lookup tvars' v |
|
240 |
of SOME sort => SOME (pairself (Thm.ctyp_of thy o TVar) (tvar, (v, sort))) |
|
241 |
| NONE => NONE; |
|
242 |
val insts = map_filter mk_inst tvars; |
|
243 |
in Thm.instantiate (insts, []) thm end; |
|
244 |
||
245 |
fun expand_eta k thm = |
|
246 |
let |
|
247 |
val thy = Thm.theory_of_thm thm; |
|
248 |
val (lhs, rhs) = (Logic.dest_equals o Thm.plain_prop_of) thm; |
|
249 |
val (head, args) = strip_comb lhs; |
|
250 |
val l = if k = ~1 |
|
251 |
then (length o fst o strip_abs) rhs |
|
252 |
else Int.max (0, k - length args); |
|
253 |
val used = Name.make_context (map (fst o fst) (Term.add_vars lhs [])); |
|
254 |
fun get_name _ 0 used = ([], used) |
|
255 |
| get_name (Abs (v, ty, t)) k used = |
|
256 |
used |
|
257 |
|> Name.variants [v] |
|
258 |
||>> get_name t (k - 1) |
|
259 |
|>> (fn ([v'], vs') => (v', ty) :: vs') |
|
260 |
| get_name t k used = |
|
261 |
let |
|
262 |
val (tys, _) = (strip_type o fastype_of) t |
|
263 |
in case tys |
|
264 |
of [] => raise TERM ("expand_eta", [t]) |
|
265 |
| ty :: _ => |
|
266 |
used |
|
267 |
|> Name.variants [""] |
|
268 |
|-> (fn [v] => get_name (t $ Var ((v, 0), ty)) (k - 1) |
|
269 |
#>> (fn vs' => (v, ty) :: vs')) |
|
270 |
end; |
|
271 |
val (vs, _) = get_name rhs l used; |
|
272 |
val vs_refl = map (fn (v, ty) => Thm.reflexive (Thm.cterm_of thy (Var ((v, 0), ty)))) vs; |
|
273 |
in |
|
274 |
thm |
|
275 |
|> fold (fn refl => fn thm => Thm.combination thm refl) vs_refl |
|
276 |
|> Conv.fconv_rule Drule.beta_eta_conversion |
|
277 |
end; |
|
278 |
||
279 |
fun rewrite_func rewrites thm = |
|
280 |
let |
|
281 |
val rewrite = MetaSimplifier.rewrite false rewrites; |
|
282 |
val (ct_eq, [ct_lhs, ct_rhs]) = (Drule.strip_comb o Thm.cprop_of) thm; |
|
283 |
val Const ("==", _) = Thm.term_of ct_eq; |
|
284 |
val (ct_f, ct_args) = Drule.strip_comb ct_lhs; |
|
285 |
val rhs' = rewrite ct_rhs; |
|
286 |
val args' = map rewrite ct_args; |
|
287 |
val lhs' = Thm.symmetric (fold (fn th1 => fn th2 => Thm.combination th2 th1) |
|
288 |
args' (Thm.reflexive ct_f)); |
|
289 |
in Thm.transitive (Thm.transitive lhs' thm) rhs' end; |
|
290 |
||
291 |
fun norm_args thms = |
|
292 |
let |
|
293 |
val num_args_of = length o snd o strip_comb o fst o Logic.dest_equals; |
|
294 |
val k = fold (curry Int.max o num_args_of o Thm.plain_prop_of) thms 0; |
|
295 |
in |
|
296 |
thms |
|
297 |
|> map (expand_eta k) |
|
298 |
|> map (Conv.fconv_rule Drule.beta_eta_conversion) |
|
299 |
end; |
|
300 |
||
301 |
fun canonical_tvars purify_tvar thm = |
|
302 |
let |
|
303 |
val ctyp = Thm.ctyp_of (Thm.theory_of_thm thm); |
|
304 |
fun tvars_subst_for thm = (fold_types o fold_atyps) |
|
305 |
(fn TVar (v_i as (v, _), sort) => let |
|
306 |
val v' = purify_tvar v |
|
307 |
in if v = v' then I |
|
308 |
else insert (op =) (v_i, (v', sort)) end |
|
309 |
| _ => I) (prop_of thm) []; |
|
310 |
fun mk_inst (v_i, (v', sort)) (maxidx, acc) = |
|
311 |
let |
|
312 |
val ty = TVar (v_i, sort) |
|
313 |
in |
|
314 |
(maxidx + 1, (ctyp ty, ctyp (TVar ((v', maxidx), sort))) :: acc) |
|
315 |
end; |
|
316 |
val maxidx = Thm.maxidx_of thm + 1; |
|
317 |
val (_, inst) = fold mk_inst (tvars_subst_for thm) (maxidx + 1, []); |
|
318 |
in Thm.instantiate (inst, []) thm end; |
|
319 |
||
320 |
fun canonical_vars purify_var thm = |
|
321 |
let |
|
322 |
val cterm = Thm.cterm_of (Thm.theory_of_thm thm); |
|
323 |
fun vars_subst_for thm = fold_aterms |
|
324 |
(fn Var (v_i as (v, _), ty) => let |
|
325 |
val v' = purify_var v |
|
326 |
in if v = v' then I |
|
327 |
else insert (op =) (v_i, (v', ty)) end |
|
328 |
| _ => I) (prop_of thm) []; |
|
329 |
fun mk_inst (v_i as (v, i), (v', ty)) (maxidx, acc) = |
|
330 |
let |
|
331 |
val t = Var (v_i, ty) |
|
332 |
in |
|
333 |
(maxidx + 1, (cterm t, cterm (Var ((v', maxidx), ty))) :: acc) |
|
334 |
end; |
|
335 |
val maxidx = Thm.maxidx_of thm + 1; |
|
336 |
val (_, inst) = fold mk_inst (vars_subst_for thm) (maxidx + 1, []); |
|
337 |
in Thm.instantiate ([], inst) thm end; |
|
338 |
||
339 |
fun canonical_absvars purify_var thm = |
|
340 |
let |
|
341 |
val t = Thm.plain_prop_of thm; |
|
342 |
val t' = Term.map_abs_vars purify_var t; |
|
343 |
in Thm.rename_boundvars t t' thm end; |
|
344 |
||
345 |
fun norm_varnames purify_tvar purify_var thms = |
|
346 |
let |
|
347 |
fun burrow_thms f [] = [] |
|
348 |
| burrow_thms f thms = |
|
349 |
thms |
|
350 |
|> Conjunction.intr_balanced |
|
351 |
|> f |
|
352 |
|> Conjunction.elim_balanced (length thms) |
|
353 |
in |
|
354 |
thms |
|
355 |
|> burrow_thms (canonical_tvars purify_tvar) |
|
356 |
|> map (canonical_vars purify_var) |
|
357 |
|> map (canonical_absvars purify_var) |
|
358 |
|> map Drule.zero_var_indexes |
|
359 |
end; |
|
360 |
||
361 |
end; |