src/ZF/Trancl.ML
author clasohm
Wed Dec 07 13:12:04 1994 +0100 (1994-12-07)
changeset 760 f0200e91b272
parent 435 ca5356bd315a
child 782 200a16083201
permissions -rw-r--r--
added qed and qed_goal[w]
clasohm@0
     1
(*  Title: 	ZF/trancl.ML
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1992  University of Cambridge
clasohm@0
     5
clasohm@0
     6
For trancl.thy.  Transitive closure of a relation
clasohm@0
     7
*)
clasohm@0
     8
clasohm@0
     9
open Trancl;
clasohm@0
    10
clasohm@0
    11
goal Trancl.thy "bnd_mono(field(r)*field(r), %s. id(field(r)) Un (r O s))";
clasohm@0
    12
by (rtac bnd_monoI 1);
clasohm@0
    13
by (REPEAT (ares_tac [subset_refl, Un_mono, comp_mono] 2));
clasohm@0
    14
by (fast_tac comp_cs 1);
clasohm@760
    15
qed "rtrancl_bnd_mono";
clasohm@0
    16
clasohm@0
    17
val [prem] = goalw Trancl.thy [rtrancl_def] "r<=s ==> r^* <= s^*";
clasohm@0
    18
by (rtac lfp_mono 1);
clasohm@0
    19
by (REPEAT (resolve_tac [rtrancl_bnd_mono, prem, subset_refl, id_mono,
clasohm@0
    20
			 comp_mono, Un_mono, field_mono, Sigma_mono] 1));
clasohm@760
    21
qed "rtrancl_mono";
clasohm@0
    22
clasohm@0
    23
(* r^* = id(field(r)) Un ( r O r^* )    *)
clasohm@0
    24
val rtrancl_unfold = rtrancl_bnd_mono RS (rtrancl_def RS def_lfp_Tarski);
clasohm@0
    25
clasohm@0
    26
(** The relation rtrancl **)
clasohm@0
    27
clasohm@0
    28
val rtrancl_type = standard (rtrancl_def RS def_lfp_subset);
clasohm@0
    29
clasohm@0
    30
(*Reflexivity of rtrancl*)
clasohm@0
    31
val [prem] = goal Trancl.thy "[| a: field(r) |] ==> <a,a> : r^*";
clasohm@0
    32
by (resolve_tac [rtrancl_unfold RS ssubst] 1);
clasohm@0
    33
by (rtac (prem RS idI RS UnI1) 1);
clasohm@760
    34
qed "rtrancl_refl";
clasohm@0
    35
clasohm@0
    36
(*Closure under composition with r  *)
clasohm@0
    37
val prems = goal Trancl.thy
clasohm@0
    38
    "[| <a,b> : r^*;  <b,c> : r |] ==> <a,c> : r^*";
clasohm@0
    39
by (resolve_tac [rtrancl_unfold RS ssubst] 1);
clasohm@0
    40
by (rtac (compI RS UnI2) 1);
clasohm@0
    41
by (resolve_tac prems 1);
clasohm@0
    42
by (resolve_tac prems 1);
clasohm@760
    43
qed "rtrancl_into_rtrancl";
clasohm@0
    44
clasohm@0
    45
(*rtrancl of r contains all pairs in r  *)
clasohm@0
    46
val prems = goal Trancl.thy "<a,b> : r ==> <a,b> : r^*";
clasohm@0
    47
by (resolve_tac [rtrancl_refl RS rtrancl_into_rtrancl] 1);
clasohm@0
    48
by (REPEAT (resolve_tac (prems@[fieldI1]) 1));
clasohm@760
    49
qed "r_into_rtrancl";
clasohm@0
    50
clasohm@0
    51
(*The premise ensures that r consists entirely of pairs*)
clasohm@0
    52
val prems = goal Trancl.thy "r <= Sigma(A,B) ==> r <= r^*";
clasohm@0
    53
by (cut_facts_tac prems 1);
clasohm@0
    54
by (fast_tac (ZF_cs addIs [r_into_rtrancl]) 1);
clasohm@760
    55
qed "r_subset_rtrancl";
clasohm@0
    56
clasohm@0
    57
goal Trancl.thy "field(r^*) = field(r)";
clasohm@0
    58
by (fast_tac (eq_cs addIs [r_into_rtrancl] 
clasohm@0
    59
		    addSDs [rtrancl_type RS subsetD]) 1);
clasohm@760
    60
qed "rtrancl_field";
clasohm@0
    61
clasohm@0
    62
clasohm@0
    63
(** standard induction rule **)
clasohm@0
    64
clasohm@0
    65
