Repository: sympy/sympy
Pull request: Limit comparison test introduced
Fixes #14111 
Fixes #14484 

This PR introduces a new way of finding whether a `Sum` series is `convergent` or not. The `Limit Comparison Test` has been added in the `is_convergent` method.
See [here](https://math.oregonstate.edu/home/programs/undergrad/CalculusQuestStudyGuides/SandS/SeriesTests/limit_comparison.html) for more theory about how the Limit Comparison test works.

I have compared the `sequence_term` with `Sum(1/n, (n, 1, oo))` because we know that the harmonic series diverges, and if the limit turns out to be infinite, then the series in question, is `divergent`. Only the comparison for divergence has been implemented.

Also, it fixes the `TypeError` returned by `Sum(sin(n)/log(log(n)), (n, 22, oo)).is_convergent()`, according to @jksuom 's [comment](https://github.com/sympy/sympy/pull/14401#issuecomment-372310836).

@normalhuman @jksuom Please review.

Problem statement:
Sum(1/log(log(n)), (n, 22, oo)).is_convergent() not implemented
`>>> Sum(1/log(log(n)), (n, 22, oo)).is_convergent()`
Traceback (most recent call last):

  File "<ipython-input-19-50f193f491f8>", line 1, in <module>
    Sum(1/log(log(n)), (n, 22, oo)).is_convergent()

  File ".\sympy\concrete\summations.py", line 528, in is_convergent
    "is not yet implemented" % (sequence_term))

NotImplementedError: The algorithm to find the Sum convergence of 1/log(log(n)) is not yet implemented



Could someone please tell me the way to put the whole thing in code form
When I try to put the whole thing in code form, with that symbol under the tilde at the start and at the end , then none of it appears in code form

Is this a flaw in the is_convergent program
That whenever it encounters a sum whose convergence is unknown, it cause an error 

Sum(sin(n)/log(log(n)), (n, 22, oo)).is_convergent() returns `Type Error`
Following error appears in master branch.

```
>>> n = symbols('n')
>>> Sum(sin(n)/log(log(n)), (n, 22, oo)).is_convergent()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/concrete/summations.py", line 442, in is_convergent
    if abs(lim_ratio) > 1:
  File "sympy/core/relational.py", line 229, in __nonzero__
    raise TypeError("cannot determine truth value of Relational")
TypeError: cannot determine truth value of Relational
```

Hints from issue discussion:
You can post a code block by surrounding it with triple backticks ``` (so-called code walls). For example
```
>>> Sum(1/log(log(n)), (n, 22, oo)).is_convergent()
NotImplementedError: The algorithm to find the Sum convergence of 1/log(log(n)) is not yet implemented
```
> whenever it encounters a sum whose convergence is unknown, it cause an error

When a Python program encounters an input for which it does not have an algorithm, it may raise NotImplementedError to inform the user about its limitation. The docstring of the `is_convergent` method says as much:

> There are various tests employed to check the convergence like divergence test, root test, integral test, alternating series test, comparison tests, Dirichlet tests. It returns true if Sum is convergent and false if divergent and NotImplementedError if it can not be checked.

So rather than writing "causes an error" it would be more accurate to say "is not implemented" in the title.
> You can post a code block by surrounding it with triple backticks ```

I put 3 backticks at the beginning and at the end
It put multiple lines in code form, but 1 line was lost and the 3 backticks at the end were displayed
> 3 backticks at the beginning

I have noticed that those have to be alone on the first line. If there is something else, the whole line will be lost.

Commit message: Added limit comparison test for n

Patch to review:
diff --git a/sympy/concrete/summations.py b/sympy/concrete/summations.py
index 79e1e51ff430..47a5ec5cd611 100644
--- a/sympy/concrete/summations.py
+++ b/sympy/concrete/summations.py
@@ -4,6 +4,7 @@
 from sympy.concrete.expr_with_intlimits import ExprWithIntLimits
 from sympy.core.function import Derivative
 from sympy.core.relational import Eq
+from sympy.core.numbers import oo
 from sympy.core.singleton import S
 from sympy.core.symbol import Dummy, Wild, Symbol
 from sympy.core.add import Add
@@ -518,6 +519,12 @@ def is_convergent(self):
                 except NotImplementedError:
                     pass
 
+        ### ------------- Limit comparison test -----------###
+        # (n) comparison
+        lim_comp = limit((sequence_term/sym), sym, oo)
+        if lim_comp is not S.Infinity:
+            return S.false
+
         ### -------------- Dirichlet tests -------------- ###
         if order.expr.is_Mul:
             a_n, b_n = order.expr.args[0], order.expr.args[1]
diff --git a/sympy/concrete/tests/test_sums_products.py b/sympy/concrete/tests/test_sums_products.py
index b0da5c2e2233..a74c5ff9d8d4 100644
--- a/sympy/concrete/tests/test_sums_products.py
+++ b/sympy/concrete/tests/test_sums_products.py
@@ -1016,3 +1016,6 @@ def test_issue_14112():
     assert Sum((-1)**n/sqrt(n), (n, 1, oo)).is_absolutely_convergent() is S.false
     assert Sum((-1)**(2*n)/n, (n, 1, oo)).is_convergent() is S.false
     assert Sum((-2)**n + (-3)**n, (n, 1, oo)).is_convergent() is S.false
+
+def test_issue_14111():
+    assert Sum(1/log(log(n)), (n, 22, oo)).is_convergent() is S.false


Code review comments:
diff_hunk: @@ -518,6 +519,12 @@ def is_convergent(self):
                 except NotImplementedError:
                     pass
 
+        ### ------------- Limit comparison test -----------###
+        # (n) comparison
+        lim_comp = limit((sequence_term/sym), sym, oo)
+        if lim_comp is not S.Infinity:
path: sympy/concrete/summations.py
text: @user1:
If `lim_comp` is `oo`, then also `limit(sequence_term, sym, oo)` must be `oo`.  Therefore this test will return `False` for all sequences whose terms have finite limit.
```
>>> Sum(sin(n)/n, (n, 1, oo)).is_convergent()
False
```

@author:
Yes. 
@user1 , It was a very abrupt implementation. I will create a more robust one.

@author:
The implementation has been tweaked. Please see [here](https://math.oregonstate.edu/home/programs/undergrad/CalculusQuestStudyGuides/SandS/SeriesTests/limit_comparison.html) for the theory part. Only the divergence comparison, with the `harmonic series` has been implemented.
Now --

```
>>> Sum(sin(n)/n, (n, 1, oo)).is_convergent()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/concrete/summations.py", line 555, in is_convergent
    "is not yet implemented" % (sequence_term))
NotImplementedError: The algorithm to find the Sum convergence of sin(n)/n is not yet implemented
```
The description has also been modified.