]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/cone/rearrangement.py
mjo/cone: rename random_psd() to random_symmetric_psd().
[sage.d.git] / mjo / cone / rearrangement.py
index 76b0dadf4f5ddc791c0cb6d95e5db9d811ac78b0..3e09c8ad948a8c70135809b6e3c5e5328babfa36 100644 (file)
@@ -1,6 +1,6 @@
 from sage.all import *
 
-def rearrangement_cone(p,n):
+def rearrangement_cone(p,n,lattice=None):
     r"""
     Return the rearrangement cone of order ``p`` in ``n`` dimensions.
 
@@ -19,14 +19,22 @@ 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).
 
     REFERENCES:
 
@@ -69,7 +77,7 @@ def rearrangement_cone(p,n):
 
         sage: all( rearrangement_cone(p,n).is_proper()
         ....:              for n in xrange(10)
-        ....:              for p in xrange(n) )
+        ....:              for p in xrange(1, n) )
         True
 
     The Lyapunov rank of the rearrangement cone of order ``p`` in ``n``
@@ -133,16 +141,35 @@ def rearrangement_cone(p,n):
         ...
         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))
 
-    def d(j):
-        v = [1]*n    # Create the list of all ones...
-        v[j] = 1 - p # Now "fix" the ``j``th entry.
-        return v
+    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))
 
-    G = identity_matrix(ZZ,n).rows() + [ d(j) for j in xrange(n) ]
-    return Cone(G)
+    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)