Ask Your Question

Revision history [back]

You have a typo in your inner if-statement: x + j^n instead of x^n + j, so it always fails for degree reasons.

You have a typo in your inner if-statement: x + j^n instead of x^n + j, so it always fails for degree reasons.

You probably also want to avoid using the symbolic x and instead give the generator of your polynomial ring a proper name such as x, and name the image in the quotient something like xbar:

# We get the ring where we will check for primality
ZnX.<x> = IntegerModRing(n)[]
ZnX_mod_f.<xbar> = ZnX.quo(x^r-1)

for j in range(1, 2*log(n,2)*sqrt(r)+2):
    if (xbar+j)^n != xbar^n+j: 
        print("The freshman dream test failed for j={}".format(j))
        return False