Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|cite|improve this question
The expression is $x \cdot 0$. – Mechanical snail Sep 19 '12 at 9:50
up vote 5 down vote accepted

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.

share|cite|improve this answer
this is what I'm looking for, thanks – 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 ...

share|cite|improve this answer

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

share|cite|improve this answer

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.

share|cite|improve this answer
cool, never heard that before... – Sep 19 '12 at 5:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.