src/CCL/trancl.ML
changeset 0 a5a9c433f639
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/CCL/trancl.ML	Thu Sep 16 12:20:38 1993 +0200
     1.3 @@ -0,0 +1,215 @@
     1.4 +(*  Title: 	CCL/trancl
     1.5 +    ID:         $Id$
     1.6 +
     1.7 +For trancl.thy.
     1.8 +
     1.9 +Modified version of
    1.10 +    Title: 	HOL/trancl.ML
    1.11 +    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
    1.12 +    Copyright   1992  University of Cambridge
    1.13 +
    1.14 +*)
    1.15 +
    1.16 +open Trancl;
    1.17 +
    1.18 +(** Natural deduction for trans(r) **)
    1.19 +
    1.20 +val prems = goalw Trancl.thy [trans_def]
    1.21 +    "(!! x y z. [| <x,y>:r;  <y,z>:r |] ==> <x,z>:r) ==> trans(r)";
    1.22 +by (REPEAT (ares_tac (prems@[allI,impI]) 1));
    1.23 +val transI = result();
    1.24 +
    1.25 +val major::prems = goalw Trancl.thy [trans_def]
    1.26 +    "[| trans(r);  <a,b>:r;  <b,c>:r |] ==> <a,c>:r";
    1.27 +by (cut_facts_tac [major] 1);
    1.28 +by (fast_tac (FOL_cs addIs prems) 1);
    1.29 +val transD = result();
    1.30 +
    1.31 +(** Identity relation **)
    1.32 +
    1.33 +goalw Trancl.thy [id_def] "<a,a> : id";  
    1.34 +by (rtac CollectI 1);
    1.35 +by (rtac exI 1);
    1.36 +by (rtac refl 1);
    1.37 +val idI = result();
    1.38 +
    1.39 +val major::prems = goalw Trancl.thy [id_def]
    1.40 +    "[| p: id;  !!x.[| p = <x,x> |] ==> P  \
    1.41 +\    |] ==>  P";  
    1.42 +by (rtac (major RS CollectE) 1);
    1.43 +by (etac exE 1);
    1.44 +by (eresolve_tac prems 1);
    1.45 +val idE = result();
    1.46 +
    1.47 +(** Composition of two relations **)
    1.48 +
    1.49 +val prems = goalw Trancl.thy [comp_def]
    1.50 +    "[| <a,b>:s; <b,c>:r |] ==> <a,c> : r O s";
    1.51 +by (fast_tac (set_cs addIs prems) 1);
    1.52 +val compI = result();
    1.53 +
    1.54 +(*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
    1.55 +val prems = goalw Trancl.thy [comp_def]
    1.56 +    "[| xz : r O s;  \
    1.57 +\       !!x y z. [| xz = <x,z>;  <x,y>:s;  <y,z>:r |] ==> P \
    1.58 +\    |] ==> P";
    1.59 +by (cut_facts_tac prems 1);
    1.60 +by (REPEAT (eresolve_tac [CollectE, exE, conjE] 1 ORELSE ares_tac prems 1));
    1.61 +val compE = result();
    1.62 +
    1.63 +val prems = goal Trancl.thy
    1.64 +    "[| <a,c> : r O s;  \
    1.65 +\       !!y. [| <a,y>:s;  <y,c>:r |] ==> P \
    1.66 +\    |] ==> P";
    1.67 +by (rtac compE 1);
    1.68 +by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [pair_inject,ssubst] 1));
    1.69 +val compEpair = result();
    1.70 +
    1.71 +val comp_cs = set_cs addIs [compI,idI] 
    1.72 +		       addEs [compE,idE] 
    1.73 +		       addSEs [pair_inject];
    1.74 +
    1.75 +val prems = goal Trancl.thy
    1.76 +    "[| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
    1.77 +by (cut_facts_tac prems 1);
    1.78 +by (fast_tac comp_cs 1);
    1.79 +val comp_mono = result();
    1.80 +
    1.81 +(** The relation rtrancl **)
    1.82 +
    1.83 +goal Trancl.thy "mono(%s. id Un (r O s))";
    1.84 +by (rtac monoI 1);
    1.85 +by (REPEAT (ares_tac [monoI, subset_refl, comp_mono, Un_mono] 1));
    1.86 +val rtrancl_fun_mono = result();
    1.87 +
    1.88 +val rtrancl_unfold = rtrancl_fun_mono RS (rtrancl_def RS def_lfp_Tarski);
    1.89 +
    1.90 +(*Reflexivity of rtrancl*)
    1.91 +goal Trancl.thy "<a,a> : r^*";
    1.92 +br (rtrancl_unfold RS ssubst) 1;
    1.93 +by (fast_tac comp_cs 1);
    1.94 +val rtrancl_refl = result();
    1.95 +
    1.96 +(*Closure under composition with r*)
    1.97 +val prems = goal Trancl.thy
    1.98 +    "[| <a,b> : r^*;  <b,c> : r |] ==> <a,c> : r^*";
    1.99 +br (rtrancl_unfold RS ssubst) 1;
   1.100 +by (fast_tac (comp_cs addIs prems) 1);
   1.101 +val rtrancl_into_rtrancl = result();
   1.102 +
   1.103 +(*rtrancl of r contains r*)
   1.104 +val [prem] = goal Trancl.thy "[| <a,b> : r |] ==> <a,b> : r^*";
   1.105 +by (rtac (rtrancl_refl RS rtrancl_into_rtrancl) 1);
   1.106 +by (rtac prem 1);
   1.107 +val r_into_rtrancl = result();
   1.108 +
   1.109 +
   1.110 +(** standard induction rule **)
   1.111 +
   1.112 +val major::prems = goal Trancl.thy 
   1.113 +  "[| <a,b> : r^*; \
   1.114 +\     !!x. P(<x,x>); \
   1.115 +\     !!x y z.[| P(<x,y>); <x,y>: r^*; <y,z>: r |]  ==>  P(<x,z>) |] \
   1.116 +\  ==>  P(<a,b>)";
   1.117 +by (rtac (major RS (rtrancl_def RS def_induct)) 1);
   1.118 +by (rtac rtrancl_fun_mono 1);
   1.119 +by (fast_tac (comp_cs addIs prems) 1);
   1.120 +val rtrancl_full_induct = result();
   1.121 +
   1.122 +(*nice induction rule*)
   1.123 +val major::prems = goal Trancl.thy
   1.124 +    "[| <a,b> : r^*;    \
   1.125 +\       P(a); \
   1.126 +\	!!y z.[| <a,y> : r^*;  <y,z> : r;  P(y) |] ==> P(z) |]  \
   1.127 +\     ==> P(b)";
   1.128 +(*by induction on this formula*)
   1.129 +by (subgoal_tac "ALL y. <a,b> = <a,y> --> P(y)" 1);
   1.130 +(*now solve first subgoal: this formula is sufficient*)
   1.131 +by (fast_tac FOL_cs 1);
   1.132 +(*now do the induction*)
   1.133 +by (resolve_tac [major RS rtrancl_full_induct] 1);
   1.134 +by (fast_tac (comp_cs addIs prems) 1);
   1.135 +by (fast_tac (comp_cs addIs prems) 1);
   1.136 +val rtrancl_induct = result();
   1.137 +
   1.138 +(*transitivity of transitive closure!! -- by induction.*)
   1.139 +goal Trancl.thy "trans(r^*)";
   1.140 +by (rtac transI 1);
   1.141 +by (res_inst_tac [("b","z")] rtrancl_induct 1);
   1.142 +by (DEPTH_SOLVE (eresolve_tac [asm_rl, rtrancl_into_rtrancl] 1));
   1.143 +val trans_rtrancl = result();
   1.144 +
   1.145 +(*elimination of rtrancl -- by induction on a special formula*)
   1.146 +val major::prems = goal Trancl.thy
   1.147 +    "[| <a,b> : r^*;  (a = b) ==> P; \
   1.148 +\	!!y.[| <a,y> : r^*; <y,b> : r |] ==> P |] \
   1.149 +\    ==> P";
   1.150 +by (subgoal_tac "a = b  | (EX y. <a,y> : r^* & <y,b> : r)" 1);
   1.151 +by (rtac (major RS rtrancl_induct) 2);
   1.152 +by (fast_tac (set_cs addIs prems) 2);
   1.153 +by (fast_tac (set_cs addIs prems) 2);
   1.154 +by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1));
   1.155 +val rtranclE = result();
   1.156 +
   1.157 +
   1.158 +(**** The relation trancl ****)
   1.159 +
   1.160 +(** Conversions between trancl and rtrancl **)
   1.161 +
   1.162 +val [major] = goalw Trancl.thy [trancl_def]
   1.163 +    "[| <a,b> : r^+ |] ==> <a,b> : r^*";
   1.164 +by (resolve_tac [major RS compEpair] 1);
   1.165 +by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
   1.166 +val trancl_into_rtrancl = result();
   1.167 +
   1.168 +(*r^+ contains r*)
   1.169 +val [prem] = goalw Trancl.thy [trancl_def]
   1.170 +   "[| <a,b> : r |] ==> <a,b> : r^+";
   1.171 +by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1));
   1.172 +val r_into_trancl = result();
   1.173 +
   1.174 +(*intro rule by definition: from rtrancl and r*)
   1.175 +val prems = goalw Trancl.thy [trancl_def]
   1.176 +    "[| <a,b> : r^*;  <b,c> : r |]   ==>  <a,c> : r^+";
   1.177 +by (REPEAT (resolve_tac ([compI]@prems) 1));
   1.178 +val rtrancl_into_trancl1 = result();
   1.179 +
   1.180 +(*intro rule from r and rtrancl*)
   1.181 +val prems = goal Trancl.thy
   1.182 +    "[| <a,b> : r;  <b,c> : r^* |]   ==>  <a,c> : r^+";
   1.183 +by (resolve_tac (prems RL [rtranclE]) 1);
   1.184 +by (etac subst 1);
   1.185 +by (resolve_tac (prems RL [r_into_trancl]) 1);
   1.186 +by (rtac (trans_rtrancl RS transD RS rtrancl_into_trancl1) 1);
   1.187 +by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1));
   1.188 +val rtrancl_into_trancl2 = result();
   1.189 +
   1.190 +(*elimination of r^+ -- NOT an induction rule*)
   1.191 +val major::prems = goal Trancl.thy
   1.192 +    "[| <a,b> : r^+;  \
   1.193 +\       <a,b> : r ==> P; \
   1.194 +\	!!y.[| <a,y> : r^+;  <y,b> : r |] ==> P  \
   1.195 +\    |] ==> P";
   1.196 +by (subgoal_tac "<a,b> : r | (EX y. <a,y> : r^+  &  <y,b> : r)" 1);
   1.197 +by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1));
   1.198 +by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
   1.199 +by (etac rtranclE 1);
   1.200 +by (fast_tac comp_cs 1);
   1.201 +by (fast_tac (comp_cs addSIs [rtrancl_into_trancl1]) 1);
   1.202 +val tranclE = result();
   1.203 +
   1.204 +(*Transitivity of r^+.
   1.205 +  Proved by unfolding since it uses transitivity of rtrancl. *)
   1.206 +goalw Trancl.thy [trancl_def] "trans(r^+)";
   1.207 +by (rtac transI 1);
   1.208 +by (REPEAT (etac compEpair 1));
   1.209 +by (rtac (rtrancl_into_rtrancl RS (trans_rtrancl RS transD RS compI)) 1);
   1.210 +by (REPEAT (assume_tac 1));
   1.211 +val trans_trancl = result();
   1.212 +
   1.213 +val prems = goal Trancl.thy
   1.214 +    "[| <a,b> : r;  <b,c> : r^+ |]   ==>  <a,c> : r^+";
   1.215 +by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1);
   1.216 +by (resolve_tac prems 1);
   1.217 +by (resolve_tac prems 1);
   1.218 +val trancl_into_trancl2 = result();