示例#1
0
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, 0).is_real is False
    assert erf2(0, 0).is_real is True

    assert expand_func(erf(x) + erf2(x, y)) == erf(y)

    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))

    raises(ArgumentIndexError, lambda: erfi(x).fdiff(3))
示例#2
0
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, 0).is_real is False
    assert erf2(0, 0).is_real is True

    assert expand_func(erf(x) + erf2(x, y)) == erf(y)

    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))

    assert erf2(x, y).diff(x) == erf2(x, y).fdiff(1)
    assert erf2(x, y).diff(y) == erf2(x, y).fdiff(2)
    assert erf2(x, y).diff(x) == -2 * exp(-x**2) / sqrt(pi)
    assert erf2(x, y).diff(y) == 2 * exp(-y**2) / sqrt(pi)
    raises(ArgumentIndexError, lambda: erf2(x, y).fdiff(3))

    assert erf2(x, y).is_extended_real is None
    xr, yr = symbols('xr yr', extended_real=True)
    assert erf2(xr, yr).is_extended_real is True
示例#3
0
def test_erf2():

    assert erf2(0, 0) is S.Zero
    assert erf2(x, x) is S.Zero
    assert erf2(nan, 0) is 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, 0).is_real is False
    assert erf2(0, 0).is_real is True

    assert expand_func(erf(x) + erf2(x, y)) == erf(y)

    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))

    assert erf2(x, y).diff(x) == erf2(x, y).fdiff(1)
    assert erf2(x, y).diff(y) == erf2(x, y).fdiff(2)
    assert erf2(x, y).diff(x) == -2 * exp(-(x**2)) / sqrt(pi)
    assert erf2(x, y).diff(y) == 2 * exp(-(y**2)) / sqrt(pi)
    raises(ArgumentIndexError, lambda: erf2(x, y).fdiff(3))

    assert erf2(x, y).is_extended_real is None
    xr, yr = symbols("xr yr", extended_real=True)
    assert erf2(xr, yr).is_extended_real is True
