Repository: sympy/sympy
Pull request: Fix Floor division with sympy.Integer 
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->
Fixes #24369 
#### 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. -->


#### Brief description of what is fixed or changed
Floor division with sympy.Integer 


#### Other comments
`import sympy`
`s0 = sympy.Symbol('s0')`
`sympy.Integer(1024)//s0`


#### 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 -->
  NO ENTRY


<!-- END RELEASE NOTES -->


Problem statement:
Floor division with sympy.Integer gives: Argument of Integer should be of numeric type, got floor(1024/s0)
```
import sympy

s0 = sympy.Symbol('s0')
sympy.Integer(1024)//s0
```

gives

```
Traceback (most recent call last):
  File "/Users/ezyang/Dev/sympy/sympy/core/numbers.py", line 2098, in __new__
    ival = int(i)
  File "/Users/ezyang/Dev/sympy/sympy/core/expr.py", line 320, in __int__
    raise TypeError("Cannot convert symbols to int")
TypeError: Cannot convert symbols to int

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "repro.py", line 4, in <module>
    sympy.Integer(1024)//s0
  File "/Users/ezyang/Dev/sympy/sympy/core/decorators.py", line 65, in __sympifyit_wrapper
    return func(a, b)
  File "/Users/ezyang/Dev/sympy/sympy/core/numbers.py", line 2426, in __floordiv__
    return Integer(divmod(self, other)[0])
  File "/Users/ezyang/Dev/sympy/sympy/core/cache.py", line 72, in wrapper
    retval = cfunc(*args, **kwargs)
  File "/Users/ezyang/Dev/sympy/sympy/core/numbers.py", line 2100, in __new__
    raise TypeError(
TypeError: Argument of Integer should be of numeric type, got floor(1024/s0).
```

oddly enough, it works if the lhs is a plain Python int.

Hints from issue discussion:
The fix seems to be
```diff
diff --git a/sympy/core/numbers.py b/sympy/core/numbers.py
index 3b1aec2..52f7ea4 100644
--- a/sympy/core/numbers.py
+++ b/sympy/core/numbers.py
@@ -2423,7 +2423,7 @@ def __floordiv__(self, other):
             return NotImplemented
         if isinstance(other, Integer):
             return Integer(self.p // other)
-        return Integer(divmod(self, other)[0])
+        return divmod(self, other)[0]
 
     def __rfloordiv__(self, other):
         return Integer(Integer(other).p // self.p)
```

Commit message: fix #24369

Patch to review:
diff --git a/.mailmap b/.mailmap
index 12ebd404ed2c..e577eb5c6bf4 100644
--- a/.mailmap
+++ b/.mailmap
@@ -209,6 +209,7 @@ Abhinav Anand <abhinav.anand2807@gmail.com>
 Abhinav Chanda <abhinavchanda01@gmail.com>
 Abhishek <uchiha@pop-os.localdomain>
 Abhishek Garg <abhishekgarg119@gmail.com>
+Abhishek Patidar <1e9abhi1e10@gmail.com> Abhishek Patidar <2311abhiptdr@gmail.com>
 Abhishek Verma <iamvermaabhishek@gmail.com>
 Achal Jain <2achaljain@gmail.com>
 Adam Bloomston <adam@glitterfram.es> <mail@adambloomston>
