Skip to content

Commit

Permalink
Trac #17402: SR.power_series cannot handle symbolic series
Browse files Browse the repository at this point in the history
{{{
sage: x=var('x')
sage: s=(1/(1-x)).series(x,6)
sage: ps=s.power_series(SR)
sage: ps
x^5 + x^4 + x^3 + x^2 + x + Order(x^6) + 1 + O(x)
sage: ps=s.power_series(QQ)
...
TypeError: unable to convert 1 + 1*x + 1*x^2 + 1*x^3 + 1*x^4 + 1*x^5 +
Order(x^6) to a rational
}}}
This is analogous to #16203 and can be worked around using `truncate()`
but really should work out of the box.

URL: http://trac.sagemath.org/17402
Reported by: rws
Ticket author(s): Ralf Stephan
Reviewer(s): Volker Braun
  • Loading branch information
Release Manager authored and vbraun committed Feb 24, 2016
2 parents 9d4c988 + 00c35cd commit 0ea8360
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/sage/symbolic/series.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,21 @@ cdef class SymbolicSeries(Expression):
ret[c[1]] = c[0]
return ret

def power_series(self, base_ring):
"""
Return algebraic power series associated to this symbolic
series. The coefficients must be coercible to the base ring.
EXAMPLES::
sage: ex=(gamma(1-x)).series(x,3); ex
1 + (euler_gamma)*x + (1/2*euler_gamma^2 + 1/12*pi^2)*x^2 + Order(x^3)
sage: g=ex.power_series(SR); g
1 + euler_gamma*x + (1/2*euler_gamma^2 + 1/12*pi^2)*x^2 + O(x^3)
sage: g.parent()
Power Series Ring in x over Symbolic Ring
"""
from sage.rings.all import PowerSeriesRing
R = PowerSeriesRing(base_ring, names=str(self.default_variable()))
return R(self.list(), self.degree(self.default_variable()))

0 comments on commit 0ea8360

Please sign in to comment.