15 |
15 |
16 (*typ instantiations*) |
16 (*typ instantiations*) |
17 val inst_thm: sort Vartab.table -> thm -> thm |
17 val inst_thm: sort Vartab.table -> thm -> thm |
18 val constrain_thm: sort -> thm -> thm |
18 val constrain_thm: sort -> thm -> thm |
19 |
19 |
20 (*constants*) |
20 (*constant aliasses*) |
21 val add_const_alias: thm -> theory -> theory |
21 val add_const_alias: thm -> theory -> theory |
22 val subst_alias: theory -> string -> string |
22 val subst_alias: theory -> string -> string |
|
23 val resubst_alias: theory -> string -> string |
|
24 val triv_classes: theory -> class list |
|
25 |
|
26 (*constants*) |
23 val string_of_typ: theory -> typ -> string |
27 val string_of_typ: theory -> typ -> string |
24 val string_of_const: theory -> string -> string |
28 val string_of_const: theory -> string -> string |
25 val no_args: theory -> string -> int |
29 val no_args: theory -> string -> int |
26 val check_const: theory -> term -> string |
30 val check_const: theory -> term -> string |
27 val read_bare_const: theory -> string -> string * typ |
31 val read_bare_const: theory -> string -> string * typ |
211 |
215 |
212 (* const aliasses *) |
216 (* const aliasses *) |
213 |
217 |
214 structure ConstAlias = TheoryDataFun |
218 structure ConstAlias = TheoryDataFun |
215 ( |
219 ( |
216 type T = ((string * string) * thm) list; |
220 type T = ((string * string) * thm) list * class list; |
217 val empty = []; |
221 val empty = ([], []); |
218 val copy = I; |
222 val copy = I; |
219 val extend = I; |
223 val extend = I; |
220 fun merge _ = Library.merge (eq_snd Thm.eq_thm_prop); |
224 fun merge _ ((alias1, classes1), (alias2, classes2)) = |
|
225 (Library.merge (eq_snd Thm.eq_thm_prop) (alias1, alias2), |
|
226 Library.merge (op =) (classes1, classes2)); |
221 ); |
227 ); |
222 |
228 |
223 fun add_const_alias thm = |
229 fun add_const_alias thm = |
224 let |
230 let |
225 val t = Thm.prop_of thm; |
231 val t = Thm.prop_of thm; |
228 of SOME lhs_rhs => lhs_rhs |
234 of SOME lhs_rhs => lhs_rhs |
229 | _ => error ("Not an equation: " ^ Display.string_of_thm thm); |
235 | _ => error ("Not an equation: " ^ Display.string_of_thm thm); |
230 val c_c' = case try (pairself (AxClass.unoverload_const thy o dest_Const)) lhs_rhs |
236 val c_c' = case try (pairself (AxClass.unoverload_const thy o dest_Const)) lhs_rhs |
231 of SOME c_c' => c_c' |
237 of SOME c_c' => c_c' |
232 | _ => error ("Not an equation with two constants: " ^ Display.string_of_thm thm); |
238 | _ => error ("Not an equation with two constants: " ^ Display.string_of_thm thm); |
233 in ConstAlias.map (cons (c_c', thm)) end; |
239 val some_class = the_list (AxClass.class_of_param thy (snd c_c')); |
|
240 in |
|
241 ConstAlias.map (fn (alias, classes) => |
|
242 ((c_c', thm) :: alias, fold (insert (op =)) some_class classes)) |
|
243 end; |
234 |
244 |
235 fun rew_alias thm = |
245 fun rew_alias thm = |
236 let |
246 let |
237 val thy = Thm.theory_of_thm thm; |
247 val thy = Thm.theory_of_thm thm; |
238 in rewrite_head (map snd (ConstAlias.get thy)) thm end; |
248 in rewrite_head ((map snd o fst o ConstAlias.get) thy) thm end; |
239 |
249 |
240 fun subst_alias thy c = ConstAlias.get thy |
250 fun subst_alias thy c = ConstAlias.get thy |
|
251 |> fst |
241 |> get_first (fn ((c', c''), _) => if c = c' then SOME c'' else NONE) |
252 |> get_first (fn ((c', c''), _) => if c = c' then SOME c'' else NONE) |
242 |> the_default c; |
253 |> the_default c; |
|
254 |
|
255 fun resubst_alias thy = |
|
256 let |
|
257 val alias = fst (ConstAlias.get thy); |
|
258 val subst_inst_param = Option.map fst o AxClass.inst_of_param thy; |
|
259 fun subst_alias c = |
|
260 get_first (fn ((c', c''), _) => if c = c'' then SOME c' else NONE) alias; |
|
261 in |
|
262 perhaps subst_inst_param |
|
263 #> perhaps subst_alias |
|
264 end; |
|
265 |
|
266 val triv_classes = snd o ConstAlias.get; |
243 |
267 |
244 (* reading constants as terms *) |
268 (* reading constants as terms *) |
245 |
269 |
246 fun check_bare_const thy t = case try dest_Const t |
270 fun check_bare_const thy t = case try dest_Const t |
247 of SOME c_ty => c_ty |
271 of SOME c_ty => c_ty |