Error functions

This module provides symbolic error functions. These functions use the \(mpmath library\) for numerical evaluation and Maxima, Pynac for symbolics.

The main objects which are exported from this module are:

  • erf – the error function

  • erfc – the complementary error function

  • erfi – the imaginary error function

  • erfinv – the inverse error function

  • fresnel_sin – the Fresnel integral \(S(x)\)

  • fresnel_cos – the Fresnel integral \(C(x)\)

AUTHORS:

  • Original authors erf/error_fcn (c) 2006-2014: Karl-Dieter Crisman, Benjamin Jones, Mike Hansen, William Stein, Burcin Erocal, Jeroen Demeyer, W. D. Joyner, R. Andrew Ohana

  • Reorganisation in new file, addition of erfi/erfinv/erfc (c) 2016: Ralf Stephan

  • Fresnel integrals (c) 2017 Marcelo Forets

REFERENCES:

class sage.functions.error.Function_Fresnel_cos[source]

Bases: BuiltinFunction

The cosine Fresnel integral.

It is defined by the integral

\[\operatorname{C}(x) = \int_0^x \cos\left(\frac{\pi t^2}{2}\right)\, dt\]

for real \(x\). Using power series expansions, it can be extended to the domain of complex numbers. See the Wikipedia article Fresnel_integral.

INPUT:

  • x – the argument of the function

EXAMPLES:

sage: # needs sage.symbolic
sage: fresnel_cos(0)
0
sage: fresnel_cos(x).subs(x==0)
0
sage: x = var('x')
sage: fresnel_cos(1).n(100)
0.77989340037682282947420641365
sage: fresnel_cos(x)._sympy_()                                              # needs sympy
fresnelc(x)
>>> from sage.all import *
>>> # needs sage.symbolic
>>> fresnel_cos(Integer(0))
0
>>> fresnel_cos(x).subs(x==Integer(0))
0
>>> x = var('x')
>>> fresnel_cos(Integer(1)).n(Integer(100))
0.77989340037682282947420641365
>>> fresnel_cos(x)._sympy_()                                              # needs sympy
fresnelc(x)
class sage.functions.error.Function_Fresnel_sin[source]

Bases: BuiltinFunction

The sine Fresnel integral.

It is defined by the integral

\[\operatorname{S}(x) = \int_0^x \sin\left(\frac{\pi t^2}{2}\right)\, dt\]

for real \(x\). Using power series expansions, it can be extended to the domain of complex numbers. See the Wikipedia article Fresnel_integral.

INPUT:

  • x – the argument of the function

EXAMPLES:

sage: # needs sage.symbolic
sage: fresnel_sin(0)
0
sage: fresnel_sin(x).subs(x==0)
0
sage: x = var('x')
sage: fresnel_sin(1).n(100)
0.43825914739035476607675669662
sage: fresnel_sin(x)._sympy_()                                              # needs sympy
fresnels(x)
>>> from sage.all import *
>>> # needs sage.symbolic
>>> fresnel_sin(Integer(0))
0
>>> fresnel_sin(x).subs(x==Integer(0))
0
>>> x = var('x')
>>> fresnel_sin(Integer(1)).n(Integer(100))
0.43825914739035476607675669662
>>> fresnel_sin(x)._sympy_()                                              # needs sympy
fresnels(x)
class sage.functions.error.Function_erf[source]

Bases: BuiltinFunction

The error function.

The error function is defined for real values as

\[\operatorname{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} dt.\]

This function is also defined for complex values, via analytic continuation.

EXAMPLES:

We can evaluate numerically:

sage: erf(2)                                                                    # needs sage.symbolic
erf(2)
sage: erf(2).n()                                                                # needs sage.symbolic
0.995322265018953
sage: erf(2).n(100)                                                             # needs sage.symbolic
0.99532226501895273416206925637
sage: erf(ComplexField(100)(2+3j))                                              # needs sage.rings.real_mpfr
-20.829461427614568389103088452 + 8.6873182714701631444280787545*I
>>> from sage.all import *
>>> erf(Integer(2))                                                                    # needs sage.symbolic
erf(2)
>>> erf(Integer(2)).n()                                                                # needs sage.symbolic
0.995322265018953
>>> erf(Integer(2)).n(Integer(100))                                                             # needs sage.symbolic
0.99532226501895273416206925637
>>> erf(ComplexField(Integer(100))(Integer(2)+ComplexNumber(0, '3')))                                              # needs sage.rings.real_mpfr
-20.829461427614568389103088452 + 8.6873182714701631444280787545*I

Basic symbolic properties are handled by Sage and Maxima:

sage: x = var("x")                                                              # needs sage.symbolic
sage: diff(erf(x),x)                                                            # needs sage.symbolic
2*e^(-x^2)/sqrt(pi)
sage: integrate(erf(x),x)                                                       # needs sage.symbolic
x*erf(x) + e^(-x^2)/sqrt(pi)
>>> from sage.all import *
>>> x = var("x")                                                              # needs sage.symbolic
>>> diff(erf(x),x)                                                            # needs sage.symbolic
2*e^(-x^2)/sqrt(pi)
>>> integrate(erf(x),x)                                                       # needs sage.symbolic
x*erf(x) + e^(-x^2)/sqrt(pi)

ALGORITHM:

Sage implements numerical evaluation of the error function via the erf() function from mpmath. Symbolics are handled by Sage and Maxima.

REFERENCES:

class sage.functions.error.Function_erfc[source]

Bases: BuiltinFunction

The complementary error function.

The complementary error function is defined by

\[\frac{2}{\sqrt{\pi}} \int_t^\infty e^{-x^2} dx.\]

EXAMPLES:

sage: erfc(6)                                                                   # needs sage.symbolic
erfc(6)
sage: erfc(6).n()                                                               # needs sage.symbolic
2.15197367124989e-17
sage: erfc(RealField(100)(1/2))                                                 # needs sage.rings.real_mpfr
0.47950012218695346231725334611

sage: 1 - erfc(0.5)                                                             # needs mpmath
0.520499877813047
sage: erf(0.5)                                                                  # needs mpmath
0.520499877813047
>>> from sage.all import *
>>> erfc(Integer(6))                                                                   # needs sage.symbolic
erfc(6)
>>> erfc(Integer(6)).n()                                                               # needs sage.symbolic
2.15197367124989e-17
>>> erfc(RealField(Integer(100))(Integer(1)/Integer(2)))                                                 # needs sage.rings.real_mpfr
0.47950012218695346231725334611

>>> Integer(1) - erfc(RealNumber('0.5'))                                                             # needs mpmath
0.520499877813047
>>> erf(RealNumber('0.5'))                                                                  # needs mpmath
0.520499877813047
class sage.functions.error.Function_erfi[source]

Bases: BuiltinFunction

The imaginary error function.

The imaginary error function is defined by

\[\operatorname{erfi}(x) = -i \operatorname{erf}(ix).\]
class sage.functions.error.Function_erfinv[source]

Bases: BuiltinFunction

The inverse error function.

The inverse error function is defined by:

\[\operatorname{erfinv}(x) = \operatorname{erf}^{-1}(x).\]