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