]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/faces.py
mjo/**/*.py: drop obsolete set_random_seed().
[sage.d.git] / mjo / cone / faces.py
1 from sage.all import *
2
3
4 def face_generated_by(K,S):
5 r"""
6 Return the intersection of all faces of ``K`` that contain ``S``.
7
8 REFERENCES:
9
10 .. [Tam] Bit-Shun Tam. On the duality operator of a convex cone. Linear
11 Algebra and its Applications, 64:33-56, 1985, doi:10.1016/0024-3795(85)
12 90265-4.
13
14 SETUP::
15
16 sage: from mjo.cone.faces import face_generated_by
17
18 EXAMPLES:
19
20 The face generated by a standard basis vector in the nonnegative
21 orthant should be the cone consisting of all nonnegative multiples
22 of that standard basis vector::
23
24 sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)])
25 sage: F = Cone([(1,0,0)])
26 sage: face_generated_by(K,F) == F
27 True
28
29 If we take a nontrivial combination of standard basis vectors in the
30 nonnegative orthant, then the face that the combination generates
31 should be the cone generated by those two basis vectors::
32
33 sage: e1 = vector(QQ, [1,0,0])
34 sage: e2 = vector(QQ, [0,1,0])
35 sage: e3 = vector(QQ, [0,0,1])
36 sage: K = Cone([e1,e2,e2])
37 sage: F = [e1/2 + e2/2]
38 sage: face_generated_by(K,F).is_equivalent(Cone([e1,e2]))
39 True
40
41 An error is raised if ``S`` is not contained in ``K``::
42
43 sage: K = Cone([(1,0),(0,1)])
44 sage: S = [(1,1), (-1,3)]
45 sage: face_generated_by(K,S)
46 Traceback (most recent call last):
47 ...
48 ValueError: S is not a subset of the cone
49
50 TESTS:
51
52 The face generated by <whatever> should be a face::
53
54 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
55 sage: S = ( K.random_element() for idx in range(5) )
56 sage: F = face_generated_by(K, S)
57 sage: F.is_face_of(K)
58 True
59
60 The face generated by a set should always contain that set::
61
62 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
63 sage: S = ( K.random_element() for idx in range(5) )
64 sage: F = face_generated_by(K, S)
65 sage: all(F.contains(x) for x in S)
66 True
67
68 The generators of a proper cone are all extreme vectors of the cone,
69 and therefore generate their own faces::
70
71 sage: K = random_cone(max_ambient_dim=8,
72 ....: max_rays=10,
73 ....: strictly_convex=True,
74 ....: solid=True)
75 sage: all(face_generated_by(K, [r]) == Cone([r]) for r in K)
76 True
77
78 For any point ``x`` in ``K`` and any face ``F`` of ``K``, we have
79 that ``x`` is in the relative interior of ``F`` if and only if
80 ``F`` is the face generated by ``x`` [Tam]_::
81
82 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
83 sage: x = K.random_element()
84 sage: S = [x]
85 sage: F = K.face_lattice().random_element()
86 sage: expected = F.relative_interior_contains(x)
87 sage: actual = (F == face_generated_by(K, S))
88 sage: actual == expected
89 True
90
91 If ``F`` and ``G`` are two faces of ``K``, then the join of ``F``
92 and ``G`` in the face lattice is equal to the face generated by
93 ``F + G`` (in the Minkowski sense) [Tam]_::
94
95 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
96 sage: L = K.face_lattice()
97 sage: F = L.random_element()
98 sage: G = L.random_element()
99 sage: expected = L.join(F,G)
100 sage: actual = face_generated_by(K, F.rays() + G.rays())
101 sage: actual == expected
102 True
103
104 Combining Proposition 3.1 and Corollary 3.9 in [Tam]_ gives the
105 following equality for any ``y`` in ``K``::
106
107 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
108 sage: y = K.random_element()
109 sage: S = [y]
110 sage: phi_y = face_generated_by(K,S)
111 sage: points_cone_gens = list(K.rays()) + [-z for z in phi_y.rays()]
112 sage: points_cone = Cone(points_cone_gens, K.lattice())
113 sage: actual = phi_y.span(QQ)
114 sage: expected = points_cone.linear_subspace()
115 sage: actual == expected
116 True
117
118 """
119 face_lattice = K.face_lattice()
120 candidates = [F for F in face_lattice if all(F.contains(x) for x in S)]
121
122 # K itself is a face of K, so unless we were given a set S that
123 # isn't a subset of K, the candidates list will be nonempty.
124 if len(candidates) == 0:
125 raise ValueError('S is not a subset of the cone')
126 else:
127 return face_lattice.sorted(candidates)[0]
128
129
130 def dual_face(K,F):
131 r"""
132 Return the dual face of ``F`` with respect to the cone ``K``.
133
134 OUTPUT:
135
136 A face of ``K.dual()``.
137
138 REFERENCES:
139
140 .. [HilgertHofmannLawson] Joachim Hilgert, Karl Heinrich Hofmann, and Jimmie
141 D. Lawson. Lie groups, convex cones and semigroups. Oxford Mathematical
142 Monographs. Clarendon Press, Oxford, 1989. ISBN 9780198535690.
143
144 .. [Tam] Bit-Shun Tam. On the duality operator of a convex cone. Linear
145 Algebra and its Applications, 64:33-56, 1985, doi:10.1016/0024-3795(85)
146 90265-4.
147
148 SETUP::
149
150 sage: from mjo.cone.faces import (dual_face, face_generated_by)
151
152 EXAMPLES:
153
154 The dual face of the first standard basis vector in three dimensions
155 is the face generated by the other two standard basis vectors::
156
157 sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)])
158 sage: F = Cone([(1,0,0)])
159 sage: dual_face(K,F).rays()
160 M(0, 0, 1),
161 M(0, 1, 0)
162 in 3-d lattice M
163
164 TESTS:
165
166 The dual face of ``K`` with respect to itself should be the
167 lineality space of its dual [Tam]_::
168
169 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
170 sage: K_dual = K.dual()
171 sage: lKd_gens = ( dir*l for dir in [1,-1] for l in K_dual.lines() )
172 sage: linspace_K_dual = Cone(lKd_gens, K_dual.lattice())
173 sage: dual_face(K,K).is_equivalent(linspace_K_dual)
174 True
175
176 If ``K`` is proper, then the dual face of its trivial face is the
177 dual of ``K`` [Tam]_::
178
179 sage: K = random_cone(max_ambient_dim=8,
180 ....: max_rays=10,
181 ....: strictly_convex=True,
182 ....: solid=True)
183 sage: L = K.lattice()
184 sage: trivial_face = Cone([L.zero()], L)
185 sage: dual_face(K,trivial_face).is_equivalent(K.dual())
186 True
187
188 The dual of the cone of ``K`` at ``y`` is the dual face of the face
189 of ``K`` generated by ``y`` ([Tam]_ Corollary 3.2)::
190
191 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
192 sage: y = K.random_element()
193 sage: S = [y]
194 sage: phi_y = face_generated_by(K,S)
195 sage: points_cone_gens = list(K.rays()) + [-z for z in phi_y.rays()]
196 sage: points_cone = Cone(points_cone_gens, K.lattice())
197 sage: points_cone.dual().is_equivalent(dual_face(K, phi_y))
198 True
199
200 Since all faces of a polyhedral cone are exposed, the dual face of a
201 dual face should be the original face [HilgertHofmannLawson]_::
202
203 sage: def check_prop(K,F):
204 ....: return dual_face(K.dual(), dual_face(K,F)).is_equivalent(F)
205 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
206 sage: all(check_prop(K,F) for F in K.face_lattice())
207 True
208
209 """
210 # Ensure that F is actually a face of K before continuing.
211 if not F.is_face_of(K):
212 raise ValueError("%s is not a face of %s" % (F,K))
213
214 span_F = Cone((c*g for c in [1,-1] for g in F), F.lattice())
215 return K.dual().intersection(span_F.dual())