8364
|
1 |
(* Title: Pure/Isar/rule_cases.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
8807
|
4 |
License: GPL (GNU GENERAL PUBLIC LICENSE)
|
8364
|
5 |
|
|
6 |
Manage local contexts of rules.
|
|
7 |
*)
|
|
8 |
|
|
9 |
signature RULE_CASES =
|
|
10 |
sig
|
|
11 |
type T (* = (string * typ) list * term list *)
|
|
12 |
val name: string list -> thm -> thm
|
8427
|
13 |
val case_names: string list -> 'a attribute
|
8364
|
14 |
val get: thm -> string list
|
|
15 |
val add: thm -> thm * string list
|
|
16 |
val none: thm -> thm * string list
|
|
17 |
val make: thm -> string list -> (string * T) list
|
8427
|
18 |
val rename_params: string list list -> thm -> thm
|
8364
|
19 |
val params: string list list -> 'a attribute
|
|
20 |
end;
|
|
21 |
|
|
22 |
structure RuleCases: RULE_CASES =
|
|
23 |
struct
|
|
24 |
|
|
25 |
|
|
26 |
(* local contexts *)
|
|
27 |
|
|
28 |
type T = (string * typ) list * term list;
|
|
29 |
val casesN = "cases";
|
|
30 |
|
|
31 |
|
|
32 |
(* case names *)
|
|
33 |
|
|
34 |
fun name names thm =
|
|
35 |
thm
|
8497
|
36 |
|> Drule.untag_rule casesN
|
8364
|
37 |
|> Drule.tag_rule (casesN, names);
|
|
38 |
|
8427
|
39 |
fun case_names ss = Drule.rule_attribute (K (name ss));
|
8364
|
40 |
|
8427
|
41 |
fun get thm = Library.assocs (Thm.tags_of_thm thm) casesN;
|
8364
|
42 |
fun add thm = (thm, get thm);
|
|
43 |
fun none thm = (thm, []);
|
|
44 |
|
|
45 |
|
|
46 |
(* prepare cases *)
|
|
47 |
|
|
48 |
fun prep_case thm name i =
|
|
49 |
let
|
|
50 |
val (_, _, Bi, _) = Thm.dest_state (thm, i)
|
|
51 |
handle THM _ => raise THM ("More cases than premises in rule", 0, [thm]);
|
|
52 |
val rev_params = rename_wrt_term Bi (Logic.strip_params Bi);
|
|
53 |
val rev_frees = map Free rev_params;
|
|
54 |
val props = map (fn t => Term.subst_bounds (rev_frees, t)) (Logic.strip_assums_hyp Bi);
|
|
55 |
in (name, (rev rev_params, props)) end;
|
|
56 |
|
|
57 |
fun make thm names =
|
|
58 |
#1 (foldr (fn (name, (cases, i)) => (prep_case thm name i :: cases, i - 1))
|
|
59 |
(Library.drop (length names - Thm.nprems_of thm, names), ([], Thm.nprems_of thm)));
|
|
60 |
|
|
61 |
|
8427
|
62 |
(* params *)
|
8364
|
63 |
|
|
64 |
fun rename_params xss thm =
|
8636
|
65 |
#1 (foldl (fn ((th, i), xs) => (Thm.rename_params_rule (xs, i) th, i + 1)) ((thm, 1), xss))
|
|
66 |
|> name (get thm);
|
8364
|
67 |
|
|
68 |
fun params xss = Drule.rule_attribute (K (rename_params xss));
|
|
69 |
|
|
70 |
|
|
71 |
end;
|