src/HOL/Integ/Equiv.ML
author paulson
Thu Nov 21 15:28:25 1996 +0100 (1996-11-21)
changeset 2215 ebf910e7ec87
parent 2036 62ff902eeffc
child 3358 13f1df323daf
permissions -rw-r--r--
Tidied up some proofs, ...
     1 (*  Title:      Equiv.ML
     2     ID:         $Id$
     3     Authors:    Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1996  University of Cambridge
     5 
     6 Equivalence relations in HOL Set Theory 
     7 *)
     8 
     9 val RSLIST = curry (op MRS);
    10 
    11 open Equiv;
    12 
    13 Delrules [equalityI];
    14 
    15 (*** Suppes, Theorem 70: r is an equiv relation iff converse(r) O r = r ***)
    16 
    17 (** first half: equiv A r ==> converse(r) O r = r **)
    18 
    19 goalw Equiv.thy [trans_def,sym_def,converse_def]
    20     "!!r. [| sym(r); trans(r) |] ==> converse(r) O r <= r";
    21 by (fast_tac (!claset addSEs [converseD]) 1);
    22 qed "sym_trans_comp_subset";
    23 
    24 goalw Equiv.thy [refl_def]
    25     "!!A r. refl A r ==> r <= converse(r) O r";
    26 by (fast_tac (!claset addIs [compI]) 1);
    27 qed "refl_comp_subset";
    28 
    29 goalw Equiv.thy [equiv_def]
    30     "!!A r. equiv A r ==> converse(r) O r = r";
    31 by (rtac equalityI 1);
    32 by (REPEAT (ares_tac [sym_trans_comp_subset, refl_comp_subset] 1
    33      ORELSE etac conjE 1));
    34 qed "equiv_comp_eq";
    35 
    36 (*second half*)
    37 goalw Equiv.thy [equiv_def,refl_def,sym_def,trans_def]
    38     "!!A r. [| converse(r) O r = r;  Domain(r) = A |] ==> equiv A r";
    39 by (etac equalityE 1);
    40 by (subgoal_tac "ALL x y. (x,y) : r --> (y,x) : r" 1);
    41 by (Step_tac 1);
    42 by (fast_tac (!claset addSIs [converseI] addIs [compI]) 3);
    43 by (ALLGOALS (fast_tac (!claset addIs [compI] addSEs [compE])));
    44 qed "comp_equivI";
    45 
    46 (** Equivalence classes **)
    47 
    48 (*Lemma for the next result*)
    49 goalw Equiv.thy [equiv_def,trans_def,sym_def]
    50     "!!A r. [| equiv A r;  (a,b): r |] ==> r^^{a} <= r^^{b}";
    51 by (Step_tac 1);
    52 by (rtac ImageI 1);
    53 by (Fast_tac 2);
    54 by (Fast_tac 1);
    55 qed "equiv_class_subset";
    56 
    57 goal Equiv.thy "!!A r. [| equiv A r;  (a,b): r |] ==> r^^{a} = r^^{b}";
    58 by (REPEAT (ares_tac [equalityI, equiv_class_subset] 1));
    59 by (rewrite_goals_tac [equiv_def,sym_def]);
    60 by (Fast_tac 1);
    61 qed "equiv_class_eq";
    62 
    63 goalw Equiv.thy [equiv_def,refl_def]
    64     "!!A r. [| equiv A r;  a: A |] ==> a: r^^{a}";
    65 by (Fast_tac 1);
    66 qed "equiv_class_self";
    67 
    68 (*Lemma for the next result*)
    69 goalw Equiv.thy [equiv_def,refl_def]
    70     "!!A r. [| equiv A r;  r^^{b} <= r^^{a};  b: A |] ==> (a,b): r";
    71 by (Fast_tac 1);
    72 qed "subset_equiv_class";
    73 
    74 goal Equiv.thy
    75     "!!A r. [| r^^{a} = r^^{b};  equiv A r;  b: A |] ==> (a,b): r";
    76 by (REPEAT (ares_tac [equalityD2, subset_equiv_class] 1));
    77 qed "eq_equiv_class";
    78 
    79 (*thus r^^{a} = r^^{b} as well*)
    80 goalw Equiv.thy [equiv_def,trans_def,sym_def]
    81     "!!A r. [| equiv A r;  x: (r^^{a} Int r^^{b}) |] ==> (a,b): r";
    82 by (Fast_tac 1);
    83 qed "equiv_class_nondisjoint";
    84 
    85 val [major] = goalw Equiv.thy [equiv_def,refl_def]
    86     "equiv A r ==> r <= A Times A";
    87 by (rtac (major RS conjunct1 RS conjunct1) 1);
    88 qed "equiv_type";
    89 
    90 goal Equiv.thy
    91     "!!A r. equiv A r ==> ((x,y): r) = (r^^{x} = r^^{y} & x:A & y:A)";
    92 by (Step_tac 1);
    93 by ((rtac equiv_class_eq 1) THEN (assume_tac 1) THEN (assume_tac 1));
    94 by ((rtac eq_equiv_class 3) THEN 
    95     (assume_tac 4) THEN (assume_tac 4) THEN (assume_tac 3));
    96 by ((dtac equiv_type 1) THEN (dtac rev_subsetD 1) THEN
    97     (assume_tac 1) THEN (dtac SigmaD1 1) THEN (assume_tac 1));
    98 by ((dtac equiv_type 1) THEN (dtac rev_subsetD 1) THEN
    99     (assume_tac 1) THEN (dtac SigmaD2 1) THEN (assume_tac 1));
   100 qed "equiv_class_eq_iff";
   101 
   102 goal Equiv.thy
   103     "!!A r. [| equiv A r;  x: A;  y: A |] ==> (r^^{x} = r^^{y}) = ((x,y): r)";
   104 by (Step_tac 1);
   105 by ((rtac eq_equiv_class 1) THEN 
   106     (assume_tac 1) THEN (assume_tac 1) THEN (assume_tac 1));
   107 by ((rtac equiv_class_eq 1) THEN 
   108     (assume_tac 1) THEN (assume_tac 1));
   109 qed "eq_equiv_class_iff";
   110 
   111 (*** Quotients ***)
   112 
   113 (** Introduction/elimination rules -- needed? **)
   114 
   115 goalw Equiv.thy [quotient_def] "!!A. x:A ==> r^^{x}: A/r";
   116 by (Fast_tac 1);
   117 qed "quotientI";
   118 
   119 val [major,minor] = goalw Equiv.thy [quotient_def]
   120     "[| X:(A/r);  !!x. [| X = r^^{x};  x:A |] ==> P |]  \
   121 \    ==> P";
   122 by (resolve_tac [major RS UN_E] 1);
   123 by (rtac minor 1);
   124 by (assume_tac 2);
   125 by (Fast_tac 1);
   126 qed "quotientE";
   127 
   128 (** Not needed by Theory Integ --> bypassed **)
   129 (**goalw Equiv.thy [equiv_def,refl_def,quotient_def]
   130     "!!A r. equiv A r ==> Union(A/r) = A";
   131 by (Fast_tac 1);
   132 qed "Union_quotient";
   133 **)
   134 
   135 (** Not needed by Theory Integ --> bypassed **)
   136 (*goalw Equiv.thy [quotient_def]
   137     "!!A r. [| equiv A r;  X: A/r;  Y: A/r |] ==> X=Y | (X Int Y <= 0)";
   138 by (safe_tac (!claset addSIs [equiv_class_eq]));
   139 by (assume_tac 1);
   140 by (rewrite_goals_tac [equiv_def,trans_def,sym_def]);
   141 by (Fast_tac 1);
   142 qed "quotient_disj";
   143 **)
   144 
   145 (**** Defining unary operations upon equivalence classes ****)
   146 
   147 (* theorem needed to prove UN_equiv_class *)
   148 goal Set.thy "!!A. [| a:A; ! y:A. b(y)=b(a) |] ==> (UN y:A. b(y))=b(a)";
   149 by (fast_tac (!claset addSEs [equalityE] addSIs [equalityI]) 1);
   150 qed "UN_singleton_lemma";
   151 val UN_singleton = ballI RSN (2,UN_singleton_lemma);
   152 
   153 
   154 (** These proofs really require the local premises
   155      equiv A r;  congruent r b
   156 **)
   157 
   158 (*Conversion rule*)
   159 goal Equiv.thy "!!A r. [| equiv A r;  congruent r b;  a: A |] \
   160 \                      ==> (UN x:r^^{a}. b(x)) = b(a)";
   161 by (rtac (equiv_class_self RS UN_singleton) 1 THEN REPEAT (assume_tac 1));
   162 by (rewrite_goals_tac [equiv_def,congruent_def,sym_def]);
   163 by (Fast_tac 1);
   164 qed "UN_equiv_class";
   165 
   166 (*type checking of  UN x:r``{a}. b(x) *)
   167 val prems = goalw Equiv.thy [quotient_def]
   168     "[| equiv A r;  congruent r b;  X: A/r;     \
   169 \       !!x.  x : A ==> b(x) : B |]             \
   170 \    ==> (UN x:X. b(x)) : B";
   171 by (cut_facts_tac prems 1);
   172 by (Step_tac 1);
   173 by (stac UN_equiv_class 1);
   174 by (REPEAT (ares_tac prems 1));
   175 qed "UN_equiv_class_type";
   176 
   177 (*Sufficient conditions for injectiveness.  Could weaken premises!
   178   major premise could be an inclusion; bcong could be !!y. y:A ==> b(y):B
   179 *)
   180 val prems = goalw Equiv.thy [quotient_def]
   181     "[| equiv A r;   congruent r b;  \
   182 \       (UN x:X. b(x))=(UN y:Y. b(y));  X: A/r;  Y: A/r;        \
   183 \       !!x y. [| x:A; y:A; b(x)=b(y) |] ==> (x,y):r |]         \
   184 \    ==> X=Y";
   185 by (cut_facts_tac prems 1);
   186 by (Step_tac 1);
   187 by (rtac equiv_class_eq 1);
   188 by (REPEAT (ares_tac prems 1));
   189 by (etac box_equals 1);
   190 by (REPEAT (ares_tac [UN_equiv_class] 1));
   191 qed "UN_equiv_class_inject";
   192 
   193 
   194 (**** Defining binary operations upon equivalence classes ****)
   195 
   196 
   197 goalw Equiv.thy [congruent_def,congruent2_def,equiv_def,refl_def]
   198     "!!A r. [| equiv A r;  congruent2 r b;  a: A |] ==> congruent r (b a)";
   199 by (Fast_tac 1);
   200 qed "congruent2_implies_congruent";
   201 
   202 goalw Equiv.thy [congruent_def]
   203     "!!A r. [| equiv A r;  congruent2 r b;  a: A |] ==> \
   204 \    congruent r (%x1. UN x2:r^^{a}. b x1 x2)";
   205 by (Step_tac 1);
   206 by (rtac (equiv_type RS subsetD RS SigmaE2) 1 THEN REPEAT (assume_tac 1));
   207 by (asm_simp_tac (!simpset addsimps [UN_equiv_class,
   208                                      congruent2_implies_congruent]) 1);
   209 by (rewrite_goals_tac [congruent2_def,equiv_def,refl_def]);
   210 by (Fast_tac 1);
   211 qed "congruent2_implies_congruent_UN";
   212 
   213 goal Equiv.thy
   214     "!!A r. [| equiv A r;  congruent2 r b;  a1: A;  a2: A |]  \
   215 \    ==> (UN x1:r^^{a1}. UN x2:r^^{a2}. b x1 x2) = b a1 a2";
   216 by (asm_simp_tac (!simpset addsimps [UN_equiv_class,
   217                                      congruent2_implies_congruent,
   218                                      congruent2_implies_congruent_UN]) 1);
   219 qed "UN_equiv_class2";
   220 
   221 (*type checking*)
   222 val prems = goalw Equiv.thy [quotient_def]
   223     "[| equiv A r;  congruent2 r b;  \
   224 \       X1: A/r;  X2: A/r;      \
   225 \       !!x1 x2.  [| x1: A; x2: A |] ==> b x1 x2 : B |]    \
   226 \    ==> (UN x1:X1. UN x2:X2. b x1 x2) : B";
   227 by (cut_facts_tac prems 1);
   228 by (Step_tac 1);
   229 by (REPEAT (ares_tac (prems@[UN_equiv_class_type,
   230                              congruent2_implies_congruent_UN,
   231                              congruent2_implies_congruent, quotientI]) 1));
   232 qed "UN_equiv_class_type2";
   233 
   234 
   235 (*Suggested by John Harrison -- the two subproofs may be MUCH simpler
   236   than the direct proof*)
   237 val prems = goalw Equiv.thy [congruent2_def,equiv_def,refl_def]
   238     "[| equiv A r;      \
   239 \       !! y z w. [| w: A;  (y,z) : r |] ==> b y w = b z w;      \
   240 \       !! y z w. [| w: A;  (y,z) : r |] ==> b w y = b w z       \
   241 \    |] ==> congruent2 r b";
   242 by (cut_facts_tac prems 1);
   243 by (Step_tac 1);
   244 by (rtac trans 1);
   245 by (REPEAT (ares_tac prems 1
   246      ORELSE etac (subsetD RS SigmaE2) 1 THEN assume_tac 2 THEN assume_tac 1));
   247 qed "congruent2I";
   248 
   249 val [equivA,commute,congt] = goal Equiv.thy
   250     "[| equiv A r;      \
   251 \       !! y z. [| y: A;  z: A |] ==> b y z = b z y;        \
   252 \       !! y z w. [| w: A;  (y,z): r |] ==> b w y = b w z       \
   253 \    |] ==> congruent2 r b";
   254 by (resolve_tac [equivA RS congruent2I] 1);
   255 by (rtac (commute RS trans) 1);
   256 by (rtac (commute RS trans RS sym) 3);
   257 by (rtac sym 5);
   258 by (REPEAT (ares_tac [congt] 1
   259      ORELSE etac (equivA RS equiv_type RS subsetD RS SigmaE2) 1));
   260 qed "congruent2_commuteI";
   261