# Ticket #7881: 7585_6_gcd.patch

File 7585_6_gcd.patch, 8.5 KB (added by robertwb, 11 years ago)
• ## sage/rings/polynomial/multi_polynomial.pyx

# HG changeset patch
# User David Roe <roed@math.harvard.edu>
# Date 1260893171 18000
# Parent  64dfca1b55f08a0eb1a986fe569e691cdb467298
Makes polynomials respect the _gcd framework so that they can use coercion in gcds.

diff -r 64dfca1b55f0 -r 7094350d64cd sage/rings/polynomial/multi_polynomial.pyx
 a from sage.misc.derivative import multi_derivative from sage.rings.infinity import infinity from sage.structure.element cimport Element def is_MPolynomial(x): return isinstance(x, MPolynomial) """ return multi_derivative(self, args) # gcd and xgcd are repeated from PrincipalIdealDomainElement since polynomials inherit from CommutativeRingElement def gcd(self, right): """ Returns the gcd of self and right, or 0 if both are 0. """ from sage.structure.element import get_coercion_model, gcd if not PY_TYPE_CHECK(right, Element) or not ((right)._parent is self._parent): return get_coercion_model().bin_op(self, right, gcd) return self._gcd(right) def xgcd(self, right): r""" Return the extended gcd of self and other, i.e., elements r, s, t such that .. math:: r = s \cdot self + t \cdot other. .. note:: There is no guarantee on minimality of the cofactors.  In the integer case, see documentation for Integer._xgcd() to obtain minimal cofactors. """ from sage.structure.element import get_coercion_model, xgcd if not PY_TYPE_CHECK(right, Element) or not ((right)._parent is self._parent): return get_coercion_model().bin_op(self, right, xgcd) return self._xgcd(right) def polynomial(self, var): """
• ## sage/rings/polynomial/multi_polynomial_libsingular.pyx

diff -r 64dfca1b55f0 -r 7094350d64cd sage/rings/polynomial/multi_polynomial_libsingular.pyx
 a id_Delete(&_I,r) return new_MP(parent,res) def gcd(self, right, algorithm=None, **kwds): def _gcd(self, right, algorithm=None, **kwds): """ Return the greatest common divisor of self and right.
• ## sage/rings/polynomial/polynomial_element.pyx

diff -r 64dfca1b55f0 -r 7094350d64cd sage/rings/polynomial/polynomial_element.pyx
 a from sage.misc.derivative import multi_derivative from sage.rings.arith import sort_complex_numbers_for_display from sage.rings.arith import sort_complex_numbers_for_display, gcd import polynomial_fateman """ return self * self # gcd and xgcd are repeated from PrincipalIdealDomainElement since polynomials inherit from CommutativeAlgebraElement def gcd(self, right): """ Returns the gcd of self and right, or 0 if both are 0. """ from sage.structure.element import get_coercion_model, gcd if not PY_TYPE_CHECK(right, Element) or not ((right)._parent is self._parent): return get_coercion_model().bin_op(self, right, gcd) return self._gcd(right) def xgcd(self, right): r""" Return the extended gcd of self and other, i.e., elements r, s, t such that .. math:: r = s \cdot self + t \cdot other. .. note:: There is no guarantee on minimality of the cofactors.  In the integer case, see documentation for Integer._xgcd() to obtain minimal cofactors. """ from sage.structure.element import get_coercion_model, xgcd if not PY_TYPE_CHECK(right, Element) or not ((right)._parent is self._parent): return get_coercion_model().bin_op(self, right, xgcd) return self._xgcd(right) def squarefree_decomposition(self): """ Return the square-free decomposition of self. This is a partial
• ## sage/rings/polynomial/polynomial_integer_dense_flint.pyx

diff -r 64dfca1b55f0 -r 7094350d64cd sage/rings/polynomial/polynomial_integer_dense_flint.pyx
 a """ return not (fmpz_poly_degree(self.__poly) == -1) def gcd(self, right): def _gcd(self, right): r""" Return the GCD of self and right.  The leading coefficient need not be 1. return (self//g)*right def xgcd(self, right): def _xgcd(self, right): """ This function can't in general return (g,s,t) as above, since they need not exist.  Instead, over the integers, we
• ## sage/rings/polynomial/polynomial_integer_dense_ntl.pyx

diff -r 64dfca1b55f0 -r 7094350d64cd sage/rings/polynomial/polynomial_integer_dense_ntl.pyx
 a def gcd(self, right): def _gcd(self, right): r""" Return the GCD of self and right.  The leading coefficient need not be 1. return (self * right).quo_rem(g)[0] def xgcd(self, right): def _xgcd(self, right): """ This function can't in general return (g,s,t) as above, since they need not exist.  Instead, over the integers, we
• ## sage/rings/polynomial/polynomial_modn_dense_ntl.pyx

diff -r 64dfca1b55f0 -r 7094350d64cd sage/rings/polynomial/polynomial_modn_dense_ntl.pyx
 a """ A dense polynomial over the integers modulo p, where p is prime. """ def gcd(self, right): return self._gcd(right) def _gcd(self, right): """ Return the GCD of self and other, as a monic polynomial. g = self.ntl_ZZ_pX().gcd(right.ntl_ZZ_pX()) return self.parent()(g, construct=True) def xgcd(self, right): r""" Return the extended gcd of self and other, i.e., elements r, s, t such that .. math:: r = s \cdot self + t \cdot other. """ # copied from sage.structure.element.PrincipalIdealDomainElement due to lack of mult inheritance if not PY_TYPE_CHECK(right, Element) or not ((right)._parent is self._parent): from sage.rings.arith import xgcd return bin_op(self, right, xgcd) return self._xgcd(right) def _xgcd(self, right): """ Return g, u, v such that g = u*self + v*right.
• ## sage/rings/polynomial/polynomial_real_mpfr_dense.pyx

diff -r 64dfca1b55f0 -r 7094350d64cd sage/rings/polynomial/polynomial_real_mpfr_dense.pyx
 a r._normalize() return q, r * leading def gcd(self, other): def _gcd(self, other): """ Returns the gcd of self and other as a monic polynomial. Due to the inherit instability of division in this inexact ring, the results may
• ## sage/rings/polynomial/polynomial_template.pxi

diff -r 64dfca1b55f0 -r 7094350d64cd sage/rings/polynomial/polynomial_template.pxi
 a #assert(r._parent(pari(self) * pari(right)) == r) return r def gcd(self, Polynomial_template other): def _gcd(self, Polynomial_template other): """ Return the greatest common divisor of self and other. #assert(r._parent(pari(self).gcd(pari(other))) == r) return r def xgcd(self, Polynomial_template other): def _xgcd(self, Polynomial_template other): """ Computes extended gcd of self and other.