src/Pure/drule.ML
changeset 229 4002c4cd450c
parent 214 ed6a3e2b1a33
child 252 7532f95d7f44
     1.1 --- a/src/Pure/drule.ML	Tue Jan 18 07:53:35 1994 +0100
     1.2 +++ b/src/Pure/drule.ML	Tue Jan 18 13:46:08 1994 +0100
     1.3 @@ -14,40 +14,50 @@
     1.4    local open Thm  in
     1.5    val asm_rl: thm
     1.6    val assume_ax: theory -> string -> thm
     1.7 +  val cterm_fun: (term -> term) -> (cterm -> cterm)
     1.8    val COMP: thm * thm -> thm
     1.9    val compose: thm * int * thm -> thm list
    1.10 -  val cterm_instantiate: (Sign.cterm*Sign.cterm)list -> thm -> thm
    1.11 +  val cterm_instantiate: (cterm*cterm)list -> thm -> thm
    1.12    val cut_rl: thm
    1.13 -  val equal_abs_elim: Sign.cterm  -> thm -> thm
    1.14 -  val equal_abs_elim_list: Sign.cterm list -> thm -> thm
    1.15 +  val equal_abs_elim: cterm  -> thm -> thm
    1.16 +  val equal_abs_elim_list: cterm list -> thm -> thm
    1.17    val eq_sg: Sign.sg * Sign.sg -> bool
    1.18    val eq_thm: thm * thm -> bool
    1.19    val eq_thm_sg: thm * thm -> bool
    1.20 -  val flexpair_abs_elim_list: Sign.cterm list -> thm -> thm
    1.21 -  val forall_intr_list: Sign.cterm list -> thm -> thm
    1.22 +  val flexpair_abs_elim_list: cterm list -> thm -> thm
    1.23 +  val forall_intr_list: cterm list -> thm -> thm
    1.24    val forall_intr_frees: thm -> thm
    1.25 -  val forall_elim_list: Sign.cterm list -> thm -> thm
    1.26 +  val forall_elim_list: cterm list -> thm -> thm
    1.27    val forall_elim_var: int -> thm -> thm
    1.28    val forall_elim_vars: int -> thm -> thm
    1.29    val implies_elim_list: thm -> thm list -> thm
    1.30 -  val implies_intr_list: Sign.cterm list -> thm -> thm
    1.31 +  val implies_intr_list: cterm list -> thm -> thm
    1.32    val MRL: thm list list * thm list -> thm list
    1.33    val MRS: thm list * thm -> thm
    1.34 -  val print_cterm: Sign.cterm -> unit
    1.35 -  val print_ctyp: Sign.ctyp -> unit
    1.36 +  val pprint_cterm: cterm -> pprint_args -> unit
    1.37 +  val pprint_ctyp: ctyp -> pprint_args -> unit
    1.38 +  val pprint_sg: Sign.sg -> pprint_args -> unit
    1.39 +  val pprint_theory: theory -> pprint_args -> unit
    1.40 +  val pprint_thm: thm -> pprint_args -> unit
    1.41 +  val pretty_thm: thm -> Sign.Syntax.Pretty.T
    1.42 +  val print_cterm: cterm -> unit
    1.43 +  val print_ctyp: ctyp -> unit
    1.44    val print_goals: int -> thm -> unit
    1.45    val print_goals_ref: (int -> thm -> unit) ref
    1.46    val print_sg: Sign.sg -> unit
    1.47    val print_theory: theory -> unit
    1.48 -  val pprint_sg: Sign.sg -> pprint_args -> unit
    1.49 -  val pprint_theory: theory -> pprint_args -> unit
    1.50 -  val pretty_thm: thm -> Sign.Syntax.Pretty.T
    1.51    val print_thm: thm -> unit
    1.52    val prth: thm -> thm
    1.53    val prthq: thm Sequence.seq -> thm Sequence.seq
    1.54    val prths: thm list -> thm list
    1.55 +  val read_ctyp: Sign.sg -> string -> ctyp
    1.56    val read_instantiate: (string*string)list -> thm -> thm
    1.57    val read_instantiate_sg: Sign.sg -> (string*string)list -> thm -> thm
    1.58 +  val read_insts: 
    1.59 +          Sign.sg -> (indexname -> typ option) * (indexname -> sort option)
    1.60 +                  -> (indexname -> typ option) * (indexname -> sort option)
    1.61 +                  -> (string*string)list
    1.62 +                  -> (indexname*ctyp)list * (cterm*cterm)list
    1.63    val reflexive_thm: thm
    1.64    val revcut_rl: thm
    1.65    val rewrite_goal_rule: bool*bool -> (meta_simpset -> thm -> thm option)
    1.66 @@ -61,9 +71,10 @@
    1.67    val show_hyps: bool ref
    1.68    val size_of_thm: thm -> int
    1.69    val standard: thm -> thm
    1.70 +  val string_of_cterm: cterm -> string
    1.71 +  val string_of_ctyp: ctyp -> string
    1.72    val string_of_thm: thm -> string
    1.73    val symmetric_thm: thm
    1.74 -  val pprint_thm: thm -> pprint_args -> unit
    1.75    val transitive_thm: thm
    1.76    val triv_forall_equality: thm
    1.77    val types_sorts: thm -> (indexname-> typ option) * (indexname-> sort option)
    1.78 @@ -82,6 +93,145 @@
    1.79  
    1.80  (**** More derived rules and operations on theorems ****)
    1.81  
    1.82 +fun cterm_fun f ct =
    1.83 + let val {sign,t,...} = rep_cterm ct in cterm_of sign (f t) end;
    1.84 +
    1.85 +fun read_ctyp sign = ctyp_of sign o Sign.read_typ(sign, K None);
    1.86 +
    1.87 +
    1.88 +(** reading of instantiations **)
    1.89 +
    1.90 +fun indexname cs = case Syntax.scan_varname cs of (v,[]) => v
    1.91 +        | _ => error("Lexical error in variable name " ^ quote (implode cs));
    1.92 +
    1.93 +fun absent ixn =
    1.94 +  error("No such variable in term: " ^ Syntax.string_of_vname ixn);
    1.95 +
    1.96 +fun inst_failure ixn =
    1.97 +  error("Instantiation of " ^ Syntax.string_of_vname ixn ^ " fails");
    1.98 +
    1.99 +fun read_insts sign (rtypes,rsorts) (types,sorts) insts =
   1.100 +let val {tsig,...} = Sign.rep_sg sign
   1.101 +    fun split([],tvs,vs) = (tvs,vs)
   1.102 +      | split((sv,st)::l,tvs,vs) = (case explode sv of
   1.103 +                  "'"::cs => split(l,(indexname cs,st)::tvs,vs)
   1.104 +                | cs => split(l,tvs,(indexname cs,st)::vs));
   1.105 +    val (tvs,vs) = split(insts,[],[]);
   1.106 +    fun readT((a,i),st) =
   1.107 +        let val ixn = ("'" ^ a,i);
   1.108 +            val S = case rsorts ixn of Some S => S | None => absent ixn;
   1.109 +            val T = Sign.read_typ (sign,sorts) st;
   1.110 +        in if Type.typ_instance(tsig,T,TVar(ixn,S)) then (ixn,T)
   1.111 +           else inst_failure ixn
   1.112 +        end
   1.113 +    val tye = map readT tvs;
   1.114 +    fun add_cterm ((cts,tye), (ixn,st)) =
   1.115 +        let val T = case rtypes ixn of
   1.116 +                      Some T => typ_subst_TVars tye T
   1.117 +                    | None => absent ixn;
   1.118 +            val (ct,tye2) = read_def_cterm (sign,types,sorts) (st,T);
   1.119 +            val cv = cterm_of sign (Var(ixn,typ_subst_TVars tye2 T))
   1.120 +        in ((cv,ct)::cts,tye2 @ tye) end
   1.121 +    val (cterms,tye') = foldl add_cterm (([],tye), vs);
   1.122 +in (map (fn (ixn,T) => (ixn,ctyp_of sign T)) tye', cterms) end;
   1.123 +
   1.124 +
   1.125 +(*** Printing of theorems ***)
   1.126 +
   1.127 +(*If false, hypotheses are printed as dots*)
   1.128 +val show_hyps = ref true;
   1.129 +
   1.130 +fun pretty_thm th =
   1.131 +let val {sign, hyps, prop,...} = rep_thm th
   1.132 +    val hsymbs = if null hyps then []
   1.133 +		 else if !show_hyps then
   1.134 +		      [Pretty.brk 2,
   1.135 +		       Pretty.lst("[","]") (map (Sign.pretty_term sign) hyps)]
   1.136 +		 else Pretty.str" [" :: map (fn _ => Pretty.str".") hyps @
   1.137 +		      [Pretty.str"]"];
   1.138 +in Pretty.blk(0, Sign.pretty_term sign prop :: hsymbs) end;
   1.139 +
   1.140 +val string_of_thm = Pretty.string_of o pretty_thm;
   1.141 +
   1.142 +val pprint_thm = Pretty.pprint o Pretty.quote o pretty_thm;
   1.143 +
   1.144 +
   1.145 +(** Top-level commands for printing theorems **)
   1.146 +val print_thm = writeln o string_of_thm;
   1.147 +
   1.148 +fun prth th = (print_thm th; th);
   1.149 +
   1.150 +(*Print and return a sequence of theorems, separated by blank lines. *)
   1.151 +fun prthq thseq =
   1.152 +    (Sequence.prints (fn _ => print_thm) 100000 thseq;
   1.153 +     thseq);
   1.154 +
   1.155 +(*Print and return a list of theorems, separated by blank lines. *)
   1.156 +fun prths ths = (print_list_ln print_thm ths; ths);
   1.157 +
   1.158 +(*Other printing commands*)
   1.159 +fun pprint_ctyp cT = 
   1.160 + let val {sign,T} = rep_ctyp cT in  Sign.pprint_typ sign T  end;
   1.161 +
   1.162 +fun string_of_ctyp cT = 
   1.163 + let val {sign,T} = rep_ctyp cT in  Sign.string_of_typ sign T  end;
   1.164 +
   1.165 +val print_ctyp = writeln o string_of_ctyp;
   1.166 +
   1.167 +fun pprint_cterm ct = 
   1.168 + let val {sign,t,...} = rep_cterm ct in  Sign.pprint_term sign t  end;
   1.169 +
   1.170 +fun string_of_cterm ct = 
   1.171 + let val {sign,t,...} = rep_cterm ct in  Sign.string_of_term sign t  end;
   1.172 +
   1.173 +val print_cterm = writeln o string_of_cterm;
   1.174 +
   1.175 +fun pretty_sg sg = 
   1.176 +  Pretty.lst ("{", "}") (map (Pretty.str o !) (#stamps (Sign.rep_sg sg)));
   1.177 +
   1.178 +val pprint_sg = Pretty.pprint o pretty_sg;
   1.179 +
   1.180 +val pprint_theory = pprint_sg o sign_of;
   1.181 +
   1.182 +val print_sg = writeln o Pretty.string_of o pretty_sg;
   1.183 +val print_theory = print_sg o sign_of;
   1.184 +
   1.185 +
   1.186 +(** Print thm A1,...,An/B in "goal style" -- premises as numbered subgoals **)
   1.187 +
   1.188 +fun prettyprints es = writeln(Pretty.string_of(Pretty.blk(0,es)));
   1.189 +
   1.190 +fun print_goals maxgoals th : unit =
   1.191 +let val {sign, hyps, prop,...} = rep_thm th;
   1.192 +    fun printgoals (_, []) = ()
   1.193 +      | printgoals (n, A::As) =
   1.194 +	let val prettyn = Pretty.str(" " ^ string_of_int n ^ ". ");
   1.195 +	    val prettyA = Sign.pretty_term sign A
   1.196 +	in prettyprints[prettyn,prettyA]; 
   1.197 +           printgoals (n+1,As) 
   1.198 +        end;
   1.199 +    fun prettypair(t,u) =
   1.200 +        Pretty.blk(0, [Sign.pretty_term sign t, Pretty.str" =?=", Pretty.brk 1,
   1.201 +		       Sign.pretty_term sign u]);
   1.202 +    fun printff [] = ()
   1.203 +      | printff tpairs =
   1.204 +	 writeln("\nFlex-flex pairs:\n" ^
   1.205 +		 Pretty.string_of(Pretty.lst("","") (map prettypair tpairs)))
   1.206 +    val (tpairs,As,B) = Logic.strip_horn(prop);
   1.207 +    val ngoals = length As
   1.208 +in 
   1.209 +   writeln (Sign.string_of_term sign B);
   1.210 +   if ngoals=0 then writeln"No subgoals!"
   1.211 +   else if ngoals>maxgoals 
   1.212 +        then (printgoals (1, take(maxgoals,As));
   1.213 +	      writeln("A total of " ^ string_of_int ngoals ^ " subgoals..."))
   1.214 +        else printgoals (1, As);
   1.215 +   printff tpairs
   1.216 +end;
   1.217 +
   1.218 +(*"hook" for user interfaces: allows print_goals to be replaced*)
   1.219 +val print_goals_ref = ref print_goals;
   1.220 +
   1.221  (*** Find the type (sort) associated with a (T)Var or (T)Free in a term 
   1.222       Used for establishing default types (of variables) and sorts (of
   1.223       type variables) when reading another term.
   1.224 @@ -111,7 +261,7 @@
   1.225  fun forall_intr_frees th =
   1.226      let val {prop,sign,...} = rep_thm th
   1.227      in  forall_intr_list
   1.228 -         (map (Sign.cterm_of sign) (sort atless (term_frees prop))) 
   1.229 +         (map (cterm_of sign) (sort atless (term_frees prop))) 
   1.230           th
   1.231      end;
   1.232  
   1.233 @@ -121,7 +271,7 @@
   1.234      let val {prop,sign,...} = rep_thm th
   1.235      in case prop of
   1.236  	  Const("all",_) $ Abs(a,T,_) =>
   1.237 -	      forall_elim (Sign.cterm_of sign (Var((a,i), T)))  th
   1.238 +	      forall_elim (cterm_of sign (Var((a,i), T)))  th
   1.239  	| _ => raise THM("forall_elim_var", i, [th])
   1.240      end;
   1.241  
   1.242 @@ -147,12 +297,12 @@
   1.243  	val inrs = add_term_tvars(prop,[]);
   1.244  	val nms' = rev(foldl add_new_id ([], map (#1 o #1) inrs));
   1.245  	val tye = map (fn ((v,rs),a) => (v, TVar((a,0),rs))) (inrs ~~ nms')
   1.246 -	val ctye = map (fn (v,T) => (v,Sign.ctyp_of sign T)) tye;
   1.247 +	val ctye = map (fn (v,T) => (v,ctyp_of sign T)) tye;
   1.248  	fun varpairs([],[]) = []
   1.249  	  | varpairs((var as Var(v,T)) :: vars, b::bs) =
   1.250  		let val T' = typ_subst_TVars tye T
   1.251 -		in (Sign.cterm_of sign (Var(v,T')),
   1.252 -		    Sign.cterm_of sign (Var((b,0),T'))) :: varpairs(vars,bs)
   1.253 +		in (cterm_of sign (Var(v,T')),
   1.254 +		    cterm_of sign (Var((b,0),T'))) :: varpairs(vars,bs)
   1.255  		end
   1.256  	  | varpairs _ = raise TERM("varpairs", []);
   1.257      in instantiate (ctye, varpairs(vars,rev bs)) th end;
   1.258 @@ -173,9 +323,9 @@
   1.259  	     [ !(A,P,a)[| ALL x:A. P(x) |] ==> [| P(a) |] ]    *)
   1.260  fun assume_ax thy sP =
   1.261      let val sign = sign_of thy
   1.262 -	val prop = Logic.close_form (Sign.term_of (Sign.read_cterm sign
   1.263 +	val prop = Logic.close_form (term_of (read_cterm sign
   1.264  			 (sP, propT)))
   1.265 -    in forall_elim_vars 0 (assume (Sign.cterm_of sign prop))  end;
   1.266 +    in forall_elim_vars 0 (assume (cterm_of sign prop))  end;
   1.267  
   1.268  (*Resolution: exactly one resolvent must be produced.*) 
   1.269  fun tha RSN (i,thb) =
   1.270 @@ -223,8 +373,7 @@
   1.271  (*Instantiate theorem th, reading instantiations under signature sg*)
   1.272  fun read_instantiate_sg sg sinsts th =
   1.273      let val ts = types_sorts th;
   1.274 -        val instpair = Sign.read_insts sg ts ts sinsts
   1.275 -    in  instantiate instpair th  end;
   1.276 +    in  instantiate (read_insts sg ts ts sinsts) th  end;
   1.277  
   1.278  (*Instantiate theorem th, reading instantiations under theory of th*)
   1.279  fun read_instantiate sinsts th =
   1.280 @@ -235,8 +384,8 @@
   1.281    Instantiates distinct Vars by terms, inferring type instantiations. *)
   1.282  local
   1.283    fun add_types ((ct,cu), (sign,tye)) =
   1.284 -    let val {sign=signt, t=t, T= T, ...} = Sign.rep_cterm ct
   1.285 -        and {sign=signu, t=u, T= U, ...} = Sign.rep_cterm cu
   1.286 +    let val {sign=signt, t=t, T= T, ...} = rep_cterm ct
   1.287 +        and {sign=signu, t=u, T= U, ...} = rep_cterm cu
   1.288          val sign' = Sign.merge(sign, Sign.merge(signt, signu))
   1.289  	val tye' = Type.unify (#tsig(Sign.rep_sg sign')) ((T,U), tye)
   1.290  	  handle Type.TUNIFY => raise TYPE("add_types", [T,U], [t,u])
   1.291 @@ -246,8 +395,8 @@
   1.292    let val (sign,tye) = foldr add_types (ctpairs0, (#sign(rep_thm th),[]))
   1.293        val tsig = #tsig(Sign.rep_sg sign);
   1.294        fun instT(ct,cu) = let val inst = subst_TVars tye
   1.295 -			 in (Sign.cfun inst ct, Sign.cfun inst cu) end
   1.296 -      fun ctyp2 (ix,T) = (ix, Sign.ctyp_of sign T)
   1.297 +			 in (cterm_fun inst ct, cterm_fun inst cu) end
   1.298 +      fun ctyp2 (ix,T) = (ix, ctyp_of sign T)
   1.299    in  instantiate (map ctyp2 tye, map instT ctpairs0) th  end
   1.300    handle TERM _ => 
   1.301             raise THM("cterm_instantiate: incompatible signatures",0,[th])
   1.302 @@ -255,88 +404,6 @@
   1.303  end;
   1.304  
   1.305  
   1.306 -(*** Printing of theorems ***)
   1.307 -
   1.308 -(*If false, hypotheses are printed as dots*)
   1.309 -val show_hyps = ref true;
   1.310 -
   1.311 -fun pretty_thm th =
   1.312 -let val {sign, hyps, prop,...} = rep_thm th
   1.313 -    val hsymbs = if null hyps then []
   1.314 -		 else if !show_hyps then
   1.315 -		      [Pretty.brk 2,
   1.316 -		       Pretty.lst("[","]") (map (Sign.pretty_term sign) hyps)]
   1.317 -		 else Pretty.str" [" :: map (fn _ => Pretty.str".") hyps @
   1.318 -		      [Pretty.str"]"];
   1.319 -in Pretty.blk(0, Sign.pretty_term sign prop :: hsymbs) end;
   1.320 -
   1.321 -val string_of_thm = Pretty.string_of o pretty_thm;
   1.322 -
   1.323 -val pprint_thm = Pretty.pprint o Pretty.quote o pretty_thm;
   1.324 -
   1.325 -
   1.326 -(** Top-level commands for printing theorems **)
   1.327 -val print_thm = writeln o string_of_thm;
   1.328 -
   1.329 -fun prth th = (print_thm th; th);
   1.330 -
   1.331 -(*Print and return a sequence of theorems, separated by blank lines. *)
   1.332 -fun prthq thseq =
   1.333 -    (Sequence.prints (fn _ => print_thm) 100000 thseq;
   1.334 -     thseq);
   1.335 -
   1.336 -(*Print and return a list of theorems, separated by blank lines. *)
   1.337 -fun prths ths = (print_list_ln print_thm ths; ths);
   1.338 -
   1.339 -(*Other printing commands*)
   1.340 -val print_cterm = writeln o Sign.string_of_cterm;
   1.341 -val print_ctyp = writeln o Sign.string_of_ctyp;
   1.342 -fun pretty_sg sg = 
   1.343 -  Pretty.lst ("{", "}") (map (Pretty.str o !) (#stamps (Sign.rep_sg sg)));
   1.344 -
   1.345 -val pprint_sg = Pretty.pprint o pretty_sg;
   1.346 -
   1.347 -val pprint_theory = pprint_sg o sign_of;
   1.348 -
   1.349 -val print_sg = writeln o Pretty.string_of o pretty_sg;
   1.350 -val print_theory = print_sg o sign_of;
   1.351 -
   1.352 -
   1.353 -(** Print thm A1,...,An/B in "goal style" -- premises as numbered subgoals **)
   1.354 -
   1.355 -fun prettyprints es = writeln(Pretty.string_of(Pretty.blk(0,es)));
   1.356 -
   1.357 -fun print_goals maxgoals th : unit =
   1.358 -let val {sign, hyps, prop,...} = rep_thm th;
   1.359 -    fun printgoals (_, []) = ()
   1.360 -      | printgoals (n, A::As) =
   1.361 -	let val prettyn = Pretty.str(" " ^ string_of_int n ^ ". ");
   1.362 -	    val prettyA = Sign.pretty_term sign A
   1.363 -	in prettyprints[prettyn,prettyA]; 
   1.364 -           printgoals (n+1,As) 
   1.365 -        end;
   1.366 -    fun prettypair(t,u) =
   1.367 -        Pretty.blk(0, [Sign.pretty_term sign t, Pretty.str" =?=", Pretty.brk 1,
   1.368 -		       Sign.pretty_term sign u]);
   1.369 -    fun printff [] = ()
   1.370 -      | printff tpairs =
   1.371 -	 writeln("\nFlex-flex pairs:\n" ^
   1.372 -		 Pretty.string_of(Pretty.lst("","") (map prettypair tpairs)))
   1.373 -    val (tpairs,As,B) = Logic.strip_horn(prop);
   1.374 -    val ngoals = length As
   1.375 -in 
   1.376 -   writeln (Sign.string_of_term sign B);
   1.377 -   if ngoals=0 then writeln"No subgoals!"
   1.378 -   else if ngoals>maxgoals 
   1.379 -        then (printgoals (1, take(maxgoals,As));
   1.380 -	      writeln("A total of " ^ string_of_int ngoals ^ " subgoals..."))
   1.381 -        else printgoals (1, As);
   1.382 -   printff tpairs
   1.383 -end;
   1.384 -
   1.385 -(*"hook" for user interfaces: allows print_goals to be replaced*)
   1.386 -val print_goals_ref = ref print_goals;
   1.387 -
   1.388  (** theorem equality test is exported and used by BEST_FIRST **)
   1.389  
   1.390  (*equality of signatures means exact identity -- by ref equality*)
   1.391 @@ -363,42 +430,40 @@
   1.392  
   1.393  
   1.394  val reflexive_thm =
   1.395 -  let val cx = Sign.cterm_of Sign.pure (Var(("x",0),TVar(("'a",0),["logic"])))
   1.396 +  let val cx = cterm_of Sign.pure (Var(("x",0),TVar(("'a",0),["logic"])))
   1.397    in Thm.reflexive cx end;
   1.398  
   1.399  val symmetric_thm =
   1.400 -  let val xy = Sign.read_cterm Sign.pure ("x::'a::logic == y",propT)
   1.401 +  let val xy = read_cterm Sign.pure ("x::'a::logic == y",propT)
   1.402    in standard(Thm.implies_intr_hyps(Thm.symmetric(Thm.assume xy))) end;
   1.403  
   1.404  val transitive_thm =
   1.405 -  let val xy = Sign.read_cterm Sign.pure ("x::'a::logic == y",propT)
   1.406 -      val yz = Sign.read_cterm Sign.pure ("y::'a::logic == z",propT)
   1.407 +  let val xy = read_cterm Sign.pure ("x::'a::logic == y",propT)
   1.408 +      val yz = read_cterm Sign.pure ("y::'a::logic == z",propT)
   1.409        val xythm = Thm.assume xy and yzthm = Thm.assume yz
   1.410    in standard(Thm.implies_intr yz (Thm.transitive xythm yzthm)) end;
   1.411  
   1.412 -(** Below, a "conversion" has type sign->term->thm **)
   1.413 +(** Below, a "conversion" has type cterm -> thm **)
   1.414 +
   1.415 +val refl_cimplies = reflexive (cterm_of Sign.pure implies);
   1.416  
   1.417  (*In [A1,...,An]==>B, rewrite the selected A's only -- for rewrite_goals_tac*)
   1.418  (*Do not rewrite flex-flex pairs*)
   1.419 -fun goals_conv pred cv sign = 
   1.420 -  let val triv = reflexive o Sign.fake_cterm_of sign
   1.421 -      fun gconv i t =
   1.422 -        let val (A,B) = Logic.dest_implies t
   1.423 -            val (thA,j) = case A of
   1.424 -                  Const("=?=",_)$_$_ => (triv A,i)
   1.425 -                | _ => (if pred i then cv sign A else triv A, i+1)
   1.426 -	in  combination (combination (triv implies) thA) (gconv j B) end
   1.427 -        handle TERM _ => triv t
   1.428 +fun goals_conv pred cv = 
   1.429 +  let fun gconv i ct =
   1.430 +        let val (A,B) = Thm.dest_cimplies ct
   1.431 +            val (thA,j) = case term_of A of
   1.432 +                  Const("=?=",_)$_$_ => (reflexive A, i)
   1.433 +                | _ => (if pred i then cv A else reflexive A, i+1)
   1.434 +	in  combination (combination refl_cimplies thA) (gconv j B) end
   1.435 +        handle TERM _ => reflexive ct
   1.436    in gconv 1 end;
   1.437  
   1.438  (*Use a conversion to transform a theorem*)
   1.439 -fun fconv_rule cv th =
   1.440 -  let val {sign,prop,...} = rep_thm th
   1.441 -  in  equal_elim (cv sign prop) th  end;
   1.442 +fun fconv_rule cv th = equal_elim (cv (cprop_of th)) th;
   1.443  
   1.444  (*rewriting conversion*)
   1.445 -fun rew_conv mode prover mss sign t =
   1.446 -  rewrite_cterm mode mss prover (Sign.fake_cterm_of sign t);
   1.447 +fun rew_conv mode prover mss = rewrite_cterm mode mss prover;
   1.448  
   1.449  (*Rewrite a theorem*)
   1.450  fun rewrite_rule thms =
   1.451 @@ -420,11 +485,11 @@
   1.452  
   1.453  (*Given the term "a", takes (%x.t)==(%x.u) to t[a/x]==u[a/x]*)
   1.454  fun equal_abs_elim ca eqth =
   1.455 -  let val {sign=signa, t=a, ...} = Sign.rep_cterm ca
   1.456 +  let val {sign=signa, t=a, ...} = rep_cterm ca
   1.457        and combth = combination eqth (reflexive ca)
   1.458        val {sign,prop,...} = rep_thm eqth
   1.459        val (abst,absu) = Logic.dest_equals prop
   1.460 -      val cterm = Sign.cterm_of (Sign.merge (sign,signa))
   1.461 +      val cterm = cterm_of (Sign.merge (sign,signa))
   1.462    in  transitive (symmetric (beta_conversion (cterm (abst$a))))
   1.463             (transitive combth (beta_conversion (cterm (absu$a))))
   1.464    end
   1.465 @@ -439,7 +504,7 @@
   1.466    fun err th = raise THM("flexpair_inst: ", 0, [th])
   1.467    fun flexpair_inst def th =
   1.468      let val {prop = Const _ $ t $ u,  sign,...} = rep_thm th
   1.469 -	val cterm = Sign.cterm_of sign
   1.470 +	val cterm = cterm_of sign
   1.471  	fun cvar a = cterm(Var((a,0),alpha))
   1.472  	val def' = cterm_instantiate [(cvar"t", cterm t), (cvar"u", cterm u)] 
   1.473  		   def
   1.474 @@ -459,17 +524,17 @@
   1.475  (*** Some useful meta-theorems ***)
   1.476  
   1.477  (*The rule V/V, obtains assumption solving for eresolve_tac*)
   1.478 -val asm_rl = trivial(Sign.read_cterm Sign.pure ("PROP ?psi",propT));
   1.479 +val asm_rl = trivial(read_cterm Sign.pure ("PROP ?psi",propT));
   1.480  
   1.481  (*Meta-level cut rule: [| V==>W; V |] ==> W *)
   1.482 -val cut_rl = trivial(Sign.read_cterm Sign.pure 
   1.483 +val cut_rl = trivial(read_cterm Sign.pure 
   1.484  	("PROP ?psi ==> PROP ?theta", propT));
   1.485  
   1.486  (*Generalized elim rule for one conclusion; cut_rl with reversed premises: 
   1.487       [| PROP V;  PROP V ==> PROP W |] ==> PROP W *)
   1.488  val revcut_rl =
   1.489 -  let val V = Sign.read_cterm Sign.pure ("PROP V", propT)
   1.490 -      and VW = Sign.read_cterm Sign.pure ("PROP V ==> PROP W", propT);
   1.491 +  let val V = read_cterm Sign.pure ("PROP V", propT)
   1.492 +      and VW = read_cterm Sign.pure ("PROP V ==> PROP W", propT);
   1.493    in  standard (implies_intr V 
   1.494  		(implies_intr VW
   1.495  		 (implies_elim (assume VW) (assume V))))
   1.496 @@ -477,9 +542,9 @@
   1.497  
   1.498  (* (!!x. PROP ?V) == PROP ?V       Allows removal of redundant parameters*)
   1.499  val triv_forall_equality =
   1.500 -  let val V  = Sign.read_cterm Sign.pure ("PROP V", propT)
   1.501 -      and QV = Sign.read_cterm Sign.pure ("!!x::'a. PROP V", propT)
   1.502 -      and x  = Sign.read_cterm Sign.pure ("x", TFree("'a",["logic"]));
   1.503 +  let val V  = read_cterm Sign.pure ("PROP V", propT)
   1.504 +      and QV = read_cterm Sign.pure ("!!x::'a. PROP V", propT)
   1.505 +      and x  = read_cterm Sign.pure ("x", TFree("'a",["logic"]));
   1.506    in  standard (equal_intr (implies_intr QV (forall_elim x (assume QV)))
   1.507  		           (implies_intr V  (forall_intr x (assume V))))
   1.508    end;