src/HOL/Relation.ML
author paulson
Thu Feb 05 10:48:43 1998 +0100 (1998-02-05)
changeset 4601 87fc0d44b837
parent 4593 6fc8f224655f
child 4644 ecf8f17f6fe0
permissions -rw-r--r--
New theorem Image_id
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
nipkow@1128
   115
(** Domain **)
nipkow@1128
   116
nipkow@1128
   117
qed_goalw "Domain_iff" Relation.thy [Domain_def]
nipkow@1128
   118
    "a: Domain(r) = (EX y. (a,y): r)"
paulson@2891
   119
 (fn _=> [ (Blast_tac 1) ]);
nipkow@1128
   120
nipkow@1128
   121
qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
nipkow@1128
   122
 (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
nipkow@1128
   123
nipkow@1128
   124
qed_goal "DomainE" Relation.thy
nipkow@1128
   125
    "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
nipkow@1128
   126
 (fn prems=>
nipkow@1128
   127
  [ (rtac (Domain_iff RS iffD1 RS exE) 1),
nipkow@1128
   128
    (REPEAT (ares_tac prems 1)) ]);
nipkow@1128
   129
paulson@1985
   130
AddIs  [DomainI];
paulson@1985
   131
AddSEs [DomainE];
paulson@1985
   132
nipkow@1128
   133
(** Range **)
nipkow@1128
   134
nipkow@1128
   135
qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
nipkow@3439
   136
 (fn _ => [ (etac (inverseI RS DomainI) 1) ]);
nipkow@1128
   137
nipkow@1128
   138
qed_goalw "RangeE" Relation.thy [Range_def]
nipkow@1128
   139
    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
nipkow@1128
   140
 (fn major::prems=>
nipkow@1128
   141
  [ (rtac (major RS DomainE) 1),
nipkow@1128
   142
    (resolve_tac prems 1),
nipkow@3439
   143
    (etac inverseD 1) ]);
nipkow@1128
   144
paulson@1985
   145
AddIs  [RangeI];
paulson@1985
   146
AddSEs [RangeE];
paulson@1985
   147
nipkow@1128
   148
(*** Image of a set under a relation ***)
nipkow@1128
   149
nipkow@1128
   150
qed_goalw "Image_iff" Relation.thy [Image_def]
nipkow@1128
   151
    "b : r^^A = (? x:A. (x,b):r)"
paulson@2891
   152
 (fn _ => [ Blast_tac 1 ]);
nipkow@1128
   153
nipkow@1128
   154
qed_goal "Image_singleton_iff" Relation.thy
nipkow@1128
   155
    "(b : r^^{a}) = ((a,b):r)"
nipkow@1128
   156
 (fn _ => [ rtac (Image_iff RS trans) 1,
paulson@2891
   157
            Blast_tac 1 ]);
nipkow@1128
   158
nipkow@1128
   159
qed_goalw "ImageI" Relation.thy [Image_def]
nipkow@1128
   160
    "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
paulson@2891
   161
 (fn _ => [ (Blast_tac 1)]);
nipkow@1128
   162
nipkow@1128
   163
qed_goalw "ImageE" Relation.thy [Image_def]
nipkow@1128
   164
    "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
nipkow@1128
   165
 (fn major::prems=>
nipkow@1128
   166
  [ (rtac (major RS CollectE) 1),
paulson@3718
   167
    (Clarify_tac 1),
nipkow@1128
   168
    (rtac (hd prems) 1),
nipkow@1128
   169
    (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
nipkow@1128
   170
paulson@1985
   171
AddIs  [ImageI];
paulson@1985
   172
AddSEs [ImageE];
paulson@1985
   173
paulson@4593
   174
paulson@4593
   175
qed_goal "Image_empty" Relation.thy
paulson@4593
   176
    "R^^{} = {}"
paulson@4593
   177
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   178
paulson@4593
   179
Addsimps [Image_empty];
paulson@4593
   180
paulson@4601
   181
goal thy "id ^^ A = A";
paulson@4601
   182
by (Blast_tac 1);
paulson@4601
   183
qed "Image_id";
paulson@4601
   184
paulson@4601
   185
Addsimps [Image_id];
paulson@4601
   186
paulson@4593
   187
qed_goal "Image_Int_subset" Relation.thy
paulson@4593
   188
    "R ^^ (A Int B) <= R ^^ A Int R ^^ B"
paulson@4593
   189
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   190
paulson@4593
   191
qed_goal "Image_Un" Relation.thy
paulson@4593
   192
    "R ^^ (A Un B) = R ^^ A Un R ^^ B"
paulson@4593
   193
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   194
paulson@4593
   195
nipkow@1128
   196
qed_goal "Image_subset" Relation.thy
paulson@1642
   197
    "!!A B r. r <= A Times B ==> r^^C <= B"
nipkow@1128
   198
 (fn _ =>
nipkow@1128
   199
  [ (rtac subsetI 1),
nipkow@1128
   200
    (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
nipkow@1128
   201
nipkow@1694
   202
goal Relation.thy "R O id = R";
wenzelm@4089
   203
by (fast_tac (claset() addbefore split_all_tac) 1);
nipkow@1694
   204
qed "R_O_id";
nipkow@1694
   205
nipkow@1694
   206
goal Relation.thy "id O R = R";
wenzelm@4089
   207
by (fast_tac (claset() addbefore split_all_tac) 1);
nipkow@1694
   208
qed "id_O_R";
nipkow@1694
   209
nipkow@1694
   210
Addsimps [R_O_id,id_O_R];