TITLE: How can I guarantee that $f$ applied to the mean of all $x$'s is equal to the mean of $f$ applied to all $x$'s?
QUESTION [5 upvotes]: I would like to know which properties a function $f:\mathbb{R}\rightarrow\mathbb{R}$ must have so that I can say:
$$f(\overline{x}) = \overline{f(x)}$$
with $\overline{x}$ being the mean of the $x$'s. Or, more explicitly written:
$$f \left(\frac{x_1 + x_2 + \cdots + x_n}{n}\right) =
\frac{f(x_1) + f(x_2) + \cdots + f(x_n)}{n}$$
Thanks in advance.

REPLY [2 votes]: Given a function $f$ with the property
$$\tag{P}
f\left(\frac{1}{n}\sum_{i=1}^nx_i\right)=\frac{1}{n}\sum_{i=1}^nf(x_i) \quad \forall\ n \in \mathbb{N},\ x_1,\ldots, x_n \in \mathbb{R},
$$
we set
$$
F(x)=f(x)-f(0).
$$
Then
$$\tag{1}
F(0)=0, \quad F\left(\frac{x}{n}\right)=\frac{1}{n}F(x) \quad \forall n \in \mathbb{N},\ x \in \mathbb{R}. 
$$
Since
$$
0=F\left(\frac{x-x}{2}\right)=f\left(\frac{x-x}{2}\right)-f(0)=\frac{f(x)+f(-x)-2f(0)}{2}=\frac{F(x)+F(-x)}{2} \quad \forall\ x \in \mathbb{R}
$$
we have
$$\tag{2}
F(-x)=-F(x) \quad \forall\ x \in \mathbb{R}
$$
Thanks to (1) and (2) we get
$$
F\left(\frac{x}{n}\right)=F\left(\frac{-x}{-n}\right)=\frac{1}{-n}F(-x)=\frac{1}{n}F(x) \quad \forall n \in -\mathbb{N},\ x \in \mathbb{R}. 
$$
Hence
$$\tag{3}
F\left(\frac{x}{m}\right)=\frac{1}{m}F(x),\
F(nx)=nF(x) \quad \forall m \in \mathbb{Z}\setminus\{0\},\ n \in \mathbb{Z},\ x \in \mathbb{R}. 
$$
It follows from (3) that 
$$\tag{4}
F(rx)=rF(x) \quad \forall r \in \mathbb{Q},\ x \in \mathbb{R}. 
$$
Again, thanks to (3) we have 
$$
F(x+y)=F\left(\frac{2x+2y}{2}\right)=\frac{F(2x)+F(2y)}{2}=F(x)+F(y) \quad \forall\ x \in \mathbb{R}. 
$$
Thus, $F: \mathbb{R} \to \mathbb{R}$ is a $\mathbb{Q}$-linear map, and any function of the form $f=F+\alpha$ satisfies (P), where $\alpha$ is a real constant, and $F$ a $\mathbb{Q}$-linear on $\mathbb{R}$.