author | wenzelm |
Mon, 04 Aug 2008 20:27:37 +0200 | |
changeset 27727 | 2397e310b2cc |
parent 27353 | 71c4dd53d4cb |
child 27809 | a1e409db516b |
permissions | -rw-r--r-- |
6429 | 1 |
(* Title: HOL/Tools/recdef_package.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
5 |
Wrapper module for Konrad Slind's TFL package. |
|
6 |
*) |
|
7 |
||
8 |
signature RECDEF_PACKAGE = |
|
9 |
sig |
|
8657 | 10 |
val get_recdef: theory -> string |
11 |
-> {simps: thm list, rules: thm list list, induct: thm, tcs: term list} option |
|
21505 | 12 |
val get_hints: Proof.context -> {simps: thm list, congs: (string * thm) list, wfs: thm list} |
18728 | 13 |
val simp_add: attribute |
14 |
val simp_del: attribute |
|
15 |
val cong_add: attribute |
|
16 |
val cong_del: attribute |
|
17 |
val wf_add: attribute |
|
18 |
val wf_del: attribute |
|
15703 | 19 |
val add_recdef: bool -> xstring -> string -> ((bstring * string) * Attrib.src list) list -> |
20 |
Attrib.src option -> theory -> theory |
|
9859 | 21 |
* {simps: thm list, rules: thm list list, induct: thm, tcs: term list} |
18728 | 22 |
val add_recdef_i: bool -> xstring -> term -> ((bstring * term) * attribute list) list -> |
9859 | 23 |
theory -> theory * {simps: thm list, rules: thm list list, induct: thm, tcs: term list} |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
24927
diff
changeset
|
24 |
val defer_recdef: xstring -> string list -> (Facts.ref * Attrib.src list) list |
6557 | 25 |
-> theory -> theory * {induct_rules: thm} |
27727
2397e310b2cc
simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents:
27353
diff
changeset
|
26 |
val defer_recdef_i: xstring -> term list -> thm list -> theory -> theory * {induct_rules: thm} |
2397e310b2cc
simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents:
27353
diff
changeset
|
27 |
val recdef_tc: bstring * Attrib.src list -> xstring -> int option -> bool -> |
2397e310b2cc
simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents:
27353
diff
changeset
|
28 |
local_theory -> Proof.state |
2397e310b2cc
simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents:
27353
diff
changeset
|
29 |
val recdef_tc_i: bstring * Attrib.src list -> string -> int option -> bool -> |
2397e310b2cc
simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents:
27353
diff
changeset
|
30 |
local_theory -> Proof.state |
18708 | 31 |
val setup: theory -> theory |
6429 | 32 |
end; |
33 |
||
34 |
structure RecdefPackage: RECDEF_PACKAGE = |
|
35 |
struct |
|
36 |
||
37 |
||
9859 | 38 |
(** recdef hints **) |
6439 | 39 |
|
9859 | 40 |
(* type hints *) |
41 |
||
42 |
type hints = {simps: thm list, congs: (string * thm) list, wfs: thm list}; |
|
43 |
||
44 |
fun mk_hints (simps, congs, wfs) = {simps = simps, congs = congs, wfs = wfs}: hints; |
|
45 |
fun map_hints f ({simps, congs, wfs}: hints) = mk_hints (f (simps, congs, wfs)); |
|
46 |
||
47 |
fun map_simps f = map_hints (fn (simps, congs, wfs) => (f simps, congs, wfs)); |
|
48 |
fun map_congs f = map_hints (fn (simps, congs, wfs) => (simps, f congs, wfs)); |
|
49 |
fun map_wfs f = map_hints (fn (simps, congs, wfs) => (simps, congs, f wfs)); |
|
50 |
||
51 |
fun pretty_hints ({simps, congs, wfs}: hints) = |
|
52 |
[Pretty.big_list "recdef simp hints:" (map Display.pretty_thm simps), |
|
21098
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
53 |
Pretty.big_list "recdef cong hints:" (map Display.pretty_thm (map snd congs)), |
9859 | 54 |
Pretty.big_list "recdef wf hints:" (map Display.pretty_thm wfs)]; |
55 |
||
56 |
||
57 |
(* congruence rules *) |
|
58 |
||
59 |
local |
|
60 |
||
61 |
val cong_head = |
|
62 |
fst o Term.dest_Const o Term.head_of o fst o Logic.dest_equals o Thm.concl_of; |
|
6439 | 63 |
|
9859 | 64 |
fun prep_cong raw_thm = |
65 |
let val thm = safe_mk_meta_eq raw_thm in (cong_head thm, thm) end; |
|
66 |
||
67 |
in |
|
68 |
||
69 |
fun add_cong raw_thm congs = |
|
21098
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
70 |
let |
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
71 |
val (c, thm) = prep_cong raw_thm; |
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
72 |
val _ = if AList.defined (op =) congs c |
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
73 |
then warning ("Overwriting recdef congruence rule for " ^ quote c) |
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
74 |
else (); |
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
75 |
in AList.update (op =) (c, thm) congs end; |
9859 | 76 |
|
77 |
fun del_cong raw_thm congs = |
|
78 |
let |
|
79 |
val (c, thm) = prep_cong raw_thm; |
|
21098
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
80 |
val _ = if AList.defined (op =) congs c |
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
81 |
then () |
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
82 |
else warning ("No recdef congruence rule for " ^ quote c); |
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
83 |
in AList.delete (op =) c congs end; |
9859 | 84 |
|
85 |
end; |
|
86 |
||
87 |
||
88 |
||
89 |
(** global and local recdef data **) |
|
90 |
||
17920 | 91 |
(* theory data *) |
6439 | 92 |
|
8657 | 93 |
type recdef_info = {simps: thm list, rules: thm list list, induct: thm, tcs: term list}; |
6439 | 94 |
|
16458 | 95 |
structure GlobalRecdefData = TheoryDataFun |
22846 | 96 |
( |
9859 | 97 |
type T = recdef_info Symtab.table * hints; |
9879 | 98 |
val empty = (Symtab.empty, mk_hints ([], [], [])): T; |
6557 | 99 |
val copy = I; |
16458 | 100 |
val extend = I; |
101 |
fun merge _ |
|
9859 | 102 |
((tab1, {simps = simps1, congs = congs1, wfs = wfs1}), |
16458 | 103 |
(tab2, {simps = simps2, congs = congs2, wfs = wfs2})) : T = |
9859 | 104 |
(Symtab.merge (K true) (tab1, tab2), |
24039
273698405054
renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
22846
diff
changeset
|
105 |
mk_hints (Thm.merge_thms (simps1, simps2), |
22360
26ead7ed4f4b
moved eq_thm etc. to structure Thm in Pure/more_thm.ML;
wenzelm
parents:
22101
diff
changeset
|
106 |
AList.merge (op =) Thm.eq_thm (congs1, congs2), |
24039
273698405054
renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
22846
diff
changeset
|
107 |
Thm.merge_thms (wfs1, wfs2))); |
22846 | 108 |
); |
6439 | 109 |
|
17412 | 110 |
val get_recdef = Symtab.lookup o #1 o GlobalRecdefData.get; |
6439 | 111 |
|
112 |
fun put_recdef name info thy = |
|
6429 | 113 |
let |
9859 | 114 |
val (tab, hints) = GlobalRecdefData.get thy; |
17412 | 115 |
val tab' = Symtab.update_new (name, info) tab |
6439 | 116 |
handle Symtab.DUP _ => error ("Duplicate recursive function definition " ^ quote name); |
9859 | 117 |
in GlobalRecdefData.put (tab', hints) thy end; |
118 |
||
119 |
val get_global_hints = #2 o GlobalRecdefData.get; |
|
120 |
||
121 |
||
17920 | 122 |
(* proof data *) |
9859 | 123 |
|
16458 | 124 |
structure LocalRecdefData = ProofDataFun |
22846 | 125 |
( |
9859 | 126 |
type T = hints; |
127 |
val init = get_global_hints; |
|
22846 | 128 |
); |
9859 | 129 |
|
21505 | 130 |
val get_hints = LocalRecdefData.get; |
131 |
fun map_hints f = Context.mapping (GlobalRecdefData.map (apsnd f)) (LocalRecdefData.map f); |
|
9859 | 132 |
|
20291 | 133 |
|
134 |
(* attributes *) |
|
135 |
||
18728 | 136 |
fun attrib f = Thm.declaration_attribute (map_hints o f); |
9859 | 137 |
|
24039
273698405054
renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
22846
diff
changeset
|
138 |
val simp_add = attrib (map_simps o Thm.add_thm); |
273698405054
renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
22846
diff
changeset
|
139 |
val simp_del = attrib (map_simps o Thm.del_thm); |
18688 | 140 |
val cong_add = attrib (map_congs o add_cong); |
141 |
val cong_del = attrib (map_congs o del_cong); |
|
24039
273698405054
renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
22846
diff
changeset
|
142 |
val wf_add = attrib (map_wfs o Thm.add_thm); |
273698405054
renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents:
22846
diff
changeset
|
143 |
val wf_del = attrib (map_wfs o Thm.del_thm); |
9859 | 144 |
|
145 |
||
9949 | 146 |
(* modifiers *) |
9859 | 147 |
|
9949 | 148 |
val recdef_simpN = "recdef_simp"; |
149 |
val recdef_congN = "recdef_cong"; |
|
150 |
val recdef_wfN = "recdef_wf"; |
|
9859 | 151 |
|
152 |
val recdef_modifiers = |
|
18728 | 153 |
[Args.$$$ recdef_simpN -- Args.colon >> K ((I, simp_add): Method.modifier), |
154 |
Args.$$$ recdef_simpN -- Args.add -- Args.colon >> K (I, simp_add), |
|
155 |
Args.$$$ recdef_simpN -- Args.del -- Args.colon >> K (I, simp_del), |
|
156 |
Args.$$$ recdef_congN -- Args.colon >> K (I, cong_add), |
|
157 |
Args.$$$ recdef_congN -- Args.add -- Args.colon >> K (I, cong_add), |
|
158 |
Args.$$$ recdef_congN -- Args.del -- Args.colon >> K (I, cong_del), |
|
159 |
Args.$$$ recdef_wfN -- Args.colon >> K (I, wf_add), |
|
160 |
Args.$$$ recdef_wfN -- Args.add -- Args.colon >> K (I, wf_add), |
|
161 |
Args.$$$ recdef_wfN -- Args.del -- Args.colon >> K (I, wf_del)] @ |
|
9949 | 162 |
Clasimp.clasimp_modifiers; |
9859 | 163 |
|
9949 | 164 |
|
9859 | 165 |
|
9949 | 166 |
(** prepare_hints(_i) **) |
9859 | 167 |
|
168 |
fun prepare_hints thy opt_src = |
|
169 |
let |
|
170 |
val ctxt0 = ProofContext.init thy; |
|
171 |
val ctxt = |
|
172 |
(case opt_src of |
|
15531 | 173 |
NONE => ctxt0 |
174 |
| SOME src => Method.only_sectioned_args recdef_modifiers I src ctxt0); |
|
21505 | 175 |
val {simps, congs, wfs} = get_hints ctxt; |
15032 | 176 |
val cs = local_claset_of ctxt; |
177 |
val ss = local_simpset_of ctxt addsimps simps; |
|
21098
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
178 |
in (cs, ss, rev (map snd congs), wfs) end; |
9859 | 179 |
|
180 |
fun prepare_hints_i thy () = |
|
15032 | 181 |
let |
182 |
val ctxt0 = ProofContext.init thy; |
|
183 |
val {simps, congs, wfs} = get_global_hints thy; |
|
21098
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
184 |
in (local_claset_of ctxt0, local_simpset_of ctxt0 addsimps simps, rev (map snd congs), wfs) end; |
9859 | 185 |
|
6439 | 186 |
|
187 |
||
188 |
(** add_recdef(_i) **) |
|
189 |
||
6557 | 190 |
fun requires_recdef thy = Theory.requires thy "Recdef" "recursive functions"; |
191 |
||
17920 | 192 |
fun gen_add_recdef tfl_fn prep_att prep_hints not_permissive raw_name R eq_srcs hints thy = |
6439 | 193 |
let |
9859 | 194 |
val _ = requires_recdef thy; |
195 |
||
16458 | 196 |
val name = Sign.intern_const thy raw_name; |
6439 | 197 |
val bname = Sign.base_name name; |
26478 | 198 |
val _ = writeln ("Defining recursive function " ^ quote name ^ " ..."); |
6429 | 199 |
|
8657 | 200 |
val ((eq_names, eqs), raw_eq_atts) = apfst split_list (split_list eq_srcs); |
201 |
val eq_atts = map (map (prep_att thy)) raw_eq_atts; |
|
202 |
||
9859 | 203 |
val (cs, ss, congs, wfs) = prep_hints thy hints; |
14241
dfae7eb2830c
Prevent recdef from looping when the inductio rule is simplified
paulson
parents:
12876
diff
changeset
|
204 |
(*We must remove imp_cong to prevent looping when the induction rule |
dfae7eb2830c
Prevent recdef from looping when the inductio rule is simplified
paulson
parents:
12876
diff
changeset
|
205 |
is simplified. Many induction rules have nested implications that would |
dfae7eb2830c
Prevent recdef from looping when the inductio rule is simplified
paulson
parents:
12876
diff
changeset
|
206 |
give rise to looping conditional rewriting.*) |
dfae7eb2830c
Prevent recdef from looping when the inductio rule is simplified
paulson
parents:
12876
diff
changeset
|
207 |
val (thy, {rules = rules_idx, induct, tcs}) = |
17920 | 208 |
tfl_fn not_permissive thy cs (ss delcongs [imp_cong]) |
14241
dfae7eb2830c
Prevent recdef from looping when the inductio rule is simplified
paulson
parents:
12876
diff
changeset
|
209 |
congs wfs name R eqs; |
21098
d0d8a48ae4e6
switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents:
21078
diff
changeset
|
210 |
val rules = (map o map) fst (partition_eq (eq_snd (op = : int * int -> bool)) rules_idx); |
24624
b8383b1bbae3
distinction between regular and default code theorems
haftmann
parents:
24457
diff
changeset
|
211 |
val simp_att = if null tcs then [Simplifier.simp_add, RecfunCodegen.add_default] else []; |
8657 | 212 |
|
18377 | 213 |
val ((simps' :: rules', [induct']), thy) = |
7798
42e94b618f34
return stored thms with proper naming in derivation;
wenzelm
parents:
7262
diff
changeset
|
214 |
thy |
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
215 |
|> Sign.add_path bname |
18688 | 216 |
|> PureThy.add_thmss |
217 |
((("simps", List.concat rules), simp_att) :: ((eq_names ~~ rules) ~~ eq_atts)) |
|
18377 | 218 |
||>> PureThy.add_thms [(("induct", induct), [])]; |
8657 | 219 |
val result = {simps = simps', rules = rules', induct = induct', tcs = tcs}; |
7798
42e94b618f34
return stored thms with proper naming in derivation;
wenzelm
parents:
7262
diff
changeset
|
220 |
val thy = |
42e94b618f34
return stored thms with proper naming in derivation;
wenzelm
parents:
7262
diff
changeset
|
221 |
thy |
6439 | 222 |
|> put_recdef name result |
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
223 |
|> Sign.parent_path; |
7798
42e94b618f34
return stored thms with proper naming in derivation;
wenzelm
parents:
7262
diff
changeset
|
224 |
in (thy, result) end; |
6429 | 225 |
|
18728 | 226 |
val add_recdef = gen_add_recdef Tfl.define Attrib.attribute prepare_hints; |
11629 | 227 |
fun add_recdef_i x y z w = gen_add_recdef Tfl.define_i (K I) prepare_hints_i x y z w (); |
9859 | 228 |
|
229 |
||
6557 | 230 |
|
231 |
(** defer_recdef(_i) **) |
|
232 |
||
27727
2397e310b2cc
simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents:
27353
diff
changeset
|
233 |
fun gen_defer_recdef tfl_fn eval_thms raw_name eqs raw_congs thy = |
6557 | 234 |
let |
16458 | 235 |
val name = Sign.intern_const thy raw_name; |
6557 | 236 |
val bname = Sign.base_name name; |
237 |
||
238 |
val _ = requires_recdef thy; |
|
26478 | 239 |
val _ = writeln ("Deferred recursive function " ^ quote name ^ " ..."); |
6557 | 240 |
|
27727
2397e310b2cc
simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents:
27353
diff
changeset
|
241 |
val congs = eval_thms (ProofContext.init thy) raw_congs; |
2397e310b2cc
simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents:
27353
diff
changeset
|
242 |
val (thy2, induct_rules) = tfl_fn thy congs name eqs; |
18377 | 243 |
val ([induct_rules'], thy3) = |
6557 | 244 |
thy2 |
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
245 |
|> Sign.add_path bname |
6557 | 246 |
|> PureThy.add_thms [(("induct_rules", induct_rules), [])] |
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24624
diff
changeset
|
247 |
||> Sign.parent_path; |
8430 | 248 |
in (thy3, {induct_rules = induct_rules'}) end; |
6557 | 249 |
|
27727
2397e310b2cc
simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents:
27353
diff
changeset
|
250 |
val defer_recdef = gen_defer_recdef Tfl.defer Attrib.eval_thms; |
2397e310b2cc
simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents:
27353
diff
changeset
|
251 |
val defer_recdef_i = gen_defer_recdef Tfl.defer_i (K I); |
6557 | 252 |
|
253 |
||
254 |
||
10775 | 255 |
(** recdef_tc(_i) **) |
256 |
||
24457
a33258c78ed2
Adapted to changes in interface of Specification.theorem_i
berghofe
parents:
24039
diff
changeset
|
257 |
fun gen_recdef_tc prep_att prep_name (bname, raw_atts) raw_name opt_i int lthy = |
10775 | 258 |
let |
21351
1fb804b96d7c
recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents:
21098
diff
changeset
|
259 |
val thy = ProofContext.theory_of lthy; |
16458 | 260 |
val name = prep_name thy raw_name; |
10775 | 261 |
val atts = map (prep_att thy) raw_atts; |
262 |
val tcs = |
|
263 |
(case get_recdef thy name of |
|
15531 | 264 |
NONE => error ("No recdef definition of constant: " ^ quote name) |
265 |
| SOME {tcs, ...} => tcs); |
|
21351
1fb804b96d7c
recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents:
21098
diff
changeset
|
266 |
val i = the_default 1 opt_i; |
1fb804b96d7c
recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents:
21098
diff
changeset
|
267 |
val tc = nth tcs (i - 1) handle Subscript => |
10775 | 268 |
error ("No termination condition #" ^ string_of_int i ^ |
269 |
" in recdef definition of " ^ quote name); |
|
21351
1fb804b96d7c
recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents:
21098
diff
changeset
|
270 |
in |
24927
48e08f37ce92
Specification: renamed XXX_i to XXX, and XXX to XXX_cmd;
wenzelm
parents:
24867
diff
changeset
|
271 |
Specification.theorem Thm.internalK NONE (K I) (bname, atts) |
24457
a33258c78ed2
Adapted to changes in interface of Specification.theorem_i
berghofe
parents:
24039
diff
changeset
|
272 |
[] (Element.Shows [(("", []), [(HOLogic.mk_Trueprop tc, [])])]) int lthy |
21351
1fb804b96d7c
recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents:
21098
diff
changeset
|
273 |
end; |
10775 | 274 |
|
21351
1fb804b96d7c
recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents:
21098
diff
changeset
|
275 |
val recdef_tc = gen_recdef_tc Attrib.intern_src Sign.intern_const; |
10775 | 276 |
val recdef_tc_i = gen_recdef_tc (K I) (K I); |
277 |
||
278 |
||
279 |
||
6439 | 280 |
(** package setup **) |
281 |
||
282 |
(* setup theory *) |
|
283 |
||
9859 | 284 |
val setup = |
285 |
Attrib.add_attributes |
|
18728 | 286 |
[(recdef_simpN, Attrib.add_del_args simp_add simp_del, "declaration of recdef simp rule"), |
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
19686
diff
changeset
|
287 |
(recdef_congN, Attrib.add_del_args cong_add cong_del, "declaration of recdef cong rule"), |
18728 | 288 |
(recdef_wfN, Attrib.add_del_args wf_add wf_del, "declaration of recdef wf rule")]; |
6439 | 289 |
|
290 |
||
6429 | 291 |
(* outer syntax *) |
292 |
||
17057 | 293 |
local structure P = OuterParse and K = OuterKeyword in |
6429 | 294 |
|
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
26988
diff
changeset
|
295 |
val _ = List.app OuterKeyword.keyword ["permissive", "congs", "hints"]; |
24867 | 296 |
|
9859 | 297 |
val hints = |
298 |
P.$$$ "(" |-- P.!!! (P.position (P.$$$ "hints" -- P.arguments) --| P.$$$ ")") >> Args.src; |
|
299 |
||
6429 | 300 |
val recdef_decl = |
11629 | 301 |
Scan.optional (P.$$$ "(" -- P.!!! (P.$$$ "permissive" -- P.$$$ ")") >> K false) true -- |
22101 | 302 |
P.name -- P.term -- Scan.repeat1 (SpecParse.opt_thm_name ":" -- P.prop) -- Scan.option hints |
11629 | 303 |
>> (fn ((((p, f), R), eqs), src) => #1 o add_recdef p f R (map P.triple_swap eqs) src); |
6429 | 304 |
|
24867 | 305 |
val _ = |
6723 | 306 |
OuterSyntax.command "recdef" "define general recursive functions (TFL)" K.thy_decl |
6429 | 307 |
(recdef_decl >> Toplevel.theory); |
308 |
||
6557 | 309 |
|
310 |
val defer_recdef_decl = |
|
8657 | 311 |
P.name -- Scan.repeat1 P.prop -- |
22101 | 312 |
Scan.optional (P.$$$ "(" |-- P.$$$ "congs" |-- P.!!! (SpecParse.xthms1 --| P.$$$ ")")) [] |
6557 | 313 |
>> (fn ((f, eqs), congs) => #1 o defer_recdef f eqs congs); |
314 |
||
24867 | 315 |
val _ = |
6723 | 316 |
OuterSyntax.command "defer_recdef" "defer general recursive functions (TFL)" K.thy_decl |
6557 | 317 |
(defer_recdef_decl >> Toplevel.theory); |
318 |
||
24867 | 319 |
val _ = |
26988
742e26213212
more uniform treatment of OuterSyntax.local_theory commands;
wenzelm
parents:
26478
diff
changeset
|
320 |
OuterSyntax.local_theory_to_proof' "recdef_tc" "recommence proof of termination condition (TFL)" |
742e26213212
more uniform treatment of OuterSyntax.local_theory commands;
wenzelm
parents:
26478
diff
changeset
|
321 |
K.thy_goal |
742e26213212
more uniform treatment of OuterSyntax.local_theory commands;
wenzelm
parents:
26478
diff
changeset
|
322 |
(SpecParse.opt_thm_name ":" -- P.xname -- Scan.option (P.$$$ "(" |-- P.nat --| P.$$$ ")") |
742e26213212
more uniform treatment of OuterSyntax.local_theory commands;
wenzelm
parents:
26478
diff
changeset
|
323 |
>> (fn ((thm_name, name), i) => recdef_tc thm_name name i)); |
10775 | 324 |
|
6429 | 325 |
end; |
326 |
||
327 |
end; |