def test_heurisch_hacking(): assert (heurisch(sqrt(1 + 7 * x**2), x, hints=[]) == x * sqrt(1 + 7 * x**2) / 2 + sqrt(7) * asinh(sqrt(7) * x) / 14) assert (heurisch(sqrt(1 - 7 * x**2), x, hints=[]) == x * sqrt(1 - 7 * x**2) / 2 + sqrt(7) * asin(sqrt(7) * x) / 14) assert heurisch(sqrt(y * x**2 - 1), x, hints=[]) is None assert (heurisch(1 / sqrt(1 + 7 * x**2), x, hints=[]) == sqrt(7) * asinh(sqrt(7) * x) / 7) assert (heurisch(1 / sqrt(1 - 7 * x**2), x, hints=[]) == sqrt(7) * asin(sqrt(7) * x) / 7) assert heurisch(exp(-7 * x**2), x, hints=[]) == sqrt(7 * pi) * erf(sqrt(7) * x) / 14 assert heurisch(exp(2 * x**2), x, hints=[]) == sqrt(2) * sqrt(pi) * erfi(sqrt(2) * x) / 4 assert (heurisch(exp(2 * x**2 - 3 * x), x, hints=[]) == sqrt(2) * sqrt(pi) * erfi(sqrt(2) * x - 3 * sqrt(2) / 4) / (4 * E**Rational(9, 8))) assert heurisch(1 / sqrt(9 - 4 * x**2), x, hints=[]) == asin(2 * x / 3) / 2 assert heurisch(1 / sqrt(9 + 4 * x**2), x, hints=[]) == asinh(2 * x / 3) / 2 assert heurisch(li(x), x, hints=[]) == x * li(x) - Ei(2 * log(x)) assert heurisch(li(log(x)), x, hints=[]) is None assert (heurisch(sqrt(1 + x), x, hints=[x, sqrt(1 + x)]) == 2 * x * sqrt(x + 1) / 3 + 2 * sqrt(x + 1) / 3)
def test_erf2(): assert erf2(0, 0) == S.Zero assert erf2(x, x) == S.Zero assert erf2(nan, 0) == nan assert erf2(-oo, y) == erf(y) + 1 assert erf2( oo, y) == erf(y) - 1 assert erf2( x, oo) == 1 - erf(x) assert erf2( x, -oo) == -1 - erf(x) assert erf2(x, erf2inv(x, y)) == y assert erf2(-x, -y) == -erf2(x, y) assert erf2(-x, y) == erf(y) + erf(x) assert erf2( x, -y) == -erf(y) - erf(x) assert erf2(x, y).rewrite('fresnels') == erf(y).rewrite(fresnels)-erf(x).rewrite(fresnels) assert erf2(x, y).rewrite('fresnelc') == erf(y).rewrite(fresnelc)-erf(x).rewrite(fresnelc) assert erf2(x, y).rewrite('hyper') == erf(y).rewrite(hyper)-erf(x).rewrite(hyper) assert erf2(x, y).rewrite('meijerg') == erf(y).rewrite(meijerg)-erf(x).rewrite(meijerg) assert erf2(x, y).rewrite('uppergamma') == erf(y).rewrite(uppergamma) - erf(x).rewrite(uppergamma) assert erf2(x, y).rewrite('expint') == erf(y).rewrite(expint)-erf(x).rewrite(expint) assert erf2(I, w).is_extended_real is False assert erf2(2*w, w).is_extended_real is True assert erf2(z, w).is_extended_real is None assert erf2(w, z).is_extended_real is None assert conjugate(erf2(x, y)) == erf2(conjugate(x), conjugate(y)) assert erf2(x, y).rewrite('erf') == erf(y) - erf(x) assert erf2(x, y).rewrite('erfc') == erfc(x) - erfc(y) assert erf2(x, y).rewrite('erfi') == I*(erfi(I*x) - erfi(I*y)) pytest.raises(ArgumentIndexError, lambda: erfi(x).fdiff(3))
def test_erfc(): assert erfc(nan) == nan assert erfc(oo) == 0 assert erfc(-oo) == 2 assert erfc(0) == 1 assert erfc(I * oo) == -oo * I assert erfc(-I * oo) == oo * I assert erfc(-x) == Integer(2) - erfc(x) assert erfc(erfcinv(x)) == x assert erfc(erfinv(x)) == 1 - x assert erfc(I).is_extended_real is False assert erfc(w).is_extended_real is True assert erfc(z).is_extended_real is None assert conjugate(erfc(z)) == erfc(conjugate(z)) assert erfc(x).as_leading_term(x) == 1 assert erfc(1 / x).as_leading_term(x) == erfc(1 / x) assert erfc(z).rewrite('erf') == 1 - erf(z) assert erfc(z).rewrite('erfi') == 1 + I * erfi(I * z) assert erfc(z).rewrite('fresnels') == 1 - (1 + I) * ( fresnelc(z * (1 - I) / sqrt(pi)) - I * fresnels(z * (1 - I) / sqrt(pi))) assert erfc(z).rewrite('fresnelc') == 1 - (1 + I) * ( fresnelc(z * (1 - I) / sqrt(pi)) - I * fresnels(z * (1 - I) / sqrt(pi))) assert erfc(z).rewrite('hyper') == 1 - 2 * z * hyper( [Rational(1, 2)], [Rational(3, 2)], -z**2) / sqrt(pi) assert erfc(z).rewrite('meijerg') == 1 - z * meijerg( [Rational(1, 2)], [], [0], [Rational(-1, 2)], z**2) / sqrt(pi) assert erfc(z).rewrite( 'uppergamma') == 1 - sqrt(z**2) * erf(sqrt(z**2)) / z assert erfc(z).rewrite('expint') == 1 - sqrt(z**2) / z + z * expint( Rational(1, 2), z**2) / sqrt(pi) assert erfc(x).as_real_imag() == \ ((erfc(re(x) - I*re(x)*abs(im(x))/abs(re(x)))/2 + erfc(re(x) + I*re(x)*abs(im(x))/abs(re(x)))/2, I*(erfc(re(x) - I*re(x)*abs(im(x))/abs(re(x))) - erfc(re(x) + I*re(x)*abs(im(x))/abs(re(x)))) * re(x)*abs(im(x))/(2*im(x)*abs(re(x))))) assert erfc(x).as_real_imag(deep=False) == erfc(x).as_real_imag() assert erfc(w).as_real_imag() == (erfc(w), 0) assert erfc(w).as_real_imag(deep=False) == erfc(w).as_real_imag() assert erfc(I).as_real_imag() == (1, -erfi(1)) pytest.raises(ArgumentIndexError, lambda: erfc(x).fdiff(2)) assert erfc(x).taylor_term(3, x, *(-2 * x / sqrt(pi), 0)) == 2 * x**3 / 3 / sqrt(pi) assert erfc(x).limit(x, oo) == 0 assert erfc(x).diff(x) == -2 * exp(-x**2) / sqrt(pi)
def test_erfc(): assert erfc(nan) == nan assert erfc(oo) == 0 assert erfc(-oo) == 2 assert erfc(0) == 1 assert erfc(I*oo) == -oo*I assert erfc(-I*oo) == oo*I assert erfc(-x) == Integer(2) - erfc(x) assert erfc(erfcinv(x)) == x assert erfc(erfinv(x)) == 1 - x assert erfc(I).is_extended_real is False assert erfc(w).is_extended_real is True assert erfc(z).is_extended_real is None assert conjugate(erfc(z)) == erfc(conjugate(z)) assert erfc(x).as_leading_term(x) == 1 assert erfc(1/x).as_leading_term(x) == erfc(1/x) assert erfc(z).rewrite('erf') == 1 - erf(z) assert erfc(z).rewrite('erfi') == 1 + I*erfi(I*z) assert erfc(z).rewrite('fresnels') == 1 - (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) - I*fresnels(z*(1 - I)/sqrt(pi))) assert erfc(z).rewrite('fresnelc') == 1 - (1 + I)*(fresnelc(z*(1 - I)/sqrt(pi)) - I*fresnels(z*(1 - I)/sqrt(pi))) assert erfc(z).rewrite('hyper') == 1 - 2*z*hyper([Rational(1, 2)], [Rational(3, 2)], -z**2)/sqrt(pi) assert erfc(z).rewrite('meijerg') == 1 - z*meijerg([Rational(1, 2)], [], [0], [Rational(-1, 2)], z**2)/sqrt(pi) assert erfc(z).rewrite('uppergamma') == 1 - sqrt(z**2)*erf(sqrt(z**2))/z assert erfc(z).rewrite('expint') == 1 - sqrt(z**2)/z + z*expint(Rational(1, 2), z**2)/sqrt(pi) assert erfc(x).as_real_imag() == \ ((erfc(re(x) - I*re(x)*Abs(im(x))/Abs(re(x)))/2 + erfc(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))/2, I*(erfc(re(x) - I*re(x)*Abs(im(x))/Abs(re(x))) - erfc(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))) * re(x)*Abs(im(x))/(2*im(x)*Abs(re(x))))) assert erfc(x).as_real_imag(deep=False) == erfc(x).as_real_imag() assert erfc(w).as_real_imag() == (erfc(w), 0) assert erfc(w).as_real_imag(deep=False) == erfc(w).as_real_imag() assert erfc(I).as_real_imag() == (1, -erfi(1)) pytest.raises(ArgumentIndexError, lambda: erfc(x).fdiff(2)) assert erfc(x).taylor_term(3, x, *(-2*x/sqrt(pi), 0)) == 2*x**3/3/sqrt(pi) assert erfc(x).limit(x, oo) == 0 assert erfc(x).diff(x) == -2*exp(-x**2)/sqrt(pi)
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_4890(): z = Symbol('z', positive=True) assert integrate(exp(-log(x)**2), x) == \ sqrt(pi)*exp(Rational(1, 4))*erf(log(x)-Rational(1, 2))/2 assert integrate(exp(log(x)**2), x) == \ sqrt(pi)*exp(-Rational(1, 4))*erfi(log(x)+Rational(1, 2))/2 assert integrate(exp(-z*log(x)**2), x) == \ sqrt(pi)*exp(1/(4*z))*erf(sqrt(z)*log(x) - 1/(2*sqrt(z)))/(2*sqrt(z))
def test_sympyissue_3940(): a, b, c, d = symbols('a:d', positive=True, finite=True) assert integrate(exp(-x**2 + I*c*x), x) == \ -sqrt(pi)*exp(-c**2/4)*erf(I*c/2 - x)/2 assert integrate(exp(a*x**2 + b*x + c), x) == \ sqrt(pi)*exp(c)*exp(-b**2/(4*a))*erfi(sqrt(a)*x + b/(2*sqrt(a)))/(2*sqrt(a)) assert expand_mul(integrate(exp(-x**2)*exp(I*k*x), (x, -oo, oo))) == \ sqrt(pi)*exp(-k**2/4) a, d = symbols('a d', positive=True) assert expand_mul(integrate(exp(-a*x**2 + 2*d*x), (x, -oo, oo))) == \ sqrt(pi)*exp(d**2/a)/sqrt(a)
def test_erf2(): assert erf2(0, 0) == 0 assert erf2(x, x) == 0 assert erf2(nan, 0) == nan assert erf2(-oo, y) == erf(y) + 1 assert erf2( oo, y) == erf(y) - 1 assert erf2( x, oo) == 1 - erf(x) assert erf2( x, -oo) == -1 - erf(x) assert erf2(x, erf2inv(x, y)) == y assert erf2(-x, -y) == -erf2(x, y) assert erf2(-x, y) == erf(y) + erf(x) assert erf2( x, -y) == -erf(y) - erf(x) assert erf2(x, y).rewrite('fresnels') == erf(y).rewrite(fresnels)-erf(x).rewrite(fresnels) assert erf2(x, y).rewrite('fresnelc') == erf(y).rewrite(fresnelc)-erf(x).rewrite(fresnelc) assert erf2(x, y).rewrite('hyper') == erf(y).rewrite(hyper)-erf(x).rewrite(hyper) assert erf2(x, y).rewrite('meijerg') == erf(y).rewrite(meijerg)-erf(x).rewrite(meijerg) assert erf2(x, y).rewrite('uppergamma') == erf(y).rewrite(uppergamma) - erf(x).rewrite(uppergamma) assert erf2(x, y).rewrite('expint') == erf(y).rewrite(expint)-erf(x).rewrite(expint) assert erf2(I, w).is_extended_real is False assert erf2(2*w, w).is_extended_real is True assert erf2(z, w).is_extended_real is None assert erf2(w, z).is_extended_real is None assert conjugate(erf2(x, y)) == erf2(conjugate(x), conjugate(y)) assert erf2(x, y).rewrite('erf') == erf(y) - erf(x) assert erf2(x, y).rewrite('erfc') == erfc(x) - erfc(y) assert erf2(x, y).rewrite('erfi') == I*(erfi(I*x) - erfi(I*y)) pytest.raises(ArgumentIndexError, lambda: erfi(x).fdiff(3)) pytest.raises(ArgumentIndexError, lambda: erf2(x, y).fdiff(3)) assert erf2(x, y).diff(x) == -2*exp(-x**2)/sqrt(pi) assert erf2(x, y).diff(y) == +2*exp(-y**2)/sqrt(pi)
def test_erfc(): assert erfc(nan) == nan assert erfc(oo) == 0 assert erfc(-oo) == 2 assert erfc(0) == 1 assert erfc(I * oo) == -oo * I assert erfc(-I * oo) == oo * I assert erfc(-x) == Integer(2) - erfc(x) assert erfc(erfcinv(x)) == x assert erfc(I).is_extended_real is False assert erfc(w).is_extended_real is True assert erfc(z).is_extended_real is None assert conjugate(erfc(z)) == erfc(conjugate(z)) assert erfc(x).as_leading_term(x) == S.One assert erfc(1 / x).as_leading_term(x) == erfc(1 / x) assert erfc(z).rewrite('erf') == 1 - erf(z) assert erfc(z).rewrite('erfi') == 1 + I * erfi(I * z) assert erfc(z).rewrite('fresnels') == 1 - (1 + I) * ( fresnelc(z * (1 - I) / sqrt(pi)) - I * fresnels(z * (1 - I) / sqrt(pi))) assert erfc(z).rewrite('fresnelc') == 1 - (1 + I) * ( fresnelc(z * (1 - I) / sqrt(pi)) - I * fresnels(z * (1 - I) / sqrt(pi))) assert erfc(z).rewrite( 'hyper') == 1 - 2 * z * hyper([S.Half], [3 * S.Half], -z**2) / sqrt(pi) assert erfc(z).rewrite('meijerg') == 1 - z * meijerg( [S.Half], [], [0], [-S.Half], z**2) / sqrt(pi) assert erfc(z).rewrite( 'uppergamma') == 1 - sqrt(z**2) * erf(sqrt(z**2)) / z assert erfc(z).rewrite('expint') == S.One - sqrt(z**2) / z + z * expint( S.Half, z**2) / sqrt(S.Pi) assert erfc(x).as_real_imag() == \ ((erfc(re(x) - I*re(x)*Abs(im(x))/Abs(re(x)))/2 + erfc(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))/2, I*(erfc(re(x) - I*re(x)*Abs(im(x))/Abs(re(x))) - erfc(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: erfc(x).fdiff(2))
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)
def test_sympyissue_13575(): assert limit(acos(erfi(x)), x, 1) == pi/2 + I*log(sqrt(erf(I)**2 + 1) + erf(I))
def test_erfi(): assert erfi(nan) == nan assert erfi(+oo) == +oo assert erfi(-oo) == -oo assert erfi(0) == 0 assert erfi(I*oo) == I assert erfi(-I*oo) == -I assert erfi(-x) == -erfi(x) assert erfi(I*erfinv(x)) == I*x assert erfi(I*erfcinv(x)) == I*(1 - x) assert erfi(I*erf2inv(0, x)) == I*x assert erfi(I).is_extended_real is False assert erfi(w).is_extended_real is True assert erfi(z).is_extended_real is None assert conjugate(erfi(z)) == erfi(conjugate(z)) assert erfi(z).rewrite('erf') == -I*erf(I*z) assert erfi(z).rewrite('erfc') == I*erfc(I*z) - I assert erfi(z).rewrite('fresnels') == (1 - I)*(fresnelc(z*(1 + I)/sqrt(pi)) - I*fresnels(z*(1 + I)/sqrt(pi))) assert erfi(z).rewrite('fresnelc') == (1 - I)*(fresnelc(z*(1 + I)/sqrt(pi)) - I*fresnels(z*(1 + I)/sqrt(pi))) assert erfi(z).rewrite('hyper') == 2*z*hyper([Rational(1, 2)], [Rational(3, 2)], z**2)/sqrt(pi) assert erfi(z).rewrite('meijerg') == z*meijerg([Rational(1, 2)], [], [0], [Rational(-1, 2)], -z**2)/sqrt(pi) assert erfi(z).rewrite('uppergamma') == (sqrt(-z**2)/z*(uppergamma(Rational(1, 2), -z**2)/sqrt(pi) - 1)) assert erfi(z).rewrite('expint') == sqrt(-z**2)/z - z*expint(Rational(1, 2), -z**2)/sqrt(pi) assert erfi(x).as_real_imag() == \ ((erfi(re(x) - I*re(x)*Abs(im(x))/Abs(re(x)))/2 + erfi(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))/2, I*(erfi(re(x) - I*re(x)*Abs(im(x))/Abs(re(x))) - erfi(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))) * re(x)*Abs(im(x))/(2*im(x)*Abs(re(x))))) assert erfi(x).as_real_imag(deep=False) == erfi(x).as_real_imag() assert erfi(w).as_real_imag() == (erfi(w), 0) assert erfi(w).as_real_imag(deep=False) == erfi(w).as_real_imag() assert erfi(I).as_real_imag() == (0, erf(1)) pytest.raises(ArgumentIndexError, lambda: erfi(x).fdiff(2)) assert erfi(x).taylor_term(3, x, *(2*x/sqrt(pi), 0)) == 2*x**3/3/sqrt(pi) assert erfi(x).limit(x, oo) == oo
def test_Function(): assert mathematica_code(f(x, y, z)) == 'f[x, y, z]' assert mathematica_code(sin(x)**cos(x)) == 'Sin[x]^Cos[x]' assert mathematica_code(sign(x)) == 'Sign[x]' assert mathematica_code(atanh(x), user_functions={'atanh': 'ArcTanh'}) == 'ArcTanh[x]' assert (mathematica_code(meijerg( ((1, 1), (3, 4)), ((1, ), ()), x)) == 'MeijerG[{{1, 1}, {3, 4}}, {{1}, {}}, x]') assert (mathematica_code(hyper( (1, 2, 3), (3, 4), x)) == 'HypergeometricPFQ[{1, 2, 3}, {3, 4}, x]') assert mathematica_code(Min(x, y)) == 'Min[x, y]' assert mathematica_code(Max(x, y)) == 'Max[x, y]' assert mathematica_code(Max(x, 2)) == 'Max[2, x]' # issue sympy/sympy#15344 assert mathematica_code(binomial(x, y)) == 'Binomial[x, y]' assert mathematica_code(log(x)) == 'Log[x]' assert mathematica_code(tan(x)) == 'Tan[x]' assert mathematica_code(cot(x)) == 'Cot[x]' assert mathematica_code(asin(x)) == 'ArcSin[x]' assert mathematica_code(acos(x)) == 'ArcCos[x]' assert mathematica_code(atan(x)) == 'ArcTan[x]' assert mathematica_code(acot(x)) == 'ArcCot[x]' assert mathematica_code(sinh(x)) == 'Sinh[x]' assert mathematica_code(cosh(x)) == 'Cosh[x]' assert mathematica_code(tanh(x)) == 'Tanh[x]' assert mathematica_code(coth(x)) == 'Coth[x]' assert mathematica_code(asinh(x)) == 'ArcSinh[x]' assert mathematica_code(acosh(x)) == 'ArcCosh[x]' assert mathematica_code(atanh(x)) == 'ArcTanh[x]' assert mathematica_code(acoth(x)) == 'ArcCoth[x]' assert mathematica_code(sech(x)) == 'Sech[x]' assert mathematica_code(csch(x)) == 'Csch[x]' assert mathematica_code(erf(x)) == 'Erf[x]' assert mathematica_code(erfi(x)) == 'Erfi[x]' assert mathematica_code(erfc(x)) == 'Erfc[x]' assert mathematica_code(conjugate(x)) == 'Conjugate[x]' assert mathematica_code(re(x)) == 'Re[x]' assert mathematica_code(im(x)) == 'Im[x]' assert mathematica_code(polygamma(x, y)) == 'PolyGamma[x, y]' assert mathematica_code(factorial(x)) == 'Factorial[x]' assert mathematica_code(factorial2(x)) == 'Factorial2[x]' assert mathematica_code(rf(x, y)) == 'Pochhammer[x, y]' assert mathematica_code(gamma(x)) == 'Gamma[x]' assert mathematica_code(zeta(x)) == 'Zeta[x]' assert mathematica_code(Heaviside(x)) == 'UnitStep[x]' assert mathematica_code(fibonacci(x)) == 'Fibonacci[x]' assert mathematica_code(polylog(x, y)) == 'PolyLog[x, y]' assert mathematica_code(loggamma(x)) == 'LogGamma[x]' assert mathematica_code(uppergamma(x, y)) == 'Gamma[x, y]' class MyFunc1(Function): @classmethod def eval(cls, x): pass class MyFunc2(Function): @classmethod def eval(cls, x, y): pass pytest.raises( ValueError, lambda: mathematica_code(MyFunc1(x), user_functions={'MyFunc1': ['Myfunc1']})) assert mathematica_code(MyFunc1(x), user_functions={'MyFunc1': 'Myfunc1'}) == 'Myfunc1[x]' assert mathematica_code( MyFunc2(x, y), user_functions={'MyFunc2': [(lambda *x: False, 'Myfunc2')]}) == 'MyFunc2[x, y]'
def test_erfi_series(): assert erfi(x).series(x, 0, 7) == 2*x/sqrt(pi) + \ 2*x**3/3/sqrt(pi) + x**5/5/sqrt(pi) + O(x**7)
def test_erfi_evalf(): assert abs( erfi(Float(2.0)) - 18.5648024145756 ) < 1E-13 # XXX
def test_erfi(): assert erfi(nan) == nan assert erfi(+oo) == +oo assert erfi(-oo) == -oo assert erfi(0) == 0 assert erfi(I * oo) == I assert erfi(-I * oo) == -I assert erfi(-x) == -erfi(x) assert erfi(I * erfinv(x)) == I * x assert erfi(I * erfcinv(x)) == I * (1 - x) assert erfi(I * erf2inv(0, x)) == I * x assert erfi(I).is_extended_real is False assert erfi(w).is_extended_real is True assert erfi(z).is_extended_real is None assert conjugate(erfi(z)) == erfi(conjugate(z)) assert erfi(z).rewrite('erf') == -I * erf(I * z) assert erfi(z).rewrite('erfc') == I * erfc(I * z) - I assert erfi(z).rewrite('fresnels') == (1 - I) * ( fresnelc(z * (1 + I) / sqrt(pi)) - I * fresnels(z * (1 + I) / sqrt(pi))) assert erfi(z).rewrite('fresnelc') == (1 - I) * ( fresnelc(z * (1 + I) / sqrt(pi)) - I * fresnels(z * (1 + I) / sqrt(pi))) assert erfi(z).rewrite('hyper') == 2 * z * hyper( [Rational(1, 2)], [Rational(3, 2)], z**2) / sqrt(pi) assert erfi(z).rewrite('meijerg') == z * meijerg( [Rational(1, 2)], [], [0], [Rational(-1, 2)], -z**2) / sqrt(pi) assert erfi(z).rewrite('uppergamma') == ( sqrt(-z**2) / z * (uppergamma(Rational(1, 2), -z**2) / sqrt(pi) - 1)) assert erfi(z).rewrite('expint') == sqrt(-z**2) / z - z * expint( Rational(1, 2), -z**2) / sqrt(pi) assert erfi(x).as_real_imag() == \ ((erfi(re(x) - I*re(x)*abs(im(x))/abs(re(x)))/2 + erfi(re(x) + I*re(x)*abs(im(x))/abs(re(x)))/2, I*(erfi(re(x) - I*re(x)*abs(im(x))/abs(re(x))) - erfi(re(x) + I*re(x)*abs(im(x))/abs(re(x)))) * re(x)*abs(im(x))/(2*im(x)*abs(re(x))))) assert erfi(x).as_real_imag(deep=False) == erfi(x).as_real_imag() assert erfi(w).as_real_imag() == (erfi(w), 0) assert erfi(w).as_real_imag(deep=False) == erfi(w).as_real_imag() assert erfi(I).as_real_imag() == (0, erf(1)) pytest.raises(ArgumentIndexError, lambda: erfi(x).fdiff(2)) assert erfi(x).taylor_term(3, x, *(2 * x / sqrt(pi), 0)) == 2 * x**3 / 3 / sqrt(pi) assert erfi(x).limit(x, oo) == oo
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)
def test_erfi(): assert erfi(nan) == nan assert erfi(oo) == S.Infinity assert erfi(-oo) == S.NegativeInfinity assert erfi(0) == S.Zero assert erfi(I*oo) == I assert erfi(-I*oo) == -I assert erfi(-x) == -erfi(x) assert erfi(I*erfinv(x)) == I*x assert erfi(I*erfcinv(x)) == I*(1 - x) assert erfi(I*erf2inv(0, x)) == I*x assert erfi(I).is_extended_real is False assert erfi(w).is_extended_real is True assert erfi(z).is_extended_real is None assert conjugate(erfi(z)) == erfi(conjugate(z)) assert erfi(z).rewrite('erf') == -I*erf(I*z) assert erfi(z).rewrite('erfc') == I*erfc(I*z) - I assert erfi(z).rewrite('fresnels') == (1 - I)*(fresnelc(z*(1 + I)/sqrt(pi)) - I*fresnels(z*(1 + I)/sqrt(pi))) assert erfi(z).rewrite('fresnelc') == (1 - I)*(fresnelc(z*(1 + I)/sqrt(pi)) - I*fresnels(z*(1 + I)/sqrt(pi))) assert erfi(z).rewrite('hyper') == 2*z*hyper([S.Half], [3*S.Half], z**2)/sqrt(pi) assert erfi(z).rewrite('meijerg') == z*meijerg([S.Half], [], [0], [-S.Half], -z**2)/sqrt(pi) assert erfi(z).rewrite('uppergamma') == (sqrt(-z**2)/z*(uppergamma(S.Half, -z**2)/sqrt(S.Pi) - S.One)) assert erfi(z).rewrite('expint') == sqrt(-z**2)/z - z*expint(S.Half, -z**2)/sqrt(S.Pi) assert erfi(x).as_real_imag() == \ ((erfi(re(x) - I*re(x)*Abs(im(x))/Abs(re(x)))/2 + erfi(re(x) + I*re(x)*Abs(im(x))/Abs(re(x)))/2, I*(erfi(re(x) - I*re(x)*Abs(im(x))/Abs(re(x))) - erfi(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: erfi(x).fdiff(2))
def test_erfi_evalf(): assert abs(erfi(Float(2.0)) - 18.5648024145756) < 1E-13 # XXX
def test_sympyissue_13575(): assert limit(acos(erfi(x)), x, 1).equals(pi/2 + I*log(sqrt(erf(I)**2 + 1) + erf(I))) is True