src/HOL/Trancl.ML
author nipkow
Tue Apr 30 17:30:54 1996 +0200 (1996-04-30)
changeset 1706 4e0d5c7f57fa
parent 1642 21db0cf9a1a4
child 1746 f0c6aabc6c02
permissions -rw-r--r--
Added backwards rtrancl_induct and special versions for pairs.
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);
nipkow@1128
    23
by (fast_tac rel_cs 1);
clasohm@923
    24
qed "rtrancl_refl";
clasohm@923
    25
clasohm@923
    26
(*Closure under composition with r*)
clasohm@923
    27
val prems = goal Trancl.thy
clasohm@972
    28
    "[| (a,b) : r^*;  (b,c) : r |] ==> (a,c) : r^*";
clasohm@923
    29
by (stac rtrancl_unfold 1);
nipkow@1128
    30
by (fast_tac (rel_cs addIs prems) 1);
clasohm@923
    31
qed "rtrancl_into_rtrancl";
clasohm@923
    32
clasohm@923
    33
(*rtrancl of r contains r*)
nipkow@1301
    34
goal Trancl.thy "!!p. p : r ==> p : r^*";
paulson@1552
    35
by (split_all_tac 1);
nipkow@1301
    36
by (etac (rtrancl_refl RS rtrancl_into_rtrancl) 1);
clasohm@923
    37
qed "r_into_rtrancl";
clasohm@923
    38
clasohm@923
    39
(*monotonicity of rtrancl*)
clasohm@923
    40
goalw Trancl.thy [rtrancl_def] "!!r s. r <= s ==> r^* <= s^*";
paulson@1552
    41
by (REPEAT(ares_tac [lfp_mono,Un_mono,comp_mono,subset_refl] 1));
clasohm@923
    42
qed "rtrancl_mono";
clasohm@923
    43
clasohm@923
    44
(** standard induction rule **)
clasohm@923
    45
clasohm@923
    46
val major::prems = goal Trancl.thy 
clasohm@972
    47
  "[| (a,b) : r^*; \
clasohm@972
    48
\     !!x. P((x,x)); \
clasohm@972
    49
\     !!x y z.[| P((x,y)); (x,y): r^*; (y,z): r |]  ==>  P((x,z)) |] \
clasohm@972
    50
\  ==>  P((a,b))";
clasohm@923
    51
by (rtac ([rtrancl_def, rtrancl_fun_mono, major] MRS def_induct) 1);
nipkow@1128
    52
by (fast_tac (rel_cs addIs prems) 1);
clasohm@923
    53
qed "rtrancl_full_induct";
clasohm@923
    54
clasohm@923
    55
(*nice induction rule*)
clasohm@923
    56
val major::prems = goal Trancl.thy
clasohm@972
    57
    "[| (a::'a,b) : r^*;    \
clasohm@923
    58
\       P(a); \
clasohm@1465
    59
\       !!y z.[| (a,y) : r^*;  (y,z) : r;  P(y) |] ==> P(z) |]  \
clasohm@923
    60
\     ==> P(b)";
clasohm@923
    61
(*by induction on this formula*)
clasohm@972
    62
by (subgoal_tac "! y. (a::'a,b) = (a,y) --> P(y)" 1);
clasohm@923
    63
(*now solve first subgoal: this formula is sufficient*)
clasohm@923
    64
by (fast_tac HOL_cs 1);
clasohm@923
    65
(*now do the induction*)
clasohm@923
    66
by (resolve_tac [major RS rtrancl_full_induct] 1);
nipkow@1128
    67
by (fast_tac (rel_cs addIs prems) 1);
nipkow@1128
    68
by (fast_tac (rel_cs addIs prems) 1);
clasohm@923
    69
qed "rtrancl_induct";
clasohm@923
    70
nipkow@1706
    71
val prems = goal Trancl.thy
nipkow@1706
    72
 "[| ((a,b),(c,d)) : r^*; P a b; \
nipkow@1706
    73
\    !!x y z u.[| ((a,b),(x,y)) : r^*;  ((x,y),(z,u)) : r;  P x y |] ==> P z u\
nipkow@1706
    74
\ |] ==> P c d";
nipkow@1706
    75
by(res_inst_tac[("R","P")]splitD 1);
nipkow@1706
    76
by(res_inst_tac[("P","split P")]rtrancl_induct 1);
nipkow@1706
    77
brs prems 1;
nipkow@1706
    78
by(Simp_tac 1);
nipkow@1706
    79
brs prems 1;
nipkow@1706
    80
by(split_all_tac 1);
nipkow@1706
    81
by(Asm_full_simp_tac 1);
nipkow@1706
    82
by(REPEAT(ares_tac prems 1));
nipkow@1706
    83
