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