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