src/CCL/Trancl.ML
author paulson
Mon Dec 07 18:26:25 1998 +0100 (1998-12-07)
changeset 6019 0e55c2fb2ebb
parent 5062 fbdb0b541314
child 17456 bcf7544875b2
permissions -rw-r--r--
tidying
clasohm@1459
     1
(*  Title:      CCL/trancl
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
clasohm@0
     4
For trancl.thy.
clasohm@0
     5
clasohm@0
     6
Modified version of
clasohm@1459
     7
    Title:      HOL/trancl.ML
clasohm@1459
     8
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     9
    Copyright   1992  University of Cambridge
clasohm@0
    10
clasohm@0
    11
*)
clasohm@0
    12
clasohm@0
    13
open Trancl;
clasohm@0
    14
clasohm@0
    15
(** Natural deduction for trans(r) **)
clasohm@0
    16
clasohm@0
    17
val prems = goalw Trancl.thy [trans_def]
clasohm@0
    18
    "(!! x y z. [| <x,y>:r;  <y,z>:r |] ==> <x,z>:r) ==> trans(r)";
clasohm@0
    19
by (REPEAT (ares_tac (prems@[allI,impI]) 1));
clasohm@757
    20
qed "transI";
clasohm@0
    21
clasohm@0
    22
val major::prems = goalw Trancl.thy [trans_def]
clasohm@0
    23
    "[| trans(r);  <a,b>:r;  <b,c>:r |] ==> <a,c>:r";
clasohm@0
    24
by (cut_facts_tac [major] 1);
clasohm@0
    25
by (fast_tac (FOL_cs addIs prems) 1);
clasohm@757
    26
qed "transD";
clasohm@0
    27
clasohm@0
    28
(** Identity relation **)
clasohm@0
    29
wenzelm@5062
    30
Goalw [id_def] "<a,a> : id";  
clasohm@0
    31
by (rtac CollectI 1);
clasohm@0
    32
by (rtac exI 1);
clasohm@0
    33
by (rtac refl 1);
clasohm@757
    34
qed "idI";
clasohm@0
    35
clasohm@0
    36
val major::prems = goalw Trancl.thy [id_def]
clasohm@0
    37
    "[| p: id;  !!x.[| p = <x,x> |] ==> P  \
clasohm@0
    38
\    |] ==>  P";  
clasohm@0
    39
by (rtac (major RS CollectE) 1);
clasohm@0
    40
by (etac exE 1);
clasohm@0
    41
by (eresolve_tac prems 1);
clasohm@757
    42
qed "idE";
clasohm@0
    43
clasohm@0
    44
(** Composition of two relations **)
clasohm@0
    45
clasohm@0
    46
val prems = goalw Trancl.thy [comp_def]
clasohm@0
    47
    "[| <a,b>:s; <b,c>:r |] ==> <a,c> : r O s";
clasohm@0
    48
by (fast_tac (set_cs addIs prems) 1);
clasohm@757
    49
qed "compI";
clasohm@0
    50
clasohm@0
    51
(*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
clasohm@0
    52
val prems = goalw Trancl.thy [comp_def]
clasohm@0
    53
    "[| xz : r O s;  \
clasohm@0
    54
\       !!x y z. [| xz = <x,z>;  <x,y>:s;  <y,z>:r |] ==> P \
clasohm@0
    55
\    |] ==> P";
clasohm@0
    56
by (cut_facts_tac prems 1);
clasohm@0
    57
by (REPEAT (eresolve_tac [CollectE, exE, conjE] 1 ORELSE ares_tac prems 1));
clasohm@757
    58
qed "compE";
clasohm@0
    59
clasohm@0
    60
val prems = goal Trancl.thy
clasohm@0
    61
    "[| <a,c> : r O s;  \
clasohm@0
    62
\       !!y. [| <a,y>:s;  <y,c>:r |] ==> P \
clasohm@0
    63
\    |] ==> P";
clasohm@0
    64
by (rtac compE 1);
clasohm@0
    65
by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [pair_inject,ssubst] 1));
clasohm@757
    66
qed "compEpair";
clasohm@0
    67
clasohm@0
    68
val comp_cs = set_cs addIs [compI,idI] 
clasohm@1459
    69
                       addEs [compE,idE] 
clasohm@1459
    70
                       addSEs [pair_inject];
clasohm@0
    71
clasohm@0
    72
val prems = goal Trancl.thy
clasohm@0
    73
    "[| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
clasohm@0
    74
by (cut_facts_tac prems 1);
clasohm@0
    75
by (fast_tac comp_cs 1);
clasohm@757
    76
qed "comp_mono";
clasohm@0
    77
clasohm@0
    78
(** The relation rtrancl **)
clasohm@0
    79
