]>
gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/permutation_invariant.py
1 # Sage doesn't load ~/.sage/init.sage during testing (sage -t), so we
2 # have to explicitly mangle our sitedir here so that "mjo.cone"
4 from os
.path
import abspath
5 from site
import addsitedir
6 addsitedir(abspath('../../'))
10 def random_permutation_invariant_cone(lattice
=None,
18 Return a random permutation-invariant cone.
20 A cone ``K`` is said to be permutation-invariant if ``P(K) == K``
21 for all permutation matrices ``P``. To generate one, we can begin
22 with any cone, and construct the set of all permutations of its
23 generators. The resulting set will generate a permutation-invariant
26 All of this function's parameters are passed to ``random_cone()``
27 function used to generate the initial cone whose generators we will
30 K
= random_cone(lattice
=lattice
,
31 min_ambient_dim
=min_ambient_dim
,
32 max_ambient_dim
=max_ambient_dim
,
35 strictly_convex
=strictly_convex
,
38 # We'll need this to turn rays into vectors so that we can permute
39 # them with permutation matrices.
40 V
= K
.lattice().vector_space()
42 # The set of all permutatin matrices on ``V``.
43 Sn
= [ p
.matrix() for p
in SymmetricGroup(V
.dimension()) ]
45 # Set of permuted generators
49 for permutation
in Sn
:
50 pgens
.append(permutation
* V(g
))
52 L
= ToricLattice(V
.dimension())
53 return Cone(pgens
, lattice
=L
)
56 def is_permutation_invariant(K
):
58 Determine if ``K`` is permutation-invariant.
60 A cone is said to be permutation-invariant if ``P(K)`` is a subset
61 of ``K`` for every permutation matrix ``P``.
65 sage: from mjo.cone.rearrangement import rearrangement_cone
66 sage: all([ is_permutation_invariant(rearrangement_cone(p,n))
67 ....: for n in range(3, 6)
68 ....: for p in range(1, n) ])
72 # We'll need this to turn rays into vectors so that we can permute
73 # them with permutation matrices.
74 V
= K
.lattice().vector_space()
76 # The set of all permutation matrices on ``V``.
77 Sn
= [ p
.matrix() for p
in SymmetricGroup(V
.dimension()) ]
79 for permutation
in Sn
:
80 L
= ToricLattice(V
.dimension())
81 permuted_gens
= [ permutation
* V(g
) for g
in K
.rays() ]
82 for g
in permuted_gens
: