src/HOLCF/domain/theorems.ML
changeset 1637 b8a8ae2e5de1
parent 1512 ce37c64244c0
child 1638 69c094639823
     1.1 --- a/src/HOLCF/domain/theorems.ML	Wed Apr 03 19:02:04 1996 +0200
     1.2 +++ b/src/HOLCF/domain/theorems.ML	Wed Apr 03 19:27:14 1996 +0200
     1.3 @@ -1,5 +1,4 @@
     1.4  (* theorems.ML
     1.5 -   ID:         $Id$
     1.6     Author : David von Oheimb
     1.7     Created: 06-Jun-95
     1.8     Updated: 08-Jun-95 first proof from cterms
     1.9 @@ -12,10 +11,12 @@
    1.10     Updated: 05-Sep-95 simultaneous domain equations (main part)
    1.11     Updated: 11-Sep-95 simultaneous domain equations (coding finished)
    1.12     Updated: 13-Sep-95 simultaneous domain equations (debugging)
    1.13 -   Copyright 1995 TU Muenchen
    1.14 +   Updated: 26-Oct-95 debugging and enhancement of proofs for take_apps, ind
    1.15 +   Updated: 16-Feb-96 bug concerning  domain Triv = triv  fixed
    1.16 +   Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
    1.17 +   Copyright 1995, 1996 TU Muenchen
    1.18  *)
    1.19  
    1.20 -
    1.21  structure Domain_Theorems = struct
    1.22  
    1.23  local
    1.24 @@ -25,58 +26,58 @@
    1.25  infix 1 ===; infix 1 ~= ; infix 1 <<; infix 1 ~<<;
    1.26  infix 9 `   ; infix 9 `% ; infix 9 `%%; infixr 9 oo;
    1.27  
    1.28 -(* ----- general proof facilities ------------------------------------------------- *)
    1.29 -
    1.30 -fun inferT sg pre_tm = #2(Sign.infer_types sg (K None)(K None)[]true([pre_tm],propT));
    1.31 +(* ----- general proof facilities ------------------------------------------- *)
    1.32  
    1.33 -(*
    1.34 -infix 0 y;
    1.35 -val b=0;
    1.36 -fun _ y t = by t;
    1.37 -fun  g  defs t = let val sg = sign_of thy;
    1.38 -                     val ct = Thm.cterm_of sg (inferT sg t);
    1.39 -                 in goalw_cterm defs ct end;
    1.40 -*)
    1.41 +fun inferT sg pre_tm = #2 (Sign.infer_types sg (K None) (K None) [] true 
    1.42 +			   ([pre_tm],propT));
    1.43  
    1.44  fun pg'' thy defs t = let val sg = sign_of thy;
    1.45 -                          val ct = Thm.cterm_of sg (inferT sg t);
    1.46 -                      in prove_goalw_cterm defs ct end;
    1.47 +		          val ct = Thm.cterm_of sg (inferT sg t);
    1.48 +		      in prove_goalw_cterm defs ct end;
    1.49  fun pg'  thy defs t tacsf=pg'' thy defs t (fn []   => tacsf 
    1.50 -                                            | prems=> (cut_facts_tac prems 1)::tacsf);
    1.51 +				| prems=> (cut_facts_tac prems 1)::tacsf);
    1.52  
    1.53  fun REPEAT_DETERM_UNTIL p tac = 
    1.54  let fun drep st = if p st then Sequence.single st
    1.55 -                          else (case Sequence.pull(tac st) of
    1.56 -                                  None        => Sequence.null
    1.57 -                                | Some(st',_) => drep st')
    1.58 -in drep end;
    1.59 +			  else (case Sequence.pull(tapply(tac,st)) of
    1.60 +		                  None        => Sequence.null
    1.61 +				| Some(st',_) => drep st')
    1.62 +in Tactic drep end;
    1.63  val UNTIL_SOLVED = REPEAT_DETERM_UNTIL (has_fewer_prems 1);
    1.64  
    1.65 -local val trueI2 = prove_goal HOL.thy "f~=x ==> True" (fn prems => [rtac TrueI 1]) in
    1.66 +local val trueI2 = prove_goal HOL.thy"f~=x ==> True"(fn prems=>[rtac TrueI 1])in
    1.67  val kill_neq_tac = dtac trueI2 end;
    1.68 -fun case_UU_tac rews i v =      res_inst_tac [("Q",v^"=UU")] classical2 i THEN
    1.69 -                                asm_simp_tac (HOLCF_ss addsimps rews) i;
    1.70 +fun case_UU_tac rews i v =	res_inst_tac [("Q",v^"=UU")] classical2 i THEN
    1.71 +				asm_simp_tac (HOLCF_ss addsimps rews) i;
    1.72  
    1.73  val chain_tac = REPEAT_DETERM o resolve_tac 
    1.74 -                [is_chain_iterate, ch2ch_fappR, ch2ch_fappL];
    1.75 +		[is_chain_iterate, ch2ch_fappR, ch2ch_fappL];
    1.76 +
    1.77 +(* ----- general proofs ----------------------------------------------------- *)
    1.78  
    1.79 -(* ----- general proofs ----------------------------------------------------------- *)
    1.80 +val quant_ss = HOL_ss addsimps (map (fn s => prove_goal HOL.thy s (fn _ =>[
    1.81 +		fast_tac HOL_cs 1]))["(x. P x  Q)=((x. P x)  Q)",
    1.82 +			    	     "(x. P  Q x) = (P  (x. Q x))"]);
    1.83 +
    1.84 +val all2E = prove_goal HOL.thy " x y . P x y; P x y  R   R" (fn prems =>[
    1.85 +				resolve_tac prems 1,
    1.86 +				cut_facts_tac prems 1,
    1.87 +				fast_tac HOL_cs 1]);
    1.88  
    1.89  val swap3 = prove_goal HOL.thy "[| Q ==> P; ~P |] ==> ~Q" (fn prems => [
    1.90                                  cut_facts_tac prems 1,
    1.91                                  etac swap 1,
    1.92                                  dtac notnotD 1,
    1.93 -                                etac (hd prems) 1]);
    1.94 +				etac (hd prems) 1]);
    1.95  
    1.96 -val dist_eqI = prove_goal Porder0.thy "~ x << y ==> x ~= y" (fn prems => [
    1.97 -                                cut_facts_tac prems 1,
    1.98 -                                etac swap 1,
    1.99 -                                dtac notnotD 1,
   1.100 -                                asm_simp_tac HOLCF_ss 1]);
   1.101 -val cfst_strict  = prove_goal Cprod3.thy "cfst`UU = UU" (fn _ => [
   1.102 -                                (simp_tac (HOLCF_ss addsimps [inst_cprod_pcpo2]) 1)]);
   1.103 -val csnd_strict  = prove_goal Cprod3.thy "csnd`UU = UU" (fn _ => [
   1.104 -                        (simp_tac (HOLCF_ss addsimps [inst_cprod_pcpo2]) 1)]);
   1.105 +val dist_eqI = prove_goal Porder.thy " x  y  x  y" (fn prems => [
   1.106 +                                rtac swap3 1,
   1.107 +				etac (antisym_less_inverse RS conjunct1) 1,
   1.108 +				resolve_tac prems 1]);
   1.109 +val cfst_strict  = prove_goal Cprod3.thy "cfst` = " (fn _ => [
   1.110 +			(simp_tac (HOLCF_ss addsimps [inst_cprod_pcpo2]) 1)]);
   1.111 +val csnd_strict  = prove_goal Cprod3.thy "csnd` = " (fn _ => [
   1.112 +			(simp_tac (HOLCF_ss addsimps [inst_cprod_pcpo2]) 1)]);
   1.113  
   1.114  in
   1.115  
   1.116 @@ -86,8 +87,17 @@
   1.117  
   1.118  val dummy = writeln ("Proving isomorphism properties of domain "^dname^"...");
   1.119  val pg = pg' thy;
   1.120 +(*
   1.121 +infixr 0 y;
   1.122 +val b = 0;
   1.123 +fun _ y t = by t;
   1.124 +fun  g  defs t = let val sg = sign_of thy;
   1.125 +		     val ct = Thm.cterm_of sg (inferT sg t);
   1.126 +		 in goalw_cterm defs ct end;
   1.127 +*)
   1.128  
   1.129 -(* ----- getting the axioms and definitions --------------------------------------- *)
   1.130 +
   1.131 +(* ----- getting the axioms and definitions --------------------------------- *)
   1.132  
   1.133  local val ga = get_axiom thy in
   1.134  val ax_abs_iso    = ga (dname^"_abs_iso"   );
   1.135 @@ -96,11 +106,11 @@
   1.136  val axs_con_def   = map (fn (con,_) => ga (extern_name con ^"_def")) cons;
   1.137  val axs_dis_def   = map (fn (con,_) => ga (   dis_name con ^"_def")) cons;
   1.138  val axs_sel_def   = flat(map (fn (_,args) => 
   1.139 -                    map (fn     arg => ga (sel_of arg      ^"_def")) args) cons);
   1.140 +		    map (fn     arg => ga (sel_of arg      ^"_def")) args)cons);
   1.141  val ax_copy_def   = ga (dname^"_copy_def"  );
   1.142  end; (* local *)
   1.143  
   1.144 -(* ----- theorems concerning the isomorphism -------------------------------------- *)
   1.145 +(* ----- theorems concerning the isomorphism -------------------------------- *)
   1.146  
   1.147  val dc_abs  = %%(dname^"_abs");
   1.148  val dc_rep  = %%(dname^"_rep");
   1.149 @@ -108,251 +118,243 @@
   1.150  val x_name = "x";
   1.151  
   1.152  val (rep_strict, abs_strict) = let 
   1.153 -               val r = ax_rep_iso RS (ax_abs_iso RS (allI  RSN(2,allI RS iso_strict)))
   1.154 -               in (r RS conjunct1, r RS conjunct2) end;
   1.155 +	 val r = ax_rep_iso RS (ax_abs_iso RS (allI  RSN(2,allI RS iso_strict)))
   1.156 +	       in (r RS conjunct1, r RS conjunct2) end;
   1.157  val abs_defin' = pg [] ((dc_abs`%x_name === UU) ==> (%x_name === UU)) [
   1.158 -                                res_inst_tac [("t",x_name)] (ax_abs_iso RS subst) 1,
   1.159 -                                etac ssubst 1,
   1.160 -                                rtac rep_strict 1];
   1.161 +			   res_inst_tac [("t",x_name)] (ax_abs_iso RS subst) 1,
   1.162 +				etac ssubst 1, rtac rep_strict 1];
   1.163  val rep_defin' = pg [] ((dc_rep`%x_name === UU) ==> (%x_name === UU)) [
   1.164 -                                res_inst_tac [("t",x_name)] (ax_rep_iso RS subst) 1,
   1.165 -                                etac ssubst 1,
   1.166 -                                rtac abs_strict 1];
   1.167 +			   res_inst_tac [("t",x_name)] (ax_rep_iso RS subst) 1,
   1.168 +				etac ssubst 1, rtac abs_strict 1];
   1.169  val iso_rews = [ax_abs_iso,ax_rep_iso,abs_strict,rep_strict];
   1.170  
   1.171  local 
   1.172  val iso_swap = pg [] (dc_rep`%"x" === %"y" ==> %"x" === dc_abs`%"y") [
   1.173 -                                dres_inst_tac [("f",dname^"_abs")] cfun_arg_cong 1,
   1.174 -                                etac (ax_rep_iso RS subst) 1];
   1.175 +			    dres_inst_tac [("f",dname^"_abs")] cfun_arg_cong 1,
   1.176 +			    etac (ax_rep_iso RS subst) 1];
   1.177  fun exh foldr1 cn quant foldr2 var = let
   1.178    fun one_con (con,args) = let val vns = map vname args in
   1.179      foldr quant (vns, foldr2 ((%x_name === con_app2 con (var vns) vns)::
   1.180 -                              map (defined o (var vns)) (nonlazy args))) end
   1.181 +			      map (defined o (var vns)) (nonlazy args))) end
   1.182    in foldr1 ((cn(%x_name===UU))::map one_con cons) end;
   1.183  in
   1.184  val cases = let 
   1.185 -            fun common_tac thm = rtac thm 1 THEN contr_tac 1;
   1.186 -            fun unit_tac true = common_tac liftE1
   1.187 -            |   unit_tac _    = all_tac;
   1.188 -            fun prod_tac []          = common_tac oneE
   1.189 -            |   prod_tac [arg]       = unit_tac (is_lazy arg)
   1.190 -            |   prod_tac (arg::args) = 
   1.191 -                                common_tac sprodE THEN
   1.192 -                                kill_neq_tac 1 THEN
   1.193 -                                unit_tac (is_lazy arg) THEN
   1.194 -                                prod_tac args;
   1.195 -            fun sum_one_tac p = SELECT_GOAL(EVERY[
   1.196 -                                rtac p 1,
   1.197 -                                rewrite_goals_tac axs_con_def,
   1.198 -                                dtac iso_swap 1,
   1.199 -                                simp_tac HOLCF_ss 1,
   1.200 -                                UNTIL_SOLVED(fast_tac HOL_cs 1)]) 1;
   1.201 -            fun sum_tac [(_,args)]       [p]        = 
   1.202 -                                prod_tac args THEN sum_one_tac p
   1.203 -            |   sum_tac ((_,args)::cons') (p::prems) = DETERM(
   1.204 -                                common_tac ssumE THEN
   1.205 -                                kill_neq_tac 1 THEN kill_neq_tac 2 THEN
   1.206 -                                prod_tac args THEN sum_one_tac p) THEN
   1.207 -                                sum_tac cons' prems
   1.208 -            |   sum_tac _ _ = Imposs "theorems:sum_tac";
   1.209 -          in pg'' thy [] (exh (fn l => foldr (op ===>) (l,mk_trp(%"P")))
   1.210 -                              (fn T => T ==> %"P") mk_All
   1.211 -                              (fn l => foldr (op ===>) (map mk_trp l,mk_trp(%"P")))
   1.212 -                              bound_arg)
   1.213 -                             (fn prems => [
   1.214 -                                cut_facts_tac [excluded_middle] 1,
   1.215 -                                etac disjE 1,
   1.216 -                                rtac (hd prems) 2,
   1.217 -                                etac rep_defin' 2,
   1.218 -                                if is_one_con_one_arg (not o is_lazy) cons
   1.219 -                                then rtac (hd (tl prems)) 1 THEN atac 2 THEN
   1.220 -                                     rewrite_goals_tac axs_con_def THEN
   1.221 -                                     simp_tac (HOLCF_ss addsimps [ax_rep_iso]) 1
   1.222 -                                else sum_tac cons (tl prems)])end;
   1.223 -val exhaust = pg [] (mk_trp(exh (foldr' mk_disj) Id mk_ex (foldr' mk_conj) (K %))) [
   1.224 -                                rtac cases 1,
   1.225 -                                UNTIL_SOLVED(fast_tac HOL_cs 1)];
   1.226 +	    fun common_tac thm = rtac thm 1 THEN contr_tac 1;
   1.227 +	    fun unit_tac true = common_tac liftE1
   1.228 +	    |   unit_tac _    = all_tac;
   1.229 +	    fun prod_tac []          = common_tac oneE
   1.230 +	    |   prod_tac [arg]       = unit_tac (is_lazy arg)
   1.231 +	    |   prod_tac (arg::args) = 
   1.232 +				common_tac sprodE THEN
   1.233 +				kill_neq_tac 1 THEN
   1.234 +				unit_tac (is_lazy arg) THEN
   1.235 +				prod_tac args;
   1.236 +	    fun sum_rest_tac p = SELECT_GOAL(EVERY[
   1.237 +				rtac p 1,
   1.238 +				rewrite_goals_tac axs_con_def,
   1.239 +				dtac iso_swap 1,
   1.240 +				simp_tac HOLCF_ss 1,
   1.241 +				UNTIL_SOLVED(fast_tac HOL_cs 1)]) 1;
   1.242 +	    fun sum_tac [(_,args)]       [p]        = 
   1.243 +				prod_tac args THEN sum_rest_tac p
   1.244 +	    |   sum_tac ((_,args)::cons') (p::prems) = DETERM(
   1.245 +				common_tac ssumE THEN
   1.246 +				kill_neq_tac 1 THEN kill_neq_tac 2 THEN
   1.247 +				prod_tac args THEN sum_rest_tac p) THEN
   1.248 +				sum_tac cons' prems
   1.249 +	    |   sum_tac _ _ = Imposs "theorems:sum_tac";
   1.250 +	  in pg'' thy [] (exh (fn l => foldr (op ===>) (l,mk_trp(%"P")))
   1.251 +			      (fn T => T ==> %"P") mk_All
   1.252 +			      (fn l => foldr (op ===>) (map mk_trp l,
   1.253 +							    mk_trp(%"P")))
   1.254 +			      bound_arg)
   1.255 +			     (fn prems => [
   1.256 +				cut_facts_tac [excluded_middle] 1,
   1.257 +				etac disjE 1,
   1.258 +				rtac (hd prems) 2,
   1.259 +				etac rep_defin' 2,
   1.260 +				if length cons = 1 andalso 
   1.261 +				   length (snd(hd cons)) = 1 andalso 
   1.262 +				   not(is_lazy(hd(snd(hd cons))))
   1.263 +				then rtac (hd (tl prems)) 1 THEN atac 2 THEN
   1.264 +				     rewrite_goals_tac axs_con_def THEN
   1.265 +				     simp_tac (HOLCF_ss addsimps [ax_rep_iso]) 1
   1.266 +				else sum_tac cons (tl prems)])end;
   1.267 +val exhaust= pg[](mk_trp(exh (foldr' mk_disj) Id mk_ex (foldr' mk_conj) (K %)))[
   1.268 +				rtac cases 1,
   1.269 +				UNTIL_SOLVED(fast_tac HOL_cs 1)];
   1.270  end;
   1.271  
   1.272  local 
   1.273 -val when_app = foldl (op `) (%%(dname^"_when"), map % (when_funs cons));
   1.274 -val when_appl = pg [ax_when_def] (mk_trp(when_app`%x_name===when_body cons 
   1.275 -                (fn (_,n) => %(nth_elem(n-1,when_funs cons)))`(dc_rep`%x_name))) [
   1.276 -                                simp_tac HOLCF_ss 1];
   1.277 +  val when_app  = foldl (op `) (%%(dname^"_when"), map % (when_funs cons));
   1.278 +  val when_appl = pg [ax_when_def] (mk_trp(when_app`%x_name===when_body cons 
   1.279 +		(fn (_,n)=> %(nth_elem(n-1,when_funs cons)))`(dc_rep`%x_name)))[
   1.280 +				simp_tac HOLCF_ss 1];
   1.281  in
   1.282 -val when_strict = pg [] ((if is_one_con_one_arg (K true) cons 
   1.283 -        then fn t => mk_trp(strict(%"f")) ===> t else Id)(mk_trp(strict when_app))) [
   1.284 -                                simp_tac(HOLCF_ss addsimps [when_appl,rep_strict]) 1];
   1.285 -val when_apps = let fun one_when n (con,args) = pg axs_con_def
   1.286 -                (lift_defined % (nonlazy args, mk_trp(when_app`(con_app con args) ===
   1.287 -                 mk_cfapp(%(nth_elem(n,when_funs cons)),map %# args))))[
   1.288 -                        asm_simp_tac (HOLCF_ss addsimps [when_appl,ax_abs_iso]) 1];
   1.289 -                in mapn one_when 0 cons end;
   1.290 +val when_strict = pg [] (mk_trp(strict when_app)) [
   1.291 +			simp_tac(HOLCF_ss addsimps [when_appl,rep_strict]) 1];
   1.292 +val when_apps = let fun one_when n (con,args) = pg axs_con_def (lift_defined % 
   1.293 +   (nonlazy args, mk_trp(when_app`(con_app con args) ===
   1.294 +	 mk_cfapp(%(nth_elem(n,when_funs cons)),map %# args))))[
   1.295 +		asm_simp_tac (HOLCF_ss addsimps [when_appl,ax_abs_iso]) 1];
   1.296 +	in mapn one_when 0 cons end;
   1.297  end;
   1.298  val when_rews = when_strict::when_apps;
   1.299  
   1.300 -(* ----- theorems concerning the constructors, discriminators and selectors ------- *)
   1.301 +(* ----- theorems concerning the constructors, discriminators and selectors - *)
   1.302  
   1.303 -val dis_stricts = map (fn (con,_) => pg axs_dis_def (mk_trp(
   1.304 -                        (if is_one_con_one_arg (K true) cons then mk_not else Id)
   1.305 -                         (strict(%%(dis_name con))))) [
   1.306 -                simp_tac (HOLCF_ss addsimps (if is_one_con_one_arg (K true) cons 
   1.307 -                                        then [ax_when_def] else when_rews)) 1]) cons;
   1.308 -val dis_apps = let fun one_dis c (con,args)= pg (axs_dis_def)
   1.309 -                   (lift_defined % (nonlazy args, (*(if is_one_con_one_arg is_lazy cons
   1.310 -                        then curry (lift_defined %#) args else Id)
   1.311 -#################*)
   1.312 -                        (mk_trp((%%(dis_name c))`(con_app con args) ===
   1.313 -                              %%(if con=c then "TT" else "FF"))))) [
   1.314 -                                asm_simp_tac (HOLCF_ss addsimps when_rews) 1];
   1.315 -        in flat(map (fn (c,_) => map (one_dis c) cons) cons) end;
   1.316 -val dis_defins = map (fn (con,args) => pg [] (defined(%x_name)==> 
   1.317 -                      defined(%%(dis_name con)`%x_name)) [
   1.318 -                                rtac cases 1,
   1.319 -                                contr_tac 1,
   1.320 -                                UNTIL_SOLVED (CHANGED(asm_simp_tac 
   1.321 -                                              (HOLCF_ss addsimps dis_apps) 1))]) cons;
   1.322 -val dis_rews = dis_stricts @ dis_defins @ dis_apps;
   1.323 +val dis_rews = let
   1.324 +  val dis_stricts = map (fn (con,_) => pg axs_dis_def (mk_trp(
   1.325 +		      	     strict(%%(dis_name con)))) [
   1.326 +				simp_tac (HOLCF_ss addsimps when_rews) 1]) cons;
   1.327 +  val dis_apps = let fun one_dis c (con,args)= pg axs_dis_def
   1.328 +		   (lift_defined % (nonlazy args,
   1.329 +			(mk_trp((%%(dis_name c))`(con_app con args) ===
   1.330 +			      %%(if con=c then "TT" else "FF"))))) [
   1.331 +				asm_simp_tac (HOLCF_ss addsimps when_rews) 1];
   1.332 +	in flat(map (fn (c,_) => map (one_dis c) cons) cons) end;
   1.333 +  val dis_defins = map (fn (con,args) => pg [] (defined(%x_name) ==> 
   1.334 +		      defined(%%(dis_name con)`%x_name)) [
   1.335 +				rtac cases 1,
   1.336 +				contr_tac 1,
   1.337 +				UNTIL_SOLVED (CHANGED(asm_simp_tac 
   1.338 +				        (HOLCF_ss addsimps dis_apps) 1))]) cons;
   1.339 +in dis_stricts @ dis_defins @ dis_apps end;
   1.340  
   1.341  val con_stricts = flat(map (fn (con,args) => map (fn vn =>
   1.342 -                        pg (axs_con_def) 
   1.343 -                           (mk_trp(con_app2 con (fn arg => if vname arg = vn 
   1.344 -                                        then UU else %# arg) args === UU))[
   1.345 -                                asm_simp_tac (HOLCF_ss addsimps [abs_strict]) 1]
   1.346 -                        ) (nonlazy args)) cons);
   1.347 +			pg (axs_con_def) 
   1.348 +			   (mk_trp(con_app2 con (fn arg => if vname arg = vn 
   1.349 +					then UU else %# arg) args === UU))[
   1.350 +				asm_simp_tac (HOLCF_ss addsimps [abs_strict]) 1]
   1.351 +			) (nonlazy args)) cons);
   1.352  val con_defins = map (fn (con,args) => pg []
   1.353 -                        (lift_defined % (nonlazy args,
   1.354 -                                mk_trp(defined(con_app con args)))) ([
   1.355 -                                rtac swap3 1] @ (if is_one_con_one_arg (K true) cons 
   1.356 -                                then [
   1.357 -                                  if is_lazy (hd args) then rtac defined_up 2
   1.358 -                                                       else atac 2,
   1.359 -                                  rtac abs_defin' 1,    
   1.360 -                                  asm_full_simp_tac (HOLCF_ss addsimps axs_con_def) 1]
   1.361 -                                else [
   1.362 -                                  eres_inst_tac [("f",dis_name con)] cfun_arg_cong 1,
   1.363 -                                  asm_simp_tac (HOLCF_ss addsimps dis_rews) 1])))cons;
   1.364 +			(lift_defined % (nonlazy args,
   1.365 +				mk_trp(defined(con_app con args)))) ([
   1.366 +			  rtac swap3 1, 
   1.367 +			  eres_inst_tac [("f",dis_name con)] cfun_arg_cong 1,
   1.368 +			  asm_simp_tac (HOLCF_ss addsimps dis_rews) 1] )) cons;
   1.369  val con_rews = con_stricts @ con_defins;
   1.370  
   1.371  val sel_stricts = let fun one_sel sel = pg axs_sel_def (mk_trp(strict(%%sel))) [
   1.372 -                                simp_tac (HOLCF_ss addsimps when_rews) 1];
   1.373 -in flat(map (fn (_,args) => map (fn arg => one_sel (sel_of arg)) args) cons) end;
   1.374 +				simp_tac (HOLCF_ss addsimps when_rews) 1];
   1.375 +in flat(map (fn (_,args) =>map (fn arg => one_sel (sel_of arg)) args) cons) end;
   1.376  val sel_apps = let fun one_sel c n sel = map (fn (con,args) => 
   1.377 -                let val nlas = nonlazy args;
   1.378 -                    val vns  = map vname args;
   1.379 -                in pg axs_sel_def (lift_defined %
   1.380 -                   (filter (fn v => con=c andalso (v<>nth_elem(n,vns))) nlas,
   1.381 -   mk_trp((%%sel)`(con_app con args) === (if con=c then %(nth_elem(n,vns)) else UU))))
   1.382 -                            ( (if con=c then [] 
   1.383 -                               else map(case_UU_tac(when_rews@con_stricts)1) nlas)
   1.384 -                             @(if con=c andalso ((nth_elem(n,vns)) mem nlas)
   1.385 -                                         then[case_UU_tac (when_rews @ con_stricts) 1 
   1.386 -                                                          (nth_elem(n,vns))] else [])
   1.387 -                             @ [asm_simp_tac(HOLCF_ss addsimps when_rews)1])end) cons;
   1.388 +		let val nlas = nonlazy args;
   1.389 +		    val vns  = map vname args;
   1.390 +		in pg axs_sel_def (lift_defined %
   1.391 +		   (filter (fn v => con=c andalso (v<>nth_elem(n,vns))) nlas,
   1.392 +				mk_trp((%%sel)`(con_app con args) === 
   1.393 +				(if con=c then %(nth_elem(n,vns)) else UU))))
   1.394 +			    ( (if con=c then [] 
   1.395 +		       else map(case_UU_tac(when_rews@con_stricts)1) nlas)
   1.396 +		     @(if con=c andalso ((nth_elem(n,vns)) mem nlas)
   1.397 +				 then[case_UU_tac (when_rews @ con_stricts) 1 
   1.398 +						  (nth_elem(n,vns))] else [])
   1.399 +		     @ [asm_simp_tac(HOLCF_ss addsimps when_rews)1])end) cons;
   1.400  in flat(map  (fn (c,args) => 
   1.401 -        flat(mapn (fn n => fn arg => one_sel c n (sel_of arg)) 0 args)) cons) end;
   1.402 -val sel_defins = if length cons = 1 then map (fn arg => pg [] (defined(%x_name) ==> 
   1.403 -                        defined(%%(sel_of arg)`%x_name)) [
   1.404 -                                rtac cases 1,
   1.405 -                                contr_tac 1,
   1.406 -                                UNTIL_SOLVED (CHANGED(asm_simp_tac 
   1.407 -                                              (HOLCF_ss addsimps sel_apps) 1))]) 
   1.408 -                 (filter_out is_lazy (snd(hd cons))) else [];
   1.409 +     flat(mapn (fn n => fn arg => one_sel c n (sel_of arg)) 0 args)) cons) end;
   1.410 +val sel_defins = if length cons=1 then map (fn arg => pg [](defined(%x_name)==> 
   1.411 +			defined(%%(sel_of arg)`%x_name)) [
   1.412 +				rtac cases 1,
   1.413 +				contr_tac 1,
   1.414 +				UNTIL_SOLVED (CHANGED(asm_simp_tac 
   1.415 +				             (HOLCF_ss addsimps sel_apps) 1))]) 
   1.416 +		 (filter_out is_lazy (snd(hd cons))) else [];
   1.417  val sel_rews = sel_stricts @ sel_defins @ sel_apps;
   1.418  
   1.419  val distincts_le = let
   1.420      fun dist (con1, args1) (con2, args2) = pg []
   1.421 -              (lift_defined % ((nonlazy args1),
   1.422 -                             (mk_trp (con_app con1 args1 ~<< con_app con2 args2))))([
   1.423 -                        rtac swap3 1,
   1.424 -                        eres_inst_tac [("fo5",dis_name con1)] monofun_cfun_arg 1]
   1.425 -                      @ map (case_UU_tac (con_stricts @ dis_rews) 1) (nonlazy args2)
   1.426 -                      @[asm_simp_tac (HOLCF_ss addsimps dis_rews) 1]);
   1.427 +	      (lift_defined % ((nonlazy args1),
   1.428 +			(mk_trp (con_app con1 args1 ~<< con_app con2 args2))))([
   1.429 +			rtac swap3 1,
   1.430 +			eres_inst_tac[("fo5",dis_name con1)] monofun_cfun_arg 1]
   1.431 +		      @map(case_UU_tac (con_stricts @ dis_rews)1)(nonlazy args2)
   1.432 +		      @[asm_simp_tac (HOLCF_ss addsimps dis_rews) 1]);
   1.433      fun distinct (con1,args1) (con2,args2) =
   1.434 -        let val arg1 = (con1, args1);
   1.435 -            val arg2 = (con2, (map (fn (arg,vn) => upd_vname (K vn) arg)
   1.436 -                              (args2~~variantlist(map vname args2,map vname args1))));
   1.437 -        in [dist arg1 arg2, dist arg2 arg1] end;
   1.438 +	let val arg1 = (con1, args1);
   1.439 +	    val arg2 = (con2, (map (fn (arg,vn) => upd_vname (K vn) arg)
   1.440 +			(args2~~variantlist(map vname args2,map vname args1))));
   1.441 +	in [dist arg1 arg2, dist arg2 arg1] end;
   1.442      fun distincts []      = []
   1.443      |   distincts (c::cs) = (map (distinct c) cs) :: distincts cs;
   1.444  in distincts cons end;
   1.445  val dists_le = flat (flat distincts_le);
   1.446  val dists_eq = let
   1.447      fun distinct (_,args1) ((_,args2),leqs) = let
   1.448 -        val (le1,le2) = (hd leqs, hd(tl leqs));
   1.449 -        val (eq1,eq2) = (le1 RS dist_eqI, le2 RS dist_eqI) in
   1.450 -        if nonlazy args1 = [] then [eq1, eq1 RS not_sym] else
   1.451 -        if nonlazy args2 = [] then [eq2, eq2 RS not_sym] else
   1.452 -                                        [eq1, eq2] end;
   1.453 +	val (le1,le2) = (hd leqs, hd(tl leqs));
   1.454 +	val (eq1,eq2) = (le1 RS dist_eqI, le2 RS dist_eqI) in
   1.455 +	if nonlazy args1 = [] then [eq1, eq1 RS not_sym] else
   1.456 +	if nonlazy args2 = [] then [eq2, eq2 RS not_sym] else
   1.457 +					[eq1, eq2] end;
   1.458      fun distincts []      = []
   1.459      |   distincts ((c,leqs)::cs) = flat(map (distinct c) ((map fst cs)~~leqs)) @
   1.460 -                                   distincts cs;
   1.461 +				   distincts cs;
   1.462      in distincts (cons~~distincts_le) end;
   1.463  
   1.464  local 
   1.465    fun pgterm rel con args = let
   1.466 -                fun append s = upd_vname(fn v => v^s);
   1.467 -                val (largs,rargs) = (args, map (append "'") args);
   1.468 -                in pg [] (mk_trp (rel(con_app con largs,con_app con rargs)) ===>
   1.469 -                      lift_defined % ((nonlazy largs),lift_defined % ((nonlazy rargs),
   1.470 -                            mk_trp (foldr' mk_conj 
   1.471 -                                (map rel (map %# largs ~~ map %# rargs)))))) end;
   1.472 +		fun append s = upd_vname(fn v => v^s);
   1.473 +		val (largs,rargs) = (args, map (append "'") args);
   1.474 +		in pg [] (mk_trp (rel(con_app con largs,con_app con rargs)) ===>
   1.475 +		      lift_defined % ((nonlazy largs),lift_defined % ((nonlazy rargs),
   1.476 +			    mk_trp (foldr' mk_conj 
   1.477 +				(map rel (map %# largs ~~ map %# rargs)))))) end;
   1.478    val cons' = filter (fn (_,args) => args<>[]) cons;
   1.479  in
   1.480  val inverts = map (fn (con,args) => 
   1.481 -                pgterm (op <<) con args (flat(map (fn arg => [
   1.482 -                                TRY(rtac conjI 1),
   1.483 -                                dres_inst_tac [("fo5",sel_of arg)] monofun_cfun_arg 1,
   1.484 -                                asm_full_simp_tac (HOLCF_ss addsimps sel_apps) 1]
   1.485 -                                                      ) args))) cons';
   1.486 +		pgterm (op <<) con args (flat(map (fn arg => [
   1.487 +				TRY(rtac conjI 1),
   1.488 +				dres_inst_tac [("fo5",sel_of arg)] monofun_cfun_arg 1,
   1.489 +				asm_full_simp_tac (HOLCF_ss addsimps sel_apps) 1]
   1.490 +			     			      ) args))) cons';
   1.491  val injects = map (fn ((con,args),inv_thm) => 
   1.492 -                           pgterm (op ===) con args [
   1.493 -                                etac (antisym_less_inverse RS conjE) 1,
   1.494 -                                dtac inv_thm 1, REPEAT(atac 1),
   1.495 -                                dtac inv_thm 1, REPEAT(atac 1),
   1.496 -                                TRY(safe_tac HOL_cs),
   1.497 -                                REPEAT(rtac antisym_less 1 ORELSE atac 1)] )
   1.498 -                  (cons'~~inverts);
   1.499 +			   pgterm (op ===) con args [
   1.500 +				etac (antisym_less_inverse RS conjE) 1,
   1.501 +				dtac inv_thm 1, REPEAT(atac 1),
   1.502 +				dtac inv_thm 1, REPEAT(atac 1),
   1.503 +				TRY(safe_tac HOL_cs),
   1.504 +				REPEAT(rtac antisym_less 1 ORELSE atac 1)] )
   1.505 +		  (cons'~~inverts);
   1.506  end;
   1.507  
   1.508 -(* ----- theorems concerning one induction step ----------------------------------- *)
   1.509 +(* ----- theorems concerning one induction step ----------------------------- *)
   1.510  
   1.511 -val copy_strict = pg [ax_copy_def] ((if is_one_con_one_arg (K true) cons then fn t =>
   1.512 -         mk_trp(strict(cproj (%"f") eqs (rec_of (hd(snd(hd cons)))))) ===> t
   1.513 -        else Id) (mk_trp(strict(dc_copy`%"f")))) [
   1.514 -                                asm_simp_tac(HOLCF_ss addsimps [abs_strict,rep_strict,
   1.515 -                                                        cfst_strict,csnd_strict]) 1];
   1.516 -val copy_apps = map (fn (con,args) => pg (ax_copy_def::axs_con_def)
   1.517 -                    (lift_defined %# (filter is_nonlazy_rec args,
   1.518 -                        mk_trp(dc_copy`%"f"`(con_app con args) ===
   1.519 -                           (con_app2 con (app_rec_arg (cproj (%"f") eqs)) args))))
   1.520 -                                 (map (case_UU_tac [ax_abs_iso] 1 o vname)
   1.521 -                                   (filter(fn a=>not(is_rec a orelse is_lazy a))args)@
   1.522 -                                 [asm_simp_tac (HOLCF_ss addsimps [ax_abs_iso]) 1])
   1.523 -                )cons;
   1.524 -val copy_stricts = map(fn(con,args)=>pg[](mk_trp(dc_copy`UU`(con_app con args) ===UU))
   1.525 -             (let val rews = cfst_strict::csnd_strict::copy_strict::copy_apps@con_rews
   1.526 -                         in map (case_UU_tac rews 1) (nonlazy args) @ [
   1.527 -                             asm_simp_tac (HOLCF_ss addsimps rews) 1] end))
   1.528 -                   (filter (fn (_,args)=>exists is_nonlazy_rec args) cons);
   1.529 +val copy_strict = pg[ax_copy_def](mk_trp(strict(dc_copy`%"f"))) [
   1.530 +		   asm_simp_tac(HOLCF_ss addsimps [abs_strict, when_strict,
   1.531 +						   cfst_strict,csnd_strict]) 1];
   1.532 +val copy_apps = map (fn (con,args) => pg [ax_copy_def]
   1.533 +		    (lift_defined % (nonlazy_rec args,
   1.534 +			mk_trp(dc_copy`%"f"`(con_app con args) ===
   1.535 +		(con_app2 con (app_rec_arg (cproj (%"f") (length eqs))) args))))
   1.536 +			(map (case_UU_tac (abs_strict::when_strict::con_stricts)
   1.537 +				 1 o vname)
   1.538 +			 (filter (fn a => not (is_rec a orelse is_lazy a)) args)
   1.539 +			@[asm_simp_tac (HOLCF_ss addsimps when_apps) 1,
   1.540 +		          simp_tac (HOLCF_ss addsimps axs_con_def) 1]))cons;
   1.541 +val copy_stricts = map (fn (con,args) => pg [] (mk_trp(dc_copy`UU`
   1.542 +					(con_app con args) ===UU))
   1.543 +     (let val rews = cfst_strict::csnd_strict::copy_strict::copy_apps@con_rews
   1.544 +			 in map (case_UU_tac rews 1) (nonlazy args) @ [
   1.545 +			     asm_simp_tac (HOLCF_ss addsimps rews) 1] end))
   1.546 +  		        (filter (fn (_,args)=>exists is_nonlazy_rec args) cons);
   1.547  val copy_rews = copy_strict::copy_apps @ copy_stricts;
   1.548  
   1.549  in     (iso_rews, exhaust, cases, when_rews,
   1.550 -        con_rews, sel_rews, dis_rews, dists_eq, dists_le, inverts, injects,
   1.551 -        copy_rews)
   1.552 +	con_rews, sel_rews, dis_rews, dists_le, dists_eq, inverts, injects,
   1.553 +	copy_rews)
   1.554  end; (* let *)
   1.555  
   1.556  
   1.557  fun comp_theorems thy (comp_dname, eqs: eq list, casess, con_rews, copy_rews) =
   1.558  let
   1.559  
   1.560 -val dummy = writeln ("Proving induction properties of domain "^comp_dname^"...");
   1.561 +val dummy = writeln("Proving induction properties of domain "^comp_dname^"...");
   1.562  val pg = pg' thy;
   1.563  
   1.564  val dnames = map (fst o fst) eqs;
   1.565  val conss  = map  snd        eqs;
   1.566  
   1.567 -(* ----- getting the composite axiom and definitions ------------------------------ *)
   1.568 +(* ----- getting the composite axiom and definitions ------------------------ *)
   1.569  
   1.570  local val ga = get_axiom thy in
   1.571  val axs_reach      = map (fn dn => ga (dn ^  "_reach"   )) dnames;
   1.572 @@ -362,230 +364,235 @@
   1.573  val ax_bisim_def   = ga (comp_dname^"_bisim_def");
   1.574  end; (* local *)
   1.575  
   1.576 -(* ----- theorems concerning finiteness and induction ----------------------------- *)
   1.577 -
   1.578  fun dc_take dn = %%(dn^"_take");
   1.579  val x_name = idx_name dnames "x"; 
   1.580  val P_name = idx_name dnames "P";
   1.581 +val n_eqs = length eqs;
   1.582 +
   1.583 +(* ----- theorems concerning finite approximation and finite induction ------ *)
   1.584  
   1.585  local
   1.586 -  val iterate_ss = simpset_of "Fix";    
   1.587 -  val iterate_Cprod_strict_ss = iterate_ss addsimps [cfst_strict, csnd_strict];
   1.588 -  val iterate_Cprod_ss = iterate_ss addsimps [cfst2,csnd2,csplit2];
   1.589 +  val iterate_Cprod_ss = simpset_of "Fix"
   1.590 +			 addsimps [cfst_strict, csnd_strict]addsimps Cprod_rews;
   1.591    val copy_con_rews  = copy_rews @ con_rews;
   1.592 -  val copy_take_defs = (if length dnames=1 then [] else [ax_copy2_def]) @axs_take_def;
   1.593 -  val take_stricts = pg copy_take_defs (mk_trp(foldr' mk_conj (map (fn ((dn,args),_)=>
   1.594 -                  (dc_take dn $ %"n")`UU === mk_constrain(Type(dn,args),UU)) eqs)))([
   1.595 -                                nat_ind_tac "n" 1,
   1.596 -                                simp_tac iterate_ss 1,
   1.597 -                                simp_tac iterate_Cprod_strict_ss 1,
   1.598 -                                asm_simp_tac iterate_Cprod_ss 1,
   1.599 -                                TRY(safe_tac HOL_cs)] @
   1.600 -                        map(K(asm_simp_tac (HOL_ss addsimps copy_rews)1))dnames);
   1.601 +  val copy_take_defs =(if n_eqs = 1 then [] else [ax_copy2_def]) @ axs_take_def;
   1.602 +  val take_stricts=pg copy_take_defs(mk_trp(foldr' mk_conj(map(fn((dn,args),_)=>
   1.603 +	    (dc_take dn $ %"n")`UU === mk_constrain(Type(dn,args),UU)) eqs)))([
   1.604 +			nat_ind_tac "n" 1,
   1.605 +			simp_tac iterate_Cprod_ss 1,
   1.606 +			asm_simp_tac (iterate_Cprod_ss addsimps copy_rews)1]);
   1.607    val take_stricts' = rewrite_rule copy_take_defs take_stricts;
   1.608 -  val take_0s = mapn (fn n => fn dn => pg axs_take_def(mk_trp((dc_take dn $ %%"0")
   1.609 -                                                                `%x_name n === UU))[
   1.610 -                                simp_tac iterate_Cprod_strict_ss 1]) 1 dnames;
   1.611 +  val take_0s = mapn(fn n=> fn dn => pg axs_take_def(mk_trp((dc_take dn $ %%"0")
   1.612 +							`%x_name n === UU))[
   1.613 +				simp_tac iterate_Cprod_ss 1]) 1 dnames;
   1.614 +  val c_UU_tac = case_UU_tac (take_stricts'::copy_con_rews) 1;
   1.615    val take_apps = pg copy_take_defs (mk_trp(foldr' mk_conj 
   1.616 -            (flat(map (fn ((dn,_),cons) => map (fn (con,args) => foldr mk_all 
   1.617 -                (map vname args,(dc_take dn $ (%%"Suc" $ %"n"))`(con_app con args) ===
   1.618 -                 con_app2 con (app_rec_arg (fn n=>dc_take (nth_elem(n,dnames))$ %"n"))
   1.619 -                              args)) cons) eqs)))) ([
   1.620 -                                nat_ind_tac "n" 1,
   1.621 -                                simp_tac iterate_Cprod_strict_ss 1,
   1.622 -                                simp_tac (HOLCF_ss addsimps copy_con_rews) 1,
   1.623 -                                TRY(safe_tac HOL_cs)] @
   1.624 -                        (flat(map (fn ((dn,_),cons) => map (fn (con,args) => EVERY (
   1.625 -                                asm_full_simp_tac iterate_Cprod_ss 1::
   1.626 -                                map (case_UU_tac (take_stricts'::copy_con_rews) 1)
   1.627 -                                    (nonlazy args) @[
   1.628 -                                asm_full_simp_tac (HOLCF_ss addsimps copy_rews) 1])
   1.629 -                        ) cons) eqs)));
   1.630 +	    (flat(map (fn ((dn,_),cons) => map (fn (con,args) => foldr mk_all 
   1.631 +	(map vname args,(dc_take dn $ (%%"Suc" $ %"n"))`(con_app con args) ===
   1.632 +  	 con_app2 con (app_rec_arg (fn n=>dc_take (nth_elem(n,dnames))$ %"n"))
   1.633 +			      args)) cons) eqs)))) ([
   1.634 +				simp_tac iterate_Cprod_ss 1,
   1.635 +				nat_ind_tac "n" 1,
   1.636 +			    simp_tac(iterate_Cprod_ss addsimps copy_con_rews) 1,
   1.637 +				asm_full_simp_tac (HOLCF_ss addsimps 
   1.638 +				      (filter (has_fewer_prems 1) copy_rews)) 1,
   1.639 +				TRY(safe_tac HOL_cs)] @
   1.640 +			(flat(map (fn ((dn,_),cons) => map (fn (con,args) => 
   1.641 +				if nonlazy_rec args = [] then all_tac else
   1.642 +				EVERY(map c_UU_tac (nonlazy_rec args)) THEN
   1.643 +				asm_full_simp_tac (HOLCF_ss addsimps copy_rews)1
   1.644 +		 					   ) cons) eqs)));
   1.645  in
   1.646  val take_rews = atomize take_stricts @ take_0s @ atomize take_apps;
   1.647  end; (* local *)
   1.648  
   1.649 -val take_lemmas = mapn (fn n => fn(dn,ax_reach) => pg'' thy axs_take_def (mk_All("n",
   1.650 -                mk_trp(dc_take dn $ Bound 0 `%(x_name n) === 
   1.651 -                       dc_take dn $ Bound 0 `%(x_name n^"'")))
   1.652 -           ===> mk_trp(%(x_name n) === %(x_name n^"'"))) (fn prems => [
   1.653 -                                res_inst_tac[("t",x_name n    )](ax_reach RS subst) 1,
   1.654 -                                res_inst_tac[("t",x_name n^"'")](ax_reach RS subst) 1,
   1.655 -                                rtac (fix_def2 RS ssubst) 1,
   1.656 -                                REPEAT(CHANGED(rtac (contlub_cfun_arg RS ssubst) 1
   1.657 -                                               THEN chain_tac 1)),
   1.658 -                                rtac (contlub_cfun_fun RS ssubst) 1,
   1.659 -                                rtac (contlub_cfun_fun RS ssubst) 2,
   1.660 -                                rtac lub_equal 3,
   1.661 -                                chain_tac 1,
   1.662 -                                rtac allI 1,
   1.663 -                                resolve_tac prems 1])) 1 (dnames~~axs_reach);
   1.664 -
   1.665  local
   1.666    fun one_con p (con,args) = foldr mk_All (map vname args,
   1.667 -        lift_defined (bound_arg (map vname args)) (nonlazy args,
   1.668 -        lift (fn arg => %(P_name (1+rec_of arg)) $ bound_arg args arg)
   1.669 -             (filter is_rec args,mk_trp(%p $ con_app2 con (bound_arg args) args))));
   1.670 +	lift_defined (bound_arg (map vname args)) (nonlazy args,
   1.671 +	lift (fn arg => %(P_name (1+rec_of arg)) $ bound_arg args arg)
   1.672 +         (filter is_rec args,mk_trp(%p $ con_app2 con (bound_arg args) args))));
   1.673    fun one_eq ((p,cons),concl) = (mk_trp(%p $ UU) ===> 
   1.674 -                           foldr (op ===>) (map (one_con p) cons,concl));
   1.675 -  fun ind_term concf = foldr one_eq (mapn (fn n => fn x => (P_name n, x)) 1 conss,
   1.676 -        mk_trp(foldr' mk_conj (mapn (fn n => concf (P_name n,x_name n)) 1 dnames)));
   1.677 +			   foldr (op ===>) (map (one_con p) cons,concl));
   1.678 +  fun ind_term concf = foldr one_eq (mapn (fn n => fn x => (P_name n, x))1conss,
   1.679 +			mk_trp(foldr' mk_conj (mapn concf 1 dnames)));
   1.680    val take_ss = HOL_ss addsimps take_rews;
   1.681 -  fun ind_tacs tacsf thms1 thms2 prems = TRY(safe_tac HOL_cs)::
   1.682 -                                flat (mapn (fn n => fn (thm1,thm2) => 
   1.683 -                                  tacsf (n,prems) (thm1,thm2) @ 
   1.684 -                                  flat (map (fn cons =>
   1.685 -                                    (resolve_tac prems 1 ::
   1.686 -                                     flat (map (fn (_,args) => 
   1.687 -                                       resolve_tac prems 1::
   1.688 -                                       map (K(atac 1)) (nonlazy args) @
   1.689 -                                       map (K(atac 1)) (filter is_rec args))
   1.690 -                                     cons)))
   1.691 -                                   conss))
   1.692 -                                0 (thms1~~thms2));
   1.693 +  fun quant_tac i = EVERY(mapn(fn n=> fn _=> res_inst_tac[("x",x_name n)]spec i)
   1.694 +			       1 dnames);
   1.695 +  fun ind_prems_tac prems = EVERY(flat (map (fn cons => (
   1.696 +				     resolve_tac prems 1 ::
   1.697 +				     flat (map (fn (_,args) => 
   1.698 +				       resolve_tac prems 1 ::
   1.699 +				       map (K(atac 1)) (nonlazy args) @
   1.700 +				       map (K(atac 1)) (filter is_rec args))
   1.701 +				     cons))) conss));
   1.702    local 
   1.703 -    fun all_rec_to ns lazy_rec (n,cons) = forall (exists (fn arg => 
   1.704 -                  is_rec arg andalso not(rec_of arg mem ns) andalso
   1.705 -                  ((rec_of arg =  n andalso not(lazy_rec orelse is_lazy arg)) orelse 
   1.706 -                    rec_of arg <> n andalso all_rec_to (rec_of arg::ns) 
   1.707 -                      (lazy_rec orelse is_lazy arg) (n, (nth_elem(rec_of arg,conss))))
   1.708 -                  ) o snd) cons;
   1.709 -    fun warn (n,cons) = if all_rec_to [] false (n,cons) then (writeln 
   1.710 -                           ("WARNING: domain "^nth_elem(n,dnames)^" is empty!"); true)
   1.711 -                        else false;
   1.712 -    fun lazy_rec_to ns lazy_rec (n,cons) = exists (exists (fn arg => 
   1.713 -                  is_rec arg andalso not(rec_of arg mem ns) andalso
   1.714 -                  ((rec_of arg =  n andalso (lazy_rec orelse is_lazy arg)) orelse 
   1.715 -                    rec_of arg <> n andalso lazy_rec_to (rec_of arg::ns)
   1.716 -                     (lazy_rec orelse is_lazy arg) (n, (nth_elem(rec_of arg,conss))))
   1.717 -                 ) o snd) cons;
   1.718 -  in val is_emptys = map warn (mapn (fn n => fn (_,cons) => (n,cons)) 0 eqs);
   1.719 -     val is_finite = forall (not o lazy_rec_to [] false) 
   1.720 -                            (mapn (fn n => fn (_,cons) => (n,cons)) 0 eqs)
   1.721 +    (* check whether every/exists constructor of the n-th part of the equation:
   1.722 +       it has a possibly indirectly recursive argument that isn't/is possibly 
   1.723 +       indirectly lazy *)
   1.724 +    fun rec_to quant nfn rfn ns lazy_rec (n,cons) = quant (exists (fn arg => 
   1.725 +	  is_rec arg andalso not(rec_of arg mem ns) andalso
   1.726 +	  ((rec_of arg =  n andalso nfn(lazy_rec orelse is_lazy arg)) orelse 
   1.727 +	    rec_of arg <> n andalso rec_to quant nfn rfn (rec_of arg::ns) 
   1.728 +	      (lazy_rec orelse is_lazy arg) (n, (nth_elem(rec_of arg,conss))))
   1.729 +	  ) o snd) cons;
   1.730 +    fun all_rec_to ns  = rec_to forall not all_rec_to  ns;
   1.731 +    fun warn (n,cons)  = if all_rec_to [] false (n,cons) then (writeln 
   1.732 +        ("WARNING: domain "^nth_elem(n,dnames)^" is empty!"); true) else false;
   1.733 +    fun lazy_rec_to ns = rec_to exists Id  lazy_rec_to ns;
   1.734 +
   1.735 +  in val n__eqs     = mapn (fn n => fn (_,cons) => (n,cons)) 0 eqs;
   1.736 +     val is_emptys = map warn n__eqs;
   1.737 +     val is_finite = forall (not o lazy_rec_to [] false) n__eqs;
   1.738    end;
   1.739 -in
   1.740 -val finite_ind = pg'' thy [] (ind_term (fn (P,x) => fn dn => 
   1.741 -                          mk_all(x,%P $ (dc_take dn $ %"n" `Bound 0)))) (fn prems=> [
   1.742 -                                nat_ind_tac "n" 1,
   1.743 -                                simp_tac (take_ss addsimps prems) 1,
   1.744 -                                TRY(safe_tac HOL_cs)]
   1.745 -                                @ flat(mapn (fn n => fn (cons,cases) => [
   1.746 -                                 res_inst_tac [("x",x_name n)] cases 1,
   1.747 -                                 asm_simp_tac (take_ss addsimps prems) 1]
   1.748 -                                 @ flat(map (fn (con,args) => 
   1.749 -                                  asm_simp_tac take_ss 1 ::
   1.750 -                                  map (fn arg =>
   1.751 -                                   case_UU_tac (prems@con_rews) 1 (
   1.752 -                                   nth_elem(rec_of arg,dnames)^"_take n1`"^vname arg))
   1.753 -                                  (filter is_nonlazy_rec args) @ [
   1.754 -                                  resolve_tac prems 1] @
   1.755 -                                  map (K (atac 1))      (nonlazy args) @
   1.756 -                                  map (K (etac spec 1)) (filter is_rec args)) 
   1.757 -                                 cons))
   1.758 -                                1 (conss~~casess)));
   1.759 +in (* local *)
   1.760 +val finite_ind = pg'' thy [] (ind_term (fn n => fn dn => %(P_name n)$
   1.761 +			     (dc_take dn $ %"n" `%(x_name n)))) (fn prems => [
   1.762 +				quant_tac 1,
   1.763 +				simp_tac quant_ss 1,
   1.764 +				nat_ind_tac "n" 1,
   1.765 +				simp_tac (take_ss addsimps prems) 1,
   1.766 +				TRY(safe_tac HOL_cs)]
   1.767 +				@ flat(map (fn (cons,cases) => [
   1.768 +				 res_inst_tac [("x","x")] cases 1,
   1.769 +				 asm_simp_tac (take_ss addsimps prems) 1]
   1.770 +				 @ flat(map (fn (con,args) => 
   1.771 +				  asm_simp_tac take_ss 1 ::
   1.772 +				  map (fn arg =>
   1.773 +				   case_UU_tac (prems@con_rews) 1 (
   1.774 +			   nth_elem(rec_of arg,dnames)^"_take n1`"^vname arg))
   1.775 +				  (filter is_nonlazy_rec args) @ [
   1.776 +				  resolve_tac prems 1] @
   1.777 +				  map (K (atac 1))      (nonlazy args) @
   1.778 +				  map (K (etac spec 1)) (filter is_rec args)) 
   1.779 +				 cons))
   1.780 +				(conss~~casess)));
   1.781 +
   1.782 +val take_lemmas =mapn(fn n=> fn(dn,ax_reach)=> pg'' thy axs_take_def(mk_All("n",
   1.783 +		mk_trp(dc_take dn $ Bound 0 `%(x_name n) === 
   1.784 +		       dc_take dn $ Bound 0 `%(x_name n^"'")))
   1.785 +	   ===> mk_trp(%(x_name n) === %(x_name n^"'"))) (fn prems => [
   1.786 +			res_inst_tac[("t",x_name n    )](ax_reach RS subst) 1,
   1.787 +			res_inst_tac[("t",x_name n^"'")](ax_reach RS subst) 1,
   1.788 +				rtac (fix_def2 RS ssubst) 1,
   1.789 +				REPEAT(CHANGED(rtac(contlub_cfun_arg RS ssubst)1
   1.790 +					       THEN chain_tac 1)),
   1.791 +				rtac (contlub_cfun_fun RS ssubst) 1,
   1.792 +				rtac (contlub_cfun_fun RS ssubst) 2,
   1.793 +				rtac lub_equal 3,
   1.794 +				chain_tac 1,
   1.795 +				rtac allI 1,
   1.796 +				resolve_tac prems 1])) 1 (dnames~~axs_reach);
   1.797 +
   1.798 +(* ----- theorems concerning finiteness and induction ----------------------- *)
   1.799  
   1.800  val (finites,ind) = if is_finite then
   1.801 -let 
   1.802 -  fun take_enough dn = mk_ex ("n",dc_take dn $ Bound 0 ` %"x" === %"x");
   1.803 -  val finite_lemmas1a = map (fn dn => pg [] (mk_trp(defined (%"x")) ===> 
   1.804 -        mk_trp(mk_disj(mk_all("n",dc_take dn $ Bound 0 ` %"x" === UU),
   1.805 -        take_enough dn)) ===> mk_trp(take_enough dn)) [
   1.806 -                                etac disjE 1,
   1.807 -                                etac notE 1,
   1.808 -                                resolve_tac take_lemmas 1,
   1.809 -                                asm_simp_tac take_ss 1,
   1.810 -                                atac 1]) dnames;
   1.811 -  val finite_lemma1b = pg [] (mk_trp (mk_all("n",foldr' mk_conj (mapn 
   1.812 -        (fn n => fn ((dn,args),_) => mk_constrainall(x_name n,Type(dn,args),
   1.813 -         mk_disj(dc_take dn $ Bound 1 ` Bound 0 === UU,
   1.814 -                 dc_take dn $ Bound 1 ` Bound 0 === Bound 0))) 1 eqs)))) ([
   1.815 -                                rtac allI 1,
   1.816 -                                nat_ind_tac "n" 1,
   1.817 -                                simp_tac take_ss 1,
   1.818 -                                TRY(safe_tac(empty_cs addSEs[conjE] addSIs[conjI]))] @
   1.819 -                                flat(mapn (fn n => fn (cons,cases) => [
   1.820 -                                  simp_tac take_ss 1,
   1.821 -                                  rtac allI 1,
   1.822 -                                  res_inst_tac [("x",x_name n)] cases 1,
   1.823 -                                  asm_simp_tac take_ss 1] @ 
   1.824 -                                  flat(map (fn (con,args) => 
   1.825 -                                    asm_simp_tac take_ss 1 ::
   1.826 -                                    flat(map (fn arg => [
   1.827 -                                      eres_inst_tac [("x",vname arg)] all_dupE 1,
   1.828 -                                      etac disjE 1,
   1.829 -                                      asm_simp_tac (HOL_ss addsimps con_rews) 1,
   1.830 -                                      asm_simp_tac take_ss 1])
   1.831 -                                    (filter is_nonlazy_rec args)))
   1.832 -                                  cons))
   1.833 -                                1 (conss~~casess))) handle ERROR => raise ERROR;
   1.834 -  val all_finite=map (fn(dn,l1b)=>pg axs_finite_def (mk_trp(%%(dn^"_finite") $ %"x"))[
   1.835 -                                case_UU_tac take_rews 1 "x",
   1.836 -                                eresolve_tac finite_lemmas1a 1,
   1.837 -                                step_tac HOL_cs 1,
   1.838 -                                step_tac HOL_cs 1,
   1.839 -                                cut_facts_tac [l1b] 1,
   1.840 -                                fast_tac HOL_cs 1]) (dnames~~atomize finite_lemma1b);
   1.841 -in
   1.842 -(all_finite,
   1.843 - pg'' thy [] (ind_term (fn (P,x) => fn dn => %P $ %x))
   1.844 -                               (ind_tacs (fn _ => fn (all_fin,finite_ind) => [
   1.845 -                                rtac (rewrite_rule axs_finite_def all_fin RS exE) 1,
   1.846 -                                etac subst 1,
   1.847 -                                rtac finite_ind 1]) all_finite (atomize finite_ind))
   1.848 +  let 
   1.849 +    fun take_enough dn = mk_ex ("n",dc_take dn $ Bound 0 ` %"x" === %"x");
   1.850 +    val finite_lemmas1a = map (fn dn => pg [] (mk_trp(defined (%"x")) ===> 
   1.851 +	mk_trp(mk_disj(mk_all("n",dc_take dn $ Bound 0 ` %"x" === UU),
   1.852 +	take_enough dn)) ===> mk_trp(take_enough dn)) [
   1.853 +				etac disjE 1,
   1.854 +				etac notE 1,
   1.855 +				resolve_tac take_lemmas 1,
   1.856 +				asm_simp_tac take_ss 1,
   1.857 +				atac 1]) dnames;
   1.858 +    val finite_lemma1b = pg [] (mk_trp (mk_all("n",foldr' mk_conj (mapn 
   1.859 +	(fn n => fn ((dn,args),_) => mk_constrainall(x_name n,Type(dn,args),
   1.860 +	 mk_disj(dc_take dn $ Bound 1 ` Bound 0 === UU,
   1.861 +		 dc_take dn $ Bound 1 ` Bound 0 === Bound 0))) 1 eqs)))) ([
   1.862 +				rtac allI 1,
   1.863 +				nat_ind_tac "n" 1,
   1.864 +				simp_tac take_ss 1,
   1.865 +			TRY(safe_tac(empty_cs addSEs[conjE] addSIs[conjI]))] @
   1.866 +				flat(mapn (fn n => fn (cons,cases) => [
   1.867 +				  simp_tac take_ss 1,
   1.868 +				  rtac allI 1,
   1.869 +				  res_inst_tac [("x",x_name n)] cases 1,
   1.870 +				  asm_simp_tac take_ss 1] @ 
   1.871 +				  flat(map (fn (con,args) => 
   1.872 +				    asm_simp_tac take_ss 1 ::
   1.873 +				    flat(map (fn vn => [
   1.874 +				      eres_inst_tac [("x",vn)] all_dupE 1,
   1.875 +				      etac disjE 1,
   1.876 +				      asm_simp_tac (HOL_ss addsimps con_rews) 1,
   1.877 +				      asm_simp_tac take_ss 1])
   1.878 +				    (nonlazy_rec args)))
   1.879 +				  cons))
   1.880 +				1 (conss~~casess))) handle ERROR => raise ERROR;
   1.881 +    val finites = map (fn (dn,l1b) => pg axs_finite_def (mk_trp(
   1.882 +						%%(dn^"_finite") $ %"x"))[
   1.883 +				case_UU_tac take_rews 1 "x",
   1.884 +				eresolve_tac finite_lemmas1a 1,
   1.885 +				step_tac HOL_cs 1,
   1.886 +				step_tac HOL_cs 1,
   1.887 +				cut_facts_tac [l1b] 1,
   1.888 +			fast_tac HOL_cs 1]) (dnames~~atomize finite_lemma1b);
   1.889 +  in
   1.890 +  (finites,
   1.891 +   pg'' thy[](ind_term (fn n => fn dn => %(P_name n) $ %(x_name n)))(fn prems =>
   1.892 +				TRY(safe_tac HOL_cs) ::
   1.893 +			 flat (map (fn (finite,fin_ind) => [
   1.894 +			       rtac(rewrite_rule axs_finite_def finite RS exE)1,
   1.895 +				etac subst 1,
   1.896 +				rtac fin_ind 1,
   1.897 +				ind_prems_tac prems]) 
   1.898 +			           (finites~~(atomize finite_ind)) ))
   1.899  ) end (* let *) else
   1.900 -(mapn (fn n => fn dn => read_instantiate_sg (sign_of thy) 
   1.901 -                    [("P",dn^"_finite "^x_name n)] excluded_middle) 1 dnames,
   1.902 - pg'' thy [] (foldr (op ===>) (mapn (fn n =>K(mk_trp(%%"adm" $ %(P_name n))))1
   1.903 -                                       dnames,ind_term (fn(P,x)=>fn dn=> %P $ %x)))
   1.904 -                               (ind_tacs (fn (n,prems) => fn (ax_reach,finite_ind) =>[
   1.905 -                                rtac (ax_reach RS subst) 1,
   1.906 -                                res_inst_tac [("x",x_name n)] spec 1,
   1.907 -                                rtac wfix_ind 1,
   1.908 -                                rtac adm_impl_admw 1,
   1.909 -                                resolve_tac adm_thms 1,
   1.910 -                                rtac adm_subst 1,
   1.911 -                                cont_tacR 1,
   1.912 -                                resolve_tac prems 1,
   1.913 -                                strip_tac 1,
   1.914 -                                rtac(rewrite_rule axs_take_def finite_ind) 1])
   1.915 -                                 axs_reach (atomize finite_ind))
   1.916 +  (mapn (fn n => fn dn => read_instantiate_sg (sign_of thy) 
   1.917 +	  	    [("P",dn^"_finite "^x_name n)] excluded_middle) 1 dnames,
   1.918 +   pg'' thy [] (foldr (op ===>) (mapn (fn n => K(mk_trp(%%"adm" $ %(P_name n))))
   1.919 +	       1 dnames, ind_term (fn n => fn dn => %(P_name n) $ %(x_name n))))
   1.920 +		   (fn prems => map (fn ax_reach => rtac (ax_reach RS subst) 1) 
   1.921 +				    axs_reach @ [
   1.922 +				quant_tac 1,
   1.923 +				rtac (adm_impl_admw RS wfix_ind) 1,
   1.924 +				REPEAT_DETERM(rtac adm_all2 1),
   1.925 +				REPEAT_DETERM(TRY(rtac adm_conj 1) THEN 
   1.926 +						  rtac adm_subst 1 THEN 
   1.927 +					cont_tacR 1 THEN resolve_tac prems 1),
   1.928 +				strip_tac 1,
   1.929 +				rtac (rewrite_rule axs_take_def finite_ind) 1,
   1.930 +				ind_prems_tac prems])
   1.931  )
   1.932  end; (* local *)
   1.933  
   1.934 +(* ----- theorem concerning coinduction ------------------------------------- *)
   1.935 +
   1.936  local
   1.937    val xs = mapn (fn n => K (x_name n)) 1 dnames;
   1.938 -  fun bnd_arg n i = Bound(2*(length dnames - n)-i-1);
   1.939 +  fun bnd_arg n i = Bound(2*(n_eqs - n)-i-1);
   1.940    val take_ss = HOL_ss addsimps take_rews;
   1.941 -  val sproj   = bin_branchr (fn s => "fst("^s^")") (fn s => "snd("^s^")");
   1.942 -  val coind_lemma = pg [ax_bisim_def] (mk_trp(mk_imp(%%(comp_dname^"_bisim") $ %"R",
   1.943 -                foldr (fn (x,t)=> mk_all(x,mk_all(x^"'",t))) (xs,
   1.944 -                  foldr mk_imp (mapn (fn n => K(proj (%"R") dnames n $ 
   1.945 -                                      bnd_arg n 0 $ bnd_arg n 1)) 0 dnames,
   1.946 -                    foldr' mk_conj (mapn (fn n => fn dn => 
   1.947 -                                (dc_take dn $ %"n" `bnd_arg n 0 === 
   1.948 -                                (dc_take dn $ %"n" `bnd_arg n 1))) 0 dnames)))))) ([
   1.949 -                                rtac impI 1,
   1.950 -                                nat_ind_tac "n" 1,
   1.951 -                                simp_tac take_ss 1,
   1.952 -                                safe_tac HOL_cs] @
   1.953 -                                flat(mapn (fn n => fn x => [
   1.954 -                                  etac allE 1, etac allE 1, 
   1.955 -                                  eres_inst_tac [("P1",sproj "R" dnames n^
   1.956 -                                                  " "^x^" "^x^"'")](mp RS disjE) 1,
   1.957 -                                  TRY(safe_tac HOL_cs),
   1.958 -                                  REPEAT(CHANGED(asm_simp_tac take_ss 1))]) 
   1.959 -                                0 xs));
   1.960 +  val sproj   = prj (fn s => "fst("^s^")") (fn s => "snd("^s^")");
   1.961 +  val coind_lemma=pg[ax_bisim_def](mk_trp(mk_imp(%%(comp_dname^"_bisim") $ %"R",
   1.962 +		foldr (fn (x,t)=> mk_all(x,mk_all(x^"'",t))) (xs,
   1.963 +		  foldr mk_imp (mapn (fn n => K(proj (%"R") n_eqs n $ 
   1.964 +				      bnd_arg n 0 $ bnd_arg n 1)) 0 dnames,
   1.965 +		    foldr' mk_conj (mapn (fn n => fn dn => 
   1.966 +				(dc_take dn $ %"n" `bnd_arg n 0 === 
   1.967 +				(dc_take dn $ %"n" `bnd_arg n 1)))0 dnames))))))
   1.968 +			     ([ rtac impI 1,
   1.969 +				nat_ind_tac "n" 1,
   1.970 +				simp_tac take_ss 1,
   1.971 +				safe_tac HOL_cs] @
   1.972 +				flat(mapn (fn n => fn x => [
   1.973 +				  rotate_tac (n+1) 1,
   1.974 +				  etac all2E 1,
   1.975 +				  eres_inst_tac [("P1", sproj "R" n_eqs n^
   1.976 +					" "^x^" "^x^"'")](mp RS disjE) 1,
   1.977 +				  TRY(safe_tac HOL_cs),
   1.978 +				  REPEAT(CHANGED(asm_simp_tac take_ss 1))]) 
   1.979 +				0 xs));
   1.980  in
   1.981  val coind = pg [] (mk_trp(%%(comp_dname^"_bisim") $ %"R") ===>
   1.982 -                foldr (op ===>) (mapn (fn n => fn x => 
   1.983 -                        mk_trp(proj (%"R") dnames n $ %x $ %(x^"'"))) 0 xs,
   1.984 -                        mk_trp(foldr' mk_conj (map (fn x => %x === %(x^"'")) xs)))) ([
   1.985 -                                TRY(safe_tac HOL_cs)] @
   1.986 -                                flat(map (fn take_lemma => [
   1.987 -                                  rtac take_lemma 1,
   1.988 -                                  cut_facts_tac [coind_lemma] 1,
   1.989 -                                  fast_tac HOL_cs 1])
   1.990 -                                take_lemmas));
   1.991 +		foldr (op ===>) (mapn (fn n => fn x => 
   1.992 +		  mk_trp(proj (%"R") n_eqs n $ %x $ %(x^"'"))) 0 xs,
   1.993 +		  mk_trp(foldr' mk_conj (map (fn x => %x === %(x^"'")) xs)))) ([
   1.994 +				TRY(safe_tac HOL_cs)] @
   1.995 +				flat(map (fn take_lemma => [
   1.996 +				  rtac take_lemma 1,
   1.997 +				  cut_facts_tac [coind_lemma] 1,
   1.998 +				  fast_tac HOL_cs 1])
   1.999 +				take_lemmas));
  1.1000  end; (* local *)
  1.1001  
  1.1002