# Step function without piece wise definition

Usually I would think of a step function in terms of a piece wise definition:

$$U(x) = \begin{cases} 1 & x \ge a\\ 0 & x < a\end{cases}$$

Can I write it in a way that does not require a piece wise definition or logic statements? For example, you could write the absolute value function in a way that does not require conditional statements by defining $|x| = \sqrt{x^2}$. Similarly, you can get the min or max of two numbers without using logic operations by following: How to calculate Maximum or Minimum of two numbers without using if? I'm looking for the same idea but for the step function. Wikipedia has some continuous approximations, and also alternative definitions like the integral of a Dirac delta function: https://en.wikipedia.org/wiki/Heaviside_step_function, but I'm wondering if there is anything simpler?

• What is your criterion for simplicity? – Rob Arthan Aug 25 '16 at 23:01
• @RobArthan I would imagine something convenient to use. – The Great Duck Dec 2 '16 at 22:45
• If you do not care about the value at $x = 0$, then you can simply use the expression $$\frac{1}{2}(1 + \operatorname{sign}(x)) = \frac{1}{2}\left(1 + \frac{x}{\sqrt{x^2}} \right).$$ – Sangchul Lee Dec 8 '16 at 1:47

## 3 Answers

If you are ok with using derivatives, you can write $$U_a(x) = \frac{1}{2}+\frac{1}{2}\frac{d}{dx}|x-a|,$$ and, as you noted, $|x-a| = \sqrt{(x-a)^2}$. Of course, this fails to be defined at $x=a$, so is not quite the same as your "$U_a(x) = 1 \text{ if } x\geq a$."

• If it is not quite the same, then you should delete your answer or find a logical way to express it fully. – The Great Duck Dec 4 '16 at 22:53

Modification of my answer here:

$$U_a(x)=\left\lfloor4\dfrac{\tan^{-1}(x+1-a)+\pi}{5\pi}\right\rfloor$$

edit: Here's another

$$U'_a(x)=\left\lfloor \dfrac{2^{x-a}-2^{-x+a}}{2^{x-a}+2^{-x+a}}+1\right\rfloor$$

• I wouldn't really consider arctan to be a simple function... Perhaps you could try to get rid of arctan to make it more convenient? – The Great Duck Dec 4 '16 at 22:55
• It is an elementary function, by definition. A synonym for elementary is simple. – David Peterson Dec 7 '16 at 5:33
• arctan is by no means a simple function to deal with in my opinion. elementary just means that the function results from precalculus rather than resulting from integrals/sums having no closed form. – The Great Duck Dec 7 '16 at 6:10
• I'm not sure I agree that arctan is not simple. However I've posted an alternative. – David Peterson Dec 8 '16 at 1:28

This is a simple form that be expressed as the following:

$$U(X) = \left\lfloor \frac {x-a}{\sqrt{(x-a)^2 +1}} \right\rfloor + 1$$

It is easy enough to see why if you know the graph of $\frac{x}{\sqrt{x^2 + 1}}$ and you know how to apply a translation to a function.