Ask Your Question

Revision history [back]

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