def test_Limits_simple_1(): assert limit((x + 1) * (x + 2) * (x + 3) / x**3, x, oo) == 1 # 172 assert limit(sqrt(x + 1) - sqrt(x), x, oo) == 0 # 179 assert limit((2 * x - 3) * (3 * x + 5) * (4 * x - 6) / (3 * x**3 + x - 1), x, oo) == 8 # Primjer 1 assert limit(x / root3(x**3 + 10), x, oo) == 1 # Primjer 2 assert limit((x + 1)**2 / (x**2 + 1), x, oo) == 1 # 181

def test_Limits_simple_4a(): assert limit((sqrt(x) - sqrt(a)) / (x - a), x, a) == 1 / (2 * sqrt(a)) # Primer 5 assert limit((sqrt(x) - 1) / (root3(x) - 1), x, 1) == Rational(3) / 2 # 205 assert limit((sqrt(1 + x) - sqrt(1 - x)) / x, x, 0) == 1 # 207 assert limit(sqrt(x**2 - 5 * x + 6) - x, x, oo) == -Rational(5) / 2 # 213

def test_erf(): assert erf(nan) == nan assert erf(oo) == 1 assert erf(-oo) == -1 assert erf(0) == 0 assert erf(I * oo) == oo * I assert erf(-I * oo) == -oo * I assert erf(-2) == -erf(2) assert erf(-x * y) == -erf(x * y) assert erf(-x - y) == -erf(x + y) assert erf(erfinv(x)) == x assert erf(erfcinv(x)) == 1 - x assert erf(erf2inv(0, x)) == x assert erf(erf2inv(0, erf(erfcinv(1 - erf(erfinv(x)))))) == x assert erf(I).is_extended_real is False assert erf(w).is_extended_real is True assert erf(z).is_extended_real is None assert conjugate(erf(z)) == erf(conjugate(z)) assert erf(x).as_leading_term(x) == 2 * x / sqrt(pi) assert erf(1 / x).as_leading_term(x) == erf(1 / x) assert erf(z).rewrite('uppergamma') == sqrt(z**2) * erf(sqrt(z**2)) / z assert erf(z).rewrite('erfc') == S.One - erfc(z) assert erf(z).rewrite('erfi') == -I * erfi(I * z) assert erf(z).rewrite('fresnels') == (1 + I) * ( fresnelc(z * (1 - I) / sqrt(pi)) - I * fresnels(z * (1 - I) / sqrt(pi))) assert erf(z).rewrite('fresnelc') == (1 + I) * ( fresnelc(z * (1 - I) / sqrt(pi)) - I * fresnels(z * (1 - I) / sqrt(pi))) assert erf(z).rewrite('hyper') == 2 * z * hyper([S.Half], [3 * S.Half], -z**2) / sqrt(pi) assert erf(z).rewrite('meijerg') == z * meijerg([S.Half], [], [0], [-S.Half], z**2) / sqrt(pi) assert erf(z).rewrite( 'expint') == sqrt(z**2) / z - z * expint(S.Half, z**2) / sqrt(S.Pi) assert limit(exp(x)*exp(x**2)*(erf(x + 1/exp(x)) - erf(x)), x, oo) == \ 2/sqrt(pi) assert limit((1 - erf(z)) * exp(z**2) * z, z, oo) == 1 / sqrt(pi) assert limit((1 - erf(x)) * exp(x**2) * sqrt(pi) * x, x, oo) == 1 assert limit(((1 - erf(x)) * exp(x**2) * sqrt(pi) * x - 1) * 2 * x**2, x, oo) == -1 assert erf(x).as_real_imag() == \ ((erf(re(x) - I*re(x)*Abs(im(x))/Abs(re(x)))/2 + erf(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))/2, I*(erf(re(x) - I*re(x)*Abs(im(x))/Abs(re(x))) - erf(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))) * re(x)*Abs(im(x))/(2*im(x)*Abs(re(x))))) pytest.raises(ArgumentIndexError, lambda: erf(x).fdiff(2))

def test_sympyissue_18176(): x = Symbol('x', real=True, positive=True) n = Symbol('n', integer=True, positive=True) k = Symbol('k') e = x**n - x**(n - k) assert limit(e.subs({k: 0}), x, oo) == 0 assert limit(e.subs({k: 1}), x, oo) == oo

