From: Michael Orlitzky Date: Sat, 1 May 2021 00:48:45 +0000 (-0400) Subject: mjo/cone: drop is_symmetric_p{s,}d() methods. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=sage.d.git;a=commitdiff_plain;h=7af2b9d146a6bf2fb8acc3c342983de577b417ce mjo/cone: drop is_symmetric_p{s,}d() methods. These are now redundant since the sage is_positive_definite() and is_positive_semidefinite() methods exist and work on inexact rings. --- diff --git a/mjo/cone/completely_positive.py b/mjo/cone/completely_positive.py index 8bb4b62..3dc66b4 100644 --- a/mjo/cone/completely_positive.py +++ b/mjo/cone/completely_positive.py @@ -6,7 +6,7 @@ the set of all matrices `$A$`of the form `$\sum uu^{T}$` for `$u \in """ from sage.all import * -from mjo.cone.symmetric_psd import factor_psd, is_symmetric_psd +from mjo.cone.symmetric_psd import factor_psd from mjo.cone.doubly_nonnegative import (is_doubly_nonnegative, is_extreme_doubly_nonnegative) @@ -89,7 +89,7 @@ def is_completely_positive(A): msg = 'The matrix ``A`` cannot be symbolic.' raise ValueError.new(msg) - if not is_symmetric_psd(A): + if not A.is_positive_semidefinite(): return False n = A.nrows() # Makes sense since ``A`` is symmetric. @@ -176,7 +176,7 @@ def is_extreme_completely_positive(A): msg = 'The matrix ``A`` cannot be symbolic.' raise ValueError(msg) - if not is_symmetric_psd(A): + if not A.is_positive_semidefinite(): return False n = A.nrows() # Makes sense since ``A`` is symmetric. diff --git a/mjo/cone/doubly_nonnegative.py b/mjo/cone/doubly_nonnegative.py index e8cacda..5e10e1a 100644 --- a/mjo/cone/doubly_nonnegative.py +++ b/mjo/cone/doubly_nonnegative.py @@ -14,7 +14,6 @@ It is represented typically by either `\mathcal{D}^{n}` or from sage.all import * from mjo.cone.symmetric_psd import (factor_psd, - is_symmetric_psd, random_symmetric_psd) from mjo.basis_repr import basis_repr @@ -63,7 +62,7 @@ def is_doubly_nonnegative(A): # It's nonnegative, so all we need to do is check that it's # symmetric positive-semidefinite. - return is_symmetric_psd(A) + return A.is_positive_semidefinite() @@ -354,7 +353,7 @@ def is_extreme_doubly_nonnegative(A): # Short circuit, we know the zero matrix is extreme. return True - if not is_symmetric_psd(A): + if not A.is_positive_semidefinite(): return False # Step 1.5, appeal to Theorem 3.1 in reference #1 to short diff --git a/mjo/cone/symmetric_pd.py b/mjo/cone/symmetric_pd.py index 75c4572..e396bbc 100644 --- a/mjo/cone/symmetric_pd.py +++ b/mjo/cone/symmetric_pd.py @@ -8,99 +8,6 @@ SEMI-definite cone. from sage.all import * from mjo.cone.symmetric_psd import random_symmetric_psd -def is_symmetric_pd(A): - """ - Determine whether or not the matrix ``A`` is symmetric - positive-definite. - - INPUT: - - - ``A`` - The matrix in question. - - OUTPUT: - - Either ``True`` if ``A`` is symmetric positive-definite, or - ``False`` otherwise. - - SETUP:: - - sage: from mjo.cone.symmetric_pd import (is_symmetric_pd, - ....: random_symmetric_pd) - - EXAMPLES: - - The identity matrix is obviously symmetric and positive-definite:: - - sage: set_random_seed() - sage: A = identity_matrix(ZZ, ZZ.random_element(10)) - sage: is_symmetric_pd(A) - True - - The following matrix is symmetric but not positive definite:: - - sage: A = matrix(ZZ, [[1, 2], [2, 1]]) - sage: is_symmetric_pd(A) - False - - This matrix isn't even symmetric:: - - sage: A = matrix(ZZ, [[1, 2], [3, 4]]) - sage: is_symmetric_pd(A) - False - - The trivial matrix in a trivial space is trivially symmetric and - positive-definite:: - - sage: A = matrix(QQ, 0,0) - sage: is_symmetric_pd(A) - True - - The implementation of "is_positive_definite" in Sage leaves a bit to - be desired. This matrix is technically positive definite over the - real numbers, but isn't symmetric:: - - sage: A = matrix(RR,[[1,1],[-1,1]]) - sage: A.is_positive_definite() - Traceback (most recent call last): - ... - ValueError: Could not see Real Field with 53 bits of precision as a - subring of the real or complex numbers - sage: is_symmetric_pd(A) - False - - TESTS: - - Every gram matrix is positive-definite, and we can sum two - positive-definite matrices (``A`` and its transpose) to get a new - positive-definite matrix that happens to be symmetric:: - - sage: set_random_seed() - sage: V = VectorSpace(QQ, ZZ.random_element(5)) - sage: A = random_symmetric_pd(V) - sage: is_symmetric_pd(A) - True - - """ - - if A.base_ring() == SR: - msg = 'The matrix ``A`` cannot be symbolic.' - raise ValueError.new(msg) - - # First make sure that ``A`` is symmetric. - if not A.is_symmetric(): - return False - - # If ``A`` is symmetric, we only need to check that it is positive - # definite. For that we can consult its minimum eigenvalue, which - # should be greater than zero. Since ``A`` is symmetric, its - # eigenvalues are guaranteed to be real. - if A.is_zero(): - # A is trivial... so trivially positive-definite. - return True - else: - return min(A.eigenvalues()) > 0 - - def random_symmetric_pd(V): r""" Generate a random symmetric positive-definite matrix over the diff --git a/mjo/cone/symmetric_psd.py b/mjo/cone/symmetric_psd.py index fd6f950..89eba53 100644 --- a/mjo/cone/symmetric_psd.py +++ b/mjo/cone/symmetric_psd.py @@ -6,75 +6,6 @@ all symmetric positive-semidefinite matrices (as a subset of from sage.all import * -def is_symmetric_psd(A): - """ - Determine whether or not the matrix ``A`` is symmetric - positive-semidefinite. - - INPUT: - - - ``A`` - The matrix in question - - OUTPUT: - - Either ``True`` if ``A`` is symmetric positive-semidefinite, or - ``False`` otherwise. - - SETUP:: - - sage: from mjo.cone.symmetric_psd import is_symmetric_psd - - EXAMPLES: - - Every completely positive matrix is symmetric - positive-semidefinite:: - - sage: set_random_seed() - sage: v = vector(map(abs, random_vector(ZZ, 10))) - sage: A = v.column() * v.row() - sage: is_symmetric_psd(A) - True - - The following matrix is symmetric but not positive semidefinite:: - - sage: A = matrix(ZZ, [[1, 2], [2, 1]]) - sage: is_symmetric_psd(A) - False - - This matrix isn't even symmetric:: - - sage: A = matrix(ZZ, [[1, 2], [3, 4]]) - sage: is_symmetric_psd(A) - False - - The trivial matrix in a trivial space is trivially symmetric and - positive-semidefinite:: - - sage: A = matrix(QQ, 0,0) - sage: is_symmetric_psd(A) - True - - """ - - if A.base_ring() == SR: - msg = 'The matrix ``A`` cannot be symbolic.' - raise ValueError.new(msg) - - # First make sure that ``A`` is symmetric. - if not A.is_symmetric(): - return False - - # If ``A`` is symmetric, we only need to check that it is positive - # semidefinite. For that we can consult its minimum eigenvalue, - # which should be zero or greater. Since ``A`` is symmetric, its - # eigenvalues are guaranteed to be real. - if A.is_zero(): - # A is trivial... so trivially positive-semudefinite. - return True - else: - return min(A.eigenvalues()) >= 0 - - def unit_eigenvectors(A): """ Return the unit eigenvectors of a symmetric positive-definite matrix. @@ -254,8 +185,7 @@ def random_symmetric_psd(V, accept_zero=True, rank=None): SETUP:: - sage: from mjo.cone.symmetric_psd import (is_symmetric_psd, - ....: random_symmetric_psd) + sage: from mjo.cone.symmetric_psd import random_symmetric_psd EXAMPLES: @@ -266,7 +196,7 @@ def random_symmetric_psd(V, accept_zero=True, rank=None): sage: A = random_symmetric_psd(V) sage: A.matrix_space() Full MatrixSpace of 2 by 2 dense matrices over Rational Field - sage: is_symmetric_psd(A) + sage: A.is_positive_semidefinite() True A matrix with the desired rank is returned::