20 val map_context: (context -> context) -> state -> state |
20 val map_context: (context -> context) -> state -> state |
21 val warn_extra_tfrees: state -> state -> state |
21 val warn_extra_tfrees: state -> state -> state |
22 val put_thms: string * thm list option -> state -> state |
22 val put_thms: string * thm list option -> state -> state |
23 val the_facts: state -> thm list |
23 val the_facts: state -> thm list |
24 val the_fact: state -> thm |
24 val the_fact: state -> thm |
|
25 val put_facts: thm list option -> state -> state |
25 val assert_forward: state -> state |
26 val assert_forward: state -> state |
26 val assert_chain: state -> state |
27 val assert_chain: state -> state |
27 val assert_forward_or_chain: state -> state |
28 val assert_forward_or_chain: state -> state |
28 val assert_backward: state -> state |
29 val assert_backward: state -> state |
29 val assert_no_chain: state -> state |
30 val assert_no_chain: state -> state |
81 val defer: int option -> state -> state Seq.seq |
82 val defer: int option -> state -> state Seq.seq |
82 val prefer: int -> state -> state Seq.seq |
83 val prefer: int -> state -> state Seq.seq |
83 val apply: Method.text -> state -> state Seq.seq |
84 val apply: Method.text -> state -> state Seq.seq |
84 val apply_end: Method.text -> state -> state Seq.seq |
85 val apply_end: Method.text -> state -> state Seq.seq |
85 val goal_names: string option -> string -> string list -> string |
86 val goal_names: string option -> string -> string list -> string |
86 val generic_goal: |
|
87 (context * 'a -> context * (term list list * (context -> context))) -> |
|
88 string -> |
|
89 (context * thm list -> thm list list -> state -> state Seq.seq) * |
|
90 (context * thm list -> thm list list -> theory -> theory) -> |
|
91 'a -> state -> state |
|
92 val local_goal: (context -> ((string * string) * (string * thm list) list) -> unit) -> |
87 val local_goal: (context -> ((string * string) * (string * thm list) list) -> unit) -> |
93 (theory -> 'a -> context attribute) -> |
88 (theory -> 'a -> context attribute) -> |
94 (context * 'b list -> context * (term list list * (context -> context))) -> |
89 (context * 'b list -> context * (term list list * (context -> context))) -> |
95 string -> (context * thm list -> thm list list -> state -> state Seq.seq) -> |
90 string -> (context * thm list -> thm list list -> state -> state Seq.seq) -> |
96 ((string * 'a list) * 'b) list -> state -> state |
91 ((string * 'a list) * 'b) list -> state -> state |
97 val local_qed: Method.text option * bool -> state -> state Seq.seq |
92 val local_qed: Method.text option * bool -> state -> state Seq.seq |
98 val auto_fix: context * (term list list * 'a) -> |
|
99 context * (term list list * 'a) |
|
100 val global_goal: (context -> (string * string) * (string * thm list) list -> unit) -> |
93 val global_goal: (context -> (string * string) * (string * thm list) list -> unit) -> |
101 (theory -> 'a -> theory attribute) -> |
94 (theory -> 'a -> theory attribute) -> |
102 (context * 'b list -> context * (term list list * (context -> context))) -> |
95 (context * 'b list -> context * (term list list * (context -> context))) -> |
103 string -> (context * thm list -> thm list list -> theory -> theory) -> string option -> |
96 string -> (context * thm list -> thm list list -> theory -> theory) -> string option -> |
104 string * 'a list -> ((string * 'a list) * 'b) list -> context -> state |
97 string * 'a list -> ((string * 'a list) * 'b) list -> context -> state |
105 val global_qed: Method.text option * bool -> state -> theory * context |
98 val global_qed: Method.text option * bool -> state -> theory * context |
106 val local_terminal_proof: Method.text * Method.text option -> state -> state Seq.seq |
99 val local_terminal_proof: Method.text * Method.text option -> state -> state Seq.seq |
107 val local_default_proof: state -> state Seq.seq |
100 val local_default_proof: state -> state Seq.seq |
108 val local_immediate_proof: state -> state Seq.seq |
101 val local_immediate_proof: state -> state Seq.seq |
109 val local_done_proof: state -> state Seq.seq |
102 val local_done_proof: state -> state Seq.seq |
468 err (Pretty.string_of (Pretty.chunks |
461 err (Pretty.string_of (Pretty.chunks |
469 (pretty_goals_local ctxt "" (true, ! show_main_goal) (! Display.goals_limit) goal @ |
462 (pretty_goals_local ctxt "" (true, ! show_main_goal) (! Display.goals_limit) goal @ |
470 [Pretty.str (string_of_int ngoals ^ " unsolved goal(s)!")])))); |
463 [Pretty.str (string_of_int ngoals ^ " unsolved goal(s)!")])))); |
471 |
464 |
472 val {hyps, thy, ...} = Thm.rep_thm goal; |
465 val {hyps, thy, ...} = Thm.rep_thm goal; |
473 val casms = List.concat (map #1 (ProofContext.assumptions_of ctxt)); |
466 val bad_hyps = fold (remove (op aconv)) (ProofContext.assms_of ctxt) hyps; |
474 val bad_hyps = fold (remove (fn (asm, hyp) => Thm.term_of asm aconv hyp)) casms hyps; |
|
475 |
467 |
476 val th = goal RS Drule.rev_triv_goal; |
468 val th = goal RS Drule.rev_triv_goal; |
477 val ths = Drule.conj_elim_precise (length props) th |
469 val ths = Drule.conj_elim_precise (length props) th |
478 handle THM _ => err "Main goal structure corrupted"; |
470 handle THM _ => err "Main goal structure corrupted"; |
479 in |
471 in |
743 val (names_attss, propp) = split_list (Attrib.map_specs prep_att stmt); |
735 val (names_attss, propp) = split_list (Attrib.map_specs prep_att stmt); |
744 val (names, attss) = split_list names_attss; |
736 val (names, attss) = split_list names_attss; |
745 in ((names, attss), propp) end; |
737 in ((names, attss), propp) end; |
746 |
738 |
747 fun goal_names target name names = |
739 fun goal_names target name names = |
748 (case target of NONE => "" | SOME loc => " (in " ^ loc ^ ")") ^ |
740 (case target of NONE => "" | SOME "" => "" | SOME loc => " (in " ^ loc ^ ")") ^ |
749 (if name = "" then "" else " " ^ name) ^ |
741 (if name = "" then "" else " " ^ name) ^ |
750 (case filter_out (equal "") names of [] => "" |
742 (case filter_out (equal "") names of [] => "" |
751 | nms => " " ^ enclose "(" ")" (space_implode " and " (Library.take (7, nms) @ |
743 | nms => " " ^ enclose "(" ")" (space_implode " and " (Library.take (7, nms) @ |
752 (if length nms > 7 then ["..."] else [])))); |
744 (if length nms > 7 then ["..."] else [])))); |
753 |
745 |
792 |> K chaining ? (`the_facts #-> using_facts) |
784 |> K chaining ? (`the_facts #-> using_facts) |
793 |> put_facts NONE |
785 |> put_facts NONE |
794 |> open_block |
786 |> open_block |
795 |> put_goal NONE |
787 |> put_goal NONE |
796 |> enter_backward |
788 |> enter_backward |
|
789 |> K (null props) ? (refine (Method.Basic Method.assumption) #> Seq.hd) |
797 end; |
790 end; |
798 |
791 |
799 fun generic_qed state = |
792 fun generic_qed state = |
800 let |
793 let |
801 val (goal_ctxt, {statement = (_, stmt), using, goal, after_qed}) = current_goal state; |
794 val (goal_ctxt, {statement = (_, stmt), using, goal, after_qed}) = current_goal state; |
838 Seq.lifts (#1 after_qed raw_results) results)); |
831 Seq.lifts (#1 after_qed raw_results) results)); |
839 |
832 |
840 |
833 |
841 (* global goals *) |
834 (* global goals *) |
842 |
835 |
843 fun auto_fix (ctxt, (propss, after_ctxt)) = |
|
844 (ctxt |> ProofContext.fix_frees (List.concat propss), (propss, after_ctxt)); |
|
845 |
|
846 fun global_goal print_results prep_att prepp |
836 fun global_goal print_results prep_att prepp |
847 kind after_qed target (name, raw_atts) stmt ctxt = |
837 kind after_qed target (name, raw_atts) stmt ctxt = |
848 let |
838 let |
849 val thy = ProofContext.theory_of ctxt; |
839 val thy = ProofContext.theory_of ctxt; |
850 val thy_ctxt = ProofContext.init thy; |
840 val thy_ctxt = ProofContext.init thy; |
851 |
841 |
852 val atts = map (prep_att thy) raw_atts; |
842 val atts = map (prep_att thy) raw_atts; |
853 val ((names, attss), propp) = prep_names (prep_att thy) stmt; |
843 val ((names, attss), propp) = prep_names (prep_att thy) stmt; |
854 |
844 |
855 fun after_qed' raw_results results = |
845 fun store_results prfx res = |
856 (map o map) (ProofContext.export_standard ctxt thy_ctxt |
846 K (prfx <> "") ? (Sign.add_path prfx #> Sign.no_base_names) |
857 #> Drule.strip_shyps_warning) results |
847 #> global_results kind ((names ~~ attss) ~~ res) |
858 |> (fn res => global_results kind ((names ~~ attss) ~~ res)) |
|
859 #-> (fn res' => |
848 #-> (fn res' => |
860 (print_results thy_ctxt ((kind, name), res') : unit; |
849 (print_results thy_ctxt ((kind, name), res') : unit; |
861 #2 o global_results kind [((name, atts), List.concat (map #2 res'))])) |
850 #2 o global_results kind [((name, atts), List.concat (map #2 res'))])) |
|
851 #> Sign.restore_naming thy; |
|
852 |
|
853 fun after_qed' raw_results results = |
|
854 (case target of NONE => I |
|
855 | SOME prfx => store_results (NameSpace.base prfx) |
|
856 (map (map (ProofContext.export_standard ctxt thy_ctxt |
|
857 #> Drule.strip_shyps_warning)) results)) |
862 #> after_qed raw_results results; |
858 #> after_qed raw_results results; |
863 |
|
864 val prepp' = prepp #> auto_fix; |
|
865 in |
859 in |
866 init ctxt |
860 init ctxt |
867 |> generic_goal prepp' (kind ^ goal_names target name names) |
861 |> generic_goal (prepp #> ProofContext.auto_fix) (kind ^ goal_names target name names) |
868 (K (K Seq.single), after_qed') propp |
862 (K (K Seq.single), after_qed') propp |
869 end; |
863 end; |
870 |
864 |
871 fun check_result msg state sq = |
865 fun check_result msg state sq = |
872 (case Seq.pull sq of |
866 (case Seq.pull sq of |