def __init__(self, f, p): if type(f) is list: f = PolynomialModP(f, p) # Polynomial gets mod p of field elif type(f) is PolynomialModP: f.p = p # Polynomial gets mod p of field else: raise ValueError("Argument f type " + str(type(f)) + " is not supported.") if type(p) is not int: raise ValueError("Argument p is not an integer.") if p < 2: raise ValueError("Argument p is too small, should be larger than 1.") if p > 100: raise ValueError("Argument p is too large, should be smaller than 100.") if not is_prime(p): raise ValueError("Argument p is not actually prime.") self.p = p if f.degree() > 1 and not self.isIrreducible(f) \ or f.degree() == 1 and f.coefs[1] == 0: raise ValueError("Argument f is not irreducible.") if f.degree() == 0: raise ValueError("Argument f can not be constant.") self.f = f
def test___init__comblist(self): C = PolynomialModP([IntegerModP(3, 7), 2, IntegerModP(1, 11)], 5) C.coefs = [3, 2, 1] C.p = 5
def test___init__intlist(self): C = PolynomialModP([3, 2, 1], 5) C.coefs = [3, 2, 1] C.p = 5