src/HOL/Trancl.ML
author nipkow
Mon Apr 27 16:45:11 1998 +0200 (1998-04-27)
changeset 4830 bd73675adbed
parent 4799 82b0ed20c2cb
child 4838 196100237656
permissions -rw-r--r--
Added a few lemmas.
Renamed expand_const -> split_const.
     1 (*  Title:      HOL/Trancl
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1992  University of Cambridge
     5 
     6 For Trancl.thy.  Theorems about the transitive closure of a relation
     7 *)
     8 
     9 open Trancl;
    10 
    11 (** The relation rtrancl **)
    12 
    13 goal Trancl.thy "mono(%s. id Un (r O s))";
    14 by (rtac monoI 1);
    15 by (REPEAT (ares_tac [monoI, subset_refl, comp_mono, Un_mono] 1));
    16 qed "rtrancl_fun_mono";
    17 
    18 val rtrancl_unfold = rtrancl_fun_mono RS (rtrancl_def RS def_lfp_Tarski);
    19 
    20 (*Reflexivity of rtrancl*)
    21 goal Trancl.thy "(a,a) : r^*";
    22 by (stac rtrancl_unfold 1);
    23 by (Blast_tac 1);
    24 qed "rtrancl_refl";
    25 
    26 Addsimps [rtrancl_refl];
    27 AddSIs   [rtrancl_refl];
    28 
    29 
    30 (*Closure under composition with r*)
    31 goal Trancl.thy "!!r. [| (a,b) : r^*;  (b,c) : r |] ==> (a,c) : r^*";
    32 by (stac rtrancl_unfold 1);
    33 by (Blast_tac 1);
    34 qed "rtrancl_into_rtrancl";
    35 
    36 (*rtrancl of r contains r*)
    37 goal Trancl.thy "!!p. p : r ==> p : r^*";
    38 by (split_all_tac 1);
    39 by (etac (rtrancl_refl RS rtrancl_into_rtrancl) 1);
    40 qed "r_into_rtrancl";
    41 
    42 (*monotonicity of rtrancl*)
    43 goalw Trancl.thy [rtrancl_def] "!!r s. r <= s ==> r^* <= s^*";
    44 by (REPEAT(ares_tac [lfp_mono,Un_mono,comp_mono,subset_refl] 1));
    45 qed "rtrancl_mono";
    46 
    47 (** standard induction rule **)
    48 
    49 val major::prems = goal Trancl.thy 
    50   "[| (a,b) : r^*; \
    51 \     !!x. P((x,x)); \
    52 \     !!x y z.[| P((x,y)); (x,y): r^*; (y,z): r |]  ==>  P((x,z)) |] \
    53 \  ==>  P((a,b))";
    54 by (rtac ([rtrancl_def, rtrancl_fun_mono, major] MRS def_induct) 1);
    55 by (blast_tac (claset() addIs prems) 1);
    56 qed "rtrancl_full_induct";
    57 
    58 (*nice induction rule*)
    59 val major::prems = goal Trancl.thy
    60     "[| (a::'a,b) : r^*;    \
    61 \       P(a); \
    62 \       !!y z.[| (a,y) : r^*;  (y,z) : r;  P(y) |] ==> P(z) |]  \
    63 \     ==> P(b)";
    64 (*by induction on this formula*)
    65 by (subgoal_tac "! y. (a::'a,b) = (a,y) --> P(y)" 1);
    66 (*now solve first subgoal: this formula is sufficient*)
    67 by (Blast_tac 1);
    68 (*now do the induction*)
    69 by (resolve_tac [major RS rtrancl_full_induct] 1);
    70 by (blast_tac (claset() addIs prems) 1);
    71 by (blast_tac (claset() addIs prems) 1);
    72 qed "rtrancl_induct";
    73 
    74 bind_thm
    75   ("rtrancl_induct2",
    76    Prod_Syntax.split_rule
    77      (read_instantiate [("a","(ax,ay)"), ("b","(bx,by)")] rtrancl_induct));
    78 
    79 (*transitivity of transitive closure!! -- by induction.*)
    80 goalw Trancl.thy [trans_def] "trans(r^*)";
    81 by Safe_tac;
    82 by (eres_inst_tac [("b","z")] rtrancl_induct 1);
    83 by (ALLGOALS(blast_tac (claset() addIs [rtrancl_into_rtrancl])));
    84 qed "trans_rtrancl";
    85 
    86 bind_thm ("rtrancl_trans", trans_rtrancl RS transD);
    87 
    88 
    89 (*elimination of rtrancl -- by induction on a special formula*)
    90 val major::prems = goal Trancl.thy
    91     "[| (a::'a,b) : r^*;  (a = b) ==> P;        \
    92 \       !!y.[| (a,y) : r^*; (y,b) : r |] ==> P  \
    93 \    |] ==> P";
    94 by (subgoal_tac "(a::'a) = b  | (? y. (a,y) : r^* & (y,b) : r)" 1);
    95 by (rtac (major RS rtrancl_induct) 2);
    96 by (blast_tac (claset() addIs prems) 2);
    97 by (blast_tac (claset() addIs prems) 2);
    98 by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1));
    99 qed "rtranclE";
   100 
   101 bind_thm ("rtrancl_into_rtrancl2", r_into_rtrancl RS rtrancl_trans);
   102 
   103 
   104 (*** More r^* equations and inclusions ***)
   105 
   106 goal Trancl.thy "(r^*)^* = r^*";
   107 by (rtac set_ext 1);
   108 by (res_inst_tac [("p","x")] PairE 1);
   109 by (hyp_subst_tac 1);
   110 by (rtac iffI 1);
   111 by (etac rtrancl_induct 1);
   112 by (rtac rtrancl_refl 1);
   113 by (blast_tac (claset() addIs [rtrancl_trans]) 1);
   114 by (etac r_into_rtrancl 1);
   115 qed "rtrancl_idemp";
   116 Addsimps [rtrancl_idemp];
   117 
   118 goal thy "R^* O R^* = R^*";
   119 br set_ext 1;
   120 by(split_all_tac 1);
   121 by(blast_tac (claset() addIs [rtrancl_trans]) 1);
   122 qed "rtrancl_idemp_self_comp";
   123 Addsimps [rtrancl_idemp_self_comp];
   124 
   125 goal Trancl.thy "!!r s. r <= s^* ==> r^* <= s^*";
   126 by (dtac rtrancl_mono 1);
   127 by (Asm_full_simp_tac 1);
   128 qed "rtrancl_subset_rtrancl";
   129 
   130 goal Trancl.thy "!!R. [| R <= S; S <= R^* |] ==> S^* = R^*";
   131 by (dtac rtrancl_mono 1);
   132 by (dtac rtrancl_mono 1);
   133 by (Asm_full_simp_tac 1);
   134 by (Blast_tac 1);
   135 qed "rtrancl_subset";
   136 
   137 goal Trancl.thy "!!R. (R^* Un S^*)^* = (R Un S)^*";
   138 by (blast_tac (claset() addSIs [rtrancl_subset]
   139                        addIs [r_into_rtrancl, rtrancl_mono RS subsetD]) 1);
   140 qed "rtrancl_Un_rtrancl";
   141 
   142 goal Trancl.thy "(R^=)^* = R^*";
   143 by (blast_tac (claset() addSIs [rtrancl_subset]
   144                        addIs  [rtrancl_refl, r_into_rtrancl]) 1);
   145 qed "rtrancl_reflcl";
   146 Addsimps [rtrancl_reflcl];
   147 
   148 goal Trancl.thy "!!r. (x,y) : (r^-1)^* ==> (x,y) : (r^*)^-1";
   149 by (rtac converseI 1);
   150 by (etac rtrancl_induct 1);
   151 by (rtac rtrancl_refl 1);
   152 by (blast_tac (claset() addIs [r_into_rtrancl,rtrancl_trans]) 1);
   153 qed "rtrancl_converseD";
   154 
   155 goal Trancl.thy "!!r. (x,y) : (r^*)^-1 ==> (x,y) : (r^-1)^*";
   156 by (dtac converseD 1);
   157 by (etac rtrancl_induct 1);
   158 by (rtac rtrancl_refl 1);
   159 by (blast_tac (claset() addIs [r_into_rtrancl,rtrancl_trans]) 1);
   160 qed "rtrancl_converseI";
   161 
   162 goal Trancl.thy "(r^-1)^* = (r^*)^-1";
   163 by (safe_tac (claset() addSDs [rtrancl_converseD] addSIs [rtrancl_converseI]
   164 			addSaltern ("split_all_tac", split_all_tac)));
   165 qed "rtrancl_converse";
   166 
   167 val major::prems = goal Trancl.thy
   168     "[| (a,b) : r^*; P(b); \
   169 \       !!y z.[| (y,z) : r;  (z,b) : r^*;  P(z) |] ==> P(y) |]  \
   170 \     ==> P(a)";
   171 by (rtac ((major RS converseI RS rtrancl_converseI) RS rtrancl_induct) 1);
   172 by (resolve_tac prems 1);
   173 by (blast_tac (claset() addIs prems addSDs[rtrancl_converseD])1);
   174 qed "converse_rtrancl_induct";
   175 
   176 val prems = goal Trancl.thy
   177  "[| ((a,b),(c,d)) : r^*; P c d; \
   178 \    !!x y z u.[| ((x,y),(z,u)) : r;  ((z,u),(c,d)) : r^*;  P z u |] ==> P x y\
   179 \ |] ==> P a b";
   180 by (res_inst_tac[("R","P")]splitD 1);
   181 by (res_inst_tac[("P","split P")]converse_rtrancl_induct 1);
   182 by (resolve_tac prems 1);
   183 by (Simp_tac 1);
   184 by (resolve_tac prems 1);
   185 by (split_all_tac 1);
   186 by (Asm_full_simp_tac 1);
   187 by (REPEAT(ares_tac prems 1));
   188 qed "converse_rtrancl_induct2";
   189 
   190 val major::prems = goal Trancl.thy
   191  "[| (x,z):r^*; \
   192 \    x=z ==> P; \
   193 \    !!y. [| (x,y):r; (y,z):r^* |] ==> P \
   194 \ |] ==> P";
   195 by (subgoal_tac "x = z  | (? y. (x,y) : r & (y,z) : r^*)" 1);
   196 by (rtac (major RS converse_rtrancl_induct) 2);
   197 by (blast_tac (claset() addIs prems) 2);
   198 by (blast_tac (claset() addIs prems) 2);
   199 by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1));
   200 qed "rtranclE2";
   201 
   202 goal Trancl.thy "r O r^* = r^* O r";
   203 by (blast_tac (claset() addEs [rtranclE, rtranclE2] 
   204 	               addIs [rtrancl_into_rtrancl, rtrancl_into_rtrancl2]) 1);
   205 qed "r_comp_rtrancl_eq";
   206 
   207 
   208 (**** The relation trancl ****)
   209 
   210 goalw Trancl.thy [trancl_def] "!!p.[| p:r^+; r <= s |] ==> p:s^+";
   211 by (blast_tac (claset() addIs [rtrancl_mono RS subsetD]) 1);
   212 qed "trancl_mono";
   213 
   214 (** Conversions between trancl and rtrancl **)
   215 
   216 goalw Trancl.thy [trancl_def]
   217     "!!p. p : r^+ ==> p : r^*";
   218 by (split_all_tac 1);
   219 by (etac compEpair 1);
   220 by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
   221 qed "trancl_into_rtrancl";
   222 
   223 (*r^+ contains r*)
   224 goalw Trancl.thy [trancl_def]
   225    "!!p. p : r ==> p : r^+";
   226 by (split_all_tac 1);
   227 by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1));
   228 qed "r_into_trancl";
   229 
   230 (*intro rule by definition: from rtrancl and r*)
   231 val prems = goalw Trancl.thy [trancl_def]
   232     "[| (a,b) : r^*;  (b,c) : r |]   ==>  (a,c) : r^+";
   233 by (REPEAT (resolve_tac ([compI]@prems) 1));
   234 qed "rtrancl_into_trancl1";
   235 
   236 (*intro rule from r and rtrancl*)
   237 val prems = goal Trancl.thy
   238     "[| (a,b) : r;  (b,c) : r^* |]   ==>  (a,c) : r^+";
   239 by (resolve_tac (prems RL [rtranclE]) 1);
   240 by (etac subst 1);
   241 by (resolve_tac (prems RL [r_into_trancl]) 1);
   242 by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1);
   243 by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1));
   244 qed "rtrancl_into_trancl2";
   245 
   246 (*Nice induction rule for trancl*)
   247 val major::prems = goal Trancl.thy
   248   "[| (a,b) : r^+;                                      \
   249 \     !!y.  [| (a,y) : r |] ==> P(y);                   \
   250 \     !!y z.[| (a,y) : r^+;  (y,z) : r;  P(y) |] ==> P(z)       \
   251 \  |] ==> P(b)";
   252 by (rtac (rewrite_rule [trancl_def] major  RS  compEpair) 1);
   253 (*by induction on this formula*)
   254 by (subgoal_tac "ALL z. (y,z) : r --> P(z)" 1);
   255 (*now solve first subgoal: this formula is sufficient*)
   256 by (Blast_tac 1);
   257 by (etac rtrancl_induct 1);
   258 by (ALLGOALS (blast_tac (claset() addIs (rtrancl_into_trancl1::prems))));
   259 qed "trancl_induct";
   260 
   261 (*elimination of r^+ -- NOT an induction rule*)
   262 val major::prems = goal Trancl.thy
   263     "[| (a::'a,b) : r^+;  \
   264 \       (a,b) : r ==> P; \
   265 \       !!y.[| (a,y) : r^+;  (y,b) : r |] ==> P  \
   266 \    |] ==> P";
   267 by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+  &  (y,b) : r)" 1);
   268 by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1));
   269 by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
   270 by (etac rtranclE 1);
   271 by (Blast_tac 1);
   272 by (blast_tac (claset() addSIs [rtrancl_into_trancl1]) 1);
   273 qed "tranclE";
   274 
   275 (*Transitivity of r^+.
   276   Proved by unfolding since it uses transitivity of rtrancl. *)
   277 goalw Trancl.thy [trancl_def] "trans(r^+)";
   278 by (rtac transI 1);
   279 by (REPEAT (etac compEpair 1));
   280 by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1);
   281 by (REPEAT (assume_tac 1));
   282 qed "trans_trancl";
   283 
   284 bind_thm ("trancl_trans", trans_trancl RS transD);
   285 
   286 goalw Trancl.thy [trancl_def]
   287   "!!r. [| (x,y):r^*; (y,z):r^+ |] ==> (x,z):r^+";
   288 by (blast_tac (claset() addIs [rtrancl_trans,r_into_rtrancl]) 1);
   289 qed "rtrancl_trancl_trancl";
   290 
   291 val prems = goal Trancl.thy
   292     "[| (a,b) : r;  (b,c) : r^+ |]   ==>  (a,c) : r^+";
   293 by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1);
   294 by (resolve_tac prems 1);
   295 by (resolve_tac prems 1);
   296 qed "trancl_into_trancl2";
   297 
   298 (* primitive recursion for trancl over finite relations: *)
   299 goal Trancl.thy "(insert (y,x) r)^+ = r^+ Un {(a,b). (a,y):r^* & (x,b):r^*}";
   300 by (rtac equalityI 1);
   301  by (rtac subsetI 1);
   302  by (split_all_tac 1);
   303  by (etac trancl_induct 1);
   304   by (blast_tac (claset() addIs [r_into_trancl]) 1);
   305  by (blast_tac (claset() addIs
   306      [rtrancl_into_trancl1,trancl_into_rtrancl,r_into_trancl,trancl_trans]) 1);
   307 by (rtac subsetI 1);
   308 by (blast_tac (claset() addIs
   309      [rtrancl_into_trancl2, rtrancl_trancl_trancl,
   310       impOfSubs rtrancl_mono, trancl_mono]) 1);
   311 qed "trancl_insert";
   312 
   313 goalw Trancl.thy [trancl_def] "(r^-1)^+ = (r^+)^-1";
   314 by (simp_tac (simpset() addsimps [rtrancl_converse,converse_comp]) 1);
   315 by (simp_tac (simpset() addsimps [rtrancl_converse RS sym,r_comp_rtrancl_eq])1);
   316 qed "trancl_converse";
   317 
   318 val irrefl_tranclI = prove_goal Trancl.thy 
   319 	"!!r. r^-1 Int r^+ = {} ==> !x. (x, x) ~: r^+" (K [
   320 	rtac allI 1,
   321 	subgoal_tac "!y. (x, y) : r^+ --> x~=y" 1,
   322 	 Fast_tac 1,
   323 	strip_tac 1,
   324 	etac trancl_induct 1,
   325 	 auto_tac (claset() addEs [equals0D, r_into_trancl], simpset())]);
   326 
   327 val major::prems = goal Trancl.thy
   328     "[| (a,b) : r^*;  r <= A Times A |] ==> a=b | a:A";
   329 by (cut_facts_tac prems 1);
   330 by (rtac (major RS rtrancl_induct) 1);
   331 by (rtac (refl RS disjI1) 1);
   332 by (Blast_tac 1);
   333 val lemma = result();
   334 
   335 goalw Trancl.thy [trancl_def]
   336     "!!r. r <= A Times A ==> r^+ <= A Times A";
   337 by (blast_tac (claset() addSDs [lemma]) 1);
   338 qed "trancl_subset_Sigma";
   339 
   340 
   341 goal Trancl.thy "(r^+)^= = r^*";
   342 by (safe_tac (claset() addSaltern ("split_all_tac", split_all_tac)));
   343 by  (etac trancl_into_rtrancl 1);
   344 by (etac rtranclE 1);
   345 by  (Auto_tac );
   346 by (etac rtrancl_into_trancl1 1);
   347 ba 1;
   348 qed "reflcl_trancl";
   349 Addsimps[reflcl_trancl];
   350 
   351 goal Trancl.thy "(r^=)^+ = r^*";
   352 by (safe_tac (claset() addSaltern ("split_all_tac", split_all_tac)));
   353 by  (dtac trancl_into_rtrancl 1);
   354 by  (Asm_full_simp_tac 1);
   355 by (etac rtranclE 1);
   356 by  Safe_tac;
   357 by  (rtac r_into_trancl 1);
   358 by  (Simp_tac 1);
   359 by (rtac rtrancl_into_trancl1 1);
   360 by (etac (rtrancl_reflcl RS equalityD2 RS subsetD) 1);
   361 by (Fast_tac 1);
   362 qed "trancl_reflcl";
   363 Addsimps[trancl_reflcl];
   364 
   365 qed_goal "trancl_empty" Trancl.thy "{}^+ = {}" 
   366   (K [auto_tac (claset() addEs [trancl_induct], simpset())]);
   367 Addsimps[trancl_empty];
   368 
   369 qed_goal "rtrancl_empty" Trancl.thy "{}^* = id" 
   370   (K [rtac (reflcl_trancl RS subst) 1, Simp_tac 1]);
   371 Addsimps[rtrancl_empty];