示例#4
0
def test_manualintegrate_special():
    f, F = 4*exp(-x**2/3), 2*sqrt(3)*sqrt(pi)*erf(sqrt(3)*x/3)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 3*exp(4*x**2), 3*sqrt(pi)*erfi(2*x)/4
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = x**(S(1)/3)*exp(-x/8), -16*uppergamma(S(4)/3, x/8)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = exp(2*x)/x, Ei(2*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = exp(1 + 2*x - x**2), sqrt(pi)*exp(2)*erf(x - 1)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f = sin(x**2 + 4*x + 1)
    F = (sqrt(2)*sqrt(pi)*(-sin(3)*fresnelc(sqrt(2)*(2*x + 4)/(2*sqrt(pi))) +
        cos(3)*fresnels(sqrt(2)*(2*x + 4)/(2*sqrt(pi))))/2)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cos(4*x**2), sqrt(2)*sqrt(pi)*fresnelc(2*sqrt(2)*x/sqrt(pi))/4
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sin(3*x + 2)/x, sin(2)*Ci(3*x) + cos(2)*Si(3*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sinh(3*x - 2)/x, -sinh(2)*Chi(3*x) + cosh(2)*Shi(3*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 5*cos(2*x - 3)/x, 5*cos(3)*Ci(2*x) + 5*sin(3)*Si(2*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cosh(x/2)/x, Chi(x/2)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cos(x**2)/x, Ci(x**2)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 1/log(2*x + 1), li(2*x + 1)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = polylog(2, 5*x)/x, polylog(3, 5*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 5/sqrt(3 - 2*sin(x)**2), 5*sqrt(3)*elliptic_f(x, S(2)/3)/3
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sqrt(4 + 9*sin(x)**2), 2*elliptic_e(x, -S(9)/4)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
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_real is False
    assert erf(0).is_real is True

    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) * (1 - erfc(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)))))

    raises(ArgumentIndexError, lambda: erf(x).fdiff(2))
示例#6
0
def test_manualintegrate_special():
    f, F = 4*exp(-x**2/3), 2*sqrt(3)*sqrt(pi)*erf(sqrt(3)*x/3)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 3*exp(4*x**2), 3*sqrt(pi)*erfi(2*x)/4
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = x**Rational(1, 3)*exp(-x/8), -16*uppergamma(Rational(4, 3), x/8)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = exp(2*x)/x, Ei(2*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = exp(1 + 2*x - x**2), sqrt(pi)*exp(2)*erf(x - 1)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f = sin(x**2 + 4*x + 1)
    F = (sqrt(2)*sqrt(pi)*(-sin(3)*fresnelc(sqrt(2)*(2*x + 4)/(2*sqrt(pi))) +
        cos(3)*fresnels(sqrt(2)*(2*x + 4)/(2*sqrt(pi))))/2)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cos(4*x**2), sqrt(2)*sqrt(pi)*fresnelc(2*sqrt(2)*x/sqrt(pi))/4
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sin(3*x + 2)/x, sin(2)*Ci(3*x) + cos(2)*Si(3*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sinh(3*x - 2)/x, -sinh(2)*Chi(3*x) + cosh(2)*Shi(3*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 5*cos(2*x - 3)/x, 5*cos(3)*Ci(2*x) + 5*sin(3)*Si(2*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cosh(x/2)/x, Chi(x/2)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cos(x**2)/x, Ci(x**2)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 1/log(2*x + 1), li(2*x + 1)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = polylog(2, 5*x)/x, polylog(3, 5*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 5/sqrt(3 - 2*sin(x)**2), 5*sqrt(3)*elliptic_f(x, Rational(2, 3))/3
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sqrt(4 + 9*sin(x)**2), 2*elliptic_e(x, Rational(-9, 4))
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
示例#7
0
def test_issue_4890():
    z = Symbol('z', positive=True)
    assert integrate(exp(-log(x)**2), x) == \
        sqrt(pi)*exp(S(1)/4)*erf(log(x)-S(1)/2)/2
    assert integrate(exp(log(x)**2), x) == \
        sqrt(pi)*exp(-S(1)/4)*erfi(log(x)+S(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))
示例#8
0
def test_issue_4890():
    z = Symbol('z', positive=True)
    assert integrate(exp(-log(x)**2), x) == \
        sqrt(pi)*exp(S(1)/4)*erf(log(x)-S(1)/2)/2
    assert integrate(exp(log(x)**2), x) == \
        sqrt(pi)*exp(-S(1)/4)*erfi(log(x)+S(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))
示例#9
0
def test_issue_13575():
    result = limit(acos(erfi(x)), x, 1)
    assert isinstance(result, Add)

    re, im = result.evalf().as_real_imag()

    assert abs(re) < 1e-12
    assert abs(im - 1.08633774961570) < 1e-12
示例#10
0
def test_erfc():
    assert erfc(nan) is 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) == S(2) - erfc(x)
    assert erfc(erfcinv(x)) == x

    assert erfc(I).is_real is False
    assert erfc(0).is_real is True

    assert erfc(erfinv(x)) == 1 - x

    assert conjugate(erfc(z)) == erfc(conjugate(z))

    assert erfc(x).as_leading_term(x) is 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], [Rational(-1, 2)], z**2) / sqrt(pi)
    assert (erfc(z).rewrite("uppergamma") == 1 - sqrt(z**2) *
            (1 - erfc(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(z).rewrite("tractable") == _erfs(z) * exp(-(z**2))
    assert expand_func(erf(x) + erfc(x)) is S.One

    assert erfc(x).as_real_imag() == (
        erfc(re(x) - I * im(x)) / 2 + erfc(re(x) + I * im(x)) / 2,
        -I * (-erfc(re(x) - I * im(x)) + erfc(re(x) + I * im(x))) / 2,
    )

    assert erfc(x).as_real_imag(deep=False) == (
        erfc(re(x) - I * im(x)) / 2 + erfc(re(x) + I * im(x)) / 2,
        -I * (-erfc(re(x) - I * im(x)) + erfc(re(x) + I * im(x))) / 2,
    )

    assert erfc(w).as_real_imag() == (erfc(w), 0)
    assert erfc(w).as_real_imag(deep=False) == (erfc(w), 0)
    raises(ArgumentIndexError, lambda: erfc(x).fdiff(2))

    assert erfc(x).inverse() == erfcinv
示例#11
0
def test_issue_13575():
    # This fails with infinite recursion when run without the cache:
    result = limit(acos(erfi(x)), x, 1)
    assert isinstance(result, Add)

    re, im = result.evalf().as_real_imag()

    assert abs(re) < 1e-12
    assert abs(im - 1.08633774961570) < 1e-12
示例#12
0
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) == S(2) - erfc(x)
    assert erfc(erfcinv(x)) == x

    assert erfc(I).is_real is False
    assert erfc(0).is_real is True

    assert erfc(erfinv(x)) == 1 - x

    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) * (1 - erfc(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(z).rewrite('tractable') == _erfs(z) * exp(-z**2)
    assert expand_func(erf(x) + erfc(x)) == S.One

    assert erfc(x).as_real_imag() == \
        (erfc(re(x) - I*im(x))/2 + erfc(re(x) + I*im(x))/2,
         -I*(-erfc(re(x) - I*im(x)) + erfc(re(x) + I*im(x)))/2)

    assert erfc(x).as_real_imag(deep=False) == \
        (erfc(re(x) - I*im(x))/2 + erfc(re(x) + I*im(x))/2,
         -I*(-erfc(re(x) - I*im(x)) + erfc(re(x) + I*im(x)))/2)

    assert erfc(w).as_real_imag() == (erfc(w), 0)
    assert erfc(w).as_real_imag(deep=False) == (erfc(w), 0)
    raises(ArgumentIndexError, lambda: erfc(x).fdiff(2))

    assert erfc(x).inverse() == erfcinv
示例#13
0
        def fdiff(self, argindex):
            r, mu, sigma, lamda = self.args
            # if mu=0 and sigma=1, then this is
            # just the inverse standard erf so return erfi
            if mu == 0 and sigma == 1:
                return sympy.diff(sympy.erfi(r), self.args[argindex-1])

            tmp = sympy.symbols("tmp", real=True, finite=True)
            z_s = GaussianMixtureCDF(tmp, mu, sigma, lamda)
            inv_diff = sympy.diff(z_s, self.args[argindex-1])
            return sympy.simplify(1/inv_diff.subs(tmp, self))            
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_real is False
    assert erf(0).is_real is True

    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)*(1 - erfc(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)))))

    raises(ArgumentIndexError, lambda: erf(x).fdiff(2))
示例#15
0
def _get_examples_ode_sol_1st_linear():
    # Type: first order linear form f'(x)+p(x)f(x)=q(x)
    return {
            'hint': "1st_linear",
            'func': f(x),
            'examples':{
    'linear_01': {
        'eq': Eq(f(x).diff(x) + x*f(x), x**2),
        'sol': [Eq(f(x), (C1 + x*exp(x**2/2)- sqrt(2)*sqrt(pi)*erfi(sqrt(2)*x/2)/2)*exp(-x**2/2))],
    },
    },
    }
示例#16
0
def test_rayleigh():
    sigma = Symbol("sigma", positive=True)

    X = Rayleigh('x', sigma)

    #Tests characteristic_function
    assert characteristic_function(X)(x) == (-sqrt(2)*sqrt(pi)*sigma*x*(erfi(sqrt(2)*sigma*x/2) - I)*exp(-sigma**2*x**2/2)/2 + 1)

    assert density(X)(x) ==  x*exp(-x**2/(2*sigma**2))/sigma**2
    assert E(X) == sqrt(2)*sqrt(pi)*sigma/2
    assert variance(X) == -pi*sigma**2/2 + 2*sigma**2
    assert cdf(X)(x) == 1 - exp(-x**2/(2*sigma**2))
    assert diff(cdf(X)(x), x) == density(X)(x)
示例#17
0
def test_issue_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))

    from sympy import expand_mul
    from sympy.abc import k
    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)
示例#18
0
def test_issue_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))

    from sympy import expand_mul
    from sympy.abc import k
    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_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) == S(2) - erfc(x)
    assert erfc(erfcinv(x)) == x

    assert erfc(I).is_real is False
    assert erfc(0).is_real is True

    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)*(1 - erfc(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 expand_func(erf(x) + erfc(x)) == S.One

    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)))))

    raises(ArgumentIndexError, lambda: erfc(x).fdiff(2))
