m2m模型翻译
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.

63 lines
2.3 KiB

6 months ago
  1. """Tests for tools for manipulation of rational expressions. """
  2. from sympy.polys.rationaltools import together
  3. from sympy.core.mul import Mul
  4. from sympy.core.numbers import Rational
  5. from sympy.core.relational import Eq
  6. from sympy.core.singleton import S
  7. from sympy.core.symbol import symbols
  8. from sympy.functions.elementary.exponential import exp
  9. from sympy.functions.elementary.trigonometric import sin
  10. from sympy.integrals.integrals import Integral
  11. from sympy.abc import x, y, z
  12. A, B = symbols('A,B', commutative=False)
  13. def test_together():
  14. assert together(0) == 0
  15. assert together(1) == 1
  16. assert together(x*y*z) == x*y*z
  17. assert together(x + y) == x + y
  18. assert together(1/x) == 1/x
  19. assert together(1/x + 1) == (x + 1)/x
  20. assert together(1/x + 3) == (3*x + 1)/x
  21. assert together(1/x + x) == (x**2 + 1)/x
  22. assert together(1/x + S.Half) == (x + 2)/(2*x)
  23. assert together(S.Half + x/2) == Mul(S.Half, x + 1, evaluate=False)
  24. assert together(1/x + 2/y) == (2*x + y)/(y*x)
  25. assert together(1/(1 + 1/x)) == x/(1 + x)
  26. assert together(x/(1 + 1/x)) == x**2/(1 + x)
  27. assert together(1/x + 1/y + 1/z) == (x*y + x*z + y*z)/(x*y*z)
  28. assert together(1/(1 + x + 1/y + 1/z)) == y*z/(y + z + y*z + x*y*z)
  29. assert together(1/(x*y) + 1/(x*y)**2) == y**(-2)*x**(-2)*(1 + x*y)
  30. assert together(1/(x*y) + 1/(x*y)**4) == y**(-4)*x**(-4)*(1 + x**3*y**3)
  31. assert together(1/(x**7*y) + 1/(x*y)**4) == y**(-4)*x**(-7)*(x**3 + y**3)
  32. assert together(5/(2 + 6/(3 + 7/(4 + 8/(5 + 9/x))))) == \
  33. Rational(5, 2)*((171 + 119*x)/(279 + 203*x))
  34. assert together(1 + 1/(x + 1)**2) == (1 + (x + 1)**2)/(x + 1)**2
  35. assert together(1 + 1/(x*(1 + x))) == (1 + x*(1 + x))/(x*(1 + x))
  36. assert together(
  37. 1/(x*(x + 1)) + 1/(x*(x + 2))) == (3 + 2*x)/(x*(1 + x)*(2 + x))
  38. assert together(1 + 1/(2*x + 2)**2) == (4*(x + 1)**2 + 1)/(4*(x + 1)**2)
  39. assert together(sin(1/x + 1/y)) == sin(1/x + 1/y)
  40. assert together(sin(1/x + 1/y), deep=True) == sin((x + y)/(x*y))
  41. assert together(1/exp(x) + 1/(x*exp(x))) == (1 + x)/(x*exp(x))
  42. assert together(1/exp(2*x) + 1/(x*exp(3*x))) == (1 + exp(x)*x)/(x*exp(3*x))
  43. assert together(Integral(1/x + 1/y, x)) == Integral((x + y)/(x*y), x)
  44. assert together(Eq(1/x + 1/y, 1 + 1/z)) == Eq((x + y)/(x*y), (z + 1)/z)
  45. assert together((A*B)**-1 + (B*A)**-1) == (A*B)**-1 + (B*A)**-1