src/HOL/Relation.ML
author paulson
Tue Dec 01 10:39:02 1998 +0100 (1998-12-01)
changeset 5998 b2ecd577b8a3
parent 5995 450cd1f0270b
child 6005 45186ec4d8b6
permissions -rw-r--r--
better version of Image_diag
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@5608
    11
Goalw [Id_def] "(a,a) : Id";  
paulson@2891
    12
by (Blast_tac 1);
nipkow@5608
    13
qed "IdI";
nipkow@1128
    14
nipkow@5608
    15
val major::prems = Goalw [Id_def]
nipkow@5608
    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@5608
    21
qed "IdE";
nipkow@1128
    22
nipkow@5608
    23
Goalw [Id_def] "(a,b):Id = (a=b)";
paulson@2891
    24
by (Blast_tac 1);
nipkow@5608
    25
qed "pair_in_Id_conv";
nipkow@5608
    26
Addsimps [pair_in_Id_conv];
nipkow@1128
    27
nipkow@1128
    28
paulson@5978
    29
(** Diagonal relation: indentity restricted to some set **)
paulson@5978
    30
paulson@5978
    31
(*** Equality : the diagonal relation ***)
paulson@5978
    32
paulson@5978
    33
Goalw [diag_def] "[| a=b;  a:A |] ==> (a,b) : diag(A)";
paulson@5978
    34
by (Blast_tac 1);
paulson@5978
    35
qed "diag_eqI";
paulson@5978
    36
paulson@5978
    37
val diagI = refl RS diag_eqI |> standard;
paulson@5978
    38
paulson@5978
    39
(*The general elimination rule*)
paulson@5978
    40
val major::prems = Goalw [diag_def]
paulson@5978
    41
    "[| c : diag(A);  \
paulson@5978
    42
\       !!x y. [| x:A;  c = (x,x) |] ==> P \
paulson@5978
    43
\    |] ==> P";
paulson@5978
    44
by (rtac (major RS UN_E) 1);
paulson@5978
    45
by (REPEAT (eresolve_tac [asm_rl,singletonE] 1 ORELSE resolve_tac prems 1));
paulson@5978
    46
qed "diagE";
paulson@5978
    47
paulson@5978
    48
AddSIs [diagI];
paulson@5978
    49
AddSEs [diagE];
paulson@5978
    50
paulson@5978
    51
Goal "((x,y) : diag A) = (x=y & x : A)";
paulson@5978
    52
by (Blast_tac 1);
paulson@5978
    53
qed "diag_iff";
paulson@5978
    54
paulson@5978
    55
Goal "diag(A) <= A Times A";
paulson@5978
    56
by (Blast_tac 1);
paulson@5995
    57
qed "diag_subset_Times";
paulson@5978
    58
paulson@5978
    59
paulson@5978
    60
nipkow@1128
    61
(** Composition of two relations **)
nipkow@1128
    62
wenzelm@5069
    63
Goalw [comp_def]
paulson@5148
    64
    "[| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
paulson@2891
    65
by (Blast_tac 1);
nipkow@1128
    66
qed "compI";
nipkow@1128
    67
nipkow@1128
    68
(*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
paulson@5316
    69
val prems = Goalw [comp_def]
nipkow@1128
    70
    "[| xz : r O s;  \
nipkow@1128
    71
\       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
nipkow@1128
    72
\    |] ==> P";
nipkow@1128
    73
by (cut_facts_tac prems 1);
paulson@1985
    74
by (REPEAT (eresolve_tac [CollectE, splitE, exE, conjE] 1 
paulson@1985
    75
     ORELSE ares_tac prems 1));
nipkow@1128
    76
qed "compE";
nipkow@1128
    77
paulson@5316
    78
val prems = Goal
nipkow@1128
    79
    "[| (a,c) : r O s;  \
nipkow@1128
    80
\       !!y. [| (a,y):s;  (y,c):r |] ==> P \
nipkow@1128
    81
\    |] ==> P";
nipkow@1128
    82
by (rtac compE 1);
nipkow@1128
    83
by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
nipkow@1128
    84
qed "compEpair";
nipkow@1128
    85
nipkow@5608
    86
AddIs [compI, IdI];
nipkow@5608
    87
AddSEs [compE, IdE];
berghofe@1754
    88
nipkow@5608
    89
Goal "R O Id = R";
paulson@4673
    90
by (Fast_tac 1);
nipkow@5608
    91
qed "R_O_Id";
paulson@4673
    92
nipkow@5608
    93
Goal "Id O R = R";
paulson@4673
    94
