1.2 Functions
A function is a relation that gives every element of its domain exactly one image. We find domains and ranges, sort functions into one-one or many-one and onto or into, count them on finite sets — $n^m$ functions, $3^m-3\cdot2^m+3$ onto ones — and combine them by composition, $(g\circ f)(x)=g(f(x))$.
A railway reservation system takes the list of passengers on a train and gives each one a seat. Each passenger must get exactly one seat — no passenger without a seat, none with two. That rule is what makes the allocation a function from passengers to seats. Two further questions decide whether the booking is sound and whether the train is full. Does any seat go to two passengers? (If not, the allocation is one-one.) Is every seat taken? (If so, it is onto.) A booking that is both pairs passengers and seats perfectly.
Functions also chain together. An oil slick spreads so that its radius after $t$ minutes is $r=3t$ metres; its area is $A=\pi r^2$. Feeding the first rule into the second gives the area directly as a function of time, $A=\pi(3t)^2=9\pi t^2$ — a composite function. In this section we define functions as special relations (Section 1.1), learn to find their domains and ranges, classify them as one-one or many-one and onto or into, count them on finite sets, and study composition. Every later unit of JEE Main — limits, derivatives, integrals, inverse trigonometric functions, probability distributions — is written in this language, and the paper regularly asks directly for the number of one-one or onto functions, the domain or range of a formula, or a property of a composite.
Functions, Domain, Codomain and Range
A relation $f$ from a non-empty set $A$ to a set $B$ is a function (or map) if every element of $A$ is related to exactly one element of $B$. We write $f:A\to B$ and $f(a)=b$ when $(a,b)\in f$; $b$ is the image of $a$, and $a$ is a pre-image of $b$.
$A$ is the domain of $f$, $B$ is its codomain, and the set of all images, $f(A)=\{f(a): a\in A\}\subseteq B$, is its range.
In an arrow diagram, a relation from $A$ to $B$ is a function when exactly one arrow leaves every element of $A$. Nothing is demanded of $B$: an element of $B$ may receive many arrows or none. On a graph in the plane, a curve is the graph of a function of $x$ exactly when every vertical line meets it at most once (the vertical line test) — the circle $x^2+y^2=1$ fails it, the parabola $y=x^2$ passes.
A real function has its domain and codomain inside $\mathbb{R}$. When only a formula is given, the domain is understood to be the largest set of real $x$ for which the formula gives a real number: avoid division by zero and even roots of negative numbers. (Logarithms, with their condition "argument $\gt0$", and the trigonometric functions join the list in Chapters 7 and 14.)
Functions $f$ and $g$ are equal if they have the same domain, the same codomain, and $f(x)=g(x)$ for every $x$ in the domain. For example $f(x)=\dfrac{x^2-1}{x-1}$ and $g(x)=x+1$ are not equal: $f$ is not defined at $x=1$.
If $n(A)=m$ and $n(B)=n$ (both finite, $m\ge1$), the number of functions from $A$ to $B$ is $n^m$.
Proof. A function is fixed by choosing an image for each of the $m$ elements of $A$, and each choice can be any of the $n$ elements of $B$, independently of the others: $n\times n\times\dots\times n=n^m$. $\blacksquare$ Compare with the $2^{mn}$ relations of Theorem 1.4: functions are a small part of all relations. For $m=n=3$ there are $27$ functions among $512$ relations — about $5\%$.
Which of the following defines a function from $\mathbb{R}$ to $\mathbb{R}$?
One-one, Many-one, Onto and Into Functions
The definition of a function makes a demand on the domain only. The two classifications below look at the codomain: does any element of $B$ receive two arrows, and does any receive none?
$f:A\to B$ is one-one (injective) if different elements have different images:
$$f(x_1)=f(x_2)\ \Rightarrow\ x_1=x_2\qquad\text{for all } x_1,x_2\in A.$$Otherwise — if some two different elements share an image — $f$ is many-one.
$f:A\to B$ is onto (surjective) if its range is the whole codomain: for every $b\in B$ there is some $a\in A$ with $f(a)=b$. Otherwise — if the range is a proper subset of $B$ — $f$ is into. A function that is both one-one and onto is a bijection (one-one correspondence).
Whether a function is onto depends on the codomain we name, not just on the formula: $x\mapsto x^2$ is not onto as a map $\mathbb{R}\to\mathbb{R}$ (no $x$ has $x^2=-1$) but is onto as a map $\mathbb{R}\to[0,\infty)$. Likewise whether it is one-one depends on the domain: $x\mapsto x^2$ is many-one on $\mathbb{R}$ but one-one on $[0,\infty)$.
- One-one, algebraically: assume $f(x_1)=f(x_2)$ and deduce $x_1=x_2$. Many-one: one pair $x_1\ne x_2$ with $f(x_1)=f(x_2)$ is enough (even functions on a symmetric domain are many-one: $f(-1)=f(1)$).
- One-one, by graph: every horizontal line meets the graph at most once (the horizontal line test). A function that is strictly increasing or strictly decreasing on its domain is one-one.
- Onto: take a general $y$ in the codomain, solve $f(x)=y$ for $x$, and check that a solution exists and lies in the domain for every such $y$. Equivalently, find the range and compare it with the codomain.
Let $A$ and $B$ be finite and $f:A\to B$.
- If $f$ is one-one, then $n(A)\le n(B)$. If $f$ is onto, then $n(A)\ge n(B)$.
- If $n(A)=n(B)$, then $f$ is one-one if and only if $f$ is onto.
Proof. (1) If $f$ is one-one, the $n(A)$ images are all different, so the range has exactly $n(A)$ elements; it sits inside $B$, so $n(A)\le n(B)$. If $f$ is onto, every element of $B$ has at least one pre-image, and different elements of $B$ have different pre-images, so $A$ has at least $n(B)$ elements. (2) If $f$ is one-one, its range is a subset of $B$ with $n(A)=n(B)$ elements, so it is all of $B$. If $f$ is onto but not one-one, two elements share an image and the range has at most $n(A)-1\lt n(B)$ elements — a contradiction. $\blacksquare$ Part (1) is the pigeonhole principle: put $5$ letters in $4$ pigeonholes and some pigeonhole gets two. Part (2) is false for infinite sets: $f:\mathbb{N}\to\mathbb{N}$, $f(n)=2n$ is one-one but not onto (no odd number is an image).
For finite sets we can count each kind of function. The count of onto functions uses inclusion–exclusion from Section 1.1.
Let $n(A)=m$ and $n(B)=n$.
- The number of one-one functions $A\to B$ is $n(n-1)(n-2)\cdots(n-m+1)$ ($m$ factors) if $m\le n$, and $0$ if $m\gt n$.
- If $m=n$, the number of bijections is $n!=n(n-1)\cdots2\cdot1$.
- The number of onto functions $A\to B$ is $2^m-2$ when $n=2$, and $3^m-3\cdot2^m+3$ when $n=3$.
Proof. (1) Choose images for the elements of $A$ one at a time: the first in $n$ ways, the second must differ from it ($n-1$ ways), the third from both ($n-2$ ways), and so on. (2) is (1) with $m=n$. (3) Let $B=\{p,q,r\}$ and let $M_p$ be the set of functions $A\to B$ whose range misses $p$ — functions into $\{q,r\}$, so $n(M_p)=2^m$; similarly for $M_q$, $M_r$. A function in $M_p\cap M_q$ sends everything to $r$: $n(M_p\cap M_q)=1$; and $M_p\cap M_q\cap M_r=\phi$. The functions that are not onto form $M_p\cup M_q\cup M_r$, which by Theorem 1.3 has $3\cdot2^m-3\cdot1+0$ elements. Subtract from all $3^m$ functions. The case $n=2$ is the same argument with $2^m-1-1$. $\blacksquare$ (In general the number of onto functions is $\sum_{k=0}^{n}(-1)^k\binom nk(n-k)^m$, with the binomial coefficients of Chapter 4.)
Set $n(A)=3$ and $n(B)=4$. Which kind of function will the lab never be able to show you, however long it runs?
A function $f:\{1,2,3,4,5\}\to\{1,2,3,4,5\}$ is known to be one-one. Then $f$
Composition of Functions
Let $f:A\to B$ and $g:B\to C$. The composite $g\circ f:A\to C$ is defined by
$$(g\circ f)(x)=g\big(f(x)\big)\qquad(x\in A).$$Read it from the right: first apply $f$, then apply $g$. For real functions given by formulas, $g\circ f$ is defined at $x$ exactly when $x$ is in the domain of $f$ and $f(x)$ is in the domain of $g$:
$$\operatorname{dom}(g\circ f)=\{x\in\operatorname{dom}f:\ f(x)\in\operatorname{dom}g\}.$$With $f(x)=2x-1$ and $g(x)=x^2$: $(g\circ f)(x)=(2x-1)^2$, but $(f\circ g)(x)=2x^2-1$. At $x=2$ these are $9$ and $7$. So, unlike multiplication of numbers, composition is not commutative: the order of the machines matters. It does, however, have the other good properties of a product.
Let $f:A\to B$, $g:B\to C$ and $h:C\to D$, and let $I_A(x)=x$ be the identity function on $A$.
- Associative: $h\circ(g\circ f)=(h\circ g)\circ f$.
- Identity: $f\circ I_A=f$ and $I_B\circ f=f$.
- If $f$ and $g$ are one-one, so is $g\circ f$. If $f$ and $g$ are onto, so is $g\circ f$. Hence a composite of bijections is a bijection.
- If $g\circ f$ is one-one, then $f$ is one-one. If $g\circ f$ is onto, then $g$ is onto.
Proof. (1) Both sides send $x$ to $h(g(f(x)))$. (2) $f(I_A(x))=f(x)$ and $I_B(f(x))=f(x)$. (3) If $g(f(x_1))=g(f(x_2))$ then $f(x_1)=f(x_2)$ because $g$ is one-one, and then $x_1=x_2$ because $f$ is one-one. For onto: given $c\in C$, pick $b$ with $g(b)=c$ ($g$ onto), then $a$ with $f(a)=b$ ($f$ onto); then $(g\circ f)(a)=c$. (4) If $f(x_1)=f(x_2)$ then certainly $g(f(x_1))=g(f(x_2))$, so $x_1=x_2$. And every $c\in C$ equals $g(f(a))$ for some $a$, so $c$ is the image under $g$ of $f(a)\in B$. $\blacksquare$
Part (4) is a JEE favourite because its converse is false: $g\circ f$ can be one-one while $g$ is not. Take $f:[0,\infty)\to\mathbb{R}$, $f(x)=\sqrt x$ and $g:\mathbb{R}\to\mathbb{R}$, $g(x)=x^2$; then $(g\circ f)(x)=x$ is one-one on $[0,\infty)$, but $g$ is many-one. A bijection $f:A\to B$ has an inverse $f^{-1}:B\to A$ with $f^{-1}\circ f=I_A$ and $f\circ f^{-1}=I_B$; inverse functions are developed in Section 7.1.
Take $f(x)=2x-1$ and $g(x)=x^2$, and put $x_0=2$. Predict the two composite values.
1. Onto depends on the codomain. "Is $f(x)=x^2$ onto?" has no answer until the codomain is named: onto $[0,\infty)$, into $\mathbb{R}$. Read the arrow $f:A\to B$ in the question carefully.
2. The order of composition. $(g\circ f)(x)=g(f(x))$: $f$ acts first. Most wrong options in composition MCQs are the other order.
3. Simplified formulas hide domains. $\left(\sqrt{x-2}\right)^2+1=x-1$ only for $x\ge2$; $\dfrac{x^2-1}{x-1}=x+1$ only for $x\ne1$. Find the domain before simplifying.
4. Counting slips. Functions from an $m$-set to an $n$-set: $n^m$ (images to the power of elements), not $m^n$. One-one needs $m\le n$; onto needs $m\ge n$. For onto maps to a $3$-set the "$+3$" in $3^m-3\cdot2^m+3$ is often forgotten.
5. One example proves "many-one", never "one-one". $f(1)\ne f(2)$ shows nothing about one-one; you must argue for all pairs (or use monotonicity). But a single pair $x_1\ne x_2$ with $f(x_1)=f(x_2)$ settles "many-one".
Let $f:A\to B$ and $g:B\to C$ be functions such that $g\circ f$ is onto. Which statement must be true?
Exercises
Real functions have their largest real domain unless a domain is stated. Justify "one-one" and "onto" by an argument for all elements; disprove them with one example.
- 1 Which of these relations from $\{1,2,3\}$ to $\{4,5,6\}$ are functions? $R_1=\{(1,4),(2,5),(3,4)\}$, $R_2=\{(1,4),(2,6)\}$, $R_3=\{(1,5),(2,5),(3,5)\}$, $R_4=\{(1,4),(1,6),(2,5),(3,6)\}$.
- 2 Find the range of each function in part 1.
- 3 How many functions are there from $\{a,b,c,d,e\}$ to $\{0,1\}$?
- 4 Find the domain and range of $f(x)=\sqrt{9-x^2}$.
- 5 Find the domain of $f(x)=\dfrac{1}{\sqrt{x^2-5x+6}}$.
- 6 Find the domain of $f(x)=\sqrt{x-1}+\sqrt{4-x}$ and its greatest value.
- 7 Find the range of $f(x)=\dfrac{x^2+2}{x^2+1}$.
- 8 Find the range of $f(x)=\dfrac{x-1}{x^2+3}$.
- 9 Are $f(x)=x$ and $g(x)=\sqrt{x^2}$ equal functions on $\mathbb{R}$? Are $f(x)=\dfrac{x^2-1}{x-1}$ and $g(x)=x+1$ equal?
- 1 $f:\mathbb{R}\to\mathbb{R}$, $f(x)=5-2x$.
- 2 $f:\mathbb{R}\to\mathbb{R}$, $f(x)=x^2+2x$. What is the least value of $f$?
- 3 $f:\mathbb{R}\to\mathbb{R}$, $f(x)=x|x|$.
- 4 $f:[0,\infty)\to\mathbb{R}$, $f(x)=\sqrt x$.
- 5 $f:\mathbb{R}-\{2\}\to\mathbb{R}-\{1\}$, $f(x)=\dfrac{x-1}{x-2}$. Find the $x$ with $f(x)=3$.
- 6 $f:\mathbb{N}\to\mathbb{N}$, $f(n)=n+1$ if $n$ is odd and $f(n)=n-1$ if $n$ is even.
- 7 $f:\mathbb{Z}\to\mathbb{Z}$, $f(n)=3n+1$. Find the pre-image of $100$. Does $101$ have one?
- 8 $f:\mathbb{R}\to\mathbb{R}$, $f(x)=x^3-3x$. How many real $x$ satisfy $f(x)=0$?
- 9 Give an example of a function $\mathbb{N}\to\mathbb{N}$ that is onto but not one-one.
- 1 $A=\{1,2,3\}$, $B=\{a,b,c,d\}$: how many functions $A\to B$?
- 2 How many one-one functions $A\to B$ (sets of part 1)?
- 3 How many onto functions $B\to A$?
- 4 How many onto functions are there from $\{1,2,3,4,5\}$ to $\{p,q\}$?
- 5 How many bijections of $\{1,2,3,4,5\}$ onto itself are there, and how many of them satisfy $f(1)=1$?
- 6 How many functions $f:\{1,2,3,4\}\to\{1,2,3,4\}$ satisfy $f(1)=f(2)$?
- 7 How many onto functions are there from a $5$-element set to a $3$-element set?
- 8 How many many-one functions are there from $\{1,2,3\}$ to itself?
- 1 $f(x)=2x+3$, $g(x)=x^2$. Find $(g\circ f)(x)$ and $(f\circ g)(x)$, and the value of $(g\circ f)(1)$.
- 2 $f(x)=3x-1$. Find $(f\circ f)(x)$ and $(f\circ f\circ f)(1)$.
- 3 $f(x)=\dfrac{1}{1-x}$ ($x\ne0,1$). Show that $(f\circ f)(x)=\dfrac{x-1}{x}$ and $(f\circ f\circ f)(x)=x$. Find $f(f(f(7)))$.
- 4 $f(x)=\sqrt x$, $g(x)=x^2-4$. Find the domains of $f\circ g$ and $g\circ f$.
- 5 $f(x)=x+1$ for $x\le1$ and $f(x)=2x$ for $x\gt1$; $g(x)=x^2$. Find $(f\circ g)(-2)$ and $(g\circ f)(-2)$.
- 6 $f(x)=ax+b$ with $a\gt0$ satisfies $f(f(x))=4x+9$ for all $x$. Find $a+b$.
- 7 Prove that if $g\circ f$ is one-one then $f$ is one-one, and give an example in which $g\circ f$ is one-one but $g$ is not.
- 8 (Modelling) An oil slick is circular with radius $r=f(t)=3t$ metres after $t$ minutes, and the area of a circle of radius $r$ is $g(r)=\pi r^2$. Express the area as a composite function of $t$ and find it at $t=4$ minutes (in $\text{m}^2$, to one decimal place).
E1. JEE Main · MCQ Which of the following functions $f:\mathbb{R}\to\mathbb{R}$ is one-one but not onto? (A) $f(x)=x^3-x$ (B) $f(x)=2x+|x|$ (C) $f(x)=x^2+1$ (D) $f(x)=\dfrac{x}{1+|x|}$
E2. JEE Main · Numerical Find the number of onto functions $f:\{1,2,3,4,5\}\to\{a,b,c\}$ with $f(1)=a$. Give the answer to the nearest integer.
E3. JEE Main · MCQ A function $f$ satisfies $3f(x)-f\!\left(\dfrac1x\right)=8x$ for all $x\ne0$. Then $f(2)$ equals (A) $6$ (B) $\dfrac{13}{2}$ (C) $7$ (D) $\dfrac{25}{4}$
E4. JEE Main · Numerical Let $f(x)=x^2-2x$ and $g(x)=2x+3$. Find the sum of the squares of all real $x$ for which $f(g(x))=g(f(x))$. Give the answer to the nearest integer.
E5. JEE Main · MCQ Let $f:A\to B$ and $g:B\to C$ be functions such that $g\circ f:A\to C$ is a bijection. Then necessarily (A) $f$ and $g$ are both bijections (B) $f$ is onto and $g$ is one-one (C) $f$ is one-one and $g$ is onto (D) $g$ is one-one, and nothing can be said about $f$
E6. JEE Main · Numerical Let $f(x)=\dfrac{2x+3}{x-2}$ for $x\ne2$. Writing $f^{(n)}$ for the $n$-fold composite $f\circ f\circ\dots\circ f$, find $f^{(2027)}(3)$. Give the answer to the nearest integer.
Research question. A computer stores records in $k$ "slots" chosen by a hash function $h$ from record numbers to slots. With more possible records than slots, $h$ cannot be one-one. How many records can be stored before two are likely to land in the same slot (a collision)?
Why it matters. Hash functions sit inside databases, compilers, password storage and the checksums that confirm a downloaded file is intact. Engineers choose the number of slots so that collisions stay rare; security researchers search for collisions to break weak hash functions. The underlying question is about many-one functions and the pigeonhole principle of Theorem 1.8.
What to do.
- Take $k=97$ slots and the hash $h(N)=N \bmod 97$ (the remainder when $N$ is divided by $97$). Generate $40$ random six-digit roll numbers (a spreadsheet's random-number function works).
- Insert them one by one and record when the first collision happens. Repeat the experiment about $30$ times and find the average number of records stored before the first collision.
- Theory: if each record lands in a random slot, the chance that the first $r$ records all differ is $\left(1-\tfrac1k\right)\left(1-\tfrac2k\right)\cdots\left(1-\tfrac{r-1}{k}\right)$. Compute it for $r=1,\dots,25$ and find the first $r$ at which a collision becomes more likely than not.
- Compare your experiment with the theory. Then use the roll numbers $970,1067,1164,\dots$ (steps of $97$): what happens, and why?
Tools: Spreadsheet (MOD and RAND functions) or a few lines of Python.
Hand in: Your table of first-collision positions, the theoretical curve, the value of $r$ where it passes $\tfrac12$, and two sentences on why a hash function is deliberately many-one.
Going further. The same calculation with $k=365$ is the "birthday problem": how many people are needed in a room for a shared birthday to be more likely than not? Why does the answer grow like $\sqrt k$ rather than like $k$?
🧪 Self-check quiz
Q1. The number of functions from a set with $3$ elements to a set with $2$ elements is
Q2. The function $f:\mathbb{R}\to\mathbb{R}$, $f(x)=x^2$, is
Q3. If $f(x)=x+1$ and $g(x)=2x$, then $(f\circ g)(x)$ is
Q4. The number of bijections from $\{1,2,3,4\}$ to $\{a,b,c,d\}$ is
Q5. $f:\mathbb{R}-\{0\}\to\mathbb{R}$ is defined by $f(x)=x+\dfrac1x$. Then $f$ is