def test_harmonic_limit(): n = Symbol("n") m = Symbol("m", positive=True) assert limit(harmonic(n, m + 1), n, oo) == zeta(m + 1) assert limit(harmonic(n, 2), n, oo) == pi**2/6 assert limit(harmonic(n, 3), n, oo) == -polygamma(2, 1)/2

def test_harmonic_limit(): n = Symbol('n') m = Symbol('m', positive=True) assert limit(harmonic(n, m + 1), n, oo) == zeta(m + 1) assert limit(harmonic(n, 2), n, oo) == pi**2 / 6 assert limit(harmonic(n, 3), n, oo) == -polygamma(2, 1) / 2

def test_Limits_simple_4a(): assert limit((sqrt(x) - sqrt(a)) / (x - a), x, a) == 1 / (2 * sqrt(a)) # Example 5 assert limit((sqrt(x) - 1) / (root(x, 3) - 1), x, 1) == Rational(3, 2) # 205 assert limit((sqrt(1 + x) - sqrt(1 - x)) / x, x, 0) == 1 # 207 assert limit(sqrt(x**2 - 5 * x + 6) - x, x, oo) == -Rational(5, 2) # 213

def test_exponential(): x = Symbol('x', extended_real=True) assert limit((1 + x/n)**n, n, oo) == exp(x) assert limit((1 + x/(2*n))**n, n, oo) == exp(x/2) assert limit((1 + x/(2*n + 1))**n, n, oo) == exp(x/2) assert limit(((x - 1)/(x + 1))**x, x, oo) == exp(-2) assert limit(1 + (1 + 1/x)**x, x, oo) == 1 + E

def test_issue_75(): assert limit(abs(log(x)), x, oo) == oo assert limit(tan(abs(pi/2 + 1/x))/acosh(pi/2 + 1/x), x, oo) == -oo assert limit(tan(abs(pi/2 - 1/x))/acosh(pi/2 - 1/x), x, oo) == +oo assert limit(abs(log(2 + 1/x)) - log(2 + 1/x), x, oo) == 0 assert limit(abs(log(2 - 1/x)) - log(2 - 1/x), x, oo) == 0

def test_exponential(): x = Symbol('x', extended_real=True) assert limit((1 + x/n)**n, n, oo) == exp(x) assert limit((1 + x/(2*n))**n, n, oo) == exp(x/2) assert limit((1 + x/(2*n + 1))**n, n, oo) == exp(x/2) assert limit(((x - 1)/(x + 1))**x, x, oo) == exp(-2) assert limit(1 + (1 + 1/x)**x, x, oo) == 1 + S.Exp1

def test_Limits_simple_1(): assert limit((n + 1) * (n + 2) * (n + 3) / n**3, n, oo) == 1 # 172 assert limit(sqrt(n + 1) - sqrt(n), n, oo) == 0 # 179 assert limit((2 * x - 3) * (3 * x + 5) * (4 * x - 6) / (3 * x**3 + x - 1), x, oo) == 8 # Example 1 assert limit(x / root(x**3 + 10, 3), x, oo) == 1 # Example 2 assert limit((x + 1)**2 / (x**2 + 1), x, oo) == 1 # 181

def test_gruntz_other(): assert limit(sqrt(log(x + 1)) - sqrt(log(x)), x, oo) == 0 # p12, 2.5 assert limit(((1 + 1/x)**y - 1)*x, x, oo) == y # p12, 2.6 assert limit(x**n/exp(x), x, oo) == 0 # p14, 2.9 assert limit((1 + 1/x)*x - 1/log(1 + 1/x), x, oo) == Rational(1, 2) # p15, 2.10 assert limit((root(1 + 1/x, n) - 1)/(root(1 + 1/x, m) - 1), x, oo) == m/n # p13, 2.7

def test_sympyissue_11526(): df = diff(1/(a*log((x - b)/(x - c))), x) res = -1/(-a*c + a*b) assert limit(df, x, oo) == res assert limit(simplify(df), x, oo) == res e = log((1/x - b)/(1/x - c)) assert e.as_leading_term(x) == x*(c - b)

