Generalized functions#

Sage implements several generalized functions (also known as distributions) such as Dirac delta, Heaviside step functions. These generalized functions can be manipulated within Sage like any other symbolic functions.

AUTHORS:

  • Golam Mortuza Hossain (2009-06-26): initial version

EXAMPLES:

Dirac delta function:

sage: dirac_delta(x)                                                                # needs sage.symbolic
dirac_delta(x)
>>> from sage.all import *
>>> dirac_delta(x)                                                                # needs sage.symbolic
dirac_delta(x)

Heaviside step function:

sage: heaviside(x)                                                                  # needs sage.symbolic
heaviside(x)
>>> from sage.all import *
>>> heaviside(x)                                                                  # needs sage.symbolic
heaviside(x)

Unit step function:

sage: unit_step(x)                                                                  # needs sage.symbolic
unit_step(x)
>>> from sage.all import *
>>> unit_step(x)                                                                  # needs sage.symbolic
unit_step(x)

Signum (sgn) function:

sage: sgn(x)                                                                        # needs sage.symbolic
sgn(x)
>>> from sage.all import *
>>> sgn(x)                                                                        # needs sage.symbolic
sgn(x)

Kronecker delta function:

sage: m, n = var('m,n')                                                             # needs sage.symbolic
sage: kronecker_delta(m, n)                                                         # needs sage.symbolic
kronecker_delta(m, n)
>>> from sage.all import *
>>> m, n = var('m,n')                                                             # needs sage.symbolic
>>> kronecker_delta(m, n)                                                         # needs sage.symbolic
kronecker_delta(m, n)
class sage.functions.generalized.FunctionDiracDelta[source]#

Bases: BuiltinFunction

The Dirac delta (generalized) function, \(\delta(x)\) (dirac_delta(x)).

INPUT:

  • x – a real number or a symbolic expression

DEFINITION:

Dirac delta function \(\delta(x)\), is defined in Sage as:

\(\delta(x) = 0\) for real \(x \ne 0\) and \(\int_{-\infty}^{\infty} \delta(x) dx = 1\)

Its alternate definition with respect to an arbitrary test function \(f(x)\) is

\(\int_{-\infty}^{\infty} f(x) \delta(x-a) dx = f(a)\)

EXAMPLES:

sage: # needs sage.symbolic
sage: dirac_delta(1)
0
sage: dirac_delta(0)
dirac_delta(0)
sage: dirac_delta(x)
dirac_delta(x)
sage: integrate(dirac_delta(x), x, -1, 1, algorithm='sympy')                    # needs sympy
1
>>> from sage.all import *
>>> # needs sage.symbolic
>>> dirac_delta(Integer(1))
0
>>> dirac_delta(Integer(0))
dirac_delta(0)
>>> dirac_delta(x)
dirac_delta(x)
>>> integrate(dirac_delta(x), x, -Integer(1), Integer(1), algorithm='sympy')                    # needs sympy
1

REFERENCES:

class sage.functions.generalized.FunctionHeaviside[source]#

Bases: GinacFunction

The Heaviside step function, \(H(x)\) (heaviside(x)).

INPUT:

  • x – a real number or a symbolic expression

DEFINITION:

The Heaviside step function, \(H(x)\) is defined in Sage as:

\(H(x) = 0\) for \(x < 0\) and \(H(x) = 1\) for \(x > 0\)

See also

unit_step()

EXAMPLES:

sage: # needs sage.symbolic
sage: heaviside(-1)
0
sage: heaviside(1)
1
sage: heaviside(0)
heaviside(0)
sage: heaviside(x)
heaviside(x)

sage: heaviside(-1/2)                                                           # needs sage.symbolic
0
sage: heaviside(exp(-1000000000000000000000))                                   # needs sage.symbolic
1
>>> from sage.all import *
>>> # needs sage.symbolic
>>> heaviside(-Integer(1))
0
>>> heaviside(Integer(1))
1
>>> heaviside(Integer(0))
heaviside(0)
>>> heaviside(x)
heaviside(x)