示例#20
0
def _create_table(table):
    """
    Creates the look-up table. For a similar implementation
    see meijerint._create_lookup_table.
    """

    def add(formula, annihilator, arg, x0=0, y0=[]):
        """
        Adds a formula in the dictionary
        """
        table.setdefault(_mytype(formula, x_1), []).append((formula,
            HolonomicFunction(annihilator, arg, x0, y0)))

    R = QQ.old_poly_ring(x_1)
    _, Dx = DifferentialOperators(R, 'Dx')

    from sympy import (sin, cos, exp, log, erf, sqrt, pi,
        sinh, cosh, sinc, erfc, Si, Ci, Shi, erfi)

    # add some basic functions
    add(sin(x_1), Dx**2 + 1, x_1, 0, [0, 1])
    add(cos(x_1), Dx**2 + 1, x_1, 0, [1, 0])
    add(exp(x_1), Dx - 1, x_1, 0, 1)
    add(log(x_1), Dx + x_1*Dx**2, x_1, 1, [0, 1])

    add(erf(x_1), 2*x_1*Dx + Dx**2, x_1, 0, [0, 2/sqrt(pi)])
    add(erfc(x_1), 2*x_1*Dx + Dx**2, x_1, 0, [1, -2/sqrt(pi)])
    add(erfi(x_1), -2*x_1*Dx + Dx**2, x_1, 0, [0, 2/sqrt(pi)])

    add(sinh(x_1), Dx**2 - 1, x_1, 0, [0, 1])
    add(cosh(x_1), Dx**2 - 1, x_1, 0, [1, 0])

    add(sinc(x_1), x_1 + 2*Dx + x_1*Dx**2, x_1)

    add(Si(x_1), x_1*Dx + 2*Dx**2 + x_1*Dx**3, x_1)
    add(Ci(x_1), x_1*Dx + 2*Dx**2 + x_1*Dx**3, x_1)

    add(Shi(x_1), -x_1*Dx + 2*Dx**2 + x_1*Dx**3, x_1)
示例#21
0
def _get_examples_ode_sol_factorable():
    """ some hints are marked as xfail for examples because they missed additional algebraic solution
    which could be found by Factorable hint. Fact_01 raise exception for
    nth_linear_constant_coeff_undetermined_coefficients"""

    y = Dummy('y')
    return {
            'hint': "factorable",
            'func': f(x),
            'examples':{
    'fact_01': {
        'eq': f(x) + f(x)*f(x).diff(x),
        'sol': [Eq(f(x), 0), Eq(f(x), C1 - x)],
        'XFAIL': ['separable', '1st_exact', '1st_linear', 'Bernoulli', '1st_homogeneous_coeff_best',
        '1st_homogeneous_coeff_subs_indep_div_dep', '1st_homogeneous_coeff_subs_dep_div_indep',
        'lie_group', 'nth_linear_euler_eq_nonhomogeneous_undetermined_coefficients',
        'nth_linear_constant_coeff_variation_of_parameters',
        'nth_linear_euler_eq_nonhomogeneous_variation_of_parameters',
        'nth_linear_constant_coeff_undetermined_coefficients']
    },

    'fact_02': {
        'eq': f(x)*(f(x).diff(x)+f(x)*x+2),
        'sol': [Eq(f(x), (C1 - sqrt(2)*sqrt(pi)*erfi(sqrt(2)*x/2))*exp(-x**2/2)), Eq(f(x), 0)],
        'XFAIL': ['Bernoulli', '1st_linear', 'lie_group']
    },

    'fact_03': {
        'eq': (f(x).diff(x)+f(x)*x**2)*(f(x).diff(x, 2) + x*f(x)),
        'sol':  [Eq(f(x), C1*airyai(-x) + C2*airybi(-x)),Eq(f(x), C1*exp(-x**3/3))]
    },

    'fact_04': {
        'eq': (f(x).diff(x)+f(x)*x**2)*(f(x).diff(x, 2) + f(x)),
        'sol': [Eq(f(x), C1*exp(-x**3/3)), Eq(f(x), C1*sin(x) + C2*cos(x))]
    },

    'fact_05': {
        'eq': (f(x).diff(x)**2-1)*(f(x).diff(x)**2-4),
        'sol': [Eq(f(x), C1 - x), Eq(f(x), C1 + x), Eq(f(x), C1 + 2*x), Eq(f(x), C1 - 2*x)]
    },

    'fact_06': {
        'eq': (f(x).diff(x, 2)-exp(f(x)))*f(x).diff(x),
        'sol': [Eq(f(x), C1)]
    },

    'fact_07': {
        'eq': (f(x).diff(x)**2-1)*(f(x)*f(x).diff(x)-1),
        'sol': [Eq(f(x), C1 - x), Eq(f(x), -sqrt(C1 + 2*x)),Eq(f(x), sqrt(C1 + 2*x)), Eq(f(x), C1 + x)]
    },

    'fact_08': {
        'eq': Derivative(f(x), x)**4 - 2*Derivative(f(x), x)**2 + 1,
        'sol': [Eq(f(x), C1 - x), Eq(f(x), C1 + x)]
    },

    'fact_09': {
        'eq': f(x)**2*Derivative(f(x), x)**6 - 2*f(x)**2*Derivative(f(x),
         x)**4 + f(x)**2*Derivative(f(x), x)**2 - 2*f(x)*Derivative(f(x),
         x)**5 + 4*f(x)*Derivative(f(x), x)**3 - 2*f(x)*Derivative(f(x),
         x) + Derivative(f(x), x)**4 - 2*Derivative(f(x), x)**2 + 1,
        'sol': [Eq(f(x), C1 - x), Eq(f(x), -sqrt(C1 + 2*x)),
           Eq(f(x), sqrt(C1 + 2*x)), Eq(f(x), C1 + x)]
    },

    'fact_10': {
        'eq': x**4*f(x)**2 + 2*x**4*f(x)*Derivative(f(x), (x, 2)) + x**4*Derivative(f(x),
         (x, 2))**2  + 2*x**3*f(x)*Derivative(f(x), x) + 2*x**3*Derivative(f(x),
         x)*Derivative(f(x), (x, 2)) - 7*x**2*f(x)**2 - 7*x**2*f(x)*Derivative(f(x),
         (x, 2)) + x**2*Derivative(f(x), x)**2 - 7*x*f(x)*Derivative(f(x), x) + 12*f(x)**2,
        'sol': [Eq(f(x), C1*besselj(2, x) + C2*bessely(2, x)), Eq(f(x), C1*besselj(sqrt(3),
           x) + C2*bessely(sqrt(3), x))]
    },

    'fact_11': {
        'eq': (f(x).diff(x, 2)-exp(f(x)))*(f(x).diff(x, 2)+exp(f(x))),
        'sol': [], #currently dsolve doesn't return any solution for this example
        'XFAIL': ['factorable']
    },

    #Below examples were added for the issue: https://github.com/sympy/sympy/issues/15889
    'fact_12': {
        'eq': exp(f(x).diff(x))-f(x)**2,
        'sol': [Eq(NonElementaryIntegral(1/log(y**2), (y, f(x))), C1 + x)],
        'XFAIL': ['lie_group'] #It shows not implemented error for lie_group.
    },

    'fact_13': {
        'eq': f(x).diff(x)**2 - f(x)**3,
        'sol': [Eq(f(x), 4/(C1**2 - 2*C1*x + x**2))],
        'XFAIL': ['lie_group'] #It shows not implemented error for lie_group.
    },

    'fact_14': {
        'eq': f(x).diff(x)**2 - f(x),
        'sol': [Eq(f(x), C1**2/4 - C1*x/2 + x**2/4)]
    },

    'fact_15': {
        'eq': f(x).diff(x)**2 - f(x)**2,
        'sol': [Eq(f(x), C1*exp(x)), Eq(f(x), C1*exp(-x))]
    },

    'fact_16': {
        'eq': f(x).diff(x)**2 - f(x)**3,
        'sol': [Eq(f(x), 4/(C1**2 - 2*C1*x + x**2))]
    },
    }
    }
