In mathematics, a binary relation associates some elements of one set called the domain with some elements of another set (possibly the same) called the codomain. Precisely, a binary relation over sets X {\displaystyle X} and Y {\displaystyle Y} is a set of ordered pairs ( x , y ) {\displaystyle (x,y)} , where x {\displaystyle x} is an element of X {\displaystyle X} and y {\displaystyle y} is an element of Y {\displaystyle Y} . It encodes the common concept of relation: an element x {\displaystyle x} is related to an element y {\displaystyle y} if and only if the pair ( x , y ) {\displaystyle (x,y)} belongs to the set of ordered pairs that defines the binary relation. An example of a binary relation is the "divides" relation over the set of prime numbers P {\displaystyle \mathbb {P} } and the set of integers Z {\displaystyle \mathbb {Z} } , in which each prime p {\displaystyle p} is related to each integer z {\displaystyle z} that is a multiple of p {\displaystyle p} , but not to an integer that is not a multiple of p {\displaystyle p} . In this relation, for instance, the prime number 2 {\displaystyle 2} is related to numbers such as − 4 {\displaystyle -4} , 0 {\displaystyle 0} , 6 {\displaystyle 6} , 10 {\displaystyle 10} , but not to 1 {\displaystyle 1} or 9 {\displaystyle 9} , just as the prime number 3 {\displaystyle 3} is related to 0 {\displaystyle 0} , 6 {\displaystyle 6} , and 9 {\displaystyle 9} , but not to 4 {\displaystyle 4} or 13 {\displaystyle 13} . A binary relation is called a homogeneous relation when X = Y {\displaystyle X=Y} . A binary relation is also called a heterogeneous relation when it is not necessary that X = Y {\displaystyle X=Y} . Binary relations, and especially homogeneous relations, are used in many branches of mathematics to model a wide variety of concepts. These include, among others:
the "is greater than", "is equal to", and "divides" relations in arithmetic; the "is congruent to" relation in geometry; the "is adjacent to" relation in graph theory; the "is orthogonal to" relation in linear algebra. A function may be defined as a binary relation that meets additional constraints. Binary relations are also heavily used in computer science. A binary relation over sets X {\displaystyle X} and Y {\displaystyle Y} can be identified with an element of the power set of the Cartesian product X × Y . {\displaystyle X\times Y.} Since a powerset is a lattice for set inclusion ( ⊆ {\displaystyle \subseteq } ), relations can be manipulated using set operations (union, intersection, and complementation) and algebra of sets. In some systems of axiomatic set theory, relations are extended to classes, which are generalizations of sets. This extension is needed for, among other things, modeling the concepts of "is an element of" or "is a subset of" in set theory, without running into logical inconsistencies such as Russell's paradox. A binary relation is the most studied special case n = 2 {\displaystyle n=2} of an n {\displaystyle n} -ary relation over sets X 1 , … , X n {\displaystyle X_{1},\dots ,X_{n}} , which is a subset of the Cartesian product X 1 × ⋯ × X n . {\displaystyle X_{1}\times \cdots \times X_{n}.}
Definition Given sets X {\displaystyle X} and Y {\displaystyle Y} , the Cartesian product X × Y {\displaystyle X\times Y} is defined as { ( x , y ) ∣ x ∈ X and y ∈ Y } , {\displaystyle \{(x,y)\mid x\in X{\text{ and }}y\in Y\},} and its elements are called ordered pairs. A binary relation R {\displaystyle R} over sets X {\displaystyle X} and Y {\displaystyle Y} is a subset of X × Y . {\displaystyle X\times Y.} The set X {\displaystyle X} is called the domain or set of departure of R {\displaystyle R} , and the set Y {\displaystyle Y} the codomain or set of destination of R {\displaystyle R} . In order to specify the choices of the sets X {\displaystyle X} and Y {\displaystyle Y} , some authors define a binary relation or correspondence as an ordered triple ( X , Y , G ) {\displaystyle (X,Y,G)} , where G {\displaystyle G} is a subset of X × Y {\displaystyle X\times Y} called the graph of the binary relation. The statement ( x , y ) ∈ R {\displaystyle (x,y)\in R} reads " x {\displaystyle x} is R {\displaystyle R} -related to y {\displaystyle y} " and is denoted by x R y {\displaystyle xRy} . The domain of definition or active domain of R {\displaystyle R} is the set of all x {\displaystyle x} such that x R y {\displaystyle xRy} for at least one y {\displaystyle y} . The codomain of definition, active codomain, image or range of R {\displaystyle R} is the set of all y {\displaystyle y} such that x R y {\displaystyle xRy} for at least one x {\displaystyle x} . The field of R {\displaystyle R} is the union of its domain of definition and its codomain of definition. When X = Y , {\displaystyle X=Y,} a binary relation is called a homogeneous relation (or endorelation). To emphasize the fact that X {\displaystyle X} and Y {\displaystyle Y} are allowed to be different, a binary relation is also called a heterogeneous relation. The prefix hetero is from the Greek ἕτερος (heteros, "other, another, different"). A heterogeneous relation has been called a rectangular relation, suggesting that it does not have the square-like symmetry of a homogeneous relation on a set where A = B . {\displaystyle A=B.} Commenting on the development of binary relations beyond homogeneous relations, researchers wrote, "... a variant of the theory has evolved that treats relations from the very beginning as heterogeneous or rectangular, i.e. as relations where the normal case is that they are relations between different sets." The terms correspondence, dyadic relation and two-place relation are synonyms for binary relation, though some authors use the term "binary relation" for any subset of a Cartesian product X × Y {\displaystyle X\times Y} without reference to X {\displaystyle X} and Y {\displaystyle Y} , and reserve the term "correspondence" for a binary relation with reference to X {\displaystyle X} and Y {\displaystyle Y} . In a binary relation, the order of the elements is important; if x ≠ y {\displaystyle x\neq y} then y R x {\displaystyle yRx} can be true or false independently of x R y {\displaystyle xRy} . For example, 3 {\displaystyle 3} divides 9 {\displaystyle 9} , but 9 {\displaystyle 9} does not divide 3 {\displaystyle 3} .
Operations
Union If R {\displaystyle R} and S {\displaystyle S} are binary relations over sets X {\displaystyle X} and Y {\displaystyle Y} then R ∪ S = { ( x , y ) ∣ x R y or x S y } {\displaystyle R\cup S=\{(x,y)\mid xRy{\text{ or }}xSy\}} is the union relation of R {\displaystyle R} and S {\displaystyle S} over X {\displaystyle X} and Y {\displaystyle Y} . The identity element is the empty relation, in which no x {\displaystyle x} is related to any y {\displaystyle y} . For example, ≤ {\displaystyle \leq } is the union of < {\displaystyle <} and = {\displaystyle =} , and ≥ {\displaystyle \geq } is the union of > {\displaystyle >} and = {\displaystyle =} .
Intersection If R {\displaystyle R} and S {\displaystyle S} are binary relations over sets X {\displaystyle X} and Y {\displaystyle Y} then R ∩ S = { ( x , y ) ∣ x R y and x S y } {\displaystyle R\cap S=\{(x,y)\mid xRy{\text{ and }}xSy\}} is the intersection relation of R {\displaystyle R} and S {\displaystyle S} over X {\displaystyle X} and Y {\displaystyle Y} . The identity element is the universal relation, in which every x {\displaystyle x} is related to every y {\displaystyle y} . For example, the relation "is divisible by 6" is the intersection of the relations "is divisible by 3" and "is divisible by 2".
Composition
If R {\displaystyle R} is a binary relation over sets X {\displaystyle X} and Y {\displaystyle Y} , and S {\displaystyle S} is a binary relation over sets Y {\displaystyle Y} and Z {\displaystyle Z} then S ∘ R = { ( x , z ) ∣ there exists y ∈ Y such that x R y and y S z } {\displaystyle S\circ R=\{(x,z)\mid {\text{ there exists }}y\in Y{\text{ such that }}xRy{\text{ and }}ySz\}} (also denoted by R ; S {\displaystyle R;S} ) is the composition relation of R {\displaystyle R} and S {\displaystyle S} over X {\displaystyle X} and Z {\displaystyle Z} . If X = Y = Z {\displaystyle X=Y=Z} , the identity element w.r.t. composition is the identity relation on X {\displaystyle X} , in which x ∈ X {\displaystyle x\in X} is related only to itself. The order of R {\displaystyle R} and S {\displaystyle S} in the notation S ∘ R {\displaystyle S\circ R} used here agrees with the standard notational order for composition of functions. For example, the composition (is parent of) ∘ {\displaystyle \circ } (is mother of) yields (is grandmother of), while the composition (is mother of) ∘ {\displaystyle \circ } (is parent of) yields (is maternal grandparent of). For the latter case, if x {\displaystyle x} is the parent of y {\displaystyle y} and y {\displaystyle y} is the mother of z {\displaystyle z} , then x {\displaystyle x} is the maternal grandparent of z {\displaystyle z} .
Converse
If R {\displaystyle R} is a binary relation over sets X {\displaystyle X} and Y {\displaystyle Y} then R T = { ( y , x ) ∣ x R y } {\displaystyle R^{\textsf {T}}=\{(y,x)\mid xRy\}} is the converse relation, also called inverse relation, of R {\displaystyle R} over Y {\displaystyle Y} and X {\displaystyle X} . For example, = {\displaystyle =} is the converse of itself, as is ≠ {\displaystyle \neq } , and < {\displaystyle <} and > {\displaystyle >} are each other's converse, as are ≤ {\displaystyle \leq } and ≥ . {\displaystyle \geq .} A binary relation is equal to its converse if and only if it is symmetric.
Complement
If R {\displaystyle R} is a binary relation over sets X {\displaystyle X} and Y {\displaystyle Y} then R ¯ = { ( x , y ) ∣ ¬ x R y } {\displaystyle {\bar {R}}=\{(x,y)\mid \neg xRy\}} (also denoted by ¬ R {\displaystyle \neg R} ) is the complementary relation of R {\displaystyle R} over X {\displaystyle X} and Y {\displaystyle Y} . For example, = {\displaystyle =} and ≠ {\displaystyle \neq } are each other's complement, as are ⊆ {\displaystyle \subseteq } and ⊈ {\displaystyle \not \subseteq } , ⊇ {\displaystyle \supseteq } and ⊉ {\displaystyle \not \supseteq } , ∈ {\displaystyle \in } and ∉ {\displaystyle \not \in } , and for total orders also < {\displaystyle <} and ≥ {\displaystyle \geq } , and > {\displaystyle >} and ≤ {\displaystyle \leq } . The complement of the converse relation R T {\displaystyle R^{\textsf {T}}} is the converse of the complement: R T ¯ = R ¯ T . {\displaystyle {\overline {R^{\mathsf {T}}}}={\bar {R}}^{\mathsf {T}}.}
If X = Y , {\displaystyle X=Y,} the complement has the following properties:
If a relation is symmetric, then so is the complement. The complement of a reflexive relation is irreflexive—and vice versa. The complement of a strict weak order is a total preorder—and vice versa.
Restriction
If R {\displaystyle R} is a binary homogeneous relation over a set X {\displaystyle X} and S {\displaystyle S} is a subset of X {\displaystyle X} then R | S = { ( x , y ) ∣ x R y and x ∈ S and y ∈ S } {\displaystyle R_{\vert S}=\{(x,y)\mid xRy{\text{ and }}x\in S{\text{ and }}y\in S\}} is the restriction relation of R {\displaystyle R} to S {\displaystyle S} over X {\displaystyle X} . If R {\displaystyle R} is a binary relation over sets X {\displaystyle X} and Y {\displaystyle Y} and if S {\displaystyle S} is a subset of X {\displaystyle X} then R | S = { ( x , y ) ∣ x R y and x ∈ S } {\displaystyle R_{\vert S}=\{(x,y)\mid xRy{\text{ and }}x\in S\}} is the left-restriction relation of R {\displaystyle R} to S {\displaystyle S} over X {\displaystyle X} and Y {\displaystyle Y} . If a relation is reflexive, irreflexive, symmetric, antisymmetric, asymmetric, transitive, total, trichotomous, a partial order, total order, strict weak order, total preorder (weak order), or an equivalence relation, then so too are its restrictions. However, the transitive closure of a restriction is a subset of the restriction of the transitive closure, i.e., in general not equal. For example, restricting the relation " x {\displaystyle x} is parent of y {\displaystyle y} " to females yields the relation " x {\displaystyle x} is mother of the woman y {\displaystyle y} "; its transitive closure does not relate a woman with her paternal grandmother. On the other hand, the transitive closure of "is parent of" is "is ancestor of"; its restriction to females does relate a woman with her paternal grandmother. Also, the various concepts of completeness (not to be confused with being "total") do not carry over to restrictions. For example, over the real numbers a property of the relation ≤ {\displaystyle \leq } is that every non-empty subset S ⊆ R {\displaystyle S\subseteq \mathbb {R} } with an upper bound in R {\displaystyle \mathbb {R} } has a least upper bound (also called supremum) in R . {\displaystyle \mathbb {R} .} However, for the rational numbers this supremum is not necessarily rational, so the same property does not hold on the restriction of the relation ≤ {\displaystyle \leq } to the rational numbers. A binary relation R {\displaystyle R} over sets X {\displaystyle X} and Y {\displaystyle Y} is said to be contained in a relation S {\displaystyle S} over X {\displaystyle X} and Y {\displaystyle Y} , written R ⊆ S , {\displaystyle R\subseteq S,} if R {\displaystyle R} is a subset of S {\displaystyle S} , that is, for all x ∈ X {\displaystyle x\in X} and y ∈ Y , {\displaystyle y\in Y,} if x R y {\displaystyle xRy} , then x S y {\displaystyle xSy} . If R {\displaystyle R} is contained in S {\displaystyle S} and S {\displaystyle S} is contained in R {\displaystyle R} , then R {\displaystyle R} and S {\displaystyle S} are called equal written R = S {\displaystyle R=S} . If R {\displaystyle R} is contained in S {\displaystyle S} but S {\displaystyle S} is not contained in R {\displaystyle R} , then R {\displaystyle R} is said to be smaller than S {\displaystyle S} , written R ⊊ S . {\displaystyle R\subsetneq S.} For example, on the rational numbers, the relation > {\displaystyle >} is smaller than ≥ {\displaystyle \geq } , and equal to the composition > ∘ > {\displaystyle >\circ >} .
Matrix representation Binary relations over sets X {\displaystyle X} and Y {\displaystyle Y} can be represented algebraically by logical matrices indexed by X {\displaystyle X} and Y {\displaystyle Y} with entries in the Boolean semiring (addition corresponds to OR and multiplication to AND) where matrix addition corresponds to union of relations, matrix multiplication corresponds to composition of relations (of a relation over X {\displaystyle X} and Y {\displaystyle Y} and a relation over Y {\displaystyle Y} and Z {\displaystyle Z} ), the Hadamard product corresponds to intersection of relations, the zero matrix corresponds to the empty relation, and the matrix of ones corresponds to the universal relation. Homogeneous relations (when X = Y {\displaystyle X=Y} ) form a matrix semiring (indeed, a matrix semialgebra over the Boolean semiring) where the identity matrix corresponds to the identity relation.
Examples
Types of binary relations
Some important types of binary relations R {\displaystyle R} over sets X {\displaystyle X} and Y {\displaystyle Y} are listed below. Uniqueness properties:
Injective (also called left-unique): for all x , y ∈ X {\displaystyle x,y\in X} and all z ∈ Y , {\displaystyle z\in Y,} if x R z {\displaystyle xRz} and y R z {\displaystyle yRz} then x = y {\displaystyle x=y} . In other words, every element of the codomain has at most one preimage element. For such a relation, Y {\displaystyle Y} is called a primary key of R {\displaystyle R} . For example, the green and blue binary relations in the diagram are injective, but the red one is not (as it relates both − 1 {\displaystyle -1} and 1 {\displaystyle 1} to 1 {\displaystyle 1} ), nor the black one (as it relates both − 1 {\displaystyle -1} and 1 {\displaystyle 1} to 0 {\displaystyle 0} ). Functional (also called right-unique or univalent): for all x ∈ X {\displaystyle x\in X} and all y , z ∈ Y , {\displaystyle y,z\in Y,} if x R y {\displaystyle xRy} and x R z {\displaystyle xRz} then y = z {\displaystyle y=z} . In other words, every element of the domain has at most one image element. Such a binary relation is called a partial function or partial mapping. For such a relation, { X } {\displaystyle \{X\}} is called a primary key of R {\displaystyle R} . For example, the red and green binary relations in the diagram are functional, but the blue one is not (as it relates 1 {\displaystyle 1} to both 1 {\displaystyle 1} and − 1 {\displaystyle -1} ), nor the black one (as it relates 0 {\displaystyle 0} to both − 1 {\displaystyle -1} and 1 {\displaystyle 1} ). One-to-one: injective and functional. For example, the green binary relation in the diagram is one-to-one, but the red, blue and black ones are not. One-to-many: injective and not functional. For example, the blue binary relation in the diagram is one-to-many, but the red, green and black ones are not. Many-to-one: functional and not injective. For example, the red binary relation in the diagram is many-to-one, but the green, blue and black ones are not. Many-to-many: not injective nor functional. For example, the black binary relation in the diagram is many-to-many, but the red, green and blue ones are not. Totality properties (only definable if the domain X {\displaystyle X} and codomain Y {\displaystyle Y} are specified):
Total (also called left-total): for all x ∈ X {\displaystyle x\in X} there exists a y ∈ Y {\displaystyle y\in Y} such that x R y {\displaystyle xRy} . In other words, every element of the domain has at least one image element. In other words, the domain of definition of R {\displaystyle R} is equal to X {\displaystyle X} . This property, is different from the definition of connected (also called total by some authors) in Properties. Such a binary relation is called a multivalued function. For example, the red and green binary relations in the diagram are total, but the blue one is not (as it does not relate − 1 {\displaystyle -1} to any real number), nor the black one (as it does not relate 2 {\displaystyle 2} to any real number). As another example, > {\displaystyle >} is a total relation over the integers. But it is not a total relation over the positive integers, because there is no y {\displaystyle y} in the positive integers such that 1 > y {\displaystyle 1>y} . However, < {\displaystyle <} is a total relation over the positive integers, the rational numbers and the real numbers. Every reflexive relation is total: for a given x {\displaystyle x} , choose y = x {\displaystyle y=x} . Surjective (also called right-total): for all y ∈ Y {\displaystyle y\in Y} , there exists an x ∈ X {\displaystyle x\in X} such that x R y {\displaystyle xRy} . In other words, every element of the codomain has at least one preimage element. In other words, the codomain of definition of R {\displaystyle R} is equal to Y {\displaystyle Y} . For example, the green and blue binary relations in the diagram are surjective, but the red one is not (as it does not relate any real number to − 1 {\displaystyle -1} ), nor the black one (as it does not relate any real number to 2 {\displaystyle 2} ). Uniqueness and totality properties (only definable if the domain X {\displaystyle X} and codomain Y {\displaystyle Y} are specified):
A function (also called mapping): a binary relation that is functional and total. In other words, every element of the domain has exactly one image element. For example, the red and green binary relations in the diagram are functions, but the blue and black ones are not. An injection: a function that is injective. For example, the green relation in the diagram is an injection, but the red one is not; the black and the blue relation is not even a function. A surjection: a function that is surjective. For example, the green relation in the diagram is a surjection, but the red one is not. A bijection: a function that is injective and surjective. In other words, every element of the domain has exactly one image element and every element of the codomain has exactly one preimage element. For example, the green binary relation in the diagram is a bijection, but the red one is not. If relations over proper classes are allowed:
Set-like (also called local): for all x ∈ X {\displaystyle x\in X} , the class of all y ∈ Y {\displaystyle y\in Y} such that y R x {\displaystyle yRx} , i.e. { y ∈ Y , y R x } {\displaystyle \{y\in Y,yRx\}} , is a set. For example, the relation ∈ {\displaystyle \in } is set-like, and every relation on two sets is set-like. The usual ordering < over the class of ordinal numbers is a set-like relation, while its inverse > is not.
Sets versus classes Certain mathematical "relations", such as "equal to", "subset of", and "member of", cannot be understood to be binary relations as defined above, because their domains and codomains cannot be taken to be sets in the usual systems of axiomatic set theory. For example, to model the general concept of "equality" as a binary relation = {\displaystyle =} , take the domain and codomain to be the "class of all sets", which is not a set in the usual set theory. In most mathematical contexts, references to the relations of equality, membership and subset are harmless because they can be understood implicitly to be restricted to some set in the context. The usual work-around to this problem is to select a "large enough" set A {\displaystyle A} , that contains all the objects of interest, and work with the restriction = A {\displaystyle =_{A}} instead of = {\displaystyle =} . Similarly, the "subset of" relation ⊆ {\displaystyle \subseteq } needs to be restricted to have domain and codomain P ( A ) {\displaystyle P(A)} (the power set of a specific set A {\displaystyle A} ): the resulting set relation can be denoted by ⊆ A . {\displaystyle \subseteq _{A}.} Also, the "member of" relation needs to be restricted to have domain A {\displaystyle A} and codomain P ( A ) {\displaystyle P(A)} to obtain a binary relation ∈ A {\displaystyle \in _{A}} that is a set. Bertrand Russell has shown that assuming ∈ {\displaystyle \in } to be defined over all sets leads to a contradiction in naive set theory, see Russell's paradox. Another solution to this problem is to
