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.Thu, 10 May 2018 15:48:58 -0500polynomials with roots of unity as coefficientshttp://ask.sagemath.org/question/42307/polynomials-with-roots-of-unity-as-coefficients/I have three polynomials $(1+x)^L+1$, $(1+\omega x)^L+$ and $(1+\omega^2 x)^L+1$ where $\omega$ is cube root of unity and L is some constant, for example, 2 or 3. I want to find the GCD of these polynomials. How do I define these polynomials in sagemath with coefficients as roots of unity?arpitThu, 10 May 2018 15:48:58 -0500http://ask.sagemath.org/question/42307/Recasting Laurent polynomialshttp://ask.sagemath.org/question/37914/recasting-laurent-polynomials/Hi,
I have 2 Laurent polynomials, f and g, and I'm trying to recast them into multivariable polynomials over ZZ (I'm eventually going to take their gcd).
However, I'm not able to do so on the Sage Cloud.
So far, I've tried the following:
1. Extracting the monomials of f and g, and their coefficients, and reconstructed f by:
`sum(map(mul,zip(f.coefficients(),f.monomials())))`
However, this didn't help, because SAGE thinks the type is:
<type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>
so I still can't take the gcd.
2. I also tried to recast into R.<x,y> = ZZ[], but this didn't work either: when I do `sage: f.change_ring(R)`, I get the following error:
`AttributeError: 'sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair' object has no attribute 'change_ring'`
Any suggestions would be greatly appreciated!! Thanks so much. krishnaSun, 11 Jun 2017 18:52:04 -0500http://ask.sagemath.org/question/37914/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/