# Need to take infinite sum of residues, is there a way to choose the order of operations for ReleaseHold?

I'm computing an infinite sum of residues. I want to do something like this:

Sum[Sum[(-1)^n (2 \[Pi] I) Residue[(w^(I nu + n/2) ws^(I nu - n/2))/(I nu + n/2)^2, {nu, I n/2 + I m}], {n, 1, \[Infinity]}], {m, 0, \[Infinity]}]


Evaluated like that, this gives zero. However, if I choose a specific value of m, specifically m=0,

Sum[(-1)^n (2 \[Pi] I) Residue[(w^(I nu + n/2) ws^(I nu - n/2))/(I nu + n/2)^2, {nu, I n/2}], {n, 1, \[Infinity]}]


I get a nonzero result. The problem is that for generic m,

Sum[(-1)^n (2 \[Pi] I) Residue[(w^(I nu + n/2) ws^(I nu - n/2))/(I nu + n/2)^2, {nu, I n/2 + I m }], {n, 1, \[Infinity]}]


is zero. It's only nonzero for m=0.

I thought that I could make this work by using Hold[], holding evaluation of the residue and releasing it outside the infinite sum. But it appears that applying ReleaseHold[] there doesn't fix the problem, it still evaluates the Residue for the generic case before fitting in the specific ones.

Is there a way to make this work, and get the correct answer out of the infinite sum over m?

(By the way, I know that in this case, all terms besides m=0 will be zero. I need the infinite sum because the same setup needs to treat cases where some of those terms are nonzero.)

-
I would say it's a bug. – b.gatessucks Dec 31 '13 at 8:00
I don't think it's fair to say it's a bug, Mathematica just has a fixed way it handles order of operations. But there should be a way around it, no? – Matt Dec 31 '13 at 18:37

It seems that Residue (and Series on which it is based) is unable to analyze all the cases in which the formula for the residue might vary. Reduce can do it, within its limitations, if we reduce the system 1/function == 0 && nu == pole.

Here's the OP's example.

fn = (w^(n/2 + I nu) ws^(-(n/2) + I nu))/(n/2 + I nu)^2;


We need to add some conditions on the system. The result has an unnecessary complication of C[1], but we can deduce that the only cases for which there is a pole is m == 0 && n >= 0:

Reduce[1/fn == 0 && nu == I n/2 + I m &&
m >= 0 && m ∈ Integers && n >= 1 && n ∈ Integers && w != 0 && ws != 0,
{m, n, nu, w, ws}]
(*
C[1] ∈ Integers && w != 0 && ws != 0 && C[1] >= 1 && m == 0 &&
n == C[1] && nu == (I n)/2
*)


Hence we need just one sum:

Block[{m = 0}, Sum[(-1)^n (2 π I) Residue[fn, {nu, I n/2 + I m}], {n, 1, ∞}]]
(*  -((2 (π Log[w] + π Log[ws]))/(1 + ws))  *)


Here's another, albeit similar, example with two special values of m.

fn2 = (w^(n/2 + I nu) ws^(-(n/2) + I nu))/((n/2 + I nu)^2 (2 + n/2 + I nu)^2);

Reduce[1/fn2 == 0 && nu == I n/2 + I m &&
m >= 0 && m ∈ Integers && n >= 1 && n ∈ Integers && w != 0 && ws != 0,
{m, n, nu, w, ws}]
(*
C[1] ∈ Integers && w != 0 && ws != 0 && C[1] >= 1 &&
((m == 0 && n == C[1] && nu == (I n)/2) ||
(m == 2 && n == C[1] && nu == -(1/2) I (-4 - n)))
*)


We can see that there are two cases, m == 0 && n >= 1 and m == 2 && n >= 1.

Block[{m = 0}, Sum[(-1)^n (2 π I) Residue[fn2, {nu, I n/2 + I m}], {n, 1, ∞}]]
Block[{m = 2}, Sum[(-1)^n (2 π I) Residue[fn2, {nu, I n/2 + I 2}], {n, 1, ∞}]]
(*
(π - π Log[w] - π Log[ws])/(2 (1 + ws))
(-π - π Log[w] - π Log[ws])/(2 w^2 ws^2 (1 + ws))
*)


Add these to get the sum over all m >= 0.

If all the use-cases exhibit the same pattern, one could write code to process the results of Reduce and set up the summations.

-
Note: This later question has some of the same problems with the summand behaving differently on generic input: mathematica.stackexchange.com/questions/78945/… – Michael E2 Aug 9 '15 at 17:32