What determines if a function has a least positive period? This question stems from this one, where if $f$ is continuous and $f(x) = f(x+1) = f(x+\pi)$, then $f$ must be constant. The above is shown using the density of $\mathbb{Z}+\pi\mathbb{Z}$ in $\mathbb{R}$ and the continuity of $f$. However, what jumps out at me from the question is the (seeming) incongruity of a period that is both rational and irrational.
Specifically, if $f$ is non-constant and has a least positive period, $T$, then it cannot be that $f(x)=f(x+1)=f(x+\pi)$, since that would imply that $\pi$ is rational. But, as was pointed out to me, this cannot be used to prove the above because not every periodic function has a least positive period.
So my question is, what determines if a function has a least positive period? Are there certain classes of functions that, if periodic, must have a least positive period? For instance, continuous periodic functions?
Also, what other examples are there of non-constant periodic functions that do not have a least positive period? The example given to me (and the only one given on the Wikipedia page) is the indicator function of rational numbers.
 A: For a given function $f$, consider the set $P = \{ p \in \mathbb{R} \mid \forall x \in \mathbb{R} : f(x+p) = f(x) \}$. Clearly $0 \in P$, and if $p, q \in P$ also $p - q \in P$. That means $P$ is a subgroup of the additive group of the real numbers. Several cases can arise


*

*$P = \{0\}$. In that case $f$ is not periodic at all.

*$P = p\mathbb{Z}$ for some $p > 0$. Then $p$ is the least period of $f$.

*$P = \mathbb{R}$. This is the case for constant functions.

*$P$ is a dense proper subgroup of $\mathbb{R}$, as in your example of the indicator function of the rationals, where $P = \mathbb{Q}$.


No other subgroups exist.
To construct an arbitrary periodic function, you can take any nontrivial
subgroup $P$ and define an arbitrary function on the quotient $\mathbb{R}/P$. This fixes the whole function, since it must be constant on every coset of $P$. 
In case 2 the quotient can be represented as the interval $[0, p)$; for case 4
this tends to be trickier, but a slightly more interesting example would be
$$
f(x) =  \begin{cases}
  p  & \text{for}\, x = q + \sqrt{p},\; q \in \mathbb{Q}, p \,\text{prime}, \\
  0  & \text{otherwise}.
\end{cases}
$$
A: The other answers are very good.  Here is a 1915 theorem of Burstin that also seems relevant:

If a Lebesgue measurable function $f: \mathbb{R} \rightarrow \mathbb{R}$ has arbitrarily small periods, then $f$ is constant almost everywhere.

A nice proof is given in this one page MONTHLY note of J.M. Henle.  A comment at the bottom claims that Burstin's original proof was faulty.
A: It seems that a nonconstant continuous periodic function must have a least positive period. First, if there are periods arbitarily close to zero, then pick your favorite point $x$ and value $f(z)$. Since the periods are getting smaller and smaller, there must be a sequence of $z_n \rightarrow x$ with $f(z_i) = f(z)$ for all $i$. Hence $f(z) = f(x)$ by continuity, violating that $f$ is nonconstant. So there is some positive lower bound $L$ to the set of periods.
If there is a sequence of periods $p_i \neq L$ converging to $L$, then $f(x + L) = f(x) = f(x + L + p_i)$ and so we have a sequence of periods converging to zero. So $L$ must be a period.
