src/HOL/Relation.ML
author paulson
Mon Mar 16 16:50:50 1998 +0100 (1998-03-16)
changeset 4746 a5dcd7e4a37d
parent 4733 2c984ac036f5
child 4760 9cdbd5a1d25a
permissions -rw-r--r--
inverse -> converse
[It is standard terminology and also used in ZF]
     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 thy [id_def] "(a,a) : id";  
    12 by (Blast_tac 1);
    13 qed "idI";
    14 
    15 val major::prems = goalw 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 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 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 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 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 thy "R O id = R";
    58 by (Fast_tac 1);
    59 qed "R_O_id";
    60 
    61 goal thy "id O R = R";
    62 by (Fast_tac 1);
    63 qed "id_O_R";
    64 
    65 Addsimps [R_O_id,id_O_R];
    66 
    67 goal thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
    68 by (Blast_tac 1);
    69 qed "comp_mono";
    70 
    71 goal thy
    72     "!!r s. [| s <= A Times B;  r <= B Times C |] ==> (r O s) <= A Times C";
    73 by (Blast_tac 1);
    74 qed "comp_subset_Sigma";
    75 
    76 (** Natural deduction for trans(r) **)
    77 
    78 val prems = goalw thy [trans_def]
    79     "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
    80 by (REPEAT (ares_tac (prems@[allI,impI]) 1));
    81 qed "transI";
    82 
    83 goalw thy [trans_def]
    84     "!!r. [| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
    85 by (Blast_tac 1);
    86 qed "transD";
    87 
    88 (** Natural deduction for r^-1 **)
    89 
    90 goalw thy [converse_def] "!!a b r. ((a,b): r^-1) = ((b,a):r)";
    91 by (Simp_tac 1);
    92 qed "converse_iff";
    93 
    94 AddIffs [converse_iff];
    95 
    96 goalw thy [converse_def] "!!a b r. (a,b):r ==> (b,a): r^-1";
    97 by (Simp_tac 1);
    98 qed "converseI";
    99 
   100 goalw thy [converse_def] "!!a b r. (a,b) : r^-1 ==> (b,a) : r";
   101 by (Blast_tac 1);
   102 qed "converseD";
   103 
   104 (*More general than converseD, as it "splits" the member of the relation*)
   105 qed_goalw "converseE" thy [converse_def]
   106     "[| yx : r^-1;  \
   107 \       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
   108 \    |] ==> P"
   109  (fn [major,minor]=>
   110   [ (rtac (major RS CollectE) 1),
   111     (REPEAT (eresolve_tac [splitE, bexE,exE, conjE, minor] 1)),
   112     (assume_tac 1) ]);
   113 
   114 AddSEs [converseE];
   115 
   116 goalw thy [converse_def] "(r^-1)^-1 = r";
   117 by (Blast_tac 1);
   118 qed "converse_converse";
   119 Addsimps [converse_converse];
   120 
   121 goal thy "(r O s)^-1 = s^-1 O r^-1";
   122 by (Blast_tac 1);
   123 qed "converse_comp";
   124 
   125 goal thy "id^-1 = id";
   126 by (Blast_tac 1);
   127 qed "converse_id";
   128 Addsimps [converse_id];
   129 
   130 (** Domain **)
   131 
   132 qed_goalw "Domain_iff" thy [Domain_def]
   133     "a: Domain(r) = (EX y. (a,y): r)"
   134  (fn _=> [ (Blast_tac 1) ]);
   135 
   136 qed_goal "DomainI" thy "!!a b r. (a,b): r ==> a: Domain(r)"
   137  (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
   138 
   139 qed_goal "DomainE" thy
   140     "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
   141  (fn prems=>
   142   [ (rtac (Domain_iff RS iffD1 RS exE) 1),
   143     (REPEAT (ares_tac prems 1)) ]);
   144 
   145 AddIs  [DomainI];
   146 AddSEs [DomainE];
   147 
   148 goal thy "Domain id = UNIV";
   149 by (Blast_tac 1);
   150 qed "Domain_id";
   151 Addsimps [Domain_id];
   152 
   153 (** Range **)
   154 
   155 qed_goalw "RangeI" thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
   156  (fn _ => [ (etac (converseI RS DomainI) 1) ]);
   157 
   158 qed_goalw "RangeE" thy [Range_def]
   159     "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
   160  (fn major::prems=>
   161   [ (rtac (major RS DomainE) 1),
   162     (resolve_tac prems 1),
   163     (etac converseD 1) ]);
   164 
   165 AddIs  [RangeI];
   166 AddSEs [RangeE];
   167 
   168 goal thy "Range id = UNIV";
   169 by (Blast_tac 1);
   170 qed "Range_id";
   171 Addsimps [Range_id];
   172 
   173 (*** Image of a set under a relation ***)
   174 
   175 qed_goalw "Image_iff" thy [Image_def]
   176     "b : r^^A = (? x:A. (x,b):r)"
   177  (fn _ => [ Blast_tac 1 ]);
   178 
   179 qed_goalw "Image_singleton" thy [Image_def]
   180     "r^^{a} = {b. (a,b):r}"
   181  (fn _ => [ Blast_tac 1 ]);
   182 
   183 qed_goal "Image_singleton_iff" thy
   184     "(b : r^^{a}) = ((a,b):r)"
   185  (fn _ => [ rtac (Image_iff RS trans) 1,
   186             Blast_tac 1 ]);
   187 
   188 AddIffs [Image_singleton_iff];
   189 
   190 qed_goalw "ImageI" thy [Image_def]
   191     "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
   192  (fn _ => [ (Blast_tac 1)]);
   193 
   194 qed_goalw "ImageE" thy [Image_def]
   195     "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
   196  (fn major::prems=>
   197   [ (rtac (major RS CollectE) 1),
   198     (Clarify_tac 1),
   199     (rtac (hd prems) 1),
   200     (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
   201 
   202 AddIs  [ImageI];
   203 AddSEs [ImageE];
   204 
   205 
   206 qed_goal "Image_empty" thy
   207     "R^^{} = {}"
   208  (fn _ => [ Blast_tac 1 ]);
   209 
   210 Addsimps [Image_empty];
   211 
   212 goal thy "id ^^ A = A";
   213 by (Blast_tac 1);
   214 qed "Image_id";
   215 
   216 Addsimps [Image_id];
   217 
   218 qed_goal "Image_Int_subset" thy
   219     "R ^^ (A Int B) <= R ^^ A Int R ^^ B"
   220  (fn _ => [ Blast_tac 1 ]);
   221 
   222 qed_goal "Image_Un" thy "R ^^ (A Un B) = R ^^ A Un R ^^ B"
   223  (fn _ => [ Blast_tac 1 ]);
   224 
   225 qed_goal "Image_subset" thy "!!A B r. r <= A Times B ==> r^^C <= B"
   226  (fn _ =>
   227   [ (rtac subsetI 1),
   228     (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
   229 
   230 (*NOT suitable for rewriting*)
   231 goal thy "r^^B = (UN y: B. r^^{y})";
   232 by (Blast_tac 1);
   233 qed "Image_eq_UN";