Like equality but not equal to it
Another common type of relation is the following.
Definition. An equivalence relation is a relation 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 . Given two integers , we say is equivelant to modulo if . We write to denote this relation.
Let’s check this is reflexive. To say that , we need, by definition, . But all integers divide : . So indeed this is reflexive.
For symmetry, assume that . Then there is some with . We also have so we have .
Now let’s check transitivity. Assume that and that . Unfolding the definitions, we have and with Then so .
Another example we have already seen.
Example. Bijection of sets is an equivalence relation. For reflexivity, we use that the identity function is a bijection.
Assume that is a bijection. Then we seen that we have an inverse which is also a bijection. Thus, being in bijection is symmetric.
Finally, given bijections and , the composition 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 , we have .
- If , then for any pair of propositional formula.
- Given with and , we have .
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 be a set with an equivalence relation . For in , the equivalence class of is In other words, is the set of elements that are equivalent to .
Example. Let’s take and consider the equivalence class of modulo . Say is just saying that . Thus, if and only if is even. Similarly, if and only if is odd.
Lemma. if and only if .
Proof. (Expand to view)
Assume that then since from reflexivity of . Then so by definition . Now assume that . We have to show that as sets. Assume that . By definition, we have . From reflexivity, we have . Then transitivity tells us that . So by definition . Now assume that . Then be definition. Using transitivity, we get and . Thus, as sets. ■
Using the previous lemma, we learn that and are the only equivalence classes mod . If is odd, then . If is even, .
Definition. The quotient by an equivalence relation is the set of equivalence classes of :
The quotient comes with a quotient function
Example. Thus, . More generally, Since any integers can be written as for . Here is the remainder under division by .
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 satisfies a universal property with respect to functions . More precisely, we have the following theorem.
Theorem. Let be a set with an equivalence relation. Then, for any function which satisfies the condition , we have a unique function with .
Proof. (Expand to view)
First, we tackle uniqueness. Since is surjective, it has a right inverse. Thus, if , we can compose with the right inverse to get . Thus, the condition that uniquely determines _if_ it exists. To show existence, we "try" to define . The essential problem here is that, as we have seen, we can have , with . So from this definition if , we also have . So we need to check that if that . If , we know that . By assumption we have , but this says that and our attempt at a function is actually a well-defined function. ■
The previous theorem says that composing with gives a bijection between the following two sets of functions Thus, we can understand functions out of in terms of data that does not explicitly reference itself. This is what is meant by a universal property: the set of functions out of to are all functions satisfies some condition.