Repository: sympy/sympy
Pull request: Src improve
<!-- BEGIN RELEASE NOTES -->
NO ENTRY
<!-- END RELEASE NOTES -->

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234". See
https://github.com/blog/1506-closing-issues-via-pull-requests . Please also
write a comment on that issue linking back to this pull request once it is
open. -->

Fixes #17274 

#### Brief description of what is fixed or changed

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->

<!-- END RELEASE NOTES -->


Problem statement:
Some confusing (Potential error) on source code (master branch) of sympy
Here is some code in sympy master branch which make me feel it is error. But I am not sure.

# 1

sympy/sets/handlers/add.py

```python3
@dispatch(Interval, Infinity)
def _set_sub(x, y):
    if self.start is S.NegativeInfinity:
        return Interval(-oo, oo)
    return FiniteSet(-oo)

@dispatch(Interval, NegativeInfinity)
def _set_sub(x, y):
    if self.start is S.NegativeInfinity:
        return Interval(-oo, oo)
    return FiniteSet(-oo)
```
What does `self` mean? or x?

# 2

sympy/physics/quantum/density.py

```python3
    def _print_operator_name_pretty(self, printer, *args):
        return prettyForm(unichr('\N{GREEK SMALL LETTER RHO}'))
```

`unichr` is a feature of python2. This module is not for compatibility. Hence I think there is something wrong.

# 3

sympy/core/numbers.py

```python3
    def _sage_(self):
        import sage.all as sage
        return sage.NaN
```

`sage` is not a dependency of sympy, and this module is obviously not for example or testing.
Should there be an `try` block?

# 4

sympy/functions/special/bessel.py

```python3
    elif method == "scipy":
        from scipy.optimize import newton
        try:
            from scipy.special import spherical_jn
            f = lambda x: spherical_jn(n, x)
        except ImportError:
            from scipy.special import sph_jn
            f = lambda x: sph_jn(n, x)[0][-1]
```

Since `scipy` is not a dependency of sympy. I don't know if it is necessary to use `try` block to import optional dependency. Or use `sympy.external.import_module`.

# 5

sympy/utilities/_compilation/compilation.py

```python3
                for path in glob.glob(k.pathname):
                    _per_file_kwargs[path] = v
```

glob is defined in module glob which is part of python standard library. But it need to be imported first.

Hints from issue discussion:
1. Not sure how the dispatch magic works, but I understand you concern. Worth looking more into.
 2. Agreed. This line is not covered in the tests, so it may very well fail in Python 3.
 3. The `_sage_` methods are only (supposed to be) called by Sage, so it should be OK. But clearly, it would be safer to use try and show a better error message. Quite a lot of instances though and I do not think there is much gain. Also, I think the error message should say that it cannot find sage and I think the only addition one could make is to tell the user to install Sage if they want to run this.
 4. Somehow similar to 3. I guess if the user decides to use the scipy switch without scipy installed, then, well, there will be an error. 
 5. Agreed. Code not covered, so may very well be an error.
Some more about 1. 

The code is not covered in tests and looking at the other methods clearly confirms your suspicions. Would be nice to add tests and correct this.

```
In [27]: a = SetExpr(Interval(0, 5))

In [28]: c = SetExpr(oo)

In [29]: a-c
Traceback (most recent call last):

  File "<ipython-input-29-6f0e715cd956>", line 1, in <module>
    a-c

  File "C:\Users\Oscar\sympy\sympy\core\decorators.py", line 91, in __sympifyit_wrapper
    return func(a, b)

  File "C:\Users\Oscar\sympy\sympy\core\decorators.py", line 129, in binary_op_wrapper
    return func(self, other)

  File "C:\Users\Oscar\sympy\sympy\sets\setexpr.py", line 52, in __sub__
    return _setexpr_apply_operation(set_sub, self, other)

  File "C:\Users\Oscar\sympy\sympy\sets\setexpr.py", line 95, in _setexpr_apply_operation
    out = op(x, y)

  File "C:\Users\Oscar\sympy\sympy\sets\sets.py", line 2085, in set_sub
    return _apply_operation(_set_sub, x, y, commutative=False)

  File "C:\Users\Oscar\sympy\sympy\sets\sets.py", line 2065, in _apply_operation
    out = op(x, y)

  File "C:\Users\Oscar\sympy\sympy\multipledispatch\dispatcher.py", line 198, in __call__
    return func(*args, **kwargs)

  File "C:\Users\Oscar\sympy\sympy\sets\handlers\add.py", line 60, in _set_sub
    if self.start is S.NegativeInfinity:

NameError: name 'self' is not defined
``` 
Oh, and here is the coverage information for 1.

https://codecov.io/gh/sympy/sympy/src/master/sympy/sets/handlers/add.py

If you (or someone else) decides to fix it, please add tests for the remaining cases as well.

The tests can go in the `test_Add_Mul` function (line 29) in `sets/test/test_setexpr.py`
> 3\. The `_sage_` methods are only (supposed to be) called by Sage, so it should be OK. But clearly, it would be safer to use try and show a better error message. Quite a lot of instances though and I do not think there is much gain. Also, I think the error message should say that it cannot find sage and I think the only addition one could make is to tell the user to install Sage if they want to run this.

I don't think there should be any change to error messages from `_sage_` methods. Users shouldn't use these methods.
@oscargus ,

