Is there a less-trivial integer function with described properties?

To be found are integer one-valued functions $f(n_1,n_2)$ with following properties:

  1. $f(n_1,n_2)=f(n_2,n_1)$,
  2. $f(f(n_1,n_2),n_3)=f(n_1,f(n_2,n_3))$,
  3. $f(n_1+n_2,n_1+n_3)=n_1+f(n_2,n_3)$.

So far I have found only the functions $\min(n_1,n_2)$ and $\max(n_1,n_2)$ and wonder, if there are some less trivial functions which would in some cases deliver other values than $n_1$ or $n_2$. If such functions do not exist, a corresponding proof would be desirable.

UPDATE:

As was pointed out by J.-E. Pin the question can be reduced to search of the one-variable (!) function $g(n)$ with the properties:

$\quad$ 1'. $g(n)-g(-n)=n$,

$\quad$ 2'. $g(g(n)-m)+m=g(g(m)-n)+n$.

Using the first property the second one can be also written as:

$\quad$ 2''. $g(n)+g(m-g(n))=g(m)+g(n-g(m))$.

The previously found functions correspond to $g(n)=\min(n,0)$ and $g(n)=\max(n,0)$.


As noted in the question, if we set $g(a)=f(0,a)$ then (3) gives $f(a,b)=a+g(b-a)$, and (1), (2) give $$\begin{eqnarray*} (1'):&&g(a)=a+g(-a),\\ (2'):&&g(a)+g(b-g(a))=g(a+g(b-a)). \end{eqnarray*}$$ Let $z=g(0)$ and put $(a,b)=(0,c+z)$ in (2') to obtain $$ (4):\;g(c)+z=g(g(c+z)). $$ Suppose $z\neq0$. Let $h(c)=c+z$. Then (4) can be restated as $hg=g^2h$. Thus $h^kg^l=g^{2^kl}h^k$ for $k,l\geq0$. It follows that for all $c\in\mathbb Z$ and $k,l\geq0$, $$ g^l(c)=c+kz\Rightarrow g^{2^kl}(c+kz)=c+2kz. $$ By induction, it follows that $$ (5):\;g^l(c)=c+kz\Rightarrow g^{s(m,k)l}(c)=c+mkz. $$ where $s(m,k)=\sum_{m'=0}^{m-1}2^{m'k}$. Similarly, $$ (5'):\;g^l(c+kz)=c\Rightarrow g^{s(m,k)l}(c+mkz)=c. $$ Let $X_n=\{g^l(0)\mid0\leq l<n\}$ and $X=\bigcup_{n>0}X_n$. Since $g(0)=z$, (5) implies $z\mathbb N\subseteq X$. In particular $X$ is unbounded, so $g^l(0)\neq g^{l'}(0)$ for distinct $l,l'\geq0$.

Lemma. Suppose $k_1,k_2,l_1,l_2>0$, $g^t(a)\in X$ for some $t\geq0$ and either:

  1. $a=g^{l_1}(a-k_1z)=g^{l_2}(a-k_2z)$, or
  2. $a=g^{l_1}(a)+k_1 z=g^{l_2}(a)+k_2z$.

Then $$ \frac{l_1}{l_2}=\frac{1-1/2^{k_1}}{1-1/2^{k_2}}. $$

Proof. Note that $g^t(a)\in X$ implies $g^{l_1}(a)\neq g^{l_2}(a)$ for $l_1\neq l_2$. By (5), the first condition implies $$ g^{s(k_2+1,k_1)l_1}(a-k_1z)=a+k_1k_2z=g^{s(k_1+1,k_2)l_2}(a-k_2z) $$ for all $m>0$. Thus $(s(k_2+1,k_1)-1)l_1=(s(k_1+1,k_2)-1)l_2$. Simplifying gives the result. The second case follows similarly using (5').

Now fix $r\in\mathbb Z$. I claim there are constant $c_r,d_r$ such that $$ |X_n\cap(r+z\mathbb Z)|\leq c_r+d_r\log(n). $$ If $|X\cap(r+z\mathbb Z)|\leq1$ this is clear, so suppose we have distinct $a,b\in X\cap(r+z\mathbb Z)$. We may suppose $b=a+kz=g^l(a)$ for some $l>0$ and $k\neq0$. Also $a=g^t(0)$ for some $t\geq0$. First suppose $k>0$. By (5), $$ g^{s(m,k)l}(a)=a+mkz $$ for $m\geq0$. Suppose $c\in X_n\cap(r+z\mathbb Z)$. Then $c=f^u(0)=a+vz$ where $0\leq u<n$ and $v\in\mathbb Z$. Pick $m$ such that $mk>v$ and $s(m,k)l+t>u$. We have $$ g^{s(m,k)l}(a)=a+mkz=g^{s(m,k)l+t-u}(a+vz). $$ Now the Lemma implies $$ \frac{s(m,k)l+t-u}{s(m,k)l}=\frac{1-1/2^{mk-v}}{1-1/2^{mk}}. $$ Simplifying, $u=t+l(2^v-1)/(2^k-1)$. Now either $u<t$ or $$ 0\leq v<\log_2(1+n(2^k-1)/l). $$ The result follows. The case $k<0$ follows similarly from (5') and the second condition of the Lemma.

Finally we have $$ n=|X_n|=\sum_{r=0}^{|z|-1}|X_n\cap(r+z\mathbb Z)| \leq\left(\sum_{r=0}^{|z|-1}c_r\right)+ \left(\sum_{r=0}^{|z|-1}d_r\right)\log n $$ for all $n$, giving a contradiction. Thus $z=g(0)=0$.

Now (4) gives $g^2=g$. Let $I=\mathrm{im}\,g$, so $g(a)=a$ for $a\in I$. Put $(a,b)=(g(c),d+g(c))$ in (2') to obtain $$ g(c)+g(d)=g(g(c)+g(d)) $$ for all $c,d$. Thus $I$ is closed under addition. Also $0\in I$ since $g(0)=0$. Finally (1') implies $g(1)=1+g(-1)$, so $I\neq\{0\}$. Note that (1') implies $a\in I$ iff $g(-a)=0$.

Putting $(a,b)=(c-d,c)$ in (2'), we have $$ (6):\;c,d\in I\Rightarrow c-g(c-d)\in I $$ Suppose $a,-b\in I$ where $a,b>0$. Using closure under addition, $ab,-ab\in I$, so (1') gives $ab=g(ab)=ab+g(-ab)=0$, a contradiction. Thus $I$ is containined in $\mathbb Z_{\geq0}$ or $\mathbb Z_{\leq0}$. Replacing $g(a)$ by $-g(-a)$ if necessary, we may suppose the former.

Let $p>0$ be the smallest positive element in $I$. Suppose $p>1$. Again by (1'), we cannot have $I\subseteq p\mathbb Z$. Pick $a\in I\setminus p\mathbb Z$ minimal, so $a-p\notin I$. Then $g(p-a)\neq 0$, so $g(p-a)\geq p$. On the other hand, (6) gives $a-g(a-p)\in I$, so $g(a-p)\leq a$. Now (1') gives $g(a-p)=a$.

Using closure under addition, $pa-a=(p-1)a\in I$. Pick $l$ minimal such that $b=(l+1)p-a\in I$. Then $b\geq0$ implies $l\geq0$. Now (6) gives $$ lp-g(lp-b)\in I. $$ But $g(lp-b)=g(a-p)=a$, so $lp-a\in I$. This contradicts the minimality of $l$.

Therefore $p=1$. By closure under addition, $I=\mathbb Z_{\geq0}$. Hence $g(a)=a$ for $a\geq0$ and $g(a)=0$ for $a<0$.