Repository: sympy/sympy

Issue:
Units are not simplified with simplify()
```python
from sympy.physics.units import *
(cm/mm).simplify()
```

expected `10`
got `centimeter/millimeter`



Discussion:

Patch:
diff --git a/sympy/physics/units/util.py b/sympy/physics/units/util.py
index 3b55faafad..cd0b18f5dd 100644
--- a/sympy/physics/units/util.py
+++ b/sympy/physics/units/util.py
@@ -14,6 +14,7 @@
 from sympy.core.compatibility import reduce
 from sympy.physics.units.dimensions import Dimension, dimsys_default
 from sympy.physics.units.quantities import Quantity
+from sympy.utilities.iterables import sift
 
 
 def dim_simplify(expr):
@@ -128,3 +129,22 @@ def get_total_scale_factor(expr):
 
     expr_scale_factor = get_total_scale_factor(expr)
     return expr_scale_factor * Mul.fromiter((1/get_total_scale_factor(u) * u) ** p for u, p in zip(target_units, depmat))
+
+
+def quantity_simplify(expr):
+    if expr.is_Atom:
+        return expr
+    if not expr.is_Mul:
+        return expr.func(*map(quantity_simplify, expr.args))
+    coeff, args = expr.as_coeff_mul(Quantity)
+    args_pow = [arg.as_base_exp() for arg in args]
+    quantity_pow, other_pow = sift(args_pow, lambda x: isinstance(x[0], Quantity), binary=True)
+    quantity_pow_by_dim = sift(quantity_pow, lambda x: x[0].dimension)
+    # Just pick the first quantity:
+    ref_quantities = [i[0][0] for i in quantity_pow_by_dim.values()]
+    new_quantities = [
+        Mul.fromiter(
+            (quantity*i.scale_factor/quantity.scale_factor)**p for i, p in v)
+            if len(v) > 1 else v[0][0]**v[0][1]
+        for quantity, (k, v) in zip(ref_quantities, quantity_pow_by_dim.items())]
+    return coeff*Mul.fromiter(other_pow)*Mul.fromiter(new_quantities)
diff --git a/sympy/simplify/simplify.py b/sympy/simplify/simplify.py
index 85ed6b1412..cafd0c0931 100644
--- a/sympy/simplify/simplify.py
+++ b/sympy/simplify/simplify.py
@@ -593,6 +593,12 @@ def shorter(*choices):
     if expr.has(Product):
         expr = product_simplify(expr)
 
+    from sympy.physics.units import Quantity
+    from sympy.physics.units.util import quantity_simplify
+
+    if expr.has(Quantity):
+        expr = quantity_simplify(expr)
+
     short = shorter(powsimp(expr, combine='exp', deep=True), powsimp(expr), expr)
     short = shorter(short, cancel(short))
     short = shorter(short, factor_terms(short), expand_power_exp(expand_mul(short)))


Test patch:
diff --git a/sympy/physics/units/tests/test_util.py b/sympy/physics/units/tests/test_util.py
index 48e65e3788..1062b93dc7 100644
--- a/sympy/physics/units/tests/test_util.py
+++ b/sympy/physics/units/tests/test_util.py
@@ -112,3 +112,19 @@ def test_convert_to_tuples_of_quantities():
     assert NS(convert_to(planck_time, second), n=6) == '5.39116e-44*second'
     assert NS(convert_to(planck_temperature, kelvin), n=7) == '1.416809e+32*kelvin'
     assert NS(convert_to(convert_to(meter, [G, speed_of_light, planck]), meter), n=10) == '1.000000000*meter'
+
+
+def test_eval_simplify():
+    from sympy.physics.units import cm, mm, km, m, K, Quantity
+    from sympy.simplify.simplify import simplify
+    from sympy.core.symbol import symbols
+    from sympy.utilities.pytest import raises
+    from sympy.core.function import Lambda
+
+    x = symbols('x')
+
+    assert ((cm/mm).simplify()) == 10
+    assert ((km/m).simplify()) == 1000
+    assert ((km/cm).simplify()) == 100000
+    assert ((10*x*K*km**2/m/cm).simplify()) == 1000000000*x*kelvin
+    assert ((cm/km/m).simplify()) == 1/(100*kilometer)