src/HOL/Trancl.ML
author clasohm
Fri Mar 24 12:30:35 1995 +0100 (1995-03-24)
changeset 972 e61b058d58d2
parent 923 ff1574a81019
child 1121 485b49694253
permissions -rw-r--r--
changed syntax of tuples from <..., ...> to (..., ...)
clasohm@923
     1
(*  Title: 	HOL/trancl
clasohm@923
     2
    ID:         $Id$
clasohm@923
     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
(** Natural deduction for trans(r) **)
clasohm@923
    12
clasohm@923
    13
val prems = goalw Trancl.thy [trans_def]
clasohm@972
    14
    "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
clasohm@923
    15
by (REPEAT (ares_tac (prems@[allI,impI]) 1));
clasohm@923
    16
qed "transI";
clasohm@923
    17
clasohm@923
    18
val major::prems = goalw Trancl.thy [trans_def]
clasohm@972
    19
    "[| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
clasohm@923
    20
by (cut_facts_tac [major] 1);
clasohm@923
    21
by (fast_tac (HOL_cs addIs prems) 1);
clasohm@923
    22
qed "transD";
clasohm@923
    23
clasohm@923
    24
(** Identity relation **)
clasohm@923
    25
clasohm@972
    26
goalw Trancl.thy [id_def] "(a,a) : id";  
clasohm@923
    27
by (rtac CollectI 1);
clasohm@923
    28
by (rtac exI 1);
clasohm@923
    29
by (rtac refl 1);
clasohm@923
    30
qed "idI";
clasohm@923
    31
clasohm@923
    32
val major::prems = goalw Trancl.thy [id_def]
clasohm@972
    33
    "[| p: id;  !!x.[| p = (x,x) |] ==> P  \
clasohm@923
    34
\    |] ==>  P";  
clasohm@923
    35
by (rtac (major RS CollectE) 1);
clasohm@923
    36
by (etac exE 1);
clasohm@923
    37
by (eresolve_tac prems 1);
clasohm@923
    38
qed "idE";
clasohm@923
    39
clasohm@972
    40
goalw Trancl.thy [id_def] "(a,b):id = (a=b)";
clasohm@923
    41
by(fast_tac prod_cs 1);
clasohm@923
    42
qed "pair_in_id_conv";
clasohm@923
    43
clasohm@923
    44
(** Composition of two relations **)
clasohm@923
    45
clasohm@923
    46
val prems = goalw Trancl.thy [comp_def]
clasohm@972
    47
    "[| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
clasohm@923
    48
by (fast_tac (set_cs addIs prems) 1);
clasohm@923
    49
qed "compI";
clasohm@923
    50
clasohm@923
    51
(*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
clasohm@923
    52
val prems = goalw Trancl.thy [comp_def]
clasohm@923
    53
    "[| xz : r O s;  \
clasohm@972
    54
\       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
clasohm@923
    55
\    |] ==> P";
clasohm@923
    56
by (cut_facts_tac prems 1);
clasohm@923
    57
by (REPEAT (eresolve_tac [CollectE, exE, conjE] 1 ORELSE ares_tac prems 1));
clasohm@923
    58
qed "compE";
clasohm@923
    59
clasohm@923
    60
val prems = goal Trancl.thy
clasohm@972
    61
    "[| (a,c) : r O s;  \
clasohm@972
    62
\       !!y. [| (a,y):s;  (y,c):r |] ==> P \
clasohm@923
    63
\    |] ==> P";
clasohm@923
    64
by (rtac compE 1);
clasohm@923
    65
by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
clasohm@923
    66
qed "compEpair";
clasohm@923
    67
clasohm@923
    68
val comp_cs = prod_cs addIs [compI, idI] addSEs [compE, idE];
clasohm@923
    69
clasohm@923
    70
goal Trancl.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
clasohm@923
    71
by (fast_tac comp_cs 1);
clasohm@923
    72
qed "comp_mono";
clasohm@923
    73
clasohm@923
    74
goal Trancl.thy
clasohm@923
    75
    "!!r s. [| s <= Sigma A (%x.B);  r <= Sigma B (%x.C) |] ==> \
clasohm@923
    76
\           (r O s) <= Sigma A (%x.C)";
clasohm@923
    77
by (fast_tac comp_cs 1);
clasohm@923
    78
qed "comp_subset_Sigma";
clasohm@923
    79
clasohm@923
    80
clasohm@923
    81
(** The relation rtrancl **)
clasohm@923
    82
clasohm@923
    83
goal Trancl.thy "mono(%s. id Un (r O s))";
clasohm@923
    84
by (rtac monoI 1);
clasohm@923
    85
by (REPEAT (ares_tac [monoI, subset_refl, comp_mono, Un_mono] 1));
clasohm@923
    86
qed "rtrancl_fun_mono";
clasohm@923
    87
clasohm@923
    88
val rtrancl_unfold = rtrancl_fun_mono RS (rtrancl_def RS def_lfp_Tarski);
clasohm@923
    89
clasohm@923
    90
(*Reflexivity of rtrancl*)
clasohm@972
    91
goal Trancl.thy "(a,a) : r^*";
clasohm@923
    92
