89 val strip_comb: cterm -> cterm * cterm list |
89 val strip_comb: cterm -> cterm * cterm list |
90 val strip_type: ctyp -> ctyp list * ctyp |
90 val strip_type: ctyp -> ctyp list * ctyp |
91 val lhs_of: thm -> cterm |
91 val lhs_of: thm -> cterm |
92 val rhs_of: thm -> cterm |
92 val rhs_of: thm -> cterm |
93 val beta_conv: cterm -> cterm -> cterm |
93 val beta_conv: cterm -> cterm -> cterm |
94 val plain_prop_of: thm -> term |
|
95 val fold_terms: (term -> 'a -> 'a) -> thm -> 'a -> 'a |
|
96 val add_used: thm -> string list -> string list |
94 val add_used: thm -> string list -> string list |
97 val flexflex_unique: thm -> thm |
95 val flexflex_unique: thm -> thm |
98 val close_derivation: thm -> thm |
96 val close_derivation: thm -> thm |
99 val store_thm: bstring -> thm -> thm |
97 val store_thm: bstring -> thm -> thm |
100 val store_standard_thm: bstring -> thm -> thm |
98 val store_standard_thm: bstring -> thm -> thm |
227 (*Beta-conversion for cterms, where x is an abstraction. Simply returns the rhs |
225 (*Beta-conversion for cterms, where x is an abstraction. Simply returns the rhs |
228 of the meta-equality returned by the beta_conversion rule.*) |
226 of the meta-equality returned by the beta_conversion rule.*) |
229 fun beta_conv x y = |
227 fun beta_conv x y = |
230 Thm.dest_arg (cprop_of (Thm.beta_conversion false (Thm.capply x y))); |
228 Thm.dest_arg (cprop_of (Thm.beta_conversion false (Thm.capply x y))); |
231 |
229 |
232 fun plain_prop_of raw_thm = |
|
233 let |
|
234 val thm = Thm.strip_shyps raw_thm; |
|
235 fun err msg = raise THM ("plain_prop_of: " ^ msg, 0, [thm]); |
|
236 val {hyps, prop, tpairs, ...} = Thm.rep_thm thm; |
|
237 in |
|
238 if not (null hyps) then |
|
239 err "theorem may not contain hypotheses" |
|
240 else if not (null (Thm.extra_shyps thm)) then |
|
241 err "theorem may not contain sort hypotheses" |
|
242 else if not (null tpairs) then |
|
243 err "theorem may not contain flex-flex pairs" |
|
244 else prop |
|
245 end; |
|
246 |
|
247 fun fold_terms f th = |
|
248 let val {tpairs, prop, hyps, ...} = Thm.rep_thm th |
|
249 in fold (fn (t, u) => f t #> f u) tpairs #> f prop #> fold f hyps end; |
|
250 |
|
251 |
230 |
252 |
231 |
253 (** reading of instantiations **) |
232 (** reading of instantiations **) |
254 |
233 |
255 fun absent ixn = |
234 fun absent ixn = |
294 Index -1 indicates that a (T)Free rather than a (T)Var is wanted. |
273 Index -1 indicates that a (T)Free rather than a (T)Var is wanted. |
295 ***) |
274 ***) |
296 |
275 |
297 fun types_sorts thm = |
276 fun types_sorts thm = |
298 let |
277 let |
299 val vars = fold_terms Term.add_vars thm []; |
278 val vars = Thm.fold_terms Term.add_vars thm []; |
300 val frees = fold_terms Term.add_frees thm []; |
279 val frees = Thm.fold_terms Term.add_frees thm []; |
301 val tvars = fold_terms Term.add_tvars thm []; |
280 val tvars = Thm.fold_terms Term.add_tvars thm []; |
302 val tfrees = fold_terms Term.add_tfrees thm []; |
281 val tfrees = Thm.fold_terms Term.add_tfrees thm []; |
303 fun types (a, i) = |
282 fun types (a, i) = |
304 if i < 0 then AList.lookup (op =) frees a else AList.lookup (op =) vars (a, i); |
283 if i < 0 then AList.lookup (op =) frees a else AList.lookup (op =) vars (a, i); |
305 fun sorts (a, i) = |
284 fun sorts (a, i) = |
306 if i < 0 then AList.lookup (op =) tfrees a else AList.lookup (op =) tvars (a, i); |
285 if i < 0 then AList.lookup (op =) tfrees a else AList.lookup (op =) tvars (a, i); |
307 in (types, sorts) end; |
286 in (types, sorts) end; |
308 |
287 |
309 val add_used = |
288 val add_used = |
310 (fold_terms o fold_types o fold_atyps) |
289 (Thm.fold_terms o fold_types o fold_atyps) |
311 (fn TFree (a, _) => insert (op =) a |
290 (fn TFree (a, _) => insert (op =) a |
312 | TVar ((a, _), _) => insert (op =) a |
291 | TVar ((a, _), _) => insert (op =) a |
313 | _ => I); |
292 | _ => I); |
314 |
293 |
315 |
294 |
327 |> Thm.instantiate ([(certT (TVar (("'a", 0), [c])), cT)], []); |
306 |> Thm.instantiate ([(certT (TVar (("'a", 0), [c])), cT)], []); |
328 in map class_triv S end; |
307 in map class_triv S end; |
329 |
308 |
330 fun unconstrainTs th = |
309 fun unconstrainTs th = |
331 fold (Thm.unconstrainT o Thm.ctyp_of (Thm.theory_of_thm th) o TVar) |
310 fold (Thm.unconstrainT o Thm.ctyp_of (Thm.theory_of_thm th) o TVar) |
332 (fold_terms Term.add_tvars th []) th; |
311 (Thm.fold_terms Term.add_tvars th []) th; |
333 |
312 |
334 (*Generalization over a list of variables*) |
313 (*Generalization over a list of variables*) |
335 val forall_intr_list = fold_rev forall_intr; |
314 val forall_intr_list = fold_rev forall_intr; |
336 |
315 |
337 (*Generalization over all suitable Free variables*) |
316 (*Generalization over all suitable Free variables*) |
344 in fold (forall_intr o cterm_of thy o Free) frees th end; |
323 in fold (forall_intr o cterm_of thy o Free) frees th end; |
345 |
324 |
346 (*Generalization over Vars -- canonical order*) |
325 (*Generalization over Vars -- canonical order*) |
347 fun forall_intr_vars th = |
326 fun forall_intr_vars th = |
348 fold forall_intr |
327 fold forall_intr |
349 (map (Thm.cterm_of (Thm.theory_of_thm th) o Var) (fold_terms Term.add_vars th [])) th; |
328 (map (Thm.cterm_of (Thm.theory_of_thm th) o Var) (Thm.fold_terms Term.add_vars th [])) th; |
350 |
329 |
351 val forall_elim_var = PureThy.forall_elim_var; |
330 val forall_elim_var = PureThy.forall_elim_var; |
352 val forall_elim_vars = PureThy.forall_elim_vars; |
331 val forall_elim_vars = PureThy.forall_elim_vars; |
353 |
332 |
354 fun outer_params t = |
333 fun outer_params t = |
371 val cert = Thm.cterm_of thy; |
350 val cert = Thm.cterm_of thy; |
372 val maxidx = Thm.maxidx_of th; |
351 val maxidx = Thm.maxidx_of th; |
373 val ps = outer_params (Thm.term_of goal) |
352 val ps = outer_params (Thm.term_of goal) |
374 |> map (fn (x, T) => Var ((x, maxidx + 1), Logic.incr_tvar (maxidx + 1) T)); |
353 |> map (fn (x, T) => Var ((x, maxidx + 1), Logic.incr_tvar (maxidx + 1) T)); |
375 val Ts = map Term.fastype_of ps; |
354 val Ts = map Term.fastype_of ps; |
376 val inst = fold_terms Term.add_vars th [] |> map (fn (xi, T) => |
355 val inst = Thm.fold_terms Term.add_vars th [] |> map (fn (xi, T) => |
377 (cert (Var (xi, T)), cert (Term.list_comb (Var (xi, Ts ---> T), ps)))); |
356 (cert (Var (xi, T)), cert (Term.list_comb (Var (xi, Ts ---> T), ps)))); |
378 in |
357 in |
379 th |> Thm.instantiate ([], inst) |
358 th |> Thm.instantiate ([], inst) |
380 |> fold_rev (Thm.forall_intr o cert) ps |
359 |> fold_rev (Thm.forall_intr o cert) ps |
381 end; |
360 end; |
999 |
978 |
1000 (*instantiate types first!*) |
979 (*instantiate types first!*) |
1001 val thm' = |
980 val thm' = |
1002 if forall is_none cTs then thm |
981 if forall is_none cTs then thm |
1003 else Thm.instantiate |
982 else Thm.instantiate |
1004 (map tyinst_of (zip_vars (rev (fold_terms Term.add_tvars thm [])) cTs), []) thm; |
983 (map tyinst_of (zip_vars (rev (Thm.fold_terms Term.add_tvars thm [])) cTs), []) thm; |
1005 val thm'' = |
984 val thm'' = |
1006 if forall is_none cts then thm' |
985 if forall is_none cts then thm' |
1007 else Thm.instantiate |
986 else Thm.instantiate |
1008 ([], map inst_of (zip_vars (rev (fold_terms Term.add_vars thm' [])) cts)) thm'; |
987 ([], map inst_of (zip_vars (rev (Thm.fold_terms Term.add_vars thm' [])) cts)) thm'; |
1009 in thm'' end; |
988 in thm'' end; |
1010 |
989 |
1011 |
990 |
1012 |
991 |
1013 (** renaming of bound variables **) |
992 (** renaming of bound variables **) |