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