Re: Question: how to get Sin[n*Pi]=0 (n integer)
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1990] Re: Question: how to get Sin[n*Pi]=0 (n integer)
- From: Bob Hanlon <hanlon at pafosu2.hq.af.mil>
- Date: Mon, 4 Sep 1995 22:23:34 -0400
In cleaning up the rules for handling integer multiples of Pi/2 (e.g., eliminating separate cases for integer multiples of Pi since they are just special cases), I noticed that I left out a minus sign in one of the Cos terms (and hence Sec). Below is a cleaned up version. Sorry for any inconvenience. I have left out the output. Bob Hanlon _______________ (* Extend definitions of standard functions IntegerQ, EvenQ, OddQ, Positive, Negative, NonNegative *) Unprotect[ IntegerQ, EvenQ, OddQ, Positive, Negative, NonNegative ]; Clear[ IntegerQ, EvenQ, OddQ, Positive, Negative, NonNegative ]; IntegerQ[ m_?IntegerQ + n_?IntegerQ ] = True; IntegerQ[ m_?IntegerQ * n_?IntegerQ ] = True; IntegerQ[ m_?IntegerQ ^ n_Integer?NonNegative ] = True; IntegerQ[ x_ ^ (-n_) ] := IntegerQ[ (1/x)^n ]; EvenQ[ x_?EvenQ + y_?EvenQ ] = True; (* 2m+2n = 2(m+n) *) EvenQ[ x_?OddQ + y_?OddQ ] = True; (* (2m+1)+(2n+1) = 2(m+n+1) *) EvenQ[ x_?EvenQ * y_?IntegerQ ] = True; (* 2m n = 2(m n) *) EvenQ[ x_?EvenQ ^ n_Integer?Positive ] = True; OddQ[ x_?OddQ + y_?EvenQ ] = True; (* (2m+1) + 2n = 2(m+n)+1 *) OddQ[ x_?OddQ * y_?OddQ ] = True; (* (2m+1)(2n+1) = 2(2m*n+m+n)+1 *) OddQ[ x_?OddQ ^ n_Integer?NonNegative ] = True; NonNegative[ x_?NonNegative + y_?NonNegative ] = True; NonNegative[ x_?NonNegative * y_?NonNegative ] = True; NonNegative[ x_?NonNegative ^ y_Integer?Positive ] = True; Positive[ x_?Positive + y_?Positive ] = True; Positive[ x_?Positive * y_?Positive ] = True; Positive[ x_?Negative * y_?Negative ] = True; Positive[ x_?Positive ^ n_Integer ] = True; Positive[ x_?Negative ^ n_?EvenQ ] = True; Negative[ x_?Negative + y_?Negative ] = True; Negative[ x_?Negative * y_?Positive ] = True; Negative[ x_?Negative ^ n_?OddQ ] = True; Protect[ IntegerQ, EvenQ, OddQ, Positive, Negative, NonNegative ]; (* Define setPos, setNeg, setNonNeg, setEven, setOdd *) Clear[ setPos, setNeg, setNonNeg, setEven, setOdd ]; setPos::usage = "setPos[varSeq] sets Positive and NonNegative to True, and Negative to False for symbols given in varSeq."; setNeg::usage = "setNeg[varSeq] sets Negative to True, and Positive and NonNegative to False for symbols given in varSeq."; setNonNeg::usage = "setNonNeg[varSeq] sets NonNegative to True, and Negative to False for symbols given in varSeq."; setInteger::usage = "setInteger[varSeq] sets IntegerQ to True for symbols given in varSeq."; setEven::usage = "setEven[varSeq] sets IntegerQ and EvenQ to True, and OddQ to False for symbols given in varSeq."; setOdd::usage = "setOdd[varSeq] sets IntegerQ and OddQ to True, and EvenQ to False for symbols given in varSeq."; setPos[varSeq__Symbol] := Module[ { varList = {varSeq} }, (#/: Positive[#] = True )& /@ varList; (#/: NonNegative[#] = True )& /@ varList; (#/: Negative[#] = False)& /@ varList ]; setNeg[varSeq__Symbol] := Module[ { varList = {varSeq} }, (#/: Negative[#] = True )& /@ varList; (#/: Positive[#] = False)& /@ varList; (#/: NonNegative[#] = False)& /@ varList ]; setNonNeg[varSeq__Symbol] := Module[ { varList = {varSeq} }, (#/: NonNegative[#] = True )& /@ varList; (#/: Negative[#] = False)& /@ varList ]; setInteger[varSeq__Symbol] := Module[ { varList = {varSeq} }, (#/: IntegerQ[#] = True )& /@ varList ]; setEven[varSeq__Symbol] := Module[ { varList = {varSeq} }, (#/: IntegerQ[#] = True )& /@ varList; (#/: EvenQ[#] = True)& /@ varList; (#/: OddQ[#] = False)& /@ varList ]; setOdd[varSeq__Symbol] := Module[ { varList = {varSeq} }, (#/: IntegerQ[#] = True )& /@ varList; (#/: EvenQ[#] = False)& /@ varList; (#/: OddQ[#] = True)& /@ varList ]; (* Extend definitions of standard trig functions *) Unprotect[Sin, Csc, Cos, Sec, Tan, Cot]; Clear[evenMultPi2Q, oddMultPi2Q, Sin, Csc, Cos, Sec, Tan, Cot]; evenMultPi2Q::usage = "evenMultPi2Q[x] returns True if x is an even integer multiple of Pi/2."; oddMultPi2Q::usage = "oddMultPi2Q[x] returns True if x is an odd integer multiple of Pi/2."; evenMultPi2Q[x_] := EvenQ[2x/Pi]; oddMultPi2Q[x_] := OddQ[2x/Pi]; pwr1 = { (-1)^(n_?EvenQ + a_:0) :> (-1)^a, (-1)^(n_?OddQ + a_:0) :> -(-1)^a, (-1)^(1 + x_) :> -(-1)^x }; Sin[ y_?evenMultPi2Q ] := 0; Sin[ y_?oddMultPi2Q ] := (-1)^Expand[(2y/Pi - 1)/2] //. pwr1; Sin[ x_ + y_?evenMultPi2Q ] := (-1)^Expand[y/Pi] Sin[x] //. pwr1; Sin[ x_ + y_?oddMultPi2Q ] := (-1)^Expand[(2y/Pi - 1)/2] Cos[x] //. pwr1; Csc[ y_?evenMultPi2Q ] = ComplexInfinity; Csc[ y_?oddMultPi2Q ] := (-1)^Expand[(2y/Pi - 1)/2] //. pwr1; Csc[ x_ + y_?evenMultPi2Q ] := (-1)^Expand[y/Pi] Csc[x] //. pwr1; Csc[ x_ + y_?oddMultPi2Q ] := (-1)^Expand[(2y/Pi - 1)/2] Sec[x] //. pwr1; Cos[ y_?evenMultPi2Q ] := (-1)^Expand[y/Pi] //. pwr1; Cos[ y_?oddMultPi2Q ] = 0; Cos[ x_ + y_?evenMultPi2Q ] := (-1)^Expand[y/Pi] Cos[x] //. pwr1; Cos[ x_ + y_?oddMultPi2Q ] := (-1)^Expand[(2y/Pi + 1)/2] Sin[x] //. pwr1; Sec[ y_?evenMultPi2Q ] = (-1)^Expand[y/Pi] //. pwr1; Sec[ y_?oddMultPi2Q ] := ComplexInfinity; Sec[ x_ + y_?evenMultPi2Q ] := (-1)^Expand[y/Pi] Sec[x] //. pwr1; Sec[ x_ + y_?oddMultPi2Q ] := (-1)^Expand[(2y/Pi + 1)/2] Csc[x] //. pwr1; Tan[ y_?evenMultPi2Q ] = 0; Tan[ y_?oddMultPi2Q ] = ComplexInfinity; Tan[ x_ + y_?evenMultPi2Q ] := Tan[x]; Tan[ x_ + y_?oddMultPi2Q ] := -Cot[x]; Cot[ y_?evenMultPi2Q ] = ComplexInfinity; Cot[ y_?oddMultPi2Q ] = 0; Cot[ x_ + y_?evenMultPi2Q ] := Cot[x]; Cot[ x_ + y_?oddMultPi2Q ] := -Tan[x]; Protect[ Sin, Csc, Cos, Sec, Tan, Cot ]; funcs = {Sin, Cos, Tan, Csc, Sec, Cot}; setInteger[m, n]; setEven[keven]; setOdd[kodd]; TableForm[ Table[#[x + n Pi/2], {n, 0, 4}]& /@ funcs, TableHeadings -> { None, {x, x + Pi/2, x + Pi, x + 3Pi/2, x + 2k Pi} } ] TableForm[ Partition[ Flatten[ { f[n Pi/2], f[keven Pi/2], f[kodd Pi/2] } /. {f -> #}& /@ funcs ], 3], TableSpacing -> {1, 5} ] test = {comment, f[a b Pi/2 + x], f[a b Pi + x] } /. { {comment -> "integers:", a -> n, b -> m}, {comment -> "one even:", a -> 2n, b -> m}, {comment -> "both even:", a -> 2n, b -> 2m}, {comment -> "one odd:", a -> 2n+1, b -> m}, {comment -> "both odd:", a -> 2n+1, b -> 2m+1} }; TableForm[test /. f -> Sin, TableSpacing -> {2, 5} ] (* very slow *) TableForm[test /. f -> Cos, TableSpacing -> {2, 5} ] (* very slow *)