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_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(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 super_categories(self): """ EXAMPLES:: sage: DiscreteValuationRings().super_categories() [Category of euclidean domains] """ return [EuclideanDomains()]
def extra_super_categories(self): """ EXAMPLES:: sage: Fields().extra_super_categories() [Category of euclidean domains] """ return [EuclideanDomains()]
def super_categories(self): """ EXAMPLES:: sage: Fields().super_categories() [Category of euclidean domains, Category of unique factorization domains, Category of division rings] """ return [EuclideanDomains(), UniqueFactorizationDomains(), DivisionRings()]
def _convert_map_from_(self, R): """ Finds conversion maps from R to this ring. Currently, a conversion exists if the defining polynomial is the same. EXAMPLES:: sage: R.<a> = Zq(125) sage: S = R.change(type='capped-abs', prec=40, print_mode='terse', print_pos=False) sage: S(a - 15) -15 + a + O(5^20) We get conversions from the exact field:: sage: K = R.exact_field(); K Number Field in a with defining polynomial x^3 + 3*x + 3 sage: R(K.gen()) a + O(5^20) and its maximal order:: sage: OK = K.maximal_order() sage: R(OK.gen(1)) a + O(5^20) """ cat = None if self._implementation == 'NTL' and R == QQ: # Want to use DefaultConvertMap_unique return None if isinstance(R, pAdicExtensionGeneric) and R.prime() == self.prime( ) and R.defining_polynomial(exact=True) == self.defining_polynomial( exact=True): if R.is_field() and not self.is_field(): cat = SetsWithPartialMaps() elif R.category() is self.category(): cat = R.category() else: cat = EuclideanDomains() & MetricSpaces().Complete() elif isinstance(R, Order) and R.number_field().defining_polynomial( ) == self.defining_polynomial(): cat = IntegralDomains() elif isinstance(R, NumberField) and R.defining_polynomial( ) == self.defining_polynomial(): if self.is_field(): cat = Fields() else: cat = SetsWithPartialMaps() else: k = self.residue_field() if R is k: return ResidueLiftingMap._create_(R, self) if cat is not None: H = Hom(R, self, cat) return H.__make_element_class__(DefPolyConversion)(H)