Jenny recently learnt the trigonometric angle-sum identities in mathematics class.
\[
\begin{array}{l}
\sin (\alpha+\beta)=\sin \alpha \cos \beta+\cos \alpha \sin \beta \\
\sin (\alpha-\beta)=\sin \alpha \cos \beta-\cos \alpha \sin \beta \\
\cos (\alpha+\beta)=\cos \alpha \cos \beta-\sin \alpha \sin \beta \\
\cos (\alpha-\beta)=\cos \alpha \cos \beta+\sin \alpha \sin \beta
\end{array}
\]
She also learnt about the Pythagorean identity: \( \sin ^{2} \theta+\cos ^{2} \theta=1 \)
which is a useful trick to simplify expressions.
Eager to apply what she's learnt, she asks her teacher for a challenge.
Her teacher poses the following problem:
If \( \sin x+\sin y=a \), and \( \cos x+\cos y=b \), what would be the value of \( \cos (x-y) \) in terms of \( a \) and \( b \) ?
(Assume a and b are both nonzero.)