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.
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:
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.