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