What 
""" python3
In [27]: a = SetExpr(Interval(0, 5))

In [28]: c = SetExpr(oo)

In [29]: a-c
```
are supposed to return?

I am a little confused about the mathematical definition about interval minus infinity.
I would assume that the logic in the incorrect code is correct, so replacing self with x should be enough. Not sure about the mathematical aspects either.
For 2nd error point, I don't know it usage.
For 5th error point, it is File System IO intensive function, I don't know the convention of these kind of test.
The 5th one is my fault. The `_compilation` submodule is used internally by our tests (if you run `$ git grep _compilation` you'll see some files using it: `sympy/codegen/tests/test_*.py`).

I ported that code over from another library of mine, and I missed to import `glob`. We should add that import statement.

Usually test coverage is of course of high priority. But since we have the conventional leading underscore in `_compilation` to indicate that it is not public API, we need not stress too much about the test coverage (unless we want to promote this to public API and drop the underscore, but that module needs to see more testing on several platforms in that case).

Either way, nice catch!

Commit message: remove extra space near * and /

Patch to review:
diff --git a/sympy/core/cache.py b/sympy/core/cache.py
index a762272792d3..573f0cf17204 100644
--- a/sympy/core/cache.py
+++ b/sympy/core/cache.py
@@ -3,6 +3,7 @@
 
 from distutils.version import LooseVersion as V
 
+
 class _cache(list):
     """ List of cached functions """
 
@@ -34,6 +35,7 @@ def clear_cache(self):
                 else:
                     myfunc = myfunc.__wrapped__
 
+
 # global cache registry:
 CACHE = _cache()
 # make clear and print methods available
diff --git a/sympy/functions/elementary/trigonometric.py b/sympy/functions/elementary/trigonometric.py
index 5542c745cfe1..37bcbcbe9737 100644
--- a/sympy/functions/elementary/trigonometric.py
+++ b/sympy/functions/elementary/trigonometric.py
@@ -120,7 +120,7 @@ def _peeloff_pi(arg):
     else:
         return arg, S.Zero
 
-    m1 = (K % S.Half) * S.Pi
+    m1 = (K % S.Half)*S.Pi
     m2 = K*S.Pi - m1
     return arg - m2, m2
 
@@ -301,7 +301,7 @@ def eval(cls, arg):
 
         i_coeff = arg.as_coefficient(S.ImaginaryUnit)
         if i_coeff is not None:
-            return S.ImaginaryUnit * sinh(i_coeff)
+            return S.ImaginaryUnit*sinh(i_coeff)
 
         pi_coeff = _pi_coeff(arg)
         if pi_coeff is not None:
@@ -349,11 +349,11 @@ def eval(cls, arg):
 
         if isinstance(arg, atan):
             x = arg.args[0]
-            return x / sqrt(1 + x**2)
+            return x/sqrt(1 + x**2)
 
         if isinstance(arg, atan2):
             y, x = arg.args
-            return y / sqrt(x**2 + y**2)
+            return y/sqrt(x**2 + y**2)
 
         if isinstance(arg, acos):
             x = arg.args[0]
@@ -361,15 +361,15 @@ def eval(cls, arg):
 
         if isinstance(arg, acot):
             x = arg.args[0]
-            return 1 / (sqrt(1 + 1 / x**2) * x)
+            return 1/(sqrt(1 + 1/x**2)*x)
 
         if isinstance(arg, acsc):
             x = arg.args[0]
-            return 1 / x
+            return 1/x
 
         if isinstance(arg, asec):
             x = arg.args[0]
-            return sqrt(1 - 1 / x**2)
+            return sqrt(1 - 1/x**2)
 
     @staticmethod
     @cacheit
@@ -381,24 +381,24 @@ def taylor_term(n, x, *previous_terms):
 
             if len(previous_terms) > 2:
                 p = previous_terms[-2]
-                return -p * x**2 / (n*(n - 1))
+                return -p*x**2/(n*(n - 1))
             else:
-                return (-1)**(n//2) * x**(n)/factorial(n)
+                return (-1)**(n//2)*x**(n)/factorial(n)
 
     def _eval_rewrite_as_exp(self, arg, **kwargs):
         I = S.ImaginaryUnit
         if isinstance(arg, TrigonometricFunction) or isinstance(arg, HyperbolicFunction):
             arg = arg.func(arg.args[0]).rewrite(exp)
-        return (exp(arg*I) - exp(-arg*I)) / (2*I)
+        return (exp(arg*I) - exp(-arg*I))/(2*I)
 
     def _eval_rewrite_as_Pow(self, arg, **kwargs):
         if isinstance(arg, log):
             I = S.ImaginaryUnit
             x = arg.args[0]
-            return I*x**-I / 2 - I*x**I /2
+            return I*x**-I/2 - I*x**I /2
 
     def _eval_rewrite_as_cos(self, arg, **kwargs):
-        return cos(arg - S.Pi / 2, evaluate=False)
+        return cos(arg - S.Pi/2, evaluate=False)
 
     def _eval_rewrite_as_tan(self, arg, **kwargs):
         tan_half = tan(S.Half*arg)
@@ -421,7 +421,7 @@ def _eval_rewrite_as_csc(self, arg, **kwargs):
         return 1/csc(arg)
 
     def _eval_rewrite_as_sec(self, arg, **kwargs):
-        return 1 / sec(arg - S.Pi / 2, evaluate=False)
+        return 1/sec(arg - S.Pi/2, evaluate=False)
 
     def _eval_rewrite_as_sinc(self, arg, **kwargs):
         return arg*sinc(arg)
@@ -666,11 +666,11 @@ def eval(cls, arg):
 
         if isinstance(arg, atan):
             x = arg.args[0]
-            return 1 / sqrt(1 + x**2)
+            return 1/sqrt(1 + x**2)
 
         if isinstance(arg, atan2):
             y, x = arg.args
-            return x / sqrt(x**2 + y**2)
+            return x/sqrt(x**2 + y**2)
 
         if isinstance(arg, asin):
             x = arg.args[0]
@@ -678,15 +678,15 @@ def eval(cls, arg):
 
         if isinstance(arg, acot):
             x = arg.args[0]
-            return 1 / sqrt(1 + 1 / x**2)
+            return 1/sqrt(1 + 1/x**2)
 
         if isinstance(arg, acsc):
             x = arg.args[0]
-            return sqrt(1 - 1 / x**2)
+            return sqrt(1 - 1/x**2)
 
         if isinstance(arg, asec):
             x = arg.args[0]
-            return 1 / x
+            return 1/x
 
     @staticmethod
     @cacheit
@@ -698,7 +698,7 @@ def taylor_term(n, x, *previous_terms):
 
             if len(previous_terms) > 2:
                 p = previous_terms[-2]
-                return -p * x**2 / (n*(n - 1))
+                return -p*x**2/(n*(n - 1))
             else:
                 return (-1)**(n//2)*x**(n)/factorial(n)
 
@@ -706,7 +706,7 @@ def _eval_rewrite_as_exp(self, arg, **kwargs):
         I = S.ImaginaryUnit
         if isinstance(arg, TrigonometricFunction) or isinstance(arg, HyperbolicFunction):
             arg = arg.func(arg.args[0]).rewrite(exp)
-        return (exp(arg*I) + exp(-arg*I)) / 2
+        return (exp(arg*I) + exp(-arg*I))/2
 
     def _eval_rewrite_as_Pow(self, arg, **kwargs):
         if isinstance(arg, log):
@@ -715,7 +715,7 @@ def _eval_rewrite_as_Pow(self, arg, **kwargs):
             return x**I/2 + x**-I/2
 
     def _eval_rewrite_as_sin(self, arg, **kwargs):
-        return sin(arg + S.Pi / 2, evaluate=False)
+        return sin(arg + S.Pi/2, evaluate=False)
 
     def _eval_rewrite_as_tan(self, arg, **kwargs):
         tan_half = tan(S.Half*arg)**2
@@ -873,7 +873,7 @@ def _eval_rewrite_as_sec(self, arg, **kwargs):
         return 1/sec(arg)
 
     def _eval_rewrite_as_csc(self, arg, **kwargs):
-        return 1 / sec(arg).rewrite(csc)
+        return 1/sec(arg).rewrite(csc)
 
     def _eval_conjugate(self):
         return self.func(self.args[0].conjugate())
@@ -1012,7 +1012,7 @@ def eval(cls, arg):
 
         i_coeff = arg.as_coefficient(S.ImaginaryUnit)
         if i_coeff is not None:
-            return S.ImaginaryUnit * tanh(i_coeff)
+            return S.ImaginaryUnit*tanh(i_coeff)
 
         pi_coeff = _pi_coeff(arg, 2)
         if pi_coeff is not None:
@@ -1036,7 +1036,7 @@ def eval(cls, arg):
                     4: sqrt(5 + 2*sqrt(5))
                     }
                 if q == 5 or q == 10:
-                    n = 10 * p / q
+                    n = 10*p/q
                     if n > 5:
                         n = 10 - n
                         return -table10[n]
@@ -1098,23 +1098,23 @@ def eval(cls, arg):
 
         if isinstance(arg, asin):
             x = arg.args[0]
-            return x / sqrt(1 - x**2)
+            return x/sqrt(1 - x**2)
 
         if isinstance(arg, acos):
             x = arg.args[0]
-            return sqrt(1 - x**2) / x
+            return sqrt(1 - x**2)/x
 
         if isinstance(arg, acot):
             x = arg.args[0]
-            return 1 / x
+            return 1/x
 
         if isinstance(arg, acsc):
             x = arg.args[0]
-            return 1 / (sqrt(1 - 1 / x**2) * x)
+            return 1/(sqrt(1 - 1/x**2)*x)
 
         if isinstance(arg, asec):
             x = arg.args[0]
-            return sqrt(1 - 1 / x**2) * x
+            return sqrt(1 - 1/x**2)*x
 
     @staticmethod
     @cacheit
@@ -1130,7 +1130,7 @@ def taylor_term(n, x, *previous_terms):
             B = bernoulli(n + 1)
             F = factorial(n + 1)
 
-            return (-1)**a * b*(b - 1) * B/F * x**n
+            return (-1)**a*b*(b - 1)*B/F*x**n
 
     def _eval_nseries(self, x, n, logx):
         i = self.args[0].limit(x, 0)*2/S.Pi
@@ -1195,7 +1195,7 @@ def _eval_rewrite_as_sin(self, x, **kwargs):
         return 2*sin(x)**2/sin(2*x)
 
     def _eval_rewrite_as_cos(self, x, **kwargs):
-        return cos(x - S.Pi / 2, evaluate=False) / cos(x)
+        return cos(x - S.Pi/2, evaluate=False)/cos(x)
 
     def _eval_rewrite_as_sincos(self, arg, **kwargs):
         return sin(arg)/cos(arg)
@@ -1206,12 +1206,12 @@ def _eval_rewrite_as_cot(self, arg, **kwargs):
     def _eval_rewrite_as_sec(self, arg, **kwargs):
         sin_in_sec_form = sin(arg).rewrite(sec)
         cos_in_sec_form = cos(arg).rewrite(sec)
-        return sin_in_sec_form / cos_in_sec_form
+        return sin_in_sec_form/cos_in_sec_form
 
     def _eval_rewrite_as_csc(self, arg, **kwargs):
         sin_in_csc_form = sin(arg).rewrite(csc)
         cos_in_csc_form = cos(arg).rewrite(csc)
-        return sin_in_csc_form / cos_in_csc_form
+        return sin_in_csc_form/cos_in_csc_form
 
     def _eval_rewrite_as_pow(self, arg, **kwargs):
         y = self.rewrite(cos).rewrite(pow)
@@ -1240,13 +1240,13 @@ def _eval_is_extended_real(self):
 
     def _eval_is_real(self):
         arg = self.args[0]
-        if arg.is_real and (arg / pi - S.Half).is_integer is False:
+        if arg.is_real and (arg/pi - S.Half).is_integer is False:
             return True
 
     def _eval_is_finite(self):
         arg = self.args[0]
 
-        if arg.is_real and (arg / pi - S.Half).is_integer is False:
+        if arg.is_real and (arg/pi - S.Half).is_integer is False:
             return True
 
         if arg.is_imaginary:
@@ -1260,7 +1260,7 @@ def _eval_is_zero(self):
     def _eval_is_complex(self):
         arg = self.args[0]
 
-        if arg.is_real and (arg / pi - S.Half).is_integer is False:
+        if arg.is_real and (arg/pi - S.Half).is_integer is False:
             return True
 
 
@@ -1337,7 +1337,7 @@ def eval(cls, arg):
 
         i_coeff = arg.as_coefficient(S.ImaginaryUnit)
         if i_coeff is not None:
-            return -S.ImaginaryUnit * coth(i_coeff)
+            return -S.ImaginaryUnit*coth(i_coeff)
 
         pi_coeff = _pi_coeff(arg, 2)
         if pi_coeff is not None:
@@ -1384,7 +1384,7 @@ def eval(cls, arg):
                         and not isinstance(sresult, cos):
                     if sresult == 0:
                         return S.ComplexInfinity
-                    return cresult / sresult
+                    return cresult/sresult
                 if narg != arg:
                     return cls(narg)
 
@@ -1405,7 +1405,7 @@ def eval(cls, arg):
 
         if isinstance(arg, atan):
             x = arg.args[0]
-            return 1 / x
+            return 1/x
 
         if isinstance(arg, atan2):
             y, x = arg.args
@@ -1413,26 +1413,26 @@ def eval(cls, arg):
 
         if isinstance(arg, asin):
             x = arg.args[0]
-            return sqrt(1 - x**2) / x
+            return sqrt(1 - x**2)/x
 
         if isinstance(arg, acos):
             x = arg.args[0]
-            return x / sqrt(1 - x**2)
+            return x/sqrt(1 - x**2)
 
         if isinstance(arg, acsc):
             x = arg.args[0]
-            return sqrt(1 - 1 / x**2) * x
+            return sqrt(1 - 1/x**2)*x
 
         if isinstance(arg, asec):
             x = arg.args[0]
-            return 1 / (sqrt(1 - 1 / x**2) * x)
+            return 1/(sqrt(1 - 1/x**2)*x)
 
     @staticmethod
     @cacheit
     def taylor_term(n, x, *previous_terms):
         from sympy import bernoulli
         if n == 0:
-            return 1 / sympify(x)
+            return 1/sympify(x)
         elif n < 0 or n % 2 == 0:
             return S.Zero
         else:
@@ -1441,7 +1441,7 @@ def taylor_term(n, x, *previous_terms):
             B = bernoulli(n + 1)
             F = factorial(n + 1)
 
-            return (-1)**((n + 1)//2) * 2**(n + 1) * B/F * x**n
+            return (-1)**((n + 1)//2)*2**(n + 1)*B/F*x**n
 
     def _eval_nseries(self, x, n, logx):
         i = self.args[0].limit(x, 0)/S.Pi
@@ -1477,7 +1477,7 @@ def _eval_rewrite_as_sin(self, x, **kwargs):
         return sin(2*x)/(2*(sin(x)**2))
 
     def _eval_rewrite_as_cos(self, x, **kwargs):
-        return cos(x) / cos(x - S.Pi / 2, evaluate=False)
+        return cos(x)/cos(x - S.Pi/2, evaluate=False)
 
     def _eval_rewrite_as_sincos(self, arg, **kwargs):
         return cos(arg)/sin(arg)
@@ -1488,12 +1488,12 @@ def _eval_rewrite_as_tan(self, arg, **kwargs):
     def _eval_rewrite_as_sec(self, arg, **kwargs):
         cos_in_sec_form = cos(arg).rewrite(sec)
         sin_in_sec_form = sin(arg).rewrite(sec)
-        return cos_in_sec_form / sin_in_sec_form
+        return cos_in_sec_form/sin_in_sec_form
 
     def _eval_rewrite_as_csc(self, arg, **kwargs):
         cos_in_csc_form = cos(arg).rewrite(csc)
         sin_in_csc_form = sin(arg).rewrite(csc)
-        return cos_in_csc_form / sin_in_csc_form
+        return cos_in_csc_form/sin_in_csc_form
 
     def _eval_rewrite_as_pow(self, arg, **kwargs):
         y = self.rewrite(cos).rewrite(pow)
@@ -1561,7 +1561,7 @@ def _eval_is_real(self):
 
     def _eval_is_complex(self):
         arg = self.args[0]
-        if arg.is_real and (arg / pi).is_integer is False:
+        if arg.is_real and (arg/pi).is_integer is False:
             return True
 
     def _eval_subs(self, old, new):
@@ -1742,13 +1742,13 @@ def _eval_rewrite_as_sincos(self, arg, **kwargs):
         return sin(arg)/(cos(arg)*sin(arg))
 
     def _eval_rewrite_as_sin(self, arg, **kwargs):
-        return (1 / cos(arg).rewrite(sin))
+        return (1/cos(arg).rewrite(sin))
 
     def _eval_rewrite_as_tan(self, arg, **kwargs):
-        return (1 / cos(arg).rewrite(tan))
+        return (1/cos(arg).rewrite(tan))
 
     def _eval_rewrite_as_csc(self, arg, **kwargs):
-        return csc(pi / 2 - arg, evaluate=False)
+        return csc(pi/2 - arg, evaluate=False)
 
     def fdiff(self, argindex=1):
         if argindex == 1:
@@ -1759,7 +1759,7 @@ def fdiff(self, argindex=1):
     def _eval_is_complex(self):
         arg = self.args[0]
 
-        if arg.is_complex and (arg / pi - S.Half).is_integer is False:
+        if arg.is_complex and (arg/pi - S.Half).is_integer is False:
             return True
 
     @staticmethod
@@ -1829,13 +1829,13 @@ def _eval_rewrite_as_cot(self, arg, **kwargs):
         return (1 + cot_half**2)/(2*cot_half)
 
     def _eval_rewrite_as_cos(self, arg, **kwargs):
-        return 1 / sin(arg).rewrite(cos)
+        return 1/sin(arg).rewrite(cos)
 
     def _eval_rewrite_as_sec(self, arg, **kwargs):
-        return sec(pi / 2 - arg, evaluate=False)
+        return sec(pi/2 - arg, evaluate=False)
 
     def _eval_rewrite_as_tan(self, arg, **kwargs):
-        return (1 / sin(arg).rewrite(tan))
+        return (1/sin(arg).rewrite(tan))
 
     def fdiff(self, argindex=1):
         if argindex == 1:
@@ -1845,7 +1845,7 @@ def fdiff(self, argindex=1):
 
     def _eval_is_complex(self):
         arg = self.args[0]
-        if arg.is_real and (arg / pi).is_integer is False:
+        if arg.is_real and (arg/pi).is_integer is False:
             return True
 
     @staticmethod
@@ -1941,7 +1941,7 @@ def eval(cls, arg):
                 if fuzzy_not(arg.is_zero):
                     return S.Zero
             elif (2*pi_coeff).is_integer:
-                return S.NegativeOne**(pi_coeff - S.Half) / arg
+                return S.NegativeOne**(pi_coeff - S.Half)/arg
 
     def _eval_nseries(self, x, n, logx):
         x = self.args[0]
@@ -2101,15 +2101,15 @@ def eval(cls, arg):
             if arg is S.NaN:
                 return S.NaN
             elif arg is S.Infinity:
-                return S.NegativeInfinity * S.ImaginaryUnit
+                return S.NegativeInfinity*S.ImaginaryUnit
             elif arg is S.NegativeInfinity:
-                return S.Infinity * S.ImaginaryUnit
+                return S.Infinity*S.ImaginaryUnit
             elif arg.is_zero:
                 return S.Zero
             elif arg is S.One:
-                return S.Pi / 2
+                return S.Pi/2
             elif arg is S.NegativeOne:
-                return -S.Pi / 2
+                return -S.Pi/2
 
         if arg is S.ComplexInfinity:
             return S.ComplexInfinity
@@ -2124,7 +2124,7 @@ def eval(cls, arg):
 
         i_coeff = arg.as_coefficient(S.ImaginaryUnit)
         if i_coeff is not None:
-            return S.ImaginaryUnit * asinh(i_coeff)
+            return S.ImaginaryUnit*asinh(i_coeff)
 
         if arg.is_zero:
             return S.Zero
@@ -2158,12 +2158,12 @@ def taylor_term(n, x, *previous_terms):
             x = sympify(x)
             if len(previous_terms) >= 2 and n > 2:
                 p = previous_terms[-2]
-                return p * (n - 2)**2/(n*(n - 1)) * x**2
+                return p*(n - 2)**2/(n*(n - 1))*x**2
             else:
                 k = (n - 1) // 2
                 R = RisingFactorial(S.Half, k)
                 F = factorial(k)
-                return R / F * x**n / n
+                return R/F*x**n/n
 
     def _eval_as_leading_term(self, x):
         from sympy import Order
@@ -2267,11 +2267,11 @@ def eval(cls, arg):
             if arg is S.NaN:
                 return S.NaN
             elif arg is S.Infinity:
-                return S.Infinity * S.ImaginaryUnit
+                return S.Infinity*S.ImaginaryUnit
             elif arg is S.NegativeInfinity:
-                return S.NegativeInfinity * S.ImaginaryUnit
+                return S.NegativeInfinity*S.ImaginaryUnit
             elif arg.is_zero:
-                return S.Pi / 2
+                return S.Pi/2
             elif arg is S.One:
                 return S.Zero
             elif arg is S.NegativeOne:
@@ -2309,19 +2309,19 @@ def eval(cls, arg):
     @cacheit
     def taylor_term(n, x, *previous_terms):
         if n == 0:
-            return S.Pi / 2
+            return S.Pi/2
         elif n < 0 or n % 2 == 0:
             return S.Zero
         else:
             x = sympify(x)
             if len(previous_terms) >= 2 and n > 2:
                 p = previous_terms[-2]
-                return p * (n - 2)**2/(n*(n - 1)) * x**2
+                return p*(n - 2)**2/(n*(n - 1))*x**2
             else:
                 k = (n - 1) // 2
                 R = RisingFactorial(S.Half, k)
                 F = factorial(k)
-                return -R / F * x**n / n
+                return -R/F*x**n/n
 
     def _eval_as_leading_term(self, x):
         from sympy import Order
@@ -2343,8 +2343,8 @@ def _eval_nseries(self, x, n, logx):
         return self._eval_rewrite_as_log(self.args[0])._eval_nseries(x, n, logx)
 
     def _eval_rewrite_as_log(self, x, **kwargs):
-        return S.Pi/2 + S.ImaginaryUnit * \
-            log(S.ImaginaryUnit * x + sqrt(1 - x**2))
+        return S.Pi/2 + S.ImaginaryUnit*\
+            log(S.ImaginaryUnit*x + sqrt(1 - x**2))
 
     def _eval_rewrite_as_asin(self, x, **kwargs):
         return S.Pi/2 - asin(x)
@@ -2447,15 +2447,15 @@ def eval(cls, arg):
             if arg is S.NaN:
                 return S.NaN
             elif arg is S.Infinity:
-                return S.Pi / 2
+                return S.Pi/2
             elif arg is S.NegativeInfinity:
-                return -S.Pi / 2
+                return -S.Pi/2
             elif arg.is_zero:
                 return S.Zero
             elif arg is S.One:
-                return S.Pi / 4
+                return S.Pi/4
             elif arg is S.NegativeOne:
-                return -S.Pi / 4
+                return -S.Pi/4
 
         if arg is S.ComplexInfinity:
             from sympy.calculus.util import AccumBounds
@@ -2471,7 +2471,7 @@ def eval(cls, arg):
 
         i_coeff = arg.as_coefficient(S.ImaginaryUnit)
         if i_coeff is not None:
-            return S.ImaginaryUnit * atanh(i_coeff)
+            return S.ImaginaryUnit*atanh(i_coeff)
 
         if arg.is_zero:
             return S.Zero
@@ -2500,7 +2500,7 @@ def taylor_term(n, x, *previous_terms):
             return S.Zero
         else:
             x = sympify(x)
-            return (-1)**((n - 1)//2) * x**n / n
+            return (-1)**((n - 1)//2)*x**n/n
 
     def _eval_as_leading_term(self, x):
         from sympy import Order
@@ -2512,8 +2512,8 @@ def _eval_as_leading_term(self, x):
             return self.func(arg)
 
     def _eval_rewrite_as_log(self, x, **kwargs):
-        return S.ImaginaryUnit/2 * (log(S.One - S.ImaginaryUnit * x)
-            - log(S.One + S.ImaginaryUnit * x))
+        return S.ImaginaryUnit/2*(log(S.One - S.ImaginaryUnit*x)
+            - log(S.One + S.ImaginaryUnit*x))
 
     def _eval_aseries(self, n, args0, x, logx):
         if args0[0] is S.Infinity:
@@ -2590,7 +2590,7 @@ class acot(InverseTrigonometricFunction):
 
     def fdiff(self, argindex=1):
         if argindex == 1:
-            return -1 / (1 + self.args[0]**2)
+            return -1/(1 + self.args[0]**2)
         else:
             raise ArgumentIndexError(self, argindex)
 
@@ -2623,9 +2623,9 @@ def eval(cls, arg):
             elif arg.is_zero:
                 return S.Pi/ 2
             elif arg is S.One:
-                return S.Pi / 4
+                return S.Pi/4
             elif arg is S.NegativeOne:
-                return -S.Pi / 4
+                return -S.Pi/4
 
         if arg is S.ComplexInfinity:
             return S.Zero
@@ -2643,7 +2643,7 @@ def eval(cls, arg):
 
         i_coeff = arg.as_coefficient(S.ImaginaryUnit)
         if i_coeff is not None:
-            return -S.ImaginaryUnit * acoth(i_coeff)
+            return -S.ImaginaryUnit*acoth(i_coeff)
 
         if arg.is_zero:
             return S.Pi*S.Half
@@ -2668,12 +2668,12 @@ def eval(cls, arg):
     @cacheit
     def taylor_term(n, x, *previous_terms):
         if n == 0:
-            return S.Pi / 2  # FIX THIS
+            return S.Pi/2  # FIX THIS
         elif n < 0 or n % 2 == 0:
             return S.Zero
         else:
             x = sympify(x)
-            return (-1)**((n + 1)//2) * x**n / n
+            return (-1)**((n + 1)//2)*x**n/n
 
     def _eval_as_leading_term(self, x):
         from sympy import Order
@@ -2693,7 +2693,7 @@ def _eval_aseries(self, n, args0, x, logx):
             return super(atan, self)._eval_aseries(n, args0, x, logx)
 
     def _eval_rewrite_as_log(self, x, **kwargs):
-        return S.ImaginaryUnit/2 * (log(1 - S.ImaginaryUnit/x)
+        return S.ImaginaryUnit/2*(log(1 - S.ImaginaryUnit/x)
             - log(1 + S.ImaginaryUnit/x))
 
     def inverse(self, argindex=1):
@@ -3030,7 +3030,7 @@ class atan2(InverseTrigonometricFunction):
     `\operatorname{atan}` function for the point `(x, y) = (-1, 1)`
 
     >>> from sympy import atan, S
-    >>> atan(S(1) / -1)
+    >>> atan(S(1)/-1)
     -pi/4
     >>> atan2(1, -1)
     3*pi/4
@@ -3092,12 +3092,12 @@ def eval(cls, y, x):
 
         if x.is_extended_real and y.is_extended_real:
             if x.is_positive:
-                return atan(y / x)
+                return atan(y/x)
             elif x.is_negative:
                 if y.is_negative:
-                    return atan(y / x) - S.Pi
+                    return atan(y/x) - S.Pi
                 elif y.is_nonnegative:
-                    return atan(y / x) + S.Pi
+                    return atan(y/x) + S.Pi
             elif x.is_zero:
                 if y.is_positive:
                     return S.Pi/2
@@ -3107,7 +3107,7 @@ def eval(cls, y, x):
                     return S.NaN
         if y.is_zero:
             if x.is_extended_nonzero:
-                return S.Pi * (S.One - Heaviside(x))
+                return S.Pi*(S.One - Heaviside(x))
             if x.is_number:
                 return Piecewise((S.Pi, re(x) < 0),
                                  (0, Ne(x, 0)),
@@ -3117,7 +3117,7 @@ def eval(cls, y, x):
                 (x + S.ImaginaryUnit*y)/sqrt(x**2 + y**2))
 
     def _eval_rewrite_as_log(self, y, x, **kwargs):
-        return -S.ImaginaryUnit*log((x + S.ImaginaryUnit*y) / sqrt(x**2 + y**2))
+        return -S.ImaginaryUnit*log((x + S.ImaginaryUnit*y)/sqrt(x**2 + y**2))
 
     def _eval_rewrite_as_atan(self, y, x, **kwargs):
         from sympy import re
diff --git a/sympy/matrices/expressions/tests/test_permutation.py b/sympy/matrices/expressions/tests/test_permutation.py
index 5d50327f6e0f..07c9858c9972 100644
--- a/sympy/matrices/expressions/tests/test_permutation.py
+++ b/sympy/matrices/expressions/tests/test_permutation.py
@@ -16,20 +16,20 @@ def test_PermutationMatrix_basic():
     assert unchanged(PermutationMatrix, p)
     raises(ValueError, lambda: PermutationMatrix((0, 1, 2)))
     assert PermutationMatrix(p).as_explicit() == Matrix([[0, 1], [1, 0]])
-    assert isinstance(PermutationMatrix(p) * MatrixSymbol('A', 2, 2), MatMul)
+    assert isinstance(PermutationMatrix(p)*MatrixSymbol('A', 2, 2), MatMul)
 
 
 def test_PermutationMatrix_matmul():
     p = Permutation([1, 2, 0])
     P = PermutationMatrix(p)
     M = Matrix([[0, 1, 2], [3, 4, 5], [6, 7, 8]])
-    assert (P * M).as_explicit() == P.as_explicit() * M
-    assert (M * P).as_explicit() == M * P.as_explicit()
+    assert (P*M).as_explicit() == P.as_explicit()*M
+    assert (M*P).as_explicit() == M*P.as_explicit()
 
     P1 = PermutationMatrix(Permutation([1, 2, 0]))
     P2 = PermutationMatrix(Permutation([2, 1, 0]))
     P3 = PermutationMatrix(Permutation([1, 0, 2]))
-    assert P1 * P2 == P3
+    assert P1*P2 == P3
 
 
 def test_PermutationMatrix_matpow():
diff --git a/sympy/physics/continuum_mechanics/beam.py b/sympy/physics/continuum_mechanics/beam.py
index 359aacba9c73..ee4f71ec7c0c 100644
--- a/sympy/physics/continuum_mechanics/beam.py
+++ b/sympy/physics/continuum_mechanics/beam.py
@@ -443,10 +443,10 @@ def apply_load(self, value, start, order, end=None):
             # NOTE : A Taylor series can be used to define the summation of
             # singularity functions that subtract from the load past the end
             # point such that it evaluates to zero past 'end'.
-            f = value * x**order
+            f = value*x**order
             for i in range(0, order + 1):
                 self._load -= (f.diff(x, i).subs(x, end - start) *
-                               SingularityFunction(x, end, i) / factorial(i))
+                               SingularityFunction(x, end, i)/factorial(i))
 
     def remove_load(self, value, start, order, end=None):
         """
