图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

  1. """Tests for quotient rings."""
  2. from sympy.polys.domains.integerring import ZZ
  3. from sympy.polys.domains.rationalfield import QQ
  4. from sympy.abc import x, y
  5. from sympy.polys.polyerrors import NotReversible
  6. from sympy.testing.pytest import raises
  7. def test_QuotientRingElement():
  8. R = QQ.old_poly_ring(x)/[x**10]
  9. X = R.convert(x)
  10. assert X*(X + 1) == R.convert(x**2 + x)
  11. assert X*x == R.convert(x**2)
  12. assert x*X == R.convert(x**2)
  13. assert X + x == R.convert(2*x)
  14. assert x + X == 2*X
  15. assert X**2 == R.convert(x**2)
  16. assert 1/(1 - X) == R.convert(sum(x**i for i in range(10)))
  17. assert X**10 == R.zero
  18. assert X != x
  19. raises(NotReversible, lambda: 1/X)
  20. def test_QuotientRing():
  21. I = QQ.old_poly_ring(x).ideal(x**2 + 1)
  22. R = QQ.old_poly_ring(x)/I
  23. assert R == QQ.old_poly_ring(x)/[x**2 + 1]
  24. assert R == QQ.old_poly_ring(x)/QQ.old_poly_ring(x).ideal(x**2 + 1)
  25. assert R != QQ.old_poly_ring(x)
  26. assert R.convert(1)/x == -x + I
  27. assert -1 + I == x**2 + I
  28. assert R.convert(ZZ(1), ZZ) == 1 + I
  29. assert R.convert(R.convert(x), R) == R.convert(x)
  30. X = R.convert(x)
  31. Y = QQ.old_poly_ring(x).convert(x)
  32. assert -1 + I == X**2 + I
  33. assert -1 + I == Y**2 + I
  34. assert R.to_sympy(X) == x
  35. raises(ValueError, lambda: QQ.old_poly_ring(x)/QQ.old_poly_ring(x, y).ideal(x))
  36. R = QQ.old_poly_ring(x, order="ilex")
  37. I = R.ideal(x)
  38. assert R.convert(1) + I == (R/I).convert(1)