Introduction

A relation records which elements of one set are associated with which elements of another: "aa divides bb", "xx is a prerequisite of yy", "page pp links to page qq". Formally, a (binary) relation from a set AA to a set BB is any subset R⊆A×BR \subseteq A \times B; we write a R ba\,R\,b or (a,b)∈R(a, b) \in R. A relation on AA is a subset of A×AA \times A.

Relations generalise functions, define orderings (partial orders) and groupings (equivalence relations), and appear throughout computer science: reachability in graphs, functional dependencies in databases, and tables in the relational model (which use nn-ary relations).

Prerequisites

  • Sets: Cartesian products, subsets, partitions, power sets.

Core concepts

Representations

For a relation RR on a finite set A={a1,…,an}A = \{a_1, \ldots, a_n\}:

  • Set of pairs: R={(1,1),(1,2),(2,3)}R = \{(1, 1), (1, 2), (2, 3)\}.
  • Zero-one matrix MRM_R: MR[i][j]=1M_R[i][j] = 1 if (ai,aj)∈R(a_i, a_j) \in R, else 0.
  • Directed graph (digraph): a vertex per element, an arc ai→aja_i \to a_j per pair; a pair (a,a)(a, a) is a loop.

Since ∣A×A∣=n2|A \times A| = n^2, there are 2n22^{n^2} relations on an nn-element set.

Properties of a relation on AA

PropertyDefinitionMatrix viewDigraph view
Reflexive∀a: (a,a)∈R\forall a:\ (a, a) \in Rall diagonal entries 1loop at every vertex
Irreflexive∀a: (a,a)∉R\forall a:\ (a, a) \notin Rall diagonal entries 0no loops
Symmetric(a,b)∈R→(b,a)∈R(a, b) \in R \to (b, a) \in RM=MTM = M^Tevery arc has its reverse
Antisymmetric(a,b)∈R∧(b,a)∈R→a=b(a, b) \in R \land (b, a) \in R \to a = bM[i][j]=M[j][i]=1M[i][j] = M[j][i] = 1 only if i=ji = jno pair of opposite arcs between distinct vertices
Asymmetric(a,b)∈R→(b,a)∉R(a, b) \in R \to (b, a) \notin Rantisymmetric and zero diagonalantisymmetric and no loops
Transitive(a,b),(b,c)∈R→(a,c)∈R(a, b), (b, c) \in R \to (a, c) \in RM⊙M≤MM \odot M \le M (Boolean product)every directed walk of length 2 has a shortcut arc

Important distinctions:

  • Not reflexive is not the same as irreflexive. {(1,1)}\{(1, 1)\} on {1,2}\{1, 2\} is neither.
  • Symmetric and antisymmetric are not opposites. The empty relation and the identity relation {(a,a)}\{(a, a)\} are both. {(1,2),(2,1),(1,3)}\{(1, 2), (2, 1), (1, 3)\} is neither.
  • Asymmetric = antisymmetric + irreflexive. Asymmetric implies irreflexive (take a=ba = b).
  • The empty relation on a non-empty set is irreflexive, symmetric, antisymmetric, asymmetric and transitive, but not reflexive.
Digraph and matrix views of relation properties
Figure 1. Four relations on {1, 2, 3} drawn as digraphs with their zero-one matrices: reflexive, symmetric, antisymmetric, and transitive, with the defining feature highlighted in each.

Counting relations with a property

For a set with nn elements there are nn diagonal pairs and (n2)=n(n−1)/2\binom{n}{2} = n(n-1)/2 unordered pairs {a,b}\{a, b\} with a≠ba \ne b. Each count comes from deciding diagonal pairs and off-diagonal pairs independently.

