def _gcd_univariate_polynomial(self, f, g): """ Return the greatest common divisor of ``f`` and ``g``, as a monic polynomial. INPUT: - ``f``, ``g`` -- two polynomials defined over ``self`` .. NOTE:: This is a helper method for :meth:`sage.rings.polynomial.polynomial_element.Polynomial.gcd`. EXAMPLES:: sage: R.<x> = QQbar[] sage: QQbar._gcd_univariate_polynomial(2*x,2*x^2) x """ ret = EuclideanDomains().element_class.gcd(f, g) c = ret.leading_coefficient() if c.is_unit(): return (1 / c) * ret return ret
def gcd(self, other): """ Return the greatest common divisor of this polynomial and ``other``, as a monic polynomial. INPUT: - ``other`` -- a polynomial defined over the same ring as ``self`` EXAMPLES:: sage: R.<x> = QQbar[] sage: (2*x).gcd(2*x^2) x sage: zero = R.zero() sage: zero.gcd(2*x) x sage: (2*x).gcd(zero) x sage: zero.gcd(zero) 0 """ from sage.categories.euclidean_domains import EuclideanDomains g = EuclideanDomains().ElementMethods().gcd(self, other) c = g.leading_coefficient() if c.is_unit(): return (1 / c) * g return g
def _gcd_univariate_polynomial(self, f, g): """ Return the greatest common divisor of ``f`` and ``g``, as a monic polynomial. INPUT: - ``f``, ``g`` -- two polynomials defined over ``self`` .. NOTE:: This is a helper method for :meth:`sage.rings.polynomial.polynomial_element.Polynomial.gcd`. EXAMPLES:: sage: R.<x> = QQbar[] sage: QQbar._gcd_univariate_polynomial(2*x,2*x^2) x """ ret = EuclideanDomains().ElementMethods().gcd(f,g) c = ret.leading_coefficient() if c.is_unit(): return (1/c)*ret return ret
def gcd(self, other): """ Return the greatest common divisor of this polynomial and ``other``, as a monic polynomial. INPUT: - ``other`` -- a polynomial defined over the same ring as ``self`` EXAMPLES:: sage: R.<x> = QQbar[] sage: (2*x).gcd(2*x^2) x sage: zero = R.zero() sage: zero.gcd(2*x) x sage: (2*x).gcd(zero) x sage: zero.gcd(zero) 0 """ from sage.categories.euclidean_domains import EuclideanDomains g = EuclideanDomains().ElementMethods().gcd(self, other) c = g.leading_coefficient() if c.is_unit(): return (1/c)*g return g