There isn't really, but it would be nice to have one.  For the
symbolic ring, the coefficients function does a lot of what you might
want:

var('a,b,x,y')
q = (1 + a + x)^4
q.expand().coefficients(a)
[[x^4 + 4*x^3 + 6*x^2 + 4*x + 1, 0], [4*x^3 + 12*x^2 + 12*x + 4, 1],
[6*x^2 + 12*x + 6, 2], [4*x + 4, 3], [1, 4]]

and I wrote something that kind of works like collect but the output
is reordered a bit in a way I can't control:

def collect(expr, a_var):
    temp = expr.expand()
    coefs = temp.coefficients(a_var)
    return sum([(q[0])*a_var^q[1] for q in coefs])

collect(q,a)
x^4 + a*(4*x^3 + 12*x^2 + 12*x + 4) + 4*x^3 + a^2*(6*x^2 + 12*x + 6) +
6*x^2 + a^3*(4*x + 4) + 4*x + a^4 + 1

Unfortunately for multivariate polynomial rings it looks like the
coefficients function doesn't take any arguments - it only gives the
coefficients for the completely expansion.  Using the exponents
function it is not hard to extract what you need though.

Hope that helps.  We should add more such functionality, although I am
not sure what to put on a trac ticket exactly.

-M. Hampton



On Nov 4, 9:23 am, mai <[EMAIL PROTECTED]> wrote:
> Hi all,
> is there in SAGE a function similar to Mathematica's Collect ?
>
> Thanks a lot,
> -- Mai
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to