Hi Anastasia,

On 2017-03-15, Anastasia Theodouli <[email protected]> wrote:
> I would like to get in a list *ONLY* the coefficients of the following 
> monomials of P (including zero coefficients in correct order)
>
> (x0^2, x0*x1, x1^2, x0*x2, x1*x2, x2^2, x0, x1, x2, 1)

If you only consider specific monomials, you may use .monomial_coefficient()
instead of .coefficients():

    sage: P.<x0,x1,x2> = QQ[]
    sage: p = (x0+x1+x2+1)^4
    sage: M_list = [x0^2, x0*x1, x1^2, x0*x2, x1*x2, x2^2, x0, x1, x2, P(1)]
    sage: [p.monomial_coefficient(M) for M in M_list]
    [6, 12, 6, 12, 12, 6, 4, 4, 4, 1]

Remarks:
- Please do "p.monomial_coefficient?" to see the documentation of that
  method. It is expected that the argument belongs to the same ring
  (P, in the example) as the polynomial. Therefore I have P(1) and not
  simply 1 in M_list.
- p.monomial_coefficient(M) does return 0 if M does not occur in
  the polynomial p.

Best regards,
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 https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to