# Finding irreducible polynomials in Sage Math

I'm new to Sage and I'm asked to find out all the monic polynomials (of the form x^m+q) that are irreducible in the finite field $\mathbb{Z}/p\mathbb{Z}$. My idea is to vary q from 0 to p-1 and m from 1 to n, where n is the highest order of polynomials given by the user, and I want to create a function that works for all integer fields. However, my codes don't work and Sage tells me

positive characteristic not allowed in symbolic computations What does this mean?

def irr(p,n):
R.<x>=PolynomialRing(Integers(p),'x')
for m in range(n+1):
for q in Integers(p):
R(f)=x^m+q
if R(f).is_irreducible():
return R(f)

edit retag close merge delete

Sort by » oldest newest most voted R(f)=x^m+q is trying to build a symbolic function named R with argument f. Just f = x^m+q would work

more

Okay, I changed R(f) to f, but now Sage always returns x. I want to find all the irreducible polynomials under a certain degree. How can I do this?

create a list, append to the list, and return the list at the end