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