src/Pure/drule.ML
author wenzelm
Fri Jul 09 16:54:54 1999 +0200 (1999-07-09 ago)
changeset 6946 309276732ee1
parent 6930 4b40fb299f9f
child 6995 d824a86266a9
permissions -rw-r--r--
added compose_single;
wenzelm@252
     1
(*  Title:      Pure/drule.ML
clasohm@0
     2
    ID:         $Id$
wenzelm@252
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1993  University of Cambridge
clasohm@0
     5
wenzelm@3766
     6
Derived rules and other operations on theorems.
clasohm@0
     7
*)
clasohm@0
     8
lcp@11
     9
infix 0 RS RSN RL RLN MRS MRL COMP;
clasohm@0
    10
wenzelm@5903
    11
signature BASIC_DRULE =
wenzelm@3766
    12
sig
wenzelm@4285
    13
  val dest_implies      : cterm -> cterm * cterm
wenzelm@4285
    14
  val skip_flexpairs	: cterm -> cterm
wenzelm@4285
    15
  val strip_imp_prems	: cterm -> cterm list
clasohm@1460
    16
  val cprems_of		: thm -> cterm list
wenzelm@4285
    17
  val read_insts	:
wenzelm@4285
    18
          Sign.sg -> (indexname -> typ option) * (indexname -> sort option)
wenzelm@4285
    19
                  -> (indexname -> typ option) * (indexname -> sort option)
wenzelm@4285
    20
                  -> string list -> (string*string)list
wenzelm@4285
    21
                  -> (indexname*ctyp)list * (cterm*cterm)list
wenzelm@4285
    22
  val types_sorts: thm -> (indexname-> typ option) * (indexname-> sort option)
clasohm@1460
    23
  val forall_intr_list	: cterm list -> thm -> thm
clasohm@1460
    24
  val forall_intr_frees	: thm -> thm
clasohm@1460
    25
  val forall_intr_vars	: thm -> thm
clasohm@1460
    26
  val forall_elim_list	: cterm list -> thm -> thm
clasohm@1460
    27
  val forall_elim_var	: int -> thm -> thm
clasohm@1460
    28
  val forall_elim_vars	: int -> thm -> thm
paulson@4610
    29
  val freeze_thaw	: thm -> thm * (thm -> thm)
clasohm@1460
    30
  val implies_elim_list	: thm -> thm list -> thm
clasohm@1460
    31
  val implies_intr_list	: cterm list -> thm -> thm
wenzelm@4285
    32
  val zero_var_indexes	: thm -> thm
wenzelm@4285
    33
  val standard		: thm -> thm
paulson@4610
    34
  val rotate_prems      : int -> thm -> thm
wenzelm@4285
    35
  val assume_ax		: theory -> string -> thm
wenzelm@4285
    36
  val RSN		: thm * (int * thm) -> thm
wenzelm@4285
    37
  val RS		: thm * thm -> thm
wenzelm@4285
    38
  val RLN		: thm list * (int * thm list) -> thm list
wenzelm@4285
    39
  val RL		: thm list * thm list -> thm list
wenzelm@4285
    40
  val MRS		: thm list * thm -> thm
clasohm@1460
    41
  val MRL		: thm list list * thm list -> thm list
wenzelm@4285
    42
  val compose		: thm * int * thm -> thm list
wenzelm@4285
    43
  val COMP		: thm * thm -> thm
clasohm@0
    44
  val read_instantiate_sg: Sign.sg -> (string*string)list -> thm -> thm
wenzelm@4285
    45
  val read_instantiate	: (string*string)list -> thm -> thm
wenzelm@4285
    46
  val cterm_instantiate	: (cterm*cterm)list -> thm -> thm
wenzelm@4285
    47
  val weak_eq_thm	: thm * thm -> bool
wenzelm@4285
    48
  val eq_thm_sg		: thm * thm -> bool
wenzelm@4285
    49
  val size_of_thm	: thm -> int
clasohm@1460
    50
  val reflexive_thm	: thm
wenzelm@4285
    51
  val symmetric_thm	: thm
wenzelm@4285
    52
  val transitive_thm	: thm
paulson@2004
    53
  val refl_implies      : thm
nipkow@4679
    54
  val symmetric_fun     : thm -> thm
wenzelm@3575
    55
  val rewrite_rule_aux	: (meta_simpset -> thm -> thm option) -> thm list -> thm -> thm
nipkow@4713
    56
  val rewrite_thm	: bool * bool * bool
nipkow@4713
    57
                          -> (meta_simpset -> thm -> thm option)
nipkow@4713
    58
                          -> meta_simpset -> thm -> thm
wenzelm@5079
    59
  val rewrite_cterm	: bool * bool * bool
wenzelm@5079
    60
                          -> (meta_simpset -> thm -> thm option)
wenzelm@5079
    61
                          -> meta_simpset -> cterm -> thm
wenzelm@4285
    62
  val rewrite_goals_rule_aux: (meta_simpset -> thm -> thm option) -> thm list -> thm -> thm
nipkow@4713
    63
  val rewrite_goal_rule	: bool* bool * bool
nipkow@4713
    64
                          -> (meta_simpset -> thm -> thm option)
nipkow@4713
    65
                          -> meta_simpset -> int -> thm -> thm
wenzelm@4285
    66
  val equal_abs_elim	: cterm  -> thm -> thm
wenzelm@4285
    67
  val equal_abs_elim_list: cterm list -> thm -> thm
wenzelm@4285
    68
  val flexpair_abs_elim_list: cterm list -> thm -> thm
wenzelm@4285
    69
  val asm_rl		: thm
wenzelm@4285
    70
  val cut_rl		: thm
wenzelm@4285
    71
  val revcut_rl		: thm
wenzelm@4285
    72
  val thin_rl		: thm
wenzelm@4285
    73
  val triv_forall_equality: thm
nipkow@1756
    74
  val swap_prems_rl     : thm
wenzelm@4285
    75
  val equal_intr_rule   : thm
wenzelm@5903
    76
  val instantiate'	: ctyp option list -> cterm option list -> thm -> thm
wenzelm@6435
    77
  val incr_indexes	: int -> thm -> thm
wenzelm@6435
    78
  val incr_indexes_wrt	: int list -> ctyp list -> cterm list -> thm list -> thm -> thm
wenzelm@5903
    79
end;
wenzelm@5903
    80
wenzelm@5903
    81
signature DRULE =
wenzelm@5903
    82
sig
wenzelm@5903
    83
  include BASIC_DRULE
