src/ZF/Trancl.ML
author paulson
Fri Jun 30 12:51:30 2000 +0200 (2000-06-30)
changeset 9211 6236c5285bd8
parent 8318 54d69141a17f
child 9907 473a6604da94
permissions -rw-r--r--
removal of batch-style proofs
     1 (*  Title:      ZF/trancl.ML
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1992  University of Cambridge
     5 
     6 Transitive closure of a relation
     7 *)
     8 
     9 Goal "bnd_mono(field(r)*field(r), %s. id(field(r)) Un (r O s))";
    10 by (rtac bnd_monoI 1);
    11 by (REPEAT (ares_tac [subset_refl, Un_mono, comp_mono] 2));
    12 by (Blast_tac 1);
    13 qed "rtrancl_bnd_mono";
    14 
    15 Goalw [rtrancl_def] "r<=s ==> r^* <= s^*";
    16 by (rtac lfp_mono 1);
    17 by (REPEAT (ares_tac [rtrancl_bnd_mono, subset_refl, id_mono,
    18 		      comp_mono, Un_mono, field_mono, Sigma_mono] 1));
    19 qed "rtrancl_mono";
    20 
    21 (* r^* = id(field(r)) Un ( r O r^* )    *)
    22 val rtrancl_unfold = rtrancl_bnd_mono RS (rtrancl_def RS def_lfp_Tarski);
    23 
    24 (** The relation rtrancl **)
    25 
    26 (*  r^* <= field(r) * field(r)  *)
    27 bind_thm ("rtrancl_type", rtrancl_def RS def_lfp_subset);
    28 
    29 (*Reflexivity of rtrancl*)
    30 Goal "[| a: field(r) |] ==> <a,a> : r^*";
    31 by (resolve_tac [rtrancl_unfold RS ssubst] 1);
    32 by (etac (idI RS UnI1) 1);
    33 qed "rtrancl_refl";
    34 
    35 (*Closure under composition with r  *)
    36 Goal "[| <a,b> : r^*;  <b,c> : r |] ==> <a,c> : r^*";
    37 by (resolve_tac [rtrancl_unfold RS ssubst] 1);
    38 by (rtac (compI RS UnI2) 1);
    39 by (assume_tac 1);
    40 by (assume_tac 1);
    41 qed "rtrancl_into_rtrancl";
    42 
    43 (*rtrancl of r contains all pairs in r  *)
    44 Goal "<a,b> : r ==> <a,b> : r^*";
    45 by (resolve_tac [rtrancl_refl RS rtrancl_into_rtrancl] 1);
    46 by (REPEAT (ares_tac [fieldI1] 1));
    47 qed "r_into_rtrancl";
    48 
    49 (*The premise ensures that r consists entirely of pairs*)
    50 Goal "r <= Sigma(A,B) ==> r <= r^*";
    51 by (blast_tac (claset() addIs [r_into_rtrancl]) 1);
    52 qed "r_subset_rtrancl";
    53 
    54 Goal "field(r^*) = field(r)";
    55 by (blast_tac (claset() addIs [r_into_rtrancl] 
    56                     addSDs [rtrancl_type RS subsetD]) 1);
    57 qed "rtrancl_field";
    58 
    59 
    60 (** standard induction rule **)
    61 
    62 val major::prems = Goal
    63   "[| <a,b> : r^*; \
    64 \     !!x. x: field(r) ==> P(<x,x>); \
    65 \     !!x y z.[| P(<x,y>); <x,y>: r^*; <y,z>: r |]  ==>  P(<x,z>) |] \
    66 \  ==>  P(<a,b>)";
    67 by (rtac ([rtrancl_def, rtrancl_bnd_mono, major] MRS def_induct) 1);
    68 by (blast_tac (claset() addIs prems) 1);
    69 qed "rtrancl_full_induct";
    70 
    71 (*nice induction rule.
    72   Tried adding the typing hypotheses y,z:field(r), but these
    73   caused expensive case splits!*)
    74 val major::prems = Goal
    75   "[| <a,b> : r^*;                                              \
    76 \     P(a);                                                     \
    77 \     !!y z.[| <a,y> : r^*;  <y,z> : r;  P(y) |] ==> P(z)       \
    78 \  |] ==> P(b)";
    79 (*by induction on this formula*)
    80 by (subgoal_tac "ALL y. <a,b> = <a,y> --> P(y)" 1);
    81 (*now solve first subgoal: this formula is sufficient*)
    82 by (EVERY1 [etac (spec RS mp), rtac refl]);
    83 (*now do the induction*)
    84 by (resolve_tac [major RS rtrancl_full_induct] 1);
    85 by (ALLGOALS (blast_tac (claset() addIs prems)));
    86 qed "rtrancl_induct";
    87 
    88 (*transitivity of transitive closure!! -- by induction.*)
    89 Goalw [trans_def] "trans(r^*)";
    90 by (REPEAT (resolve_tac [allI,impI] 1));
    91 by (eres_inst_tac [("b","z")] rtrancl_induct 1);
    92 by (DEPTH_SOLVE (eresolve_tac [asm_rl, rtrancl_into_rtrancl] 1));
    93 qed "trans_rtrancl";
    94 
    95 bind_thm ("rtrancl_trans", trans_rtrancl RS transD);
    96 
    97 (*elimination of rtrancl -- by induction on a special formula*)
    98 val major::prems = Goal
    99     "[| <a,b> : r^*;  (a=b) ==> P;                       \
   100 \       !!y.[| <a,y> : r^*;   <y,b> : r |] ==> P |]      \
   101 \    ==> P";
   102 by (subgoal_tac "a = b  | (EX y. <a,y> : r^* & <y,b> : r)" 1);
   103 (*see HOL/trancl*)
   104 by (rtac (major RS rtrancl_induct) 2);
   105 by (ALLGOALS (fast_tac (claset() addSEs prems)));
   106 qed "rtranclE";
   107 
   108 
   109 (**** The relation trancl ****)
   110 
   111 (*Transitivity of r^+ is proved by transitivity of r^*  *)
   112 Goalw [trans_def,trancl_def] "trans(r^+)";
   113 by (blast_tac (claset() addIs [rtrancl_into_rtrancl RS 
   114 			      (trans_rtrancl RS transD RS compI)]) 1);
   115 qed "trans_trancl";
   116 
   117 bind_thm ("trancl_trans", trans_trancl RS transD);
   118 
   119 (** Conversions between trancl and rtrancl **)
   120 
   121 Goalw [trancl_def] "<a,b> : r^+ ==> <a,b> : r^*";
   122 by (blast_tac (claset() addIs [rtrancl_into_rtrancl]) 1);
   123 qed "trancl_into_rtrancl";
   124 
   125 (*r^+ contains all pairs in r  *)
   126 Goalw [trancl_def] "<a,b> : r ==> <a,b> : r^+";
   127 by (blast_tac (claset() addSIs [rtrancl_refl]) 1);
   128 qed "r_into_trancl";
   129 
   130 (*The premise ensures that r consists entirely of pairs*)
   131 Goal "r <= Sigma(A,B) ==> r <= r^+";
   132 by (blast_tac (claset() addIs [r_into_trancl]) 1);
   133 qed "r_subset_trancl";
   134 
   135 (*intro rule by definition: from r^* and r  *)
   136 Goalw [trancl_def] "[| <a,b> : r^*;  <b,c> : r |]   ==>  <a,c> : r^+";
   137 by (Blast_tac 1);
   138 qed "rtrancl_into_trancl1";
   139 
   140 (*intro rule from r and r^*  *)
   141 val prems = goal Trancl.thy
   142     "[| <a,b> : r;  <b,c> : r^* |]   ==>  <a,c> : r^+";
   143 by (resolve_tac (prems RL [rtrancl_induct]) 1);
   144 by (resolve_tac (prems RL [r_into_trancl]) 1);
   145 by (etac trancl_trans 1);
   146 by (etac r_into_trancl 1);
   147 qed "rtrancl_into_trancl2";
   148 
   149 (*Nice induction rule for trancl*)
   150 val major::prems = Goal
   151   "[| <a,b> : r^+;                                      \
   152 \     !!y.  [| <a,y> : r |] ==> P(y);                   \
   153 \     !!y z.[| <a,y> : r^+;  <y,z> : r;  P(y) |] ==> P(z)       \
   154 \  |] ==> P(b)";
   155 by (rtac (rewrite_rule [trancl_def] major  RS  compEpair) 1);
   156 (*by induction on this formula*)
   157 by (subgoal_tac "ALL z. <y,z> : r --> P(z)" 1);
   158 (*now solve first subgoal: this formula is sufficient*)
   159 by (Blast_tac 1);
   160 by (etac rtrancl_induct 1);
   161 by (ALLGOALS (fast_tac (claset() addIs (rtrancl_into_trancl1::prems))));
   162 qed "trancl_induct";
   163 
   164 (*elimination of r^+ -- NOT an induction rule*)
   165 val major::prems = Goal
   166     "[| <a,b> : r^+;  \
   167 \       <a,b> : r ==> P; \
   168 \       !!y.[| <a,y> : r^+; <y,b> : r |] ==> P  \
   169 \    |] ==> P";
   170 by (subgoal_tac "<a,b> : r | (EX y. <a,y> : r^+  &  <y,b> : r)" 1);
   171 by (fast_tac (claset() addIs prems) 1);
   172 by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
   173 by (etac rtranclE 1);
   174 by (ALLGOALS (blast_tac (claset() addIs [rtrancl_into_trancl1])));
   175 qed "tranclE";
   176 
   177 Goalw [trancl_def] "r^+ <= field(r)*field(r)";
   178 by (blast_tac (claset() addEs [rtrancl_type RS subsetD RS SigmaE2]) 1);
   179 qed "trancl_type";
   180 
   181 Goalw [trancl_def] "r<=s ==> r^+ <= s^+";
   182 by (REPEAT (ares_tac [comp_mono, rtrancl_mono] 1));
   183 qed "trancl_mono";
   184 
   185 (** Suggested by Sidi Ould Ehmety **)
   186 
   187 Goal "(r^*)^* = r^*";
   188 by (rtac equalityI 1);
   189 by Auto_tac;
   190 by (ALLGOALS (forward_tac [impOfSubs rtrancl_type]));
   191 by (ALLGOALS Clarify_tac);
   192 by (etac r_into_rtrancl 2);
   193 by (etac rtrancl_induct 1);
   194 by (asm_full_simp_tac (simpset() addsimps [rtrancl_refl, rtrancl_field]) 1);
   195 by (blast_tac (claset() addIs [rtrancl_trans]) 1);
   196 qed "rtrancl_idemp";
   197 Addsimps [rtrancl_idemp];
   198 
   199 Goal "[| R <= S; S <= R^* |] ==> S^* = R^*";
   200 by (dtac rtrancl_mono 1);
   201 by (dtac rtrancl_mono 1);
   202 by (ALLGOALS Asm_full_simp_tac);
   203 by (Blast_tac 1);
   204 qed "rtrancl_subset";
   205 
   206 Goal "[| r<= Sigma(A,B); s<=Sigma(C,D) |] ==> (r^* Un s^*)^* = (r Un s)^*";
   207 by (rtac rtrancl_subset 1);
   208 by (blast_tac (claset() addDs [r_subset_rtrancl]) 1);
   209 by (blast_tac (claset() addIs [rtrancl_mono RS subsetD]) 1);
   210 qed "rtrancl_Un_rtrancl";
   211 
   212 (** "converse" laws by Sidi Ould Ehmety **)
   213 
   214 Goal "<x,y>:converse(r)^* ==> <x,y>:converse(r^*)";
   215 by (rtac converseI 1);
   216 by (forward_tac [rtrancl_type RS subsetD] 1);
   217 by (etac rtrancl_induct 1);
   218 by (blast_tac (claset() addIs [rtrancl_refl]) 1);
   219 by (blast_tac (claset() addIs [r_into_rtrancl,rtrancl_trans]) 1);
   220 qed "rtrancl_converseD";
   221 
   222 Goal "<x,y>:converse(r^*) ==> <x,y>:converse(r)^*";
   223 by (dtac converseD 1);
   224 by (forward_tac [rtrancl_type RS subsetD] 1);
   225 by (etac rtrancl_induct 1);
   226 by (blast_tac (claset() addIs [rtrancl_refl]) 1);
   227 by (blast_tac (claset() addIs [r_into_rtrancl,rtrancl_trans]) 1);
   228 qed "rtrancl_converseI";
   229 
   230 Goal "converse(r)^* = converse(r^*)";
   231 by (safe_tac (claset() addSIs [equalityI]));
   232 by (forward_tac [rtrancl_type RS subsetD] 1);
   233 by (safe_tac (claset() addSDs [rtrancl_converseD] addSIs [rtrancl_converseI]));
   234 qed "rtrancl_converse";