Ticket #3620: sage-3620.patch

File sage-3620.patch, 2.2 KB (added by was, 13 years ago)
  • sage/structure/element.pyx

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1215633079 25200
    # Node ID 027817147b2d958189c0ad84373daf5b3712485a
    # Parent  aa1c43becd4187080d06774c7e321c1568436e04
    trac #3620  -- first step: minpoly absurdly slow for elements of finte fields
    
    diff -r aa1c43becd41 -r 027817147b2d sage/structure/element.pyx
    a b cdef class FiniteFieldElement(FieldEleme 
    25212521            return s
    25222522        return s.replace(self.parent().variable_name(), var)
    25232523
    2524     def charpoly(self, var='x'):
     2524    def charpoly(self, var='x', algorithm='matrix'):
    25252525        """
    25262526        Return the characteristic polynomial of self as a polynomial with given variable.
     2527
     2528        INPUT:
     2529            var -- string (default: 'x')
     2530            algorithm -- string (default: 'matrix')
     2531                         'matrix' -- return the charpoly computed from the
     2532                                     matrix of left multiplication by self
     2533                         'pari' -- use pari's charpoly routine on polymods,
     2534                                   which is not very good except in small cases
     2535
     2536        The result is not cached.
    25272537
    25282538        EXAMPLES:
    25292539            sage: k.<a> = GF(19^2)
    cdef class FiniteFieldElement(FieldEleme 
    25332543            X^2 + 18*X + 2
    25342544            sage: a^2 + 18*a + 2
    25352545            0           
     2546            sage: a.charpoly('X', algorithm='pari')
     2547            X^2 + 18*X + 2
    25362548        """
    2537         from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
    2538         R = PolynomialRing(self.parent().prime_subfield(), var)
    2539         return R(self._pari_().charpoly('x').lift())
     2549        if algorithm == 'matrix':
     2550            return self.matrix().charpoly(var)
     2551        elif algorithm == 'pari':
     2552            from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
     2553            R = PolynomialRing(self.parent().prime_subfield(), var)
     2554            return R(self._pari_().charpoly('x').lift())
     2555        else:
     2556            raise ValueError, "unknown algorithm '%s'"%algorithm
    25402557
    25412558    def norm(self):
    25422559        """