@@ -519,10 +519,10 @@ def remove_load(self, value, start, order, end=None):
             # NOTE : A Taylor series can be used to define the summation of
             # singularity functions that subtract from the load past the end
             # point such that it evaluates to zero past 'end'.
-            f = value * x**order
+            f = value*x**order
             for i in range(0, order + 1):
                 self._load += (f.diff(x, i).subs(x, end - start) *
-                               SingularityFunction(x, end, i) / factorial(i))
+                               SingularityFunction(x, end, i)/factorial(i))
 
     @property
     def load(self):
@@ -1643,7 +1643,7 @@ def _draw_load(self, pictorial, length, l):
                         f2 = 10**(1-order)*x**order if order > 0 else length/2*x**order
                         for i in range(0, order + 1):
                             scaled_load -= (f2.diff(x, i).subs(x, end - start)*
-                                           SingularityFunction(x, end, i) / factorial(i))
+                                           SingularityFunction(x, end, i)/factorial(i))
 
         # `fill` will be assigned only when higher order loads are present
         if higher_order:
diff --git a/sympy/physics/continuum_mechanics/tests/test_beam.py b/sympy/physics/continuum_mechanics/tests/test_beam.py
index 5dae1ae66bba..99cbe19edf3b 100644
--- a/sympy/physics/continuum_mechanics/tests/test_beam.py
+++ b/sympy/physics/continuum_mechanics/tests/test_beam.py
@@ -569,11 +569,11 @@ def test_parabolic_loads():
 
     beam.solve_for_reaction_loads(R, M)
 