wenzelm@6946
    84
  val compose_single	: thm * int * thm -> thm
paulson@5311
    85
  val triv_goal		: thm
paulson@5311
    86
  val rev_triv_goal	: thm
paulson@5311
    87
  val mk_triv_goal      : cterm -> thm
wenzelm@5903
    88
  val tvars_of_terms	: term list -> (indexname * sort) list
wenzelm@5903
    89
  val vars_of_terms	: term list -> (indexname * typ) list
wenzelm@5903
    90
  val tvars_of		: thm -> (indexname * sort) list
wenzelm@5903
    91
  val vars_of		: thm -> (indexname * typ) list
wenzelm@5688
    92
  val unvarifyT		: thm -> thm
wenzelm@5688
    93
  val unvarify		: thm -> thm
wenzelm@6086
    94
  val rule_attribute	: ('a -> thm -> thm) -> 'a attribute
wenzelm@6086
    95
  val tag		: tag -> 'a attribute
wenzelm@6086
    96
  val untag		: tag -> 'a attribute
wenzelm@6086
    97
  val tag_lemma		: 'a attribute
wenzelm@6086
    98
  val tag_assumption	: 'a attribute
wenzelm@6086
    99
  val tag_internal	: 'a attribute
wenzelm@3766
   100
end;
clasohm@0
   101
wenzelm@5903
   102
structure Drule: DRULE =
clasohm@0
   103
struct
clasohm@0
   104
wenzelm@3991
   105
lcp@708
   106
(** some cterm->cterm operations: much faster than calling cterm_of! **)
lcp@708
   107
paulson@2004
   108
(** SAME NAMES as in structure Logic: use compound identifiers! **)
paulson@2004
   109
clasohm@1703
   110
(*dest_implies for cterms. Note T=prop below*)
paulson@2004
   111
fun dest_implies ct =
paulson@2004
   112
    case term_of ct of 
paulson@2004
   113
	(Const("==>", _) $ _ $ _) => 
paulson@2004
   114
	    let val (ct1,ct2) = dest_comb ct
paulson@2004
   115
	    in  (#2 (dest_comb ct1), ct2)  end	     
paulson@2004
   116
      | _ => raise TERM ("dest_implies", [term_of ct]) ;
clasohm@1703
   117
clasohm@1703
   118
lcp@708
   119
(*Discard flexflex pairs; return a cterm*)
paulson@2004
   120
fun skip_flexpairs ct =
lcp@708
   121
    case term_of ct of
clasohm@1460
   122
	(Const("==>", _) $ (Const("=?=",_)$_$_) $ _) =>
paulson@2004
   123
	    skip_flexpairs (#2 (dest_implies ct))
lcp@708
   124
      | _ => ct;
lcp@708
   125
lcp@708
   126
(* A1==>...An==>B  goes to  [A1,...,An], where B is not an implication *)
paulson@2004
   127
fun strip_imp_prems ct =
paulson@2004
   128
    let val (cA,cB) = dest_implies ct
paulson@2004
   129
    in  cA :: strip_imp_prems cB  end
lcp@708
   130
    handle TERM _ => [];
lcp@708
   131
paulson@2004
   132
(* A1==>...An==>B  goes to B, where B is not an implication *)
paulson@2004
   133
fun strip_imp_concl ct =
paulson@2004
   134
    case term_of ct of (Const("==>", _) $ _ $ _) => 
paulson@2004
   135
	strip_imp_concl (#2 (dest_comb ct))
paulson@2004
   136
  | _ => ct;
paulson@2004
   137
lcp@708
   138
(*The premises of a theorem, as a cterm list*)
paulson@2004
   139
val cprems_of = strip_imp_prems o skip_flexpairs o cprop_of;
lcp@708
   140
lcp@708
   141
lcp@229
   142
(** reading of instantiations **)
lcp@229
   143
lcp@229
   144
fun absent ixn =
lcp@229
   145
  error("No such variable in term: " ^ Syntax.string_of_vname ixn);
lcp@229
   146
lcp@229
   147
fun inst_failure ixn =
lcp@229
   148
  error("Instantiation of " ^ Syntax.string_of_vname ixn ^ " fails");
lcp@229
   149
nipkow@4281
   150
fun read_insts sign (rtypes,rsorts) (types,sorts) used insts =
nipkow@4281
   151
let val {tsig,...} = Sign.rep_sg sign
nipkow@4281
   152
    fun split([],tvs,vs) = (tvs,vs)
wenzelm@4691
   153
      | split((sv,st)::l,tvs,vs) = (case Symbol.explode sv of
wenzelm@4691
   154
                  "'"::cs => split(l,(Syntax.indexname cs,st)::tvs,vs)
wenzelm@4691
   155
                | cs => split(l,tvs,(Syntax.indexname cs,st)::vs));
nipkow@4281
   156
    val (tvs,vs) = split(insts,[],[]);
nipkow@4281
   157
    fun readT((a,i),st) =
nipkow@4281
   158
        let val ixn = ("'" ^ a,i);
nipkow@4281
   159
            val S = case rsorts ixn of Some S => S | None => absent ixn;
nipkow@4281
   160
            val T = Sign.read_typ (sign,sorts) st;
nipkow@4281
   161
        in if Type.typ_instance(tsig,T,TVar(ixn,S)) then (ixn,T)
nipkow@4281
   162
           else inst_failure ixn
nipkow@4281
   163
        end
nipkow@4281
   164
    val tye = map readT tvs;
nipkow@4281
   165
    fun mkty(ixn,st) = (case rtypes ixn of
nipkow@4281
   166
                          Some T => (ixn,(st,typ_subst_TVars tye T))
nipkow@4281
   167
                        | None => absent ixn);
nipkow@4281
   168
    val ixnsTs = map mkty vs;
nipkow@4281
   169
    val ixns = map fst ixnsTs
nipkow@4281
   170
    and sTs  = map snd ixnsTs
nipkow@4281
   171
    val (cts,tye2) = read_def_cterms(sign,types,sorts) used false sTs;
nipkow@4281
   172
    fun mkcVar(ixn,T) =
nipkow@4281
   173
        let val U = typ_subst_TVars tye2 T
nipkow@4281
   174
        in cterm_of sign (Var(ixn,U)) end
nipkow@4281
   175
    val ixnTs = ListPair.zip(ixns, map snd sTs)
nipkow@4281
   176
in (map (fn (ixn,T) => (ixn,ctyp_of sign T)) (tye2 @ tye),
nipkow@4281
   177
    ListPair.zip(map mkcVar ixnTs,cts))
nipkow@4281
   178
end;
lcp@229
   179
lcp@229
   180
wenzelm@252
   181
(*** Find the type (sort) associated with a (T)Var or (T)Free in a term
clasohm@0
   182
     Used for establishing default types (of variables) and sorts (of
clasohm@0
   183
     type variables) when reading another term.
clasohm@0
   184
     Index -1 indicates that a (T)Free rather than a (T)Var is wanted.
clasohm@0
   185
***)
clasohm@0
   186
clasohm@0
   187
fun types_sorts thm =
clasohm@0
   188
    let val {prop,hyps,...} = rep_thm thm;
wenzelm@252
   189
        val big = list_comb(prop,hyps); (* bogus term! *)
wenzelm@252
   190
        val vars = map dest_Var (term_vars big);
wenzelm@252
   191
        val frees = map dest_Free (term_frees big);
wenzelm@252
   192
        val tvars = term_tvars big;
wenzelm@252
   193
        val tfrees = term_tfrees big;
wenzelm@252
   194
        fun typ(a,i) = if i<0 then assoc(frees,a) else assoc(vars,(a,i));
wenzelm@252
   195
        fun sort(a,i) = if i<0 then assoc(tfrees,a) else assoc(tvars,(a,i));
clasohm@0
   196
    in (typ,sort) end;
clasohm@0
   197
clasohm@0
   198
(** Standardization of rules **)
clasohm@0
   199
clasohm@0
   200
(*Generalization over a list of variables, IGNORING bad ones*)
clasohm@0
   201
fun forall_intr_list [] th = th
clasohm@0
   202
  | forall_intr_list (y::ys) th =
wenzelm@252
   203
        let val gth = forall_intr_list ys th
wenzelm@252
   204
        in  forall_intr y gth   handle THM _ =>  gth  end;
clasohm@0
   205
clasohm@0
   206
(*Generalization over all suitable Free variables*)
clasohm@0
   207
fun forall_intr_frees th =
clasohm@0
   208
    let val {prop,sign,...} = rep_thm th
clasohm@0
   209
    in  forall_intr_list
wenzelm@4440
   210
         (map (cterm_of sign) (sort (make_ord atless) (term_frees prop)))
clasohm@0
   211
         th
clasohm@0
   212
    end;
clasohm@0
   213
clasohm@0
   214
(*Replace outermost quantified variable by Var of given index.
clasohm@0
   215
    Could clash with Vars already present.*)
wenzelm@252
   216
fun forall_elim_var i th =
clasohm@0
   217
    let val {prop,sign,...} = rep_thm th
clasohm@0
   218
    in case prop of
wenzelm@252
   219
          Const("all",_) $ Abs(a,T,_) =>
wenzelm@252
   220
              forall_elim (cterm_of sign (Var((a,i), T)))  th
wenzelm@252
   221
        | _ => raise THM("forall_elim_var", i, [th])
clasohm@0
   222
    end;
clasohm@0
   223
clasohm@0
   224
(*Repeat forall_elim_var until all outer quantifiers are removed*)
wenzelm@252
   225
fun forall_elim_vars i th =
clasohm@0
   226
    forall_elim_vars i (forall_elim_var i th)
wenzelm@252
   227
        handle THM _ => th;
clasohm@0
   228
clasohm@0
   229
(*Specialization over a list of cterms*)
clasohm@0
   230
fun forall_elim_list cts th = foldr (uncurry forall_elim) (rev cts, th);
clasohm@0
   231
clasohm@0
   232
(* maps [A1,...,An], B   to   [| A1;...;An |] ==> B  *)
clasohm@0
   233
fun implies_intr_list cAs th = foldr (uncurry implies_intr) (cAs,th);
clasohm@0
   234
clasohm@0
   235
(* maps [| A1;...;An |] ==> B and [A1,...,An]   to   B *)
clasohm@0
   236
fun implies_elim_list impth ths = foldl (uncurry implies_elim) (impth,ths);
clasohm@0
   237
clasohm@0
   238
(*Reset Var indexes to zero, renaming to preserve distinctness*)
wenzelm@252
   239
fun zero_var_indexes th =
clasohm@0
   240
    let val {prop,sign,...} = rep_thm th;
clasohm@0
   241
        val vars = term_vars prop
clasohm@0
   242
        val bs = foldl add_new_id ([], map (fn Var((a,_),_)=>a) vars)
wenzelm@252
   243
        val inrs = add_term_tvars(prop,[]);
wenzelm@252
   244
        val nms' = rev(foldl add_new_id ([], map (#1 o #1) inrs));
paulson@2266
   245
        val tye = ListPair.map (fn ((v,rs),a) => (v, TVar((a,0),rs)))
paulson@2266
   246
	             (inrs, nms')
wenzelm@252
   247
        val ctye = map (fn (v,T) => (v,ctyp_of sign T)) tye;
wenzelm@252
   248
        fun varpairs([],[]) = []
wenzelm@252
   249
          | varpairs((var as Var(v,T)) :: vars, b::bs) =
wenzelm@252
   250
                let val T' = typ_subst_TVars tye T
wenzelm@252
   251
                in (cterm_of sign (Var(v,T')),
wenzelm@252
   252
                    cterm_of sign (Var((b,0),T'))) :: varpairs(vars,bs)
wenzelm@252
   253
                end
wenzelm@252
   254
          | varpairs _ = raise TERM("varpairs", []);
clasohm@0
   255
    in instantiate (ctye, varpairs(vars,rev bs)) th end;
clasohm@0
   256
clasohm@0
   257
clasohm@0
   258
(*Standard form of object-rule: no hypotheses, Frees, or outer quantifiers;
clasohm@0
   259
    all generality expressed by Vars having index 0.*)
clasohm@0
   260
fun standard th =
wenzelm@1218
   261
  let val {maxidx,...} = rep_thm th
wenzelm@1237
   262
  in
wenzelm@1218
   263
    th |> implies_intr_hyps
paulson@1412
   264
       |> forall_intr_frees |> forall_elim_vars (maxidx + 1)
wenzelm@1439
   265
       |> Thm.strip_shyps |> Thm.implies_intr_shyps
paulson@1412
   266
       |> zero_var_indexes |> Thm.varifyT |> Thm.compress
wenzelm@1218
   267
  end;
wenzelm@1218
   268
clasohm@0
   269
paulson@4610
   270
(*Convert all Vars in a theorem to Frees.  Also return a function for 
paulson@4610
   271
  reversing that operation.  DOES NOT WORK FOR TYPE VARIABLES.
paulson@4610
   272
  Similar code in type/freeze_thaw*)
paulson@4610
   273
fun freeze_thaw th =
paulson@4610
   274
  let val fth = freezeT th
paulson@4610
   275
      val {prop,sign,...} = rep_thm fth
paulson@4610
   276
      val used = add_term_names (prop, [])
paulson@4610
   277
      and vars = term_vars prop
paulson@4610
   278
      fun newName (Var(ix,_), (pairs,used)) = 
paulson@4610
   279
	    let val v = variant used (string_of_indexname ix)
paulson@4610
   280
	    in  ((ix,v)::pairs, v::used)  end;
paulson@4610
   281
      val (alist, _) = foldr newName (vars, ([], used))
paulson@4610
   282
      fun mk_inst (Var(v,T)) = 
paulson@4610
   283
	  (cterm_of sign (Var(v,T)),
paulson@4610
   284
	   cterm_of sign (Free(the (assoc(alist,v)), T)))
paulson@4610
   285
      val insts = map mk_inst vars
paulson@4610
   286
      fun thaw th' = 
paulson@4610
   287
	  th' |> forall_intr_list (map #2 insts)
paulson@4610
   288
	      |> forall_elim_list (map #1 insts)
paulson@4610
   289
  in  (instantiate ([],insts) fth, thaw)  end;
paulson@4610
   290
paulson@4610
   291
paulson@4610
   292
(*Rotates a rule's premises to the left by k.  Does nothing if k=0 or
paulson@4610
   293
  if k equals the number of premises.  Useful, for instance, with etac.
paulson@4610
   294
  Similar to tactic/defer_tac*)
paulson@4610
   295
fun rotate_prems k rl = 
paulson@4610
   296
    let val (rl',thaw) = freeze_thaw rl
paulson@4610
   297
	val hyps = strip_imp_prems (adjust_maxidx (cprop_of rl'))
paulson@4610
   298
	val hyps' = List.drop(hyps, k)
paulson@4610
   299
    in  implies_elim_list rl' (map assume hyps)
paulson@4610
   300
        |> implies_intr_list (hyps' @ List.take(hyps, k))
paulson@4610
   301
        |> thaw |> varifyT
paulson@4610
   302
    end;
paulson@4610
   303
paulson@4610
   304
wenzelm@252
   305
(*Assume a new formula, read following the same conventions as axioms.
clasohm@0
   306
  Generalizes over Free variables,
clasohm@0
   307
  creates the assumption, and then strips quantifiers.
clasohm@0
   308
  Example is [| ALL x:?A. ?P(x) |] ==> [| ?P(?a) |]
wenzelm@252
   309
             [ !(A,P,a)[| ALL x:A. P(x) |] ==> [| P(a) |] ]    *)
clasohm@0
   310
fun assume_ax thy sP =
wenzelm@6390
   311
    let val sign = Theory.sign_of thy
paulson@4610
   312
        val prop = Logic.close_form (term_of (read_cterm sign (sP, propT)))
lcp@229
   313
    in forall_elim_vars 0 (assume (cterm_of sign prop))  end;
clasohm@0
   314
wenzelm@252
   315
(*Resolution: exactly one resolvent must be produced.*)
clasohm@0
   316
fun tha RSN (i,thb) =
wenzelm@4270
   317
  case Seq.chop (2, biresolution false [(false,tha)] i thb) of
clasohm@0
   318
      ([th],_) => th
clasohm@0
   319
    | ([],_)   => raise THM("RSN: no unifiers", i, [tha,thb])
clasohm@0
   320
    |      _   => raise THM("RSN: multiple unifiers", i, [tha,thb]);
clasohm@0
   321
clasohm@0
   322
(*resolution: P==>Q, Q==>R gives P==>R. *)
clasohm@0
   323
fun tha RS thb = tha RSN (1,thb);
clasohm@0
   324
clasohm@0
   325
(*For joining lists of rules*)
wenzelm@252
   326
fun thas RLN (i,thbs) =
clasohm@0
   327
  let val resolve = biresolution false (map (pair false) thas) i
wenzelm@4270
   328
      fun resb thb = Seq.list_of (resolve thb) handle THM _ => []
paulson@2672
   329
  in  List.concat (map resb thbs)  end;
clasohm@0
   330
clasohm@0
   331
fun thas RL thbs = thas RLN (1,thbs);
clasohm@0
   332
lcp@11
   333
(*Resolve a list of rules against bottom_rl from right to left;
lcp@11
   334
  makes proof trees*)
wenzelm@252
   335
fun rls MRS bottom_rl =
lcp@11
   336
  let fun rs_aux i [] = bottom_rl
wenzelm@252
   337
        | rs_aux i (rl::rls) = rl RSN (i, rs_aux (i+1) rls)
lcp@11
   338
  in  rs_aux 1 rls  end;
lcp@11
   339
lcp@11
   340
(*As above, but for rule lists*)
wenzelm@252
   341
fun rlss MRL bottom_rls =
lcp@11
   342
  let fun rs_aux i [] = bottom_rls
wenzelm@252
   343
        | rs_aux i (rls::rlss) = rls RLN (i, rs_aux (i+1) rlss)
lcp@11
   344
  in  rs_aux 1 rlss  end;
lcp@11
   345
wenzelm@252
   346
(*compose Q and [...,Qi,Q(i+1),...]==>R to [...,Q(i+1),...]==>R
clasohm@0
   347
  with no lifting or renaming!  Q may contain ==> or meta-quants
clasohm@0
   348
  ALWAYS deletes premise i *)
wenzelm@252
   349
fun compose(tha,i,thb) =
wenzelm@4270
   350
    Seq.list_of (bicompose false (false,tha,0) i thb);
clasohm@0
   351
wenzelm@6946
   352
fun compose_single (tha,i,thb) =
wenzelm@6946
   353
  (case compose (tha,i,thb) of
wenzelm@6946
   354
    [th] => th
wenzelm@6946
   355
  | _ => raise THM ("compose: unique result expected", i, [tha,thb]));
wenzelm@6946
   356
clasohm@0
   357
(*compose Q and [Q1,Q2,...,Qk]==>R to [Q2,...,Qk]==>R getting unique result*)
clasohm@0
   358
fun tha COMP thb =
clasohm@0
   359
    case compose(tha,1,thb) of
wenzelm@252
   360
        [th] => th
clasohm@0
   361
      | _ =>   raise THM("COMP", 1, [tha,thb]);
clasohm@0
   362
clasohm@0
   363
(*Instantiate theorem th, reading instantiations under signature sg*)
clasohm@0
   364
fun read_instantiate_sg sg sinsts th =
clasohm@0
   365
    let val ts = types_sorts th;
nipkow@952
   366
        val used = add_term_tvarnames(#prop(rep_thm th),[]);
nipkow@952
   367
    in  instantiate (read_insts sg ts ts used sinsts) th  end;
clasohm@0
   368
clasohm@0
   369
(*Instantiate theorem th, reading instantiations under theory of th*)
clasohm@0
   370
fun read_instantiate sinsts th =
clasohm@0
   371
    read_instantiate_sg (#sign (rep_thm th)) sinsts th;
clasohm@0
   372
clasohm@0
   373
clasohm@0
   374
(*Left-to-right replacements: tpairs = [...,(vi,ti),...].
clasohm@0
   375
  Instantiates distinct Vars by terms, inferring type instantiations. *)
clasohm@0
   376
local
nipkow@1435
   377
  fun add_types ((ct,cu), (sign,tye,maxidx)) =
paulson@2152
   378
    let val {sign=signt, t=t, T= T, maxidx=maxt,...} = rep_cterm ct
paulson@2152
   379
        and {sign=signu, t=u, T= U, maxidx=maxu,...} = rep_cterm cu;
paulson@2152
   380
        val maxi = Int.max(maxidx, Int.max(maxt, maxu));
clasohm@0
   381
        val sign' = Sign.merge(sign, Sign.merge(signt, signu))
nipkow@1435
   382
        val (tye',maxi') = Type.unify (#tsig(Sign.rep_sg sign')) maxi tye (T,U)
wenzelm@252
   383
          handle Type.TUNIFY => raise TYPE("add_types", [T,U], [t,u])
nipkow@1435
   384
    in  (sign', tye', maxi')  end;
clasohm@0
   385
in
wenzelm@252
   386
fun cterm_instantiate ctpairs0 th =
nipkow@1435
   387
  let val (sign,tye,_) = foldr add_types (ctpairs0, (#sign(rep_thm th),[],0))
clasohm@0
   388
      val tsig = #tsig(Sign.rep_sg sign);
clasohm@0
   389
      fun instT(ct,cu) = let val inst = subst_TVars tye
wenzelm@252
   390
                         in (cterm_fun inst ct, cterm_fun inst cu) end
lcp@229
   391
      fun ctyp2 (ix,T) = (ix, ctyp_of sign T)
clasohm@0
   392
  in  instantiate (map ctyp2 tye, map instT ctpairs0) th  end
wenzelm@252
   393
  handle TERM _ =>
clasohm@0
   394
           raise THM("cterm_instantiate: incompatible signatures",0,[th])
wenzelm@6930
   395
       | TYPE (msg, _, _) => raise THM(msg, 0, [th])
clasohm@0
   396
end;
clasohm@0
   397
clasohm@0
   398
wenzelm@4016
   399
(** theorem equality **)
clasohm@0
   400
clasohm@0
   401
(*Do the two theorems have the same signature?*)
wenzelm@252
   402
fun eq_thm_sg (th1,th2) = Sign.eq_sg(#sign(rep_thm th1), #sign(rep_thm th2));
clasohm@0
   403
clasohm@0
   404
(*Useful "distance" function for BEST_FIRST*)
clasohm@0
   405
val size_of_thm = size_of_term o #prop o rep_thm;
clasohm@0
   406
clasohm@0
   407
lcp@1194
   408
(** Mark Staples's weaker version of eq_thm: ignores variable renaming and
lcp@1194
   409
    (some) type variable renaming **)
lcp@1194
   410
lcp@1194
   411
 (* Can't use term_vars, because it sorts the resulting list of variable names.
lcp@1194
   412
    We instead need the unique list noramlised by the order of appearance
lcp@1194
   413
    in the term. *)
lcp@1194
   414
fun term_vars' (t as Var(v,T)) = [t]
lcp@1194
   415
  | term_vars' (Abs(_,_,b)) = term_vars' b
lcp@1194
   416
  | term_vars' (f$a) = (term_vars' f) @ (term_vars' a)
lcp@1194
   417
  | term_vars' _ = [];
lcp@1194
   418
lcp@1194
   419
fun forall_intr_vars th =
lcp@1194
   420
  let val {prop,sign,...} = rep_thm th;
lcp@1194
   421
      val vars = distinct (term_vars' prop);
lcp@1194
   422
  in forall_intr_list (map (cterm_of sign) vars) th end;
lcp@1194
   423
wenzelm@1237
   424
fun weak_eq_thm (tha,thb) =
lcp@1194
   425
    eq_thm(forall_intr_vars (freezeT tha), forall_intr_vars (freezeT thb));
lcp@1194
   426
lcp@1194
   427
lcp@1194
   428
clasohm@0
   429
(*** Meta-Rewriting Rules ***)
clasohm@0
   430
wenzelm@6390
   431
val proto_sign = Theory.sign_of ProtoPure.thy;
paulson@4610
   432
paulson@4610
   433
fun read_prop s = read_cterm proto_sign (s, propT);
paulson@4610
   434
wenzelm@4016
   435
fun store_thm name thm = PureThy.smart_store_thm (name, standard thm);
wenzelm@4016
   436
clasohm@0
   437
val reflexive_thm =
paulson@4610
   438
  let val cx = cterm_of proto_sign (Var(("x",0),TVar(("'a",0),logicS)))
wenzelm@4016
   439
  in store_thm "reflexive" (Thm.reflexive cx) end;
clasohm@0
   440
clasohm@0
   441
val symmetric_thm =
paulson@4610
   442
  let val xy = read_prop "x::'a::logic == y"
paulson@4610
   443
  in store_thm "symmetric" 
paulson@4610
   444
      (Thm.implies_intr_hyps(Thm.symmetric(Thm.assume xy)))
paulson@4610
   445
   end;
clasohm@0
   446
clasohm@0
   447
val transitive_thm =
paulson@4610
   448
  let val xy = read_prop "x::'a::logic == y"
paulson@4610
   449
      val yz = read_prop "y::'a::logic == z"
clasohm@0
   450
      val xythm = Thm.assume xy and yzthm = Thm.assume yz
paulson@4610
   451
  in store_thm "transitive" (Thm.implies_intr yz (Thm.transitive xythm yzthm))
paulson@4610
   452
  end;
clasohm@0
   453
nipkow@4679
   454
fun symmetric_fun thm = thm RS symmetric_thm;
nipkow@4679
   455
lcp@229
   456
(** Below, a "conversion" has type cterm -> thm **)
lcp@229
   457
paulson@4610
   458
val refl_implies = reflexive (cterm_of proto_sign implies);
clasohm@0
   459
clasohm@0
   460
(*In [A1,...,An]==>B, rewrite the selected A's only -- for rewrite_goals_tac*)
nipkow@214
   461
(*Do not rewrite flex-flex pairs*)
wenzelm@252
   462
fun goals_conv pred cv =
lcp@229
   463
  let fun gconv i ct =
paulson@2004
   464
        let val (A,B) = dest_implies ct
lcp@229
   465
            val (thA,j) = case term_of A of
lcp@229
   466
                  Const("=?=",_)$_$_ => (reflexive A, i)
lcp@229
   467
                | _ => (if pred i then cv A else reflexive A, i+1)
paulson@2004
   468
        in  combination (combination refl_implies thA) (gconv j B) end
lcp@229
   469
        handle TERM _ => reflexive ct
clasohm@0
   470
  in gconv 1 end;
clasohm@0
   471
clasohm@0
   472
(*Use a conversion to transform a theorem*)
lcp@229
   473
fun fconv_rule cv th = equal_elim (cv (cprop_of th)) th;
clasohm@0
   474
clasohm@0
   475
(*rewriting conversion*)
lcp@229
   476
fun rew_conv mode prover mss = rewrite_cterm mode mss prover;
clasohm@0
   477
clasohm@0
   478
(*Rewrite a theorem*)
wenzelm@3575
   479
fun rewrite_rule_aux _ []   th = th
wenzelm@3575
   480
  | rewrite_rule_aux prover thms th =
nipkow@4713
   481
      fconv_rule (rew_conv (true,false,false) prover (Thm.mss_of thms)) th;
clasohm@0
   482
wenzelm@3555
   483
fun rewrite_thm mode prover mss = fconv_rule (rew_conv mode prover mss);
wenzelm@5079
   484
fun rewrite_cterm mode prover mss = Thm.rewrite_cterm mode mss prover;
wenzelm@3555
   485
clasohm@0
   486
(*Rewrite the subgoals of a proof state (represented by a theorem) *)
wenzelm@3575
   487
fun rewrite_goals_rule_aux _ []   th = th
wenzelm@3575
   488
  | rewrite_goals_rule_aux prover thms th =
nipkow@4713
   489
      fconv_rule (goals_conv (K true) (rew_conv (true, true, false) prover
wenzelm@3575
   490
        (Thm.mss_of thms))) th;
clasohm@0
   491
clasohm@0
   492
(*Rewrite the subgoal of a proof state (represented by a theorem) *)
nipkow@214
   493
fun rewrite_goal_rule mode prover mss i thm =
nipkow@214
   494
  if 0 < i  andalso  i <= nprems_of thm
nipkow@214
   495
  then fconv_rule (goals_conv (fn j => j=i) (rew_conv mode prover mss)) thm
nipkow@214
   496
  else raise THM("rewrite_goal_rule",i,[thm]);
clasohm@0
   497
clasohm@0
   498
clasohm@0
   499
(** Derived rules mainly for METAHYPS **)
clasohm@0
   500
clasohm@0
   501
(*Given the term "a", takes (%x.t)==(%x.u) to t[a/x]==u[a/x]*)
clasohm@0
   502
fun equal_abs_elim ca eqth =
lcp@229
   503
  let val {sign=signa, t=a, ...} = rep_cterm ca
clasohm@0
   504
      and combth = combination eqth (reflexive ca)
clasohm@0
   505
      val {sign,prop,...} = rep_thm eqth
clasohm@0
   506
      val (abst,absu) = Logic.dest_equals prop
lcp@229
   507
      val cterm = cterm_of (Sign.merge (sign,signa))
clasohm@0
   508
  in  transitive (symmetric (beta_conversion (cterm (abst$a))))
clasohm@0
   509
           (transitive combth (beta_conversion (cterm (absu$a))))
clasohm@0
   510
  end
clasohm@0
   511
  handle THM _ => raise THM("equal_abs_elim", 0, [eqth]);
clasohm@0
   512
clasohm@0
   513
(*Calling equal_abs_elim with multiple terms*)
clasohm@0
   514
fun equal_abs_elim_list cts th = foldr (uncurry equal_abs_elim) (rev cts, th);
clasohm@0
   515
clasohm@0
   516
local
clasohm@0
   517
  val alpha = TVar(("'a",0), [])     (*  type ?'a::{}  *)
clasohm@0
   518
  fun err th = raise THM("flexpair_inst: ", 0, [th])
clasohm@0
   519
  fun flexpair_inst def th =
clasohm@0
   520
    let val {prop = Const _ $ t $ u,  sign,...} = rep_thm th
wenzelm@252
   521
        val cterm = cterm_of sign
wenzelm@252
   522
        fun cvar a = cterm(Var((a,0),alpha))
wenzelm@252
   523
        val def' = cterm_instantiate [(cvar"t", cterm t), (cvar"u", cterm u)]
wenzelm@252
   524
                   def
clasohm@0
   525
    in  equal_elim def' th
clasohm@0
   526
    end
clasohm@0
   527
    handle THM _ => err th | bind => err th
clasohm@0
   528
in
wenzelm@3991
   529
val flexpair_intr = flexpair_inst (symmetric ProtoPure.flexpair_def)
wenzelm@3991
   530
and flexpair_elim = flexpair_inst ProtoPure.flexpair_def
clasohm@0
   531
end;
clasohm@0
   532
clasohm@0
   533
(*Version for flexflex pairs -- this supports lifting.*)
wenzelm@252
   534
fun flexpair_abs_elim_list cts =
clasohm@0
   535
    flexpair_intr o equal_abs_elim_list cts o flexpair_elim;
clasohm@0
   536
clasohm@0
   537
clasohm@0
   538
(*** Some useful meta-theorems ***)
clasohm@0
   539
clasohm@0
   540
(*The rule V/V, obtains assumption solving for eresolve_tac*)
wenzelm@4016
   541
val asm_rl =
paulson@4610
   542
  store_thm "asm_rl" (trivial(read_prop "PROP ?psi"));
clasohm@0
   543
clasohm@0
   544
(*Meta-level cut rule: [| V==>W; V |] ==> W *)
wenzelm@4016
   545
val cut_rl =
wenzelm@4016
   546
  store_thm "cut_rl"
paulson@4610
   547
    (trivial(read_prop "PROP ?psi ==> PROP ?theta"));
clasohm@0
   548
wenzelm@252
   549
(*Generalized elim rule for one conclusion; cut_rl with reversed premises:
clasohm@0
   550
     [| PROP V;  PROP V ==> PROP W |] ==> PROP W *)
clasohm@0
   551
val revcut_rl =
paulson@4610
   552
  let val V = read_prop "PROP V"
paulson@4610
   553
      and VW = read_prop "PROP V ==> PROP W";
wenzelm@4016
   554
  in
wenzelm@4016
   555
    store_thm "revcut_rl"
wenzelm@4016
   556
      (implies_intr V (implies_intr VW (implies_elim (assume VW) (assume V))))
clasohm@0
   557
  end;
clasohm@0
   558
lcp@668
   559
(*for deleting an unwanted assumption*)
lcp@668
   560
val thin_rl =
paulson@4610
   561
  let val V = read_prop "PROP V"
paulson@4610
   562
      and W = read_prop "PROP W";
wenzelm@4016
   563
  in  store_thm "thin_rl" (implies_intr V (implies_intr W (assume W)))
lcp@668
   564
  end;
lcp@668
   565
clasohm@0
   566
(* (!!x. PROP ?V) == PROP ?V       Allows removal of redundant parameters*)
clasohm@0
   567
val triv_forall_equality =
paulson@4610
   568
  let val V  = read_prop "PROP V"
paulson@4610
   569
      and QV = read_prop "!!x::'a. PROP V"
paulson@4610
   570
      and x  = read_cterm proto_sign ("x", TFree("'a",logicS));
wenzelm@4016
   571
  in
wenzelm@4016
   572
    store_thm "triv_forall_equality"
wenzelm@4016
   573
      (equal_intr (implies_intr QV (forall_elim x (assume QV)))
wenzelm@4016
   574
        (implies_intr V  (forall_intr x (assume V))))
clasohm@0
   575
  end;
clasohm@0
   576
nipkow@1756
   577
(* (PROP ?PhiA ==> PROP ?PhiB ==> PROP ?Psi) ==>
nipkow@1756
   578
   (PROP ?PhiB ==> PROP ?PhiA ==> PROP ?Psi)
nipkow@1756
   579
   `thm COMP swap_prems_rl' swaps the first two premises of `thm'
nipkow@1756
   580
*)
nipkow@1756
   581
val swap_prems_rl =
paulson@4610
   582
  let val cmajor = read_prop "PROP PhiA ==> PROP PhiB ==> PROP Psi";
nipkow@1756
   583
      val major = assume cmajor;
paulson@4610
   584
      val cminor1 = read_prop "PROP PhiA";
nipkow@1756
   585
      val minor1 = assume cminor1;
paulson@4610
   586
      val cminor2 = read_prop "PROP PhiB";
nipkow@1756
   587
      val minor2 = assume cminor2;
wenzelm@4016
   588
  in store_thm "swap_prems_rl"
nipkow@1756
   589
       (implies_intr cmajor (implies_intr cminor2 (implies_intr cminor1
nipkow@1756
   590
         (implies_elim (implies_elim major minor1) minor2))))
nipkow@1756
   591
  end;
nipkow@1756
   592
nipkow@3653
   593
(* [| PROP ?phi ==> PROP ?psi; PROP ?psi ==> PROP ?phi |]
nipkow@3653
   594
   ==> PROP ?phi == PROP ?psi
paulson@4610
   595
   Introduction rule for == as a meta-theorem.  
nipkow@3653
   596
*)
nipkow@3653
   597
val equal_intr_rule =
paulson@4610
   598
  let val PQ = read_prop "PROP phi ==> PROP psi"
paulson@4610
   599
      and QP = read_prop "PROP psi ==> PROP phi"
wenzelm@4016
   600
  in
wenzelm@4016
   601
    store_thm "equal_intr_rule"
wenzelm@4016
   602
      (implies_intr PQ (implies_intr QP (equal_intr (assume PQ) (assume QP))))
nipkow@3653
   603
  end;
nipkow@3653
   604
wenzelm@4285
   605
wenzelm@4789
   606
(* GOAL (PROP A) <==> PROP A *)
wenzelm@4789
   607
wenzelm@4789
   608
local
wenzelm@4789
   609
  val A = read_prop "PROP A";
wenzelm@4789
   610
  val G = read_prop "GOAL (PROP A)";
wenzelm@4789
   611
  val (G_def, _) = freeze_thaw ProtoPure.Goal_def;
wenzelm@4789
   612
in
wenzelm@4789
   613
  val triv_goal = store_thm "triv_goal" (Thm.equal_elim (Thm.symmetric G_def) (Thm.assume A));
wenzelm@4789
   614
  val rev_triv_goal = store_thm "rev_triv_goal" (Thm.equal_elim G_def (Thm.assume G));
wenzelm@4789
   615
end;
wenzelm@4789
   616
wenzelm@4789
   617
wenzelm@4285
   618
wenzelm@5688
   619
(** variations on instantiate **)
wenzelm@4285
   620
wenzelm@4285
   621
(* collect vars *)
wenzelm@4285
   622
wenzelm@4285
   623
val add_tvarsT = foldl_atyps (fn (vs, TVar v) => v ins vs | (vs, _) => vs);
wenzelm@4285
   624
val add_tvars = foldl_types add_tvarsT;
wenzelm@4285
   625
val add_vars = foldl_aterms (fn (vs, Var v) => v ins vs | (vs, _) => vs);
wenzelm@4285
   626
wenzelm@5903
   627
fun tvars_of_terms ts = rev (foldl add_tvars ([], ts));
wenzelm@5903
   628
fun vars_of_terms ts = rev (foldl add_vars ([], ts));
wenzelm@5903
   629
wenzelm@5903
   630
fun tvars_of thm = tvars_of_terms [#prop (Thm.rep_thm thm)];
wenzelm@5903
   631
fun vars_of thm = vars_of_terms [#prop (Thm.rep_thm thm)];
wenzelm@4285
   632
wenzelm@4285
   633
wenzelm@4285
   634
(* instantiate by left-to-right occurrence of variables *)
wenzelm@4285
   635
wenzelm@4285
   636
fun instantiate' cTs cts thm =
wenzelm@4285
   637
  let
wenzelm@4285
   638
    fun err msg =
wenzelm@4285
   639
      raise TYPE ("instantiate': " ^ msg,
wenzelm@4285
   640
        mapfilter (apsome Thm.typ_of) cTs,
wenzelm@4285
   641
        mapfilter (apsome Thm.term_of) cts);
wenzelm@4285
   642
wenzelm@4285
   643
    fun inst_of (v, ct) =
wenzelm@4285
   644
      (Thm.cterm_of (#sign (Thm.rep_cterm ct)) (Var v), ct)
wenzelm@4285
   645
        handle TYPE (msg, _, _) => err msg;
wenzelm@4285
   646
wenzelm@4285
   647
    fun zip_vars _ [] = []
wenzelm@4285
   648
      | zip_vars (_ :: vs) (None :: opt_ts) = zip_vars vs opt_ts
wenzelm@4285
   649
      | zip_vars (v :: vs) (Some t :: opt_ts) = (v, t) :: zip_vars vs opt_ts
wenzelm@4285
   650
      | zip_vars [] _ = err "more instantiations than variables in thm";
wenzelm@4285
   651
wenzelm@4285
   652
    (*instantiate types first!*)
wenzelm@4285
   653
    val thm' =
wenzelm@4285
   654
      if forall is_none cTs then thm
wenzelm@4285
   655
      else Thm.instantiate (zip_vars (map fst (tvars_of thm)) cTs, []) thm;
wenzelm@4285
   656
    in
wenzelm@4285
   657
      if forall is_none cts then thm'
wenzelm@4285
   658
      else Thm.instantiate ([], map inst_of (zip_vars (vars_of thm') cts)) thm'
wenzelm@4285
   659
    end;
wenzelm@4285
   660
wenzelm@4285
   661
wenzelm@5688
   662
(* unvarify(T) *)
wenzelm@5688
   663
wenzelm@5688
   664
(*assume thm in standard form, i.e. no frees, 0 var indexes*)
wenzelm@5688
   665
wenzelm@5688
   666
fun unvarifyT thm =
wenzelm@5688
   667
  let
wenzelm@5688
   668
    val cT = Thm.ctyp_of (Thm.sign_of_thm thm);
wenzelm@5688
   669
    val tfrees = map (fn ((x, _), S) => Some (cT (TFree (x, S)))) (tvars_of thm);
wenzelm@5688
   670
  in instantiate' tfrees [] thm end;
wenzelm@5688
   671
wenzelm@5688
   672
fun unvarify raw_thm =
wenzelm@5688
   673
  let
wenzelm@5688
   674
    val thm = unvarifyT raw_thm;
wenzelm@5688
   675
    val ct = Thm.cterm_of (Thm.sign_of_thm thm);
wenzelm@5688
   676
    val frees = map (fn ((x, _), T) => Some (ct (Free (x, T)))) (vars_of thm);
wenzelm@5688
   677
  in instantiate' [] frees thm end;
wenzelm@5688
   678
wenzelm@5688
   679
wenzelm@6435
   680
(* increment var indexes *)
wenzelm@6435
   681
wenzelm@6435
   682
fun incr_indexes 0 thm = thm
wenzelm@6435
   683
  | incr_indexes inc thm =
wenzelm@6435
   684
      let
wenzelm@6435
   685
        val sign = Thm.sign_of_thm thm;
wenzelm@6435
   686
wenzelm@6435
   687
        fun inc_tvar ((x, i), S) = Some (Thm.ctyp_of sign (TVar ((x, i + inc), S)));
wenzelm@6435
   688
        fun inc_var ((x, i), T) = Some (Thm.cterm_of sign (Var ((x, i + inc), T)));
wenzelm@6930
   689
        val thm' = instantiate' (map inc_tvar (tvars_of thm)) [] thm;
wenzelm@6930
   690
        val thm'' = instantiate' [] (map inc_var (vars_of thm')) thm';
wenzelm@6930
   691
      in thm'' end;
wenzelm@6435
   692
wenzelm@6435
   693
fun incr_indexes_wrt is cTs cts thms =
wenzelm@6435
   694
  let
wenzelm@6435
   695
    val maxidx =
wenzelm@6435
   696
      foldl Int.max (~1, is @
wenzelm@6435
   697
        map (maxidx_of_typ o #T o Thm.rep_ctyp) cTs @
wenzelm@6435
   698
        map (#maxidx o Thm.rep_cterm) cts @
wenzelm@6435
   699
        map (#maxidx o Thm.rep_thm) thms);
wenzelm@6435
   700
  in incr_indexes (maxidx + 1) end;
wenzelm@6435
   701
wenzelm@6435
   702
wenzelm@5688
   703
(* mk_triv_goal *)
wenzelm@5688
   704
wenzelm@5688
   705
(*make an initial proof state, "PROP A ==> (PROP A)" *)
paulson@5311
   706
fun mk_triv_goal ct = instantiate' [] [Some ct] triv_goal;
paulson@5311
   707
wenzelm@5688
   708
wenzelm@6086
   709
wenzelm@6086
   710
(** basic attributes **)
wenzelm@6086
   711
wenzelm@6086
   712
(* dependent rules *)
wenzelm@6086
   713
wenzelm@6086
   714
fun rule_attribute f (x, thm) = (x, (f x thm));
wenzelm@6086
   715
wenzelm@6086
   716
wenzelm@6086
   717
(* add / delete tags *)
wenzelm@6086
   718
wenzelm@6086
   719
fun map_tags f thm =
wenzelm@6086
   720
  Thm.put_name_tags (Thm.name_of_thm thm, f (#2 (Thm.get_name_tags thm))) thm;
wenzelm@6086
   721
wenzelm@6086
   722
fun tag tg x = rule_attribute (K (map_tags (fn tgs => if tg mem tgs then tgs else tgs @ [tg]))) x;
wenzelm@6086
   723
fun untag tg x = rule_attribute (K (map_tags (fn tgs => tgs \ tg))) x;
wenzelm@6086
   724
wenzelm@6086
   725
fun simple_tag name x = tag (name, []) x;
wenzelm@6086
   726
wenzelm@6086
   727
fun tag_lemma x = simple_tag "lemma" x;
wenzelm@6086
   728
fun tag_assumption x = simple_tag "assumption" x;
wenzelm@6086
   729
fun tag_internal x = simple_tag "internal" x;
wenzelm@6086
   730
wenzelm@6086
   731
clasohm@0
   732
end;
wenzelm@252
   733
wenzelm@5903
   734
wenzelm@5903
   735
structure BasicDrule: BASIC_DRULE = Drule;
wenzelm@5903
   736
open BasicDrule;