139 (rewrite (map (R.ASSUME o tych) cntxt) (R.SPEC_ALL th))) |
147 (rewrite (map (R.ASSUME o tych) cntxt) (R.SPEC_ALL th))) |
140 end |
148 end |
141 val gen_all = S.gen_all |
149 val gen_all = S.gen_all |
142 in |
150 in |
143 fun proof_stage ss theory {f, R, rules, full_pats_TCs, TCs} = |
151 fun proof_stage ss theory {f, R, rules, full_pats_TCs, TCs} = |
144 let val dummy = writeln "Proving induction theorem.. " |
152 let val dummy = message "Proving induction theorem ..." |
145 val ind = Prim.mk_induction theory |
153 val ind = Prim.mk_induction theory |
146 {fconst=f, R=R, SV=[], pat_TCs_list=full_pats_TCs} |
154 {fconst=f, R=R, SV=[], pat_TCs_list=full_pats_TCs} |
147 val dummy = writeln "Proved induction theorem.\nPostprocessing.. " |
155 val dummy = (message "Proved induction theorem."; message "Postprocessing ..."); |
148 val {rules, induction, nested_tcs} = |
156 val {rules, induction, nested_tcs} = |
149 std_postprocessor ss theory {rules=rules, induction=ind, TCs=TCs} |
157 std_postprocessor ss theory {rules=rules, induction=ind, TCs=TCs} |
150 in |
158 in |
151 case nested_tcs |
159 case nested_tcs |
152 of [] => (writeln "Postprocessing done."; |
160 of [] => (message "Postprocessing done."; |
153 {induction=induction, rules=rules,tcs=[]}) |
161 {induction=induction, rules=rules,tcs=[]}) |
154 | L => let val dummy = writeln "Simplifying nested TCs.. " |
162 | L => let val dummy = message "Simplifying nested TCs ..." |
155 val (solved,simplified,stubborn) = |
163 val (solved,simplified,stubborn) = |
156 U.itlist (fn th => fn (So,Si,St) => |
164 U.itlist (fn th => fn (So,Si,St) => |
157 if (id_thm th) then (So, Si, th::St) else |
165 if (id_thm th) then (So, Si, th::St) else |
158 if (solved th) then (th::So, Si, St) |
166 if (solved th) then (th::So, Si, St) |
159 else (So, th::Si, St)) nested_tcs ([],[],[]) |
167 else (So, th::Si, St)) nested_tcs ([],[],[]) |
160 val simplified' = map join_assums simplified |
168 val simplified' = map join_assums simplified |
161 val rewr = full_simplify (ss addsimps (solved @ simplified')); |
169 val rewr = full_simplify (ss addsimps (solved @ simplified')); |
162 val induction' = rewr induction |
170 val induction' = rewr induction |
163 and rules' = rewr rules |
171 and rules' = rewr rules |
164 val dummy = writeln "Postprocessing done." |
172 val dummy = message "Postprocessing done." |
165 in |
173 in |
166 {induction = induction', |
174 {induction = induction', |
167 rules = rules', |
175 rules = rules', |
168 tcs = map (gen_all o S.rhs o #2 o S.strip_forall o concl) |
176 tcs = map (gen_all o S.rhs o #2 o S.strip_forall o concl) |
169 (simplified@stubborn)} |
177 (simplified@stubborn)} |
236 fun function_i thy fid congs eqs = |
244 fun function_i thy fid congs eqs = |
237 let val dum = Theory.requires thy "WF_Rel" "recursive function definitions" |
245 let val dum = Theory.requires thy "WF_Rel" "recursive function definitions" |
238 val {rules,R,theory,full_pats_TCs,SV,...} = |
246 val {rules,R,theory,full_pats_TCs,SV,...} = |
239 Prim.lazyR_def thy fid congs eqs |
247 Prim.lazyR_def thy fid congs eqs |
240 val f = func_of_cond_eqn (concl(R.CONJUNCT1 rules handle _ => rules)) |
248 val f = func_of_cond_eqn (concl(R.CONJUNCT1 rules handle _ => rules)) |
241 val dummy = writeln "Definition made.\nProving induction theorem.. " |
249 val dummy = (message "Definition made."; message "Proving induction theorem ..."); |
242 val induction = Prim.mk_induction theory |
250 val induction = Prim.mk_induction theory |
243 {fconst=f, R=R, SV=SV, pat_TCs_list=full_pats_TCs} |
251 {fconst=f, R=R, SV=SV, pat_TCs_list=full_pats_TCs} |
244 val dummy = writeln "Induction theorem proved." |
252 val dummy = message "Induction theorem proved." |
245 in (theory, |
253 in (theory, |
246 (*return the conjoined induction rule and recursion equations, |
254 (*return the conjoined induction rule and recursion equations, |
247 with assumptions remaining to discharge*) |
255 with assumptions remaining to discharge*) |
248 standard (induction RS (rules RS conjI))) |
256 standard (induction RS (rules RS conjI))) |
249 end |
257 end |
250 |
258 |
251 fun function thy fid congs seqs = |
259 fun function thy fid congs seqs = |
252 let val _ = writeln ("Deferred recursive function " ^ fid) |
260 let val _ = message ("Deferred recursive function " ^ fid) |
253 fun read thy = readtm (Theory.sign_of thy) (TVar(("DUMMY",0),[])) |
261 fun read thy = readtm (Theory.sign_of thy) (TVar(("DUMMY",0),[])) |
254 in function_i thy fid congs (map (read thy) seqs) end |
262 in function_i thy fid congs (map (read thy) seqs) end |
255 handle Utils.ERR {mesg,...} => error mesg; |
263 handle Utils.ERR {mesg,...} => error mesg; |
256 |
264 |
257 end; |
265 end; |