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