# Lecture 7: relations

We talked about relations in general and equivalence relations

A relation on sets X1, X2, ..., Xn is simply a subset of X1 × X2 × . . .  × Xn. If (x1, x2, . . . , xn) ∈ R, we think of the elements x1, x2, as being related.

A binary relation R on a set A is a relation between A and itself, i.e. a subset of A × A. For elements a and b of A, we write aRb to indicate (a, b) ∈ R.

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:

1. Reflexivity: for all a ∈ A, aRa.
2. Symmetry: for all a and b ∈ A, if aRb then bRa.
3. Transitivity: for all a, b, and c ∈ A, if aRb and bRc then aRc.

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