src/HOL/Trancl.ML
author oheimb
Tue Apr 07 13:43:07 1998 +0200 (1998-04-07)
changeset 4799 82b0ed20c2cb
parent 4772 8c7e7eaffbdf
child 4830 bd73675adbed
permissions -rw-r--r--
made split_all_tac as safe wrapper more defensive:
if it is added as unsafe wrapper again (as its was before),
this does not break the current proofs.
     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 Trancl.thy "!!r s. r <= s^* ==> r^* <= s^*";
   119 by (dtac rtrancl_mono 1);
   120 by (Asm_full_simp_tac 1);
   121 qed "rtrancl_subset_rtrancl";
   122 
   123 goal Trancl.thy "!!R. [| R <= S; S <= R^* |] ==> S^* = R^*";
   124 by (dtac rtrancl_mono 1);
   125 by (dtac rtrancl_mono 1);
   126 by (Asm_full_simp_tac 1);
   127 by (Blast_tac 1);
   128 qed "rtrancl_subset";
   129 
   130 goal Trancl.thy "!!R. (R^* Un S^*)^* = (R Un S)^*";
   131 by (blast_tac (claset() addSIs [rtrancl_subset]
   132                        addIs [r_into_rtrancl, rtrancl_mono RS subsetD]) 1);
   133 qed "rtrancl_Un_rtrancl";
   134 
   135 goal Trancl.thy "(R^=)^* = R^*";
   136 by (blast_tac (claset() addSIs [rtrancl_subset]
   137                        addIs  [rtrancl_refl, r_into_rtrancl]) 1);
   138 qed "rtrancl_reflcl";
   139 Addsimps [rtrancl_reflcl];
   140 
   141 goal Trancl.thy "!!r. (x,y) : (r^-1)^* ==> (x,y) : (r^*)^-1";
   142 by (rtac converseI 1);
   143 by (etac rtrancl_induct 1);
   144 by (rtac rtrancl_refl 1);
   145 by (blast_tac (claset() addIs [r_into_rtrancl,rtrancl_trans]) 1);
   146 qed "rtrancl_converseD";
   147 
   148 goal Trancl.thy "!!r. (x,y) : (r^*)^-1 ==> (x,y) : (r^-1)^*";
   149 by (dtac converseD 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_converseI";
   154 
   155 goal Trancl.thy "(r^-1)^* = (r^*)^-1";
   156 by (safe_tac (claset() addSDs [rtrancl_converseD] addSIs [rtrancl_converseI]
   157 			addSaltern ("split_all_tac", split_all_tac)));
   158 qed "rtrancl_converse";
   159 
   160 val major::prems = goal Trancl.thy
   161     "[| (a,b) : r^*; P(b); \
   162 \       !!y z.[| (y,z) : r;  (z,b) : r^*;  P(z) |] ==> P(y) |]  \
   163 \     ==> P(a)";
   164 by (rtac ((major RS converseI RS rtrancl_converseI) RS rtrancl_induct) 1);
   165 by (resolve_tac prems 1);
   166 by (blast_tac (claset() addIs prems addSDs[rtrancl_converseD])1);
   167 qed "converse_rtrancl_induct";
   168 
   169 val prems = goal Trancl.thy
   170  "[| ((a,b),(c,d)) : r^*; P c d; \
   171 \    !!x y z u.[| ((x,y),(z,u)) : r;  ((z,u),(c,d)) : r^*;  P z u |] ==> P x y\
   172 \ |] ==> P a b";
   173 by (res_inst_tac[("R","P")]splitD 1);
   174 by (res_inst_tac[("P","split P")]converse_rtrancl_induct 1);
   175 by (resolve_tac prems 1);
   176 by (Simp_tac 1);
   177 by (resolve_tac prems 1);
   178 by (split_all_tac 1);
   179 by (Asm_full_simp_tac 1);
   180 by (REPEAT(ares_tac prems 1));
   181 qed "converse_rtrancl_induct2";
   182 
   183 val major::prems = goal Trancl.thy
   184  "[| (x,z):r^*; \
   185 \    x=z ==> P; \
   186 \    !!y. [| (x,y):r; (y,z):r^* |] ==> P \
   187 \ |] ==> P";
   188 by (subgoal_tac "x = z  | (? y. (x,y) : r & (y,z) : r^*)" 1);
   189 by (rtac (major RS converse_rtrancl_induct) 2);
   190 by (blast_tac (claset() addIs prems) 2);
   191 by (blast_tac (claset() addIs prems) 2);
   192 by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1));
   193 qed "rtranclE2";
   194 
   195 goal Trancl.thy "r O r^* = r^* O r";
   196 by (blast_tac (claset() addEs [rtranclE, rtranclE2] 
   197 	               addIs [rtrancl_into_rtrancl, rtrancl_into_rtrancl2]) 1);
   198 qed "r_comp_rtrancl_eq";
   199 
   200 
   201 (**** The relation trancl ****)
   202 
   203 goalw Trancl.thy [trancl_def] "!!p.[| p:r^+; r <= s |] ==> p:s^+";
   204 by (blast_tac (claset() addIs [rtrancl_mono RS subsetD]) 1);
   205 qed "trancl_mono";
   206 
   207 (** Conversions between trancl and rtrancl **)
   208 
   209 goalw Trancl.thy [trancl_def]
   210     "!!p. p : r^+ ==> p : r^*";
   211 by (split_all_tac 1);
   212 by (etac compEpair 1);
   213 by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
   214 qed "trancl_into_rtrancl";
   215 
   216 (*r^+ contains r*)
   217 goalw Trancl.thy [trancl_def]
   218    "!!p. p : r ==> p : r^+";
   219 by (split_all_tac 1);
   220 by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1));
   221 qed "r_into_trancl";
   222 
   223 (*intro rule by definition: from rtrancl and r*)
   224 val prems = goalw Trancl.thy [trancl_def]
   225     "[| (a,b) : r^*;  (b,c) : r |]   ==>  (a,c) : r^+";
   226 by (REPEAT (resolve_tac ([compI]@prems) 1));
   227 qed "rtrancl_into_trancl1";
   228 
   229 (*intro rule from r and rtrancl*)
   230 val prems = goal Trancl.thy
   231     "[| (a,b) : r;  (b,c) : r^* |]   ==>  (a,c) : r^+";
   232 by (resolve_tac (prems RL [rtranclE]) 1);
   233 by (etac subst 1);
   234 by (resolve_tac (prems RL [r_into_trancl]) 1);
   235 by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1);
   236 by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1));
   237 qed "rtrancl_into_trancl2";
   238 
   239 (*Nice induction rule for trancl*)
   240 val major::prems = goal Trancl.thy
   241   "[| (a,b) : r^+;                                      \
   242 \     !!y.  [| (a,y) : r |] ==> P(y);                   \
   243 \     !!y z.[| (a,y) : r^+;  (y,z) : r;  P(y) |] ==> P(z)       \
   244 \  |] ==> P(b)";
   245 by (rtac (rewrite_rule [trancl_def] major  RS  compEpair) 1);
   246 (*by induction on this formula*)
   247 by (subgoal_tac "ALL z. (y,z) : r --> P(z)" 1);
   248 (*now solve first subgoal: this formula is sufficient*)
   249 by (Blast_tac 1);
   250 by (etac rtrancl_induct 1);
   251 by (ALLGOALS (blast_tac (claset() addIs (rtrancl_into_trancl1::prems))));
   252 qed "trancl_induct";
   253 
   254 (*elimination of r^+ -- NOT an induction rule*)
   255 val major::prems = goal Trancl.thy
   256     "[| (a::'a,b) : r^+;  \
   257 \       (a,b) : r ==> P; \
   258 \       !!y.[| (a,y) : r^+;  (y,b) : r |] ==> P  \
   259 \    |] ==> P";
   260 by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+  &  (y,b) : r)" 1);
   261 by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1));
   262 by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
   263 by (etac rtranclE 1);
   264 by (Blast_tac 1);
   265 by (blast_tac (claset() addSIs [rtrancl_into_trancl1]) 1);
   266 qed "tranclE";
   267 
   268 (*Transitivity of r^+.
   269   Proved by unfolding since it uses transitivity of rtrancl. *)
   270 goalw Trancl.thy [trancl_def] "trans(r^+)";
   271 by (rtac transI 1);
   272 by (REPEAT (etac compEpair 1));
   273 by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1);
   274 by (REPEAT (assume_tac 1));
   275 qed "trans_trancl";
   276 
   277 bind_thm ("trancl_trans", trans_trancl RS transD);
   278 
   279 goalw Trancl.thy [trancl_def]
   280   "!!r. [| (x,y):r^*; (y,z):r^+ |] ==> (x,z):r^+";
   281 by (blast_tac (claset() addIs [rtrancl_trans,r_into_rtrancl]) 1);
   282 qed "rtrancl_trancl_trancl";
   283 
   284 val prems = goal Trancl.thy
   285     "[| (a,b) : r;  (b,c) : r^+ |]   ==>  (a,c) : r^+";
   286 by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1);
   287 by (resolve_tac prems 1);
   288 by (resolve_tac prems 1);
   289 qed "trancl_into_trancl2";
   290 
   291 (* primitive recursion for trancl over finite relations: *)
   292 goal Trancl.thy "(insert (y,x) r)^+ = r^+ Un {(a,b). (a,y):r^* & (x,b):r^*}";
   293 by (rtac equalityI 1);
   294  by (rtac subsetI 1);
   295  by (split_all_tac 1);
   296  by (etac trancl_induct 1);
   297   by (blast_tac (claset() addIs [r_into_trancl]) 1);
   298  by (blast_tac (claset() addIs
   299      [rtrancl_into_trancl1,trancl_into_rtrancl,r_into_trancl,trancl_trans]) 1);
   300 by (rtac subsetI 1);
   301 by (blast_tac (claset() addIs
   302      [rtrancl_into_trancl2, rtrancl_trancl_trancl,
   303       impOfSubs rtrancl_mono, trancl_mono]) 1);
   304 qed "trancl_insert";
   305 
   306 goalw Trancl.thy [trancl_def] "(r^-1)^+ = (r^+)^-1";
   307 by (simp_tac (simpset() addsimps [rtrancl_converse,converse_comp]) 1);
   308 by (simp_tac (simpset() addsimps [rtrancl_converse RS sym,r_comp_rtrancl_eq])1);
   309 qed "trancl_converse";
   310 
   311 val irrefl_tranclI = prove_goal Trancl.thy 
   312 	"!!r. r^-1 Int r^+ = {} ==> !x. (x, x) ~: r^+" (K [
   313 	rtac allI 1,
   314 	subgoal_tac "!y. (x, y) : r^+ --> x~=y" 1,
   315 	 Fast_tac 1,
   316 	strip_tac 1,
   317 	etac trancl_induct 1,
   318 	 auto_tac (claset() addEs [equals0D, r_into_trancl], simpset())]);
   319 
   320 val major::prems = goal Trancl.thy
   321     "[| (a,b) : r^*;  r <= A Times A |] ==> a=b | a:A";
   322 by (cut_facts_tac prems 1);
   323 by (rtac (major RS rtrancl_induct) 1);
   324 by (rtac (refl RS disjI1) 1);
   325 by (Blast_tac 1);
   326 val lemma = result();
   327 
   328 goalw Trancl.thy [trancl_def]
   329     "!!r. r <= A Times A ==> r^+ <= A Times A";
   330 by (blast_tac (claset() addSDs [lemma]) 1);
   331 qed "trancl_subset_Sigma";
   332 
   333 
   334 goal Trancl.thy "(r^+)^= = r^*";
   335 by (safe_tac (claset() addSaltern ("split_all_tac", split_all_tac)));
   336 by  (etac trancl_into_rtrancl 1);
   337 by (etac rtranclE 1);
   338 by  (Auto_tac );
   339 by (etac rtrancl_into_trancl1 1);
   340 ba 1;
   341 qed "reflcl_trancl";
   342 Addsimps[reflcl_trancl];
   343 
   344 goal Trancl.thy "(r^=)^+ = r^*";
   345 by (safe_tac (claset() addSaltern ("split_all_tac", split_all_tac)));
   346 by  (dtac trancl_into_rtrancl 1);
   347 by  (Asm_full_simp_tac 1);
   348 by (etac rtranclE 1);
   349 by  Safe_tac;
   350 by  (rtac r_into_trancl 1);
   351 by  (Simp_tac 1);
   352 by (rtac rtrancl_into_trancl1 1);
   353 by (etac (rtrancl_reflcl RS equalityD2 RS subsetD) 1);
   354 by (Fast_tac 1);
   355 qed "trancl_reflcl";
   356 Addsimps[trancl_reflcl];
   357 
   358 qed_goal "trancl_empty" Trancl.thy "{}^+ = {}" 
   359   (K [auto_tac (claset() addEs [trancl_induct], simpset())]);
   360 Addsimps[trancl_empty];
   361 
   362 qed_goal "rtrancl_empty" Trancl.thy "{}^* = id" 
   363   (K [rtac (reflcl_trancl RS subst) 1, Simp_tac 1]);
   364 Addsimps[rtrancl_empty];