Be $B$ a basis of $\mathbb R$ as vector space over $\mathbb Q$, then it is immediately clear that for any $b,b'\in B$, we can independently choose $f(b)$ and $f(b')$ because the addition theorem doesn't relate values in different $\mathbb Q$-subspaces of $\mathbb R$.
We can remove this ambiguity by additionally demanding that $f$ is continuous. Then the values of $f$ on the rational numbers determine the values on the irrational numbers by continuity. Therefore in the following I'll assume $f$ is continuous.
First, I'll put forward a few general properties of the solutions:
Observation 1: For any fixed $g(x)$, the set $V_g:=\{f:f(x+y)=f(x)g(y)+f(y)g(x)\}$ is a vector space.
Proof:
- The function $f(x)=0$ obviously is in $V_g$.
- if $f_1\in V_g$ and $f_2\in V_g$ then also $f=f_1+f_2\in V_g$:
$$\begin{align}
f(x+y) &= f_1(x+y)+f_2(x+y)\\
&= f_1(x)g(y)+f_1(y)g(x) + f_2(x)g(y)+f_2(y)g(x)\\
&= (f_1(x)+f_2(x))g(y) + (f_1(y)+f_2(y))g(x)\\
&= f(x)g(y) + f(y)g(x)
\end{align}$$
- If $f\in V_g$, then also $F=\alpha f\in V_g$:
$$F(x+y)=\alpha f(x+y) = \alpha (f(x)g(y)+f(y)g(x)) = \alpha f(x)g(y) + \alpha f(y)g(x) = F(x)g(y)+F(y)g(x)$$
This observation means that we only have to find a basis for each $g$, and can then get the other functions as linear combinations.
Note that in proving the vector space property, we've actually already proved the
- First solution: $\color{red}{f(x)=0}$
Observation 2: If $f(x)$ is a solution with $g(x)$ as "companion function", then for any $\alpha$, $f_\alpha(x):=f(\alpha x)$ is a solution with $g_\alpha(x):=g(\alpha x)$ as companion function.
Proof:
$$f_\alpha(x+y) = f(\alpha(x+y)) = f(\alpha x+\alpha y) = f(\alpha x)g(\alpha y)+f(\alpha y)g(\alpha x) = f_\alpha(x)g_\alpha(y)+f_\alpha(y)g_\alpha(x)$$
This scaling property will prove quite handy.
Observation 3: If $f(x)$ is a solution with the function $g(x)$, then $f_\lambda(x):=f(x)\mathrm e^{\lambda x}$ is a solution with the function $g_\lambda(x):=g(x)\mathrm e^{\lambda x}$.
Proof: $f_\lambda(x+y) = f(x+y)\mathrm e^{x+y} = (f(x)g(y)+f(y)g(x))\mathrm e^{x+y} = f(x)\mathrm e^xg(y)\mathrm e^y + f(y)\mathrm e^yg(x)\mathrm e^x = f_\lambda(x)g_\lambda(y)+f_\lambda(y)g_\lambda(x)$.
Note that this observation already allows to derive some new solutions in addition to those found in the question, for example $\mathrm e^x\sin x$ is another such function.
Observation 4: If $g(0)=0$, then $f(x)=0$ is the only element of $V_g$
Proof: We have $f(x) = f(0+x) = f(0)g(x) + g(0)f(x)$. Since by assumption $g(x)=0$, we get $f(x) = f(0)g(x)$. But for $x=0$ this means $f(0) = f(0)g(0) = 0$, therefore $f(x)=0$ for all $x$.
Observation 4 means that for any non-trivial solution, we have $g(0)\ne 0$.
Observation 5: If for any $x_0$ we have $f(x_0)=0$, then $f(0)=0$.
Proof: We have $0 = f(x_0) = f(0 + x_0) = f(0)g(x_0) + f(x_0)g(0) = f(0)g(x_0)$. So either $f(0)=0$ or $g(x_0)=0$. In the latter case, $f(x+x_0) = f(x)g(x_0)+f(x_0)g(x)=0$ for all $x$, that is, we would have the trivial solution, which of course also has $f(0)=0$ (as can be seen also directly by inserting $x=-x_0$).
Observation 5 means we have at most three types of solutions:
- Solutions which are zero at some $x_0\ne 0$ (and additionally at $x=0$).
- Solutions which are zero only at $x=0$.
- Solutions that are nowhere zero.
Let's first consider the case that there's an $x_0\ne0$ so that $f(x_0)=0$.
Since we have proved that $g(x_0)=0$ only admits the trivial solution, we can in the following assume $g(x_0)\ne 0$.
Observation 6: If $f(x_0)=0$ and $f(y_0)=0$, then $f(x_0+y_0)=0$.
Proof: This follows directly from the sum formula: $f(x_0+y_0) = f(x_0)g(y_0) + g(x_0)f(y_0) = 0$
From this observation one gets immediately:
Observation 7: If $f(x_0)=0$, then $f(n x_0)=0$ for all $n\in\mathbb N$.
Proof by induction:
- For $n=0$, we have proved it in observation 4.
- For $n=1$, it is just the assumption.
- If we have proven it for $n$,
$f((n+1) x_0) = f(n x_0 + x_0) = 0$ by observation 5.
Observation 8: If $f(x_0)=0$, then $f(-x_0)=0$.
Proof: $0 = f(-x_0 + x_0) = f(-x_0)g(x_0)+f(x_0)g(-x_0) = f(-x_0)g(x_0)$. Since $g(x_0)\ne 0$, we must have $f(-x_0)=0$
Observations 7 and 8 together mean that if $f(x_0)=0$, then $f(nx_0)=0$ for all $n\in\mathbb Z$.
Observation 9: There's a minimal $x_0$ so that $f(x_0)=0$.
Proof: If there were no such minimal $x_0$, then for any $\epsilon>0$ we would find an $x_1<\epsilon$ so that $f(x_1)=0$. But with that and the fact that with $x_1$, also all $nx_1$ are zeros of $f$, it is easy to create a series of zeros converging to an arbitrary real number, so we would have $f(x)=0$ for all $x$.
To simplify our notation, we can use the scaling property (observation 2) to assume without loss of generality that the first positive zero of $f(x)$ is $1$. Then the previous result mean that $f(n)=0$ for all $n\in\mathbb Z$.
Observation 10: There are no non-integer values $x_0$ so that $f(x_0)=0$.
Proof: If there were such a value, then $f(x_0-\lfloor x_0\rfloor)=0$. But $0<x_0-\lfloor x_0\rfloor<1$, contrary to the assumption that $1$ is the smallest positive zero of $f$.
Observation 11: $f(x+n) = f(x)g(1)^n$
Proof: We have $f(x+1)=f(x)g(1)$, which implies $f(x+n)=f(x)g(1)^n$. On the other hand, a direct application of the sum formula gives $f(x+n)=f(x)g(n)$. Thus $g(n) = g(1)^n$.
Observation 12: $g$ vanishes for all $n+\frac12$.
Proof: For $n$ odd, we get $0 = f(n) = f(\frac n2+\frac n2) = 2f(\frac n2)g(\frac n2)$. Since $n$ is odd, $f(\frac n2)\ne 0$, and therefore $g(n/2)=0$.
To simplify the further considerations, use the vector space property (observation 1) together with the knowledge that $f(\frac12)\ne0$ to fix without loss of generality $f(\frac12)=1$.
Observation 13: $g(x)=f(x+\frac12)$.
Proof: By the addition property, $f(x+\frac12)=f(x)g(\frac12)+g(x)f(\frac12)$. Bur $g(\frac12)=0$ (observation 12) and $f(\frac12)=1$ (we just fixed that value).
Observation 14: $g(x+y)=g(x)g(y)+f(x+1)f(y)$
Proof: $g(x+y) = f(\frac12+x+y) = f(\frac12+x)g(y) + f(y)g(\frac12+x) = g(x)g(y)+f)y=f(\frac12+\frac12+x)$.
Observation 15: $g(n) = g(1)^n$
Proof: By induction: $g(n+1) = g(n)g(1) + f(n+1)f(1) = g(n)g(1)$.
Note that the same recursion formula can be used also backwards, so it is true for all $n$.
Now we can use observation 3 (the exponential factor property) to reduce our considerations to the two cases $g(1)=1$ and $g(1)=-1$. Then of course $g(n)=(\pm 1)^n$. Especially $g(-1)=g(1)$ and $g(2)=1$.