Relations on an nn-set that areCountn=3n = 3
Any2n22^{n^2}512
Reflexive2n2−n2^{n^2 - n}64
Irreflexive2n2−n2^{n^2 - n}64
Symmetric2n(n+1)/22^{n(n+1)/2}64
Reflexive and symmetric2n(n−1)/22^{n(n-1)/2}8
Antisymmetric2n⋅3n(n−1)/22^{n} \cdot 3^{n(n-1)/2}216
Asymmetric3n(n−1)/23^{n(n-1)/2}27
Reflexive and antisymmetric3n(n−1)/23^{n(n-1)/2}27
Equivalence relationsBell number BnB_n5

Reasoning for antisymmetric: each diagonal pair is free (2 ways); for each unordered off-diagonal pair {a,b}\{a, b\}, allow neither arc, only (a,b)(a, b), or only (b,a)(b, a) (3 ways). There is no simple closed formula for transitive relations; for n=1,2,3,4n = 1, 2, 3, 4 there are 2, 13, 171, 3994.

Operations on relations

  • Inverse: R−1={(b,a)∣(a,b)∈R}R^{-1} = \{(b, a) \mid (a, b) \in R\}; MR−1=MRTM_{R^{-1}} = M_R^T.
  • Complement: R‾=(A×B)−R\overline{R} = (A \times B) - R.
  • Composition: for R⊆A×BR \subseteq A \times B and S⊆B×CS \subseteq B \times C,
S∘R={(a,c)∣∃b∈B: (a,b)∈R∧(b,c)∈S},S \circ R = \{(a, c) \mid \exists b \in B:\ (a, b) \in R \land (b, c) \in S\},

and MS∘R=MR⊙MSM_{S \circ R} = M_R \odot M_S, the Boolean matrix product (OR of ANDs). Note the order: S∘RS \circ R applies RR first, as with functions.

  • Powers: R1=RR^1 = R, Rk+1=Rk∘RR^{k+1} = R^k \circ R. (a,b)∈Rk(a, b) \in R^k if and only if there is a directed walk of length exactly kk from aa to bb in the digraph.
  • RR is transitive if and only if R2⊆RR^2 \subseteq R (equivalently Rk⊆RR^k \subseteq R for all k≥1k \ge 1).

Closures

The closure of RR with respect to a property is the smallest relation that contains RR and has the property.

ClosureFormula
ReflexiveR∪ΔAR \cup \Delta_A, where ΔA={(a,a)∣a∈A}\Delta_A = \{(a, a) \mid a \in A\}
SymmetricR∪R−1R \cup R^{-1}
TransitiveR+=R∪R2∪R3∪⋯=⋃k=1nRkR^{+} = R \cup R^2 \cup R^3 \cup \cdots = \bigcup_{k=1}^{n} R^k for ∣A∣=n\lvert A \rvert = n
Reflexive-transitiveR∗=R+∪ΔAR^{*} = R^{+} \cup \Delta_A

The transitive closure is reachability by a nonempty directed walk. For distinct endpoints, remove repeated segments to obtain a simple path of length at most n−1n-1; for equal endpoints, take a shortest nonempty return cycle of length at most nn. Thus the union stops at RnR^n. Warshall's algorithm computes it in Θ(n3)\Theta(n^3) time. Matrix indices below are 1-based, from 1 through n. On the unit-cost Boolean-matrix model, best, average and worst time are all Θ(n3)\Theta(n^3), since all three loops run fully. A separate W needs Θ(n2)\Theta(n^2) auxiliary space; updating M in place uses O(1)O(1) additional scalar space:

Text
WARSHALL(M, n)          // M is the n x n zero-one matrix of R
    W <- M
    for k <- 1 to n
        for i <- 1 to n
            for j <- 1 to n
                W[i][j] <- W[i][j] OR (W[i][k] AND W[k][j])
    return W            // matrix of the transitive closure

After iteration kk, W[i][j]=1W[i][j] = 1 exactly when there is a nonempty directed walk (including a return cycle when the endpoints coincide) from ii to jj whose intermediate vertices all lie in {1,…,k}\{1, \ldots, k\}. It is the Boolean version of Floyd-Warshall.

