author | wenzelm |
Wed, 11 Mar 2009 15:42:19 +0100 | |
changeset 30435 | e62d6ecab6ad |
parent 30364 | 577edc39b501 |
child 30486 | 9cdc7ce0e389 |
permissions | -rw-r--r-- |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
1 |
(* Title: HOL/Tools/function_package/fundef_package.ML |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
2 |
Author: Alexander Krauss, TU Muenchen |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
3 |
|
20363
f34c5dbe74d5
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20338
diff
changeset
|
4 |
A package for general recursive function definitions. |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
5 |
Isar commands. |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
6 |
*) |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
7 |
|
20363
f34c5dbe74d5
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20338
diff
changeset
|
8 |
signature FUNDEF_PACKAGE = |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
9 |
sig |
29581 | 10 |
val add_fundef : (binding * string option * mixfix) list |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28083
diff
changeset
|
11 |
-> (Attrib.binding * string) list |
20877
368b997ad67e
removed with_local_path -- LocalTheory.note admits qualified names;
wenzelm
parents:
20654
diff
changeset
|
12 |
-> FundefCommon.fundef_config |
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
13 |
-> bool list |
20877
368b997ad67e
removed with_local_path -- LocalTheory.note admits qualified names;
wenzelm
parents:
20654
diff
changeset
|
14 |
-> local_theory |
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
15 |
-> Proof.state |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
16 |
|
29581 | 17 |
val add_fundef_i: (binding * typ option * mixfix) list |
28084
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
wenzelm
parents:
28083
diff
changeset
|
18 |
-> (Attrib.binding * term) list |
22170 | 19 |
-> FundefCommon.fundef_config |
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
20 |
-> bool list |
20877
368b997ad67e
removed with_local_path -- LocalTheory.note admits qualified names;
wenzelm
parents:
20654
diff
changeset
|
21 |
-> local_theory |
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
22 |
-> Proof.state |
21211
5370cfbf3070
Preparations for making "lexicographic_order" part of "fun"
krauss
parents:
21051
diff
changeset
|
23 |
|
5370cfbf3070
Preparations for making "lexicographic_order" part of "fun"
krauss
parents:
21051
diff
changeset
|
24 |
val setup_termination_proof : string option -> local_theory -> Proof.state |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
25 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
26 |
val setup : theory -> theory |
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
19617
diff
changeset
|
27 |
val get_congs : theory -> thm list |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
28 |
end |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
29 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
30 |
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
31 |
structure FundefPackage : FUNDEF_PACKAGE = |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
32 |
struct |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
33 |
|
21051
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
21000
diff
changeset
|
34 |
open FundefLib |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
35 |
open FundefCommon |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
36 |
|
30435
e62d6ecab6ad
explicit Binding.qualified_name -- prevents implicitly qualified bstring;
wenzelm
parents:
30364
diff
changeset
|
37 |
fun note_theorem ((name, atts), ths) = |
e62d6ecab6ad
explicit Binding.qualified_name -- prevents implicitly qualified bstring;
wenzelm
parents:
30364
diff
changeset
|
38 |
LocalTheory.note Thm.theoremK ((Binding.qualified_name name, atts), ths) |
21435 | 39 |
|
22166 | 40 |
fun mk_defname fixes = fixes |> map (fst o fst) |> space_implode "_" |
41 |
||
26529 | 42 |
fun add_simps fnames post sort extra_qualify label moreatts simps lthy = |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
43 |
let |
29866
6e93ae65c678
Added Nitpick_Const_Psimp attribute, dropped the 's' in Nitpick_Const_Simps, and killed the Nitpick_Ind_Intros attribute.
blanchet
parents:
29863
diff
changeset
|
44 |
val atts = Attrib.internal (K Simplifier.simp_add) :: moreatts |
23819 | 45 |
val spec = post simps |
46 |
|> map (apfst (apsnd (append atts))) |
|
26529 | 47 |
|> map (apfst (apfst extra_qualify)) |
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21240
diff
changeset
|
48 |
|
22166 | 49 |
val (saved_spec_simps, lthy) = |
23819 | 50 |
fold_map note_theorem spec lthy |
51 |
||
22498
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
krauss
parents:
22325
diff
changeset
|
52 |
val saved_simps = flat (map snd saved_spec_simps) |
22166 | 53 |
val simps_by_f = sort saved_simps |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
54 |
|
22166 | 55 |
fun add_for_f fname simps = |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30223
diff
changeset
|
56 |
note_theorem ((Long_Name.qualify fname label, []), simps) #> snd |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
57 |
in |
22166 | 58 |
(saved_simps, |
59 |
fold2 add_for_f fnames simps_by_f lthy) |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
60 |
end |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
61 |
|
26594
1c676ae50311
fundef_afterqed: removed unused config, added do_print flag;
wenzelm
parents:
26580
diff
changeset
|
62 |
fun fundef_afterqed do_print fixes post defname cont sort_cont cnames [[proof]] lthy = |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
63 |
let |
26529 | 64 |
val FundefResult {fs, R, psimps, trsimps, simple_pinducts, termination, domintros, cases, ...} = |
26628
63306cb94313
replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
wenzelm
parents:
26594
diff
changeset
|
65 |
cont (Thm.close_derivation proof) |
22166 | 66 |
|
23819 | 67 |
val fnames = map (fst o fst) fixes |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30223
diff
changeset
|
68 |
val qualify = Long_Name.qualify defname |
23819 | 69 |
val addsmps = add_simps fnames post sort_cont |
21602 | 70 |
|
71 |
val (((psimps', pinducts'), (_, [termination'])), lthy) = |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21240
diff
changeset
|
72 |
lthy |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30223
diff
changeset
|
73 |
|> addsmps (Long_Name.qualify "partial") "psimps" |
29866
6e93ae65c678
Added Nitpick_Const_Psimp attribute, dropped the 's' in Nitpick_Const_Simps, and killed the Nitpick_Ind_Intros attribute.
blanchet
parents:
29863
diff
changeset
|
74 |
[Attrib.internal (K Nitpick_Const_Psimp_Thms.add)] psimps |
6e93ae65c678
Added Nitpick_Const_Psimp attribute, dropped the 's' in Nitpick_Const_Simps, and killed the Nitpick_Ind_Intros attribute.
blanchet
parents:
29863
diff
changeset
|
75 |
||> fold_option (snd oo addsmps I "simps" [Attrib.internal (K Nitpick_Const_Simp_Thms.add)]) trsimps |
22166 | 76 |
||>> note_theorem ((qualify "pinduct", |
25222
78943ac46f6d
fun/function: generate case names for induction rules
krauss
parents:
25201
diff
changeset
|
77 |
[Attrib.internal (K (RuleCases.case_names cnames)), |
78943ac46f6d
fun/function: generate case names for induction rules
krauss
parents:
25201
diff
changeset
|
78 |
Attrib.internal (K (RuleCases.consumes 1)), |
78943ac46f6d
fun/function: generate case names for induction rules
krauss
parents:
25201
diff
changeset
|
79 |
Attrib.internal (K (Induct.induct_pred ""))]), simple_pinducts) |
22166 | 80 |
||>> note_theorem ((qualify "termination", []), [termination]) |
25222
78943ac46f6d
fun/function: generate case names for induction rules
krauss
parents:
25201
diff
changeset
|
81 |
||> (snd o note_theorem ((qualify "cases", |
78943ac46f6d
fun/function: generate case names for induction rules
krauss
parents:
25201
diff
changeset
|
82 |
[Attrib.internal (K (RuleCases.case_names cnames))]), [cases])) |
22166 | 83 |
||> fold_option (snd oo curry note_theorem (qualify "domintros", [])) domintros |
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21240
diff
changeset
|
84 |
|
25222
78943ac46f6d
fun/function: generate case names for induction rules
krauss
parents:
25201
diff
changeset
|
85 |
val cdata = FundefCtxData { add_simps=addsmps, case_names=cnames, psimps=psimps', |
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
86 |
pinducts=snd pinducts', termination=termination', fs=fs, R=R, defname=defname } |
26594
1c676ae50311
fundef_afterqed: removed unused config, added do_print flag;
wenzelm
parents:
26580
diff
changeset
|
87 |
val _ = |
1c676ae50311
fundef_afterqed: removed unused config, added do_print flag;
wenzelm
parents:
26580
diff
changeset
|
88 |
if not do_print then () |
1c676ae50311
fundef_afterqed: removed unused config, added do_print flag;
wenzelm
parents:
26580
diff
changeset
|
89 |
else Specification.print_consts lthy (K false) (map fst fixes) |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
90 |
in |
22623 | 91 |
lthy |
25201 | 92 |
|> LocalTheory.declaration (add_fundef_data o morph_fundef_data cdata) |
25222
78943ac46f6d
fun/function: generate case names for induction rules
krauss
parents:
25201
diff
changeset
|
93 |
end |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
94 |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
95 |
|
29051 | 96 |
fun gen_add_fundef is_external prep default_constraint fixspec eqnss config flags lthy = |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
97 |
let |
29051 | 98 |
val constrn_fxs = map (fn (b, T, mx) => (b, SOME (the_default default_constraint T), mx)) |
99 |
val ((fixes0, spec0), ctxt') = |
|
100 |
prep (constrn_fxs fixspec) (map (single o apsnd single) eqnss) lthy |
|
30223
24d975352879
renamed Binding.name_pos to Binding.make, renamed Binding.base_name to Binding.name_of, renamed Binding.map_base to Binding.map_name, added mandatory flag to Binding.qualify;
wenzelm
parents:
29866
diff
changeset
|
101 |
val fixes = map (apfst (apfst Binding.name_of)) fixes0; |
24d975352879
renamed Binding.name_pos to Binding.make, renamed Binding.base_name to Binding.name_of, renamed Binding.map_base to Binding.map_name, added mandatory flag to Binding.qualify;
wenzelm
parents:
29866
diff
changeset
|
102 |
val spec = map (apfst (apfst Binding.name_of)) spec0; |
25222
78943ac46f6d
fun/function: generate case names for induction rules
krauss
parents:
25201
diff
changeset
|
103 |
val (eqs, post, sort_cont, cnames) = FundefCommon.get_preproc lthy config flags ctxt' fixes spec |
22166 | 104 |
|
105 |
val defname = mk_defname fixes |
|
106 |
||
23819 | 107 |
val ((goalstate, cont), lthy) = |
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
108 |
FundefMutual.prepare_fundef_mutual config defname fixes eqs lthy |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
109 |
|
26594
1c676ae50311
fundef_afterqed: removed unused config, added do_print flag;
wenzelm
parents:
26580
diff
changeset
|
110 |
val afterqed = fundef_afterqed is_external fixes post defname cont sort_cont cnames |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
111 |
in |
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
112 |
lthy |
26594
1c676ae50311
fundef_afterqed: removed unused config, added do_print flag;
wenzelm
parents:
26580
diff
changeset
|
113 |
|> is_external ? LocalTheory.set_group (serial_string ()) |
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
114 |
|> Proof.theorem_i NONE afterqed [[(Logic.unprotect (concl_of goalstate), [])]] |
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
115 |
|> Proof.refine (Method.primitive_text (fn _ => goalstate)) |> Seq.hd |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
116 |
end |
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
117 |
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
118 |
fun total_termination_afterqed data [[totality]] lthy = |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
119 |
let |
25222
78943ac46f6d
fun/function: generate case names for induction rules
krauss
parents:
25201
diff
changeset
|
120 |
val FundefCtxData { add_simps, case_names, psimps, pinducts, defname, ... } = data |
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21240
diff
changeset
|
121 |
|
26628
63306cb94313
replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
wenzelm
parents:
26594
diff
changeset
|
122 |
val totality = Thm.close_derivation totality |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
123 |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21240
diff
changeset
|
124 |
val remove_domain_condition = full_simplify (HOL_basic_ss addsimps [totality, True_implies_equals]) |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
125 |
|
22166 | 126 |
val tsimps = map remove_domain_condition psimps |
127 |
val tinduct = map remove_domain_condition pinducts |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
19617
diff
changeset
|
128 |
|
21511
16c62deb1adf
The function package declares the [code] attribute automatically again.
krauss
parents:
21491
diff
changeset
|
129 |
val has_guards = exists ((fn (Const ("Trueprop", _) $ _) => false | _ => true) o prop_of) tsimps |
29866
6e93ae65c678
Added Nitpick_Const_Psimp attribute, dropped the 's' in Nitpick_Const_Simps, and killed the Nitpick_Ind_Intros attribute.
blanchet
parents:
29863
diff
changeset
|
130 |
val allatts = (not has_guards ? cons Code.add_default_eqn_attrib) |
6e93ae65c678
Added Nitpick_Const_Psimp attribute, dropped the 's' in Nitpick_Const_Simps, and killed the Nitpick_Ind_Intros attribute.
blanchet
parents:
29863
diff
changeset
|
131 |
[Attrib.internal (K Nitpick_Const_Simp_Thms.add)] |
21602 | 132 |
|
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30223
diff
changeset
|
133 |
val qualify = Long_Name.qualify defname; |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
134 |
in |
21511
16c62deb1adf
The function package declares the [code] attribute automatically again.
krauss
parents:
21491
diff
changeset
|
135 |
lthy |
26529 | 136 |
|> add_simps I "simps" allatts tsimps |> snd |
25222
78943ac46f6d
fun/function: generate case names for induction rules
krauss
parents:
25201
diff
changeset
|
137 |
|> note_theorem ((qualify "induct", [Attrib.internal (K (RuleCases.case_names case_names))]), tinduct) |> snd |
20363
f34c5dbe74d5
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20338
diff
changeset
|
138 |
end |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
139 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
140 |
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
141 |
fun setup_termination_proof term_opt lthy = |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
142 |
let |
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
143 |
val data = the (case term_opt of |
24508
c8b82fec6447
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents:
24168
diff
changeset
|
144 |
SOME t => import_fundef_data (Syntax.read_term lthy t) (Context.Proof lthy) |
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
145 |
| NONE => import_last_fundef (Context.Proof lthy)) |
27187 | 146 |
handle Option.Option => error ("Not a function: " ^ quote (the_default "" term_opt)) |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
147 |
|
22166 | 148 |
val FundefCtxData {termination, R, ...} = data |
22325 | 149 |
val domT = domain_type (fastype_of R) |
150 |
val goal = HOLogic.mk_Trueprop (HOLogic.mk_all ("x", domT, mk_acc domT R $ Free ("x", domT))) |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
151 |
in |
20877
368b997ad67e
removed with_local_path -- LocalTheory.note admits qualified names;
wenzelm
parents:
20654
diff
changeset
|
152 |
lthy |
28965 | 153 |
|> ProofContext.note_thmss_i "" [((Binding.empty, [ContextRules.rule_del]), [([allI], [])])] |> snd |
154 |
|> ProofContext.note_thmss_i "" [((Binding.empty, [ContextRules.intro_bang (SOME 1)]), [([allI], [])])] |> snd |
|
21602 | 155 |
|> ProofContext.note_thmss_i "" |
28965 | 156 |
[((Binding.name "termination", [ContextRules.intro_bang (SOME 0)]), |
21602 | 157 |
[([Goal.norm_result termination], [])])] |> snd |
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
158 |
|> Proof.theorem_i NONE (total_termination_afterqed data) [[(goal, [])]] |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
159 |
end |
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
160 |
|
26171
5426a823455c
more precise handling of "group" for termination;
wenzelm
parents:
26129
diff
changeset
|
161 |
fun termination_cmd term_opt lthy = |
5426a823455c
more precise handling of "group" for termination;
wenzelm
parents:
26129
diff
changeset
|
162 |
lthy |
5426a823455c
more precise handling of "group" for termination;
wenzelm
parents:
26129
diff
changeset
|
163 |
|> LocalTheory.set_group (serial_string ()) |
5426a823455c
more precise handling of "group" for termination;
wenzelm
parents:
26129
diff
changeset
|
164 |
|> setup_termination_proof term_opt; |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
165 |
|
29051 | 166 |
val add_fundef = gen_add_fundef true Specification.read_specification "_::type" |
167 |
val add_fundef_i = |
|
168 |
gen_add_fundef false Specification.check_specification (TypeInfer.anyT HOLogic.typeS) |
|
19611
da2a0014c461
Function Package: Quick-and-dirty-fixed strange "Proved a different theorem bug"
krauss
parents:
19585
diff
changeset
|
169 |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
170 |
|
21235
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
171 |
(* Datatype hook to declare datatype congs as "fundef_congs" *) |
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
172 |
|
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
173 |
|
21602 | 174 |
fun add_case_cong n thy = |
24168
86a03a092062
simplified internal interfaces; cong rules are now handled directly by "context_tree.ML"
krauss
parents:
24039
diff
changeset
|
175 |
Context.theory_map (FundefCtxTree.map_fundef_congs (Thm.add_thm |
21235
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
176 |
(DatatypePackage.get_datatype thy n |> the |
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
177 |
|> #case_cong |
21602 | 178 |
|> safe_mk_meta_eq))) |
21235
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
179 |
thy |
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
180 |
|
24626
85eceef2edc7
introduced generic concepts for theory interpretators
haftmann
parents:
24624
diff
changeset
|
181 |
val case_cong = fold add_case_cong |
21235
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
182 |
|
24711 | 183 |
val setup_case_cong = DatatypePackage.interpretation case_cong |
24626
85eceef2edc7
introduced generic concepts for theory interpretators
haftmann
parents:
24624
diff
changeset
|
184 |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
185 |
(* setup *) |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
186 |
|
21602 | 187 |
val setup = |
22846 | 188 |
Attrib.add_attributes |
24168
86a03a092062
simplified internal interfaces; cong rules are now handled directly by "context_tree.ML"
krauss
parents:
24039
diff
changeset
|
189 |
[("fundef_cong", Attrib.add_del_args FundefCtxTree.cong_add FundefCtxTree.cong_del, |
22846 | 190 |
"declaration of congruence rule for function definitions")] |
24626
85eceef2edc7
introduced generic concepts for theory interpretators
haftmann
parents:
24624
diff
changeset
|
191 |
#> setup_case_cong |
22846 | 192 |
#> FundefRelation.setup |
26749
397a1aeede7d
* New attribute "termination_simp": Simp rules for termination proofs
krauss
parents:
26628
diff
changeset
|
193 |
#> FundefCommon.TerminationSimps.setup |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
194 |
|
24168
86a03a092062
simplified internal interfaces; cong rules are now handled directly by "context_tree.ML"
krauss
parents:
24039
diff
changeset
|
195 |
val get_congs = FundefCtxTree.get_fundef_congs o Context.Theory |
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
19617
diff
changeset
|
196 |
|
21235
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
197 |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
198 |
(* outer syntax *) |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
199 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
200 |
local structure P = OuterParse and K = OuterKeyword in |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
201 |
|
27353
71c4dd53d4cb
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents:
27187
diff
changeset
|
202 |
val _ = OuterKeyword.keyword "otherwise"; |
24867 | 203 |
|
204 |
val _ = |
|
26989 | 205 |
OuterSyntax.local_theory_to_proof "function" "define general recursive functions" K.thy_goal |
22498
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
krauss
parents:
22325
diff
changeset
|
206 |
(fundef_parser default_config |
26989 | 207 |
>> (fn ((config, fixes), (flags, statements)) => add_fundef fixes statements config flags)); |
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
208 |
|
24867 | 209 |
val _ = |
26989 | 210 |
OuterSyntax.local_theory_to_proof "termination" "prove termination of a recursive function" K.thy_goal |
211 |
(Scan.option P.term >> termination_cmd); |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
212 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
213 |
end; |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
214 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
215 |
|
19585 | 216 |
end |