Link Search Menu Expand Document

Like equality but not equal to it

Another common type of relation is the following.

Definition. An equivalence relation is a relation \cong that is

  • reflexive
  • symmetric and
  • transitive

Equivalence relations are already built in to Lean’s core code

structure Equivalence {α : Sort u} (r : α  α  Prop) : Prop where
  refl  :  x, r x x
  symm  :  {x y}, r x y  r y x
  trans :  {x y z}, r x y  r y z  r x z

The prototypical example of an equivalence relation is equality ==. Here is another example prominent example.

Example. Let mZm \in \mathbb{Z}. Given two integers a,ba,b, we say aa is equivelant to bb modulo mm if mbam \mid b-a. We write abmod  ma \equiv b \mod m to denote this relation.

Let’s check this is reflexive. To say that aamod  ma \equiv a \mod m, we need, by definition, maa=0m \mid a - a = 0. But all integers divide 00: 0=0m0 = 0 \cdot m. So indeed this is reflexive.

For symmetry, assume that abmod  ma \equiv b \mod m. Then there is some cc with ba=cmb - a = cm. We also have ab=(ba)=(cm)=(c)ma - b = -(b-a) = -(cm) = (-c)m so we have bamod  mb \equiv a \mod m.

Now let’s check transitivity. Assume that abmod  ma \equiv b \mod m and that bcmod  mb \equiv c \mod m. Unfolding the definitions, we have d1d_1 and d2d_2 with ba=d1m, cb=d2mb - a = d_1 m,~ c - b = d_2 m Then ca=cb+ba=d1m+d2m=(d1+d2)mc - a = c - b + b - a = d_1 m + d_2 m = (d_1+d_2)m so mcam \mid c -a.

Another example we have already seen.

Example. Bijection of sets is an equivalence relation. For reflexivity, we use that the identity function idX:XX\operatorname{id}_X : X \to X is a bijection.

Assume that f:XYf : X \to Y is a bijection. Then we seen that we have an inverse f1:YXf^{-1} : Y \to X which is also a bijection. Thus, being in bijection is symmetric.

Finally, given bijections f:XYf: X \to Y and g:YZg: Y \to Z, the composition gf:XZg \circ f : X \to Z is a bijection giving transitivity.

One last example from the beginning of class.

Example. Bi-implication of proposition is an equivalence relation. We need to check

  • For all propositional formula XX, we have XXX \leftrightarrow X.
  • If XYX \leftrightarrow Y, then YXY \leftrightarrow X for any pair of propositional formula.
  • Given X,Y,ZX, Y, Z with XYX \leftrightarrow Y and YZY \leftrightarrow Z, we have XZX \leftrightarrow Z.

Here are the proofs in Lean

variable (X Y Z : Prop) 

theorem biimp_refl : X  X := fun h => h,fun h => h 

theorem biimp_symm (h : X  Y) : Y  X := h.mpr, h.mp 

theorem biimp_trans (h : X  Y) (h : Y  Z) : X  Z := 
  h.mp  h.mp, h.mpr  h.mpr 

Very often, properties of interest are preserved by an equivalence relation. Mentally, we start to treat equivalent elements as equal even through they are not.

But there is a construction by which equivalence becomes equality.

Definition. Let XX be a set with an equivalence relation \cong. For xx in XX, the equivalence class of xx is [x]:={xxx}[x] := \lbrace x^\prime \mid x \cong x^\prime \rbrace In other words, [x][x] is the set of elements that are equivalent to xx.

Example. Let’s take m=2m = 2 and consider the equivalence class of 00 modulo 22. Say 0dmod  20 \equiv d \mod 2 is just saying that 2d0=d2 \mid d - 0 = d. Thus, d[0]d \in [0] if and only if dd is even. Similarly, d[1]d \in [1] if and only if dd is odd.

Lemma. [x]=[x][x^\prime] = [x] if and only if xxx \cong x^\prime.

Proof. (Expand to view)

