test_approximants.py 1012 B

1234567891011121314151617181920212223
  1. from sympy.series import approximants
  2. from sympy.core.symbol import symbols
  3. from sympy.functions.combinatorial.factorials import binomial
  4. from sympy.functions.combinatorial.numbers import (fibonacci, lucas)
  5. def test_approximants():
  6. x, t = symbols("x,t")
  7. g = [lucas(k) for k in range(16)]
  8. assert list(approximants(g)) == (
  9. [2, -4/(x - 2), (5*x - 2)/(3*x - 1), (x - 2)/(x**2 + x - 1)] )
  10. g = [lucas(k)+fibonacci(k+2) for k in range(16)]
  11. assert list(approximants(g)) == (
  12. [3, -3/(x - 1), (3*x - 3)/(2*x - 1), -3/(x**2 + x - 1)] )
  13. g = [lucas(k)**2 for k in range(16)]
  14. assert list(approximants(g)) == (
  15. [4, -16/(x - 4), (35*x - 4)/(9*x - 1), (37*x - 28)/(13*x**2 + 11*x - 7),
  16. (50*x**2 + 63*x - 52)/(37*x**2 + 19*x - 13),
  17. (-x**2 - 7*x + 4)/(x**3 - 2*x**2 - 2*x + 1)] )
  18. p = [sum(binomial(k,i)*x**i for i in range(k+1)) for k in range(16)]
  19. y = approximants(p, t, simplify=True)
  20. assert next(y) == 1
  21. assert next(y) == -1/(t*(x + 1) - 1)