What might this function be? The problem:
I'm looking for a particular function $f(x, y)$—this isn't "homework" in the sense that I have no idea if such a function exists. It has a continuous domain $-1 \lt x \lt 1$ and $-1 \lt y \lt 1$, and a continuous range $-1 \le f(x, y) \le 1$ (EDIT: I have no idea how to word these requirements. See comments.) Additionally:
$f(n, -n) = 0$
$f(n, 0) = f(0, n) = n$
$f(n, 1) = f(1, n) = 1$
$f(n, -1) = f(-1, n) = -1$
I did work out the following cubic function $g$ which comes close:
$g(x, y) = (-\frac{x^2}{1-x^2})y^3 - xy^2 + (\frac{1 - 2x^2}{1-x^2})y + x$
$g(n, -n) = 0$
$g(n, 0) = g(0, n) = n$
$g(n, 1) = 1$
$g(n, -1) = -1$
However:
$g(\lim \limits_{x \to 1}, |n|) = \infty$
What I'm trying to achieve:
In my code, $x$ and $y$ are two "match" percentages between elements $a$ and $b$ (for $x =$ +100%, $a$ and $b$ are perfect matches; for $x =$ 0%, $a$ and $b$ have no relation; for $x =$ -100%, $a$ and $b$ are exact opposites). I'm trying to (elegantly) combine these two match values such that $x$ & $y$ with the same sign pull each other toward |100%| and $x$ & $y$ with opposite signs pull each other toward 0% (cancel each other out).
If I can't find an elegant mathematic solution, I'll just use linear interpolation in the three ranges $(sign(x), 0), (0, -x), (-x, -sign(x))$.
EDIT: Also worth noting that function $g$ doesn't work well for this purpose for $|x| > \frac23$ or $|y| > \frac23$, since the cubic function grows a peak & valley beyond that threshold.

What about
$$f(x, y) =
\begin{cases}
x + y & -1 \leq x + y \leq 1 \\
1 & x + y > 1 \\
-1 & -1 > x + y
\end{cases}$$
OK, so it's a piecewise function, but it does what (I think) you intended. Bear in mind that I guessed most of it based on the fact that $x$ and $y$ represent percentages and you are probably trying to combine two aspects of similarity into a single number.
For $-1 \leq n \leq 1$,
$$
f(n, 0) = f(0, n) = n
$$
For $n \geq 0$:
$$
f(n, 1) = f(1, n) = 1
$$
(If there's one 100% correlation and the other one is negative, then that isn't a 100% result, is it?) For $n \leq 0$:
$$
f(n, -1) = f(-1, n)
$$
(A similar observation as above applies.)
Do tell me whether this works.