示例#22
0
def _get_examples_ode_sol_factorable():
    """ some hints are marked as xfail for examples because they missed additional algebraic solution
    which could be found by Factorable hint. Fact_01 raise exception for
    nth_linear_constant_coeff_undetermined_coefficients"""

    return {
        'hint': "factorable",
        'func': f(x),
        'examples': {
            'fact_01': {
                'eq':
                f(x) + f(x) * f(x).diff(x),
                'sol': [Eq(f(x), 0), Eq(f(x), C1 - x)],
                'XFAIL': [
                    'separable', '1st_exact', '1st_linear', 'Bernoulli',
                    '1st_homogeneous_coeff_best',
                    '1st_homogeneous_coeff_subs_indep_div_dep',
                    '1st_homogeneous_coeff_subs_dep_div_indep', 'lie_group',
                    'nth_linear_euler_eq_nonhomogeneous_undetermined_coefficients',
                    'nth_linear_constant_coeff_variation_of_parameters',
                    'nth_linear_euler_eq_nonhomogeneous_variation_of_parameters',
                    'nth_linear_constant_coeff_undetermined_coefficients'
                ]
            },
            'fact_02': {
                'eq':
                f(x) * (f(x).diff(x) + f(x) * x + 2),
                'sol': [
                    Eq(f(x),
                       (C1 - sqrt(2) * sqrt(pi) * erfi(sqrt(2) * x / 2)) *
                       exp(-x**2 / 2)),
                    Eq(f(x), 0)
                ],
                'XFAIL': ['Bernoulli', '1st_linear', 'lie_group']
            },
            'fact_03': {
                'eq':
                (f(x).diff(x) + f(x) * x**2) * (f(x).diff(x, 2) + x * f(x)),
                'sol': [
                    Eq(f(x),
                       C1 * airyai(-x) + C2 * airybi(-x)),
                    Eq(f(x), C1 * exp(-x**3 / 3))
                ]
            },
            'fact_04': {
                'eq': (f(x).diff(x) + f(x) * x**2) * (f(x).diff(x, 2) + f(x)),
                'sol': [
                    Eq(f(x), C1 * exp(-x**3 / 3)),
                    Eq(f(x),
                       C1 * sin(x) + C2 * cos(x))
                ]
            },
            'fact_05': {
                'eq': (f(x).diff(x)**2 - 1) * (f(x).diff(x)**2 - 4),
                'sol': [
                    Eq(f(x), C1 - x),
                    Eq(f(x), C1 + x),
                    Eq(f(x), C1 + 2 * x),
                    Eq(f(x), C1 - 2 * x)
                ]
            },
            'fact_06': {
                'eq': (f(x).diff(x, 2) - exp(f(x))) * f(x).diff(x),
                'sol': [Eq(f(x), C1)]
            },
            'fact_07': {
                'eq': (f(x).diff(x)**2 - 1) * (f(x) * f(x).diff(x) - 1),
                'sol': [
                    Eq(f(x), C1 - x),
                    Eq(f(x), -sqrt(C1 + 2 * x)),
                    Eq(f(x), sqrt(C1 + 2 * x)),
                    Eq(f(x), C1 + x)
                ]
            },
            'fact_08': {
                'eq': Derivative(f(x), x)**4 - 2 * Derivative(f(x), x)**2 + 1,
                'sol': [Eq(f(x), C1 - x), Eq(f(x), C1 + x)]
            },
            'fact_09': {
                'eq':
                f(x)**2 * Derivative(f(x), x)**6 -
                2 * f(x)**2 * Derivative(f(x), x)**4 +
                f(x)**2 * Derivative(f(x), x)**2 -
                2 * f(x) * Derivative(f(x), x)**5 +
                4 * f(x) * Derivative(f(x), x)**3 -
                2 * f(x) * Derivative(f(x), x) + Derivative(f(x), x)**4 -
                2 * Derivative(f(x), x)**2 + 1,
                'sol': [
                    Eq(f(x), C1 - x),
                    Eq(f(x), -sqrt(C1 + 2 * x)),
                    Eq(f(x), sqrt(C1 + 2 * x)),
                    Eq(f(x), C1 + x)
                ]
            },
            'fact_10': {
                'eq':
                x**4 * f(x)**2 + 2 * x**4 * f(x) * Derivative(f(x), (x, 2)) +
                x**4 * Derivative(f(x), (x, 2))**2 +
                2 * x**3 * f(x) * Derivative(f(x), x) +
                2 * x**3 * Derivative(f(x), x) * Derivative(f(x), (x, 2)) -
                7 * x**2 * f(x)**2 -
                7 * x**2 * f(x) * Derivative(f(x), (x, 2)) +
                x**2 * Derivative(f(x), x)**2 -
                7 * x * f(x) * Derivative(f(x), x) + 12 * f(x)**2,
                'sol': [
                    Eq(f(x),
                       C1 * besselj(2, x) + C2 * bessely(2, x)),
                    Eq(f(x),
                       C1 * besselj(sqrt(3), x) + C2 * bessely(sqrt(3), x))
                ]
            },
            'fact_11': {
                'eq':
                (f(x).diff(x, 2) - exp(f(x))) * (f(x).diff(x, 2) + exp(f(x))),
                'sol':
                [],  #currently dsolve doesn't return any solution for this example
                'XFAIL': ['factorable']
            },
        }
    }