by (stac rtrancl_unfold 1);
clasohm@923
    93
by (fast_tac comp_cs 1);
clasohm@923
    94
qed "rtrancl_refl";
clasohm@923
    95
clasohm@923
    96
(*Closure under composition with r*)
clasohm@923
    97
val prems = goal Trancl.thy
clasohm@972
    98
    "[| (a,b) : r^*;  (b,c) : r |] ==> (a,c) : r^*";
clasohm@923
    99
by (stac rtrancl_unfold 1);
clasohm@923
   100
by (fast_tac (comp_cs addIs prems) 1);
clasohm@923
   101
qed "rtrancl_into_rtrancl";
clasohm@923
   102
clasohm@923
   103
(*rtrancl of r contains r*)
clasohm@972
   104
val [prem] = goal Trancl.thy "[| (a,b) : r |] ==> (a,b) : r^*";
clasohm@923
   105
by (rtac (rtrancl_refl RS rtrancl_into_rtrancl) 1);
clasohm@923
   106
by (rtac prem 1);
clasohm@923
   107
qed "r_into_rtrancl";
clasohm@923
   108
clasohm@923
   109
(*monotonicity of rtrancl*)
clasohm@923
   110
goalw Trancl.thy [rtrancl_def] "!!r s. r <= s ==> r^* <= s^*";
clasohm@923
   111
by(REPEAT(ares_tac [lfp_mono,Un_mono,comp_mono,subset_refl] 1));
clasohm@923
   112
qed "rtrancl_mono";
clasohm@923
   113
clasohm@923
   114
(** standard induction rule **)
clasohm@923
   115
clasohm@923
   116
val major::prems = goal Trancl.thy 
clasohm@972
   117
  "[| (a,b) : r^*; \
clasohm@972
   118
\     !!x. P((x,x)); \
clasohm@972
   119
\     !!x y z.[| P((x,y)); (x,y): r^*; (y,z): r |]  ==>  P((x,z)) |] \
clasohm@972
   120
\  ==>  P((a,b))";
clasohm@923
   121
by (rtac ([rtrancl_def, rtrancl_fun_mono, major] MRS def_induct) 1);
clasohm@923
   122
by (fast_tac (comp_cs addIs prems) 1);
clasohm@923
   123
qed "rtrancl_full_induct";
clasohm@923
   124
clasohm@923
   125
(*nice induction rule*)
clasohm@923
   126
val major::prems = goal Trancl.thy
clasohm@972
   127
    "[| (a::'a,b) : r^*;    \
clasohm@923
   128
\       P(a); \
clasohm@972
   129
\	!!y z.[| (a,y) : r^*;  (y,z) : r;  P(y) |] ==> P(z) |]  \
clasohm@923
   130
\     ==> P(b)";
clasohm@923
   131
(*by induction on this formula*)
clasohm@972
   132
by (subgoal_tac "! y. (a::'a,b) = (a,y) --> P(y)" 1);
clasohm@923
   133
(*now solve first subgoal: this formula is sufficient*)
clasohm@923
   134
by (fast_tac HOL_cs 1);
clasohm@923
   135
(*now do the induction*)
clasohm@923
   136
by (resolve_tac [major RS rtrancl_full_induct] 1);
clasohm@923
   137
by (fast_tac (comp_cs addIs prems) 1);
clasohm@923
   138
by (fast_tac (comp_cs addIs prems) 1);
clasohm@923
   139
qed "rtrancl_induct";
clasohm@923
   140
clasohm@923
   141
(*transitivity of transitive closure!! -- by induction.*)
clasohm@923
   142
goal Trancl.thy "trans(r^*)";
clasohm@923
   143
by (rtac transI 1);
clasohm@923
   144
by (res_inst_tac [("b","z")] rtrancl_induct 1);
clasohm@923
   145
by (DEPTH_SOLVE (eresolve_tac [asm_rl, rtrancl_into_rtrancl] 1));
clasohm@923
   146
qed "trans_rtrancl";
clasohm@923
   147
clasohm@923
   148
(*elimination of rtrancl -- by induction on a special formula*)
clasohm@923
   149
val major::prems = goal Trancl.thy
clasohm@972
   150
    "[| (a::'a,b) : r^*;  (a = b) ==> P; 	\
clasohm@972
   151
\	!!y.[| (a,y) : r^*; (y,b) : r |] ==> P 	\
clasohm@923
   152
\    |] ==> P";
clasohm@972
   153
by (subgoal_tac "(a::'a) = b  | (? y. (a,y) : r^* & (y,b) : r)" 1);
clasohm@923
   154
by (rtac (major RS rtrancl_induct) 2);
clasohm@923
   155
by (fast_tac (set_cs addIs prems) 2);
clasohm@923
   156
by (fast_tac (set_cs addIs prems) 2);
clasohm@923
   157
by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1));
clasohm@923
   158
qed "rtranclE";
clasohm@923
   159
clasohm@923
   160
clasohm@923
   161
(**** The relation trancl ****)
clasohm@923
   162
clasohm@923
   163
(** Conversions between trancl and rtrancl **)
clasohm@923
   164
