Repository: sympy/sympy

Issue:
CDF of the Uniform distribution
Hi,

```
x = sp.symbols('x')
X = Uniform(x, 0, 1)
plot(cdf(X)(x),(x,-1,2),adaptive=False, num_of_points=200)
```
The code above displays the following plot:

![git_sympy_cdf_current](https://user-images.githubusercontent.com/33783067/34317931-443b956a-e7f5-11e7-8477-70134385fbc4.png)

It should rather look like this:

![git_sympy_cdf_right](https://user-images.githubusercontent.com/33783067/34317959-62cec74e-e7f6-11e7-9563-31face0a4efe.png)


In stats/crv_types.py, the cdf function is calculated from the pdf function (that cannot be plotted). I cannot tell exactly why it doesn't work, but the two following fixes might be a good starting point.

First, in stats/crv_types.py (line 2445 - 2449), change 

```
    def pdf(self, x):
        left, right = self.left, self.right
        return Piecewise(
            (S.One/(right - left), And(left <= x, x <= right)),
            (S.Zero, True))
```
to
```
    def pdf(self, x):
        left, right = self.left, self.right
        return (Piecewise((S.Zero, x <= left), (S.One / (right - left), x > left), (S.Zero, True)) 
                - Piecewise((S.Zero, x <= right), (S.One / (right - left), True)))
```

Second, in stats/crv_types.py (line 2451 - 2460), change 

```
    def compute_cdf(self, **kwargs):
        from sympy import Lambda, Min
        z = Dummy('z', real=True, finite=True)
        result = SingleContinuousDistribution.compute_cdf(self, **kwargs)(z)
        reps = {
            Min(z, self.right): z,
            Min(z, self.left, self.right): self.left,
            Min(z, self.left): self.left}
        result = result.subs(reps)
        return Lambda(z, result)
```

to

```
    def _cdf(self, x, ):
        return Piecewise((S.Zero, x < self.left), (S.One, x > self.right), 
                        ((x - self.right) / (self.left - self.right), True))
```

Discussion:

Patch:
diff --git a/sympy/stats/crv_types.py b/sympy/stats/crv_types.py
index 5aee41540b..e636d67940 100644
--- a/sympy/stats/crv_types.py
+++ b/sympy/stats/crv_types.py
@@ -2446,18 +2446,16 @@ def pdf(self, x):
         left, right = self.left, self.right
         return Piecewise(
             (S.One/(right - left), And(left <= x, x <= right)),
-            (S.Zero, True))
+            (S.Zero, True)
+        )
 
-    def compute_cdf(self, **kwargs):
-        from sympy import Lambda, Min
-        z = Dummy('z', real=True, finite=True)
-        result = SingleContinuousDistribution.compute_cdf(self, **kwargs)(z)
-        reps = {
-            Min(z, self.right): z,
-            Min(z, self.left, self.right): self.left,
-            Min(z, self.left): self.left}
-        result = result.subs(reps)
-        return Lambda(z, result)
+    def _cdf(self, x):
+        left, right = self.left, self.right
+        return Piecewise(
+            (S.Zero, x < left),
+            ((x - left)/(right - left), x <= right),
+            (S.One, True)
+        )
 
     def expectation(self, expr, var, **kwargs):
         from sympy import Max, Min


Test patch:
diff --git a/sympy/stats/tests/test_continuous_rv.py b/sympy/stats/tests/test_continuous_rv.py
index 6a9f4a57a2..edbcb74340 100644
--- a/sympy/stats/tests/test_continuous_rv.py
+++ b/sympy/stats/tests/test_continuous_rv.py
@@ -379,6 +379,7 @@ def test_lognormal():
     X = LogNormal('x', 0, 1)  # Mean 0, standard deviation 1
     assert density(X)(x) == sqrt(2)*exp(-log(x)**2/2)/(2*x*sqrt(pi))
 
+
 def test_maxwell():
     a = Symbol("a", positive=True)
 
@@ -444,18 +445,21 @@ def test_rayleigh():
     assert E(X) == sqrt(2)*sqrt(pi)*sigma/2
     assert variance(X) == -pi*sigma**2/2 + 2*sigma**2
 
+
 def test_shiftedgompertz():
     b = Symbol("b", positive=True)
     eta = Symbol("eta", positive=True)
     X = ShiftedGompertz("x", b, eta)
     assert density(X)(x) == b*(eta*(1 - exp(-b*x)) + 1)*exp(-b*x)*exp(-eta*exp(-b*x))
 
+
 def test_studentt():
     nu = Symbol("nu", positive=True)
 
     X = StudentT('x', nu)
     assert density(X)(x) == (1 + x**2/nu)**(-nu/2 - 1/2)/(sqrt(nu)*beta(1/2, nu/2))
 
+
 def test_trapezoidal():
     a = Symbol("a", real=True)
     b = Symbol("b", real=True)
@@ -495,6 +499,7 @@ def test_quadratic_u():
     assert density(X)(x) == (Piecewise((12*(x - a/2 - b/2)**2/(-a + b)**3,
                           And(x <= b, a <= x)), (0, True)))
 
+
 def test_uniform():
     l = Symbol('l', real=True, finite=True)
     w = Symbol('w', positive=True, finite=True)
@@ -503,12 +508,22 @@ def test_uniform():
     assert simplify(E(X)) == l + w/2
     assert simplify(variance(X)) == w**2/12
 
-
     # With numbers all is well
     X = Uniform('x', 3, 5)
     assert P(X < 3) == 0 and P(X > 5) == 0
     assert P(X < 4) == P(X > 4) == S.Half
 
+    z = Symbol('z')
+    p = density(X)(z)
+    assert p.subs(z, 3.7) == S(1)/2
+    assert p.subs(z, -1) == 0
+    assert p.subs(z, 6) == 0
+
+    c = cdf(X)
+    assert c(2) == 0 and c(3) == 0
+    assert c(S(7)/2) == S(1)/4
+    assert c(5) == 1 and c(6) == 1
+
 
 def test_uniform_P():
     """ This stopped working because SingleContinuousPSpace.compute_density no