How to evaluate sum only when the function is specified explicitly?

How does one instruct Mathematica to perform the following infinite sum only if the function U is specified explicitly?

ωn = 2 π n;
Sum[(ωn^2 + D[U[x], x])/(ωn^2 + k^2 + D[U[x], x]), {n, -Infinity, Infinity}]

Currently the sum evaluates with an error message Sum::div: Sum does not converge."

• Isn't that what is happening already? In other words, in your code Sum returns unevaluated, with a warning. If you don't want the warning, you could use Quiet@Sum[...]. You can still use the return value further. – MarcoB Jul 5 '18 at 20:34
• "...function is specified explicitly"... what do you mean by that? Of course you put in a function. Do you mean instead "...if the sum converges"? – David G. Stork Jul 5 '18 at 20:35
• @DavidG.Stork I think OP meant "only when U[x] has been assigned a specific value". – MarcoB Jul 5 '18 at 20:36
• If you mean when U[x] has a value, then you could do something like sum /; U[x] === Unevaluated[U[x]] := Sum[ ... ], and use sum where you would use Sum[ ... ]. – JungHwan Min Jul 5 '18 at 22:04
• @DavidG.Stork I want to evaluate the sum if and only if the explicit form of the function U[x] is specified. The convergence of the sum depends on the choice of U[x]. – 121 Jul 5 '18 at 23:00

I'm not sure if this accurately tends to the needs of the question but I guess it's a start: