# Simplify $\cos(n \pi)$ and $\sin(n \pi)$ when n is an integer

I was trying to calculate this integral in Mathematica 9:

2/π Integrate[ Cosh[a x] Cos[n x], {x, 0, π}, Assumptions -> n ∈ Integers]


I got as a result :

$$\frac{2 (a \sinh (\pi a) \cos (\pi n)+n \cosh (\pi a) \sin (\pi n))}{\pi \left(a^2+n^2\right)}$$

That's the same result I obtained manually, but how can I force Mathematica to change $\sin(n \pi)$ into $0$ and $\cos(n \pi)$ into $(-1)^n$ ?

-
Did you already try Assuming[Element[n, Integers], 2/Pi Integrate[Cosh[a x] Cos[n x], {x, 0, Pi}]]? – J. M. Jun 22 '13 at 9:34
Thank you, it does work indeed, what's wrong with the form I used ? (Assumptions -> ...) Maybe you could post this as an answer so I can award you the points – Skydreamer Jun 22 '13 at 9:35
I'm not quite sure why one works and the other doesn't, even though they are ostensibly equivalent; the reason I left a comment is because I am not at a machine with Mathematica. Might I suggest writing your own answer to your own question instead? – J. M. Jun 22 '13 at 9:39
I'm on it, thank you for the help ! – Skydreamer Jun 22 '13 at 9:41
You can do it also this way: Simplify[2/Pi Integrate[Cosh[a x] Cos[n x], {x, 0, Pi}], Element[n, Integers]], it should work in more general cases than your original problem. – Artes Jun 22 '13 at 9:41

Thanks to 0x4A4D and Artes, I figured out what the problem was.

2/π Integrate[ Cosh[a x] Cos[n x], {x, 0, π}, Assumptions -> n ∈ Integers]


into

Assuming[ n ∈ Integers, 2/π Integrate[ Cosh[a x] Cos[n x], {x, 0, π}]]


or

Simplify[ 2/π Integrate[ Cosh[a x] Cos[n x], {x, 0, π}], n ∈ Integers]


I don't know what's the problem with the first form but still, it works !

-
If you set the assumptions outside the scope of Integrate[], that is inside Assuming[] or Simplify[] then Integrate[] doesn't mess with them. That is how I understand it. Check this link also. mathematica.stackexchange.com/questions/19833/… – Zet Nov 11 '13 at 9:36