Ask Your Question
0

Help with symbolic sum

asked 2015-01-11 14:59:32 +0100

Peter Luschny gravatar image

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

I ask for enlightenment.

edit retag flag offensive close merge delete

Comments

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

tmonteil gravatar imagetmonteil ( 2015-01-11 16:18:24 +0100 )edit

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?

Peter Luschny gravatar imagePeter Luschny ( 2015-01-11 16:45:12 +0100 )edit

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

Nathann gravatar imageNathann ( 2015-01-11 16:57:59 +0100 )edit

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

Peter Luschny gravatar imagePeter Luschny ( 2015-01-11 17:18:20 +0100 )edit

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

Nathann gravatar imageNathann ( 2015-01-11 17:44:41 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-01-11 16:04:24 +0100

Nathann gravatar image

updated 2015-01-11 16:52:41 +0100

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])

edit flag offensive delete link more

Comments

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/

Nathann gravatar imageNathann ( 2015-01-11 16:05:46 +0100 )edit

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

Peter Luschny gravatar imagePeter Luschny ( 2015-01-11 18:08:26 +0100 )edit

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

Peter Luschny gravatar imagePeter Luschny ( 2015-01-11 18:11:27 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-01-11 14:59:32 +0100

Seen: 928 times

Last updated: Jan 11 '15