test_demidovich.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. from sympy.core.numbers import (Rational, oo, pi)
  2. from sympy.core.singleton import S
  3. from sympy.core.symbol import Symbol
  4. from sympy.functions.elementary.exponential import (exp, log)
  5. from sympy.functions.elementary.miscellaneous import (root, sqrt)
  6. from sympy.functions.elementary.trigonometric import (asin, cos, sin, tan)
  7. from sympy.polys.rationaltools import together
  8. from sympy.series.limits import limit
  9. # Numbers listed with the tests refer to problem numbers in the book
  10. # "Anti-demidovich, problemas resueltos, Ed. URSS"
  11. x = Symbol("x")
  12. def test_leadterm():
  13. assert (3 + 2*x**(log(3)/log(2) - 1)).leadterm(x) == (3, 0)
  14. def root3(x):
  15. return root(x, 3)
  16. def root4(x):
  17. return root(x, 4)
  18. def test_Limits_simple_0():
  19. assert limit((2**(x + 1) + 3**(x + 1))/(2**x + 3**x), x, oo) == 3 # 175
  20. def test_Limits_simple_1():
  21. assert limit((x + 1)*(x + 2)*(x + 3)/x**3, x, oo) == 1 # 172
  22. assert limit(sqrt(x + 1) - sqrt(x), x, oo) == 0 # 179
  23. assert limit((2*x - 3)*(3*x + 5)*(4*x - 6)/(3*x**3 + x - 1), x, oo) == 8 # Primjer 1
  24. assert limit(x/root3(x**3 + 10), x, oo) == 1 # Primjer 2
  25. assert limit((x + 1)**2/(x**2 + 1), x, oo) == 1 # 181
  26. def test_Limits_simple_2():
  27. assert limit(1000*x/(x**2 - 1), x, oo) == 0 # 182
  28. assert limit((x**2 - 5*x + 1)/(3*x + 7), x, oo) is oo # 183
  29. assert limit((2*x**2 - x + 3)/(x**3 - 8*x + 5), x, oo) == 0 # 184
  30. assert limit((2*x**2 - 3*x - 4)/sqrt(x**4 + 1), x, oo) == 2 # 186
  31. assert limit((2*x + 3)/(x + root3(x)), x, oo) == 2 # 187
  32. assert limit(x**2/(10 + x*sqrt(x)), x, oo) is oo # 188
  33. assert limit(root3(x**2 + 1)/(x + 1), x, oo) == 0 # 189
  34. assert limit(sqrt(x)/sqrt(x + sqrt(x + sqrt(x))), x, oo) == 1 # 190
  35. def test_Limits_simple_3a():
  36. a = Symbol('a')
  37. #issue 3513
  38. assert together(limit((x**2 - (a + 1)*x + a)/(x**3 - a**3), x, a)) == \
  39. (a - 1)/(3*a**2) # 196
  40. def test_Limits_simple_3b():
  41. h = Symbol("h")
  42. assert limit(((x + h)**3 - x**3)/h, h, 0) == 3*x**2 # 197
  43. assert limit((1/(1 - x) - 3/(1 - x**3)), x, 1) == -1 # 198
  44. assert limit((sqrt(1 + x) - 1)/(root3(1 + x) - 1), x, 0) == Rational(3)/2 # Primer 4
  45. assert limit((sqrt(x) - 1)/(x - 1), x, 1) == Rational(1)/2 # 199
  46. assert limit((sqrt(x) - 8)/(root3(x) - 4), x, 64) == 3 # 200
  47. assert limit((root3(x) - 1)/(root4(x) - 1), x, 1) == Rational(4)/3 # 201
  48. assert limit(
  49. (root3(x**2) - 2*root3(x) + 1)/(x - 1)**2, x, 1) == Rational(1)/9 # 202
  50. def test_Limits_simple_4a():
  51. a = Symbol('a')
  52. assert limit((sqrt(x) - sqrt(a))/(x - a), x, a) == 1/(2*sqrt(a)) # Primer 5
  53. assert limit((sqrt(x) - 1)/(root3(x) - 1), x, 1) == Rational(3, 2) # 205
  54. assert limit((sqrt(1 + x) - sqrt(1 - x))/x, x, 0) == 1 # 207
  55. assert limit(sqrt(x**2 - 5*x + 6) - x, x, oo) == Rational(-5, 2) # 213
  56. def test_limits_simple_4aa():
  57. assert limit(x*(sqrt(x**2 + 1) - x), x, oo) == Rational(1)/2 # 214
  58. def test_Limits_simple_4b():
  59. #issue 3511
  60. assert limit(x - root3(x**3 - 1), x, oo) == 0 # 215
  61. def test_Limits_simple_4c():
  62. assert limit(log(1 + exp(x))/x, x, -oo) == 0 # 267a
  63. assert limit(log(1 + exp(x))/x, x, oo) == 1 # 267b
  64. def test_bounded():
  65. assert limit(sin(x)/x, x, oo) == 0 # 216b
  66. assert limit(x*sin(1/x), x, 0) == 0 # 227a
  67. def test_f1a():
  68. #issue 3508:
  69. assert limit((sin(2*x)/x)**(1 + x), x, 0) == 2 # Primer 7
  70. def test_f1a2():
  71. #issue 3509:
  72. assert limit(((x - 1)/(x + 1))**x, x, oo) == exp(-2) # Primer 9
  73. def test_f1b():
  74. m = Symbol("m")
  75. n = Symbol("n")
  76. h = Symbol("h")
  77. a = Symbol("a")
  78. assert limit(sin(x)/x, x, 2) == sin(2)/2 # 216a
  79. assert limit(sin(3*x)/x, x, 0) == 3 # 217
  80. assert limit(sin(5*x)/sin(2*x), x, 0) == Rational(5, 2) # 218
  81. assert limit(sin(pi*x)/sin(3*pi*x), x, 0) == Rational(1, 3) # 219
  82. assert limit(x*sin(pi/x), x, oo) == pi # 220
  83. assert limit((1 - cos(x))/x**2, x, 0) == S.Half # 221
  84. assert limit(x*sin(1/x), x, oo) == 1 # 227b
  85. assert limit((cos(m*x) - cos(n*x))/x**2, x, 0) == -m**2/2 + n**2/2 # 232
  86. assert limit((tan(x) - sin(x))/x**3, x, 0) == S.Half # 233
  87. assert limit((x - sin(2*x))/(x + sin(3*x)), x, 0) == -Rational(1, 4) # 237
  88. assert limit((1 - sqrt(cos(x)))/x**2, x, 0) == Rational(1, 4) # 239
  89. assert limit((sqrt(1 + sin(x)) - sqrt(1 - sin(x)))/x, x, 0) == 1 # 240
  90. assert limit((1 + h/x)**x, x, oo) == exp(h) # Primer 9
  91. assert limit((sin(x) - sin(a))/(x - a), x, a) == cos(a) # 222, *176
  92. assert limit((cos(x) - cos(a))/(x - a), x, a) == -sin(a) # 223
  93. assert limit((sin(x + h) - sin(x))/h, h, 0) == cos(x) # 225
  94. def test_f2a():
  95. assert limit(((x + 1)/(2*x + 1))**(x**2), x, oo) == 0 # Primer 8
  96. def test_f2():
  97. assert limit((sqrt(
  98. cos(x)) - root3(cos(x)))/(sin(x)**2), x, 0) == -Rational(1, 12) # *184
  99. def test_f3():
  100. a = Symbol('a')
  101. #issue 3504
  102. assert limit(asin(a*x)/x, x, 0) == a