src/HOL/Trancl.ML
author wenzelm
Mon Nov 03 12:13:18 1997 +0100 (1997-11-03)
changeset 4089 96fba19bcbe2
parent 3723 034f0f5ca43f
child 4153 e534c4c32d54
permissions -rw-r--r--
isatool fixclasimp;
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);
wenzelm@4089
    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);
wenzelm@4089
    70
by (blast_tac (claset() addIs prems) 1);
wenzelm@4089
    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^*)";
wenzelm@4089
    81
by (safe_tac (claset()));
paulson@1642
    82
by (eres_inst_tac [("b","z")] rtrancl_induct 1);
wenzelm@4089
    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);
wenzelm@4089
    96
by (blast_tac (claset() addIs prems) 2);
wenzelm@4089
    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);
wenzelm@4089
   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)^*";
wenzelm@4089
   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^*";
wenzelm@4089
   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);
wenzelm@4089
   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);
wenzelm@4089
   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";
wenzelm@4089
   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);
wenzelm@4089
   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);
wenzelm@4089
   192
by (blast_tac (claset() addIs prems) 2);
wenzelm@4089
   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";
wenzelm@4089
   198
by (blast_tac (claset() addEs [rtranclE, rtranclE2] 
paulson@3723
   199
	               addIs [rtrancl_into_rtrancl, rtrancl_into_rtrancl2]) 1);
nipkow@3413
   200
qed "r_comp_rtrancl_eq";
nipkow@3413
   201
clasohm@923
   202
clasohm@923
   203
(**** The relation trancl ****)
clasohm@923
   204
nipkow@3413
   205
goalw Trancl.thy [trancl_def] "!!p.[| p:r^+; r <= s |] ==> p:s^+";
wenzelm@4089
   206
by (blast_tac (claset() addIs [rtrancl_mono RS subsetD]) 1);
nipkow@3413
   207
qed "trancl_mono";
nipkow@3413
   208
clasohm@923
   209
(** Conversions between trancl and rtrancl **)
clasohm@923
   210
clasohm@923
   211
val [major] = goalw Trancl.thy [trancl_def]
clasohm@972
   212
    "(a,b) : r^+ ==> (a,b) : r^*";
clasohm@923
   213
by (resolve_tac [major RS compEpair] 1);
clasohm@923
   214
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
clasohm@923
   215
qed "trancl_into_rtrancl";
clasohm@923
   216
clasohm@923
   217
(*r^+ contains r*)
clasohm@923
   218
val [prem] = goalw Trancl.thy [trancl_def]
clasohm@972
   219
   "[| (a,b) : r |] ==> (a,b) : r^+";
clasohm@923
   220
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1));
clasohm@923
   221
qed "r_into_trancl";
clasohm@923
   222
clasohm@923
   223
(*intro rule by definition: from rtrancl and r*)
clasohm@923
   224
val prems = goalw Trancl.thy [trancl_def]
clasohm@972
   225
    "[| (a,b) : r^*;  (b,c) : r |]   ==>  (a,c) : r^+";
clasohm@923
   226
by (REPEAT (resolve_tac ([compI]@prems) 1));
clasohm@923
   227
qed "rtrancl_into_trancl1";
clasohm@923
   228
clasohm@923
   229
(*intro rule from r and rtrancl*)
clasohm@923
   230
val prems = goal Trancl.thy
clasohm@972
   231
    "[| (a,b) : r;  (b,c) : r^* |]   ==>  (a,c) : r^+";
clasohm@923
   232
by (resolve_tac (prems RL [rtranclE]) 1);
clasohm@923
   233
by (etac subst 1);
clasohm@923
   234
by (resolve_tac (prems RL [r_into_trancl]) 1);
nipkow@1122
   235
by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1);
clasohm@923
   236
by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1));
clasohm@923
   237
qed "rtrancl_into_trancl2";
clasohm@923
   238
paulson@1642
   239
(*Nice induction rule for trancl*)
paulson@1642
   240
val major::prems = goal Trancl.thy
paulson@1642
   241
  "[| (a,b) : r^+;                                      \
paulson@1642
   242
\     !!y.  [| (a,y) : r |] ==> P(y);                   \
paulson@1642
   243
\     !!y z.[| (a,y) : r^+;  (y,z) : r;  P(y) |] ==> P(z)       \
paulson@1642
   244
\  |] ==> P(b)";
paulson@1642
   245
by (rtac (rewrite_rule [trancl_def] major  RS  compEpair) 1);
paulson@1642
   246
(*by induction on this formula*)
paulson@1642
   247
by (subgoal_tac "ALL z. (y,z) : r --> P(z)" 1);
paulson@1642
   248
(*now solve first subgoal: this formula is sufficient*)
paulson@2891
   249
by (Blast_tac 1);
paulson@1642
   250
by (etac rtrancl_induct 1);
wenzelm@4089
   251
by (ALLGOALS (blast_tac (claset() addIs (rtrancl_into_trancl1::prems))));
paulson@1642
   252
qed "trancl_induct";
paulson@1642
   253