>>> heaviside(-Integer(1)/Integer(2))                                                           # needs sage.symbolic
0
>>> heaviside(exp(-Integer(1000000000000000000000)))                                   # needs sage.symbolic
1

REFERENCES:

class sage.functions.generalized.FunctionKroneckerDelta[source]#

Bases: BuiltinFunction

The Kronecker delta function \(\delta_{m,n}\) (kronecker_delta(m, n)).

INPUT:

  • m – a number or a symbolic expression

  • n – a number or a symbolic expression

DEFINITION:

Kronecker delta function \(\delta_{m,n}\) is defined as:

\(\delta_{m,n} = 0\) for \(m \ne n\) and \(\delta_{m,n} = 1\) for \(m = n\)

EXAMPLES:

sage: kronecker_delta(1, 2)                                                     # needs sage.rings.complex_interval_field
0
sage: kronecker_delta(1, 1)                                                     # needs sage.rings.complex_interval_field
1
sage: m, n = var('m,n')                                                         # needs sage.symbolic
sage: kronecker_delta(m, n)                                                     # needs sage.symbolic
kronecker_delta(m, n)
>>> from sage.all import *
>>> kronecker_delta(Integer(1), Integer(2))                                                     # needs sage.rings.complex_interval_field
0
>>> kronecker_delta(Integer(1), Integer(1))                                                     # needs sage.rings.complex_interval_field
1
>>> m, n = var('m,n')                                                         # needs sage.symbolic
>>> kronecker_delta(m, n)                                                     # needs sage.symbolic
kronecker_delta(m, n)

REFERENCES:

class sage.functions.generalized.FunctionSignum[source]#

Bases: BuiltinFunction

The signum or sgn function \(\mathrm{sgn}(x)\) (sgn(x)).

INPUT:

  • x – a real number or a symbolic expression

DEFINITION:

The sgn function, \(\mathrm{sgn}(x)\) is defined as:

\(\mathrm{sgn}(x) = 1\) for \(x > 0\), \(\mathrm{sgn}(x) = 0\) for \(x = 0\) and \(\mathrm{sgn}(x) = -1\) for \(x < 0\)

EXAMPLES:

sage: sgn(-1)
-1
sage: sgn(1)
1
sage: sgn(0)
0
sage: sgn(x)                                                                    # needs sage.symbolic
sgn(x)
>>> from sage.all import *
>>> sgn(-Integer(1))
-1
>>> sgn(Integer(1))
1
>>> sgn(Integer(0))
0
>>> sgn(x)                                                                    # needs sage.symbolic
sgn(x)

We can also use sign:

sage: sign(1)
1
sage: sign(0)
0
sage: a = AA(-5).nth_root(7)                                                    # needs sage.rings.number_field
sage: sign(a)                                                                   # needs sage.rings.number_field
-1
>>> from sage.all import *
>>> sign(Integer(1))
1
>>> sign(Integer(0))
0
>>> a = AA(-Integer(5)).nth_root(Integer(7))                                                    # needs sage.rings.number_field
>>> sign(a)                                                                   # needs sage.rings.number_field
-1

REFERENCES:

class sage.functions.generalized.FunctionUnitStep[source]#

Bases: GinacFunction

The unit step function, \(\mathrm{u}(x)\) (unit_step(x)).

INPUT:

  • x – a real number or a symbolic expression

DEFINITION:

The unit step function, \(\mathrm{u}(x)\) is defined in Sage as:

\(\mathrm{u}(x) = 0\) for \(x < 0\) and \(\mathrm{u}(x) = 1\) for \(x \geq 0\)

See also

heaviside()

EXAMPLES:

sage: # needs sage.symbolic
sage: unit_step(-1)
0
sage: unit_step(1)
1
sage: unit_step(0)
1
sage: unit_step(x)
unit_step(x)
sage: unit_step(-exp(-10000000000000000000))
0
>>> from sage.all import *
>>> # needs sage.symbolic
>>> unit_step(-Integer(1))
0
>>> unit_step(Integer(1))
1
>>> unit_step(Integer(0))
1
>>> unit_step(x)
unit_step(x)
>>> unit_step(-exp(-Integer(10000000000000000000)))
0