diff --git a/sympy/core/numbers.py b/sympy/core/numbers.py
index 3b1aec24296e..52f7ea45ada0 100644
--- a/sympy/core/numbers.py
+++ b/sympy/core/numbers.py
@@ -2423,7 +2423,7 @@ def __floordiv__(self, other):
             return NotImplemented
         if isinstance(other, Integer):
             return Integer(self.p // other)
-        return Integer(divmod(self, other)[0])
+        return divmod(self, other)[0]
 
     def __rfloordiv__(self, other):
         return Integer(Integer(other).p // self.p)
diff --git a/sympy/core/tests/test_numbers.py b/sympy/core/tests/test_numbers.py
index 8e42e2b0c70a..0575d30a2fa9 100644
--- a/sympy/core/tests/test_numbers.py
+++ b/sympy/core/tests/test_numbers.py
@@ -16,6 +16,7 @@
 from sympy.core.symbol import Dummy, Symbol
 from sympy.core.sympify import sympify
 from sympy.functions.combinatorial.factorials import factorial
+from sympy.functions.elementary.integers import floor
 from sympy.functions.combinatorial.numbers import fibonacci
 from sympy.functions.elementary.exponential import exp, log
 from sympy.functions.elementary.miscellaneous import sqrt, cbrt
@@ -121,6 +122,7 @@ def test_mod():
 
 
 def test_divmod():
+    s0 = Symbol("s0")
     assert divmod(S(12), S(8)) == Tuple(1, 4)
     assert divmod(-S(12), S(8)) == Tuple(-2, 4)
     assert divmod(S.Zero, S.One) == Tuple(0, 0)
@@ -128,6 +130,7 @@ def test_divmod():
     raises(ZeroDivisionError, lambda: divmod(S.One, S.Zero))
     assert divmod(S(12), 8) == Tuple(1, 4)
     assert divmod(12, S(8)) == Tuple(1, 4)
+    assert divmod(1024,s0)[0] == floor(1024/s0)
 
     assert divmod(S("2"), S("3/2")) == Tuple(S("1"), S("1/2"))
     assert divmod(S("3/2"), S("2")) == Tuple(S("0"), S("3/2"))


Code review comments:
diff_hunk: @@ -121,13 +122,15 @@ def test_mod():
 
 
 def test_divmod():
+    s0 = Symbol("s0")
     assert divmod(S(12), S(8)) == Tuple(1, 4)
     assert divmod(-S(12), S(8)) == Tuple(-2, 4)
     assert divmod(S.Zero, S.One) == Tuple(0, 0)
     raises(ZeroDivisionError, lambda: divmod(S.Zero, S.Zero))
     raises(ZeroDivisionError, lambda: divmod(S.One, S.Zero))
     assert divmod(S(12), 8) == Tuple(1, 4)
     assert divmod(12, S(8)) == Tuple(1, 4)
+    assert divmod(1024,s0)[0] == floor(1024/s0)
path: sympy/core/tests/test_numbers.py
text: @user1:
```suggestion
    x = Symbol("x")
    assert divmod(S(12), S(8)) == Tuple(1, 4)
    assert divmod(-S(12), S(8)) == Tuple(-2, 4)
    assert divmod(S.Zero, S.One) == Tuple(0, 0)
    raises(ZeroDivisionError, lambda: divmod(S.Zero, S.Zero))
    raises(ZeroDivisionError, lambda: divmod(S.One, S.Zero))
    assert divmod(S(12), 8) == Tuple(1, 4)
    assert divmod(12, S(8)) == Tuple(1, 4)
    assert S(1024)//x == 1024//x == floor(1024/x)
```

diff_hunk: @@ -121,13 +122,15 @@ def test_mod():
 
 
 def test_divmod():
+    s0 = Symbol("s0")
     assert divmod(S(12), S(8)) == Tuple(1, 4)
     assert divmod(-S(12), S(8)) == Tuple(-2, 4)
     assert divmod(S.Zero, S.One) == Tuple(0, 0)
     raises(ZeroDivisionError, lambda: divmod(S.Zero, S.Zero))
     raises(ZeroDivisionError, lambda: divmod(S.One, S.Zero))
     assert divmod(S(12), 8) == Tuple(1, 4)
     assert divmod(12, S(8)) == Tuple(1, 4)
+    assert divmod(1024,s0)[0] == floor(1024/s0)
path: sympy/core/tests/test_numbers.py
text: @user1:
This test already passes on master. We need another test for the case that fails which is specifically `Integer(1024) // s0`. We should also test `1024 // s0` if that isn't tested anywhere.

The symbol should just be called `x` rather than `s0`.