Ticket #14508: trac_14508-possible-improvement-dg.patch

File trac_14508-possible-improvement-dg.patch, 3.7 KB (added by darij, 8 years ago)

A is no longer basechanged if the base_ring keyword was None and the base ring of A is a field. is this what we want?

  • sage/matrix/matrix2.pyx

    # HG changeset patch
    # User darij grinberg <darijgrinberg@gmail.com>
    # Date 1381365647 25200
    # Node ID 375e81f56dda840b5c8542017ac8e77d39c24f40
    # Parent  e3743b7a749fbdf97b95f945897237b7b75fe932
    trac #14508: better now?
    
    diff --git a/sage/matrix/matrix2.pyx b/sage/matrix/matrix2.pyx
    a b cdef class Matrix(matrix1.Matrix): 
    87858785            Traceback (most recent call last):
    87868786            ...
    87878787            ValueError: Jordan normal form not implemented over inexact rings.
    8788            
    8789         Here we need to specify a field (#14508).
    8790        
    8791         ::
    8792        
     8788
     8789        Here we need to specify a field, since the eigenvalues are not defined
     8790        in the smallest ring containing the matrix entries (:trac:`14508`)::
     8791
    87938792            sage: c = matrix([[0,1,0],[0,0,1],[1,0,0]]);
    87948793            sage: c.jordan_form(CyclotomicField(3))
    87958794            [         1|         0|         0]
    cdef class Matrix(matrix1.Matrix): 
    87978796            [         0|     zeta3|         0]
    87988797            [----------+----------+----------]
    87998798            [         0|         0|-zeta3 - 1]
    8800        
     8799
    88018800        If you need the transformation matrix as well as the Jordan form of
    8802         ``self``, then pass the option ``transformation=True``.
    8803        
    8804         ::
    8805        
     8801        ``self``, then pass the option ``transformation=True``. For example::
     8802
    88068803            sage: m = matrix([[5,4,2,1],[0,1,-1,-1],[-1,-1,3,0],[1,1,-1,2]]); m
    88078804            [ 5  4  2  1]
    88088805            [ 0  1 -1 -1]
    cdef class Matrix(matrix1.Matrix): 
    88218818            [0 1 0 0]
    88228819            [0 0 4 1]
    88238820            [0 0 0 4]
    8824        
    8825         Note that for matrices over inexact rings and associated numerical
    8826         stability problems, we do not attempt to compute the Jordan normal
    8827         form.
    8828        
    8829         ::
    8830        
     8821
     8822        Note that for matrices over inexact rings, we do not attempt to
     8823        compute the Jordan normal form, since it is not numerically
     8824        stable::
     8825
    88318826            sage: b = matrix(ZZ,3,3,range(9))
    88328827            sage: jf, p = b.jordan_form(RealField(15), transformation=True)
    88338828            Traceback (most recent call last):
    88348829            ...
    88358830            ValueError: Jordan normal form not implemented over inexact rings.
    8836        
     8831
    88378832        TESTS::
    88388833       
    88398834            sage: c = matrix(ZZ, 3, [1]*9); c
    cdef class Matrix(matrix1.Matrix): 
    90649059                return self
    90659060            else:
    90669061                return self, self.parent().identity_matrix()
    9067        
     9062
     9063        inferred_base_ring = base_ring
     9064
    90689065        if base_ring is None:
    9069             base_ring = self.base_ring()
    9070 
    9071         if not base_ring.is_exact():
     9066            inferred_base_ring = self.base_ring()
     9067
     9068        if not inferred_base_ring.is_exact():
    90729069            raise ValueError("Jordan normal form not implemented over inexact rings.")
    90739070       
    90749071        # Make sure we're working with a field.
    9075         if base_ring.is_field():
    9076             A = self.change_ring(base_ring)
     9072        if inferred_base_ring.is_field():
     9073            if base_ring is not None:
     9074                A = self.change_ring(inferred_base_ring)
     9075            else:
     9076                A = self
    90779077        else:
    90789078            try:
    9079                 base_field = base_ring.fraction_field()
     9079                base_field = inferred_base_ring.fraction_field()
    90809080            except (NotImplementedError, TypeError, AttributeError):
    90819081                raise ValueError("Matrix entries must be from a field, not {0}".
    9082                                  format(base_ring))
     9082                                 format(inferred_base_ring))
    90839083            A = self.change_ring(base_field)
    90849084
    90859085        # Compute the eigenvalues of the matrix, with multiplicities.  Here,