1 (* Title: Pure/Isar/proof.ML |
1 (* Title: Pure/Isar/proof.ML |
2 ID: $Id$ |
2 ID: $Id$ |
3 Author: Markus Wenzel, TU Muenchen |
3 Author: Markus Wenzel, TU Muenchen |
4 |
4 |
5 Proof states and methods. |
5 Proof states and methods. |
6 |
|
7 TODO: |
|
8 - assume: improve schematic Vars handling (!?); |
|
9 - warn_vars; |
|
10 - bind: check rhs (extra (T)Vars etc.) (How to handle these anyway?); |
|
11 - prep_result: avoid duplicate asms; |
|
12 - prep_result error: use error channel (!); |
|
13 - check_finished: trace results (!?); |
|
14 - next_block: fetch_facts (!?); |
|
15 *) |
6 *) |
16 |
7 |
17 signature PROOF = |
8 signature PROOF = |
18 sig |
9 sig |
19 type context |
10 type context |
56 val have_i: string -> context attribute list -> term * term list -> state -> state |
47 val have_i: string -> context attribute list -> term * term list -> state -> state |
57 val begin_block: state -> state |
48 val begin_block: state -> state |
58 val next_block: state -> state |
49 val next_block: state -> state |
59 val end_block: state -> state |
50 val end_block: state -> state |
60 val at_bottom: state -> bool |
51 val at_bottom: state -> bool |
61 val local_qed: (state -> state Seq.seq) -> bool -> state -> state Seq.seq |
52 val local_qed: (state -> state Seq.seq) -> ({kind: string, name: string, thm: thm} -> unit) |
|
53 -> state -> state Seq.seq |
62 val global_qed: (state -> state Seq.seq) -> bstring option |
54 val global_qed: (state -> state Seq.seq) -> bstring option |
63 -> theory attribute list option -> state -> theory * {kind: string, name: string, thm: thm} |
55 -> theory attribute list option -> state -> theory * {kind: string, name: string, thm: thm} |
64 end; |
56 end; |
65 |
57 |
66 signature PROOF_PRIVATE = |
58 signature PROOF_PRIVATE = |
239 val enter_backward = put_mode Backward; |
231 val enter_backward = put_mode Backward; |
240 |
232 |
241 fun assert_mode pred state = |
233 fun assert_mode pred state = |
242 let val mode = get_mode state in |
234 let val mode = get_mode state in |
243 if pred mode then state |
235 if pred mode then state |
244 else raise STATE ("Illegal application of command in " ^ mode_name mode ^ " mode", state) |
236 else raise STATE ("Illegal application of proof command in " ^ mode_name mode ^ " mode", state) |
245 end; |
237 end; |
246 |
238 |
247 fun is_chain state = get_mode state = ForwardChain; |
239 fun is_chain state = get_mode state = ForwardChain; |
248 val assert_forward = assert_mode (equal Forward); |
240 val assert_forward = assert_mode (equal Forward); |
249 val assert_forward_or_chain = assert_mode (equal Forward orf equal ForwardChain); |
241 val assert_forward_or_chain = assert_mode (equal Forward orf equal ForwardChain); |
365 |
357 |
366 val thm = |
358 val thm = |
367 raw_thm RS Drule.rev_triv_goal |
359 raw_thm RS Drule.rev_triv_goal |
368 |> implies_elim_hyps |
360 |> implies_elim_hyps |
369 |> Drule.implies_intr_list asms |
361 |> Drule.implies_intr_list asms |
370 |> varify_frees (ProofContext.fixed_names ctxt); |
362 |> varify_frees (ProofContext.fixed_names ctxt) |
|
363 |> Thm.varifyT; |
371 |
364 |
372 val {hyps, prop, sign, ...} = Thm.rep_thm thm; |
365 val {hyps, prop, sign, ...} = Thm.rep_thm thm; |
373 val tsig = Sign.tsig_of sign; |
366 val tsig = Sign.tsig_of sign; |
374 in |
367 in |
375 (* FIXME |
368 (* FIXME |
606 |> fetch_facts state; |
599 |> fetch_facts state; |
607 |
600 |
608 |
601 |
609 (* local_qed *) |
602 (* local_qed *) |
610 |
603 |
611 fun finish_local state = |
604 fun finish_local print_result state = |
612 let |
605 let |
613 val ((kind, name, asms, t), (_, raw_thm)) = current_goal state; |
606 val ((kind, name, asms, t), (_, raw_thm)) = current_goal state; |
614 val result = prep_result state asms t raw_thm; |
607 val result = prep_result state asms t raw_thm; |
615 val (atts, opt_solve) = |
608 val (atts, opt_solve) = |
616 (case kind of |
609 (case kind of |
617 Goal atts => (atts, solve_goal result) |
610 Goal atts => (atts, solve_goal result) |
618 | Aux atts => (atts, Seq.single) |
611 | Aux atts => (atts, Seq.single) |
619 | _ => raise STATE ("No local goal!", state)); |
612 | _ => raise STATE ("No local goal!", state)); |
620 in |
613 in |
|
614 print_result {kind = kind_name kind, name = name, thm = result}; |
621 state |
615 state |
622 |> close_block |
616 |> close_block |
623 |> have_thmss name atts [Thm.no_attributes [result]] |
617 |> have_thmss name atts [Thm.no_attributes [result]] |
624 |> opt_solve |
618 |> opt_solve |
625 end; |
619 end; |
626 |
620 |
627 fun local_qed finalize int state = (* FIXME handle int *) |
621 fun local_qed finalize print_result state = |
628 state |
622 state |
629 |> finish_proof false finalize |
623 |> finish_proof false finalize |
630 |> (Seq.flat o Seq.map finish_local); |
624 |> (Seq.flat o Seq.map (finish_local print_result)); |
631 |
625 |
632 |
626 |
633 (* global_qed *) |
627 (* global_qed *) |
634 |
628 |
635 fun finish_global alt_name alt_atts state = |
629 fun finish_global alt_name alt_atts state = |