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