From: Michael Orlitzky Date: Mon, 28 Sep 2015 03:27:24 +0000 (-0400) Subject: Add the cone.permutation_invariant module. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=f14bcc7d014547bca733363b2a32ce9b0722f251;p=sage.d.git Add the cone.permutation_invariant module. --- diff --git a/mjo/all.py b/mjo/all.py index 246f1a0..580cca5 100644 --- a/mjo/all.py +++ b/mjo/all.py @@ -6,6 +6,7 @@ in his script. Instead, he can just `from mjo.all import *`. from cone.cone import * from cone.completely_positive import * from cone.doubly_nonnegative import * +from cone.permutation_invariant import * from cone.rearrangement import * from cone.symmetric_psd import * from interpolation import * diff --git a/mjo/cone/permutation_invariant.py b/mjo/cone/permutation_invariant.py new file mode 100644 index 0000000..65e22f5 --- /dev/null +++ b/mjo/cone/permutation_invariant.py @@ -0,0 +1,85 @@ +# 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, + min_ambient_dim=0, + max_ambient_dim=None, + min_rays=0, + max_rays=None, + strictly_convex=None, + solid=None): + r""" + Return a random permutation-invariant cone. + + A cone ``K`` is said to be permutation-invariant if ``P(K) == K`` + for all permutation matrices ``P``. To generate one, we can begin + with any cone, and construct the set of all permutations of its + generators. The resulting set will generate a permutation-invariant + cone by construction. + + All of this function's parameters are passed to ``random_cone()`` + function used to generate the initial cone whose generators we will + permute. + """ + K = random_cone(lattice=lattice, + min_ambient_dim=min_ambient_dim, + max_ambient_dim=max_ambient_dim, + min_rays=min_rays, + max_rays=max_rays, + strictly_convex=strictly_convex, + solid=solid) + + # We'll need this to turn rays into vectors so that we can permute + # them with permutation matrices. + V = K.lattice().vector_space() + + # The set of all permutatin matrices on ``V``. + 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)) + + L = ToricLattice(V.dimension()) + return Cone(pgens, lattice=L) + + +def is_permutation_invariant(K): + r""" + Determine if ``K`` is permutation-invariant. + + A cone is said to be permutation-invariant if ``P(K)`` is a subset + of ``K`` for every permutation matrix ``P``. + + EXAMPLES: + + sage: all([ is_permutation_invariant(rearrangement_cone(p,n)) + ....: for n in range(3, 6) + ....: for p in range(1, n) ]) + True + + """ + # We'll need this to turn rays into vectors so that we can permute + # them with permutation matrices. + 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 + + return True