def test_PolyElement(): Ruv, u, v = ring('u v', ZZ) _, x, y, _ = ring('x y z', Ruv) assert str(x - x) == '0' assert str(x - 1) == 'x - 1' assert str(x + 1) == 'x + 1' assert str((u**2 + 3 * u * v + 1) * x**2 * y + u + 1) == '(u**2 + 3*u*v + 1)*x**2*y + u + 1' assert str((u**2 + 3 * u * v + 1) * x**2 * y + (u + 1) * x) == '(u**2 + 3*u*v + 1)*x**2*y + (u + 1)*x' assert str((u**2 + 3 * u * v + 1) * x**2 * y + (u + 1) * x + 1) == '(u**2 + 3*u*v + 1)*x**2*y + (u + 1)*x + 1' assert str((-u**2 + 3 * u * v - 1) * x**2 * y - (u + 1) * x - 1) == '-(u**2 - 3*u*v + 1)*x**2*y - (u + 1)*x - 1' assert str(-(v**2 + v + 1) * x + 3 * u * v + 1) == '-(v**2 + v + 1)*x + 3*u*v + 1' assert str(-(v**2 + v + 1) * x - 3 * u * v + 1) == '-(v**2 + v + 1)*x - 3*u*v + 1' K, t = field('t', ZZ) _, x = ring('x', K) assert str(x / t) == '1/t*x' assert str(CC.inject(w).convert(I)) == '(0.0 + 1.0j)'
def test_Domain_unify(): F3 = GF(3) assert unify(F3, F3) == F3 assert unify(F3, ZZ) == F3 assert unify(F3, QQ) == QQ assert unify(F3, ALG) == ALG assert unify(F3, RR) == RR assert unify(F3, CC) == CC assert unify(F3, ZZ.inject(x)) == F3.inject(x) assert unify(F3, ZZ.inject(x).field) == F3.inject(x).field assert unify(F3, EX) == EX assert unify(ZZ, F3) == F3 assert unify(ZZ, ZZ) == ZZ assert unify(ZZ, QQ) == QQ assert unify(ZZ, ALG) == ALG assert unify(ZZ, RR) == RR assert unify(ZZ, CC) == CC assert unify(ZZ, ZZ.inject(x)) == ZZ.inject(x) assert unify(ZZ, ZZ.inject(x).field) == ZZ.inject(x).field assert unify(ZZ, EX) == EX assert unify(QQ, F3) == QQ assert unify(QQ, ZZ) == QQ assert unify(QQ, QQ) == QQ assert unify(QQ, ALG) == ALG assert unify(QQ, RR) == RR assert unify(QQ, CC) == CC assert unify(QQ, ZZ.inject(x)) == QQ.inject(x) assert unify(QQ, ZZ.inject(x).field) == QQ.inject(x).field assert unify(QQ, EX) == EX assert unify(RR, F3) == RR assert unify(RR, ZZ) == RR assert unify(RR, QQ) == RR assert unify(RR, ALG) == RR assert unify(RR, RR) == RR assert unify(RR, CC) == CC assert unify(RR, ZZ.inject(x)) == RR.inject(x) assert unify(RR, ZZ.inject(x).field) == RR.inject(x).field assert unify(RR, EX) == EX assert unify(CC, F3) == CC assert unify(CC, ZZ) == CC assert unify(CC, QQ) == CC assert unify(CC, ALG) == CC assert unify(CC, RR) == CC assert unify(CC, CC) == CC assert unify(CC, ZZ.inject(x)) == CC.inject(x) assert unify(CC, ZZ.inject(x).field) == CC.inject(x).field assert unify(CC, EX) == EX CC2 = ComplexField(prec=20) assert unify(CC, CC2) == unify(CC2, CC) == ComplexField(prec=CC.precision, tol=CC2.tolerance) RR2 = RealField(prec=20) assert unify(RR, RR2) == unify(RR2, RR) == RealField(prec=RR.precision, tol=RR2.tolerance) assert unify(ZZ.inject(x), F3) == F3.inject(x) assert unify(ZZ.inject(x), ZZ) == ZZ.inject(x) assert unify(ZZ.inject(x), QQ) == QQ.inject(x) assert unify(ZZ.inject(x), ALG) == ALG.inject(x) assert unify(ZZ.inject(x), RR) == RR.inject(x) assert unify(ZZ.inject(x), CC) == CC.inject(x) assert unify(ZZ.inject(x), ZZ.inject(x)) == ZZ.inject(x) assert unify(ZZ.inject(x), ZZ.inject(x).field) == ZZ.inject(x).field assert unify(ZZ.inject(x), EX) == EX assert unify(ZZ.inject(x).field, F3) == F3.inject(x).field assert unify(ZZ.inject(x).field, ZZ) == ZZ.inject(x).field assert unify(ZZ.inject(x).field, QQ) == QQ.inject(x).field assert unify(ZZ.inject(x).field, ALG) == ALG.inject(x).field assert unify(ZZ.inject(x).field, RR) == RR.inject(x).field assert unify(ZZ.inject(x).field, CC) == CC.inject(x).field assert unify(ZZ.inject(x).field, ZZ.inject(x)) == ZZ.inject(x).field assert unify(ZZ.inject(x).field, ZZ.inject(x).field) == ZZ.inject(x).field assert unify(ZZ.inject(x).field, EX) == EX assert unify(EX, F3) == EX assert unify(EX, ZZ) == EX assert unify(EX, QQ) == EX assert unify(EX, ALG) == EX assert unify(EX, RR) == EX assert unify(EX, CC) == EX assert unify(EX, ZZ.inject(x)) == EX assert unify(EX, ZZ.inject(x).field) == EX assert unify(EX, EX) == EX