Revision history [back]

You're getting the TypeError because you're double-assigning x: in your second line, you make it a list of variables, but in the third you redefine it as a symbolic variable. The f(x)=sum(x[i],i,0,n) line is translated as

sage: preparse("f(x) = sum(x[i], i, 0, n")
'__tmp__=var("x"); f = symbolic_expression(sum(x[i], i, Integer(0), n).function(x)'

Unfortunately we can't simply rename x to xx: the "f(x,y) = x+y" syntax requires explicit specification of the variable, and you can't pass it a list. So for a fixed n (which is the only case I really know how to handle offhand) I would probably do this instead:

sage: n = 2
sage: xx = [var('x_%d' % i) for i in range(n)]
sage:
sage: f = sum(xx).function(*xx)
sage: f
(x_0, x_1) |--> x_0 + x_1

[Here I took advantage of the * operator in *xx, which turns f(*[a,b,c]) into f(a,b,c).]

You're getting the TypeError because you're double-assigning x: in your second line, you make it a list of variables, but in the third you redefine it as a symbolic variable. The f(x)=sum(x[i],i,0,n) line is translated as

sage: preparse("f(x) = sum(x[i], i, 0, n")
'__tmp__=var("x"); f = symbolic_expression(sum(x[i], i, Integer(0), n).function(x)'

Unfortunately we can't simply rename x to xx: the "f(x,y) = x+y" syntax requires explicit specification of the variable, variables, and you can't pass it a list. So for a fixed n (which is the only case I really know how to handle offhand) I would probably do this instead:

sage: n = 2
sage: xx = [var('x_%d' % i) for i in range(n)]
sage:
sage: f = sum(xx).function(*xx)
sage: f
(x_0, x_1) |--> x_0 + x_1

[Here I took advantage of the * operator in *xx, which turns f(*[a,b,c]) into f(a,b,c).]

You're getting the TypeError because you're double-assigning x: in your second line, you make it a list of variables, but in the third you redefine it as a symbolic variable. The f(x)=sum(x[i],i,0,n) line is translated as

sage: preparse("f(x) = sum(x[i], i, 0, n")
'__tmp__=var("x"); f = symbolic_expression(sum(x[i], i, Integer(0), n).function(x)'

Unfortunately we can't simply rename x to xx: the "f(x,y) = x+y" syntax requires explicit specification of the variables, and you can't pass it a list. So for a fixed n (which is the only case I really know how to handle offhand) I would probably do this instead:

sage: n = 2
sage: xx = [var('x_%d' % i) for i in range(n)]
sage:
sage: f = sum(xx).function(*xx)
sage: f
(x_0, x_1) |--> x_0 + x_1

[Here I took advantage of the * operator in *xx, which turns f(*[a,b,c]) into f(a,b,c).]

Oh, I've just noticed that I used [0..n-1] as the indices and I think you're using [0..n], but that's easy to change.