Topic · Algebra

Functions

A function is a rule that turns inputs into outputs, with one ironclad requirement: each input gets exactly one output. Once you have that idea, much of higher mathematics — calculus, statistics, machine learning — is just the study of which functions do what.

What you'll leave with

  • What a function actually is, and the single rule that disqualifies a relation from being one.
  • The notation $f(x)$ — what it says, and what it does not say.
  • What "domain" and "range" mean, and how to read them off a formula or a graph.
  • The vertical line test — a one-second visual check for whether a curve is a function.
  • What it means to compose two functions, and what the inverse of a function is.
  • An interactive feel for how five common functions behave as you sweep their input.

1. What a function is

Picture a machine. You put in a number; the machine does something to it; another number comes out. The rule the machine follows is the function.

Function

A rule that assigns to each input from one set (the domain) exactly one output from another set (the codomain). The defining requirement: each input has exactly one output. No more, no less.

Examples of functions:

  • "Multiply by $3$ and add $2$." Input $1$ gives $5$; input $-4$ gives $-10$; input $\pi$ gives $3\pi + 2$.
  • "Take the square." Input $5$ gives $25$; input $-5$ also gives $25$. Two different inputs producing the same output is fine — what's not allowed is one input producing two outputs.
  • The rule "give me the temperature at this time of day." For each time, there's one temperature.

And a non-example: "give me a number whose square is $x$." That rule fails because, for $x = 9$, there are two answers ($3$ and $-3$). For the rule to be a function, you have to commit to one of them — say, always the positive root. That's exactly what $\sqrt{x}$ does.

Why the "one output" rule matters

Almost every calculation in math and science assumes that the rule it's using is well-defined: feed it the same input, get the same output. A "rule" that gives different answers depending on mood isn't usable in a calculation. Functions are the formalization of "well-defined rule."

2. Function notation: $f(x)$

The standard way of writing a function is to name it (typically $f$, $g$, $h$) and write its input in parentheses. If $f$ is the function "multiply by $3$ and add $2$," then:

$$ f(x) = 3x + 2. $$

The notation $f(x)$ is read "$f$ of $x$." It does not mean "$f$ times $x$." The parentheses here group an input to the function, not a factor in a product.

To evaluate a function at a particular input, substitute it in:

$$ f(1) = 3 \cdot 1 + 2 = 5, \qquad f(-4) = 3 \cdot (-4) + 2 = -10, \qquad f(\pi) = 3\pi + 2. $$

The input can itself be an expression:

$$ f(a + 1) = 3(a + 1) + 2 = 3a + 5. $$

Wherever the formula had an $x$, write $(a + 1)$ instead. Parentheses are crucial — they keep the substituted expression intact under the order of operations.

Different letters, same idea

Mathematicians switch between names freely. You'll see $g(t)$, $h(x)$, $\varphi(\theta)$, $\sigma(n)$ — all functions, all with the same notation. The letters are conventional shorthand for which kind of function or input is at play, not anything structural.

3. Domain and range

Two sets come with every function:

  • The domain is the set of valid inputs — every number for which the rule produces a sensible output.
  • The range is the set of actual outputs — every value the function ever takes for some input in the domain.

For most algebraic functions on real numbers, the domain is "all real numbers" unless something would force a problem. The two main problems:

  • Division by zero. $f(x) = \tfrac{1}{x - 2}$ has domain "all real numbers except $2$," because at $x = 2$ the denominator is zero.
  • Square root of a negative. $f(x) = \sqrt{x - 5}$ has domain $x \geq 5$, because for $x < 5$ the inside is negative.

Finding the range from a formula can be harder. For $f(x) = x^2$, the range is "all non-negative reals" — because $x^2 \geq 0$ always, and every non-negative number is the square of something. For $f(x) = x^2 + 3$, the range is $[3, \infty)$ — every output is at least $3$.

4. Graphs and the vertical line test

The graph of a function $f$ is the set of points $(x, f(x))$ in the plane. For each $x$ in the domain, there's exactly one point on the graph.

This gives an easy visual check, the vertical line test:

A curve in the plane is the graph of a function if and only if every vertical line crosses it at most once.
Function: y = x² (passes) 1 intersection ✓ Not a function: x = y² (fails) 2 intersections ✗

A vertical line at $x = a$ corresponds to "the value of the function at $x = a$." Hitting the curve twice means the function would give two outputs for the same input — which isn't allowed. Hitting it once is fine. Hitting it not at all just means $a$ isn't in the domain.

5. Composition and inverses

Composition

If $f$ and $g$ are both functions, you can apply them one after the other. Apply $g$ first, then $f$ on the result. This is written $f \circ g$, read "$f$ of $g$":

$$ (f \circ g)(x) = f(g(x)). $$

Example: $f(x) = x^2$ and $g(x) = x + 1$. Then:

$$ (f \circ g)(x) = f(g(x)) = f(x + 1) = (x + 1)^2. $$

Composition is generally not commutative: $f \circ g$ and $g \circ f$ are usually different functions. With the same $f$ and $g$, $(g \circ f)(x) = g(f(x)) = x^2 + 1$, which is not $(x + 1)^2$.

Inverses