-    assert beam.reaction_loads[R] == -L**3 / 3
+    assert beam.reaction_loads[R] == -L**3/3
 
     # cantilever beam fixed at x=0 and parabolic distributed loading across
     # first half of beam
-    beam = Beam(2 * L, E, I)
+    beam = Beam(2*L, E, I)
 
     beam.bc_deflection.append((0, 0))
     beam.bc_slope.append((0, 0))
@@ -586,27 +586,27 @@ def test_parabolic_loads():
     beam.solve_for_reaction_loads(R, M)
 
     # result should be the same as the prior example
-    assert beam.reaction_loads[R] == -L**3 / 3
+    assert beam.reaction_loads[R] == -L**3/3
 
     # check constant load
-    beam = Beam(2 * L, E, I)
+    beam = Beam(2*L, E, I)
     beam.apply_load(P, 0, 0, end=L)
     loading = beam.load.xreplace({L: 10, E: 20, I: 30, P: 40})
     assert loading.xreplace({x: 5}) == 40
     assert loading.xreplace({x: 15}) == 0
 
     # check ramp load
-    beam = Beam(2 * L, E, I)
+    beam = Beam(2*L, E, I)
     beam.apply_load(P, 0, 1, end=L)
     assert beam.load == (P*SingularityFunction(x, 0, 1) -
                          P*SingularityFunction(x, L, 1) -
                          P*L*SingularityFunction(x, L, 0))
 
     # check higher order load: x**8 load from x=0 to x=L
-    beam = Beam(2 * L, E, I)
+    beam = Beam(2*L, E, I)
     beam.apply_load(P, 0, 8, end=L)
     loading = beam.load.xreplace({L: 10, E: 20, I: 30, P: 40})
-    assert loading.xreplace({x: 5}) == 40 * 5**8
+    assert loading.xreplace({x: 5}) == 40*5**8
     assert loading.xreplace({x: 15}) == 0
 
 
diff --git a/sympy/physics/mechanics/tests/test_lagrange.py b/sympy/physics/mechanics/tests/test_lagrange.py
index 038c23fea5fa..a33a19a11ef0 100644
--- a/sympy/physics/mechanics/tests/test_lagrange.py
+++ b/sympy/physics/mechanics/tests/test_lagrange.py
@@ -28,7 +28,7 @@ def test_disc_on_an_incline_plane():
     # is created. Finally, we create the disc.
     Do = Point('Do')
     Do.set_vel(N, yd * A.x)
-    I = m * R**2 / 2 * B.z | B.z
+    I = m * R**2/2 * B.z | B.z
     D = RigidBody('D', Do, B, m, (I, Do))
 
     # To construct the Lagrangian, 'L', of the disc, we determine its kinetic
@@ -203,7 +203,7 @@ def test_rolling_disc():
     Dmc.v2pt_theory(C, N, R)
 
     # Forming the inertia dyadic.
-    I = inertia(L, m / 4 * r**2, m / 2 * r**2, m / 4 * r**2)
+    I = inertia(L, m/4 * r**2, m/2 * r**2, m/4 * r**2)
     BodyD = RigidBody('BodyD', Dmc, R, m, (I, Dmc))
 
     # Finally we form the equations of motion, using the same steps we did
diff --git a/sympy/physics/mechanics/tests/test_system.py b/sympy/physics/mechanics/tests/test_system.py
index e0cd2941dde8..6f578266f05c 100644
--- a/sympy/physics/mechanics/tests/test_system.py
+++ b/sympy/physics/mechanics/tests/test_system.py
@@ -38,7 +38,7 @@
 comb_explicit_rhs = comb_implicit_mat.LUsolve(comb_implicit_rhs)
 
 # Set up a body and load to pass into the system
-theta = atan(x / y)
+theta = atan(x/y)
 N = ReferenceFrame('N')
 A = N.orientnew('A', 'Axis', [theta, N.z])
 O = Point('O')
diff --git a/sympy/physics/quantum/cg.py b/sympy/physics/quantum/cg.py
index 6b33fce5233c..f985d7fa31a8 100644
--- a/sympy/physics/quantum/cg.py
+++ b/sympy/physics/quantum/cg.py
@@ -106,7 +106,7 @@ def _pretty(self, printer, *args):
             (printer._print(self.j3), printer._print(self.m3)))
         hsep = 2
         vsep = 1
-        maxw = [-1] * 3
+        maxw = [-1]*3
         for j in range(3):
             maxw[j] = max([ m[j][i].width() for i in range(2) ])
         D = None
@@ -204,9 +204,9 @@ def _pretty(self, printer, *args):
         top = prettyForm(*top.left(' '))
 
         if not pad == bot.width():
-            bot = prettyForm(*bot.right(' ' * (pad - bot.width())))
+            bot = prettyForm(*bot.right(' '*(pad - bot.width())))
         if not pad == top.width():
-            top = prettyForm(*top.right(' ' * (pad - top.width())))
+            top = prettyForm(*top.right(' '*(pad - top.width())))
         s = stringPict('C' + ' '*pad)
         s = prettyForm(*s.below(bot))
         s = prettyForm(*s.above(top))
@@ -266,7 +266,7 @@ def _pretty(self, printer, *args):
             (printer._print(self.j12), printer._print(self.j23)))
         hsep = 2
         vsep = 1
-        maxw = [-1] * 3
+        maxw = [-1]*3
         for j in range(3):
             maxw[j] = max([ m[j][i].width() for i in range(2) ])
         D = None
@@ -370,7 +370,7 @@ def _pretty(self, printer, *args):
             (printer._print(self.j12), printer._print(self.j34), printer._print(self.j)))
         hsep = 2
         vsep = 1
-        maxw = [-1] * 3
+        maxw = [-1]*3
         for j in range(3):
             maxw[j] = max([ m[j][i].width() for i in range(3) ])
         D = None
