src/Pure/Isar/local_defs.ML
author wenzelm
Sun, 29 Jan 2006 19:23:47 +0100
changeset 18840 ce16e2bad548
parent 18830 34b51dcdc570
child 18859 75248f8badc9
permissions -rw-r--r--
added attributes defn_add/del; added (un)fold operations (from object_logic.ML); tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18830
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/local_defs.ML
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
     4
18840
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
     5
Local definitions.
18830
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
     6
*)
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
     7
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
     8
signature LOCAL_DEFS =
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
     9
sig
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    10
  val mk_def: ProofContext.context -> (string * term) list -> term list
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    11
  val cert_def: ProofContext.context -> term -> string * term
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    12
  val abs_def: term -> (string * typ) * term
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    13
  val def_export: ProofContext.export
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    14
  val add_def: string * term -> ProofContext.context ->
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    15
    ((string * typ) * thm) * ProofContext.context
18840
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    16
  val print_rules: Context.generic -> unit
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    17
  val defn_add: attribute
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    18
  val defn_del: attribute
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    19
  val unfold: ProofContext.context -> bool -> thm list -> thm -> thm
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    20
  val unfold_goals: ProofContext.context -> bool -> thm list -> thm -> thm
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    21
  val unfold_tac: ProofContext.context -> bool -> thm list -> tactic
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    22
  val fold: ProofContext.context -> bool -> thm list -> thm -> thm
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    23
  val fold_tac: ProofContext.context -> bool -> thm list -> tactic
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    24
  val derived_def: ProofContext.context -> term ->
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    25
    ((string * typ) * term) * (ProofContext.context -> term -> thm -> thm)
18830
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    26
end;
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    27
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    28
structure LocalDefs: LOCAL_DEFS =
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    29
struct
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    30
18840
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    31
(** primitive definitions **)
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
    32