示例#23
0
def Z_sp(ksi):
    return sp.sqrt(sp.pi) * sp.exp(-ksi**2) * (sp.I - sp.erfi(ksi)
                                               )  # définition d'Anaïs et Éric
示例#24
0
def test_erfi_evalf():
    assert abs( erfi(Float(2.0)) - 18.5648024145756 ) < 1E-13  # XXX
示例#25
0
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)
示例#26
0
def test_issue_13575():
    assert limit(acos(erfi(x)), x, 1).cancel() == acos(-I * erf(I))
示例#27
0
def test_factorable():

    eq = f(x) + f(x) * f(x).diff(x)
    sols = [Eq(f(x), C1 - x), Eq(f(x), 0)]
    assert set(sols) == set(dsolve(eq, f(x), hint='factorable'))
    assert checkodesol(eq, sols) == 2 * [(True, 0)]

    eq = f(x) * (f(x).diff(x) + f(x) * x + 2)
    sols = [
        Eq(f(x),
           (C1 - sqrt(2) * sqrt(pi) * erfi(sqrt(2) * x / 2)) * exp(-x**2 / 2)),
        Eq(f(x), 0)
    ]
    assert set(sols) == set(dsolve(eq, f(x), hint='factorable'))
    assert checkodesol(eq, sols) == 2 * [(True, 0)]

    eq = (f(x).diff(x) + f(x) * x**2) * (f(x).diff(x, 2) + x * f(x))
    sols = [
        Eq(f(x),
           C1 * airyai(-x) + C2 * airybi(-x)),
        Eq(f(x), C1 * exp(-x**3 / 3))
    ]
    assert set(sols) == set(dsolve(eq, f(x), hint='factorable'))
    assert checkodesol(eq, sols[1]) == (True, 0)

    eq = (f(x).diff(x) + f(x) * x**2) * (f(x).diff(x, 2) + f(x))
    sols = [Eq(f(x), C1 * exp(-x**3 / 3)), Eq(f(x), C1 * sin(x) + C2 * cos(x))]
    assert set(sols) == set(dsolve(eq, f(x), hint='factorable'))
    assert checkodesol(eq, sols) == 2 * [(True, 0)]

    eq = (f(x).diff(x)**2 - 1) * (f(x).diff(x)**2 - 4)
    sols = [
        Eq(f(x), C1 - x),
        Eq(f(x), C1 + x),
        Eq(f(x), C1 + 2 * x),
        Eq(f(x), C1 - 2 * x)
    ]
    assert set(sols) == set(dsolve(eq, f(x), hint='factorable'))
    assert checkodesol(eq, sols) == 4 * [(True, 0)]

    eq = (f(x).diff(x, 2) - exp(f(x))) * f(x).diff(x)
    sol = Eq(f(x), C1)
    assert sol == dsolve(eq, f(x), hint='factorable')
    assert checkodesol(eq, sol) == (True, 0)

    eq = (f(x).diff(x)**2 - 1) * (f(x) * f(x).diff(x) - 1)
    sol = [
        Eq(f(x), C1 - x),
        Eq(f(x), -sqrt(C1 + 2 * x)),
        Eq(f(x), sqrt(C1 + 2 * x)),
        Eq(f(x), C1 + x)
    ]
    assert set(sol) == set(dsolve(eq, f(x), hint='factorable'))
    assert checkodesol(eq, sol) == 4 * [(True, 0)]

    eq = Derivative(f(x), x)**4 - 2 * Derivative(f(x), x)**2 + 1
    sol = [Eq(f(x), C1 - x), Eq(f(x), C1 + x)]
    assert set(sol) == set(dsolve(eq, f(x), hint='factorable'))
    assert checkodesol(eq, sol) == 2 * [(True, 0)]

    eq = f(x)**2 * Derivative(f(x), x)**6 - 2 * f(x)**2 * Derivative(
        f(x), x)**4 + f(x)**2 * Derivative(f(x), x)**2 - 2 * f(x) * Derivative(
            f(x), x)**5 + 4 * f(x) * Derivative(
                f(x), x)**3 - 2 * f(x) * Derivative(f(x), x) + Derivative(
                    f(x), x)**4 - 2 * Derivative(f(x), x)**2 + 1
    sol = [
        Eq(f(x), C1 - x),
        Eq(f(x), -sqrt(C1 + 2 * x)),
        Eq(f(x), sqrt(C1 + 2 * x)),
        Eq(f(x), C1 + x)
    ]
    assert set(sol) == set(dsolve(eq, f(x), hint='factorable'))
    assert checkodesol(eq, sol) == 4 * [(True, 0)]

    eq = (f(x).diff(x, 2) - exp(f(x))) * (f(x).diff(x, 2) + exp(f(x)))
    raises(NotImplementedError, lambda: dsolve(eq, hint='factorable'))

    eq = x**4 * f(x)**2 + 2 * x**4 * f(x) * Derivative(
        f(x), (x, 2)
    ) + x**4 * Derivative(f(x), (x, 2))**2 + 2 * x**3 * f(x) * Derivative(
        f(x), x) + 2 * x**3 * Derivative(f(x), x) * Derivative(
            f(x), (x, 2)) - 7 * x**2 * f(x)**2 - 7 * x**2 * f(x) * Derivative(
                f(x), (x, 2)) + x**2 * Derivative(f(x), x)**2 - 7 * x * f(
                    x) * Derivative(f(x), x) + 12 * f(x)**2

    sol = [
        Eq(f(x),
           C1 * besselj(2, x) + C2 * bessely(2, x)),
        Eq(f(x),
           C1 * besselj(sqrt(3), x) + C2 * bessely(sqrt(3), x))
    ]

    assert set(sol) == set(dsolve(eq, f(x), hint='factorable'))
    assert checkodesol(eq, sol) == 2 * [(True, 0)]
