# Composition $\left(f \circ g, g \circ f \right)$ of piecewise functions

I'm trying to solve this problem from my homework a few hours now, I know how to do composition for regular functions, but can't seem to understand the composition of piecewise functions.

I have checked other solutions here, but didn't get it.

Here is the problem: $$f(x) = \begin{cases} x+1, & \text{if x<0} \\ 3x+4, & \text{if x\ge0} \end{cases}$$ $$g(x) = \begin{cases} 3x+2, & \text{if x<3} \\ 5x-8, & \text{if x\ge3} \end{cases}$$ find $f(g(x))$ and $g(f(x))$? thanks :)

• – Rohan Dec 29 '17 at 8:33
• @Rohan thank you, i've tried to figure out this general method but didn't quite make it. – John Dekker Dec 29 '17 at 10:24

Here is step-by-step hints to do it:

1. For the composition of $f(g(x))$, focus on $g(x)$ first, it has a range of $\mathbb R$ and since $f(x)$ has a domain of $\mathbb R$ too, everything is well.
2. You see that $f(x)$ is a piecewise function with two parts for $x<0$ and $x\ge0$, so you need to solve these inequalities by substituting x with $g(x)$. Now you realize that the composite function has four pieces, with domains determined by solving: $$\begin{cases} 3x+2<0\\ x<3 \end{cases}$$ $$\begin{cases} 3x+2\ge0\\ x<3 \end{cases}$$ $$\begin{cases} 5x-8<0\\ x\ge3 \end{cases}$$ $$\begin{cases} 5x-8\ge0\\ x\ge3 \end{cases}$$
3. Finally, put each piece of $g(x)$ into $f(x)$, simplify the expression, and write down the domains that you just found in step 2 for each piece. $$f(g(x))= \begin{cases} (3x+2)+1, \ ...\\ 3(3x+2)+4, \ ...\\ (5x-8)+1, \ ...\\ 3(5x-8)+4, \ ...\\ \end{cases}$$

Then you have it! In the same way you can find $g(f(x))$ without much effort.

• thank you for your quick and detailed answer, just one thing that I didn't understand is why in step 2 we check x<3 for 4 times? – John Dekker Dec 29 '17 at 10:19
• Oh sorry, typo... How careless I am! Will edit that... – Macrophage Dec 29 '17 at 10:24
• thank you very much, I think i solved it. – John Dekker Dec 29 '17 at 10:27
• No problem. It would be great if you manually accept my answer on this page. So short on reputation now :P – Macrophage Dec 29 '17 at 10:30
• Upvote from me! (also upvoted some other things) It is hard to start with not much reputation. – user370967 Dec 29 '17 at 10:40