X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Fcone%2Frearrangement.py;h=fd792c4b481351a37ab3a0d73227120109de1dc1;hb=8bed8a3c21a0d19d01a7625b3849ac07c9a9f9e6;hp=38b5931d6b6f48ea6ed5517e01d255b8626e03b5;hpb=4de036f15220b7aa07fb8f82e0f6430668d90daa;p=sage.d.git diff --git a/mjo/cone/rearrangement.py b/mjo/cone/rearrangement.py index 38b5931..fd792c4 100644 --- a/mjo/cone/rearrangement.py +++ b/mjo/cone/rearrangement.py @@ -28,6 +28,25 @@ def rearrangement_cone(p,n): A polyhedral closed convex cone object representing a rearrangement cone of order ``p`` in ``n`` dimensions. + REFERENCES: + + .. [HenrionSeeger] Rene Henrion and Alberto Seeger. + Inradius and Circumradius of Various Convex Cones Arising in + Applications. Set-Valued and Variational Analysis, 18(3-4), + 483-511, 2010. doi:10.1007/s11228-010-0150-z + + .. [GowdaJeong] Muddappa Seetharama Gowda and Juyoung Jeong. + Spectral cones in Euclidean Jordan algebras. + Linear Algebra and its Applications, 509, 286-305. + doi:10.1016/j.laa.2016.08.004 + + .. [Jeong] Juyoung Jeong. + Spectral sets and functions on Euclidean Jordan algebras. + + SETUP:: + + sage: from mjo.cone.rearrangement import rearrangement_cone + EXAMPLES: The rearrangement cones of order one are nonnegative orthants:: @@ -48,21 +67,21 @@ def rearrangement_cone(p,n): All rearrangement cones are proper:: - sage: all([ rearrangement_cone(p,n).is_proper() - ....: for n in range(10) - ....: for p in range(n) ]) + sage: all( rearrangement_cone(p,n).is_proper() + ....: for n in xrange(10) + ....: for p in xrange(1, n) ) True The Lyapunov rank of the rearrangement cone of order ``p`` in ``n`` dimensions is ``n`` for ``p == 1`` or ``p == n`` and one otherwise:: - sage: all([ rearrangement_cone(p,n).lyapunov_rank() == n - ....: for n in range(2, 10) - ....: for p in [1, n-1] ]) + sage: all( rearrangement_cone(p,n).lyapunov_rank() == n + ....: for n in xrange(2, 10) + ....: for p in [1, n-1] ) True - sage: all([ rearrangement_cone(p,n).lyapunov_rank() == 1 - ....: for n in range(3, 10) - ....: for p in range(2, n-1) ]) + sage: all( rearrangement_cone(p,n).lyapunov_rank() == 1 + ....: for n in xrange(3, 10) + ....: for p in xrange(2, n-1) ) True TESTS: @@ -73,62 +92,57 @@ def rearrangement_cone(p,n): sage: p = ZZ.random_element(1,n) sage: K = rearrangement_cone(p,n) sage: P = SymmetricGroup(n).random_element().matrix() - sage: all([ K.contains(P*r) for r in K.rays() ]) + sage: all( K.contains(P*r) for r in K ) + True + + The smallest ``p`` components of every element of the rearrangement + cone should sum to a nonnegative number (this tests that the + generators really are what we think they are):: + + sage: set_random_seed() + sage: def _has_rearrangement_property(v,p): + ....: return sum( sorted(v)[0:p] ) >= 0 + sage: all( _has_rearrangement_property( + ....: rearrangement_cone(p,n).random_element(), + ....: p + ....: ) + ....: for n in xrange(2, 10) + ....: for p in xrange(1, n-1) + ....: ) True + The rearrangenent cone of order ``p`` is contained in the + rearrangement cone of order ``p + 1``:: + + sage: set_random_seed() + sage: n = ZZ.random_element(2,10) + sage: p = ZZ.random_element(1,n) + sage: K1 = rearrangement_cone(p,n) + sage: K2 = rearrangement_cone(p+1,n) + sage: all( x in K2 for x in K1 ) + True + + The order ``p`` should be between ``1`` and ``n``, inclusive:: + + sage: rearrangement_cone(0,3) + Traceback (most recent call last): + ... + ValueError: order p=0 should be between 1 and n=3, inclusive + sage: rearrangement_cone(5,3) + Traceback (most recent call last): + ... + ValueError: order p=5 should be between 1 and n=3, inclusive + """ + if p < 1 or p > n: + raise ValueError('order p=%d should be between 1 and n=%d, inclusive' + % + (p,n)) def d(j): v = [1]*n # Create the list of all ones... v[j] = 1 - p # Now "fix" the ``j``th entry. return v - V = VectorSpace(QQ, n) - G = V.basis() + [ d(j) for j in range(n) ] + G = identity_matrix(ZZ,n).rows() + [ d(j) for j in xrange(n) ] return Cone(G) - - -def has_rearrangement_property(v, p): - r""" - Test if the vector ``v`` has the "rearrangement property." - - The rearrangement cone of order ``p`` in `n` dimensions has its - members vectors of length `n`. The "rearrangement property," - satisfied by its elements, is to have its smallest ``p`` components - sum to a nonnegative number. - - We believe that we have a description of the extreme vectors of the - rearrangement cone: see ``rearrangement_cone()``. This function is - used to test that conic combinations of those extreme vectors are in - fact elements of the rearrangement cone. We can't test all conic - combinations, obviously, but we can test a random one. - - To become more sure of the result, generate a bunch of vectors with - ``random_element()`` and test them with this function. - - INPUT: - - - ``v`` -- An element of a cone suspected of being the rearrangement - cone of order ``p``. - - - ``p`` -- The suspected order of the rearrangement cone. - - OUTPUT: - - If ``v`` has the rearrangement property (that is, if its smallest ``p`` - components sum to a nonnegative number), ``True`` is returned. Otherwise - ``False`` is returned. - - EXAMPLES: - - Every element of a rearrangement cone should have the property:: - - sage: for n in range(2,10): - ....: for p in range(1, n-1): - ....: K = rearrangement_cone(p,n) - ....: v = K.random_element() - ....: if not has_rearrangement_property(v,p): print v - - """ - components = sorted(v)[0:p] - return sum(components) >= 0