# Coercion from symbolic ring to Laurent series ring?

Is there a good way to convert from a symbolic expression to a Laurent series ring? For example, if x is a symbolic variable and LSR is a laurent series ring, then sage produces an error for

LSR(1/x)

saying that the element is not integral.

edit retag close merge delete

You should rather avoid using the symbolic ring at all if possible.

Sort by » oldest newest most voted

This is a known bug in Sage, developers are working on it.

In the meanwhile, a workaround is to use the numerator and denominator.

Suppose you have defined the Laurent series ring

sage: L.<x> = LaurentSeriesRing(QQ)


and the symbolic variable

sage: xx = SR.var('x')


and you want to convert this symbolic expression

sage: f = 1/xx + xx
sage: f
x + 1/x


into an element of L, the direct approach fails as you noted

sage L(f)
Traceback (most recent call last)
...
TypeError: denominator must be a unit


but this will work:

sage: a, b = f.numerator(), f.denominator()
sage: L(a) / L(b)
x^-1 + x


You can now write a small function laurent that will take f and L as arguments, and return L(f.numerator())/L(f.denominator()).

def laurent(f, L):
"""
Return the Laurent series for this symbolic expression
"""
return L(f.numerator()) / L(f.denominator())


Test it using the above examples

sage: laurent(f, L)
x^-1 + x

more