| To define a general polynomial in Maple one writes 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 Is this the right way? It doesn't behave as nice as in maple. Trying series, taylor, and diff only taylor works correctly: 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.
Jason Grout (Jul 04 '11)
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.
parzan (Jul 13 '11) |
| I think the best way to do this is to use python's list comprehension/generator syntax to define the sequence of variables. Something like the following provides a formal sum which works as expected for
a = list(var("a%d" % i) for i in range(4))?
DSM (Jun 23 '11)
By the way, in Python 3 this is going to get even more confusing, with the {0} notation we'll need looking vaguely like subscript notation...
kcrisman (Jun 23 '11)
then maybe someone will improve `var` to automatically generate a sequence of variables ;)
niles (Jun 23 '11)
Thanks for the ideas! This is nice, but it's not exactly what I want, since it bounds the polynomial degree. What I am looking for is a way to represent general polynomials, i.e., the "4" in the example should somehow be replaced by a variable 'n'.
parzan (Jun 23 '11)
Maybe this would be possible with a generator...
kcrisman (Jun 23 '11) |
| How about something like this?
Note that this doesn't solve the "number of variables is a variable" problem, only the "how do I easily generate a number of variables" problem.
Jason Grout (Jul 04 '11)
This is nice. Perhaps you could make "VariableGenerator" inherit "sage.symbolic.expression.Expression" so that it would be a variable with indexing? and even better, if the key could be a symbolic expression itself - maybe that way we could achieve maple's functionality?
parzan (Jul 13 '11) |
| I found out that maxima does offer this capability, so one can use it in sage: sadly: Also, it is not as strong as maple: whereas in maple this works - gives the desired answer $1+\sum _{i=1}^{k}a_{{i}}x+ \left( \sum _{i=1}^{k}b_{{i}}-1/2\cdot{a_{{i} }}^{2}+1/2\cdot \left( \sum _{i=1}^{k}a_{{i}} \right) ^{2} \right) {x}^{2 }+O \left( {x}^{3} \right) $. |
Asked: Jun 22 '11
Seen: 345 times
Last updated: Jul 14 '11
powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.