Repository: sympy/sympy

Issue:
Inverse Laplace Transform of e^(-s) doesn't give dirac function.
Inverse Laplace transform of e^(-s) should give dirac function, but instead it can't evaluate.


Discussion:

Patch:
diff --git a/sympy/integrals/meijerint.py b/sympy/integrals/meijerint.py
index f90e037636..74acf3fccb 100644
--- a/sympy/integrals/meijerint.py
+++ b/sympy/integrals/meijerint.py
@@ -38,7 +38,7 @@
 from sympy.simplify import hyperexpand, powdenest, collect
 from sympy.simplify.fu import sincos_to_sum
 from sympy.logic.boolalg import And, Or, BooleanAtom
-from sympy.functions.special.delta_functions import Heaviside
+from sympy.functions.special.delta_functions import DiracDelta, Heaviside
 from sympy.functions.elementary.exponential import exp
 from sympy.functions.elementary.piecewise import Piecewise, piecewise_fold
 from sympy.functions.elementary.hyperbolic import \
@@ -2051,11 +2051,19 @@ def meijerint_inversion(f, x, t):
     if not _is_analytic(f, x):
         _debug('But expression is not analytic.')
         return None
-    # We filter out exponentials here. If we are given an Add this will not
+    # Exponentials correspond to shifts; we filter them out and then
+    # shift the result later.  If we are given an Add this will not
     # work, but the calling code will take care of that.
-    shift = 0
+    shift = S.Zero
+
     if f.is_Mul:
         args = list(f.args)
+    elif isinstance(f, exp):
+        args = [f]
+    else:
+        args = None
+
+    if args:
         newargs = []
         exponentials = []
         while args:
@@ -2091,6 +2099,18 @@ def meijerint_inversion(f, x, t):
         shift = Add(*exponentials)
         f = Mul(*newargs)
 
+    if x not in f.free_symbols:
+        _debug('Expression consists of constant and exp shift:', f, shift)
+        from sympy import Eq, im
+        cond = Eq(im(shift), 0)
+        if cond == False:
+            _debug('but shift is nonreal, cannot be a Laplace transform')
+            return None
+        res = f*DiracDelta(t + shift)
+        _debug('Result is a delta function, possibly conditional:', res, cond)
+        # cond is True or Eq
+        return Piecewise((res.subs(t, t_), cond))
+
     gs = _rewrite1(f, x)
     if gs is not None:
         fac, po, g, cond = gs


Test patch:
diff --git a/sympy/integrals/tests/test_meijerint.py b/sympy/integrals/tests/test_meijerint.py
index ebbc9009d4..091dc8cf2d 100644
--- a/sympy/integrals/tests/test_meijerint.py
+++ b/sympy/integrals/tests/test_meijerint.py
@@ -306,6 +306,20 @@ def test_inversion_conditional_output():
     assert f2.args[-1][0] == ILT or f2.args[-1][0] == ILT.as_integral
 
 
+def test_inversion_exp_real_nonreal_shift():
+    from sympy import Symbol, DiracDelta
+    r = Symbol('r', real=True)
+    c = Symbol('c', real=False)
+    a = 1 + 2*I
+    z = Symbol('z')
+    assert not meijerint_inversion(exp(r*s), s, t).is_Piecewise
+    assert meijerint_inversion(exp(a*s), s, t) is None
+    assert meijerint_inversion(exp(c*s), s, t) is None
+    f = meijerint_inversion(exp(z*s), s, t)
+    assert f.is_Piecewise
+    assert isinstance(f.args[0][0], DiracDelta)
+
+
 @slow
 def test_lookup_table():
     from random import uniform, randrange
diff --git a/sympy/integrals/tests/test_transforms.py b/sympy/integrals/tests/test_transforms.py
index 3e636bf387..6e1ddd7a85 100644
--- a/sympy/integrals/tests/test_transforms.py
+++ b/sympy/integrals/tests/test_transforms.py
@@ -583,6 +583,37 @@ def simp_hyp(expr):
         Matrix([[exp(t)*Heaviside(t), 0], [0, exp(2*t)*Heaviside(t)]])
 
 
+def test_inverse_laplace_transform_delta():
+    from sympy import DiracDelta
+    ILT = inverse_laplace_transform
+    t = symbols('t')
+    assert ILT(2, s, t) == 2*DiracDelta(t)
+    assert ILT(2*exp(3*s) - 5*exp(-7*s), s, t) == \
+        2*DiracDelta(t + 3) - 5*DiracDelta(t - 7)
+    a = cos(sin(7)/2)
+    assert ILT(a*exp(-3*s), s, t) == a*DiracDelta(t - 3)
+    assert ILT(exp(2*s), s, t) == DiracDelta(t + 2)
+    r = Symbol('r', real=True)
+    assert ILT(exp(r*s), s, t) == DiracDelta(t + r)
+
+
+def test_inverse_laplace_transform_delta_cond():
+    from sympy import DiracDelta, Eq, im
+    ILT = inverse_laplace_transform
+    t = symbols('t')
+    r = Symbol('r', real=True)
+    assert ILT(exp(r*s), s, t, noconds=False) == (DiracDelta(t + r), True)
+    z = Symbol('z')
+    assert ILT(exp(z*s), s, t, noconds=False) == \
+        (DiracDelta(t + z), Eq(im(z), 0))
+    # inversion does not exist: verify it doesn't evaluate to DiracDelta
+    for z in (Symbol('z', real=False),
+              Symbol('z', imaginary=True, zero=False)):
+        f = ILT(exp(z*s), s, t, noconds=False)
+        f = f[0] if isinstance(f, tuple) else f
+        assert f.func != DiracDelta
+
+
 def test_fourier_transform():
     from sympy import simplify, expand, expand_complex, factor, expand_trig
     FT = fourier_transform