The inverse of a function $f$, written $f^{-1}$, undoes whatever $f$ did. If $f(3) = 7$, then $f^{-1}(7) = 3$. Composing a function with its inverse gives back the input:

$$ f^{-1}(f(x)) = x, \qquad f(f^{-1}(x)) = x. $$

For $f(x) = 3x + 2$, the inverse is found by reversing the steps: subtract $2$, then divide by $3$. So $f^{-1}(x) = \tfrac{x - 2}{3}$.

One subtlety: not every function has an inverse. The squaring function $f(x) = x^2$ doesn't have a single inverse on all real numbers, because $f(3) = f(-3) = 9$ — given output $9$, the inverse can't decide whether the answer is $3$ or $-3$. We fix this either by restricting the domain (just non-negative numbers, say) or by accepting that the "inverse" is a multivalued thing.

$f^{-1}$ is not a reciprocal

The notation $f^{-1}$ is a serious source of confusion. It is not $\tfrac{1}{f(x)}$. The superscript $-1$ here means "inverse function," not "reciprocal." Trig functions get the same treatment: $\sin^{-1}(x)$ is the inverse sine, not $\tfrac{1}{\sin(x)}$. The clash is unfortunate but universal.

6. Playground: feed inputs to a function

Pick a function. Sweep the input $x$. Watch the output, the curve, and the point trace at $(x, f(x))$ update together. The dashed lines show the bookkeeping every function does: take an $x$ on the horizontal axis, climb up to the curve, then read across to the value on the vertical axis.

function  f(x) = 2x + 1
domain    all real x
input     x = 1.00
output    f(x) = 3.00
1.00
x y
Try it

Switch to $1/x$ and drag the slider through $x = 0$ — notice the slider refuses to land there because the function isn't defined. Switch to $\sqrt{x}$ and the slider clamps to non-negative values. Domain isn't a footnote; it's part of the function.

7. Common pitfalls

$f(x)$ does not mean $f$ times $x$

The parentheses indicate function application, not multiplication. $f(a + b)$ means "apply $f$ to $a + b$," not "$f \cdot (a + b)$." This trips up everyone the first time.

Forgetting to check the domain

Before declaring a function "$f(x) = \sqrt{x - 5}$," check that the input makes sense. $f(2)$ is undefined ($\sqrt{-3}$ has no real value). Always verify that an input is in the domain — or at least be aware of where the domain fails.

Composition order

$(f \circ g)(x)$ is $f(g(x))$ — apply the inner function first. Reading composition left-to-right and applying the leftmost function first is wrong half the time. When unsure, evaluate at a concrete number and confirm.

Treating $f^{-1}$ as a reciprocal

$f^{-1}(x) \neq \tfrac{1}{f(x)}$. The first is the inverse function; the second is the reciprocal value. They're almost never the same number. The "$-1$" is a function-level superscript, not an exponent on the output.

8. Worked examples

Example 1 · For $f(x) = 2x^2 - 3$, find $f(4)$, $f(-1)$, $f(a + 2)$

Substitute the inputs:

  • $f(4) = 2(16) - 3 = 29$.
  • $f(-1) = 2(1) - 3 = -1$.
  • $f(a + 2) = 2(a + 2)^2 - 3 = 2(a^2 + 4a + 4) - 3 = 2a^2 + 8a + 5$.
Example 2 · Find the domain of $f(x) = \dfrac{1}{x^2 - 4}$

The denominator vanishes when $x^2 - 4 = 0$, i.e. $x = \pm 2$. Those values must be excluded.

Domain: $\boxed{\{x : x \neq 2 \text{ and } x \neq -2\}}$, or in interval notation $(-\infty, -2) \cup (-2, 2) \cup (2, \infty)$.

Example 3 · For $f(x) = x^2 + 1$ and $g(x) = 2x$, find $(f \circ g)(x)$ and $(g \circ f)(x)$

$(f \circ g)(x) = f(g(x)) = f(2x) = (2x)^2 + 1 = 4x^2 + 1$.

$(g \circ f)(x) = g(f(x)) = g(x^2 + 1) = 2(x^2 + 1) = 2x^2 + 2$.

They're different — composition is not commutative.

Example 4 · Find the inverse of $f(x) = 3x + 5$

Trick: write $y = 3x + 5$, then swap $x$ and $y$ and solve for $y$:

$$ x = 3y + 5 \;\Longrightarrow\; x - 5 = 3y \;\Longrightarrow\; y = \tfrac{x - 5}{3}. $$

So $f^{-1}(x) = \tfrac{x - 5}{3}$. Check: $f(f^{-1}(x)) = 3 \cdot \tfrac{x - 5}{3} + 5 = x - 5 + 5 = x$ ✓.

Example 5 · Does the equation $y = \pm\sqrt{x}$ define a function?

No. For each positive $x$, the equation gives two values of $y$ (positive and negative root). A function must give exactly one. The vertical line test would catch this — a vertical line at $x = 4$ would hit both $y = 2$ and $y = -2$.

The single-valued square-root function $y = \sqrt{x}$ (just the positive root) is a function. The relation $y^2 = x$ (which includes both roots) is not.

Sources & further reading

Test your understanding

A quiz that builds from easy to hard. Pick an answer to get instant feedback and a worked explanation. Your progress is saved in this browser — come back anytime to continue.

Question 1
0 correct