Skip to content

Counting on Sets, Relations, and Functions

Every counting tool we have built across Sections 01–09—the Multiplication Principle, Combinations, Stars and Bars, Inclusion–Exclusion, Stirling Numbers, and Bell Numbers—comes together naturally when counting the three core structures of discrete mathematics: subsets, relations, and functions on finite sets.


1. Counting Subsets

Let \(A\) be a finite set containing \(n\) elements. Recall that the collection of all subsets of \(A\) is called the power set of \(A\), denoted \(\mathcal{P}(A)\).

  • Total subsets of \(A\): \(|\mathcal{P}(A)| = \binom{n}{0} + \binom{n}{1} + \dots + \binom{n}{n} = 2^n\), because each of the \(n\) elements independently has \(2\) choices (either included in the subset or excluded).
  • Proper subsets of \(A\): Excluding \(A\) itself leaves \(2^n - 1\) proper subsets (and excluding both \(\emptyset\) and \(A\) leaves \(2^n - 2\) non-empty proper subsets).
  • Subsets of exact size \(r\): \(\binom{n}{r}\).
  • Subsets always containing \(k\) particular elements: Those \(k\) fixed elements have only \(1\) choice (must be included), while the remaining \(n - k\) elements have \(2\) choices each, giving \(1^k \cdot 2^{n - k} = 2^{n - k}\) subsets. (For a single particular element, \(2^{n - 1}\).)

Example 1 (Pairs of Subsets Under Set Conditions): Let \(|A| = n\). Find the number of ordered pairs \((P, Q)\) of subsets of \(A\) such that: (a) \(P \cap Q = \emptyset\), (b) \(P \cup Q = A\), (c) \(P \subseteq Q\).

Solution: Decide the fate of each element \(x \in A\) independently! In general, any element \(x \in A\) has \(4\) possibilities across \((P, Q)\): (1) \(x \in P, x \in Q\); (2) \(x \in P, x \notin Q\); (3) \(x \notin P, x \in Q\); (4) \(x \notin P, x \notin Q\).

  • (a) \(P \cap Q = \emptyset\): Possibility (1) is forbidden, leaving \(3\) independent choices for each of the \(n\) elements \(\implies 3^n\) ordered pairs. (If we instead ask for unordered disjoint pairs \(\{P, Q\}\), notice \((\emptyset, \emptyset)\) is the unique pair with \(P = Q\); the remaining \(3^n - 1\) ordered pairs come in symmetric twins \((P, Q)\) and \((Q, P)\), giving \(\frac{3^n - 1}{2} + 1 = \frac{3^n + 1}{2}\) unordered pairs.)
  • (b) \(P \cup Q = A\): Possibility (4) (\(x\) in neither set) is forbidden, leaving \(3\) choices per element \(\implies 3^n\) ordered pairs.
  • (c) \(P \subseteq Q\): Possibility (2) (\(x \in P\) but \(x \notin Q\)) is forbidden, leaving \(3\) choices per element \(\implies 3^n\) ordered pairs.

2. Counting Relations on Finite Sets

Let \(A\) and \(B\) be finite sets containing \(m\) and \(n\) elements respectively. Recall that the Cartesian product \(A \times B\) is the set of all ordered pairs:

\[A \times B = \{(a, b) : a \in A,\; b \in B\}\]

Because the first entry can be chosen from \(A\) in \(m\) ways and the second entry from \(B\) in \(n\) ways, \(|A \times B| = mn\).

By definition, any relation \(R\) from \(A\) to \(B\) is a subset of \(A \times B\). Since \(A \times B\) contains \(mn\) elements:

\[\text{Total number of relations from } A \text{ to } B = 2^{mn}\]

Visualizing Relations on a Set via a Square Matrix Grid

Now focus on relations defined on a single set \(A = \{a_1, a_2, \dots, a_n\}\)—that is, subsets of \(A \times A\). To count special classes of relations effortlessly, arrange all \(n^2\) ordered pairs of \(A \times A\) in an \(n \times n\) matrix:

\[A \times A = \begin{bmatrix} (a_1, a_1) & (a_1, a_2) & \cdots & (a_1, a_n) \\ (a_2, a_1) & (a_2, a_2) & \cdots & (a_2, a_n) \\ \vdots & \vdots & \ddots & \vdots \\ (a_n, a_1) & (a_n, a_2) & \cdots & (a_n, a_n) \end{bmatrix}\]

