Ask Your Question
1

Polynomial identity

asked 2012-05-27 04:53:59 -0600

Angel gravatar image

updated 2012-05-27 05:13:33 -0600

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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-05-27 11:35:53 -0600

Mike Hansen gravatar image

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]
edit flag offensive delete link more

Comments

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 gravatar imageAngel ( 2012-05-27 13:22:30 -0600 )edit

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 gravatar imageMike Hansen ( 2012-05-27 16:32:42 -0600 )edit

Cool! I actually managed myself to write a slightly different version of your code. Great. I really thank you for your help ^^'.

Angel gravatar imageAngel ( 2012-05-27 21:37:19 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2012-05-27 04:53:59 -0600

Seen: 221 times

Last updated: May 27 '12