qed "rtrancl_induct2";
nipkow@1706
    84
clasohm@923
    85
(*transitivity of transitive closure!! -- by induction.*)
paulson@1642
    86
goalw Trancl.thy [trans_def] "trans(r^*)";
paulson@1642
    87
by (safe_tac HOL_cs);
paulson@1642
    88
by (eres_inst_tac [("b","z")] rtrancl_induct 1);
paulson@1552
    89
by (ALLGOALS(fast_tac (HOL_cs addIs [rtrancl_into_rtrancl])));
paulson@1642
    90
qed "trans_rtrancl";
paulson@1642
    91
paulson@1642
    92
bind_thm ("rtrancl_trans", trans_rtrancl RS transD);
paulson@1642
    93
clasohm@923
    94
clasohm@923
    95
(*elimination of rtrancl -- by induction on a special formula*)
clasohm@923
    96
val major::prems = goal Trancl.thy
clasohm@1465
    97
    "[| (a::'a,b) : r^*;  (a = b) ==> P;        \
clasohm@1465
    98
\       !!y.[| (a,y) : r^*; (y,b) : r |] ==> P  \
clasohm@923
    99
\    |] ==> P";
clasohm@972
   100
by (subgoal_tac "(a::'a) = b  | (? y. (a,y) : r^* & (y,b) : r)" 1);
clasohm@923
   101
by (rtac (major RS rtrancl_induct) 2);
clasohm@923
   102
by (fast_tac (set_cs addIs prems) 2);
clasohm@923
   103
by (fast_tac (set_cs addIs prems) 2);
clasohm@923
   104
by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1));
clasohm@923
   105
qed "rtranclE";
clasohm@923
   106
paulson@1642
   107
bind_thm ("rtrancl_into_rtrancl2", r_into_rtrancl RS rtrancl_trans);
paulson@1642
   108
paulson@1642
   109
paulson@1642
   110
(*** More r^* equations and inclusions ***)
paulson@1642
   111
paulson@1642
   112
goal Trancl.thy "(r^*)^* = r^*";
paulson@1642
   113
by (rtac set_ext 1);
paulson@1642
   114
by (res_inst_tac [("p","x")] PairE 1);
paulson@1642
   115
by (hyp_subst_tac 1);
paulson@1642
   116
by (rtac iffI 1);
paulson@1552
   117
by (etac rtrancl_induct 1);
paulson@1642
   118
by (rtac rtrancl_refl 1);
paulson@1642
   119
by (fast_tac (HOL_cs addEs [rtrancl_trans]) 1);
paulson@1642
   120
by (etac r_into_rtrancl 1);
paulson@1642
   121
qed "rtrancl_idemp";
paulson@1642
   122
Addsimps [rtrancl_idemp];
paulson@1642
   123
paulson@1642
   124
goal Trancl.thy "!!r s. r <= s^* ==> r^* <= s^*";
paulson@1642
   125
bd rtrancl_mono 1;
paulson@1642
   126
by (Asm_full_simp_tac 1);
paulson@1642
   127
qed "rtrancl_subset_rtrancl";
paulson@1642
   128
paulson@1642
   129
goal Trancl.thy "!!R. [| R <= S; S <= R^* |] ==> S^* = R^*";
paulson@1642
   130
by (dtac rtrancl_mono 1);
paulson@1642
   131
by (dtac rtrancl_mono 1);
paulson@1642
   132
by (Asm_full_simp_tac 1);
paulson@1642
   133
by (fast_tac eq_cs 1);
paulson@1642
   134
qed "rtrancl_subset";
paulson@1642
   135
paulson@1642
   136
goal Trancl.thy "!!R. (R^* Un S^*)^* = (R Un S)^*";
paulson@1642
   137
by (best_tac (set_cs addIs [rtrancl_subset,r_into_rtrancl,
paulson@1642
   138
                           rtrancl_mono RS subsetD]) 1);
paulson@1642
   139
qed "rtrancl_Un_rtrancl";
nipkow@1496
   140
paulson@1642
   141
goal Trancl.thy "(R^=)^* = R^*";
paulson@1642
   142
by (fast_tac (rel_cs addIs [rtrancl_refl,rtrancl_subset,r_into_rtrancl]) 1);
paulson@1642
   143
qed "rtrancl_reflcl";
paulson@1642
   144
Addsimps [rtrancl_reflcl];
paulson@1642
   145
paulson@1642
   146
goal Trancl.thy "!!r. (x,y) : (converse r)^* ==> (x,y) : converse(r^*)";
paulson@1642
   147
by (rtac converseI 1);
paulson@1642
   148
by (etac rtrancl_induct 1);
paulson@1642
   149
