Suppose I have a polynomial function $f\in \mathbb{Z}[x\_1, \dotsc, x\_k],$ such that whenever $r\_1, \dotsc, r\_k$ are roots of a monic polynomial of degree $k$ with integer coefficients, we have $f(r\_1, \dotsc, r\_k) \in \mathbb{Z}.$ Is it true that $f$ is a symmetric function of its arguments?


Note: this was asked on MSE, but only resulted in an inconclusive discussion with Qiaochu...


**EDIT** Fedor Petrov's argument certainly answers the question quite elegantly, but I was thinking of the case where $r\_1\dotsc, r\_k$ are roots of an *irreducible* polynomial, so the reduction to $k=2$ is not quite so obvious. If there is an argument in that setting as well, that would be very much of interest.



polynomials and symmetric functions
Consider the minimal polynomial $P$ of $f$ over the fixed field
$\mathbb Q(\sigma\_1, \ldots, \sigma\_k) = \mathbb Q(x\_1, \ldots, x\_k)^{S\_k}$
(where the $\sigma\_j$ are the elementary symmetric polynomials), so
$P$ is irreducible and $P(f) = 0$. Since $f$ is a polynomial,
the coefficients of $P$ will actually be polynomials in the $\sigma\_j$.


By the Hilbert Irreducibility Theorem, $P$ will
remain irreducible when we specialize $\sigma\_1, \ldots, \sigma\_k$
to rational numbers, outside a thin set of such $k$-tuples.
But the set of $k$-tuples corresponding to $(x\_1, \ldots, x\_k)$ forming
a Galois orbit is not thin (its *complement* is thin: it consists of the
points $(a\_1, \ldots, a\_k)$ such that
$h(T) = T^k - a\_1 T^{k-1} + \ldots \pm a\_k$
is reducible; this set can be written as a finite union of images
of $\mathbb Q$-rational points under dominant morphisms that correspond
to the various possibilities of factoring $h$).


So there are (plenty of) integer (see [this Wikipedia entry](https://en.wikipedia.org/wiki/Hilbert%27s_irreducibility_theorem))
specializations $\boldsymbol{a}$ with irreducible $h$ such that the specialized $P\_{\boldsymbol{a}}$
is irreducible. But by assumption, $P\_{\boldsymbol{a}}$
has a rational root (since
$f$ evaluated at the roots $\boldsymbol{r}$ of $h$ is an integer):
$P\_{\boldsymbol{a}}(f(\boldsymbol{r})) = 0$.
So $P$ must have degree 1,
and $f$ is in $\mathbb Q[\sigma\_1, \ldots, \sigma\_k]$.


In more detail: Write
$$P(X) = X^n + p\_{n-1}(\sigma\_1, \ldots, \sigma\_k) X^{n-1} + \ldots + p\_0(\sigma\_1, \ldots, \sigma\_k) .$$
Then there are integers $\boldsymbol{a} = (a\_1, \ldots, a\_k)$
such that $h\_{\boldsymbol{a}} = T^n - a\_1 T^{n-1} + \ldots \pm a\_k$
is irreducible and
$$P\_{\boldsymbol{a}}(X) = X^n + p\_{n-1}(a\_1, \ldots, a\_k) X^{n-1} + \ldots + p\_0(a\_1, \ldots, a\_k) \in {\mathbb Q}[X]$$
is also irreducible. Let $\boldsymbol{r} = (r\_1, \ldots, r\_k)$ be
the roots of $h\_{\boldsymbol{a}}$.
Then $f(\boldsymbol{r}) = m \in \mathbb Z$. On the other hand,
$\sigma\_j(\boldsymbol{r}) = a\_j$, so
$$0 = P\_{\boldsymbol{a}}(f(\boldsymbol{r}))
 = m^n + p\_{n-1}(\boldsymbol{a}) m^{n-1} + \ldots + p\_0(\boldsymbol{a}),$$
i.e., $m$ is a root of the irreducible polynomial $P\_{\boldsymbol{a}}$.


