src/HOL/Relation.ML
changeset 1128 64b30e3cc6d4
child 1264 3eb91524b938
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Relation.ML	Fri May 26 18:11:47 1995 +0200
     1.3 @@ -0,0 +1,173 @@
     1.4 +(*  Title: 	Relation.ML
     1.5 +    ID:         $Id$
     1.6 +    Authors: 	Riccardo Mattolini, Dip. Sistemi e Informatica
     1.7 +        	Lawrence C Paulson, Cambridge University Computer Laboratory
     1.8 +    Copyright   1994 Universita' di Firenze
     1.9 +    Copyright   1993  University of Cambridge
    1.10 +*)
    1.11 +
    1.12 +val RSLIST = curry (op MRS);
    1.13 +
    1.14 +open Relation;
    1.15 +
    1.16 +(** Identity relation **)
    1.17 +
    1.18 +goalw Relation.thy [id_def] "(a,a) : id";  
    1.19 +by (rtac CollectI 1);
    1.20 +by (rtac exI 1);
    1.21 +by (rtac refl 1);
    1.22 +qed "idI";
    1.23 +
    1.24 +val major::prems = goalw Relation.thy [id_def]
    1.25 +    "[| p: id;  !!x.[| p = (x,x) |] ==> P  \
    1.26 +\    |] ==>  P";  
    1.27 +by (rtac (major RS CollectE) 1);
    1.28 +by (etac exE 1);
    1.29 +by (eresolve_tac prems 1);
    1.30 +qed "idE";
    1.31 +
    1.32 +goalw Relation.thy [id_def] "(a,b):id = (a=b)";
    1.33 +by(fast_tac prod_cs 1);
    1.34 +qed "pair_in_id_conv";
    1.35 +
    1.36 +
    1.37 +(** Composition of two relations **)
    1.38 +
    1.39 +val prems = goalw Relation.thy [comp_def]
    1.40 +    "[| (a,b):s; (b,c):r |] ==> (a,c) : r O s";
    1.41 +by (fast_tac (set_cs addIs prems) 1);
    1.42 +qed "compI";
    1.43 +
    1.44 +(*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
    1.45 +val prems = goalw Relation.thy [comp_def]
    1.46 +    "[| xz : r O s;  \
    1.47 +\       !!x y z. [| xz = (x,z);  (x,y):s;  (y,z):r |] ==> P \
    1.48 +\    |] ==> P";
    1.49 +by (cut_facts_tac prems 1);
    1.50 +by (REPEAT (eresolve_tac [CollectE, exE, conjE] 1 ORELSE ares_tac prems 1));
    1.51 +qed "compE";
    1.52 +
    1.53 +val prems = goal Relation.thy
    1.54 +    "[| (a,c) : r O s;  \
    1.55 +\       !!y. [| (a,y):s;  (y,c):r |] ==> P \
    1.56 +\    |] ==> P";
    1.57 +by (rtac compE 1);
    1.58 +by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [Pair_inject,ssubst] 1));
    1.59 +qed "compEpair";
    1.60 +
    1.61 +val comp_cs = prod_cs addIs [compI, idI] addSEs [compE, idE];
    1.62 +
    1.63 +goal Relation.thy "!!r s. [| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
    1.64 +by (fast_tac comp_cs 1);
    1.65 +qed "comp_mono";
    1.66 +
    1.67 +goal Relation.thy
    1.68 +    "!!r s. [| s <= Sigma A (%x.B);  r <= Sigma B (%x.C) |] ==> \
    1.69 +\           (r O s) <= Sigma A (%x.C)";
    1.70 +by (fast_tac comp_cs 1);
    1.71 +qed "comp_subset_Sigma";
    1.72 +
    1.73 +(** Natural deduction for trans(r) **)
    1.74 +
    1.75 +val prems = goalw Relation.thy [trans_def]
    1.76 +    "(!! x y z. [| (x,y):r;  (y,z):r |] ==> (x,z):r) ==> trans(r)";
    1.77 +by (REPEAT (ares_tac (prems@[allI,impI]) 1));
    1.78 +qed "transI";
    1.79 +
    1.80 +val major::prems = goalw Relation.thy [trans_def]
    1.81 +    "[| trans(r);  (a,b):r;  (b,c):r |] ==> (a,c):r";
    1.82 +by (cut_facts_tac [major] 1);
    1.83 +by (fast_tac (HOL_cs addIs prems) 1);
    1.84 +qed "transD";
    1.85 +
    1.86 +(** Natural deduction for converse(r) **)
    1.87 +
    1.88 +goalw Relation.thy [converse_def] "!!a b r. (a,b):r ==> (b,a):converse(r)";
    1.89 +by (simp_tac prod_ss 1);
    1.90 +by (fast_tac set_cs 1);
    1.91 +qed "converseI";
    1.92 +
    1.93 +goalw Relation.thy [converse_def] "!!a b r. (a,b) : converse(r) ==> (b,a) : r";
    1.94 +by (fast_tac comp_cs 1);
    1.95 +qed "converseD";
    1.96 +
    1.97 +qed_goalw "converseE" Relation.thy [converse_def]
    1.98 +    "[| yx : converse(r);  \
    1.99 +\       !!x y. [| yx=(y,x);  (x,y):r |] ==> P \
   1.100 +\    |] ==> P"
   1.101 + (fn [major,minor]=>
   1.102 +  [ (rtac (major RS CollectE) 1),
   1.103 +    (REPEAT (eresolve_tac [bexE,exE, conjE, minor] 1)),
   1.104 +    (hyp_subst_tac 1),
   1.105 +    (assume_tac 1) ]);
   1.106 +
   1.107 +val converse_cs = comp_cs addSIs [converseI] 
   1.108 +			  addSEs [converseD,converseE];
   1.109 +
   1.110 +(** Domain **)
   1.111 +
   1.112 +qed_goalw "Domain_iff" Relation.thy [Domain_def]
   1.113 +    "a: Domain(r) = (EX y. (a,y): r)"
   1.114 + (fn _=> [ (fast_tac comp_cs 1) ]);
   1.115 +
   1.116 +qed_goal "DomainI" Relation.thy "!!a b r. (a,b): r ==> a: Domain(r)"
   1.117 + (fn _ => [ (etac (exI RS (Domain_iff RS iffD2)) 1) ]);
   1.118 +
   1.119 +qed_goal "DomainE" Relation.thy
   1.120 +    "[| a : Domain(r);  !!y. (a,y): r ==> P |] ==> P"
   1.121 + (fn prems=>
   1.122 +  [ (rtac (Domain_iff RS iffD1 RS exE) 1),
   1.123 +    (REPEAT (ares_tac prems 1)) ]);
   1.124 +
   1.125 +(** Range **)
   1.126 +
   1.127 +qed_goalw "RangeI" Relation.thy [Range_def] "!!a b r.(a,b): r ==> b : Range(r)"
   1.128 + (fn _ => [ (etac (converseI RS DomainI) 1) ]);
   1.129 +
   1.130 +qed_goalw "RangeE" Relation.thy [Range_def]
   1.131 +    "[| b : Range(r);  !!x. (x,b): r ==> P |] ==> P"
   1.132 + (fn major::prems=>
   1.133 +  [ (rtac (major RS DomainE) 1),
   1.134 +    (resolve_tac prems 1),
   1.135 +    (etac converseD 1) ]);
   1.136 +
   1.137 +(*** Image of a set under a relation ***)
   1.138 +
   1.139 +qed_goalw "Image_iff" Relation.thy [Image_def]
   1.140 +    "b : r^^A = (? x:A. (x,b):r)"
   1.141 + (fn _ => [ fast_tac (comp_cs addIs [RangeI]) 1 ]);
   1.142 +
   1.143 +qed_goal "Image_singleton_iff" Relation.thy
   1.144 +    "(b : r^^{a}) = ((a,b):r)"
   1.145 + (fn _ => [ rtac (Image_iff RS trans) 1,
   1.146 +	    fast_tac comp_cs 1 ]);
   1.147 +
   1.148 +qed_goalw "ImageI" Relation.thy [Image_def]
   1.149 +    "!!a b r. [| (a,b): r;  a:A |] ==> b : r^^A"
   1.150 + (fn _ => [ (REPEAT (ares_tac [CollectI,RangeI,bexI] 1)),
   1.151 +            (resolve_tac [conjI ] 1),
   1.152 +            (resolve_tac [RangeI] 1),
   1.153 +            (REPEAT (fast_tac set_cs 1))]);
   1.154 +
   1.155 +qed_goalw "ImageE" Relation.thy [Image_def]
   1.156 +    "[| b: r^^A;  !!x.[| (x,b): r;  x:A |] ==> P |] ==> P"
   1.157 + (fn major::prems=>
   1.158 +  [ (rtac (major RS CollectE) 1),
   1.159 +    (safe_tac set_cs),
   1.160 +    (etac RangeE 1),
   1.161 +    (rtac (hd prems) 1),
   1.162 +    (REPEAT (etac bexE 1 ORELSE ares_tac prems 1)) ]);
   1.163 +
   1.164 +qed_goal "Image_subset" Relation.thy
   1.165 +    "!!A B r. r <= Sigma A (%x.B) ==> r^^C <= B"
   1.166 + (fn _ =>
   1.167 +  [ (rtac subsetI 1),
   1.168 +    (REPEAT (eresolve_tac [asm_rl, ImageE, subsetD RS SigmaD2] 1)) ]);
   1.169 +
   1.170 +val rel_cs = converse_cs addSIs [converseI] 
   1.171 +                         addIs  [ImageI, DomainI, RangeI]
   1.172 +                         addSEs [ImageE, DomainE, RangeE];
   1.173 +
   1.174 +val rel_eq_cs = rel_cs addSIs [equalityI];
   1.175 +
   1.176 +val rel_ss = prod_ss addsimps [pair_in_id_conv];