]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/cone/permutation_invariant.py
eja: undo overzealous hack in _all2list; the bug was elsewhere.
[sage.d.git] / mjo / cone / permutation_invariant.py
index d6642806c0e0d8473908c5f761a75556085e0653..faa39f76fbe9072c54f1ff29cebb563d1e8524cb 100644 (file)
@@ -1,10 +1,3 @@
-# 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 *
 
 def random_permutation_invariant_cone(lattice=None,
@@ -40,17 +33,12 @@ def random_permutation_invariant_cone(lattice=None,
     V = K.lattice().vector_space()
 
     # The set of all permutatin matrices on ``V``.
-    Sn = [ p.matrix() for p in SymmetricGroup(V.dimension()) ]
+    Sn = ( p.matrix() for p in SymmetricGroup(V.dimension()) )
 
     # Set of permuted generators
-    pgens = []
-
-    for g in K.rays():
-        for permutation in Sn:
-            pgens.append(permutation * V(g))
+    pgens = ( permutation*V(g) for permutation in Sn for g in K )
 
-    L = ToricLattice(V.dimension())
-    return Cone(pgens, lattice=L)
+    return Cone(pgens, K.lattice())
 
 
 def is_permutation_invariant(K):
@@ -62,14 +50,24 @@ def is_permutation_invariant(K):
 
     SETUP::
 
-        sage: from mjo.cone.rearrangement import rearrangement_cone
+        sage: from mjo.cone.nonnegative_orthant import nonnegative_orthant
         sage: from mjo.cone.permutation_invariant import is_permutation_invariant
+        sage: from mjo.cone.rearrangement import rearrangement_cone
+
+    EXAMPLES:
 
-    EXAMPLES::
+    The rearrangement cone is permutation-invariant::
 
-        sage: all([ is_permutation_invariant(rearrangement_cone(p,n))
+        sage: all( is_permutation_invariant(rearrangement_cone(p,n))
         ....:               for n in range(3, 6)
-        ....:               for p in range(1, n) ])
+        ....:               for p in range(1, n) )
+        True
+
+    As is the nonnegative orthant::
+
+        sage: set_random_seed()
+        sage: K = nonnegative_orthant(ZZ.random_element(5))
+        sage: is_permutation_invariant(K)
         True
 
     """
@@ -78,13 +76,8 @@ def is_permutation_invariant(K):
     V = K.lattice().vector_space()
 
     # The set of all permutation matrices on ``V``.
-    Sn = [ p.matrix() for p in SymmetricGroup(V.dimension()) ]
-
-    for permutation in Sn:
-        L = ToricLattice(V.dimension())
-        permuted_gens = [ permutation * V(g) for g in K.rays() ]
-        for g in permuted_gens:
-            if not K.contains(g):
-                return False
+    Sn = ( p.matrix() for p in SymmetricGroup(V.dimension()) )
 
-    return True
+    return all(K.contains(permutation*V(g))
+                   for g in K
+                   for permutation in Sn)