Ask Your Question

Revision history [back]

There is already a problem in the h() function:

sage: h(4,4,2,x,0)
1/3*x^3 - 1/2*x^2 - 1/12*x - 7/8
sage: h(4,4,2,x,0)(x=1)
sage: h(4,4,2,1,0)

First, your sum is indexed on non-integer entries as x+n+(k+1)/2+1-i may not be an integer. You should fix this if possible (i am not sure how the symbolic sum() handles this, and this might be a reason for this weird behaviour).

Then, you should make a difference between symbolic variables and python variables.

A symbolic variable is defined with the var() function ; these are elements of the Symbolic Ring, they somehow play the role of the identity function x |--> x and are not aimed at receiving a value:

sage: var('x')
sage: x.derivative()

But then writing:

sage: x = 2

just overwrites the previous value of x (which was a kind of identity map), and make x an integer. If you want to evaluate the symbolic variable x at the point 2, you will have to write

sage: x(x=2)


You can read more about symbolic expressions here.

When you write:

t = var('t')

and later:

for t in range(2,2*x+2*n+2):

Then the t stops being a symbolic variable and becomes a python integer, and the first line was useless.

All variables that aim to recieve a value (e.g. i=2) should be python variables, not symbolic ones (though, you could call h(4,4,2,var('y'),0) but in this case the symbolic variable y is the value recieved by the parameter x).

When you write:

def h(i,j,k,x,n):

i,j,k,x,n are python parameters. They will eventually get a value. If some of them (x?) has to remains a symbolic varialbe until the end, it should not be a parameter of your function. So the question is: which variable in your expression will remain an unknown at the end ?

This is somehow the same difference between the function sum() and making a loop: the first one works symbolically and can take symbolic variables as endpoints (like for computing an integral with formulas), the second cannot since it does the computation by effectively adding the elements one by one.

That said, it is still possible that there is a bug with symbolic summations of binomals, but you should first try to clean the two mentionned issues.

I hope i am not too confusing.