If $\frac{1}{2y} \int_{x-y}^{x+y} f(t) \space \mathrm{d}t = f(x)$, then $f$ is linear The problem is:

$f : \mathbb{R} \to \mathbb{R}$ is a twice differentiable function such that
$$ \frac{1}{2y} \int_{x-y}^{x+y} f(t) \space \mathrm{d}t = f(x) \quad [x \in \mathbb{R}, \space y>0] $$
Show $f(x) = ax + b$ for some $a, b$ for all $x \in \mathbb{R}$

I have seen various solutions to this problem online, but I found one that does not use the twice-differentiable property, and was wondering if I had made a slip somewhere.
Solution
By differentiating w.r.t. $y$, we get
$$\frac{f(x+y) + f(x-y)}{2} = f(x)$$
This means that $f$ has the property that if any two points lie on the graph of $f$, so does their midpoint. As a corollary, if $P_1, P_2$ lie on this graph, then if $P_3$ is a point such that the midpoint of $P_1P_3$ is $P_2$, then $P_3$ lies on the the graph also.
So now let $A = (0, f(0)), \space B = (1, f(1))$, and the line joining them be given by $y = g(x) = ax+b$. By the property described above, this means that $f(\pm 2^n) = g(\pm 2^n) \space [n \in \mathbb{Z}]$. So by a 'binary search' procedure, we can, for any $k$, construct a sequence $a_n$ with $\lim a_n = k$ and $f(a_n) = g(a_n)$.
But then, since $f$ and $g$ are both continuous, we wind up with $f(k) = g(k)$, which is what we wanted to prove.
 A: Your approach is correct, but I think that you should give a full explanation of your statement:

By the property described above, this means that $f(\pm 2^n) = g(\pm 2^n) \space [n \in \mathbb{Z}]$.

A shorter way. Starting from
$$\frac{1}{2}\int_{x-y}^{x+y} f(t) \,dt = f(x)y$$
by differentiating with respect to $y$ we obtain
$$\frac{f(x+y) + f(x-y)}{2} = f(x)$$
This is your first step. Note that such identity holds for any $y\in\mathbb{R}$.
Now, we differentiate two more times with respect to $y$ (recall that $f$ is twice differentiable):
$$\frac{f'(x+y) - f'(x-y)}{2} = 0,$$
$$\frac{f''(x+y) + f''(x-y)}{2} = 0.$$
Finally, by letting $y=0$, we have that $f''(x)=0$ for all $x\in\mathbb{R}$, and therefore $f(x)=ax+b$ for some $a,b\in\mathbb{R}$.
A: This is an interesting problem (albeit not too difficult) which admits a solution under a considerably more general hypothesis, as follows:

Assume $f \colon \mathbb{R} \to \mathbb{R}$ is continuous and that the relation:
$$\frac{1}{2y}\int_{x-y}^{x+y}f(t)\mathrm{d}t=f(x)$$
holds for any $x \in \mathbb{R}$ and $y>0$. Then $f$ is $\mathbb{R}$-affine (this means it is a an affine endomorphism of $\mathbb{R}$ regarded as an affine space over itself with the canonical structure or in more simple terms that there exist coefficients $a, b \in \mathbb{R}$ such that $f(x)=ax+b$ for any $x \in \mathbb{R}$; if we are to be pedantic with the algebraic nuances, "affine" is the correct term to be used here, "linear" bearing a slightly different - albeit related - meaning).

Proof. Since $f$ is continuous it is automatically Riemann integrable on every compact interval and furthermore the function:
$$\begin{align*}
F \colon \mathbb{R} &\to \mathbb{R}\\
F(x):&=\int_{0}^{x} f(t)\mathrm{d}t
\end{align*}$$
is a primitive of $f$ (by virtue of the Fundamental Theorem of Calculus). The hypothesis relation can be rewritten as $F(x+y)-F(x-y)=2yf(x)$ and bearing in mind the differentiability of $F$ entails indeed:
$$f(x+y)+f(x-y)=2f(x) \tag{*}$$
for any $x \in \mathrm{R}$ and $y>0$, by differentiation with respect to $y$, as you and many other users have pointed out above.
Notice that the above relation is equivalently expressed as:
$$f\left(\frac{u+v}{2}\right)=\frac{f(u)+f(v)}{2} \tag{**}$$
for any real numbers $u, v \in \mathbb{R}$. Indeed, this claim is trivially valid for $u=v$ and in the case $u \neq v$ we can assume without any loss of generality that $u<v$. By setting $x:=\frac{v+u}{2}$ and $y:=\frac{v-u}{2}$ we have $y>0$ and the relation $(^*)$ applied to this particular choice of $x$ and $y$ leads immediately to $(^{**})$.
In order to show that $f$ is affine it suffices to prove that for any $t, x, y \in \mathbb{R}$ one has the relation $f(tx+(1-t)y)=tf(x)+(1-t)f(y)$ (this relation is actually characteristic to affine maps). Indeed, were such a relation to take place we would have:
$$f(x)=f(x1+(1-x)0)=xf(1)+(1-x)f(0)=(f(1)-f(0))x+f(0)$$
valid for any $x \in \mathbb{R}$, rendering $f$ into the desired form. We shall thus consider the set:
$$T:=\{t \in \mathbb{R}|\ (\forall x, y)(x, y \in \mathbb{R} \Rightarrow f(tx+(1-t)y)=tf(x)+(1-t)f(y))\}$$
and make it our subsequent objective to prove that $T=\mathbb{R}$.
We begin by remarking that by definition the set $T$ is stable with respect to the map $t \mapsto 1-t$, in other words that $1-T \subseteq T$ (and since this map is clearly an involution we can furthermore assert that $1-T=T$). It is also immediate that $\{0, 1\} \subseteq T$ and by virtue of relation $(^{**})$ we also gather that $\frac{1}{2} \in T$. Let us now establish in order a number of properties of the set $T$ which will eventually lead us to our desired conclusion:

*

*The relation $\frac{1}{2}(T+T) \subseteq T$ holds, in other words for any $s, t \in T$ their arithmetic mean $\frac{1}{2}(s+t) \in T$ is also in $T$. Considering arbitrary $x, y \in \mathbb{R}$ we have the relations:
$$\begin{align*}
f\left(\frac{s+t}{2}x+\left(1-\frac{s+t}{2}\right)y\right)&=f\left(\frac{sx+(1-s)y}{2}+\frac{tx+(1-t)y}{2}\right)\\
&=\frac{1}{2}f(sx+(1-s)y)+\frac{1}{2}f(tx+(1-t)y)\\
&=\frac{1}{2}(sf(x)+(1-s)f(y))+\frac{1}{2}(tf(x)+(1-t)f(y))\\
&=\frac{s+t}{2}f(x)+\left(1-\frac{s+t}{2}\right)f(y),
\end{align*}$$
which prove our assertion.

*$T$ is a closed subset of $\mathbb{R}$ (with respect to the standard topology, of course). Indeed, consider a fixed pair of elements $x, y \in \mathbb{R}$ and define the map:
$$\begin{align*}
h_{x, y} \colon \mathbb{R} &\to \mathbb{R}\\
h_{x, y}(t)\colon&=f(tx+(1-t)y)-tf(x)+(t-1)f(y).
\end{align*}$$
On account of $f$ being continuous, $h_{x, y}$ will also be continuos for every double index $(x, y) \in \mathbb{R}^2$ and therefore the zero set $h_{x, y}^{-1}[\{0\}]$ will be a closed subset of $\mathbb{R}$. Since by definition:
$$T=\bigcap_{x, y \in \mathbb{R}}h_{x, y}^{-1}[\{0\}]$$
and arbitrary intersections of closed subsets are closed, we conclude that $T$ is closed.

*For arbitrary subsets $M \subseteq \mathbb{R}$ and $N \subseteq \mathbb{R}^{\times}$ write $\frac{M}{N}\colon=\left\{\frac{x}{y}\right\}_{\substack{x \in M \\ y \in N}}$. For any $u \in \mathbb{R}$ similarly write $u^{\mathbb{N}}\colon=\{u^n\}_{n \in \mathbb{N}}$. Here we make the claim that:
$$\frac{\mathbb{N}}{2^{\mathbb{N}}} \cap [0, 1] \subseteq T.$$
Indeed, on the grounds of observation 1) above it is easy to prove by induction on $n \in \mathbb{N}$ that $\frac{1}{2^n}\mathbb{N}\cap [0, 1] \subseteq T$. The base case $n=0$ amounts to the claim $\mathbb{N} \cap [0, 1]=\{0, 1\} \subseteq T$ which we have already remarked is true. Assuming the claim for $n \in \mathbb{N}$ let us prove it for $n+1$. To this end, let $m \in \mathbb{N}$ be such that $\frac{m}{2^{n+1}} \in [0, 1]$ or in other words $0 \leqslant m \leqslant 2^{n+1}$. If $m \leqslant 2^n$ it is clear that $\frac{m}{2^n} \in \frac{1}{2^n}\mathbb{N} \cap [0, 1]$ and owing to the induction hypothesis we gather $\frac{m}{2^n} \in T$. Hence, from 1) we infer that $\frac{m}{2^{n+1}}=\frac{0+\frac{m}{2^n}}{2} \in T$. If on the other hand $2^n<m\leqslant 2^{n+1}$ we derive $0<m-2^n \leqslant 2^n$ and subsequently $\frac{m-2^n}{2^n}=\frac{m}{2^n}-1 \in T$ thanks to the induction hypothesis. Applying observation 1) once again we can infer that $\frac{1+\left(\frac{m}{2^n}-1\right)}{2}=\frac{m}{2^{n+1}} \in T$, since $1 \in T$.


For reasons of a lagging compiler when the input text excedes a certain length limit, I will ask the interested reader to bear with me throughout the next posting, where I will continue this current proof.
A: $$\frac{1}{2y} \int_{x-y}^{x+y} f(t) dt=f(x). $$
D. w.r. t. $y$ using Lebnitz
$$-\frac{1}{2y^2}\int_{x-y}^{x+y} f(t) dt +\frac{1}{2y} [f(x+y)-(-1)f(x-y)]=0$$
Use (1) again to get
$$\implies f(x)=\frac{1}{2}[f(x+y)+f(x-y)].$$
This will be satisfied only by $f(x)=mx+c.$
A: A simpler consideration:
If
$$\frac{1}{2y} \int_{x-y}^{x+y} f(t) dt=f(x).~~~~(1)$$
Then  $$f(0)=\frac{1}{2y} \int_{-y}^{y} f(t) dt. ~~~~(2)$$
Also, for the RHS to be independent of $y$, the only choice is the linear function $f(t)=at+b.$
Then (1) gives the identical linear function: $f(x)=ax+b$.
Next, (2) shows consistency by giving $f(0)=b$ (independent of $y$).
Hence, the solution of (1) is a linear function only.
