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.

59 lines
2.9 KiB

6 months ago
  1. from sympy.core.numbers import Rational
  2. from sympy.functions.combinatorial.numbers import fibonacci
  3. from sympy.core import S, symbols
  4. from sympy.testing.pytest import raises
  5. from sympy.discrete.recurrences import linrec
  6. def test_linrec():
  7. assert linrec(coeffs=[1, 1], init=[1, 1], n=20) == 10946
  8. assert linrec(coeffs=[1, 2, 3, 4, 5], init=[1, 1, 0, 2], n=10) == 1040
  9. assert linrec(coeffs=[0, 0, 11, 13], init=[23, 27], n=25) == 59628567384
  10. assert linrec(coeffs=[0, 0, 1, 1, 2], init=[1, 5, 3], n=15) == 165
  11. assert linrec(coeffs=[11, 13, 15, 17], init=[1, 2, 3, 4], n=70) == \
  12. 56889923441670659718376223533331214868804815612050381493741233489928913241
  13. assert linrec(coeffs=[0]*55 + [1, 1, 2, 3], init=[0]*50 + [1, 2, 3], n=4000) == \
  14. 702633573874937994980598979769135096432444135301118916539
  15. assert linrec(coeffs=[11, 13, 15, 17], init=[1, 2, 3, 4], n=10**4)
  16. assert linrec(coeffs=[11, 13, 15, 17], init=[1, 2, 3, 4], n=10**5)
  17. assert all(linrec(coeffs=[1, 1], init=[0, 1], n=n) == fibonacci(n)
  18. for n in range(95, 115))
  19. assert all(linrec(coeffs=[1, 1], init=[1, 1], n=n) == fibonacci(n + 1)
  20. for n in range(595, 615))
  21. a = [S.Half, Rational(3, 4), Rational(5, 6), 7, Rational(8, 9), Rational(3, 5)]
  22. b = [1, 2, 8, Rational(5, 7), Rational(3, 7), Rational(2, 9), 6]
  23. x, y, z = symbols('x y z')
  24. assert linrec(coeffs=a[:5], init=b[:4], n=80) == \
  25. Rational(1726244235456268979436592226626304376013002142588105090705187189,
  26. 1960143456748895967474334873705475211264)
  27. assert linrec(coeffs=a[:4], init=b[:4], n=50) == \
  28. Rational(368949940033050147080268092104304441, 504857282956046106624)
  29. assert linrec(coeffs=a[3:], init=b[:3], n=35) == \
  30. Rational(97409272177295731943657945116791049305244422833125109,
  31. 814315512679031689453125)
  32. assert linrec(coeffs=[0]*60 + [Rational(2, 3), Rational(4, 5)], init=b, n=3000) == \
  33. Rational(26777668739896791448594650497024, 48084516708184142230517578125)
  34. raises(TypeError, lambda: linrec(coeffs=[11, 13, 15, 17], init=[1, 2, 3, 4, 5], n=1))
  35. raises(TypeError, lambda: linrec(coeffs=a[:4], init=b[:5], n=10000))
  36. raises(ValueError, lambda: linrec(coeffs=a[:4], init=b[:4], n=-10000))
  37. raises(TypeError, lambda: linrec(x, b, n=10000))
  38. raises(TypeError, lambda: linrec(a, y, n=10000))
  39. assert linrec(coeffs=[x, y, z], init=[1, 1, 1], n=4) == \
  40. x**2 + x*y + x*z + y + z
  41. assert linrec(coeffs=[1, 2, 1], init=[x, y, z], n=20) == \
  42. 269542*x + 664575*y + 578949*z
  43. assert linrec(coeffs=[0, 3, 1, 2], init=[x, y], n=30) == \
  44. 58516436*x + 56372788*y
  45. assert linrec(coeffs=[0]*50 + [1, 2, 3], init=[x, y, z], n=1000) == \
  46. 11477135884896*x + 25999077948732*y + 41975630244216*z
  47. assert linrec(coeffs=[], init=[1, 1], n=20) == 0
  48. assert linrec(coeffs=[x, y, z], init=[1, 2, 3], n=2) == 3