wenzelm@5062
    80
Goal "mono(%s. id Un (r O s))";
clasohm@0
    81
by (rtac monoI 1);
clasohm@0
    82
by (REPEAT (ares_tac [monoI, subset_refl, comp_mono, Un_mono] 1));
clasohm@757
    83
qed "rtrancl_fun_mono";
clasohm@0
    84
clasohm@0
    85
val rtrancl_unfold = rtrancl_fun_mono RS (rtrancl_def RS def_lfp_Tarski);
clasohm@0
    86
clasohm@0
    87
(*Reflexivity of rtrancl*)
wenzelm@5062
    88
Goal "<a,a> : r^*";
paulson@2035
    89
by (stac rtrancl_unfold 1);
clasohm@0
    90
by (fast_tac comp_cs 1);
clasohm@757
    91
qed "rtrancl_refl";
clasohm@0
    92
clasohm@0
    93
(*Closure under composition with r*)
clasohm@0
    94
val prems = goal Trancl.thy
clasohm@0
    95
    "[| <a,b> : r^*;  <b,c> : r |] ==> <a,c> : r^*";
paulson@2035
    96
by (stac rtrancl_unfold 1);
clasohm@0
    97
by (fast_tac (comp_cs addIs prems) 1);
clasohm@757
    98
qed "rtrancl_into_rtrancl";
clasohm@0
    99
clasohm@0
   100
(*rtrancl of r contains r*)
clasohm@0
   101
val [prem] = goal Trancl.thy "[| <a,b> : r |] ==> <a,b> : r^*";
clasohm@0
   102
by (rtac (rtrancl_refl RS rtrancl_into_rtrancl) 1);
clasohm@0
   103
by (rtac prem 1);
clasohm@757
   104
qed "r_into_rtrancl";
clasohm@0
   105
clasohm@0
   106
clasohm@0
   107
(** standard induction rule **)
clasohm@0
   108
clasohm@0
   109
val major::prems = goal Trancl.thy 
clasohm@0
   110
  "[| <a,b> : r^*; \
clasohm@0
   111
\     !!x. P(<x,x>); \
clasohm@0
   112
\     !!x y z.[| P(<x,y>); <x,y>: r^*; <y,z>: r |]  ==>  P(<x,z>) |] \
clasohm@0
   113
\  ==>  P(<a,b>)";
clasohm@0
   114
by (rtac (major RS (rtrancl_def RS def_induct)) 1);
clasohm@0
   115
by (rtac rtrancl_fun_mono 1);
clasohm@0
   116
by (fast_tac (comp_cs addIs prems) 1);
clasohm@757
   117
qed "rtrancl_full_induct";
clasohm@0
   118
clasohm@0
   119
(*nice induction rule*)
clasohm@0
   120
val major::prems = goal Trancl.thy
clasohm@0
   121
    "[| <a,b> : r^*;    \
clasohm@0
   122
\       P(a); \
clasohm@1459
   123
\       !!y z.[| <a,y> : r^*;  <y,z> : r;  P(y) |] ==> P(z) |]  \
clasohm@0
   124
\     ==> P(b)";
clasohm@0
   125
(*by induction on this formula*)
clasohm@0
   126
by (subgoal_tac "ALL y. <a,b> = <a,y> --> P(y)" 1);
clasohm@0
   127
(*now solve first subgoal: this formula is sufficient*)
clasohm@0
   128
by (fast_tac FOL_cs 1);
clasohm@0
   129
(*now do the induction*)
clasohm@0
   130
by (resolve_tac [major RS rtrancl_full_induct] 1);
clasohm@0
   131
by (fast_tac (comp_cs addIs prems) 1);
clasohm@0
   132
by (fast_tac (comp_cs addIs prems) 1);
clasohm@757
   133
qed "rtrancl_induct";
clasohm@0
   134
clasohm@0
   135
(*transitivity of transitive closure!! -- by induction.*)
wenzelm@5062
   136
Goal "trans(r^*)";
clasohm@0
   137
by (rtac transI 1);
clasohm@0
   138
by (res_inst_tac [("b","z")] rtrancl_induct 1);
clasohm@0
   139
by (DEPTH_SOLVE (eresolve_tac [asm_rl, rtrancl_into_rtrancl] 1));
clasohm@757
   140
qed "trans_rtrancl";
clasohm@0
   141
clasohm@0
   142
(*elimination of rtrancl -- by induction on a special formula*)
clasohm@0
   143
val major::prems = goal Trancl.thy
clasohm@0
   144
    "[| <a,b> : r^*;  (a = b) ==> P; \
clasohm@1459
   145
\       !!y.[| <a,y> : r^*; <y,b> : r |] ==> P |] \
clasohm@0
   146
