New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"sympy.core.numbers.Integer" should be registered with "numbers.Integral" #19311
Comments
The use of |
Ah, yes. I'd forgotten that Python's "tower of numbers" is effectively inverted from intuition. For shame, me! Thanks for the friendly reminder that it is late and I should go to sleep, which I am now doing. 😴
Right. As it currently stands, SymPy integers are rational but not integers from the non-SymPy perspective, which... absolutely must be wrong. |
The issue came from implementing #16652
And for reference to the comment, the bitwise operations should be defined, which may not be viable for sympy because sympy defines overrides bitwise operations for logical programming purposes. |
On one hand, that's definitely a compatibility issue. On the other hand, |
Does anyone have any actual use for the Numbers ABCs? |
That is fixed now. |
Potentially we could just add the bitwise operations to sympy.Integer. Currently among sympy types the bitwise operations are defined for Boolean but not Expr. The potential point of confusion is the fact that Symbol is both Boolean and Expr (which I personally consider a contradiction) so e.g.: In [114]: x, y = symbols('x, y')
In [115]: 1 << 2
Out[115]: 4
In [116]: (x << y).subs(x, 1).subs(y, 2)
Out[116]: True Really though I think it's a mistake to use Symbol this way at all: there should be a BooleanSymbol class for use in Boolean contexts. That would take quite a while to fix but if we want to do that eventually then we can still add the bitwise operators to Integer now. |
This is fixed now by #21699 which adds the bitwise methods to Integer and registers it with the numbers.Integral ABC. |
While recently perusing the
sympy.core.numbers
submodule, I espied with my rheumy little eye a trivial typo with respect to type registration. SymPy'sInteger
type is currently registered as satisfying thenumbers.Rational
API(which it obviously doesn't)(which is technically true but less useful), but should instead be registered as satisfying thenumbers.Integral
API(which it obviously does)(which is also true and much more useful): e.g.,Thanks for all the symbolic maths, beloved SymPy volunteers! 💛
The text was updated successfully, but these errors were encountered: