src/HOL/Relation.ML
author nipkow
Mon Apr 27 16:45:11 1998 +0200 (1998-04-27)
changeset 4830 bd73675adbed
parent 4760 9cdbd5a1d25a
child 5069 3ea049f7979d
permissions -rw-r--r--
Added a few lemmas.
Renamed expand_const -> split_const.
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
paulson@4673
    11
goalw thy [id_def] "(a,a) : id";  
paulson@2891
    12
by (Blast_tac 1);
nipkow@1128
    13
qed "idI";
nipkow@1128
    14
paulson@4673
    15
val major::prems = goalw 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
paulson@4673
    23
goalw 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@4673
    31
goalw 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*)
paulson@4673
    37
val prems = goalw 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
paulson@4673
    46
val prems = goal 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
paulson@4673
    57
goal thy "R O id = R";
paulson@4673
    58
by (Fast_tac 1);
paulson@4673
    59
qed "R_O_id";
paulson@4673
    60
paulson@4673
    61
goal thy "id O R = R";
paulson@4673
    62
by (Fast_tac 1);
paulson@4673
    63
qed "id_O_R";
paulson@4673
    64
paulson@4673
    65
Addsimps [R_O_id,id_O_R];
paulson@4673
    66
nipkow@4830
    67
goal thy "(R O S) O T = R O (S O T)";
nipkow@4830
    68
by (Blast_tac 1);
nipkow@4830
    69
qed "O_assoc";
nipkow@4830
    70
paulson@4673
    71
goal thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
paulson@2891
    72
by (Blast_tac 1);
nipkow@1128
    73
qed "comp_mono";
nipkow@1128
    74
paulson@4673
    75
goal thy
paulson@1985
    76
    "!!r s. [| s <= A Times B;  r <= B Times C |] ==> (r O s) <= A Times C";
paulson@2891
    77
by (Blast_tac 1);
nipkow@1128
    78
qed "comp_subset_Sigma";
nipkow@1128
    79
nipkow@1128
    80
(** Natural deduction for trans(r) **)
nipkow@1128
    81
paulson@4673
    82
val prems = goalw thy [trans_def]
nipkow@1128
    83
    "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
nipkow@1128
    84
by (REPEAT (ares_tac (prems@[allI,impI]) 1));
nipkow@1128
    85
qed "transI";
nipkow@1128
    86
paulson@4673
    87
goalw thy [trans_def]
paulson@1985
    88
    "!!r. [| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
paulson@2891
    89
by (Blast_tac 1);
nipkow@1128
    90
qed "transD";
nipkow@1128
    91
nipkow@3439
    92
(** Natural deduction for r^-1 **)
nipkow@1128
    93
paulson@4746
    94
goalw thy [converse_def] "!!a b r. ((a,b): r^-1) = ((b,a):r)";
paulson@1985
    95
by (Simp_tac 1);
paulson@4746
    96
qed "converse_iff";
paulson@1985
    97
paulson@4746
    98
AddIffs [converse_iff];
paulson@1985
    99
paulson@4746
   100
goalw thy [converse_def] "!!a b r. (a,b):r ==> (b,a): r^-1";
clasohm@1264
   101
by (Simp_tac 1);
paulson@4746
   102
qed "converseI";
nipkow@1128
   103
paulson@4746
   104
goalw thy [converse_def] "!!a b r. (a,b) : r^-1 ==> (b,a) : r";
paulson@2891
   105
by (Blast_tac 1);
paulson@4746
   106
qed "converseD";
nipkow@1128
   107
paulson@4746
   108
(*More general than converseD, as it "splits" the member of the relation*)
paulson@4746
   109
qed_goalw "converseE" thy [converse_def]
nipkow@3439
   110
    "[| yx : r^-1;  \
nipkow@1128
   111
\       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
nipkow@1128
   112
