Repository: sympy/sympy (Python)

Issue:
Incorrect result of `reduce_inequalities`
To reproduce: 

```python
>>> x = symbols('x')
>>> reduce_inequalities(pi/Abs(x) <= 1)
 (x > -oo) & (x < oo) & Ne(x, 0)
>>> (pi/Abs(x) <= 1).as_set()
Union(Interval(-oo, -pi), Interval(pi, oo))
```

Sympy version: master, commit: ffd3f417742ecb9ee0cc0820677980ce78d8ea7d. Sympy v1.12 works correctly.


Discussion:
`git bisect` points at commit 9172e03c82f4466df9bbdcb494d0da41bbd425a6 :
```
9172e03c82f4466df9bbdcb494d0da41bbd425a6 is the first bad commit                                                                                                                                                   
commit 9172e03c82f4466df9bbdcb494d0da41bbd425a6                                                                                                                                                                    
Author: Chris Smith <smichr@gmail.com>                                                                                                                                                                             
Date:   Thu Oct 5 21:57:11 2023 -0500                                                                                                                                                                              

    25738: handle subsolutions in reduce-inequalities                                                                                                                                                              

 sympy/solvers/inequalities.py            | 9 ++++++---                                                                                                                                                            
 sympy/solvers/tests/test_inequalities.py | 5 +++++                                                                                                                                                                
```
Here's the output of 1.12:
```
In [1]: reduce_inequalities(pi/Abs(x) <= 1)
Out[1]: (π ≤ x ∧ x < ∞) ∨ (x ≤ -π ∧ -∞ < x)
```
The PR is gh-25766. CC @smichr 

It is not clear from the code or the docs what the intended meaning of the arguments to `reduce_rational_inequalities` is supposed to be. In this case if we have
```
reduce_inequalities(pi/Abs(x) <= 1)
```
Then `reduce_abs_inequality` will call `reduce_rational_inequalities` with
```python
[[1 - pi/_x >= 0, _x >= 0], [1 + pi/_x >= 0, _x < 0]]
```
I would read that as an or-of-ands so it means:
```python
In [7]: Or(*(And(*c) for c in ineqs))
Out[7]: 
⎛            π    ⎞   ⎛    π            ⎞
⎜x ≥ 0 ∧ 1 - ─ ≥ 0⎟ ∨ ⎜1 + ─ ≥ 0 ∧ x < 0⎟
⎝            x    ⎠   ⎝    x            ⎠
```
If that is the case then the logic seems to have been wrong both before and after because we cannot separate some conditions into the `eqs` variable and process them after the others:
https://github.com/sympy/sympy/blob/f5f6c98bf9ee71c9f3c5569f54d15c4d299049d7/sympy/solvers/inequalities.py#L263-L278
I think that the `if eqs` block needs to move inside the loop.
My suggested fix:
```diff
diff --git a/sympy/solvers/inequalities.py b/sympy/solvers/inequalities.py
index 61afa2cbc2..9a5cf9737f 100644
--- a/sympy/solvers/inequalities.py
+++ b/sympy/solvers/inequalities.py
@@ -267,15 +267,13 @@ def reduce_rational_inequalities(exprs, gen, relational=True):
             else:
                 _eqs.append(((numer, denom), rel))
 
-        solution |= _sol
         if _eqs:
-            eqs.append(_eqs)
+            _sol &= solve_rational_inequalities([_eqs])
+            exclude = solve_rational_inequalities([[((d, d.one), '==')
+                for i in eqs for ((n, d), _) in i if d.has(gen)]])
+            _sol -= exclude
 
-    if eqs:
-        solution &= solve_rational_inequalities(eqs)
-        exclude = solve_rational_inequalities([[((d, d.one), '==')
-            for i in eqs for ((n, d), _) in i if d.has(gen)]])
-        solution -= exclude
+        solution |= _sol
 
     if not exact and solution:
         solution = solution.evalf()
```



Patch:
diff --git a/.mailmap b/.mailmap
index 5d17b34c9413..dc50205a00d0 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1151,6 +1151,7 @@ Raphael Michel <webmaster@raphaelmichel.de>
 Rashmi Shehana <rashmi.watagedara@syscolabs.com>
 Rastislav Rabatin <rastislav.rabatin@gmail.com>
 Ravi charan <ravicharan.vsp@gmail.com>
+Ravindu-Hirimuthugoda <ravindu.18@cse.mrt.ac.lk>
 Ray Cathcart <github@cathcart.us> <pix2@_nospam_.cathcart.us>
 Raymond Wong <rayman_407@yahoo.com> <rayman@CoolGuy.(none)>
 Raymond Wong <rayman_407@yahoo.com> <rayman@CoolGuyJr.(none)>
diff --git a/sympy/solvers/inequalities.py b/sympy/solvers/inequalities.py
index 61afa2cbc21b..9a5cf9737f7e 100644
--- a/sympy/solvers/inequalities.py
+++ b/sympy/solvers/inequalities.py
@@ -267,15 +267,13 @@ def reduce_rational_inequalities(exprs, gen, relational=True):
             else:
                 _eqs.append(((numer, denom), rel))
 
-        solution |= _sol
         if _eqs:
-            eqs.append(_eqs)
+            _sol &= solve_rational_inequalities([_eqs])
+            exclude = solve_rational_inequalities([[((d, d.one), '==')
+                for i in eqs for ((n, d), _) in i if d.has(gen)]])
+            _sol -= exclude
 
-    if eqs:
-        solution &= solve_rational_inequalities(eqs)
-        exclude = solve_rational_inequalities([[((d, d.one), '==')
-            for i in eqs for ((n, d), _) in i if d.has(gen)]])
-        solution -= exclude
+        solution |= _sol
 
     if not exact and solution:
         solution = solution.evalf()


Test patch:
diff --git a/sympy/solvers/tests/test_inequalities.py b/sympy/solvers/tests/test_inequalities.py
index de7e8e1c9743..6ce6f4520b52 100644
--- a/sympy/solvers/tests/test_inequalities.py
+++ b/sympy/solvers/tests/test_inequalities.py
@@ -494,3 +494,7 @@ def test_issue_25697():
 def test_issue_25738():
     assert reduce_inequalities(3 < abs(x)
         ) == reduce_inequalities(pi < abs(x)).subs(pi, 3)
+
+
+def test_issue_25983():
+    assert(reduce_inequalities(pi/Abs(x) <= 1) == ((pi <= x) & (x < oo)) | ((-oo < x) & (x <= -pi)))