Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is the same answer as the one of tmonteil, but done when started with a "polynomial expression".

So let us define

var('x');
f = x^8 + x^2 + 1

As declared, f is not a polynomial, an algebraic object, but

sage: f
x^8 + x^2 + 1
sage: type(f)
<class 'sage.symbolic.expression.Expression'>

an expression, so square roots, exponentials, and other non-algebraic operations are allowed. We have to switch to the world of true (sage) polynomials, by building f.polynomial( ... ), and this method asks for a base ring. We pass GF(3) as base ring. So the following does the job:

sage: pol = f.polynomial( GF(3) )
sage: pol.is_irreducible()
False
sage: pol.factor()
(x + 1) * (x + 2) * (x^3 + 2*x + 1) * (x^3 + 2*x + 2)

Note: This works also with an other variable name...

sage: var('y');
sage: f = y^8 + y^2 + 1
sage: pol = f.polynomial( GF(3) )
sage: pol.factor()
(y + 1) * (y + 2) * (y^3 + 2*y + 1) * (y^3 + 2*y + 2)

But note that the y involved in f and the y involved in pol are different objects.