Ticket #13438: trac_13438_header.patch

File trac_13438_header.patch, 4.8 KB (added by mkosters, 6 years ago)
  • sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py

    # HG changeset patch
    # User Michiel Kosters  <mkosters@math.leidenuniv.nl>
    # Date 1374741903 -7200
    # Node ID dfc623ede81ecfa65f19b6e643476e814d4fd8c9
    # Parent  0f8fd922eaed351e39f913f1317d319dcceb4c01
    Trac 13438: xgcd fix
    
    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  
    991991        from sage.misc.stopgap import stopgap
    992992        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)
    993993
    994         return self._xgcd(right)
     994        from sage.rings.polynomial.polynomial_element_generic import Polynomial_generic_field
     995        return Polynomial_generic_field._xgcd.im_func(self,right)
    995996
    996997    #def discriminant(self):
    997998    #    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  
    54565456        deprecation(4522, "This function is deprecated. It will be removed in a future release of Sage. Please use the .variable_name() function instead.")
    54575457        return self.parent().variable_name()
    54585458
    5459     def _xgcd(self, other):
    5460         r"""
    5461         Extended gcd of self and polynomial other.
    5462        
    5463         Returns g, u, and v such that ``g = u*self + v*other.``
    5464        
    5465         EXAMPLES::
    5466        
    5467             sage: P.<x> = QQ[]
    5468             sage: F = (x^2 + 2)*x^3; G = (x^2+2)*(x-3)
    5469             sage: g, u, v = F.xgcd(G)
    5470             sage: g, u, v
    5471             (x^2 + 2, 1/27, -1/27*x^2 - 1/9*x - 1/3)
    5472             sage: u*F + v*G
    5473             x^2 + 2
    5474        
    5475         ::
    5476        
    5477             sage: g, u, v = x.xgcd(P(0)); g, u, v
    5478             (x, 1, 0)
    5479             sage: g == u*x + v*P(0)
    5480             True
    5481             sage: g, u, v = P(0).xgcd(x); g, u, v
    5482             (x, 0, 1)           
    5483             sage: g == u*P(0) + v*x
    5484             True
    5485         """
    5486         if other.is_zero():
    5487             R = self.parent()
    5488             return self, R.one_element(), R.zero_element()
    5489         # Algorithm 3.2.2 of Cohen, GTM 138
    5490         R = self.parent()
    5491         A = self
    5492         B = other
    5493         U = R.one_element()
    5494         G = A
    5495         V1 = R.zero_element()
    5496         V3 = B
    5497         while not V3.is_zero():
    5498             Q, R = G.quo_rem(V3)
    5499             T = U - V1*Q
    5500             U = V1
    5501             G = V3
    5502             V1 = T
    5503             V3 = R
    5504         V = (G-A*U)//B
    5505         lc = G.leading_coefficient()
    5506         return G/lc, U/lc, V/lc
    5507 
    55085459    def is_irreducible(self):
    55095460        """
    55105461        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  
    645645        if c.is_unit():
    646646            return (1/c)*g
    647647        return g
    648        
    649        
     648
     649    def _xgcd(self, other):
     650        r"""
     651        Extended gcd of ``self`` and polynomial ``other``.
     652
     653        INPUT:
     654
     655        - ``other`` -- a polynomial defined over the same ring as ``self``
     656
     657        OUTPUT:
     658
     659        Polynomials ``g``, ``u``, and ``v`` such that ``g = u * self + v * other``.
     660
     661        EXAMPLES::
     662
     663            sage: P.<x> = QQ[]
     664            sage: F = (x^2 + 2)*x^3; G = (x^2+2)*(x-3)
     665            sage: g, u, v = F.xgcd(G)
     666            sage: g, u, v
     667            (x^2 + 2, 1/27, -1/27*x^2 - 1/9*x - 1/3)
     668            sage: u*F + v*G
     669            x^2 + 2
     670
     671        ::
     672
     673            sage: g, u, v = x.xgcd(P(0)); g, u, v
     674            (x, 1, 0)
     675            sage: g == u*x + v*P(0)
     676            True
     677            sage: g, u, v = P(0).xgcd(x); g, u, v
     678            (x, 0, 1)
     679            sage: g == u*P(0) + v*x
     680            True
     681
     682        """
     683        if other.is_zero():
     684            R = self.parent()
     685            return self, R.one_element(), R.zero_element()
     686        # Algorithm 3.2.2 of Cohen, GTM 138
     687        R = self.parent()
     688        A = self
     689        B = other
     690        U = R.one_element()
     691        G = A
     692        V1 = R.zero_element()
     693        V3 = B
     694        while not V3.is_zero():
     695            Q, R = G.quo_rem(V3)
     696            T = U - V1*Q
     697            U = V1
     698            G = V3
     699            V1 = T
     700            V3 = R
     701        V = (G-A*U)//B
     702        lc = G.leading_coefficient()
     703        return G/lc, U/lc, V/lc
     704
     705
    650706class Polynomial_generic_sparse_field(Polynomial_generic_sparse, Polynomial_generic_field):
    651707    """
    652708    EXAMPLES::