src/HOL/Relation.ML
author paulson
Wed Aug 19 10:27:00 1998 +0200 (1998-08-19)
changeset 5335 07fb8999de62
parent 5316 7a8975451a89
child 5608 a82a038a3e7a
permissions -rw-r--r--
Overloading decl should assist Blast_tac
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
wenzelm@5069
    11
Goalw [id_def] "(a,a) : id";  
paulson@2891
    12
by (Blast_tac 1);
nipkow@1128
    13
qed "idI";
nipkow@1128
    14
paulson@5316
    15
val major::prems = Goalw [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
wenzelm@5069
    23
Goalw [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
wenzelm@5069
    31
Goalw [comp_def]
paulson@5148
    32
    "[| (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@5316
    37
val prems = Goalw [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@5316
    46
val prems = Goal
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
wenzelm@5069
    57
Goal "R O id = R";
paulson@4673
    58
by (Fast_tac 1);
paulson@4673
    59
qed "R_O_id";
paulson@4673
    60
wenzelm@5069
    61
Goal "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
wenzelm@5069
    67
Goal "(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@5143
    71
Goal "[| 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@5148
    75
Goal "[| s <= A Times B;  r <= B Times C |] ==> (r O s) <= A Times C";
paulson@2891
    76
by (Blast_tac 1);
nipkow@1128
    77
qed "comp_subset_Sigma";
nipkow@1128
    78
nipkow@1128
    79
(** Natural deduction for trans(r) **)
nipkow@1128
    80
paulson@5316
    81
val prems = Goalw [trans_def]
nipkow@1128
    82
    "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
nipkow@1128
    83
by (REPEAT (ares_tac (prems@[allI,impI]) 1));
nipkow@1128
    84
qed "transI";
nipkow@1128
    85
paulson@5148
    86
Goalw [trans_def] "[| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
paulson@2891
    87
by (Blast_tac 1);
nipkow@1128
    88
qed "transD";
nipkow@1128
    89
nipkow@3439
    90
(** Natural deduction for r^-1 **)
nipkow@1128
    91
paulson@5143
    92
Goalw [converse_def] "((a,b): r^-1) = ((b,a):r)";
paulson@1985
    93
by (Simp_tac 1);
paulson@4746
    94
qed "converse_iff";
paulson@1985
    95
paulson@4746
    96
AddIffs [converse_iff];
paulson@1985
    97
paulson@5143
    98
Goalw [converse_def] "(a,b):r ==> (b,a): r^-1";
clasohm@1264
    99
by (Simp_tac 1);
paulson@4746
   100
qed "converseI";
nipkow@1128
   101
paulson@5143
   102
Goalw [converse_def] "(a,b) : r^-1 ==> (b,a) : r";
paulson@2891
   103
by (Blast_tac 1);
paulson@4746
   104
qed "converseD";
nipkow@1128
   105
paulson@4746
   106
(*More general than converseD, as it "splits" the member of the relation*)
paulson@4746
   107
qed_goalw "converseE" thy [converse_def]
nipkow@3439
   108
    "[| yx : r^-1;  \
nipkow@1128
   109
\       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
nipkow@1128
   110
\    |] ==> P"
nipkow@1128
   111
 (fn [major,minor]=>
nipkow@1128
   112
  [ (rtac (major RS CollectE) 1),
nipkow@1454
   113
    (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
nipkow@1128
   114
    (assume_tac 1) ]);
nipkow@1128
   115
paulson@4746
   116
AddSEs [converseE];
nipkow@1128
   117
wenzelm@5069
   118
Goalw [converse_def] "(r^-1)^-1 = r";
paulson@2891
   119
by (Blast_tac 1);
paulson@4746
   120
qed "converse_converse";
paulson@4746
   121
Addsimps [converse_converse];
nipkow@3413
   122
wenzelm@5069
   123
Goal "(r O s)^-1 = s^-1 O r^-1";
wenzelm@4423
   124
by (Blast_tac 1);
paulson@4746
   125
qed "converse_comp";
nipkow@1605
   126
wenzelm@5069
   127
Goal "id^-1 = id";
paulson@4644
   128
by (Blast_tac 1);
paulson@4746
   129
qed "converse_id";
paulson@4746
   130
Addsimps [converse_id];
paulson@4644
   131
nipkow@1128
   132
(** Domain **)
nipkow@1128
   133
paulson@4673
   134
qed_goalw "Domain_iff" thy [Domain_def]
nipkow@1128
   135
    "a: Domain(r) = (EX y. (a,y): r)"
paulson@2891
   136
 (fn _=> [ (Blast_tac 1) ]);
nipkow@1128
   137
paulson@4673
   138
qed_goal "DomainI" thy "!!a b r. (a,b): r ==> a: Domain(r)"
nipkow@1128
   139
 (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
nipkow@1128
   140
paulson@4673
   141
qed_goal "DomainE" thy
nipkow@1128
   142
    "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
nipkow@1128
   143
 (fn prems=>
nipkow@1128
   144
  [ (rtac (Domain_iff RS iffD1 RS exE) 1),
nipkow@1128
   145
    (REPEAT (ares_tac prems 1)) ]);
nipkow@1128
   146
paulson@1985
   147
AddIs  [DomainI];
paulson@1985
   148
AddSEs [DomainE];
paulson@1985
   149
wenzelm@5069
   150
Goal "Domain id = UNIV";
paulson@4644
   151
by (Blast_tac 1);
paulson@4644
   152
qed "Domain_id";
paulson@4644
   153
Addsimps [Domain_id];
paulson@4644
   154
nipkow@1128
   155
(** Range **)
nipkow@1128
   156
paulson@4673
   157
qed_goalw "RangeI" thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
paulson@4746
   158
 (fn _ => [ (etac (converseI RS DomainI) 1) ]);
nipkow@1128
   159
paulson@4673
   160
qed_goalw "RangeE" thy [Range_def]
nipkow@1128
   161
    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
nipkow@1128
   162
 (fn major::prems=>
nipkow@1128
   163
  [ (rtac (major RS DomainE) 1),
nipkow@1128
   164
    (resolve_tac prems 1),
paulson@4746
   165
    (etac converseD 1) ]);
nipkow@1128
   166
paulson@1985
   167
AddIs  [RangeI];
paulson@1985
   168
AddSEs [RangeE];
paulson@1985
   169
wenzelm@5069
   170
Goal "Range id = UNIV";
paulson@4644
   171
by (Blast_tac 1);
paulson@4644
   172
qed "Range_id";
paulson@4644
   173
Addsimps [Range_id];
paulson@4644
   174
nipkow@1128
   175
(*** Image of a set under a relation ***)
nipkow@1128
   176
paulson@5335
   177
Blast.overloaded ("Relation.op ^^", HOLogic.dest_setT o domain_type);
paulson@5335
   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
wenzelm@5069
   216
Goal "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*)
wenzelm@5069
   235
Goal "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]);
paulson@5231
   247
paulson@5231
   248
paulson@5231
   249
(** Graphs of partial functions **)
paulson@5231
   250
paulson@5231
   251
Goal "Domain{(x,y). y = f x & P x} = {x. P x}";
paulson@5231
   252
by (Blast_tac 1);
paulson@5231
   253
qed "Domain_partial_func";
paulson@5231
   254
paulson@5231
   255
Goal "Range{(x,y). y = f x & P x} = f``{x. P x}";
paulson@5231
   256
by (Blast_tac 1);
paulson@5231
   257
qed "Range_partial_func";
paulson@5231
   258