示例#28
0
def test_checksysodesol():
    x, y, z = symbols('x, y, z', cls=Function)
    t = Symbol('t')
    eq = (Eq(diff(x(t), t), 9 * y(t)), Eq(diff(y(t), t), 12 * x(t)))
    sol = [Eq(x(t), 9*C1*exp(-6*sqrt(3)*t) + 9*C2*exp(6*sqrt(3)*t)), \
    Eq(y(t), -6*sqrt(3)*C1*exp(-6*sqrt(3)*t) + 6*sqrt(3)*C2*exp(6*sqrt(3)*t))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t),
             2 * x(t) + 4 * y(t)), Eq(diff(y(t), t), 12 * x(t) + 41 * y(t)))
    sol = [Eq(x(t), 4*C1*exp(t*(-sqrt(1713)/2 + Rational(43, 2))) + 4*C2*exp(t*(sqrt(1713)/2 + \
    Rational(43, 2)))), Eq(y(t), C1*(-sqrt(1713)/2 + Rational(39, 2))*exp(t*(-sqrt(1713)/2 + \
    Rational(43, 2))) + C2*(Rational(39, 2) + sqrt(1713)/2)*exp(t*(sqrt(1713)/2 + Rational(43, 2))))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t),
             x(t) + y(t)), Eq(diff(y(t), t), -2 * x(t) + 2 * y(t)))
    sol = [Eq(x(t), (C1*sin(sqrt(7)*t/2) + C2*cos(sqrt(7)*t/2))*exp(t*Rational(3, 2))), \
    Eq(y(t), ((C1/2 - sqrt(7)*C2/2)*sin(sqrt(7)*t/2) + (sqrt(7)*C1/2 + \
    C2/2)*cos(sqrt(7)*t/2))*exp(t*Rational(3, 2)))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t),
             x(t) + y(t) + 9), Eq(diff(y(t), t), 2 * x(t) + 5 * y(t) + 23))
    sol = [Eq(x(t), C1*exp(t*(-sqrt(6) + 3)) + C2*exp(t*(sqrt(6) + 3)) - \
    Rational(22, 3)), Eq(y(t), C1*(-sqrt(6) + 2)*exp(t*(-sqrt(6) + 3)) + C2*(2 + \
    sqrt(6))*exp(t*(sqrt(6) + 3)) - Rational(5, 3))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t),
             x(t) + y(t) + 81), Eq(diff(y(t), t), -2 * x(t) + y(t) + 23))
    sol = [Eq(x(t), (C1*sin(sqrt(2)*t) + C2*cos(sqrt(2)*t))*exp(t) - Rational(58, 3)), \
    Eq(y(t), (sqrt(2)*C1*cos(sqrt(2)*t) - sqrt(2)*C2*sin(sqrt(2)*t))*exp(t) - Rational(185, 3))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t), 5 * t * x(t) + 2 * y(t)),
          Eq(diff(y(t), t), 2 * x(t) + 5 * t * y(t)))
    sol = [Eq(x(t), (C1*exp((Integral(2, t).doit())) + C2*exp(-(Integral(2, t)).doit()))*\
    exp((Integral(5*t, t)).doit())), Eq(y(t), (C1*exp((Integral(2, t)).doit()) - \
    C2*exp(-(Integral(2, t)).doit()))*exp((Integral(5*t, t)).doit()))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t), 5 * t * x(t) + t**2 * y(t)),
          Eq(diff(y(t), t), -t**2 * x(t) + 5 * t * y(t)))
    sol = [Eq(x(t), (C1*cos((Integral(t**2, t)).doit()) + C2*sin((Integral(t**2, t)).doit()))*\
    exp((Integral(5*t, t)).doit())), Eq(y(t), (-C1*sin((Integral(t**2, t)).doit()) + \
    C2*cos((Integral(t**2, t)).doit()))*exp((Integral(5*t, t)).doit()))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t), 5 * t * x(t) + t**2 * y(t)),
          Eq(diff(y(t), t), -t**2 * x(t) + (5 * t + 9 * t**2) * y(t)))
    sol = [Eq(x(t), (C1*exp((-sqrt(77)/2 + Rational(9, 2))*(Integral(t**2, t)).doit()) + \
    C2*exp((sqrt(77)/2 + Rational(9, 2))*(Integral(t**2, t)).doit()))*exp((Integral(5*t, t)).doit())), \
    Eq(y(t), (C1*(-sqrt(77)/2 + Rational(9, 2))*exp((-sqrt(77)/2 + Rational(9, 2))*(Integral(t**2, t)).doit()) + \
    C2*(sqrt(77)/2 + Rational(9, 2))*exp((sqrt(77)/2 + Rational(9, 2))*(Integral(t**2, t)).doit()))*exp((Integral(5*t, t)).doit()))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t, t),
             5 * x(t) + 43 * y(t)), Eq(diff(y(t), t, t),
                                       x(t) + 9 * y(t)))
    root0 = -sqrt(-sqrt(47) + 7)
    root1 = sqrt(-sqrt(47) + 7)
    root2 = -sqrt(sqrt(47) + 7)
    root3 = sqrt(sqrt(47) + 7)
    sol = [Eq(x(t), 43*C1*exp(t*root0) + 43*C2*exp(t*root1) + 43*C3*exp(t*root2) + 43*C4*exp(t*root3)), \
    Eq(y(t), C1*(root0**2 - 5)*exp(t*root0) + C2*(root1**2 - 5)*exp(t*root1) + \
    C3*(root2**2 - 5)*exp(t*root2) + C4*(root3**2 - 5)*exp(t*root3))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t, t), 8 * x(t) + 3 * y(t) + 31),
          Eq(diff(y(t), t, t), 9 * x(t) + 7 * y(t) + 12))
    root0 = -sqrt(-sqrt(109) / 2 + Rational(15, 2))
    root1 = sqrt(-sqrt(109) / 2 + Rational(15, 2))
    root2 = -sqrt(sqrt(109) / 2 + Rational(15, 2))
    root3 = sqrt(sqrt(109) / 2 + Rational(15, 2))
    sol = [Eq(x(t), 3*C1*exp(t*root0) + 3*C2*exp(t*root1) + 3*C3*exp(t*root2) + 3*C4*exp(t*root3) - Rational(181, 29)), \
    Eq(y(t), C1*(root0**2 - 8)*exp(t*root0) + C2*(root1**2 - 8)*exp(t*root1) + \
    C3*(root2**2 - 8)*exp(t*root2) + C4*(root3**2 - 8)*exp(t*root3) + Rational(183, 29))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t, t) - 9 * diff(y(t), t) + 7 * x(t),
             0), Eq(diff(y(t), t, t) + 9 * diff(x(t), t) + 7 * y(t), 0))
    sol = [Eq(x(t), C1*cos(t*(Rational(9, 2) + sqrt(109)/2)) + C2*sin(t*(Rational(9, 2) + sqrt(109)/2)) + \
    C3*cos(t*(-sqrt(109)/2 + Rational(9, 2))) + C4*sin(t*(-sqrt(109)/2 + Rational(9, 2)))), Eq(y(t), -C1*sin(t*(Rational(9, 2) + sqrt(109)/2)) \
    + C2*cos(t*(Rational(9, 2) + sqrt(109)/2)) - C3*sin(t*(-sqrt(109)/2 + Rational(9, 2))) + C4*cos(t*(-sqrt(109)/2 + Rational(9, 2))))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t, t), 9 * t * diff(y(t), t) - 9 * y(t)),
          Eq(diff(y(t), t, t), 7 * t * diff(x(t), t) - 7 * x(t)))
    I1 = sqrt(6) * 7**Rational(1, 4) * sqrt(pi) * erfi(
        sqrt(6) * 7**Rational(1, 4) * t / 2) / 2 - exp(
            3 * sqrt(7) * t**2 / 2) / t
    I2 = -sqrt(6) * 7**Rational(1, 4) * sqrt(pi) * erf(
        sqrt(6) * 7**Rational(1, 4) * t / 2) / 2 - exp(
            -3 * sqrt(7) * t**2 / 2) / t
    sol = [
        Eq(x(t), C3 * t + t * (9 * C1 * I1 + 9 * C2 * I2)),
        Eq(y(t), C4 * t + t * (3 * sqrt(7) * C1 * I1 - 3 * sqrt(7) * C2 * I2))
    ]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t), 21 * x(t)), Eq(diff(y(t), t),
                                           17 * x(t) + 3 * y(t)),
          Eq(diff(z(t), t), 5 * x(t) + 7 * y(t) + 9 * z(t)))
    sol = [Eq(x(t), C1*exp(21*t)), Eq(y(t), 17*C1*exp(21*t)/18 + C2*exp(3*t)), \
    Eq(z(t), 209*C1*exp(21*t)/216 - 7*C2*exp(3*t)/6 + C3*exp(9*t))]
    assert checksysodesol(eq, sol) == (True, [0, 0, 0])

    eq = (Eq(diff(x(t), t),
             3 * y(t) - 11 * z(t)), Eq(diff(y(t), t), 7 * z(t) - 3 * x(t)),
          Eq(diff(z(t), t), 11 * x(t) - 7 * y(t)))
    sol = [Eq(x(t), 7*C0 + sqrt(179)*C1*cos(sqrt(179)*t) + (77*C1/3 + 130*C2/3)*sin(sqrt(179)*t)), \
    Eq(y(t), 11*C0 + sqrt(179)*C2*cos(sqrt(179)*t) + (-58*C1/3 - 77*C2/3)*sin(sqrt(179)*t)), \
    Eq(z(t), 3*C0 + sqrt(179)*(-7*C1/3 - 11*C2/3)*cos(sqrt(179)*t) + (11*C1 - 7*C2)*sin(sqrt(179)*t))]
    assert checksysodesol(eq, sol) == (True, [0, 0, 0])

    eq = (Eq(3 * diff(x(t), t), 4 * 5 * (y(t) - z(t))),
          Eq(4 * diff(y(t), t), 3 * 5 * (z(t) - x(t))),
          Eq(5 * diff(z(t), t), 3 * 4 * (x(t) - y(t))))
    sol = [Eq(x(t), C0 + 5*sqrt(2)*C1*cos(5*sqrt(2)*t) + (12*C1/5 + 164*C2/15)*sin(5*sqrt(2)*t)), \
    Eq(y(t), C0 + 5*sqrt(2)*C2*cos(5*sqrt(2)*t) + (-51*C1/10 - 12*C2/5)*sin(5*sqrt(2)*t)), \
    Eq(z(t), C0 + 5*sqrt(2)*(-9*C1/25 - 16*C2/25)*cos(5*sqrt(2)*t) + (12*C1/5 - 12*C2/5)*sin(5*sqrt(2)*t))]
    assert checksysodesol(eq, sol) == (True, [0, 0, 0])

    eq = (Eq(diff(x(t), t),
             4 * x(t) - z(t)), Eq(diff(y(t), t), 2 * x(t) + 2 * y(t) - z(t)),
          Eq(diff(z(t), t), 3 * x(t) + y(t)))
    sol = [Eq(x(t), C1*exp(2*t) + C2*t*exp(2*t) + C2*exp(2*t) + C3*t**2*exp(2*t)/2 + C3*t*exp(2*t) + C3*exp(2*t)), \
    Eq(y(t), C1*exp(2*t) + C2*t*exp(2*t) + C2*exp(2*t) + C3*t**2*exp(2*t)/2 + C3*t*exp(2*t)), \
    Eq(z(t), 2*C1*exp(2*t) + 2*C2*t*exp(2*t) + C2*exp(2*t) + C3*t**2*exp(2*t) + C3*t*exp(2*t) + C3*exp(2*t))]
    assert checksysodesol(eq, sol) == (True, [0, 0, 0])

    eq = (Eq(diff(x(t), t), 4 * x(t) - y(t) - 2 * z(t)),
          Eq(diff(y(t), t),
             2 * x(t) + y(t) - 2 * z(t)), Eq(diff(z(t), t),
                                             5 * x(t) - 3 * z(t)))
    sol = [Eq(x(t), C1*exp(2*t) + C2*(-sin(t) + 3*cos(t)) + C3*(3*sin(t) + cos(t))), \
    Eq(y(t), C2*(-sin(t) + 3*cos(t)) + C3*(3*sin(t) + cos(t))), Eq(z(t), C1*exp(2*t) + 5*C2*cos(t) + 5*C3*sin(t))]
    assert checksysodesol(eq, sol) == (True, [0, 0, 0])

    eq = (Eq(diff(x(t), t), x(t) * y(t)**3), Eq(diff(y(t), t), y(t)**5))
    sol = [Eq(x(t), C1*exp((-1/(4*C2 + 4*t))**(Rational(-1, 4)))), Eq(y(t), -(-1/(4*C2 + 4*t))**Rational(1, 4)), \
    Eq(x(t), C1*exp(-1/(-1/(4*C2 + 4*t))**Rational(1, 4))), Eq(y(t), (-1/(4*C2 + 4*t))**Rational(1, 4)), \
    Eq(x(t), C1*exp(-I/(-1/(4*C2 + 4*t))**Rational(1, 4))), Eq(y(t), -I*(-1/(4*C2 + 4*t))**Rational(1, 4)), \
    Eq(x(t), C1*exp(I/(-1/(4*C2 + 4*t))**Rational(1, 4))), Eq(y(t), I*(-1/(4*C2 + 4*t))**Rational(1, 4))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(diff(x(t), t),
             exp(3 * x(t)) * y(t)**3), Eq(diff(y(t), t),
                                          y(t)**5))
    sol = [Eq(x(t), -log(C1 - 3/(-1/(4*C2 + 4*t))**Rational(1, 4))/3), Eq(y(t), -(-1/(4*C2 + 4*t))**Rational(1, 4)), \
    Eq(x(t), -log(C1 + 3/(-1/(4*C2 + 4*t))**Rational(1, 4))/3), Eq(y(t), (-1/(4*C2 + 4*t))**Rational(1, 4)), \
    Eq(x(t), -log(C1 + 3*I/(-1/(4*C2 + 4*t))**Rational(1, 4))/3), Eq(y(t), -I*(-1/(4*C2 + 4*t))**Rational(1, 4)), \
    Eq(x(t), -log(C1 - 3*I/(-1/(4*C2 + 4*t))**Rational(1, 4))/3), Eq(y(t), I*(-1/(4*C2 + 4*t))**Rational(1, 4))]
    assert checksysodesol(eq, sol) == (True, [0, 0])

    eq = (Eq(x(t),
             t * diff(x(t), t) + diff(x(t), t) * diff(y(t), t)),
          Eq(y(t),
             t * diff(y(t), t) + diff(y(t), t)**2))
    sol = set([Eq(x(t), C1 * C2 + C1 * t), Eq(y(t), C2**2 + C2 * t)])
    assert checksysodesol(eq, sol) == (True, [0, 0])
