author | ballarin |
Wed, 09 Mar 2005 18:44:52 +0100 | |
changeset 15596 | 8665d08085df |
parent 15570 | 8d8c70b41bab |
child 15703 | 727ef1b8b3ee |
permissions | -rw-r--r-- |
5823 | 1 |
(* Title: Pure/Isar/attrib.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
5 |
Symbolic theorem attributes. |
|
6 |
*) |
|
7 |
||
8 |
signature BASIC_ATTRIB = |
|
9 |
sig |
|
10 |
val print_attributes: theory -> unit |
|
5879 | 11 |
val Attribute: bstring -> (Args.src -> theory attribute) * (Args.src -> Proof.context attribute) |
12 |
-> string -> unit |
|
5823 | 13 |
end; |
14 |
||
15 |
signature ATTRIB = |
|
16 |
sig |
|
17 |
include BASIC_ATTRIB |
|
5912 | 18 |
exception ATTRIB_FAIL of (string * Position.T) * exn |
5823 | 19 |
val global_attribute: theory -> Args.src -> theory attribute |
20 |
val local_attribute: theory -> Args.src -> Proof.context attribute |
|
15596 | 21 |
val multi_attribute: theory -> Args.src -> Locale.multi_attribute |
5912 | 22 |
val local_attribute': Proof.context -> Args.src -> Proof.context attribute |
7673
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
23 |
val undef_global_attribute: theory attribute |
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
24 |
val undef_local_attribute: Proof.context attribute |
5823 | 25 |
val add_attributes: (bstring * ((Args.src -> theory attribute) * |
26 |
(Args.src -> Proof.context attribute)) * string) list -> theory -> theory |
|
6091 | 27 |
val global_thm: theory * Args.T list -> thm * (theory * Args.T list) |
28 |
val global_thms: theory * Args.T list -> thm list * (theory * Args.T list) |
|
29 |
val global_thmss: theory * Args.T list -> thm list * (theory * Args.T list) |
|
30 |
val local_thm: Proof.context * Args.T list -> thm * (Proof.context * Args.T list) |
|
31 |
val local_thms: Proof.context * Args.T list -> thm list * (Proof.context * Args.T list) |
|
32 |
val local_thmss: Proof.context * Args.T list -> thm list * (Proof.context * Args.T list) |
|
5879 | 33 |
val syntax: ('a * Args.T list -> 'a attribute * ('a * Args.T list)) -> Args.src -> 'a attribute |
5823 | 34 |
val no_args: 'a attribute -> Args.src -> 'a attribute |
8633 | 35 |
val add_del_args: 'a attribute -> 'a attribute -> Args.src -> 'a attribute |
5823 | 36 |
val setup: (theory -> theory) list |
37 |
end; |
|
38 |
||
39 |
structure Attrib: ATTRIB = |
|
40 |
struct |
|
41 |
||
42 |
||
43 |
(** attributes theory data **) |
|
44 |
||
45 |
(* data kind 'Isar/attributes' *) |
|
46 |
||
47 |
structure AttributesDataArgs = |
|
48 |
struct |
|
49 |
val name = "Isar/attributes"; |
|
50 |
type T = |
|
51 |
{space: NameSpace.T, |
|
52 |
attrs: |
|
53 |
((((Args.src -> theory attribute) * (Args.src -> Proof.context attribute)) |
|
54 |
* string) * stamp) Symtab.table}; |
|
55 |
||
56 |
val empty = {space = NameSpace.empty, attrs = Symtab.empty}; |
|
6546 | 57 |
val copy = I; |
5823 | 58 |
val prep_ext = I; |
59 |
||
60 |
fun merge ({space = space1, attrs = attrs1}, {space = space2, attrs = attrs2}) = |
|
61 |
{space = NameSpace.merge (space1, space2), |
|
62 |
attrs = Symtab.merge eq_snd (attrs1, attrs2) handle Symtab.DUPS dups => |
|
63 |
error ("Attempt to merge different versions of attributes " ^ commas_quote dups)}; |
|
64 |
||
9216 | 65 |
fun print _ {space, attrs} = |
5823 | 66 |
let |
67 |
fun prt_attr (name, ((_, comment), _)) = Pretty.block |
|
6846 | 68 |
[Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment]; |
5823 | 69 |
in |
8720 | 70 |
[Pretty.big_list "attributes:" (map prt_attr (NameSpace.cond_extern_table space attrs))] |
9216 | 71 |
|> Pretty.chunks |> Pretty.writeln |
5823 | 72 |
end; |
73 |
end; |
|
74 |
||
75 |
structure AttributesData = TheoryDataFun(AttributesDataArgs); |
|
76 |
val print_attributes = AttributesData.print; |
|
7611 | 77 |
|
5823 | 78 |
|
79 |
(* get global / local attributes *) |
|
80 |
||
5912 | 81 |
exception ATTRIB_FAIL of (string * Position.T) * exn; |
82 |
||
5823 | 83 |
fun gen_attribute which thy = |
84 |
let |
|
85 |
val {space, attrs} = AttributesData.get thy; |
|
86 |
||
5879 | 87 |
fun attr src = |
88 |
let |
|
89 |
val ((raw_name, _), pos) = Args.dest_src src; |
|
90 |
val name = NameSpace.intern space raw_name; |
|
91 |
in |
|
5823 | 92 |
(case Symtab.lookup (attrs, name) of |
15531 | 93 |
NONE => error ("Unknown attribute: " ^ quote name ^ Position.str_of pos) |
94 |
| SOME ((p, _), _) => transform_failure (curry ATTRIB_FAIL (name, pos)) (which p src)) |
|
5823 | 95 |
end; |
96 |
in attr end; |
|
97 |
||
98 |
val global_attribute = gen_attribute fst; |
|
99 |
val local_attribute = gen_attribute snd; |
|
15596 | 100 |
fun multi_attribute thy src = |
101 |
(global_attribute thy src, local_attribute thy src); |
|
5879 | 102 |
val local_attribute' = local_attribute o ProofContext.theory_of; |
5823 | 103 |
|
7673
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
104 |
val undef_global_attribute: theory attribute = |
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
105 |
fn _ => error "attribute undefined in theory context"; |
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
106 |
|
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
107 |
val undef_local_attribute: Proof.context attribute = |
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
108 |
fn _ => error "attribute undefined in proof context"; |
b8e7fa177d62
added undef_global_attribute, undef_local_attribute;
wenzelm
parents:
7668
diff
changeset
|
109 |
|
5823 | 110 |
|
111 |
(* add_attributes *) |
|
112 |
||
113 |
fun add_attributes raw_attrs thy = |
|
114 |
let |
|
115 |
val full = Sign.full_name (Theory.sign_of thy); |
|
116 |
val new_attrs = |
|
117 |
map (fn (name, (f, g), comment) => (full name, (((f, g), comment), stamp ()))) raw_attrs; |
|
118 |
||
119 |
val {space, attrs} = AttributesData.get thy; |
|
120 |
val space' = NameSpace.extend (space, map fst new_attrs); |
|
121 |
val attrs' = Symtab.extend (attrs, new_attrs) handle Symtab.DUPS dups => |
|
122 |
error ("Duplicate declaration of attributes(s) " ^ commas_quote dups); |
|
123 |
in thy |> AttributesData.put {space = space', attrs = attrs'} end; |
|
124 |
||
5879 | 125 |
(*implicit version*) |
126 |
fun Attribute name att cmt = Context.>> (add_attributes [(name, att, cmt)]); |
|
5823 | 127 |
|
5879 | 128 |
|
129 |
||
130 |
(** attribute parsers **) |
|
131 |
||
132 |
(* tags *) |
|
5823 | 133 |
|
5879 | 134 |
fun tag x = Scan.lift (Args.name -- Scan.repeat Args.name) x; |
135 |
||
136 |
||
137 |
(* theorems *) |
|
138 |
||
15456
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15117
diff
changeset
|
139 |
val thm_sel = Args.parens (Scan.pass () (Args.enum1 "," (Scan.lift |
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15117
diff
changeset
|
140 |
( Args.nat --| Args.$$$ "-" -- Args.nat >> op upto |
15570 | 141 |
|| Args.nat >> single)) >> List.concat)); |
15456
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15117
diff
changeset
|
142 |
|
5879 | 143 |
fun gen_thm get attrib app = |
15456
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
berghofe
parents:
15117
diff
changeset
|
144 |
Scan.depend (fn st => Args.name -- Scan.option thm_sel -- Args.opt_attribs >> |
5879 | 145 |
(fn (name, srcs) => app ((st, get st name), map (attrib st) srcs))); |
5823 | 146 |
|
6091 | 147 |
val global_thm = gen_thm PureThy.get_thm global_attribute Thm.apply_attributes; |
148 |
val global_thms = gen_thm PureThy.get_thms global_attribute Thm.applys_attributes; |
|
15570 | 149 |
val global_thmss = Scan.repeat global_thms >> List.concat; |
5879 | 150 |
|
6091 | 151 |
val local_thm = gen_thm ProofContext.get_thm local_attribute' Thm.apply_attributes; |
152 |
val local_thms = gen_thm ProofContext.get_thms local_attribute' Thm.applys_attributes; |
|
15570 | 153 |
val local_thmss = Scan.repeat local_thms >> List.concat; |
5879 | 154 |
|
5823 | 155 |
|
5879 | 156 |
|
157 |
(** attribute syntax **) |
|
5823 | 158 |
|
5879 | 159 |
fun syntax scan src (st, th) = |
8282 | 160 |
let val (st', f) = Args.syntax "attribute" scan src st |
5879 | 161 |
in f (st', th) end; |
162 |
||
163 |
fun no_args x = syntax (Scan.succeed x); |
|
5823 | 164 |
|
10034 | 165 |
fun add_del_args add del x = syntax |
166 |
(Scan.lift (Args.add >> K add || Args.del >> K del || Scan.succeed add)) x; |
|
8633 | 167 |
|
5823 | 168 |
|
169 |
||
170 |
(** Pure attributes **) |
|
171 |
||
172 |
(* tags *) |
|
173 |
||
9902 | 174 |
fun gen_tagged x = syntax (tag >> Drule.tag) x; |
175 |
fun gen_untagged x = syntax (Scan.lift Args.name >> Drule.untag) x; |
|
5823 | 176 |
|
177 |
||
6772 | 178 |
(* COMP *) |
179 |
||
6948 | 180 |
fun comp (i, B) (x, A) = (x, Drule.compose_single (A, i, B)); |
6772 | 181 |
|
10151 | 182 |
fun gen_COMP thm = syntax (Scan.lift (Scan.optional (Args.bracks Args.nat) 1) -- thm >> comp); |
9902 | 183 |
val COMP_global = gen_COMP global_thm; |
184 |
val COMP_local = gen_COMP local_thm; |
|
6772 | 185 |
|
186 |
||
15117 | 187 |
(* THEN, which corresponds to RS *) |
5879 | 188 |
|
6091 | 189 |
fun resolve (i, B) (x, A) = (x, A RSN (i, B)); |
5879 | 190 |
|
15117 | 191 |
fun gen_THEN thm = syntax (Scan.lift (Scan.optional (Args.bracks Args.nat) 1) -- thm >> resolve); |
192 |
val THEN_global = gen_THEN global_thm; |
|
193 |
val THEN_local = gen_THEN local_thm; |
|
5879 | 194 |
|
195 |
||
9902 | 196 |
(* OF *) |
5879 | 197 |
|
6091 | 198 |
fun apply Bs (x, A) = (x, Bs MRS A); |
5879 | 199 |
|
9902 | 200 |
val OF_global = syntax (global_thmss >> apply); |
201 |
val OF_local = syntax (local_thmss >> apply); |
|
5879 | 202 |
|
203 |
||
14718 | 204 |
(* where *) |
205 |
||
206 |
(*named instantiations; permits instantiation of type and term variables*) |
|
5879 | 207 |
|
10807 | 208 |
fun read_instantiate _ [] _ thm = thm |
209 |
| read_instantiate context_of insts x thm = |
|
210 |
let |
|
211 |
val ctxt = context_of x; |
|
212 |
val sign = ProofContext.sign_of ctxt; |
|
213 |
||
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
214 |
(* Separate type and term insts, |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
215 |
type insts must occur strictly before term insts *) |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
216 |
fun has_type_var ((x, _), _) = (case Symbol.explode x of |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
217 |
"'"::cs => true | cs => false); |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
218 |
val (Tinst, tinsts) = take_prefix has_type_var insts; |
14718 | 219 |
val _ = if exists has_type_var tinsts |
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
220 |
then error |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
221 |
"Type instantiations must occur before term instantiations." |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
222 |
else (); |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
223 |
|
15570 | 224 |
val Tinsts = List.filter has_type_var insts; |
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
225 |
val tinsts = filter_out has_type_var insts; |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
226 |
|
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
227 |
(* Type instantiations first *) |
14718 | 228 |
(* Process type insts: Tinsts_env *) |
229 |
fun absent xi = error |
|
230 |
("No such type variable in theorem: " ^ |
|
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
231 |
Syntax.string_of_vname xi); |
14718 | 232 |
val (rtypes, rsorts) = types_sorts thm; |
233 |
fun readT (xi, s) = |
|
15531 | 234 |
let val S = case rsorts xi of SOME S => S | NONE => absent xi; |
14718 | 235 |
val T = ProofContext.read_typ ctxt s; |
236 |
in if Sign.typ_instance sign (T, TVar (xi, S)) then (xi, T) |
|
237 |
else error |
|
238 |
("Instantiation of " ^ Syntax.string_of_vname xi ^ " fails") |
|
239 |
end; |
|
240 |
val Tinsts_env = map readT Tinsts; |
|
241 |
val cenvT = map (apsnd (Thm.ctyp_of sign)) (Tinsts_env); |
|
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
242 |
val thm' = Thm.instantiate (cenvT, []) thm; |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
243 |
(* Instantiate, but don't normalise: *) |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
244 |
(* this happens after term insts anyway. *) |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
245 |
|
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
246 |
(* Term instantiations *) |
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
247 |
val vars = Drule.vars_of thm'; |
10807 | 248 |
fun get_typ xi = |
249 |
(case assoc (vars, xi) of |
|
15531 | 250 |
SOME T => T |
251 |
| NONE => error ("No such variable in theorem: " ^ Syntax.string_of_vname xi)); |
|
5879 | 252 |
|
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
253 |
val (xs, ss) = Library.split_list tinsts; |
10807 | 254 |
val Ts = map get_typ xs; |
5879 | 255 |
|
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
256 |
val used = add_term_tvarnames (prop_of thm',[]) |
14718 | 257 |
(* Names of TVars occuring in thm'. read_def_termTs ensures |
14257
a7ef3f7588c5
Type inference bug in Isar attributes "where" and "of" fixed.
ballarin
parents:
14082
diff
changeset
|
258 |
that new TVars introduced when reading the instantiation string |
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
259 |
are distinct from those occuring in the theorem. *) |
14257
a7ef3f7588c5
Type inference bug in Isar attributes "where" and "of" fixed.
ballarin
parents:
14082
diff
changeset
|
260 |
|
14718 | 261 |
val (ts, envT) = |
15531 | 262 |
ProofContext.read_termTs ctxt (K false) (K NONE) (K NONE) used (ss ~~ Ts); |
14718 | 263 |
|
10807 | 264 |
val cenvT = map (apsnd (Thm.ctyp_of sign)) envT; |
265 |
val cenv = |
|
266 |
map (fn (xi, t) => pairself (Thm.cterm_of sign) (Var (xi, fastype_of t), t)) |
|
267 |
(gen_distinct (fn ((x1, t1), (x2, t2)) => x1 = x2 andalso t1 aconv t2) (xs ~~ ts)); |
|
268 |
in |
|
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
269 |
thm' |
10807 | 270 |
|> Drule.instantiate (cenvT, cenv) |
271 |
|> RuleCases.save thm |
|
272 |
end; |
|
5879 | 273 |
|
6448 | 274 |
fun insts x = Args.and_list (Scan.lift (Args.var --| Args.$$$ "=" -- Args.name)) x; |
5879 | 275 |
|
6091 | 276 |
fun gen_where context_of = syntax (insts >> (Drule.rule_attribute o read_instantiate context_of)); |
5823 | 277 |
|
9902 | 278 |
val where_global = gen_where ProofContext.init; |
279 |
val where_local = gen_where I; |
|
5879 | 280 |
|
281 |
||
9902 | 282 |
(* of: positional instantiations *) |
14287
f630017ed01c
Isar: where attribute supports instantiation of type variables.
ballarin
parents:
14257
diff
changeset
|
283 |
(* permits instantiation of term variables only *) |
5912 | 284 |
|
10807 | 285 |
fun read_instantiate' _ ([], []) _ thm = thm |
286 |
| read_instantiate' context_of (args, concl_args) x thm = |
|
287 |
let |
|
288 |
fun zip_vars _ [] = [] |
|
15531 | 289 |
| zip_vars (_ :: xs) (NONE :: opt_ts) = zip_vars xs opt_ts |
290 |
| zip_vars ((x, _) :: xs) (SOME t :: opt_ts) = (x, t) :: zip_vars xs opt_ts |
|
10807 | 291 |
| zip_vars [] _ = error "More instantiations than variables in theorem"; |
292 |
val insts = |
|
12804 | 293 |
zip_vars (Drule.vars_of_terms [Thm.prop_of thm]) args @ |
10807 | 294 |
zip_vars (Drule.vars_of_terms [Thm.concl_of thm]) concl_args; |
295 |
in |
|
296 |
thm |
|
297 |
|> read_instantiate context_of insts x |
|
298 |
|> RuleCases.save thm |
|
299 |
end; |
|
5912 | 300 |
|
10807 | 301 |
val concl = Args.$$$ "concl" -- Args.colon; |
8687 | 302 |
val inst_arg = Scan.unless concl Args.name_dummy; |
5912 | 303 |
val inst_args = Scan.repeat inst_arg; |
10807 | 304 |
fun insts' x = (inst_args -- Scan.optional (concl |-- Args.!!! inst_args) []) x; |
5912 | 305 |
|
10807 | 306 |
fun gen_of context_of = |
307 |
syntax (Scan.lift insts' >> (Drule.rule_attribute o read_instantiate' context_of)); |
|
5912 | 308 |
|
9902 | 309 |
val of_global = gen_of ProofContext.init; |
310 |
val of_local = gen_of I; |
|
5912 | 311 |
|
312 |
||
13782
44de406a7273
Added rename_abs attribute for renaming bound variables.
berghofe
parents:
13414
diff
changeset
|
313 |
(* rename_abs *) |
44de406a7273
Added rename_abs attribute for renaming bound variables.
berghofe
parents:
13414
diff
changeset
|
314 |
|
44de406a7273
Added rename_abs attribute for renaming bound variables.
berghofe
parents:
13414
diff
changeset
|
315 |
fun rename_abs src = syntax |
14082
c69d5bf3047d
Moved function for renaming bound variables to Pure/drule.ML
berghofe
parents:
13782
diff
changeset
|
316 |
(Scan.lift (Scan.repeat Args.name_dummy >> (apsnd o Drule.rename_bvars'))) src; |
13782
44de406a7273
Added rename_abs attribute for renaming bound variables.
berghofe
parents:
13414
diff
changeset
|
317 |
|
44de406a7273
Added rename_abs attribute for renaming bound variables.
berghofe
parents:
13414
diff
changeset
|
318 |
|
7598 | 319 |
(* unfold / fold definitions *) |
320 |
||
321 |
fun gen_rewrite rew defs (x, thm) = (x, rew defs thm); |
|
322 |
||
9902 | 323 |
val unfolded_global = syntax (global_thmss >> gen_rewrite Tactic.rewrite_rule); |
324 |
val unfolded_local = syntax (local_thmss >> gen_rewrite Tactic.rewrite_rule); |
|
325 |
val folded_global = syntax (global_thmss >> gen_rewrite Tactic.fold_rule); |
|
326 |
val folded_local = syntax (local_thmss >> gen_rewrite Tactic.fold_rule); |
|
7598 | 327 |
|
328 |
||
8368 | 329 |
(* rule cases *) |
330 |
||
10528 | 331 |
fun consumes x = syntax (Scan.lift (Scan.optional Args.nat 1) >> RuleCases.consumes) x; |
8368 | 332 |
fun case_names x = syntax (Scan.lift (Scan.repeat1 Args.name) >> RuleCases.case_names) x; |
333 |
fun params x = syntax (Args.and_list1 (Scan.lift (Scan.repeat Args.name)) >> RuleCases.params) x; |
|
334 |
||
335 |
||
11770 | 336 |
(* rule_format *) |
337 |
||
338 |
fun rule_format_att x = syntax |
|
339 |
(Scan.lift (Args.parens (Args.$$$ "no_asm") |
|
340 |
>> K ObjectLogic.rule_format_no_asm || Scan.succeed ObjectLogic.rule_format)) x; |
|
341 |
||
342 |
||
5879 | 343 |
(* misc rules *) |
344 |
||
6091 | 345 |
fun standard x = no_args (Drule.rule_attribute (K Drule.standard)) x; |
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9902
diff
changeset
|
346 |
fun elim_format x = no_args (Drule.rule_attribute (K Tactic.make_elim)) x; |
9216 | 347 |
fun no_vars x = no_args (Drule.rule_attribute (K (#1 o Drule.freeze_thaw))) x; |
5879 | 348 |
|
349 |
||
13370 | 350 |
(* rule declarations *) |
351 |
||
352 |
local |
|
353 |
||
354 |
fun add_args a b c x = syntax |
|
355 |
(Scan.lift ((Args.bang >> K a || Args.query >> K c || Scan.succeed b) -- (Scan.option Args.nat)) |
|
356 |
>> (fn (f, n) => f n)) x; |
|
357 |
||
358 |
fun del_args att = syntax (Scan.lift Args.del >> K att); |
|
359 |
||
360 |
open ContextRules; |
|
361 |
||
362 |
in |
|
363 |
||
364 |
val rule_atts = |
|
365 |
[("intro", |
|
366 |
(add_args intro_bang_global intro_global intro_query_global, |
|
367 |
add_args intro_bang_local intro_local intro_query_local), |
|
368 |
"declaration of introduction rule"), |
|
369 |
("elim", |
|
370 |
(add_args elim_bang_global elim_global elim_query_global, |
|
371 |
add_args elim_bang_local elim_local elim_query_local), |
|
372 |
"declaration of elimination rule"), |
|
373 |
("dest", |
|
374 |
(add_args dest_bang_global dest_global dest_query_global, |
|
375 |
add_args dest_bang_local dest_local dest_query_local), |
|
376 |
"declaration of destruction rule"), |
|
377 |
("rule", (del_args rule_del_global, del_args rule_del_local), |
|
378 |
"remove declaration of intro/elim/dest rule")]; |
|
379 |
||
380 |
end; |
|
381 |
||
382 |
||
11770 | 383 |
|
5879 | 384 |
(** theory setup **) |
5823 | 385 |
|
386 |
(* pure_attributes *) |
|
387 |
||
388 |
val pure_attributes = |
|
9902 | 389 |
[("tagged", (gen_tagged, gen_tagged), "tagged theorem"), |
390 |
("untagged", (gen_untagged, gen_untagged), "untagged theorem"), |
|
391 |
("COMP", (COMP_global, COMP_local), "direct composition with rules (no lifting)"), |
|
15117 | 392 |
("THEN", (THEN_global, THEN_local), "resolution with rule"), |
9902 | 393 |
("OF", (OF_global, OF_local), "rule applied to facts"), |
394 |
("where", (where_global, where_local), "named instantiation of theorem"), |
|
395 |
("of", (of_global, of_local), "rule applied to terms"), |
|
13782
44de406a7273
Added rename_abs attribute for renaming bound variables.
berghofe
parents:
13414
diff
changeset
|
396 |
("rename_abs", (rename_abs, rename_abs), "rename bound variables in abstractions"), |
9902 | 397 |
("unfolded", (unfolded_global, unfolded_local), "unfolded definitions"), |
398 |
("folded", (folded_global, folded_local), "folded definitions"), |
|
399 |
("standard", (standard, standard), "result put into standard form"), |
|
9941
fe05af7ec816
renamed atts: rulify to rule_format, elimify to elim_format;
wenzelm
parents:
9902
diff
changeset
|
400 |
("elim_format", (elim_format, elim_format), "destruct rule turned into elimination rule format"), |
9902 | 401 |
("no_vars", (no_vars, no_vars), "frozen schematic vars"), |
10528 | 402 |
("consumes", (consumes, consumes), "number of consumed facts"), |
9902 | 403 |
("case_names", (case_names, case_names), "named rule cases"), |
404 |
("params", (params, params), "named rule parameters"), |
|
11770 | 405 |
("atomize", (no_args ObjectLogic.declare_atomize, no_args undef_local_attribute), |
406 |
"declaration of atomize rule"), |
|
407 |
("rulify", (no_args ObjectLogic.declare_rulify, no_args undef_local_attribute), |
|
408 |
"declaration of rulify rule"), |
|
13370 | 409 |
("rule_format", (rule_format_att, rule_format_att), "result put into standard rule format")] @ |
410 |
rule_atts; |
|
5823 | 411 |
|
412 |
||
5879 | 413 |
(* setup *) |
5823 | 414 |
|
415 |
val setup = [AttributesData.init, add_attributes pure_attributes]; |
|
416 |
||
417 |
end; |
|
418 |
||
419 |
structure BasicAttrib: BASIC_ATTRIB = Attrib; |
|
420 |
open BasicAttrib; |