src/HOL/Trancl.ML
author paulson
Mon Aug 19 13:03:17 1996 +0200 (1996-08-19)
changeset 1921 56a77911efe4
parent 1786 8a31d85d27b8
child 1985 84cf16192e03
permissions -rw-r--r--
Tidied up the proofs
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);
berghofe@1760
    23
by (Fast_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@1921
    33
by (Fast_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);
berghofe@1760
    55
by (fast_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*)
berghofe@1760
    67
by (Fast_tac 1);
clasohm@923
    68
(*now do the induction*)
clasohm@923
    69
by (resolve_tac [major RS rtrancl_full_induct] 1);
berghofe@1760
    70
by (fast_tac (!claset addIs prems) 1);
berghofe@1760
    71
by (fast_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);
berghofe@1760
    83
by (ALLGOALS(fast_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);
berghofe@1760
    96
by (fast_tac (!claset addIs prems) 2);
berghofe@1760
    97
by (fast_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);
berghofe@1760
   113
by (fast_tac (!claset addEs [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@1642
   119
bd 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);
berghofe@1760
   127
by (Fast_tac 1);
paulson@1642
   128
qed "rtrancl_subset";
paulson@1642
   129
paulson@1642
   130
goal Trancl.thy "!!R. (R^* Un S^*)^* = (R Un S)^*";
nipkow@1766
   131
by (best_tac (!claset addSIs [rtrancl_subset]
nipkow@1766
   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^*";
nipkow@1766
   136
by (fast_tac (!claset addSIs [rtrancl_refl,rtrancl_subset]
nipkow@1766
   137
                      addIs  [r_into_rtrancl]) 1);
paulson@1642
   138
qed "rtrancl_reflcl";
paulson@1642
   139
Addsimps [rtrancl_reflcl];
paulson@1642
   140
paulson@1642
   141
goal Trancl.thy "!!r. (x,y) : (converse r)^* ==> (x,y) : converse(r^*)";
paulson@1642
   142
by (rtac converseI 1);
paulson@1642
   143
by (etac rtrancl_induct 1);
paulson@1642
   144
by (rtac rtrancl_refl 1);
paulson@1921
   145
by (deepen_tac (!claset addIs [r_into_rtrancl,rtrancl_trans]) 0 1);
paulson@1642
   146
qed "rtrancl_converseD";
paulson@1642
   147
paulson@1642
   148
goal Trancl.thy "!!r. (x,y) : converse(r^*) ==> (x,y) : (converse r)^*";
paulson@1642
   149
by (dtac converseD 1);
paulson@1642
   150
by (etac rtrancl_induct 1);
paulson@1642
   151
by (rtac rtrancl_refl 1);
paulson@1921
   152
by (deepen_tac (!claset addIs [r_into_rtrancl,rtrancl_trans]) 0 1);
paulson@1642
   153
qed "rtrancl_converseI";
paulson@1642
   154
paulson@1642
   155
goal Trancl.thy "(converse r)^* = converse(r^*)";
berghofe@1786
   156
by (safe_tac (!claset addSIs [rtrancl_converseI]));
paulson@1642
   157
by (res_inst_tac [("p","x")] PairE 1);
paulson@1642
   158
by (hyp_subst_tac 1);
paulson@1642
   159
by (etac rtrancl_converseD 1);
paulson@1642
   160
qed "rtrancl_converse";
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@1706
   166
br ((major RS converseI RS rtrancl_converseI) RS rtrancl_induct) 1;
paulson@1921
   167
brs prems 1;
berghofe@1760
   168
by(fast_tac (!claset addIs prems addSEs[converseD]addSDs[rtrancl_converseD])1);
nipkow@1706
   169
qed "converse_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";
nipkow@1706
   175
by(res_inst_tac[("R","P")]splitD 1);
nipkow@1706
   176
by(res_inst_tac[("P","split P")]converse_rtrancl_induct 1);
nipkow@1706
   177
brs prems 1;
nipkow@1706
   178
by(Simp_tac 1);
nipkow@1706
   179
brs prems 1;
nipkow@1706
   180
by(split_all_tac 1);
nipkow@1706
   181
by(Asm_full_simp_tac 1);
nipkow@1706
   182
by(REPEAT(ares_tac prems 1));
nipkow@1706
   183
qed "converse_rtrancl_induct2";
nipkow@1496
   184
clasohm@923
   185
clasohm@923
   186
(**** The relation trancl ****)
clasohm@923
   187
clasohm@923
   188
(** Conversions between trancl and rtrancl **)
clasohm@923
   189
clasohm@923
   190
val [major] = goalw Trancl.thy [trancl_def]
clasohm@972
   191
    "(a,b) : r^+ ==> (a,b) : r^*";
clasohm@923
   192
by (resolve_tac [major RS compEpair] 1);
clasohm@923
   193
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
clasohm@923
   194
qed "trancl_into_rtrancl";
clasohm@923
   195
clasohm@923
   196
(*r^+ contains r*)
clasohm@923
   197
val [prem] = goalw Trancl.thy [trancl_def]
clasohm@972
   198
   "[| (a,b) : r |] ==> (a,b) : r^+";
clasohm@923
   199
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1));
clasohm@923
   200
qed "r_into_trancl";
clasohm@923
   201
clasohm@923
   202
(*intro rule by definition: from rtrancl and r*)
clasohm@923
   203
val prems = goalw Trancl.thy [trancl_def]
clasohm@972
   204
    "[| (a,b) : r^*;  (b,c) : r |]   ==>  (a,c) : r^+";
clasohm@923
   205
by (REPEAT (resolve_tac ([compI]@prems) 1));
clasohm@923
   206
qed "rtrancl_into_trancl1";
clasohm@923
   207
clasohm@923
   208
(*intro rule from r and rtrancl*)
clasohm@923
   209
val prems = goal Trancl.thy
clasohm@972
   210
    "[| (a,b) : r;  (b,c) : r^* |]   ==>  (a,c) : r^+";
clasohm@923
   211
by (resolve_tac (prems RL [rtranclE]) 1);
clasohm@923
   212
by (etac subst 1);
clasohm@923
   213
by (resolve_tac (prems RL [r_into_trancl]) 1);
nipkow@1122
   214
by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1);
clasohm@923
   215
by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1));
clasohm@923
   216
qed "rtrancl_into_trancl2";
clasohm@923
   217
paulson@1642
   218
(*Nice induction rule for trancl*)
paulson@1642
   219
val major::prems = goal Trancl.thy
paulson@1642
   220
  "[| (a,b) : r^+;                                      \
paulson@1642
   221
\     !!y.  [| (a,y) : r |] ==> P(y);                   \
paulson@1642
   222
\     !!y z.[| (a,y) : r^+;  (y,z) : r;  P(y) |] ==> P(z)       \
paulson@1642
   223
\  |] ==> P(b)";
paulson@1642
   224