Notice the exact geometry of these \(n^2\) entries:

  • \(n\) main-diagonal entries: \((a_i, a_i)\) for \(1 \le i \le n\).
  • \(n^2 - n\) non-diagonal entries, split evenly into \(\frac{n^2 - n}{2} = \frac{n(n - 1)}{2}\) upper-triangular entries \((a_i, a_j)\) (\(i < j\)) and \(\frac{n(n - 1)}{2}\) lower-triangular entries \((a_j, a_i)\) (\(i < j\)), where each upper entry sits directly opposite its mirror pair across the diagonal.

Matrix Grid Visualization of A x A Highlighting Diagonal and Off-Diagonal Pairs

Now count every major type of relation on \(A\) directly from this matrix:

1. Total Relations on \(A\): Each of the \(n^2\) entries independently has \(2\) choices (in \(R\) or not in \(R\)):

\[2^{n^2}\]

2. Reflexive Relations: A relation \(R\) on \(A\) is reflexive if \((a, a) \in R\) for all \(a \in A\) (e.g., on \(A = \{1, 2, 3\}\), \(R = \{(1, 1), (2, 2), (3, 3), (1, 2)\}\) is reflexive).

In the matrix of \(A \times A\), all \(n\) main-diagonal entries must be included (\(1\) choice each), while each of the \(n^2 - n\) non-diagonal entries is free (\(2\) choices each):

\[\underbrace{1 \times 1 \times \dots \times 1}_{n \text{ times}} \times \underbrace{2 \times 2 \times \dots \times 2}_{n^2 - n \text{ times}} = 2^{n^2 - n} = 2^{n(n - 1)}\]

3. Irreflexive Relations: A relation \(R\) on \(A\) is irreflexive if \((a, a) \notin R\) for all \(a \in A\). All \(n\) diagonal entries are forced to be excluded (\(1\) choice each), while the \(n^2 - n\) off-diagonal entries remain free:

\[2^{n(n - 1)}\]

4. Symmetric Relations: A relation \(R\) on \(A\) is symmetric if whenever \((a, b) \in R\), we also have \((b, a) \in R\). For example, on \(A = \{1, 2, 3, 4\}\):

  • \(R_1 = \{(1, 1), (2, 2)\}\) and \(R_2 = \{(1, 1), (1, 2), (2, 1)\}\) are symmetric.
  • The empty relation \(R_3 = \emptyset\) is vacuously symmetric (there is no pair \((a, b) \in \emptyset\) that violates the rule!).
  • \(R_4 = \{(1, 1), (2, 3)\}\) and \(R_5 = \{(1, 1), (1, 2), (2, 1), (2, 3)\}\) are not symmetric because \((3, 2)\) is missing.

Look at the matrix of \(A \times A\):

  • Each of the \(n\) diagonal entries \((a_i, a_i)\) is its own mirror, so it freely has \(2\) choices (included or excluded).
  • Each of the \(\frac{n(n - 1)}{2}\) upper-triangular entries \((a_i, a_j)\) (\(i < j\)) has \(2\) choices—and once that choice is made, its lower-triangular mirror \((a_j, a_i)\) has only \(1\) forced choice (it must match)!

By the Multiplication Principle:

\[\text{Symmetric relations on } A = 2^n \cdot 2^{n(n - 1)/2} = 2^{\frac{n^2 + n}{2}} = 2^{n(n + 1)/2}\]

5. Relations That Are Both Reflexive and Symmetric: All \(n\) diagonal entries are forced to be included (\(1\) choice each), and the \(\frac{n(n - 1)}{2}\) off-diagonal mirror pairs have \(2\) choices each:

\[2^{n(n - 1)/2}\]

6. Antisymmetric Relations: A relation \(R\) on \(A\) is antisymmetric if whenever \((a, b) \in R\) and \((b, a) \in R\), we must have \(a = b\). (In other words, for distinct \(a \neq b\), we can never include both \((a, b)\) and \((b, a)\) simultaneously!)

Look at the matrix of \(A \times A\):

  • Each of the \(n\) diagonal entries \((a_i, a_i)\) has \(a = b\), so it never violates antisymmetry: \(2\) choices each.
  • For each of the \(\frac{n(n - 1)}{2}\) off-diagonal pairs \(\{(a_i, a_j), (a_j, a_i)\}\) (\(i < j\)), including both is forbidden, leaving exactly \(3\) valid choices: include neither, include only \((a_i, a_j)\), or include only \((a_j, a_i)\).

By the Multiplication Principle:

\[\text{Antisymmetric relations on } A = 2^n \cdot 3^{n(n - 1)/2}\]

7. Equivalence Relations (The Bell Number Connection): A relation \(R\) on \(A\) is an equivalence relation if it is simultaneously reflexive, symmetric, and transitive.

