Repository: sympy/sympy

Issue:
Incorrect computation of a basic limit, regression from 1.6.2 to 1.7.1
Using SymPy 1.6.2:

```python
from sympy import *
var('x')
limit( sin(pi*x)/(3*x-12), x, 4 )  # gives the answer pi/3
```

Manual calculation using l'Hôpital's rule verifies that the above answer is correct.

Using SymPy 1.7.1:

```python
from sympy import *
var('x')
limit( sin(pi*x)/(3*x-12), x, 4 )  # gives the answer 0
```


Discussion:
sympy-bot: :white_check_mark:

Hi, I am the [SymPy bot](https://github.com/sympy/sympy-bot) (v161). I'm here to help you write a release notes entry. Please read the [guide on how to write release notes](https://github.com/sympy/sympy/wiki/Writing-Release-Notes).



Your release notes are in good order.

Here is what the release notes will look like:
* functions
  *  Fixed leading term calculation of `sin` functions to handle angles outside `[-2pi, 2pi]` ([#21042](https://github.com/sympy/sympy/pull/21042) by [@0sidharth](https://github.com/0sidharth))

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.8.

<details><summary>Click here to see the pull request description that was parsed.</summary>

    <!-- Your title above should be a short description of what
    was changed. Do not include the issue number in the title. -->

    #### References to other Issues or PRs
    <!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
    format, e.g. "Fixes #1234" (see
    https://tinyurl.com/auto-closing for more information). Also, please
    write a comment on that issue linking back to this pull request once it is
    open. -->
    Closes #21038 

    #### Brief description of what is fixed or changed
    Leading term calculations of `sin` outside the domain `[-2pi, 2pi]` were giving wrong results. This is now being accounted for.

    #### Release Notes

    <!-- Write the release notes for this release below between the BEGIN and END
    statements. The basic format is a bulleted list with the name of the subpackage
    and the release note for this PR. For example:

    * solvers
      * Added a new solver for logarithmic equations.

    * functions
      * Fixed a bug with log of integers.

    or if no release note(s) should be included use:

    NO ENTRY

    See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
    information on how to write release notes. The bot will check your release
    notes automatically to see if they are formatted correctly. -->

    <!-- BEGIN RELEASE NOTES -->
    * functions
      *  Fixed leading term calculation of `sin` functions to handle angles outside `[-2pi, 2pi]`
    <!-- END RELEASE NOTES -->


</details><p>

oscarbenjamin: A test for the limit in the issue should be added as well.

Patch:
diff --git a/sympy/functions/elementary/trigonometric.py b/sympy/functions/elementary/trigonometric.py
index f65810101a..2146fd263a 100644
--- a/sympy/functions/elementary/trigonometric.py
+++ b/sympy/functions/elementary/trigonometric.py
@@ -478,16 +478,13 @@ def _eval_expand_trig(self, **hints):
         return sin(arg)
 
     def _eval_as_leading_term(self, x, cdir=0):
-        from sympy import Order
-        arg = self.args[0].as_leading_term(x)
-
-        if x in arg.free_symbols and Order(1, x).contains(arg):
-            return arg
-        else:
-            if not arg.subs(x, 0).is_finite:
-                return self
-            else:
-                return self.func(arg)
+        arg = self.args[0]
+        x0 = arg.subs(x, 0).cancel()
+        n = x0/S.Pi
+        if n.is_integer:
+            lt = (arg - n*S.Pi).as_leading_term(x)
+            return ((-1)**n)*lt
+        return self.func(x0) if x0.is_finite else self
 
     def _eval_is_extended_real(self):
         if self.args[0].is_extended_real:
diff --git a/sympy/simplify/simplify.py b/sympy/simplify/simplify.py
index 707046aee0..8bb7347315 100644
--- a/sympy/simplify/simplify.py
+++ b/sympy/simplify/simplify.py
@@ -576,7 +576,7 @@ def done(e):
         rv = e.doit() if doit else e
         return shorter(rv, collect_abs(rv))
 
-    expr = sympify(expr, rational=rational)
+    expr = sympify(expr)
     kwargs = dict(
         ratio=kwargs.get('ratio', ratio),
         measure=kwargs.get('measure', measure),
diff --git a/sympy/solvers/solvers.py b/sympy/solvers/solvers.py
index 06d30cbdea..65e1ef0d2e 100644
--- a/sympy/solvers/solvers.py
+++ b/sympy/solvers/solvers.py
@@ -3296,7 +3296,7 @@ def _take(d, take_int_pow):
 
     eq = _mexpand(eq, recursive=True)
     if eq.is_number:
-        return eq, []
+        return
 
     syms = set(syms) or eq.free_symbols
     poly = eq.as_poly()


Test patch:
diff --git a/sympy/calculus/tests/test_util.py b/sympy/calculus/tests/test_util.py
index 510fb12741..fdb261dea0 100644
--- a/sympy/calculus/tests/test_util.py
+++ b/sympy/calculus/tests/test_util.py
@@ -42,7 +42,6 @@ def test_function_range():
     assert function_range(cos(x), x, Interval(-oo, -4)
         ) == Interval(-1, 1)
     assert function_range(cos(x), x, S.EmptySet) == S.EmptySet
-    assert function_range(x/sqrt(x**2+1), x, S.Reals) == Interval.open(-1,1)
     raises(NotImplementedError, lambda : function_range(
         exp(x)*(sin(x) - cos(x))/2 - x, x, S.Reals))
     raises(NotImplementedError, lambda : function_range(
@@ -259,7 +258,6 @@ def test_maximum():
     assert maximum(abs(a**3 + a), a, Interval(0, 2)) == 10
     assert maximum(abs(60*a**3 + 24*a), a, Interval(0, 2)) == 528
     assert maximum(abs(12*a*(5*a**2 + 2)), a, Interval(0, 2)) == 528
-    assert maximum(x/sqrt(x**2+1), x, S.Reals) == 1
 
     raises(ValueError, lambda : maximum(sin(x), x, S.EmptySet))
     raises(ValueError, lambda : maximum(log(cos(x)), x, S.EmptySet))
@@ -288,7 +286,6 @@ def test_minimum():
         ) is S.NegativeOne
     assert minimum(cos(x)-sin(x), x, S.Reals) == -sqrt(2)
     assert minimum(y, x, S.Reals) == y
-    assert minimum(x/sqrt(x**2+1), x, S.Reals) == -1
 
     raises(ValueError, lambda : minimum(sin(x), x, S.EmptySet))
     raises(ValueError, lambda : minimum(log(cos(x)), x, S.EmptySet))
diff --git a/sympy/functions/elementary/tests/test_trigonometric.py b/sympy/functions/elementary/tests/test_trigonometric.py
index fd941ff150..65b068349b 100644
--- a/sympy/functions/elementary/tests/test_trigonometric.py
+++ b/sympy/functions/elementary/tests/test_trigonometric.py
@@ -1222,6 +1222,10 @@ def test_leading_terms():
             eq = func(a)
             assert eq.as_leading_term(x) == eq
 
+    # https://github.com/sympy/sympy/issues/21038
+    f = sin(pi*(x + 4))/(3*x)
+    assert f.as_leading_term(x) == pi/3
+
 
 def test_atan2_expansion():
     assert cancel(atan2(x**2, x + 1).diff(x) - atan(x**2/(x + 1)).diff(x)) == 0
diff --git a/sympy/series/tests/test_limits.py b/sympy/series/tests/test_limits.py
index fb525fc51c..3d5e31373e 100644
--- a/sympy/series/tests/test_limits.py
+++ b/sympy/series/tests/test_limits.py
@@ -939,3 +939,7 @@ def test_issue_7535():
 
 def test_issue_20704():
     assert limit(x*(Abs(1/x + y) - Abs(y - 1/x))/2, x, 0) == 0
+
+
+def test_issue_21038():
+    assert limit(sin(pi*x)/(3*x - 12), x, 4) == pi/3
diff --git a/sympy/simplify/tests/test_simplify.py b/sympy/simplify/tests/test_simplify.py
index 1b3b47386b..54fb015515 100644
--- a/sympy/simplify/tests/test_simplify.py
+++ b/sympy/simplify/tests/test_simplify.py
@@ -201,7 +201,6 @@ def test_simplify_rational():
     assert simplify(expr, rational = True) == 2**(x+y)
     assert simplify(expr, rational = None) == 2.0**(x+y)
     assert simplify(expr, rational = False) == expr
-    assert simplify('0.9 - 0.8 - 0.1', rational = True) == 0
 
 
 def test_simplify_issue_1308():
diff --git a/sympy/solvers/tests/test_solvers.py b/sympy/solvers/tests/test_solvers.py
index 6fb2588eb9..7545daffcc 100644
--- a/sympy/solvers/tests/test_solvers.py
+++ b/sympy/solvers/tests/test_solvers.py
@@ -315,13 +315,6 @@ def test_issue_7190():
     assert solve(log(x-3) + log(x+3), x) == [sqrt(10)]
 
 
-def test_issue_21004():
-    x = symbols('x')
-    f = x/sqrt(x**2+1)
-    f_diff = f.diff(x)
-    assert solve(f_diff, x) == []
-
-
 def test_linear_system():
     x, y, z, t, n = symbols('x, y, z, t, n')