]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/schur.py
cone/schur.py: add "lattice" argument.
[sage.d.git] / mjo / cone / schur.py
1 """
2 The Schur cone, as described in the "Critical angles..." papers by
3 Iusem, Seeger, and Sossa. It defines the Schur ordering on `R^{n}`.
4 """
5
6 from sage.all import *
7
8 def schur_cone(n, lattice=None):
9 r"""
10 Return the Schur cone in ``n`` dimensions.
11
12 INPUT:
13
14 - ``n`` -- the dimension the ambient space.
15
16 - ``lattice`` -- (default: ``None``) an ambient lattice of rank ``n``
17 to be passed to the :func:`Cone` constructor.
18
19 OUTPUT:
20
21 A rational closed convex Schur cone of dimension ``n``. Each
22 generating ray will have the integer ring as its base ring.
23
24 If a ``lattice`` was specified, then the resulting cone will live in
25 that lattice unless its rank is incompatible with the dimension
26 ``n`` (in which case a ``ValueError`` is raised).
27
28 REFERENCES:
29
30 .. [GourionSeeger] Daniel Gourion and Alberto Seeger.
31 Critical angles in polyhedral convex cones: numerical and
32 statistical considerations. Mathematical Programming, 123:173-198,
33 2010, doi:10.1007/s10107-009-0317-2.
34
35 .. [IusemSeegerOnPairs] Alfredo Iusem and Alberto Seeger.
36 On pairs of vectors achieving the maximal angle of a convex cone.
37 Mathematical Programming, 104(2-3):501-523, 2005,
38 doi:10.1007/s10107-005-0626-z.
39
40 .. [SeegerSossaI] Alberto Seeger and David Sossa.
41 Critical angles between two convex cones I. General theory.
42 TOP, 24(1):44-65, 2016, doi:10.1007/s11750-015-0375-y.
43
44 SETUP::
45
46 sage: from mjo.cone.nonnegative_orthant import nonnegative_orthant
47 sage: from mjo.cone.schur import schur_cone
48
49 EXAMPLES:
50
51 Verify the claim that the maximal angle between any two generators
52 of the Schur cone and the nonnegative quintant is ``3*pi/4``::
53
54 sage: P = schur_cone(5)
55 sage: Q = nonnegative_orthant(5)
56 sage: G = ( g.change_ring(QQbar).normalized() for g in P )
57 sage: H = ( h.change_ring(QQbar).normalized() for h in Q )
58 sage: actual = max(arccos(u.inner_product(v)) for u in G for v in H)
59 sage: expected = 3*pi/4
60 sage: abs(actual - expected).n() < 1e-12
61 True
62
63 The dual of the Schur cone is the "downward monotonic cone"
64 [GourionSeeger]_, whose elements' entries are in non-increasing
65 order::
66
67 sage: set_random_seed()
68 sage: n = ZZ.random_element(10)
69 sage: K = schur_cone(n).dual()
70 sage: x = K.random_element()
71 sage: all( x[i] >= x[i+1] for i in xrange(n-1) )
72 True
73
74 TESTS:
75
76 We get the trivial cone when ``n`` is zero::
77
78 sage: schur_cone(0).is_trivial()
79 True
80
81 The Schur cone induces the majorization ordering::
82
83 sage: set_random_seed()
84 sage: def majorized_by(x,y):
85 ....: return (all(sum(x[0:i]) <= sum(y[0:i])
86 ....: for i in xrange(x.degree()-1))
87 ....: and sum(x) == sum(y))
88 sage: n = ZZ.random_element(10)
89 sage: V = VectorSpace(QQ, n)
90 sage: S = schur_cone(n)
91 sage: majorized_by(V.zero(), S.random_element())
92 True
93 sage: x = V.random_element()
94 sage: y = V.random_element()
95 sage: majorized_by(x,y) == ( (y-x) in S )
96 True
97
98 If a ``lattice`` was given, it is actually used::
99
100 sage: L = ToricLattice(3, 'M')
101 sage: schur_cone(3, lattice=L)
102 2-d cone in 3-d lattice M
103
104 Unless the rank of the lattice disagrees with ``n``::
105
106 sage: L = ToricLattice(1, 'M')
107 sage: schur_cone(3, lattice=L)
108 Traceback (most recent call last):
109 ...
110 ValueError: lattice rank=1 and dimension n=3 are incompatible
111
112 """
113 if lattice is None:
114 lattice = ToricLattice(n)
115
116 if lattice.rank() != n:
117 raise ValueError('lattice rank=%d and dimension n=%d are incompatible'
118 %
119 (lattice.rank(), n))
120
121 def _f(i,j):
122 if i == j:
123 return 1
124 elif j - i == 1:
125 return -1
126 else:
127 return 0
128
129 # The "max" below catches the trivial case where n == 0.
130 S = matrix(ZZ, max(0,n-1), n, _f)
131
132 return Cone(S.rows(), lattice)