18830
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    33
(* prepare defs *)
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    34
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    35
fun mk_def ctxt args =
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    36
  let
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    37
    val (xs, rhss) = split_list args;
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    38
    val (bind, _) = ProofContext.bind_fixes xs ctxt;
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    39
    val lhss = map (fn (x, rhs) => bind (Free (x, Term.fastype_of rhs))) args;
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    40
  in map Logic.mk_equals (lhss ~~ rhss) end;
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    41
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    42
fun cert_def ctxt eq =
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    43
  let
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    44
    fun err msg = cat_error msg
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    45
      ("The error(s) above occurred in definition: " ^ ProofContext.string_of_term ctxt eq);
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    46
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    47
    val (lhs, rhs) = Logic.dest_equals (Term.strip_all_body eq)
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    48
      handle TERM _ => err "Not a meta-equality (==)";
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    49
    val (f, xs) = Term.strip_comb (Pattern.beta_eta_contract lhs);
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    50
    val (c, _) = Term.dest_Free f handle TERM _ =>
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    51
      err "Head of lhs must be a free/fixed variable";
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    52
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    53
    fun check_arg (Bound _) = true
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    54
      | check_arg (Free (x, _)) = not (ProofContext.is_fixed ctxt x)
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    55
      | check_arg t = (case try Logic.dest_type t of SOME (TFree _) => true | _ => false);
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    56
    fun close_arg (Free (x, T)) t = Term.all T $ Term.absfree (x, T, t)
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    57
      | close_arg (Const ("TYPE", T)) t = Term.all T $ Term.absdummy (T, t)
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    58
      | close_arg _ t = t;
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    59
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    60
    val extra_frees = Term.fold_aterms (fn v as Free (x, _) =>
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    61
      if ProofContext.is_fixed ctxt x orelse member (op aconv) xs v then I
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    62
      else insert (op =) x | _ => I) rhs [];
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    63
  in
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    64
    if not (forall check_arg xs) orelse has_duplicates (op =) xs then
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    65
      err "Arguments of lhs must be distinct free/bound variables"
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    66
    else if not (null extra_frees) then
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    67
      err ("Extra free variables on rhs: " ^ commas_quote extra_frees)
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    68
    else if Term.exists_subterm (fn t => t = f) rhs then
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    69
      err "Element to be defined occurs on rhs"
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    70
    else (c, fold_rev close_arg xs eq)
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    71
  end;
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    72
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    73
fun abs_def eq =
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    74
  let
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    75
    val body = Term.strip_all_body eq;
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    76
    val vars = map Free (Term.rename_wrt_term body (Term.strip_all_vars eq));
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    77
    val (lhs, rhs) = Logic.dest_equals (Term.subst_bounds (vars, body));
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    78
    val (f, xs) = Term.strip_comb (Pattern.beta_eta_contract lhs);
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    79
    val eq' = Term.list_abs_free (map Term.dest_Free xs, rhs);
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    80
  in (Term.dest_Free f, eq') end;
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    81
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    82
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    83
(* export defs *)
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    84
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    85
fun head_of_def cprop =
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    86
  #1 (Term.strip_comb (#1 (Logic.dest_equals (Term.strip_all_body (Thm.term_of cprop)))))
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    87
  |> Thm.cterm_of (Thm.theory_of_cterm cprop);
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    88
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    89
fun def_export _ cprops thm =
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    90
  thm
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    91
  |> Drule.implies_intr_list cprops
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    92
  |> Drule.forall_intr_list (map head_of_def cprops)
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    93
  |> Drule.forall_elim_vars 0
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    94
  |> RANGE (replicate (length cprops) (Tactic.rtac Drule.reflexive_thm)) 1;
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    95
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    96
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    97
(* add defs *)
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    98
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
    99
fun add_def (x, t) ctxt =
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
   100
  let
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
   101
    val [eq] = mk_def ctxt [(x, t)];
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
   102
    val x' = Term.dest_Free (fst (Logic.dest_equals eq));
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
   103
  in
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
   104
    ctxt
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
   105
    |> ProofContext.add_fixes_i [(x, NONE, NoSyn)] |> snd
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
   106
    |> ProofContext.add_assms_i def_export [(("", []), [(eq, ([], []))])]
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
   107
    |>> (fn [(_, [th])] => (x', th))
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
   108
  end;
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
   109
18840
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   110
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   111
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   112
(** defived definitions **)
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   113
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   114
(* transformation rules *)
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   115
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   116
structure Data = GenericDataFun
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   117
(
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   118
  val name = "Pure/derived_defs";
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   119
  type T = thm list;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   120
  val empty = []
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   121
  val extend = I;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   122
  fun merge _ = Drule.merge_rules;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   123
  fun print context rules =
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   124
    Pretty.writeln (Pretty.big_list "definitional transformations:"
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   125
      (map (ProofContext.pretty_thm (Context.proof_of context)) rules));
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   126
);
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   127
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   128
val _ = Context.add_setup Data.init;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   129
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   130
val print_rules = Data.print;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   131
val get_rules = Data.get o Context.Proof;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   132
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   133
val defn_add = Thm.declaration_attribute (Data.map o Drule.add_rule);
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   134
val defn_del = Thm.declaration_attribute (Data.map o Drule.del_rule);
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   135
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   136
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   137
(* transform rewrite rules *)
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   138
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   139
val equals_ss =
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   140
  MetaSimplifier.theory_context ProtoPure.thy MetaSimplifier.empty_ss
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   141
    addeqcongs [Drule.equals_cong];    (*protect meta-level equality*)
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   142
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   143
fun meta_rewrite ctxt =
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   144
  MetaSimplifier.rewrite_cterm (false, false, false) (K (K NONE))
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   145
    (equals_ss addsimps (get_rules ctxt));
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   146
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   147
val meta_rewrite_thm = Drule.fconv_rule o meta_rewrite;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   148
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   149
fun meta_rewrite_tac ctxt i =
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   150
  PRIMITIVE (Drule.fconv_rule (Drule.goals_conv (equal i) (meta_rewrite ctxt)));
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   151
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   152
fun transformed f _ false = f
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   153
  | transformed f ctxt true = f o map (meta_rewrite_thm ctxt);
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   154
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   155
val unfold       = transformed Tactic.rewrite_rule;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   156
val unfold_goals = transformed Tactic.rewrite_goals_rule;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   157
val unfold_tac   = transformed Tactic.rewrite_goals_tac;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   158
val fold         = transformed Tactic.fold_rule;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   159
val fold_tac     = transformed Tactic.fold_goals_tac;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   160
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   161
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   162
(* derived defs -- potentially within the object-logic *)
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   163
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   164
fun derived_def ctxt prop =
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   165
  let
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   166
    val thy = ProofContext.theory_of ctxt;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   167
    val ((c, T), rhs) = prop
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   168
      |> Thm.cterm_of thy
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   169
      |> meta_rewrite ctxt
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   170
      |> (snd o Logic.dest_equals o Thm.prop_of)
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   171
      |> Logic.strip_imp_concl
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   172
      |> (snd o cert_def ctxt)
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   173
      |> abs_def;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   174
    fun prove ctxt' t def =
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   175
      let
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   176
        val thy' = ProofContext.theory_of ctxt';
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   177
        val prop' = Term.subst_atomic [(Free (c, T), t)] prop;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   178
        val frees = Term.fold_aterms (fn Free (x, _) =>
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   179
          if ProofContext.is_fixed ctxt' x then I else insert (op =) x | _ => I) prop' [];
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   180
      in
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   181
        Goal.prove thy' frees [] prop' (K (ALLGOALS
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   182
          (meta_rewrite_tac ctxt' THEN'
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   183
            Tactic.rewrite_goal_tac [def] THEN'
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   184
            Tactic.resolve_tac [Drule.reflexive_thm])))
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   185
        handle ERROR msg => cat_error msg "Failed to prove definitional specification."
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   186
      end;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   187
  in (((c, T), rhs), prove) end;
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   188
ce16e2bad548 added attributes defn_add/del;
wenzelm
parents: 18830
diff changeset
   189
18830
34b51dcdc570 Basic operations on local definitions.
wenzelm
parents:
diff changeset
   190
end;