clasohm@923
   254
(*elimination of r^+ -- NOT an induction rule*)
clasohm@923
   255
val major::prems = goal Trancl.thy
clasohm@972
   256
    "[| (a::'a,b) : r^+;  \
clasohm@972
   257
\       (a,b) : r ==> P; \
clasohm@1465
   258
\       !!y.[| (a,y) : r^+;  (y,b) : r |] ==> P  \
clasohm@923
   259
\    |] ==> P";
clasohm@972
   260
by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+  &  (y,b) : r)" 1);
clasohm@923
   261
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1));
clasohm@923
   262
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
clasohm@923
   263
by (etac rtranclE 1);
paulson@2891
   264
by (Blast_tac 1);
wenzelm@4089
   265
by (blast_tac (claset() addSIs [rtrancl_into_trancl1]) 1);
clasohm@923
   266
qed "tranclE";
clasohm@923
   267
clasohm@923
   268
(*Transitivity of r^+.
clasohm@923
   269
  Proved by unfolding since it uses transitivity of rtrancl. *)
clasohm@923
   270
goalw Trancl.thy [trancl_def] "trans(r^+)";
clasohm@923
   271
by (rtac transI 1);
clasohm@923
   272
by (REPEAT (etac compEpair 1));
nipkow@1122
   273
by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1);
clasohm@923
   274
by (REPEAT (assume_tac 1));
clasohm@923
   275
qed "trans_trancl";
clasohm@923
   276
paulson@1642
   277
bind_thm ("trancl_trans", trans_trancl RS transD);
paulson@1642
   278
nipkow@3413
   279
goalw Trancl.thy [trancl_def]
nipkow@3413
   280
  "!!r. [| (x,y):r^*; (y,z):r^+ |] ==> (x,z):r^+";
wenzelm@4089
   281
by (blast_tac (claset() addIs [rtrancl_trans,r_into_rtrancl]) 1);
nipkow@3413
   282
qed "rtrancl_trancl_trancl";
nipkow@3413
   283
clasohm@923
   284
val prems = goal Trancl.thy
clasohm@972
   285
    "[| (a,b) : r;  (b,c) : r^+ |]   ==>  (a,c) : r^+";
clasohm@923
   286
by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1);
clasohm@923
   287
by (resolve_tac prems 1);
clasohm@923
   288
by (resolve_tac prems 1);
clasohm@923
   289
qed "trancl_into_trancl2";
clasohm@923
   290
nipkow@3413
   291
(* primitive recursion for trancl over finite relations: *)
nipkow@3413
   292
goal Trancl.thy "(insert (y,x) r)^+ = r^+ Un {(a,b). (a,y):r^* & (x,b):r^*}";
paulson@3457
   293
by (rtac equalityI 1);
paulson@3457
   294
 by (rtac subsetI 1);
paulson@3457
   295
 by (split_all_tac 1);
paulson@3457
   296
 by (etac trancl_induct 1);
wenzelm@4089
   297
  by (blast_tac (claset() addIs [r_into_trancl]) 1);
wenzelm@4089
   298
 by (blast_tac (claset() addIs
nipkow@3413
   299
     [rtrancl_into_trancl1,trancl_into_rtrancl,r_into_trancl,trancl_trans]) 1);
paulson@3457
   300
by (rtac subsetI 1);
wenzelm@4089
   301
by (blast_tac (claset() addIs
nipkow@3413
   302
     [rtrancl_into_trancl2, rtrancl_trancl_trancl,
nipkow@3413
   303
      impOfSubs rtrancl_mono, trancl_mono]) 1);
nipkow@3413
   304
qed "trancl_insert";
nipkow@3413
   305
nipkow@3439
   306
goalw Trancl.thy [trancl_def] "(r^-1)^+ = (r^+)^-1";
wenzelm@4089
   307
by (simp_tac (simpset() addsimps [rtrancl_inverse,inverse_comp]) 1);
wenzelm@4089
   308
by (simp_tac (simpset() addsimps [rtrancl_inverse RS sym,r_comp_rtrancl_eq]) 1);
nipkow@3439
   309
qed "trancl_inverse";
nipkow@3413
   310
nipkow@1130
   311
clasohm@923
   312
val major::prems = goal Trancl.thy
paulson@1642
   313
    "[| (a,b) : r^*;  r <= A Times A |] ==> a=b | a:A";
clasohm@923
   314
by (cut_facts_tac prems 1);
clasohm@923
   315
by (rtac (major RS rtrancl_induct) 1);
clasohm@923
   316
by (rtac (refl RS disjI1) 1);
paulson@2891
   317
by (Blast_tac 1);
paulson@1642
   318
val lemma = result();
clasohm@923
   319
clasohm@923
   320
goalw Trancl.thy [trancl_def]
paulson@1642
   321
    "!!r. r <= A Times A ==> r^+ <= A Times A";
wenzelm@4089
   322
by (blast_tac (claset() addSDs [lemma]) 1);
clasohm@923
   323
qed "trancl_subset_Sigma";
nipkow@1130
   324