## Piecewise Functions

Suppose $f(x)$ and $g(x)$ are functions $\mathbb{R}\to \mathbb{R}$, and consider the piecewise function

$p(x)=\begin{cases} f(x) & x<0 \\ g(x) & x>0 \end{cases}.$

For no particularly good reason, today I went in search of another way to write this expression. I wasn’t sure exactly what sort of expression I was shooting for, but I hoped I’d know it when I saw it.

I’m want to try to avoid explicitly writing a piecewise function, and somehow use $|x|$ to disguise the piecewise nature of the function. This can be further obfuscated by writing it as $\sqrt{x^2}$, but I’ll leave it as $|x|$. Actually, a function I think might be more useful is $|x|/x$, a favorite from calculus classes. Recall that this is 1 for $x$ positive, and -1 for $x$ negative. Conveniently, the domains of the pieces here are exactly the domains of the pieces I want for $p(x)$.

My first step actually makes $p(x)$ looks worse:

$p(x)=\frac{f(x)+g(x)}{2}+\begin{cases} \frac{-g(x)+f(x)}{2} & x<0 \\ \frac{g(x)-f(x)}{2} & x>0 \end{cases}$

However, let me write $a(x)=(f(x)+g(x))/2$ and $d(x)=(f(x)-g(x))/2$. Then notice that the pieces in the above line are exactly $d(x)$ or $-d(x)$. That is,

$p(x)=\begin{cases} a(x)+d(x) & x<0 \\ a(x)-d(x) & x>0 \end{cases}$

I can wrap this up using my $|x|/x$ from above to get that sign distinction, arriving at

$p(x)=a(x)-\frac{|x|}{x}d(x).$

That’s a reasonable answer I suppose. I’ve written my piecewise function all on one line, I guess, as

$p(x)=(f(x)+g(x)-\frac{|x|}{x}(f(x)-g(x)))/2.$

With this, I could then shift things horizontally and assume that my pieces where defined on $(-\infty,a)$ and $(a,\infty)$, instead of just splitting at 0. I could also, sort of inductively, get a piecewise function with more than 2 pieces. To do this, just split it into a leftmost non-piecewise function, and then a right-hand piecewise function, and use the ideas above.

I don’t think that this is the answer that makes me the happiest though. But it’s the only idea I’ve got currently. The reason I don’t like this is that $f(x)$ and $g(x)$ need to be defined on all of $\mathbb{R}$, even though in the original piecewise function they need only be defined on half the line. Also, I’m not sure I’m a huge fan of the handling of more than 2 pieces with the above method.

So, what suggestions have you got for improvement?