src/HOL/Tools/Lifting/lifting_setup.ML
changeset 74220 c49134ee16c1
parent 74152 069f6b2c5a07
child 74266 612b7e0d6721
equal deleted inserted replaced
74219:1d25be2353e1 74220:c49134ee16c1
    76     val param_rel_subst = Envir.subst_term (tyenv_match,Vartab.empty) param_rel
    76     val param_rel_subst = Envir.subst_term (tyenv_match,Vartab.empty) param_rel
    77     val args_subst = map (Envir.subst_term (tyenv_match,Vartab.empty)) args
    77     val args_subst = map (Envir.subst_term (tyenv_match,Vartab.empty)) args
    78     val (instT, lthy2) = lthy1
    78     val (instT, lthy2) = lthy1
    79       |> Variable.declare_names fixed_crel
    79       |> Variable.declare_names fixed_crel
    80       |> Variable.importT_inst (param_rel_subst :: args_subst)
    80       |> Variable.importT_inst (param_rel_subst :: args_subst)
    81     val args_fixed = (map (Term_Subst.instantiate (instT, []))) args_subst
    81     val args_fixed = (map (Term_Subst.instantiate (instT, Term_Subst.Vars.empty))) args_subst
    82     val param_rel_fixed = Term_Subst.instantiate (instT, []) param_rel_subst
    82     val param_rel_fixed = Term_Subst.instantiate (instT, Term_Subst.Vars.empty) param_rel_subst
    83     val rty = (domain_type o fastype_of) param_rel_fixed
    83     val rty = (domain_type o fastype_of) param_rel_fixed
    84     val relcomp_op = Const (\<^const_name>\<open>relcompp\<close>, 
    84     val relcomp_op = Const (\<^const_name>\<open>relcompp\<close>, 
    85           (rty --> rty' --> HOLogic.boolT) --> 
    85           (rty --> rty' --> HOLogic.boolT) --> 
    86           (rty' --> qty --> HOLogic.boolT) --> 
    86           (rty' --> qty --> HOLogic.boolT) --> 
    87           rty --> qty --> HOLogic.boolT)
    87           rty --> qty --> HOLogic.boolT)
   293 local
   293 local
   294   fun importT_inst_exclude exclude ts ctxt =
   294   fun importT_inst_exclude exclude ts ctxt =
   295     let
   295     let
   296       val tvars = rev (subtract op= exclude (fold Term.add_tvars ts []))
   296       val tvars = rev (subtract op= exclude (fold Term.add_tvars ts []))
   297       val (tfrees, ctxt') = Variable.invent_types (map #2 tvars) ctxt
   297       val (tfrees, ctxt') = Variable.invent_types (map #2 tvars) ctxt
   298     in (tvars ~~ map TFree tfrees, ctxt') end
   298     in (Term_Subst.TVars.table (tvars ~~ map TFree tfrees), ctxt') end
   299   
   299   
   300   fun import_inst_exclude exclude ts ctxt =
   300   fun import_inst_exclude exclude ts ctxt =
   301     let
   301     let
   302       val excludeT = fold (Term.add_tvarsT o snd) exclude []
   302       val excludeT = fold (Term.add_tvarsT o snd) exclude []
   303       val (instT, ctxt') = importT_inst_exclude excludeT ts ctxt
   303       val (instT, ctxt') = importT_inst_exclude excludeT ts ctxt
   304       val vars = map (apsnd (Term_Subst.instantiateT instT)) 
   304       val vars = map (apsnd (Term_Subst.instantiateT instT)) 
   305         (rev (subtract op= exclude (fold Term.add_vars ts [])))
   305         (rev (subtract op= exclude (fold Term.add_vars ts [])))
   306       val (xs, ctxt'') = Variable.variant_fixes (map (#1 o #1) vars) ctxt'
   306       val (xs, ctxt'') = Variable.variant_fixes (map (#1 o #1) vars) ctxt'
   307       val inst = vars ~~ map Free (xs ~~ map #2 vars)
   307       val inst = Term_Subst.Vars.table (vars ~~ map Free (xs ~~ map #2 vars))
   308     in ((instT, inst), ctxt'') end
   308     in ((instT, inst), ctxt'') end
   309   
   309   
   310   fun import_terms_exclude exclude ts ctxt =
   310   fun import_terms_exclude exclude ts ctxt =
   311     let val (inst, ctxt') = import_inst_exclude exclude ts ctxt
   311     let val (inst, ctxt') = import_inst_exclude exclude ts ctxt
   312     in (map (Term_Subst.instantiate inst) ts, ctxt') end
   312     in (map (Term_Subst.instantiate inst) ts, ctxt') end