I'm having some trouble with
Mod[k, 2] == 0
versus
EvenQ[k]
They are sometimes yielding different results when given the same input.
A function I'm attempting to define:
sinmultipletheta[n_] :=
ComplexExpand[Im[(Cos[θ] + I Sin[θ])^n]] /.
{Cos[θ]^k_ ->
If[Mod[k, 2] == 0,
(1 - Sin[θ]^2)^(k/2),
(1 - Sin[θ]^2)^((k - 1)/2) Cos[θ]]} // Expand
This yields the correct answer. For example,
sinmultipletheta[9]
9 Sin[θ] - 120 Sin[θ]^3 + 432 Sin[θ]^5 - 576 Sin[θ]^7 + 256 Sin[θ]^9
When I replace Mod[k, 2] == 0
above with EvenQ[k]
, that is if I define
sinmultipletheta[n_] :=
ComplexExpand[
Im[(Cos[θ] + I Sin[θ])^n]] /.
{Cos[θ]^k_ ->
If[EvenQ[k],
(1 - Sin[θ]^2)^(k/2),
(1 - Sin[θ]^2)^((k - 1)/2) Cos[θ]]} // Expand
then
sinmultipletheta[9]
Sin[θ]^9 + 9 Cos[θ] Sin[θ] Sqrt[1 - Sin[θ]^2] - 111 Cos[θ] Sin[θ]^3 Sqrt[1 - Sin[θ]^2] + 321 Cos[θ] Sin[θ]^5 Sqrt[1 - Sin[θ]^2] - 255 Cos[θ] Sin[θ]^7 Sqrt[1 - Sin[θ]^2]
In this case, it seems my conditional statement is always evaluated as though it were false.
Any insight?
EvenQ[expr]
returnsFalse
unlessexpr
is manifestly an even integer (i.e. has headInteger
, and is even)". This is different fromMod
andDivisible
. $\endgroup$