# In Sage, how do I check for irreducibility of a polynomial modulo prime.

In particular, I need to check irreducibility of this polynomial, x^8+x^2+1, modulo 3.

In Sage, how do I check for irreducibility of a polynomial modulo prime.

In particular, I need to check irreducibility of this polynomial, x^8+x^2+1, modulo 3.

add a comment

0

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.

0

The trick is first to define the ring `R`

where your polynomial will live, namely Polynomial Ring in the undeterminate `x`

over the finite field of size 3, $\mathbf{F}_3[x]$:

```
sage: R.<x> = GF(3)[]
```

This defines both `R`

and `x`

:

```
sage: R
Univariate Polynomial Ring in x over Finite Field of size 3
sage: x
x
sage: x.parent()
Univariate Polynomial Ring in x over Finite Field of size 3
```

Then, you can do:

```
sage: P = x^8+x^2+1
sage: P.is_irreducible()
False
sage: P.factor()
(x + 1) * (x + 2) * (x^3 + 2*x + 1) * (x^3 + 2*x + 2)
```

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

Asked: ** 2022-09-17 07:32:49 +0200 **

Seen: **75 times**

Last updated: **Oct 06 '22**

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.