# Expression that only result a natural number

There's any math trick that can turn any negative number to 0? I'm not sure if this is possible without conditional logic

f(x>=0) = x

f(x<0) = 0

-
The expression is $x \cdot 0$. –  Mechanical snail Sep 19 '12 at 9:50

You can avoid absolute value (and therefore avoid "if") using $$f(x) = \frac{x + \sqrt{x^2}}{2}.$$ I adopt the convention that $\sqrt{}$ is a function returning only the positive square root of its argument.

-
this is what I'm looking for, thanks –  Vitim.us Sep 19 '12 at 5:25
You are taking the implied positive root here, otherwise this is f(x) = +/- x –  Nick Sep 19 '12 at 9:35
@Nick I've incorporated your remark into my solution. Thank you. –  Austin Mohr Sep 19 '12 at 18:31

How about $f(x)=\frac{x+|x|}2$? The "if" is then hidden in the definition of absoulute value of course ...

-

It's surprisingly easy to write down the function $\max$ in terms of absolute values: $$\max(x,y)=\frac{|x-y|+x+y}{2}$$

So just take $\max(x,0)$.

-

Computer science, and some branches of mathematics, deal with a "truncated subtraction" operator, $\dot-$ which is exactly what you want. The value of $a\;\dot-\;b$ is defined to be the same as $a-b$ if $a$ is at least as big as $b$, and zero if it is smaller.

So you could say for example that $f(x) = x\;\dot-\;0$.

But this is just saying the same as what you said in your question, and making up a funny symbol for it. There is no reason why writing $x\;\dot-\;0$ is better than writing what you actually wrote. So just write what you wrote and don't worry about the funny symbol. No "math tricks" are needed. All that is needed is for you to say what you mean.

-
cool, never heard that before... –  Vitim.us Sep 19 '12 at 5:24