Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Sympy can handle the delta but not the Heaviside product:

sage: import sympy
sage: x,a = sympy.var("x a")
sage: sympy.integrate(x^2*sympy.DiracDelta(x -a), (x,-sympy.oo, sympy.oo))
sage: x,x1,x2 = sympy.var('x,x1,x2')
sage: k=sympy.Heaviside(x-x1)*sympy.Heaviside(x2-x)
sage: sympy.integrate(k,(x, -sympy.oo, sympy.oo))
Integral(Heaviside(x2 - x)*Heaviside(x - x1), (x, -oo, oo))

Unfortunately because of interface gaps algorithm='sympy' doesn't work:

sage: reset()
sage: var("a x")
(a, x)
sage: integral(x^2*dirac_delta(-a + x), x, -infinity, +infinity,algorithm='sympy')
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (534, 0))
NotImplementedError: SymPy function 'dirac_delta' doesn't exist

The monkeypatch doesn't take much, though:

sage: reset()
sage: import sympy
sage: sympy.dirac_delta = sympy.DiracDelta
sage: sage.rings.infinity.MinusInfinity._sympy_ = lambda self: -sympy.oo
sage: var("a x")
(a, x)
sage: integral(x^2*dirac_delta(-a + x), x, -infinity, +infinity,algorithm='sympy')

A better fix would be to improve sage.symbolic.expression_conversions.sympy and add more functions to the translation table. But I have the impression that sympy-style integration is considered a dead end, which is strange to me because at least I can understand the code, whereas I wouldn't know where to begin to fix a maxima issue.