Function with arbitrary small period

Solution 1:

You're right. The characteristic function of the rationals is periodic of period $1/n$ for all $n \in \mathbb N$ because $x$ is rational iff $x+1/n$ is rational.

Solution 2:

You're correct.

Let $\epsilon$ be arbitrarily small. You need to prove that there exists some $0<p<\epsilon$ such that $D(x)=D(x+p)$ for all $x\in \mathbb{R}$.

We know that $\epsilon$ is some positive real number, so there exists some $p\in \mathbb{Q}$ such that $0<p<\epsilon$. Let's look at an arbitrary $x\in \mathbb{R}$ and see if our property is satisfied or not:

If $x$ is rational, then $D(x)=1$. Since the sum of two rationals is rational, then $D(x+p)=1$ too.

If $x$ is irrational, then $D(x)=0$. Since the sum of a rational and an irrational is irrational, then $D(x+p)=0$ too.

So if we choose our period to be $p$, our property is satisfied.