def test_sympyissue_21029(): e = (sinh(x) + cosh(x) - 1)/x/4 ans0 = Rational(1, 4) ansz = (exp(z) - 1)/z/4 assert limit(e, x, 0) == ans0 assert limit(e, x, z) == ansz assert limit(ansz, z, 0) == ans0

def test_issue_55(): assert limit((x + exp(x))/(x - 1), x, -oo) == 1 assert limit((x*exp(x))/(exp(x) - 1), x, -oo) == 0 # issue sympy/sympy#2929 # issue sympy/sympy#22982 assert limit((log(E + 1/x) - 1)**(1 - sqrt(E + 1/x)), x, oo) == oo assert limit((log(E + 1/x))**(1 - sqrt(E + 1/x)), x, oo) == 1 assert limit((log(E + 1/x) - 1)**-sqrt(E + 1/x), x, oo) == oo

def test_sympyissue_17431(): assert limit(((n + 1) + 1)/(((n + 1) + 2)*factorial(n + 1)) * (n + 2)*factorial(n)/(n + 1), n, oo) == 0 assert limit((n + 2)**2*factorial(n)/((n + 1)*(n + 3)*factorial(n + 1)), n, oo) == 0 # test from sympy/sympy#17434 (see also diofant/diofant#425): y = symbols('y', integer=True, positive=True) assert isinstance(limit(x*factorial(x)/factorial(x + y), x, oo), Limit)

def test_sympyissue_22220(): e1 = sqrt(30)*atan(sqrt(30)*tan(x/2)/6)/30 e2 = sqrt(30)*I*(-log(sqrt(2)*tan(x/2) - 2*sqrt(15)*I/5) + +log(sqrt(2)*tan(x/2) + 2*sqrt(15)*I/5))/60 assert limit(e1, x, -pi) == -sqrt(30)*pi/60 assert limit(e2, x, -pi) == -sqrt(30)*pi/30 assert limit(e1, x, -pi, 1) == sqrt(30)*pi/60 assert limit(e2, x, -pi, 1) == 0

def test_sympyissue_5172(): r = Symbol('r', positive=True) p = Symbol('p', positive=True) m = Symbol('m', negative=True) expr = ((2*n*(n - r + 1)/(n + r*(n - r + 1)))**c + (r - 1)*(n*(n - r + 2)/(n + r*(n - r + 1)))**c - n)/(n**c - n) expr = expr.subs({c: c + 1}) assert limit(expr.subs({c: m}), n, oo) == 1 assert limit(expr.subs({c: p}), n, oo) == (2**(p + 1) + r - 1)/(r + 1)**(p + 1)

def test_basic4(): assert limit(2*x + y*x, x, 0) == 0 assert limit(2*x + y*x, x, 1) == 2 + y assert limit(2*x**8 + y*x**(-3), x, -2) == 512 - y/8 assert limit(sqrt(x + 1) - sqrt(x), x, oo) == 0 assert integrate(1/(x**3 + 1), (x, 0, oo)) == 2*pi*sqrt(3)/9 # coverage test l = Limit(Piecewise((x, x > 1), (0, True)), x, -1) assert l.doit() == l

def test_sympyissue_5172(): r = Symbol('r', positive=True) p = Symbol('p', positive=True) m = Symbol('m', negative=True) expr = ((2*n*(n - r + 1)/(n + r*(n - r + 1)))**c + (r - 1)*(n*(n - r + 2)/(n + r*(n - r + 1)))**c - n)/(n**c - n) expr = expr.subs(c, c + 1) assert limit(expr.subs(c, m), n, oo) == 1 assert limit(expr.subs(c, p), n, oo).simplify() == \ (2**(p + 1) + r - 1)/(r + 1)**(p + 1)

def test_sympyissue_5172(): r = Symbol('r', positive=True) p = Symbol('p', positive=True) m = Symbol('m', negative=True) expr = ((2*n*(n - r + 1)/(n + r*(n - r + 1)))**c + (r - 1)*(n*(n - r + 2)/(n + r*(n - r + 1)))**c - n)/(n**c - n) expr = expr.subs({c: c + 1}) assert limit(expr.subs({c: m}), n, oo) == 1 assert limit(expr.subs({c: p}), n, oo).simplify() == \ (2**(p + 1) + r - 1)/(r + 1)**(p + 1)