\    ==> P";
clasohm@0
   147
by (subgoal_tac "a = b  | (EX y. <a,y> : r^* & <y,b> : r)" 1);
clasohm@0
   148
by (rtac (major RS rtrancl_induct) 2);
clasohm@0
   149
by (fast_tac (set_cs addIs prems) 2);
clasohm@0
   150
by (fast_tac (set_cs addIs prems) 2);
clasohm@0
   151
by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1));
clasohm@757
   152
qed "rtranclE";
clasohm@0
   153
clasohm@0
   154
clasohm@0
   155
(**** The relation trancl ****)
clasohm@0
   156
clasohm@0
   157
(** Conversions between trancl and rtrancl **)
clasohm@0
   158
clasohm@0
   159
val [major] = goalw Trancl.thy [trancl_def]
clasohm@0
   160
    "[| <a,b> : r^+ |] ==> <a,b> : r^*";
clasohm@0
   161
by (resolve_tac [major RS compEpair] 1);
clasohm@0
   162
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
clasohm@757
   163
qed "trancl_into_rtrancl";
clasohm@0
   164
clasohm@0
   165
(*r^+ contains r*)
clasohm@0
   166
val [prem] = goalw Trancl.thy [trancl_def]
clasohm@0
   167
   "[| <a,b> : r |] ==> <a,b> : r^+";
clasohm@0
   168
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1));
clasohm@757
   169
qed "r_into_trancl";
clasohm@0
   170
clasohm@0
   171
(*intro rule by definition: from rtrancl and r*)
clasohm@0
   172
val prems = goalw Trancl.thy [trancl_def]
clasohm@0
   173
    "[| <a,b> : r^*;  <b,c> : r |]   ==>  <a,c> : r^+";
clasohm@0
   174
by (REPEAT (resolve_tac ([compI]@prems) 1));
clasohm@757
   175
qed "rtrancl_into_trancl1";
clasohm@0
   176
clasohm@0
   177
(*intro rule from r and rtrancl*)
clasohm@0
   178
val prems = goal Trancl.thy
clasohm@0
   179
    "[| <a,b> : r;  <b,c> : r^* |]   ==>  <a,c> : r^+";
clasohm@0
   180
by (resolve_tac (prems RL [rtranclE]) 1);
clasohm@0
   181
by (etac subst 1);
clasohm@0
   182
by (resolve_tac (prems RL [r_into_trancl]) 1);
clasohm@0
   183
by (rtac (trans_rtrancl RS transD RS rtrancl_into_trancl1) 1);
clasohm@0
   184
by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1));
clasohm@757
   185
qed "rtrancl_into_trancl2";
clasohm@0
   186
clasohm@0
   187
(*elimination of r^+ -- NOT an induction rule*)
clasohm@0
   188
val major::prems = goal Trancl.thy
clasohm@0
   189
    "[| <a,b> : r^+;  \
clasohm@0
   190
\       <a,b> : r ==> P; \
clasohm@1459
   191
\       !!y.[| <a,y> : r^+;  <y,b> : r |] ==> P  \
clasohm@0
   192
\    |] ==> P";
clasohm@0
   193
by (subgoal_tac "<a,b> : r | (EX y. <a,y> : r^+  &  <y,b> : r)" 1);
clasohm@0
   194
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1));
clasohm@0
   195
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
clasohm@0
   196
by (etac rtranclE 1);
clasohm@0
   197
by (fast_tac comp_cs 1);
clasohm@0
   198
by (fast_tac (comp_cs addSIs [rtrancl_into_trancl1]) 1);
clasohm@757
   199
qed "tranclE";
clasohm@0
   200
clasohm@0
   201
(*Transitivity of r^+.
clasohm@0
   202
  Proved by unfolding since it uses transitivity of rtrancl. *)
wenzelm@5062
   203
Goalw [trancl_def] "trans(r^+)";
clasohm@0
   204
by (rtac transI 1);
clasohm@0
   205
by (REPEAT (etac compEpair 1));
clasohm@0
   206
by (rtac (rtrancl_into_rtrancl RS (trans_rtrancl RS transD RS compI)) 1);
clasohm@0
   207
by (REPEAT (assume_tac 1));
clasohm@757
   208
qed "trans_trancl";
clasohm@0
   209
clasohm@0
   210
val prems = goal Trancl.thy
clasohm@0
   211
    "[| <a,b> : r;  <b,c> : r^+ |]   ==>  <a,c> : r^+";
clasohm@0
   212
by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1);
clasohm@0
   213
by (resolve_tac prems 1);
clasohm@0
   214
by (resolve_tac prems 1);
clasohm@757
   215
qed "trancl_into_trancl2";