Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 3543 by [email protected]: Infinite loop when doing print() on
summation containing summation
http://code.google.com/p/sympy/issues/detail?id=3543
Trying to execute the following minimal example throws SymPy into an
infinite loop:
from sympy import symbols,summation,binomial,Function
i,n,j=symbols('i n j', integer=True)
t=symbols('t',real=True)
ival=Function('ival')
def Ra(i) : return
summation((-1)**(i+j)*binomial(i,j)*binomial(n,i)*ival(j),(j,0,i))
print(summation(t**i*Ra(i),(i,0,5)))
Curiously replacing 5 by n, i.e. as print(summation(t**i*Ra(i),(i,0,n)))
gives the output:
Sum(t**i*Sum((-1)**(i + j)*ival(j)*binomial(i, j)*binomial(n, i), (j, 0,
i)), (i, 0, n))
so only when the actual finite evaluation is done does the problem surface.
For the finite evaluation, I am able to do:
print(summation(t**i*Ra(i),(i,0,5)).doit())
and it works, but all the same it should not be a problem to output the
expression with the unevaluated inner summation.
When I reported the above on the mailing list, Aaron Meurer replied:
The problem seems to be with the printer. Namely, the printer tries
to order the terms, which involves calling evalf on the summations.
You can see what you would get by
pprint(summation(t**i*Ra(i),(i,0,5)), order='none') (or
sstr(summation(t**i*Ra(i),(i,0,5)), order='none') for the 1-d format).
So there are a few issues here.
First, the printing methods should not call evalf to determine the
order to print things, as it obviously can be too slow.
Second, evalf should not be slow. The summations are finite.
The real issue though is that when you call
summation(t**i*Ra(i),(i,0,5)), the Ra(i) returns the summation
unevaluated. It then apparently doesn't evaluate when the outer
summation is evaluated (this might be considered a SymPy bug).
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.