]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/schur.py
cone/schur.py: test that the schur cone induces the majorization ordering.
[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):
9 r"""
10 Return the Schur cone in ``n`` dimensions.
11
12 INPUT:
13
14 - ``n`` -- the dimension the ambient space.
15
16 OUTPUT:
17
18 A rational closed convex Schur cone of dimension ``n``.
19
20 REFERENCES:
21
22 .. [IusemSeegerOnPairs] Alfredo Iusem and Alberto Seeger.
23 On pairs of vectors achieving the maximal angle of a convex cone.
24 Mathematical Programming, 104(2-3):501-523, 2005,
25 doi:10.1007/s10107-005-0626-z.
26
27 .. [SeegerSossaI] Alberto Seeger and David Sossa.
28 Critical angles between two convex cones I. General theory.
29 TOP, 24(1):44-65, 2016, doi:10.1007/s11750-015-0375-y.
30
31 SETUP::
32
33 sage: from mjo.cone.nonnegative_orthant import nonnegative_orthant
34 sage: from mjo.cone.schur import schur_cone
35
36 EXAMPLES:
37
38 Verify the claim that the maximal angle between any two generators
39 of the Schur cone and the nonnegative quintant is ``3*pi/4``::
40
41 sage: P = schur_cone(5)
42 sage: Q = nonnegative_orthant(5)
43 sage: G = [ g.change_ring(QQbar).normalized() for g in P ]
44 sage: H = [ h.change_ring(QQbar).normalized() for h in Q ]
45 sage: actual = max([arccos(u.inner_product(v)) for u in G for v in H])
46 sage: expected = 3*pi/4
47 sage: abs(actual - expected).n() < 1e-12
48 True
49
50 TESTS:
51
52 We get the trivial cone when ``n`` is zero::
53
54 sage: schur_cone(0).is_trivial()
55 True
56
57 The Schur cone induces the majorization ordering::
58
59 sage: set_random_seed()
60 sage: def majorized_by(x,y):
61 ....: return (all(sum(x[0:i]) <= sum(y[0:i])
62 ....: for i in range(x.degree()-1))
63 ....: and sum(x) == sum(y))
64 sage: n = ZZ.random_element(10)
65 sage: V = VectorSpace(QQ, n)
66 sage: S = schur_cone(n)
67 sage: majorized_by(V.zero(), S.random_element())
68 True
69 sage: x = V.random_element()
70 sage: y = V.random_element()
71 sage: majorized_by(x,y) == ( (y-x) in S )
72 True
73
74 """
75
76 def _f(i,j):
77 if i == j:
78 return 1
79 elif j - i == 1:
80 return -1
81 else:
82 return 0
83
84 # The "max" below catches the trivial case where n == 0.
85 S = matrix(ZZ, max(0,n-1), n, _f)
86
87 # Likewise, when n == 0, we need to specify the lattice.
88 return Cone(S.rows(), ToricLattice(n))