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 = 0
for i in range(0, n):
summand = coeff * (R_ordinary.gen(i)) ^ (exp[i] + shift[i])
ret += 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.