5
$\begingroup$

First I apologize in advance for I don't know math's English at all and I haven't done math in almost a decade.

I'm looking for a function whose "domain/ensemble of definition" would be ℝ (or maybe ℤ) and whose "ensemble/domain of variation" would be ℕ{0, 1} that would look like something this awesome ascii graph...

          ^f(x)           |                     | 1________ | __________ 0________\./__________>x          0|           |           |           | 

f(x) is always 1, but 0 when x = 0

Actually I need this for programming, I could always find other ways to do what I wanted with booleans so far but it would be much better in most cases to have a simple algebra formula to represent my needs instead.

I just hope it's not too complicated a function to write/understand and that it exists of course. Thanks in advance guys.

4 Answers 4

1

I think that the most compact way to write this is using the Iverson Bracket:

$f: \mathbb{R} \to \{{0,1}\}$

$ f(x) = [x \neq 0]$

  • 0
    This one is pretty straightforward since it's only a redefinition.2012-12-03
4

Define $f: \mathbb{R} \rightarrow \{0,1\}$ via $ f(x) = \begin{cases} 0 &\text{ if } x = 0\\ 1 &\text{ if } x \neq 0. \end{cases} $

If you are programming, this can be accomplished with a single if-then-else statement. This will surely be more efficient to compute than any "algebra formula" (by which I take you to mean "non-piecewise formula"), since if clauses are built into the language at a very low level.

  • 0
    Thanks, it's much better and kind of embarrassing that I couldn't do it myself n_n;;2012-12-03
3

The function $f: \mathbb{R} \rightarrow \{0,1\}$ defined via $ f(x) = \lim_{n \rightarrow \infty} \sqrt[n]{x^2} $ satisfies $f(0) = 0$ and $f(x) = 1$ for all $x \neq 0$. This is entirely useless for programming, but it is the simplest function I can think of that avoids a piecewise definition.

  • 0
    @sinekonata For $x = 0$, you have $\lim_{n \rightarrow \infty} \sqrt[n]{0}.$ The sequence generated by the $n$'s is constantly $0$ ($0 = \sqrt{0} = \sqrt[3]{0} = \cdots$), so the limit is $0$.2012-12-03