by (Fast_tac 1);
nipkow@5608
    95
qed "Id_O_R";
paulson@4673
    96
nipkow@5608
    97
Addsimps [R_O_Id,Id_O_R];
paulson@4673
    98
wenzelm@5069
    99
Goal "(R O S) O T = R O (S O T)";
nipkow@4830
   100
by (Blast_tac 1);
nipkow@4830
   101
qed "O_assoc";
nipkow@4830
   102
paulson@5143
   103
Goal "[| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
paulson@2891
   104
by (Blast_tac 1);
nipkow@1128
   105
qed "comp_mono";
nipkow@1128
   106
paulson@5148
   107
Goal "[| s <= A Times B;  r <= B Times C |] ==> (r O s) <= A Times C";
paulson@2891
   108
by (Blast_tac 1);
nipkow@1128
   109
qed "comp_subset_Sigma";
nipkow@1128
   110
nipkow@1128
   111
(** Natural deduction for trans(r) **)
nipkow@1128
   112
paulson@5316
   113
val prems = Goalw [trans_def]
nipkow@1128
   114
    "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
nipkow@1128
   115
by (REPEAT (ares_tac (prems@[allI,impI]) 1));
nipkow@1128
   116
qed "transI";
nipkow@1128
   117
paulson@5148
   118
Goalw [trans_def] "[| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
paulson@2891
   119
by (Blast_tac 1);
nipkow@1128
   120
qed "transD";
nipkow@1128
   121
nipkow@3439
   122
(** Natural deduction for r^-1 **)
nipkow@1128
   123
paulson@5143
   124
Goalw [converse_def] "((a,b): r^-1) = ((b,a):r)";
paulson@1985
   125
by (Simp_tac 1);
paulson@4746
   126
qed "converse_iff";
paulson@1985
   127
paulson@4746
   128
AddIffs [converse_iff];
paulson@1985
   129
paulson@5143
   130
Goalw [converse_def] "(a,b):r ==> (b,a): r^-1";
clasohm@1264
   131
by (Simp_tac 1);
paulson@4746
   132
qed "converseI";
nipkow@1128
   133
paulson@5143
   134
Goalw [converse_def] "(a,b) : r^-1 ==> (b,a) : r";
paulson@2891
   135
by (Blast_tac 1);
paulson@4746
   136
qed "converseD";
nipkow@1128
   137
paulson@4746
   138
(*More general than converseD, as it "splits" the member of the relation*)
paulson@4746
   139
qed_goalw "converseE" thy [converse_def]
nipkow@3439
   140
    "[| yx : r^-1;  \
nipkow@1128
   141
\       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
nipkow@1128
   142
