81 val defer: int option -> state -> state Seq.seq |
81 val defer: int option -> state -> state Seq.seq |
82 val prefer: int -> state -> state Seq.seq |
82 val prefer: int -> state -> state Seq.seq |
83 val apply: Method.text -> state -> state Seq.seq |
83 val apply: Method.text -> state -> state Seq.seq |
84 val apply_end: Method.text -> state -> state Seq.seq |
84 val apply_end: Method.text -> state -> state Seq.seq |
85 val local_goal: (context -> ((string * string) * (string * thm list) list) -> unit) -> |
85 val local_goal: (context -> ((string * string) * (string * thm list) list) -> unit) -> |
86 (theory -> 'a -> attribute) -> |
86 (Proof.context -> 'a -> attribute) -> |
87 ('b list -> context -> (term list list * (context -> context)) * context) -> |
87 ('b list -> context -> (term list list * (context -> context)) * context) -> |
88 string -> Method.text option -> (thm list list -> state -> state) -> |
88 string -> Method.text option -> (thm list list -> state -> state) -> |
89 ((binding * 'a list) * 'b) list -> state -> state |
89 ((binding * 'a list) * 'b) list -> state -> state |
90 val local_qed: Method.text option * bool -> state -> state |
90 val local_qed: Method.text option * bool -> state -> state |
91 val theorem: Method.text option -> (thm list list -> context -> context) -> |
91 val theorem: Method.text option -> (thm list list -> context -> context) -> |
398 fun goals st = map goalN (1 upto Thm.nprems_of st); |
398 fun goals st = map goalN (1 upto Thm.nprems_of st); |
399 |
399 |
400 fun no_goal_cases st = map (rpair NONE) (goals st); |
400 fun no_goal_cases st = map (rpair NONE) (goals st); |
401 |
401 |
402 fun goal_cases st = |
402 fun goal_cases st = |
403 Rule_Cases.make_common (Thm.theory_of_thm st, Thm.prop_of st) (map (rpair [] o rpair []) (goals st)); |
403 Rule_Cases.make_common |
|
404 (Thm.theory_of_thm st, Thm.prop_of st) (map (rpair [] o rpair []) (goals st)); |
404 |
405 |
405 fun apply_method current_context meth state = |
406 fun apply_method current_context meth state = |
406 let |
407 let |
407 val (goal_ctxt, (_, {statement, messages = _, using, goal, before_qed, after_qed})) = |
408 val (goal_ctxt, (_, {statement, messages = _, using, goal, before_qed, after_qed})) = |
408 find_goal state; |
409 find_goal state; |
610 local |
611 local |
611 |
612 |
612 fun gen_assume asm prep_att exp args state = |
613 fun gen_assume asm prep_att exp args state = |
613 state |
614 state |
614 |> assert_forward |
615 |> assert_forward |
615 |> map_context_result (asm exp (Attrib.map_specs (map (prep_att (theory_of state))) args)) |
616 |> map_context_result (asm exp (Attrib.map_specs (map (prep_att (context_of state))) args)) |
616 |> these_factss [] |> #2; |
617 |> these_factss [] |> #2; |
617 |
618 |
618 in |
619 in |
619 |
620 |
620 val assm = gen_assume Proof_Context.add_assms_i (K I); |
621 val assm = gen_assume Proof_Context.add_assms_i (K I); |
621 val assm_cmd = gen_assume Proof_Context.add_assms Attrib.attribute; |
622 val assm_cmd = gen_assume Proof_Context.add_assms Attrib.attribute_cmd; |
622 val assume = assm Assumption.assume_export; |
623 val assume = assm Assumption.assume_export; |
623 val assume_cmd = assm_cmd Assumption.assume_export; |
624 val assume_cmd = assm_cmd Assumption.assume_export; |
624 val presume = assm Assumption.presume_export; |
625 val presume = assm Assumption.presume_export; |
625 val presume_cmd = assm_cmd Assumption.presume_export; |
626 val presume_cmd = assm_cmd Assumption.presume_export; |
626 |
627 |
632 local |
633 local |
633 |
634 |
634 fun gen_def prep_att prep_vars prep_binds args state = |
635 fun gen_def prep_att prep_vars prep_binds args state = |
635 let |
636 let |
636 val _ = assert_forward state; |
637 val _ = assert_forward state; |
637 val thy = theory_of state; |
|
638 |
|
639 val (raw_name_atts, (raw_vars, raw_rhss)) = args |> split_list ||> split_list; |
638 val (raw_name_atts, (raw_vars, raw_rhss)) = args |> split_list ||> split_list; |
640 val name_atts = map (apsnd (map (prep_att thy))) raw_name_atts; |
639 val name_atts = map (apsnd (map (prep_att (context_of state)))) raw_name_atts; |
641 in |
640 in |
642 state |
641 state |
643 |> map_context_result (prep_vars (map (fn (x, mx) => (x, NONE, mx)) raw_vars)) |
642 |> map_context_result (prep_vars (map (fn (x, mx) => (x, NONE, mx)) raw_vars)) |
644 |>> map (fn (x, _, mx) => (x, mx)) |
643 |>> map (fn (x, _, mx) => (x, mx)) |
645 |-> (fn vars => |
644 |-> (fn vars => |
681 local |
680 local |
682 |
681 |
683 fun gen_thmss more_facts opt_chain opt_result prep_atts prep_fact args state = |
682 fun gen_thmss more_facts opt_chain opt_result prep_atts prep_fact args state = |
684 state |
683 state |
685 |> assert_forward |
684 |> assert_forward |
686 |> map_context_result (Proof_Context.note_thmss "" |
685 |> map_context_result (fn ctxt => ctxt |> Proof_Context.note_thmss "" |
687 (Attrib.map_facts_refs |
686 (Attrib.map_facts_refs (map (prep_atts ctxt)) (prep_fact ctxt) args)) |
688 (map (prep_atts (theory_of state))) |
|
689 (prep_fact (context_of state)) args)) |
|
690 |> these_factss (more_facts state) |
687 |> these_factss (more_facts state) |
691 ||> opt_chain |
688 ||> opt_chain |
692 |> opt_result; |
689 |> opt_result; |
693 |
690 |
694 in |
691 in |
695 |
692 |
696 val note_thmss = gen_thmss (K []) I #2 (K I) (K I); |
693 val note_thmss = gen_thmss (K []) I #2 (K I) (K I); |
697 val note_thmss_cmd = gen_thmss (K []) I #2 Attrib.attribute Proof_Context.get_fact; |
694 val note_thmss_cmd = gen_thmss (K []) I #2 Attrib.attribute_cmd Proof_Context.get_fact; |
698 |
695 |
699 val from_thmss = gen_thmss (K []) chain #2 (K I) (K I) o no_binding; |
696 val from_thmss = gen_thmss (K []) chain #2 (K I) (K I) o no_binding; |
700 val from_thmss_cmd = gen_thmss (K []) chain #2 Attrib.attribute Proof_Context.get_fact o no_binding; |
697 val from_thmss_cmd = |
|
698 gen_thmss (K []) chain #2 Attrib.attribute_cmd Proof_Context.get_fact o no_binding; |
701 |
699 |
702 val with_thmss = gen_thmss the_facts chain #2 (K I) (K I) o no_binding; |
700 val with_thmss = gen_thmss the_facts chain #2 (K I) (K I) o no_binding; |
703 val with_thmss_cmd = gen_thmss the_facts chain #2 Attrib.attribute Proof_Context.get_fact o no_binding; |
701 val with_thmss_cmd = |
|
702 gen_thmss the_facts chain #2 Attrib.attribute_cmd Proof_Context.get_fact o no_binding; |
704 |
703 |
705 val local_results = gen_thmss (K []) I I (K I) (K I) o map (apsnd Thm.simple_fact); |
704 val local_results = gen_thmss (K []) I I (K I) (K I) o map (apsnd Thm.simple_fact); |
706 |
705 |
707 end; |
706 end; |
708 |
707 |
713 |
712 |
714 fun gen_using f g prep_att prep_fact args state = |
713 fun gen_using f g prep_att prep_fact args state = |
715 state |
714 state |
716 |> assert_backward |
715 |> assert_backward |
717 |> map_context_result |
716 |> map_context_result |
718 (Proof_Context.note_thmss "" |
717 (fn ctxt => ctxt |> Proof_Context.note_thmss "" |
719 (Attrib.map_facts_refs (map (prep_att (theory_of state))) (prep_fact (context_of state)) |
718 (Attrib.map_facts_refs (map (prep_att ctxt)) (prep_fact ctxt) (no_binding args))) |
720 (no_binding args))) |
|
721 |> (fn (named_facts, state') => |
719 |> (fn (named_facts, state') => |
722 state' |> map_goal I (fn (statement, _, using, goal, before_qed, after_qed) => |
720 state' |> map_goal I (fn (statement, _, using, goal, before_qed, after_qed) => |
723 let |
721 let |
724 val ctxt = context_of state'; |
722 val ctxt = context_of state'; |
725 val ths = maps snd named_facts; |
723 val ths = maps snd named_facts; |
730 val unfold_goals = Local_Defs.unfold_goals; |
728 val unfold_goals = Local_Defs.unfold_goals; |
731 |
729 |
732 in |
730 in |
733 |
731 |
734 val using = gen_using append_using (K (K I)) (K I) (K I); |
732 val using = gen_using append_using (K (K I)) (K I) (K I); |
735 val using_cmd = gen_using append_using (K (K I)) Attrib.attribute Proof_Context.get_fact; |
733 val using_cmd = gen_using append_using (K (K I)) Attrib.attribute_cmd Proof_Context.get_fact; |
736 val unfolding = gen_using unfold_using unfold_goals (K I) (K I); |
734 val unfolding = gen_using unfold_using unfold_goals (K I) (K I); |
737 val unfolding_cmd = gen_using unfold_using unfold_goals Attrib.attribute Proof_Context.get_fact; |
735 val unfolding_cmd = gen_using unfold_using unfold_goals Attrib.attribute_cmd Proof_Context.get_fact; |
738 |
736 |
739 end; |
737 end; |
740 |
738 |
741 |
739 |
742 (* case *) |
740 (* case *) |
746 fun qualified_binding a = |
744 fun qualified_binding a = |
747 Binding.qualify true (Long_Name.qualifier a) (Binding.name (Long_Name.base_name a)); |
745 Binding.qualify true (Long_Name.qualifier a) (Binding.name (Long_Name.base_name a)); |
748 |
746 |
749 fun gen_invoke_case prep_att (name, xs, raw_atts) state = |
747 fun gen_invoke_case prep_att (name, xs, raw_atts) state = |
750 let |
748 let |
751 val atts = map (prep_att (theory_of state)) raw_atts; |
749 val atts = map (prep_att (context_of state)) raw_atts; |
752 val (asms, state') = state |> map_context_result (fn ctxt => |
750 val (asms, state') = state |> map_context_result (fn ctxt => |
753 ctxt |> Proof_Context.apply_case (Proof_Context.get_case ctxt name xs)); |
751 ctxt |> Proof_Context.apply_case (Proof_Context.get_case ctxt name xs)); |
754 val assumptions = asms |> map (fn (a, ts) => ((qualified_binding a, atts), map (rpair []) ts)); |
752 val assumptions = asms |> map (fn (a, ts) => ((qualified_binding a, atts), map (rpair []) ts)); |
755 in |
753 in |
756 state' |
754 state' |
933 |
931 |
934 (* local goals *) |
932 (* local goals *) |
935 |
933 |
936 fun local_goal print_results prep_att prepp kind before_qed after_qed stmt state = |
934 fun local_goal print_results prep_att prepp kind before_qed after_qed stmt state = |
937 let |
935 let |
938 val thy = theory_of state; |
|
939 val ((names, attss), propp) = |
936 val ((names, attss), propp) = |
940 Attrib.map_specs (map (prep_att thy)) stmt |> split_list |>> split_list; |
937 Attrib.map_specs (map (prep_att (context_of state))) stmt |> split_list |>> split_list; |
941 |
938 |
942 fun after_qed' results = |
939 fun after_qed' results = |
943 local_results ((names ~~ attss) ~~ results) |
940 local_results ((names ~~ attss) ~~ results) |
944 #-> (fn res => tap (fn st => print_results (context_of st) ((kind, ""), res) : unit)) |
941 #-> (fn res => tap (fn st => print_results (context_of st) ((kind, ""), res) : unit)) |
945 #> after_qed results; |
942 #> after_qed results; |