ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 22 Nov 2017 00:04:45 +0100How do I code a Laurent Series with variable coefficients?https://ask.sagemath.org/question/39662/how-do-i-code-a-laurent-series-with-variable-coefficients/Edit: Adding more context.
I am attempting the following procedure:
1. Begin with a polynomial $Z(u)$ with variable coefficients, of the form $1 + a*u + b*u^2 + c*u^3 + p*b*u^4 + p^2*a*u^5 + p^3*u^6$.
2. Examine the coefficients of $Z'(u)/Z(u)$ as a power series in $u$.
It is this quest which leads me to attempt to construct a LaurentSeriesRing with variable coefficients. However, I keep encountering TypeErrors, I am wondering if a kind soul could help me in my quest. I will use here a very simple polynomial f to get the point across.
I am attempting to construct a LaurentSeriesRing with variable coefficients. However, I keep encountering TypeErrors, I am wondering if a kind soul could help me in my quest. I will use here a very simple polynomial f to get the point across.
sage: R.<t> = LaurentSeriesRing(QQ, 't')
sage: var('a')
a
sage: f = 1 + a*t
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-31-06d3f2f41e45> in <module>()
----> 1 f = Integer(1) + a*t
sage/structure/element.pyx in sage.structure.element.Element.__mul__ (/usr/lib/sagemath//src/build/cythonized/sage/structure/element.c:12443)()
sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (/usr/lib/sagemath//src/build/cythonized/sage/structure/coerce.c:10496)()
TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and 'Laurent Series Ring in t over Rational Field'
I also tried:
sage: R.<u> = QQ[]
sage: var('a')
a
sage: f = 1 + a*u
sage: ff = derivative(f, u)
sage: R.<u> = LaurentSeriesRing(QQ); R
sage: f/ff + O(u^5)
----------------------
TypeError Traceback (most recent call last)
<ipython-input-28-c4846de7ced8> in <module>()
----> 1 f/ff + O(u**Integer(5))
sage/structure/element.pyx in sage.structure.element.Element.__add__ (/usr/lib/sagemath//src/build/cythonized/sage/structure/element.c:11198)()
sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (/usr/lib/sagemath//src/build/cythonized/sage/structure/coerce.c:10496)()
TypeError: unsupported operand parent(s) for '+': 'Symbolic Ring' and 'Laurent Series Ring in u over Rational Field'Sun, 19 Nov 2017 20:35:21 +0100https://ask.sagemath.org/question/39662/how-do-i-code-a-laurent-series-with-variable-coefficients/Answer by vdelecroix for <p>Edit: Adding more context.</p>
<p>I am attempting the following procedure: </p>
<ol>
<li>Begin with a polynomial $Z(u)$ with variable coefficients, of the form $1 + a<em>u + b</em>u^2 + c<em>u^3 + p</em>b<em>u^4 + p^2</em>a<em>u^5 + p^3</em>u^6$. </li>
<li>Examine the coefficients of $Z'(u)/Z(u)$ as a power series in $u$.</li>
</ol>
<p>It is this quest which leads me to attempt to construct a LaurentSeriesRing with variable coefficients. However, I keep encountering TypeErrors, I am wondering if a kind soul could help me in my quest. I will use here a very simple polynomial f to get the point across.</p>
<p>I am attempting to construct a LaurentSeriesRing with variable coefficients. However, I keep encountering TypeErrors, I am wondering if a kind soul could help me in my quest. I will use here a very simple polynomial f to get the point across.</p>
<pre><code>sage: R.<t> = LaurentSeriesRing(QQ, 't')
sage: var('a')
a
sage: f = 1 + a*t
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-31-06d3f2f41e45> in <module>()
----> 1 f = Integer(1) + a*t
sage/structure/element.pyx in sage.structure.element.Element.__mul__ (/usr/lib/sagemath//src/build/cythonized/sage/structure/element.c:12443)()
sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (/usr/lib/sagemath//src/build/cythonized/sage/structure/coerce.c:10496)()
TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and 'Laurent Series Ring in t over Rational Field'
</code></pre>
<p>I also tried: </p>
<pre><code>sage: R.<u> = QQ[]
sage: var('a')
a
sage: f = 1 + a*u
sage: ff = derivative(f, u)
sage: R.<u> = LaurentSeriesRing(QQ); R
sage: f/ff + O(u^5)
----------------------
TypeError Traceback (most recent call last)
<ipython-input-28-c4846de7ced8> in <module>()
----> 1 f/ff + O(u**Integer(5))
sage/structure/element.pyx in sage.structure.element.Element.__add__ (/usr/lib/sagemath//src/build/cythonized/sage/structure/element.c:11198)()
sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (/usr/lib/sagemath//src/build/cythonized/sage/structure/coerce.c:10496)()
TypeError: unsupported operand parent(s) for '+': 'Symbolic Ring' and 'Laurent Series Ring in u over Rational Field'
</code></pre>
https://ask.sagemath.org/question/39662/how-do-i-code-a-laurent-series-with-variable-coefficients/?answer=39664#post-id-39664One possibility is to use multivariate Laurent polynomials and let one variable be your parameter
sage: R.<a,t> = LaurentSeriesRing(QQ)
sage: R
Multivariate Laurent Polynomial Ring in a, t over Rational Field
another one is to use coefficients being themselves polynomials
sage: P.<t> = PolynomialRing(QQ)
sage: R.<a> = LaurentSeriesRing(P)
sage: R
Univariate Laurent Polynomial Ring in a over Univariate Polynomial Ring in t over Rational Field
There are also several other ways but everything depends on what you want to do with them... try to make your question more precise.
EDIT: to expand a quotient (of polynomials) with parameters, the second method is more appropriate
sage: P.<t> = PolynomialRing(QQ)
sage: R.<a> = LaurentSeriesRing(P)
sage: num = (t^2 + 1) * a^2 + (-t + 2) * a + (t^2 - 1)
sage: den = (t^3 + t + 1) * a^2 + (2*t + 5) * a - 1
sage: num / den
(-t^2 + 1) + (-2*t^3 - 5*t^2 + 3*t + 3)*a + ... + O(a^20)Sun, 19 Nov 2017 22:11:22 +0100https://ask.sagemath.org/question/39662/how-do-i-code-a-laurent-series-with-variable-coefficients/?answer=39664#post-id-39664Comment by masseygirl for <p>One possibility is to use multivariate Laurent polynomials and let one variable be your parameter</p>
<pre><code>sage: R.<a,t> = LaurentSeriesRing(QQ)
sage: R
Multivariate Laurent Polynomial Ring in a, t over Rational Field
</code></pre>
<p>another one is to use coefficients being themselves polynomials</p>
<pre><code>sage: P.<t> = PolynomialRing(QQ)
sage: R.<a> = LaurentSeriesRing(P)
sage: R
Univariate Laurent Polynomial Ring in a over Univariate Polynomial Ring in t over Rational Field
</code></pre>
<p>There are also several other ways but everything depends on what you want to do with them... try to make your question more precise.</p>
<p>EDIT: to expand a quotient (of polynomials) with parameters, the second method is more appropriate</p>
<pre><code>sage: P.<t> = PolynomialRing(QQ)
sage: R.<a> = LaurentSeriesRing(P)
sage: num = (t^2 + 1) * a^2 + (-t + 2) * a + (t^2 - 1)
sage: den = (t^3 + t + 1) * a^2 + (2*t + 5) * a - 1
sage: num / den
(-t^2 + 1) + (-2*t^3 - 5*t^2 + 3*t + 3)*a + ... + O(a^20)
</code></pre>
https://ask.sagemath.org/question/39662/how-do-i-code-a-laurent-series-with-variable-coefficients/?comment=39667#post-id-39667I am attempting to expand as a power series a quotient with variable coefficients. With this formalism, I am still unable to expand the polynomial quotient I receive (for my more complicated quotient, still in a and t) by adding + O(t^5).Mon, 20 Nov 2017 08:41:50 +0100https://ask.sagemath.org/question/39662/how-do-i-code-a-laurent-series-with-variable-coefficients/?comment=39667#post-id-39667Comment by vdelecroix for <p>One possibility is to use multivariate Laurent polynomials and let one variable be your parameter</p>
<pre><code>sage: R.<a,t> = LaurentSeriesRing(QQ)
sage: R
Multivariate Laurent Polynomial Ring in a, t over Rational Field
</code></pre>
<p>another one is to use coefficients being themselves polynomials</p>
<pre><code>sage: P.<t> = PolynomialRing(QQ)
sage: R.<a> = LaurentSeriesRing(P)
sage: R
Univariate Laurent Polynomial Ring in a over Univariate Polynomial Ring in t over Rational Field
</code></pre>
<p>There are also several other ways but everything depends on what you want to do with them... try to make your question more precise.</p>
<p>EDIT: to expand a quotient (of polynomials) with parameters, the second method is more appropriate</p>
<pre><code>sage: P.<t> = PolynomialRing(QQ)
sage: R.<a> = LaurentSeriesRing(P)
sage: num = (t^2 + 1) * a^2 + (-t + 2) * a + (t^2 - 1)
sage: den = (t^3 + t + 1) * a^2 + (2*t + 5) * a - 1
sage: num / den
(-t^2 + 1) + (-2*t^3 - 5*t^2 + 3*t + 3)*a + ... + O(a^20)
</code></pre>
https://ask.sagemath.org/question/39662/how-do-i-code-a-laurent-series-with-variable-coefficients/?comment=39682#post-id-39682Then I advice you to edit your own question starting with what you are trying to achieve together with an example of a quotient.Mon, 20 Nov 2017 21:41:19 +0100https://ask.sagemath.org/question/39662/how-do-i-code-a-laurent-series-with-variable-coefficients/?comment=39682#post-id-39682Comment by masseygirl for <p>One possibility is to use multivariate Laurent polynomials and let one variable be your parameter</p>
<pre><code>sage: R.<a,t> = LaurentSeriesRing(QQ)
sage: R
Multivariate Laurent Polynomial Ring in a, t over Rational Field
</code></pre>
<p>another one is to use coefficients being themselves polynomials</p>
<pre><code>sage: P.<t> = PolynomialRing(QQ)
sage: R.<a> = LaurentSeriesRing(P)
sage: R
Univariate Laurent Polynomial Ring in a over Univariate Polynomial Ring in t over Rational Field
</code></pre>
<p>There are also several other ways but everything depends on what you want to do with them... try to make your question more precise.</p>
<p>EDIT: to expand a quotient (of polynomials) with parameters, the second method is more appropriate</p>
<pre><code>sage: P.<t> = PolynomialRing(QQ)
sage: R.<a> = LaurentSeriesRing(P)
sage: num = (t^2 + 1) * a^2 + (-t + 2) * a + (t^2 - 1)
sage: den = (t^3 + t + 1) * a^2 + (2*t + 5) * a - 1
sage: num / den
(-t^2 + 1) + (-2*t^3 - 5*t^2 + 3*t + 3)*a + ... + O(a^20)
</code></pre>
https://ask.sagemath.org/question/39662/how-do-i-code-a-laurent-series-with-variable-coefficients/?comment=39714#post-id-39714Thank you very much, your edit was a lifesaver, and now everything works!Wed, 22 Nov 2017 00:04:45 +0100https://ask.sagemath.org/question/39662/how-do-i-code-a-laurent-series-with-variable-coefficients/?comment=39714#post-id-39714