def __init__(self, mod, symmetric=True): if mod <= 0: raise ValueError('modulus must be a positive integer, got %s' % mod) self.dtype = ModularIntegerFactory(mod, self.dom, symmetric) self.zero = self.dtype(0) self.one = self.dtype(1) self.mod = mod
def __init__(self, mod, symmetric=True): from sympy.polys.domains import ZZ dom = ZZ if mod <= 0: raise ValueError('modulus must be a positive integer, got %s' % mod) self.dtype = ModularIntegerFactory(mod, dom, symmetric, self) self.zero = self.dtype(0) self.one = self.dtype(1) self.dom = dom self.mod = mod
def test_ModularInteger(): GF = ModularIntegerFactory(3) a = GF(0) assert isinstance(a, GF) and a == 0 a = GF(1) assert isinstance(a, GF) and a == 1 a = GF(2) assert isinstance(a, GF) and a == 2 a = GF(3) assert isinstance(a, GF) and a == 0 a = GF(4) assert isinstance(a, GF) and a == 1 a = GF(GF(0)) assert isinstance(a, GF) and a == 0 a = GF(GF(1)) assert isinstance(a, GF) and a == 1 a = GF(GF(2)) assert isinstance(a, GF) and a == 2 a = GF(GF(3)) assert isinstance(a, GF) and a == 0 a = GF(GF(4)) assert isinstance(a, GF) and a == 1 a = -GF(1) assert isinstance(a, GF) and a == 2 a = -GF(2) assert isinstance(a, GF) and a == 1 a = 2 + GF(2) assert isinstance(a, GF) and a == 1 a = GF(2) + 2 assert isinstance(a, GF) and a == 1 a = GF(2) + GF(2) assert isinstance(a, GF) and a == 1 a = GF(2) + GF(2) assert isinstance(a, GF) and a == 1 a = 3 - GF(2) assert isinstance(a, GF) and a == 1 a = GF(3) - 2 assert isinstance(a, GF) and a == 1 a = GF(3) - GF(2) assert isinstance(a, GF) and a == 1 a = GF(3) - GF(2) assert isinstance(a, GF) and a == 1 a = 2 * GF(2) assert isinstance(a, GF) and a == 1 a = GF(2) * 2 assert isinstance(a, GF) and a == 1 a = GF(2) * GF(2) assert isinstance(a, GF) and a == 1 a = GF(2) * GF(2) assert isinstance(a, GF) and a == 1 a = 2 / GF(2) assert isinstance(a, GF) and a == 1 a = GF(2) / 2 assert isinstance(a, GF) and a == 1 a = GF(2) / GF(2) assert isinstance(a, GF) and a == 1 a = GF(2) / GF(2) assert isinstance(a, GF) and a == 1 a = 1 % GF(2) assert isinstance(a, GF) and a == 1 a = GF(1) % 2 assert isinstance(a, GF) and a == 1 a = GF(1) % GF(2) assert isinstance(a, GF) and a == 1 a = GF(1) % GF(2) assert isinstance(a, GF) and a == 1 a = GF(2)**0 assert isinstance(a, GF) and a == 1 a = GF(2)**1 assert isinstance(a, GF) and a == 2 a = GF(2)**2 assert isinstance(a, GF) and a == 1 assert bool(GF(3)) is False assert bool(GF(4)) is True GF = ModularIntegerFactory(5) a = GF(1)**(-1) assert isinstance(a, GF) and a == 1 a = GF(2)**(-1) assert isinstance(a, GF) and a == 3 a = GF(3)**(-1) assert isinstance(a, GF) and a == 2 a = GF(4)**(-1) assert isinstance(a, GF) and a == 4 assert (GF(1) < GF(2)) == True assert (GF(1) <= GF(2)) == True assert (GF(1) > GF(2)) == False assert (GF(1) >= GF(2)) == False assert (GF(3) < GF(2)) == False assert (GF(3) <= GF(2)) == False assert (GF(3) > GF(2)) == True assert (GF(3) >= GF(2)) == True assert (GF(1) < GF(7)) == True assert (GF(1) <= GF(7)) == True assert (GF(1) > GF(7)) == False assert (GF(1) >= GF(7)) == False assert (GF(3) < GF(7)) == False assert (GF(3) <= GF(7)) == False assert (GF(3) > GF(7)) == True assert (GF(3) >= GF(7)) == True assert (GF(1) < 2) == True assert (GF(1) <= 2) == True assert (GF(1) > 2) == False assert (GF(1) >= 2) == False assert (GF(3) < 2) == False assert (GF(3) <= 2) == False assert (GF(3) > 2) == True assert (GF(3) >= 2) == True assert (GF(1) < 7) == True assert (GF(1) <= 7) == True assert (GF(1) > 7) == False assert (GF(1) >= 7) == False assert (GF(3) < 7) == False assert (GF(3) <= 7) == False assert (GF(3) > 7) == True assert (GF(3) >= 7) == True raises(NotInvertible, "GF(0)**(-1)") raises(NotInvertible, "GF(5)**(-1)") raises(ValueError, "ModularIntegerFactory(0)") raises(ValueError, "ModularIntegerFactory(2.1)") raises(TypeError, "ModularIntegerFactory(3, QQ)")