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