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.Thu, 13 Jul 2017 23:56:37 +0200Recasting Laurent polynomialshttps://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. Mon, 12 Jun 2017 01:52:04 +0200https://ask.sagemath.org/question/37914/recasting-laurent-polynomials/Comment by krishna for <p>Hi, </p>
<p>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). </p>
<p>However, I'm not able to do so on the Sage Cloud. </p>
<p>So far, I've tried the following:</p>
<ol>
<li>Extracting the monomials of f and g, and their coefficients, and reconstructed f by:</li>
</ol>
<p><code>sum(map(mul,zip(f.coefficients(),f.monomials())))</code></p>
<p>However, this didn't help, because SAGE thinks the type is:</p>
<pre><code><type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>
</code></pre>
<p>so I still can't take the gcd.</p>
<ol>
<li><p>I also tried to recast into R.<x,y> = ZZ[], but this didn't work either: when I do <code>sage: f.change_ring(R)</code>, I get the following error:</p>
<p><code>AttributeError: 'sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair' object has no attribute 'change_ring'</code></p></li>
</ol>
<p>Any suggestions would be greatly appreciated!! Thanks so much. </p>
https://ask.sagemath.org/question/37914/recasting-laurent-polynomials/?comment=37915#post-id-37915Also, I have already seen (https://ask.sagemath.org/question/33260/gcd-of-multivariable-polynomials-and-conversion-of-laurent-polynomials-to-ordinary-polynomials/), but it didn't help me fix the issue at hand. Thanks again!Mon, 12 Jun 2017 01:52:12 +0200https://ask.sagemath.org/question/37914/recasting-laurent-polynomials/?comment=37915#post-id-37915Comment by dan_fulea for <p>Hi, </p>
<p>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). </p>
<p>However, I'm not able to do so on the Sage Cloud. </p>
<p>So far, I've tried the following:</p>
<ol>
<li>Extracting the monomials of f and g, and their coefficients, and reconstructed f by:</li>
</ol>
<p><code>sum(map(mul,zip(f.coefficients(),f.monomials())))</code></p>
<p>However, this didn't help, because SAGE thinks the type is:</p>
<pre><code><type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>
</code></pre>
<p>so I still can't take the gcd.</p>
<ol>
<li><p>I also tried to recast into R.<x,y> = ZZ[], but this didn't work either: when I do <code>sage: f.change_ring(R)</code>, I get the following error:</p>
<p><code>AttributeError: 'sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair' object has no attribute 'change_ring'</code></p></li>
</ol>
<p>Any suggestions would be greatly appreciated!! Thanks so much. </p>
https://ask.sagemath.org/question/37914/recasting-laurent-polynomials/?comment=37917#post-id-37917Please give two simple polynomials f and g, (simple, but still relevant as an example,) and the code initializing them. Then what does it mean to "recast" them? (Mathematically...) And which gcd (over which polynomial ring) should be taken?Mon, 12 Jun 2017 17:02:39 +0200https://ask.sagemath.org/question/37914/recasting-laurent-polynomials/?comment=37917#post-id-37917Comment by vdelecroix for <p>Hi, </p>
<p>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). </p>
<p>However, I'm not able to do so on the Sage Cloud. </p>
<p>So far, I've tried the following:</p>
<ol>
<li>Extracting the monomials of f and g, and their coefficients, and reconstructed f by:</li>
</ol>
<p><code>sum(map(mul,zip(f.coefficients(),f.monomials())))</code></p>
<p>However, this didn't help, because SAGE thinks the type is:</p>
<pre><code><type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>
</code></pre>
<p>so I still can't take the gcd.</p>
<ol>
<li><p>I also tried to recast into R.<x,y> = ZZ[], but this didn't work either: when I do <code>sage: f.change_ring(R)</code>, I get the following error:</p>
<p><code>AttributeError: 'sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair' object has no attribute 'change_ring'</code></p></li>
</ol>
<p>Any suggestions would be greatly appreciated!! Thanks so much. </p>
https://ask.sagemath.org/question/37914/recasting-laurent-polynomials/?comment=38243#post-id-38243Note that `change_ring` is for changing the **base ring** (ZZ in your case)Thu, 13 Jul 2017 23:56:37 +0200https://ask.sagemath.org/question/37914/recasting-laurent-polynomials/?comment=38243#post-id-38243Comment by B r u n o for <p>Hi, </p>
<p>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). </p>
<p>However, I'm not able to do so on the Sage Cloud. </p>
<p>So far, I've tried the following:</p>
<ol>
<li>Extracting the monomials of f and g, and their coefficients, and reconstructed f by:</li>
</ol>
<p><code>sum(map(mul,zip(f.coefficients(),f.monomials())))</code></p>
<p>However, this didn't help, because SAGE thinks the type is:</p>
<pre><code><type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>
</code></pre>
<p>so I still can't take the gcd.</p>
<ol>
<li><p>I also tried to recast into R.<x,y> = ZZ[], but this didn't work either: when I do <code>sage: f.change_ring(R)</code>, I get the following error:</p>
<p><code>AttributeError: 'sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair' object has no attribute 'change_ring'</code></p></li>
</ol>
<p>Any suggestions would be greatly appreciated!! Thanks so much. </p>
https://ask.sagemath.org/question/37914/recasting-laurent-polynomials/?comment=37923#post-id-37923If your Laurent polynomials happen to be classical polynomials (no negative powers), you can do as follows:
sage: R.<x,y> = LaurentPolynomialRing(ZZ)
sage: S.<X,Y> = PolynomialRing(ZZ)
sage: f = x^2+y^2+1 # Laurent polynomial
sage: g = x*y - 1 # Laurent polynomial
sage: F = S(f.dict()) # Classical polynomial
sage: G = S(g.dict()) # Classical polynomial
sage: H = F.gcd(G) # Classical polynomial
sage: h = R(H) # Laurent polynomial
Note that you could then define a gcd for Laurent polynomial that have no negative power quite easily.Tue, 13 Jun 2017 11:21:18 +0200https://ask.sagemath.org/question/37914/recasting-laurent-polynomials/?comment=37923#post-id-37923