39
$\begingroup$

Is there a name for the function $ \max(x, 0) $?

For comparison, the function $ \max(x, -x) $ is known as the absolute value (or modulus) of x, and has its own notation $ |x| $

$\endgroup$
4
  • 9
    $\begingroup$ should there be a name for this function? is it important enough to get its own name? is it used often enough to warrant an abbreviation? does it capture something so profound to be worth naming? If you answer any of these question positively, then you can improve your question. $\endgroup$ Aug 15 '14 at 10:20
  • 7
    $\begingroup$ In finance max(x-s,0) is the payoff of a call option where s is the strike price and x is the price of the underlying stock on the expiry date. $\endgroup$ Aug 15 '14 at 11:06
  • 4
    $\begingroup$ The question asks for the name of the operation, not an example of something that is computed using it. The operation $\max(x,0)$ isn't called "payoff of a call option", just as the operation of multiplication isn't called "force", despite Newton's second law. $\endgroup$ Aug 16 '14 at 20:37
  • 1
    $\begingroup$ @ColonelPanic - a notation that is frequently used for the payoff of a call option is $(x-s)_{+}$, especially in actuarial science. $\endgroup$ Aug 17 '14 at 1:58
69
$\begingroup$

This is called the positive part of the real number $x$, and often denoted by $x^+$.

Likewise, the negative part of $x$ is $x^-=\max\{-x,0\}$ and the pair of nonnegative real numbers $(x^+,x^-)$ is fully characterized by the pair of identities $$x=x^+-x^-,\qquad\lvert x\rvert=x^++x^-.$$

$\endgroup$
5
  • 23
    $\begingroup$ It should be noted that the negative part is, in fact, a positive number. For example the negative part of -3 is 3. $\endgroup$ Aug 15 '14 at 13:19
  • $\begingroup$ Indeed the positive part and the negative part are both nonnegative numbers. $\endgroup$
    – Did
    Aug 15 '14 at 15:51
  • 8
    $\begingroup$ Similarly, the imaginary part of a complex number is a real number. $\endgroup$
    – user133281
    Aug 15 '14 at 22:40
  • 1
    $\begingroup$ I would rather call this the "positive part of the identity function", because the "positive part" definition as you cite it refers to functions and not numbers. $\endgroup$
    – example
    Aug 16 '14 at 13:34
  • 1
    $\begingroup$ @example Thanks for your input. It just happens that this (i.e., the positive part of the real number $x$) is what mathematicians call it (i.e., $\max(x,0)$). $\endgroup$
    – Did
    Aug 16 '14 at 13:42
19
$\begingroup$

Wikipedia calls this the ramp function and notes that it can be written using Macaulay brackets.

$ \{x\} = \begin{cases} 0, & x < 0 \\ x, & x \ge 0. \end{cases} $

$\endgroup$
16
$\begingroup$

Since this is a math site, not a programming site, my answer may or may not be regarded as trivia. Anyway...

In computer graphics this function is called clamping. The general form is $\mathrm{clamp(x, lowerBound, upperBound)}$ and is defined as

function clamp(x, lowerBound, upperBound):
  if(x < lowerBound)
    return lowerBound
  else if(x > upperBound)
    return upperBound
  else
    return x

or $\mathrm{min( max(x, lowerBound), upperBound)}$.

$\max(x,0)$ is the special case $\mathrm{clamp}(x, 0, +\infty)$.

The clamping function is ubiquitous in computer graphics: You often need to confine a calculated value (e.g. a color intensity) into a range of valid values (e.g. $[0,1]$ or $[0,255]$).