val major::prems = goal Trancl.thy
clasohm@0
    66
  "[| <a,b> : r^*; \
clasohm@0
    67
\     !!x. x: field(r) ==> P(<x,x>); \
clasohm@0
    68
\     !!x y z.[| P(<x,y>); <x,y>: r^*; <y,z>: r |]  ==>  P(<x,z>) |] \
clasohm@0
    69
\  ==>  P(<a,b>)";
clasohm@0
    70
by (rtac ([rtrancl_def, rtrancl_bnd_mono, major] MRS def_induct) 1);
clasohm@0
    71
by (fast_tac (ZF_cs addIs prems addSEs [idE,compE]) 1);
clasohm@760
    72
qed "rtrancl_full_induct";
clasohm@0
    73
clasohm@0
    74
(*nice induction rule.
clasohm@0
    75
  Tried adding the typing hypotheses y,z:field(r), but these
clasohm@0
    76
  caused expensive case splits!*)
clasohm@0
    77
val major::prems = goal Trancl.thy
clasohm@0
    78
  "[| <a,b> : r^*;   						\
clasohm@0
    79
\     P(a); 							\
clasohm@0
    80
\     !!y z.[| <a,y> : r^*;  <y,z> : r;  P(y) |] ==> P(z) 	\
clasohm@0
    81
\  |] ==> P(b)";
clasohm@0
    82
(*by induction on this formula*)
clasohm@0
    83
by (subgoal_tac "ALL y. <a,b> = <a,y> --> P(y)" 1);
clasohm@0
    84
(*now solve first subgoal: this formula is sufficient*)
clasohm@0
    85
by (EVERY1 [etac (spec RS mp), rtac refl]);
clasohm@0
    86
(*now do the induction*)
clasohm@0
    87
by (resolve_tac [major RS rtrancl_full_induct] 1);
clasohm@0
    88
by (ALLGOALS (fast_tac (ZF_cs addIs prems)));
clasohm@760
    89
qed "rtrancl_induct";
clasohm@0
    90
clasohm@0
    91
(*transitivity of transitive closure!! -- by induction.*)
clasohm@0
    92
goalw Trancl.thy [trans_def] "trans(r^*)";
clasohm@0
    93
by (REPEAT (resolve_tac [allI,impI] 1));
clasohm@0
    94
by (eres_inst_tac [("b","z")] rtrancl_induct 1);
clasohm@0
    95
by (DEPTH_SOLVE (eresolve_tac [asm_rl, rtrancl_into_rtrancl] 1));
clasohm@760
    96
qed "trans_rtrancl";
clasohm@0
    97
clasohm@0
    98
(*elimination of rtrancl -- by induction on a special formula*)
clasohm@0
    99
val major::prems = goal Trancl.thy
clasohm@0
   100
    "[| <a,b> : r^*;  (a=b) ==> P;			 \
clasohm@0
   101
\	!!y.[| <a,y> : r^*;   <y,b> : r |] ==> P |]	 \
clasohm@0
   102
\    ==> P";
clasohm@0
   103
by (subgoal_tac "a = b  | (EX y. <a,y> : r^* & <y,b> : r)" 1);
clasohm@0
   104
(*see HOL/trancl*)
clasohm@0
   105
by (rtac (major RS rtrancl_induct) 2);
clasohm@0
   106
by (ALLGOALS (fast_tac (ZF_cs addSEs prems)));
clasohm@760
   107
qed "rtranclE";
clasohm@0
   108
clasohm@0
   109
clasohm@0
   110
(**** The relation trancl ****)
clasohm@0
   111
clasohm@0
   112
(*Transitivity of r^+ is proved by transitivity of r^*  *)
clasohm@0
   113
goalw Trancl.thy [trans_def,trancl_def] "trans(r^+)";
clasohm@0
   114
by (safe_tac comp_cs);
clasohm@0
   115
by (rtac (rtrancl_into_rtrancl RS (trans_rtrancl RS transD RS compI)) 1);
clasohm@0
   116
by (REPEAT (assume_tac 1));
clasohm@760
   117
qed "trans_trancl";
clasohm@0
   118
clasohm@0
   119
(** Conversions between trancl and rtrancl **)
clasohm@0
   120
clasohm@0
   121
val [major] = goalw Trancl.thy [trancl_def] "<a,b> : r^+ ==> <a,b> : r^*";
clasohm@0
   122
by (resolve_tac [major RS compEpair] 1);
clasohm@0
   123
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
clasohm@760
   124
qed "trancl_into_rtrancl";
clasohm@0
   125
clasohm@0
   126
(*r^+ contains all pairs in r  *)
clasohm@0
   127
val [prem] = goalw Trancl.thy [trancl_def] "<a,b> : r ==> <a,b> : r^+";
clasohm@0
   128
