MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Question: how to get Sin[n*Pi]=0 (n integer)

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg1975] Re: Question: how to get Sin[n*Pi]=0 (n integer)
  • From: econrad at math.ohio-state.edu (Eric Conrad)
  • Date: Mon, 4 Sep 1995 22:20:55 -0400
  • Organization: Department of Mathematics, The Ohio State University

In article <DE3sCL.Gr9 at wri.com>, Rex Dieter <rdieter at mathlab41.unl.edu> wrote:
>In article <DDuM67.IuF at wri.com> izovko at dominis.phy.hr (Ilija I Zovko) writes:
>
>> How can one tell Mathematica to simplify Sin[n Pi]=0 or
>> Cos[n Pi]=(-1)^n and similar kind of stuff.
>
>That's a good question.  Mathematica normally can't make assumptions like "n  
>is an integer)", and I'm not sure how to do this easily.  Perhaps try the  
>following... say you want to simplify an expression "expr" that contains the  
>constructs you describe above.  To get the simplifications you desire, simply  
>execute:  ...

One can easily extend the rules in Mathematica.  For example, if 'n' is
a free variable you want Mathematica to treat as an integer, you can
try:
    (1) Unprotect[IntegerQ];
    (2) IntegerQ[n] := True
    (3) Protect[IntegerQ];

Notice that there is no underscore after the n in line (2).  Unfortunately
this won't get Sin to evaluate Sin[n Pi].  You can work around that
problem as follows:
    (4) Unprotect[Sin, Cos];
    (5) Sin[x_ Pi] /; IntegerQ[x] := 0
    (6) Cos[x_ Pi] /; IntegerQ[x] := (-1)^x
    (7) Protect[Sin, Cos];

This will give you the result you need for Sin[n Pi] and Cos[n Pi]
but you'll be disappointed by Sin[2 n Pi] and Cos[2 n Pi].  But you
can work around this by defining integers to be closed under addition and
multiplication and additive inverses:
    (8) Unprotect[IntegerQ];
    (9) IntegerQ[-x_] := IntegerQ[x]
    (10) IntegerQ[x_+y_] /; IntegerQ[x] && IntegerQ[y] := True
    (11) IntegerQ[x_ y_] /; IntegerQ[x] && IntegerQ[y] := True
    (12) Protect[IntegerQ];

(Note) The following would be INCORRECT:
    (10') IntegerQ[x_+y_] := IntegerQ[x] && IntegerQ[y]
as can be seen from the example IntegerQ[1/2 + 1/2]

If you lose track of rule changes, say for IntegerQ, type
    (13) ?? IntegerQ
In addition to displaying the usage information for IntegerQ, any
user-defined rules are displayed.

Eric


  • Prev by Date: Help reduce this expression (Not Long)
  • Next by Date: Re: Q: ArcTan[ Tan[ x ] ] = x
  • Previous by thread: Re: Question: how to get Sin[n*Pi]=0 (n integer)
  • Next by thread: Re: Help in defining nearly orderless function