Ticket #11595: trac_11595-exact-eigenspaces-format-draft.patch

File trac_11595-exact-eigenspaces-format-draft.patch, 4.6 KB (added by rbeezer, 11 years ago)

Apply on top of main patch (this is a draft)

  • sage/matrix/matrix2.pyx

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1313813339 25200
    # Node ID 85c431fe8c8a8dfa96eace1a8b45244f779d2d7b
    # Parent  2cb5efc74bed3d837ab725f7dd152e67fd4eabc7
    11595: format behavior for exact eigenspaces
    
    diff --git a/sage/matrix/matrix2.pyx b/sage/matrix/matrix2.pyx
    a b  
    43654365    # Deprecated Aug 2008 Trac #3794
    43664366    # Removed July 2011
    43674367    # def eigenspaces(self, var='a', even_if_inexact=None):
     4368   
     4369    def _eigenspace_format(self, format):
     4370        r"""
     4371        """
     4372        if not format in [None, 'all', 'galois']:
     4373            msg = "format keyword must be None, 'all' or 'galois', not {0}"
     4374            raise ValueError(msg.format(format))
     4375
     4376        # For subrings of implemented algebraically closed fields we
     4377        #   default to all eigenspaces in the absence of a format keyword
     4378        # Add newly implemented algebraically closed fields to list below
     4379        #   and implement the determintion of the actual eigenvalues
     4380        #   in the eigenspace_left() routine
     4381        if format is None:
     4382            R = self.base_ring()
     4383            from sage.rings.qqbar import QQbar
     4384            try:
     4385                if R.fraction_field().algebraic_closure() in [QQbar]:
     4386                    return 'all'
     4387                else:
     4388                    return 'galois'
     4389            except AttributeError:
     4390                return 'galois'
     4391        else:
     4392            return format
     4393       
    43684394
    43694395    def eigenspaces_left(self, format='all', var='a', algebraic_multiplicity=False):
    43704396        r"""
     
    46254651            Traceback (most recent call last):
    46264652            ...
    46274653            ValueError: algebraic_multiplicity keyword must be True or False
    4628 
    4629         """
    4630         if not format in ['all', 'galois']:
    4631             raise ValueError("format keyword must be 'all' or 'galois', not {0}".format(format))
     4654        """
    46324655        if not algebraic_multiplicity in [True, False]:
    4633             raise ValueError('algebraic_multiplicity keyword must be True or False'.format(algebraic_multiplicity))
     4656            msg = 'algebraic_multiplicity keyword must be True or False'
     4657            raise ValueError(msg.format(algebraic_multiplicity))
    46344658        if not self.is_square():
    4635             raise TypeError('matrix must be square, not {0} x {1}'.format(self.nrows(), self.ncols()))
     4659            msg = 'matrix must be square, not {0} x {1}'
     4660            raise TypeError(msg.format(self.nrows(), self.ncols()))
    46364661        if not self.base_ring().is_exact():
    46374662            msg = ("eigenspaces cannot be computed reliably for inexact rings such as {0},\n",
    46384663                   "consult numerical or symbolic matrix classes for other options")
    46394664            raise NotImplementedError(''.join(msg).format(self.base_ring()))
    46404665
     4666        format = self._eigenspace_format(format)
     4667       
    46414668        key = 'eigenspaces_left_' + format + '{0}'.format(var)
    46424669        x = self.fetch(key)
    46434670        if not x is None:
     
    46514678        # use minpoly when algebraic_multiplicity=False
    46524679        # as of 2007-03-25 minpoly is unreliable via linbox
    46534680
     4681        import sage.categories.homset
    46544682        import sage.rings.qqbar
    4655         import sage.categories.homset
     4683       
    46564684        G = self.fcp()   # factored characteristic polynomial
    46574685        V = []
    46584686        i = -1 # variable name index, increments for each eigenvalue
     
    48604888            ...
    48614889            ValueError: algebraic_multiplicity keyword must be True or False
    48624890        """
    4863         if not format in ['all', 'galois']:
    4864             raise ValueError("format keyword must be 'all' or 'galois', not {0}".format(format))
    48654891        if not algebraic_multiplicity in [True, False]:
    4866             raise ValueError('algebraic_multiplicity keyword must be True or False'.format(algebraic_multiplicity))
     4892            msg = 'algebraic_multiplicity keyword must be True or False'
     4893            raise ValueError(msg.format(algebraic_multiplicity))
    48674894        if not self.is_square():
    4868             raise TypeError('matrix must be square, not {0} x {1}'.format(self.nrows(), self.ncols()))
     4895            msg = 'matrix must be square, not {0} x {1}'
     4896            raise TypeError(msg.format(self.nrows(), self.ncols()))
    48694897        if not self.base_ring().is_exact():
    48704898            msg = ("eigenspaces cannot be computed reliably for inexact rings such as {0},\n",
    48714899                   "consult numerical or symbolic matrix classes for other options")
    48724900            raise NotImplementedError(''.join(msg).format(self.base_ring()))
     4901       
     4902        format = self._eigenspace_format(format)
    48734903
    48744904        key = 'eigenspaces_right_' + format + '{0}'.format(var)
    48754905        x = self.fetch(key)