test_lseries.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from sympy.core.numbers import E
  2. from sympy.core.singleton import S
  3. from sympy.functions.elementary.exponential import exp
  4. from sympy.functions.elementary.hyperbolic import tanh
  5. from sympy.functions.elementary.trigonometric import (cos, sin)
  6. from sympy.series.order import Order
  7. from sympy.abc import x, y
  8. def test_sin():
  9. e = sin(x).lseries(x)
  10. assert next(e) == x
  11. assert next(e) == -x**3/6
  12. assert next(e) == x**5/120
  13. def test_cos():
  14. e = cos(x).lseries(x)
  15. assert next(e) == 1
  16. assert next(e) == -x**2/2
  17. assert next(e) == x**4/24
  18. def test_exp():
  19. e = exp(x).lseries(x)
  20. assert next(e) == 1
  21. assert next(e) == x
  22. assert next(e) == x**2/2
  23. assert next(e) == x**3/6
  24. def test_exp2():
  25. e = exp(cos(x)).lseries(x)
  26. assert next(e) == E
  27. assert next(e) == -E*x**2/2
  28. assert next(e) == E*x**4/6
  29. assert next(e) == -31*E*x**6/720
  30. def test_simple():
  31. assert list(x.lseries()) == [x]
  32. assert list(S.One.lseries(x)) == [1]
  33. assert not next((x/(x + y)).lseries(y)).has(Order)
  34. def test_issue_5183():
  35. s = (x + 1/x).lseries()
  36. assert list(s) == [1/x, x]
  37. assert next((x + x**2).lseries()) == x
  38. assert next(((1 + x)**7).lseries(x)) == 1
  39. assert next((sin(x + y)).series(x, n=3).lseries(y)) == x
  40. # it would be nice if all terms were grouped, but in the
  41. # following case that would mean that all the terms would have
  42. # to be known since, for example, every term has a constant in it.
  43. s = ((1 + x)**7).series(x, 1, n=None)
  44. assert [next(s) for i in range(2)] == [128, -448 + 448*x]
  45. def test_issue_6999():
  46. s = tanh(x).lseries(x, 1)
  47. assert next(s) == tanh(1)
  48. assert next(s) == x - (x - 1)*tanh(1)**2 - 1
  49. assert next(s) == -(x - 1)**2*tanh(1) + (x - 1)**2*tanh(1)**3
  50. assert next(s) == -(x - 1)**3*tanh(1)**4 - (x - 1)**3/3 + \
  51. 4*(x - 1)**3*tanh(1)**2/3