# Dirichlet function
The Dirichlet function is defined by $D:\mathbb{R}\to\{0,1\}$
$$
D(x):=\begin{cases}1,&\text{if }x\in\mathbb{Q}\\0,&\text{if }x\in\mathbb{R}-\mathbb{Q}\end{cases}
$$
**Theorem**
$$
D(x)=\displaystyle\lim_{m\to\infty}[\lim_{n\to\infty}\cos^{2n}(m!\pi x)],\forall x\in\mathbb{R},
$$
where $n,m\in\mathbb{N}$.
**Proof**
Since $0\le\cos^{2n}(m!\pi x)\le 1,\forall n,m\in\mathbb{N}$, the limit always exists for any $x\in\mathbb{R}$.
Suppose $x\in\mathbb{Q}$, then $x=\dfrac{p}{q},q\in\mathbb{N},p\in\mathbb{Z}$.
By taking $m\ge \max(q,2)$, we can eliminate the denominator of $x$ so that $m! x$ is an even integer.
Hence $\cos^{2n}(m!\pi x)=1$ in this case, by taking the limit,
$$
D(x)=\displaystyle\lim_{m\to\infty}[\lim_{n\to\infty}\cos^{2n}(m!\pi x)]=1
$$
if $x\in\mathbb{Q}$.
Suppose $x\in\mathbb{R}-\mathbb{Q}$, then $0<\cos^{2n}(m!\pi x)<1$, and for fixed $x$ and $m$, $\cos^{2n}(m!\pi x)$ is just a geometric sequence with common ratio less than $1$, hence it converges to $0$.
So,
$$
D(x)=0=\displaystyle\lim_{m\to\infty}[\lim_{n\to\infty}\cos^{2n}(m!\pi x)]
$$
if $x\in\mathbb{R}-\mathbb{Q}$.
**Theorem**
$D(x)$ is not Riemann integrable on any closed interval $[a,b]\subseteq\mathbb{R},a<b$.
**Proof**
Suppose that $D(x)$ is integrable on $[a,b]$ for some $a,b\in\mathbb{R},a<b$, then:
For any partition $P=\{x_0,x_1,\dots,x_n\},x_0=a,x_n=b,x_{i-1}<x_i$ of $[a,b]$, take $\delta=\displaystyle\max_{1\le i\le n}\{x_i-x_{i-1}\}$, define $\Delta x_i:=x_{i}-x_{i-1}$ and let $x_{i}^*\in[x_{i-1},x_i]$ be arbitrary.
Hence
$$
\displaystyle\lim_{\delta\to 0}\displaystyle\sum_{i=1}^{n}D(x_{i}^*)\Delta x_i
$$
exists, say its value is $L$.
Since $x_{i}^*\in[x_{i-1},x_i],\forall i$ are arbitrarily chosen, we can choose $x_{i}^*\in\mathbb{Q}$ for each $i$ ($\mathbb{Q}$ is dense in $\mathbb{R}$), and thus the limit becomes:
$$
\displaystyle\lim_{\delta\to 0}\displaystyle\sum_{i=1}^{n}\Delta x_i=L
$$
Clearly, $L=b-a>0$.
But then by choosing $x_{i}^*\in\mathbb{R}-\mathbb{Q}$ for each $i$, the limit becomes:
$$
\displaystyle\lim_{\delta\to 0}\displaystyle\sum_{i=1}^{n}0\Delta x_i=0=L
$$
This contradicts the uniqueness of a limit.
Hence we can conclude that $D(x)$ is not Riemann integrable on any closed interval $[a,b]\subseteq\mathbb{R},a<b$.