Converted to new theory format.
authorberghofe
Wed Feb 20 15:47:42 2002 +0100 (2002-02-20)
changeset 12905bbbae3f359e6
parent 12904 c208d71702d1
child 12906 165f4e1937f4
Converted to new theory format.
src/HOL/Relation.ML
src/HOL/Relation.thy
     1.1 --- a/src/HOL/Relation.ML	Wed Feb 20 00:55:42 2002 +0100
     1.2 +++ b/src/HOL/Relation.ML	Wed Feb 20 15:47:42 2002 +0100
     1.3 @@ -1,472 +1,103 @@
     1.4 -(*  Title:      Relation.ML
     1.5 -    ID:         $Id$
     1.6 -    Authors:    Lawrence C Paulson, Cambridge University Computer Laboratory
     1.7 -    Copyright   1996  University of Cambridge
     1.8 -*)
     1.9  
    1.10 -(** Identity relation **)
    1.11 -
    1.12 -Goalw [Id_def] "(a,a) : Id";  
    1.13 -by (Blast_tac 1);
    1.14 -qed "IdI";
    1.15 -
    1.16 -val major::prems = Goalw [Id_def]
    1.17 -    "[| p: Id;  !!x.[| p = (x,x) |] ==> P  \
    1.18 -\    |] ==>  P";  
    1.19 -by (rtac (major RS CollectE) 1);
    1.20 -by (etac exE 1);
    1.21 -by (eresolve_tac prems 1);
    1.22 -qed "IdE";
    1.23 -
    1.24 -Goalw [Id_def] "((a,b):Id) = (a=b)";
    1.25 -by (Blast_tac 1);
    1.26 -qed "pair_in_Id_conv";
    1.27 -AddIffs [pair_in_Id_conv];
    1.28 -
    1.29 -Goalw [refl_def] "reflexive Id";
    1.30 -by Auto_tac;
    1.31 -qed "reflexive_Id";
    1.32 -
    1.33 -(*A strange result, since Id is also symmetric.*)
    1.34 -Goalw [antisym_def] "antisym Id";
    1.35 -by Auto_tac;
    1.36 -qed "antisym_Id";
    1.37 -
    1.38 -Goalw [trans_def] "trans Id";
    1.39 -by Auto_tac;
    1.40 -qed "trans_Id";
    1.41 -
    1.42 -
    1.43 -(** Diagonal relation: indentity restricted to some set **)
    1.44 -
    1.45 -(*** Equality : the diagonal relation ***)
    1.46 -
    1.47 -Goalw [diag_def] "[| a=b;  a:A |] ==> (a,b) : diag(A)";
    1.48 -by (Blast_tac 1);
    1.49 -qed "diag_eqI";
    1.50 -
    1.51 -bind_thm ("diagI", refl RS diag_eqI |> standard);
    1.52 -
    1.53 -(*The general elimination rule*)
    1.54 -val major::prems = Goalw [diag_def]
    1.55 -    "[| c : diag(A);  \
    1.56 -\       !!x y. [| x:A;  c = (x,x) |] ==> P \
    1.57 -\    |] ==> P";
    1.58 -by (rtac (major RS UN_E) 1);
    1.59 -by (REPEAT (eresolve_tac [asm_rl,singletonE] 1 ORELSE resolve_tac prems 1));
    1.60 -qed "diagE";
    1.61 -
    1.62 -AddSIs [diagI];
    1.63 -AddSEs [diagE];
    1.64 -
    1.65 -Goal "((x,y) : diag A) = (x=y & x : A)";
    1.66 -by (Blast_tac 1);
    1.67 -qed "diag_iff";
    1.68 -
    1.69 -Goal "diag(A) <= A <*> A";
    1.70 -by (Blast_tac 1);
    1.71 -qed "diag_subset_Times";
    1.72 -
    1.73 -
    1.74 -
    1.75 -(** Composition of two relations **)
    1.76 -
    1.77 -Goalw [rel_comp_def]
    1.78 -    "[| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
    1.79 -by (Blast_tac 1);
    1.80 -qed "rel_compI";
    1.81 -
    1.82 -(*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
    1.83 -val prems = Goalw [rel_comp_def]
    1.84 -    "[| xz : r O s;  \
    1.85 -\       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
    1.86 -\    |] ==> P";
    1.87 -by (cut_facts_tac prems 1);
    1.88 -by (REPEAT (eresolve_tac [CollectE, splitE, exE, conjE] 1 
    1.89 -     ORELSE ares_tac prems 1));
    1.90 -qed "rel_compE";
    1.91 -
    1.92 -val prems = Goal
    1.93 -    "[| (a,c) : r O s;  \
    1.94 -\       !!y. [| (a,y):s;  (y,c):r |] ==> P \
    1.95 -\    |] ==> P";
    1.96 -by (rtac rel_compE 1);
    1.97 -by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
    1.98 -qed "rel_compEpair";
    1.99 -
   1.100 -AddIs [rel_compI, IdI];
   1.101 -AddSEs [rel_compE, IdE];
   1.102 -
   1.103 -Goal "R O Id = R";
   1.104 -by (Fast_tac 1);
   1.105 -qed "R_O_Id";
   1.106 -
   1.107 -Goal "Id O R = R";
   1.108 -by (Fast_tac 1);
   1.109 -qed "Id_O_R";
   1.110 -
   1.111 -Addsimps [R_O_Id,Id_O_R];
   1.112 -
   1.113 -Goal "(R O S) O T = R O (S O T)";
   1.114 -by (Blast_tac 1);
   1.115 -qed "O_assoc";
   1.116 -
   1.117 -Goalw [trans_def] "trans r ==> r O r <= r";
   1.118 -by (Blast_tac 1);
   1.119 -qed "trans_O_subset";
   1.120 -
   1.121 -Goal "[| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
   1.122 -by (Blast_tac 1);
   1.123 -qed "rel_comp_mono";
   1.124 -
   1.125 -Goal "[| s <= A <*> B;  r <= B <*> C |] ==> (r O s) <= A <*> C";
   1.126 -by (Blast_tac 1);
   1.127 -qed "rel_comp_subset_Sigma";
   1.128 -
   1.129 -(** Natural deduction for refl(r) **)
   1.130 -
   1.131 -val prems = Goalw [refl_def]
   1.132 -    "[| r <= A <*> A;  !! x. x:A ==> (x,x):r |] ==> refl A r";
   1.133 -by (REPEAT (ares_tac (prems@[ballI,conjI]) 1));
   1.134 -qed "reflI";
   1.135 -
   1.136 -Goalw [refl_def] "[| refl A r; a:A |] ==> (a,a):r";
   1.137 -by (Blast_tac 1);
   1.138 -qed "reflD";
   1.139 -
   1.140 -(** Natural deduction for antisym(r) **)
   1.141 -
   1.142 -val prems = Goalw [antisym_def]
   1.143 -    "(!! x y. [| (x,y):r;  (y,x):r |] ==> x=y) ==> antisym(r)";
   1.144 -by (REPEAT (ares_tac (prems@[allI,impI]) 1));
   1.145 -qed "antisymI";
   1.146 -
   1.147 -Goalw [antisym_def] "[| antisym(r);  (a,b):r;  (b,a):r |] ==> a=b";
   1.148 -by (Blast_tac 1);
   1.149 -qed "antisymD";
   1.150 -
   1.151 -(** Natural deduction for trans(r) **)
   1.152 -
   1.153 -val prems = Goalw [trans_def]
   1.154 -    "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
   1.155 -by (REPEAT (ares_tac (prems@[allI,impI]) 1));
   1.156 -qed "transI";
   1.157 -
   1.158 -Goalw [trans_def] "[| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
   1.159 -by (Blast_tac 1);
   1.160 -qed "transD";
   1.161 -
   1.162 -(** Natural deduction for r^-1 **)
   1.163 -
   1.164 -Goalw [converse_def] "((a,b): r^-1) = ((b,a):r)";
   1.165 -by (Simp_tac 1);
   1.166 -qed "converse_iff";
   1.167 -
   1.168 -AddIffs [converse_iff];
   1.169 -
   1.170 -Goalw [converse_def] "(a,b):r ==> (b,a): r^-1";
   1.171 -by (Simp_tac 1);
   1.172 -qed "converseI";
   1.173 -
   1.174 -Goalw [converse_def] "(a,b) : r^-1 ==> (b,a) : r";
   1.175 -by (Blast_tac 1);
   1.176 -qed "converseD";
   1.177 -
   1.178 -(*More general than converseD, as it "splits" the member of the relation*)
   1.179 -
   1.180 -val [major,minor] = Goalw [converse_def]
   1.181 -    "[| yx : r^-1;  \
   1.182 -\       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
   1.183 -\    |] ==> P";
   1.184 -by (rtac (major RS CollectE) 1);
   1.185 -by (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1));
   1.186 -by (assume_tac 1);
   1.187 -qed "converseE";
   1.188 -AddSEs [converseE];
   1.189 -
   1.190 -Goalw [converse_def] "(r^-1)^-1 = r";
   1.191 -by (Blast_tac 1);
   1.192 -qed "converse_converse";
   1.193 -Addsimps [converse_converse];
   1.194 -
   1.195 -Goal "(r O s)^-1 = s^-1 O r^-1";
   1.196 -by (Blast_tac 1);
   1.197 -qed "converse_rel_comp";
   1.198 -
   1.199 -Goal "Id^-1 = Id";
   1.200 -by (Blast_tac 1);
   1.201 -qed "converse_Id";
   1.202 -Addsimps [converse_Id];
   1.203 -
   1.204 -Goal "(diag A) ^-1 = diag A";
   1.205 -by (Blast_tac 1);
   1.206 -qed "converse_diag";
   1.207 -Addsimps [converse_diag];
   1.208 -
   1.209 -Goalw [refl_def] "refl A r ==> refl A (converse r)";
   1.210 -by (Blast_tac 1);
   1.211 -qed "refl_converse";
   1.212 -
   1.213 -Goalw [antisym_def] "antisym (converse r) = antisym r";
   1.214 -by (Blast_tac 1);
   1.215 -qed "antisym_converse";
   1.216 -
   1.217 -Goalw [trans_def] "trans (converse r) = trans r";
   1.218 -by (Blast_tac 1);
   1.219 -qed "trans_converse";
   1.220 -
   1.221 -(** Domain **)
   1.222 -
   1.223 -Goalw [Domain_def] "(a: Domain(r)) = (EX y. (a,y): r)";
   1.224 -by (Blast_tac 1);
   1.225 -qed "Domain_iff";
   1.226 -
   1.227 -Goal "(a,b): r ==> a: Domain(r)";
   1.228 -by (etac (exI RS (Domain_iff RS iffD2)) 1) ;
   1.229 -qed "DomainI";
   1.230 -
   1.231 -val prems= Goal "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P";
   1.232 -by (rtac (Domain_iff RS iffD1 RS exE) 1);
   1.233 -by (REPEAT (ares_tac prems 1)) ;
   1.234 -qed "DomainE";
   1.235 -
   1.236 -AddIs  [DomainI];
   1.237 -AddSEs [DomainE];
   1.238 +(* legacy ML bindings *)
   1.239  
   1.240 -Goal "Domain {} = {}";
   1.241 -by (Blast_tac 1); 
   1.242 -qed "Domain_empty";
   1.243 -Addsimps [Domain_empty];
   1.244 -
   1.245 -Goal "Domain (insert (a, b) r) = insert a (Domain r)";
   1.246 -by (Blast_tac 1); 
   1.247 -qed "Domain_insert";
   1.248 -
   1.249 -Goal "Domain Id = UNIV";
   1.250 -by (Blast_tac 1);
   1.251 -qed "Domain_Id";
   1.252 -Addsimps [Domain_Id];
   1.253 -
   1.254 -Goal "Domain (diag A) = A";
   1.255 -by Auto_tac;
   1.256 -qed "Domain_diag";
   1.257 -Addsimps [Domain_diag];
   1.258 -
   1.259 -Goal "Domain(A Un B) = Domain(A) Un Domain(B)";
   1.260 -by (Blast_tac 1);
   1.261 -qed "Domain_Un_eq";
   1.262 -
   1.263 -Goal "Domain(A Int B) <= Domain(A) Int Domain(B)";
   1.264 -by (Blast_tac 1);
   1.265 -qed "Domain_Int_subset";
   1.266 -
   1.267 -Goal "Domain(A) - Domain(B) <= Domain(A - B)";
   1.268 -by (Blast_tac 1);
   1.269 -qed "Domain_Diff_subset";
   1.270 -
   1.271 -Goal "Domain (Union S) = (UN A:S. Domain A)";
   1.272 -by (Blast_tac 1);
   1.273 -qed "Domain_Union";
   1.274 -
   1.275 -Goal "r <= s ==> Domain r <= Domain s";
   1.276 -by (Blast_tac 1);
   1.277 -qed "Domain_mono";
   1.278 -
   1.279 -
   1.280 -(** Range **)
   1.281 -
   1.282 -Goalw [Domain_def, Range_def] "(a: Range(r)) = (EX y. (y,a): r)";
   1.283 -by (Blast_tac 1);
   1.284 -qed "Range_iff";
   1.285 -
   1.286 -Goalw [Range_def] "(a,b): r ==> b : Range(r)";
   1.287 -by (etac (converseI RS DomainI) 1);
   1.288 -qed "RangeI";
   1.289 -
   1.290 -val major::prems = Goalw [Range_def] 
   1.291 -    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P";
   1.292 -by (rtac (major RS DomainE) 1);
   1.293 -by (resolve_tac prems 1);
   1.294 -by (etac converseD 1) ;
   1.295 -qed "RangeE";
   1.296 -
   1.297 -AddIs  [RangeI];
   1.298 -AddSEs [RangeE];
   1.299 -
   1.300 -Goal "Range {} = {}";
   1.301 -by (Blast_tac 1); 
   1.302 -qed "Range_empty";
   1.303 -Addsimps [Range_empty];
   1.304 -
   1.305 -Goal "Range (insert (a, b) r) = insert b (Range r)";
   1.306 -by (Blast_tac 1); 
   1.307 -qed "Range_insert";
   1.308 -
   1.309 -Goal "Range Id = UNIV";
   1.310 -by (Blast_tac 1);
   1.311 -qed "Range_Id";
   1.312 -Addsimps [Range_Id];
   1.313 -
   1.314 -Goal "Range (diag A) = A";
   1.315 -by Auto_tac;
   1.316 -qed "Range_diag";
   1.317 -Addsimps [Range_diag];
   1.318 -
   1.319 -Goal "Range(A Un B) = Range(A) Un Range(B)";
   1.320 -by (Blast_tac 1);
   1.321 -qed "Range_Un_eq";
   1.322 -
   1.323 -Goal "Range(A Int B) <= Range(A) Int Range(B)";
   1.324 -by (Blast_tac 1);
   1.325 -qed "Range_Int_subset";
   1.326 -
   1.327 -Goal "Range(A) - Range(B) <= Range(A - B)";
   1.328 -by (Blast_tac 1);
   1.329 -qed "Range_Diff_subset";
   1.330 -
   1.331 -Goal "Range (Union S) = (UN A:S. Range A)";
   1.332 -by (Blast_tac 1);
   1.333 -qed "Range_Union";
   1.334 -
   1.335 -
   1.336 -(*** Image of a set under a relation ***)
   1.337 -
   1.338 -overload_1st_set "Relation.Image";
   1.339 -
   1.340 -Goalw [Image_def] "(b : r``A) = (EX x:A. (x,b):r)";
   1.341 -by (Blast_tac 1);
   1.342 -qed "Image_iff";
   1.343 -
   1.344 -Goalw [Image_def] "r``{a} = {b. (a,b):r}";
   1.345 -by (Blast_tac 1);
   1.346 -qed "Image_singleton";
   1.347 -
   1.348 -Goal "(b : r``{a}) = ((a,b):r)";
   1.349 -by (rtac (Image_iff RS trans) 1);
   1.350 -by (Blast_tac 1);
   1.351 -qed "Image_singleton_iff";
   1.352 -
   1.353 -AddIffs [Image_singleton_iff];
   1.354 -
   1.355 -Goalw [Image_def] "[| (a,b): r;  a:A |] ==> b : r``A";
   1.356 -by (Blast_tac 1);
   1.357 -qed "ImageI";
   1.358 -
   1.359 -val major::prems = Goalw [Image_def]
   1.360 -    "[| b: r``A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P";
   1.361 -by (rtac (major RS CollectE) 1);
   1.362 -by (Clarify_tac 1);
   1.363 -by (rtac (hd prems) 1);
   1.364 -by (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ;
   1.365 -qed "ImageE";
   1.366 -
   1.367 -AddIs  [ImageI];
   1.368 -AddSEs [ImageE];
   1.369 -
   1.370 -(*This version's more effective when we already have the required "a"*)
   1.371 -Goal  "[| a:A;  (a,b): r |] ==> b : r``A";
   1.372 -by (Blast_tac 1);
   1.373 -qed "rev_ImageI";
   1.374 -
   1.375 -Goal "R``{} = {}";
   1.376 -by (Blast_tac 1);
   1.377 -qed "Image_empty";
   1.378 -
   1.379 -Addsimps [Image_empty];
   1.380 -
   1.381 -Goal "Id `` A = A";
   1.382 -by (Blast_tac 1);
   1.383 -qed "Image_Id";
   1.384 -
   1.385 -Goal "diag A `` B = A Int B";
   1.386 -by (Blast_tac 1);
   1.387 -qed "Image_diag";
   1.388 -
   1.389 -Addsimps [Image_Id, Image_diag];
   1.390 -
   1.391 -Goal "R `` (A Int B) <= R `` A Int R `` B";
   1.392 -by (Blast_tac 1);
   1.393 -qed "Image_Int_subset";
   1.394 -
   1.395 -Goal "R `` (A Un B) = R `` A Un R `` B";
   1.396 -by (Blast_tac 1);
   1.397 -qed "Image_Un";
   1.398 -
   1.399 -Goal "r <= A <*> B ==> r``C <= B";
   1.400 -by (rtac subsetI 1);
   1.401 -by (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ;
   1.402 -qed "Image_subset";
   1.403 -
   1.404 -(*NOT suitable for rewriting*)
   1.405 -Goal "r``B = (UN y: B. r``{y})";
   1.406 -by (Blast_tac 1);
   1.407 -qed "Image_eq_UN";
   1.408 -
   1.409 -Goal "[| r'<=r; A'<=A |] ==> (r' `` A') <= (r `` A)";
   1.410 -by (Blast_tac 1);
   1.411 -qed "Image_mono";
   1.412 -
   1.413 -Goal "(r `` (UNION A B)) = (UN x:A.(r `` (B x)))";
   1.414 -by (Blast_tac 1);
   1.415 -qed "Image_UN";
   1.416 -
   1.417 -(*Converse inclusion fails*)
   1.418 -Goal "(r `` (INTER A B)) <= (INT x:A.(r `` (B x)))";
   1.419 -by (Blast_tac 1);
   1.420 -qed "Image_INT_subset";
   1.421 -
   1.422 -Goal "(r``A <= B) = (A <= - ((r^-1) `` (-B)))";
   1.423 -by (Blast_tac 1);
   1.424 -qed "Image_subset_eq";
   1.425 -
   1.426 -section "single_valued";
   1.427 -
   1.428 -Goalw [single_valued_def]
   1.429 -     "ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z) ==> single_valued r";
   1.430 -by (assume_tac 1);
   1.431 -qed "single_valuedI";
   1.432 -
   1.433 -Goalw [single_valued_def]
   1.434 -     "[| single_valued r;  (x,y):r;  (x,z):r|] ==> y=z";
   1.435 -by Auto_tac;
   1.436 -qed "single_valuedD";
   1.437 -
   1.438 -
   1.439 -(** Graphs given by Collect **)
   1.440 -
   1.441 -Goal "Domain{(x,y). P x y} = {x. EX y. P x y}";
   1.442 -by Auto_tac; 
   1.443 -qed "Domain_Collect_split";
   1.444 -
   1.445 -Goal "Range{(x,y). P x y} = {y. EX x. P x y}";
   1.446 -by Auto_tac; 
   1.447 -qed "Range_Collect_split";
   1.448 -
   1.449 -Goal "{(x,y). P x y} `` A = {y. EX x:A. P x y}";
   1.450 -by Auto_tac; 
   1.451 -qed "Image_Collect_split";
   1.452 -
   1.453 -Addsimps [Domain_Collect_split, Range_Collect_split, Image_Collect_split];
   1.454 -
   1.455 -(** Composition of function and relation **)
   1.456 -
   1.457 -Goalw [fun_rel_comp_def] "A <= B ==> fun_rel_comp f A <= fun_rel_comp f B";
   1.458 -by (Fast_tac 1);
   1.459 -qed "fun_rel_comp_mono";
   1.460 -
   1.461 -Goalw [fun_rel_comp_def]
   1.462 -     "ALL x. EX! y. (f x, y) : R ==> EX! g. g : fun_rel_comp f R";
   1.463 -by (res_inst_tac [("a","%x. THE y. (f x, y) : R")] ex1I 1);
   1.464 -by (fast_tac (claset() addSDs [theI']) 1); 
   1.465 -by (fast_tac (claset() addIs [ext, the1_equality RS sym]) 1);
   1.466 -qed "fun_rel_comp_unique";
   1.467 -
   1.468 -
   1.469 -section "inverse image";
   1.470 -
   1.471 -Goalw [trans_def,inv_image_def]
   1.472 -    "trans r ==> trans (inv_image r f)";
   1.473 -by (Simp_tac 1);
   1.474 -by (Blast_tac 1);
   1.475 -qed "trans_inv_image";
   1.476 -
   1.477 +val DomainE = thm "DomainE";
   1.478 +val DomainI = thm "DomainI";
   1.479 +val Domain_Collect_split = thm "Domain_Collect_split";
   1.480 +val Domain_Diff_subset = thm "Domain_Diff_subset";
   1.481 +val Domain_Id = thm "Domain_Id";
   1.482 +val Domain_Int_subset = thm "Domain_Int_subset";
   1.483 +val Domain_Un_eq = thm "Domain_Un_eq";
   1.484 +val Domain_Union = thm "Domain_Union";
   1.485 +val Domain_def = thm "Domain_def";
   1.486 +val Domain_diag = thm "Domain_diag";
   1.487 +val Domain_empty = thm "Domain_empty";
   1.488 +val Domain_iff = thm "Domain_iff";
   1.489 +val Domain_insert = thm "Domain_insert";
   1.490 +val Domain_mono = thm "Domain_mono";
   1.491 +val Field_def = thm "Field_def";
   1.492 +val IdE = thm "IdE";
   1.493 +val IdI = thm "IdI";
   1.494 +val Id_O_R = thm "Id_O_R";
   1.495 +val Id_def = thm "Id_def";
   1.496 +val ImageE = thm "ImageE";
   1.497 +val ImageI = thm "ImageI";
   1.498 +val Image_Collect_split = thm "Image_Collect_split";
   1.499 +val Image_INT_subset = thm "Image_INT_subset";
   1.500 +val Image_Id = thm "Image_Id";
   1.501 +val Image_Int_subset = thm "Image_Int_subset";
   1.502 +val Image_UN = thm "Image_UN";
   1.503 +val Image_Un = thm "Image_Un";
   1.504 +val Image_def = thm "Image_def";
   1.505 +val Image_diag = thm "Image_diag";
   1.506 +val Image_empty = thm "Image_empty";
   1.507 +val Image_eq_UN = thm "Image_eq_UN";
   1.508 +val Image_iff = thm "Image_iff";
   1.509 +val Image_mono = thm "Image_mono";
   1.510 +val Image_singleton = thm "Image_singleton";
   1.511 +val Image_singleton_iff = thm "Image_singleton_iff";
   1.512 +val Image_subset = thm "Image_subset";
   1.513 +val Image_subset_eq = thm "Image_subset_eq";
   1.514 +val O_assoc = thm "O_assoc";
   1.515 +val R_O_Id = thm "R_O_Id";
   1.516 +val RangeE = thm "RangeE";
   1.517 +val RangeI = thm "RangeI";
   1.518 +val Range_Collect_split = thm "Range_Collect_split";
   1.519 +val Range_Diff_subset = thm "Range_Diff_subset";
   1.520 +val Range_Id = thm "Range_Id";
   1.521 +val Range_Int_subset = thm "Range_Int_subset";
   1.522 +val Range_Un_eq = thm "Range_Un_eq";
   1.523 +val Range_Union = thm "Range_Union";
   1.524 +val Range_def = thm "Range_def";
   1.525 +val Range_diag = thm "Range_diag";
   1.526 +val Range_empty = thm "Range_empty";
   1.527 +val Range_iff = thm "Range_iff";
   1.528 +val Range_insert = thm "Range_insert";
   1.529 +val antisymD = thm "antisymD";
   1.530 +val antisymI = thm "antisymI";
   1.531 +val antisym_Id = thm "antisym_Id";
   1.532 +val antisym_converse = thm "antisym_converse";
   1.533 +val antisym_def = thm "antisym_def";
   1.534 +val converseD = thm "converseD";
   1.535 +val converseE = thm "converseE";
   1.536 +val converseI = thm "converseI";
   1.537 +val converse_Id = thm "converse_Id";
   1.538 +val converse_converse = thm "converse_converse";
   1.539 +val converse_def = thm "converse_def";
   1.540 +val converse_diag = thm "converse_diag";
   1.541 +val converse_iff = thm "converse_iff";
   1.542 +val converse_rel_comp = thm "converse_rel_comp";
   1.543 +val diagE = thm "diagE";
   1.544 +val diagI = thm "diagI";
   1.545 +val diag_def = thm "diag_def";
   1.546 +val diag_eqI = thm "diag_eqI";
   1.547 +val diag_iff = thm "diag_iff";
   1.548 +val diag_subset_Times = thm "diag_subset_Times";
   1.549 +val fun_rel_comp_def = thm "fun_rel_comp_def";
   1.550 +val fun_rel_comp_mono = thm "fun_rel_comp_mono";
   1.551 +val fun_rel_comp_unique = thm "fun_rel_comp_unique";
   1.552 +val inv_image_def = thm "inv_image_def";
   1.553 +val pair_in_Id_conv = thm "pair_in_Id_conv";
   1.554 +val reflD = thm "reflD";
   1.555 +val reflI = thm "reflI";
   1.556 +val refl_converse = thm "refl_converse";
   1.557 +val refl_def = thm "refl_def";
   1.558 +val reflexive_Id = thm "reflexive_Id";
   1.559 +val rel_compE = thm "rel_compE";
   1.560 +val rel_compEpair = thm "rel_compEpair";
   1.561 +val rel_compI = thm "rel_compI";
   1.562 +val rel_comp_def = thm "rel_comp_def";
   1.563 +val rel_comp_mono = thm "rel_comp_mono";
   1.564 +val rel_comp_subset_Sigma = thm "rel_comp_subset_Sigma";
   1.565 +val rev_ImageI = thm "rev_ImageI";
   1.566 +val single_valuedD = thm "single_valuedD";
   1.567 +val single_valuedI = thm "single_valuedI";
   1.568 +val single_valued_def = thm "single_valued_def";
   1.569 +val sym_def = thm "sym_def";
   1.570 +val transD = thm "transD";
   1.571 +val transI = thm "transI";
   1.572 +val trans_Id = thm "trans_Id";
   1.573 +val trans_O_subset = thm "trans_O_subset";
   1.574 +val trans_converse = thm "trans_converse";
   1.575 +val trans_def = thm "trans_def";
   1.576 +val trans_inv_image = thm "trans_inv_image";
     2.1 --- a/src/HOL/Relation.thy	Wed Feb 20 00:55:42 2002 +0100
     2.2 +++ b/src/HOL/Relation.thy	Wed Feb 20 15:47:42 2002 +0100
     2.3 @@ -4,13 +4,15 @@
     2.4      Copyright   1996  University of Cambridge
     2.5  *)
     2.6  
     2.7 -Relation = Product_Type +
     2.8 +header {* Relations *}
     2.9 +
    2.10 +theory Relation = Product_Type:
    2.11  
    2.12  constdefs
    2.13    converse :: "('a * 'b) set => ('b * 'a) set"    ("(_^-1)" [1000] 999)
    2.14    "r^-1 == {(y, x). (x, y) : r}"
    2.15  syntax (xsymbols)
    2.16 -  converse :: "('a * 'b) set => ('b * 'a) set"    ("(_\\<inverse>)" [1000] 999)
    2.17 +  converse :: "('a * 'b) set => ('b * 'a) set"    ("(_\<inverse>)" [1000] 999)
    2.18  
    2.19  constdefs
    2.20    rel_comp  :: "[('b * 'c) set, ('a * 'b) set] => ('a * 'c) set"  (infixr "O" 60)
    2.21 @@ -19,10 +21,10 @@
    2.22    Image :: "[('a * 'b) set, 'a set] => 'b set"                (infixl "``" 90)
    2.23      "r `` s == {y. ? x:s. (x,y):r}"
    2.24  
    2.25 -  Id    :: "('a * 'a) set"                            (*the identity relation*)
    2.26 +  Id    :: "('a * 'a) set"  -- {* the identity relation *}
    2.27      "Id == {p. ? x. p = (x,x)}"
    2.28  
    2.29 -  diag  :: "'a set => ('a * 'a) set"          (*diagonal: identity over a set*)
    2.30 +  diag  :: "'a set => ('a * 'a) set"  -- {* diagonal: identity over a set *}
    2.31      "diag(A) == UN x:A. {(x,x)}"
    2.32    
    2.33    Domain :: "('a * 'b) set => 'a set"
    2.34 @@ -34,16 +36,16 @@
    2.35    Field :: "('a * 'a) set => 'a set"
    2.36      "Field r == Domain r Un Range r"
    2.37  
    2.38 -  refl   :: "['a set, ('a * 'a) set] => bool" (*reflexivity over a set*)
    2.39 +  refl   :: "['a set, ('a * 'a) set] => bool"  -- {* reflexivity over a set *}
    2.40      "refl A r == r <= A <*> A & (ALL x: A. (x,x) : r)"
    2.41  
    2.42 -  sym    :: "('a * 'a) set => bool"             (*symmetry predicate*)
    2.43 +  sym    :: "('a * 'a) set => bool"  -- {* symmetry predicate *}
    2.44      "sym(r) == ALL x y. (x,y): r --> (y,x): r"
    2.45  
    2.46 -  antisym:: "('a * 'a) set => bool"          (*antisymmetry predicate*)
    2.47 +  antisym:: "('a * 'a) set => bool"  -- {* antisymmetry predicate *}
    2.48      "antisym(r) == ALL x y. (x,y):r --> (y,x):r --> x=y"
    2.49  
    2.50 -  trans  :: "('a * 'a) set => bool"          (*transitivity predicate*)
    2.51 +  trans  :: "('a * 'a) set => bool"  -- {* transitivity predicate *}
    2.52      "trans(r) == (!x y z. (x,y):r --> (y,z):r --> (x,z):r)"
    2.53  
    2.54    single_valued :: "('a * 'b) set => bool"
    2.55 @@ -56,8 +58,329 @@
    2.56      "inv_image r f == {(x,y). (f(x), f(y)) : r}"
    2.57  
    2.58  syntax
    2.59 -  reflexive :: "('a * 'a) set => bool"       (*reflexivity over a type*)
    2.60 +  reflexive :: "('a * 'a) set => bool"  -- {* reflexivity over a type *}
    2.61  translations
    2.62    "reflexive" == "refl UNIV"
    2.63  
    2.64 +
    2.65 +subsection {* Identity relation *}
    2.66 +
    2.67 +lemma IdI [intro]: "(a, a) : Id"
    2.68 +  by (simp add: Id_def)
    2.69 +
    2.70 +lemma IdE [elim!]: "p : Id ==> (!!x. p = (x, x) ==> P) ==> P"
    2.71 +  by (unfold Id_def) (rules elim: CollectE)
    2.72 +
    2.73 +lemma pair_in_Id_conv [iff]: "((a, b) : Id) = (a = b)"
    2.74 +  by (unfold Id_def) blast
    2.75 +
    2.76 +lemma reflexive_Id: "reflexive Id"
    2.77 +  by (simp add: refl_def)
    2.78 +
    2.79 +lemma antisym_Id: "antisym Id"
    2.80 +  -- {* A strange result, since @{text Id} is also symmetric. *}
    2.81 +  by (simp add: antisym_def)
    2.82 +
    2.83 +lemma trans_Id: "trans Id"
    2.84 +  by (simp add: trans_def)
    2.85 +
    2.86 +
    2.87 +subsection {* Diagonal relation: identity restricted to some set *}
    2.88 +
    2.89 +lemma diag_eqI: "a = b ==> a : A ==> (a, b) : diag A"
    2.90 +  by (simp add: diag_def)
    2.91 +
    2.92 +lemma diagI [intro!]: "a : A ==> (a, a) : diag A"
    2.93 +  by (rule diag_eqI) (rule refl)
    2.94 +
    2.95 +lemma diagE [elim!]:
    2.96 +  "c : diag A ==> (!!x. x : A ==> c = (x, x) ==> P) ==> P"
    2.97 +  -- {* The general elimination rule *}
    2.98 +  by (unfold diag_def) (rules elim!: UN_E singletonE)
    2.99 +
   2.100 +lemma diag_iff: "((x, y) : diag A) = (x = y & x : A)"
   2.101 +  by blast
   2.102 +
   2.103 +lemma diag_subset_Times: "diag A <= A <*> A"
   2.104 +  by blast
   2.105 +
   2.106 +
   2.107 +subsection {* Composition of two relations *}
   2.108 +
   2.109 +lemma rel_compI [intro]: 
   2.110 +  "(a, b) : s ==> (b, c) : r ==> (a, c) : r O s"
   2.111 +  by (unfold rel_comp_def) blast
   2.112 +
   2.113 +lemma rel_compE [elim!]: "xz : r O s ==>   
   2.114 +  (!!x y z. xz = (x, z) ==> (x, y) : s ==> (y, z) : r  ==> P) ==> P"
   2.115 +  by (unfold rel_comp_def) (rules elim!: CollectE splitE exE conjE)
   2.116 +
   2.117 +lemma rel_compEpair:
   2.118 +  "(a, c) : r O s ==> (!!y. (a, y) : s ==> (y, c) : r ==> P) ==> P"
   2.119 +  by (rules elim: rel_compE Pair_inject ssubst)
   2.120 +
   2.121 +lemma R_O_Id [simp]: "R O Id = R"
   2.122 +  by fast
   2.123 +
   2.124 +lemma Id_O_R [simp]: "Id O R = R"
   2.125 +  by fast
   2.126 +
   2.127 +lemma O_assoc: "(R O S) O T = R O (S O T)"
   2.128 +  by blast
   2.129 +
   2.130 +lemma trans_O_subset: "trans r ==> r O r <= r"
   2.131 +  by (unfold trans_def) blast
   2.132 +
   2.133 +lemma rel_comp_mono: "[| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)"
   2.134 +  by blast
   2.135 +
   2.136 +lemma rel_comp_subset_Sigma:
   2.137 +  "[| s <= A <*> B;  r <= B <*> C |] ==> (r O s) <= A <*> C"
   2.138 +  by blast
   2.139 +
   2.140 +subsection {* Natural deduction for refl(r) *}
   2.141 +
   2.142 +lemma reflI: "r <= A <*> A ==> (!!x. x : A ==> (x, x) : r) ==> refl A r"
   2.143 +  by (unfold refl_def) (rules intro!: ballI)
   2.144 +
   2.145 +lemma reflD: "refl A r ==> a : A ==> (a, a) : r"
   2.146 +  by (unfold refl_def) blast
   2.147 +
   2.148 +subsection {* Natural deduction for antisym(r) *}
   2.149 +
   2.150 +lemma antisymI:
   2.151 +  "(!!x y. (x, y) : r ==> (y, x) : r ==> x=y) ==> antisym r"
   2.152 +  by (unfold antisym_def) rules
   2.153 +
   2.154 +lemma antisymD: "antisym r ==> (a, b) : r ==> (b, a) : r ==> a = b"
   2.155 +  by (unfold antisym_def) rules
   2.156 +
   2.157 +subsection {* Natural deduction for trans(r) *}
   2.158 +
   2.159 +lemma transI:
   2.160 +  "(!!x y z. (x, y) : r ==> (y, z) : r ==> (x, z) : r) ==> trans r"
   2.161 +  by (unfold trans_def) rules
   2.162 +
   2.163 +lemma transD: "trans r ==> (a, b) : r ==> (b, c) : r ==> (a, c) : r"
   2.164 +  by (unfold trans_def) rules
   2.165 +
   2.166 +subsection {* Natural deduction for r^-1 *}
   2.167 +
   2.168 +lemma converse_iff [iff]: "((a,b): r^-1) = ((b,a):r)"
   2.169 +  by (simp add: converse_def)
   2.170 +
   2.171 +lemma converseI: "(a,b):r ==> (b,a): r^-1"
   2.172 +  by (simp add: converse_def)
   2.173 +
   2.174 +lemma converseD: "(a,b) : r^-1 ==> (b,a) : r"
   2.175 +  by (simp add: converse_def)
   2.176 +
   2.177 +(*More general than converseD, as it "splits" the member of the relation*)
   2.178 +
   2.179 +lemma converseE [elim!]:
   2.180 +  "yx : r^-1 ==> (!!x y. yx = (y, x) ==> (x, y) : r ==> P) ==> P"
   2.181 +  by (unfold converse_def) (rules elim!: CollectE splitE bexE)
   2.182 +
   2.183 +lemma converse_converse [simp]: "(r^-1)^-1 = r"
   2.184 +  by (unfold converse_def) blast
   2.185 +
   2.186 +lemma converse_rel_comp: "(r O s)^-1 = s^-1 O r^-1"
   2.187 +  by blast
   2.188 +
   2.189 +lemma converse_Id [simp]: "Id^-1 = Id"
   2.190 +  by blast
   2.191 +
   2.192 +lemma converse_diag [simp]: "(diag A) ^-1 = diag A"
   2.193 +  by blast
   2.194 +
   2.195 +lemma refl_converse: "refl A r ==> refl A (converse r)"
   2.196 +  by (unfold refl_def) blast
   2.197 +
   2.198 +lemma antisym_converse: "antisym (converse r) = antisym r"
   2.199 +  by (unfold antisym_def) blast
   2.200 +
   2.201 +lemma trans_converse: "trans (converse r) = trans r"
   2.202 +  by (unfold trans_def) blast
   2.203 +
   2.204 +subsection {* Domain *}
   2.205 +
   2.206 +lemma Domain_iff: "(a : Domain r) = (EX y. (a, y) : r)"
   2.207 +  by (unfold Domain_def) blast
   2.208 +
   2.209 +lemma DomainI [intro]: "(a, b) : r ==> a : Domain r"
   2.210 +  by (rules intro!: iffD2 [OF Domain_iff])
   2.211 +
   2.212 +lemma DomainE [elim!]:
   2.213 +  "a : Domain r ==> (!!y. (a, y) : r ==> P) ==> P"
   2.214 +  by (rules dest!: iffD1 [OF Domain_iff])
   2.215 +
   2.216 +lemma Domain_empty [simp]: "Domain {} = {}"
   2.217 +  by blast
   2.218 +
   2.219 +lemma Domain_insert: "Domain (insert (a, b) r) = insert a (Domain r)"
   2.220 +  by blast
   2.221 +
   2.222 +lemma Domain_Id [simp]: "Domain Id = UNIV"
   2.223 +  by blast
   2.224 +
   2.225 +lemma Domain_diag [simp]: "Domain (diag A) = A"
   2.226 +  by blast
   2.227 +
   2.228 +lemma Domain_Un_eq: "Domain(A Un B) = Domain(A) Un Domain(B)"
   2.229 +  by blast
   2.230 +
   2.231 +lemma Domain_Int_subset: "Domain(A Int B) <= Domain(A) Int Domain(B)"
   2.232 +  by blast
   2.233 +
   2.234 +lemma Domain_Diff_subset: "Domain(A) - Domain(B) <= Domain(A - B)"
   2.235 +  by blast
   2.236 +
   2.237 +lemma Domain_Union: "Domain (Union S) = (UN A:S. Domain A)"
   2.238 +  by blast
   2.239 +
   2.240 +lemma Domain_mono: "r <= s ==> Domain r <= Domain s"
   2.241 +  by blast
   2.242 +
   2.243 +
   2.244 +subsection {* Range *}
   2.245 +
   2.246 +lemma Range_iff: "(a : Range r) = (EX y. (y, a) : r)"
   2.247 +  by (simp add: Domain_def Range_def)
   2.248 +
   2.249 +lemma RangeI [intro]: "(a, b) : r ==> b : Range r"
   2.250 +  by (unfold Range_def) (rules intro!: converseI DomainI)
   2.251 +
   2.252 +lemma RangeE [elim!]: "b : Range r ==> (!!x. (x, b) : r ==> P) ==> P"
   2.253 +  by (unfold Range_def) (rules elim!: DomainE dest!: converseD)
   2.254 +
   2.255 +lemma Range_empty [simp]: "Range {} = {}"
   2.256 +  by blast
   2.257 +
   2.258 +lemma Range_insert: "Range (insert (a, b) r) = insert b (Range r)"
   2.259 +  by blast
   2.260 +
   2.261 +lemma Range_Id [simp]: "Range Id = UNIV"
   2.262 +  by blast
   2.263 +
   2.264 +lemma Range_diag [simp]: "Range (diag A) = A"
   2.265 +  by auto
   2.266 +
   2.267 +lemma Range_Un_eq: "Range(A Un B) = Range(A) Un Range(B)"
   2.268 +  by blast
   2.269 +
   2.270 +lemma Range_Int_subset: "Range(A Int B) <= Range(A) Int Range(B)"
   2.271 +  by blast
   2.272 +
   2.273 +lemma Range_Diff_subset: "Range(A) - Range(B) <= Range(A - B)"
   2.274 +  by blast
   2.275 +
   2.276 +lemma Range_Union: "Range (Union S) = (UN A:S. Range A)"
   2.277 +  by blast
   2.278 +
   2.279 +
   2.280 +subsection {* Image of a set under a relation *}
   2.281 +
   2.282 +ML {* overload_1st_set "Relation.Image" *}
   2.283 +
   2.284 +lemma Image_iff: "(b : r``A) = (EX x:A. (x,b):r)"
   2.285 +  by (simp add: Image_def)
   2.286 +
   2.287 +lemma Image_singleton: "r``{a} = {b. (a,b):r}"
   2.288 +  by (simp add: Image_def)
   2.289 +
   2.290 +lemma Image_singleton_iff [iff]: "(b : r``{a}) = ((a,b):r)"
   2.291 +  by (rule Image_iff [THEN trans]) simp
   2.292 +
   2.293 +lemma ImageI [intro]: "[| (a,b): r;  a:A |] ==> b : r``A"
   2.294 +  by (unfold Image_def) blast
   2.295 +
   2.296 +lemma ImageE [elim!]:
   2.297 +  "b : r `` A ==> (!!x. (x, b) : r ==> x : A ==> P) ==> P"
   2.298 +  by (unfold Image_def) (rules elim!: CollectE bexE)
   2.299 +
   2.300 +lemma rev_ImageI: "a : A ==> (a, b) : r ==> b : r `` A"
   2.301 +  -- {* This version's more effective when we already have the required @{text a} *}
   2.302 +  by blast
   2.303 +
   2.304 +lemma Image_empty [simp]: "R``{} = {}"
   2.305 +  by blast
   2.306 +
   2.307 +lemma Image_Id [simp]: "Id `` A = A"
   2.308 +  by blast
   2.309 +
   2.310 +lemma Image_diag [simp]: "diag A `` B = A Int B"
   2.311 +  by blast
   2.312 +
   2.313 +lemma Image_Int_subset: "R `` (A Int B) <= R `` A Int R `` B"
   2.314 +  by blast
   2.315 +
   2.316 +lemma Image_Un: "R `` (A Un B) = R `` A Un R `` B"
   2.317 +  by blast
   2.318 +
   2.319 +lemma Image_subset: "r <= A <*> B ==> r``C <= B"
   2.320 +  by (rules intro!: subsetI elim!: ImageE dest!: subsetD SigmaD2)
   2.321 +
   2.322 +lemma Image_eq_UN: "r``B = (UN y: B. r``{y})"
   2.323 +  -- {* NOT suitable for rewriting *}
   2.324 +  by blast
   2.325 +
   2.326 +lemma Image_mono: "[| r'<=r; A'<=A |] ==> (r' `` A') <= (r `` A)"
   2.327 +  by blast
   2.328 +
   2.329 +lemma Image_UN: "(r `` (UNION A B)) = (UN x:A.(r `` (B x)))"
   2.330 +  by blast
   2.331 +
   2.332 +lemma Image_INT_subset: "(r `` (INTER A B)) <= (INT x:A.(r `` (B x)))"
   2.333 +  -- {* Converse inclusion fails *}
   2.334 +  by blast
   2.335 +
   2.336 +lemma Image_subset_eq: "(r``A <= B) = (A <= - ((r^-1) `` (-B)))"
   2.337 +  by blast
   2.338 +
   2.339 +subsection "single_valued"
   2.340 +
   2.341 +lemma single_valuedI: 
   2.342 +  "ALL x y. (x,y):r --> (ALL z. (x,z):r --> y=z) ==> single_valued r"
   2.343 +  by (unfold single_valued_def)
   2.344 +
   2.345 +lemma single_valuedD:
   2.346 +  "single_valued r ==> (x, y) : r ==> (x, z) : r ==> y = z"
   2.347 +  by (simp add: single_valued_def)
   2.348 +
   2.349 +
   2.350 +subsection {* Graphs given by @{text Collect} *}
   2.351 +
   2.352 +lemma Domain_Collect_split [simp]: "Domain{(x,y). P x y} = {x. EX y. P x y}"
   2.353 +  by auto
   2.354 +
   2.355 +lemma Range_Collect_split [simp]: "Range{(x,y). P x y} = {y. EX x. P x y}"
   2.356 +  by auto
   2.357 +
   2.358 +lemma Image_Collect_split [simp]: "{(x,y). P x y} `` A = {y. EX x:A. P x y}"
   2.359 +  by auto
   2.360 +
   2.361 +
   2.362 +subsection {* Composition of function and relation *}
   2.363 +
   2.364 +lemma fun_rel_comp_mono: "A <= B ==> fun_rel_comp f A <= fun_rel_comp f B"
   2.365 +  by (unfold fun_rel_comp_def) fast
   2.366 +
   2.367 +lemma fun_rel_comp_unique: 
   2.368 +  "ALL x. EX! y. (f x, y) : R ==> EX! g. g : fun_rel_comp f R"
   2.369 +  apply (unfold fun_rel_comp_def)
   2.370 +  apply (rule_tac a = "%x. THE y. (f x, y) : R" in ex1I)
   2.371 +  apply (fast dest!: theI')
   2.372 +  apply (fast intro: ext the1_equality [symmetric])
   2.373 +  done
   2.374 +
   2.375 +
   2.376 +subsection "inverse image"
   2.377 +
   2.378 +lemma trans_inv_image: 
   2.379 +  "trans r ==> trans (inv_image r f)"
   2.380 +  apply (unfold trans_def inv_image_def)
   2.381 +  apply (simp (no_asm))
   2.382 +  apply blast
   2.383 +  done
   2.384 +
   2.385  end