girgit.org

Relations and Functions

How many functions? Counting maps between finite sets

The big ideaFrom a set of m elements to a set of n elements there are \( n^m \) functions, because each input picks its output independently; one-one, bijective and onto functions are counted with permutations and a little care.

In simple words

Three children each choose an ice cream from two flavours. Each child has 2 choices, and the choices don't affect each other, so there are 2 × 2 × 2 = 8 ways. A function is exactly this: every input picks one output. If no two children may pick the same flavour, the count is smaller. If every flavour must be picked by someone, it changes again.

Not in the current textbook, but JEE asks it: NCERT counts one case (the one-one functions from {1, 2, 3} to itself are its 3! = 6 rearrangements) and asks for the onto functions from {1, 2, …, n} to itself. JEE asks the general counts below, using the permutations and combinations from Class 11.

Guess first: which way round?

A = {1, 2, 3} and B = {a, b}. Guess: how many functions are there from A to B: \( 3^2 = 9 \), \( 2^3 = 8 \), or \( 3 \times 2 = 6 \)?

See what happens
8. The choosing is done by the inputs: each of the 3 elements of A picks one of the 2 elements of B, so \( 2 \times 2 \times 2 = 2^3 \). The rule is (number of outputs)(number of inputs). And 6 is the number of pairs in A × B, not the number of functions. Of these 8 functions, 2 are constant (all to a, or all to b), and the other 6 are onto.

The counts

Let A have \( m \) elements and B have \( n \) elements.

Kind of function A → BCountWhy
All functions\( n^m \)each of the m inputs picks one of n outputs
One-one (needs m ≤ n)\( ^n\text{P}_m = \frac{n!}{(n-m)!} \)first input: n choices, next: n − 1, …, no repeats allowed
One-one when m > n0more inputs than outputs: two must share
Bijective (needs m = n)\( n! \)a rearrangement of n things
Onto a 2-element set\( 2^m - 2 \)all functions minus the 2 constant ones
Many-one\( n^m - {}^n\text{P}_m \)all minus one-one
Into (not onto)\( n^m - \) (number onto)all minus onto

For onto in general, JEE uses inclusion-exclusion (subtract the functions that miss an output, add back those that miss two, and so on):

\[ \text{onto}(m \to n) = n^m - \binom{n}{1}(n-1)^m + \binom{n}{2}(n-2)^m - \cdots \]

Here \( \binom{n}{k} \) is the same as \( ^n\text{C}_k \), the number of ways to choose which k outputs to leave out.

Try it: guess first, then see every function at once and check each term of the onto count.

Worked examples

  1. A = {1, 2, 3}, B = {a, b, c, d}. All functions: \( 4^3 = 64 \). One-one: \( 4 \times 3 \times 2 = 24 \). Onto: 0, since 3 inputs can't cover 4 outputs. Many-one: \( 64 - 24 = 40 \).
  2. Onto functions from a 4-set to a 3-set. Inclusion-exclusion: \( 3^4 - 3 \cdot 2^4 + 3 \cdot 1^4 = 81 - 48 + 3 = 36 \). Check another way: exactly one output is hit twice. Choose which 2 of the 4 inputs share: \( ^4\text{C}_2 = 6 \). Now there are 3 "groups" to match with 3 outputs: \( 3! = 6 \). Total \( 6 \times 6 = 36 \).
  3. Onto functions from {1, 2, …, n} to itself. On a finite set onto means one-one (previous page), so these are exactly the bijections: \( n! \).
  4. Onto functions from a 5-set to a 3-set. \( 3^5 - 3 \cdot 2^5 + 3 \cdot 1^5 = 243 - 96 + 3 = 150 \).

All of these were checked by listing every function by computer.

Don't mix these up

  • Functions A → B: \( n^m \), outputs to the power inputs. Relations A → B: \( 2^{mn} \).
  • One-one needs m ≤ n; onto needs m ≥ n; bijective needs m = n.
  • Onto ≠ "all minus the constant ones" except when the co-domain has 2 elements.

Try it. A has 2 elements and B has 5. How many functions from A to B are one-one? How many are onto?

Answer
One-one: \( 5 \times 4 = 20 \) (out of \( 5^2 = 25 \) functions; the other 5 are constant). Onto: 0, since 2 inputs can reach at most 2 of the 5 outputs.

Words to know

\( n^m \)
The number of functions from an m-element set to an n-element set.
\( ^n\text{P}_m \)
Ordered choices of m different things from n: the one-one count.
\( n! \)
n × (n − 1) × … × 1: the number of bijections of an n-set.
Constant function
Sends every input to the same output.
Inclusion-exclusion
Subtract overlaps, add back double-subtractions, and so on.

How many functions are there from {1, 2, 3} to {p, q, r, s}?

  1. 81
  2. 64
  3. 12

How many onto functions are there from {1, 2, 3, 4} to {x, y}?

  1. 14
  2. 16
  3. 6

How many one-one functions are there from {1, 2, 3} to {1, 2, 3, 4, 5}?

  1. 125
  2. 10
  3. 60