$\endgroup$
11
  • 1
    $\begingroup$ It looks like Java, only function is not Java. Replacing function with something like public static int makes it Java, a method to be inserted in some class. $\endgroup$
    – MickG
    Aug 16 '14 at 9:40
  • 9
    $\begingroup$ It's pseudocode. $\endgroup$ Aug 16 '14 at 10:14
  • 1
    $\begingroup$ It's pseudocode and can trivially easily be translated into Python, JS or anything else. @OutlawLemur It's not literal Python because of a few minor differences: a) function clamp(...) instead of def clamp(...): b) No colons at the end of the if/elif/else lines c) Conditional expressions enclosed by parentheses if(x < lowerBound) instead of if x < lowerBound: $\endgroup$
    – smci
    Aug 17 '14 at 0:31
  • 6
    $\begingroup$ @MickG Even if you replaced function with public static int, it would still be a long way away from being Java. $\endgroup$
    – JLRishe
    Aug 17 '14 at 11:53
  • 1
    $\begingroup$ @MickG: It is much closer to Python than Java. $\endgroup$
    – Reid
    Aug 17 '14 at 19:55
11
$\begingroup$

You can check that:

$$\color{blue}{\max(x,0) = x \, H(x)}$$

where $H(x)$ is the Heaviside or unit step function. A name for this? Not a clue, but hope it helps.

$\endgroup$
1
  • $\begingroup$ This is actually a pretty nice implementation. For example, here's a quick and dirty computation of the derivative for $x \neq 0$: $$\frac{d}{dx} \max(x,0) = \frac{d}{dx} H(x)\cdot x = H(x) \frac{d}{dx} x = H(x) \cdot 1 = H(x).$$ It works because $H(x)$ is basically a constant. More precisely, the function $$\begin{cases} 1 & x>0 \\ 0 & x < 0\end{cases}$$ is a locally constant openly-supported partial functions $\mathbb{R} \rightarrow \mathbb{R}$, which is exactly what you need in order to treat it as a constant insofar as differentiation is concerned. $\endgroup$ Aug 5 '17 at 4:12
8
$\begingroup$

I have heard this function called the rectifier. This is a pretty exclusive field name though, and I wouldn't expect to see it anywhere outside of neural networks.

$\endgroup$
3
  • 3
    $\begingroup$ I think the use in neural networks derives from the use of the term in electrical engineering: en.wikipedia.org/wiki/Rectifier $\endgroup$
    – A. Donda
    Aug 16 '14 at 2:27
  • $\begingroup$ @A.Donda Thanks for the information. $\endgroup$
    – Did
    Aug 16 '14 at 13:05
  • $\begingroup$ This might be a newer coinage than when this answer was originally written, but as of 2021 the term "ReLU" (for rectified linear unit) is also frequently used for this function. $\endgroup$
    – Emil
    Sep 17 at 12:03
4
$\begingroup$

You can use:

$$f(x) = \frac{x + |x|}{2}$$

$\endgroup$
8
  • 7
    $\begingroup$ I suppose that's interesting, but it's not at all what the question is asking. $\endgroup$
    – Ray
    Aug 15 '14 at 18:38
  • 3
    $\begingroup$ The point is that the function doesn't need a name, it can be expressed in terms of $|x|$ and $x$. $\endgroup$
    – Darth Geek
    Aug 15 '14 at 18:42
  • 7
    $\begingroup$ So squaring doesn't need a name because it can be expressed in terms of $x$ and $2$? And factorial doesn't need a name because it can be expressed in terms of product? And... $\endgroup$ Aug 16 '14 at 20:40
  • 2
    $\begingroup$ @DavidRicherby It's not about that. We call $x^2$ squaring but we don't have a name for $x^2+3$. We have a name for $n!$ but not one for $(-1)^nn!$. So perhaps a name for the function described is not really needed. It turns out it does have a name, but if it didn't and you needed to use it in a paper, for instance you can just give it a special letter and define it at the beggining of the paper and it would be ok. $\endgroup$
    – Darth Geek
    Aug 17 '14 at 8:19
  • 5
    $\begingroup$ How is (x+|x|)/2 better then max(x, 0) anyway? $\endgroup$
    – Cthulhu
    Aug 17 '14 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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