V 12.1 on windows.
I remember asking something similar many years ago. I was hoping Mathematica now could have done this automatically:
$$ \int_{-\pi}^{\pi} \cos (n x) \cos (m x) \, dx $$
For integers $n,m$ is zero for $n \ne m$ and $\pi$ for $n=m$. This can be verified as follows
Clear["Global`*"];
res = Flatten[
Table[{n, m, Integrate[Cos[n x] Cos[m x], {x, -Pi, Pi}]},
{n, 1,5}, {m, 1, 5}], 1];
Grid[PrependTo[res, {"n", "m", "result"}], Frame -> All]

I was looking at this at Maple forum question, and saw that Maple 2020 can now give this result automatically as shown there, which is by using
restart;
int(cos(n*x)*cos(m*x), x = -Pi..Pi, allsolutions) assuming n::posint,m::posint
convert(%, piecewise, n);
Mathematica does not do the above directly
Assuming[Element[{n, m}, Integers],
FullSimplify[Integrate[Cos[n x] Cos[m x], {x, -Pi, Pi}]]]
(*0*)
Assuming[Element[{n, m}, Integers] && n > 0 && m > 0,
FullSimplify[Integrate[Cos[n x] Cos[m x], {x, -Pi, Pi}]]]
(*0*)
I had to do the following to get same result. Which is more work compared to Maple (one has to know to take the limit).
res = Integrate[Cos[n x] Cos[m x], {x, -Pi, Pi}]
Assuming[Element[m, Integers], Limit[res, n -> m]]
(* Pi *)
Assuming[Element[{n, m}, Integers] && n != m, Simplify@res]
(* 0 *)
Any one knows or a trick to make Integrate do the following automatically without having to do post-processing each time? Assumptions are needed ofcourse.
Is the reason Integrate does not do it automatically because needing to use Limit to get the right result?



sol[m_, n_] = Integrate[ Piecewise[{{Cos[n x] Cos[m x], m != n}, {1, m == n == 0}}, Cos[n x]^2], {x, -Pi, Pi}]and for the integer caseAssuming[Element[{m, n}, Integers], sol[m, n] // Simplify]– Bob Hanlon May 20 '20 at 17:39