I'm looking for an operator that returns the greater of two values.

Here's an example. If $a=5$, $b=6$ and $???$ is the operator, I'd like to have $x$ equal $b$ when I do $x=a???b$, since $b$ is the larger of the two values.

  • 3
    $\begingroup$ This is usually denoted by $\max$. For instance $\max(5,6)=6$. $\endgroup$ – Git Gud Jan 4 '16 at 23:00
  • 1
    $\begingroup$ @GitGud The OP was asking for an operator rather than a function. I am not sure if such an operator exists? $\endgroup$ – Mufasa Jan 4 '16 at 23:02
  • 2
    $\begingroup$ @Mufasa I don't see why $a\star b$ is any more or less preferable than $\star(a,b)$ in this situation. Especially since the extension of the notation beyond the binary case for this is so useful and widely used. $\endgroup$ – JMoravitz Jan 4 '16 at 23:06
  • 1
    $\begingroup$ @JMoravitz - fair enough :) $\endgroup$ – Mufasa Jan 4 '16 at 23:06
  • 7
    $\begingroup$ @Mufasa One can look at $\max$ as a binary operation,pretty much by definition of binary operation. If one is required to build $\max$ from $+,-,\cdot$ and $\div$, then one can note that $$\forall x,y\in \mathbb R\left(\max(x,y)=\dfrac{x + y + |x-y|}{2}\right).$$ $\endgroup$ – Git Gud Jan 4 '16 at 23:06

You can always write $x=\max\{a,b\}$; this is common. A less common notation is $x=a\lor b$; although it is used, it is uncommon enough that I would definitely define it before using it. Note too that the more common notation easily generalizes to the maximum of any finite set of numbers: if $A=\{a_k:k=1,\ldots,n\}$, for instance, you can write $x=\max A$, $x=\max\{a_1,\ldots,a_n\}$, or $x=\max\{a_k:k=1,\ldots,n\}$.

The matching usages for the smaller of two numbers are $\min\{a,b\}$ and $a\land b$.


For $S=\{a_1,\cdots,a_n\}$, define $*$ inductively by operator $*:\mathbb{R}^n\to\mathbb{R}$ as $*(a_1,a_2)=\dfrac{|a_2-a_1|+a_2+a_1}{2}$ if $n=2$ and $*:\mathbb{R}^{n+1}\to\mathbb{R}$ as $*(a_1,...,a_n,a_{n+1})=*(*(a_1,\cdots,a_n),a_{n+1})$. Thus $*(a_1,\cdots,a_n)=\max S$ for any set $S=\{a_1,\cdots,a_n\}$.


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.