2020-01-16 10:11:29 -0500 received badge ● Popular Question (source) 2017-03-15 09:17:06 -0500 asked a question Multivariate polynomial coefficients including zeros Dears, I would like to get the coefficients of a multivariate polynomial including the zero coefficients (in their correct positions). I have found a similar answer as regards a polynomial f of two variables x,y P. = 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]) x=vector(list(V)) P1=PolynomialRing(GF(q),V)  How can I do that? Any help will be much appreciated. Regards, Natassa 2016-12-11 02:26:07 -0500 received badge ● Nice Question (source) 2016-12-11 02:25:39 -0500 received badge ● Self-Learner (source) 2016-12-11 02:25:39 -0500 received badge ● Teacher (source) 2016-12-08 04:40:08 -0500 commented answer Problem with the minus sign in symbolic expression Indeed, now I see what the problem was. Thank you! 2016-12-08 04:18:28 -0500 received badge ● Editor (source) 2016-12-08 03:15:46 -0500 asked a question Problem with the minus sign in symbolic expression Hi all! My sage version is: 'SageMath Version 6.9, Release Date: 2015-10-10' In my code, I have a multivariate polynomial with a sign symbol which doesn't return the correct result. I.e. The code snippet is as follows: A1 = [(', '.join('x%i'%i for i in [1.. n]))]; ### construct a suitable multivariate ring V = var(A1[0]) ### define a str variable x=vector(list(V)) ### convert to vector f1=b1-a1.dot_product(x)  a1 and b1 are returned from another function. types of a1 and x are different:  type(a1)= type(x)=  Could this be a problem? a1 is a vector with values (76, 83), b1 is scalar with value 62, x is a vector with values (x1,x2). Thus, f1 should return 62-76 * x1-83 * x2; however it returns 25x1 + 18x2 + 62 which is not correct. Please note that if I use addition in f1 as follows: sage: f1=b1+a1.dot_product(x)  The result is correct,i.e. 76x1 + 83x2 + 62 type(f1) is sage.symbolic.expression.Expression What could the problem be? I tried to convert the symbolic expression to multivariate polynomial, but this didn't work either? I also though there might be a problem with the minus symbol in my PC but couldn't solve it this way either. Thank you for your responses! Regards, Natassa 2016-12-03 05:24:19 -0500 received badge ● Scholar (source) 2016-12-03 05:23:41 -0500 answered a question Reduce multivariate polynomial coefficients to 1 Thank you all, Indeed, considering sum of all monomials does the trick! As a reference, a slightly tweaked solution below that worked for me: g # the polynomial list(g) # convert polynomial to list g1=sum(mon for coeff, mon in g) # get the sum of all monomials  2016-12-02 09:42:00 -0500 received badge ● Student (source) 2016-12-02 07:57:35 -0500 asked a question Reduce multivariate polynomial coefficients to 1 Hi all, I'm new to Python and SAGE and would like to ask a question: I have a multivariate polynomial, of a degree 3, i.e: g.=x1^2 + 2x1x2 + x2^2 + 2x1x3 + 2x2x3 + x3^2 + 2x1 + 2x2 + 2*x3 + 1 Its type is The question is how can I reduce all its leading coefficients to 1, i.e. transform ig to: g.=x1^2 + x1x2 + x2^2 + x1x3 + x2x3 + x3^2 + *x1 + *x2 + *x3 + 1 I tried to get the coefficients of the polynomial (which is a list), iterate through its items, and set the values of the items to 1, i.e. for s in g.coefficients(): if s==2: s=1 I think that the problem is that list items can't be cast to integer (TypeError). How could I solve this? Is there a more efficient way to do this? Thank you for your responses! Regards, Natassa