Repository: sympy/sympy

Issue:
is_convergent() returns a wrong result
The code
```
expr1 = 1/n - 3/(3*n +2)
res1 = Sum(expr1, (n, 1, oo)).is_convergent()
```
returns the wrong result `False`.

The code
```
expr2 = simplify(expr1)
res2 = Sum(expr2, (n, 1, oo)).is_convergent()
```
returns the correct result `True`.

The different behaviour is in line 471 of `summations.py`. In the first case order is `1/n` (correct, but not sharp), while in the second one `n**(-2)`, which is sharp.

Discussion:

Patch:
diff --git a/sympy/matrices/common.py b/sympy/matrices/common.py
index 86c48e91b1..a21d4f9d6d 100644
--- a/sympy/matrices/common.py
+++ b/sympy/matrices/common.py
@@ -2557,10 +2557,8 @@ def multiply(self, other, dotprodsimp=None):
         isimpbool = _get_intermediate_simp_bool(False, dotprodsimp)
         other = _matrixify(other)
         # matrix-like objects can have shapes.  This is
-        # our first sanity check. Double check other is not explicitly not a Matrix.
-        if (hasattr(other, 'shape') and len(other.shape) == 2 and
-            (getattr(other, 'is_Matrix', True) or
-             getattr(other, 'is_MatrixLike', True))):
+        # our first sanity check.
+        if hasattr(other, 'shape') and len(other.shape) == 2:
             if self.shape[1] != other.shape[0]:
                 raise ShapeError("Matrix size mismatch: %s * %s." % (
                     self.shape, other.shape))
@@ -2729,10 +2727,8 @@ def __rmatmul__(self, other):
     def __rmul__(self, other):
         other = _matrixify(other)
         # matrix-like objects can have shapes.  This is
-        # our first sanity check. Double check other is not explicitly not a Matrix.
-        if (hasattr(other, 'shape') and len(other.shape) == 2 and
-            (getattr(other, 'is_Matrix', True) or
-             getattr(other, 'is_MatrixLike', True))):
+        # our first sanity check.
+        if hasattr(other, 'shape') and len(other.shape) == 2:
             if self.shape[0] != other.shape[1]:
                 raise ShapeError("Matrix size mismatch.")
 
@@ -2920,9 +2916,6 @@ def _matrixify(mat):
     if getattr(mat, 'is_Matrix', False) or getattr(mat, 'is_MatrixLike', False):
         return mat
 
-    if not(getattr(mat, 'is_Matrix', True) or getattr(mat, 'is_MatrixLike', True)):
-        return mat
-
     shape = None
 
     if hasattr(mat, 'shape'): # numpy, scipy.sparse
diff --git a/sympy/series/order.py b/sympy/series/order.py
index 362edd4ade..132cff6a2f 100644
--- a/sympy/series/order.py
+++ b/sympy/series/order.py
@@ -197,8 +197,7 @@ def __new__(cls, expr, *args, **kwargs):
             expr = expr.subs(s)
 
             if expr.is_Add:
-                from sympy import expand_multinomial
-                expr = expand_multinomial(expr)
+                expr = expr.factor()
 
             if s:
                 args = tuple([r[0] for r in rs.items()])


Test patch:
diff --git a/sympy/concrete/tests/test_sums_products.py b/sympy/concrete/tests/test_sums_products.py
index 258f98acdd..18a9f850d5 100644
--- a/sympy/concrete/tests/test_sums_products.py
+++ b/sympy/concrete/tests/test_sums_products.py
@@ -1050,6 +1050,8 @@ def test_is_convergent():
     assert Sum(1/(x**3), (x, 1, oo)).is_convergent() is S.true
     assert Sum(1/(x**S.Half), (x, 1, oo)).is_convergent() is S.false
 
+    # issue 19545
+    assert Sum(1/n - 3/(3*n +2), (n, 1, oo)).is_convergent() is S.true
 
 def test_is_absolutely_convergent():
     assert Sum((-1)**n, (n, 1, oo)).is_absolutely_convergent() is S.false
diff --git a/sympy/matrices/tests/test_commonmatrix.py b/sympy/matrices/tests/test_commonmatrix.py
index 8f87f9397e..9dcc4468e1 100644
--- a/sympy/matrices/tests/test_commonmatrix.py
+++ b/sympy/matrices/tests/test_commonmatrix.py
@@ -1,5 +1,4 @@
 from sympy.assumptions import Q
-from sympy.core.expr import Expr
 from sympy.core.add import Add
 from sympy.core.function import Function
 from sympy.core.numbers import I, Integer, oo, pi, Rational
@@ -732,22 +731,6 @@ def test_matmul():
         pass
 
 
-def test_non_matmul():
-    """
-    Test that if explicitly specified as non-matrix, mul reverts
-    to scalar multiplication.
-    """
-    class foo(Expr):
-        is_Matrix=False
-        is_MatrixLike=False
-        shape = (1, 1)
-
-    A = Matrix([[1, 2], [3, 4]])
-    b = foo()
-    assert b*A == Matrix([[b, 2*b], [3*b, 4*b]])
-    assert A*b == Matrix([[b, 2*b], [3*b, 4*b]])
-
-
 def test_power():
     raises(NonSquareMatrixError, lambda: Matrix((1, 2))**2)
 
diff --git a/sympy/series/tests/test_order.py b/sympy/series/tests/test_order.py
index f98247fd51..76f433bcec 100644
--- a/sympy/series/tests/test_order.py
+++ b/sympy/series/tests/test_order.py
@@ -376,6 +376,8 @@ def test_order_at_infinity():
     assert Order(exp(x), (x, oo)).expr == Order(2*exp(x), (x, oo)).expr == exp(x)
     assert Order(y**x, (x, oo)).expr == Order(2*y**x, (x, oo)).expr == exp(log(y)*x)
 
+    # issue 19545
+    assert Order(1/x - 3/(3*x + 2), (x, oo)).expr == x**(-2)
 
 def test_mixing_order_at_zero_and_infinity():
     assert (Order(x, (x, 0)) + Order(x, (x, oo))).is_Add