src/HOL/Eisbach/match_method.ML
changeset 61838 5f43c7f3d691
parent 61837 3c19a230835f
child 61839 6f47a66afcd3
equal deleted inserted replaced
61837:3c19a230835f 61838:5f43c7f3d691
   648   in
   648   in
   649     all_matches
   649     all_matches
   650     |> Seq.map (apsnd (morphism_env morphism))
   650     |> Seq.map (apsnd (morphism_env morphism))
   651   end;
   651   end;
   652 
   652 
   653 fun real_match using ctxt fixes m text pats goal =
   653 fun real_match using goal_ctxt fixes m text pats goal =
   654   let
   654   let
   655     fun make_fact_matches ctxt get =
   655     fun make_fact_matches ctxt get =
   656       let
   656       let
   657         val (pats', ctxt') = fold_map prep_fact_pat pats ctxt;
   657         val (pats', ctxt') = fold_map prep_fact_pat pats ctxt;
   658       in
   658       in
   675       end;
   675       end;
   676   in
   676   in
   677     (case m of
   677     (case m of
   678       Match_Fact net =>
   678       Match_Fact net =>
   679         Seq.map (fn (text, ctxt') => Method_Closure.method_evaluate text ctxt' using goal)
   679         Seq.map (fn (text, ctxt') => Method_Closure.method_evaluate text ctxt' using goal)
   680           (make_fact_matches ctxt (Item_Net.retrieve net))
   680           (make_fact_matches goal_ctxt (Item_Net.retrieve net))
   681     | Match_Term net =>
   681     | Match_Term net =>
   682         Seq.map (fn (text, ctxt') => Method_Closure.method_evaluate text ctxt' using goal)
   682         Seq.map (fn (text, ctxt') => Method_Closure.method_evaluate text ctxt' using goal)
   683           (make_term_matches ctxt (Item_Net.retrieve net))
   683           (make_term_matches goal_ctxt (Item_Net.retrieve net))
   684     | match_kind =>
   684     | match_kind =>
   685         if Thm.no_prems goal then Seq.empty
   685         if Thm.no_prems goal then Seq.empty
   686         else
   686         else
   687           let
   687           let
   688             fun focus_cases f g =
   688             fun focus_cases f g =
   692               | _ => raise Fail "Match kind fell through");
   692               | _ => raise Fail "Match kind fell through");
   693 
   693 
   694             val (goal_thins, goal) = get_thinned_prems goal;
   694             val (goal_thins, goal) = get_thinned_prems goal;
   695 
   695 
   696             val ((local_premids, {context = focus_ctxt, params, asms, concl, ...}), focused_goal) =
   696             val ((local_premids, {context = focus_ctxt, params, asms, concl, ...}), focused_goal) =
   697               focus_cases (K Subgoal.focus_prems) focus_concl ctxt 1 NONE goal
   697               focus_cases (K Subgoal.focus_prems) focus_concl goal_ctxt 1 NONE goal
   698               |>> augment_focus;
   698               |>> augment_focus;
   699 
   699 
   700             val texts =
   700             val texts =
   701               focus_cases
   701               focus_cases
   702                 (fn is_local => fn _ =>
   702                 (fn is_local => fn _ =>
   746                 fun prep_filter t =
   746                 fun prep_filter t =
   747                   Term.subst_bounds (map (Thm.term_of o snd) params |> rev, Term.strip_all_body t);
   747                   Term.subst_bounds (map (Thm.term_of o snd) params |> rev, Term.strip_all_body t);
   748                 fun filter_test prems t =
   748                 fun filter_test prems t =
   749                   if member (op =) prems t then SOME (remove1 (op aconv) t prems) else NONE;
   749                   if member (op =) prems t then SOME (remove1 (op aconv) t prems) else NONE;
   750               in
   750               in
   751                 Subgoal.retrofit inner_ctxt ctxt params asms 1 goal' goal |>
   751                 Subgoal.retrofit inner_ctxt goal_ctxt params asms 1 goal' goal |>
   752                 (if n_subgoals = 0 orelse null local_thins then I
   752                 (if n_subgoals = 0 orelse null local_thins then I
   753                  else
   753                  else
   754                   Seq.map (Goal.restrict 1 n_subgoals)
   754                   Seq.map (Goal.restrict 1 n_subgoals)
   755                   #> Seq.maps (ALLGOALS (fn i =>
   755                   #> Seq.maps (ALLGOALS (fn i =>
   756                       DETERM (filter_prems_tac' ctxt prep_filter filter_test local_thins i)))
   756                       DETERM (filter_prems_tac' goal_ctxt prep_filter filter_test local_thins i)))
   757                   #> Seq.map (Goal.unrestrict 1))
   757                   #> Seq.map (Goal.unrestrict 1))
   758                   |> Seq.map (fold Thm.weaken extra_thins)
   758                   |> Seq.map (fold Thm.weaken extra_thins)
   759               end;
   759               end;
   760 
   760 
   761             fun apply_text (text, ctxt') =
   761             fun apply_text (text, ctxt') =