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
expand(x**(a+b)) iff x != 0 or a & b both nonneg or nonpos #23962
Conversation
✅ Hi, I am the SymPy bot (v167). 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.12. 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) before after ratio
[41d90958] [ed600afb]
<sympy-1.11.1^0>
- 995±2μs 628±3μs 0.63 solve.TimeSparseSystem.time_linear_eq_to_matrix(10)
- 2.86±0ms 1.17±0ms 0.41 solve.TimeSparseSystem.time_linear_eq_to_matrix(20)
- 5.71±0.02ms 1.71±0ms 0.30 solve.TimeSparseSystem.time_linear_eq_to_matrix(30)
Full benchmark results can be found as artifacts in GitHub Actions |
Is there any reason we shouldn't do this? |
I didn't think this would be so easy to fix. It is similar to not allowing |
The title of this PR says In [30]: e1 = x**(y + z)
In [31]: e2 = e1.expand()
In [32]: e1
Out[32]:
y + z
x
In [33]: e2
Out[33]:
y z
x ⋅x
In [34]: e1.subs(x, 0).subs({y:1,z:-2})
Out[34]: zoo
In [35]: e2.subs(x, 0).subs({y:1,z:-2})
Out[35]: 0 |
@oscarbenjamin , to get your example to work you would have to have assumptions on symbols in a sum that would allow the assumptions system to determine that the exponent wasn't zero. The example you gave relies on one number being positive and the other negative; that will not evaluate as having a non-zero assumption. I think the nearest we could come is with |
answer: >>> one = Symbol('1',integer=1,prime=0,odd=1,positive=1)
>>> two = Symbol('2',integer=1,prime=1,even=1)
>>> eq = two-one
>>> 0**(2-1)
0
>>> 0**eq
0**(-1 + 2)
>>> expand(_)
nan
>>> (x**eq).expand().subs(x,0)
nan
>>> S.Zero**-1
zoo
>>> 0**-eq
0**(1 - 2)
>>> expand(_)
nan
>>> (x**-eq).expand().subs(x,0)
nan |
2108f71
to
243b4e9
Compare
The question is under what conditions does the identity The docs here claim that the identity is "always true": I think that misses the possibility that In [59]: e1 = x**(a + b)
In [60]: e2 = e1.expand()
In [61]: e1.subs(x, 0).subs({a:I, b:-I})
Out[61]: 1
In [62]: e2.subs(x, 0).subs({a:I, b:-I})
Out[62]: nan
In [67]: e1.subs(x, 0).subs({a:-1, b:2})
Out[67]: 0
In [68]: e2.subs(x, 0).subs({a:-1, b:2})
Out[68]: nan
In [69]: e1.subs(x, 0).subs({a:1, b:-2})
Out[69]: zoo
In [70]: e2.subs(x, 0).subs({a:1, b:-2})
Out[70]: 0 The last case is problematic because of the bogus evaluation of In [73]: e2.subs(x, 0).subs(b, -2)
Out[73]:
a
0 ⋅zoo
In [74]: e2.subs(x, 0).subs(b, -2).subs(a, 1)
Out[74]: nan
In [75]: e2.subs(x, 0).subs(a, 1).subs(b, -2)
Out[75]: 0 |
I am not seeing why this is passing. I checked the
|
I will squash to two commits and merge if there are no other concerns. |
f = x**(n - 2)*cos(x) | ||
assert fps(f, x).truncate() == \ | ||
(x**(n - 2) - x**n/2 + x**(n + 2)/24 - x**(n + 4)/720 + O(x**(n + 6), x)) | ||
(x**(n - 2) - x**n/2 + x**(n + 2)/24 + O(x**(n + 4), x)) | ||
|
||
f = x**(n - 2)*sin(x) + x**n*exp(x) | ||
assert fps(f, x).truncate() == \ | ||
(x**(n - 1) + x**n + 5*x**(n + 1)/6 + x**(n + 2)/2 + 7*x**(n + 3)/40 + | ||
x**(n + 4)/24 + 41*x**(n + 5)/5040 + O(x**(n + 6), x)) | ||
(x**(n - 1) + x**(n + 1) + x**(n + 2)/2 + x**n + | ||
x**(n + 4)/24 + x**(n + 5)/60 + O(x**(n + 6), x)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have these changed?
I think this mostly looks good but please don't self merge PRs. |
@mkoeppe after this PR the SAGE doctest is failing:
Is there a new SAGE ticket to track updating to SymPy 1.12 where a doctest like this could be updated? |
I've opened https://trac.sagemath.org/ticket/34489 for this |
So I guess the process is to update this line: sympy/.github/workflows/ci-sage.yml Line 58 in 8e65a42
and then push a commit to the trac ticket? |
I've opened a PR to update the ticket number: #24015 |
Yes, that's right. |
References to other Issues or PRs
Brief description of what is fixed or changed
fixes #23952 but required treating zoo/x as non-rational.
Other comments
This fixes the root issue (of the expansion to 0) but better handling needs to be implemented to get the original issue to be solved:
If the assumptions are omitted then
Release Notes
x**(a + b)
will not expand unlessa
andb
are both nonnegative or nonpositive orx
is not zeroexpr.is_rational_function()->False