$f(x)=\cos(ax) + \sin(bx)$ 
With the restriction $a \ne 0, b \ne 0 $
why $$f(x)=\cos(ax) + \sin(bx)$$ is periodic if and only if $a/b \,  
 \in \mathbb{Q} $?

I tried to justify, but I don't know how to justify that if $h=f+g$, being $f$ of periods $p_1=2\pi/a\times m,$ and $g$ of periods $p_2=2\pi/b\times n$, $m,n\in\mathbb Z\backslash\{0\}$, then for $h$ to be periodic there must be $m,n$ such that $p_1=p_2$.
I've seen several answers here but none seemed enlightening and direct enough.
 A: Recall that a function $f$ on $\mathbb{R}$ is said to be $p$-periodic, $p > 0$, if
$$f(x) = f(x + p)$$
for all $x \in \mathbb{R}$. (We remark that this does not mean that $p$ is the minimal period of $f$. For example, $1$, $\sin(x)$, $\cos(2022x)$ are all $2\pi$-periodic functions.)
Observation. Consider a function $f$ on $\mathbb{R}$ that is continuous and $p$-periodic for some $p > 0$. For each $r > 0$ and $x \in \mathbb{R}$, we define $f_r(x)$ by
$$ f_r(x) := \lim_{n\to\infty} \frac{\sum_{j=0}^{n-1} f(x+jr)}{n}. $$

*

*Case 1. Suppose $p/r \in \mathbb{Q}$ so that $p/r = a/b$ for some $a, b \in \mathbb{Z}^+$. Then $bp = ar$ implies that $j \mapsto f(x + jr)$ is $a$-periodic. Using this, it is not hard to verify that $f_r(x)$ exists and satisfies
$$
f_r(x) = \frac{\sum_{j=0}^{a-1} f(x+jr)}{a}
$$
for each $x \in \mathbb{R}$. In particular, $f_r$ is well-defined as a function on $\mathbb{R}$ and $p$-periodic.


*Case 2. Suppose $p/r \notin \mathbb{Q}$. Then by the equidistribution theorem,
$$
f_r(x) = \frac{1}{q} \int_{0}^{q} f(t) \, \mathrm{d}t.
$$
Consequently, $f_r$ is constant on all of $\mathbb{R}$.
We also observe:

*

*It is clear that $f_p(x) = f(x)$ for all $x \in \mathbb{R}$.


*If $f$ is both $p$-periodic and $q$-periodic for some $p, q > 0$ with $p/q \notin \mathbb{Q}$, then Case 2 shows that $f = f_q$ must be constant.

Now returning to the original question, we make the following assumption:

Assumption. $f$ and $g$ are non-constant continuous function on $\mathbb{R}$, and there exist $p, q > 0$ with $p/q \notin \mathbb{Q}$ such that

*

*$f$ is $p$-periodic, and

*$g$ is $q$-periodic.


Our goal is to show that $h = f + g$ is not periodic. To this end, assume otherwise that $h$ is $r$-periodic for some $r > 0$. Then either $p/r \notin \mathbb{Q}$ or $q/r \notin \mathbb{Q}$. By swapping the roles of $f$ and $g$ if necessary, we may assume that $q/r \notin \mathbb{Q}$. Then
$$ h(x) = h_r(x) = f_r(x) + g_r(x) = f_r(x) + g_r(0) $$
This shows that $h$ is $p$-periodic, so the same is true for $ g(x) = h(x) - f(x) $. This then forces that $g$ is both $p$-periodic and $q$-periodic, hence $g$ is constant, contradicting the assumption. Therefore the desired claim is established.
A: Let the period of $h(x)$ and $g(x)$ be $T_1$ and $T_2$, respectively then
$$f(x)=\alpha g(x) + \beta h(x)$$ will be periodic iff $T_1/T_2$ is rational. The period of $f(x)$ is usually given by $T=\text{LCM}(T_1,T_2)$ provided there exists no   $P<T$, such that $f(x+P)=f(x)$, then $P$ would be the period.
So $f(x)=\cos ax +\sin bx$ will be periodic if $a/b$ is rational.Here  $T_1=2\pi/a, T_2=2\pi/b$, then $T=2\pi ~\text{LCM}(1/a,1/b).$.
If $p,q,r,s,u,v$ are positive integers  $$\text{LCM}(p/q,r/s,u/v)=\frac{\text{LCM}(p.r,u)}{\text{HCF}(q,s,v)}.$$
Note that
(1) $\sin(x\sqrt{2})$  and $\cos(x)$ are peripdic but $f(x)=\sin(x\sqrt{2})+\cos x$ is not periodic because $T_1/T_2$ is not rational.
(2) The period of $f(x)=|\sin x|+ |\cos x|$ is $\pi/2$ and npt $\pi$.
A: $\cos(ax)+\sin(bx)$ is periodic iff $\cos(x)+\sin\left(\frac{b}{a}x\right)$ is periodic, so let us set $r=\frac{b}{a}$ and focus on
$$ f_r(x) = \cos(x)+\sin(rx) $$
under the assumption $r\in\mathbb{R}\setminus\mathbb{Q}$.  If $f_r(x)$ is periodic with period $T\neq 0$ the same holds for $f_r''(x)$ and $f_r(x)+f_r''(x)$.
On the other hand
$$ f_r(x)+f_r''(x) = (1-r^2)\sin(rx) $$
so $T\in\frac{2\pi}{r}\mathbb{Z}\setminus\{0\}$. This leads to a contradiction since for any element $t$ of this set
$$ f_r(x+t)-f_r(x) = \cos(x+t)-\cos(x) \neq 0. $$
A: For the function to be periodic, there must be some number $p$ such that:
$$f(x) = f(x + p)$$
$$\cos(ax) + \sin(bx) = \cos(ax + ap) + \sin(bx + bp)$$
$$\cos(ax) + \sin(bx) = \cos(ax)\cos(ap) - \sin(ax)\sin(ap) + \sin(bx)\cos(bp) + \cos(bx)\sin(bp)$$
This equation is true for all $x$ if:
$$\cos(ap) = 1, \sin(ap) = 0, \cos(bp) = 1, \sin(bp) = 0$$
Which is equivalent to both $ap$ and $bp$ being integer multiples (not necessarily the same integer) of $2\pi$.  That is, $\exists m, n \in \mathbb{Z}: ap = 2\pi m, bp = 2\pi n$.  So $\frac{a}{b} = \frac{ap}{bp} = \frac{2\pi m}{2 \pi n} = \frac{m}{n} \in \mathbb{Q}$.
