Addition of two piecewise function Suppose I have function 

$$y(x)=\begin{cases}
 x+1\qquad & 0\leq x\leq1 \\
 2-x\qquad &  1<x \leq2 \\
0\qquad & \mathrm{elsewhere}
\end{cases}$$
  I need to find the function $g(x)=y(x+2)+2y(x+1)$


$$y(x+2)=\begin{cases}
 x+3\qquad &-2\leq x\leq-1 \\
 -x\qquad &  -1<x \leq0 \\
0\qquad &\mathrm{elsewhere}
\end{cases}$$
$$2y(x+1)=\begin{cases}
 2x+4\qquad & -1\leq x\leq0\\
 2-2x\qquad &  0<x \leq1 \\
0\qquad &\mathrm{elsewhere}
\end{cases}$$
Now,
$$g(x)=y(x+2)+2y(x+1)=\begin{cases}
 x+3\qquad & -2\leq x\leq -1 \\
 x+4\qquad &  -1<x \leq0 \\
2-2x\qquad &0<x\leq1\\
0\qquad &\mathrm{elsewhere}
\end{cases}$$
Now the result looks Okay,
But the problem is the value of $y(x+2)$ at $x=-1$ is $2$ and $2y(x+2)$ at $x=-1$ is also $2$ so if I add both then $y(x+2)+2y(x+1)$ at $x=-1$ will be $2+2=4$,but the value of $g(x)$ at $x=-1$ is $-1+3=2$ 
 A: In your calculation of $g(x)$, the first line, $x+3$, was obtained by adding $y(x+2)=x+3$ and $2y(x+1)=0$.  The first of these two equations, $y(x+2)=x+3$, is valid for $x$ in the range $-2\leq x\leq-1$. The second, $2y(x+1)=0$, is valid when $x<-1$ and also when $x>1$. In particular, it is not valid when $x=-1$.  So the $x+3$ line in your formula for $g(x)$ is not valid for $x=-1$ but only for $-2\leq x<-1$.  
More generally, when you combine several formulas, each f which is valid for a certain range of $x$ values, then the combination will in general only be valid for those $x$ values that are in all the relevant ranges simultaneously.  
A: \begin{eqnarray}
g_1(x)=y(x+2)=\begin{cases}
x+3&\text{ for }-2\le x\le -1\\
-x&\text{ for }-1< x\le0\\
0&\text{ otherwise}
\end{cases}
\end{eqnarray}
and
\begin{eqnarray}
g_2(x)=2y(x+1)=\begin{cases}
2x+4&\text{ for }-1\le x\le0\\
2-2x&\text{ for }0< x\le1\\
0&\text{ otherwise}
\end{cases}
\end{eqnarray}
Giving the result
\begin{eqnarray}
g(x)=\begin{cases}
x+3&\text{ for }-2\le x<-1\\
3x+7&\text{ for }x=-1\\
x+4&\text{ for }-1< x\le0\\
2-2x&\text{ for }0< x\le1\\
0&\text{ otherwise }
\end{cases}
\end{eqnarray}
Now we see that $g_1(-1)=2,\,g_2(-1)=2$ and $g(-1)=4$.
