src/HOL/Relation.ML
author oheimb
Wed Feb 25 15:48:04 1998 +0100 (1998-02-25)
changeset 4650 91af1ef45d68
parent 4644 ecf8f17f6fe0
child 4673 59d80bacee62
permissions -rw-r--r--
added split_all_tac to claset()
clasohm@1465
     1
(*  Title:      Relation.ML
nipkow@1128
     2
    ID:         $Id$
paulson@1985
     3
    Authors:    Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@1985
     4
    Copyright   1996  University of Cambridge
nipkow@1128
     5
*)
nipkow@1128
     6
nipkow@1128
     7
open Relation;
nipkow@1128
     8
nipkow@1128
     9
(** Identity relation **)
nipkow@1128
    10
nipkow@1128
    11
goalw Relation.thy [id_def] "(a,a) : id";  
paulson@2891
    12
by (Blast_tac 1);
nipkow@1128
    13
qed "idI";
nipkow@1128
    14
nipkow@1128
    15
val major::prems = goalw Relation.thy [id_def]
nipkow@1128
    16
    "[| p: id;  !!x.[| p = (x,x) |] ==> P  \
nipkow@1128
    17
\    |] ==>  P";  
nipkow@1128
    18
by (rtac (major RS CollectE) 1);
nipkow@1128
    19
by (etac exE 1);
nipkow@1128
    20
by (eresolve_tac prems 1);
nipkow@1128
    21
qed "idE";
nipkow@1128
    22
nipkow@1128
    23
goalw Relation.thy [id_def] "(a,b):id = (a=b)";
paulson@2891
    24
by (Blast_tac 1);
nipkow@1128
    25
qed "pair_in_id_conv";
nipkow@1694
    26
Addsimps [pair_in_id_conv];
nipkow@1128
    27
nipkow@1128
    28
nipkow@1128
    29
(** Composition of two relations **)
nipkow@1128
    30
paulson@1985
    31
goalw Relation.thy [comp_def]
paulson@1985
    32
    "!!r s. [| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
paulson@2891
    33
by (Blast_tac 1);
nipkow@1128
    34
qed "compI";
nipkow@1128
    35
nipkow@1128
    36
(*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
nipkow@1128
    37
val prems = goalw Relation.thy [comp_def]
nipkow@1128
    38
    "[| xz : r O s;  \
nipkow@1128
    39
\       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
nipkow@1128
    40
\    |] ==> P";
nipkow@1128
    41
by (cut_facts_tac prems 1);
paulson@1985
    42
by (REPEAT (eresolve_tac [CollectE, splitE, exE, conjE] 1 
paulson@1985
    43
     ORELSE ares_tac prems 1));
nipkow@1128
    44
qed "compE";
nipkow@1128
    45
nipkow@1128
    46
val prems = goal Relation.thy
nipkow@1128
    47
    "[| (a,c) : r O s;  \
nipkow@1128
    48
\       !!y. [| (a,y):s;  (y,c):r |] ==> P \
nipkow@1128
    49
\    |] ==> P";
nipkow@1128
    50
by (rtac compE 1);
nipkow@1128
    51
by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
nipkow@1128
    52
qed "compEpair";
nipkow@1128
    53
berghofe@1754
    54
AddIs [compI, idI];
berghofe@1754
    55
AddSEs [compE, idE];
berghofe@1754
    56
nipkow@1128
    57
goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
paulson@2891
    58
by (Blast_tac 1);
nipkow@1128
    59
qed "comp_mono";
nipkow@1128
    60
nipkow@1128
    61
goal Relation.thy
paulson@1985
    62
    "!!r s. [| s <= A Times B;  r <= B Times C |] ==> (r O s) <= A Times C";
paulson@2891
    63
by (Blast_tac 1);
nipkow@1128
    64
qed "comp_subset_Sigma";
nipkow@1128
    65
nipkow@1128
    66
(** Natural deduction for trans(r) **)
nipkow@1128
    67
nipkow@1128
    68
val prems = goalw Relation.thy [trans_def]
nipkow@1128
    69
    "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
nipkow@1128
    70
by (REPEAT (ares_tac (prems@[allI,impI]) 1));
nipkow@1128
    71
qed "transI";
nipkow@1128
    72
