0

As a SymPy newbie, I am considering the following SymPy expression (which should be equal to 1 if 0<x<1):

f = Sum((2/(lambda_m*besselj(1, lambda_m)))*besselj(0,x*lambda_m), (m, 1, oo))

where lambda_m is the m-th zero of besselj(0,x).

Now, mpmath has a function besseljzero(0,m,0) which computes exactly this.

Unfortunately, if I replace (manually, I mean...) lambda_m by besseljzero(0,m,0) in the upper formula, SymPy gives me an error because m is not an integer...

I imagine solving this issues by creating a function which should:

  • return j0(m) if m does not evaluate to an integer
  • return besseljzero(0,m,0) if it does

But I do not know how to proceed.

Is this a good idea, and can somebody help me?

Wrzlprmft
  • 4,234
  • 1
  • 28
  • 54

1 Answers1

0

The problem is that MPMath is for numeric evaluation and usually gives you numerical approximations, while SymPy operates symbolically: arbitrary precision is not the same as infinite precision. You cannot calculate an infinite sum of output from MPMath, as you would actually have to deal with infinitely many summands.

To compute your sum symbolically, SymPy must have representations of all arguments and be aware of the identity you are describing (f(x)==1 if 0<x<1) or be able to derive it. This does not seem to be the case.

Thus all you can do is to approximate the result numerically, e.g., using the implementations from MPMath:

from mpmath import besseljzero, besselj
from itertools import count

threshold = 1e-5
min_m = 100

def f(x):
    Sum = 0
    for m in count(1):
        lambda_m = besseljzero(0,m,0)
        summand = 2/(lambda_m*besselj(1, lambda_m))*besselj(0,x*lambda_m)
        Sum += summand
        if m>min_m and abs(summand)<threshold:
            break
    return Sum
Wrzlprmft
  • 4,234
  • 1
  • 28
  • 54
  • Sorry - the last part of my comment was dropped by the system Obviously, it is possible to program this function explicitely - this is not my point... if besselzero(0,m,0) would behave exactely as besselj(0,x), everything would be ok. My question was: is it possible to write a sympy function which behave like besselj(0,x) (or sin(x), for instance)? Probably using besseljzero(0,m,0) in its code... I hopethis is clearer... Regards – P. Weiss May 02 '17 at 08:01
  • If I understand your desire correctly, this should be addressed in the second paragraph of my answer. – Wrzlprmft May 02 '17 at 08:19
  • Well.. The purpose of all this exercise is to show that the igven expression is effectively equal to 1 between 0 and 1 - So the identity f(x)==1 if 0 – P. Weiss May 04 '17 at 13:41
  • Sure, but to show this, SymPy has to have the capabilities compute the infinite sum. And this can only work if the summands are purely symbolical (and understood by SymPy). So at the very least, there must be an abstract representation of the zeroes (that SymPy can handle) or there must be an analytic expression. Both do not seem to exist. – Wrzlprmft May 04 '17 at 13:48
  • I shall try to explain better... This formula (an other ones similar to it..) is obtained symbolically with sympy. Now, is my derivation correct? How quick does the sum xonverge? I am quite conscious that sympy will be unable to compute the sum to m=infinity. However, I would like to substitute infinity by - let's say - 100, and to do the sum. This shoud work nicely. Only, I cannot introduce the besselj0(0,m,0) in the general formula - I have to substitute them in a loop AFTER fixing m. – P. Weiss May 05 '17 at 14:39
  • @P.Weiss: *Only, I cannot introduce the besselj0(0,m,0) in the general formula - I have to substitute them in a loop AFTER fixing m.* – Exactly. It seems that you solved your own problem (if not; I fail to understand what it is). – Wrzlprmft May 05 '17 at 14:48