def test_sympyissue_8635(): n = Symbol('n', integer=True, positive=True) k = 0 assert limit(x**n - x**(n - k), x, oo) == 0 k = 1 assert limit(x**n - x**(n - k), x, oo) == oo k = 2 assert limit(x**n - x**(n - k), x, oo) == oo k = 3 assert limit(x**n - x**(n - k), x, oo) == oo

def test_acosh(): assert limit(acosh(I*x), x, 0) == 2*log(1 + I) - log(2) assert limit(acosh(I*x), x, 0, 1) == 2*log(1 - I) - log(2) assert limit(acosh(-I*x), x, 0) == 2*log(1 - I) - log(2) assert limit(acosh(-I*x), x, 0, 1) == 2*log(1 + I) - log(2) pytest.raises(PoleError, lambda: limit(acosh(I*x), x, 0, Reals)) assert limit(acosh(x - I*x), x, 0) == 2*log(1 - I) - log(2) assert limit(acosh(x - I*x), x, 0, 1) == 2*log(1 + I) - log(2) pytest.raises(PoleError, lambda: limit(acosh(x - I*x), x, 0, Reals)) assert limit(acosh(I*x**2), x, 0, Reals) == 2*log(1 + I) - log(2) assert limit(acosh(x**2 - I*x**2), x, 0, Reals) == 2*log(1 - I) - log(2)

def test_sympyissue_16722(): n, z = symbols('n z') assert isinstance(limit(binomial(n + z, n)*n**-z, n, oo), Limit) z = symbols('z', positive=True) assert limit(binomial(n + z, n)*n**-z, n, oo) == 1/gamma(z + 1) n = symbols('n', positive=True, integer=True) z = symbols('z', positive=True) assert isinstance(limit(binomial(n + z, n)*n**-z, n, oo), Limit) n, z = symbols('n z', positive=True, integer=True) assert isinstance(limit(binomial(n + z, n)*n**-z, n, oo), Limit)

def test_sympyissue_19453(): beta = Symbol('beta', real=True, positive=True) h = Symbol('h', real=True, positive=True) m = Symbol('m', real=True, positive=True) w = Symbol('omega', real=True, positive=True) g = Symbol('g', real=True, positive=True) q = 3*h**2*beta*g*exp(h*beta*w/2) p = m**2*w**2 s = exp(h*beta*w) - 1 z = (-q/(4*p*s) - q/(2*p*s**2) - q*(exp(h*beta*w) + 1)/(2*p*s**3) + exp(h*beta*w/2)/s) e = -diff(log(z), beta) assert limit(e - h*w/2, beta, oo) == 0 assert limit(e.simplify() - h*w/2, beta, oo) == 0

def test_floor_requires_robust_assumptions(): assert limit(floor(sin(x)), x, 0, "+") == 0 assert limit(floor(sin(x)), x, 0, "-") == -1 assert limit(floor(cos(x)), x, 0, "+") == 0 assert limit(floor(cos(x)), x, 0, "-") == 0 assert limit(floor(5 + sin(x)), x, 0, "+") == 5 assert limit(floor(5 + sin(x)), x, 0, "-") == 4 assert limit(floor(5 + cos(x)), x, 0, "+") == 5 assert limit(floor(5 + cos(x)), x, 0, "-") == 5

def test_Limits_simple_2(): assert limit(1000 * x / (x**2 - 1), x, oo) == 0 # 182 assert limit((x**2 - 5 * x + 1) / (3 * x + 7), x, oo) == oo # 183 assert limit((2 * x**2 - x + 3) / (x**3 - 8 * x + 5), x, oo) == 0 # 184 assert limit((2 * x**2 - 3 * x - 4) / sqrt(x**4 + 1), x, oo) == 2 # 186 assert limit((2 * x + 3) / (x + root3(x)), x, oo) == 2 # 187 assert limit(x**2 / (10 + x * sqrt(x)), x, oo) == oo # 188 assert limit(root3(x**2 + 1) / (x + 1), x, oo) == 0 # 189 assert limit(sqrt(x) / sqrt(x + sqrt(x + sqrt(x))), x, oo) == 1 # 190

