Using OddQ and EvenQ in piecewise functions: Buggy?
As suggested by J.M., the solution is to use Mod
:
f[k_] := Piecewise[{{1, k==0}, {x^k/k!, Mod[k, 2]==1}, {x^k/k!, Mod[k, 2]==0}}]
This returns the expected values for both
Sum[f[k], {k,0,5}]
and for
Sum[f[k], {k, 0, Infinity}]
As an interface-design issue, the choice to make *Q
functions return a value even for generic symbols seems like a very poor and inconsistent one. But at least now I know to be wary...