# Help with symbolic sum

Simple things that I will do with Maple in seconds, with Sage often drive me desperate to Ask-Sage. Sigh.

With Maple:

for n from 0 to 4 do add(j!*stirling1(n,j)*(x-1)^(-j-1), j=0..n) od;

1
-----
x - 1

1
--------
2
(x - 1)

1          2
- -------- + --------
2          3
(x - 1)    (x - 1)

2          6          6
-------- - -------- + --------
2          3          4
(x - 1)    (x - 1)    (x - 1)


With Sage 6.3:

x = SR.var('x')
for n in range(4):
S = sum(factorial(j)*stirling_number1(n,j)*(x-1)^(-j-1) for j in (0,n))
print S


Returns:

2/(x - 1)
(x - 1)^(-2)
2/(x - 1)^3
6/(x - 1)^4
24/(x - 1)^5


Or:

from sage.calculus.calculus import symbolic_sum
x, j = SR.var('x, j')
for n in range(5):
S = symbolic_sum(factorial(j)*stirling_number1(n,j)*(x-1)^(-j-1),j,0,n)
print S


Returns:

TypeError: unable to convert x (=j) to an integer


edit retag close merge delete

What is your question ? Why are you unhappy with your first attempt ?

I am unhappy because the results of Maple and Sage obviously diverge and I suspect that Maple's answer is the correct one; or isn't it?

You used (0,n), and this thing is a pair. What you wanted to use was range(n+1) or [0..n].

+1 for Nathann. Yes. Thanks. I was hopping between different languages until I was blind. Nathann please convert your comment to an answer and I will accept it.

It also appears at the bottom of my other answer. But I will never compare to tmonteil where it comes to Karma!

Sort by » oldest newest most voted

One alternative: instead of having a loop and a 'print', you build the list of your expressions. On this list, you can call "view":

view([sum(factorial(j)*stirling_number1(n,j)*(x-1)^(-j-1) for j in (0,n)) for n in range(4)])


The problem that you meed in your second code is that 'stirling1' does not understand symbolic variables

sage: stirling_number1(4,3)
6
sage: stirling_number1(4,x)
TypeError: unable to convert x to an integer
sage: stirling_number1(x,4)
TypeError: unable to convert x to an integer


EDIT: If you want this loop to work, you cannot use 'symbolic_sum', as it feeds stirling_number1 with a symbolic variable. You must build a list and use 'sum'

for n in range(5):
S = sum(factorial(j)*stirling_number1(n,j)*(x-1)^(-j-1) for j in range(n))
print S


EDIT2: I just understood that your problem was not the hard-to-read output but the results themselves. Instead of (0,n) (which is the PAIR (0,n)) you probably want to use range(n+1) or [0..n])

more

A comment about "Simple things that I will do with Maple in seconds, with Sage often drive me desperate to Ask-Sage. Sigh": Sage is an open-source software. You did not pay for Sage, but you have to pay for Maple. Sage is not selling licenses to hire engineers. The way Sage works is the following: if you need sage to do something, come code it. Others will benefit from it. http://www.sagemath.org/doc/developer/

Sorry for my frustrated initial comment; I appreciate the work of the open-source developers very high (otherwise I would not try to switch from Maple to Sage).

For your EDIT2 I accept your answer. Note that you can also write (0..n) for the range (what I usually do).