Ask Your Question
0

Powers of irreducible polynomials

asked 2013-06-29 22:20:00 +0100

alex.jordan gravatar image

I'm working on a WeBWorK project to demonstrate the relatively new WeBWorK-Sage connectivity. We'd like to demonstrate some math problems that one could program in WeBWorK using Sage more cleanly than without Sage.

To that end I'm trying the following: WeBWorK would display a randomly generated polynomial in Z[x]. Let's say it could be degree 2, 3, or 4 with integer coefficients from [-10,10]. A student has to factor it completely.

I'm able to send the student's answer to Sage as a string, properly formatted for Sage. It might be '(x^2+1)(2x+1)' or '2(x^2+3x+2)*(x+2)^2'. But how can I evaluate whether or not the answer is fully factored? (For the moment, I'm not concerned about factoring out integers.)

So far, I have done this, where poly is the string passed to Sage:


factored = True  
if (poly).operator()!=operator.mul:  
    if (poly).polynomial(base_ring=QQ).is_irreducible():  
        factored = True  
    else:  
        factored = False  
else:  
    factors = (poly).operands()  
    for factor in factors:  
        factored = factored and factor.polynomial(base_ring=QQ).is_irreducible()  
print factored
 

And factored is True if all of the factors in poly were irreducible, and False otherwise. This is not what I want since I want something like '(x+1)^2*(x+2)' to count as factored. Is there a quick test for whether or not a polynomial is a power of an irreducible? Or a constant multiple of such a thing?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2013-06-30 16:55:51 +0100

vdelecroix gravatar image

For your very last question:

sage: R.<x> = PolynomialRing(QQ, 'x')
sage: P = (1/2*x+3)^5
sage: P.factor()
(1/32) * (x + 6)^5
sage: len(P.factor())
1
sage: Q = P * (3*x+2)
sage: len(Q.factor())
2

This is because you may think of the result of .factor() as a unit together with a list of pairs (factor, multiplicity).

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2013-06-29 22:20:00 +0100

Seen: 897 times

Last updated: Jun 30 '13