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