Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

implicitly defining a sequence of variables

To define a general polynomial in Maple one writes

p := sum(a[i]*x^i,i=0..n);

and gets $p = \sum _{i=0}^{n}a_{{i}}{x}^{i}$.

So the "a[i]" are implicitly understood as variables, and their number (n) is also a variable. Or perhaps "a" is implicitly understood as a sequence of variables? I don't know what happens behind the scenes here, but is is very usefull.

Trying to accomplish this in sage I reached

sage: var('x,i,n')
(x, i, n)
sage: a = function('a')
sage: p = sum(a(i)*x^i,i,0,n);p
sum(x^i*a(i), i, 0, n)

Is this the right way? It doesn't behave as nice as in maple. Trying series, taylor, and diff only taylor works correctly:

sage: p.series(x==0,3)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
....
RuntimeError: power::eval(): division by zero
sage: p.taylor(x,0,3) 
x^3*a(3) + x^2*a(2) + x*a(1) + a(0)
sage: p.diff(x)              
i*x^(i - 1)*a(i)*D[0](sum)(x^i*a(i), i, 0, n)

In Maple they all give good results.

Am I going at this the right way? Is there a way to implicitly define variables as in Maple?

implicitly defining a sequence of variables

To define a general polynomial in Maple one writes

p := sum(a[i]*x^i,i=0..n);

and gets $p = \sum _{i=0}^{n}a_{{i}}{x}^{i}$.

So the "a[i]" are implicitly understood as variables, and their number (n) is also a variable. Or perhaps "a" is implicitly understood as a sequence of variables? I don't know what happens behind the scenes here, but is it is very usefull.

Trying to accomplish this in sage I reached

sage: var('x,i,n')
(x, i, n)
sage: a = function('a')
sage: p = sum(a(i)*x^i,i,0,n);p
sum(x^i*a(i), i, 0, n)

Is this the right way? It doesn't behave as nice as in maple. Trying series, taylor, and diff only taylor works correctly:

sage: p.series(x==0,3)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
....
RuntimeError: power::eval(): division by zero
sage: p.taylor(x,0,3) 
x^3*a(3) + x^2*a(2) + x*a(1) + a(0)
sage: p.diff(x)              
i*x^(i - 1)*a(i)*D[0](sum)(x^i*a(i), i, 0, n)

In Maple they all give good results.

Am I going at this the right way? Is there a way to implicitly define variables as in Maple?