1
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ What is your criterion for simplicity? $\endgroup$
    – Rob Arthan
    Aug 25, 2016 at 23:01
  • $\begingroup$ 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). $$ $\endgroup$ Dec 8, 2016 at 1:47

2 Answers 2

1
$\begingroup$

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 $$

$\endgroup$
2
  • $\begingroup$ It is an elementary function, by definition. A synonym for elementary is simple. $\endgroup$
    – David P
    Dec 7, 2016 at 5:33
  • 1
    $\begingroup$ I'm not sure I agree that arctan is not simple. However I've posted an alternative. $\endgroup$
    – David P
    Dec 8, 2016 at 1:28
0
$\begingroup$

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$."

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .