A function constant almost everywhere Q: Suppose $f:\mathbb{R}\rightarrow \mathbb{R}$ is measurable with respect to Lebesgue measure and $f(x)=f(x+1)=f(x+\pi)$ for almost every $x$. Prove that $f$ is constant almost everywhere. 
Proof attempt: Since the ratio of $1$ and $pi$ is irrational, given any real number $r$ we have there exist $m, n\in \mathbb{Z}$ such that $|r-(m+n \pi )|< \epsilon$, so that the set $P=\{m+n\pi : m, n\in \mathbb{Z}\}$ is everywhere dense. 
Now by Lusin's theorem take the interval $[a, b]$, so there is a compact set $E\subset [a,b]$ such that $\mu(E) > (b-a-\delta)$ for some arbitrarily small $\delta$ and so that $f|_{E}$ is continous. Pick a point $x$ like the one in the condition of the problem and any $y\in E$. By continuity of $f$ on $E$ and by the density of $P$ there will be a point such that $|f(x)-f(y)|=|f(x)-f(y)|=|C-f(y)|<\epsilon_{2}$. Taking the limit as $\delta \rightarrow 0$, $f$ is constant almost everywhere on the interval $[a, b]$, and since the interval is arbitrary we can say $f$ is constant almost everywhere.
Does this look alright? Is there another way of doing this without invoking something like Lusin's theorem? Measurable functions can be very ugly, so are there any other results similar to Lusin's theorem that allow us to put some sort of regularity on measurable functions and gain some intuition about them?
Thanks in advance! 
 A: This answer explains my idea from the comment in more detail.
First, you can not truncate $f$ in such a way that the truncated version is in $L^1$, because this will destroy periodicity.
My idea was to consider
$$
g := f \cdot \chi_{|f| \leq n}.
$$
You should verify that $g$ is again "periodic" in the same sense as $f$ is (and bounded).
Now take any approximation of the identity (e.g. $h_\varepsilon = \varepsilon^{-n} \cdot h(x/\varepsilon)$, where $h \in C_c$ with $\int h \, dx = 1$) and consider the family of convoultion products
$$
F_\varepsilon := (g \ast h_\varepsilon) (x) = \int g(x-y) h_\varepsilon (y) \, dy.
$$
It is then not too hard to show that $g \ast h_\varepsilon$ is continuous and is periodic in the classical sense with periods $1,\pi$, i.e. $F_\varepsilon (x) = F_\varepsilon (x+1) = F_\varepsilon (x+\varepsilon)$ for all $x$. This is so, because the integral used in the definition of $F_\varepsilon$ does not "see" the null-set on which this property might fail for $g$ (or $f$).
Now conclude (using a variant of your proof) that $F_\varepsilon \equiv C_\varepsilon$ for some constant $C_\varepsilon$.
By classical theorems about approximation by convolution, you also get $F_\varepsilon (x) \to g(x)$ almost everywhere (at every Lebesgue-point of $g$, see e.g. Why convolution of integrable function $f$ with some sequence tends to $f$ a.e.).
This will allow you to conclude $g \equiv c$ almost everywhere and then also that $f \equiv c'$ almost everywhere for some constant $c'$.
A: An alternative proof is this, given by Nathan Chen:
First note that $\{{a+b\pi}\}$ for $a,b$ in $\mathbb{Z}$ is dense in $\mathbb{R}$. Now partition $\mathbb{R}$ into disjoint intervals $E_n$ where each $E_n = f^{-1}[n,n+1)$. It suffices to show $f$ is constant a.e. on $[0,1]$ so we can restrict ourselves to the unit interval.
Now, as $[0,1] = \bigcup E_n$ we have that there exists an $N$ such that $E_N$ has positive measure (otherwise the unit interval would have measure zero). As $E_N$ has positive measure, by Lebesgue density we can find a Lebesgue point $x$ such that for $0 < \alpha < 1$ there is a ball of arbitrarily small radius $\epsilon = a + b\pi$ for $a,b$ integers such that $m(E_N \cap B(x,\epsilon)) > 2\epsilon\alpha$ (since by Lebesgue density, we have that the limit approaches $1$ as the radius goes to $0$). Moreover we can choose our $x$ to satisfy the assumed hypothesis above (the "almost-everywhere periodicity").
But we also have that $m(E_N\cap B(x+2k\epsilon,\epsilon))>2\epsilon\alpha$ for any integer $k$ since Lebesgue measure is translation invariant and by our "almost-everywhere periodicity". Then we can write $E_N = \bigcup_k E_N \cap B(x+2k\epsilon,\epsilon)$, which is a disjoint union such that $x+2k\epsilon$ remains in $[0,1]$. Taking the measure of both sides we have that $m(E_N) > \alpha$ as a sum over approximately $\frac{1}{2\epsilon}$ terms. But as $\alpha$ was arbitrary, we can let $\alpha$ tend to $1$, so that $m(E_N) = 1$. So $f$ maps $[0,1]$ into $[N,N+1)$ almost everywhere.
To conclude the proof, we can then partition $[N,N+1)$ even smaller, maybe with $[N+mq, N+(m+1)q)$ for $q$ rational and arbitrarily small, and $m$ non-negative integer, applying the same proof above we can continue to shrink the range of f until we obtain that $f$ hits just a point a.e.
