# Piecewise Composite Functions and Surjective/Injective

I understand how to work out a composite function when it is just one function but have no clue when it comes to piecewise composite functions like follows:

$$f(x) = \begin{cases} x-1, & \ x\ge0 \\ x^3, & \ x < 0 \end{cases}$$

$$g(x) = \begin{cases} x+1, & \ x\ge0 \\ 2x, & \ x < 0 \end{cases}$$

How would I go about working out $f \circ g$ and $g \circ f$?

Also, how can I tell if a piece wise function is surjective or injective? By graphing both of them I have worked out (if I am correct) that $f(x)$ is not injective as $f(0) = f(-1)$ and $g(x)$ is injective.

• Graphing is a good way to do this kind of problem - go ahead and graph the composite functions too. In general, if $f$ isn't injective then $g \circ f$ can't be. – Ethan Bolker Mar 21 '17 at 13:52

You are correct that $f$ is not injective and that $g$ is injective.

The graph of $f$ is shown below.

The function assumes all negative values in the interval $(-\infty, 0)$ and all values greater than or equal to $-1$ in the interval $[0, \infty)$. Consequently, it assumes every real value, so it is surjective.

The graph of $g$ is shown below. Since the function $g$ assumes all values greater than or equal to $1$ in the interval $[0, \infty)$ and all negative values in the interval $(-\infty, 0)$, it never assumes the values in the interval $[0, 1)$, so $g$ is not surjective.

Let's find $f \circ g$. By definition, $(f \circ g)(x) = f(g(x))$. Since the rule for $f$ is determined by whether the value substituted into the function is nonnegative or negative, we have to determine whether $g(x)$ is nonnegative or negative in order to determine which rule to apply.

If $x \geq 0$, $g(x) = x + 1 \geq 1$, so we are applying $f$ to positive values. Hence, we apply the rule $f(x) = x - 1$ to $g(x) = x + 1$. Thus, if $x \geq 0$, \begin{align*} (f \circ g)(x) & = f(g(x))\\ & = f(x + 1)\\ & = x + 1 - 1\\ & = x \end{align*} If $x < 0$, then $g(x) = 2x < 0$, so we are applying $f$ to negative values. Hence, we apply the rule $f(x) = x^3$ to $g(x) = 2x$. Thus, if $x < 0$,
\begin{align*} (f \circ g)(x) & = f(g(x))\\ & = f(2x)\\ & = (2x)^3\\ & = 8x^3 \end{align*} Hence, $$(f \circ g)(x) = \begin{cases} x & \text{if x \geq 0}\\ 8x^3 & \text{if x < 0} \end{cases}$$

The graph of the composite function $f \circ g$ is shown below.

From the graph, we see that $f \circ g$ assumes every real value precisely once. Hence, $f \circ g$ is both injective and surjective.

I will leave finding $g \circ f$ to you. Be careful. Notice that $f$ changes sign at $x = 1$. Thus, you will need to consider three intervals, $[1, \infty)$, $[0, 1)$, and $(-\infty, 0)$. As @EthanBolker suggested in the comments, drawing the graph of the composite function is helpful in determining whether it is injective or surjective.