\    |] ==> P"
nipkow@1128
   143
 (fn [major,minor]=>
nipkow@1128
   144
  [ (rtac (major RS CollectE) 1),
nipkow@1454
   145
    (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
nipkow@1128
   146
    (assume_tac 1) ]);
nipkow@1128
   147
paulson@4746
   148
AddSEs [converseE];
nipkow@1128
   149
wenzelm@5069
   150
Goalw [converse_def] "(r^-1)^-1 = r";
paulson@2891
   151
by (Blast_tac 1);
paulson@4746
   152
qed "converse_converse";
paulson@4746
   153
Addsimps [converse_converse];
nipkow@3413
   154
wenzelm@5069
   155
Goal "(r O s)^-1 = s^-1 O r^-1";
wenzelm@4423
   156
by (Blast_tac 1);
paulson@4746
   157
qed "converse_comp";
nipkow@1605
   158
nipkow@5608
   159
Goal "Id^-1 = Id";
paulson@4644
   160
by (Blast_tac 1);
nipkow@5608
   161
qed "converse_Id";
nipkow@5608
   162
Addsimps [converse_Id];
paulson@4644
   163
paulson@5995
   164
Goal "(diag A) ^-1 = diag A";
paulson@5995
   165
by (Blast_tac 1);
paulson@5995
   166
qed "converse_diag";
paulson@5995
   167
Addsimps [converse_diag];
paulson@5995
   168
nipkow@1128
   169
(** Domain **)
nipkow@1128
   170
paulson@5811
   171
Goalw [Domain_def] "a: Domain(r) = (EX y. (a,y): r)";
paulson@5811
   172
by (Blast_tac 1);
paulson@5811
   173
qed "Domain_iff";
nipkow@1128
   174
paulson@4673
   175
qed_goal "DomainI" thy "!!a b r. (a,b): r ==> a: Domain(r)"
nipkow@1128
   176
 (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
nipkow@1128
   177
paulson@4673
   178
qed_goal "DomainE" thy
nipkow@1128
   179
    "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
nipkow@1128
   180
 (fn prems=>
nipkow@1128
   181
  [ (rtac (Domain_iff RS iffD1 RS exE) 1),
nipkow@1128
   182
    (REPEAT (ares_tac prems 1)) ]);
nipkow@1128
   183
paulson@1985
   184
AddIs  [DomainI];
paulson@1985
   185
AddSEs [DomainE];
paulson@1985
   186
nipkow@5608
   187
Goal "Domain Id = UNIV";
paulson@4644
   188
by (Blast_tac 1);
nipkow@5608
   189
qed "Domain_Id";
nipkow@5608
   190
Addsimps [Domain_Id];
paulson@4644
   191
paulson@5978
   192
Goal "Domain (diag A) = A";
paulson@5978
   193
by Auto_tac;
paulson@5978
   194
qed "Domain_diag";
paulson@5978
   195
Addsimps [Domain_diag];
paulson@5978
   196
paulson@5811
   197
Goal "Domain(A Un B) = Domain(A) Un Domain(B)";
paulson@5811
   198
by (Blast_tac 1);
paulson@5811
   199
qed "Domain_Un_eq";
paulson@5811
   200
paulson@5811
   201
Goal "Domain(A Int B) <= Domain(A) Int Domain(B)";
paulson@5811
   202
by (Blast_tac 1);
paulson@5811
   203
qed "Domain_Int_subset";
paulson@5811
   204
paulson@5811
   205
Goal "Domain(A) - Domain(B) <= Domain(A - B)";
paulson@5811
   206
by (Blast_tac 1);
paulson@5811
   207
qed "Domain_Diff_subset";
paulson@5811
   208
paulson@5811
   209
nipkow@1128
   210
(** Range **)
nipkow@1128
   211
paulson@5811
   212
Goalw [Domain_def, Range_def] "a: Range(r) = (EX y. (y,a): r)";
paulson@5811
   213
by (Blast_tac 1);
paulson@5811
   214
qed "Range_iff";
paulson@5811
   215
paulson@4673
   216
qed_goalw "RangeI" thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
paulson@4746
   217
 (fn _ => [ (etac (converseI RS DomainI) 1) ]);
nipkow@1128
   218
paulson@4673
   219
qed_goalw "RangeE" thy [Range_def]
nipkow@1128
   220
    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
nipkow@1128
   221
 (fn major::prems=>
nipkow@1128
   222
  [ (rtac (major RS DomainE) 1),
nipkow@1128
   223
    (resolve_tac prems 1),
paulson@4746
   224
    (etac converseD 1) ]);
nipkow@1128
   225
paulson@1985
   226
AddIs  [RangeI];
paulson@1985
   227
AddSEs [RangeE];
paulson@1985
   228
nipkow@5608
   229
Goal "Range Id = UNIV";
paulson@4644
   230
by (Blast_tac 1);
nipkow@5608
   231
qed "Range_Id";
nipkow@5608
   232
Addsimps [Range_Id];
paulson@4644
   233
paulson@5995
   234
Goal "Range (diag A) = A";
paulson@5995
   235
by Auto_tac;
paulson@5995
   236
qed "Range_diag";
paulson@5995
   237
Addsimps [Range_diag];
paulson@5995
   238
paulson@5811
   239
Goal "Range(A Un B) = Range(A) Un Range(B)";
paulson@5811
   240
by (Blast_tac 1);
paulson@5811
   241
qed "Range_Un_eq";
paulson@5811
   242
paulson@5811
   243
Goal "Range(A Int B) <= Range(A) Int Range(B)";
paulson@5811
   244
by (Blast_tac 1);
paulson@5811
   245
qed "Range_Int_subset";
paulson@5811
   246
paulson@5811
   247
Goal "Range(A) - Range(B) <= Range(A - B)";
paulson@5811
   248
by (Blast_tac 1);
paulson@5811
   249
qed "Range_Diff_subset";
paulson@5811
   250
paulson@5811
   251
nipkow@1128
   252
(*** Image of a set under a relation ***)
nipkow@1128
   253
paulson@5649
   254
overload_1st_set "Relation.op ^^";
paulson@5335
   255
paulson@4673
   256
qed_goalw "Image_iff" thy [Image_def]
nipkow@1128
   257
    "b : r^^A = (? x:A. (x,b):r)"
paulson@2891
   258
 (fn _ => [ Blast_tac 1 ]);
nipkow@1128
   259
paulson@4673
   260
qed_goalw "Image_singleton" thy [Image_def]
paulson@4673
   261
    "r^^{a} = {b. (a,b):r}"
paulson@4673
   262
 (fn _ => [ Blast_tac 1 ]);
paulson@4673
   263
paulson@4673
   264
qed_goal "Image_singleton_iff" thy
nipkow@1128
   265
    "(b : r^^{a}) = ((a,b):r)"
nipkow@1128
   266
 (fn _ => [ rtac (Image_iff RS trans) 1,
paulson@2891
   267
            Blast_tac 1 ]);
nipkow@1128
   268
paulson@4673
   269
AddIffs [Image_singleton_iff];
paulson@4673
   270
paulson@4673
   271
qed_goalw "ImageI" thy [Image_def]
nipkow@1128
   272
    "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
paulson@2891
   273
 (fn _ => [ (Blast_tac 1)]);
nipkow@1128
   274
paulson@4673
   275
qed_goalw "ImageE" thy [Image_def]
nipkow@1128
   276
    "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
nipkow@1128
   277
 (fn major::prems=>
nipkow@1128
   278
  [ (rtac (major RS CollectE) 1),
paulson@3718
   279
    (Clarify_tac 1),
nipkow@1128
   280
    (rtac (hd prems) 1),
nipkow@1128
   281
    (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
nipkow@1128
   282
paulson@1985
   283
AddIs  [ImageI];
paulson@1985
   284
AddSEs [ImageE];
paulson@1985
   285
paulson@4593
   286
paulson@4673
   287
qed_goal "Image_empty" thy
paulson@4593
   288
    "R^^{} = {}"
paulson@4593
   289
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   290
paulson@4593
   291
Addsimps [Image_empty];
paulson@4593
   292
nipkow@5608
   293
Goal "Id ^^ A = A";
paulson@4601
   294
by (Blast_tac 1);
nipkow@5608
   295
qed "Image_Id";
paulson@4601
   296
paulson@5998
   297
Goal "diag A ^^ B = A Int B";
paulson@5995
   298
by (Blast_tac 1);
paulson@5995
   299
qed "Image_diag";
paulson@5995
   300
paulson@5995
   301
Addsimps [Image_Id, Image_diag];
paulson@4601
   302
paulson@4673
   303
qed_goal "Image_Int_subset" thy
paulson@4593
   304
    "R ^^ (A Int B) <= R ^^ A Int R ^^ B"
paulson@4593
   305
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   306
paulson@4733
   307
qed_goal "Image_Un" thy "R ^^ (A Un B) = R ^^ A Un R ^^ B"
paulson@4593
   308
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   309
paulson@4733
   310
qed_goal "Image_subset" thy "!!A B r. r <= A Times B ==> r^^C <= B"
nipkow@1128
   311
 (fn _ =>
nipkow@1128
   312
  [ (rtac subsetI 1),
nipkow@1128
   313
    (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
nipkow@1128
   314
paulson@4733
   315
(*NOT suitable for rewriting*)
wenzelm@5069
   316
Goal "r^^B = (UN y: B. r^^{y})";
paulson@4673
   317
by (Blast_tac 1);
paulson@4733
   318
qed "Image_eq_UN";
oheimb@4760
   319
oheimb@4760
   320
oheimb@4760
   321
section "Univalent";
oheimb@4760
   322
oheimb@4760
   323
qed_goalw "UnivalentI" Relation.thy [Univalent_def] 
oheimb@4760
   324
   "!!r. !x y. (x,y):r --> (!z. (x,z):r --> y=z) ==> Univalent r" (K [atac 1]);
oheimb@4760
   325
oheimb@4760
   326
qed_goalw "UnivalentD" Relation.thy [Univalent_def] 
oheimb@4760
   327
	"!!r. [| Univalent r; (x,y):r; (x,z):r|] ==> y=z" (K [Auto_tac]);
paulson@5231
   328
paulson@5231
   329
paulson@5231
   330
(** Graphs of partial functions **)
paulson@5231
   331
paulson@5231
   332
Goal "Domain{(x,y). y = f x & P x} = {x. P x}";
paulson@5231
   333
by (Blast_tac 1);
paulson@5231
   334
qed "Domain_partial_func";
paulson@5231
   335
paulson@5231
   336
Goal "Range{(x,y). y = f x & P x} = f``{x. P x}";
paulson@5231
   337
by (Blast_tac 1);
paulson@5231
   338
qed "Range_partial_func";
paulson@5231
   339