TITLE: Function with arbitrary small period
QUESTION [10 upvotes]: Is there a function f: $\mathbb{R} \to \mathbb{R}$ with arbitrary small period different from $f(x) = k$? ($\forall \epsilon >0  \exists a < \epsilon $ such that f(x) has a periodicity $a$) 
I think the function is the Dirichlet function but I don't know how to prove it properly.

REPLY [4 votes]: The main question has been answered in other answers well enough, but I would like to address a few natural follow-up questions. What about continuous functions $f$ with this property?
It turns out that in this case there are no nontrivial solutions - every such function is constant. Here's a topological proof: Let $K=\{x\in\Bbb R\mid \forall y, f(y)=f(x+y)\}$ be the set of periods of $f$. If $f$ is continuous, then this is an intersection of the sets $\{x\in\Bbb R\mid f(y)=f(x+y)\}$, which is closed (it is the preimage of $\{0\}$ under the function $g(x)=f(y)-f(x+y)$), so $K$ itself is closed. $K$ is also dense in $\Bbb R$, because it is an additive group with arbitrarily small elements, so $K=\Bbb R$ and hence $f(x)=f(y)$ for all $x,y\in \Bbb R$.
If we consider discontinuous functions again, then we know $K$ is a dense additive subgroup of $\Bbb R$. Does every dense additive subgroup generate such a function? Yes, we can just take the characteristic function of $K$. For a fixed $K$, the space of such functions is just all functions $\Bbb R/K\to \Bbb R$. This is another way to get at the constancy result, since as a topological group, $\Bbb R/K$ has the indiscrete topology, because any open set will cover $\Bbb R$ if copied around with translations by $K$.
Of course $\Bbb R/K$ can be uncountable, for example if $K=\Bbb Q$ or any other countable subgroup. Can it be countable or finite? It can be countable assuming some choice, as observed in TomGrubb's answer. If we consider a Hamel basis $B$ of $\Bbb R$ over $\Bbb Q$, then the set of all real numbers with zero first projection is a subgroup $K$ of $\Bbb R$ for which $\Bbb R/K\simeq \Bbb Q$.
But it can't be finite (unless it is trivial). In other words, there is no coherent way to talk about real numbers being partitioned into the "even" and "odd" ones. If $\Bbb R/K$ has $n>1$ elements, then that means that every number which is a multiple of $n$ is in $K$; but every real number is a multiple of $n$, to wit, $x=n(x/n)$.