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
Mrvasympt #7529
Mrvasympt #7529
Conversation
@@ -2468,6 +2468,9 @@ def series(self, x=None, x0=0, n=6, dir="+", logx=None): | |||
if (s1 + o).removeO() == s1: | |||
o = S.Zero | |||
|
|||
# Try asymptotic expansion | |||
if s1.removeO() == 0: | |||
return self.subs(x, 1/x).aseries(x, n, logx, False).subs(x, 1/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.
It looks for me, this line wasn't covered by your test suite. Perhaps, you should add a test when coeff.series(x, S.Infinity, n, logx=logx) call aseries?
Earlier as soon as coefficient had an infinite series expansion we terminated. Now other terms are also added as long as they don't have an infinite series expansion
@@ -2646,6 +2649,101 @@ def _eval_nseries(self, x, n, logx): | |||
nseries calls it.""" % self.func) | |||
) | |||
|
|||
def aseries(self, x, n=6, logx=None, bound=0, hir=False): | |||
""" | |||
This algorithm is directly induced from the limit computational algorithm |
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.
No, that's not a good docstring. See this.
Docstring shouldn't be about the algorithm in first place.
Use the ``hir`` parameter to produce hierarchical series. It stops the recursion | ||
at an early level and may provide nicer and more useful results. | ||
|
||
If the most rapidly varrying subexpression of a given expression f is f itself, |
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.
typo *varying
In the thesis, it mentions the parameter as |
@@ -2646,6 +2649,107 @@ def _eval_nseries(self, x, n, logx): | |||
nseries calls it.""" % self.func) | |||
) | |||
|
|||
def aseries(self, x, n=6, logx=None, bound=0, hir=False): | |||
""" | |||
Returns the asymptotic expansion of self. |
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.
you can add a reference here.
Yes, but the user can call the series method directly. Using
I added the wikipedia reference in the references section. I'll mention that there. |
Again. Please keep context of the discussion. Use "Add a line note" buttons or reply to email notifications.
I'm not sure if you do this right. Please take look to other docstrings and please actually build the documentation.
I mean that you should document all parameters. |
The following line : I tried using When I applied the patch, the substitution works. |
The pull request #7636 removed denesting of certain powers |
No. Someone just don't get familar with git bisect. For commit above the one from #7636:
|
I haven't seen any work on this, so I'm going to bump the milestone. Please let me know if it should be put back on. |
closed in favor of #8542 |
Hi! I have read the algorithm and would like to work upon the XFAIL'ed test. |
Do something like this:
Then commit more changes and push into your own fork at github and create a new PR. Note that you also have to resolve conflicts with master ( |
On Mon, Feb 09, 2015 at 03:26:10PM -0800, Ondřej Čertík wrote:
Conflicts are resolved in the linked pr #8542. (BTW, a little example how you, Ondrej, read pr content first ;)) Unsubscribed. |
There seems to be 2 issues: First: Second:
Just entering the expression in the console raise the error that the answer is dependent on the sign of The hierarchical series expansion should not be attempted to be simplified, rather it should be printed as it is. It is just an intermediate expansion.( Explained at Page 95). However when we substitute the final variable:
it automatically tries to simplify and fails. Any help to how to proceed ? Is there a way to just substitute and not try to evaluate it ? Or should I return as a string ? |
Don't return strings. What kind of simplification are you trying to avoid? |
Consider the XFAIL'ed test:
Following is the expected output:
In the function, one step before the final answer is returned, following is the intermediate output:
with Clearly the answer achieved here is correct. Only substitution of
Basically when the value gets substituted, the expression becomes univariate in Other tests did not have any symbols apart from So what is needed that |
When finding series expansion of a function, In this case |
Great idea! Lets assume something arbitrary about parameters to get random output in turn |
The issue here is that Add shouldn't ever raise NotImplementedError. It should catch the error and return an unevaluated expression. The way O() works, the expression isn't going to be wrong if terms aren't absorbed into it. So I would add a I also don't think it should call gruntz (that is, no |
Yes.
If you have one broken place (contains method) - lets fix one in another, completely unrelated. Sympy way
No. The correct way is enforce the contract "foo.contains(t) should return either boolean or None". Something like this: diff --git a/sympy/series/order.py b/sympy/series/order.py
index 33049a0..6208798 100644
--- a/sympy/series/order.py
+++ b/sympy/series/order.py
@@ -369,7 +369,10 @@ def contains(self, expr):
ratio = self.expr/expr.expr
ratio = powsimp(ratio, deep=True, combine='exp')
for s in common_symbols:
- l = ratio.limit(s, point)
+ try:
+ l = ratio.limit(s, point)
+ except NotImplementedError:
+ l = None
if not isinstance(l, C.Limit):
l = l != 0
else: |
Yes, returning None does sound better, although that would strictly speaking change the API. |
Mentioned above "contract" is a part of the API. Raising a not implemented error - is not, in any case. |
# 6.6 | ||
e = sin(1/x + exp(-x)) - sin(1/x) | ||
assert e.aseries(x) == (1/(24*x**4) - 1/(2*x**2) + 1 + O(x**(-6), (x, oo)))*exp(-x) | ||
assert e.series(x, oo) == (1/(24*x**4) - 1/(2*x**2) + 1 + O(x**(-6), (x, oo)))*exp(-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.
This fails on master.
# 6.15 | ||
e3 = lambda x: exp(exp(exp(x))) | ||
e = e3(x)/e3(x-1/e3(x)) | ||
assert e.aseries(x, n=3) == 1 + exp(x + exp(x))*exp(-exp(exp(x))) + ((-exp(x)/2 - S.Half)*exp(x + exp(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.
+1
def test_issue_7872(): | ||
a, b = symbols('a b', integer=True) | ||
e = exp(1/x + exp(-x**2) * (exp(a*x) - exp(b*x))) - exp(1/x) | ||
assert e.aseries(x, n=3, hir=True) == (exp(2*a*x + 1/x)/2 + exp(2*b*x + 1/x)/2 - \ |
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.
+1
Closing this as all the code apart from example 6.15 is already there in master. I will open a separate PR with that example |
MrvAsympt algorithm to find asymptotic expansion.