Why is counting equivalence relations not a simple power of \(2\) or \(3\)? Because transitivity links triples of entries across the matrix! Fortunately, a fundamental theorem of Set Theory gives an exact bijection:

  • Every equivalence relation \(R\) on \(A\) partitions \(A\) into pairwise disjoint, non-empty equivalence classes.
  • Conversely, every partition of \(A\) into non-empty subsets uniquely defines an equivalence relation (\(x \sim y\) if and only if \(x\) and \(y\) lie in the same block of the partition).

By the Bijection Principle (Section 01) and Stirling / Bell Numbers (Section 09):

\[\text{Equivalence relations on an } n\text{-element set} = B_n = \sum_{r=1}^{n} S(n, r)\]

Bijection Between Set Partitions and Equivalence Relations on A = 1, 2, 3, 4

Example 2: On the set \(A = \{1, 2, 3, 4\}\) (\(n = 4\)), find the number of: (a) total relations, (b) reflexive relations, (c) symmetric relations, (d) antisymmetric relations, (e) equivalence relations.

Solution:

  • (a) Total relations: \(2^{4^2} = 2^{16} = 65{,}536\).
  • (b) Reflexive relations: \(2^{4 \times 3} = 2^{12} = 4096\).
  • (c) Symmetric relations: \(2^{4 \times 5 / 2} = 2^{10} = 1024\).
  • (d) Antisymmetric relations: \(2^4 \cdot 3^{4 \times 3 / 2} = 16 \times 3^6 = 16 \times 729 = 11{,}664\).
  • (e) Equivalence relations: \(B_4 = S(4, 1) + S(4, 2) + S(4, 3) + S(4, 4) = 1 + 7 + 6 + 1 = 15\).

3. Counting Functions Between Finite Sets

Let \(A\) and \(B\) be finite sets with \(|A| = m\) (the domain) and \(|B| = n\) (the codomain). According to the definition of a function, a mapping \(f : A \to B\) assigns to every element \(a \in A\) one and only one image \(f(a) \in B\).

Look closely at what that definition means combinatorially: defining a function \(f : A \to B\) is 100% identical to distributing \(m\) distinct objects (elements of \(A\)) into \(n\) distinct boxes (elements of \(B\))!

Injective, Surjective, and Bijective Mappings Between Finite Sets A and B

1. Total Number of Functions

Each of the \(m\) elements in \(A\) independently chooses its image from the \(n\) elements in \(B\). By the Multiplication Principle:

\[\text{Total functions } f : A \to B = \underbrace{n \times n \times \dots \times n}_{m \text{ times}} = n^m\]

2. Injective (One-One) Functions

A function \(f : A \to B\) is injective (one-one) if distinct inputs always produce distinct outputs: \(a_1 \neq a_2 \implies f(a_1) \neq f(a_2)\) (no two balls land in the same box).

  • If \(m > n\): By the Pigeonhole Principle (Section 01), placing \(m\) domain elements into \(n < m\) codomain elements guarantees a collision—so there are \(0\) injective functions.
  • If \(m \le n\): The first element of \(A\) has \(n\) choices, the second has \(n - 1\), ..., and the \(m\)-th has \(n - m + 1\) choices:
\[\text{Injective functions} = {}^n P_m = \frac{n!}{(n - m)!} \qquad (m \le n)\]

3. Bijective (One-One and Onto) Functions

A function is bijective if it is both injective and surjective. This requires \(m \le n\) (for injectivity) and \(m \ge n\) (for surjectivity), so \(m = n\) is mandatory! When \(m = n\), every injective function automatically covers all \(n\) elements of \(B\):

\[\text{Bijective functions} = \begin{cases} n! & \text{if } m = n \\ 0 & \text{if } m \neq n \end{cases}\]

4. Surjective (Onto) Functions

A function \(f : A \to B\) is surjective (onto) if every element \(b \in B\) is hit by at least one element of \(A\) (its range equals the entire codomain \(B\)).

  • If \(m < n\): Not enough domain elements exist to cover all \(n\) elements of \(B\), so there are \(0\) surjective functions.
  • If \(m \ge n\): Covering every element of \(B\) is literally identical to distributing \(m\) distinct objects into \(n\) distinct non-empty boxes (Section 09)! By PIE and Stirling numbers of the second kind:
\[\text{Surjective functions} = n!\,S(m, n) = \sum_{k=0}^{n} (-1)^k \binom{n}{k} (n - k)^m \qquad (m \ge n)\]

Example 3: Let \(A = \{1, 2, 3, 4, 5\}\) (\(m = 5\)) and \(B = \{a, b, c\}\) (\(n = 3\)). Find the number of functions \(f : A \to B\) that are: (a) unrestricted, (b) injective, (c) surjective, (d) into (not onto).

Solution:

