Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
2  
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

1 Answer 1

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
1  
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

Your Answer

 
discard

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.