What a Function Is
Take two sets. A relation pairs members of the first set with members of the second. A function is a special kind of relation: every member of the first set is paired with one member of the second set, and only one. A class register is a good picture of this. Every student has exactly one roll number, so the rule "student to roll number" is a function. A student with two roll numbers, or with none at all, would break it.
Function: a relation from set A to set B in which every member of A is related to exactly one member of B. If f is a function from A to B we write \( f: A \to B \). The member of B paired with x is called the image of x and is written \( f(x) \).
People used the idea of a function informally for a very long time. It was given a formal shape in the seventeenth century, when calculus was being developed. In 1673 Gottfried Wilhelm Leibniz used the word "function". In 1730 Leonhard Euler was the first to write a function in the form \( y = f(x) \), the notation still used in every classroom today.


Functions appear in daily life and in mathematics, science, commerce, economics and engineering. The price you pay for petrol depends on how many litres you buy. The distance a bus covers depends on how long it travels. In each case one quantity is a function of another.
Joining Two Functions in a Chain
Now take three sets instead of two: \( A = \{1, 2, 3, 4\} \), \( B = \{2, 3, 4, 5\} \) and \( C = \{3, 4, 5, 6\} \). A function f carries A into B, and a second function g carries B into C. Follow the arrows in the diagram below.

Written as ordered pairs, the two functions are:
\[ f = \{(1, 2), (2, 3), (3, 4), (4, 5)\} \]
\[ g = \{(2, 3), (3, 4), (4, 5), (5, 6)\} \]
Each member of A is joined by f to exactly one member of B: 1 goes to 2, 2 goes to 3, 3 goes to 4 and 4 goes to 5. Under g, the images of the members of B are 3, 4, 5 and 6. Now follow the member 1 all the way along. The function f takes it to 2, and then g takes 2 on to 3. So 1 in A ends up joined to 3 in C, even though neither f nor g has an arrow going directly from A to C. Doing the same for every member of A gives a new relation from A to C:
\[ A \to C = \{(1, 3), (2, 4), (3, 5), (4, 6)\} \]
Every member of A appears exactly once as a first entry, so this relation is itself a function from A to C. It was made by joining f and g one after the other, and that is exactly what a composite function is. Look at the rules behind the arrows as well. The function f adds 1, so \( f(x) = x + 1 \). The function g also adds 1, so \( g(x) = x + 1 \). Passing through both adds 2, and every pair in the new function fits the rule "add 2".
Composite Function and Its Notation
Composite function: if \( f: A \to B \) and \( g: B \to C \) are functions, and the relation from A to C formed by applying f first and then g is also a function, then this function from A to C is called the composite function of f and g. It is written \( gof: A \to C \), or \( gof(x) \), \( gof \), \( gf(x) \) or simply \( gf \).
The symbol gof is read "g of f", or "the composite of g and f". The small letter o between the two function names means "following": g following f. The meaning of the symbol is carried by one formula:
\[ gof(x) = g(f(x)) \]
Read it from the inside outwards. First find \( f(x) \), the image of x under f. That image is a member of B, so g can act on it, and the result \( g(f(x)) \) is a member of C. In the chain above, \( f(1) = 2 \) and \( g(2) = 3 \), so \( gof(1) = g(f(1)) = g(2) = 3 \).
A function can also be joined to itself, as long as its outputs can be fed straight back into it. Then \( ff(x) = f(f(x)) \): apply f, and then apply f again to the answer. For example, if \( f(x) = x + 1 \), then \( ff(x) = f(x + 1) = x + 2 \).
Which Function Acts First
In \( gf(x) \) the letter standing next to x is f, and f acts first. The letter on the far left acts last. So a composite is read from right to left, the opposite of the way we read words. Swap the two letters and the order of the work swaps too:
\[ fg(x) = f(g(x)) \]
Here g acts first and f acts second. The same rule reads an arrow diagram. Look at the arrow that leaves the first set. The function it belongs to acts first, so its letter goes on the right of the name. In the diagram below, g carries A into B and f carries B into C, so the function from A to C is \( fg(x) \).

gof and fog are not the same function. In gof, f acts first. In fog, g acts first. For most pairs of functions the two give different answers, so never swap the letters to make a question easier.
The order rule lets you check a label for yourself. In the next diagram, g leaves A and f arrives at C. The composite from A to C is therefore fog, which means \( f(g(x)) \). The lower arrow carries the label gof, which has the letters the wrong way round. Trust the arrows, not the label.

When a Composite Can Be Formed
A composite only works if the chain connects. Every output of the first function must be something the second function is able to act on. For \( gof \), each image \( f(x) \) must lie in the domain of g. In this lesson the functions are set up so that the first one ends in the very set where the second one starts, \( f: A \to B \) and \( g: B \to C \). When f is onto B, its outputs fill the whole of B, and g is defined on every one of them, so the chain always connects.
Think of a relay race. The first runner must hand the baton to someone standing on the second runner's track. If f sends a member of A to a place where g has no arrow leaving it, that member of A is stranded. It has no partner in C, and the relation from A to C is no longer a function.
This is also why a composite does not run backwards. From \( f: A \to B \) and \( g: B \to C \) we can build a function from A to C, but a relation from C to A is not the composite of f and g. The chain only runs in the direction of its arrows.
Worked Example 1: Composites from an Arrow Diagram
In the diagram below, the functions \( g: A \to A \) and \( f: A \to A \) both act on the set \( A = \{1, 2, 3, 5\} \). The function g acts first and f acts second, so the lower arrow is fog.