by (rtac (rewrite_rule [trancl_def] major  RS  compEpair) 1);
paulson@1642
   225
(*by induction on this formula*)
paulson@1642
   226
by (subgoal_tac "ALL z. (y,z) : r --> P(z)" 1);
paulson@1642
   227
(*now solve first subgoal: this formula is sufficient*)
berghofe@1760
   228
by (Fast_tac 1);
paulson@1642
   229
by (etac rtrancl_induct 1);
berghofe@1760
   230
by (ALLGOALS (fast_tac (!claset addIs (rtrancl_into_trancl1::prems))));
paulson@1642
   231
qed "trancl_induct";
paulson@1642
   232
clasohm@923
   233
(*elimination of r^+ -- NOT an induction rule*)
clasohm@923
   234
val major::prems = goal Trancl.thy
clasohm@972
   235
    "[| (a::'a,b) : r^+;  \
clasohm@972
   236
\       (a,b) : r ==> P; \
clasohm@1465
   237
\       !!y.[| (a,y) : r^+;  (y,b) : r |] ==> P  \
clasohm@923
   238
\    |] ==> P";
clasohm@972
   239
by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+  &  (y,b) : r)" 1);
clasohm@923
   240
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1));
clasohm@923
   241
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
clasohm@923
   242
by (etac rtranclE 1);
berghofe@1760
   243
by (Fast_tac 1);
berghofe@1760
   244
by (fast_tac (!claset addSIs [rtrancl_into_trancl1]) 1);
clasohm@923
   245
qed "tranclE";
clasohm@923
   246
clasohm@923
   247
(*Transitivity of r^+.
clasohm@923
   248
  Proved by unfolding since it uses transitivity of rtrancl. *)
clasohm@923
   249
goalw Trancl.thy [trancl_def] "trans(r^+)";
clasohm@923
   250
by (rtac transI 1);
clasohm@923
   251
by (REPEAT (etac compEpair 1));
nipkow@1122
   252
by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1);
clasohm@923
   253
by (REPEAT (assume_tac 1));
clasohm@923
   254
qed "trans_trancl";
clasohm@923
   255
paulson@1642
   256
bind_thm ("trancl_trans", trans_trancl RS transD);
paulson@1642
   257
clasohm@923
   258
val prems = goal Trancl.thy
clasohm@972
   259
    "[| (a,b) : r;  (b,c) : r^+ |]   ==>  (a,c) : r^+";
clasohm@923
   260
by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1);
clasohm@923
   261
by (resolve_tac prems 1);
clasohm@923
   262
by (resolve_tac prems 1);
clasohm@923
   263
qed "trancl_into_trancl2";
clasohm@923
   264
nipkow@1130
   265
clasohm@923
   266
val major::prems = goal Trancl.thy
paulson@1642
   267
    "[| (a,b) : r^*;  r <= A Times A |] ==> a=b | a:A";
clasohm@923
   268
by (cut_facts_tac prems 1);
clasohm@923
   269
by (rtac (major RS rtrancl_induct) 1);
clasohm@923
   270
by (rtac (refl RS disjI1) 1);
berghofe@1760
   271
by (fast_tac (!claset addSEs [SigmaE2]) 1);
paulson@1642
   272
val lemma = result();
clasohm@923
   273
clasohm@923
   274
goalw Trancl.thy [trancl_def]
paulson@1642
   275
    "!!r. r <= A Times A ==> r^+ <= A Times A";
berghofe@1760
   276
by (fast_tac (!claset addSDs [lemma]) 1);
clasohm@923
   277
qed "trancl_subset_Sigma";
nipkow@1130
   278
nipkow@1301
   279
(* Don't add r_into_rtrancl: it messes up the proofs in Lambda *)
nipkow@1130
   280
val trancl_cs = rel_cs addIs [rtrancl_refl];
paulson@1642
   281