def test_issue_10102(): assert limit(fresnels(x), x, oo) == S.Half assert limit(3 + fresnels(x), x, oo) == 3 + S.Half assert limit(5 * fresnels(x), x, oo) == 5 * S.Half assert limit(fresnelc(x), x, oo) == S.Half assert limit(fresnels(x), x, -oo) == -S.Half assert limit(4 * fresnelc(x), x, -oo) == -2
def test_issue_10102(): assert limit(fresnels(x), x, oo) == S.Half assert limit(3 + fresnels(x), x, oo) == 3 + S.Half assert limit(5 * fresnels(x), x, oo) == Rational(5, 2) assert limit(fresnelc(x), x, oo) == S.Half assert limit(fresnels(x), x, -oo) == Rational(-1, 2) assert limit(4 * fresnelc(x), x, -oo) == -2
def test_issue_10102(): assert limit(fresnels(x), x, oo) == S.Half assert limit(3 + fresnels(x), x, oo) == 3 + S.Half assert limit(5*fresnels(x), x, oo) == 5*S.Half assert limit(fresnelc(x), x, oo) == S.Half assert limit(fresnels(x), x, -oo) == -S.Half assert limit(4*fresnelc(x), x, -oo) == -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_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))
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(x).as_leading_term(x) == 2 * x / sqrt(pi) assert erfi(x * y).as_leading_term(y) == 2 * x * y / sqrt(pi) assert (erfi(x * y) / erfi(y)).as_leading_term(y) == x assert erfi(1 / x).as_leading_term(x) == erfi(1 / x) 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_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
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
def test_fresnel_integrals_scipy(): if not scipy: skip("scipy not installed") f1 = fresnelc(x) f2 = fresnels(x) F1 = lambdify(x, f1, modules='scipy') F2 = lambdify(x, f2, modules='scipy') assert abs(fresnelc(1.3) - F1(1.3)) <= 1e-10 assert abs(fresnels(1.3) - F2(1.3)) <= 1e-10
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))
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))
def test_fresnel_integrals(): from sympy import fresnelc, fresnels expr1 = fresnelc(x) expr2 = fresnels(x) prntr = SciPyPrinter() assert prntr.doprint(expr1) == 'scipy.special.fresnel(x)[1]' assert prntr.doprint(expr2) == 'scipy.special.fresnel(x)[0]' prntr = NumPyPrinter() assert prntr.doprint( expr1 ) == ' # Not supported in Python with NumPy:\n # fresnelc\nfresnelc(x)' assert prntr.doprint( expr2 ) == ' # Not supported in Python with NumPy:\n # fresnels\nfresnels(x)' prntr = PythonCodePrinter() assert prntr.doprint( expr1) == ' # Not supported in Python:\n # fresnelc\nfresnelc(x)' assert prntr.doprint( expr2) == ' # Not supported in Python:\n # fresnels\nfresnels(x)' prntr = MpmathPrinter() assert prntr.doprint(expr1) == 'mpmath.fresnelc(x)' assert prntr.doprint(expr2) == 'mpmath.fresnels(x)'
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)
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_fresnel_series(): assert fresnelc(z).series(z, n=15) == \ z - pi**2*z**5/40 + pi**4*z**9/3456 - pi**6*z**13/599040 + O(z**15) # issues 6510, 10102 fs = (S.Half - sin(pi*z**2/2)/(pi**2*z**3) + (-1/(pi*z) + 3/(pi**3*z**5))*cos(pi*z**2/2)) fc = (S.Half - cos(pi*z**2/2)/(pi**2*z**3) + (1/(pi*z) - 3/(pi**3*z**5))*sin(pi*z**2/2)) assert fresnels(z).series(z, oo) == fs + O(z**(-6), (z, oo)) assert fresnelc(z).series(z, oo) == fc + O(z**(-6), (z, oo)) assert (fresnels(z).series(z, -oo) + fs.subs(z, -z)).expand().is_Order assert (fresnelc(z).series(z, -oo) + fc.subs(z, -z)).expand().is_Order assert (fresnels(1/z).series(z) - fs.subs(z, 1/z)).expand().is_Order assert (fresnelc(1/z).series(z) - fc.subs(z, 1/z)).expand().is_Order assert ((2*fresnels(3*z)).series(z, oo) - 2*fs.subs(z, 3*z)).expand().is_Order assert ((3*fresnelc(2*z)).series(z, oo) - 3*fc.subs(z, 2*z)).expand().is_Order
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))
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))
def test_fresnel(): from sympy import fresnels, fresnelc assert expand_func(integrate(sin(pi * x ** 2 / 2), x)) == fresnels(x) assert expand_func(integrate(cos(pi * x ** 2 / 2), x)) == fresnelc(x)
def test_laplace_transform(): from sympy import fresnels, fresnelc, DiracDelta LT = laplace_transform a, b, c, = symbols('a b c', positive=True) t = symbols('t') w = Symbol("w") f = Function("f") # Test unevaluated form assert laplace_transform(f(t), t, w) == LaplaceTransform(f(t), t, w) assert inverse_laplace_transform(f(w), w, t, plane=0) == InverseLaplaceTransform( f(w), w, t, 0) # test a bug spos = symbols('s', positive=True) assert LT(exp(t), t, spos)[:2] == (1 / (spos - 1), 1) # basic tests from wikipedia assert LT((t - a)**b*exp(-c*(t - a))*Heaviside(t - a), t, s) == \ ((s + c)**(-b - 1)*exp(-a*s)*gamma(b + 1), -c, True) assert LT(t**a, t, s) == (s**(-a - 1) * gamma(a + 1), 0, True) assert LT(Heaviside(t), t, s) == (1 / s, 0, True) assert LT(Heaviside(t - a), t, s) == (exp(-a * s) / s, 0, True) assert LT(1 - exp(-a * t), t, s) == (a / (s * (a + s)), 0, True) assert LT((exp(2*t) - 1)*exp(-b - t)*Heaviside(t)/2, t, s, noconds=True) \ == exp(-b)/(s**2 - 1) assert LT(exp(t), t, s)[:2] == (1 / (s - 1), 1) assert LT(exp(2 * t), t, s)[:2] == (1 / (s - 2), 2) assert LT(exp(a * t), t, s)[:2] == (1 / (s - a), a) assert LT(log(t / a), t, s) == ((log(a * s) + EulerGamma) / s / -1, 0, True) assert LT(erf(t), t, s) == (erfc(s / 2) * exp(s**2 / 4) / s, 0, True) assert LT(sin(a * t), t, s) == (a / (a**2 + s**2), 0, True) assert LT(cos(a * t), t, s) == (s / (a**2 + s**2), 0, True) # TODO would be nice to have these come out better assert LT(exp(-a * t) * sin(b * t), t, s) == (b / (b**2 + (a + s)**2), -a, True) assert LT(exp(-a*t)*cos(b*t), t, s) == \ ((a + s)/(b**2 + (a + s)**2), -a, True) assert LT(besselj(0, t), t, s) == (1 / sqrt(1 + s**2), 0, True) assert LT(besselj(1, t), t, s) == (1 - 1 / sqrt(1 + 1 / s**2), 0, True) # TODO general order works, but is a *mess* # TODO besseli also works, but is an even greater mess # test a bug in conditions processing # TODO the auxiliary condition should be recognised/simplified assert LT(exp(t) * cos(t), t, s)[:-1] in [ ((s - 1) / (s**2 - 2 * s + 2), -oo), ((s - 1) / ((s - 1)**2 + 1), -oo), ] # DiracDelta function: standard cases assert LT(DiracDelta(t), t, s) == (1, -oo, True) assert LT(DiracDelta(a * t), t, s) == (1 / a, -oo, True) assert LT(DiracDelta(t / 42), t, s) == (42, -oo, True) assert LT(DiracDelta(t + 42), t, s) == (0, -oo, True) assert LT(DiracDelta(t)+DiracDelta(t-42), t, s) == \ (1 + exp(-42*s), -oo, True) assert LT(DiracDelta(t) - a * exp(-a * t), t, s) == (-a / (a + s) + 1, 0, True) assert LT(exp(-t)*(DiracDelta(t)+DiracDelta(t-42)), t, s) == \ (exp(-42*s - 42) + 1, -oo, True) # Collection of cases that cannot be fully evaluated and/or would catch # some common implementation errors assert LT(DiracDelta(t**2), t, s) == LaplaceTransform(DiracDelta(t**2), t, s) assert LT(DiracDelta(t**2 - 1), t, s) == (exp(-s) / 2, -oo, True) assert LT(DiracDelta(t*(1 - t)), t, s) == \ LaplaceTransform(DiracDelta(-t**2 + t), t, s) assert LT((DiracDelta(t) + 1)*(DiracDelta(t - 1) + 1), t, s) == \ (LaplaceTransform(DiracDelta(t)*DiracDelta(t - 1), t, s) + \ 1 + exp(-s) + 1/s, 0, True) assert LT(DiracDelta(2*t - 2*exp(a)), t, s) == \ (exp(-s*exp(a))/2, -oo, True) # Fresnel functions assert laplace_transform(fresnels(t), t, s) == \ ((-sin(s**2/(2*pi))*fresnels(s/pi) + sin(s**2/(2*pi))/2 - cos(s**2/(2*pi))*fresnelc(s/pi) + cos(s**2/(2*pi))/2)/s, 0, True) assert laplace_transform( fresnelc(t), t, s) == (((2 * sin(s**2 / (2 * pi)) * fresnelc(s / pi) - 2 * cos(s**2 / (2 * pi)) * fresnels(s / pi) + sqrt(2) * cos(s**2 / (2 * pi) + pi / 4)) / (2 * s), 0, True)) # What is this testing: Ne(1 / s, 1) & (0 < cos(Abs(periodic_argument(s, oo))) * Abs(s) - 1) Mt = Matrix([[exp(t), t * exp(-t)], [t * exp(-t), exp(t)]]) Ms = Matrix([[1 / (s - 1), (s + 1)**(-2)], [(s + 1)**(-2), 1 / (s - 1)]]) # The default behaviour for Laplace tranform of a Matrix returns a Matrix # of Tuples and is deprecated: with warns_deprecated_sympy(): Ms_conds = Matrix([[(1 / (s - 1), 1, s > 1), ((s + 1)**(-2), 0, True)], [((s + 1)**(-2), 0, True), (1 / (s - 1), 1, s > 1)]]) with warns_deprecated_sympy(): assert LT(Mt, t, s) == Ms_conds # The new behavior is to return a tuple of a Matrix and the convergence # conditions for the matrix as a whole: assert LT(Mt, t, s, legacy_matrix=False) == (Ms, 1, s > 1) # With noconds=True the transformed matrix is returned without conditions # either way: assert LT(Mt, t, s, noconds=True) == Ms assert LT(Mt, t, s, legacy_matrix=False, noconds=True) == Ms
def test_fresnel(): assert fresnels(0) == 0 assert fresnels(oo) == S.Half assert fresnels(-oo) == -S.Half assert fresnels(z) == fresnels(z) assert fresnels(-z) == -fresnels(z) assert fresnels(I*z) == -I*fresnels(z) assert fresnels(-I*z) == I*fresnels(z) assert conjugate(fresnels(z)) == fresnels(conjugate(z)) assert fresnels(z).diff(z) == sin(pi*z**2/2) assert fresnels(z).rewrite(erf) == (S.One + I)/4 * ( erf((S.One + I)/2*sqrt(pi)*z) - I*erf((S.One - I)/2*sqrt(pi)*z)) assert fresnels(z).rewrite(hyper) == \ pi*z**3/6 * hyper([S(3)/4], [S(3)/2, S(7)/4], -pi**2*z**4/16) assert fresnels(z).series(z, n=15) == \ pi*z**3/6 - pi**3*z**7/336 + pi**5*z**11/42240 + O(z**15) assert fresnels(w).is_real is True assert fresnels(z).as_real_imag() == \ ((fresnels(re(z) - I*re(z)*Abs(im(z))/Abs(re(z)))/2 + fresnels(re(z) + I*re(z)*Abs(im(z))/Abs(re(z)))/2, I*(fresnels(re(z) - I*re(z)*Abs(im(z))/Abs(re(z))) - fresnels(re(z) + I*re(z)*Abs(im(z))/Abs(re(z)))) * re(z)*Abs(im(z))/(2*im(z)*Abs(re(z))))) assert fresnels(2 + 3*I).as_real_imag() == ( fresnels(2 + 3*I)/2 + fresnels(2 - 3*I)/2, I*(fresnels(2 - 3*I) - fresnels(2 + 3*I))/2 ) assert expand_func(integrate(fresnels(z), z)) == \ z*fresnels(z) + cos(pi*z**2/2)/pi assert fresnels(z).rewrite(meijerg) == sqrt(2)*pi*z**(S(9)/4) * \ meijerg(((), (1,)), ((S(3)/4,), (S(1)/4, 0)), -pi**2*z**4/16)/(2*(-z)**(S(3)/4)*(z**2)**(S(3)/4)) assert fresnelc(0) == 0 assert fresnelc(oo) == S.Half assert fresnelc(-oo) == -S.Half assert fresnelc(z) == fresnelc(z) assert fresnelc(-z) == -fresnelc(z) assert fresnelc(I*z) == I*fresnelc(z) assert fresnelc(-I*z) == -I*fresnelc(z) assert conjugate(fresnelc(z)) == fresnelc(conjugate(z)) assert fresnelc(z).diff(z) == cos(pi*z**2/2) assert fresnelc(z).rewrite(erf) == (S.One - I)/4 * ( erf((S.One + I)/2*sqrt(pi)*z) + I*erf((S.One - I)/2*sqrt(pi)*z)) assert fresnelc(z).rewrite(hyper) == \ z * hyper([S.One/4], [S.One/2, S(5)/4], -pi**2*z**4/16) assert fresnelc(z).series(z, n=15) == \ z - pi**2*z**5/40 + pi**4*z**9/3456 - pi**6*z**13/599040 + O(z**15) # issue 6510 assert fresnels(z).series(z, S.Infinity) == \ (-1/(pi**2*z**3) + O(z**(-6), (z, oo)))*sin(pi*z**2/2) + \ (3/(pi**3*z**5) - 1/(pi*z) + O(z**(-6), (z, oo)))*cos(pi*z**2/2) + S.Half assert fresnelc(z).series(z, S.Infinity) == \ (-1/(pi**2*z**3) + O(z**(-6), (z, oo)))*cos(pi*z**2/2) + \ (-3/(pi**3*z**5) + 1/(pi*z) + O(z**(-6), (z, oo)))*sin(pi*z**2/2) + S.Half assert fresnels(1/z).series(z) == \ (-z**3/pi**2 + O(z**6))*sin(pi/(2*z**2)) + (-z/pi + 3*z**5/pi**3 + \ O(z**6))*cos(pi/(2*z**2)) + S.Half assert fresnelc(1/z).series(z) == \ (-z**3/pi**2 + O(z**6))*cos(pi/(2*z**2)) + (z/pi - 3*z**5/pi**3 + \ O(z**6))*sin(pi/(2*z**2)) + S.Half assert fresnelc(w).is_real is True assert fresnelc(z).as_real_imag() == \ ((fresnelc(re(z) - I*re(z)*Abs(im(z))/Abs(re(z)))/2 + fresnelc(re(z) + I*re(z)*Abs(im(z))/Abs(re(z)))/2, I*(fresnelc(re(z) - I*re(z)*Abs(im(z))/Abs(re(z))) - fresnelc(re(z) + I*re(z)*Abs(im(z))/Abs(re(z)))) * re(z)*Abs(im(z))/(2*im(z)*Abs(re(z))))) assert fresnelc(2 + 3*I).as_real_imag() == ( fresnelc(2 - 3*I)/2 + fresnelc(2 + 3*I)/2, I*(fresnelc(2 - 3*I) - fresnelc(2 + 3*I))/2 ) assert expand_func(integrate(fresnelc(z), z)) == \ z*fresnelc(z) - sin(pi*z**2/2)/pi assert fresnelc(z).rewrite(meijerg) == sqrt(2)*pi*z**(S(3)/4) * \ meijerg(((), (1,)), ((S(1)/4,), (S(3)/4, 0)), -pi**2*z**4/16)/(2*(-z)**(S(1)/4)*(z**2)**(S(1)/4)) from sympy.utilities.randtest import verify_numerically verify_numerically(re(fresnels(z)), fresnels(z).as_real_imag()[0], z) verify_numerically(im(fresnels(z)), fresnels(z).as_real_imag()[1], z) verify_numerically(fresnels(z), fresnels(z).rewrite(hyper), z) verify_numerically(fresnels(z), fresnels(z).rewrite(meijerg), z) verify_numerically(re(fresnelc(z)), fresnelc(z).as_real_imag()[0], z) verify_numerically(im(fresnelc(z)), fresnelc(z).as_real_imag()[1], z) verify_numerically(fresnelc(z), fresnelc(z).rewrite(hyper), z) verify_numerically(fresnelc(z), fresnelc(z).rewrite(meijerg), z)
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
def test_fresnel(): assert fresnels(0) == 0 assert fresnels(oo) == S.Half assert fresnels(-oo) == -S.Half assert fresnels(I * oo) == -I * S.Half assert unchanged(fresnels, z) assert fresnels(-z) == -fresnels(z) assert fresnels(I * z) == -I * fresnels(z) assert fresnels(-I * z) == I * fresnels(z) assert conjugate(fresnels(z)) == fresnels(conjugate(z)) assert fresnels(z).diff(z) == sin(pi * z**2 / 2) assert fresnels(z).rewrite(erf) == (S.One + I) / 4 * (erf( (S.One + I) / 2 * sqrt(pi) * z) - I * erf( (S.One - I) / 2 * sqrt(pi) * z)) assert fresnels(z).rewrite(hyper) == \ pi*z**3/6 * hyper([S(3)/4], [S(3)/2, S(7)/4], -pi**2*z**4/16) assert fresnels(z).series(z, n=15) == \ pi*z**3/6 - pi**3*z**7/336 + pi**5*z**11/42240 + O(z**15) assert fresnels(w).is_extended_real is True assert fresnels(w).is_finite is True assert fresnels(z).is_extended_real is None assert fresnels(z).is_finite is None assert fresnels(z).as_real_imag() == ( fresnels(re(z) - I * im(z)) / 2 + fresnels(re(z) + I * im(z)) / 2, -I * (-fresnels(re(z) - I * im(z)) + fresnels(re(z) + I * im(z))) / 2) assert fresnels(z).as_real_imag(deep=False) == ( fresnels(re(z) - I * im(z)) / 2 + fresnels(re(z) + I * im(z)) / 2, -I * (-fresnels(re(z) - I * im(z)) + fresnels(re(z) + I * im(z))) / 2) assert fresnels(w).as_real_imag() == (fresnels(w), 0) assert fresnels(w).as_real_imag(deep=True) == (fresnels(w), 0) assert fresnels(2 + 3 * I).as_real_imag() == ( fresnels(2 + 3 * I) / 2 + fresnels(2 - 3 * I) / 2, -I * (fresnels(2 + 3 * I) - fresnels(2 - 3 * I)) / 2) assert expand_func(integrate(fresnels(z), z)) == \ z*fresnels(z) + cos(pi*z**2/2)/pi assert fresnels(z).rewrite(meijerg) == sqrt(2)*pi*z**(S(9)/4) * \ meijerg(((), (1,)), ((S(3)/4,), (S(1)/4, 0)), -pi**2*z**4/16)/(2*(-z)**(S(3)/4)*(z**2)**(S(3)/4)) assert fresnelc(0) == 0 assert fresnelc(oo) == S.Half assert fresnelc(-oo) == -S.Half assert fresnelc(I * oo) == I * S.Half assert unchanged(fresnelc, z) assert fresnelc(-z) == -fresnelc(z) assert fresnelc(I * z) == I * fresnelc(z) assert fresnelc(-I * z) == -I * fresnelc(z) assert conjugate(fresnelc(z)) == fresnelc(conjugate(z)) assert fresnelc(z).diff(z) == cos(pi * z**2 / 2) assert fresnelc(z).rewrite(erf) == (S.One - I) / 4 * (erf( (S.One + I) / 2 * sqrt(pi) * z) + I * erf( (S.One - I) / 2 * sqrt(pi) * z)) assert fresnelc(z).rewrite(hyper) == \ z * hyper([S.One/4], [S.One/2, S(5)/4], -pi**2*z**4/16) assert fresnelc(w).is_extended_real is True assert fresnelc(z).as_real_imag() == \ (fresnelc(re(z) - I*im(z))/2 + fresnelc(re(z) + I*im(z))/2, -I*(-fresnelc(re(z) - I*im(z)) + fresnelc(re(z) + I*im(z)))/2) assert fresnelc(z).as_real_imag(deep=False) == \ (fresnelc(re(z) - I*im(z))/2 + fresnelc(re(z) + I*im(z))/2, -I*(-fresnelc(re(z) - I*im(z)) + fresnelc(re(z) + I*im(z)))/2) assert fresnelc(2 + 3 * I).as_real_imag() == ( fresnelc(2 - 3 * I) / 2 + fresnelc(2 + 3 * I) / 2, -I * (fresnelc(2 + 3 * I) - fresnelc(2 - 3 * I)) / 2) assert expand_func(integrate(fresnelc(z), z)) == \ z*fresnelc(z) - sin(pi*z**2/2)/pi assert fresnelc(z).rewrite(meijerg) == sqrt(2)*pi*z**(S(3)/4) * \ meijerg(((), (1,)), ((S(1)/4,), (S(3)/4, 0)), -pi**2*z**4/16)/(2*(-z)**(S(1)/4)*(z**2)**(S(1)/4)) from sympy.utilities.randtest import verify_numerically verify_numerically(re(fresnels(z)), fresnels(z).as_real_imag()[0], z) verify_numerically(im(fresnels(z)), fresnels(z).as_real_imag()[1], z) verify_numerically(fresnels(z), fresnels(z).rewrite(hyper), z) verify_numerically(fresnels(z), fresnels(z).rewrite(meijerg), z) verify_numerically(re(fresnelc(z)), fresnelc(z).as_real_imag()[0], z) verify_numerically(im(fresnelc(z)), fresnelc(z).as_real_imag()[1], z) verify_numerically(fresnelc(z), fresnelc(z).rewrite(hyper), z) verify_numerically(fresnelc(z), fresnelc(z).rewrite(meijerg), z) raises(ArgumentIndexError, lambda: fresnels(z).fdiff(2)) raises(ArgumentIndexError, lambda: fresnelc(z).fdiff(2)) assert fresnels(x).taylor_term(-1, x) == S.Zero assert fresnelc(x).taylor_term(-1, x) == S.Zero assert fresnelc(x).taylor_term(1, x) == -pi**2 * x**5 / 40
def test_laplace_transform(): from sympy import fresnels, fresnelc LT = laplace_transform a, b, c, = symbols('a b c', positive=True) t = symbols('t') w = Symbol("w") f = Function("f") # Test unevaluated form assert laplace_transform(f(t), t, w) == LaplaceTransform(f(t), t, w) assert inverse_laplace_transform(f(w), w, t, plane=0) == InverseLaplaceTransform( f(w), w, t, 0) # test a bug spos = symbols('s', positive=True) assert LT(exp(t), t, spos)[:2] == (1 / (spos - 1), True) # basic tests from wikipedia assert LT((t - a)**b*exp(-c*(t - a))*Heaviside(t - a), t, s) == \ ((s + c)**(-b - 1)*exp(-a*s)*gamma(b + 1), -c, True) assert LT(t**a, t, s) == (s**(-a - 1) * gamma(a + 1), 0, True) assert LT(Heaviside(t), t, s) == (1 / s, 0, True) assert LT(Heaviside(t - a), t, s) == (exp(-a * s) / s, 0, True) assert LT(1 - exp(-a * t), t, s) == (a / (s * (a + s)), 0, True) assert LT((exp(2*t) - 1)*exp(-b - t)*Heaviside(t)/2, t, s, noconds=True) \ == exp(-b)/(s**2 - 1) assert LT(exp(t), t, s)[:2] == (1 / (s - 1), 1) assert LT(exp(2 * t), t, s)[:2] == (1 / (s - 2), 2) assert LT(exp(a * t), t, s)[:2] == (1 / (s - a), a) assert LT(log(t / a), t, s) == ((log(a * s) + EulerGamma) / s / -1, 0, True) assert LT(erf(t), t, s) == ((erfc(s / 2)) * exp(s**2 / 4) / s, 0, True) assert LT(sin(a * t), t, s) == (a / (a**2 + s**2), 0, True) assert LT(cos(a * t), t, s) == (s / (a**2 + s**2), 0, True) # TODO would be nice to have these come out better assert LT(exp(-a * t) * sin(b * t), t, s) == (b / (b**2 + (a + s)**2), -a, True) assert LT(exp(-a*t)*cos(b*t), t, s) == \ ((a + s)/(b**2 + (a + s)**2), -a, True) assert LT(besselj(0, t), t, s) == (1 / sqrt(1 + s**2), 0, True) assert LT(besselj(1, t), t, s) == (1 - 1 / sqrt(1 + 1 / s**2), 0, True) # TODO general order works, but is a *mess* # TODO besseli also works, but is an even greater mess # test a bug in conditions processing # TODO the auxiliary condition should be recognised/simplified assert LT(exp(t) * cos(t), t, s)[:-1] in [ ((s - 1) / (s**2 - 2 * s + 2), -oo), ((s - 1) / ((s - 1)**2 + 1), -oo), ] # Fresnel functions assert laplace_transform(fresnels(t), t, s) == \ ((-sin(s**2/(2*pi))*fresnels(s/pi) + sin(s**2/(2*pi))/2 - cos(s**2/(2*pi))*fresnelc(s/pi) + cos(s**2/(2*pi))/2)/s, 0, True) assert laplace_transform( fresnelc(t), t, s) == (((2 * sin(s**2 / (2 * pi)) * fresnelc(s / pi) - 2 * cos(s**2 / (2 * pi)) * fresnels(s / pi) + sqrt(2) * cos(s**2 / (2 * pi) + pi / 4)) / (2 * s), 0, True)) assert LT(Matrix([[exp(t), t*exp(-t)], [t*exp(-t), exp(t)]]), t, s) ==\ Matrix([ [(1/(s - 1), 1, True), ((s + 1)**(-2), 0, True)], [((s + 1)**(-2), 0, True), (1/(s - 1), 1, True)] ])
def test_laplace_transform(): from sympy import (fresnels, fresnelc, hyper) LT = laplace_transform a, b, c, = symbols('a b c', positive=True) t = symbols('t') w = Symbol("w") f = Function("f") # Test unevaluated form assert laplace_transform(f(t), t, w) == LaplaceTransform(f(t), t, w) assert inverse_laplace_transform( f(w), w, t, plane=0) == InverseLaplaceTransform(f(w), w, t, 0) # test a bug spos = symbols('s', positive=True) assert LT(exp(t), t, spos)[:2] == (1/(spos - 1), True) # basic tests from wikipedia assert LT((t - a)**b*exp(-c*(t - a))*Heaviside(t - a), t, s) == \ ((s + c)**(-b - 1)*exp(-a*s)*gamma(b + 1), -c, True) assert LT(t**a, t, s) == (s**(-a - 1)*gamma(a + 1), 0, True) assert LT(Heaviside(t), t, s) == (1/s, 0, True) assert LT(Heaviside(t - a), t, s) == (exp(-a*s)/s, 0, True) assert LT(1 - exp(-a*t), t, s) == (a/(s*(a + s)), 0, True) assert LT((exp(2*t) - 1)*exp(-b - t)*Heaviside(t)/2, t, s, noconds=True) \ == exp(-b)/(s**2 - 1) assert LT(exp(t), t, s)[:2] == (1/(s - 1), 1) assert LT(exp(2*t), t, s)[:2] == (1/(s - 2), 2) assert LT(exp(a*t), t, s)[:2] == (1/(s - a), a) assert LT(log(t/a), t, s) == ((log(a*s) + EulerGamma)/s/-1, 0, True) assert LT(erf(t), t, s) == ((-erf(s/2) + 1)*exp(s**2/4)/s, 0, True) assert LT(sin(a*t), t, s) == (a/(a**2 + s**2), 0, True) assert LT(cos(a*t), t, s) == (s/(a**2 + s**2), 0, True) # TODO would be nice to have these come out better assert LT( exp(-a*t)*sin(b*t), t, s) == (b/(b**2 + (a + s)**2), -a, True) assert LT(exp(-a*t)*cos(b*t), t, s) == \ ((a + s)/(b**2 + (a + s)**2), -a, True) # TODO sinh, cosh have delicate cancellation assert LT(besselj(0, t), t, s) == (1/sqrt(1 + s**2), 0, True) assert LT(besselj(1, t), t, s) == (1 - 1/sqrt(1 + 1/s**2), 0, True) # TODO general order works, but is a *mess* # TODO besseli also works, but is an even greater mess # test a bug in conditions processing # TODO the auxiliary condition should be recognised/simplified assert LT(exp(t)*cos(t), t, s)[:-1] in [ ((s - 1)/(s**2 - 2*s + 2), -oo), ((s - 1)/((s - 1)**2 + 1), -oo), ] # Fresnel functions assert laplace_transform(fresnels(t), t, s) == \ ((-sin(s**2/(2*pi))*fresnels(s/pi) + sin(s**2/(2*pi))/2 - cos(s**2/(2*pi))*fresnelc(s/pi) + cos(s**2/(2*pi))/2)/s, 0, True) assert laplace_transform(fresnelc(t), t, s) == ( (sin(s**2/(2*pi))*fresnelc(s/pi)/s - cos(s**2/(2*pi))*fresnels(s/pi)/s + sqrt(2)*cos(s**2/(2*pi) + pi/4)/(2*s), 0, True))
def test_issue_3686(): # remove this when fresnel itegrals are implemented from sympy import expand_func, fresnels assert expand_func(integrate(sin(x**2), x)) == \ sqrt(2)*sqrt(pi)*fresnels(sqrt(2)*x/sqrt(pi))/2
def test_fresnel(): from sympy import fresnels, fresnelc assert expand_func(integrate(sin(pi * x**2 / 2), x)) == fresnels(x) assert expand_func(integrate(cos(pi * x**2 / 2), x)) == fresnelc(x)