[Math] How to rewrite a piecewise function in terms of the Heaviside function

functions

Let's say I have a piecewise function:

$$f(x) = \begin{cases}x ,& 0 \leq x \leq 1 \\1 ,& 1 \leq x\end{cases}$$

How can I rewrite this in terms of the Heaviside function $u(x-a)$?

Best Answer

I gave a good rundown of a mechanical method here. The main idea is to change everything to Iverson brackets before finally switching to the unit step function, since there is the relationship

$$[x\geq a]=[x-a\geq0]=\begin{cases}1&\text{if }x-a\geq0\\0&\text{if }x-a<0\end{cases}=u(x-a)$$

With

$$f(x) = \begin{cases} x & 0 \leq x < 1 \\ 1 & 1 \leq x \end{cases}$$

(and assuming that the function is zero in all other cases), translation to the Iverson convention is easy:

$$f(x)=x[0 \leq x < 1]+[1 \leq x]$$

and we can then do some massaging:

$$\begin{align*} f(x)&=x[0 \leq x < 1]+[1\leq x]\\ &=x[x \geq 0][x < 1]+[x-1 \geq 0]\\ &=x[x \geq 0][\lnot(x \geq 1)]+[x-1 \geq 0]\\ &=x[x \geq 0](1-[x \geq 1])+[x-1 \geq 0]\\ &=x[x \geq 0](1-[x-1 \geq 0])+[x-1 \geq 0]\\ &=x[x \geq 0]-x[x \geq 0][x-1 \geq 0]+[x-1 \geq 0]\\ &=x\,u(x)-x\,u(x)u(x-1)+u(x-1)\\ \end{align*}$$

where the properties $[p\text{ and }q]=[p][q]$ and $[\lnot p]=1-[p]$ of the Iverson bracket were useful.

One can do a further simplification, since $u(x)u(x-1)=[(x \geq 0)\text{ and }(x \geq 1)]=[x \geq 1]=u(x-1)$. We then finally have

$$f(x)=x\,u(x)-x\,u(x-1)+u(x-1)=x\,u(x)+(1-x)u(x-1)$$

Related Question