We talked about relations in general and equivalence relations

A **relation** on sets *X*_{1}, *X*_{2}, ..., *X*_{n} is simply a subset of *X*_{1} × *X*_{2} × . . . × *X*_{n}. If (*x*_{1}, *x*_{2}, . . . , *x*_{n}) ∈ *R*, we think of the elements *x*_{1}, *x*_{2}, as being related.

A **binary relation R on a set A** is a relation between

Examples of binary relations:

- equality (on sets of sets, or sets of functions, or sets of numbers)
- less than (on numbers)
- sitting on the left of (on the set of people in the room)
- extends (on the set of partial functions from A to B)
- the "everything is related" relation (
*A*×*A*) on any set*A* - the "nothing is related" relation (∅) on any set
*A*

A binary relation *R* on *A* is an **equivalence relation** if it satisfies the following three properties:

**Reflexivity**: for all*a*∈*A*,*a**R**a*.**Symmetry**: for all*a*and*b*∈*A*, if*a**R**b*then*b**R**a*.**Transitivity**: for all*a*,*b*, and*c*∈*A*, if*a**R**b*and*b**R**c*then*a**R**c*.

When writing a program that implements an "equals" method, you should always check that equals satisfies these properties. Otherwise, programmers will get confused.