An equivalence relation on a finite collection of objects may be described as follows: each object is related to itself and the relationship is symmetric; also, if two objects are related to the same third object, the two objects themselves must also be related.
A binary relationship ~ between two objects is said to be an equivalence relation if:
An equivalence relation allows one to partition a set of objects into equivalence classes: that is, a collection of subsets where all entries in a given equivalence class are related to all other elements within the same equivalence class.
Given $ n $ objects which satisfy an equivalence relation, we may partition them such that all objects in the same partition are related to each other as is shown in Figure 1.
Figure 1. The partitioning of 10 objects satisfying an equivalence relation.
An equivalence relationship between two objects a and b may be implicitly defined through a function related(a, b) or member function a.related(b) which returns a Boolean value. The relationship is implicit to the objects.
Alternatively, the programmer can explicitly define an equivalence relation by defining the equivalence classes and where two objects are related if they fall within the same equivalence class.
Operations which may be performed on a container with objects which satisfy an equivalence relation include:
If the equivalence classes are explicitly defined by the programmer, there is no object-related member function which can return whether two objects are related, and therefore there is an addition operation: