- Introduction
- What is a function?
- Ways to represent a function
- Domain and range
- The line tests
- Common function families
- Inverse functions
- What is function composition?
- Order matters
- Domains and decomposing
- Real-world chains
- AI and machine learning
- Common mistakes
- Practice problems
- Conclusion
1. Introduction
Variables hold values, equations tie them together, and functions turn that structure into something you can use over and over. A function is a rule that takes an input and produces exactly one output. A vending machine is a good picture: press B4 and you always get the same snack. You can understand it without knowing what happens inside.
Once you have functions, you can connect them. Feed the output of one into the next and you build a pipeline. That is function composition, and it matters far beyond algebra: a modern neural network is nothing but a long composition of simple functions.
This article covers what functions are, how to represent them, what inputs they allow, how to reverse them, and how to compose them. We end with how composition drives deep learning, including why a network needs more than linear steps.
2. What is a function?
A function is a rule that assigns to each allowed input exactly one output. We write y = f(x), read "y equals f of x." Here x is the input, f is the name of the rule, and f(x) is the output. The brackets do not mean multiplication. They mean "apply f to what is inside."
Take f(x) = 2x + 3. To evaluate f(4), replace every x by 4, giving 2(4) + 3 = 11. The input can be a negative number, a fraction, or even another expression such as f(a + 1) = 2(a + 1) + 3 = 2a + 5.
| Input x | Substitution | Output f(x) |
|---|---|---|
| -2 | 2(-2) + 3 | -1 |
| -1 | 2(-1) + 3 | 1 |
| 0 | 2(0) + 3 | 3 |
| 1 | 2(1) + 3 | 5 |
| 2 | 2(2) + 3 | 7 |
| 3 | 2(3) + 3 | 9 |
| 4 | 2(4) + 3 | 11 |
| Term | Meaning | Example |
|---|---|---|
| Input | the value you feed in (independent variable) | x = 4 |
| Output | the value that comes out (dependent variable) | f(4) = 11 |
| Domain | all allowed inputs | all real numbers |
| Range | all outputs that actually occur | all real numbers |
| Rule | what the function does to the input | double, then add 3 |
The key requirement is that each input gives only one output. Different inputs may share an output, but one input may never produce two.
| Input | Output (function) | Input | Output (not a function) |
|---|---|---|---|
| 1 | 4 | 1 | 4 |
| 2 | 7 | 2 | 7 |
| 3 | 7 | 2 | 9 |
The left table is fine, because two different inputs (2 and 3) may share the output 7. The right table breaks the rule because the input 2 is paired with both 7 and 9, so the machine would not know which to return.
3. Ways to represent a function
The same function can be shown in four ways, and moving between them is a valuable skill. An equation is compact and exact. A table lists sample values. A mapping diagram draws arrows from inputs to outputs. A graph shows the whole behaviour at once, with each point an (input, output) pair. Words, such as "double the input and add 3," are often the starting point in real problems.
| Representation | Best for | Limitation |
|---|---|---|
| Equation | exact values and calculation | shape is not obvious |
| Table | seeing specific values | only some inputs shown |
| Mapping diagram | checking one output per input | impractical for many inputs |
| Graph | overall shape and trends | reading exact values is hard |
4. Domain and range
The domain is the set of inputs a function accepts, and the range is the set of outputs it produces. Domains are limited by two common troubles: you cannot divide by zero, and you cannot take the square root of a negative number (in real numbers). For f(x) = √(x − 2), the expression under the root must be at least zero, so x ≥ 2. Because a square root is never negative, the range is y ≥ 0.
| Function | Domain | Range | Reason |
|---|---|---|---|
| 2x + 3 | all real numbers | all real numbers | no restrictions |
| x² | all real numbers | y ≥ 0 | squares are never negative |
| √x | x ≥ 0 | y ≥ 0 | no root of a negative |
| 1/x | x ≠ 0 | y ≠ 0 | cannot divide by zero |
| |x| | all real numbers | y ≥ 0 | absolute value is never negative |
5. The line tests
How do you tell whether a graph shows a function? Use the vertical line test. If any vertical line crosses the graph more than once, one input has two outputs, so it is not a function. A parabola passes, while a circle fails because a vertical line cuts it in two places.
A related horizontal line test checks whether a function is one-to-one, meaning no two inputs share an output. The curve y = x² fails because both 2 and −2 give 4, while y = x³ passes. Only one-to-one functions can be reversed cleanly, which matters in the next section.
6. Common function families
A handful of function families appear again and again. Recognising their shapes and formulas lets you recognise them in the wild, and several of them are the topics of the next articles in this series.
| Family | Formula | Shape or role |
|---|---|---|
| Linear | f(x) = mx + b | straight line, constant rate |
| Quadratic | f(x) = ax² + bx + c | parabola, one turning point |
| Absolute value | f(x) = |x| | V shape |
| Square root | f(x) = √x | half-parabola on its side |
| Reciprocal | f(x) = 1/x | two branches, never touches the axes |
| Exponential | f(x) = bˣ | rapid growth or decay |
| Logarithmic | f(x) = log x | slow growth, inverse of exponential |
| Sigmoid | f(x) = 1/(1 + e⁻ˣ) | S-curve squeezing values into 0 to 1 |
| ReLU | f(x) = max(0, x) | zero for negatives, identity for positives |
Some functions use different rules on different parts of the domain. These are piecewise functions. The absolute value, |x|, equals x when x ≥ 0 and −x otherwise. ReLU is the same idea: max(0, x) outputs 0 for negative inputs and x for the rest, so ReLU(−3) = 0 and ReLU(5) = 5. Piecewise definitions are how a simple formula can still produce a bend or a corner.
7. Inverse functions
An inverse function undoes the original. If f turns 4 into 11, then f⁻¹ turns 11 back into 4. To find it, write y = f(x), swap x and y, and solve for y. The notation f⁻¹ means "inverse," not "one over f."
| Step | Work |
|---|---|
| 1. Write y = | y = 2x + 3 |
| 2. Swap x and y | x = 2y + 3 |
| 3. Solve for y | y = (x − 3) / 2 |
| 4. Name it | f⁻¹(x) = (x − 3) / 2 |
The check is composition, covered next: f(f⁻¹(x)) = 2 · (x − 3)/2 + 3 = x. The graphs of a function and its inverse are mirror images across the line y = x, because every point (a, b) on one becomes (b, a) on the other.
| x | f(x) = 2x + 3 | f⁻¹ of that |
|---|---|---|
| 0 | 3 | 0 |
| 1 | 5 | 1 |
| 2 | 7 | 2 |
| 5 | 13 | 5 |
Only one-to-one functions have inverses. The function x² fails the horizontal line test, so to reverse it we restrict the domain to x ≥ 0, where the inverse is √x.
8. What is function composition?
Function composition means feeding the output of one function into another. The composite of f and g is written (f ∘ g)(x) = f(g(x)). Read it from the inside out: apply g to x first, then apply f to the result. The small circle is read "composed with" or "after."
Let f(x) = 2x + 3 and g(x) = x². Then (f ∘ g)(x) = f(x²) = 2x² + 3. At x = 2, first g(2) = 4, then f(4) = 11. As a check, the formula gives 2(4) + 3 = 11.
9. Order matters
Composition is not commutative: f ∘ g and g ∘ f are usually different. Reversing the order above gives (g ∘ f)(x) = g(2x + 3) = (2x + 3)², and at x = 2 this is f(2) = 7 then 7² = 49, not 11. Think of getting dressed: socks then shoes is a very different outcome from shoes then socks.
| x | g(x) | (f ∘ g)(x) = 2x² + 3 | f(x) | (g ∘ f)(x) = (2x + 3)² |
|---|---|---|---|---|
| -2 | 4 | 11 | -1 | 1 |
| -1 | 1 | 5 | 1 | 1 |
| 0 | 0 | 3 | 3 | 9 |
| 1 | 1 | 5 | 5 | 25 |
| 2 | 4 | 11 | 7 | 49 |
| 3 | 9 | 21 | 9 | 81 |
Money shows the same effect. A shop takes 10 dollars off, then adds 10 percent tax. With d(p) = p − 10 and t(p) = 1.1p, discounting first gives t(d(p)) = 1.1p − 11, while taxing first gives d(t(p)) = 1.1p − 10. For a 100 dollar item that is 99 versus 100 dollars.
| Property | Statement | True? |
|---|---|---|
| Commutative | f ∘ g = g ∘ f | usually not |
| Associative | (f ∘ g) ∘ h = f ∘ (g ∘ h) | always |
| Identity | f ∘ I = I ∘ f = f, where I(x) = x | always |
| Inverse | f ∘ f⁻¹ = f⁻¹ ∘ f = I | when f⁻¹ exists |
10. Domains and decomposing
For (f ∘ g)(x) to make sense, two things must hold: x must be allowed in g, and the result g(x) must be allowed in f. Take f(x) = √x and g(x) = x − 4. The composite (f ∘ g)(x) = √(x − 4) requires x − 4 ≥ 0, so its domain is x ≥ 4. The other order, (g ∘ f)(x) = √x − 4, only needs x ≥ 0.
| Composite | Formula | Domain |
|---|---|---|
| f ∘ g | √(x − 4) | x ≥ 4 |
| g ∘ f | √x − 4 | x ≥ 0 |
The reverse skill is decomposition: spotting the inner and outer function inside a formula. Ask what happens to x first, then what happens to that result.
| Formula h(x) | Inner g(x) | Outer f(u) |
|---|---|---|
| (3x − 1)² | 3x − 1 | u² |
| √(x² + 1) | x² + 1 | √u |
| 1/(x + 5) | x + 5 | 1/u |
| e²ˣ | 2x | eᵘ |
Compositions can chain three or more functions. With h(x) = x + 1, g(x) = 2x and f(x) = x², we get f(g(h(x))) = (2(x + 1))². At x = 2: h = 3, then g = 6, then f = 36.
11. Real-world chains
Unit conversions are compositions. Celsius to Fahrenheit is F(C) = 1.8C + 32, and Fahrenheit to Kelvin is K(F) = (F − 32)/1.8 + 273.15. Composing them gives K(F(C)) = C + 273.15, which is the direct Celsius-to-Kelvin rule. The messy middle step simplifies away, a typical gain from composing.
| C (°C) | F(C) (°F) | K(F(C)) (K) | C + 273.15 |
|---|---|---|---|
| -40 | -40 | 233.15 | 233.15 |
| 0 | 32 | 273.15 | 273.15 |
| 37 | 98.6 | 310.15 | 310.15 |
| 100 | 212 | 373.15 | 373.15 |
Pricing, physics and data pipelines work the same way: each stage is a function, and the whole process is their composition. Spotting that structure lets you analyse, test and replace one stage at a time.
12. AI and machine learning
A single artificial neuron is a composition of two functions. First a linear function mixes the inputs, z = wx + b. Then an activation function such as sigmoid or ReLU reshapes the result. A layer repeats this for many neurons, and a network stacks layers, so the model is ŷ = f₃(f₂(f₁(x))): composition, just deeper.
| Stage | x = 2 | x = 1 |
|---|---|---|
| input x | 2 | 1 |
| linear: 2x − 3 | 1 | -1 |
| ReLU | 1 | 0 |
| linear: 3a − 1 | 2 | -1 |
| sigmoid σ | 0.881 | 0.269 |
Why not use only linear functions? Because composing linear functions gives another linear function. With f(x) = 2x + 1 and g(x) = 3x − 2, the composite is f(g(x)) = 2(3x − 2) + 1 = 6x − 3. A hundred linear layers collapse into one, and the model can only draw straight lines. Inserting a non-linear activation between layers makes the composite bend, which is what lets networks capture curves, shapes and patterns.
| Network | Composite | Shape |
|---|---|---|
| linear then linear | 6x − 3 | straight line |
| linear, ReLU, linear | 3·ReLU(2x − 1) − 2 | bent line, flat then rising |
Depth is simply the number of functions in the chain. Small networks compose a handful of layers, while large language and vision models compose dozens or hundreds, each a simple function on its own. The power comes from the composition. Early stages detect simple patterns, later stages combine them, and the final stages turn them into an answer, just as g feeds f in our small examples.
Training also depends on composition. To improve the weights we need to know how the output changes when an early value changes. The chain rule from calculus says the slope of a composite is the product of the slopes of its stages: d/dx f(g(x)) = f′(g(x)) · g′(x). Backpropagation applies this stage by stage, multiplying from the output back toward the input. This is calculus rather than algebra, but it only works because networks are compositions.
| Stage | Value or slope | Calculation |
|---|---|---|
| inner g(x) = 3x − 1 | 2 | 3(1) − 1 |
| slope of g | 3 | g′(x) = 3 |
| outer f(u) = u², slope at u = 2 | 4 | 2u = 2(2) |
| slope of h | 12 | 4 × 3 |
| Algebra | Machine learning |
|---|---|
| function | model, layer or activation |
| input / output | features / prediction |
| composition f(g(x)) | stacked layers |
| sigmoid, ReLU (function families) | activation functions |
| inverse function | decoding, undoing a transform |
| domain restriction | valid input range, preprocessing |
13. Common mistakes
| Mistake | Wrong | Right |
|---|---|---|
| Reading f(g(x)) left to right | f(g(x)): apply f first | apply g first, then f |
| Treating composition as multiplication | f(g(x)) = (2x + 3)·x² | f(g(x)) = 2x² + 3 |
| Reading f⁻¹ as a reciprocal | f⁻¹(x) = 1/(2x + 3) | f⁻¹(x) = (x − 3)/2 |
| Assuming f(a + b) = f(a) + f(b) | f(x) = x²: f(1 + 2) = 5 | f(3) = 9, but f(1) + f(2) = 5 |
| Ignoring the domain | √(x − 4) at x = 2 | needs x ≥ 4 |
| Skipping the vertical line test | calling a circle a function | a vertical line hits it twice |
14. Practice problems
Try these before looking at the answers.
- If f(x) = 3x − 4, find f(5) and f(−2).
- State the domain and range of g(x) = √(x + 6).
- With f(x) = x + 5 and g(x) = 2x, find (f ∘ g)(x) and (g ∘ f)(x).
- With f(x) = x² − 1 and g(x) = x + 2, evaluate (f ∘ g)(3).
- Find the inverse of f(x) = (x + 7)/3.
- Write h(x) = (x − 4)³ as f(g(x)).
- With f(x) = √x and g(x) = x − 9, find the domain of f ∘ g.
- Show that f(x) = 2x + 1 composed with g(x) = 3x − 2 equals 6x − 3.
Answers.
- f(5) = 3(5) − 4 = 11 and f(−2) = 3(−2) − 4 = −10.
- Domain x ≥ −6, range y ≥ 0.
- (f ∘ g)(x) = 2x + 5 and (g ∘ f)(x) = 2(x + 5) = 2x + 10.
- g(3) = 5, then f(5) = 25 − 1 = 24.
- Swap: x = (y + 7)/3, so y = 3x − 7. The inverse is f⁻¹(x) = 3x − 7.
- g(x) = x − 4 and f(u) = u³.
- √(x − 9) needs x − 9 ≥ 0, so the domain is x ≥ 9.
- f(g(x)) = 2(3x − 2) + 1 = 6x − 4 + 1 = 6x − 3.
15. Conclusion
A function is a rule with one output for every allowed input, and it can be shown as an equation, a table, a mapping or a graph. The domain and range describe what goes in and what comes out, the line tests tell you whether a graph is a function and whether it can be reversed, and the inverse undoes it.
Composition chains functions into pipelines. Its order matters, its domain depends on both parts, and in machine learning it is the structure of every neural network, with non-linear activations preventing the whole stack from collapsing into a single line. Next in this series come exponential and logarithmic functions, which are themselves inverses and are the engines of growth, probability and loss functions.