paulson@1985
    73
goalw Relation.thy [trans_def]
paulson@1985
    74
    "!!r. [| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
paulson@2891
    75
by (Blast_tac 1);
nipkow@1128
    76
qed "transD";
nipkow@1128
    77
nipkow@3439
    78
(** Natural deduction for r^-1 **)
nipkow@1128
    79
nipkow@3439
    80
goalw Relation.thy [inverse_def] "!!a b r. ((a,b): r^-1) = ((b,a):r)";
paulson@1985
    81
by (Simp_tac 1);
nipkow@3439
    82
qed "inverse_iff";
paulson@1985
    83
nipkow@3439
    84
AddIffs [inverse_iff];
paulson@1985
    85
nipkow@3439
    86
goalw Relation.thy [inverse_def] "!!a b r. (a,b):r ==> (b,a): r^-1";
clasohm@1264
    87
by (Simp_tac 1);
nipkow@3439
    88
qed "inverseI";
nipkow@1128
    89
nipkow@3439
    90
goalw Relation.thy [inverse_def] "!!a b r. (a,b) : r^-1 ==> (b,a) : r";
paulson@2891
    91
by (Blast_tac 1);
nipkow@3439
    92
qed "inverseD";
nipkow@1128
    93
nipkow@3439
    94
(*More general than inverseD, as it "splits" the member of the relation*)
nipkow@3439
    95
qed_goalw "inverseE" Relation.thy [inverse_def]
nipkow@3439
    96
    "[| yx : r^-1;  \
nipkow@1128
    97
\       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
nipkow@1128
    98
