7 |
7 |
8 signature RECDEF_PACKAGE = |
8 signature RECDEF_PACKAGE = |
9 sig |
9 sig |
10 val quiet_mode: bool ref |
10 val quiet_mode: bool ref |
11 val print_recdefs: theory -> unit |
11 val print_recdefs: theory -> unit |
12 val get_recdef: theory -> string -> {rules: thm list, induct: thm, tcs: term list} option |
12 val get_recdef: theory -> string -> {simps: thm list, induct: thm, tcs: term list} option |
13 val add_recdef: xstring -> string -> string list -> simpset option |
13 val add_recdef: xstring -> string -> string list -> simpset option |
14 -> (xstring * Args.src list) list -> theory |
14 -> (xstring * Args.src list) list -> theory |
15 -> theory * {rules: thm list, induct: thm, tcs: term list} |
15 -> theory * {simps: thm list, induct: thm, tcs: term list} |
16 val add_recdef_i: xstring -> term -> term list -> simpset option |
16 val add_recdef_i: xstring -> term -> term list -> simpset option |
17 -> (thm * theory attribute list) list |
17 -> (thm * theory attribute list) list |
18 -> theory -> theory * {rules: thm list, induct: thm, tcs: term list} |
18 -> theory -> theory * {simps: thm list, induct: thm, tcs: term list} |
19 val defer_recdef: xstring -> string list -> (xstring * Args.src list) list |
19 val defer_recdef: xstring -> string list -> (xstring * Args.src list) list |
20 -> theory -> theory * {induct_rules: thm} |
20 -> theory -> theory * {induct_rules: thm} |
21 val defer_recdef_i: xstring -> term list -> (thm * theory attribute list) list |
21 val defer_recdef_i: xstring -> term list -> (thm * theory attribute list) list |
22 -> theory -> theory * {induct_rules: thm} |
22 -> theory -> theory * {induct_rules: thm} |
23 val setup: (theory -> theory) list |
23 val setup: (theory -> theory) list |
33 |
33 |
34 (** theory data **) |
34 (** theory data **) |
35 |
35 |
36 (* data kind 'HOL/recdef' *) |
36 (* data kind 'HOL/recdef' *) |
37 |
37 |
38 type recdef_info = {rules: thm list, induct: thm, tcs: term list}; |
38 type recdef_info = {simps: thm list, induct: thm, tcs: term list}; |
39 |
39 |
40 structure RecdefArgs = |
40 structure RecdefArgs = |
41 struct |
41 struct |
42 val name = "HOL/recdef"; |
42 val name = "HOL/recdef"; |
43 type T = recdef_info Symtab.table; |
43 type T = recdef_info Symtab.table; |
70 |
70 |
71 (** add_recdef(_i) **) |
71 (** add_recdef(_i) **) |
72 |
72 |
73 fun requires_recdef thy = Theory.requires thy "Recdef" "recursive functions"; |
73 fun requires_recdef thy = Theory.requires thy "Recdef" "recursive functions"; |
74 |
74 |
|
75 |
|
76 fun prepare_simps no_tcs ixsimps = |
|
77 let val partnd = partition_eq (fn ((_,i),(_,j)) => i=j) ixsimps; |
|
78 val attr = if no_tcs then [Simplifier.simp_add_global] else [] |
|
79 in map (fn (rl,i)::rls => ((string_of_int i, rl::map fst rls), attr)) partnd |
|
80 end; |
|
81 |
75 fun gen_add_recdef tfl_fn prep_ss app_thms raw_name R eqs raw_ss raw_congs thy = |
82 fun gen_add_recdef tfl_fn prep_ss app_thms raw_name R eqs raw_ss raw_congs thy = |
76 let |
83 let |
77 val name = Sign.intern_const (Theory.sign_of thy) raw_name; |
84 val name = Sign.intern_const (Theory.sign_of thy) raw_name; |
78 val bname = Sign.base_name name; |
85 val bname = Sign.base_name name; |
79 |
86 |
81 val _ = message ("Defining recursive function " ^ quote name ^ " ..."); |
88 val _ = message ("Defining recursive function " ^ quote name ^ " ..."); |
82 |
89 |
83 val ss = (case raw_ss of None => Simplifier.simpset_of thy | Some x => prep_ss x); |
90 val ss = (case raw_ss of None => Simplifier.simpset_of thy | Some x => prep_ss x); |
84 val (thy, congs) = thy |> app_thms raw_congs; |
91 val (thy, congs) = thy |> app_thms raw_congs; |
85 val (thy, {rules, induct, tcs}) = tfl_fn thy name R (ss, congs) eqs; |
92 val (thy, {rules, induct, tcs}) = tfl_fn thy name R (ss, congs) eqs; |
|
93 val named_simps = prepare_simps (null tcs) rules |
86 val case_numbers = map Library.string_of_int (1 upto Thm.nprems_of induct); |
94 val case_numbers = map Library.string_of_int (1 upto Thm.nprems_of induct); |
87 val (thy, ([rules], [induct])) = |
95 val (thy, (simpss, [induct])) = |
88 thy |
96 thy |
89 |> Theory.add_path bname |
97 |> Theory.add_path bname |
90 |> PureThy.add_thmss [(("rules", rules), [])] |
98 |> PureThy.add_thmss named_simps |
91 |>>> PureThy.add_thms [(("induct", induct), [RuleCases.case_names case_numbers])]; |
99 |>>> PureThy.add_thms [(("induct", induct), [RuleCases.case_names case_numbers])]; |
92 val result = {rules = rules, induct = induct, tcs = tcs}; |
100 val result = {simps = flat simpss, induct = induct, tcs = tcs}; |
93 val thy = |
101 val thy = |
94 thy |
102 thy |
95 |> put_recdef name result |
103 |> put_recdef name result |
96 |> Theory.parent_path; |
104 |> Theory.parent_path; |
97 in (thy, result) end; |
105 in (thy, result) end; |