# Evaluating ∫P(sinx,cosx)dx\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

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.

There are several general approaches to integrals that involve expressions with sines and cosines, polynomial expressions being the simplest ones.

### Weierstrass Substitution

A method that always works is Weierstrass substitution, which will turn such an integral into an integral of rational functions, which in turn can always be solved, at least in principle, by the method of partial fractions. This works even for rational functions of sine and cosine, as well as functions that involve the other trigonometric functions.

Weierstrass substitution replaces sines and cosines (and by extension, tangents, cotangents, secants, and cosecants) by rational functions of a new variable. The identities begin by the trigonometric substitution $t = \tan\frac{x}{2}$, with $-\pi\lt x\lt \pi$, which yields

For example, if we have

using the substitution above we obtain:

which can then be integrated by the method of partial fractions.

### Substitutions and Reduction formulas

However, there are usually faster methods, particularly for polynomial expressions. By breaking up the integral into a sum of integrals corresponding to the monomials, the problem reduces to solving integrals of the form

with $n$ and $m$ nonnegative integers. The standard methods then are:

1. If $n$ is odd, then “reserve” one sine, and transform the others into cosines by using the identity $\sin^2 x = 1-\cos^2x$. Then do the change of variable $u=\cos x$ to transform the integral into the integral of a polynomial. For example,

then take $(\sin x)^5$, and write it as

Then setting $u=\cos x$ and $du = -\sin x\,dx$, we get

which can be solved easily.

2. If $m$ is odd, then do the same trick by by “reserving” one cosine and using the substitution $u=\sin x$. For example,

and then setting $u=\sin x$, $du = \cos x\,dx$, we get

which can be solved easily again.

3. If $n$ and $m$ are both even, then either replace all the sines with cosines or vice versa, using $\sin^2 x = 1 - \cos^2x$ or $\cos^2x = 1-\sin^2 x$, and expand. This will leave integrals of the form

with $n$ and $m$ even positive and even. In that situation, one can use the reduction formulas, which can be obtained by using integration by parts:

By repeated application of these formulas, one eventually ends up with an integral of the form $\int \,dx$ which can be solved directly.

The process can be shortened if you happen to spot or know some trigonometric identities; for example, the power reduction formulas allow you to replace powers of sines or cosines by expressions of multiple angles, e.g.,

could replace a single integral with three integrals that can be done fairly easily via substitution.

### Other methods

If you are comfortable enough integrating functions with a complex variable in it, then the method described by Qiaochu will transform any integral that involves sines and cosines in any way into an integral that involves exponential functions instead.