Repository: sympy/sympy

Issue:
Addition of a quantity and a number does not raise an error
If I add two quantities with inconsistent units, sympy rightly returns an error:
```
>>> from sympy.physics.units import kilogram, kelvin
>>> try: print kilogram + kelvin
>>> except Exception, error: print error
summation of quantities of incompatible dimensions
```
However, if one of the terms is a number, no error is raised:
```
>>> try: print kilogram + 1.1
>>> except Exception, error: print error
kilogram + 1.1
```

If I add two quantities, one of which does not have a dimension, an error is raised:
```
>>> from sympy.physics.units import Quantity, mass
>>> try: print Quantity('x', mass, kilogram) + Quantity('y', S.One, 1.1)
>>> except Exception, error: print error
summation of quantities of incompatible dimensions
```

If I add a quantity and a number, no error is raised:
```
>>> try: print Quantity('x', mass, kilogram) + Number(1.1)
>>> except Exception, error: print error
x + 1.1
```
I believe that this is a bug, as numbers should be treated like dimensionless quantities whenever they are used alongside with quantities.


Discussion:

Patch:
diff --git a/sympy/core/power.py b/sympy/core/power.py
index e221fa252b..61d7a8f928 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -1062,7 +1062,14 @@ def _eval_is_rational(self):
                 return e.is_zero
 
     def _eval_is_algebraic(self):
-        if self.base.is_zero or (self.base - 1).is_zero:
+        def _is_one(expr):
+            try:
+                return (expr - 1).is_zero
+            except ValueError:
+                # when the operation is not allowed
+                return False
+
+        if self.base.is_zero or _is_one(self.base):
             return True
         elif self.exp.is_rational:
             if self.base.is_algebraic is False:
@@ -1070,7 +1077,7 @@ def _eval_is_algebraic(self):
             return self.base.is_algebraic
         elif self.base.is_algebraic and self.exp.is_algebraic:
             if ((fuzzy_not(self.base.is_zero)
-                and fuzzy_not((self.base - 1).is_zero))
+                and fuzzy_not(_is_one(self.base)))
                 or self.base.is_integer is False
                 or self.base.is_irrational):
                 return self.exp.is_rational
diff --git a/sympy/physics/units/quantities.py b/sympy/physics/units/quantities.py
index 602ba55b2c..28df5e26c4 100644
--- a/sympy/physics/units/quantities.py
+++ b/sympy/physics/units/quantities.py
@@ -153,12 +153,11 @@ def _Quantity_constructor_postprocessor_Add(expr):
 
     deset = {
         tuple(sorted(Dimension(
-            Quantity.get_dimensional_expr(i)
+            Quantity.get_dimensional_expr(i) if not i.is_number else 1
         ).get_dimensional_dependencies().items()))
         for i in expr.args
         if i.free_symbols == set()  # do not raise if there are symbols
                     # (free symbols could contain the units corrections)
-        and not i.is_number
     }
     # If `deset` has more than one element, then some dimensions do not
     # match in the sum:


Test patch:
diff --git a/sympy/physics/units/tests/test_quantities.py b/sympy/physics/units/tests/test_quantities.py
index b8df677fa2..560683b00c 100644
--- a/sympy/physics/units/tests/test_quantities.py
+++ b/sympy/physics/units/tests/test_quantities.py
@@ -226,6 +226,7 @@ def test_Quantity_derivative():
 
 
 def test_sum_of_incompatible_quantities():
+    raises(ValueError, lambda: meter + 1)
     raises(ValueError, lambda: meter + second)
     raises(ValueError, lambda: 2 * meter + second)
     raises(ValueError, lambda: 2 * meter + 3 * second)