\    |] ==> P"
nipkow@1128
    99
 (fn [major,minor]=>
nipkow@1128
   100
  [ (rtac (major RS CollectE) 1),
nipkow@1454
   101
    (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
nipkow@1128
   102
    (assume_tac 1) ]);
nipkow@1128
   103
nipkow@3439
   104
AddSEs [inverseE];
nipkow@1128
   105
nipkow@3439
   106
goalw Relation.thy [inverse_def] "(r^-1)^-1 = r";
paulson@2891
   107
by (Blast_tac 1);
nipkow@3439
   108
qed "inverse_inverse";
nipkow@3439
   109
Addsimps [inverse_inverse];
nipkow@3413
   110
nipkow@3439
   111
goal Relation.thy "(r O s)^-1 = s^-1 O r^-1";
wenzelm@4423
   112
by (Blast_tac 1);
nipkow@3439
   113
qed "inverse_comp";
nipkow@1605
   114
paulson@4644
   115
goal Relation.thy "id^-1 = id";
paulson@4644
   116
by (Blast_tac 1);
paulson@4644
   117
qed "inverse_id";
paulson@4644
   118
Addsimps [inverse_id];
paulson@4644
   119
nipkow@1128
   120
(** Domain **)
nipkow@1128
   121
nipkow@1128
   122
qed_goalw "Domain_iff" Relation.thy [Domain_def]
nipkow@1128
   123
    "a: Domain(r) = (EX y. (a,y): r)"
paulson@2891
   124
 (fn _=> [ (Blast_tac 1) ]);
nipkow@1128
   125
nipkow@1128
   126
qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
nipkow@1128
   127
 (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
nipkow@1128
   128
nipkow@1128
   129
qed_goal "DomainE" Relation.thy
nipkow@1128
   130
    "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
nipkow@1128
   131
 (fn prems=>
nipkow@1128
   132
  [ (rtac (Domain_iff RS iffD1 RS exE) 1),
nipkow@1128
   133
    (REPEAT (ares_tac prems 1)) ]);
nipkow@1128
   134
paulson@1985
   135
AddIs  [DomainI];
paulson@1985
   136
AddSEs [DomainE];
paulson@1985
   137
paulson@4644
   138
goal thy "Domain id = UNIV";
paulson@4644
   139
by (Blast_tac 1);
paulson@4644
   140
qed "Domain_id";
paulson@4644
   141
Addsimps [Domain_id];
paulson@4644
   142
nipkow@1128
   143
(** Range **)
nipkow@1128
   144
nipkow@1128
   145
qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
nipkow@3439
   146
 (fn _ => [ (etac (inverseI RS DomainI) 1) ]);
nipkow@1128
   147
nipkow@1128
   148
qed_goalw "RangeE" Relation.thy [Range_def]
nipkow@1128
   149
    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
nipkow@1128
   150
 (fn major::prems=>
nipkow@1128
   151
  [ (rtac (major RS DomainE) 1),
nipkow@1128
   152
    (resolve_tac prems 1),
nipkow@3439
   153
    (etac inverseD 1) ]);
nipkow@1128
   154
paulson@1985
   155
AddIs  [RangeI];
paulson@1985
   156
AddSEs [RangeE];
paulson@1985
   157
paulson@4644
   158
goal thy "Range id = UNIV";
paulson@4644
   159
by (Blast_tac 1);
paulson@4644
   160
qed "Range_id";
paulson@4644
   161
Addsimps [Range_id];
paulson@4644
   162
nipkow@1128
   163
(*** Image of a set under a relation ***)
nipkow@1128
   164
nipkow@1128
   165
qed_goalw "Image_iff" Relation.thy [Image_def]
nipkow@1128
   166
    "b : r^^A = (? x:A. (x,b):r)"
paulson@2891
   167
 (fn _ => [ Blast_tac 1 ]);
nipkow@1128
   168
nipkow@1128
   169
qed_goal "Image_singleton_iff" Relation.thy
nipkow@1128
   170
    "(b : r^^{a}) = ((a,b):r)"
nipkow@1128
   171
 (fn _ => [ rtac (Image_iff RS trans) 1,
paulson@2891
   172
            Blast_tac 1 ]);
nipkow@1128
   173
nipkow@1128
   174
qed_goalw "ImageI" Relation.thy [Image_def]
nipkow@1128
   175
    "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
paulson@2891
   176
 (fn _ => [ (Blast_tac 1)]);
nipkow@1128
   177
nipkow@1128
   178
qed_goalw "ImageE" Relation.thy [Image_def]
nipkow@1128
   179
    "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
nipkow@1128
   180
 (fn major::prems=>
nipkow@1128
   181
  [ (rtac (major RS CollectE) 1),
paulson@3718
   182
    (Clarify_tac 1),
nipkow@1128
   183
    (rtac (hd prems) 1),
nipkow@1128
   184
    (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
nipkow@1128
   185
paulson@1985
   186
AddIs  [ImageI];
paulson@1985
   187
AddSEs [ImageE];
paulson@1985
   188
paulson@4593
   189
paulson@4593
   190
qed_goal "Image_empty" Relation.thy
paulson@4593
   191
    "R^^{} = {}"
paulson@4593
   192
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   193
paulson@4593
   194
Addsimps [Image_empty];
paulson@4593
   195
paulson@4601
   196
goal thy "id ^^ A = A";
paulson@4601
   197
by (Blast_tac 1);
paulson@4601
   198
qed "Image_id";
paulson@4601
   199
paulson@4601
   200
Addsimps [Image_id];
paulson@4601
   201
paulson@4593
   202
qed_goal "Image_Int_subset" Relation.thy
paulson@4593
   203
    "R ^^ (A Int B) <= R ^^ A Int R ^^ B"
paulson@4593
   204
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   205
paulson@4593
   206
qed_goal "Image_Un" Relation.thy
paulson@4593
   207
    "R ^^ (A Un B) = R ^^ A Un R ^^ B"
paulson@4593
   208
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   209
paulson@4593
   210
nipkow@1128
   211
qed_goal "Image_subset" Relation.thy
paulson@1642
   212
    "!!A B r. r <= A Times B ==> r^^C <= B"
nipkow@1128
   213
 (fn _ =>
nipkow@1128
   214
  [ (rtac subsetI 1),
nipkow@1128
   215
    (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
nipkow@1128
   216
nipkow@1694
   217
goal Relation.thy "R O id = R";
oheimb@4650
   218
by (Fast_tac 1);
nipkow@1694
   219
qed "R_O_id";
nipkow@1694
   220
nipkow@1694
   221
goal Relation.thy "id O R = R";
oheimb@4650
   222
by (Fast_tac 1);
nipkow@1694
   223
qed "id_O_R";
nipkow@1694
   224
nipkow@1694
   225
Addsimps [R_O_id,id_O_R];