Ask Your Question
2

GCD of multivariable polynomials and conversion of Laurent polynomials to ordinary polynomials

asked 2016-04-30 00:27:56 +0200

Eilenberg gravatar image

updated 2017-04-06 19:05:39 +0200

FrédéricC gravatar image

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 ... (more)

edit retag flag offensive close merge delete

Comments

I've not read all your code (I'll do it later) but as a quick answer to your second question: The problem is that gcd of multivariate polynomial over CC appears not to be implemented. [EDIT] Introduced in ticket #20220, available from version 7.2beta1. [/EDIT] Three solutions: 1. You work over another field than CC (probably not applicable...); 2. You convert your polynomials to "recursive univariate" polynomials (ring CC['t1']['t2']...['tn']) and use the gcd provided for these univariate polynomial rings; 3. (Better!) You propose a ticket on trac.sagemath.org to add a gcd implementation for multivariate polynomials over CC (or a generic implementation). Use Sage version at least 7.2beta1.

B r u n o gravatar imageB r u n o ( 2016-04-30 23:48:39 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2016-05-02 15:31:53 +0200

B r u n o gravatar image

updated 2016-05-02 15:32:42 +0200

A more complete answer:

  1. First question: The code you are writing does not appear to be redundant with any of Sage's methods. As a comment, note that given a Laurent polynomial p, you can access its parent (the Laurent polynomial ring) using p.parent(), and the corresponding polynomial ring using p.parent().polynomial_ring() so that you do not need to pass the polynomial ring as argument of your last method. In the same way, the number n of variables is accessible through p.parent().ngens().

  2. As I wrote in the comment, multivariate polynomials over CC have no method gcd yet. Actually, I forgot that I added such a method in the ticket #20220, that is merged in sage version 7.2beta1.¹ In the cloud.sagemath.com, the current version seems to be version 6.10 (type sage -v in a terminal to get the information), but you can access a more recent version, though potentially buggy, using sage-develop (which is 7.2beta6 apparently, so contains in particular the code I introduced in #20220).

¹ That is, it will be available in the future version 7.2 of Sage.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-04-30 00:21:39 +0200

Seen: 684 times

Last updated: May 02 '16