by (rtac rtrancl_refl 1);
paulson@1642
   150
by (fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1);
paulson@1642
   151
qed "rtrancl_converseD";
paulson@1642
   152
paulson@1642
   153
goal Trancl.thy "!!r. (x,y) : converse(r^*) ==> (x,y) : (converse r)^*";
paulson@1642
   154
by (dtac converseD 1);
paulson@1642
   155
by (etac rtrancl_induct 1);
paulson@1642
   156
by (rtac rtrancl_refl 1);
paulson@1642
   157
by (fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1);
paulson@1642
   158
qed "rtrancl_converseI";
paulson@1642
   159
paulson@1642
   160
goal Trancl.thy "(converse r)^* = converse(r^*)";
paulson@1642
   161
by (safe_tac (rel_eq_cs addSIs [rtrancl_converseI]));
paulson@1642
   162
by (res_inst_tac [("p","x")] PairE 1);
paulson@1642
   163
by (hyp_subst_tac 1);
paulson@1642
   164
by (etac rtrancl_converseD 1);
paulson@1642
   165
qed "rtrancl_converse";
paulson@1642
   166
nipkow@1706
   167
val major::prems = goal Trancl.thy
nipkow@1706
   168
    "[| (a,b) : r^*; P(b); \
nipkow@1706
   169
\       !!y z.[| (y,z) : r;  (z,b) : r^*;  P(z) |] ==> P(y) |]  \
nipkow@1706
   170
\     ==> P(a)";
nipkow@1706
   171
br ((major RS converseI RS rtrancl_converseI) RS rtrancl_induct) 1;
nipkow@1706
   172
 brs prems 1;
nipkow@1706
   173
by(fast_tac (HOL_cs addIs prems addSEs[converseD]addSDs[rtrancl_converseD])1);
nipkow@1706
   174
qed "converse_rtrancl_induct";
nipkow@1706
   175
nipkow@1706
   176
val prems = goal Trancl.thy
nipkow@1706
   177
 "[| ((a,b),(c,d)) : r^*; P c d; \
nipkow@1706
   178
\    !!x y z u.[| ((x,y),(z,u)) : r;  ((z,u),(c,d)) : r^*;  P z u |] ==> P x y\
nipkow@1706
   179
\ |] ==> P a b";
nipkow@1706
   180
by(res_inst_tac[("R","P")]splitD 1);
nipkow@1706
   181
by(res_inst_tac[("P","split P")]converse_rtrancl_induct 1);
nipkow@1706
   182
brs prems 1;
nipkow@1706
   183
by(Simp_tac 1);
nipkow@1706
   184
brs prems 1;
nipkow@1706
   185
by(split_all_tac 1);
nipkow@1706
   186
by(Asm_full_simp_tac 1);
nipkow@1706
   187
by(REPEAT(ares_tac prems 1));
nipkow@1706
   188
qed "converse_rtrancl_induct2";
nipkow@1496
   189
clasohm@923
   190
clasohm@923
   191
(**** The relation trancl ****)
clasohm@923
   192
clasohm@923
   193
(** Conversions between trancl and rtrancl **)
clasohm@923
   194
clasohm@923
   195
val [major] = goalw Trancl.thy [trancl_def]
clasohm@972
   196
    "(a,b) : r^+ ==> (a,b) : r^*";
clasohm@923
   197
by (resolve_tac [major RS compEpair] 1);
clasohm@923
   198
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
clasohm@923
   199
qed "trancl_into_rtrancl";
clasohm@923
   200
clasohm@923
   201
(*r^+ contains r*)
clasohm@923
   202
val [prem] = goalw Trancl.thy [trancl_def]
clasohm@972
   203
   "[| (a,b) : r |] ==> (a,b) : r^+";
clasohm@923
   204
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1));
clasohm@923
   205
qed "r_into_trancl";
clasohm@923
   206
clasohm@923
   207
(*intro rule by definition: from rtrancl and r*)
clasohm@923
   208
val prems = goalw Trancl.thy [trancl_def]
clasohm@972
   209
    "[| (a,b) : r^*;  (b,c) : r |]   ==>  (a,c) : r^+";
clasohm@923
   210
by (REPEAT (resolve_tac ([compI]@prems) 1));
clasohm@923
   211
qed "rtrancl_into_trancl1";
clasohm@923
   212
clasohm@923
   213
(*intro rule from r and rtrancl*)
clasohm@923
   214
val prems = goal Trancl.thy
clasohm@972
   215
    "[| (a,b) : r;  (b,c) : r^* |]   ==>  (a,c) : r^+";
clasohm@923
   216
by (resolve_tac (prems RL [rtranclE]) 1);
clasohm@923
   217
