4. Given $\cos \alpha+\cos \beta=a, \sin \alpha+\sin \beta=b, a^{2}+b^{2} \neq$ 0. Write the expression for $\cos (\alpha+\beta)$ in terms of $a$ and $b$.
$$
\begin{array}{l}
\cos \alpha+\cos \beta=2 \cos \frac{\alpha+\beta}{2} \cdot \cos \frac{\alpha-\beta}{2}=a, \\
\sin \alpha+\sin \beta=2 \sin \frac{\alpha+\beta}{2} \cos \frac{\alpha-\beta}{2}=b,
\end{array}
$$

We can get $\operatorname{tg} \frac{\alpha+\beta}{2}=\frac{b}{a}$.
$$
\begin{array}{l}
\because \cos x=\frac{1-\operatorname{tg}^{2} \frac{x}{2}}{1+\operatorname{tg}^{2} \frac{x}{2}}, \\
\therefore \cos (\alpha+\beta)=\frac{1-\left(\frac{b}{a}\right)^{2}}{1+\left(\frac{b}{a}\right)^{2}}=\frac{a^{2}-b^{2}}{a^{2}+b^{2}} .
\end{array}
$$