Constructing a smooth function with derivative constraints I am looking to construct a smooth ($C^\infty$) function, $g$ such that $g'(x) = -1$ for $x \le -1$ and $g'(x) =1$ for $x \ge 1$.
I am thinking of setting $g(x) = -x$ for $x \le -1$ and $g(x) = x$ for $x \ge -1$ however I can't think what to use for $-1 < x < 1$. 
I have thought about using cos but obviously it needs to "match" the tails at $0$ at $x = 1$ and $-1$ for derivatives greater than and including the 2nd,  so this didn't work.
Any help would be appreciated, thanks.
 A: Set $\psi$ to be the "standard bump function" as in Wikipedia $$\psi(x) = \begin{cases} \exp\Big(-\frac1{1-x^2}\Big) & x\in (-1,1), \\ 0 & x \notin (-1,1).\end{cases} $$
This function is probably the classic example of a $C^\infty$ function with compact support$^1$. One writes $\psi \in C^\infty_c$. The support is clearly $[-1,1]$, and the proof of the smoothness is written out in this other Wikipedia page.
Its easy to see directly using $0≤ \psi \le 1$ that $0<\int_{-1}^1\psi < 2.$ (For the upper bound, note that either $\phi(x) = 0$, or $\psi(x) = e^{-\left[\substack{\tiny \text{something}\\\tiny\text{positive}}\right]} \le e^0 = 1.)$Set $\phi = \frac{\psi}{\int_{-1}^1 \psi}$. Then $\int\phi = 1$, so we can set
$$ g(x) = \int_0^x \left( -1 + \int_{-1}^{x_1} 2\phi (x_2) dx_2 \right )dx_1. $$
Here is a graph of all these functions(with slightly different names). You can make it run yourself here but I had to hard-code some parts using a piecewise definition to make Desmos compile in a reasonable time.

There is a different more general construction using smooth cut-off functions.

$^1$: the support of a function $f:A\to B$ is the closed set $$\operatorname{supp} f :=\overline{\{ x \in A : f(x) \neq 0 \}}.$$
