Skip to content
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
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/sage/rings/power_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`)::

Expand Down Expand Up @@ -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
Copy link
Contributor

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…?)

Copy link
Contributor Author

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...

L = LazyPowerSeriesRing(self.base_ring(), self.variable_name())
series_lazy = L.taylor(func)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's another way to get the Taylor expansion

sage: (1/(x+1)).series(x, 10)
1 + (-1)*x + 1*x^2 + (-1)*x^3 + 1*x^4 + (-1)*x^5 + 1*x^6 + (-1)*x^7 + 1*x^8 + (-1)*x^9 + Order(x^10)

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):
Expand Down