src/Pure/Isar/generic_target.ML
changeset 59621 291934bac95e
parent 59616 eb59c6968219
child 60283 c927fa99d045
equal deleted inserted replaced
59620:92d7d8e4f1bf 59621:291934bac95e
   177 fun define foundation internal ((b, mx), ((b_def, atts), rhs)) lthy =
   177 fun define foundation internal ((b, mx), ((b_def, atts), rhs)) lthy =
   178   let
   178   let
   179     val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy);
   179     val thy_ctxt = Proof_Context.init_global (Proof_Context.theory_of lthy);
   180 
   180 
   181     (*term and type parameters*)
   181     (*term and type parameters*)
   182     val ((defs, _), rhs') = Proof_Context.cterm_of lthy rhs
   182     val ((defs, _), rhs') = Thm.cterm_of lthy rhs
   183       |> Local_Defs.export_cterm lthy thy_ctxt ||> Thm.term_of;
   183       |> Local_Defs.export_cterm lthy thy_ctxt ||> Thm.term_of;
   184 
   184 
   185     val xs = Variable.add_fixed lthy rhs' [];
   185     val xs = Variable.add_fixed lthy rhs' [];
   186     val T = Term.fastype_of rhs;
   186     val T = Term.fastype_of rhs;
   187     val tfreesT = Term.add_tfreesT T (fold (Term.add_tfreesT o #2) xs []);
   187     val tfreesT = Term.add_tfreesT T (fold (Term.add_tfreesT o #2) xs []);
   203       |> Local_Defs.add_def ((b, NoSyn), lhs');
   203       |> Local_Defs.add_def ((b, NoSyn), lhs');
   204 
   204 
   205     (*result*)
   205     (*result*)
   206     val def =
   206     val def =
   207       Thm.transitive local_def global_def
   207       Thm.transitive local_def global_def
   208       |> Local_Defs.contract lthy3 defs (Proof_Context.cterm_of lthy3 (Logic.mk_equals (lhs, rhs)));
   208       |> Local_Defs.contract lthy3 defs (Thm.cterm_of lthy3 (Logic.mk_equals (lhs, rhs)));
   209     val ([(res_name, [res])], lthy4) = lthy3
   209     val ([(res_name, [res])], lthy4) = lthy3
   210       |> Local_Theory.notes [((if internal then Binding.empty else b_def, atts), [([def], [])])];
   210       |> Local_Theory.notes [((if internal then Binding.empty else b_def, atts), [([def], [])])];
   211   in ((lhs, (res_name, res)), lthy4) end;
   211   in ((lhs, (res_name, res)), lthy4) end;
   212 
   212 
   213 
   213 
   226 
   226 
   227     (*export fixes*)
   227     (*export fixes*)
   228     val tfrees = map TFree (Thm.fold_terms Term.add_tfrees th' []);
   228     val tfrees = map TFree (Thm.fold_terms Term.add_tfrees th' []);
   229     val frees = map Free (Thm.fold_terms Term.add_frees th' []);
   229     val frees = map Free (Thm.fold_terms Term.add_frees th' []);
   230     val (th'' :: vs) =
   230     val (th'' :: vs) =
   231       (th' :: map (Drule.mk_term o Proof_Context.cterm_of ctxt) (map Logic.mk_type tfrees @ frees))
   231       (th' :: map (Drule.mk_term o Thm.cterm_of ctxt) (map Logic.mk_type tfrees @ frees))
   232       |> Variable.export ctxt thy_ctxt
   232       |> Variable.export ctxt thy_ctxt
   233       |> Drule.zero_var_indexes_list;
   233       |> Drule.zero_var_indexes_list;
   234 
   234 
   235     (*thm definition*)
   235     (*thm definition*)
   236     val result = Global_Theory.name_thm true true name th'';
   236     val result = Global_Theory.name_thm true true name th'';
   241       |>> map Logic.dest_type;
   241       |>> map Logic.dest_type;
   242 
   242 
   243     val instT = map_filter (fn (TVar v, T) => SOME (v, T) | _ => NONE) (tvars ~~ tfrees);
   243     val instT = map_filter (fn (TVar v, T) => SOME (v, T) | _ => NONE) (tvars ~~ tfrees);
   244     val inst = filter (is_Var o fst) (vars ~~ frees);
   244     val inst = filter (is_Var o fst) (vars ~~ frees);
   245     val cinstT = instT
   245     val cinstT = instT
   246       |> map (apply2 (Proof_Context.ctyp_of ctxt) o apfst TVar);
   246       |> map (apply2 (Thm.ctyp_of ctxt) o apfst TVar);
   247     val cinst = inst
   247     val cinst = inst
   248       |> map (apply2 (Proof_Context.cterm_of ctxt o Term.map_types (Term_Subst.instantiateT instT)));
   248       |> map (apply2 (Thm.cterm_of ctxt o Term.map_types (Term_Subst.instantiateT instT)));
   249     val result' = Thm.instantiate (cinstT, cinst) result;
   249     val result' = Thm.instantiate (cinstT, cinst) result;
   250 
   250 
   251     (*import assumes/defines*)
   251     (*import assumes/defines*)
   252     val result'' =
   252     val result'' =
   253       (fold (curry op COMP) asms' result'
   253       (fold (curry op COMP) asms' result'