14
$\begingroup$

It's well-known that $\max(a,b)=\frac{a+b+|a-b|}{2}.$

Is there a (good) generalization to several variables? Of course $\max(a,b,c)=\max(a,\max(b,c))$ and so $\max(a,b,c)=\frac{a+\frac{b+c+|b-c|}{2}+|a-\frac{b+c+|b-c|}{2}|}{2}$ $=\frac{a+0.5b+0.5c+0.5\left|b-c|+|a-0.5b-0.5c-0.5|b-c|\right|}{2}$ but I'd like a form that shows the natural symmetry better and which doesn't have so many operations.

This is a practical problem working on a system which has an absolute value operator but no maximum and not much ability to execute conditional statements, but to be honest the real reason I'm interedted is an attempt to beautify something that is seemingly ugly.

For the practical side I need 5-10 arguments and it's acceptable to assume that all arguments are at least 0, though of course it would be much more satisfying if this latter assumption was not needed.

  • 0
    Ceiling, floor, /(a)tan, +-*/^, integer division and modulus, comparison operators, logical (not bitwise!) and/or, and transcendentals (!): exp/log, (a)sin/(a)cos.2011-04-21

1 Answers 1

2

I think that integer division may provide a path to a different answer, depending on exactly how it works. I 'll do the formatting programming-style, not math-style since that is what I'm use to.

Suppose you have n arguments, A[1], A[2], A[3]..., A[n].

Define multiplier coefficient C[i][j] such that C[i][j] = 1 for A[i]>A[j], zero otherwise. This can be done using the absolute value trick as in the above formula.

Define a coefficient T[i] = sum (C[i][j]) / (n-1) using integer division. For subscript i belonging to the max value, the sum will be n-1, so T[i] will be 1. For other subscripts, the sum will be less than n-1, so T[i] will be zero.

Max = sum (T[i] A[i])

Probably I have something backwards, but I think the approach is workable, though maybe not better than original suggestion.

  • 0
    I'm in a Turing-incomplete language that doesn't have loops or variables. This formula is very large to write in that format! It would take a whole page to express the five-variable version. (Yes, the language is awful. No, I can't change.)2011-05-02