A binary relation from a set A to a set B is a subset . It is a collection of ordered pairs where and . When , we say a is related to b by R, written .
A relation is more general than a function. A function requires that each element of A appears in exactly one pair. A relation has no such constraint. An element of A may be related to many elements of B, to one, or to none. An element of B may be related to by many elements of A, one, or none.
A relation on a single set — a subset — is called a relation on A. Relations on a single set can have properties that relations between two different sets cannot:
- Reflexive: every element is related to itself. .
- Symmetric: if a is related to b then b is related to a. .
- Antisymmetric: if a is related to b and b is related to a, then they are the same. .
- Transitive: if a is related to b and b is related to c, then a is related to c. .
These properties combine into named structures. A relation that is reflexive, symmetric, and transitive is an equivalence relation — it partitions A into classes of equivalent elements. A relation that is reflexive, antisymmetric, and transitive is a partial order.
The identity relation on A is — every element related only to itself. The empty relation is — no element related to any other. The total relation is — every element related to every other.
Relations compose. If and , the composition contains whenever there exists with and . Composition is associative. The identity relation is neutral under composition.
In the category Set, a relation from A to B is equivalently a function — a characteristic function that says yes or no for each pair. In a topos, this generalizes: a relation is a morphism into the subobject classifier, where may have more truth values than just true and false.