src/Pure/drule.ML
changeset 0 a5a9c433f639
child 11 d0e17c42dbb4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/drule.ML	Thu Sep 16 12:20:38 1993 +0200
     1.3 @@ -0,0 +1,465 @@
     1.4 +(*  Title: 	drule
     1.5 +    ID:         $Id$
     1.6 +    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
     1.7 +    Copyright   1993  University of Cambridge
     1.8 +
     1.9 +Derived rules and other operations on theorems and theories
    1.10 +*)
    1.11 +
    1.12 +infix 0 RS RSN RL RLN COMP;
    1.13 +
    1.14 +signature DRULE =
    1.15 +  sig
    1.16 +  structure Thm : THM
    1.17 +  local open Thm  in
    1.18 +  val asm_rl: thm
    1.19 +  val assume_ax: theory -> string -> thm
    1.20 +  val COMP: thm * thm -> thm
    1.21 +  val compose: thm * int * thm -> thm list
    1.22 +  val cterm_instantiate: (Sign.cterm*Sign.cterm)list -> thm -> thm
    1.23 +  val cut_rl: thm
    1.24 +  val equal_abs_elim: Sign.cterm  -> thm -> thm
    1.25 +  val equal_abs_elim_list: Sign.cterm list -> thm -> thm
    1.26 +  val eq_sg: Sign.sg * Sign.sg -> bool
    1.27 +  val eq_thm: thm * thm -> bool
    1.28 +  val eq_thm_sg: thm * thm -> bool
    1.29 +  val flexpair_abs_elim_list: Sign.cterm list -> thm -> thm
    1.30 +  val forall_intr_list: Sign.cterm list -> thm -> thm
    1.31 +  val forall_intr_frees: thm -> thm
    1.32 +  val forall_elim_list: Sign.cterm list -> thm -> thm
    1.33 +  val forall_elim_var: int -> thm -> thm
    1.34 +  val forall_elim_vars: int -> thm -> thm
    1.35 +  val implies_elim_list: thm -> thm list -> thm
    1.36 +  val implies_intr_list: Sign.cterm list -> thm -> thm
    1.37 +  val print_cterm: Sign.cterm -> unit
    1.38 +  val print_ctyp: Sign.ctyp -> unit
    1.39 +  val print_goals: int -> thm -> unit
    1.40 +  val print_sg: Sign.sg -> unit
    1.41 +  val print_theory: theory -> unit
    1.42 +  val pprint_sg: Sign.sg -> pprint_args -> unit
    1.43 +  val pprint_theory: theory -> pprint_args -> unit
    1.44 +  val print_thm: thm -> unit
    1.45 +  val prth: thm -> thm
    1.46 +  val prthq: thm Sequence.seq -> thm Sequence.seq
    1.47 +  val prths: thm list -> thm list
    1.48 +  val read_instantiate: (string*string)list -> thm -> thm
    1.49 +  val read_instantiate_sg: Sign.sg -> (string*string)list -> thm -> thm
    1.50 +  val reflexive_thm: thm
    1.51 +  val revcut_rl: thm
    1.52 +  val rewrite_goal_rule: (meta_simpset -> thm -> thm option) -> meta_simpset ->
    1.53 +        int -> thm -> thm
    1.54 +  val rewrite_goals_rule: thm list -> thm -> thm
    1.55 +  val rewrite_rule: thm list -> thm -> thm
    1.56 +  val RS: thm * thm -> thm
    1.57 +  val RSN: thm * (int * thm) -> thm
    1.58 +  val RL: thm list * thm list -> thm list
    1.59 +  val RLN: thm list * (int * thm list) -> thm list
    1.60 +  val show_hyps: bool ref
    1.61 +  val size_of_thm: thm -> int
    1.62 +  val standard: thm -> thm
    1.63 +  val string_of_thm: thm -> string
    1.64 +  val symmetric_thm: thm
    1.65 +  val pprint_thm: thm -> pprint_args -> unit
    1.66 +  val transitive_thm: thm
    1.67 +  val triv_forall_equality: thm
    1.68 +  val types_sorts: thm -> (indexname-> typ option) * (indexname-> sort option)
    1.69 +  val zero_var_indexes: thm -> thm
    1.70 +  end
    1.71 +  end;
    1.72 +
    1.73 +functor DruleFun (structure Logic: LOGIC and Thm: THM) : DRULE = 
    1.74 +struct
    1.75 +structure Thm = Thm;
    1.76 +structure Sign = Thm.Sign;
    1.77 +structure Type = Sign.Type;
    1.78 +structure Pretty = Sign.Syntax.Pretty
    1.79 +local open Thm
    1.80 +in
    1.81 +
    1.82 +(**** More derived rules and operations on theorems ****)
    1.83 +
    1.84 +(*** Find the type (sort) associated with a (T)Var or (T)Free in a term 
    1.85 +     Used for establishing default types (of variables) and sorts (of
    1.86 +     type variables) when reading another term.
    1.87 +     Index -1 indicates that a (T)Free rather than a (T)Var is wanted.
    1.88 +***)
    1.89 +
    1.90 +fun types_sorts thm =
    1.91 +    let val {prop,hyps,...} = rep_thm thm;
    1.92 +	val big = list_comb(prop,hyps); (* bogus term! *)
    1.93 +	val vars = map dest_Var (term_vars big);
    1.94 +	val frees = map dest_Free (term_frees big);
    1.95 +	val tvars = term_tvars big;
    1.96 +	val tfrees = term_tfrees big;
    1.97 +	fun typ(a,i) = if i<0 then assoc(frees,a) else assoc(vars,(a,i));
    1.98 +	fun sort(a,i) = if i<0 then assoc(tfrees,a) else assoc(tvars,(a,i));
    1.99 +    in (typ,sort) end;
   1.100 +
   1.101 +(** Standardization of rules **)
   1.102 +
   1.103 +(*Generalization over a list of variables, IGNORING bad ones*)
   1.104 +fun forall_intr_list [] th = th
   1.105 +  | forall_intr_list (y::ys) th =
   1.106 +	let val gth = forall_intr_list ys th
   1.107 +	in  forall_intr y gth   handle THM _ =>  gth  end;
   1.108 +
   1.109 +(*Generalization over all suitable Free variables*)
   1.110 +fun forall_intr_frees th =
   1.111 +    let val {prop,sign,...} = rep_thm th
   1.112 +    in  forall_intr_list
   1.113 +         (map (Sign.cterm_of sign) (sort atless (term_frees prop))) 
   1.114 +         th
   1.115 +    end;
   1.116 +
   1.117 +(*Replace outermost quantified variable by Var of given index.
   1.118 +    Could clash with Vars already present.*)
   1.119 +fun forall_elim_var i th = 
   1.120 +    let val {prop,sign,...} = rep_thm th
   1.121 +    in case prop of
   1.122 +	  Const("all",_) $ Abs(a,T,_) =>
   1.123 +	      forall_elim (Sign.cterm_of sign (Var((a,i), T)))  th
   1.124 +	| _ => raise THM("forall_elim_var", i, [th])
   1.125 +    end;
   1.126 +
   1.127 +(*Repeat forall_elim_var until all outer quantifiers are removed*)
   1.128 +fun forall_elim_vars i th = 
   1.129 +    forall_elim_vars i (forall_elim_var i th)
   1.130 +	handle THM _ => th;
   1.131 +
   1.132 +(*Specialization over a list of cterms*)
   1.133 +fun forall_elim_list cts th = foldr (uncurry forall_elim) (rev cts, th);
   1.134 +
   1.135 +(* maps [A1,...,An], B   to   [| A1;...;An |] ==> B  *)
   1.136 +fun implies_intr_list cAs th = foldr (uncurry implies_intr) (cAs,th);
   1.137 +
   1.138 +(* maps [| A1;...;An |] ==> B and [A1,...,An]   to   B *)
   1.139 +fun implies_elim_list impth ths = foldl (uncurry implies_elim) (impth,ths);
   1.140 +
   1.141 +(*Reset Var indexes to zero, renaming to preserve distinctness*)
   1.142 +fun zero_var_indexes th = 
   1.143 +    let val {prop,sign,...} = rep_thm th;
   1.144 +        val vars = term_vars prop
   1.145 +        val bs = foldl add_new_id ([], map (fn Var((a,_),_)=>a) vars)
   1.146 +	val inrs = add_term_tvars(prop,[]);
   1.147 +	val nms' = rev(foldl add_new_id ([], map (#1 o #1) inrs));
   1.148 +	val tye = map (fn ((v,rs),a) => (v, TVar((a,0),rs))) (inrs ~~ nms')
   1.149 +	val ctye = map (fn (v,T) => (v,Sign.ctyp_of sign T)) tye;
   1.150 +	fun varpairs([],[]) = []
   1.151 +	  | varpairs((var as Var(v,T)) :: vars, b::bs) =
   1.152 +		let val T' = typ_subst_TVars tye T
   1.153 +		in (Sign.cterm_of sign (Var(v,T')),
   1.154 +		    Sign.cterm_of sign (Var((b,0),T'))) :: varpairs(vars,bs)
   1.155 +		end
   1.156 +	  | varpairs _ = raise TERM("varpairs", []);
   1.157 +    in instantiate (ctye, varpairs(vars,rev bs)) th end;
   1.158 +
   1.159 +
   1.160 +(*Standard form of object-rule: no hypotheses, Frees, or outer quantifiers;
   1.161 +    all generality expressed by Vars having index 0.*)
   1.162 +fun standard th =
   1.163 +    let val {maxidx,...} = rep_thm th
   1.164 +    in  varifyT (zero_var_indexes (forall_elim_vars(maxidx+1) 
   1.165 +                         (forall_intr_frees(implies_intr_hyps th))))
   1.166 +    end;
   1.167 +
   1.168 +(*Assume a new formula, read following the same conventions as axioms. 
   1.169 +  Generalizes over Free variables,
   1.170 +  creates the assumption, and then strips quantifiers.
   1.171 +  Example is [| ALL x:?A. ?P(x) |] ==> [| ?P(?a) |]
   1.172 +	     [ !(A,P,a)[| ALL x:A. P(x) |] ==> [| P(a) |] ]    *)
   1.173 +fun assume_ax thy sP =
   1.174 +    let val sign = sign_of thy
   1.175 +	val prop = Logic.close_form (Sign.term_of (Sign.read_cterm sign
   1.176 +			 (sP, propT)))
   1.177 +    in forall_elim_vars 0 (assume (Sign.cterm_of sign prop))  end;
   1.178 +
   1.179 +(*Resolution: exactly one resolvent must be produced.*) 
   1.180 +fun tha RSN (i,thb) =
   1.181 +  case Sequence.chop (2, biresolution false [(false,tha)] i thb) of
   1.182 +      ([th],_) => th
   1.183 +    | ([],_)   => raise THM("RSN: no unifiers", i, [tha,thb])
   1.184 +    |      _   => raise THM("RSN: multiple unifiers", i, [tha,thb]);
   1.185 +
   1.186 +(*resolution: P==>Q, Q==>R gives P==>R. *)
   1.187 +fun tha RS thb = tha RSN (1,thb);
   1.188 +
   1.189 +(*For joining lists of rules*)
   1.190 +fun thas RLN (i,thbs) = 
   1.191 +  let val resolve = biresolution false (map (pair false) thas) i
   1.192 +      fun resb thb = Sequence.list_of_s (resolve thb) handle THM _ => []
   1.193 +  in  flat (map resb thbs)  end;
   1.194 +
   1.195 +fun thas RL thbs = thas RLN (1,thbs);
   1.196 +
   1.197 +(*compose Q and [...,Qi,Q(i+1),...]==>R to [...,Q(i+1),...]==>R 
   1.198 +  with no lifting or renaming!  Q may contain ==> or meta-quants
   1.199 +  ALWAYS deletes premise i *)
   1.200 +fun compose(tha,i,thb) = 
   1.201 +    Sequence.list_of_s (bicompose false (false,tha,0) i thb);
   1.202 +
   1.203 +(*compose Q and [Q1,Q2,...,Qk]==>R to [Q2,...,Qk]==>R getting unique result*)
   1.204 +fun tha COMP thb =
   1.205 +    case compose(tha,1,thb) of
   1.206 +        [th] => th  
   1.207 +      | _ =>   raise THM("COMP", 1, [tha,thb]);
   1.208 +
   1.209 +(*Instantiate theorem th, reading instantiations under signature sg*)
   1.210 +fun read_instantiate_sg sg sinsts th =
   1.211 +    let val ts = types_sorts th;
   1.212 +        val instpair = Sign.read_insts sg ts ts sinsts
   1.213 +    in  instantiate instpair th  end;
   1.214 +
   1.215 +(*Instantiate theorem th, reading instantiations under theory of th*)
   1.216 +fun read_instantiate sinsts th =
   1.217 +    read_instantiate_sg (#sign (rep_thm th)) sinsts th;
   1.218 +
   1.219 +
   1.220 +(*Left-to-right replacements: tpairs = [...,(vi,ti),...].
   1.221 +  Instantiates distinct Vars by terms, inferring type instantiations. *)
   1.222 +local
   1.223 +  fun add_types ((ct,cu), (sign,tye)) =
   1.224 +    let val {sign=signt, t=t, T= T, ...} = Sign.rep_cterm ct
   1.225 +        and {sign=signu, t=u, T= U, ...} = Sign.rep_cterm cu
   1.226 +        val sign' = Sign.merge(sign, Sign.merge(signt, signu))
   1.227 +	val tye' = Type.unify (#tsig(Sign.rep_sg sign')) ((T,U), tye)
   1.228 +	  handle Type.TUNIFY => raise TYPE("add_types", [T,U], [t,u])
   1.229 +    in  (sign', tye')  end;
   1.230 +in
   1.231 +fun cterm_instantiate ctpairs0 th = 
   1.232 +  let val (sign,tye) = foldr add_types (ctpairs0, (#sign(rep_thm th),[]))
   1.233 +      val tsig = #tsig(Sign.rep_sg sign);
   1.234 +      fun instT(ct,cu) = let val inst = subst_TVars tye
   1.235 +			 in (Sign.cfun inst ct, Sign.cfun inst cu) end
   1.236 +      fun ctyp2 (ix,T) = (ix, Sign.ctyp_of sign T)
   1.237 +  in  instantiate (map ctyp2 tye, map instT ctpairs0) th  end
   1.238 +  handle TERM _ => 
   1.239 +           raise THM("cterm_instantiate: incompatible signatures",0,[th])
   1.240 +       | TYPE _ => raise THM("cterm_instantiate: types", 0, [th])
   1.241 +end;
   1.242 +
   1.243 +
   1.244 +(*** Printing of theorems ***)
   1.245 +
   1.246 +(*If false, hypotheses are printed as dots*)
   1.247 +val show_hyps = ref true;
   1.248 +
   1.249 +fun pretty_thm th =
   1.250 +let val {sign, hyps, prop,...} = rep_thm th
   1.251 +    val hsymbs = if null hyps then []
   1.252 +		 else if !show_hyps then
   1.253 +		      [Pretty.brk 2,
   1.254 +		       Pretty.lst("[","]") (map (Sign.pretty_term sign) hyps)]
   1.255 +		 else Pretty.str" [" :: map (fn _ => Pretty.str".") hyps @
   1.256 +		      [Pretty.str"]"];
   1.257 +in Pretty.blk(0, Sign.pretty_term sign prop :: hsymbs) end;
   1.258 +
   1.259 +val string_of_thm = Pretty.string_of o pretty_thm;
   1.260 +
   1.261 +val pprint_thm = Pretty.pprint o Pretty.quote o pretty_thm;
   1.262 +
   1.263 +
   1.264 +(** Top-level commands for printing theorems **)
   1.265 +val print_thm = writeln o string_of_thm;
   1.266 +
   1.267 +fun prth th = (print_thm th; th);
   1.268 +
   1.269 +(*Print and return a sequence of theorems, separated by blank lines. *)
   1.270 +fun prthq thseq =
   1.271 +    (Sequence.prints (fn _ => print_thm) 100000 thseq;
   1.272 +     thseq);
   1.273 +
   1.274 +(*Print and return a list of theorems, separated by blank lines. *)
   1.275 +fun prths ths = (print_list_ln print_thm ths; ths);
   1.276 +
   1.277 +(*Other printing commands*)
   1.278 +val print_cterm = writeln o Sign.string_of_cterm;
   1.279 +val print_ctyp = writeln o Sign.string_of_ctyp;
   1.280 +fun pretty_sg sg = 
   1.281 +  Pretty.lst ("{", "}") (map (Pretty.str o !) (#stamps (Sign.rep_sg sg)));
   1.282 +
   1.283 +val pprint_sg = Pretty.pprint o pretty_sg;
   1.284 +
   1.285 +val pprint_theory = pprint_sg o sign_of;
   1.286 +
   1.287 +val print_sg = writeln o Pretty.string_of o pretty_sg;
   1.288 +val print_theory = print_sg o sign_of;
   1.289 +
   1.290 +
   1.291 +(** Print thm A1,...,An/B in "goal style" -- premises as numbered subgoals **)
   1.292 +
   1.293 +fun prettyprints es = writeln(Pretty.string_of(Pretty.blk(0,es)));
   1.294 +
   1.295 +fun print_goals maxgoals th : unit =
   1.296 +let val {sign, hyps, prop,...} = rep_thm th;
   1.297 +    fun printgoals (_, []) = ()
   1.298 +      | printgoals (n, A::As) =
   1.299 +	let val prettyn = Pretty.str(" " ^ string_of_int n ^ ". ");
   1.300 +	    val prettyA = Sign.pretty_term sign A
   1.301 +	in prettyprints[prettyn,prettyA]; 
   1.302 +           printgoals (n+1,As) 
   1.303 +        end;
   1.304 +    fun prettypair(t,u) =
   1.305 +        Pretty.blk(0, [Sign.pretty_term sign t, Pretty.str" =?=", Pretty.brk 1,
   1.306 +		       Sign.pretty_term sign u]);
   1.307 +    fun printff [] = ()
   1.308 +      | printff tpairs =
   1.309 +	 writeln("\nFlex-flex pairs:\n" ^
   1.310 +		 Pretty.string_of(Pretty.lst("","") (map prettypair tpairs)))
   1.311 +    val (tpairs,As,B) = Logic.strip_horn(prop);
   1.312 +    val ngoals = length As
   1.313 +in 
   1.314 +   writeln (Sign.string_of_term sign B);
   1.315 +   if ngoals=0 then writeln"No subgoals!"
   1.316 +   else if ngoals>maxgoals 
   1.317 +        then (printgoals (1, take(maxgoals,As));
   1.318 +	      writeln("A total of " ^ string_of_int ngoals ^ " subgoals..."))
   1.319 +        else printgoals (1, As);
   1.320 +   printff tpairs
   1.321 +end;
   1.322 +
   1.323 +
   1.324 +(** theorem equality test is exported and used by BEST_FIRST **)
   1.325 +
   1.326 +(*equality of signatures means exact identity -- by ref equality*)
   1.327 +fun eq_sg (sg1,sg2) = (#stamps(Sign.rep_sg sg1) = #stamps(Sign.rep_sg sg2));
   1.328 +
   1.329 +(*equality of theorems uses equality of signatures and 
   1.330 +  the a-convertible test for terms*)
   1.331 +fun eq_thm (th1,th2) = 
   1.332 +    let val {sign=sg1, hyps=hyps1, prop=prop1, ...} = rep_thm th1
   1.333 +	and {sign=sg2, hyps=hyps2, prop=prop2, ...} = rep_thm th2
   1.334 +    in  eq_sg (sg1,sg2) andalso 
   1.335 +        aconvs(hyps1,hyps2) andalso 
   1.336 +        prop1 aconv prop2  
   1.337 +    end;
   1.338 +
   1.339 +(*Do the two theorems have the same signature?*)
   1.340 +fun eq_thm_sg (th1,th2) = eq_sg(#sign(rep_thm th1), #sign(rep_thm th2));
   1.341 +
   1.342 +(*Useful "distance" function for BEST_FIRST*)
   1.343 +val size_of_thm = size_of_term o #prop o rep_thm;
   1.344 +
   1.345 +
   1.346 +(*** Meta-Rewriting Rules ***)
   1.347 +
   1.348 +
   1.349 +val reflexive_thm =
   1.350 +  let val cx = Sign.cterm_of Sign.pure (Var(("x",0),TVar(("'a",0),["logic"])))
   1.351 +  in Thm.reflexive cx end;
   1.352 +
   1.353 +val symmetric_thm =
   1.354 +  let val xy = Sign.read_cterm Sign.pure ("x::'a::logic == y",propT)
   1.355 +  in standard(Thm.implies_intr_hyps(Thm.symmetric(Thm.assume xy))) end;
   1.356 +
   1.357 +val transitive_thm =
   1.358 +  let val xy = Sign.read_cterm Sign.pure ("x::'a::logic == y",propT)
   1.359 +      val yz = Sign.read_cterm Sign.pure ("y::'a::logic == z",propT)
   1.360 +      val xythm = Thm.assume xy and yzthm = Thm.assume yz
   1.361 +  in standard(Thm.implies_intr yz (Thm.transitive xythm yzthm)) end;
   1.362 +
   1.363 +
   1.364 +(** Below, a "conversion" has type sign->term->thm **)
   1.365 +
   1.366 +(*In [A1,...,An]==>B, rewrite the selected A's only -- for rewrite_goals_tac*)
   1.367 +fun goals_conv pred cv sign = 
   1.368 +  let val triv = reflexive o Sign.cterm_of sign
   1.369 +      fun gconv i t =
   1.370 +        let val (A,B) = Logic.dest_implies t
   1.371 +	    val thA = if (pred i) then (cv sign A) else (triv A)
   1.372 +	in  combination (combination (triv implies) thA)
   1.373 +                        (gconv (i+1) B)
   1.374 +        end
   1.375 +        handle TERM _ => triv t
   1.376 +  in gconv 1 end;
   1.377 +
   1.378 +(*Use a conversion to transform a theorem*)
   1.379 +fun fconv_rule cv th =
   1.380 +  let val {sign,prop,...} = rep_thm th
   1.381 +  in  equal_elim (cv sign prop) th  end;
   1.382 +
   1.383 +(*rewriting conversion*)
   1.384 +fun rew_conv prover mss sign t =
   1.385 +  rewrite_cterm mss prover (Sign.cterm_of sign t);
   1.386 +
   1.387 +(*Rewrite a theorem*)
   1.388 +fun rewrite_rule thms = fconv_rule (rew_conv (K(K None)) (Thm.mss_of thms));
   1.389 +
   1.390 +(*Rewrite the subgoals of a proof state (represented by a theorem) *)
   1.391 +fun rewrite_goals_rule thms =
   1.392 +  fconv_rule (goals_conv (K true) (rew_conv (K(K None)) (Thm.mss_of thms)));
   1.393 +
   1.394 +(*Rewrite the subgoal of a proof state (represented by a theorem) *)
   1.395 +fun rewrite_goal_rule prover mss i =
   1.396 +      fconv_rule (goals_conv (fn j => j=i) (rew_conv prover mss));
   1.397 +
   1.398 +
   1.399 +(** Derived rules mainly for METAHYPS **)
   1.400 +
   1.401 +(*Given the term "a", takes (%x.t)==(%x.u) to t[a/x]==u[a/x]*)
   1.402 +fun equal_abs_elim ca eqth =
   1.403 +  let val {sign=signa, t=a, ...} = Sign.rep_cterm ca
   1.404 +      and combth = combination eqth (reflexive ca)
   1.405 +      val {sign,prop,...} = rep_thm eqth
   1.406 +      val (abst,absu) = Logic.dest_equals prop
   1.407 +      val cterm = Sign.cterm_of (Sign.merge (sign,signa))
   1.408 +  in  transitive (symmetric (beta_conversion (cterm (abst$a))))
   1.409 +           (transitive combth (beta_conversion (cterm (absu$a))))
   1.410 +  end
   1.411 +  handle THM _ => raise THM("equal_abs_elim", 0, [eqth]);
   1.412 +
   1.413 +(*Calling equal_abs_elim with multiple terms*)
   1.414 +fun equal_abs_elim_list cts th = foldr (uncurry equal_abs_elim) (rev cts, th);
   1.415 +
   1.416 +local
   1.417 +  open Logic
   1.418 +  val alpha = TVar(("'a",0), [])     (*  type ?'a::{}  *)
   1.419 +  fun err th = raise THM("flexpair_inst: ", 0, [th])
   1.420 +  fun flexpair_inst def th =
   1.421 +    let val {prop = Const _ $ t $ u,  sign,...} = rep_thm th
   1.422 +	val cterm = Sign.cterm_of sign
   1.423 +	fun cvar a = cterm(Var((a,0),alpha))
   1.424 +	val def' = cterm_instantiate [(cvar"t", cterm t), (cvar"u", cterm u)] 
   1.425 +		   def
   1.426 +    in  equal_elim def' th
   1.427 +    end
   1.428 +    handle THM _ => err th | bind => err th
   1.429 +in
   1.430 +val flexpair_intr = flexpair_inst (symmetric flexpair_def)
   1.431 +and flexpair_elim = flexpair_inst flexpair_def
   1.432 +end;
   1.433 +
   1.434 +(*Version for flexflex pairs -- this supports lifting.*)
   1.435 +fun flexpair_abs_elim_list cts = 
   1.436 +    flexpair_intr o equal_abs_elim_list cts o flexpair_elim;
   1.437 +
   1.438 +
   1.439 +(*** Some useful meta-theorems ***)
   1.440 +
   1.441 +(*The rule V/V, obtains assumption solving for eresolve_tac*)
   1.442 +val asm_rl = trivial(Sign.read_cterm Sign.pure ("PROP ?psi",propT));
   1.443 +
   1.444 +(*Meta-level cut rule: [| V==>W; V |] ==> W *)
   1.445 +val cut_rl = trivial(Sign.read_cterm Sign.pure 
   1.446 +	("PROP ?psi ==> PROP ?theta", propT));
   1.447 +
   1.448 +(*Generalized elim rule for one conclusion; cut_rl with reversed premises: 
   1.449 +     [| PROP V;  PROP V ==> PROP W |] ==> PROP W *)
   1.450 +val revcut_rl =
   1.451 +  let val V = Sign.read_cterm Sign.pure ("PROP V", propT)
   1.452 +      and VW = Sign.read_cterm Sign.pure ("PROP V ==> PROP W", propT);
   1.453 +  in  standard (implies_intr V 
   1.454 +		(implies_intr VW
   1.455 +		 (implies_elim (assume VW) (assume V))))
   1.456 +  end;
   1.457 +
   1.458 +(* (!!x. PROP ?V) == PROP ?V       Allows removal of redundant parameters*)
   1.459 +val triv_forall_equality =
   1.460 +  let val V  = Sign.read_cterm Sign.pure ("PROP V", propT)
   1.461 +      and QV = Sign.read_cterm Sign.pure ("!!x::'a. PROP V", propT)
   1.462 +      and x  = Sign.read_cterm Sign.pure ("x", TFree("'a",["logic"]));
   1.463 +  in  standard (equal_intr (implies_intr QV (forall_elim x (assume QV)))
   1.464 +		           (implies_intr V  (forall_intr x (assume V))))
   1.465 +  end;
   1.466 +
   1.467 +end
   1.468 +end;