(a) Writing g as ordered pairs. Each arrow of g gives one pair: the first entry is where the arrow starts and the second entry is where it lands:
\[ g = \{(1, 3), (2, 1), (3, 2), (5, 5)\} \]
(b) Writing f as ordered pairs, reading the arrows from the middle set to the right-hand set in the same way:
\[ f = \{(1, 5), (2, 1), (3, 3), (5, 2)\} \]
(c) Finding fog(1), fog(2), fog(3) and fog(5). For each input, g is applied first and its answer is fed into f. Starting with 1, g gives 3, and f takes 3 to 3:
\[ fog(1) = f(g(1)) = f(3) = 3 \]
Starting with 2, g gives 1, and f takes 1 to 5:
\[ fog(2) = f(g(2)) = f(1) = 5 \]
Starting with 3, g gives 2, and f takes 2 to 1:
\[ fog(3) = f(g(3)) = f(2) = 1 \]
Starting with 5, g gives 5, and f takes 5 to 2:
\[ fog(5) = f(g(5)) = f(5) = 2 \]
(d) Writing fog as ordered pairs, pairing each input with the value just found:
\[ fog = \{(1, 3), (2, 5), (3, 1), (5, 2)\} \]
(e) Finding gof(1), gof(2), gof(3) and gof(5). Now the order is reversed: f acts first and g acts second. So the arrow diagram for gof is drawn with the arrows of f on the left:

