]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/cone/rearrangement.py
mjo/**/*.py: drop obsolete set_random_seed().
[sage.d.git] / mjo / cone / rearrangement.py
index 5da9b284ab66d7ca816167e2729a31eabbc22700..0bbf95bb7603bed819d4b9e91a4b148856dc464c 100644 (file)
@@ -1,14 +1,6 @@
-# Sage doesn't load ~/.sage/init.sage during testing (sage -t), so we
-# have to explicitly mangle our sitedir here so that "mjo.cone"
-# resolves.
-from os.path import abspath
-from site import addsitedir
-addsitedir(abspath('../../'))
-
 from sage.all import *
-from mjo.cone.cone import lyapunov_rank
 
-def rearrangement_cone(p,n):
+def rearrangement_cone(p,n,lattice=None):
     r"""
     Return the rearrangement cone of order ``p`` in ``n`` dimensions.
 
@@ -27,14 +19,47 @@ def rearrangement_cone(p,n):
 
     INPUT:
 
-    - ``p`` -- The number of components to "rearrange."
+      - ``p`` -- The number of components to "rearrange."
+
+      - ``n`` -- The dimension of the ambient space for the resulting cone.
 
-    - ``n`` -- The dimension of the ambient space for the resulting cone.
+      - ``lattice`` -- (default: ``None``) an ambient lattice of rank ``n``
+                       to be passed to the :func:`Cone` constructor.
 
     OUTPUT:
 
     A polyhedral closed convex cone object representing a rearrangement
-    cone of order ``p`` in ``n`` dimensions.
+    cone of order ``p`` in ``n`` dimensions. Each generating ray will
+    have the integer ring as its base ring.
+
+    If a ``lattice`` was specified, then the resulting cone will live in
+    that lattice unless its rank is incompatible with the dimension
+    ``n`` (in which case a ``ValueError`` is raised).
+
+    ALGORITHM:
+
+    The generators for the rearrangement cone are given by [Jeong]_
+    Theorem 5.2.3.
+
+    REFERENCES:
+
+    .. [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
+
+    .. [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
+
+    .. [Jeong] Juyoung Jeong.
+       Spectral sets and functions on Euclidean Jordan algebras.
+       University of Maryland, Baltimore County, Ph.D. thesis, 2017.
+
+    SETUP::
+
+        sage: from mjo.cone.rearrangement import rearrangement_cone
 
     EXAMPLES:
 
@@ -54,43 +79,116 @@ def rearrangement_cone(p,n):
         sage: rearrangement_cone(5,5).lineality()
         4
 
-    All rearrangement cones are proper::
+    All rearrangement cones are proper when ``p`` is less than ``n`` by
+    [Jeong]_ Proposition 5.2.1::
 
-        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 range(10)
+        ....:              for p in range(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::
+    dimensions is ``n`` for ``p == 1`` or ``p == n`` and one otherwise,
+    by [Jeong]_ Corollary 5.2.4::
 
-        sage: all([ lyapunov_rank(rearrangement_cone(p,n)) == 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 range(2, 10)
+        ....:              for p in [1, n-1] )
         True
-        sage: all([ lyapunov_rank(rearrangement_cone(p,n)) == 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 range(3, 10)
+        ....:              for p in range(2, n-1) )
         True
 
     TESTS:
 
-    The rearrangement cone is permutation-invariant::
+    All rearrangement cones are permutation-invariant by [Jeong]_
+    Proposition 5.2.1::
 
         sage: n = ZZ.random_element(2,10).abs()
         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: 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 range(2, 10)
+        ....:    for p in range(1, n-1)
+        ....: )
+        True
 
-    def d(j):
-        v = [1]*n    # Create the list of all ones...
-        v[j] = 1 - p # Now "fix" the ``j``th entry.
-        return v
+    The rearrangenent cone of order ``p`` is contained in the rearrangement
+    cone of order ``p + 1`` by [Jeong]_ Proposition 5.2.1::
 
-    V = VectorSpace(QQ, n)
-    G = V.basis() + [ d(j) for j in range(n) ]
-    return Cone(G)
+        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 rearrangement cone of order ``p`` is linearly isomorphic to the
+    rearrangement cone of order ``n - p`` when ``p`` is less than ``n``,
+    by [Jeong]_ Proposition 5.2.1::
+
+        sage: n = ZZ.random_element(2,10)
+        sage: p = ZZ.random_element(1,n)
+        sage: K1 = rearrangement_cone(p,n)
+        sage: K2 = rearrangement_cone(n-p, n)
+        sage: Mp = (1/p)*matrix.ones(QQ,n) - identity_matrix(QQ,n)
+        sage: Cone( (Mp*K2.rays()).columns() ).is_equivalent(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 a ``lattice`` was given, it is actually used::
+
+        sage: L = ToricLattice(3, 'M')
+        sage: rearrangement_cone(2, 3, lattice=L)
+        3-d cone in 3-d lattice M
+
+    Unless the rank of the lattice disagrees with ``n``::
+
+        sage: L = ToricLattice(1, 'M')
+        sage: rearrangement_cone(2, 3, lattice=L)
+        Traceback (most recent call last):
+        ...
+        ValueError: lattice rank=1 and dimension n=3 are incompatible
+
+    """
+    if p < 1 or p > n:
+        raise ValueError('order p=%d should be between 1 and n=%d, inclusive'
+                         %
+                         (p,n))
+
+    if lattice is None:
+        lattice = ToricLattice(n)
+
+    if lattice.rank() != n:
+        raise ValueError('lattice rank=%d and dimension n=%d are incompatible'
+                         %
+                         (lattice.rank(), n))
+
+    I = identity_matrix(ZZ,n)
+    M = matrix.ones(ZZ,n) - p*I
+    G = identity_matrix(ZZ,n).rows() + M.rows()
+    return Cone(G, lattice=lattice)