示例#29
0
def test_issue_13575():
    assert limit(acos(erfi(x)), x, 1) == acos(erfi(S.One))
示例#30
0
def test_issue_841():
    a, b, c, d = symbols('a:d', positive=True, bounded=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))
def test_erfi():
    assert erfi(nan) is nan

    assert erfi(oo) is S.Infinity
    assert erfi(-oo) is S.NegativeInfinity

    assert erfi(0) is 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 * erf2inv(0, x, evaluate=False)) == I * x  # To cover code in erfi

    assert erfi(I).is_real is False
    assert erfi(0).is_real is True

    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], [Rational(-1, 2)], -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(z).rewrite('tractable') == -I * (-_erfs(I * z) * exp(z**2) + 1)
    assert expand_func(erfi(I * z)) == I * erf(z)

    assert erfi(x).as_real_imag() == \
        (erfi(re(x) - I*im(x))/2 + erfi(re(x) + I*im(x))/2,
         -I*(-erfi(re(x) - I*im(x)) + erfi(re(x) + I*im(x)))/2)
    assert erfi(x).as_real_imag(deep=False) == \
        (erfi(re(x) - I*im(x))/2 + erfi(re(x) + I*im(x))/2,
         -I*(-erfi(re(x) - I*im(x)) + erfi(re(x) + I*im(x)))/2)

    assert erfi(w).as_real_imag() == (erfi(w), 0)
    assert erfi(w).as_real_imag(deep=False) == (erfi(w), 0)

    raises(ArgumentIndexError, lambda: erfi(x).fdiff(2))
