src/Tools/misc_legacy.ML
changeset 60642 48dd1cefb4ae
parent 60358 aebfbcab1eb8
child 61914 16bfe0a6702d
equal deleted inserted replaced
60641:f6e8293747fd 60642:48dd1cefb4ae
   171       fun mk_subgoal_inst concl_vars (v, T) =
   171       fun mk_subgoal_inst concl_vars (v, T) =
   172           if member (op =) concl_vars (v, T)
   172           if member (op =) concl_vars (v, T)
   173           then ((v, T), true, free_of "METAHYP2_" (v, T))
   173           then ((v, T), true, free_of "METAHYP2_" (v, T))
   174           else ((v, T), false, free_of "METAHYP2_" (v, map #2 params ---> T))
   174           else ((v, T), false, free_of "METAHYP2_" (v, map #2 params ---> T))
   175       (*Instantiate subgoal vars by Free applied to params*)
   175       (*Instantiate subgoal vars by Free applied to params*)
   176       fun mk_ctpair (v, in_concl, u) =
   176       fun mk_inst (v, in_concl, u) =
   177           if in_concl then apply2 (Thm.cterm_of ctxt) (Var v, u)
   177           if in_concl then (v, Thm.cterm_of ctxt u)
   178           else apply2 (Thm.cterm_of ctxt) (Var v, list_comb (u, fparams))
   178           else (v, Thm.cterm_of ctxt (list_comb (u, fparams)))
   179       (*Restore Vars with higher type and index*)
   179       (*Restore Vars with higher type and index*)
   180       fun mk_subgoal_swap_ctpair (((a, i), T), in_concl, u as Free (_, U)) =
   180       fun mk_subgoal_swap_ctpair (((a, i), T), in_concl, u as Free (_, U)) =
   181           if in_concl then apply2 (Thm.cterm_of ctxt) (u, Var ((a, i), T))
   181           if in_concl then apply2 (Thm.cterm_of ctxt) (u, Var ((a, i), T))
   182           else apply2 (Thm.cterm_of ctxt) (u, Var ((a, i + maxidx), U))
   182           else apply2 (Thm.cterm_of ctxt) (u, Var ((a, i + maxidx), U))
   183       (*Embed B in the original context of params and hyps*)
   183       (*Embed B in the original context of params and hyps*)
   189         let val prop = Thm.prop_of st
   189         let val prop = Thm.prop_of st
   190             val subgoal_vars = (*Vars introduced in the subgoals*)
   190             val subgoal_vars = (*Vars introduced in the subgoals*)
   191               fold Term.add_vars (Logic.strip_imp_prems prop) []
   191               fold Term.add_vars (Logic.strip_imp_prems prop) []
   192             and concl_vars = Term.add_vars (Logic.strip_imp_concl prop) []
   192             and concl_vars = Term.add_vars (Logic.strip_imp_concl prop) []
   193             val subgoal_insts = map (mk_subgoal_inst concl_vars) subgoal_vars
   193             val subgoal_insts = map (mk_subgoal_inst concl_vars) subgoal_vars
   194             val st' = Thm.instantiate ([], map mk_ctpair subgoal_insts) st
   194             val st' = Thm.instantiate ([], map mk_inst subgoal_insts) st
   195             val emBs = map (Thm.cterm_of ctxt o embed) (Thm.prems_of st')
   195             val emBs = map (Thm.cterm_of ctxt o embed) (Thm.prems_of st')
   196             val Cth  = implies_elim_list st' (map (elim o Thm.assume) emBs)
   196             val Cth  = implies_elim_list st' (map (elim o Thm.assume) emBs)
   197         in  (*restore the unknowns to the hypotheses*)
   197         in  (*restore the unknowns to the hypotheses*)
   198             free_instantiate (map swap_ctpair insts @
   198             free_instantiate (map swap_ctpair insts @
   199                               map mk_subgoal_swap_ctpair subgoal_insts)
   199                               map mk_subgoal_swap_ctpair subgoal_insts)
   267                   (Var (v, T), Free (the (AList.lookup (op =) alist v), T))
   267                   (Var (v, T), Free (the (AList.lookup (op =) alist v), T))
   268              val insts = map mk_inst vars
   268              val insts = map mk_inst vars
   269              fun thaw i th' = (*i is non-negative increment for Var indexes*)
   269              fun thaw i th' = (*i is non-negative increment for Var indexes*)
   270                  th' |> forall_intr_list (map #2 insts)
   270                  th' |> forall_intr_list (map #2 insts)
   271                      |> forall_elim_list (map (Thm.incr_indexes_cterm i o #1) insts)
   271                      |> forall_elim_list (map (Thm.incr_indexes_cterm i o #1) insts)
   272          in  (Thm.instantiate ([],insts) fth, thaw)  end
   272          in  (Thm.instantiate ([], map (apfst (dest_Var o Thm.term_of)) insts) fth, thaw)  end
   273  end;
   273  end;
   274 
   274 
   275 (*Basic version of the function above. No option to rename Vars apart in thaw.
   275 (*Basic version of the function above. No option to rename Vars apart in thaw.
   276   The Frees created from Vars have nice names.*)
   276   The Frees created from Vars have nice names.*)
   277 fun freeze_thaw ctxt th =
   277 fun freeze_thaw ctxt th =
   289                 apply2 (Thm.cterm_of ctxt) (Var (v, T), Free (the (AList.lookup (op =) alist v), T))
   289                 apply2 (Thm.cterm_of ctxt) (Var (v, T), Free (the (AList.lookup (op =) alist v), T))
   290              val insts = map mk_inst vars
   290              val insts = map mk_inst vars
   291              fun thaw th' =
   291              fun thaw th' =
   292                  th' |> forall_intr_list (map #2 insts)
   292                  th' |> forall_intr_list (map #2 insts)
   293                      |> forall_elim_list (map #1 insts)
   293                      |> forall_elim_list (map #1 insts)
   294          in  (Thm.instantiate ([],insts) fth, thaw)  end
   294          in  (Thm.instantiate ([], map (apfst (dest_Var o Thm.term_of)) insts) fth, thaw)  end
   295  end;
   295  end;
   296 
   296 
   297 end;
   297 end;