Evaluating $\int P(\sin x, \cos x) \text{d}x$ Suppose $\displaystyle P(x,y)$ a polynomial in the variables $x,y$. 
For example, $\displaystyle x^4$ or $\displaystyle x^3y^2 + 3xy + 1$.
Is there a general method which allows us to evaluate the indefinite integral

$$ \int P(\sin x, \cos x) \text{d} x$$

What about the case when $\displaystyle P(x,y)$ is a rational function (i.e. a ratio of two polynomials)? 
Example of a rational function: $\displaystyle \frac{x^2y + y^3}{x+y}$.

This is being asked in an effort to cut down on duplicates, see here: Coping with *abstract* duplicate questions.
and here: List of Generalizations of Common Questions.

Calculus books teach an annoying method based around using trig identities to reduce the integral to one where trig substitution can be applied. This method requires a little bit of guess-work to determine which identity should be applied, and my recollection is that it does not always work.
Here is a completely mechanical method which always works, although for simple $P$ it may require more calculation than a smarter method. Instead of using $\sin \theta, \cos \theta$, use the complex exponential $e^{i \theta}$; then Euler's formula $e^{i \theta} = \cos \theta + i \sin \theta$ tells you that
$$\cos \theta = \frac{e^{i \theta} + e^{-i \theta}}{2}, \sin \theta = \frac{e^{i \theta} - e^{-i \theta}}{2i}$$
and now the problem is reduced to integrating a sum of exponentials.
Example. The integral $\int_{0}^{2\pi} \cos^{2n} \theta \, d \theta$ has come up several times on math.SE in one form or another. It is readily solved using this method: write it as
$$\frac{1}{4^n} \int_0^{2\pi} (e^{i \theta} + e^{-i \theta})^{2n} \, d \theta$$
and note that when integrating from $0$ to $2\pi$ all of the terms vanish except the constant term, so the final answer is
$$\frac{2\pi}{4^n} {2n \choose n}.$$
This method generalizes to the case when $P$ is replaced by a rational function; in that case the integrand becomes a rational function of $e^{i \theta}$ (rather than a Laurent polynomial) and using $u$-substitution we can reduce the problem to integrating a rational function, which can be done in a number of ways (partial fractions, residues...). 
