Finding a non-piece wise function that gives us the $i$'th largest number.

41 Views Asked by At

A friend of mine was asked to find a non-piece wise function on four variables $i,a,b,c$ such that $f(i,a,b,c)$ is the $i$'th largest number among $\{a,b,c\}$. Using max and min or defining the function by pieces is prohibited.

The solution I found uses Lagrange Polynomials but to explain it I first had to find how to find the max, middle and min elements.

To find max I just use $$\frac{c+(\frac{a+b}{2}+\frac{|a-b|}{2})}{2}+\frac{|c-(\frac{a+b}{2}+\frac{|a-b|}{2})|}{2}$$

This is because the max of $a,b,c$ is $max(max(a,b),c)$

To find min I just use the same approach: $$\frac{c+(\frac{a+b}{2}-\frac{|a-b|}{2})}{2}-\frac{|c-(\frac{a+b}{2}-\frac{|a-b|}{2})|}{2}$$

To find the middle element I substract the maximum and minimum from $a+b+c$.

So it is $$a+b+c-(\frac{c+(\frac{a+b}{2}+\frac{|a-b|}{2})}{2}+\frac{|c-(\frac{a+b}{2}+\frac{|a-b|}{2})|}{2})-(\frac{c+(\frac{a+b}{2}-\frac{|a-b|}{2})}{2}-\frac{|c-(\frac{a+b}{2}-\frac{|a-b|}{2})|}{2})$$.

After having this I just build the lagrange polynomial so that

$$f(i,a,b,c)=\color\red{\frac{(2-i)(3-i)}{2}[\frac{c+(\frac{a+b}{2}+\frac{|a-b|}{2})}{2}+\frac{|c-(\frac{a+b}{2}+\frac{|a-b|}{2})|}{2}}]+\color{blue}{\frac{(1-i)(3-i)}{-1}[a+b+c-(\frac{c+(\frac{a+b}{2}+\frac{|a-b|}{2})}{2}+\frac{|c-(\frac{a+b}{2}+\frac{|a-b|}{2})|}{2})-(\frac{c+(\frac{a+b}{2}-\frac{|a-b|}{2})}{2}-\frac{|c-(\frac{a+b}{2}-\frac{|a-b|}{2})|}{2})}]+\color\green{\frac{(1-i)(2-i)}{2}[\frac{c+(\frac{a+b}{2}-\frac{|a-b|}{2})}{2}-\frac{|c-(\frac{a+b}{2}-\frac{|a-b|}{2})|}{2}}]$$

I would like this space to provide alternative constructions (If they could be simpler it would be better.

Thank you, regards.

1

There are 1 best solutions below

2
On BEST ANSWER

That's about the way I would do it, although I would split it up into a number of subsidiary functions (the "b" prefix stands for "bear"):

$bmin2(a, b) =\frac12(a+b-|a-b|) $, $bmax2(a, b) =\frac12(a+b+|a-b|) $, $bmin3(a, b, c) =bmin2(bmin2(a, b), c) $, $bmax3(a, b, c) =bmax2(bmax2(a, b), c) $, $bmid(a, b, c) =a+b+c-bmax3(a, b, c)-bmin3(a, b, c) $.

Then I would write your interpolating polynomial in terms of the min, max, and mid functions.

To do this for four variables seems harder. We can get the min and max as above (with another level of calls), and we can get the sum of the middle two, but how to separate that sum into the individual values so we can we can decide which is smaller is not immediately clear to me.

I think I'll propose it as a problem.