src/FOLP/simp.ML
changeset 1459 d12da312eff4
parent 611 11098f505bfe
child 1512 ce37c64244c0
     1.1 --- a/src/FOLP/simp.ML	Mon Jan 29 13:56:41 1996 +0100
     1.2 +++ b/src/FOLP/simp.ML	Mon Jan 29 13:58:15 1996 +0100
     1.3 @@ -76,13 +76,13 @@
     1.4    rewrite rules are not ordered.*)
     1.5  fun net_tac net =
     1.6    SUBGOAL(fn (prem,i) => 
     1.7 -	  resolve_tac (Net.unify_term net (strip_assums_concl prem)) i);
     1.8 +          resolve_tac (Net.unify_term net (strip_assums_concl prem)) i);
     1.9  
    1.10  (*match subgoal i against possible theorems indexed by lhs in the net*)
    1.11  fun lhs_net_tac net =
    1.12    SUBGOAL(fn (prem,i) => 
    1.13 -	  biresolve_tac (Net.unify_term net
    1.14 -		       (lhs_of (strip_assums_concl prem))) i);
    1.15 +          biresolve_tac (Net.unify_term net
    1.16 +                       (lhs_of (strip_assums_concl prem))) i);
    1.17  
    1.18  fun nth_subgoal i thm = nth_elem(i-1,prems_of thm);
    1.19  
    1.20 @@ -113,12 +113,12 @@
    1.21  val norms =
    1.22    let fun norm thm = 
    1.23        case lhs_of(concl_of thm) of
    1.24 -	  Const(n,_)$_ => n
    1.25 -	| _ => (prths normE_thms; error"No constant in lhs of a norm_thm")
    1.26 +          Const(n,_)$_ => n
    1.27 +        | _ => (prths normE_thms; error"No constant in lhs of a norm_thm")
    1.28    in map norm normE_thms end;
    1.29  
    1.30  fun lhs_is_NORM(thm,i) = case lhs_of_eq i thm of
    1.31 -	Const(s,_)$_ => s mem norms | _ => false;
    1.32 +        Const(s,_)$_ => s mem norms | _ => false;
    1.33  
    1.34  val refl_tac = resolve_tac refl_thms;
    1.35  
    1.36 @@ -136,7 +136,7 @@
    1.37  
    1.38  (*Applies tactic and returns the first resulting state, FAILS if none!*)
    1.39  fun one_result(tac,thm) = case Sequence.pull(tapply(tac,thm)) of
    1.40 -	Some(thm',_) => thm'
    1.41 +        Some(thm',_) => thm'
    1.42        | None => raise THM("Simplifier: could not continue", 0, [thm]);
    1.43  
    1.44  fun res1(thm,thms,i) = one_result(resolve_tac thms i,thm);
    1.45 @@ -147,8 +147,8 @@
    1.46  (*get name of the constant from conclusion of a congruence rule*)
    1.47  fun cong_const cong = 
    1.48      case head_of (lhs_of (concl_of cong)) of
    1.49 -	Const(c,_) => c
    1.50 -      | _ => ""			(*a placeholder distinct from const names*);
    1.51 +        Const(c,_) => c
    1.52 +      | _ => ""                 (*a placeholder distinct from const names*);
    1.53  
    1.54  (*true if the term is an atomic proposition (no ==> signs) *)
    1.55  val atomic = null o strip_assums_hyp;
    1.56 @@ -156,34 +156,34 @@
    1.57  (*ccs contains the names of the constants possessing congruence rules*)
    1.58  fun add_hidden_vars ccs =
    1.59    let fun add_hvars(tm,hvars) = case tm of
    1.60 -	      Abs(_,_,body) => add_term_vars(body,hvars)
    1.61 -	    | _$_ => let val (f,args) = strip_comb tm 
    1.62 -		     in case f of
    1.63 -			    Const(c,T) => 
    1.64 -				if c mem ccs
    1.65 -				then foldr add_hvars (args,hvars)
    1.66 -				else add_term_vars(tm,hvars)
    1.67 -			  | _ => add_term_vars(tm,hvars)
    1.68 -		     end
    1.69 -	    | _ => hvars;
    1.70 +              Abs(_,_,body) => add_term_vars(body,hvars)
    1.71 +            | _$_ => let val (f,args) = strip_comb tm 
    1.72 +                     in case f of
    1.73 +                            Const(c,T) => 
    1.74 +                                if c mem ccs
    1.75 +                                then foldr add_hvars (args,hvars)
    1.76 +                                else add_term_vars(tm,hvars)
    1.77 +                          | _ => add_term_vars(tm,hvars)
    1.78 +                     end
    1.79 +            | _ => hvars;
    1.80    in add_hvars end;
    1.81  
    1.82  fun add_new_asm_vars new_asms =
    1.83      let fun itf((tm,at),vars) =
    1.84 -		if at then vars else add_term_vars(tm,vars)
    1.85 -	fun add_list(tm,al,vars) = let val (_,tml) = strip_comb tm
    1.86 -		in if length(tml)=length(al)
    1.87 -		   then foldr itf (tml~~al,vars)
    1.88 -		   else vars
    1.89 -		end
    1.90 -	fun add_vars (tm,vars) = case tm of
    1.91 -		  Abs (_,_,body) => add_vars(body,vars)
    1.92 -		| r$s => (case head_of tm of
    1.93 -			  Const(c,T) => (case assoc(new_asms,c) of
    1.94 -				  None => add_vars(r,add_vars(s,vars))
    1.95 -				| Some(al) => add_list(tm,al,vars))
    1.96 -			| _ => add_vars(r,add_vars(s,vars)))
    1.97 -		| _ => vars
    1.98 +                if at then vars else add_term_vars(tm,vars)
    1.99 +        fun add_list(tm,al,vars) = let val (_,tml) = strip_comb tm
   1.100 +                in if length(tml)=length(al)
   1.101 +                   then foldr itf (tml~~al,vars)
   1.102 +                   else vars
   1.103 +                end
   1.104 +        fun add_vars (tm,vars) = case tm of
   1.105 +                  Abs (_,_,body) => add_vars(body,vars)
   1.106 +                | r$s => (case head_of tm of
   1.107 +                          Const(c,T) => (case assoc(new_asms,c) of
   1.108 +                                  None => add_vars(r,add_vars(s,vars))
   1.109 +                                | Some(al) => add_list(tm,al,vars))
   1.110 +                        | _ => add_vars(r,add_vars(s,vars)))
   1.111 +                | _ => vars
   1.112      in add_vars end;
   1.113  
   1.114  
   1.115 @@ -197,27 +197,27 @@
   1.116      val hvars = foldr (add_hidden_vars ccs) (lhs::rhs::asms,[])
   1.117      val hvars = add_new_asm_vars new_asms (rhs,hvars)
   1.118      fun it_asms (asm,hvars) =
   1.119 -	if atomic asm then add_new_asm_vars new_asms (asm,hvars)
   1.120 -	else add_term_frees(asm,hvars)
   1.121 +        if atomic asm then add_new_asm_vars new_asms (asm,hvars)
   1.122 +        else add_term_frees(asm,hvars)
   1.123      val hvars = foldr it_asms (asms,hvars)
   1.124      val hvs = map (#1 o dest_Var) hvars
   1.125      val refl1_tac = refl_tac 1
   1.126      val add_norm_tac = DEPTH_FIRST (has_fewer_prems nops)
   1.127 -	      (STATE(fn thm =>
   1.128 -		case head_of(rhs_of_eq 1 thm) of
   1.129 -		  Var(ixn,_) => if ixn mem hvs then refl1_tac
   1.130 -				else resolve_tac normI_thms 1 ORELSE refl1_tac
   1.131 -		| Const _ => resolve_tac normI_thms 1 ORELSE
   1.132 -			     resolve_tac congs 1 ORELSE refl1_tac
   1.133 -		| Free _ => resolve_tac congs 1 ORELSE refl1_tac
   1.134 -		| _ => refl1_tac))
   1.135 +              (STATE(fn thm =>
   1.136 +                case head_of(rhs_of_eq 1 thm) of
   1.137 +                  Var(ixn,_) => if ixn mem hvs then refl1_tac
   1.138 +                                else resolve_tac normI_thms 1 ORELSE refl1_tac
   1.139 +                | Const _ => resolve_tac normI_thms 1 ORELSE
   1.140 +                             resolve_tac congs 1 ORELSE refl1_tac
   1.141 +                | Free _ => resolve_tac congs 1 ORELSE refl1_tac
   1.142 +                | _ => refl1_tac))
   1.143      val Some(thm'',_) = Sequence.pull(tapply(add_norm_tac,thm'))
   1.144  in thm'' end;
   1.145  
   1.146  fun add_norm_tags congs =
   1.147      let val ccs = map cong_const congs
   1.148 -	val new_asms = filter (exists not o #2)
   1.149 -		(ccs ~~ (map (map atomic o prems_of) congs));
   1.150 +        val new_asms = filter (exists not o #2)
   1.151 +                (ccs ~~ (map (map atomic o prems_of) congs));
   1.152      in add_norms(congs,ccs,new_asms) end;
   1.153  
   1.154  fun normed_rews congs =
   1.155 @@ -225,7 +225,7 @@
   1.156    in fn thm => map (varifyT o add_norms o mk_trans) (mk_rew_rules(freezeT thm))
   1.157    end;
   1.158  
   1.159 -fun NORM norm_lhs_tac = EVERY'[resolve_tac [red2], norm_lhs_tac, refl_tac];
   1.160 +fun NORM norm_lhs_tac = EVERY'[rtac red2 , norm_lhs_tac, refl_tac];
   1.161  
   1.162  val trans_norms = map mk_trans normE_thms;
   1.163  
   1.164 @@ -233,15 +233,15 @@
   1.165  (* SIMPSET *)
   1.166  
   1.167  datatype simpset =
   1.168 -	SS of {auto_tac: int -> tactic,
   1.169 -	       congs: thm list,
   1.170 -	       cong_net: thm Net.net,
   1.171 -	       mk_simps: thm -> thm list,
   1.172 -	       simps: (thm * thm list) list,
   1.173 -	       simp_net: thm Net.net}
   1.174 +        SS of {auto_tac: int -> tactic,
   1.175 +               congs: thm list,
   1.176 +               cong_net: thm Net.net,
   1.177 +               mk_simps: thm -> thm list,
   1.178 +               simps: (thm * thm list) list,
   1.179 +               simp_net: thm Net.net}
   1.180  
   1.181  val empty_ss = SS{auto_tac= K no_tac, congs=[], cong_net=Net.empty,
   1.182 -		  mk_simps=normed_rews[], simps=[], simp_net=Net.empty};
   1.183 +                  mk_simps=normed_rews[], simps=[], simp_net=Net.empty};
   1.184  
   1.185  (** Insertion of congruences and rewrites **)
   1.186  
   1.187 @@ -289,10 +289,10 @@
   1.188  
   1.189  fun delrew(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net}, thm) =
   1.190  let fun find((p as (th,ths))::ps',ps) =
   1.191 -	  if eq_thm(thm,th) then (ths,ps@ps') else find(ps',p::ps)
   1.192 +          if eq_thm(thm,th) then (ths,ps@ps') else find(ps',p::ps)
   1.193        | find([],simps') = (writeln"\nNo such rewrite or congruence rule:";
   1.194 -			   print_thm thm;
   1.195 -			   ([],simps'))
   1.196 +                           print_thm thm;
   1.197 +                           ([],simps'))
   1.198      val (thms,simps') = find(simps,[])
   1.199  in SS{auto_tac=auto_tac, congs=congs, cong_net=cong_net, mk_simps=mk_simps,
   1.200        simps = simps', simp_net = delete_thms(thms,simp_net)}
   1.201 @@ -311,8 +311,8 @@
   1.202  fun dest_ss(SS{congs,simps,...}) = (congs, map #1 simps);
   1.203  
   1.204  fun print_ss(SS{congs,simps,...}) =
   1.205 -	(writeln"Congruences:"; prths congs;
   1.206 -	 writeln"Rewrite Rules:"; prths (map #1 simps); ());
   1.207 +        (writeln"Congruences:"; prths congs;
   1.208 +         writeln"Rewrite Rules:"; prths (map #1 simps); ());
   1.209  
   1.210  
   1.211  (* Rewriting with conditionals *)
   1.212 @@ -322,32 +322,32 @@
   1.213  
   1.214  fun if_rewritable ifc i thm =
   1.215      let val tm = goal_concl i thm
   1.216 -	fun nobound(Abs(_,_,tm),j,k) = nobound(tm,j,k+1)
   1.217 -	  | nobound(s$t,j,k) = nobound(s,j,k) andalso nobound(t,j,k)
   1.218 -	  | nobound(Bound n,j,k) = n < k orelse k+j <= n
   1.219 -	  | nobound(_) = true;
   1.220 -	fun check_args(al,j) = forall (fn t => nobound(t,j,0)) al
   1.221 -	fun find_if(Abs(_,_,tm),j) = find_if(tm,j+1)
   1.222 -	  | find_if(tm as s$t,j) = let val (f,al) = strip_comb tm in
   1.223 -		case f of Const(c,_) =>	if c=ifc then check_args(al,j)
   1.224 -			else find_if(s,j) orelse find_if(t,j)
   1.225 -		| _ => find_if(s,j) orelse find_if(t,j) end
   1.226 -	  | find_if(_) = false;
   1.227 +        fun nobound(Abs(_,_,tm),j,k) = nobound(tm,j,k+1)
   1.228 +          | nobound(s$t,j,k) = nobound(s,j,k) andalso nobound(t,j,k)
   1.229 +          | nobound(Bound n,j,k) = n < k orelse k+j <= n
   1.230 +          | nobound(_) = true;
   1.231 +        fun check_args(al,j) = forall (fn t => nobound(t,j,0)) al
   1.232 +        fun find_if(Abs(_,_,tm),j) = find_if(tm,j+1)
   1.233 +          | find_if(tm as s$t,j) = let val (f,al) = strip_comb tm in
   1.234 +                case f of Const(c,_) => if c=ifc then check_args(al,j)
   1.235 +                        else find_if(s,j) orelse find_if(t,j)
   1.236 +                | _ => find_if(s,j) orelse find_if(t,j) end
   1.237 +          | find_if(_) = false;
   1.238      in find_if(tm,0) end;
   1.239  
   1.240  fun IF1_TAC cong_tac i =
   1.241      let fun seq_try (ifth::ifths,ifc::ifcs) thm = tapply(
   1.242 -		COND (if_rewritable ifc i) (DETERM(resolve_tac[ifth]i))
   1.243 -			(Tactic(seq_try(ifths,ifcs))), thm)
   1.244 -	      | seq_try([],_) thm = tapply(no_tac,thm)
   1.245 -	and try_rew thm = tapply(Tactic(seq_try(case_rews,case_consts))
   1.246 -				 ORELSE Tactic one_subt, thm)
   1.247 -	and one_subt thm =
   1.248 -		let val test = has_fewer_prems (nprems_of thm + 1)
   1.249 -		    fun loop thm = tapply(COND test no_tac
   1.250 -			((Tactic try_rew THEN DEPTH_FIRST test (refl_tac i))
   1.251 -			 ORELSE (refl_tac i THEN Tactic loop)), thm)
   1.252 -		in tapply(cong_tac THEN Tactic loop, thm) end
   1.253 +                COND (if_rewritable ifc i) (DETERM(rtac ifth i))
   1.254 +                        (Tactic(seq_try(ifths,ifcs))), thm)
   1.255 +              | seq_try([],_) thm = tapply(no_tac,thm)
   1.256 +        and try_rew thm = tapply(Tactic(seq_try(case_rews,case_consts))
   1.257 +                                 ORELSE Tactic one_subt, thm)
   1.258 +        and one_subt thm =
   1.259 +                let val test = has_fewer_prems (nprems_of thm + 1)
   1.260 +                    fun loop thm = tapply(COND test no_tac
   1.261 +                        ((Tactic try_rew THEN DEPTH_FIRST test (refl_tac i))
   1.262 +                         ORELSE (refl_tac i THEN Tactic loop)), thm)
   1.263 +                in tapply(cong_tac THEN Tactic loop, thm) end
   1.264      in COND (may_match(case_consts,i)) (Tactic try_rew) no_tac end;
   1.265  
   1.266  fun CASE_TAC (SS{cong_net,...}) i =
   1.267 @@ -357,7 +357,7 @@
   1.268  (* Rewriting Automaton *)
   1.269  
   1.270  datatype cntrl = STOP | MK_EQ | ASMS of int | SIMP_LHS | REW | REFL | TRUE
   1.271 -	       | PROVE | POP_CS | POP_ARTR | IF;
   1.272 +               | PROVE | POP_CS | POP_ARTR | IF;
   1.273  (*
   1.274  fun pr_cntrl c = case c of STOP => prs("STOP") | MK_EQ => prs("MK_EQ") |
   1.275  ASMS i => print_int i | POP_ARTR => prs("POP_ARTR") |
   1.276 @@ -367,7 +367,7 @@
   1.277  *)
   1.278  fun simp_refl([],_,ss) = ss
   1.279    | simp_refl(a'::ns,a,ss) = if a'=a then simp_refl(ns,a,SIMP_LHS::REFL::ss)
   1.280 -	else simp_refl(ns,a,ASMS(a)::SIMP_LHS::REFL::POP_ARTR::ss);
   1.281 +        else simp_refl(ns,a,ASMS(a)::SIMP_LHS::REFL::POP_ARTR::ss);
   1.282  
   1.283  (** Tracing **)
   1.284  
   1.285 @@ -381,13 +381,13 @@
   1.286  (*Select subgoal i from proof state; substitute parameters, for printing*)
   1.287  fun prepare_goal i st =
   1.288      let val subgi = nth_subgoal i st
   1.289 -	val params = rev(strip_params subgi)
   1.290 +        val params = rev(strip_params subgi)
   1.291      in variants_abs (params, strip_assums_concl subgi) end;
   1.292  
   1.293  (*print lhs of conclusion of subgoal i*)
   1.294  fun pr_goal_lhs i st =
   1.295      writeln (Sign.string_of_term (#sign(rep_thm st)) 
   1.296 -	     (lhs_of (prepare_goal i st)));
   1.297 +             (lhs_of (prepare_goal i st)));
   1.298  
   1.299  (*print conclusion of subgoal i*)
   1.300  fun pr_goal_concl i st =
   1.301 @@ -404,17 +404,17 @@
   1.302      if !tracing
   1.303      then (if not_asms then () else writeln"Assumption used in";
   1.304            pr_goal_lhs i thm; writeln"->"; pr_goal_lhs (i+n) thm';
   1.305 -	  if n>0 then (writeln"Conditions:"; pr_goals (i, i+n-1) thm')
   1.306 +          if n>0 then (writeln"Conditions:"; pr_goals (i, i+n-1) thm')
   1.307            else ();
   1.308            writeln"" )
   1.309      else ();
   1.310  
   1.311  (* Skip the first n hyps of a goal, and return the rest in generalized form *)
   1.312  fun strip_varify(Const("==>", _) $ H $ B, n, vs) =
   1.313 -	if n=0 then subst_bounds(vs,H)::strip_varify(B,0,vs)
   1.314 -	else strip_varify(B,n-1,vs)
   1.315 +        if n=0 then subst_bounds(vs,H)::strip_varify(B,0,vs)
   1.316 +        else strip_varify(B,n-1,vs)
   1.317    | strip_varify(Const("all",_)$Abs(_,T,t), n, vs) =
   1.318 -	strip_varify(t,n,Var(("?",length vs),T)::vs)
   1.319 +        strip_varify(t,n,Var(("?",length vs),T)::vs)
   1.320    | strip_varify  _  = [];
   1.321  
   1.322  fun execute(ss,if_fl,auto_tac,cong_tac,net,i,thm) = let
   1.323 @@ -423,73 +423,73 @@
   1.324      if var_lhs(thm,i) then (ss,thm,anet,ats,cs) else
   1.325      if lhs_is_NORM(thm,i) then (ss, res1(thm,trans_norms,i), anet,ats,cs)
   1.326      else case Sequence.pull(tapply(cong_tac i,thm)) of
   1.327 -	    Some(thm',_) =>
   1.328 -		    let val ps = prems_of thm and ps' = prems_of thm';
   1.329 -			val n = length(ps')-length(ps);
   1.330 -			val a = length(strip_assums_hyp(nth_elem(i-1,ps)))
   1.331 -			val l = map (fn p => length(strip_assums_hyp(p)))
   1.332 -				    (take(n,drop(i-1,ps')));
   1.333 -		    in (simp_refl(rev(l),a,REW::ss),thm',anet,ats,cs) end
   1.334 -	  | None => (REW::ss,thm,anet,ats,cs);
   1.335 +            Some(thm',_) =>
   1.336 +                    let val ps = prems_of thm and ps' = prems_of thm';
   1.337 +                        val n = length(ps')-length(ps);
   1.338 +                        val a = length(strip_assums_hyp(nth_elem(i-1,ps)))
   1.339 +                        val l = map (fn p => length(strip_assums_hyp(p)))
   1.340 +                                    (take(n,drop(i-1,ps')));
   1.341 +                    in (simp_refl(rev(l),a,REW::ss),thm',anet,ats,cs) end
   1.342 +          | None => (REW::ss,thm,anet,ats,cs);
   1.343  
   1.344  (*NB: the "Adding rewrites:" trace will look strange because assumptions
   1.345        are represented by rules, generalized over their parameters*)
   1.346  fun add_asms(ss,thm,a,anet,ats,cs) =
   1.347      let val As = strip_varify(nth_subgoal i thm, a, []);
   1.348 -	val thms = map (trivial o cterm_of(#sign(rep_thm(thm))))As;
   1.349 -	val new_rws = flat(map mk_rew_rules thms);
   1.350 -	val rwrls = map mk_trans (flat(map mk_rew_rules thms));
   1.351 -	val anet' = foldr lhs_insert_thm (rwrls,anet)
   1.352 +        val thms = map (trivial o cterm_of(#sign(rep_thm(thm))))As;
   1.353 +        val new_rws = flat(map mk_rew_rules thms);
   1.354 +        val rwrls = map mk_trans (flat(map mk_rew_rules thms));
   1.355 +        val anet' = foldr lhs_insert_thm (rwrls,anet)
   1.356      in  if !tracing andalso not(null new_rws)
   1.357 -	then (writeln"Adding rewrites:";  prths new_rws;  ())
   1.358 -	else ();
   1.359 -	(ss,thm,anet',anet::ats,cs) 
   1.360 +        then (writeln"Adding rewrites:";  prths new_rws;  ())
   1.361 +        else ();
   1.362 +        (ss,thm,anet',anet::ats,cs) 
   1.363      end;
   1.364  
   1.365  fun rew(seq,thm,ss,anet,ats,cs, more) = case Sequence.pull seq of
   1.366        Some(thm',seq') =>
   1.367 -	    let val n = (nprems_of thm') - (nprems_of thm)
   1.368 -	    in pr_rew(i,n,thm,thm',more);
   1.369 -	       if n=0 then (SIMP_LHS::ss, thm', anet, ats, cs)
   1.370 -	       else ((replicate n PROVE) @ (POP_CS::SIMP_LHS::ss),
   1.371 -		     thm', anet, ats, (ss,thm,anet,ats,seq',more)::cs)
   1.372 -	    end
   1.373 +            let val n = (nprems_of thm') - (nprems_of thm)
   1.374 +            in pr_rew(i,n,thm,thm',more);
   1.375 +               if n=0 then (SIMP_LHS::ss, thm', anet, ats, cs)
   1.376 +               else ((replicate n PROVE) @ (POP_CS::SIMP_LHS::ss),
   1.377 +                     thm', anet, ats, (ss,thm,anet,ats,seq',more)::cs)
   1.378 +            end
   1.379      | None => if more
   1.380 -	    then rew(tapply(lhs_net_tac anet i THEN assume_tac i,thm),
   1.381 -		     thm,ss,anet,ats,cs,false)
   1.382 -	    else (ss,thm,anet,ats,cs);
   1.383 +            then rew(tapply(lhs_net_tac anet i THEN assume_tac i,thm),
   1.384 +                     thm,ss,anet,ats,cs,false)
   1.385 +            else (ss,thm,anet,ats,cs);
   1.386  
   1.387  fun try_true(thm,ss,anet,ats,cs) =
   1.388      case Sequence.pull(tapply(auto_tac i,thm)) of
   1.389        Some(thm',_) => (ss,thm',anet,ats,cs)
   1.390      | None => let val (ss0,thm0,anet0,ats0,seq,more)::cs0 = cs
   1.391 -	      in if !tracing
   1.392 -		 then (writeln"*** Failed to prove precondition. Normal form:";
   1.393 -		       pr_goal_concl i thm;  writeln"")
   1.394 -		 else ();
   1.395 -		 rew(seq,thm0,ss0,anet0,ats0,cs0,more)
   1.396 -	      end;
   1.397 +              in if !tracing
   1.398 +                 then (writeln"*** Failed to prove precondition. Normal form:";
   1.399 +                       pr_goal_concl i thm;  writeln"")
   1.400 +                 else ();
   1.401 +                 rew(seq,thm0,ss0,anet0,ats0,cs0,more)
   1.402 +              end;
   1.403  
   1.404  fun if_exp(thm,ss,anet,ats,cs) =
   1.405 -	case Sequence.pull(tapply(IF1_TAC (cong_tac i) i,thm)) of
   1.406 -		Some(thm',_) => (SIMP_LHS::IF::ss,thm',anet,ats,cs)
   1.407 -	      | None => (ss,thm,anet,ats,cs);
   1.408 +        case Sequence.pull(tapply(IF1_TAC (cong_tac i) i,thm)) of
   1.409 +                Some(thm',_) => (SIMP_LHS::IF::ss,thm',anet,ats,cs)
   1.410 +              | None => (ss,thm,anet,ats,cs);
   1.411  
   1.412  fun step(s::ss, thm, anet, ats, cs) = case s of
   1.413 -	  MK_EQ => (ss, res1(thm,[red2],i), anet, ats, cs)
   1.414 -	| ASMS(a) => add_asms(ss,thm,a,anet,ats,cs)
   1.415 -	| SIMP_LHS => simp_lhs(thm,ss,anet,ats,cs)
   1.416 -	| REW => rew(tapply(net_tac net i,thm),thm,ss,anet,ats,cs,true)
   1.417 -	| REFL => (ss, res1(thm,refl_thms,i), anet, ats, cs)
   1.418 -	| TRUE => try_true(res1(thm,refl_thms,i),ss,anet,ats,cs)
   1.419 -	| PROVE => (if if_fl then MK_EQ::SIMP_LHS::IF::TRUE::ss
   1.420 -		    else MK_EQ::SIMP_LHS::TRUE::ss, thm, anet, ats, cs)
   1.421 -	| POP_ARTR => (ss,thm,hd ats,tl ats,cs)
   1.422 -	| POP_CS => (ss,thm,anet,ats,tl cs)
   1.423 -	| IF => if_exp(thm,ss,anet,ats,cs);
   1.424 +          MK_EQ => (ss, res1(thm,[red2],i), anet, ats, cs)
   1.425 +        | ASMS(a) => add_asms(ss,thm,a,anet,ats,cs)
   1.426 +        | SIMP_LHS => simp_lhs(thm,ss,anet,ats,cs)
   1.427 +        | REW => rew(tapply(net_tac net i,thm),thm,ss,anet,ats,cs,true)
   1.428 +        | REFL => (ss, res1(thm,refl_thms,i), anet, ats, cs)
   1.429 +        | TRUE => try_true(res1(thm,refl_thms,i),ss,anet,ats,cs)
   1.430 +        | PROVE => (if if_fl then MK_EQ::SIMP_LHS::IF::TRUE::ss
   1.431 +                    else MK_EQ::SIMP_LHS::TRUE::ss, thm, anet, ats, cs)
   1.432 +        | POP_ARTR => (ss,thm,hd ats,tl ats,cs)
   1.433 +        | POP_CS => (ss,thm,anet,ats,tl cs)
   1.434 +        | IF => if_exp(thm,ss,anet,ats,cs);
   1.435  
   1.436  fun exec(state as (s::ss, thm, _, _, _)) =
   1.437 -	if s=STOP then thm else exec(step(state));
   1.438 +        if s=STOP then thm else exec(step(state));
   1.439  
   1.440  in exec(ss, thm, Net.empty, [], []) end;
   1.441  
   1.442 @@ -497,9 +497,9 @@
   1.443  fun EXEC_TAC(ss,fl) (SS{auto_tac,cong_net,simp_net,...}) =
   1.444  let val cong_tac = net_tac cong_net
   1.445  in fn i => Tactic(fn thm =>
   1.446 -	if i <= 0 orelse nprems_of thm < i then Sequence.null
   1.447 -	else Sequence.single(execute(ss,fl,auto_tac,cong_tac,simp_net,i,thm)))
   1.448 -	   THEN TRY(auto_tac i)
   1.449 +        if i <= 0 orelse nprems_of thm < i then Sequence.null
   1.450 +        else Sequence.single(execute(ss,fl,auto_tac,cong_tac,simp_net,i,thm)))
   1.451 +           THEN TRY(auto_tac i)
   1.452  end;
   1.453  
   1.454  val SIMP_TAC = EXEC_TAC([MK_EQ,SIMP_LHS,REFL,STOP],false);
   1.455 @@ -513,7 +513,7 @@
   1.456  fun REWRITE (ss,fl) (SS{auto_tac,cong_net,simp_net,...}) =
   1.457  let val cong_tac = net_tac cong_net
   1.458  in fn thm => let val state = thm RSN (2,red1)
   1.459 -	     in execute(ss,fl,auto_tac,cong_tac,simp_net,1,state) end
   1.460 +             in execute(ss,fl,auto_tac,cong_tac,simp_net,1,state) end
   1.461  end;
   1.462  
   1.463  val SIMP_THM = REWRITE ([ASMS(0),SIMP_LHS,IF,REFL,STOP],false);
   1.464 @@ -529,7 +529,7 @@
   1.465    | exp_app(i,t) = exp_app(i-1,t $ Bound (i-1));
   1.466  
   1.467  fun exp_abs(Type("fun",[T1,T2]),t,i) =
   1.468 -	Abs("x"^string_of_int i,T1,exp_abs(T2,t,i+1))
   1.469 +        Abs("x"^string_of_int i,T1,exp_abs(T2,t,i+1))
   1.470    | exp_abs(T,t,i) = exp_app(i,t);
   1.471  
   1.472  fun eta_Var(ixn,T) = exp_abs(T,Var(ixn,T),0);
   1.473 @@ -537,20 +537,20 @@
   1.474  
   1.475  fun Pinst(f,fT,(eq,eqT),k,i,T,yik,Ts) =
   1.476  let fun xn_list(x,n) =
   1.477 -	let val ixs = map (fn i => (x^(radixstring(26,"a",i)),0)) (0 upto n);
   1.478 -	in map eta_Var (ixs ~~ (take(n+1,Ts))) end
   1.479 +        let val ixs = map (fn i => (x^(radixstring(26,"a",i)),0)) (0 upto n);
   1.480 +        in map eta_Var (ixs ~~ (take(n+1,Ts))) end
   1.481      val lhs = list_comb(f,xn_list("X",k-1))
   1.482      val rhs = list_comb(f,xn_list("X",i-1) @ [Bound 0] @ yik)
   1.483  in Abs("", T, Const(eq,[fT,fT]--->eqT) $ lhs $ rhs) end;
   1.484  
   1.485  fun find_subst tsig T =
   1.486  let fun find (thm::thms) =
   1.487 -	let val (Const(_,cT), va, vb) =	dest_red(hd(prems_of thm));
   1.488 -	    val [P] = add_term_vars(concl_of thm,[]) \\ [va,vb]
   1.489 -	    val eqT::_ = binder_types cT
   1.490 +        let val (Const(_,cT), va, vb) = dest_red(hd(prems_of thm));
   1.491 +            val [P] = add_term_vars(concl_of thm,[]) \\ [va,vb]
   1.492 +            val eqT::_ = binder_types cT
   1.493          in if Type.typ_instance(tsig,T,eqT) then Some(thm,va,vb,P)
   1.494 -	   else find thms
   1.495 -	end
   1.496 +           else find thms
   1.497 +        end
   1.498        | find [] = None
   1.499  in find subst_thms end;
   1.500  
   1.501 @@ -558,20 +558,20 @@
   1.502  let val tsig = #tsig(Sign.rep_sg sg);
   1.503      val k = length aTs;
   1.504      fun ri((subst,va as Var(_,Ta),vb as Var(_,Tb),P),i,si,T,yik) =
   1.505 -	let val ca = cterm_of sg va
   1.506 -	    and cx = cterm_of sg (eta_Var(("X"^si,0),T))
   1.507 -	    val cb = cterm_of sg vb
   1.508 -	    and cy = cterm_of sg (eta_Var(("Y"^si,0),T))
   1.509 -	    val cP = cterm_of sg P
   1.510 -	    and cp = cterm_of sg (Pinst(f,rT,eq,k,i,T,yik,aTs))
   1.511 -	in cterm_instantiate [(ca,cx),(cb,cy),(cP,cp)] subst end;
   1.512 +        let val ca = cterm_of sg va
   1.513 +            and cx = cterm_of sg (eta_Var(("X"^si,0),T))
   1.514 +            val cb = cterm_of sg vb
   1.515 +            and cy = cterm_of sg (eta_Var(("Y"^si,0),T))
   1.516 +            val cP = cterm_of sg P
   1.517 +            and cp = cterm_of sg (Pinst(f,rT,eq,k,i,T,yik,aTs))
   1.518 +        in cterm_instantiate [(ca,cx),(cb,cy),(cP,cp)] subst end;
   1.519      fun mk(c,T::Ts,i,yik) =
   1.520 -	let val si = radixstring(26,"a",i)
   1.521 -	in case find_subst tsig T of
   1.522 -	     None => mk(c,Ts,i-1,eta_Var(("X"^si,0),T)::yik)
   1.523 -	   | Some s => let val c' = c RSN (2,ri(s,i,si,T,yik))
   1.524 -		       in mk(c',Ts,i-1,eta_Var(("Y"^si,0),T)::yik) end
   1.525 -	end
   1.526 +        let val si = radixstring(26,"a",i)
   1.527 +        in case find_subst tsig T of
   1.528 +             None => mk(c,Ts,i-1,eta_Var(("X"^si,0),T)::yik)
   1.529 +           | Some s => let val c' = c RSN (2,ri(s,i,si,T,yik))
   1.530 +                       in mk(c',Ts,i-1,eta_Var(("Y"^si,0),T)::yik) end
   1.531 +        end
   1.532        | mk(c,[],_,_) = c;
   1.533  in mk(refl,rev aTs,k-1,[]) end;
   1.534  
   1.535 @@ -579,10 +579,10 @@
   1.536  let val (aTs,rT) = strip_type T;
   1.537      val tsig = #tsig(Sign.rep_sg sg);
   1.538      fun find_refl(r::rs) =
   1.539 -	let val (Const(eq,eqT),_,_) = dest_red(concl_of r)
   1.540 -	in if Type.typ_instance(tsig, rT, hd(binder_types eqT))
   1.541 -	   then Some(r,(eq,body_type eqT)) else find_refl rs
   1.542 -	end
   1.543 +        let val (Const(eq,eqT),_,_) = dest_red(concl_of r)
   1.544 +        in if Type.typ_instance(tsig, rT, hd(binder_types eqT))
   1.545 +           then Some(r,(eq,body_type eqT)) else find_refl rs
   1.546 +        end
   1.547        | find_refl([]) = None;
   1.548  in case find_refl refl_thms of
   1.549       None => []  |  Some(refl) => [mk_cong sg (f,aTs,rT) refl]
   1.550 @@ -591,7 +591,7 @@
   1.551  fun mk_cong_thy thy f =
   1.552  let val sg = sign_of thy;
   1.553      val T = case Sign.const_type sg f of
   1.554 -		None => error(f^" not declared") | Some(T) => T;
   1.555 +                None => error(f^" not declared") | Some(T) => T;
   1.556      val T' = incr_tvar 9 T;
   1.557  in mk_cong_type sg (Const(f,T'),T') end;
   1.558  
   1.559 @@ -601,10 +601,10 @@
   1.560  let val sg = sign_of thy;
   1.561      val S0 = Type.defaultS(#tsig(Sign.rep_sg sg))
   1.562      fun readfT(f,s) =
   1.563 -	let val T = incr_tvar 9 (Sign.read_typ(sg,K(Some(S0))) s);
   1.564 -	    val t = case Sign.const_type sg f of
   1.565 -		      Some(_) => Const(f,T) | None => Free(f,T)
   1.566 -	in (t,T) end
   1.567 +        let val T = incr_tvar 9 (Sign.read_typ(sg,K(Some(S0))) s);
   1.568 +            val t = case Sign.const_type sg f of
   1.569 +                      Some(_) => Const(f,T) | None => Free(f,T)
   1.570 +        in (t,T) end
   1.571  in flat o map (mk_cong_type sg o readfT) end;
   1.572  
   1.573  end (* local *)