def test_ceiling_requires_robust_assumptions(): assert limit(ceiling(sin(x)), x, 0, "+") == 1 assert limit(ceiling(sin(x)), x, 0, "-") == 0 assert limit(ceiling(cos(x)), x, 0, "+") == 1 assert limit(ceiling(cos(x)), x, 0, "-") == 1 assert limit(ceiling(5 + sin(x)), x, 0, "+") == 6 assert limit(ceiling(5 + sin(x)), x, 0, "-") == 5 assert limit(ceiling(5 + cos(x)), x, 0, "+") == 6 assert limit(ceiling(5 + cos(x)), x, 0, "-") == 6

def test_basic2(): assert limit(x**x, x, 0, dir="+") == 1 assert limit((exp(x) - 1)/x, x, 0) == 1 assert limit(1 + 1/x, x, oo) == 1 assert limit(-exp(1/x), x, oo) == -1 assert limit(x + exp(-x), x, oo) == oo assert limit(x + exp(-x**2), x, oo) == oo assert limit(x + exp(-exp(x)), x, oo) == oo assert limit(13 + 1/x - exp(-x), x, oo) == 13

def test_acoth(): assert limit(acoth(x), x, 0) == -I*pi/2 assert limit(acoth(x), x, 0, 1) == I*pi/2 pytest.raises(PoleError, lambda: limit(acoth(x), x, 0, Reals)) assert limit(acoth(-x), x, 0) == I*pi/2 assert limit(acoth(x**2), x, 0, Reals) == -I*pi/2 assert limit(acoth(I*x), x, 0) == -I*pi/2 assert limit(acoth(I*x), x, 0, 1) == I*pi/2 pytest.raises(PoleError, lambda: limit(acoth(x - I*x), x, 0, Reals))

def test_issue_74(): assert limit(sign(log(1 + 1/x)), x, oo) == +1 assert limit(sign(log(1 - 1/x)), x, oo) == -1 assert limit(sign(sin(+1/x)), x, oo) == +1 assert limit(sign(sin(-1/x)), x, oo) == -1 assert limit(sign(tan(+1/x)), x, oo) == +1 assert limit(sign(tan(-1/x)), x, oo) == -1 assert limit(sign(cos(pi/2 + 1/x)), x, oo) == -1 assert limit(sign(cos(pi/2 - 1/x)), x, oo) == +1

def test_sympyissue_11678(): p = Matrix([[1./2, 1./4, 1./4], [1./2, 0, 1./2], [1./4, 0, 3./4]]) e = (p**x).applyfunc(lambda i: limit(i, x, oo)) assert e == Matrix([[Float('0.36363636363636359', prec=15), Float('0.090909090909090898', prec=15), Float('0.54545454545454541', prec=15)]]*3)

def test_sympyissue_11678(): p = Matrix([[1./2, 1./4, 1./4], [1./2, 0, 1./2], [1./4, 0, 3./4]]) e = (p**x).applyfunc(lambda i: limit(i, x, oo)) assert e == Matrix([[Float('0.36363636363636359', dps=15), Float('0.090909090909090898', dps=15), Float('0.54545454545454541', dps=15)]]*3)

def test_diofantissue_558(): n = Symbol('n') r = Symbol('r', positive=True) c = Symbol('c') expr = ((2*n*(n - r + 1)/(n + r*(n - r + 1)))**c + (r - 1)*(n*(n - r + 2)/(n + r*(n - r + 1)))**c - n)/(n**c - n) expr = expr.subs({c: c + 1}) assert limit(expr, n, oo) == Limit(expr, n, oo)

def test_basic5(): class my(Function): @classmethod def eval(cls, arg): if arg is oo: return nan assert limit(my(x), x, oo) == Limit(my(x), x, oo) assert limit(4/x > 8, x, 0) # relational test assert limit(my(x) > 0, x, oo) == Limit(my(x) > 0, x, oo) # from https://groups.google.com/forum/#!topic/sympy/LkTMQKC_BOw # fix bisected to ade6d20 and c459d18 a = Symbol('a', positive=True) f = exp(x*(-a - 1)) * sinh(x) assert limit(f, x, oo) == 0 assert limit(O(x), x, x**2) == Limit(O(x), x, x**2)

