Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

How to randomly generate a quadratic, monic, irreducible polynomial over ring of integers ZZ with small coefficients?

asked 2 years ago

DreDd gravatar image

In finite fields, we can use irreducible_element, is there any similar way for an integer ring?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 2 years ago

dazedANDconfused gravatar image

updated 2 years ago

You haven't made it clear how big integers can be and still be small. The following code can easily be modified as needed

R.<x>=ZZ[]  #ring of polynomials with integral coefficients
f = R.random_element(2) #choose polynomial from the ring with degree at most 2
L = f.list() #get the coefficients
while L[2] != 1 or abs(L[1])>9 or abs(L[0])>10 or f.is_irreducible() == False:
    f = R.random_element(2)
    L = f.list()
print(f)

L[2] is the coefficient of x^2, so we insist that if it isn't 1 then we throw the polynomial away. We also throw the polynomial away if the coefficient of x in absolute value is >9 or the constant (in absolute value) is >10 or the polynomial is not irreducible.

There's probably a less clunky way to do it but this works.

EDIT: following rburing comment below will mean not having to throw out so many polynomials for not being monic.

R.<x>=ZZ[]  #ring of polynomials with integral coefficients
poly = R.random_element(1) #choose polynomial from the ring with degree at most 1
f = x^2+poly
L = f.list() #get the coefficients
while abs(L[1])>9 or abs(L[0])>10 or f.is_irreducible() == False:
    poly = R.random_element(1)
    f = x^2+poly
    L = f.list()
print(f)
Preview: (hide)
link

Comments

1

Instead of generating polynomials of degree at most d and throwing away all which are not monic of degree d, you could just start with xd and add arbitrary polynomials of degree at most d1.

rburing gravatar imagerburing ( 2 years ago )

Good idea! I revised code to do that.

dazedANDconfused gravatar imagedazedANDconfused ( 2 years ago )

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: 2 years ago

Seen: 414 times

Last updated: Sep 19 '22