src/HOL/Relation.ML
author paulson
Mon Feb 23 11:15:40 1998 +0100 (1998-02-23)
changeset 4644 ecf8f17f6fe0
parent 4601 87fc0d44b837
child 4650 91af1ef45d68
permissions -rw-r--r--
New laws for id
     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 Relation.thy [id_def] "(a,a) : id";  
    12 by (Blast_tac 1);
    13 qed "idI";
    14 
    15 val major::prems = goalw Relation.thy [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 Relation.thy [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 (** Composition of two relations **)
    30 
    31 goalw Relation.thy [comp_def]
    32     "!!r s. [| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
    33 by (Blast_tac 1);
    34 qed "compI";
    35 
    36 (*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
    37 val prems = goalw Relation.thy [comp_def]
    38     "[| xz : r O s;  \
    39 \       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
    40 \    |] ==> P";
    41 by (cut_facts_tac prems 1);
    42 by (REPEAT (eresolve_tac [CollectE, splitE, exE, conjE] 1 
    43      ORELSE ares_tac prems 1));
    44 qed "compE";
    45 
    46 val prems = goal Relation.thy
    47     "[| (a,c) : r O s;  \
    48 \       !!y. [| (a,y):s;  (y,c):r |] ==> P \
    49 \    |] ==> P";
    50 by (rtac compE 1);
    51 by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
    52 qed "compEpair";
    53 
    54 AddIs [compI, idI];
    55 AddSEs [compE, idE];
    56 
    57 goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
    58 by (Blast_tac 1);
    59 qed "comp_mono";
    60 
    61 goal Relation.thy
    62     "!!r s. [| s <= A Times B;  r <= B Times C |] ==> (r O s) <= A Times C";
    63 by (Blast_tac 1);
    64 qed "comp_subset_Sigma";
    65 
    66 (** Natural deduction for trans(r) **)
    67 
    68 val prems = goalw Relation.thy [trans_def]
    69     "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
    70 by (REPEAT (ares_tac (prems@[allI,impI]) 1));
    71 qed "transI";
    72 
    73 goalw Relation.thy [trans_def]
    74     "!!r. [| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
    75 by (Blast_tac 1);
    76 qed "transD";
    77 
    78 (** Natural deduction for r^-1 **)
    79 
    80 goalw Relation.thy [inverse_def] "!!a b r. ((a,b): r^-1) = ((b,a):r)";
    81 by (Simp_tac 1);
    82 qed "inverse_iff";
    83 
    84 AddIffs [inverse_iff];
    85 
    86 goalw Relation.thy [inverse_def] "!!a b r. (a,b):r ==> (b,a): r^-1";
    87 by (Simp_tac 1);
    88 qed "inverseI";
    89 
    90 goalw Relation.thy [inverse_def] "!!a b r. (a,b) : r^-1 ==> (b,a) : r";
    91 by (Blast_tac 1);
    92 qed "inverseD";
    93 
    94 (*More general than inverseD, as it "splits" the member of the relation*)
    95 qed_goalw "inverseE" Relation.thy [inverse_def]
    96     "[| yx : r^-1;  \
    97 \       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
    98 \    |] ==> P"
    99  (fn [major,minor]=>
   100   [ (rtac (major RS CollectE) 1),
   101     (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
   102     (assume_tac 1) ]);
   103 
   104 AddSEs [inverseE];
   105 
   106 goalw Relation.thy [inverse_def] "(r^-1)^-1 = r";
   107 by (Blast_tac 1);
   108 qed "inverse_inverse";
   109 Addsimps [inverse_inverse];
   110 
   111 goal Relation.thy "(r O s)^-1 = s^-1 O r^-1";
   112 by (Blast_tac 1);
   113 qed "inverse_comp";
   114 
   115 goal Relation.thy "id^-1 = id";
   116 by (Blast_tac 1);
   117 qed "inverse_id";
   118 Addsimps [inverse_id];
   119 
   120 (** Domain **)
   121 
   122 qed_goalw "Domain_iff" Relation.thy [Domain_def]
   123     "a: Domain(r) = (EX y. (a,y): r)"
   124  (fn _=> [ (Blast_tac 1) ]);
   125 
   126 qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
   127  (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
   128 
   129 qed_goal "DomainE" Relation.thy
   130     "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
   131  (fn prems=>
   132   [ (rtac (Domain_iff RS iffD1 RS exE) 1),
   133     (REPEAT (ares_tac prems 1)) ]);
   134 
   135 AddIs  [DomainI];
   136 AddSEs [DomainE];
   137 
   138 goal thy "Domain id = UNIV";
   139 by (Blast_tac 1);
   140 qed "Domain_id";
   141 Addsimps [Domain_id];
   142 
   143 (** Range **)
   144 
   145 qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
   146  (fn _ => [ (etac (inverseI RS DomainI) 1) ]);
   147 
   148 qed_goalw "RangeE" Relation.thy [Range_def]
   149     "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
   150  (fn major::prems=>
   151   [ (rtac (major RS DomainE) 1),
   152     (resolve_tac prems 1),
   153     (etac inverseD 1) ]);
   154 
   155 AddIs  [RangeI];
   156 AddSEs [RangeE];
   157 
   158 goal thy "Range id = UNIV";
   159 by (Blast_tac 1);
   160 qed "Range_id";
   161 Addsimps [Range_id];
   162 
   163 (*** Image of a set under a relation ***)
   164 
   165 qed_goalw "Image_iff" Relation.thy [Image_def]
   166     "b : r^^A = (? x:A. (x,b):r)"
   167  (fn _ => [ Blast_tac 1 ]);
   168 
   169 qed_goal "Image_singleton_iff" Relation.thy
   170     "(b : r^^{a}) = ((a,b):r)"
   171  (fn _ => [ rtac (Image_iff RS trans) 1,
   172             Blast_tac 1 ]);
   173 
   174 qed_goalw "ImageI" Relation.thy [Image_def]
   175     "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
   176  (fn _ => [ (Blast_tac 1)]);
   177 
   178 qed_goalw "ImageE" Relation.thy [Image_def]
   179     "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
   180  (fn major::prems=>
   181   [ (rtac (major RS CollectE) 1),
   182     (Clarify_tac 1),
   183     (rtac (hd prems) 1),
   184     (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
   185 
   186 AddIs  [ImageI];
   187 AddSEs [ImageE];
   188 
   189 
   190 qed_goal "Image_empty" Relation.thy
   191     "R^^{} = {}"
   192  (fn _ => [ Blast_tac 1 ]);
   193 
   194 Addsimps [Image_empty];
   195 
   196 goal thy "id ^^ A = A";
   197 by (Blast_tac 1);
   198 qed "Image_id";
   199 
   200 Addsimps [Image_id];
   201 
   202 qed_goal "Image_Int_subset" Relation.thy
   203     "R ^^ (A Int B) <= R ^^ A Int R ^^ B"
   204  (fn _ => [ Blast_tac 1 ]);
   205 
   206 qed_goal "Image_Un" Relation.thy
   207     "R ^^ (A Un B) = R ^^ A Un R ^^ B"
   208  (fn _ => [ Blast_tac 1 ]);
   209 
   210 
   211 qed_goal "Image_subset" Relation.thy
   212     "!!A B r. r <= A Times B ==> r^^C <= B"
   213  (fn _ =>
   214   [ (rtac subsetI 1),
   215     (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
   216 
   217 goal Relation.thy "R O id = R";
   218 by (fast_tac (claset() addbefore split_all_tac) 1);
   219 qed "R_O_id";
   220 
   221 goal Relation.thy "id O R = R";
   222 by (fast_tac (claset() addbefore split_all_tac) 1);
   223 qed "id_O_R";
   224 
   225 Addsimps [R_O_id,id_O_R];