Assume that [x]=[x][x^\prime] = [x] then x[x]x^\prime \in [x^\prime] since xxx^\prime \cong x^\prime from reflexivity of \cong. Then x[x]x^\prime \in [x] so by definition xxx \cong x^\prime. Now assume that xxx \cong x^\prime. We have to show that [x]=[x][x] = [x^\prime] as sets. Assume that y[x]y \in [x]. By definition, we have xyx \cong y. From reflexivity, we have xxx^\prime \cong x. Then transitivity tells us that xyx^\prime \cong y. So by definition y[x]y \in [x^\prime]. Now assume that y[x]y \in [x^\prime]. Then xyx^\prime \cong y be definition. Using transitivity, we get xyx \cong y and y[x]y \in [x]. Thus, [x]=[x][x] = [x^\prime] as sets.

Using the previous lemma, we learn that [0][0] and [1][1] are the only equivalence classes mod 22. If dd is odd, then [d]=[1][d] = [1]. If dd is even, [d]=[0][d] = [0].

Definition. The quotient by an equivalence relation \cong is the set of equivalence classes of \cong: X/:={[x]xX}X/\cong := \lbrace [x] \mid x \in X \rbrace

The quotient comes with a quotient function π:XX/x[x]\pi : X \to X/ \cong \\ x \mapsto [x]

Example. Thus, Z/2={[0],[1]}\mathbb{Z}/\equiv_2 = \lbrace [0],[1] \rbrace. More generally, Z/m={[0],[1],[2],,[m1]}\mathbb{Z}/\equiv_m = \lbrace [0], [1], [2], \ldots, [m-1] \rbrace Since any integers aa can be written as a=r+qma = r + qm for 0r<m0 \leq r < m. Here rr is the remainder under division by mm.

Example. The quotient of Prop by is in bijection with the set of truth tables. This follows from completeness and soundness of propositional logic.

The set X/X/\cong satisfies a universal property with respect to functions f:X/Yf : X/\cong \to Y. More precisely, we have the following theorem.

Theorem. Let (X,)(X,\cong) be a set with an equivalence relation. Then, for any function f:XYf : X \to Y which satisfies the condition xxf(x)=f(x)x \cong x^\prime \to f(x) = f(x^\prime), we have a unique function f:X/Y\overline{f} : X / \cong \to Y with fπ=f\overline{f} \circ \pi = f.

Proof. (Expand to view)

First, we tackle uniqueness. Since π\pi is surjective, it has a right inverse. Thus, if fπ=fπ\overline{f} \circ \pi = \overline{f}^\prime \circ \pi, we can compose with the right inverse to get f=f\overline{f} = \overline{f}^\prime. Thus, the condition that fπ=f\overline{f} \circ \pi = f uniquely determines f\overline{f} _if_ it exists. To show existence, we "try" to define f([x])=f(x)\overline{f}([x]) = f(x). The essential problem here is that, as we have seen, we can have [x]=[x][x] = [x^\prime], with xxx \neq x^\prime. So from this definition if xxx \cong x^\prime, we also have f([x])=f(x)\overline{f}([x]) = f(x^\prime). So we need to check that if [x]=[x][x] = [x^\prime] that f([x])=f([x])\overline{f}([x]) = \overline{f}([x^\prime]). If [x]=[x][x] = [x^\prime], we know that xxx \cong x^\prime. By assumption we have f(x)=f(x)f(x) = f(x^\prime), but this says that f([x])=f(x)=f(x)=f([x]) \overline{f}([x]) = f(x) = f(x^\prime) = \overline{f}([x^\prime]) and our attempt at a function is actually a well-defined function.

The previous theorem says that composing with π\pi gives a bijection between the following two sets of functions {g:X/Y}π{f:XYf(x)=f(x) whenever xx}\lbrace g : X/\cong \to Y \rbrace \overset{- \circ \pi}{\to} \lbrace f : X \to Y \mid f(x) = f(x^\prime) \text{ whenever } x \cong x^\prime \rbrace Thus, we can understand functions out of X/X/\cong in terms of data that does not explicitly reference X/X/\cong itself. This is what is meant by a universal property: the set of functions out of X/X/\cong to YY are all functions XYX \to Y satisfies some condition.