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 = ( permutation*V(g) for permutation in Sn for g in K ) return Cone(pgens, K.lattice()) 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``. SETUP:: 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: The rearrangement cone is permutation-invariant:: sage: all( is_permutation_invariant(rearrangement_cone(p,n)) ....: for n in range(3, 6) ....: for p in range(1, n) ) True As is the nonnegative orthant:: sage: K = nonnegative_orthant(ZZ.random_element(5)) sage: is_permutation_invariant(K) 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()) ) return all(K.contains(permutation*V(g)) for g in K for permutation in Sn)