author | wenzelm |
Thu, 30 Nov 2006 14:17:25 +0100 | |
changeset 21602 | cb13024d0e36 |
parent 21255 | 617fdb08abe9 |
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_proof.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 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
5 |
A package for general recursive function definitions. |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
6 |
Internal proofs. |
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 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
10 |
signature FUNDEF_PROOF = |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
11 |
sig |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
12 |
|
19922 | 13 |
val mk_partial_rules : theory -> FundefCommon.prep_result |
21237 | 14 |
-> thm -> FundefCommon.fundef_result |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
15 |
end |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
16 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
17 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
18 |
structure FundefProof : FUNDEF_PROOF = |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
19 |
struct |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
20 |
|
21051
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20523
diff
changeset
|
21 |
open FundefLib |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
22 |
open FundefCommon |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
23 |
open FundefAbbrev |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
24 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
25 |
(* Theory dependencies *) |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
26 |
val subsetD = thm "subsetD" |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
27 |
val split_apply = thm "Product_Type.split" |
21051
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20523
diff
changeset
|
28 |
val wf_induct_rule = thm "FunDef.wfP_induct_rule"; |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
29 |
val Pair_inject = thm "Product_Type.Pair_inject"; |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
30 |
|
21051
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20523
diff
changeset
|
31 |
val wf_in_rel = thm "FunDef.wf_in_rel"; |
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20523
diff
changeset
|
32 |
val in_rel_def = thm "FunDef.in_rel_def"; |
19564
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:
20523
diff
changeset
|
34 |
val acc_induct_rule = thm "FunDef.accP_induct_rule" |
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20523
diff
changeset
|
35 |
val acc_downward = thm "FunDef.accP_downward" |
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20523
diff
changeset
|
36 |
val accI = thm "FunDef.accPI" |
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20523
diff
changeset
|
37 |
|
c49467a9c1e1
Switched function package to use the new package for inductive predicates.
krauss
parents:
20523
diff
changeset
|
38 |
val acc_subset_induct = thm "FunDef.accP_subset_induct" |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
39 |
|
19922 | 40 |
val conjunctionD1 = thm "conjunctionD1" |
41 |
val conjunctionD2 = thm "conjunctionD2" |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
42 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
43 |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19930
diff
changeset
|
44 |
fun mk_psimp thy globals R f_iff graph_is_function clause valthm = |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
45 |
let |
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
46 |
val Globals {domT, z, ...} = globals |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
47 |
|
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
48 |
val ClauseInfo {qglr = (oqs, _, _, _), cdata = ClauseContext {qs, cqs, gs, lhs, rhs, ags, ...}, ...} = clause |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
49 |
val lhs_acc = cterm_of thy (Trueprop (mk_acc domT R $ lhs)) (* "acc R lhs" *) |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
50 |
val z_smaller = cterm_of thy (Trueprop (R $ z $ lhs)) (* "R z lhs" *) |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
51 |
in |
21237 | 52 |
((assume z_smaller) RS ((assume lhs_acc) RS acc_downward)) |
53 |
|> (fn it => it COMP graph_is_function) |
|
54 |
|> implies_intr z_smaller |
|
55 |
|> forall_intr (cterm_of thy z) |
|
56 |
|> (fn it => it COMP valthm) |
|
57 |
|> implies_intr lhs_acc |
|
58 |
|> asm_simplify (HOL_basic_ss addsimps [f_iff]) |
|
59 |
|> fold_rev (implies_intr o cprop_of) ags |
|
60 |
|> fold_rev forall_intr_rename (map fst oqs ~~ cqs) |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
61 |
end |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
62 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
63 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
64 |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19930
diff
changeset
|
65 |
fun mk_partial_induct_rule thy globals R complete_thm clauses = |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
66 |
let |
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
67 |
val Globals {domT, x, z, a, P, D, ...} = globals |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
68 |
val acc_R = mk_acc domT R |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
69 |
|
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
70 |
val x_D = assume (cterm_of thy (Trueprop (D $ x))) |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
71 |
val a_D = cterm_of thy (Trueprop (D $ a)) |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
72 |
|
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
73 |
val D_subset = cterm_of thy (mk_forall x (implies $ Trueprop (D $ x) $ Trueprop (acc_R $ x))) |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
74 |
|
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
75 |
val D_dcl = (* "!!x z. [| x: D; (z,x):R |] ==> z:D" *) |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
76 |
mk_forall x |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
77 |
(mk_forall z (Logic.mk_implies (Trueprop (D $ x), |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
78 |
Logic.mk_implies (Trueprop (R $ z $ x), |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
79 |
Trueprop (D $ z))))) |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
80 |
|> cterm_of thy |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
81 |
|
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
82 |
|
21237 | 83 |
(* Inductive Hypothesis: !!z. (z,x):R ==> P z *) |
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
84 |
val ihyp = all domT $ Abs ("z", domT, |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
85 |
implies $ Trueprop (R $ Bound 0 $ x) |
21237 | 86 |
$ Trueprop (P $ Bound 0)) |
87 |
|> cterm_of thy |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
88 |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
89 |
val aihyp = assume ihyp |
19922 | 90 |
|
21237 | 91 |
fun prove_case clause = |
92 |
let |
|
93 |
val ClauseInfo {cdata = ClauseContext {qs, cqs, ags, gs, lhs, rhs, case_hyp, ...}, RCs, |
|
94 |
qglr = (oqs, _, _, _), ...} = clause |
|
95 |
||
96 |
val replace_x_ss = HOL_basic_ss addsimps [case_hyp] |
|
97 |
val lhs_D = simplify replace_x_ss x_D (* lhs : D *) |
|
98 |
val sih = full_simplify replace_x_ss aihyp |
|
99 |
||
100 |
fun mk_Prec (RCInfo {llRI, RIvs, CCas, rcarg, ...}) = |
|
101 |
sih |> forall_elim (cterm_of thy rcarg) |
|
102 |
|> implies_elim_swp llRI |
|
103 |
|> fold_rev (implies_intr o cprop_of) CCas |
|
104 |
|> fold_rev (forall_intr o cterm_of thy o Free) RIvs |
|
105 |
||
106 |
val P_recs = map mk_Prec RCs (* [P rec1, P rec2, ... ] *) |
|
107 |
||
108 |
val step = Trueprop (P $ lhs) |
|
109 |
|> fold_rev (curry Logic.mk_implies o prop_of) P_recs |
|
110 |
|> fold_rev (curry Logic.mk_implies) gs |
|
111 |
|> curry Logic.mk_implies (Trueprop (D $ lhs)) |
|
112 |
|> fold_rev mk_forall_rename (map fst oqs ~~ qs) |
|
113 |
|> cterm_of thy |
|
114 |
||
115 |
val P_lhs = assume step |
|
116 |
|> fold forall_elim cqs |
|
117 |
|> implies_elim_swp lhs_D |
|
118 |
|> fold_rev implies_elim_swp ags |
|
119 |
|> fold implies_elim_swp P_recs |
|
120 |
||
121 |
val res = cterm_of thy (Trueprop (P $ x)) |
|
122 |
|> Simplifier.rewrite replace_x_ss |
|
123 |
|> symmetric (* P lhs == P x *) |
|
124 |
|> (fn eql => equal_elim eql P_lhs) (* "P x" *) |
|
125 |
|> implies_intr (cprop_of case_hyp) |
|
126 |
|> fold_rev (implies_intr o cprop_of) ags |
|
127 |
|> fold_rev forall_intr cqs |
|
128 |
in |
|
129 |
(res, step) |
|
130 |
end |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
131 |
|
21237 | 132 |
val (cases, steps) = split_list (map prove_case clauses) |
19770
be5c23ebe1eb
HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents:
19583
diff
changeset
|
133 |
|
21237 | 134 |
val istep = complete_thm |
135 |
|> forall_elim_vars 0 |
|
136 |
|> fold (curry op COMP) cases (* P x *) |
|
137 |
|> implies_intr ihyp |
|
138 |
|> implies_intr (cprop_of x_D) |
|
139 |
|> forall_intr (cterm_of thy x) |
|
140 |
||
141 |
val subset_induct_rule = |
|
142 |
acc_subset_induct |
|
143 |
|> (curry op COMP) (assume D_subset) |
|
144 |
|> (curry op COMP) (assume D_dcl) |
|
145 |
|> (curry op COMP) (assume a_D) |
|
146 |
|> (curry op COMP) istep |
|
147 |
|> fold_rev implies_intr steps |
|
148 |
|> implies_intr a_D |
|
149 |
|> implies_intr D_dcl |
|
150 |
|> implies_intr D_subset |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
151 |
|
21237 | 152 |
val subset_induct_all = fold_rev (forall_intr o cterm_of thy) [P, a, D] subset_induct_rule |
153 |
||
154 |
val simple_induct_rule = |
|
155 |
subset_induct_rule |
|
156 |
|> forall_intr (cterm_of thy D) |
|
157 |
|> forall_elim (cterm_of thy acc_R) |
|
158 |
|> assume_tac 1 |> Seq.hd |
|
159 |
|> (curry op COMP) (acc_downward |
|
160 |
|> (instantiate' [SOME (ctyp_of thy domT)] |
|
161 |
(map (SOME o cterm_of thy) [R, x, z])) |
|
162 |
|> forall_intr (cterm_of thy z) |
|
163 |
|> forall_intr (cterm_of thy x)) |
|
164 |
|> forall_intr (cterm_of thy a) |
|
165 |
|> forall_intr (cterm_of thy P) |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
166 |
in |
21237 | 167 |
(subset_induct_all, simple_induct_rule) |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
168 |
end |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
169 |
|
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 |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19930
diff
changeset
|
172 |
(* Does this work with Guards??? *) |
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19930
diff
changeset
|
173 |
fun mk_domain_intro thy globals R R_cases clause = |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
174 |
let |
21237 | 175 |
val Globals {z, domT, ...} = globals |
176 |
val ClauseInfo {cdata = ClauseContext {qs, gs, lhs, rhs, cqs, ...}, |
|
177 |
qglr = (oqs, _, _, _), ...} = clause |
|
178 |
val goal = Trueprop (mk_acc domT R $ lhs) |
|
179 |
|> fold_rev (curry Logic.mk_implies) gs |
|
180 |
|> cterm_of thy |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
181 |
in |
21237 | 182 |
Goal.init goal |
183 |
|> (SINGLE (resolve_tac [accI] 1)) |> the |
|
184 |
|> (SINGLE (eresolve_tac [forall_elim_vars 0 R_cases] 1)) |> the |
|
185 |
|> (SINGLE (CLASIMPSET auto_tac)) |> the |
|
186 |
|> Goal.conclude |
|
187 |
|> fold_rev forall_intr_rename (map fst oqs ~~ cqs) |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
188 |
end |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
189 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
190 |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
191 |
fun maybe_mk_domain_intro thy = |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
192 |
if !FundefCommon.domintros then mk_domain_intro thy |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
193 |
else K (K (K (K refl))) |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
194 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
195 |
|
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19930
diff
changeset
|
196 |
fun mk_nest_term_case thy globals R' ihyp clause = |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
197 |
let |
21237 | 198 |
val Globals {x, z, ...} = globals |
199 |
val ClauseInfo {cdata = ClauseContext {qs,cqs,ags,lhs,rhs,case_hyp,...},tree, |
|
200 |
qglr=(oqs, _, _, _), ...} = clause |
|
201 |
||
202 |
val ih_case = full_simplify (HOL_basic_ss addsimps [case_hyp]) ihyp |
|
203 |
||
204 |
fun step (fixes, assumes) (_ $ arg) u (sub,(hyps,thms)) = |
|
205 |
let |
|
206 |
val used = map (fn ((f,a),thm) => FundefCtxTree.export_thm thy (f, map prop_of a) thm) (u @ sub) |
|
207 |
||
208 |
val hyp = Trueprop (R' $ arg $ lhs) |
|
209 |
|> fold_rev (curry Logic.mk_implies o prop_of) used |
|
210 |
|> FundefCtxTree.export_term (fixes, map prop_of assumes) |
|
211 |
|> fold_rev (curry Logic.mk_implies o prop_of) ags |
|
212 |
|> fold_rev mk_forall_rename (map fst oqs ~~ qs) |
|
213 |
|> cterm_of thy |
|
214 |
||
215 |
val thm = assume hyp |
|
216 |
|> fold forall_elim cqs |
|
217 |
|> fold implies_elim_swp ags |
|
218 |
|> FundefCtxTree.import_thm thy (fixes, assumes) (* "(arg, lhs) : R'" *) |
|
219 |
|> fold implies_elim_swp used |
|
220 |
||
221 |
val acc = thm COMP ih_case |
|
222 |
||
223 |
val z_eq_arg = cterm_of thy (Trueprop (HOLogic.mk_eq (z, arg))) |
|
224 |
||
225 |
val arg_eq_z = (assume z_eq_arg) RS sym |
|
226 |
||
227 |
val z_acc = simplify (HOL_basic_ss addsimps [arg_eq_z]) acc (* fragile, slow... *) |
|
228 |
|> implies_intr (cprop_of case_hyp) |
|
229 |
|> implies_intr z_eq_arg |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
230 |
|
21237 | 231 |
val z_eq_arg = assume (cterm_of thy (Trueprop (mk_eq (z, arg)))) |
232 |
val x_eq_lhs = assume (cterm_of thy (Trueprop (mk_eq (x, lhs)))) |
|
233 |
||
234 |
val ethm = (z_acc OF [z_eq_arg, x_eq_lhs]) |
|
235 |
|> FundefCtxTree.export_thm thy (fixes, |
|
236 |
prop_of z_eq_arg :: prop_of x_eq_lhs :: map prop_of (ags @ assumes)) |
|
237 |
|> fold_rev forall_intr_rename (map fst oqs ~~ cqs) |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
238 |
|
21237 | 239 |
val sub' = sub @ [(([],[]), acc)] |
240 |
in |
|
241 |
(sub', (hyp :: hyps, ethm :: thms)) |
|
242 |
end |
|
243 |
| step _ _ _ _ = raise Match |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
244 |
in |
21237 | 245 |
FundefCtxTree.traverse_tree step tree |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
246 |
end |
21237 | 247 |
|
248 |
||
20523
36a59e5d0039
Major update to function package, including new syntax and the (only theoretical)
krauss
parents:
19930
diff
changeset
|
249 |
fun mk_nest_term_rule thy globals R R_cases clauses = |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
250 |
let |
21237 | 251 |
val Globals { domT, x, z, ... } = globals |
252 |
val acc_R = mk_acc domT R |
|
253 |
||
254 |
val R' = Free ("R", fastype_of R) |
|
255 |
||
256 |
val Rrel = Free ("R", mk_relT (domT, domT)) |
|
257 |
val inrel_R = Const ("FunDef.in_rel", mk_relT (domT, domT) --> fastype_of R) $ Rrel |
|
258 |
||
259 |
val wfR' = cterm_of thy (Trueprop (Const ("FunDef.wfP", (domT --> domT --> boolT) --> boolT) $ R')) (* "wf R'" *) |
|
260 |
||
261 |
(* Inductive Hypothesis: !!z. (z,x):R' ==> z : acc R *) |
|
262 |
val ihyp = all domT $ Abs ("z", domT, |
|
263 |
implies $ Trueprop (R' $ Bound 0 $ x) |
|
264 |
$ Trueprop (acc_R $ Bound 0)) |
|
265 |
|> cterm_of thy |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
266 |
|
21237 | 267 |
val ihyp_a = assume ihyp |> forall_elim_vars 0 |
268 |
||
269 |
val R_z_x = cterm_of thy (Trueprop (R $ z $ x)) |
|
270 |
||
271 |
val (hyps,cases) = fold (mk_nest_term_case thy globals R' ihyp_a) clauses ([],[]) |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
272 |
in |
21237 | 273 |
R_cases |
274 |
|> forall_elim (cterm_of thy z) |
|
275 |
|> forall_elim (cterm_of thy x) |
|
276 |
|> forall_elim (cterm_of thy (acc_R $ z)) |
|
277 |
|> curry op COMP (assume R_z_x) |
|
278 |
|> fold_rev (curry op COMP) cases |
|
279 |
|> implies_intr R_z_x |
|
280 |
|> forall_intr (cterm_of thy z) |
|
281 |
|> (fn it => it COMP accI) |
|
282 |
|> implies_intr ihyp |
|
283 |
|> forall_intr (cterm_of thy x) |
|
284 |
|> (fn it => Drule.compose_single(it,2,wf_induct_rule)) |
|
285 |
|> curry op RS (assume wfR') |
|
286 |
|> fold implies_intr hyps |
|
287 |
|> implies_intr wfR' |
|
288 |
|> forall_intr (cterm_of thy R') |
|
289 |
|> forall_elim (cterm_of thy (inrel_R)) |
|
290 |
|> curry op RS wf_in_rel |
|
291 |
|> full_simplify (HOL_basic_ss addsimps [in_rel_def]) |
|
292 |
|> forall_intr (cterm_of thy Rrel) |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
293 |
end |
21237 | 294 |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
295 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
296 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
297 |
|
19922 | 298 |
fun mk_partial_rules thy data provedgoal = |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
299 |
let |
21237 | 300 |
val Prep {globals, G, f, R, clauses, values, R_cases, ex1_iff, ...} = data |
301 |
||
21602 | 302 |
val provedgoal = PROFILE "Closing result" Goal.close_result provedgoal |
21237 | 303 |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
304 |
val graph_is_function = PROFILE "Getting function theorem" (fn x => (x COMP conjunctionD1) |> forall_elim_vars 0) provedgoal |
21237 | 305 |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
306 |
val complete_thm = PROFILE "Getting cases" (curry op COMP provedgoal) conjunctionD2 |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
307 |
|
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
308 |
val f_iff = PROFILE "Making f_iff" (curry op RS graph_is_function) ex1_iff |
21237 | 309 |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
310 |
val psimps = PROFILE "Proving simplification rules" (map2 (mk_psimp thy globals R f_iff graph_is_function)) clauses values |
21237 | 311 |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
312 |
val (subset_pinduct, simple_pinduct) = PROFILE "Proving partial induction rule" |
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
313 |
(mk_partial_induct_rule thy globals R complete_thm) clauses |
21237 | 314 |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
315 |
val total_intro = PROFILE "Proving nested termination rule" (mk_nest_term_rule thy globals R R_cases) clauses |
21237 | 316 |
|
21255
617fdb08abe9
added profiling code, improved handling of proof terms, generation of domain
krauss
parents:
21237
diff
changeset
|
317 |
val dom_intros = PROFILE "Proving domain introduction rules" (map (maybe_mk_domain_intro thy globals R R_cases)) clauses |
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
318 |
in |
21237 | 319 |
FundefResult {f=f, G=G, R=R, completeness=complete_thm, |
320 |
psimps=psimps, subset_pinduct=subset_pinduct, simple_pinduct=simple_pinduct, total_intro=total_intro, |
|
321 |
dom_intros=dom_intros} |
|
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
322 |
end |
21237 | 323 |
|
324 |
||
19564
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
325 |
end |
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
326 |
|
d3e2f532459a
First usable version of the new function definition package (HOL/function_packake/...).
krauss
parents:
diff
changeset
|
327 |