Starting with 1, f gives 5, and g takes 5 to 5:
\[ gof(1) = g(f(1)) = g(5) = 5 \]
Starting with 2, f gives 1, and g takes 1 to 3:
\[ gof(2) = g(f(2)) = g(1) = 3 \]
Starting with 3, f gives 3, and g takes 3 to 2:
\[ gof(3) = g(f(3)) = g(3) = 2 \]
Starting with 5, f gives 2, and g takes 2 to 1:
\[ gof(5) = g(f(5)) = g(2) = 1 \]
(f) Writing gof as ordered pairs:
\[ gof = \{(1, 5), (2, 3), (3, 2), (5, 1)\} \]
Compare the two answers. \( fog(1) = 3 \) but \( gof(1) = 5 \). The same two functions, joined in the opposite order, give a different composite.
Worked Example 2: Composites of Two Formulas
When functions are given as formulas, a composite is found by substitution. The whole expression for the inner function is put in place of x in the outer function. Take \( f(x) = 3x \) and \( g(x) = 2x + 1 \), and find gf(x), fg(x), ff(x) and fg(1).
(a) Finding gf(x). Step 1: By the meaning of the notation, f acts first:
\[ gf(x) = g(f(x)) \]
Step 2: Replacing f(x) by its formula, 3x:
\[ gf(x) = g(3x) \]
Step 3: The rule of g is "double and add 1", so 3x takes the place of x in 2x + 1:
\[ gf(x) = 2(3x) + 1 \]
Step 4: Multiplying out the bracket:
\[ gf(x) = 6x + 1 \]
(b) Finding fg(x). Step 1: This time g acts first:
\[ fg(x) = f(g(x)) \]
Step 2: Replacing g(x) by its formula, 2x + 1:
\[ fg(x) = f(2x + 1) \]
Step 3: The rule of f is "multiply by 3", so the whole of 2x + 1 is multiplied by 3:
\[ fg(x) = 3(2x + 1) \]
Step 4: Expanding the bracket:
\[ fg(x) = 6x + 3 \]
(c) Finding ff(x). Step 1: f acts twice, one after the other:
\[ ff(x) = f(f(x)) \]
Step 2: Replacing the inner f(x) by 3x:
\[ ff(x) = f(3x) \]
Step 3: Multiplying the input 3x by 3:
\[ ff(x) = 3(3x) = 9x \]
(d) Finding fg(1). Step 1: Part (b) gave \( fg(x) = 6x + 3 \), so x is replaced by 1:
\[ fg(1) = 6 \times 1 + 3 \]
Step 2: Multiplying first and then adding:
\[ fg(1) = 6 + 3 = 9 \]
You can check this by walking the chain instead: \( g(1) = 2 \times 1 + 1 = 3 \), and then \( f(3) = 3 \times 3 = 9 \). Both routes give 9. Notice also that parts (a) and (b) gave \( gf(x) = 6x + 1 \) and \( fg(x) = 6x + 3 \), which are different.
Worked Example 3: Where Two Functions Give the Same Value
Sometimes two functions are compared rather than joined. If \( f(x) = x^2 + 2 \), \( g(x) = x + 14 \) and \( f(a) = g(a) \), find the value of a. The question asks for the input at which both functions give the same output.
Step 1: Putting a in place of x in both formulas and setting them equal:
\[ a^2 + 2 = a + 14 \]
Step 2: Bringing every term to the left side:
\[ a^2 - a - 12 = 0 \]
Step 3: Splitting the middle term, because \( -4 \times 3 = -12 \) and \( -4 + 3 = -1 \):
\[ a^2 - 4a + 3a - 12 = 0 \]
Step 4: Taking out the common factor from each pair of terms:
\[ a(a - 4) + 3(a - 4) = 0 \]
Step 5: Taking out the common bracket \( (a - 4) \):
\[ (a - 4)(a + 3) = 0 \]
Step 6: A product is zero only when one of its factors is zero, so:
\[ a = 4 \text{ or } a = -3 \]
Checking both answers: \( f(4) = 18 \) and \( g(4) = 18 \), while \( f(-3) = 11 \) and \( g(-3) = 11 \). Both values of a work.
Worked Example 4: Finding an Unknown Constant
If \( f(x) = kx + 3 \), \( g(x) = 2x - 4 \) and \( gf(2) = 34 \), find the value of k. The plan is to build the composite first, then use the value it is given.
Step 1: In gf(x), f acts first, so kx + 3 is fed into g:
\[ gf(x) = g(kx + 3) \]
Step 2: The rule of g is "double and subtract 4":
\[ gf(x) = 2(kx + 3) - 4 \]
Step 3: Expanding and collecting the numbers, since \( 6 - 4 = 2 \):
\[ gf(x) = 2kx + 2 \]
Step 4: Putting x = 2 and using \( gf(2) = 34 \):
\[ 2k \times 2 + 2 = 34 \]
Step 5: Simplifying the left side:
\[ 4k + 2 = 34 \]
Step 6: Subtracting 2 from both sides:
\[ 4k = 32 \]
Step 7: Dividing both sides by 4:
\[ k = 8 \]
Checking: with k = 8, \( f(2) = 8 \times 2 + 3 = 19 \), and \( g(19) = 2 \times 19 - 4 = 34 \). That is the value we were given.
Worked Example 5: Finding a Missing Function
If \( f(x) = 2x + 5 \) and \( gf(x) = 18x + 41 \), find g(x). This time the composite is known and the outer function is missing. There are two sensible ways to find it.
Method 1, rewriting the right side. Step 1: Since \( gf(x) = g(f(x)) \) and \( f(x) = 2x + 5 \):
\[ g(2x + 5) = 18x + 41 \]
Step 2: Writing the right side in terms of 2x + 5. Because \( 9(2x + 5) = 18x + 45 \), the term 18x equals \( 9(2x + 5) - 45 \):
\[ g(2x + 5) = 9(2x + 5) - 45 + 41 \]
Step 3: Collecting the numbers, since \( -45 + 41 = -4 \):
\[ g(2x + 5) = 9(2x + 5) - 4 \]
Step 4: This says that g multiplies whatever it receives by 9 and then subtracts 4. Writing x for the input:
\[ g(x) = 9x - 4 \]
Method 2, substituting a new letter. Step 1: As before:
\[ g(2x + 5) = 18x + 41 \]
Step 2: Letting a stand for the input of g:
\[ a = 2x + 5 \]
Step 3: Making x the subject, by subtracting 5 and dividing by 2:
\[ x = \frac{a - 5}{2} \]
Step 4: Putting this in place of x on the right side:
\[ g(a) = 18\left(\frac{a - 5}{2}\right) + 41 \]
Step 5: Dividing 18 by 2 and expanding:
\[ g(a) = 9a - 45 + 41 \]
Step 6: Collecting the numbers:
\[ g(a) = 9a - 4 \]
Step 7: The letter used for the input does not change the rule, so a can be written as x:
\[ g(x) = 9x - 4 \]
Both methods agree. As a check, \( g(f(x)) = 9(2x + 5) - 4 = 18x + 45 - 4 = 18x + 41 \), which is the composite we were given.
Composite Functions at a Glance
The table below gathers the four composites that can be made from one pair of functions, using \( f(x) = 3x \) and \( g(x) = 2x + 1 \). Read each row from right to left to see which function works first.
| Written as | Meaning | Acts first | With f(x) = 3x, g(x) = 2x + 1 |
| \( gf(x) \) or \( gof(x) \) | \( g(f(x)) \) | f | \( 6x + 1 \) |
| \( fg(x) \) or \( fog(x) \) | \( f(g(x)) \) | g | \( 6x + 3 \) |
| \( ff(x) \) or \( fof(x) \) | \( f(f(x)) \) | f, twice | \( 9x \) |
| \( gg(x) \) or \( gog(x) \) | \( g(g(x)) \) | g, twice | \( 4x + 3 \) |
Every composite question comes down to the same two moves: decide which function acts first by looking at the letter next to x, then put the first function's answer into the second function.
The full lesson is waiting for you
The notes are free to read in full. A free account opens the rest of the practice, and tracks your progress and confidence score for every subject. Presentations and videos need approval from Learn Yeti.