223 |
223 |
224 fun gen_have_thmss get attrib f ((name, more_srcs), th_srcs) x = |
224 fun gen_have_thmss get attrib f ((name, more_srcs), th_srcs) x = |
225 f name (map (attrib x) more_srcs) |
225 f name (map (attrib x) more_srcs) |
226 (map (fn (s, srcs) => (get x s, map (attrib x) srcs)) th_srcs) x; |
226 (map (fn (s, srcs) => (get x s, map (attrib x) srcs)) th_srcs) x; |
227 |
227 |
228 fun global_have_thmss x = gen_have_thmss PureThy.get_thms Attrib.global_attribute x; |
228 fun global_have_thmss kind f (x as ((name, _), _)) thy = |
|
229 let val (thy', thms) = gen_have_thmss PureThy.get_thms Attrib.global_attribute f x thy in |
|
230 if kind <> "" then Context.setmp (Some thy') (Present.results kind name) thms else (); |
|
231 (thy', thms) |
|
232 end; |
229 |
233 |
230 fun local_have_thmss x = |
234 fun local_have_thmss x = |
231 gen_have_thmss (ProofContext.get_thms o Proof.context_of) |
235 gen_have_thmss (ProofContext.get_thms o Proof.context_of) |
232 (Attrib.local_attribute o Proof.theory_of) x; |
236 (Attrib.local_attribute o Proof.theory_of) x; |
233 |
237 |
235 f name more_atts (map (apfst single) th_atts); |
239 f name more_atts (map (apfst single) th_atts); |
236 |
240 |
237 fun have_lemss name atts = PureThy.have_thmss name (atts @ [Drule.tag_lemma]); |
241 fun have_lemss name atts = PureThy.have_thmss name (atts @ [Drule.tag_lemma]); |
238 |
242 |
239 |
243 |
240 fun apply_theorems th_srcs = global_have_thmss PureThy.have_thmss (("", []), th_srcs); |
244 fun apply_theorems th_srcs = global_have_thmss "" PureThy.have_thmss (("", []), th_srcs); |
241 fun apply_theorems_i th_srcs = gen_have_thmss_i PureThy.have_thmss (("", []), th_srcs); |
245 fun apply_theorems_i th_srcs = gen_have_thmss_i PureThy.have_thmss (("", []), th_srcs); |
242 val have_theorems = #1 oo (global_have_thmss PureThy.have_thmss o Comment.ignore); |
246 val have_theorems = #1 oo (global_have_thmss "theorems" PureThy.have_thmss o Comment.ignore); |
243 val have_theorems_i = #1 oo (gen_have_thmss_i PureThy.have_thmss o Comment.ignore); |
247 val have_theorems_i = #1 oo (gen_have_thmss_i PureThy.have_thmss o Comment.ignore); |
244 val have_lemmas = #1 oo (global_have_thmss have_lemss o Comment.ignore); |
248 val have_lemmas = #1 oo (global_have_thmss "lemmas" have_lemss o Comment.ignore); |
245 val have_lemmas_i = #1 oo (gen_have_thmss_i have_lemss o Comment.ignore); |
249 val have_lemmas_i = #1 oo (gen_have_thmss_i have_lemss o Comment.ignore); |
246 val have_facts = ProofHistory.apply o local_have_thmss (Proof.have_thmss []) o Comment.ignore; |
250 val have_facts = ProofHistory.apply o local_have_thmss (Proof.have_thmss []) o Comment.ignore; |
247 val have_facts_i = ProofHistory.apply o gen_have_thmss_i (Proof.have_thmss []) o Comment.ignore; |
251 val have_facts_i = ProofHistory.apply o gen_have_thmss_i (Proof.have_thmss []) o Comment.ignore; |
248 |
252 |
249 |
253 |
333 apsome Comment.ignore_interest o Comment.ignore_interest' o Comment.ignore; |
337 apsome Comment.ignore_interest o Comment.ignore_interest' o Comment.ignore; |
334 |
338 |
335 |
339 |
336 (* print result *) |
340 (* print result *) |
337 |
341 |
|
342 local |
|
343 |
338 fun pretty_result {kind, name, thm} = |
344 fun pretty_result {kind, name, thm} = |
339 Pretty.block [Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk, Proof.pretty_thm thm]; |
345 Pretty.block [Pretty.str (kind ^ (if name = "" then "" else " " ^ name ^ ":")), |
|
346 Pretty.fbrk, Proof.pretty_thm thm]; |
340 |
347 |
341 fun pretty_rule thm = |
348 fun pretty_rule thm = |
342 Pretty.block [Pretty.str "trying to solve goal by rule:", Pretty.fbrk, Proof.pretty_thm thm]; |
349 Pretty.block [Pretty.str "trying to solve goal by rule:", Pretty.fbrk, Proof.pretty_thm thm]; |
|
350 |
|
351 in |
343 |
352 |
344 val print_result = Pretty.writeln o pretty_result; |
353 val print_result = Pretty.writeln o pretty_result; |
345 |
354 |
346 fun cond_print_result_rule int = |
355 fun cond_print_result_rule int = |
347 if int then (print_result, Pretty.writeln o pretty_rule) |
356 if int then (print_result, Pretty.writeln o pretty_rule) |
348 else (K (), K ()); |
357 else (K (), K ()); |
349 |
358 |
350 fun proof'' f = Toplevel.proof' (f o cond_print_result_rule); |
359 fun proof'' f = Toplevel.proof' (f o cond_print_result_rule); |
|
360 |
|
361 end; |
351 |
362 |
352 |
363 |
353 (* local endings *) |
364 (* local endings *) |
354 |
365 |
355 val local_qed = |
366 val local_qed = |
371 |
382 |
372 fun global_result finish = Toplevel.proof_to_theory (fn prf => |
383 fun global_result finish = Toplevel.proof_to_theory (fn prf => |
373 let |
384 let |
374 val state = ProofHistory.current prf; |
385 val state = ProofHistory.current prf; |
375 val _ = if Proof.at_bottom state then () else raise Toplevel.UNDEF; |
386 val _ = if Proof.at_bottom state then () else raise Toplevel.UNDEF; |
376 val (thy, res) = finish state; |
387 val (thy, res as {kind, name, thm}) = finish state; |
377 in print_result res; thy end); |
388 in print_result res; Context.setmp (Some thy) (Present.result kind name) thm; thy end); |
378 |
389 |
379 val global_qed = global_result o Method.global_qed o apsome Comment.ignore_interest; |
390 val global_qed = global_result o Method.global_qed o apsome Comment.ignore_interest; |
380 val global_terminal_proof = global_result o Method.global_terminal_proof o ignore_interests; |
391 val global_terminal_proof = global_result o Method.global_terminal_proof o ignore_interests; |
381 val global_immediate_proof = global_result Method.global_immediate_proof; |
392 val global_immediate_proof = global_result Method.global_immediate_proof; |
382 val global_default_proof = global_result Method.global_default_proof; |
393 val global_default_proof = global_result Method.global_default_proof; |