def test_extended_real_line(): assert limit(x - oo, x, oo) == -oo assert limit(oo - x, x, -oo) == oo assert limit(x**2/(x - 5) - oo, x, oo) == -oo assert limit(1/(x + sin(x)) - oo, x, 0) == -oo assert limit(oo/x, x, oo) == oo assert limit(x - oo + 1/x, x, oo) == -oo assert limit(x - oo + 1/x, x, 0) == -oo

def test_sympyissue_4546(): # using list(...) so py.test can recalculate values tests = list(itertools.product([cot, tan], [-pi/2, 0, pi/2, pi, 3*pi/2], ['-', '+'])) results = (0, 0, -oo, oo, 0, 0, -oo, oo, 0, 0, oo, -oo, 0, 0, oo, -oo, 0, 0, oo, -oo) assert len(tests) == len(results) for i, (args, res) in enumerate(zip(tests, results)): f, l, d = args eq = f(x) assert limit(eq, x, l, dir=d) == res

def test_sympyissue_12769(): r, z, x = symbols('r,z,x', real=True) a, b, s0, K, F0, s, T = symbols('a,b,s0,K,F0,s,T', positive=True, real=True) fx = (F0**b*K**b*r*s0 - sqrt((F0**2*K**(2*b)*a**2*(b - 1) + F0**(2*b)*K**2*a**2*(b - 1) + F0**(2*b)*K**(2*b)*s0**2*(b - 1)*(b**2 - 2*b + 1) - 2*F0**(2*b)*K**(b + 1)*a*r*s0*(b**2 - 2*b + 1) + 2*F0**(b + 1)*K**(2*b)*a*r*s0*(b**2 - 2*b + 1) - 2*F0**(b + 1)*K**(b + 1)*a**2*(b - 1))/((b - 1)*(b**2 - 2*b + 1))))*(b*r - b - r + 1) assert limit(fx, K, F0) == (F0**(2*b)*b*r**2*s0 - 2*F0**(2*b)*b*r*s0 + F0**(2*b)*b*s0 - F0**(2*b)*r**2*s0 + 2*F0**(2*b)*r*s0 - F0**(2*b)*s0)

def test_sympyissue_5184(): assert limit(sin(x)/x, x, oo) == 0 assert limit(atan(x), x, oo) == pi/2 assert limit(gamma(x), x, oo) == oo assert limit(cos(x)/x, x, oo) == 0 assert limit(gamma(x), x, Rational(1, 2)) == sqrt(pi) r = Symbol('r', real=True) assert limit(r*sin(1/r), r, 0) == 0

def test_sympyissue_5183(): # using list(...) so py.test can recalculate values tests = list(itertools.product([x, -x], [-1, 1], [2, 3, Rational(1, 2), Rational(2, 3)], ['-', '+'])) results = (oo, oo, -oo, oo, -oo*I, oo, -oo*sign(cbrt(-1)), oo, 0, 0, 0, 0, 0, 0, 0, 0, oo, oo, oo, -oo, oo, -oo*I, oo, -oo*sign(cbrt(-1)), 0, 0, 0, 0, 0, 0, 0, 0) assert len(tests) == len(results) for i, (args, res) in enumerate(zip(tests, results)): y, s, e, d = args eq = y**(s*e) assert limit(eq, x, 0, dir=d) == res

def test_factorial(): f = factorial(x) assert limit(f, x, oo) == oo assert limit(x/f, x, oo) == 0 # see Stirling's approximation: # https//en.wikipedia.org/wiki/Stirling's_approximation assert limit(f/(sqrt(2*pi*x)*(x/E)**x), x, oo) == 1 assert limit(f, x, -oo) == factorial(-oo) assert (limit(f, x, x**2) - factorial(x**2)).simplify() == 0 assert (limit(f, x, -x**2) - factorial(-x**2)).simplify() == 0

