(where we used $[p\text{ and }q]=[p][q]$), or
$$f(x)(1-[x-a\geq 0])+g(x)[x-a\geq 0](1-[x-b\geq 0])+h(x)[x-b\geq 0]$$
which can be simplified like so:
$$f(x)+(g(x)-f(x))[x-a\geq 0]-g(x)[x-a\geq 0][x-b\geq 0]+h(x)[x-b\geq 0]$$
and since $[x-a\geq 0][x-b\geq 0]=[x-b\geq 0]$ for $a \leq b$, we finally have the expression
$$f(x)+(g(x)-f(x))[x-a\geq 0]+(h(x)-g(x))[x-b\geq 0]$$
The extension to more than three pieces is straightforward.
We can apply all this to the function
$$f(x)=\begin{cases}7&\text{if }|x|\geq 10\\x^2&\text{if }|x|<10\end{cases}$$
which can also be expressed as
$$\begin{cases}7&\text{if }x\leq -10\\x^2&\text{if }-10 < x < 10\\7&\text{if }10\leq x\end{cases}$$
Applying the results of the previous section (for now being sloppy with the values at the points of discontinuity), we have
$$f(x)=7+(x^2-7)[x+10\geq 0]+(7-x^2)[x-10\geq 0]$$
(If you are really careful with putting in the Iverson brackets, and carefully pay attention to values at the joining points, the expression required is actually $x^2+(7-x^2)([x-10\geq 0]+[-x-10\geq 0])$, whose derivation I leave as an exercise (a matter of choosing whether to use $[x\geq 0]$ or $[x > 0]=1-[-x \geq 0]$). The sloppiness does not matter so much if the "pieces" mutually agree at the breakpoints, however.)
If you're working in an environment like C/++ where Iverson brackets are implicitly supported (TRUE
is 1
and FALSE
is 0
), then you should be content and happy with Iverson bracket expressions. If not, the unit step function implicit in the previous expression can be "replaced" (ignoring for the moment the case when $x=0$) like so:
$$[x\geq 0]=\frac{x+|x|}{2x}$$
Sometimes, the problem at the points of discontinuity resolves itself after simplification of the expression, post-substitution. Sometimes, it doesn't. Therefore, when replacing your Iverson brackets/unit step functions (or even in the construction proper), you always must be careful to check that your function behaves as it's supposed to behave at the joining points.