Repository: diofant/diofant

Issue:
(x/abs(sqrt(1 - x**2))).limit(x, oo) is -1 (should be 1)
c.f.
```
In [12]: (x/abs(sqrt(x**2 - 1))).limit(x, oo)
Out[12]: 1
```

Another wrong example:
```
In [13]: e1 = (4*x - 2)/abs(sqrt(4 - 4*(2*x - 1)**2))
In [14]: e1.limit(x, oo)
Out[14]: -1
```


Discussion:
A related issue here which neither sympy nor diofant can solve as of now ,is series of expressions of type `Pow` where there are two branches or some discrepancy between negative and positive values . 
Consider this 
```
>>> from diofant import *
>>> x = Symbol('x', negative =True)
>>> 1/Abs(sqrt(1 - (-1 + 1/x)**2))
1/Abs(sqrt(-(-1 + 1/x)**2 + 1))
>>> _.series(x)
-x - x**2 - 3*x**3/2 - 5*x**4/2 - 35*x**5/8 + O(x**6)
>>>
>>>
>>>
>>> x = Symbol('x', positive=True)
>>> 1/Abs(sqrt(1 - (-1 + 1/x)**2))
1/Abs(sqrt(-(-1 + 1/x)**2 + 1))
>>> _.series(x)
-x - x**2 - 3*x**3/2 - 5*x**4/2 - 35*x**5/8 + O(x**6)
```
Answer from wolfram 
![image](https://user-images.githubusercontent.com/87052487/160133446-c081ecfb-6e77-4c80-89a7-3c92454358c7.png)

I plan to include this in my Gsoc 22' proposal but am not fully sure what's the best and mathematically correct approach here . Let me know if you know of a method to approach this (which is mathematically correct in all sense) or what is going wrong in `diofant `  @skirpichev 

Abs._eval_nseries() method is wrong.
```
In [14]: abs(sqrt(x**2 - 1))._eval_nseries(x, 2, None).expand()
Out[14]: 
      2        
     x     ⎛ 4⎞
-1 + ── + O⎝x ⎠
     2         
```

Resolving patch:
diff --git a/diofant/functions/elementary/complexes.py b/diofant/functions/elementary/complexes.py
--- a/diofant/functions/elementary/complexes.py
+++ b/diofant/functions/elementary/complexes.py
@@ -507,9 +507,9 @@ def _eval_nseries(self, x, n, logx):
         s = self.args[0]._eval_nseries(x, n=n, logx=logx)
         when, lim = Eq(direction, 0), direction.limit(x, 0)
         if lim.equals(0) is False:
-            return sign(lim)*s
+            return s/sign(lim)
         else:
-            return Piecewise((lim, when), (sign(direction)*s, True))
+            return Piecewise((lim, when), (s/sign(direction), True))
 
     def _eval_derivative(self, s):
         if self.args[0].is_extended_real or self.args[0].is_imaginary:


Test patch:
diff --git a/diofant/tests/series/test_gruntz.py b/diofant/tests/series/test_gruntz.py
--- a/diofant/tests/series/test_gruntz.py
+++ b/diofant/tests/series/test_gruntz.py
@@ -326,7 +326,7 @@ def test_limit():
     assert limit(27**(log(x, 3) + 1)/x**3, x, oo) == 27
 
     # issue sympy/sympy#9449
-    assert limit(x*(abs(1/x + y) - abs(y - 1/x))/2, x, oo) == sign(y)
+    assert limit(x*(abs(1/x + y) - abs(y - 1/x))/2, x, oo) == sign(y)**-1
 
     # issue sympy/sympy#8481
     assert limit(m**x * exp(-m) / factorial(x), x, oo) == 0
diff --git a/diofant/tests/series/test_limits.py b/diofant/tests/series/test_limits.py
--- a/diofant/tests/series/test_limits.py
+++ b/diofant/tests/series/test_limits.py
@@ -938,3 +938,8 @@ def test_sympyissue_7391():
     l = Limit(func.subs({y: f(x)}), x, 0)
     assert l.doit() == l
     assert l.subs({f: Lambda(x, sqrt(x))}).doit() == Rational(1, 2)
+
+
+def test_issue_1216():
+    assert (x/abs(sqrt(1 - x**2))).limit(x, oo) == 1
+    assert((4*x - 2)/abs(sqrt(4 - 4*(2*x - 1)**2))).limit(x, oo) == 1
diff --git a/diofant/tests/series/test_nseries.py b/diofant/tests/series/test_nseries.py
--- a/diofant/tests/series/test_nseries.py
+++ b/diofant/tests/series/test_nseries.py
@@ -449,7 +449,7 @@ def test_abs():
     assert abs(x + 1).series(x, n=4) == x + 1
     assert abs(sin(x)).series(x, n=4) == x - x**3/6 + O(x**4)
     assert abs(sin(-x)).series(x, n=4) == x - x**3/6 + O(x**4)
-    assert abs(x - a).series(x, 1) == (x - a)*sign(1 - a)
+    assert abs(x - a).series(x, 1) == (x - a)/sign(1 - a)
 
     # issue sympy/sympy#5183
     assert abs(x + x**2).series(n=1) == O(x)