test_rewrite.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. from sympy.core.numbers import I
  2. from sympy.core.symbol import symbols
  3. from sympy.functions.elementary.exponential import exp
  4. from sympy.functions.elementary.trigonometric import (cos, cot, sin)
  5. from sympy.testing.pytest import _both_exp_pow
  6. x, y, z, n = symbols('x,y,z,n')
  7. @_both_exp_pow
  8. def test_has():
  9. assert cot(x).has(x)
  10. assert cot(x).has(cot)
  11. assert not cot(x).has(sin)
  12. assert sin(x).has(x)
  13. assert sin(x).has(sin)
  14. assert not sin(x).has(cot)
  15. assert exp(x).has(exp)
  16. @_both_exp_pow
  17. def test_sin_exp_rewrite():
  18. assert sin(x).rewrite(sin, exp) == -I/2*(exp(I*x) - exp(-I*x))
  19. assert sin(x).rewrite(sin, exp).rewrite(exp, sin) == sin(x)
  20. assert cos(x).rewrite(cos, exp).rewrite(exp, cos) == cos(x)
  21. assert (sin(5*y) - sin(
  22. 2*x)).rewrite(sin, exp).rewrite(exp, sin) == sin(5*y) - sin(2*x)
  23. assert sin(x + y).rewrite(sin, exp).rewrite(exp, sin) == sin(x + y)
  24. assert cos(x + y).rewrite(cos, exp).rewrite(exp, cos) == cos(x + y)
  25. # This next test currently passes... not clear whether it should or not?
  26. assert cos(x).rewrite(cos, exp).rewrite(exp, sin) == cos(x)