I also tried the following
P1 = PolynomialRing(ZZ,'x',3)
f=x0^2+2*x0*x1+x1^2+2*x0*x2+x1*x2+2*x2^2+x0+2*x1+x2+2
coeffs=[]
for mon in f.monomials():
coeffs.append(f.monomial_coefficient(mon))
coeffs
it returns the correct list, i.e.
[1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
but if I omit a monomial in f, e.g. if I set f=2*x0*x1+x1^2+2*x0*x2+x1*x2+2*
x2^2+x0+2*x1+x2+2
it returns* 9* coefficients instead of *10*, i.e it returns
[2, 1, 2, 1, 2, 1, 2, 1, 2] while I would like it to return [*0*, 2, 1, 2, 1,
2, 1, 2, 1, 2]
On Wednesday, March 15, 2017 at 5:52:54 PM UTC+2, Anastasia Theodouli wrote:
>
> Thank you very much Vincent! The code below is very close to what I want
> to achieve.
>
> There is a detail I haven't mentioned before.
>
> If I have n=3, which means that P is
>
> P: Multivariate Polynomial Ring in x0, x1, x2 over Integer Ring
>
> 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)
>
>
> How could I achieve that?
>
> On Wednesday, March 15, 2017 at 4:06:38 PM UTC+2, Anastasia Theodouli
> wrote:
>>
>> Dears,
>>
>> I would like to get the coefficients of a *multivariate* polynomial*
>> including the zero coefficients (in their correct position*s). I have
>> found a similar answer as regards a polynomial f of two variables x,y
>>
>>
>> P.<x,y> = PolynomialRing(ZZ, 2, order='lex')
>> f=3*x^2*y^2+x*y+3
>>
>>
>> Then using the following code:
>>
>> coeffs = []
>> for i in range(f.degree(x), -1, -1):
>> for j in range(f.degree(y), -1, -1):
>> coeffs.append(f.coefficient({x:i, y:j}))
>>
>>
>> The result is as expected:
>> [3, ,0 , 0, 1, 0, 0, 0, 0, 3]
>>
>> *Now, I would like to extend this solution for a multivariate polynomial
>> of n variables [xo,x1,...xn-1]*
>> The polynomial is defined with the following code: (Note:
>> q=next_prime(10000))
>> A1 = [(', '.join('x%i'%i for i in [0.. n-1]))]; ### construct a suitable
>> multivariate ring
>> V = var(A1[0]) ### define a str
>> variable
>> x=vector(list(V)) ### convert to vector
>>
>> P1=PolynomialRing(GF(q),V)
>> How can I do that? Any help will be much appreciated.
>>
>> Regards,
>> Natassa
>>
>>
--
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.