ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 21 Jun 2011 23:48:29 -0500implicitly defining a sequence of variableshttp://ask.sagemath.org/question/8181/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 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?
parzanTue, 21 Jun 2011 23:48:29 -0500http://ask.sagemath.org/question/8181/