ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 20 Jun 2016 05:14:23 -0500Coercion from symbolic ring to Laurent series ring?https://ask.sagemath.org/question/33806/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.Wed, 15 Jun 2016 16:12:44 -0500https://ask.sagemath.org/question/33806/coercion-from-symbolic-ring-to-laurent-series-ring/Comment by FrédéricC for <p>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 </p>
<p>LSR(1/x)</p>
<p>saying that the element is not integral.</p>
https://ask.sagemath.org/question/33806/coercion-from-symbolic-ring-to-laurent-series-ring/?comment=33826#post-id-33826You should rather avoid using the symbolic ring at all if possible.Fri, 17 Jun 2016 07:02:25 -0500https://ask.sagemath.org/question/33806/coercion-from-symbolic-ring-to-laurent-series-ring/?comment=33826#post-id-33826Answer by slelievre for <p>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 </p>
<p>LSR(1/x)</p>
<p>saying that the element is not integral.</p>
https://ask.sagemath.org/question/33806/coercion-from-symbolic-ring-to-laurent-series-ring/?answer=33857#post-id-33857This 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
Mon, 20 Jun 2016 05:14:23 -0500https://ask.sagemath.org/question/33806/coercion-from-symbolic-ring-to-laurent-series-ring/?answer=33857#post-id-33857