When you see the word “almost” in a mathematical context, it might be used informally, but often it has a precise meaning. I wrote about this before in the post Common words that have a technical meaning.
Often the technical meaning of “almost” is “within any finite tolerance.” That’s how it is used in the context of almost periodic functions.
A function f is periodic with period T if for all x,
f(x + T) = f(x)
For example, the sine function is periodic with period 2π.
So what does almost periodic mean? It means that for any ε > 0, there exists a T > 0 such that
|f(x + T) − f(x)| < ε
for all x. Note that the value of T depends on the value of ε. You tell me your tolerance for “almost” and in theory I could hand you back T that meets your tolerance.
That’s in theory. Can we actually do it in practice? Let’s consider
f(t) = sin(2παt) + sin(2πβt)
where α/β is irrational. In the previous post we had α = 1/log 2 and β = 1/log 5.
The Hurwitz approximation theorem says that because α/β is irrational, there are infinitely many integers p and q such that
|α/β – p/q| < 1/(√5q²).
To put it another way, we can find p and q such that
|qα – pβ| < β/√5q,
i.e. we can find p and q such that qα and pβ are close together as we wish by looking for a large enough q, and Hurwitz promises us that we can find a q as large as we want.
If we let T = q/α then the first component of f is exactly periodic, i.e.
sin(2πα(t + q/α) = sin(2παt).
With a little effort we can show that
sin(2πβ(t + q/α)) = sin(2πβt + 2π(qβ − pα)t/α)
and we said above we can make
qβ − pα
as small as we like by choosing a large enough q in Hurwitz’ theorem. And so we can choose q large enough that
sin(2πβ(t + q/α)) − sin(2πβt)
is uniformly as small as we’d like.
One of the standard reference works for the number-theoretic aspects of almost periodic (as well as limit-periodic!) functions is the book “Arithmetical Functions” from Schwarz and Spilker: https://www.cambridge.org/core/books/arithmetical-functions/504B94E03437D4788E67D6EFCD2F9376
(also the chapters on Ramanujan Expansions are worth the read!)