Considering a function $f$ such that: $$ f(x_1, x_2, x_3) = f(f(x_1, x_2), x_3) = f(x_1, f(x_2, x_3)) $$ and $$ f(x_1, x_2) = f(x_2, x_1) $$
and a set $X = \{ x_1, \dots, x_n \}$; how to compute $$f(x_1, \dots, x_{i - 1}, x_{i + 1}, \dots, x_{j-1}, x_{j+1}, \dots, x_n)$$ for all pairs $i, j \in 1, \dots, n$, $i < j$ while minimizing the number of calls to $f$?
- Only $f(x)$ and $f(x, y)$ can be computed
- $f^{-1}$ is not defined
For example, let $f$ be addition, i.e, $f(x_1, x_2, \cdots, x_n)=x_1+x_2+\cdots+x_n$. However, only calls to $f$ with one or two arguments are allowed, i.e $f(x)=x$ and $f(x_1,x_2)=x_1+x_2$. In particular, neither subtraction nor negation is allowed. The problem is to compute all sums of $n-2$ numbers among the given $n$ numbers with the least number of additions. There are $n(n-1)/2$ such sums.