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