src/HOL/Trancl.ML
author paulson
Wed Mar 06 12:52:11 1996 +0100 (1996-03-06)
changeset 1552 6f71b5d46700
parent 1496 c443b2adaf52
child 1642 21db0cf9a1a4
permissions -rw-r--r--
Ran expandshort
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
clasohm@923
    71
(*transitivity of transitive closure!! -- by induction.*)
nipkow@1122
    72
goal Trancl.thy "!!r. [| (a,b):r^*; (b,c):r^* |] ==> (a,c):r^*";
nipkow@1122
    73
by (eres_inst_tac [("b","c")] rtrancl_induct 1);
paulson@1552
    74
by (ALLGOALS(fast_tac (HOL_cs addIs [rtrancl_into_rtrancl])));
nipkow@1122
    75
qed "rtrancl_trans";
clasohm@923
    76
clasohm@923
    77
(*elimination of rtrancl -- by induction on a special formula*)
clasohm@923
    78
val major::prems = goal Trancl.thy
clasohm@1465
    79
    "[| (a::'a,b) : r^*;  (a = b) ==> P;        \
clasohm@1465
    80
\       !!y.[| (a,y) : r^*; (y,b) : r |] ==> P  \
clasohm@923
    81
\    |] ==> P";
clasohm@972
    82
by (subgoal_tac "(a::'a) = b  | (? y. (a,y) : r^* & (y,b) : r)" 1);
clasohm@923
    83
by (rtac (major RS rtrancl_induct) 2);
clasohm@923
    84
by (fast_tac (set_cs addIs prems) 2);
clasohm@923
    85
by (fast_tac (set_cs addIs prems) 2);
clasohm@923
    86
by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1));
clasohm@923
    87
qed "rtranclE";
clasohm@923
    88
nipkow@1496
    89
goal Trancl.thy "!!R. (y,z):R^* ==> !x. (x,y):R --> (x,z):R^*";
paulson@1552
    90
by (etac rtrancl_induct 1);
paulson@1552
    91
by (fast_tac (HOL_cs addIs [r_into_rtrancl]) 1);
paulson@1552
    92
by (fast_tac (HOL_cs addEs [rtrancl_into_rtrancl]) 1);
nipkow@1496
    93
val lemma = result();
nipkow@1496
    94
nipkow@1496
    95
goal Trancl.thy  "!!R. [| (x,y) : R;  (y,z) : R^* |] ==> (x,z) : R^*";
paulson@1552
    96
by (fast_tac (HOL_cs addDs [lemma]) 1);
nipkow@1496
    97
qed "rtrancl_into_rtrancl2";
nipkow@1496
    98
clasohm@923
    99
clasohm@923
   100
(**** The relation trancl ****)
clasohm@923
   101
clasohm@923
   102
(** Conversions between trancl and rtrancl **)
clasohm@923
   103
clasohm@923
   104
val [major] = goalw Trancl.thy [trancl_def]
clasohm@972
   105
    "(a,b) : r^+ ==> (a,b) : r^*";
clasohm@923
   106
by (resolve_tac [major RS compEpair] 1);
clasohm@923
   107
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
clasohm@923
   108
qed "trancl_into_rtrancl";
clasohm@923
   109
clasohm@923
   110
(*r^+ contains r*)
clasohm@923
   111
val [prem] = goalw Trancl.thy [trancl_def]
clasohm@972
   112
   "[| (a,b) : r |] ==> (a,b) : r^+";
clasohm@923
   113
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1));
clasohm@923
   114
qed "r_into_trancl";
clasohm@923
   115
clasohm@923
   116
(*intro rule by definition: from rtrancl and r*)
clasohm@923
   117
val prems = goalw Trancl.thy [trancl_def]
clasohm@972
   118
    "[| (a,b) : r^*;  (b,c) : r |]   ==>  (a,c) : r^+";
clasohm@923
   119
by (REPEAT (resolve_tac ([compI]@prems) 1));
clasohm@923
   120
