Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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 *)
share|improve this answer
Of course, one could also use Assuming[]. – J. M. Apr 24 '13 at 13:43
Huh, I had something like Simplify[Cos[π n/2], n ∈ Integers && Mod[n, 2] == 1] in mind... – J. M. Apr 25 '13 at 12:43
You said "append", but this is not correct: Note that using Simplify[Sqrt[x^2], Assumptions -> x>0 ] will use only that one assumption in the Simplify command. If you previously set global assumptions in $Assumptions, these will (temporarily) be ignored. Instead, you can use Simplify[Sqrt[x^2], x>0 ] - here, the new assumption is truly appended. – Martin J.H. Aug 20 '14 at 14:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.