Double limit of $\cos^{2n}(m! \pi x)$ at rationals and irrationals I stumbled upon this "relation" (is the name correct?):
$$
\lim_{m \to \infty} \lim_{n \to \infty} \cos^{2n}(m! \pi x) = \begin{cases}
1,&x\text{ is rational}\\
0,&x\text{ is irrational}\end{cases}
$$
How is it called and why is it so? I'm really not asking for a proof since I fear it would be too complicated for me to understand, but rather for an "intuition".
 A: This is known as Dirichlet Function,
If $m!x$ is an integer, then $\cos^{2n}(m!\pi x) = 1$.
If $x$ is rational $\frac{p}{q}$, then, eventually, for large enough $m$, $m!$ will be divisible by $q$ (and stay so for all larger m), so that $m!x$ will be an integer, and we have what we want.
If $x$ is irrational, $m!x$ will never be an integer, and $|\cos(m!\pi x)| \lt 1$, so that $\lim_{n \to \infty} \cos^{2n}(m!\pi x) = 0 $ for all $m>0$.
A: The intuition is already almost the proof.


*

*The cosine takes values between $-1$ and $1$, inclusive

*Taking an even power ensures that the values are between $0$ and $1$.

*Taking higher and higher powers will not affect those $x$ where the cosine squared is $1$, but all other values will converge to $0$


Thus $f(x):=\lim_{n\to\infty}\cos^{2n}(x)$ is a function that has value $0$ for all $x$, except that $f(x)=1$ if $\cos(x)=\pm1$, i.e. if $x$ is a multiple of $\pi$.
After this, we see that multiplying the argument with $\pi$ is done to have the value $1$ at integers instead of multiples of $\pi$. Then the multiplication with $m!$ serves the purpose to obtain $1$ for any integer multiple of $\frac1{m!}$. As $m\to \infty$, this exhausts the rationals (and only them).
A: First notice that $-1\le\cos m!\pi x\le 1$ for all $m$ and $x$, so $0\le\cos^2m!\pi x\le 1$. Suppose that $0\le y\le 1$; then 
$$\lim_{n\to\infty}y^n=\begin{cases}
0,&\text{if }y\ne 1\\
1,&\text{if }y=1\;.
\end{cases}\tag{1}$$
Now $\cos^2 m!\pi x=1$ if and only if $m!x$ is an integer. Say $m!x=a$ for some integer $a$; then $x=\frac{a}{m!}$, a rational number. Thus, $m!x$ is never an integer when $x$ is irrational, and therefore for all $m$ we have $\cos^2m!\pi x\ne 1$. $(1)$ then implies that $$\lim_{n\to\infty}\cos^{2n}m!\pi x=0$$ for all $m$, and of course in that case $$\lim_{m\to\infty}\lim_{n\to\infty}\cos^{2n}m!\pi x=\lim_{m\to\infty}0=0\;.$$
This explains why the limit is $0$ when $x$ is irrational.
If $x$ is rational, on the other hand, we can write $x=\frac{a}b$ for some integers $a,b$ with $b>0$. Then for all $m\ge b$ we can be sure that $m!x$ is an integer and hence that $\cos^2m!\pi x=1$. But then the sequence
$$\left\langle\cos^{2n}m!\pi x:n\in\Bbb N\right\rangle$$
is constantly $1$ for $m\ge b!$, so for $m\ge b!$ we have
$$\lim_{n\to\infty}\cos^{2n}m!\pi x=1\;.$$
But then the sequence $$\left\langle\lim_{n\to\infty}\cos^{2n}m!\pi x:m\in\Bbb N\right\rangle$$
is constantly $1$ for $m\ge b!$, and
$$\lim_{m\to\infty}\lim_{n\to\infty}\cos^{2n}m!\pi x=1\;.$$
