src/Pure/Isar/local_defs.ML
changeset 63344 c9910404cc8a
parent 63221 7d43fbbaba28
child 63395 734723445a8c
equal deleted inserted replaced
63343:fb5d8a50c641 63344:c9910404cc8a
     8 sig
     8 sig
     9   val cert_def: Proof.context -> term -> (string * typ) * term
     9   val cert_def: Proof.context -> term -> (string * typ) * term
    10   val abs_def: term -> (string * typ) * term
    10   val abs_def: term -> (string * typ) * term
    11   val expand: cterm list -> thm -> thm
    11   val expand: cterm list -> thm -> thm
    12   val def_export: Assumption.export
    12   val def_export: Assumption.export
    13   val add_defs: ((binding * mixfix) * (Thm.binding * term)) list -> Proof.context ->
    13   val define: ((binding * mixfix) * (Thm.binding * term)) list -> Proof.context ->
    14     (term * (string * thm)) list * Proof.context
    14     (term * (string * thm)) list * Proof.context
    15   val add_def: (binding * mixfix) * term -> Proof.context -> (term * thm) * Proof.context
       
    16   val fixed_abbrev: (binding * mixfix) * term -> Proof.context ->
    15   val fixed_abbrev: (binding * mixfix) * term -> Proof.context ->
    17     (term * term) * Proof.context
    16     (term * term) * Proof.context
    18   val export: Proof.context -> Proof.context -> thm -> (thm list * thm list) * thm
    17   val export: Proof.context -> Proof.context -> thm -> (thm list * thm list) * thm
    19   val export_cterm: Proof.context -> Proof.context -> cterm -> (thm list * thm list) * cterm
    18   val export_cterm: Proof.context -> Proof.context -> cterm -> (thm list * thm list) * cterm
    20   val contract: Proof.context -> thm list -> cterm -> thm -> thm
    19   val contract: Proof.context -> thm list -> cterm -> thm -> thm
    64 
    63 
    65 fun mk_def ctxt args =
    64 fun mk_def ctxt args =
    66   let
    65   let
    67     val (bs, rhss) = split_list args;
    66     val (bs, rhss) = split_list args;
    68     val Ts = map Term.fastype_of rhss;
    67     val Ts = map Term.fastype_of rhss;
    69     val (xs, _) = Proof_Context.add_fixes (map2 (fn b => fn T => (b, SOME T, NoSyn)) bs Ts) ctxt;
    68     val (xs, _) = ctxt
       
    69       |> Context_Position.set_visible false
       
    70       |> Proof_Context.add_fixes (map2 (fn b => fn T => (b, SOME T, NoSyn)) bs Ts);
    70     val lhss = ListPair.map Free (xs, Ts);
    71     val lhss = ListPair.map Free (xs, Ts);
    71   in map Logic.mk_equals (lhss ~~ rhss) end;
    72   in map Logic.mk_equals (lhss ~~ rhss) end;
    72 
    73 
    73 
    74 
    74 (* export defs *)
    75 (* export defs *)
    92 val expand_term = Envir.expand_term_frees o map (abs_def o Thm.term_of);
    93 val expand_term = Envir.expand_term_frees o map (abs_def o Thm.term_of);
    93 
    94 
    94 fun def_export _ defs = (expand defs, expand_term defs);
    95 fun def_export _ defs = (expand defs, expand_term defs);
    95 
    96 
    96 
    97 
    97 (* add defs *)
    98 (* define *)
    98 
    99 
    99 fun add_defs defs ctxt =
   100 fun define defs ctxt =
   100   let
   101   let
   101     val ((xs, mxs), specs) = defs |> split_list |>> split_list;
   102     val ((xs, mxs), specs) = defs |> split_list |>> split_list;
   102     val (bs, rhss) = specs |> split_list;
   103     val (bs, rhss) = specs |> split_list;
   103     val eqs = mk_def (Context_Position.set_visible false ctxt) (xs ~~ rhss);
   104     val eqs = mk_def ctxt (xs ~~ rhss);
   104     val lhss = map (fst o Logic.dest_equals) eqs;
   105     val lhss = map (fst o Logic.dest_equals) eqs;
   105   in
   106   in
   106     ctxt
   107     ctxt
   107     |> Proof_Context.add_fixes (map2 (fn x => fn mx => (x, NONE, mx)) xs mxs) |> #2
   108     |> Proof_Context.add_fixes (map2 (fn x => fn mx => (x, NONE, mx)) xs mxs) |> #2
   108     |> fold Variable.declare_term eqs
   109     |> fold Variable.declare_term eqs
   109     |> Proof_Context.add_assms def_export (map2 (fn b => fn eq => (b, [(eq, [])])) bs eqs)
   110     |> Proof_Context.add_assms def_export (map2 (fn b => fn eq => (b, [(eq, [])])) bs eqs)
   110     |>> map2 (fn lhs => fn (name, [th]) => (lhs, (name, th))) lhss
   111     |>> map2 (fn lhs => fn (name, [th]) => (lhs, (name, th))) lhss
   111   end;
   112   end;
   112 
       
   113 fun add_def (var, rhs) ctxt =
       
   114   let val ([(lhs, (_, th))], ctxt') = add_defs [(var, (Thm.empty_binding, rhs))] ctxt
       
   115   in ((lhs, th), ctxt') end;
       
   116 
   113 
   117 
   114 
   118 (* fixed_abbrev *)
   115 (* fixed_abbrev *)
   119 
   116 
   120 fun fixed_abbrev ((x, mx), rhs) ctxt =
   117 fun fixed_abbrev ((x, mx), rhs) ctxt =