Repository: sympy/sympy

Issue:
ValueError in subs
`(-512*b**3).subs(-2*b,-a+m)` gives `ValueError: negative shift count`

Discussion:

Patch:
diff --git a/sympy/combinatorics/fp_groups.py b/sympy/combinatorics/fp_groups.py
index afb0799c01..46e9ef6adb 100644
--- a/sympy/combinatorics/fp_groups.py
+++ b/sympy/combinatorics/fp_groups.py
@@ -297,125 +297,50 @@ class FpSubgroup(DefaultPrinting):
     group belongs to the subgroup
 
     '''
-    def __init__(self, G, gens, normal=False):
+    def __init__(self, G, gens):
         super(FpSubgroup,self).__init__()
         self.parent = G
         self.generators = list(set([g for g in gens if g != G.identity]))
         self._min_words = None #for use in __contains__
         self.C = None
-        self.normal = normal
 
     def __contains__(self, g):
-
-        if isinstance(self.parent, FreeGroup):
-            if self._min_words is None:
-                # make _min_words - a list of subwords such that
-                # g is in the subgroup if and only if it can be
-                # partitioned into these subwords. Infinite families of
-                # subwords are presented by tuples, e.g. (r, w)
-                # stands fot the family of subwords r*w**n*r**-1
-
-                def _process(w):
-                    # this is to be used before adding new words
-                    # into _min_words; if the word w is not cyclically
-                    # reduced, it will generate an infinite family of
-                    # subwords so should be written as a tuple;
-                    # if it is, w**-1 should be added to the list
-                    # as well
-                    p, r = w.cyclic_reduction(removed=True)
-                    if not r.is_identity:
-                        return [(r, p)]
-                    else:
-                        return [w, w**-1]
-
-                # make the initial list
-                gens = []
-                for w in self.generators:
-                    if self.normal:
-                        w = w.cyclic_reduction()
-                    gens.extend(_process(w))
-
-                for w1 in gens:
-                    for w2 in gens:
-                        # if w1 and w2 are equal or are inverses, continue
-                        if w1 == w2 or (not isinstance(w1, tuple)
-                                                        and w1**-1 == w2):
-                            continue
-
-                        # if the start of one word is the inverse of the
-                        # end of the other, their multuple should be added
-                        # to _min_words because of cancellation
-                        if isinstance(w1, tuple):
-                            # start, end
-                            s1, s2 = w1[0][0], w1[0][0]**-1
-                        else:
-                            s1, s2 = w1[0], w1[len(w1)-1]
-
-                        if isinstance(w2, tuple):
-                            # start, end
-                            r1, r2 = w2[0][0], w2[0][0]**-1
-                        else:
-                            r1, r2 = w2[0], w2[len(w1)-1]
-
-                        # p1 and p2 are w1 and w2 or, in case when
-                        # w1 or w2 is an infinite family, a representative
-                        p1, p2 = w1, w2
-                        if isinstance(w1, tuple):
-                            p1 = w1[0]*w1[1]*w1[0]**-1
-                        if isinstance(w2, tuple):
-                            p2 = w2[0]*w2[1]*w2[0]**-1
-
-                        # add the product of the words to the list is necessary
-                        if r1**-1 == s2 and not (p1*p2).is_identity:
-                            new = _process(p1*p2)
-                            if not new in gens:
-                                gens.extend(new)
-
-                        if r2**-1 == s1 and not (p2*p1).is_identity:
-                            new = _process(p2*p1)
-                            if not new in gens:
-                                gens.extend(new)
-
-                self._min_words = gens
-
-            min_words = self._min_words
-
-            def _is_subword(w):
-                # check if w is a word in _min_words or one of
-                # the infinite families in it
-                w, r = w.cyclic_reduction(removed=True)
-                if r.is_identity or self.normal:
-                    return w in min_words
-                else:
-                    t = [s[1] for s in min_words if isinstance(s, tuple)
-                                                                and s[0] == r]
-                    return [s for s in t if w.power_of(s)] != []
-
-            # store the solution of words for which the result of
-            # _word_break (below) is known
-            known = {}
-
-            def _word_break(w):
-                # check if w can be written as a product of words
-                # in min_words
-                if len(w) == 0:
-                    return True
-                i = 0
-                while i < len(w):
-                    i += 1
-                    prefix = w.subword(0, i)
-                    if not _is_subword(prefix):
+        if self._min_words is None:
+            gens = self.generators[:]
+            gens.extend([e**-1 for e in gens])
+            for w1 in gens:
+                for w2 in gens:
+                    if w2**-1 == w1:
                         continue
-                    rest = w.subword(i, len(w))
-                    if rest not in known:
-                        known[rest] = _word_break(rest)
-                    if known[rest]:
-                        return True
-                return False
-
-            if self.normal:
-                g = g.cyclic_reduction()
-            return _word_break(g)
+                    if w2[len(w2)-1]**-1 == w1[0] and w2*w1 not in gens:
+                        gens.append(w2*w1)
+                    if w2[0]**-1 == w1[len(w1)-1] and w1*w2 not in gens:
+                        gens.append(w1*w2)
+            self._min_words = gens
+
+        min_words = self._min_words
+        known = {} #to keep track of words
+
+        def _word_break(w):
+            if len(w) == 0:
+                return True
+            i = 0
+            while i < len(w):
+                i += 1
+                prefix = w.subword(0, i)
+                if prefix not in min_words:
+                    continue
+                rest = w.subword(i, len(w))
+                if rest not in known:
+                    known[rest] = _word_break(rest)
+                if known[rest]:
+                    return True
+            return False
+
+        if _word_break(g):
+            return True
+        elif isinstance(self.parent, FreeGroup):
+            return False
         else:
             if self.C is None:
                 C = self.parent.coset_enumeration(self.generators)
@@ -444,15 +369,6 @@ def to_FpGroup(self):
             return free_group(', '.join(gen_syms))[0]
         return self.parent.subgroup(C=self.C)
 
-    def __str__(self):
-        if len(self.generators) > 30:
-            str_form = "<fp subgroup with %s generators>" % len(self.generators)
-        else:
-            str_form = "<fp subgroup on the generators %s>" % str(self.generators)
-        return str_form
-
-    __repr__ = __str__
-
 
 ###############################################################################
 #                           LOW INDEX SUBGROUPS                               #
diff --git a/sympy/combinatorics/free_groups.py b/sympy/combinatorics/free_groups.py
index 4790170206..d4af202584 100644
--- a/sympy/combinatorics/free_groups.py
+++ b/sympy/combinatorics/free_groups.py
@@ -1207,89 +1207,6 @@ def identity_cyclic_reduction(self):
             word = group.dtype(rep)
         return word
 
-    def cyclic_reduction(self, removed=False):
-        """Return a cyclically reduced version of the word. Unlike
-        `identity_cyclic_reduction`, this will not cyclically permute
-        the reduced word - just remove the "unreduced" bits on either
-        side of it. Compare the examples with those of
-        `identity_cyclic_reduction`.
-
-        When `removed` is `True`, return a tuple `(word, r)` where
-        self `r` is such that before the reductin the word was either
-        `r*word*r**-1`.
-
-        Examples
-        ========
-
-        >>> from sympy.combinatorics.free_groups import free_group
-        >>> F, x, y = free_group("x, y")
-        >>> (x**2*y**2*x**-1).cyclic_reduction()
-        x*y**2
-        >>> (x**-3*y**-1*x**5).cyclic_reduction()
-        y**-1*x**2
-        >>> (x**-3*y**-1*x**5).cyclic_reduction(removed=True)
-        (y**-1*x**2, x**-3)
-
-        """
-        word = self.copy()
-        group = self.group
-        g = self.group.identity
-        while not word.is_cyclically_reduced():
-            exp1 = abs(word.exponent_syllable(0))
-            exp2 = abs(word.exponent_syllable(-1))
-            exp = min(exp1, exp2)
-            start = word[0]**abs(exp)
-            end = word[-1]**abs(exp)
-            word = start**-1*word*end**-1
-            g = g*start
-        if removed:
-            return word, g
-        return word
-
-    def power_of(self, other):
-        '''
-        Check if `self == other**n` for some integer n.
-
-        Examples
-        ========
-
-        >>> from sympy.combinatorics.free_groups import free_group
-        >>> F, x, y = free_group("x, y")
-        >>> ((x*y)**2).power_of(x*y)
-        True
-        >>> (x**-3*y**-2*x**3).power_of(x**-3*y*x**3)
-        True
-
-        '''
-        if self.is_identity:
-            return True
-
-        l = len(other)
-        if l == 1:
-            # self has to be a power of one generator
-            gens = self.contains_generators()
-            s = other in gens or other**-1 in gens
-            return len(gens) == 1 and s
-
-        # if self is not cyclically reduced and it is a power of other,
-        # other isn't cyclically reduced and the parts removed during
-        # their reduction must be equal
-        reduced, r1 = self.cyclic_reduction(removed=True)
-        if not r1.is_identity:
-            other, r2 = other.cyclic_reduction(removed=True)
-            if r1 == r2:
-                return reduced.power_of(other)
-            return False
-
-        if len(self) < l or len(self) % l:
-            return False
-
-        prefix = self.subword(0, l)
-        if prefix == other or prefix**-1 == other:
-            rest = self.subword(l, len(self))
-            return rest.power_of(other)
-        return False
-
 
 def letter_form_to_array_form(array_form, group):
     """
diff --git a/sympy/combinatorics/homomorphisms.py b/sympy/combinatorics/homomorphisms.py
index fd85e94373..6501c835c4 100644
--- a/sympy/combinatorics/homomorphisms.py
+++ b/sympy/combinatorics/homomorphisms.py
@@ -84,14 +84,14 @@ def _compute_kernel(self):
             raise NotImplementedError(
                 "Kernel computation is not implemented for infinite groups")
         gens = []
-        K = FpSubgroup(G, gens, normal=True)
+        K = FpSubgroup(G, gens)
         i = self.image().order()
         while K.order()*i != G_order:
             r = G.random_element()
             k = r*self.invert(self(r))
             if not k in K:
                 gens.append(k)
-                K = FpSubgroup(G, gens, normal=True)
+                K = FpSubgroup(G, gens)
         return K
 
     def image(self):
diff --git a/sympy/core/evalf.py b/sympy/core/evalf.py
index c794656514..2ddc332158 100644
--- a/sympy/core/evalf.py
+++ b/sympy/core/evalf.py
@@ -32,7 +32,9 @@
 
 
 def bitcount(n):
-    return mpmath_bitcount(int(n))
+    """Return smallest integer, b, such that |n|/2**b < 1.
+    """
+    return mpmath_bitcount(abs(int(n)))
 
 # Used in a few places as placeholder values to denote exponents and
 # precision levels, e.g. of exact numbers. Must be careful to avoid
diff --git a/sympy/functions/elementary/miscellaneous.py b/sympy/functions/elementary/miscellaneous.py
index 24fcbb87e3..198a197a06 100644
--- a/sympy/functions/elementary/miscellaneous.py
+++ b/sympy/functions/elementary/miscellaneous.py
@@ -354,32 +354,6 @@ def __new__(cls, *args, **assumptions):
             obj._argset = _args
             return obj
 
-    def _eval_simplify(self, ratio, measure):
-        # simplify Min(foo, y, Max(foo, x)) to Min(foo, y)
-        # Like And/Or, anything in common between the two
-        # is cause to eliminate the opposite arg.
-        cls = self.func
-        if cls == Min:
-            op = Max
-        elif cls == Max:
-            op = Min
-        else:
-            op = None
-        if op:
-            unnested = set()
-            nested = []
-            remove = []
-            for a in self.args:
-                if isinstance(a, op):
-                    nested.append(a)
-                else:
-                    unnested.add(a)
-            N = len(nested) - 1
-            for i, n in enumerate(reversed(nested)):
-                if set(n.args) & unnested:
-                    nested.pop(N - i)
-            return cls(*(list(unnested) + nested))
-
     @classmethod
     def _new_args_filter(cls, arg_sequence):
         """
diff --git a/sympy/integrals/intpoly.py b/sympy/integrals/intpoly.py
index da84e0f5f5..fc72bd206f 100644
--- a/sympy/integrals/intpoly.py
+++ b/sympy/integrals/intpoly.py
@@ -556,7 +556,7 @@ def decompose(expr, separate=False):
     >>> decompose(x**2 + x*y + x + y + x**3*y**2 + y**5)
     {1: x + y, 2: x**2 + x*y, 5: x**3*y**2 + y**5}
     >>> decompose(x**2 + x*y + x + y + x**3*y**2 + y**5, True)
-    {x, x**2, y, y**5, x*y, x**3*y**2}
+    [x, y, x**2, y**5, x*y, x**3*y**2]
     """
     expr = S(expr)
     poly_dict = {}
@@ -569,7 +569,7 @@ def decompose(expr, separate=False):
             degrees = [(sum(degree_list(monom, *symbols)), monom)
                        for monom in expr.args]
             if separate:
-                return {monom[1] for monom in degrees}
+                return [monom[1] for monom in degrees]
             else:
                 for monom in degrees:
                     degree, term = monom
@@ -593,7 +593,7 @@ def decompose(expr, separate=False):
         poly_dict[0] = expr
 
     if separate:
-        return set(poly_dict.values())
+        return list(poly_dict.values())
     return poly_dict
 
 
diff --git a/sympy/logic/boolalg.py b/sympy/logic/boolalg.py
index 9da8a80b61..113232ab6b 100644
--- a/sympy/logic/boolalg.py
+++ b/sympy/logic/boolalg.py
@@ -1321,7 +1321,7 @@ def eliminate_implications(expr):
     >>> eliminate_implications(Equivalent(A, B, C))
     (A | ~C) & (B | ~A) & (C | ~B)
     """
-    return to_nnf(expr, simplify=False)
+    return to_nnf(expr)
 
 
 def is_literal(expr):
diff --git a/sympy/ntheory/factor_.py b/sympy/ntheory/factor_.py
index 9e8f557d94..bc83e08dc5 100644
--- a/sympy/ntheory/factor_.py
+++ b/sympy/ntheory/factor_.py
@@ -166,7 +166,7 @@ def trailing(n):
     >>> trailing(63)
     0
     """
-    n = int(n)
+    n = abs(int(n))
     if not n:
         return 0
     low_byte = n & 0xff
diff --git a/sympy/physics/units/__init__.py b/sympy/physics/units/__init__.py
index da394d8c8b..195cb83854 100644
--- a/sympy/physics/units/__init__.py
+++ b/sympy/physics/units/__init__.py
@@ -180,14 +180,6 @@
     planck_time,
     planck_temperature,
     planck_length,
-    bit, bits,
-    byte,
-    kibibyte, kibibytes,
-    mebibyte, mebibytes,
-    gibibyte, gibibytes,
-    tebibyte, tebibytes,
-    pebibyte, pebibytes,
-    exbibyte, exbibytes,
 )
 
 
diff --git a/sympy/physics/units/definitions.py b/sympy/physics/units/definitions.py
index 05da8059f0..b4c38d0572 100644
--- a/sympy/physics/units/definitions.py
+++ b/sympy/physics/units/definitions.py
@@ -2,12 +2,11 @@
 from sympy.physics.units import Quantity
 from sympy.physics.units.dimensions import (
     acceleration, action, amount_of_substance, capacitance, charge,
-    conductance, current, energy, force, frequency, information, impedance, inductance,
+    conductance, current, energy, force, frequency, impedance, inductance,
     length, luminous_intensity, magnetic_density, magnetic_flux, mass, power,
     pressure, temperature, time, velocity, voltage)
 from sympy.physics.units.prefixes import (
-    centi, deci, kilo, micro, milli, nano, pico,
-    kibi, mebi, gibi, tebi, pebi, exbi)
+    centi, deci, kilo, micro, milli, nano, pico)
 
 #### UNITS ####
 
@@ -171,13 +170,3 @@
 planck_temperature = Quantity("planck_temperature", temperature, sqrt(hbar*speed_of_light**5/G/boltzmann**2), "T_P")
 planck_length = Quantity("planck_length", length, sqrt(hbar*G/speed_of_light**3), "l_P")
 # TODO: add more from https://en.wikipedia.org/wiki/Planck_units
-
-# Information theory units:
-bit = bits = Quantity('bit', information, 1)
-byte = bytes = Quantity('byte', information, 8*bit)
-kibibyte = kibibytes = Quantity('kibibyte', information, kibi*byte)
-mebibyte = mebibytes = Quantity('mebibyte', information, mebi*byte)
-gibibyte = gibibytes = Quantity('gibibyte', information, gibi*byte)
-tebibyte = tebibytes = Quantity('tebibyte', information, tebi*byte)
-pebibyte = pebibytes = Quantity('pebibyte', information, pebi*byte)
-exbibyte = exbibytes = Quantity('exbibyte', information, exbi*byte)
diff --git a/sympy/physics/units/dimensions.py b/sympy/physics/units/dimensions.py
index 771aca85ac..ec99014b9b 100644
--- a/sympy/physics/units/dimensions.py
+++ b/sympy/physics/units/dimensions.py
@@ -272,9 +272,6 @@ def has_integer_powers(self):
 magnetic_density = Dimension(name='magnetic_density', symbol='B')
 magnetic_flux = Dimension(name='magnetic_flux')
 
-# Dimensions in information theory:
-information = Dimension(name='information')
-
 # Create dimensions according the the base units in MKSA.
 # For other unit systems, they can be derived by transforming the base
 # dimensional dependency dictionary.
@@ -292,8 +289,6 @@ def has_integer_powers(self):
 amount_of_substance._register_as_base_dim()
 luminous_intensity._register_as_base_dim()
 
-information._register_as_base_dim()
-
 # Dimensional dependencies for derived dimensions
 Dimension._dimensional_dependencies["velocity"] = dict(length=1, time=-1)
 Dimension._dimensional_dependencies["acceleration"] = dict(length=1, time=-2)
diff --git a/sympy/tensor/tensor.py b/sympy/tensor/tensor.py
index 88314bd589..0dbd50de8a 100644
--- a/sympy/tensor/tensor.py
+++ b/sympy/tensor/tensor.py
@@ -33,7 +33,7 @@
 
 from collections import defaultdict
 import itertools
-from sympy import Matrix, Rational, prod, Integer
+from sympy import Matrix, Rational, prod
 from sympy.combinatorics.tensor_can import get_symmetric_group_sgs, \
     bsgs_direct_product, canonicalize, riemann_bsgs
 from sympy.core import Basic, sympify, Add, S
@@ -1723,7 +1723,7 @@ def get_kronecker_delta(self):
         return delta
 
     def get_epsilon(self):
-        if not isinstance(self._eps_dim, (int, Integer)):
+        if not isinstance(self._eps_dim, int):
             return None
         sym = TensorSymmetry(get_symmetric_group_sgs(self._eps_dim, 1))
         Sdim = TensorType([self]*self._eps_dim, sym)
diff --git a/sympy/vector/coordsysrect.py b/sympy/vector/coordsysrect.py
index 5fba3b983b..9e17b78143 100644
--- a/sympy/vector/coordsysrect.py
+++ b/sympy/vector/coordsysrect.py
@@ -407,30 +407,6 @@ def _rotation_trans_equations(self, matrix):
 
         return trans_eq1, trans_eq2, trans_eq3
 
-    def _translation_trans_equations(self, inverse=False):
-        """
-        Returns the transformation equations obtained from translation
-        vector. Translation vector is defined as a linking vector of
-        origins of two coordinate systems.
-
-        """
-        if inverse:
-            sign = -1
-        else:
-            sign = 1
-
-        if self._parent is None:
-            return self.base_scalars()
-        else:
-            vec_component = self._origin.position_wrt(self._parent).components
-            vec_norm_projections = []
-            for i in self._parent.base_vectors():
-                try:
-                    vec_norm_projections.append(sign * vec_component[i])
-                except:
-                    vec_norm_projections.append(0)
-            return tuple([sum(i) for i in zip(vec_norm_projections, self.base_scalars())])
-
     @property
     def origin(self):
         return self._origin


Test patch:
diff --git a/sympy/assumptions/tests/test_query.py b/sympy/assumptions/tests/test_query.py
index 7014f23401..1f0d7fbfea 100644
--- a/sympy/assumptions/tests/test_query.py
+++ b/sympy/assumptions/tests/test_query.py
@@ -1789,7 +1789,9 @@ def test_nonnegative():
     assert ask(Q.nonnegative(sqrt(-1))) is False
     assert ask(Q.nonnegative(x), Q.imaginary(x)) is False
 
-def test_real_basic():
+
+@slow
+def test_real():
     assert ask(Q.real(x)) is None
     assert ask(Q.real(x), Q.real(x)) is True
     assert ask(Q.real(x), Q.nonzero(x)) is True
@@ -1811,8 +1813,6 @@ def test_real_basic():
     assert ask(Q.real(I*x), Q.imaginary(x)) is True
     assert ask(Q.real(I*x), Q.complex(x)) is None
 
-@slow
-def test_real_pow():
     assert ask(Q.real(x**2), Q.real(x)) is True
     assert ask(Q.real(sqrt(x)), Q.negative(x)) is False
     assert ask(Q.real(x**y), Q.real(x) & Q.integer(y)) is True
@@ -1839,7 +1839,6 @@ def test_real_pow():
     assert ask(Q.real(x**i), Q.imaginary(i)) is None  # x could be 0
     assert ask(Q.real(x**(I*pi/log(x))), Q.real(x)) is True
 
-def test_real_functions():
     # trigonometric functions
     assert ask(Q.real(sin(x))) is None
     assert ask(Q.real(cos(x))) is None
diff --git a/sympy/combinatorics/tests/test_fp_groups.py b/sympy/combinatorics/tests/test_fp_groups.py
index 5325fe0035..635b9631a7 100644
--- a/sympy/combinatorics/tests/test_fp_groups.py
+++ b/sympy/combinatorics/tests/test_fp_groups.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 from sympy import S
 from sympy.combinatorics.fp_groups import (FpGroup, low_index_subgroups,
-                                   reidemeister_presentation, FpSubgroup)
+                                           reidemeister_presentation)
 from sympy.combinatorics.free_groups import free_group
 
 """
@@ -158,13 +158,3 @@ def test_order():
     F, a, b, c = free_group("a, b, c")
     f = FpGroup(F, [a**250, b**2, c*b*c**-1*b, c**4, c**-1*a**-1*c*a, a**-1*b**-1*a*b])
     assert f.order() == 2000
-
-def test_fp_subgroup():
-    F, x, y = free_group("x, y")
-    f = FpGroup(F, [x**4, y**2, x*y*x**-1*y])
-    S = FpSubgroup(f, [x*y])
-    assert (x*y)**-3 in S
-
-    S = FpSubgroup(F, [x**-1*y*x])
-    assert x**-1*y**4*x in S
-    assert x**-1*y**4*x**2 not in S
diff --git a/sympy/functions/elementary/tests/test_miscellaneous.py b/sympy/functions/elementary/tests/test_miscellaneous.py
index 8738b3b92a..1fb2ccd184 100644
--- a/sympy/functions/elementary/tests/test_miscellaneous.py
+++ b/sympy/functions/elementary/tests/test_miscellaneous.py
@@ -369,10 +369,3 @@ def test_issue_11099():
             Min(x, y).subs(random_test_data).evalf()
         assert Max(x, y).evalf(subs=random_test_data) == \
             Max(x, y).subs(random_test_data).evalf()
-
-
-def test_issue_12638():
-    from sympy.abc import a, b, c, d
-    assert Min(a, b, c, Max(a, b)).simplify() == Min(a, b, c)
-    assert Min(a, b, Max(a, b, c)).simplify() == Min(a, b)
-    assert Min(a, b, Max(a, c)).simplify() == Min(a, b)
diff --git a/sympy/integrals/tests/test_intpoly.py b/sympy/integrals/tests/test_intpoly.py
index 80dee95dca..1e0cc29731 100644
--- a/sympy/integrals/tests/test_intpoly.py
+++ b/sympy/integrals/tests/test_intpoly.py
@@ -26,15 +26,15 @@ def test_decompose():
     assert decompose(9*x**2 + y + 4*x + x**3 + y**2*x + 3) ==\
         {0: 3, 1: 4*x + y, 2: 9*x**2, 3: x**3 + x*y**2}
 
-    assert decompose(x, True) == {x}
-    assert decompose(x ** 2, True) == {x**2}
-    assert decompose(x * y, True) == {x * y}
-    assert decompose(x + y, True) == {x, y}
-    assert decompose(x ** 2 + y, True) == {y, x ** 2}
-    assert decompose(8 * x ** 2 + 4 * y + 7, True) == {7, 4*y, 8*x**2}
-    assert decompose(x ** 2 + 3 * y * x, True) == {x ** 2, 3 * x * y}
+    assert decompose(x, True) == [x]
+    assert decompose(x ** 2, True) == [x ** 2]
+    assert decompose(x * y, True) == [x * y]
+    assert decompose(x + y, True) == [x, y]
+    assert decompose(x ** 2 + y, True) == [y, x ** 2]
+    assert decompose(8 * x ** 2 + 4 * y + 7, True) == [7, 4*y, 8*x**2]
+    assert decompose(x ** 2 + 3 * y * x, True) == [x ** 2, 3 * x * y]
     assert decompose(9 * x ** 2 + y + 4 * x + x ** 3 + y ** 2 * x + 3, True) == \
-           {3, y, 4*x, 9*x**2, x*y**2, x**3}
+           [3, y, x**3, 4*x, 9*x**2, x*y**2]
 
 
 def test_best_origin():
diff --git a/sympy/ntheory/tests/test_factor_.py b/sympy/ntheory/tests/test_factor_.py
index 7b4c4fbd56..ea8bbcc9b6 100644
--- a/sympy/ntheory/tests/test_factor_.py
+++ b/sympy/ntheory/tests/test_factor_.py
@@ -1,6 +1,7 @@
 from sympy import (Sieve, binomial_coefficients, binomial_coefficients_list,
     Mul, S, Pow, sieve, Symbol, summation, Dummy,
     factorial as fac)
+from sympy.core.evalf import bitcount
 from sympy.core.numbers import Integer, Rational
 from sympy.core.compatibility import long, range
 
@@ -12,7 +13,7 @@
     factorrat, reduced_totient)
 from sympy.ntheory.factor_ import (smoothness, smoothness_p,
     antidivisors, antidivisor_count, core, digits, udivisors, udivisor_sigma,
-    udivisor_count, primenu, primeomega)
+    udivisor_count, primenu, primeomega, small_trailing)
 from sympy.ntheory.generate import cycle_length
 from sympy.ntheory.multinomial import (
     multinomial_coefficients, multinomial_coefficients_iterator)
@@ -66,7 +67,7 @@ def multiproduct(seq=(), start=1):
     return units * multiproduct(multi)**2
 
 
-def test_trailing():
+def test_trailing_bitcount():
     assert trailing(0) == 0
     assert trailing(1) == 0
     assert trailing(-1) == 0
@@ -78,6 +79,10 @@ def test_trailing():
         assert trailing((1 << i) * 31337) == i
     assert trailing((1 << 1000001)) == 1000001
     assert trailing((1 << 273956)*7**37) == 273956
+    # issue 12709
+    big = small_trailing[-1]*2
+    assert trailing(-big) == trailing(big)
+    assert bitcount(-big) == bitcount(big)
 
 
 def test_multiplicity():
diff --git a/sympy/physics/units/tests/test_quantities.py b/sympy/physics/units/tests/test_quantities.py
index 97e7f215c7..bc551e8ba1 100644
--- a/sympy/physics/units/tests/test_quantities.py
+++ b/sympy/physics/units/tests/test_quantities.py
@@ -10,8 +10,7 @@
 from sympy.physics.units.definitions import (
     amu, au, centimeter, coulomb, day, foot, grams, hour, inch, kg, km, m,
     meter, mile, millimeter, minute, mole, quart, s, second, speed_of_light,
-    steradian,
-    bit, byte, kibibyte, mebibyte, gibibyte, tebibyte, pebibyte, exbibyte)
+    steradian)
 from sympy.physics.units.dimensions import Dimension, charge, length, time
 from sympy.physics.units.prefixes import PREFIXES, kilo
 from sympy.physics.units.quantities import Quantity
@@ -306,21 +305,3 @@ def test_get_dimensional_expr_with_function():
     v_w1 = Quantity('v_w1', length / time, meter / second)
     assert Quantity.get_dimensional_expr(sin(v_w1)) == \
         sin(Quantity.get_dimensional_expr(v_w1))
-
-
-def test_binary_information():
-    assert convert_to(kibibyte, byte) == 1024*byte
-    assert convert_to(mebibyte, byte) == 1024**2*byte
-    assert convert_to(gibibyte, byte) == 1024**3*byte
-    assert convert_to(tebibyte, byte) == 1024**4*byte
-    assert convert_to(pebibyte, byte) == 1024**5*byte
-    assert convert_to(exbibyte, byte) == 1024**6*byte
-
-    assert kibibyte.convert_to(bit) == 8*1024*bit
-    assert byte.convert_to(bit) == 8*bit
-
-    a = 10*kibibyte*hour
-
-    assert convert_to(a, byte) == 10240*byte*hour
-    assert convert_to(a, minute) == 600*kibibyte*minute
-    assert convert_to(a, [byte, minute]) == 614400*byte*minute
diff --git a/sympy/tensor/tests/test_tensor.py b/sympy/tensor/tests/test_tensor.py
index 9f6105fd3a..6de5b79b28 100644
--- a/sympy/tensor/tests/test_tensor.py
+++ b/sympy/tensor/tests/test_tensor.py
@@ -1,16 +1,17 @@
-from sympy import Matrix, eye, Integer
+from sympy import Matrix, eye
 from sympy.combinatorics import Permutation
 from sympy.core import S, Rational, Symbol, Basic
 from sympy.core.containers import Tuple
 from sympy.core.symbol import symbols
+from sympy.external import import_module
 from sympy.functions.elementary.miscellaneous import sqrt
 from sympy.printing.pretty.pretty import pretty
 from sympy.tensor.array import Array
 from sympy.tensor.tensor import TensorIndexType, tensor_indices, TensorSymmetry, \
     get_symmetric_group_sgs, TensorType, TensorIndex, tensor_mul, TensAdd, \
     riemann_cyclic_replace, riemann_cyclic, TensMul, tensorsymmetry, tensorhead, \
-    TensorManager, TensExpr, TIDS, TensorHead
-from sympy.utilities.pytest import raises
+    TensorManager, TensExpr, TIDS
+from sympy.utilities.pytest import raises, skip
 from sympy.core.compatibility import range
 
 
@@ -1001,7 +1002,6 @@ def test_metric_contract3():
     t1 = t.contract_metric(C)
     assert _is_equal(t1, B(-a2,a1)*psi(-a1))
 
-
 def test_epsilon():
     Lorentz = TensorIndexType('Lorentz', dim=4, dummy_fmt='L')
     a, b, c, d, e = tensor_indices('a,b,c,d,e', Lorentz)
@@ -1041,11 +1041,6 @@ def test_epsilon():
     t1 = t.canon_bp()
     assert t1 == -2*epsilon(c, d, a, b)*p(-a)*q(-b)
 
-    # Test that epsilon can be create with a SymPy integer:
-    Lorentz = TensorIndexType('Lorentz', dim=Integer(4), dummy_fmt='L')
-    epsilon = Lorentz.epsilon
-    assert isinstance(epsilon, TensorHead)
-
 def test_contract_delta1():
     # see Group Theory by Cvitanovic page 9
     n = Symbol('n')
diff --git a/sympy/vector/tests/test_coordsysrect.py b/sympy/vector/tests/test_coordsysrect.py
index ba98e58d7a..4c6118ec14 100644
--- a/sympy/vector/tests/test_coordsysrect.py
+++ b/sympy/vector/tests/test_coordsysrect.py
@@ -399,17 +399,3 @@ def test_rotation_trans_equations():
            (-sin(q0) * c.y + cos(q0) * c.x, sin(q0) * c.x + cos(q0) * c.y, c.z)
     assert c._rotation_trans_equations(c._inverse_rotation_matrix()) == \
            (sin(q0) * c.y + cos(q0) * c.x, -sin(q0) * c.x + cos(q0) * c.y, c.z)
-
-def test_translation_trans_equations():
-    from sympy import symbols
-    q0 = symbols('q0')
-    a = CoordSys3D('a')
-    assert a._translation_trans_equations() == (a.x, a.y, a.z)
-    b = a.locate_new('b', None)
-    assert b._translation_trans_equations() == (b.x, b.y, b.z)
-    assert b._translation_trans_equations(inverse=True) == (b.x, b.y, b.z)
-    c = a.locate_new('c', (a.i + a.j + a.k))
-    assert c._translation_trans_equations() == (c.x + 1, c.y + 1, c.z + 1)
-    d = a.locate_new('d', (a.i + a.j + Vector.zero))
-    assert d._translation_trans_equations() == (d.x + 1, d.y + 1, d.z)
-    assert d._translation_trans_equations(inverse=True) == (d.x - 1, d.y - 1, d.z)