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