qed "rtrancl_into_trancl1";
clasohm@923
   121
clasohm@923
   122
(*intro rule from r and rtrancl*)
clasohm@923
   123
val prems = goal Trancl.thy
clasohm@972
   124
    "[| (a,b) : r;  (b,c) : r^* |]   ==>  (a,c) : r^+";
clasohm@923
   125
by (resolve_tac (prems RL [rtranclE]) 1);
clasohm@923
   126
by (etac subst 1);
clasohm@923
   127
by (resolve_tac (prems RL [r_into_trancl]) 1);
nipkow@1122
   128
by (rtac (rtrancl_trans RS rtrancl_into_trancl1) 1);
clasohm@923
   129
by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1));
clasohm@923
   130
qed "rtrancl_into_trancl2";
clasohm@923
   131
clasohm@923
   132
(*elimination of r^+ -- NOT an induction rule*)
clasohm@923
   133
val major::prems = goal Trancl.thy
clasohm@972
   134
    "[| (a::'a,b) : r^+;  \
clasohm@972
   135
\       (a,b) : r ==> P; \
clasohm@1465
   136
\       !!y.[| (a,y) : r^+;  (y,b) : r |] ==> P  \
clasohm@923
   137
\    |] ==> P";
clasohm@972
   138
by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+  &  (y,b) : r)" 1);
clasohm@923
   139
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1));
clasohm@923
   140
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
clasohm@923
   141
by (etac rtranclE 1);
nipkow@1128
   142
by (fast_tac rel_cs 1);
nipkow@1128
   143
by (fast_tac (rel_cs addSIs [rtrancl_into_trancl1]) 1);
clasohm@923
   144
qed "tranclE";
clasohm@923
   145
clasohm@923
   146
(*Transitivity of r^+.
clasohm@923
   147
  Proved by unfolding since it uses transitivity of rtrancl. *)
clasohm@923
   148
goalw Trancl.thy [trancl_def] "trans(r^+)";
clasohm@923
   149
by (rtac transI 1);
clasohm@923
   150
by (REPEAT (etac compEpair 1));
nipkow@1122
   151
by (rtac (rtrancl_into_rtrancl RS (rtrancl_trans RS compI)) 1);
clasohm@923
   152
by (REPEAT (assume_tac 1));
clasohm@923
   153
qed "trans_trancl";
clasohm@923
   154
clasohm@923
   155
val prems = goal Trancl.thy
clasohm@972
   156
    "[| (a,b) : r;  (b,c) : r^+ |]   ==>  (a,c) : r^+";
clasohm@923
   157
by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1);
clasohm@923
   158
by (resolve_tac prems 1);
clasohm@923
   159
by (resolve_tac prems 1);
clasohm@923
   160
qed "trancl_into_trancl2";
clasohm@923
   161
nipkow@1130
   162
(** More about r^* **)
nipkow@1121
   163
nipkow@1121
   164
goal Trancl.thy "(r^*)^* = r^*";
clasohm@1465
   165
by (rtac set_ext 1);
paulson@1552
   166
by (res_inst_tac [("p","x")] PairE 1);
paulson@1552
   167
by (hyp_subst_tac 1);
clasohm@1465
   168
by (rtac iffI 1);
clasohm@1465
   169
by (etac rtrancl_induct 1);
clasohm@1465
   170
by (rtac rtrancl_refl 1);
paulson@1552
   171
by (fast_tac (HOL_cs addEs [rtrancl_trans]) 1);
clasohm@1465
   172
by (etac r_into_rtrancl 1);
nipkow@1121
   173
qed "rtrancl_idemp";
nipkow@1301
   174
Addsimps [rtrancl_idemp];
clasohm@923
   175
nipkow@1301
   176
goal Trancl.thy "!!R. [| R <= S; S <= R^* |] ==> S^* = R^*";
clasohm@1465
   177
by (dtac rtrancl_mono 1);
clasohm@1465
   178
