-
-
Notifications
You must be signed in to change notification settings - Fork 597
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
Fix conversion from symbolic expressions with nonintegral exponents to power series ring #39809
Open
TinaJin0228
wants to merge
2
commits into
sagemath:develop
Choose a base branch
from
TinaJin0228:conversion-to-power-series
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -820,6 +820,20 @@ def _element_constructor_(self, f, prec=infinity, check=True): | |
sage: R(ex) | ||
1 + euler_gamma*y + (1/2*euler_gamma^2 + 1/12*pi^2)*y^2 + O(y^3) | ||
|
||
Conversion from general symbolic expressions (see :issue:`39736`):: | ||
|
||
sage: # Conversion from non-polynomial symbolic expressions, e.g. sqrt(1+x) | ||
sage: R.<x> = PowerSeriesRing(QQ, default_prec=7) | ||
sage: f = R(sqrt(1+x)) | ||
sage: f | ||
1 + 1/2*x - 1/8*x^2 + 1/16*x^3 - 5/128*x^4 + 7/256*x^5 - 21/1024*x^6 + O(x^7) | ||
sage: g = R(sin(x)) | ||
sage: g | ||
x - 1/6*x^3 + 1/120*x^5 + O(x^7) | ||
sage: t = R(e^x) | ||
sage: t | ||
1 + x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + O(x^7) | ||
|
||
Laurent series with nonnegative valuation are accepted (see | ||
:issue:`6431`):: | ||
|
||
|
@@ -878,6 +892,16 @@ def _element_constructor_(self, f, prec=infinity, check=True): | |
check=check) | ||
else: | ||
raise TypeError("Can only convert series into ring with same variable name.") | ||
else: | ||
from sage.symbolic.ring import SR | ||
sym_var = SR.var(self.variable_name()) | ||
if f.is_polynomial(sym_var): | ||
poly_ring = self._poly_ring() | ||
return self.element_class(self, poly_ring(f), prec, check=check) | ||
func = f.function(sym_var) # test for exception | ||
L = LazyPowerSeriesRing(self.base_ring(), self.variable_name()) | ||
series_lazy = L.taylor(func) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's another way to get the Taylor expansion
Are they equivalent, if not is there any significant difference (e.g. which one is faster?) |
||
return self(series_lazy, prec=prec, check=check) | ||
else: | ||
from sage.rings.lazy_series import LazyPowerSeries | ||
if isinstance(f, LazyPowerSeries): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what does this comment mean here (I thought we're not testing for exception here…?)
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.
my fault, I forget to delete it after the testing...