clasohm@923
   165
val [major] = goalw Trancl.thy [trancl_def]
clasohm@972
   166
    "(a,b) : r^+ ==> (a,b) : r^*";
clasohm@923
   167
by (resolve_tac [major RS compEpair] 1);
clasohm@923
   168
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
clasohm@923
   169
qed "trancl_into_rtrancl";
clasohm@923
   170
clasohm@923
   171
(*r^+ contains r*)
clasohm@923
   172
val [prem] = goalw Trancl.thy [trancl_def]
clasohm@972
   173
   "[| (a,b) : r |] ==> (a,b) : r^+";
clasohm@923
   174
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1));
clasohm@923
   175
qed "r_into_trancl";
clasohm@923
   176
clasohm@923
   177
(*intro rule by definition: from rtrancl and r*)
clasohm@923
   178
val prems = goalw Trancl.thy [trancl_def]
clasohm@972
   179
    "[| (a,b) : r^*;  (b,c) : r |]   ==>  (a,c) : r^+";
clasohm@923
   180
by (REPEAT (resolve_tac ([compI]@prems) 1));
clasohm@923
   181
qed "rtrancl_into_trancl1";
clasohm@923
   182
clasohm@923
   183
(*intro rule from r and rtrancl*)
clasohm@923
   184
val prems = goal Trancl.thy
clasohm@972
   185
    "[| (a,b) : r;  (b,c) : r^* |]   ==>  (a,c) : r^+";
clasohm@923
   186
by (resolve_tac (prems RL [rtranclE]) 1);
clasohm@923
   187
by (etac subst 1);
clasohm@923
   188
by (resolve_tac (prems RL [r_into_trancl]) 1);
clasohm@923
   189
by (rtac (trans_rtrancl RS transD RS rtrancl_into_trancl1) 1);
clasohm@923
   190
by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1));
clasohm@923
   191
qed "rtrancl_into_trancl2";
clasohm@923
   192
clasohm@923
   193
(*elimination of r^+ -- NOT an induction rule*)
clasohm@923
   194
val major::prems = goal Trancl.thy
clasohm@972
   195
    "[| (a::'a,b) : r^+;  \
clasohm@972
   196
\       (a,b) : r ==> P; \
clasohm@972
   197
\	!!y.[| (a,y) : r^+;  (y,b) : r |] ==> P  \
clasohm@923
   198
\    |] ==> P";
clasohm@972
   199
by (subgoal_tac "(a::'a,b) : r | (? y. (a,y) : r^+  &  (y,b) : r)" 1);
clasohm@923
   200
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1));
clasohm@923
   201
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
clasohm@923
   202
by (etac rtranclE 1);
clasohm@923
   203
by (fast_tac comp_cs 1);
clasohm@923
   204
by (fast_tac (comp_cs addSIs [rtrancl_into_trancl1]) 1);
clasohm@923
   205
qed "tranclE";
clasohm@923
   206
clasohm@923
   207
(*Transitivity of r^+.
clasohm@923
   208
  Proved by unfolding since it uses transitivity of rtrancl. *)
clasohm@923
   209
goalw Trancl.thy [trancl_def] "trans(r^+)";
clasohm@923
   210
by (rtac transI 1);
clasohm@923
   211
by (REPEAT (etac compEpair 1));
clasohm@923
   212
by (rtac (rtrancl_into_rtrancl RS (trans_rtrancl RS transD RS compI)) 1);
clasohm@923
   213
by (REPEAT (assume_tac 1));
clasohm@923
   214
qed "trans_trancl";
clasohm@923
   215
clasohm@923
   216
val prems = goal Trancl.thy
clasohm@972
   217
    "[| (a,b) : r;  (b,c) : r^+ |]   ==>  (a,c) : r^+";
clasohm@923
   218
by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1);
clasohm@923
   219
by (resolve_tac prems 1);
clasohm@923
   220
by (resolve_tac prems 1);
clasohm@923
   221
qed "trancl_into_trancl2";
clasohm@923
   222
clasohm@923
   223
clasohm@923
   224
val major::prems = goal Trancl.thy
clasohm@972
   225
    "[| (a,b) : r^*;  r <= Sigma A (%x.A) |] ==> a=b | a:A";
clasohm@923
   226
by (cut_facts_tac prems 1);
clasohm@923
   227
by (rtac (major RS rtrancl_induct) 1);
clasohm@923
   228
by (rtac (refl RS disjI1) 1);
clasohm@923
   229
by (fast_tac (comp_cs addSEs [SigmaE2]) 1);
clasohm@923
   230
qed "trancl_subset_Sigma_lemma";
clasohm@923
   231
clasohm@923
   232
goalw Trancl.thy [trancl_def]
clasohm@923
   233
    "!!r. r <= Sigma A (%x.A) ==> trancl(r) <= Sigma A (%x.A)";
clasohm@923
   234
by (fast_tac (comp_cs addSDs [trancl_subset_Sigma_lemma]) 1);
clasohm@923
   235
qed "trancl_subset_Sigma";
clasohm@923
   236
clasohm@923
   237
val prod_ss = prod_ss addsimps [pair_in_id_conv];