# Polynomial identity

 0 I'm pretty interested in solving the following kind of problem using Sage: Let R be a polynomial ring in, say, x,y,z as variables over a field k. I'd like to find field-elements a,b,c such that a(x^2+y^2)+b(xy+zx)+c(xyz)==0, if they exist (I know they do)'' so that Sage returns (a,b,c)=(0,0,0). That seems to be an easy matter if one can traduce the polynomial identity into a vector space identity. I proved to be unable to do so. I've to say that my polynomial identities are quite more cumbersome and include up to 7 variables so working them by-hand is almost impossible in a finite ammount of time or patience. asked May 27 '12 Angel 1 ● 1

 1 Here is some code which "linearizes" your problem: def polynomial_identity(polys): monomials = set() for p in polys: monomials.update(p.monomials()) base_ring = p.base_ring() monomial_order = list(monomials) m = [] for p in polys: row = [] for monomial in monomial_order: try: row.append(base_ring(p.coefficient(monomial))) except TypeError: row.append(base_ring(0)) m.append(row) m = matrix(m) return m.kernel()  The result is a vector space which gives you all of your solutions. Your example sage: polynomial_identity([x^2 + y^2, x*y + x*z, x*y*z]) Vector space of degree 3 and dimension 0 over Rational Field Basis matrix: []  shows that (0,0,0) is the only answer. Another example: sage: polynomial_identity([x+y, 2*x+2*y, 3*(x+y)]) Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [ 1 0 -1/3] [ 0 1 -2/3]  posted May 27 '12 Mike Hansen 3840 ● 21 ● 46 ● 84 First of all I thank you for your interest. I knew nothing about Sage till today's evening. I tried to type your code directly into the console, but something happens at line 8. Is any way I can include this function in the core of the program so that I don't need to define it everytime from console (just in case I am able to do so...). I mainly understand your code even I know nothing about this language nor its functions. Any comment that lead to understanding would be really appreciated.Angel (May 27 '12)You can put this in ~/.sage/init.sage and it will be loaded each time you start Sage. You can also run "%cpaste" from the command line, paste the code in, and then put in "--" to finish the paste.Mike Hansen (May 27 '12)Cool! I actually managed myself to write a slightly different version of your code. Great. I really thank you for your help ^^'.Angel (May 28 '12)

[hide preview]

## Stats:

Seen: 102 times

Last updated: May 27 '12