by (dtac rtrancl_mono 1);
paulson@1552
   179
by (Asm_full_simp_tac 1);
paulson@1552
   180
by (fast_tac eq_cs 1);
nipkow@1301
   181
qed "rtrancl_subset";
nipkow@1301
   182
nipkow@1301
   183
goal Trancl.thy "!!R. (R^* Un S^*)^* = (R Un S)^*";
paulson@1552
   184
by (best_tac (set_cs addIs [rtrancl_subset,r_into_rtrancl,
nipkow@1301
   185
                           rtrancl_mono RS subsetD]) 1);
nipkow@1301
   186
qed "trancl_Un_trancl";
nipkow@1301
   187
nipkow@1301
   188
goal Trancl.thy "(R^=)^* = R^*";
paulson@1552
   189
by (fast_tac (rel_cs addIs [rtrancl_refl,rtrancl_subset,r_into_rtrancl]) 1);
nipkow@1301
   190
qed "rtrancl_reflcl";
nipkow@1301
   191
Addsimps [rtrancl_reflcl];
nipkow@1130
   192
nipkow@1130
   193
goal Trancl.thy "!!r. (x,y) : (converse r)^* ==> (x,y) : converse(r^*)";
clasohm@1465
   194
by (rtac converseI 1);
clasohm@1465
   195
by (etac rtrancl_induct 1);
clasohm@1465
   196
by (rtac rtrancl_refl 1);
paulson@1552
   197
by (fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1);
nipkow@1130
   198
qed "rtrancl_converseD";
nipkow@1130
   199
nipkow@1130
   200
goal Trancl.thy "!!r. (x,y) : converse(r^*) ==> (x,y) : (converse r)^*";
clasohm@1465
   201
by (dtac converseD 1);
clasohm@1465
   202
by (etac rtrancl_induct 1);
clasohm@1465
   203
by (rtac rtrancl_refl 1);
paulson@1552
   204
by (fast_tac (rel_cs addIs [r_into_rtrancl,rtrancl_trans]) 1);
nipkow@1130
   205
qed "rtrancl_converseI";
nipkow@1130
   206
nipkow@1130
   207
goal Trancl.thy "(converse r)^* = converse(r^*)";
paulson@1552
   208
by (safe_tac (rel_eq_cs addSIs [rtrancl_converseI]));
paulson@1552
   209
by (res_inst_tac [("p","x")] PairE 1);
paulson@1552
   210
by (hyp_subst_tac 1);
clasohm@1465
   211
by (etac rtrancl_converseD 1);
nipkow@1130
   212
qed "rtrancl_converse";
nipkow@1130
   213
nipkow@1130
   214
clasohm@923
   215
val major::prems = goal Trancl.thy
clasohm@972
   216
    "[| (a,b) : r^*;  r <= Sigma A (%x.A) |] ==> a=b | a:A";
clasohm@923
   217
by (cut_facts_tac prems 1);
clasohm@923
   218
by (rtac (major RS rtrancl_induct) 1);
clasohm@923
   219
by (rtac (refl RS disjI1) 1);
nipkow@1128
   220
by (fast_tac (rel_cs addSEs [SigmaE2]) 1);
clasohm@923
   221
qed "trancl_subset_Sigma_lemma";
clasohm@923
   222
clasohm@923
   223
goalw Trancl.thy [trancl_def]
clasohm@923
   224
    "!!r. r <= Sigma A (%x.A) ==> trancl(r) <= Sigma A (%x.A)";
nipkow@1128
   225
by (fast_tac (rel_cs addSDs [trancl_subset_Sigma_lemma]) 1);
clasohm@923
   226
qed "trancl_subset_Sigma";
nipkow@1130
   227
nipkow@1301
   228
(* Don't add r_into_rtrancl: it messes up the proofs in Lambda *)
nipkow@1130
   229
val trancl_cs = rel_cs addIs [rtrancl_refl];