@@ -615,7 +615,7 @@ def _check_cg_simp(expr, simp, sign, lt, term_list, variables, dep_variables, bu
             i += 1
             continue
         sub_dep = [(x, sub_1[x]) for x in dep_variables]
-        cg_index = [None] * build_index_expr.subs(sub_1)
+        cg_index = [None]*build_index_expr.subs(sub_1)
         for j in range(i, len(term_list)):
             sub_2 = _check_cg(term_list[j], expr.subs(sub_dep), len(variables) - len(dep_variables), sign=(sign.subs(sub_1), sign.subs(sub_dep)))
             if sub_2 is None:
@@ -631,8 +631,8 @@ def _check_cg_simp(expr, simp, sign, lt, term_list, variables, dep_variables, bu
             [ term_list.pop(j) for j in indices ]
             for term in cg_index:
                 if abs(term[2]) > min_lt:
-                    term_list.append( (term[2] - min_lt*term[3]) * term[1] )
-            other_part += min_lt * (sign*simp).subs(sub_1)
+                    term_list.append( (term[2] - min_lt*term[3])*term[1] )
+            other_part += min_lt*(sign*simp).subs(sub_1)
         else:
             i += 1
     return term_list, other_part
diff --git a/sympy/physics/quantum/density.py b/sympy/physics/quantum/density.py
index f051d8c15fb6..496d9c3a67b1 100644
--- a/sympy/physics/quantum/density.py
+++ b/sympy/physics/quantum/density.py
@@ -35,7 +35,6 @@ class Density(HermitianOperator):
     'Density'((|0>, 0.5),(|1>, 0.5))
 
     """
-
     @classmethod
     def _eval_args(cls, args):
         # call this to qsympify the args
@@ -43,8 +42,7 @@ def _eval_args(cls, args):
 
         for arg in args:
             # Check if arg is a tuple
-            if not (isinstance(arg, Tuple) and
-                    len(arg) == 2):
+            if not (isinstance(arg, Tuple) and len(arg) == 2):
                 raise ValueError("Each argument should be of form [state,prob]"
                                  " or ( state, prob )")
 
@@ -166,11 +164,10 @@ def doit(self, **hints):
             state = state.expand()  # needed to break up (a+b)*c
             if (isinstance(state, Add)):
                 for arg in product(state.args, repeat=2):
-                    terms.append(prob *
-                                 self._generate_outer_prod(arg[0], arg[1]))
+                    terms.append(prob*self._generate_outer_prod(arg[0],
+                                                                arg[1]))
             else:
-                terms.append(prob *
-                             self._generate_outer_prod(state, state))
+                terms.append(prob*self._generate_outer_prod(state, state))
 
         return Add(*terms)
 
@@ -178,21 +175,20 @@ def _generate_outer_prod(self, arg1, arg2):
         c_part1, nc_part1 = arg1.args_cnc()
         c_part2, nc_part2 = arg2.args_cnc()
 
-        if ( len(nc_part1) == 0 or
-             len(nc_part2) == 0 ):
+        if (len(nc_part1) == 0 or len(nc_part2) == 0):
             raise ValueError('Atleast one-pair of'
                              ' Non-commutative instance required'
                              ' for outer product.')
 
         # Muls of Tensor Products should be expanded
         # before this function is called
-        if (isinstance(nc_part1[0], TensorProduct) and
-                len(nc_part1) == 1 and len(nc_part2) == 1):
-            op = tensor_product_simp(nc_part1[0] * Dagger(nc_part2[0]))
+        if (isinstance(nc_part1[0], TensorProduct) and len(nc_part1) == 1
+                and len(nc_part2) == 1):
+            op = tensor_product_simp(nc_part1[0]*Dagger(nc_part2[0]))
         else:
-            op = Mul(*nc_part1) * Dagger(Mul(*nc_part2))
+            op = Mul(*nc_part1)*Dagger(Mul(*nc_part2))
 
-        return Mul(*c_part1)*Mul(*c_part2)*op
+        return Mul(*c_part1)*Mul(*c_part2) * op
 
     def _represent(self, **options):
         return represent(self.doit(), **options)
@@ -285,12 +281,12 @@ def fidelity(state1, state2):
     >>> up = JzKet(S(1)/2,S(1)/2)
     >>> down = JzKet(S(1)/2,-S(1)/2)
     >>> amp = 1/sqrt(2)
-    >>> updown = (amp * up) + (amp * down)
+    >>> updown = (amp*up) + (amp*down)
     >>>
     >>> # represent turns Kets into matrices
-    >>> up_dm = represent(up * Dagger(up))
-    >>> down_dm = represent(down * Dagger(down))
-    >>> updown_dm = represent(updown * Dagger(updown))
+    >>> up_dm = represent(up*Dagger(up))
+    >>> down_dm = represent(down*Dagger(down))
+    >>> updown_dm = represent(updown*Dagger(updown))
     >>>
     >>> fidelity(up_dm, up_dm)
     1
@@ -308,15 +304,14 @@ def fidelity(state1, state2):
     state1 = represent(state1) if isinstance(state1, Density) else state1
     state2 = represent(state2) if isinstance(state2, Density) else state2
 
-    if (not isinstance(state1, Matrix) or
-            not isinstance(state2, Matrix)):
+    if not isinstance(state1, Matrix) or not isinstance(state2, Matrix):
         raise ValueError("state1 and state2 must be of type Density or Matrix "
                          "received type=%s for state1 and type=%s for state2" %
                          (type(state1), type(state2)))
 
-    if ( state1.shape != state2.shape and state1.is_square):
+    if state1.shape != state2.shape and state1.is_square:
         raise ValueError("The dimensions of both args should be equal and the "
                          "matrix obtained should be a square matrix")
 
     sqrt_state1 = state1**S.Half
-    return Tr((sqrt_state1 * state2 * sqrt_state1)**S.Half).doit()
+    return Tr((sqrt_state1*state2*sqrt_state1)**S.Half).doit()
diff --git a/sympy/physics/quantum/qubit.py b/sympy/physics/quantum/qubit.py
index 4e9a94e8cc03..ad5068a384c5 100644
--- a/sympy/physics/quantum/qubit.py
+++ b/sympy/physics/quantum/qubit.py
@@ -345,7 +345,7 @@ class IntQubit(IntQubitState, Qubit):
 
     The differences between this class and ``Qubit`` are:
 
-    * The form of the constructor.
+   *The form of the constructor.
     * The qubit values are printed as their corresponding integer, rather
       than the raw qubit values. The internal storage format of the qubit
       values in the same as ``Qubit``.
diff --git a/sympy/physics/quantum/spin.py b/sympy/physics/quantum/spin.py
index 3dbf46421b95..b5d41715f774 100644
--- a/sympy/physics/quantum/spin.py
+++ b/sympy/physics/quantum/spin.py
@@ -103,7 +103,7 @@ def _apply_op(self, ket, orig_basis, **options):
         state = ket.rewrite(self.basis)
         # If the state has only one term
         if isinstance(state, State):
-            ret = (hbar*state.m) * state
+            ret = (hbar*state.m)*state
         # state is a linear combination of states
         elif isinstance(state, Sum):
             ret = self._apply_operator_Sum(state, **options)
@@ -147,7 +147,7 @@ def _apply_operator_TensorProduct(self, tp, **options):
 
     # TODO: move this to qapply_Mul
     def _apply_operator_Sum(self, s, **options):
-        new_func = qapply(self * s.function)
+        new_func = qapply(self*s.function)
         if new_func == self*s.function:
             raise NotImplementedError
         return Sum(new_func, *s.limits)
@@ -636,14 +636,14 @@ def _apply_operator_uncoupled(self, state, ket, **options):
             for mp in sz:
                 r = Rotation.D(j, m, mp, a, b, g)
                 z = r.doit()
-                s.append(z * state(j, mp))
+                s.append(z*state(j, mp))
             return Add(*s)
         else:
             if options.pop('dummy', True):
                 mp = Dummy('mp')
             else:
                 mp = symbols('mp')
-            return Sum(Rotation.D(j, m, mp, a, b, g) * state(j, mp), (mp, -j, j))
+            return Sum(Rotation.D(j, m, mp, a, b, g)*state(j, mp), (mp, -j, j))
 
     def _apply_operator_JxKet(self, ket, **options):
         return self._apply_operator_uncoupled(JxKet, ket, **options)
@@ -669,14 +669,14 @@ def _apply_operator_coupled(self, state, ket, **options):
             for mp in sz:
                 r = Rotation.D(j, m, mp, a, b, g)
                 z = r.doit()
-                s.append(z * state(j, mp, jn, coupling))
+                s.append(z*state(j, mp, jn, coupling))
             return Add(*s)
         else:
             if options.pop('dummy', True):
                 mp = Dummy('mp')
             else:
                 mp = symbols('mp')
-            return Sum(Rotation.D(j, m, mp, a, b, g) * state(
+            return Sum(Rotation.D(j, m, mp, a, b, g)*state(
                 j, mp, jn, coupling), (mp, -j, j))
 
     def _apply_operator_JxKetCoupled(self, ket, **options):
@@ -827,9 +827,9 @@ def _pretty(self, printer, *args):
         top = prettyForm(*top.left(' '))
         bot = prettyForm(*bot.left(' '))
         if pad > top.width():
-            top = prettyForm(*top.right(' ' * (pad - top.width())))
+            top = prettyForm(*top.right(' '*(pad - top.width())))
         if pad > bot.width():
-            bot = prettyForm(*bot.right(' ' * (pad - bot.width())))
+            bot = prettyForm(*bot.right(' '*(pad - bot.width())))
         if self.alpha == 0 and self.gamma == 0:
             args = printer._print(self.beta)
             s = stringPict('d' + ' '*pad)
@@ -869,25 +869,25 @@ def _eval_wignerd(self):
             for k in range(2*j + 1):
                 if k > j + mp or k > j - m or k < mp - m:
                     continue
-                r += (S.NegativeOne)**k * binomial(j + mp, k) * binomial(j - mp, k + m - mp)
-            r *= (S.NegativeOne)**(m - mp) / 2**j * sqrt(factorial(j + m) *
-                    factorial(j - m) / (factorial(j + mp) * factorial(j - mp)))
+                r += (S.NegativeOne)**k*binomial(j + mp, k)*binomial(j - mp, k + m - mp)
+            r *= (S.NegativeOne)**(m - mp) / 2**j*sqrt(factorial(j + m) *
+                    factorial(j - m) / (factorial(j + mp)*factorial(j - mp)))
         else:
             # Varshalovich Equation(5), Section 4.7.2, page 87, where we set
             # beta1=beta2=pi/2, and we get alpha=gamma=pi/2 and beta=phi+pi,
             # then we use the Eq. (1), Section 4.4. page 79, to simplify:
-            # d(j, m, mp, beta+pi) = (-1)**(j-mp) * d(j, m, -mp, beta)
+            # d(j, m, mp, beta+pi) = (-1)**(j-mp)*d(j, m, -mp, beta)
             # This happens to be almost the same as in Eq.(10), Section 4.16,
             # except that we need to substitute -mp for mp.
             size, mvals = m_values(j)
             for mpp in mvals:
-                r += Rotation.d(j, m, mpp, pi/2).doit() * (cos(-mpp*beta) + I*sin(-mpp*beta)) * \
+                r += Rotation.d(j, m, mpp, pi/2).doit()*(cos(-mpp*beta) + I*sin(-mpp*beta))*\
                     Rotation.d(j, mpp, -mp, pi/2).doit()
             # Empirical normalization factor so results match Varshalovich
             # Tables 4.3-4.12
             # Note that this exact normalization does not follow from the
             # above equations
-            r = r * I**(2*j - m - mp) * (-1)**(2*m)
+            r = r*I**(2*j - m - mp)*(-1)**(2*m)
             # Finally, simplify the whole expression
             r = simplify(r)
         r *= exp(-I*m*alpha)*exp(-I*mp*gamma)
@@ -992,7 +992,7 @@ def _rewrite_basis(self, basis, evect, **options):
                 start = 0
             vect = represent(self, basis=basis, **options)
             result = Add(
-                *[vect[start + i] * evect(j, j - i, *args) for i in range(2*j + 1)])
+                *[vect[start + i]*evect(j, j - i, *args) for i in range(2*j + 1)])
             if isinstance(self, CoupledSpinState) and options.get('coupled') is False:
                 return uncouple(result)
             return result
@@ -1020,7 +1020,7 @@ def _rewrite_basis(self, basis, evect, **options):
             else:
                 state = evect(j, mi, *args)
                 lt = Rotation.D(j, mi, self.m, *angles)
-                return Sum(lt * state, (mi, -j, j))
+                return Sum(lt*state, (mi, -j, j))
 
     def _eval_innerproduct_JxBra(self, bra, **hints):
         result = KroneckerDelta(self.j, bra.j)
@@ -1028,7 +1028,7 @@ def _eval_innerproduct_JxBra(self, bra, **hints):
             result *= self._represent_JxOp(None)[bra.j - bra.m]
         else:
             result *= KroneckerDelta(
-                self.j, bra.j) * KroneckerDelta(self.m, bra.m)
+                self.j, bra.j)*KroneckerDelta(self.m, bra.m)
         return result
 
     def _eval_innerproduct_JyBra(self, bra, **hints):
@@ -1037,7 +1037,7 @@ def _eval_innerproduct_JyBra(self, bra, **hints):
             result *= self._represent_JyOp(None)[bra.j - bra.m]
         else:
             result *= KroneckerDelta(
-                self.j, bra.j) * KroneckerDelta(self.m, bra.m)
+                self.j, bra.j)*KroneckerDelta(self.m, bra.m)
         return result
 
     def _eval_innerproduct_JzBra(self, bra, **hints):
@@ -1046,7 +1046,7 @@ def _eval_innerproduct_JzBra(self, bra, **hints):
             result *= self._represent_JzOp(None)[bra.j - bra.m]
         else:
             result *= KroneckerDelta(
-                self.j, bra.j) * KroneckerDelta(self.m, bra.m)
+                self.j, bra.j)*KroneckerDelta(self.m, bra.m)
         return result
 
     def _eval_trace(self, bra, **hints):
diff --git a/sympy/physics/sho.py b/sympy/physics/sho.py
index 98e3816e8a5a..2f4c2b2fc953 100644
--- a/sympy/physics/sho.py
+++ b/sympy/physics/sho.py
@@ -43,11 +43,11 @@ def R_nl(n, l, nu, r):
     The normalization of the radial wavefunction is:
 
     >>> from sympy import Integral, oo
-    >>> Integral(R_nl(0, 0, 1, r)**2 * r**2, (r, 0, oo)).n()
+    >>> Integral(R_nl(0, 0, 1, r)**2*r**2, (r, 0, oo)).n()
     1.00000000000000
-    >>> Integral(R_nl(1, 0, 1, r)**2 * r**2, (r, 0, oo)).n()
+    >>> Integral(R_nl(1, 0, 1, r)**2*r**2, (r, 0, oo)).n()
     1.00000000000000
-    >>> Integral(R_nl(1, 1, 1, r)**2 * r**2, (r, 0, oo)).n()
+    >>> Integral(R_nl(1, 1, 1, r)**2*r**2, (r, 0, oo)).n()
     1.00000000000000
 
     """
diff --git a/sympy/polys/domains/__init__.py b/sympy/polys/domains/__init__.py
index 05b6c84558c5..928938af6c9e 100644
--- a/sympy/polys/domains/__init__.py
+++ b/sympy/polys/domains/__init__.py
@@ -1,10 +1,11 @@
 """Implementation of mathematical domains. """
 
 __all__ = ['Domain', 'FiniteField', 'IntegerRing', 'RationalField',
-        'RealField', 'ComplexField', 'PythonFiniteField', 'GMPYFiniteField',
-        'PythonIntegerRing', 'GMPYIntegerRing', 'PythonRational',
-        'GMPYRationalField', 'AlgebraicField', 'PolynomialRing',
-        'FractionField', 'ExpressionDomain', 'PythonRational']
+           'RealField', 'ComplexField', 'PythonFiniteField',
+           'GMPYFiniteField', 'PythonIntegerRing',
+           'GMPYIntegerRing', 'PythonRational',
+           'GMPYRationalField', 'AlgebraicField', 'PolynomialRing',
+           'FractionField', 'ExpressionDomain', 'PythonRational']
 
 from .domain import Domain
 from .finitefield import FiniteField
diff --git a/sympy/polys/polymatrix.py b/sympy/polys/polymatrix.py
index 48980f852461..3cc71358d27a 100644
--- a/sympy/polys/polymatrix.py
+++ b/sympy/polys/polymatrix.py
@@ -58,7 +58,7 @@ def __init__(self, *args, **kwargs):
     def _eval_matrix_mul(self, other):
         self_cols = self.cols
         other_rows, other_cols = other.rows, other.cols
-        other_len = other_rows * other_cols
+        other_len = other_rows*other_cols
         new_mat_rows = self.rows
         new_mat_cols = other.cols
 
diff --git a/sympy/polys/ring_series.py b/sympy/polys/ring_series.py
index bcd9e4053630..81a3961c63e4 100644
--- a/sympy/polys/ring_series.py
+++ b/sympy/polys/ring_series.py
@@ -1825,7 +1825,7 @@ def rs_compose_add(p1, p2):
     """
     R = p1.ring
     x = R.gens[0]
-    prec = p1.degree() * p2.degree() + 1
+    prec = p1.degree()*p2.degree() + 1
     np1 = rs_newton(p1, x, prec)
     np1e = rs_hadamard_exp(np1)
     np2 = rs_newton(p2, x, prec)
@@ -1837,7 +1837,7 @@ def rs_compose_add(p1, p2):
     q = rs_exp(q, x, prec)
     q = _invert_monoms(q)
     q = q.primitive()[1]
-    dp = p1.degree() * p2.degree() - q.degree()
+    dp = p1.degree()*p2.degree() - q.degree()
     # `dp` is the multiplicity of the zeroes of the resultant;
     # these zeroes are missed in this computation so they are put here.
     # if p1 and p2 are monic irreducible polynomials,
diff --git a/sympy/series/tests/test_nseries.py b/sympy/series/tests/test_nseries.py
index 37d5ef84b128..a4e711ab4fb6 100644
--- a/sympy/series/tests/test_nseries.py
+++ b/sympy/series/tests/test_nseries.py
@@ -146,7 +146,7 @@ def test_series2x():
     assert (1/(1 + 1/x**2)).nseries(x, 0, 6) == x**2 - x**4 + O(x**6, x)
 
 
-def test_bug2():  # 1/log(0) * log(0) problem
+def test_bug2():  # 1/log(0)*log(0) problem
     w = Symbol("w")
     e = (w**(-1) + w**(
         -log(3)*log(2)**(-1)))**(-1)*(3*w**(-log(3)*log(2)**(-1)) + 2*w**(-1))
@@ -366,7 +366,7 @@ def test_series2():
     w = Symbol("w", real=True)
     x = Symbol("x", real=True)
     e = w**(-2)*(w*exp(1/x - w) - w*exp(1/x))
-    assert e.nseries(w, n=4) == -exp(1/x) + w * exp(1/x) / 2 + O(w**2)
+    assert e.nseries(w, n=4) == -exp(1/x) + w*exp(1/x) / 2 + O(w**2)
 
 
 def test_series3():
diff --git a/sympy/sets/handlers/add.py b/sympy/sets/handlers/add.py
index 5d172ca5c7dc..373c98035fbe 100644
--- a/sympy/sets/handlers/add.py
+++ b/sympy/sets/handlers/add.py
@@ -1,10 +1,13 @@
+
 from sympy import symbols, S, oo
+
 from sympy.core import Basic, Expr
 from sympy.core.numbers import Infinity, NegativeInfinity
 from sympy.multipledispatch import dispatch
 from sympy.sets import Interval, FiniteSet
 
 
+
 # XXX: The functions in this module are clearly not tested and are broken in a
 # number of ways.
 
@@ -15,10 +18,12 @@
 def _set_add(x, y): # noqa:F811
     return None
 
+
 @dispatch(Expr, Expr)
 def _set_add(x, y): # noqa:F811
     return x+y
 
+
 @dispatch(Interval, Interval)
 def _set_add(x, y): # noqa:F811
     """
@@ -26,7 +31,8 @@ def _set_add(x, y): # noqa:F811
     https://en.wikipedia.org/wiki/Interval_arithmetic
     """
     return Interval(x.start + y.start, x.end + y.end,
-        x.left_open or y.left_open, x.right_open or y.right_open)
+                    x.left_open or y.left_open, x.right_open or y.right_open)
+
 
 @dispatch(Interval, Infinity)
 def _set_add(x, y): # noqa:F811
@@ -45,10 +51,12 @@ def _set_add(x, y): # noqa:F811
 def _set_sub(x, y): # noqa:F811
     return None
 
+
 @dispatch(Expr, Expr)
 def _set_sub(x, y): # noqa:F811
     return x-y
 
+
 @dispatch(Interval, Interval)
 def _set_sub(x, y): # noqa:F811
     """
@@ -56,7 +64,8 @@ def _set_sub(x, y): # noqa:F811
     https://en.wikipedia.org/wiki/Interval_arithmetic
     """
     return Interval(x.start - y.end, x.end - y.start,
-        x.left_open or y.right_open, x.right_open or y.left_open)
+                    x.left_open or y.right_open, x.right_open or y.left_open)
+
 
 @dispatch(Interval, Infinity)
 def _set_sub(x, y): # noqa:F811
diff --git a/sympy/sets/tests/test_setexpr.py b/sympy/sets/tests/test_setexpr.py
index bb6f1171e726..b079429e3850 100644
--- a/sympy/sets/tests/test_setexpr.py
+++ b/sympy/sets/tests/test_setexpr.py
@@ -1,8 +1,10 @@
 from sympy.sets.setexpr import SetExpr
 from sympy.sets import Interval, FiniteSet, Intersection, ImageSet, Union
+
 from sympy import (Expr, Set, exp, log, cos, Symbol, Min, Max, S, oo, I,
         symbols, Lambda, Dummy, Rational)
 
+
 a, x = symbols("a, x")
 _d = Dummy("d")
 
@@ -27,7 +29,7 @@ def test_scalar_funcs():
 
 def test_Add_Mul():
     assert (SetExpr(Interval(0, 1)) + 1).set == Interval(1, 2)
-    assert (SetExpr(Interval(0, 1)) * 2).set == Interval(0, 2)
+    assert (SetExpr(Interval(0, 1))*2).set == Interval(0, 2)
 
 
 def test_Pow():
@@ -35,33 +37,33 @@ def test_Pow():
 
 
 def test_compound():
-    assert (exp(SetExpr(Interval(0, 1)) * 2 + 1)).set == \
-        Interval(exp(1), exp(3))
+    assert (exp(SetExpr(Interval(0, 1))*2 + 1)).set == \
+           Interval(exp(1), exp(3))
 
 
 def test_Interval_Interval():
     assert (SetExpr(Interval(1, 2)) + SetExpr(Interval(10, 20))).set == \
-        Interval(11, 22)
-    assert (SetExpr(Interval(1, 2)) * SetExpr(Interval(10, 20))).set == \
-        Interval(10, 40)
+           Interval(11, 22)
+    assert (SetExpr(Interval(1, 2))*SetExpr(Interval(10, 20))).set == \
+           Interval(10, 40)
 
 
 def test_FiniteSet_FiniteSet():
-    assert (SetExpr(FiniteSet(1, 2, 3)) + SetExpr(FiniteSet(1, 2))).set ==\
-        FiniteSet(2, 3, 4, 5)
-    assert (SetExpr(FiniteSet(1, 2, 3)) * SetExpr(FiniteSet(1, 2))).set ==\
-        FiniteSet(1, 2, 3, 4, 6)
+    assert (SetExpr(FiniteSet(1, 2, 3)) + SetExpr(FiniteSet(1, 2))).set == \
+           FiniteSet(2, 3, 4, 5)
+    assert (SetExpr(FiniteSet(1, 2, 3))*SetExpr(FiniteSet(1, 2))).set == \
+           FiniteSet(1, 2, 3, 4, 6)
 
 
 def test_Interval_FiniteSet():
     assert (SetExpr(FiniteSet(1, 2)) + SetExpr(Interval(0, 10))).set == \
-        Interval(1, 12)
+           Interval(1, 12)
 
 
 def test_Many_Sets():
     assert (SetExpr(Interval(0, 1)) +
-                    SetExpr(Interval(2, 3)) +
-                    SetExpr(FiniteSet(10, 11, 12))).set == Interval(12, 16)
+            SetExpr(Interval(2, 3)) +
+            SetExpr(FiniteSet(10, 11, 12))).set == Interval(12, 16)
 
 
 def test_same_setexprs_are_not_identical():
@@ -88,97 +90,100 @@ def test_Interval_arithmetic():
 
     assert i12cc + i12cc == SetExpr(Interval(2, 4))
     assert i12cc - i12cc == SetExpr(Interval(-1, 1))
-    assert i12cc * i12cc == SetExpr(Interval(1, 4))
-    assert i12cc / i12cc == SetExpr(Interval(S.Half, 2))
-    assert i12cc ** 2 == SetExpr(Interval(1, 4))
-    assert i12cc ** 3 == SetExpr(Interval(1, 8))
+    assert i12cc*i12cc == SetExpr(Interval(1, 4))
+    assert i12cc/i12cc == SetExpr(Interval(S.Half, 2))
+    assert i12cc**2 == SetExpr(Interval(1, 4))
+    assert i12cc**3 == SetExpr(Interval(1, 8))
 
     assert i12lo + i12ro == SetExpr(Interval.open(2, 4))
     assert i12lo - i12ro == SetExpr(Interval.Lopen(-1, 1))
-    assert i12lo * i12ro == SetExpr(Interval.open(1, 4))
-    assert i12lo / i12ro == SetExpr(Interval.Lopen(S.Half, 2))
+    assert i12lo*i12ro == SetExpr(Interval.open(1, 4))
+    assert i12lo/i12ro == SetExpr(Interval.Lopen(S.Half, 2))
     assert i12lo + i12lo == SetExpr(Interval.Lopen(2, 4))
     assert i12lo - i12lo == SetExpr(Interval.open(-1, 1))
-    assert i12lo * i12lo == SetExpr(Interval.Lopen(1, 4))
-    assert i12lo / i12lo == SetExpr(Interval.open(S.Half, 2))
+    assert i12lo*i12lo == SetExpr(Interval.Lopen(1, 4))
+    assert i12lo/i12lo == SetExpr(Interval.open(S.Half, 2))
     assert i12lo + i12cc == SetExpr(Interval.Lopen(2, 4))
     assert i12lo - i12cc == SetExpr(Interval.Lopen(-1, 1))
-    assert i12lo * i12cc == SetExpr(Interval.Lopen(1, 4))
-    assert i12lo / i12cc == SetExpr(Interval.Lopen(S.Half, 2))
+    assert i12lo*i12cc == SetExpr(Interval.Lopen(1, 4))
+    assert i12lo/i12cc == SetExpr(Interval.Lopen(S.Half, 2))
     assert i12lo + i12o == SetExpr(Interval.open(2, 4))
     assert i12lo - i12o == SetExpr(Interval.open(-1, 1))
-    assert i12lo * i12o == SetExpr(Interval.open(1, 4))
-    assert i12lo / i12o == SetExpr(Interval.open(S.Half, 2))
-    assert i12lo ** 2 == SetExpr(Interval.Lopen(1, 4))
-    assert i12lo ** 3 == SetExpr(Interval.Lopen(1, 8))
+    assert i12lo*i12o == SetExpr(Interval.open(1, 4))
+    assert i12lo/i12o == SetExpr(Interval.open(S.Half, 2))
+    assert i12lo**2 == SetExpr(Interval.Lopen(1, 4))
+    assert i12lo**3 == SetExpr(Interval.Lopen(1, 8))
 
     assert i12ro + i12ro == SetExpr(Interval.Ropen(2, 4))
     assert i12ro - i12ro == SetExpr(Interval.open(-1, 1))
-    assert i12ro * i12ro == SetExpr(Interval.Ropen(1, 4))
-    assert i12ro / i12ro == SetExpr(Interval.open(S.Half, 2))
+    assert i12ro*i12ro == SetExpr(Interval.Ropen(1, 4))
+    assert i12ro/i12ro == SetExpr(Interval.open(S.Half, 2))
     assert i12ro + i12cc == SetExpr(Interval.Ropen(2, 4))
     assert i12ro - i12cc == SetExpr(Interval.Ropen(-1, 1))
-    assert i12ro * i12cc == SetExpr(Interval.Ropen(1, 4))
-    assert i12ro / i12cc == SetExpr(Interval.Ropen(S.Half, 2))
+    assert i12ro*i12cc == SetExpr(Interval.Ropen(1, 4))
+    assert i12ro/i12cc == SetExpr(Interval.Ropen(S.Half, 2))
     assert i12ro + i12o == SetExpr(Interval.open(2, 4))
     assert i12ro - i12o == SetExpr(Interval.open(-1, 1))
-    assert i12ro * i12o == SetExpr(Interval.open(1, 4))
-    assert i12ro / i12o == SetExpr(Interval.open(S.Half, 2))
-    assert i12ro ** 2 == SetExpr(Interval.Ropen(1, 4))
-    assert i12ro ** 3 == SetExpr(Interval.Ropen(1, 8))
+    assert i12ro*i12o == SetExpr(Interval.open(1, 4))
+    assert i12ro/i12o == SetExpr(Interval.open(S.Half, 2))
+    assert i12ro**2 == SetExpr(Interval.Ropen(1, 4))
+    assert i12ro**3 == SetExpr(Interval.Ropen(1, 8))
 
     assert i12o + i12lo == SetExpr(Interval.open(2, 4))
     assert i12o - i12lo == SetExpr(Interval.open(-1, 1))
-    assert i12o * i12lo == SetExpr(Interval.open(1, 4))
-    assert i12o / i12lo == SetExpr(Interval.open(S.Half, 2))
+    assert i12o*i12lo == SetExpr(Interval.open(1, 4))
+    assert i12o/i12lo == SetExpr(Interval.open(S.Half, 2))
     assert i12o + i12ro == SetExpr(Interval.open(2, 4))
     assert i12o - i12ro == SetExpr(Interval.open(-1, 1))
-    assert i12o * i12ro == SetExpr(Interval.open(1, 4))
-    assert i12o / i12ro == SetExpr(Interval.open(S.Half, 2))
+    assert i12o*i12ro == SetExpr(Interval.open(1, 4))
+    assert i12o/i12ro == SetExpr(Interval.open(S.Half, 2))
     assert i12o + i12cc == SetExpr(Interval.open(2, 4))
     assert i12o - i12cc == SetExpr(Interval.open(-1, 1))
-    assert i12o * i12cc == SetExpr(Interval.open(1, 4))
-    assert i12o / i12cc == SetExpr(Interval.open(S.Half, 2))
-    assert i12o ** 2 == SetExpr(Interval.open(1, 4))
-    assert i12o ** 3 == SetExpr(Interval.open(1, 8))
+    assert i12o*i12cc == SetExpr(Interval.open(1, 4))
+    assert i12o/i12cc == SetExpr(Interval.open(S.Half, 2))
+    assert i12o**2 == SetExpr(Interval.open(1, 4))
+    assert i12o**3 == SetExpr(Interval.open(1, 8))
 
     assert n23cc + n23cc == SetExpr(Interval(-4, 6))
     assert n23cc - n23cc == SetExpr(Interval(-5, 5))
-    assert n23cc * n23cc == SetExpr(Interval(-6, 9))
-    assert n23cc / n23cc == SetExpr(Interval.open(-oo, oo))
+    assert n23cc*n23cc == SetExpr(Interval(-6, 9))
+    assert n23cc/n23cc == SetExpr(Interval.open(-oo, oo))
     assert n23cc + n23ro == SetExpr(Interval.Ropen(-4, 6))
     assert n23cc - n23ro == SetExpr(Interval.Lopen(-5, 5))
-    assert n23cc * n23ro == SetExpr(Interval.Ropen(-6, 9))
-    assert n23cc / n23ro == SetExpr(Interval.Lopen(-oo, oo))
+    assert n23cc*n23ro == SetExpr(Interval.Ropen(-6, 9))
+    assert n23cc/n23ro == SetExpr(Interval.Lopen(-oo, oo))
     assert n23cc + n23lo == SetExpr(Interval.Lopen(-4, 6))
     assert n23cc - n23lo == SetExpr(Interval.Ropen(-5, 5))
-    assert n23cc * n23lo == SetExpr(Interval(-6, 9))
-    assert n23cc / n23lo == SetExpr(Interval.open(-oo, oo))
+    assert n23cc*n23lo == SetExpr(Interval(-6, 9))
+    assert n23cc/n23lo == SetExpr(Interval.open(-oo, oo))
     assert n23cc + n23o == SetExpr(Interval.open(-4, 6))
     assert n23cc - n23o == SetExpr(Interval.open(-5, 5))
-    assert n23cc * n23o == SetExpr(Interval.open(-6, 9))
-    assert n23cc / n23o == SetExpr(Interval.open(-oo, oo))
-    assert n23cc ** 2 == SetExpr(Interval(0, 9))
-    assert n23cc ** 3 == SetExpr(Interval(-8, 27))
+    assert n23cc*n23o == SetExpr(Interval.open(-6, 9))
+    assert n23cc/n23o == SetExpr(Interval.open(-oo, oo))
+    assert n23cc**2 == SetExpr(Interval(0, 9))
+    assert n23cc**3 == SetExpr(Interval(-8, 27))
 
     n32cc = SetExpr(Interval(-3, 2))
     n32lo = SetExpr(Interval.Lopen(-3, 2))
     n32ro = SetExpr(Interval.Ropen(-3, 2))
-    assert n32cc * n32lo == SetExpr(Interval.Ropen(-6, 9))
-    assert n32cc * n32cc == SetExpr(Interval(-6, 9))
-    assert n32lo * n32cc == SetExpr(Interval.Ropen(-6, 9))
-    assert n32cc * n32ro == SetExpr(Interval(-6, 9))
-    assert n32lo * n32ro == SetExpr(Interval.Ropen(-6, 9))
-    assert n32cc / n32lo == SetExpr(Interval.Ropen(-oo, oo))
-    assert i12cc / n32lo == SetExpr(Interval.Ropen(-oo, oo))
+    assert n32cc*n32lo == SetExpr(Interval.Ropen(-6, 9))
+    assert n32cc*n32cc == SetExpr(Interval(-6, 9))
+    assert n32lo*n32cc == SetExpr(Interval.Ropen(-6, 9))
+    assert n32cc*n32ro == SetExpr(Interval(-6, 9))
+    assert n32lo*n32ro == SetExpr(Interval.Ropen(-6, 9))
+    assert n32cc/n32lo == SetExpr(Interval.Ropen(-oo, oo))
+    assert i12cc/n32lo == SetExpr(Interval.Ropen(-oo, oo))
 
-    assert n3n2cc ** 2 == SetExpr(Interval(4, 9))
-    assert n3n2cc ** 3 == SetExpr(Interval(-27, -8))
+    assert n3n2cc**2 == SetExpr(Interval(4, 9))
+    assert n3n2cc**3 == SetExpr(Interval(-27, -8))
 
     assert n23cc + i12cc == SetExpr(Interval(-1, 5))
     assert n23cc - i12cc == SetExpr(Interval(-4, 2))
-    assert n23cc * i12cc == SetExpr(Interval(-4, 6))
-    assert n23cc / i12cc == SetExpr(Interval(-2, 3))
+    assert n23cc*i12cc == SetExpr(Interval(-4, 6))
+    assert n23cc/i12cc == SetExpr(Interval(-2, 3))
+
+
+
 
 
 def test_SetExpr_Intersection():
@@ -188,8 +193,8 @@ def test_SetExpr_Intersection():
     inter = Intersection(set1, set2)
     se = SetExpr(inter)
     assert exp(se).set == Intersection(
-            ImageSet(Lambda(x, exp(x)), set1),
-            ImageSet(Lambda(x, exp(x)), set2))
+        ImageSet(Lambda(x, exp(x)), set1),
+        ImageSet(Lambda(x, exp(x)), set2))
     assert cos(se).set == ImageSet(Lambda(x, cos(x)), inter)
 
 
@@ -203,31 +208,32 @@ def test_SetExpr_Interval_div():
     assert SetExpr(Interval(2, 4))/SetExpr(Interval(-3, 0)) == SetExpr(Interval(-oo, Rational(-2, 3)))
     assert SetExpr(Interval(2, 4))/SetExpr(Interval(0, 3)) == SetExpr(Interval(Rational(2, 3), oo))
 
-    #assert SetExpr(Interval(0, 1))/SetExpr(Interval(0, 1)) == SetExpr(Interval(0, oo))
-    #assert SetExpr(Interval(-1, 0))/SetExpr(Interval(0, 1)) == SetExpr(Interval(-oo, 0))
+    # assert SetExpr(Interval(0, 1))/SetExpr(Interval(0, 1)) == SetExpr(Interval(0, oo))
+    # assert SetExpr(Interval(-1, 0))/SetExpr(Interval(0, 1)) == SetExpr(Interval(-oo, 0))
     assert SetExpr(Interval(-1, 2))/SetExpr(Interval(-2, 2)) == SetExpr(Interval(-oo, oo))
 
     assert 1/SetExpr(Interval(-1, 2)) == SetExpr(Union(Interval(-oo, -1), Interval(S.Half, oo)))
+
     assert 1/SetExpr(Interval(0, 2)) == SetExpr(Interval(S.Half, oo))
     assert (-1)/SetExpr(Interval(0, 2)) == SetExpr(Interval(-oo, Rational(-1, 2)))
-    #assert 1/SetExpr(Interval(-oo, 0)) == SetExpr(Interval.open(-oo, 0))
+    # assert 1/SetExpr(Interval(-oo, 0)) == SetExpr(Interval.open(-oo, 0))
     assert 1/SetExpr(Interval(-1, 0)) == SetExpr(Interval(-oo, -1))
-    #assert (-2)/SetExpr(Interval(-oo, 0)) == SetExpr(Interval(0, oo))
-    #assert 1/SetExpr(Interval(-oo, -1)) == SetExpr(Interval(-1, 0))
+    # assert (-2)/SetExpr(Interval(-oo, 0)) == SetExpr(Interval(0, oo))
+    # assert 1/SetExpr(Interval(-oo, -1)) == SetExpr(Interval(-1, 0))
 
-    #assert SetExpr(Interval(1, 2))/a == Mul(SetExpr(Interval(1, 2)), 1/a, evaluate=False)
+    # assert SetExpr(Interval(1, 2))/a == Mul(SetExpr(Interval(1, 2)), 1/a, evaluate=False)
 
-    #assert SetExpr(Interval(1, 2))/0 == SetExpr(Interval(1, 2))*zoo
-    #assert SetExpr(Interval(1, oo))/oo == SetExpr(Interval(0, oo))
-    #assert SetExpr(Interval(1, oo))/(-oo) == SetExpr(Interval(-oo, 0))
-    #assert SetExpr(Interval(-oo, -1))/oo == SetExpr(Interval(-oo, 0))
-    #assert SetExpr(Interval(-oo, -1))/(-oo) == SetExpr(Interval(0, oo))
-    #assert SetExpr(Interval(-oo, oo))/oo == SetExpr(Interval(-oo, oo))
-    #assert SetExpr(Interval(-oo, oo))/(-oo) == SetExpr(Interval(-oo, oo))
-    #assert SetExpr(Interval(-1, oo))/oo == SetExpr(Interval(0, oo))
-    #assert SetExpr(Interval(-1, oo))/(-oo) == SetExpr(Interval(-oo, 0))
-    #assert SetExpr(Interval(-oo, 1))/oo == SetExpr(Interval(-oo, 0))
-    #assert SetExpr(Interval(-oo, 1))/(-oo) == SetExpr(Interval(0, oo))
+    # assert SetExpr(Interval(1, 2))/0 == SetExpr(Interval(1, 2))*zoo
+    # assert SetExpr(Interval(1, oo))/oo == SetExpr(Interval(0, oo))
+    # assert SetExpr(Interval(1, oo))/(-oo) == SetExpr(Interval(-oo, 0))
+    # assert SetExpr(Interval(-oo, -1))/oo == SetExpr(Interval(-oo, 0))
+    # assert SetExpr(Interval(-oo, -1))/(-oo) == SetExpr(Interval(0, oo))
+    # assert SetExpr(Interval(-oo, oo))/oo == SetExpr(Interval(-oo, oo))
+    # assert SetExpr(Interval(-oo, oo))/(-oo) == SetExpr(Interval(-oo, oo))
+    # assert SetExpr(Interval(-1, oo))/oo == SetExpr(Interval(0, oo))
+    # assert SetExpr(Interval(-1, oo))/(-oo) == SetExpr(Interval(-oo, 0))
+    # assert SetExpr(Interval(-oo, 1))/oo == SetExpr(Interval(-oo, 0))
+    # assert SetExpr(Interval(-oo, 1))/(-oo) == SetExpr(Interval(0, oo))
 
 
 def test_SetExpr_Interval_pow():
@@ -237,6 +243,7 @@ def test_SetExpr_Interval_pow():
     assert SetExpr(Interval(-1, 2))**3 == SetExpr(Interval(-1, 8))
     assert SetExpr(Interval(-1, 1))**0 == SetExpr(FiniteSet(1))
 
+
     #assert SetExpr(Interval(1, 2))**Rational(5, 2) == SetExpr(Interval(1, 4*sqrt(2)))
     #assert SetExpr(Interval(-1, 2))**Rational(1, 3) == SetExpr(Interval(-1, 2**Rational(1, 3)))
     #assert SetExpr(Interval(0, 2))**S.Half == SetExpr(Interval(0, sqrt(2)))
@@ -249,6 +256,7 @@ def test_SetExpr_Interval_pow():
 
     assert SetExpr(Interval(1, 5))**(-2) == SetExpr(Interval(Rational(1, 25), 1))
     assert SetExpr(Interval(-1, 3))**(-2) == SetExpr(Interval(0, oo))
+
     assert SetExpr(Interval(0, 2))**(-2) == SetExpr(Interval(Rational(1, 4), oo))
     assert SetExpr(Interval(-1, 2))**(-3) == SetExpr(Union(Interval(-oo, -1), Interval(Rational(1, 8), oo)))
     assert SetExpr(Interval(-3, -2))**(-3) == SetExpr(Interval(Rational(-1, 8), Rational(-1, 27)))
@@ -256,6 +264,7 @@ def test_SetExpr_Interval_pow():
     #assert SetExpr(Interval(0, oo))**S.Half == SetExpr(Interval(0, oo))
     #assert SetExpr(Interval(-oo, -1))**Rational(1, 3) == SetExpr(Interval(-oo, -1))
     #assert SetExpr(Interval(-2, 3))**(Rational(-1, 3)) == SetExpr(Interval(-oo, oo))
+
     assert SetExpr(Interval(-oo, 0))**(-2) == SetExpr(Interval.open(0, oo))
     assert SetExpr(Interval(-2, 0))**(-2) == SetExpr(Interval(Rational(1, 4), oo))
 
diff --git a/sympy/utilities/_compilation/compilation.py b/sympy/utilities/_compilation/compilation.py
index 2c25916de0f8..af9aefda490e 100644
--- a/sympy/utilities/_compilation/compilation.py
+++ b/sympy/utilities/_compilation/compilation.py
@@ -1,5 +1,6 @@
 from __future__ import (absolute_import, division, print_function)
 
+import glob
 import os
 import shutil
 import subprocess
@@ -10,18 +11,16 @@
 from distutils.errors import CompileError
 from distutils.sysconfig import get_config_var
 
-from .util import (
-    get_abspath, make_dirs, copy, Glob, ArbitraryDepthGlob,
-    glob_at_depth, import_module_from_file, pyx_is_cplus,
-    sha256_of_string, sha256_of_file
-)
-
 from .runners import (
     CCompilerRunner,
     CppCompilerRunner,
     FortranCompilerRunner
 )
-
+from .util import (
+    get_abspath, make_dirs, copy, Glob, ArbitraryDepthGlob,
+    glob_at_depth, import_module_from_file, pyx_is_cplus,
+    sha256_of_string, sha256_of_file
+)
 
 sharedext = get_config_var('EXT_SUFFIX' if sys.version_info >= (3, 3) else 'SO')
 
@@ -349,7 +348,7 @@ def src2obj(srcpath, Runner=None, objpath=None, cwd=None, inc_py=False, **kwargs
             objpath = objpath or '.'  # avoid objpath == ''
 
     if os.path.isdir(objpath):
-        objpath = os.path.join(objpath, name+objext)
+        objpath = os.path.join(objpath, name + objext)
 
     include_dirs = kwargs.pop('include_dirs', [])
     if inc_py:
@@ -431,7 +430,7 @@ def pyx2obj(pyxpath, objpath=None, destdir=None, cwd=None,
     if os.path.isdir(abs_objpath):
         pyx_fname = os.path.basename(pyxpath)
         name, ext = os.path.splitext(pyx_fname)
-        objpath = os.path.join(objpath, name+objext)
+        objpath = os.path.join(objpath, name + objext)
 
     cy_kwargs = cy_kwargs or {}
     cy_kwargs['output_dir'] = cwd
@@ -533,6 +532,7 @@ def compile_link_import_py_ext(sources, extname=None, build_dir='.', compile_kwa
         mod = import_module_from_file(so)
     return mod
 
+
 def _write_sources_to_build_dir(sources, build_dir):
     build_dir = build_dir or tempfile.mkdtemp()
     if not os.path.isdir(build_dir):
@@ -544,8 +544,8 @@ def _write_sources_to_build_dir(sources, build_dir):
         differs = True
         sha256_in_mem = sha256_of_string(src.encode('utf-8')).hexdigest()
         if os.path.exists(dest):
-            if os.path.exists(dest+'.sha256'):
-                sha256_on_disk = open(dest+'.sha256', 'rt').read()
+            if os.path.exists(dest + '.sha256'):
+                sha256_on_disk = open(dest + '.sha256', 'rt').read()
             else:
                 sha256_on_disk = sha256_of_file(dest).hexdigest()
 
@@ -553,7 +553,7 @@ def _write_sources_to_build_dir(sources, build_dir):
         if differs:
             with open(dest, 'wt') as fh:
                 fh.write(src)
-                open(dest+'.sha256', 'wt').write(sha256_in_mem)
+                open(dest + '.sha256', 'wt').write(sha256_in_mem)
         source_files.append(dest)
     return source_files, build_dir
 


Code review comments:
diff_hunk: @@ -345,7 +345,7 @@ class IntQubit(IntQubitState, Qubit):
 
     The differences between this class and ``Qubit`` are:
 
-    * The form of the constructor.
+   *The form of the constructor.
path: sympy/physics/quantum/qubit.py
text: @user1:
It should be left as it was.