(a) Unrestricted: \(3^5 = 243\).

(b) Injective: Since \(m = 5 > 3 = n\), there are \(0\) injective functions.

(c) Surjective: Using PIE with \(m = 5\) and \(n = 3\):

\[3^5 - \binom{3}{1}2^5 + \binom{3}{2}1^5 - \binom{3}{3}0^5 = 243 - 3(32) + 3(1) - 0 = 150\]

(Notice also \(3!\,S(5, 3) = 6 \times 25 = 150\)!)

(d) Into (not onto): By the Subtraction Principle, \(243 - 150 = 93\).

5. Monotonic Functions

Suppose both \(A = \{1, 2, \dots, m\}\) and \(B = \{1, 2, \dots, n\}\) are ordered sets of numbers, and we want to count functions that respect order.

Strictly Increasing Functions (\(i < j \implies f(i) < f(j)\)): Every strictly increasing function outputs \(m\) distinct values from \(B\). Conversely, once you choose any unordered subset of \(m\) distinct values from \(B\), there is only \(1\) way to assign them in strictly increasing order (smallest value to \(1\), next smallest to \(2\), ..., largest to \(m\))! By the Bijection Principle (for \(m \le n\)):

\[\text{Strictly increasing functions} = \binom{n}{m}\]

(By the exact same reasoning, the number of strictly decreasing functions is also \(\binom{n}{m}\).)

Non-Decreasing (Weakly Increasing) Functions (\(i < j \implies f(i) \le f(j)\)): Now output values are allowed to repeat! A non-decreasing function is completely determined by choosing \(m\) values from \(B\) with repetition allowed (unordered) and writing them in non-decreasing order! Equivalently, let \(x_j\) be the number of domain elements mapping to \(j \in B\) (\(1 \le j \le n\)); then \(x_1 + x_2 + \dots + x_n = m\) with \(x_j \ge 0\). By Stars and Bars (Section 07):

\[\text{Non-decreasing functions} = \binom{n + m - 1}{m}\]

(And by symmetry, the number of non-increasing functions is also \(\binom{n + m - 1}{m}\).)

Example 4: How many functions \(f : \{1, 2, 3, 4\} \to \{1, 2, 3, 4, 5, 6\}\) are: (a) strictly increasing, (b) non-decreasing, (c) monotonic (either non-decreasing or non-increasing)?

Solution: Here \(m = 4\) and \(n = 6\).

  • (a) Strictly increasing: \(\binom{6}{4} = 15\).
  • (b) Non-decreasing: \(\binom{6 + 4 - 1}{4} = \binom{9}{4} = 126\).
  • (c) Monotonic: There are \(126\) non-decreasing functions and \(126\) non-increasing functions. Watch out for overlap! Which functions are both non-decreasing and non-increasing? Precisely the \(6\) constant functions (\(f(x) \equiv c\) for \(c \in \{1, \dots, 6\}\))! By PIE (avoiding overcounting):
\[126 + 126 - 6 = 246\]

Master Summary Table

Discrete Structure Count Condition
Subsets of an \(n\)-element set \(2^n\) \(n \ge 0\)
Relations from \(A\) to \(B\) \(2^{mn}\) \(\lvert A \rvert = m,\; \lvert B \rvert = n\)
Reflexive / Irreflexive relations on \(A\) \(2^{n(n - 1)}\) \(\lvert A \rvert = n\)
Symmetric relations on \(A\) \(2^{n(n + 1)/2}\) \(\lvert A \rvert = n\)
Reflexive & Symmetric relations on \(A\) \(2^{n(n - 1)/2}\) \(\lvert A \rvert = n\)
Antisymmetric relations on \(A\) \(2^n \cdot 3^{n(n - 1)/2}\) \(\lvert A \rvert = n\)
Equivalence relations on \(A\) \(B_n = \sum_{r=1}^n S(n, r)\) \(\lvert A \rvert = n \ge 1\)
Total functions \(f : A \to B\) \(n^m\) \(\lvert A \rvert = m,\; \lvert B \rvert = n\)
Injective (one-one) functions \({}^n P_m = \frac{n!}{(n - m)!}\) \(m \le n\) (\(0\) if \(m > n\))
Bijective functions \(n!\) \(m = n\) (\(0\) if \(m \neq n\))
Surjective (onto) functions \(n!\,S(m, n) = \sum_{k=0}^n (-1)^k \binom{n}{k}(n - k)^m\) \(m \ge n\) (\(0\) if \(m < n\))
Strictly increasing / decreasing functions \(\binom{n}{m}\) \(m \le n\)
Non-decreasing / non-increasing functions \(\binom{n + m - 1}{m}\) \(m, n \ge 1\)