Caution: the symmetric closure of a transitive relation need not be transitive, and the transitive closure of a symmetric relation is symmetric. To get the smallest equivalence relation containing RR, take the reflexive, symmetric and then transitive closure, in that order (transitive last).

Equivalence relations and partitions

A relation is an equivalence relation if it is reflexive, symmetric and transitive. The equivalence class of aa is [a]={x∈A∣x R a}[a] = \{x \in A \mid x\,R\,a\}.

Key facts:

  • Any two classes are either identical or disjoint: [a]=[b][a] = [b] if and only if a R ba\,R\,b.
  • The distinct classes form a partition of AA; conversely every partition of AA defines an equivalence relation ("in the same block"). This bijection is why the number of equivalence relations on an nn-set equals the number of partitions, the Bell number BnB_n: B0,…,B6=1,1,2,5,15,52,203B_0, \ldots, B_6 = 1, 1, 2, 5, 15, 52, 203.
  • An equivalence relation whose partition has blocks of sizes s1,…,sks_1, \ldots, s_k contains exactly ∑si2\sum s_i^2 ordered pairs.

Examples: congruence modulo mm on Z\mathbb{Z} (a≡b(modm)a \equiv b \pmod m if m∣a−bm \mid a - b) has the mm classes [0],[1],…,[m−1][0], [1], \ldots, [m-1]. "Same length" on strings is an equivalence relation. "Is a friend of" is usually not (not transitive).

Partition of a set into equivalence classes
Figure 2. The set {0, 1, ..., 11} partitioned into the three classes of congruence modulo 3, with the digraph of the relation restricted to one class.

Partial orders (preview)

A relation that is reflexive, antisymmetric and transitive is a partial order (for example ≤\le on Z\mathbb{Z}, ⊆\subseteq on P(A)\mathcal{P}(A), "divides" on Z+\mathbb{Z}^+). These are treated in Partial Orders and Lattices.

Worked examples

Example 1: classify relations

On A={1,2,3}A = \{1, 2, 3\}:

RelationRefl.Irrefl.Symm.Antisymm.Trans.
R1={(1,1),(2,2),(3,3),(1,2),(2,1)}R_1 = \{(1,1),(2,2),(3,3),(1,2),(2,1)\}YesNoYesNoYes
R2={(1,2),(2,3),(1,3)}R_2 = \{(1,2),(2,3),(1,3)\}NoYesNoYesYes
R3={(1,2),(2,1)}R_3 = \{(1,2),(2,1)\}NoYesYesNoNo
R4={(1,1)}R_4 = \{(1,1)\}NoNoYesYesYes

R3R_3 fails transitivity because (1,2),(2,1)∈R3(1, 2), (2, 1) \in R_3 but (1,1)∉R3(1, 1) \notin R_3. R1R_1 is an equivalence relation with classes {1,2}\{1, 2\} and {3}\{3\}, and 22+12=52^2 + 1^2 = 5 pairs, as listed.

Example 2: transitive closure

R={(1,2),(2,3),(3,4)}R = \{(1, 2), (2, 3), (3, 4)\} on {1,2,3,4}\{1, 2, 3, 4\}. R2={(1,3),(2,4)}R^2 = \{(1, 3), (2, 4)\}, R3={(1,4)}R^3 = \{(1, 4)\}, R4=∅R^4 = \emptyset. So

R+={(1,2),(2,3),(3,4),(1,3),(2,4),(1,4)},R^{+} = \{(1,2),(2,3),(3,4),(1,3),(2,4),(1,4)\},

6 pairs: the strict order << on {1,2,3,4}\{1, 2, 3, 4\}.

Example 3: counting

How many relations on a 4-element set are both reflexive and symmetric? The diagonal is forced; each of the (42)=6\binom{4}{2} = 6 unordered pairs is in or out (both directions together): 26=642^6 = 64. How many are symmetric and antisymmetric? Off-diagonal pairs must all be absent; the diagonal is free: 24=162^4 = 16.

