equal
deleted
inserted
replaced
9 sig |
9 sig |
10 val quiet_mode: bool ref |
10 val quiet_mode: bool ref |
11 val add_primrec: string -> ((bstring * string) * Attrib.src list) list |
11 val add_primrec: string -> ((bstring * string) * Attrib.src list) list |
12 -> theory -> theory * thm list |
12 -> theory -> theory * thm list |
13 val add_primrec_i: string -> ((bstring * term) * attribute list) list |
13 val add_primrec_i: string -> ((bstring * term) * attribute list) list |
|
14 -> theory -> theory * thm list |
|
15 val add_primrec_unchecked_i: string -> ((bstring * term) * attribute list) list |
14 -> theory -> theory * thm list |
16 -> theory -> theory * thm list |
15 end; |
17 end; |
16 |
18 |
17 structure PrimrecPackage : PRIMREC_PACKAGE = |
19 structure PrimrecPackage : PRIMREC_PACKAGE = |
18 struct |
20 struct |
219 induction |
221 induction |
220 |> RuleCases.rename_params (map params_of (List.concat (map (map #1 o #3 o #2) descr))) |
222 |> RuleCases.rename_params (map params_of (List.concat (map (map #1 o #3 o #2) descr))) |
221 |> RuleCases.save induction |
223 |> RuleCases.save induction |
222 end; |
224 end; |
223 |
225 |
224 fun add_primrec_i alt_name eqns_atts thy = |
226 fun gen_primrec unchecked alt_name eqns_atts thy = |
225 let |
227 let |
226 val (eqns, atts) = split_list eqns_atts; |
228 val (eqns, atts) = split_list eqns_atts; |
227 val sg = Theory.sign_of thy; |
229 val sg = Theory.sign_of thy; |
228 val dt_info = DatatypePackage.get_datatypes thy; |
230 val dt_info = DatatypePackage.get_datatypes thy; |
229 val rec_eqns = foldr (process_eqn sg) [] (map snd eqns); |
231 val rec_eqns = foldr (process_eqn sg) [] (map snd eqns); |
245 val nameTs1 = map snd fnameTs; |
247 val nameTs1 = map snd fnameTs; |
246 val nameTs2 = map fst rec_eqns; |
248 val nameTs2 = map fst rec_eqns; |
247 val primrec_name = |
249 val primrec_name = |
248 if alt_name = "" then (space_implode "_" (map (Sign.base_name o #1) defs)) else alt_name; |
250 if alt_name = "" then (space_implode "_" (map (Sign.base_name o #1) defs)) else alt_name; |
249 val (defs_thms', thy') = thy |> Theory.add_path primrec_name |> |
251 val (defs_thms', thy') = thy |> Theory.add_path primrec_name |> |
250 (if eq_set (nameTs1, nameTs2) then (PureThy.add_defs_i false o map Thm.no_attributes) defs' |
252 (if eq_set (nameTs1, nameTs2) then |
|
253 ((if unchecked then PureThy.add_defs_unchecked_i else PureThy.add_defs_i) false o |
|
254 map Thm.no_attributes) defs' |
251 else primrec_err ("functions " ^ commas_quote (map fst nameTs2) ^ |
255 else primrec_err ("functions " ^ commas_quote (map fst nameTs2) ^ |
252 "\nare not mutually recursive")); |
256 "\nare not mutually recursive")); |
253 val rewrites = (map mk_meta_eq rec_rewrites) @ defs_thms'; |
257 val rewrites = (map mk_meta_eq rec_rewrites) @ defs_thms'; |
254 val _ = message ("Proving equations for primrec function(s) " ^ |
258 val _ = message ("Proving equations for primrec function(s) " ^ |
255 commas_quote (map fst nameTs1) ^ " ..."); |
259 commas_quote (map fst nameTs1) ^ " ..."); |
263 |> Theory.parent_path |
267 |> Theory.parent_path |
264 in |
268 in |
265 (thy''', simps') |
269 (thy''', simps') |
266 end; |
270 end; |
267 |
271 |
|
272 val add_primrec_i = gen_primrec false; |
|
273 val add_primrec_unchecked_i = gen_primrec true; |
268 |
274 |
269 fun add_primrec alt_name eqns thy = |
275 fun add_primrec alt_name eqns thy = |
270 let |
276 let |
271 val sign = Theory.sign_of thy; |
277 val sign = Theory.sign_of thy; |
272 val ((names, strings), srcss) = apfst split_list (split_list eqns); |
278 val ((names, strings), srcss) = apfst split_list (split_list eqns); |