| author | huffman |
| Mon, 11 Jun 2007 00:53:18 +0200 | |
| changeset 23303 | 6091e530ff77 |
| parent 23203 | a5026e73cfcf |
| child 23473 | 997bca36d4fe |
| 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 |
ID: $Id$ |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
3 |
Author: Alexander Krauss, TU Muenchen |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
4 |
|
|
20363
f34c5dbe74d5
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20338
diff
changeset
|
5 |
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
|
6 |
Isar commands. |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
7 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
8 |
*) |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
9 |
|
|
20363
f34c5dbe74d5
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20338
diff
changeset
|
10 |
signature FUNDEF_PACKAGE = |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
11 |
sig |
|
20877
368b997ad67e
removed with_local_path -- LocalTheory.note admits qualified names;
wenzelm
parents:
20654
diff
changeset
|
12 |
val add_fundef : (string * string option * mixfix) list |
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
13 |
-> ((bstring * Attrib.src list) * string) list |
|
20877
368b997ad67e
removed with_local_path -- LocalTheory.note admits qualified names;
wenzelm
parents:
20654
diff
changeset
|
14 |
-> FundefCommon.fundef_config |
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
15 |
-> bool list |
|
20877
368b997ad67e
removed with_local_path -- LocalTheory.note admits qualified names;
wenzelm
parents:
20654
diff
changeset
|
16 |
-> local_theory |
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
17 |
-> Proof.state |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
18 |
|
|
20877
368b997ad67e
removed with_local_path -- LocalTheory.note admits qualified names;
wenzelm
parents:
20654
diff
changeset
|
19 |
val add_fundef_i: (string * typ option * mixfix) list |
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
20 |
-> ((bstring * Attrib.src list) * term) list |
| 22170 | 21 |
-> FundefCommon.fundef_config |
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
22 |
-> bool list |
|
20877
368b997ad67e
removed with_local_path -- LocalTheory.note admits qualified names;
wenzelm
parents:
20654
diff
changeset
|
23 |
-> local_theory |
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
24 |
-> Proof.state |
|
21211
5370cfbf3070
Preparations for making "lexicographic_order" part of "fun"
krauss
parents:
21051
diff
changeset
|
25 |
|
|
5370cfbf3070
Preparations for making "lexicographic_order" part of "fun"
krauss
parents:
21051
diff
changeset
|
26 |
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
|
27 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
28 |
val cong_add: attribute |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
29 |
val cong_del: attribute |
|
20363
f34c5dbe74d5
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20338
diff
changeset
|
30 |
|
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
31 |
val setup : theory -> theory |
|
21235
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
32 |
val setup_case_cong_hook : theory -> theory |
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
19617
diff
changeset
|
33 |
val get_congs : theory -> thm list |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
34 |
end |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
35 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
36 |
|
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
37 |
structure FundefPackage : FUNDEF_PACKAGE = |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
38 |
struct |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
39 |
|
|
21051
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
21000
diff
changeset
|
40 |
open FundefLib |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
41 |
open FundefCommon |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
42 |
|
| 21435 | 43 |
val note_theorem = LocalTheory.note Thm.theoremK |
44 |
||
| 22166 | 45 |
fun mk_defname fixes = fixes |> map (fst o fst) |> space_implode "_" |
46 |
||
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
47 |
fun add_simps fixes post sort label moreatts simps lthy = |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
48 |
let |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
49 |
val fnames = map (fst o fst) fixes |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21240
diff
changeset
|
50 |
|
| 22166 | 51 |
val (saved_spec_simps, lthy) = |
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
52 |
fold_map note_theorem (post simps) lthy |
|
22498
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
krauss
parents:
22325
diff
changeset
|
53 |
val saved_simps = flat (map snd saved_spec_simps) |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21240
diff
changeset
|
54 |
|
| 22166 | 55 |
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
|
56 |
|
| 22166 | 57 |
fun add_for_f fname simps = |
| 21435 | 58 |
note_theorem |
| 21658 | 59 |
((NameSpace.qualified fname label, Attrib.internal (K Simplifier.simp_add) :: moreatts), |
| 22166 | 60 |
simps) #> snd |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
61 |
in |
| 22166 | 62 |
(saved_simps, |
63 |
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
|
64 |
end |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
65 |
|
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
66 |
fun fundef_afterqed config fixes post defname cont sort_cont [[proof]] lthy = |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
67 |
let |
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
68 |
val FundefResult {fs, R, psimps, trsimps, subset_pinducts, simple_pinducts, termination, domintros, cases, ...} =
|
| 22166 | 69 |
cont (Goal.close_result proof) |
70 |
||
|
21391
a8809f46bd7f
replaced NameSpace.append by NameSpace.qualified, which handles empty names as expected;
wenzelm
parents:
21359
diff
changeset
|
71 |
val qualify = NameSpace.qualified defname |
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
72 |
val addsmps = add_simps fixes post sort_cont |
| 21602 | 73 |
|
74 |
val (((psimps', pinducts'), (_, [termination'])), lthy) = |
|
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21240
diff
changeset
|
75 |
lthy |
| 22170 | 76 |
|> addsmps "psimps" [] psimps |
77 |
||> fold_option (snd oo addsmps "simps" []) trsimps |
|
| 22166 | 78 |
||>> note_theorem ((qualify "pinduct", |
79 |
[Attrib.internal (K (InductAttrib.induct_set ""))]), simple_pinducts) |
|
80 |
||>> note_theorem ((qualify "termination", []), [termination]) |
|
81 |
||> (snd o note_theorem ((qualify "cases", []), [cases])) |
|
82 |
||> 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
|
83 |
|
| 22170 | 84 |
val cdata = FundefCtxData { add_simps=addsmps, psimps=psimps',
|
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
85 |
pinducts=snd pinducts', termination=termination', fs=fs, R=R, defname=defname } |
|
22668
8183ee579232
data declaration: removed obsolete target_morphism (still required for local data!?);
wenzelm
parents:
22635
diff
changeset
|
86 |
val cdata' = cdata |> morph_fundef_data (LocalTheory.target_morphism lthy); (* FIXME !? *) |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
87 |
in |
| 22623 | 88 |
lthy |
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
89 |
|> LocalTheory.declaration (fn phi => add_fundef_data (morph_fundef_data phi cdata)) (* save in target *) |
|
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
90 |
|> Context.proof_map (add_fundef_data cdata') (* also save in local context *) |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
91 |
end (* FIXME: Add cases for induct and cases thm *) |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
92 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
93 |
|
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
94 |
fun prepare_spec prep fixspec eqnss lthy = (* FIXME: obsolete when "read_specification" etc. is there *) |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
95 |
let |
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
96 |
val eqns = map (apsnd single) eqnss |
|
22498
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
krauss
parents:
22325
diff
changeset
|
97 |
|
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
98 |
val ((fixes, _), ctxt') = prep fixspec [] lthy |
|
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
99 |
fun prep_eqn e = the_single (snd (fst (prep [] [e] ctxt'))) |
| 23189 | 100 |
|
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
101 |
val spec = map prep_eqn eqns |
|
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
102 |
|> map (apsnd (map (fn t => fold_rev (mk_forall o Free) (frees_in_term ctxt' t) t))) (* Add quantifiers *) |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
103 |
in |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
104 |
((fixes, spec), ctxt') |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
105 |
end |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
106 |
|
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
107 |
fun gen_add_fundef prep fixspec eqnss config flags lthy = |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
108 |
let |
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
109 |
val ((fixes, spec), ctxt') = prepare_spec prep fixspec eqnss lthy |
|
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
110 |
val (eqs, post) = FundefCommon.get_preproc lthy config flags ctxt' fixes spec |
| 22166 | 111 |
|
112 |
val defname = mk_defname fixes |
|
113 |
||
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
114 |
val ((goalstate, cont, sort_cont), lthy) = |
|
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
115 |
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
|
116 |
|
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
117 |
val afterqed = fundef_afterqed config fixes post defname cont sort_cont |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
118 |
in |
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
119 |
lthy |
|
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
120 |
|> 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
|
121 |
|> 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
|
122 |
end |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
123 |
|
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
124 |
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
|
125 |
let |
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
126 |
val FundefCtxData { add_simps, psimps, pinducts, defname, ... } = data
|
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21240
diff
changeset
|
127 |
|
| 22166 | 128 |
val totality = Goal.close_result totality |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
129 |
|
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21240
diff
changeset
|
130 |
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
|
131 |
|
| 22166 | 132 |
val tsimps = map remove_domain_condition psimps |
133 |
val tinduct = map remove_domain_condition pinducts |
|
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
19617
diff
changeset
|
134 |
|
|
21511
16c62deb1adf
The function package declares the [code] attribute automatically again.
krauss
parents:
21491
diff
changeset
|
135 |
val has_guards = exists ((fn (Const ("Trueprop", _) $ _) => false | _ => true) o prop_of) tsimps
|
| 21658 | 136 |
val allatts = if has_guards then [] else [Attrib.internal (K (RecfunCodegen.add NONE))] |
| 21602 | 137 |
|
|
21511
16c62deb1adf
The function package declares the [code] attribute automatically again.
krauss
parents:
21491
diff
changeset
|
138 |
val qualify = NameSpace.qualified defname; |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
139 |
in |
|
21511
16c62deb1adf
The function package declares the [code] attribute automatically again.
krauss
parents:
21491
diff
changeset
|
140 |
lthy |
| 22166 | 141 |
|> add_simps "simps" allatts tsimps |> snd |
142 |
|> note_theorem ((qualify "induct", []), tinduct) |> snd |
|
|
20363
f34c5dbe74d5
global goals/qeds: after_qed operates on Proof.context (potentially local_theory);
wenzelm
parents:
20338
diff
changeset
|
143 |
end |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
144 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
145 |
|
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
146 |
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
|
147 |
let |
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
148 |
val data = the (case term_opt of |
|
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
149 |
SOME t => import_fundef_data (ProofContext.read_term lthy t) (Context.Proof lthy) |
|
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
150 |
| NONE => import_last_fundef (Context.Proof lthy)) |
|
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
151 |
handle Option.Option => raise 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
|
152 |
|
| 22166 | 153 |
val FundefCtxData {termination, R, ...} = data
|
| 22325 | 154 |
val domT = domain_type (fastype_of R) |
155 |
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
|
156 |
in |
|
20877
368b997ad67e
removed with_local_path -- LocalTheory.note admits qualified names;
wenzelm
parents:
20654
diff
changeset
|
157 |
lthy |
| 22325 | 158 |
|> ProofContext.note_thmss_i "" [(("", [ContextRules.rule_del]), [([allI], [])])] |> snd
|
159 |
|> ProofContext.note_thmss_i "" [(("", [ContextRules.intro_bang (SOME 1)]), [([allI], [])])] |> snd
|
|
| 21602 | 160 |
|> ProofContext.note_thmss_i "" |
| 22325 | 161 |
[(("termination", [ContextRules.intro_bang (SOME 0)]),
|
| 21602 | 162 |
[([Goal.norm_result termination], [])])] |> snd |
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
163 |
|> 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
|
164 |
end |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
165 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
166 |
|
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
167 |
val add_fundef = gen_add_fundef Specification.read_specification |
|
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
168 |
val add_fundef_i = gen_add_fundef Specification.cert_specification |
|
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 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
171 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
172 |
(* congruence rules *) |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
173 |
|
| 19617 | 174 |
val cong_add = Thm.declaration_attribute (map_fundef_congs o Drule.add_rule o safe_mk_meta_eq); |
175 |
val cong_del = Thm.declaration_attribute (map_fundef_congs o Drule.del_rule o safe_mk_meta_eq); |
|
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
176 |
|
|
21235
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
177 |
(* 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
|
178 |
|
|
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
179 |
|
| 21602 | 180 |
fun add_case_cong n thy = |
181 |
Context.theory_map (map_fundef_congs (Drule.add_rule |
|
|
21235
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
182 |
(DatatypePackage.get_datatype thy n |> the |
|
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
183 |
|> #case_cong |
| 21602 | 184 |
|> safe_mk_meta_eq))) |
|
21235
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
185 |
thy |
|
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
186 |
|
|
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
187 |
val case_cong_hook = fold add_case_cong |
|
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
188 |
|
| 21602 | 189 |
val setup_case_cong_hook = |
|
21235
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
190 |
DatatypeHooks.add case_cong_hook |
|
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
191 |
#> (fn thy => case_cong_hook (Symtab.keys (DatatypePackage.get_datatypes thy)) thy) |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
192 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
193 |
(* setup *) |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
194 |
|
| 21602 | 195 |
val setup = |
| 22846 | 196 |
Attrib.add_attributes |
197 |
[("fundef_cong", Attrib.add_del_args cong_add cong_del,
|
|
198 |
"declaration of congruence rule for function definitions")] |
|
199 |
#> setup_case_cong_hook |
|
200 |
#> FundefRelation.setup |
|
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
201 |
|
|
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
19617
diff
changeset
|
202 |
val get_congs = FundefCommon.get_fundef_congs o Context.Theory |
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
19617
diff
changeset
|
203 |
|
|
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
19617
diff
changeset
|
204 |
|
|
21235
674e2731b519
Added datatype hook to declare all case_congs as "fundef_cong" automatically.
krauss
parents:
21211
diff
changeset
|
205 |
|
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
206 |
(* outer syntax *) |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
207 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
208 |
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
|
209 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
210 |
val functionP = |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
211 |
OuterSyntax.command "function" "define general recursive functions" K.thy_goal |
|
22498
62cdd4b3e96b
made function syntax strict, requiring | to separate equations; cleanup
krauss
parents:
22325
diff
changeset
|
212 |
(fundef_parser default_config |
|
23203
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
213 |
>> (fn ((config, fixes), (flags, statements)) => |
|
a5026e73cfcf
"function (sequential)" and "fun" now handle incomplete patterns silently by adding "undefined" cases.
krauss
parents:
23189
diff
changeset
|
214 |
Toplevel.local_theory_to_proof (target_of config) (add_fundef fixes statements config flags) |
|
21211
5370cfbf3070
Preparations for making "lexicographic_order" part of "fun"
krauss
parents:
21051
diff
changeset
|
215 |
#> Toplevel.print)); |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
20363
diff
changeset
|
216 |
|
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
217 |
val terminationP = |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
218 |
OuterSyntax.command "termination" "prove termination of a recursive function" K.thy_goal |
|
22733
0b14bb35be90
definition lookup via terms, not names. Methods "relation" and "lexicographic_order"
krauss
parents:
22725
diff
changeset
|
219 |
(P.opt_target -- Scan.option P.term |
| 21000 | 220 |
>> (fn (target, name) => |
221 |
Toplevel.print o |
|
|
21211
5370cfbf3070
Preparations for making "lexicographic_order" part of "fun"
krauss
parents:
21051
diff
changeset
|
222 |
Toplevel.local_theory_to_proof target (setup_termination_proof name))); |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
223 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
224 |
val _ = OuterSyntax.add_parsers [functionP]; |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
225 |
val _ = OuterSyntax.add_parsers [terminationP]; |
|
20654
d80502f0d701
1. Function package accepts a parameter (default "some_term"), which specifies the functions
krauss
parents:
20638
diff
changeset
|
226 |
val _ = OuterSyntax.add_keywords ["sequential", "otherwise"]; |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
227 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
228 |
end; |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
229 |
|
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
230 |
|
| 19585 | 231 |
end |