0
$\begingroup$

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."

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – MarcoB Jul 5 '18 at 20:34
  • $\begingroup$ "...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"? $\endgroup$ – David G. Stork Jul 5 '18 at 20:35
  • $\begingroup$ @DavidG.Stork I think OP meant "only when U[x] has been assigned a specific value". $\endgroup$ – MarcoB Jul 5 '18 at 20:36
  • 3
    $\begingroup$ 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[ ... ]. $\endgroup$ – JungHwan Min Jul 5 '18 at 22:04
  • $\begingroup$ @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]. $\endgroup$ – 121 Jul 5 '18 at 23:00
2
$\begingroup$

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

sum[U_?((Head[#]===Symbol//Not)&), var_,k_]:=Module[{dU=D[U,var]},
   Sum[((2 π n)^2 + dU)/((2 π n)^2 + k^2 + dU), 
     {n, -Infinity, Infinity}]
 ]

In a nutshell, sum evaluates when U is not a symbol.

Obviously this is not a foolproof way to check if there is a function defined with that head. I suspect that a more thorough solution would have to go through the DownValues and perhaps OwnValues (check thoroughly what kind of definitions are associated with symbol U).

$\endgroup$
  • $\begingroup$ This does it -- thanks! $\endgroup$ – 121 Jul 6 '18 at 16:13
  • $\begingroup$ Great to know it helps; you're welcome $\endgroup$ – yosimitsu kodanuri Jul 7 '18 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.