sympy/series/tests/test_demidovich.py
author Fredrik Johansson <fredrik.johansson@gmail.com>
Thu Jun 19 18:42:52 2008 +0200 (20 months ago)
changeset 1274 53ea24e1700c
parent 1173e33b68271cf3
child 1693dc9441567464
permissions -rw-r--r--
Fix bug in integer_nthroot. 2**Rational(1,10**10) now doesn't hang.
     1 from sympy import limit, Symbol, oo, sqrt, Rational, log, exp, cos, sin, tan, \
     2     pi
     3 from sympy.utilities.pytest import XFAIL
     4 
     5 """
     6 (*) in problem number means that the number is relative to the book "Anti-demidovich,
     7 problemas resueltos, Ed. URSS"
     8 
     9 """
    10 
    11 x = Symbol("x", real=True, unbounded=True)
    12 
    13 def test_leadterm():
    14     assert (3+2*x**(log(3)/log(2)-1)).leadterm(x)==(3,0)
    15 
    16 def sqrt3(x):
    17     return x**Rational(1,3)
    18 
    19 def sqrt4(x):
    20     return x**Rational(1,4)
    21 
    22 def test_Limits_simple_0():
    23     assert limit((2**(x+1)+3**(x+1))/(2**x+3**x),x,oo)==3  #175
    24 
    25 def test_Limits_simple_1():
    26     assert limit((x+1)*(x+2)*(x+3)/x**3,x, oo)==1  #172
    27     assert limit(sqrt(x+1)-sqrt(x),x,oo)==0  #179
    28     assert limit((2*x-3)*(3*x+5)*(4*x-6)/(3*x**3+x-1),x,oo)==8  #Primjer 1
    29     assert limit(x/sqrt3(x**3+10),x,oo)==1  #Primjer 2
    30     assert limit((x+1)**2/(x**2+1),x,oo)==1  #181
    31 
    32 def test_Limits_simple_2():
    33     assert limit(1000*x/(x**2-1),x,oo)==0  #182
    34     assert limit((x**2-5*x+1)/(3*x+7),x,oo)==oo  #183
    35     assert limit((2*x**2-x+3)/(x**3-8*x+5),x,oo)==0  #184
    36     assert limit((2*x**2-3*x-4)/sqrt(x**4+1),x,oo)==2  #186
    37     assert limit((2*x+3)/(x+sqrt3(x)),x,oo)==2  #187
    38     assert limit(x**2/(10+x*sqrt(x)),x,oo)==oo  #188
    39     assert limit(sqrt3(x**2+1)/(x+1),x,oo)==0  #189
    40     assert limit(sqrt(x)/sqrt(x+sqrt(x+sqrt(x))),x,oo)==1  #190
    41 
    42 @XFAIL
    43 def test_Limits_simple_3a():
    44     a = Symbol('a', real=True)
    45     #issue 414
    46     assert limit((x**2-(a+1)*x+a)/(x**3-a**3),x,a)==(a-1)/(3*a**2)  #196
    47 
    48 def test_Limits_simple_3b():
    49     h = Symbol("h")
    50     assert limit(((x+h)**3-x**3)/h,h,0)==3*x**2  #197
    51     assert limit((1/(1-x)-3/(1-x**3)),x,1)==-1  #198
    52     assert limit((sqrt(1+x)-1)/(sqrt3(1+x)-1),x,0)==Rational(3)/2  #Primer 4
    53     assert limit((sqrt(x)-1)/(x-1),x,1)==Rational(1)/2  #199
    54     assert limit((sqrt(x)-8)/(sqrt3(x)-4),x,64)==3  #200
    55     assert limit((sqrt3(x)-1)/(sqrt4(x)-1),x,1)==Rational(4)/3  #201
    56     assert limit((sqrt3(x**2)-2*sqrt3(x)+1)/(x-1)**2,x,1)==Rational(1)/9  #202
    57 
    58 def test_Limits_simple_4a():
    59     a = Symbol('a', real=True)
    60     assert limit((sqrt(x)-sqrt(a))/(x-a),x,a)==1/(2*sqrt(a))  #Primer 5
    61     assert limit((sqrt(x)-1)/(sqrt3(x)-1),x,1)==Rational(3)/2  #205
    62     assert limit((sqrt(1+x)-sqrt(1-x))/x,x,0)==1  #207
    63     assert limit(sqrt(x**2-5*x+6)-x,x,oo)==-Rational(5)/2  #213
    64 
    65 def test_limits_simple_4aa():
    66     assert limit(x*(sqrt(x**2+1)-x),x,oo)==Rational(1)/2  #214
    67 
    68 def test_Limits_simple_4b():
    69     #issue 412
    70     assert limit(x-sqrt3(x**3-1),x,oo)==0  #215
    71 
    72 def test_Limits_simple_4c():
    73     assert limit(log(1+exp(x))/x,x,-oo)==0  #267a
    74     assert limit(log(1+exp(x))/x,x,oo)==1  #267b
    75 
    76 @XFAIL
    77 def test_f1a():
    78     h = Symbol("h")
    79     #needs a special logic for deciding that sin(x) is bounded:
    80     assert limit(sin(x)/x,x,oo) == 0 #216b
    81     #needs a special logic for deciding that sin(x) is bounded:
    82     assert limit(x*sin(1/x),x,0) == 0 #227a
    83     #issue 409:
    84     assert limit((sin(2*x)/x)**(1+x),x,0) == 2 #Primer 7
    85     #issue 410:
    86     assert limit(((x-1)/(x+1))**x,x,oo) == exp(-2) #Primer 9
    87 
    88 def test_f1b():
    89     m = Symbol("m")
    90     n = Symbol("n")
    91     h = Symbol("h")
    92     a = Symbol("a")
    93     assert limit(sin(x)/x,x,2) == sin(2)/2 #216a
    94     assert limit(sin(3*x)/x,x,0) == 3 #217
    95     assert limit(sin(5*x)/sin(2*x),x,0) == Rational(5)/2 #218
    96     assert limit(sin(pi*x)/sin(3*pi*x),x,0) == Rational(1)/3 #219
    97     assert limit(x*sin(pi/x),x,oo) == pi #220
    98     assert limit((1-cos(x))/x**2,x,0) == Rational(1,2) #221
    99     assert limit(x*sin(1/x),x,oo) == 1 #227b
   100     assert limit((cos(m*x)-cos(n*x))/x**2,x,0) == ((n**2-m**2)/2) #232
   101     assert limit((tan(x)-sin(x))/x**3,x,0) == Rational(1,2) #233
   102     assert limit((x-sin(2*x))/(x+sin(3*x)),x,0) == -Rational(1,4) #237
   103     assert limit((1-sqrt(cos(x)))/x**2,x,0) == Rational(1,4) #239
   104     assert limit((sqrt(1+sin(x))-sqrt(1-sin(x)))/x,x,0) == 1 #240
   105 
   106     assert limit((1+h/x)**x,x,oo) == exp(h) #Primer 9
   107     assert limit((sin(x)-sin(a))/(x-a),x,a) == cos(a) #222, *176
   108     assert limit((cos(x)-cos(a))/(x-a),x,a) == -sin(a) #223
   109     assert limit((sin(x+h)-sin(x))/h,h,0) == cos(x) #225
   110 
   111 def test_f2a():
   112     assert limit(((x+1)/(2*x+1))**(x**2),x,oo) == 0 #Primer 8
   113 
   114 def test_f2():
   115     assert limit((sqrt(cos(x))-sqrt3(cos(x)))/(sin(x)**2),x,0) == -Rational(1,12) #*184
   116 
   117 @XFAIL
   118 def test_f3():
   119     a = Symbol('a', real=True)
   120     #issue 405
   121     assert limit(asin(a*x)/x, x, 0) == a