Ticket #13438: trac_13438.patch

File trac_13438.patch, 5.0 KB (added by saraedum, 7 years ago)
  • sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py

    # HG changeset patch
    # User Julian Rueth <julian.rueth@gmail.com>
    # Date 1350770071 0
    # Node ID 7ffe38b585130075a207b9069d9f0d72c0e231d6
    # Parent  698ec14c513f99fa5a3a7aeca982cc14fd249a89
    Trac #13438: moved _xgcd from general polynomial to polynomials over fields.
    
    diff --git a/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py b/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py
    a b class Polynomial_padic_capped_relative_dense(Polynomial_generic_domain): 
    975975        from sage.misc.stopgap import stopgap
    976976        stopgap("Extended gcd computations over p-adic fields are performed using the standard Euclidean algorithm which might produce mathematically incorrect results in some cases.", 13439)
    977977
    978         return self._xgcd(right)
     978        from sage.rings.polynomial.polynomial_element_generic import Polynomial_generic_field
     979        return Polynomial_generic_field._xgcd.im_func(self,right)
    979980
    980981    #def discriminant(self):
    981982    #    raise NotImplementedError
  • sage/rings/polynomial/polynomial_element.pyx

    diff --git a/sage/rings/polynomial/polynomial_element.pyx b/sage/rings/polynomial/polynomial_element.pyx
    a b cdef class Polynomial(CommutativeAlgebraElement): 
    54495449        deprecation(4522, "This function is deprecated. It will be removed in a future release of Sage. Please use the .variable_name() function instead.")
    54505450        return self.parent().variable_name()
    54515451
    5452 
    5453     def _xgcd(self, other):
    5454         r"""
    5455         Extended gcd of self and polynomial other.
    5456        
    5457         Returns g, u, and v such that ``g = u*self + v*other.``
    5458        
    5459         EXAMPLES::
    5460        
    5461             sage: P.<x> = QQ[]
    5462             sage: F = (x^2 + 2)*x^3; G = (x^2+2)*(x-3)
    5463             sage: g, u, v = F.xgcd(G)
    5464             sage: g, u, v
    5465             (x^2 + 2, 1/27, -1/27*x^2 - 1/9*x - 1/3)
    5466             sage: u*F + v*G
    5467             x^2 + 2
    5468        
    5469         ::
    5470        
    5471             sage: g, u, v = x.xgcd(P(0)); g, u, v
    5472             (x, 1, 0)
    5473             sage: g == u*x + v*P(0)
    5474             True
    5475             sage: g, u, v = P(0).xgcd(x); g, u, v
    5476             (x, 0, 1)           
    5477             sage: g == u*P(0) + v*x
    5478             True
    5479         """
    5480         if other.is_zero():
    5481             R = self.parent()
    5482             return self, R.one_element(), R.zero_element()
    5483         # Algorithm 3.2.2 of Cohen, GTM 138
    5484         R = self.parent()
    5485         A = self
    5486         B = other
    5487         U = R.one_element()
    5488         G = A
    5489         V1 = R.zero_element()
    5490         V3 = B
    5491         while not V3.is_zero():
    5492             Q, R = G.quo_rem(V3)
    5493             T = U - V1*Q
    5494             U = V1
    5495             G = V3
    5496             V1 = T
    5497             V3 = R
    5498         V = (G-A*U)//B
    5499         lc = G.leading_coefficient()
    5500         return G/lc, U/lc, V/lc
    5501 
    55025452    def is_irreducible(self):
    55035453        """
    55045454        Return True precisely if this polynomial is irreducible over its
  • sage/rings/polynomial/polynomial_element_generic.py

    diff --git a/sage/rings/polynomial/polynomial_element_generic.py b/sage/rings/polynomial/polynomial_element_generic.py
    a b class Polynomial_generic_field(Polynomial_singular_repr, 
    629629        if c.is_unit():
    630630            return (1/c)*g
    631631        return g
    632        
    633        
     632
     633    def _xgcd(self, other):
     634        r"""
     635        Extended gcd of ``self`` and polynomial ``other``.
     636
     637        INPUT:
     638
     639            - ``other`` -- a polynomial defined over the same ring as ``self``
     640
     641        OUTPUT:
     642
     643        polynomials g, u, and v such that ``g = u*self + v*other``.
     644
     645        EXAMPLES::
     646
     647            sage: P.<x> = QQ[]
     648            sage: F = (x^2 + 2)*x^3; G = (x^2+2)*(x-3)
     649            sage: g, u, v = F.xgcd(G)
     650            sage: g, u, v
     651            (x^2 + 2, 1/27, -1/27*x^2 - 1/9*x - 1/3)
     652            sage: u*F + v*G
     653            x^2 + 2
     654
     655        ::
     656
     657            sage: g, u, v = x.xgcd(P(0)); g, u, v
     658            (x, 1, 0)
     659            sage: g == u*x + v*P(0)
     660            True
     661            sage: g, u, v = P(0).xgcd(x); g, u, v
     662            (x, 0, 1)
     663            sage: g == u*P(0) + v*x
     664            True
     665
     666        """
     667        if other.is_zero():
     668            R = self.parent()
     669            return self, R.one_element(), R.zero_element()
     670        # Algorithm 3.2.2 of Cohen, GTM 138
     671        R = self.parent()
     672        A = self
     673        B = other
     674        U = R.one_element()
     675        G = A
     676        V1 = R.zero_element()
     677        V3 = B
     678        while not V3.is_zero():
     679            Q, R = G.quo_rem(V3)
     680            T = U - V1*Q
     681            U = V1
     682            G = V3
     683            V1 = T
     684            V3 = R
     685        V = (G-A*U)//B
     686        lc = G.leading_coefficient()
     687        return G/lc, U/lc, V/lc
     688
     689
    634690class Polynomial_generic_sparse_field(Polynomial_generic_sparse, Polynomial_generic_field):
    635691    """
    636692    EXAMPLES::