Example 4: equivalence relations with a given class structure

How many equivalence relations on {1,2,3,4}\{1, 2, 3, 4\} have exactly two classes? This is the number of ways to split a 4-set into 2 non-empty blocks, the Stirling number S(4,2)=7S(4, 2) = 7: four splits of type 3+1 and three of type 2+2. Over all numbers of classes, S(4,1)+S(4,2)+S(4,3)+S(4,4)=1+7+6+1=15=B4S(4,1) + S(4,2) + S(4,3) + S(4,4) = 1 + 7 + 6 + 1 = 15 = B_4.

Important properties and observations

  • Intersection of two equivalence relations is an equivalence relation; their union need not be (transitivity fails). Example on {1,2,3}\{1, 2, 3\}: classes {1,2},{3}\{1, 2\}, \{3\} and {1},{2,3}\{1\}, \{2, 3\}; the union contains (1,2),(2,3)(1, 2), (2, 3) but not (1,3)(1, 3).
  • Unions preserve reflexivity, irreflexivity and symmetry, but not antisymmetry, asymmetry or transitivity. Intersections preserve reflexivity, irreflexivity, symmetry, antisymmetry, asymmetry and transitivity (irreflexivity, antisymmetry and asymmetry pass to every subset; reflexivity, symmetry and transitivity survive because each pair the definition requires is in both relations, so it is in the intersection: if (a,b)∈R∩S(a, b) \in R \cap S then (b,a)∈R(b, a) \in R and (b,a)∈S(b, a) \in S, and likewise if (a,b),(b,c)∈R∩S(a, b), (b, c) \in R \cap S then (a,c)(a, c) is in both).
  • The inverse preserves all six of those properties. The complement preserves symmetry only, and it swaps reflexivity with irreflexivity. Composition of two relations preserves reflexivity only.
OperationPreservesDoes not preserve
Unionreflexive, irreflexive, symmetricantisymmetric, asymmetric, transitive
Intersectionall sixnone
Inverseall sixnone
Complementsymmetric (and swaps reflexive with irreflexive)reflexive, irreflexive, antisymmetric, asymmetric, transitive
Compositionreflexiveirreflexive, symmetric, antisymmetric, asymmetric, transitive
  • RR is symmetric if and only if R=R−1R = R^{-1}; antisymmetric if and only if R∩R−1⊆ΔAR \cap R^{-1} \subseteq \Delta_A.
  • A relation that is symmetric, transitive and "serial" (every element related to something) is reflexive; without the serial condition the classic false proof of "symmetric and transitive implies reflexive" fails, as R=∅R = \emptyset shows.

GATE examination perspective

  • Property checks. Expect a relation given by pairs or by a rule on integers (for example a R ba\,R\,b if a−ba - b is even, or if ab≥0ab \ge 0); test each property and look for a single counterexample.
  • Counting relations. The counting-relations table covers the common counts. Derive them from the diagonal/off-diagonal split instead of memorising.
  • Equivalence classes and partitions. Bell numbers for the total; Stirling numbers of the second kind for a fixed number of classes.
  • Closures. Transitive closure equals reachability; Warshall's algorithm is Θ(n3)\Theta(n^3).
  • Trap: "not reflexive" versus "irreflexive"; "antisymmetric" versus "not symmetric".
  • Trap: ab≥0ab \ge 0 on Z\mathbb{Z} is reflexive and symmetric but not transitive (1⋅0≥01 \cdot 0 \ge 0, 0⋅(−1)≥00 \cdot (-1) \ge 0, but 1⋅(−1)<01 \cdot (-1) < 0).

Summary

Sources

  1. K. H. Rosen, Discrete Mathematics and Its Applications, 7th ed., McGraw-Hill, 2012: Sections 9.1 (Relations and Their Properties), 9.3 (Representing Relations), 9.4 (Closures of Relations) and 9.5 (Equivalence Relations).

Next steps