# Can Mathematica check if two expressions give the same output for integer input?

Let me give the background for this question. I'm using WebAssign to assign homework problems, and WebAssign has a built-in mechanism which can grade problems using Mathematica commands. For instance, if the solution to a problem is $e^{x+y}$ then it is possible to use the Simplify command to ensure that $e^x e^y$ is marked as correct.

I'm currently assigning problems on Fourier series, and expressions like $\cos(n \pi)$ occur frequently. It is fairly standard practice to rewrite $\cos(n \pi)$ as $(-1)^n$, and I want these two expressions to be treated as equivalent (as well as similar expressions for $\cos(n \pi /2)$, etc.) The problem is that these expressions are only equal on the integers, and so Mathematica has no reason to believe they are the same. I suppose I could just write some code which plugs in the first hundred integers and checks to see if the values are the same, but I'm wondering if there's a more elegant solution.

-
If you denote in Simplify that n is an integer it will simplify it to the form $(-1)^n$. –  Spawn1701D Apr 24 '13 at 13:05
Silly answer: did you contact the WebAssign math editor, or other WebAssign tech support, for help on this? –  murray Apr 24 '13 at 15:04

Table[Simplify[f[Pi n], Element[n, Integers]], {f, {Cos, Sin}}]
(* {(-1)^n, 0} *)

Simplify[Cos[Pi n/2], Element[n, Integers]]
(* Cos[(n Pi)/2] *)


You could do something about this differently I guess ... what, as @J. M. suggests, you could append an assumption that n is odd eg.

Simplify[Cos[Pi n/2],
Element[n, Integers],
Assumptions -> Mod[n, 2] == 1]
(* 0 *)

-
Of course, one could also use Assuming[]. –  Ｊ. Ｍ. Apr 24 '13 at 13:43
Huh, I had something like Simplify[Cos[π n/2], n ∈ Integers && Mod[n, 2] == 1] in mind... –  Ｊ. Ｍ. Apr 25 '13 at 12:43