Repository: sympy/sympy

Issue:
Can't solve limit(x**2 + x*sin(x) + cos(x), x, -oo) 
`limit(x**2 + x*sin(x) + cos(x), x, -oo)` should return oo

Discussion:

Patch:
diff --git a/sympy/series/limits.py b/sympy/series/limits.py
index bfc0d7ecf3..1a5bc279f4 100644
--- a/sympy/series/limits.py
+++ b/sympy/series/limits.py
@@ -11,7 +11,8 @@
 from .gruntz import gruntz
 from sympy.core.exprtools import factor_terms
 from sympy.simplify.ratsimp import ratsimp
-from sympy.polys import PolynomialError
+from sympy.polys import PolynomialError, factor
+from sympy.simplify.simplify import together
 
 def limit(e, z, z0, dir="+"):
     """
@@ -60,6 +61,15 @@ def heuristics(e, z, z0, dir):
         for a in e.args:
             l = limit(a, z, z0, dir)
             if l.has(S.Infinity) and l.is_finite is None:
+                if isinstance(e, Add):
+                    m = factor_terms(e)
+                    if not isinstance(m, Mul): # try together
+                        m = together(m)
+                    if not isinstance(m, Mul): # try factor if the previous methods failed
+                        m = factor(e)
+                    if isinstance(m, Mul):
+                        return heuristics(m, z, z0, dir)
+                    return
                 return
             elif isinstance(l, Limit):
                 return


Test patch:
diff --git a/sympy/series/tests/test_limits.py b/sympy/series/tests/test_limits.py
index 627517526f..807696428f 100644
--- a/sympy/series/tests/test_limits.py
+++ b/sympy/series/tests/test_limits.py
@@ -505,3 +505,11 @@ def test_issue_6599():
 def test_issue_12555():
     assert limit((3**x + 2* x**10) / (x**10 + exp(x)), x, -oo) == 2
     assert limit((3**x + 2* x**10) / (x**10 + exp(x)), x, oo) == oo
+
+def test_issue_12564():
+    assert limit(x**2 + x*sin(x) + cos(x), x, -oo) == oo
+    assert limit(x**2 + x*sin(x) + cos(x), x, oo) == oo
+    assert limit(((x + cos(x))**2).expand(), x, oo) == oo
+    assert limit(((x + sin(x))**2).expand(), x, oo) == oo
+    assert limit(((x + cos(x))**2).expand(), x, -oo) == oo
+    assert limit(((x + sin(x))**2).expand(), x, -oo) == oo