by (REPEAT (ares_tac [prem,compI,rtrancl_refl,fieldI1] 1));
clasohm@760
   129
qed "r_into_trancl";
clasohm@0
   130
clasohm@0
   131
(*The premise ensures that r consists entirely of pairs*)
clasohm@0
   132
val prems = goal Trancl.thy "r <= Sigma(A,B) ==> r <= r^+";
clasohm@0
   133
by (cut_facts_tac prems 1);
clasohm@0
   134
by (fast_tac (ZF_cs addIs [r_into_trancl]) 1);
clasohm@760
   135
qed "r_subset_trancl";
clasohm@0
   136
clasohm@0
   137
(*intro rule by definition: from r^* and r  *)
clasohm@0
   138
val prems = goalw Trancl.thy [trancl_def]
clasohm@0
   139
    "[| <a,b> : r^*;  <b,c> : r |]   ==>  <a,c> : r^+";
clasohm@0
   140
by (REPEAT (resolve_tac ([compI]@prems) 1));
clasohm@760
   141
qed "rtrancl_into_trancl1";
clasohm@0
   142
clasohm@0
   143
(*intro rule from r and r^*  *)
clasohm@0
   144
val prems = goal Trancl.thy
clasohm@0
   145
    "[| <a,b> : r;  <b,c> : r^* |]   ==>  <a,c> : r^+";
clasohm@0
   146
by (resolve_tac (prems RL [rtrancl_induct]) 1);
clasohm@0
   147
by (resolve_tac (prems RL [r_into_trancl]) 1);
clasohm@0
   148
by (etac (trans_trancl RS transD) 1);
clasohm@0
   149
by (etac r_into_trancl 1);
clasohm@760
   150
qed "rtrancl_into_trancl2";
clasohm@0
   151
clasohm@0
   152
(*Nice induction rule for trancl*)
clasohm@0
   153
val major::prems = goal Trancl.thy
clasohm@0
   154
  "[| <a,b> : r^+;    					\
clasohm@0
   155
\     !!y.  [| <a,y> : r |] ==> P(y); 			\
clasohm@0
   156
\     !!y z.[| <a,y> : r^+;  <y,z> : r;  P(y) |] ==> P(z) 	\
clasohm@0
   157
\  |] ==> P(b)";
clasohm@0
   158
by (rtac (rewrite_rule [trancl_def] major  RS  compEpair) 1);
clasohm@0
   159
(*by induction on this formula*)
clasohm@0
   160
by (subgoal_tac "ALL z. <y,z> : r --> P(z)" 1);
clasohm@0
   161
(*now solve first subgoal: this formula is sufficient*)
clasohm@0
   162
by (fast_tac ZF_cs 1);
clasohm@0
   163
by (etac rtrancl_induct 1);
clasohm@0
   164
by (ALLGOALS (fast_tac (ZF_cs addIs (rtrancl_into_trancl1::prems))));
clasohm@760
   165
qed "trancl_induct";
clasohm@0
   166
clasohm@0
   167
(*elimination of r^+ -- NOT an induction rule*)
clasohm@0
   168
val major::prems = goal Trancl.thy
clasohm@0
   169
    "[| <a,b> : r^+;  \
clasohm@0
   170
\       <a,b> : r ==> P; \
clasohm@0
   171
\	!!y.[| <a,y> : r^+; <y,b> : r |] ==> P  \
clasohm@0
   172
\    |] ==> P";
clasohm@0
   173
by (subgoal_tac "<a,b> : r | (EX y. <a,y> : r^+  &  <y,b> : r)" 1);
clasohm@0
   174
by (fast_tac (ZF_cs addIs prems) 1);
clasohm@0
   175
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
clasohm@0
   176
by (etac rtranclE 1);
clasohm@0
   177
by (ALLGOALS (fast_tac (ZF_cs addIs [rtrancl_into_trancl1])));
clasohm@760
   178
qed "tranclE";
clasohm@0
   179
clasohm@0
   180
goalw Trancl.thy [trancl_def] "r^+ <= field(r)*field(r)";
clasohm@0
   181
by (fast_tac (ZF_cs addEs [compE, rtrancl_type RS subsetD RS SigmaE2]) 1);
clasohm@760
   182
qed "trancl_type";
clasohm@0
   183
clasohm@0
   184
val [prem] = goalw Trancl.thy [trancl_def] "r<=s ==> r^+ <= s^+";
clasohm@0
   185
by (REPEAT (resolve_tac [prem, comp_mono, rtrancl_mono] 1));
clasohm@760
   186
qed "trancl_mono";
clasohm@0
   187