def test_abs(): assert limit(abs(x), x, 0) == 0 assert limit(abs(sin(x)), x, 0) == 0 assert limit(abs(cos(x)), x, 0) == 1 assert limit(abs(sin(x + 1)), x, 0) == sin(1) # sympy/sympy#12398 assert limit(abs(log(n)/n**3), n, oo) == 0 expr = abs(log(n)/n**3) expr2 = expr.subs({n: n + 1}) assert limit(n*(expr/expr2 - 1), n, oo) == 3

def test_function_series1(): """Create our new "sin" function.""" class my_function(Function): def fdiff(self, argindex=1): return cos(self.args[0]) @classmethod def eval(cls, arg): arg = sympify(arg) if arg == 0: return sympify(0) # Test that the taylor series is correct assert my_function(x).series(x, 0, 10) == sin(x).series(x, 0, 10) assert limit(my_function(x)/x, x, 0) == 1

def test_ci(): m1 = exp_polar(I*pi) m1_ = exp_polar(-I*pi) pI = exp_polar(I*pi/2) mI = exp_polar(-I*pi/2) assert Ci(m1*x) == Ci(x) + I*pi assert Ci(m1_*x) == Ci(x) - I*pi assert Ci(pI*x) == Chi(x) + I*pi/2 assert Ci(mI*x) == Chi(x) - I*pi/2 assert Chi(m1*x) == Chi(x) + I*pi assert Chi(m1_*x) == Chi(x) - I*pi assert Chi(pI*x) == Ci(x) + I*pi/2 assert Chi(mI*x) == Ci(x) - I*pi/2 assert Ci(exp_polar(2*I*pi)*x) == Ci(x) + 2*I*pi assert Chi(exp_polar(-2*I*pi)*x) == Chi(x) - 2*I*pi assert Chi(exp_polar(2*I*pi)*x) == Chi(x) + 2*I*pi assert Ci(exp_polar(-2*I*pi)*x) == Ci(x) - 2*I*pi assert Ci(oo) == 0 assert Ci(-oo) == I*pi assert Chi(oo) == oo assert Chi(-oo) == oo assert mytd(Ci(x), cos(x)/x, x) assert mytd(Chi(x), cosh(x)/x, x) assert mytn(Ci(x), Ci(x).rewrite(Ei), Ei(x*exp_polar(-I*pi/2))/2 + Ei(x*exp_polar(I*pi/2))/2, x) assert mytn(Chi(x), Chi(x).rewrite(Ei), Ei(x)/2 + Ei(x*exp_polar(I*pi))/2 - I*pi/2, x) assert tn_arg(Ci) assert tn_arg(Chi) assert Ci(x).nseries(x, n=4) == \ EulerGamma + log(x) - x**2/4 + x**4/96 + O(x**6) assert Chi(x).nseries(x, n=4) == \ EulerGamma + log(x) + x**2/4 + x**4/96 + O(x**6) assert limit(log(x) - Ci(2*x), x, 0) == -log(2) - EulerGamma

def test_sympyissue_14811(): assert limit(((1 + Rational(2, 3)**(x + 1))**2**x)/(2**Rational(4, 3)**(x - 1)), x, oo) == oo

def test_sympyissue_4329(): assert tan(x).series(x, pi/2, n=3).removeO() == \ -pi/6 + x/3 - 1/(x - pi/2) assert cot(x).series(x, pi, n=3).removeO() == \ -x/3 + pi/3 + 1/(x - pi) assert limit(tan(x)**tan(2*x), x, pi/4) == exp(-1)

def test_sympyissue_14590(): assert limit((n**3*((n + 1)/n)**n)/((n + 1)*(n + 2)*(n + 3)), n, oo) == E

def test_sympyissue_14793(): e = ((x + Rational(1, 2))*log(x) - x + log(2*pi)/2 - log(factorial(x)) + 1/(12*x))*x**3 assert limit(e, x, oo) == Rational(1, 360)

def test_sympyissue_15055(): assert limit(n**3*((-n - 1)*sin(1/n) + (n + 2)*sin(1/(n + 1)))/(-n + 1), n, oo) == 1

