def quad_residue(q,m): """Check if q is a quadratic residue modulo m""" if is_prime(m) and gcd(q,m) == 1: e = q**((m-1)//2) % m if e == 1: return True return False else: for i in range(m): if i**2 % m == q: return True return False
def content(poly): """GCD of the coefficients, negative if leading coef is negative""" assert type(poly) == ZPoly return gcd(poly.coef) * int(copysign(1, poly[-1]))
if Q == P: Q = factor_at_nonzero(P) return Q #def poly_factor(P): # F = [] # Q = poly_factor_1L(P) # if Q == P: # return [P] # # F.append(Q) # F.append(P//Q) # # ## out = [] ## while True: ## R = F.pop() ## r = poly_factor_1L(P) ## if ==: Q = Polynomial([-20, 6, 2, 12]) g = abs(gcd(Q.coef)) print(Q) print(f"GCD = {g}") Q = Q / g print(Q) F = poly_factor_1L(Q) print(F) print(Q / F) #print(F*(Q/F))
def simplify(self): """Convert fraction to simplest form""" g = abs(gcd(self.n, self.d)) self.n = self.n // g self.d = self.d // g