src/HOL/Relation.ML
author paulson
Fri Nov 27 10:40:29 1998 +0100 (1998-11-27)
changeset 5978 fa2c2dd74f8c
parent 5811 0867068942e6
child 5995 450cd1f0270b
permissions -rw-r--r--
moved diag (diagonal relation) from Univ to Relation
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@5978
    57
qed "diag_subset_Sigma";
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
nipkow@1128
   164
(** Domain **)
nipkow@1128
   165
paulson@5811
   166
Goalw [Domain_def] "a: Domain(r) = (EX y. (a,y): r)";
paulson@5811
   167
by (Blast_tac 1);
paulson@5811
   168
qed "Domain_iff";
nipkow@1128
   169
paulson@4673
   170
qed_goal "DomainI" thy "!!a b r. (a,b): r ==> a: Domain(r)"
nipkow@1128
   171
 (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
nipkow@1128
   172
paulson@4673
   173
qed_goal "DomainE" thy
nipkow@1128
   174
    "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
nipkow@1128
   175
 (fn prems=>
nipkow@1128
   176
  [ (rtac (Domain_iff RS iffD1 RS exE) 1),
nipkow@1128
   177
    (REPEAT (ares_tac prems 1)) ]);
nipkow@1128
   178
paulson@1985
   179
AddIs  [DomainI];
paulson@1985
   180
AddSEs [DomainE];
paulson@1985
   181
nipkow@5608
   182
Goal "Domain Id = UNIV";
paulson@4644
   183
by (Blast_tac 1);
nipkow@5608
   184
qed "Domain_Id";
nipkow@5608
   185
Addsimps [Domain_Id];
paulson@4644
   186
paulson@5978
   187
Goal "Domain (diag A) = A";
paulson@5978
   188
by Auto_tac;
paulson@5978
   189
qed "Domain_diag";
paulson@5978
   190
Addsimps [Domain_diag];
paulson@5978
   191
paulson@5811
   192
Goal "Domain(A Un B) = Domain(A) Un Domain(B)";
paulson@5811
   193
by (Blast_tac 1);
paulson@5811
   194
qed "Domain_Un_eq";
paulson@5811
   195
paulson@5811
   196
Goal "Domain(A Int B) <= Domain(A) Int Domain(B)";
paulson@5811
   197
by (Blast_tac 1);
paulson@5811
   198
qed "Domain_Int_subset";
paulson@5811
   199
paulson@5811
   200
Goal "Domain(A) - Domain(B) <= Domain(A - B)";
paulson@5811
   201
by (Blast_tac 1);
paulson@5811
   202
qed "Domain_Diff_subset";
paulson@5811
   203
paulson@5811
   204
nipkow@1128
   205
(** Range **)
nipkow@1128
   206
paulson@5811
   207
Goalw [Domain_def, Range_def] "a: Range(r) = (EX y. (y,a): r)";
paulson@5811
   208
by (Blast_tac 1);
paulson@5811
   209
qed "Range_iff";
paulson@5811
   210
paulson@4673
   211
qed_goalw "RangeI" thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
paulson@4746
   212
 (fn _ => [ (etac (converseI RS DomainI) 1) ]);
nipkow@1128
   213
paulson@4673
   214
qed_goalw "RangeE" thy [Range_def]
nipkow@1128
   215
    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
nipkow@1128
   216
 (fn major::prems=>
nipkow@1128
   217
  [ (rtac (major RS DomainE) 1),
nipkow@1128
   218
    (resolve_tac prems 1),
paulson@4746
   219
    (etac converseD 1) ]);
nipkow@1128
   220
paulson@1985
   221
AddIs  [RangeI];
paulson@1985
   222
AddSEs [RangeE];
paulson@1985
   223
nipkow@5608
   224
Goal "Range Id = UNIV";
paulson@4644
   225
by (Blast_tac 1);
nipkow@5608
   226
qed "Range_Id";
nipkow@5608
   227
Addsimps [Range_Id];
paulson@4644
   228
paulson@5811
   229
Goal "Range(A Un B) = Range(A) Un Range(B)";
paulson@5811
   230
by (Blast_tac 1);
paulson@5811
   231
qed "Range_Un_eq";
paulson@5811
   232
paulson@5811
   233
Goal "Range(A Int B) <= Range(A) Int Range(B)";
paulson@5811
   234
by (Blast_tac 1);
paulson@5811
   235
qed "Range_Int_subset";
paulson@5811
   236
paulson@5811
   237
Goal "Range(A) - Range(B) <= Range(A - B)";
paulson@5811
   238
by (Blast_tac 1);
paulson@5811
   239
qed "Range_Diff_subset";
paulson@5811
   240
paulson@5811
   241
nipkow@1128
   242
(*** Image of a set under a relation ***)
nipkow@1128
   243
paulson@5649
   244
overload_1st_set "Relation.op ^^";
paulson@5335
   245
paulson@4673
   246
qed_goalw "Image_iff" thy [Image_def]
nipkow@1128
   247
    "b : r^^A = (? x:A. (x,b):r)"
paulson@2891
   248
 (fn _ => [ Blast_tac 1 ]);
nipkow@1128
   249
paulson@4673
   250
qed_goalw "Image_singleton" thy [Image_def]
paulson@4673
   251
    "r^^{a} = {b. (a,b):r}"
paulson@4673
   252
 (fn _ => [ Blast_tac 1 ]);
paulson@4673
   253
paulson@4673
   254
qed_goal "Image_singleton_iff" thy
nipkow@1128
   255
    "(b : r^^{a}) = ((a,b):r)"
nipkow@1128
   256
 (fn _ => [ rtac (Image_iff RS trans) 1,
paulson@2891
   257
            Blast_tac 1 ]);
nipkow@1128
   258
paulson@4673
   259
AddIffs [Image_singleton_iff];
paulson@4673
   260
paulson@4673
   261
qed_goalw "ImageI" thy [Image_def]
nipkow@1128
   262
    "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
paulson@2891
   263
 (fn _ => [ (Blast_tac 1)]);
nipkow@1128
   264
paulson@4673
   265
qed_goalw "ImageE" thy [Image_def]
nipkow@1128
   266
    "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
nipkow@1128
   267
 (fn major::prems=>
nipkow@1128
   268
  [ (rtac (major RS CollectE) 1),
paulson@3718
   269
    (Clarify_tac 1),
nipkow@1128
   270
    (rtac (hd prems) 1),
nipkow@1128
   271
    (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
nipkow@1128
   272
paulson@1985
   273
AddIs  [ImageI];
paulson@1985
   274
AddSEs [ImageE];
paulson@1985
   275
paulson@4593
   276
paulson@4673
   277
qed_goal "Image_empty" thy
paulson@4593
   278
    "R^^{} = {}"
paulson@4593
   279
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   280
paulson@4593
   281
Addsimps [Image_empty];
paulson@4593
   282
nipkow@5608
   283
Goal "Id ^^ A = A";
paulson@4601
   284
by (Blast_tac 1);
nipkow@5608
   285
qed "Image_Id";
paulson@4601
   286
nipkow@5608
   287
Addsimps [Image_Id];
paulson@4601
   288
paulson@4673
   289
qed_goal "Image_Int_subset" thy
paulson@4593
   290
    "R ^^ (A Int B) <= R ^^ A Int R ^^ B"
paulson@4593
   291
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   292
paulson@4733
   293
qed_goal "Image_Un" thy "R ^^ (A Un B) = R ^^ A Un R ^^ B"
paulson@4593
   294
 (fn _ => [ Blast_tac 1 ]);
paulson@4593
   295
paulson@4733
   296
qed_goal "Image_subset" thy "!!A B r. r <= A Times B ==> r^^C <= B"
nipkow@1128
   297
 (fn _ =>
nipkow@1128
   298
  [ (rtac subsetI 1),
nipkow@1128
   299
    (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
nipkow@1128
   300
paulson@4733
   301
(*NOT suitable for rewriting*)
wenzelm@5069
   302
Goal "r^^B = (UN y: B. r^^{y})";
paulson@4673
   303
by (Blast_tac 1);
paulson@4733
   304
qed "Image_eq_UN";
oheimb@4760
   305
oheimb@4760
   306
oheimb@4760
   307
section "Univalent";
oheimb@4760
   308
oheimb@4760
   309
qed_goalw "UnivalentI" Relation.thy [Univalent_def] 
oheimb@4760
   310
   "!!r. !x y. (x,y):r --> (!z. (x,z):r --> y=z) ==> Univalent r" (K [atac 1]);
oheimb@4760
   311
oheimb@4760
   312
qed_goalw "UnivalentD" Relation.thy [Univalent_def] 
oheimb@4760
   313
	"!!r. [| Univalent r; (x,y):r; (x,z):r|] ==> y=z" (K [Auto_tac]);
paulson@5231
   314
paulson@5231
   315
paulson@5231
   316
(** Graphs of partial functions **)
paulson@5231
   317
paulson@5231
   318
Goal "Domain{(x,y). y = f x & P x} = {x. P x}";
paulson@5231
   319
by (Blast_tac 1);
paulson@5231
   320
qed "Domain_partial_func";
paulson@5231
   321
paulson@5231
   322
Goal "Range{(x,y). y = f x & P x} = f``{x. P x}";
paulson@5231
   323
by (Blast_tac 1);
paulson@5231
   324
qed "Range_partial_func";
paulson@5231
   325