by (etac subst 1);
clasohm@923
   218
by (resolve_tac (prems RL [r_into_trancl]) 1);
nipkow@1122
   219
by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1);
clasohm@923
   220
by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1));
clasohm@923
   221
qed "rtrancl_into_trancl2";
clasohm@923
   222
paulson@1642
   223
(*Nice induction rule for trancl*)
paulson@1642
   224
val major::prems = goal Trancl.thy
paulson@1642
   225
  "[| (a,b) : r^+;                                      \
paulson@1642
   226
\     !!y.  [| (a,y) : r |] ==> P(y);                   \
paulson@1642
   227
\     !!y z.[| (a,y) : r^+;  (y,z) : r;  P(y) |] ==> P(z)       \
paulson@1642
   228
\  |] ==> P(b)";
paulson@1642
   229
by (rtac (rewrite_rule [trancl_def] major  RS  compEpair) 1);
paulson@1642
   230
(*by induction on this formula*)
paulson@1642
   231
by (subgoal_tac "ALL z. (y,z) : r --> P(z)" 1);
paulson@1642
   232
(*now solve first subgoal: this formula is sufficient*)
paulson@1642
   233
by (fast_tac HOL_cs 1);
paulson@1642
   234
by (etac rtrancl_induct 1);
paulson@1642
   235
by (ALLGOALS (fast_tac (set_cs addIs (rtrancl_into_trancl1::prems))));
paulson@1642
   236
qed "trancl_induct";
paulson@1642
   237
clasohm@923
   238
(*elimination of r^+ -- NOT an induction rule*)
clasohm@923
   239
val major::prems = goal Trancl.thy
clasohm@972
   240
    "[| (a::'a,b) : r^+;  \
clasohm@972
   241
\       (a,b) : r ==> P; \
clasohm@1465
   242
\       !!y.[| (a,y) : r^+;  (y,b) : r |] ==> P  \
clasohm@923
   243
\    |] ==> P";
clasohm@972
   244
by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+  &  (y,b) : r)" 1);
clasohm@923
   245
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1));
clasohm@923
   246
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
clasohm@923
   247
by (etac rtranclE 1);
nipkow@1128
   248
by (fast_tac rel_cs 1);
nipkow@1128
   249
by (fast_tac (rel_cs addSIs [rtrancl_into_trancl1]) 1);
clasohm@923
   250
qed "tranclE";
clasohm@923
   251
clasohm@923
   252
(*Transitivity of r^+.
clasohm@923
   253
  Proved by unfolding since it uses transitivity of rtrancl. *)
clasohm@923
   254
goalw Trancl.thy [trancl_def] "trans(r^+)";
clasohm@923
   255
by (rtac transI 1);
clasohm@923
   256
by (REPEAT (etac compEpair 1));
nipkow@1122
   257
by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1);
clasohm@923
   258
by (REPEAT (assume_tac 1));
clasohm@923
   259
qed "trans_trancl";
clasohm@923
   260
paulson@1642
   261
bind_thm ("trancl_trans", trans_trancl RS transD);
paulson@1642
   262
clasohm@923
   263
val prems = goal Trancl.thy
clasohm@972
   264
    "[| (a,b) : r;  (b,c) : r^+ |]   ==>  (a,c) : r^+";
clasohm@923
   265
by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1);
clasohm@923
   266
by (resolve_tac prems 1);
clasohm@923
   267
by (resolve_tac prems 1);
clasohm@923
   268
qed "trancl_into_trancl2";
clasohm@923
   269
nipkow@1130
   270
clasohm@923
   271
val major::prems = goal Trancl.thy
paulson@1642
   272
    "[| (a,b) : r^*;  r <= A Times A |] ==> a=b | a:A";
clasohm@923
   273
by (cut_facts_tac prems 1);
clasohm@923
   274
by (rtac (major RS rtrancl_induct) 1);
clasohm@923
   275
by (rtac (refl RS disjI1) 1);
nipkow@1128
   276
by (fast_tac (rel_cs addSEs [SigmaE2]) 1);
paulson@1642
   277
val lemma = result();
clasohm@923
   278
clasohm@923
   279
goalw Trancl.thy [trancl_def]
paulson@1642
   280
    "!!r. r <= A Times A ==> r^+ <= A Times A";
paulson@1642
   281
by (fast_tac (rel_cs addSDs [lemma]) 1);
clasohm@923
   282
qed "trancl_subset_Sigma";
nipkow@1130
   283
nipkow@1301
   284
(* Don't add r_into_rtrancl: it messes up the proofs in Lambda *)
nipkow@1130
   285
val trancl_cs = rel_cs addIs [rtrancl_refl];
paulson@1642
   286
paulson@1642
   287