def test_erf():
    assert erf(nan) is 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, x, evaluate=False)) == x  # To cover code in erf
    assert erf(erf2inv(0, erf(erfcinv(1 - erf(erfinv(x)))))) == x

    assert erf(I).is_real is False
    assert erf(0).is_real is True

    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) * (1 - erfc(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], [Rational(-1, 2)], 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*im(x))/2 + erf(re(x) + I*im(x))/2,
         -I*(-erf(re(x) - I*im(x)) + erf(re(x) + I*im(x)))/2)

    assert erf(x).as_real_imag(deep=False) == \
        (erf(re(x) - I*im(x))/2 + erf(re(x) + I*im(x))/2,
         -I*(-erf(re(x) - I*im(x)) + erf(re(x) + I*im(x)))/2)

    assert erf(w).as_real_imag() == (erf(w), 0)
    assert erf(w).as_real_imag(deep=False) == (erf(w), 0)
    # issue 13575
    assert erf(I).as_real_imag() == (0, -I * erf(I))

    raises(ArgumentIndexError, lambda: erf(x).fdiff(2))

    assert erf(x).inverse() == erfinv
示例#33
0
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)

    assert erfi(x).series(x, oo) == \
        (3/(4*x**5) + 1/(2*x**3) + 1/x + O(x**(-6), (x, oo)))*exp(x**2)/sqrt(pi) - I
示例#34
0
def test_issue_841():
    a, b, c, d = symbols('a:d', positive=True, bounded=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))
示例#35
0
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_real is False
    assert erfi(0).is_real is True

    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 expand_func(erfi(I*z)) == I*erf(z)

    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)))))

    raises(ArgumentIndexError, lambda: erfi(x).fdiff(2))