-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Improve automatic evaluation of arg(exp()) #25953
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
Fixes sympy#17300. Before this commit, expressions of the form arg(exp()) are not special cased and the argument to arg(), including exp(), ends up being split apart by .as_real_imag(). The real and imaginary parts are then passed to atan2. This often leads to poor results. See issue sympy#17300 for examples. This commit adds a special case for arg(exp()) to better handle these expressions. BEFORE: >>> arg(exp(1 + 5*I)) atan(sin(5)/cos(5)) >>> arg(exp(1 + I*pi/8)) atan(sqrt(1/2 - sqrt(2)/4)/sqrt(sqrt(2)/4 + 1/2)) AFTER: >>> arg(exp(1 + 5*I)) 5 - 2⋅π >>> arg(exp(1 + I*pi/8)) π - 8
✅ 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 [4adf8d24] | Ratio | Benchmark (Parameter) |
|----------|----------------------|---------------------|---------|----------------------------------------------------------------------|
| - | 67.5±0.7ms | 43.5±0.3ms | 0.64 | integrate.TimeIntegrationRisch02.time_doit(10) |
| - | 67.3±1ms | 44.1±0.4ms | 0.66 | integrate.TimeIntegrationRisch02.time_doit_risch(10) |
| + | 18.0±0.2μs | 29.1±0.4μs | 1.62 | integrate.TimeIntegrationRisch03.time_doit(1) |
| - | 5.18±0.03ms | 2.83±0.03ms | 0.55 | logic.LogicSuite.time_load_file |
| - | 73.6±0.2ms | 28.1±0.1ms | 0.38 | polys.TimeGCD_GaussInt.time_op(1, 'dense') |
| - | 25.8±0.08ms | 16.7±0.05ms | 0.65 | polys.TimeGCD_GaussInt.time_op(1, 'expr') |
| - | 72.1±0.6ms | 28.4±0.1ms | 0.39 | polys.TimeGCD_GaussInt.time_op(1, 'sparse') |
| - | 254±1ms | 123±0.9ms | 0.49 | polys.TimeGCD_GaussInt.time_op(2, 'dense') |
| - | 255±2ms | 126±1ms | 0.49 | polys.TimeGCD_GaussInt.time_op(2, 'sparse') |
| - | 661±5ms | 374±2ms | 0.57 | polys.TimeGCD_GaussInt.time_op(3, 'dense') |
| - | 660±3ms | 369±3ms | 0.56 | polys.TimeGCD_GaussInt.time_op(3, 'sparse') |
| - | 492±2μs | 281±2μs | 0.57 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(1, 'dense') |
| - | 1.74±0.01ms | 1.05±0ms | 0.6 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(2, 'dense') |
| - | 5.71±0.02ms | 3.06±0.02ms | 0.54 | polys.TimeGCD_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 449±2μs | 233±2μs | 0.52 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(1, 'dense') |
| - | 1.46±0.01ms | 658±4μs | 0.45 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(2, 'dense') |
| - | 4.83±0.02ms | 1.62±0.01ms | 0.33 | polys.TimeGCD_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 372±2μs | 202±2μs | 0.54 | polys.TimeGCD_SparseGCDHighDegree.time_op(1, 'dense') |
| - | 2.43±0.02ms | 1.21±0.01ms | 0.5 | polys.TimeGCD_SparseGCDHighDegree.time_op(3, 'dense') |
| - | 10.0±0.07ms | 4.24±0.02ms | 0.42 | polys.TimeGCD_SparseGCDHighDegree.time_op(5, 'dense') |
| - | 360±2μs | 165±0.9μs | 0.46 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(1, 'dense') |
| - | 2.47±0.01ms | 877±10μs | 0.36 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(3, 'dense') |
| - | 9.39±0.07ms | 2.59±0.02ms | 0.28 | polys.TimeGCD_SparseNonMonicQuadratic.time_op(5, 'dense') |
| - | 999±10μs | 419±2μs | 0.42 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 1.71±0.02ms | 499±3μs | 0.29 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(3, 'sparse') |
| - | 5.68±0.05ms | 1.76±0.01ms | 0.31 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'dense') |
| - | 8.27±0.04ms | 1.50±0ms | 0.18 | polys.TimePREM_LinearDenseQuadraticGCD.time_op(5, 'sparse') |
| - | 288±2μs | 63.1±0.5μs | 0.22 | polys.TimePREM_QuadraticNonMonicGCD.time_op(1, 'sparse') |
| - | 3.29±0.03ms | 389±2μs | 0.12 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 3.90±0.02ms | 279±2μs | 0.07 | polys.TimePREM_QuadraticNonMonicGCD.time_op(3, 'sparse') |
| - | 6.78±0.1ms | 1.23±0.01ms | 0.18 | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'dense') |
| - | 8.47±0.05ms | 838±4μs | 0.1 | polys.TimePREM_QuadraticNonMonicGCD.time_op(5, 'sparse') |
| - | 5.00±0.03ms | 2.96±0.01ms | 0.59 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(2, 'sparse') |
| - | 11.8±0.09ms | 6.38±0.03ms | 0.54 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'dense') |
| - | 22.2±0.1ms | 9.05±0.03ms | 0.41 | polys.TimeSUBRESULTANTS_LinearDenseQuadraticGCD.time_op(3, 'sparse') |
| - | 5.26±0.01ms | 860±2μs | 0.16 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(1, 'sparse') |
| - | 12.6±0.03ms | 7.04±0.04ms | 0.56 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(2, 'sparse') |
| - | 98.7±0.7ms | 25.4±0.2ms | 0.26 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'dense') |
| - | 165±2ms | 54.4±0.2ms | 0.33 | polys.TimeSUBRESULTANTS_QuadraticNonMonicGCD.time_op(3, 'sparse') |
| - | 176±2μs | 114±3μs | 0.64 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(1, 'dense') |
| - | 366±2μs | 213±2μs | 0.58 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(1, 'sparse') |
| - | 4.20±0.01ms | 823±3μs | 0.2 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'dense') |
| - | 5.22±0.04ms | 377±1μs | 0.07 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(3, 'sparse') |
| - | 19.2±0.09ms | 2.78±0.01ms | 0.14 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'dense') |
| - | 22.2±0.2ms | 623±2μs | 0.03 | polys.TimeSUBRESULTANTS_SparseGCDHighDegree.time_op(5, 'sparse') |
| - | 490±5μs | 132±0.8μs | 0.27 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(1, 'sparse') |
| - | 4.64±0.06ms | 601±3μs | 0.13 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'dense') |
| - | 5.22±0.03ms | 136±0.6μs | 0.03 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(3, 'sparse') |
| - | 12.7±0.1ms | 1.29±0ms | 0.1 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'dense') |
| - | 13.4±0.09ms | 138±1μs | 0.01 | polys.TimeSUBRESULTANTS_SparseNonMonicQuadratic.time_op(5, 'sparse') |
| - | 131±0.3μs | 74.1±0.4μs | 0.57 | solve.TimeMatrixOperations.time_rref(3, 0) |
| - | 251±2μs | 87.5±1μs | 0.35 | solve.TimeMatrixOperations.time_rref(4, 0) |
| - | 24.1±0.06ms | 10.2±0.03ms | 0.42 | solve.TimeSolveLinSys189x49.time_solve_lin_sys |
Full benchmark results can be found as artifacts in GitHub Actions |
Looks ok to me. I don't prefer the Will commit in 12 hours if there is no other argument. This is a nice clean up to automatic evaluation of such expressions! |
References to other Issues or PRs
Fixes #17300
Brief description of what is fixed or changed
Before this commit, expressions of the form
arg(exp())
are not special cased and the argument toarg()
, includingexp()
, ends up being split apart by.as_real_imag()
. The real and imaginary parts are then passed toatan2
. This often leads to poor results. See issue #17300 for examples.This commit adds a special case for
arg(exp())
to better handle these expressions.BEFORE:
AFTER:
Other comments
Release Notes
arg(exp())
.