src/HOL/Trancl.ML
author wenzelm
Thu Mar 11 13:20:35 1999 +0100 (1999-03-11)
changeset 6349 f7750d816c21
parent 6162 484adda70b65
child 6856 0364007b4bb3
permissions -rw-r--r--
removed foo_build_completed -- now handled by session management (via usedir);
     1 (*  Title:      HOL/Trancl
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1992  University of Cambridge
     5 
     6 Theorems about the transitive closure of a relation
     7 *)
     8 
     9 (** The relation rtrancl **)
    10 
    11 section "^*";
    12 
    13 Goal "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 "(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 "[| (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 "!!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 [rtrancl_def] "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 
    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
    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 ("rtrancl_induct2", split_rule
    75   (read_instantiate [("a","(ax,ay)"), ("b","(bx,by)")] rtrancl_induct));
    76 
    77 (*transitivity of transitive closure!! -- by induction.*)
    78 Goalw [trans_def] "trans(r^*)";
    79 by Safe_tac;
    80 by (eres_inst_tac [("b","z")] rtrancl_induct 1);
    81 by (ALLGOALS(blast_tac (claset() addIs [rtrancl_into_rtrancl])));
    82 qed "trans_rtrancl";
    83 
    84 bind_thm ("rtrancl_trans", trans_rtrancl RS transD);
    85 
    86 
    87 (*elimination of rtrancl -- by induction on a special formula*)
    88 val major::prems = Goal
    89     "[| (a::'a,b) : r^*;  (a = b) ==> P;        \
    90 \       !!y.[| (a,y) : r^*; (y,b) : r |] ==> P  \
    91 \    |] ==> P";
    92 by (subgoal_tac "(a::'a) = b  | (? y. (a,y) : r^* & (y,b) : r)" 1);
    93 by (rtac (major RS rtrancl_induct) 2);
    94 by (blast_tac (claset() addIs prems) 2);
    95 by (blast_tac (claset() addIs prems) 2);
    96 by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1));
    97 qed "rtranclE";
    98 
    99 bind_thm ("rtrancl_into_rtrancl2", r_into_rtrancl RS rtrancl_trans);
   100 
   101 
   102 (*** More r^* equations and inclusions ***)
   103 
   104 Goal "(r^*)^* = r^*";
   105 by (rtac set_ext 1);
   106 by (res_inst_tac [("p","x")] PairE 1);
   107 by (hyp_subst_tac 1);
   108 by (rtac iffI 1);
   109 by (etac rtrancl_induct 1);
   110 by (rtac rtrancl_refl 1);
   111 by (blast_tac (claset() addIs [rtrancl_trans]) 1);
   112 by (etac r_into_rtrancl 1);
   113 qed "rtrancl_idemp";
   114 Addsimps [rtrancl_idemp];
   115 
   116 Goal "R^* O R^* = R^*";
   117 by (rtac set_ext 1);
   118 by (split_all_tac 1);
   119 by (blast_tac (claset() addIs [rtrancl_trans]) 1);
   120 qed "rtrancl_idemp_self_comp";
   121 Addsimps [rtrancl_idemp_self_comp];
   122 
   123 Goal "r <= s^* ==> r^* <= s^*";
   124 by (dtac rtrancl_mono 1);
   125 by (Asm_full_simp_tac 1);
   126 qed "rtrancl_subset_rtrancl";
   127 
   128 Goal "[| R <= S; S <= R^* |] ==> S^* = R^*";
   129 by (dtac rtrancl_mono 1);
   130 by (dtac rtrancl_mono 1);
   131 by (Asm_full_simp_tac 1);
   132 by (Blast_tac 1);
   133 qed "rtrancl_subset";
   134 
   135 Goal "(R^* Un S^*)^* = (R Un S)^*";
   136 by (blast_tac (claset() addSIs [rtrancl_subset]
   137                         addIs [r_into_rtrancl, rtrancl_mono RS subsetD]) 1);
   138 qed "rtrancl_Un_rtrancl";
   139 
   140 Goal "(R^=)^* = R^*";
   141 by (blast_tac (claset() addSIs [rtrancl_subset] addIs [r_into_rtrancl]) 1);
   142 qed "rtrancl_reflcl";
   143 Addsimps [rtrancl_reflcl];
   144 
   145 Goal "(x,y) : (r^-1)^* ==> (x,y) : (r^*)^-1";
   146 by (rtac converseI 1);
   147 by (etac rtrancl_induct 1);
   148 by (rtac rtrancl_refl 1);
   149 by (blast_tac (claset() addIs [r_into_rtrancl,rtrancl_trans]) 1);
   150 qed "rtrancl_converseD";
   151 
   152 Goal "(x,y) : (r^*)^-1 ==> (x,y) : (r^-1)^*";
   153 by (dtac converseD 1);
   154 by (etac rtrancl_induct 1);
   155 by (rtac rtrancl_refl 1);
   156 by (blast_tac (claset() addIs [r_into_rtrancl,rtrancl_trans]) 1);
   157 qed "rtrancl_converseI";
   158 
   159 Goal "(r^-1)^* = (r^*)^-1";
   160 by (safe_tac (claset() addSDs [rtrancl_converseD] addSIs [rtrancl_converseI]));
   161 qed "rtrancl_converse";
   162 
   163 val major::prems = Goal
   164     "[| (a,b) : r^*; P(b); \
   165 \       !!y z.[| (y,z) : r;  (z,b) : r^*;  P(z) |] ==> P(y) |]  \
   166 \     ==> P(a)";
   167 by (rtac ((major RS converseI RS rtrancl_converseI) RS rtrancl_induct) 1);
   168 by (resolve_tac prems 1);
   169 by (blast_tac (claset() addIs prems addSDs[rtrancl_converseD])1);
   170 qed "converse_rtrancl_induct";
   171 
   172 bind_thm ("converse_rtrancl_induct2", split_rule
   173   (read_instantiate [("a","(ax,ay)"),("b","(bx,by)")]converse_rtrancl_induct));
   174 
   175 val major::prems = Goal
   176  "[| (x,z):r^*; \
   177 \    x=z ==> P; \
   178 \    !!y. [| (x,y):r; (y,z):r^* |] ==> P \
   179 \ |] ==> P";
   180 by (subgoal_tac "x = z  | (? y. (x,y) : r & (y,z) : r^*)" 1);
   181 by (rtac (major RS converse_rtrancl_induct) 2);
   182 by (blast_tac (claset() addIs prems) 2);
   183 by (blast_tac (claset() addIs prems) 2);
   184 by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1));
   185 qed "converse_rtranclE";
   186 
   187 bind_thm ("converse_rtranclE2", split_rule
   188   (read_instantiate [("x","(xa,xb)"), ("z","(za,zb)")] converse_rtranclE));
   189 
   190 Goal "r O r^* = r^* O r";
   191 by (blast_tac (claset() addEs [rtranclE, converse_rtranclE] 
   192 	               addIs [rtrancl_into_rtrancl, rtrancl_into_rtrancl2]) 1);
   193 qed "r_comp_rtrancl_eq";
   194 
   195 
   196 (**** The relation trancl ****)
   197 
   198 section "^+";
   199 
   200 Goalw [trancl_def] "[| p:r^+; r <= s |] ==> p:s^+";
   201 by (blast_tac (claset() addIs [rtrancl_mono RS subsetD]) 1);
   202 qed "trancl_mono";
   203 
   204 (** Conversions between trancl and rtrancl **)
   205 
   206 Goalw [trancl_def]
   207     "!!p. p : r^+ ==> p : r^*";
   208 by (split_all_tac 1);
   209 by (etac compEpair 1);
   210 by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
   211 qed "trancl_into_rtrancl";
   212 
   213 (*r^+ contains r*)
   214 Goalw [trancl_def]
   215    "!!p. p : r ==> p : r^+";
   216 by (split_all_tac 1);
   217 by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1));
   218 qed "r_into_trancl";
   219 
   220 (*intro rule by definition: from rtrancl and r*)
   221 Goalw [trancl_def] "[| (a,b) : r^*;  (b,c) : r |]   ==>  (a,c) : r^+";
   222 by Auto_tac;
   223 qed "rtrancl_into_trancl1";
   224 
   225 (*intro rule from r and rtrancl*)
   226 Goal "[| (a,b) : r;  (b,c) : r^* |]   ==>  (a,c) : r^+";
   227 by (etac rtranclE 1);
   228 by (blast_tac (claset() addIs [r_into_trancl]) 1);
   229 by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1);
   230 by (REPEAT (ares_tac [r_into_rtrancl] 1));
   231 qed "rtrancl_into_trancl2";
   232 
   233 (*Nice induction rule for trancl*)
   234 val major::prems = Goal
   235   "[| (a,b) : r^+;                                      \
   236 \     !!y.  [| (a,y) : r |] ==> P(y);                   \
   237 \     !!y z.[| (a,y) : r^+;  (y,z) : r;  P(y) |] ==> P(z)       \
   238 \  |] ==> P(b)";
   239 by (rtac (rewrite_rule [trancl_def] major  RS  compEpair) 1);
   240 (*by induction on this formula*)
   241 by (subgoal_tac "ALL z. (y,z) : r --> P(z)" 1);
   242 (*now solve first subgoal: this formula is sufficient*)
   243 by (Blast_tac 1);
   244 by (etac rtrancl_induct 1);
   245 by (ALLGOALS (blast_tac (claset() addIs (rtrancl_into_trancl1::prems))));
   246 qed "trancl_induct";
   247 
   248 (*elimination of r^+ -- NOT an induction rule*)
   249 val major::prems = Goal
   250     "[| (a::'a,b) : r^+;  \
   251 \       (a,b) : r ==> P; \
   252 \       !!y.[| (a,y) : r^+;  (y,b) : r |] ==> P  \
   253 \    |] ==> P";
   254 by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+  &  (y,b) : r)" 1);
   255 by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1));
   256 by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
   257 by (etac rtranclE 1);
   258 by (Blast_tac 1);
   259 by (blast_tac (claset() addSIs [rtrancl_into_trancl1]) 1);
   260 qed "tranclE";
   261 
   262 (*Transitivity of r^+.
   263   Proved by unfolding since it uses transitivity of rtrancl. *)
   264 Goalw [trancl_def] "trans(r^+)";
   265 by (rtac transI 1);
   266 by (REPEAT (etac compEpair 1));
   267 by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1);
   268 by (REPEAT (assume_tac 1));
   269 qed "trans_trancl";
   270 
   271 bind_thm ("trancl_trans", trans_trancl RS transD);
   272 
   273 Goalw [trancl_def] "[| (x,y):r^*; (y,z):r^+ |] ==> (x,z):r^+";
   274 by (blast_tac (claset() addIs [rtrancl_trans,r_into_rtrancl]) 1);
   275 qed "rtrancl_trancl_trancl";
   276 
   277 (* "[| (a,b) : r;  (b,c) : r^+ |]   ==>  (a,c) : r^+" *)
   278 bind_thm ("trancl_into_trancl2", [trans_trancl, r_into_trancl] MRS transD);
   279 
   280 (* primitive recursion for trancl over finite relations: *)
   281 Goal "(insert (y,x) r)^+ = r^+ Un {(a,b). (a,y):r^* & (x,b):r^*}";
   282 by (rtac equalityI 1);
   283  by (rtac subsetI 1);
   284  by (split_all_tac 1);
   285  by (etac trancl_induct 1);
   286   by (blast_tac (claset() addIs [r_into_trancl]) 1);
   287  by (blast_tac (claset() addIs
   288      [rtrancl_into_trancl1,trancl_into_rtrancl,r_into_trancl,trancl_trans]) 1);
   289 by (rtac subsetI 1);
   290 by (blast_tac (claset() addIs
   291      [rtrancl_into_trancl2, rtrancl_trancl_trancl,
   292       impOfSubs rtrancl_mono, trancl_mono]) 1);
   293 qed "trancl_insert";
   294 
   295 Goalw [trancl_def] "(r^-1)^+ = (r^+)^-1";
   296 by (simp_tac (simpset() addsimps [rtrancl_converse,converse_comp]) 1);
   297 by (simp_tac (simpset() addsimps [rtrancl_converse RS sym,
   298 				  r_comp_rtrancl_eq]) 1);
   299 qed "trancl_converse";
   300 
   301 Goal "(x,y) : (r^+)^-1 ==> (x,y) : (r^-1)^+";
   302 by (asm_full_simp_tac (simpset() addsimps [trancl_converse]) 1);
   303 qed "trancl_converseI";
   304 
   305 Goal "(x,y) : (r^-1)^+ ==> (x,y) : (r^+)^-1";
   306 by (asm_full_simp_tac (simpset() addsimps [trancl_converse]) 1);
   307 qed "trancl_converseD";
   308 
   309 val major::prems = Goal
   310     "[| (a,b) : r^+; !!y. (y,b) : r ==> P(y); \
   311 \       !!y z.[| (y,z) : r;  (z,b) : r^+;  P(z) |] ==> P(y) |]  \
   312 \     ==> P(a)";
   313 by (rtac ((major RS converseI RS trancl_converseI) RS trancl_induct) 1);
   314  by (resolve_tac prems 1);
   315  by (etac converseD 1);
   316 by (blast_tac (claset() addIs prems addSDs [trancl_converseD])1);
   317 qed "converse_trancl_induct";
   318 
   319 (*Unused*)
   320 qed_goal "irrefl_tranclI" Trancl.thy 
   321    "!!r. r^-1 Int r^+ = {} ==> (x, x) ~: r^+" 
   322  (K [subgoal_tac "!y. (x, y) : r^+ --> x~=y" 1,
   323      Fast_tac 1,
   324      strip_tac 1,
   325      etac trancl_induct 1,
   326      auto_tac (claset() addIs [r_into_trancl], simpset())]);
   327 
   328 Goal "[| (a,b) : r^*;  r <= A Times A |] ==> a=b | a:A";
   329 by (etac rtrancl_induct 1);
   330 by Auto_tac;
   331 val lemma = result();
   332 
   333 Goalw [trancl_def] "r <= A Times A ==> r^+ <= A Times A";
   334 by (blast_tac (claset() addSDs [lemma]) 1);
   335 qed "trancl_subset_Sigma";
   336 
   337 
   338 Goal "(r^+)^= = r^*";
   339 by Safe_tac;
   340 by  (etac trancl_into_rtrancl 1);
   341 by (etac rtranclE 1);
   342 by  (Auto_tac );
   343 by (etac rtrancl_into_trancl1 1);
   344 by (assume_tac 1);
   345 qed "reflcl_trancl";
   346 Addsimps[reflcl_trancl];
   347 
   348 Goal "(r^=)^+ = r^*";
   349 by Safe_tac;
   350 by  (dtac trancl_into_rtrancl 1);
   351 by  (Asm_full_simp_tac 1);
   352 by (etac rtranclE 1);
   353 by  Safe_tac;
   354 by  (rtac r_into_trancl 1);
   355 by  (Simp_tac 1);
   356 by (rtac rtrancl_into_trancl1 1);
   357 by (etac (rtrancl_reflcl RS equalityD2 RS subsetD) 1);
   358 by (Fast_tac 1);
   359 qed "trancl_reflcl";
   360 Addsimps[trancl_reflcl];
   361 
   362 qed_goal "trancl_empty" Trancl.thy "{}^+ = {}" 
   363   (K [auto_tac (claset() addEs [trancl_induct], simpset())]);
   364 Addsimps[trancl_empty];
   365 
   366 qed_goal "rtrancl_empty" Trancl.thy "{}^* = Id" 
   367   (K [rtac (reflcl_trancl RS subst) 1, Simp_tac 1]);
   368 Addsimps[rtrancl_empty];