Skip to main content
Mathematics LibreTexts

4.3 Compositions of Functions

  • Page ID
    153653
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)
    Learning Objectives

    By the end of this section, you will be able to:

    • produce new functions from other functions via addition, subtraction, multiplication, and division
    • produce new functions by composing other functions
    • decompose functions into constituent parts

    They say there's no such thing as one cockroach, and the same is true of functions (ew). What I'm saying is, as soon as you have a couple o' functions, they can produce more just by combining them in different ways. These are the basic ones, real quick...

    Given two functions, \(f\) and \(g\), you can make:

    • their sum, a new function named "\(f+g\)," defined by \( (f+g)(x) = f(x) + g(x) \).
    • their difference, a new function named "\( f-g \)," defined by \( (f-g)(x) = f(x) - g(x) \). (ALERT: subtract the WHOLE function \(g\), using parentheses!)
    • their product, a new function named "\( fg\)," defined by \( (fg)(x) = f(x)g(x) \). (ALERT: if the functions have multiple terms, this would require expanding! Again, use parentheses!)
    • their quotient, a new function named "\( \frac{f}{g} \)," defined by \( \left( \frac{f}{g} \right) (x) = \dfrac{ f(x)}{g(x)} \). (ALERT: any \(x\) such that \(g(x) = 0\) is not allowed in the domain of this new function!)

    These functions are defined on domains where both \(f\) and \(g\) are defined, so we say the domain is the intersection of the domains of \(f\) and \(g\). The domain of the quotient of the functions is further restricted because you can't divide by zero.

    Example \(\PageIndex{1}\)

    For \(f(x) = x^2 \) and \(g(x) = \frac{1}{x-1} \), find the functions and tell their domains.

    1. \( (f+g)(x) \)
    2. \( (fg)(x) \)
    3. \( \left( \frac{g}{f} \right)(x) \)
    Solution
    1. \( (f+g)(x) = f(x) + g(x) = (x^2) + \left( \frac{1}{x-1} \right) = x^2 + \frac{1}{x-1} \). This function's domain is \(\{ x \: | \: x \neq 1 \} \).
    2. \( (fg)(x) = f(x)g(x) = (x^2) \left( \frac{1}{x-1} \right) = \frac{x^2}{x-1} \). This function's domain is \(\{ x \: | \: x \neq 1 \} \).
    3. \( \left( \frac{g}{f} \right)(x) = \dfrac{ g(x)}{f(x)} = \dfrac{ \frac{1}{x-1}}{x^2} = \dfrac{1}{x^2(x-1)} \). This function's domain is \(\{ x \: | \: x \neq 0, 1 \} \).
    Exercise \(\PageIndex{1}\)

    For \( f(x) = \sqrt{x}\) and \( g(x) = x+2 \), find the functions and tell their domains.

    1. \( (f+g)(x) \)
    2. \( (f-g)(x) \)
    3. \( (fg)(x) \)
    4. \( \left( \frac{f}{g} \right)(x) \)
    Answer
    1. \( (f+g)(x) = \sqrt{x} + x + 2 \). Domain: \( x \geq 0 \).
    2. \( (f-g)(x) = \sqrt{x} -x - 2 \). Domain: \( x \geq 0 \).
    3. \( (fg)(x) = \sqrt{x}(x+2) = x\sqrt{x} + 2 \sqrt{x} \). Domain: \( x \geq 0 \).
    4. \( \left( \frac{f}{g} \right)(x) = \dfrac{ \sqrt{x}}{x+2} \). Domain: \( x \geq 0 \). (The problematic \(x = -2\) is a non-issue because we're already not allowing negative numbers.)

    Compositions of Functions

    Recall that way of thinking of functions as maps from one set of elements to another. Let's say I have a function \( f\) with domain \(A\) mapping to a set \(B\) where his outputs live. Then say that the set \(B\) is in fact the set of inputs for another function, \(g\), who maps to yet another set \( C\). Then I could chain up these two functions, first following \(f\) and then following \(g\), to find a way of assigning an output from \(C\) to each input in \(A\). Aka, defining a new function. This daisychain function is called the composition of \(g\) and \(f\), and denoted \( g \circ f \).

    composition.png

    If you prefer the machine analogy, it's this process:

    comp.png

    Composing a function \(g\) with another function \(f\) results in the composite function, \( g \circ f\), defined by \((g\circ f)(x) = g( f(x)) \). This function is defined for \(x\) values where both \( f(x)\) and \(g(f(x))\) are defined.

    You can compose two functions in either order to get new functions, and you can even compose a function with himself...and then compose that with himself again... The sky is the limit.

    Example \(\PageIndex{2}\)

    Given \( f(x) = x^2\) and \(g(x) = \frac{1}{x-1}\), find the functions and their domains.

    1. \( (g \circ f)(x) \)
    2. \( (f \circ g) (x) \)
    3. \( (f \circ f)(x) \)
    4. \( (g \circ f \circ f )(x) \)
    Solution

    1. We know that \( (g \circ f)(x) = g(f(x)) \). We are going to work from the inside outward just applying the definitions of these functions. We replace \( f(x)\) with his definition first. Then we treat him as the input that we plug into the definition of \(g\).

    \[ (g \circ f)(x) = g(\textcolor{red}{f(x)}) = g(\textcolor{red}{ x^2}) = \frac{1}{(x^2)-1} = \frac{1}{x^2 - 1} \notag \]

    The domain of this function is all real numbers but \(x \neq \pm 1 \).

    2. We repeat the same process, just being careful with who goes where. You will see that the final answer is NOT the same as the previous one! With composition, order matters!

    \[ (f \circ g) (x) = f(g(x)) = f\left( \frac{1}{x-1} \right) = \left( \frac{1}{x-1} \right)^2 \notag \]

    The domain of this function is all real numbers but \(x \neq 1\).

    3. This time, we are composing \(f\) with another copy of itself.

    \[ (f \circ f)(x) = f(f(x)) = f( x^2) = (x^2)^2 = x^4 \notag \]

    The domain is \( \mathbb{R}\).

    4. You can compose more than just two things. First, convince yourself that \( (g \circ f \circ f)(x) = g(\textcolor{red}{f(}\textcolor{blue}{f(x)}\textcolor{red}{)}) \). Then work from the inside outward.

    \[ g(\textcolor{red}{f(}\textcolor{blue}{f(x)}\textcolor{red}{)}) = g(\textcolor{red}{f(}\textcolor{blue}{x^2}\textcolor{red}{)}) = g( \textcolor{red}{(x^2)^2}) = g(x^4) = \frac{1}{x^4 - 1} \notag \]

    The domain is all real numbers but \(x \neq \pm 1\).

    Exercise \(\PageIndex{2}\)

    For \( f(x) = \sqrt{x}\) and \( g(x) = x+2 \), find the functions and tell their domains.

    1. \( (g \circ f)(x) \)
    2. \( (f \circ g) (x) \)
    3. \( (f \circ f)(x) \)
    4. \( (g \circ f \circ f )(x) \)
    Answer
    1. \( (g \circ f)(x) = \sqrt{x}+2\). Domain: \( x \geq 0\).
    2. \( (f \circ g)(x) = \sqrt{x+2} \). Domain: \( x \geq -2 \).
    3. \( (f \circ f)(x) = \sqrt{ \sqrt{x}} = \sqrt[4]{x} \). (Recall that you can write these roots as \( (x^{1/2})^{1/2} \) and simplify with power rules.) Domain: \( x \geq 0\).
    4. \( (g \circ f \circ f)(x) = \sqrt[4]{x}+2 \). Domain: \( x \geq 0 \).

    Decomposing Functions

    It's also important for our critical thinking and function intuition skills to be able to identify what constituents could have been composed to produce a complicated function. As always, I try to only make you learn things that are going to actually serve you later in math. This decomposing skill, like the basic skill of understanding the order of operations in a function, will come in handy when you do something called chain rule and u-substitution in various Calculuses. Tbh, though, this is no biggie if you just remember how to describe operations in English.

    Example \(\PageIndex{3}\)

    Identify two functions \(f\) and \(g\) such that \(h = f \circ g\).

    1. \( h(x) = \sqrt{x+1} \)
    2. \( h(x) = (x-2)^2 + x - 2 \)
    3. \( h(x) = (x^2 + 3x + 1)^3 \)
    4. \( h(x) = | x - 1 | \)
    5. \( h(x) = \sqrt{1 + \sqrt{x}} \)
    Solution

    1. A good place to start is to ask myself what happened over the course of this function? Looks like an input was added to 1, and then the square root was taken. Hone in on the "and then" in that sentence. That's a great place to split up the action. If I take \(g(x) = x+1 \), the function "add 1 to something," and \( f(x) = \sqrt{x}\), the function "take the square root of something," then the composition is

    \[ (f \circ g)(x) = f(g(x)) = f(x+1) = \sqrt{x+1} \quad = h(x) \quad \checkmark \notag \]

    2. In this one, I notice something interesting going on: \(h(x) = (x-2)^2 + (x-2) \). It kinda looks like the action "subtract 2 from something" has been inserted into another action, "square something and add it to itself." If I take \( g(x) = x-2\) and \(f(x) = x^2 + x \), then the composition is

    \[ (f \circ g)(x) = f(g(x)) = f( x-2) = (x-2)^2 + (x-2) \quad = h(x) \quad \checkmark \notag \]

    3. Here, the process is "plug an input into a certain quadratic polynomial, and then cube the whole thing." I take \(g(x)\) to be the part before the "and then," so \(g(x) = x^2 + 3x + 1 \). Then I take the second step for \(f\), getting \(f(x) = x^3\). Then the composition is

    \[ (f \circ g)(x) = f(g(x)) = f(x^2 + 3x + 1) = (x^2 + 3x + 1)^3 \quad = h(x) \quad \checkmark \notag \]

    4. The process is, "subtract 1 from the input, and then take the absolute value of the result." We use \( g(x) = x - 1 \) and \( f(x) = |x| \). Then the composition is

    \[ (f \circ g)(x) = f(g(x)) = f( x-1) = |x-1| \quad = h(x) \quad \checkmark \notag \]

    5. Sometimes you actually have a few choices on which pairs of functions to choose. I describe this process, "Take the square root, then add 1, then take the square root again." I could break up my functions at either "then" in the sentence. One option is to have \( g(x) = 1+\sqrt{x} \) and then \(f(x) = \sqrt{x}\). Check this composition to make sure it matches \(h(x)\). Another option is to have \( g(x) = \sqrt{x}\) and \( f(x) = \sqrt{1+x} \). Check this one too to confirm!

    Exercise \(\PageIndex{3}\)

    Identify two functions \(f\) and \(g\) such that \(h = f \circ g\).

    1. \( h(x) = 2x + 1 \)
    2. \( h(x) = (x+2)^2 - 3 \)
    3. \( h(x) = \dfrac{1}{1+\sqrt{x}} \)
    4. \( h(x) = \sqrt{ 1 - x^2} \)
    Answer

    YMMV, but these are some options:

    1. \( g(x) = 2x, f(x) = x+1 \)
    2. \( g(x) = x+2, f(x) = x^2 - 3 \)
    3. \( g(x) = \sqrt{x}, f(x) = \dfrac{1}{1+x} \)
    4. \( g(x) = 1- x^2, f(x) = \sqrt{x} \)

    Now be sure to go over the exercises section carefully, because we'll see some real-life applications of the composition of functions in there!

    * (Minecraft hopper image from Minecraft Wiki)


    This page titled 4.3 Compositions of Functions is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Lydia de Wolf.

    • Was this article helpful?