def test_sympyissue_15146(): assert limit((n/2)*(-2*n**3 - 2*(n**3 - 1)*n**2*digamma(n**3 + 1) + 2*(n**3 - 1)*n**2*digamma(n**3 + n + 1) + n + 3), n, oo) == Rational(1, 3)

def test_sympyissue_15323(): assert limit(((1 - 1/x)**x).diff(x), x, 1) == 1

def test_basic3(): assert limit(1/x, x, 0, dir="+") == oo assert limit(1/x, x, 0, dir="-") == -oo

def test_basic4(): assert limit(2*x + y*x, x, 0) == 0 assert limit(2*x + y*x, x, 1) == 2 + y assert limit(2*x**8 + y*x**(-3), x, -2) == 512 - y/8 assert limit(sqrt(x + 1) - sqrt(x), x, oo) == 0 assert integrate(1/(x**3 + 1), (x, 0, oo)) == 2*pi*sqrt(3)/9

def test_erf(): assert erf(nan) == nan assert erf(oo) == 1 assert erf(-oo) == -1 assert erf(0) == 0 assert erf(I*oo) == oo*I assert erf(-I*oo) == -oo*I assert erf(-2) == -erf(2) assert erf(-x*y) == -erf(x*y) assert erf(-x - y) == -erf(x + y) assert erf(erfinv(x)) == x assert erf(erfcinv(x)) == 1 - x assert erf(erf2inv(0, x)) == x assert erf(erf2inv(0, erf(erfcinv(1 - erf(erfinv(x)))))) == x assert erf(I).is_extended_real is False assert erf(w).is_extended_real is True assert erf(z).is_extended_real is None assert conjugate(erf(z)) == erf(conjugate(z)) assert erf(x).as_leading_term(x) == 2*x/sqrt(pi) assert erf(1/x).as_leading_term(x) == erf(1/x) assert erf(z).rewrite('uppergamma') == sqrt(z**2)*erf(sqrt(z**2))/z assert erf(z).rewrite('erfc') == 1 - erfc(z) assert erf(z).rewrite('erfi') == -I*erfi(I*z) assert erf(z).rewrite('fresnels') == (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) - I*fresnels(z*(1 - I)/sqrt(pi))) assert erf(z).rewrite('fresnelc') == (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) - I*fresnels(z*(1 - I)/sqrt(pi))) assert erf(z).rewrite('hyper') == 2*z*hyper([Rational(1, 2)], [Rational(3, 2)], -z**2)/sqrt(pi) assert erf(z).rewrite('meijerg') == z*meijerg([Rational(1, 2)], [], [0], [Rational(-1, 2)], z**2)/sqrt(pi) assert erf(z).rewrite('expint') == sqrt(z**2)/z - z*expint(Rational(1, 2), z**2)/sqrt(pi) assert limit(exp(x)*exp(x**2)*(erf(x + 1/exp(x)) - erf(x)), x, oo) == \ 2/sqrt(pi) assert limit((1 - erf(z))*exp(z**2)*z, z, oo) == 1/sqrt(pi) assert limit((1 - erf(x))*exp(x**2)*sqrt(pi)*x, x, oo) == 1 assert limit(((1 - erf(x))*exp(x**2)*sqrt(pi)*x - 1)*2*x**2, x, oo) == -1 l = Limit((1 - erf(y/x))*exp(y**2/x**2), x, 0) assert l.doit() == l # cover _erfs._eval_aseries assert erf(x).as_real_imag() == \ ((erf(re(x) - I*re(x)*Abs(im(x))/Abs(re(x)))/2 + erf(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))/2, I*(erf(re(x) - I*re(x)*Abs(im(x))/Abs(re(x))) - erf(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))) * re(x)*Abs(im(x))/(2*im(x)*Abs(re(x))))) assert erf(x).as_real_imag() == erf(x).as_real_imag(deep=False) assert erf(w).as_real_imag() == (erf(w), 0) assert erf(w).as_real_imag() == erf(w).as_real_imag(deep=False) assert erf(I).as_real_imag() == (0, erfi(1)) pytest.raises(ArgumentIndexError, lambda: erf(x).fdiff(2)) assert erf(x).taylor_term(3, x, *(2*x/sqrt(pi), 0)) == -2*x**3/3/sqrt(pi)