]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/rearrangement.py
Begin work on the rearrangement cone.
[sage.d.git] / mjo / cone / rearrangement.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"
3 # resolves.
4 from os.path import abspath
5 from site import addsitedir
6 addsitedir(abspath('../../'))
7
8 from sage.all import *
9
10 def rearrangement_cone(p,n):
11 r"""
12 Return the rearrangement cone of order ``p`` in ``n`` dimensions.
13
14 The rearrangement cone in ``n`` dimensions has as its elements
15 vectors of length ``n``. For inclusion in the cone, the smallest
16 ``p`` components of a vector must sum to a nonnegative number.
17
18 For example, the rearrangement cone of order ``p == 1`` has its
19 single smallest component nonnegative. This implies that all
20 components are nonnegative, and that therefore the rearrangement
21 cone of order one is the nonnegative orthant.
22
23 When ``p == n``, the sum of all components of a vector must be
24 nonnegative for inclusion in the cone. That is, the cone is a
25 half-space in ``n`` dimensions.
26
27 INPUT:
28
29 - ``p`` -- The number of components to "rearrange."
30
31 - ``n`` -- The dimension of the ambient space for the resulting cone.
32
33 OUTPUT:
34
35 A polyhedral closed convex cone object representing a rearrangement
36 cone of order ``p`` in ``n`` dimensions.
37
38 EXAMPLES:
39
40 The rearrangement cones of order one are nonnegative orthants::
41
42 sage: rearrangement_cone(1,1) == Cone([(1,)])
43 True
44 sage: rearrangement_cone(1,2) == Cone([(0,1),(1,0)])
45 True
46 sage: rearrangement_cone(1,3) == Cone([(0,0,1),(0,1,0),(1,0,0)])
47 True
48
49 When ``p == n``, the resulting cone will be a half-space, so we
50 expect its lineality to be one less than ``n`` because it will
51 contain a hyperplane but is not the entire space::
52
53 sage: rearrangement_cone(5,5).lineality()
54 4
55
56 TESTS:
57
58 todo.
59 should be permutation invariant.
60 should have the expected lyapunov rank.
61 just loop through them all for n <= 10 and p < n?
62
63 """
64
65 def d(j):
66 v = [1]*n # Create the list of all ones...
67 v[j] = 1 - p # Now "fix" the ``j``th entry.
68 return v
69
70 V = VectorSpace(QQ, n)
71 G = V.basis() + [ d(j) for j in range(n) ]
72 return Cone(G)