1
$\begingroup$

$x = 0$, $f(x) = 0$

$x = 1$, $f(x) = 1$

$x = 2$, $f(x) = 1$

$x = 3$, $f(x) = 1$

...

There have been so many times I could have used this at different programming problems but I always resorted to logical expressions. I feel that there should be a more elegant, purely mathematical, solution.

  • 9
    Your description in the title is perfectly mathematical. There is nothing non-mathematical about "f(x) = 0 if x = 0, and f(x) = 1 for x > 0". If you want you can use Iverson notation and write it as $f(x) = [x>0]$, or as an indicator variable $f(x) = 1_{\{x > 0\}}$, but ultimately they're all ways of saying the same thing. (Questions like this have come up before multiple times on this site; maybe someone can find the duplicates.)2012-05-30
  • 2
    See [sign function](http://en.wikipedia.org/wiki/Sign_function) at Wikipedia.2012-05-30
  • 5
    Your description even has a name: [Heaviside step function](http://en.wikipedia.org/wiki/Heaviside_step_function), though you're actually describing $H(n-1)$.2012-05-30
  • 1
    In C you can just write `(x>0)` since Boolean values are actually the numeric values 0 and 1.2012-05-30
  • 2
    Yes Davis here has written a mathematical function here. However, oftentimes people think "function" means "formula" as in an equation (I think historians of mathematics believe that many respected authors thought of functions this way also... including Euler). So, Davis probably wants a formula like those referenced by lhf.2012-05-30

2 Answers 2