# 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?

How does Maple deal with formal polynomials? I think we'd need some other sort of formal polynomial class to deal with them, as what you're doing above in Sage is only constructing an explicit symbolic polynomial.

I really don't know how Maple does this. I am certain it is not by a class of formal polynomials, but simply a symbolic sum of symbolic expressions (involving indexing). One could also take products instead of sums, or combinations of such. I assume Maplesoft would not explain how this is implemented, but Maxima also knows how to do this (see my answer below), and it is open source, so hopefully one day someone would implement this in sage, or at least wrap the maxima implementation.