]>
gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/permutation_invariant.py
3 def random_permutation_invariant_cone(lattice
=None,
11 Return a random permutation-invariant cone.
13 A cone ``K`` is said to be permutation-invariant if ``P(K) == K``
14 for all permutation matrices ``P``. To generate one, we can begin
15 with any cone, and construct the set of all permutations of its
16 generators. The resulting set will generate a permutation-invariant
19 All of this function's parameters are passed to ``random_cone()``
20 function used to generate the initial cone whose generators we will
23 K
= random_cone(lattice
=lattice
,
24 min_ambient_dim
=min_ambient_dim
,
25 max_ambient_dim
=max_ambient_dim
,
28 strictly_convex
=strictly_convex
,
31 # We'll need this to turn rays into vectors so that we can permute
32 # them with permutation matrices.
33 V
= K
.lattice().vector_space()
35 # The set of all permutatin matrices on ``V``.
36 Sn
= ( p
.matrix() for p
in SymmetricGroup(V
.dimension()) )
38 # Set of permuted generators
39 pgens
= ( permutation
*V(g
) for permutation
in Sn
for g
in K
)
41 return Cone(pgens
, K
.lattice())
44 def is_permutation_invariant(K
):
46 Determine if ``K`` is permutation-invariant.
48 A cone is said to be permutation-invariant if ``P(K)`` is a subset
49 of ``K`` for every permutation matrix ``P``.
53 sage: from mjo.cone.nonnegative_orthant import nonnegative_orthant
54 sage: from mjo.cone.permutation_invariant import is_permutation_invariant
55 sage: from mjo.cone.rearrangement import rearrangement_cone
59 The rearrangement cone is permutation-invariant::
61 sage: all( is_permutation_invariant(rearrangement_cone(p,n))
62 ....: for n in range(3, 6)
63 ....: for p in range(1, n) )
66 As is the nonnegative orthant::
68 sage: set_random_seed()
69 sage: K = nonnegative_orthant(ZZ.random_element(5))
70 sage: is_permutation_invariant(K)
74 # We'll need this to turn rays into vectors so that we can permute
75 # them with permutation matrices.
76 V
= K
.lattice().vector_space()
78 # The set of all permutation matrices on ``V``.
79 Sn
= ( p
.matrix() for p
in SymmetricGroup(V
.dimension()) )
81 return all(K
.contains(permutation
*V(g
))
83 for permutation
in Sn
)