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