-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Float(0).is_integer is True, Float(1.1).is_integer is False, Float(1) is None #25875
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
Conversation
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.13. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
Benchmark results from GitHub Actions Lower numbers are good, higher numbers are bad. A ratio less than 1 Significantly changed benchmark results (PR vs master) Significantly changed benchmark results (master vs previous release) | Change | Before [a00718ba] | After [6f3767c2] | Ratio | Benchmark (Parameter) |
|----------|----------------------|---------------------|---------|----------------------------------------------------------------------|
| - | 69.2±1ms | 45.6±0.5ms | 0.66 | integrate.TimeIntegrationRisch02.time_doit(10) |
| + | 17.7±0.2μs | 30.5±0.2μs | 1.73 | integrate.TimeIntegrationRisch03.time_doit(1) |
| - | 5.44±0.02ms | 2.89±0.02ms | 0.53 | logic.LogicSuite.time_load_file |
| - | 71.6±0.4ms | 28.3±0.2ms | 0.4 | polys.TimeGCD_GaussInt.time_op(1, 'dense') |
| - | 26.2±0.4ms | 17.1±0.2ms | 0.65 | polys.TimeGCD_GaussInt.time_op(1, 'expr') |
| - | 72.9±0.3ms | 28.6±0.2ms | 0.39 | polys.TimeGCD_GaussInt.time_op(1, 'sparse') |
| - | 253±1ms | 125±0.4ms | 0.49 | polys.TimeGCD_GaussInt.time_op(2, 'dense') |
| - | 254±2ms | 124±1ms | 0.49 | polys.TimeGCD_GaussInt.time_op(2, 'sparse') |
| - | 652±9ms | 371±3ms | 0.57 | polys.TimeGCD_GaussInt.time_op(3, 'dense') |
| - | 658±5ms | 373±3ms | 0.57 | polys.TimeGCD_GaussInt.time_op(3, 'sparse') |
| - | 490±6μs | 283±2μs | 0.58 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(1, 'dense') |
| - | 1.78±0.03ms | 1.05±0ms | 0.59 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(2, 'dense') |
| - | 5.82±0.03ms | 3.07±0.05ms | 0.53 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 445±7μs | 230±3μs | 0.52 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(1, 'dense') |
| - | 1.46±0.01ms | 670±2μs | 0.46 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(2, 'dense') |
| - | 4.85±0.01ms | 1.63±0.01ms | 0.34 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 371±0.9μs | 201±0.5μs | 0.54 | polys.TimeGCD_SparseGCDHighDegree.time_op(1, 'dense') |
| - | 2.46±0.02ms | 1.19±0.01ms | 0.48 | polys.TimeGCD_SparseGCDHighDegree.time_op(3, 'dense') |
| - | 9.78±0.04ms | 4.34±0.02ms | 0.44 | polys.TimeGCD_SparseGCDHighDegree.time_op(5, 'dense') |
| - | 355±3μs | 165±1μs | 0.47 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(1, 'dense') |
| - | 2.42±0.01ms | 876±10μs | 0.36 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(3, 'dense') |
| - | 9.63±0.04ms | 2.59±0.01ms | 0.27 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(5, 'dense') |
| - | 1.03±0.02ms | 419±3μs | 0.41 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 1.71±0.01ms | 508±1μs | 0.3 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'sparse') |
| - | 5.77±0.05ms | 1.77±0.01ms | 0.31 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'dense') |
| - | 8.38±0.08ms | 1.53±0.01ms | 0.18 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'sparse') |
| - | 289±2μs | 63.2±0.2μs | 0.22 | polys.TimePREM_QuadraticNonMonicGCD.time_op(1, 'sparse') |
| - | 3.40±0.04ms | 388±3μs | 0.11 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 3.88±0.02ms | 281±2μs | 0.07 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'sparse') |
| - | 6.73±0.05ms | 1.25±0.01ms | 0.19 | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'dense') |
| - | 8.60±0.1ms | 835±1μs | 0.1 | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'sparse') |
| - | 5.13±0.06ms | 2.99±0.01ms | 0.58 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(2, 'sparse') |
| - | 11.9±0.08ms | 6.43±0.03ms | 0.54 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 22.4±0.08ms | 9.18±0.06ms | 0.41 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'sparse') |
| - | 5.33±0.02ms | 872±4μs | 0.16 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(1, 'sparse') |
| - | 12.8±0.07ms | 7.04±0.03ms | 0.55 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(2, 'sparse') |
| - | 100±1ms | 25.4±0.05ms | 0.25 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 166±0.6ms | 54.9±0.2ms | 0.33 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'sparse') |
| - | 170±0.7μs | 111±0.4μs | 0.65 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(1, 'dense') |
| - | 360±2μs | 214±0.7μs | 0.59 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(1, 'sparse') |
| - | 4.18±0.01ms | 830±4μs | 0.2 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'dense') |
| - | 5.31±0.1ms | 384±1μs | 0.07 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'sparse') |
| - | 19.6±0.06ms | 2.81±0.01ms | 0.14 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'dense') |
| - | 22.3±0.1ms | 629±3μs | 0.03 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'sparse') |
| - | 489±4μs | 134±0.7μs | 0.27 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(1, 'sparse') |
| - | 4.56±0.04ms | 609±2μs | 0.13 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'dense') |
| - | 5.29±0.02ms | 137±0.9μs | 0.03 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'sparse') |
| - | 12.7±0.07ms | 1.30±0.01ms | 0.1 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'dense') |
| - | 13.8±0.04ms | 139±1μs | 0.01 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'sparse') |
| - | 133±0.4μs | 75.2±1μs | 0.56 | solve.TimeMatrixOperations.time_rref(3, 0) |
| - | 250±0.9μs | 87.9±0.4μs | 0.35 | solve.TimeMatrixOperations.time_rref(4, 0) |
| - | 24.1±0.06ms | 10.1±0.04ms | 0.42 | solve.TimeSolveLinSys189x49.time_solve_lin_sys |
Full benchmark results can be found as artifacts in GitHub Actions |
The point should also be made that Float(1).is_integer = None does not preclude making it True in the future, since None means "True or False". So I think this is the safest fix, and it matches what we decided in the past for Float.is_rational = False. I don't know if making Float.is_integer = False was done intentionally or accidentally, but it's clearly wrong given the Eq behavior, and that sort of thing could happen anywhere in the code that uses an is_integer check. |
Thanks for picking up this work @smichr For future readers, if we ever in the future decide that making Float(1).is_integer = True (or even Float.is_rational = True in general) we can revisit that. I think it could be dangerous, since floats don't actually satisfy the same mathematical properties as integers and rationals, although I'm not completely sure yet just how much that would matter in practice. |
References to other Issues or PRs
yet another attempt to fix #23731
alternate to #25865, #25864, #25856
Brief description of what is fixed or changed
Other comments
There was a long discussion of whether
Float
should be classified asrational
here. One major concern was that float/Float objects do not behave as Rationals in operations, e.g.Release Notes
Float.is_integer
is nowNone
except for0.0
andFloats
with a non-zero fraction. Previously, onlyFloat(0)
was TrueFalse
in some cases with floats.