src/HOL/Tools/Predicate_Compile/predicate_compile_aux.ML
changeset 74282 c2ee8d993d6a
parent 74266 612b7e0d6721
child 77879 dd222e2af01a
equal deleted inserted replaced
74281:7829d6435c60 74282:c2ee8d993d6a
   869     val (pats', intro_t', ctxt2) = rewrite_args args ([], intro_t, ctxt1)
   869     val (pats', intro_t', ctxt2) = rewrite_args args ([], intro_t, ctxt1)
   870     val (pats', _, ctxt3) = fold_atoms rewrite_prem intro_t' (pats', intro_t', ctxt2)
   870     val (pats', _, ctxt3) = fold_atoms rewrite_prem intro_t' (pats', intro_t', ctxt2)
   871     fun rewrite_pat (ct1, ct2) =
   871     fun rewrite_pat (ct1, ct2) =
   872       (ct1, Thm.cterm_of ctxt3 (Pattern.rewrite_term thy pats' [] (Thm.term_of ct2)))
   872       (ct1, Thm.cterm_of ctxt3 (Pattern.rewrite_term thy pats' [] (Thm.term_of ct2)))
   873     val t_insts' = map rewrite_pat (Vars.dest t_insts)
   873     val t_insts' = map rewrite_pat (Vars.dest t_insts)
   874     val intro'' = Thm.instantiate (TVars.dest T_insts, t_insts') intro
   874     val intro'' = Thm.instantiate (T_insts, Vars.make t_insts') intro
   875     val [intro'''] = Variable.export ctxt3 ctxt [intro'']
   875     val [intro'''] = Variable.export ctxt3 ctxt [intro'']
   876     val intro'''' =
   876     val intro'''' =
   877       Simplifier.full_simplify
   877       Simplifier.full_simplify
   878         (put_simpset HOL_basic_ss ctxt
   878         (put_simpset HOL_basic_ss ctxt
   879           addsimps [@{thm fst_conv}, @{thm snd_conv}, @{thm prod.inject}])
   879           addsimps [@{thm fst_conv}, @{thm snd_conv}, @{thm prod.inject}])
   939     val U = TFree ("'u", \<^sort>\<open>type\<close>)
   939     val U = TFree ("'u", \<^sort>\<open>type\<close>)
   940     val y = Free (yname, U)
   940     val y = Free (yname, U)
   941     val f' = absdummy (U --> T') (Bound 0 $ y)
   941     val f' = absdummy (U --> T') (Bound 0 $ y)
   942     val th' =
   942     val th' =
   943       Thm.instantiate
   943       Thm.instantiate
   944         ([(dest_TVar uninst_T, Thm.ctyp_of ctxt' (U --> T')),
   944         (TVars.make [(dest_TVar uninst_T, Thm.ctyp_of ctxt' (U --> T')),
   945           (dest_TVar uninst_T', Thm.ctyp_of ctxt' T')],
   945           (dest_TVar uninst_T', Thm.ctyp_of ctxt' T')],
   946          [((fst (dest_Var f), (U --> T') --> T'), Thm.cterm_of ctxt' f')]) th
   946          Vars.make [((fst (dest_Var f), (U --> T') --> T'), Thm.cterm_of ctxt' f')]) th
   947     val [th'] = Variable.export (Variable.declare_thm th' ctxt') ctxt [th']
   947     val [th'] = Variable.export (Variable.declare_thm th' ctxt') ctxt [th']
   948   in
   948   in
   949     th'
   949     th'
   950   end
   950   end
   951 
   951 
  1081                 raise Fail "Trying to instantiate another predicate"
  1081                 raise Fail "Trying to instantiate another predicate"
  1082               else ()
  1082               else ()
  1083             val instT =
  1083             val instT =
  1084               TVars.fold (fn (v, T) => cons (v, Thm.ctyp_of ctxt' T))
  1084               TVars.fold (fn (v, T) => cons (v, Thm.ctyp_of ctxt' T))
  1085                 (subst_of (pred', pred)) [];
  1085                 (subst_of (pred', pred)) [];
  1086           in Thm.instantiate (instT, []) th end
  1086           in Thm.instantiate (TVars.make instT, Vars.empty) th end
  1087         fun instantiate_ho_args th =
  1087         fun instantiate_ho_args th =
  1088           let
  1088           let
  1089             val (_, args') =
  1089             val (_, args') =
  1090               (strip_comb o HOLogic.dest_Trueprop o Logic.strip_imp_concl o Thm.prop_of) th
  1090               (strip_comb o HOLogic.dest_Trueprop o Logic.strip_imp_concl o Thm.prop_of) th
  1091             val ho_args' = map dest_Var (ho_args_of_typ T args')
  1091             val ho_args' = map dest_Var (ho_args_of_typ T args')
  1092           in Thm.instantiate ([], ho_args' ~~ map (Thm.cterm_of ctxt') ho_args) th end
  1092           in
       
  1093             Thm.instantiate (TVars.empty, Vars.make (ho_args' ~~ map (Thm.cterm_of ctxt') ho_args))
       
  1094               th
       
  1095           end
  1093         val outp_pred =
  1096         val outp_pred =
  1094           Term_Subst.instantiate (subst_of (inp_pred, pred), Vars.empty) inp_pred
  1097           Term_Subst.instantiate (subst_of (inp_pred, pred), Vars.empty) inp_pred
  1095         val ((_, ths'), ctxt1) =
  1098         val ((_, ths'), ctxt1) =
  1096           Variable.import false (map (instantiate_typ #> instantiate_ho_args) ths) ctxt'
  1099           Variable.import false (map (instantiate_typ #> instantiate_ho_args) ths) ctxt'
  1097       in
  1100       in