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:

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.