\    |] ==> P"
nipkow@1128
   113
 (fn [major,minor]=>
nipkow@1128
   114
  [ (rtac (major RS CollectE) 1),
nipkow@1454
   115
    (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
nipkow@1128
   116
    (assume_tac 1) ]);
nipkow@1128
   117
paulson@4746
   118
AddSEs [converseE];
nipkow@1128
   119
paulson@4746
   120
goalw thy [converse_def] "(r^-1)^-1 = r";
paulson@2891
   121
by (Blast_tac 1);
paulson@4746
   122
qed "converse_converse";
paulson@4746
   123
Addsimps [converse_converse];
nipkow@3413
   124
paulson@4673
   125
goal thy "(r O s)^-1 = s^-1 O r^-1";
wenzelm@4423
   126
by (Blast_tac 1);
paulson@4746
   127
qed "converse_comp";
nipkow@1605
   128
paulson@4673
   129
goal thy "id^-1 = id";
paulson@4644
   130
by (Blast_tac 1);
paulson@4746
   131
qed "converse_id";
paulson@4746
   132
Addsimps [converse_id];
paulson@4644
   133
nipkow@1128
   134
(** Domain **)
nipkow@1128
   135
paulson@4673
   136
qed_goalw "Domain_iff" thy [Domain_def]
nipkow@1128
   137
    "a: Domain(r) = (EX y. (a,y): r)"
paulson@2891
   138
 (fn _=> [ (Blast_tac 1) ]);
nipkow@1128
   139
paulson@4673
   140
qed_goal "DomainI" thy "!!a b r. (a,b): r ==> a: Domain(r)"
nipkow@1128
   141
 (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
nipkow@1128
   142
paulson@4673
   143
qed_goal "DomainE" thy
nipkow@1128
   144
    "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
nipkow@1128
   145
 (fn prems=>
nipkow@1128
   146
  [ (rtac (Domain_iff RS iffD1 RS exE) 1),
nipkow@1128
   147
    (REPEAT (ares_tac prems 1)) ]);
nipkow@1128
   148
paulson@1985
   149
AddIs  [DomainI];
paulson@1985
   150
AddSEs [DomainE];
paulson@1985
   151
paulson@4644
   152
goal thy "Domain id = UNIV";
paulson@4644
   153
by (Blast_tac 1);
paulson@4644
   154
qed "Domain_id";
paulson@4644
   155
Addsimps [Domain_id];
paulson@4644
   156
nipkow@1128
   157
(** Range **)
nipkow@1128
   158
paulson@4673
   159
qed_goalw "RangeI" thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
paulson@4746
   160
 (fn _ => [ (etac (converseI RS DomainI) 1) ]);
nipkow@1128
   161
paulson@4673
   162
qed_goalw "RangeE" thy [Range_def]
nipkow@1128
   163
    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
nipkow@1128
   164
 (fn major::prems=>
nipkow@1128
   165
  [ (rtac (major RS DomainE) 1),
nipkow@1128
   166
    (resolve_tac prems 1),
paulson@4746
   167
    (etac converseD 1) ]);
nipkow@1128
   168
paulson@1985
   169
AddIs  [RangeI];
paulson@1985
   170
AddSEs [RangeE];
paulson@1985
   171
paulson@4644
   172
goal thy "Range id = UNIV";
paulson@4644
   173
by (Blast_tac 1);
paulson@4644
   174
qed "Range_id";
paulson@4644
   175
Addsimps [Range_id];
paulson@4644
   176
nipkow@1128
   177
(*** Image of a set under a relation ***)
nipkow@1128
   178
paulson@4673
   179
qed_goalw "Image_iff" thy [Image_def]
nipkow@1128
   180
    "b : r^^A = (? x:A. (x,b):r)"
paulson@2891
   181
 (fn _ => [ Blast_tac 1 ]);
nipkow@1128
   182
paulson@4673
   183
qed_goalw "Image_singleton" thy [Image_def]
paulson@4673
   184
    "r^^{a} = {b. (a,b):r}"
paulson@4673
   185
 (fn _ => [ Blast_tac 1 ]);
paulson@4673
   186
paulson@4673
   187
qed_goal "Image_singleton_iff" thy
nipkow@1128
   188
    "(b : r^^{a}) = ((a,b):r)"
nipkow@1128
   189
 (fn _ => [ rtac (Image_iff RS trans) 1,
paulson@2891
   190
            Blast_tac 1 ]);
nipkow@1128
   191
paulson@4673
   192
AddIffs [Image_singleton_iff];
paulson@4673
   193
paulson@4673
   194
qed_goalw "ImageI" thy [Image_def]
nipkow@1128
   195
    "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
paulson@2891
   196
 (fn _ => [ (Blast_tac 1)]);
nipkow@1128
   197
paulson@4673
   198
qed_goalw "ImageE" thy [Image_def]
nipkow@1128
   199
    "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
nipkow@1128
   200
 (fn major::prems=>
nipkow@1128
   201
  [ (rtac (major RS CollectE) 1),
paulson@3718
   202
    (Clarify_tac 1),
nipkow@1128
   203
    (rtac (hd prems) 1),
nipkow@1128
   204
    (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
nipkow@1128
   205
paulson@1985
   206
AddIs  [ImageI];
paulson@1985
   207
AddSEs [ImageE];
paulson@1985
   208
paulson@4593
   209
paulson@4673
   210
qed_goal "Image_empty" thy
paulson@4593
   211
    "R^^{} = {}"
paulson@4593
   212
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   213
paulson@4593
   214
Addsimps [Image_empty];
paulson@4593
   215
paulson@4601
   216
goal thy "id ^^ A = A";
paulson@4601
   217
by (Blast_tac 1);
paulson@4601
   218
qed "Image_id";
paulson@4601
   219
paulson@4601
   220
Addsimps [Image_id];
paulson@4601
   221
paulson@4673
   222
qed_goal "Image_Int_subset" thy
paulson@4593
   223
    "R ^^ (A Int B) <= R ^^ A Int R ^^ B"
paulson@4593
   224
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   225
paulson@4733
   226
qed_goal "Image_Un" thy "R ^^ (A Un B) = R ^^ A Un R ^^ B"
paulson@4593
   227
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   228
paulson@4733
   229
qed_goal "Image_subset" thy "!!A B r. r <= A Times B ==> r^^C <= B"
nipkow@1128
   230
 (fn _ =>
nipkow@1128
   231
  [ (rtac subsetI 1),
nipkow@1128
   232
    (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
nipkow@1128
   233
paulson@4733
   234
(*NOT suitable for rewriting*)
paulson@4733
   235
goal thy "r^^B = (UN y: B. r^^{y})";
paulson@4673
   236
by (Blast_tac 1);
paulson@4733
   237
qed "Image_eq_UN";
oheimb@4760
   238
oheimb@4760
   239
oheimb@4760
   240
section "Univalent";
oheimb@4760
   241
oheimb@4760
   242
qed_goalw "UnivalentI" Relation.thy [Univalent_def] 
oheimb@4760
   243
   "!!r. !x y. (x,y):r --> (!z. (x,z):r --> y=z) ==> Univalent r" (K [atac 1]);
oheimb@4760
   244
oheimb@4760
   245
qed_goalw "UnivalentD" Relation.thy [Univalent_def] 
oheimb@4760
   246
	"!!r. [| Univalent r; (x,y):r; (x,z):r|] ==> y=z" (K [Auto_tac]);