30
$\begingroup$

For two variables, their maximum $\max\{x_1,x_2\}$ can be expressed using one $|\cdot|$ operation: $$ \max\{x_1,x_2\} = \frac12(x_1+x_2+|x_1-x_2|). $$ For $3$ variables, it seems fairly clear that three $|\cdot|$ operations are necessary, though I can only demonstrate sufficiency: $$ \max\{x_1,x_2,x_3\} = \frac14\left[ 2x_1+x_2+x_3+|x_2-x_3|+2\left|x_1-\frac12(x_2+x_3+|x_2-x_3|)\right| \right] . $$ For $5$ variables, it has been claimed here https://twitter.com/ereliuer_eteer/status/1669081421007454209 that the minimum number of $|\cdot|$ operations is 54, though I have verified neither sufficiency nor necessity.

Question: How many $|\cdot|$ operations are necessary for $n$ variables? To be explicit about the rules, in addition to $|\cdot|$, the 4 arithmetic operations are allowed.

Update. That twitter post I linked is actually computing the median, not the max of 5 variables. So the analogous question for abs-operation complexity, but now for the median, is quite natural.

$\endgroup$
9
  • 3
    $\begingroup$ Evidently you get some kind of bound using the fact that $\max (x_1,\ldots,x_n) = \max(x_1, \max(x_2,\ldots,x_n))$. $\endgroup$ Commented Jun 14, 2023 at 21:23
  • 1
    $\begingroup$ Sure, that would give an exponential upper bound -- right? $\endgroup$ Commented Jun 14, 2023 at 21:23
  • 2
    $\begingroup$ I guess $\lfloor \log n \rfloor$ is a weak lowerbound from information theoretic considerations. $\endgroup$
    – Tony Huynh
    Commented Jun 14, 2023 at 22:31
  • 6
    $\begingroup$ @TonyHuynh If we are allowed just linear forms and absolute value, the trivial lower bound is $n-1$. Otherwise, we can keep all absolute values at $0$ and obtain a 2-dimensional subspace on which the maximum is a linear function, which is absurd. $\endgroup$
    – fedja
    Commented Jun 15, 2023 at 12:57
  • 4
    $\begingroup$ @fedja’s $n-1$ lower bound holds even if we consider circuit size rather than formula size. For circuit size, it is tight, as the recurrence in Sam Hopkins comment gives a circuit using linear forms and $n-1$ absolute values. $\endgroup$ Commented Jun 15, 2023 at 13:06

2 Answers 2

27
$\begingroup$

Let $f(k)$ be the minimum number of $|\cdot|$ operations to express the maximum of $2^k$ variables. Using the identities $$\max\{x_1,x_2\} = (x_1+x_2+|x_1-x_2|)/2,$$ $$\max\{x_1,\ldots,x_{2^{k+1}}\} = \max\{\max\{x_1,\ldots,x_{2^k}\},\max\{x_{2^k+1},\ldots,x_{2^{k+1}}\}\},$$ it is clear that $f(1)=1$ and $f(k+1)\leq 4f(k)+1$. Hence it follows by induction that $$f(k)\leq (4^k-1)/3.$$ Now let us consider the case of $n$ variables. If $2^{k-1}<n\leq 2^k$, then the minimal number of corresponding $|\cdot|$ operations is less than $4^k/3$, which is less than $(4/3)n^2$.

Added. In fact that minimal number of $|\cdot|$ operations is less than $(3/8)n^2$. For details, see AspiringMat's response and the comments below it.

$\endgroup$
7
  • 1
    $\begingroup$ Very nice! Can you prove that the minimal number of abs operations is $\Omega(n^2)$? $\endgroup$ Commented Jun 14, 2023 at 22:31
  • 2
    $\begingroup$ @AryehKontorovich What's best lower bound you know? $\endgroup$ Commented Jun 14, 2023 at 23:26
  • 5
    $\begingroup$ In particular, $(4/3)5^2=100/3< 34 < 54$. $\endgroup$ Commented Jun 14, 2023 at 23:46
  • 2
    $\begingroup$ In particular by splitting 5 into 2 and 3 items, we have $g(5) \le 2*g(2) + 2*g(3) + 1 \le 2 + 6 + 1$, where $g(n)$ is the minimal number of abs operations on $n$ items $\endgroup$ Commented Jun 15, 2023 at 1:50
  • 3
    $\begingroup$ @AryehKontorovich But there is often a gap between minimum formula size and minimum circuit size. Do you have an example that beats the upper bound given in AspiringMat's answer? $\endgroup$ Commented Jun 15, 2023 at 12:43
15
$\begingroup$

This is just a tighter analysis of the analysis from @GH from MO.

Let $f(n)$ be the minimum number of $|\cdot|$ operations to compute $\max(x_1, \ldots, x_n)$. Then $f(1)=0$ and for $n\geq 1$:

$$f(n)\leq 1+2\min_{1\leq j < n}\left( f(j)+f(n-j)\right)$$

Generating the first few values, we get for $n\geq 2$: $1, 3, 5, 9, 13, 17, \ldots$ which plugging into OEIS give this sequence (Shifted by 2). Plugging in, we get

$$f(n) \leq n 2^{\lfloor \log_2(n) \rfloor } - \frac{2\cdot 4^{\lfloor \log_2(n) \rfloor} + 1}{3}$$

In the notes, it says that this is the solution to the recurrence $$a(n)=1+2a(\lfloor n/2 \rfloor)+2a(\lceil n/2 \rceil) $$ which suggests that the minimization above happens precisely at $j=\lfloor n/2 \rfloor$.

The upper bound behaves like $1/3 n^2$. Comparing the upper bound above and $4/3 n^2$, we get:

enter image description here

One interesting note is that if we consider the DP

$$f(n)\leq \min_{i,j | 0\leq i+j <n }3+2f(i)+4f(j)+4f(n-i-j)$$

Which uses the second identity in OP's answer ($x_1$ appears twice, and $x_2, x_3$ appear 4 times, with $3$ extra $|\cdot|$), then it seems to be minimized at precisely the same minima as the 2D case. It would be interesting if there are alternative expressions for $n=3$ that use less variables which can be used to get better bounds.

$\endgroup$
8
  • 1
    $\begingroup$ @MaxAlekseyev Few typos, fixed now. $\endgroup$ Commented Jun 15, 2023 at 11:40
  • 1
    $\begingroup$ @TimothyChow yes you're right, edited. $\endgroup$ Commented Jun 15, 2023 at 12:40
  • 2
    $\begingroup$ The bound is about $\frac13n^2$ when $n$ is close to a power of $2$, but it gets up to about $\frac38n^2$ when $n\sim\frac432^k$. $\endgroup$ Commented Jun 15, 2023 at 12:59
  • 6
    $\begingroup$ The reason the 3-variable DP is not any better is that it follows from the 2-variable DP: $f(x+y+z) \le 2f(x) + 2f(y+z) + 1 \le 2f(x) + 4f(y) + 4f(z) + 3$. $\endgroup$ Commented Jun 15, 2023 at 13:57
  • 1
    $\begingroup$ @SeanEberhard Ahh, not so interesting after all :). $\endgroup$ Commented Jun 15, 2023 at 16:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .