# Finding the domain and range of a difficult piecewise composite function

I recently inquired about finding a formula for a composition of two piecewise functions, but I have been thoroughly confused by a slightly different example. In this case, I have a question about finding the domain and range for a piecewise composite function. The functions are defined as follows:

$$f(x) = \begin{cases} 1-x, & \text{if x \le 0} \\ x^{2}, & \text{if x > 0} \end{cases}$$

$$g(x) = \begin{cases} -x, & \text{if x < 1} \\ x+1, & \text{if x \ge 1} \end{cases}$$

Specifically, my question regards how I should find the domain and range of the composite function $f(g(x))$.

My attempts at the problem:

From my gathered understanding of this type of question (credit goes to @tilper and @lulu for this lucid methodology), I should proceed with the idea that $$f(g(x)) = \begin{cases} 1-g(x), & \text{if g(x) \le 0} \\ (g(x))^{2}, & \text{if g(x) > 0} \end{cases}.$$ Thus, we ascertain when $g(x) \le 0$ and when $g(x) > 0$. For the piece $-x$ of the original $g(x)$ function, we determine that $-x \le 0$ $\implies$ $x \ge 0$. In addition, we determine that $-x > 0$ $\implies$ $x < 0$. However, the condition must be met that x <1, so $g(x)$ is never $\le 0$ on this piece. However, it seems that $g(x) > 0$ on this piece when $x < 0$ $< 1$. Thus, we have established that $g(x) > 0$ when $x < 0$.

On the next piece of $g(x)$, which is $x + 1$, we again determine when $g(x)$ is $\le 0$ and/or $> 0$. $x+1 \le 0$ $\implies$ $x \le -1$, but for this piece the condition must be met that $x \ge 1$, so clearly $g(x)$ is never $\le 0$ on this piece. Next, $x + 1 > 0$ $\implies$ $x > -1$, which eventually satisfies the condition of $x \ge 1$. What do I do about the values for $-1 < x <1$ where this condition is not satisfied? I am absolutely stumped as to how to proceed with this problem and, once I determine the composition, how to find the domain and range of that new composition.

Many thanks to those of you who could see through my rambling.

The best is to draw a table in which the expressions of $g(x)$ and theirs signs are given explicitly: $$\begin{array}{r|p{1.5cm}cp{1.5cm}cp{1.5cm}|} x&&0&&1&\\ \hline g(x)=&-x&0&-x&2&x+1\\ \hline \operatorname{sgn}g(x)& +&|& -&|&+\\ \hline f(g(x))&g(x)^2=x^2&1& \begin{matrix}1-g(x)\\=x+1\end{matrix}&4& (x+1)^2\\ \hline \end{array}$$ From this table, we conclude at once the range of $f\circ g$ is $\mathbf R_+^{*}$.
Not sure if it helps. Let $g$ be any function. Define $f\circ g$ by $$f(g(x)) =\begin{cases} 1-g(x) & \text{ if } g(x)\leq 0 \\ (g(x))^{2} & \text{ if } g(x)>0. \end{cases}$$ Now let $g$ be the function satisfying on your post. We will check $x<1$ and $x\geq 1$ seperately. If $x<1$, then $f(g(x))=1-(-x)=1+x$ for all $1>x\geq 0$; $f(g(x))=(-x)^2=x^2$ for all $x<0\,(<1)$. If $x\geq 1$, then $f(g(x))$ doesn't make sense on the first case; $f(g(x))=(x+1)^2$ for all $x\geq 1\,(>-1)$. Altogether, you have $$f(g(x)) =\begin{cases} x^2 & \text{ if } x<0\\ 1+x & \text{ if } 0\leq x<1 \\ (1+x)^2 & \text{ if } 1\leq x. \end{cases}$$