]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/permutation_invariant.py
Kill unnecessary sitedir mangling.
[sage.d.git] / mjo / cone / permutation_invariant.py
1 from sage.all import *
2
3 def random_permutation_invariant_cone(lattice=None,
4 min_ambient_dim=0,
5 max_ambient_dim=None,
6 min_rays=0,
7 max_rays=None,
8 strictly_convex=None,
9 solid=None):
10 r"""
11 Return a random permutation-invariant cone.
12
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
17 cone by construction.
18
19 All of this function's parameters are passed to ``random_cone()``
20 function used to generate the initial cone whose generators we will
21 permute.
22 """
23 K = random_cone(lattice=lattice,
24 min_ambient_dim=min_ambient_dim,
25 max_ambient_dim=max_ambient_dim,
26 min_rays=min_rays,
27 max_rays=max_rays,
28 strictly_convex=strictly_convex,
29 solid=solid)
30
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()
34
35 # The set of all permutatin matrices on ``V``.
36 Sn = [ p.matrix() for p in SymmetricGroup(V.dimension()) ]
37
38 # Set of permuted generators
39 pgens = []
40
41 for g in K.rays():
42 for permutation in Sn:
43 pgens.append(permutation * V(g))
44
45 L = ToricLattice(V.dimension())
46 return Cone(pgens, lattice=L)
47
48
49 def is_permutation_invariant(K):
50 r"""
51 Determine if ``K`` is permutation-invariant.
52
53 A cone is said to be permutation-invariant if ``P(K)`` is a subset
54 of ``K`` for every permutation matrix ``P``.
55
56 SETUP::
57
58 sage: from mjo.cone.rearrangement import rearrangement_cone
59 sage: from mjo.cone.permutation_invariant import is_permutation_invariant
60
61 EXAMPLES::
62
63 sage: all([ is_permutation_invariant(rearrangement_cone(p,n))
64 ....: for n in range(3, 6)
65 ....: for p in range(1, n) ])
66 True
67
68 """
69 # We'll need this to turn rays into vectors so that we can permute
70 # them with permutation matrices.
71 V = K.lattice().vector_space()
72
73 # The set of all permutation matrices on ``V``.
74 Sn = [ p.matrix() for p in SymmetricGroup(V.dimension()) ]
75
76 for permutation in Sn:
77 L = ToricLattice(V.dimension())
78 permuted_gens = [ permutation * V(g) for g in K.rays() ]
79 for g in permuted_gens:
80 if not K.contains(g):
81 return False
82
83 return True