ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 19 Nov 2017 13:35:21 -0600How do I code a Laurent Series with variable coefficients?http://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'masseygirlSun, 19 Nov 2017 13:35:21 -0600http://ask.sagemath.org/question/39662/GCD of multivariable polynomials and conversion of Laurent polynomials to ordinary polynomialshttp://ask.sagemath.org/question/33260/gcd-of-multivariable-polynomials-and-conversion-of-laurent-polynomials-to-ordinary-polynomials/Let's assume that I am working with some set of Laurent polynomials in $\mathbb{C}[t_1^{\pm1}, \ldots, t_n^{\pm 1}]$.
R = LaurentPolynomialRing(CC, 't', n)
My first question: is there any method which would multiply elements of $R$ by a big enough monomial $t_1^{k_1}\cdot \ldots \cdot t_n^{k_n}$ to get rid of the negative powers and after that changed them to ordinary polynomials? I will consider resulting polynomials up to $t_1^{k_1}\cdot \ldots \cdot t_n^{k_n}$, so $k_i$'s don't matter that much as long as multiplication will result in a Laurent polynomial with non-negative powers (however I would like to avoid shifting exponents by some huge constant). At the moment I am using following workaround which I hope is redundant to some sage method.
# Since I am working over C I would like to get rid of summands coming from numeric errors
def clean_poly(laurent_poly, precision):
decomp = list(laurent_poly)
ret = 0
for (coeff, monom) in decomp:
if(coeff * coeff.conjugate() >= precision):
ret += coeff * monom
return ret
# Here I am finding lowest exponents of laurent_poly corresponding to particular t_i's
def find_shift(laurent_poly, n):
shift = [0 for i in range(0, n)]
for exp in laurent_poly.exponents():
for i in range(0, n):
shift[i] = max(shift[i], -exp[i])
return shift
def change_laurent_poly_to_ordinary(laurent_poly, R_ordinary, n):
laurent_poly = clean_poly(laurent_poly, 0.00000000001)
decomp = list(laurent_poly)
shift = find_shift(laurent_poly, n)
ret = 0
for (coeff, monom) in decomp:
exp = monom.exponents()
exp = exp[0]
summand = 1
for i in range(0, n):
summand *= (R_ordinary.gen(i)) ^ (exp[i] + shift[i])
ret += coeff * summand
return ret
Where $R_{\text{ordinary}} = \mathbb{C}[t_1, \ldots, t_n]$ is passed as argument in the last method.
R_ordinary = PolynomialRing(CC, 's', n)
My second and the most important question is how to fix the last method to return a polynomial which posses a gcd() method just like in this snippet which I've found in the documentation (I can't post a link due to insufficient karma):
sage: R, (x, y) = PolynomialRing(RationalField(), 2, 'xy').objgens()
sage: f = (x^3 + 2*y^2*x)^2
sage: g = x^2*y^2
sage: f.gcd(g)
x^2
Unfortunately at the moment method change_laurent_poly_to_ordinary returns class of type MPolynomial_polydict which doesn't have gcd() method, what results in the following error after attempting to use them:
Traceback (most recent call last):
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 28, in <module>
File "sage/structure/element.pyx", line 420, in sage.structure.element.Element.__getattr__ (/projects/sage/sage-6.10/src/build/cythonized/sage/structure/element.c:4675)
return getattr_from_other_class(self, P._abstract_element_class, name)
File "sage/structure/misc.pyx", line 259, in sage.structure.misc.getattr_from_other_class (/projects/sage/sage-6.10/src/build/cythonized/sage/structure/misc.c:1771)
raise dummy_attribute_error
AttributeError: 'MPolynomial_polydict' object has no attribute 'gcd'
I am working with sage version offered by cloud sagemath.EilenbergFri, 29 Apr 2016 17:21:39 -0500http://ask.sagemath.org/question/33260/