Repository: sympy/sympy

Issue:
P(X < -1) of ExponentialDistribution
```
>>> from sympy import *
>>> from sympy.stats import Exponential, Gamma, P, pspace, Normal, Uniform
>>> X = Exponential('X', 3)
>>> P(X < -1)
AttributeError                            Traceback (most recent call last)
<ipython-input-168-7d38f8bb52c5> in <module>()
----> 1 P(X < -1)

/home/gxyd/Public/sympy/sympy/stats/rv.py in probability(condition, given_condition, numsamples, evaluate, **kwargs)
    621     result = pspace(condition).probability(condition, **kwargs)
    622     if evaluate and hasattr(result, 'doit'):
--> 623         return result.doit()
    624     else:
    625         return result

/home/gxyd/Public/sympy/sympy/integrals/integrals.py in doit(self, **hints)
    525                     else:
    526                         try:
--> 527                             function = antideriv._eval_interval(x, a, b)
    528                         except NotImplementedError:
    529                             # This can happen if _eval_interval depends in a

/home/gxyd/Public/sympy/sympy/core/expr.py in _eval_interval(self, x, a, b)
    778             B = 0
    779         else:
--> 780             B = self.subs(x, b)
    781             if B.has(S.NaN, S.Infinity, S.NegativeInfinity, S.ComplexInfinity):
    782                 B = limit(self, x, b)

/home/gxyd/Public/sympy/sympy/core/basic.py in subs(self, *args, **kwargs)
    893             rv = self
    894             for old, new in sequence:
--> 895                 rv = rv._subs(old, new, **kwargs)
    896                 if not isinstance(rv, Basic):
    897                     break

/home/gxyd/Public/sympy/sympy/core/cache.py in wrapper(*args, **kwargs)
     91             def wrapper(*args, **kwargs):
     92                 try:
---> 93                     retval = cfunc(*args, **kwargs)
     94                 except TypeError:
     95                     retval = func(*args, **kwargs)

/usr/lib/python3.4/functools.py in wrapper(*args, **kwds)
    470                         hits += 1
    471                         return result
--> 472                 result = user_function(*args, **kwds)
    473                 with lock:
    474                     if key in cache:

/home/gxyd/Public/sympy/sympy/core/basic.py in _subs(self, old, new, **hints)
   1007         rv = self._eval_subs(old, new)
   1008         if rv is None:
-> 1009             rv = fallback(self, old, new)
   1010         return rv
   1011 

/home/gxyd/Public/sympy/sympy/core/basic.py in fallback(self, old, new)
    979                 if not hasattr(arg, '_eval_subs'):
    980                     continue
--> 981                 arg = arg._subs(old, new, **hints)
    982                 if not _aresame(arg, args[i]):
    983                     hit = True

/home/gxyd/Public/sympy/sympy/core/cache.py in wrapper(*args, **kwargs)
     91             def wrapper(*args, **kwargs):
     92                 try:
---> 93                     retval = cfunc(*args, **kwargs)
     94                 except TypeError:
     95                     retval = func(*args, **kwargs)

/usr/lib/python3.4/functools.py in wrapper(*args, **kwds)
    470                         hits += 1
    471                         return result
--> 472                 result = user_function(*args, **kwds)
    473                 with lock:
    474                     if key in cache:

/home/gxyd/Public/sympy/sympy/core/basic.py in _subs(self, old, new, **hints)
   1007         rv = self._eval_subs(old, new)
   1008         if rv is None:
-> 1009             rv = fallback(self, old, new)
   1010         return rv
   1011 

/home/gxyd/Public/sympy/sympy/core/basic.py in fallback(self, old, new)
    979                 if not hasattr(arg, '_eval_subs'):
    980                     continue
--> 981                 arg = arg._subs(old, new, **hints)
    982                 if not _aresame(arg, args[i]):
    983                     hit = True

/home/gxyd/Public/sympy/sympy/core/cache.py in wrapper(*args, **kwargs)
     91             def wrapper(*args, **kwargs):
     92                 try:
---> 93                     retval = cfunc(*args, **kwargs)
     94                 except TypeError:
     95                     retval = func(*args, **kwargs)

/usr/lib/python3.4/functools.py in wrapper(*args, **kwds)
    470                         hits += 1
    471                         return result
--> 472                 result = user_function(*args, **kwds)
    473                 with lock:
    474                     if key in cache:

/home/gxyd/Public/sympy/sympy/core/basic.py in _subs(self, old, new, **hints)
   1007         rv = self._eval_subs(old, new)
   1008         if rv is None:
-> 1009             rv = fallback(self, old, new)
   1010         return rv
   1011 

/home/gxyd/Public/sympy/sympy/core/basic.py in fallback(self, old, new)
    984                     args[i] = arg
    985             if hit:
--> 986                 rv = self.func(*args)
    987                 hack2 = hints.get('hack2', False)
    988                 if hack2 and self.is_Mul and not rv.is_Mul:  # 2-arg hack

/home/gxyd/Public/sympy/sympy/core/cache.py in wrapper(*args, **kwargs)
     91             def wrapper(*args, **kwargs):
     92                 try:
---> 93                     retval = cfunc(*args, **kwargs)
     94                 except TypeError:
     95                     retval = func(*args, **kwargs)

/usr/lib/python3.4/functools.py in wrapper(*args, **kwds)
    470                         hits += 1
    471                         return result
--> 472                 result = user_function(*args, **kwds)
    473                 with lock:
    474                     if key in cache:

/home/gxyd/Public/sympy/sympy/core/operations.py in __new__(cls, *args, **options)
     39             return args[0]
     40 
---> 41         c_part, nc_part, order_symbols = cls.flatten(args)
     42         is_commutative = not nc_part
     43         obj = cls._from_args(c_part + nc_part, is_commutative)

/home/gxyd/Public/sympy/sympy/core/mul.py in flatten(cls, seq)
    179             assert not a is S.One
    180             if not a.is_zero and a.is_Rational:
--> 181                 r, b = b.as_coeff_Mul()
    182                 if b.is_Add:
    183                     if r is not S.One:  # 2-arg hack

AttributeError: 'EmptySet' object has no attribute 'as_coeff_Mul'
```

I guess this should return `S.Zero`, instead of an `AttributeError`.

Discussion:

Patch:
diff --git a/sympy/stats/crv.py b/sympy/stats/crv.py
index 292427da84..fe2fd5e221 100644
--- a/sympy/stats/crv.py
+++ b/sympy/stats/crv.py
@@ -300,6 +300,9 @@ def probability(self, condition, **kwargs):
             rv = [rv for rv in self.values if rv.symbol == domain.symbol][0]
             # Integrate out all other random variables
             pdf = self.compute_density(rv, **kwargs)
+            # return S.Zero if `domain` is empty set
+            if domain.set is S.EmptySet:
+                return S.Zero
             # Integrate out the last variable over the special domain
             return Integral(pdf(z), (z, domain.set), **kwargs)
 


Test patch:
diff --git a/sympy/stats/tests/test_continuous_rv.py b/sympy/stats/tests/test_continuous_rv.py
index 2ee455c1c1..05f5400293 100644
--- a/sympy/stats/tests/test_continuous_rv.py
+++ b/sympy/stats/tests/test_continuous_rv.py
@@ -633,3 +633,10 @@ def test_difficult_univariate():
     assert density(x**3)
     assert density(exp(x**2))
     assert density(log(x))
+
+
+def test_issue_10003():
+    X = Exponential('x', 3)
+    G = Gamma('g', 1, 2)
+    assert P(X < -1) == S.Zero
+    assert P(G < -1) == S.Zero