Hi!

On 2013-03-31, Dima Pasechnik <[email protected]> wrote:
> On 2013-03-30, tvn <[email protected]> wrote:
>> ------=_Part_1723_8861826.1364684060099
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> In sympy there's a method call as_coeffficients_dict()  that returns all 
>> the terms and their coefficients from an expression.  I am if I can do 
>> something like this in Sage.  
> you can do a similar thing, except that the monomials are encoded by
> their exponents
>
> sage: R.<x,a> = ZZ[]
> sage: p=x^2*a-a^2+a-4

Note that this is not a symbolic expression, but a "proper" polynomial.
But the original question was about symbolic expressions. Perhaps the
original poster has a reason for using symbolic expressions?

Perhaps the following does what is requested?
  sage: var('x','a')
  (x, a)
  sage: b = (3*x + a*x + 4)
  sage: b.operands()
  [a*x, 3*x, 4]

It would probably not be too dificult to extract the constant
coefficient of each operand.

It all depends on what answer you would expect. Say, if you present an
equal polynomial symbolic expression by
  sage: c = (3+a)*x + 4
Then you get
  sage: c.operands()
  [(a + 3)*x, 4]

Is this what you want? Or do you want that an automatic expansion into a
sum takes place? In this case it might really be better to use
polynomials.

Cheers,
Simon


-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to