src/HOL/Integ/Equiv.ML
author clasohm
Fri Mar 24 12:30:35 1995 +0100 (1995-03-24)
changeset 972 e61b058d58d2
parent 925 15539deb6863
child 1045 0cdf86973c49
permissions -rw-r--r--
changed syntax of tuples from <..., ...> to (..., ...)
     1 (*  Title: 	Equiv.ML
     2     ID:         $Id$
     3     Authors: 	Riccardo Mattolini, Dip. Sistemi e Informatica
     4         	Lawrence C Paulson, Cambridge University Computer Laboratory
     5     Copyright   1994 Universita' di Firenze
     6     Copyright   1993  University of Cambridge
     7 
     8 Equivalence relations in HOL Set Theory 
     9 *)
    10 
    11 open Equiv;
    12 
    13 (*** Suppes, Theorem 70: r is an equiv relation iff converse(r) O r = r ***)
    14 
    15 (** first half: equiv A r ==> converse(r) O r = r **)
    16 
    17 goalw Equiv.thy [trans_def,sym_def,converse_def]
    18     "!!r. [| sym(r); trans(r) |] ==> converse(r) O r <= r";
    19 by (fast_tac (comp_cs addSEs [converseD]) 1);
    20 qed "sym_trans_comp_subset";
    21 
    22 val [major,minor]=goal Equiv.thy "[|(x,y):r; z=(x,y)|] ==>  z:r";
    23 by (simp_tac (prod_ss addsimps [minor]) 1);
    24 by (rtac major 1);
    25 qed "BreakPair";
    26 
    27 val [major]=goal Equiv.thy "[|? x y. (x,y):r & z=(x,y)|] ==>  z:r";
    28 by (resolve_tac [major RS exE] 1);
    29 by (etac exE 1);
    30 by (etac conjE 1);
    31 by (asm_simp_tac (prod_ss addsimps [minor]) 1);
    32 qed "BreakPair1";
    33 
    34 val [major,minor]=goal Equiv.thy "[|z:r; z=(x,y)|] ==> (x,y):r";
    35 by (simp_tac (prod_ss addsimps [minor RS sym]) 1);
    36 by (rtac major 1);
    37 qed "BuildPair";
    38 
    39 val [major]=goal Equiv.thy "[|? z:r. (x,y)=z|] ==> (x,y):r";
    40 by (resolve_tac [major RS bexE] 1);
    41 by (asm_simp_tac (prod_ss addsimps []) 1);
    42 qed "BuildPair1";
    43 
    44 val rel_pair_cs = rel_cs addIs [BuildPair1] 
    45                          addEs [BreakPair1];
    46 
    47 goalw Equiv.thy [refl_def,converse_def]
    48     "!!A r. refl A r ==> r <= converse(r) O r";
    49 by (step_tac comp_cs 1);
    50 by (dtac subsetD 1);
    51 by (assume_tac 1);
    52 by (etac SigmaE 1);
    53 by (rtac BreakPair1 1);
    54 by (fast_tac comp_cs 1);
    55 qed "refl_comp_subset";
    56 
    57 goalw Equiv.thy [equiv_def]
    58     "!!A r. equiv A r ==> converse(r) O r = r";
    59 by (rtac equalityI 1);
    60 by (REPEAT (ares_tac [sym_trans_comp_subset, refl_comp_subset] 1
    61      ORELSE etac conjE 1));
    62 qed "equiv_comp_eq";
    63 
    64 (*second half*)
    65 goalw Equiv.thy [equiv_def,refl_def,sym_def,trans_def]
    66     "!!A r. [| converse(r) O r = r;  Domain(r) = A |] ==> equiv A r";
    67 by (etac equalityE 1);
    68 by (subgoal_tac "ALL x y. (x,y) : r --> (y,x) : r" 1);
    69 by (safe_tac set_cs);
    70 by (fast_tac (set_cs addSIs [converseI] addIs [compI]) 3);
    71 by (fast_tac (set_cs addSIs [converseI] addIs [compI] addSEs [DomainE]) 2);
    72 by (fast_tac (rel_pair_cs addSEs [SigmaE] addSIs [SigmaI]) 1);
    73 by (dtac subsetD 1);
    74 by (dtac subsetD 1);
    75 by (fast_tac rel_cs 1);
    76 by (fast_tac rel_cs 1);
    77 by flexflex_tac;
    78 by (dtac subsetD 1);
    79 by (fast_tac converse_cs 2);
    80 by (fast_tac converse_cs 1);
    81 qed "comp_equivI";
    82 
    83 (** Equivalence classes **)
    84 
    85 (*Lemma for the next result*)
    86 goalw Equiv.thy [equiv_def,trans_def,sym_def]
    87     "!!A r. [| equiv A r;  (a,b): r |] ==> r^^{a} <= r^^{b}";
    88 by (safe_tac rel_cs);
    89 by (rtac ImageI 1);
    90 by (fast_tac rel_cs 2);
    91 by (fast_tac rel_cs 1);
    92 qed "equiv_class_subset";
    93 
    94 goal Equiv.thy "!!A r. [| equiv A r;  (a,b): r |] ==> r^^{a} = r^^{b}";
    95 by (REPEAT (ares_tac [equalityI, equiv_class_subset] 1));
    96 by (rewrite_goals_tac [equiv_def,sym_def]);
    97 by (fast_tac rel_cs 1);
    98 qed "equiv_class_eq";
    99 
   100 val prems = goalw Equiv.thy [equiv_def,refl_def]
   101     "[| equiv A r;  a: A |] ==> a: r^^{a}";
   102 by (cut_facts_tac prems 1);
   103 by (fast_tac rel_cs 1);
   104 qed "equiv_class_self";
   105 
   106 (*Lemma for the next result*)
   107 goalw Equiv.thy [equiv_def,refl_def]
   108     "!!A r. [| equiv A r;  r^^{b} <= r^^{a};  b: A |] ==> (a,b): r";
   109 by (fast_tac rel_cs 1);
   110 qed "subset_equiv_class";
   111 
   112 val prems = goal Equiv.thy
   113     "[| r^^{a} = r^^{b};  equiv A r;  b: A |] ==> (a,b): r";
   114 by (REPEAT (resolve_tac (prems @ [equalityD2, subset_equiv_class]) 1));
   115 qed "eq_equiv_class";
   116 
   117 (*thus r^^{a} = r^^{b} as well*)
   118 goalw Equiv.thy [equiv_def,trans_def,sym_def]
   119     "!!A r. [| equiv A r;  x: (r^^{a} Int r^^{b}) |] ==> (a,b): r";
   120 by (fast_tac rel_cs 1);
   121 qed "equiv_class_nondisjoint";
   122 
   123 val [major] = goalw Equiv.thy [equiv_def,refl_def]
   124     "equiv A r ==> r <= Sigma A (%x.A)";
   125 by (rtac (major RS conjunct1 RS conjunct1) 1);
   126 qed "equiv_type";
   127 
   128 goal Equiv.thy
   129     "!!A r. equiv A r ==> ((x,y): r) = (r^^{x} = r^^{y} & x:A & y:A)";
   130 by (safe_tac rel_cs);
   131 by ((rtac equiv_class_eq 1) THEN (assume_tac 1) THEN (assume_tac 1));
   132 by ((rtac eq_equiv_class 3) THEN 
   133     (assume_tac 4) THEN (assume_tac 4) THEN (assume_tac 3));
   134 by ((dtac equiv_type 1) THEN (dtac rev_subsetD 1) THEN
   135     (assume_tac 1) THEN (dtac SigmaD1 1) THEN (assume_tac 1));
   136 by ((dtac equiv_type 1) THEN (dtac rev_subsetD 1) THEN
   137     (assume_tac 1) THEN (dtac SigmaD2 1) THEN (assume_tac 1));
   138 qed "equiv_class_eq_iff";
   139 
   140 goal Equiv.thy
   141     "!!A r. [| equiv A r;  x: A;  y: A |] ==> (r^^{x} = r^^{y}) = ((x,y): r)";
   142 by (safe_tac rel_cs);
   143 by ((rtac eq_equiv_class 1) THEN 
   144     (assume_tac 1) THEN (assume_tac 1) THEN (assume_tac 1));
   145 by ((rtac equiv_class_eq 1) THEN 
   146     (assume_tac 1) THEN (assume_tac 1));
   147 qed "eq_equiv_class_iff";
   148 
   149 (*** Quotients ***)
   150 
   151 (** Introduction/elimination rules -- needed? **)
   152 
   153 val prems = goalw Equiv.thy [quotient_def] "x:A ==> r^^{x}: A/r";
   154 by (rtac UN_I 1);
   155 by (resolve_tac prems 1);
   156 by (rtac singletonI 1);
   157 qed "quotientI";
   158 
   159 val [major,minor] = goalw Equiv.thy [quotient_def]
   160     "[| X:(A/r);  !!x. [| X = r^^{x};  x:A |] ==> P |] 	\
   161 \    ==> P";
   162 by (resolve_tac [major RS UN_E] 1);
   163 by (rtac minor 1);
   164 by (assume_tac 2);
   165 by (fast_tac rel_cs 1);
   166 qed "quotientE";
   167 
   168 (** Not needed by Theory Integ --> bypassed **)
   169 (**goalw Equiv.thy [equiv_def,refl_def,quotient_def]
   170     "!!A r. equiv A r ==> Union(A/r) = A";
   171 by (fast_tac eq_cs 1);
   172 qed "Union_quotient";
   173 **)
   174 
   175 (** Not needed by Theory Integ --> bypassed **)
   176 (*goalw Equiv.thy [quotient_def]
   177     "!!A r. [| equiv A r;  X: A/r;  Y: A/r |] ==> X=Y | (X Int Y <= 0)";
   178 by (safe_tac (ZF_cs addSIs [equiv_class_eq]));
   179 by (assume_tac 1);
   180 by (rewrite_goals_tac [equiv_def,trans_def,sym_def]);
   181 by (fast_tac ZF_cs 1);
   182 qed "quotient_disj";
   183 **)
   184 
   185 (**** Defining unary operations upon equivalence classes ****)
   186 
   187 (* theorem needed to prove UN_equiv_class *)
   188 goal Set.thy "!!A. [| a:A; ! y:A. b(y)=b(a) |] ==> (UN y:A. b(y))=b(a)";
   189 by (fast_tac (eq_cs addSEs [equalityE]) 1);
   190 qed "UN_singleton_lemma";
   191 val UN_singleton = ballI RSN (2,UN_singleton_lemma);
   192 
   193 
   194 (** These proofs really require as local premises
   195      equiv A r;  congruent r b
   196 **)
   197 
   198 (*Conversion rule*)
   199 val prems as [equivA,bcong,_] = goal Equiv.thy
   200     "[| equiv A r;  congruent r b;  a: A |] ==> (UN x:r^^{a}. b(x)) = b(a)";
   201 by (cut_facts_tac prems 1);
   202 by (rtac UN_singleton 1);
   203 by (rtac equiv_class_self 1);
   204 by (assume_tac 1);
   205 by (assume_tac 1);
   206 by (rewrite_goals_tac [equiv_def,congruent_def,sym_def]);
   207 by (fast_tac rel_cs 1);
   208 qed "UN_equiv_class";
   209 
   210 (*Resolve th against the "local" premises*)
   211 val localize = RSLIST [equivA,bcong];
   212 
   213 (*type checking of  UN x:r``{a}. b(x) *)
   214 val _::_::prems = goalw Equiv.thy [quotient_def]
   215     "[| equiv A r;  congruent r b;  X: A/r;	\
   216 \	!!x.  x : A ==> b(x) : B |] 	\
   217 \    ==> (UN x:X. b(x)) : B";
   218 by (cut_facts_tac prems 1);
   219 by (safe_tac rel_cs);
   220 by (rtac (localize UN_equiv_class RS ssubst) 1);
   221 by (REPEAT (ares_tac prems 1));
   222 qed "UN_equiv_class_type";
   223 
   224 (*Sufficient conditions for injectiveness.  Could weaken premises!
   225   major premise could be an inclusion; bcong could be !!y. y:A ==> b(y):B
   226 *)
   227 val _::_::prems = goalw Equiv.thy [quotient_def]
   228     "[| equiv A r;   congruent r b;  \
   229 \       (UN x:X. b(x))=(UN y:Y. b(y));  X: A/r;  Y: A/r;  \
   230 \       !!x y. [| x:A; y:A; b(x)=b(y) |] ==> (x,y):r |] 	\
   231 \    ==> X=Y";
   232 by (cut_facts_tac prems 1);
   233 by (safe_tac rel_cs);
   234 by (rtac (equivA RS equiv_class_eq) 1);
   235 by (REPEAT (ares_tac prems 1));
   236 by (etac box_equals 1);
   237 by (REPEAT (ares_tac [localize UN_equiv_class] 1));
   238 qed "UN_equiv_class_inject";
   239 
   240 
   241 (**** Defining binary operations upon equivalence classes ****)
   242 
   243 
   244 goalw Equiv.thy [congruent_def,congruent2_def,equiv_def,refl_def]
   245     "!!A r. [| equiv A r;  congruent2 r b;  a: A |] ==> congruent r (b a)";
   246 by (fast_tac rel_cs 1);
   247 qed "congruent2_implies_congruent";
   248 
   249 val equivA::prems = goalw Equiv.thy [congruent_def]
   250     "[| equiv A r;  congruent2 r b;  a: A |] ==> \
   251 \    congruent r (%x1. UN x2:r^^{a}. b x1 x2)";
   252 by (cut_facts_tac (equivA::prems) 1);
   253 by (safe_tac rel_cs);
   254 by (rtac (equivA RS equiv_type RS subsetD RS SigmaE2) 1);
   255 by (assume_tac 1);
   256 by (asm_simp_tac (prod_ss addsimps [equivA RS UN_equiv_class,
   257 				 congruent2_implies_congruent]) 1);
   258 by (rewrite_goals_tac [congruent2_def,equiv_def,refl_def]);
   259 by (fast_tac rel_cs 1);
   260 qed "congruent2_implies_congruent_UN";
   261 
   262 val prems as equivA::_ = goal Equiv.thy
   263     "[| equiv A r;  congruent2 r b;  a1: A;  a2: A |]  \
   264 \    ==> (UN x1:r^^{a1}. UN x2:r^^{a2}. b x1 x2) = b a1 a2";
   265 by (cut_facts_tac prems 1);
   266 by (asm_simp_tac (prod_ss addsimps [equivA RS UN_equiv_class,
   267 				    congruent2_implies_congruent,
   268 				    congruent2_implies_congruent_UN]) 1);
   269 qed "UN_equiv_class2";
   270 
   271 (*type checking*)
   272 val prems = goalw Equiv.thy [quotient_def]
   273     "[| equiv A r;  congruent2 r b;  \
   274 \       X1: A/r;  X2: A/r;	\
   275 \	!!x1 x2.  [| x1: A; x2: A |] ==> b x1 x2 : B |]    \
   276 \    ==> (UN x1:X1. UN x2:X2. b x1 x2) : B";
   277 by (cut_facts_tac prems 1);
   278 by (safe_tac rel_cs);
   279 by (REPEAT (ares_tac (prems@[UN_equiv_class_type,
   280 			     congruent2_implies_congruent_UN,
   281 			     congruent2_implies_congruent, quotientI]) 1));
   282 qed "UN_equiv_class_type2";
   283 
   284 
   285 (*Suggested by John Harrison -- the two subproofs may be MUCH simpler
   286   than the direct proof*)
   287 val prems = goalw Equiv.thy [congruent2_def,equiv_def,refl_def]
   288     "[| equiv A r;	\
   289 \       !! y z w. [| w: A;  (y,z) : r |] ==> b y w = b z w;      \
   290 \       !! y z w. [| w: A;  (y,z) : r |] ==> b w y = b w z       \
   291 \    |] ==> congruent2 r b";
   292 by (cut_facts_tac prems 1);
   293 by (safe_tac rel_cs);
   294 by (rtac trans 1);
   295 by (REPEAT (ares_tac prems 1
   296      ORELSE etac (subsetD RS SigmaE2) 1 THEN assume_tac 2 THEN assume_tac 1));
   297 qed "congruent2I";
   298 
   299 val [equivA,commute,congt] = goal Equiv.thy
   300     "[| equiv A r;	\
   301 \       !! y z. [| y: A;  z: A |] ==> b y z = b z y;        \
   302 \       !! y z w. [| w: A;  (y,z): r |] ==> b w y = b w z	\
   303 \    |] ==> congruent2 r b";
   304 by (resolve_tac [equivA RS congruent2I] 1);
   305 by (rtac (commute RS trans) 1);
   306 by (rtac (commute RS trans RS sym) 3);
   307 by (rtac sym 5);
   308 by (REPEAT (ares_tac [congt] 1
   309      ORELSE etac (equivA RS equiv_type RS subsetD RS SigmaE2) 1));
   310 qed "congruent2_commuteI";
   311