]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/faces.py
cone/faces.py: test that dual-face-of-dual-face is a no-op.
[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: set_random_seed()
55 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
56 sage: S = [K.random_element() for idx in range(0,5)]
57 sage: F = face_generated_by(K, S)
58 sage: F.is_face_of(K)
59 True
60
61 The face generated by a set should always contain that set::
62
63 sage: set_random_seed()
64 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
65 sage: S = [K.random_element() for idx in range(0,5)]
66 sage: F = face_generated_by(K, S)
67 sage: all([F.contains(x) for x in S])
68 True
69
70 The generators of a proper cone are all extreme vectors of the cone,
71 and therefore generate their own faces::
72
73 sage: set_random_seed()
74 sage: K = random_cone(max_ambient_dim=8,
75 ....: max_rays=10,
76 ....: strictly_convex=True,
77 ....: solid=True)
78 sage: all([face_generated_by(K, [r]) == Cone([r]) for r in K])
79 True
80
81 For any point ``x`` in ``K`` and any face ``F`` of ``K``, we have
82 that ``x`` is in the relative interior of ``F`` if and only if
83 ``F`` is the face generated by ``x`` [Tam]_::
84
85 sage: set_random_seed()
86 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
87 sage: x = K.random_element()
88 sage: S = [x]
89 sage: F = K.face_lattice().random_element()
90 sage: expected = F.relative_interior_contains(x)
91 sage: actual = (F == face_generated_by(K, S))
92 sage: actual == expected
93 True
94
95 If ``F`` and ``G`` are two faces of ``K``, then the join of ``F``
96 and ``G`` in the face lattice is equal to the face generated by
97 ``F + G`` (in the Minkowski sense) [Tam]_::
98
99 sage: set_random_seed()
100 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
101 sage: L = K.face_lattice()
102 sage: F = L.random_element()
103 sage: G = L.random_element()
104 sage: expected = L.join(F,G)
105 sage: actual = face_generated_by(K, F.rays() + G.rays())
106 sage: actual == expected
107 True
108
109 Combining Proposition 3.1 and Corollary 3.9 in [Tam]_ gives the
110 following equality for any ``y`` in ``K``::
111
112 sage: set_random_seed()
113 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
114 sage: y = K.random_element()
115 sage: S = [y]
116 sage: phi_y = face_generated_by(K,S)
117 sage: points_cone_gens = list(K.rays()) + [-z for z in phi_y.rays()]
118 sage: points_cone = Cone(points_cone_gens, K.lattice())
119 sage: actual = phi_y.span(QQ)
120 sage: expected = points_cone.linear_subspace()
121 sage: actual == expected
122 True
123
124 """
125 face_lattice = K.face_lattice()
126 candidates = [F for F in face_lattice if all([F.contains(x) for x in S])]
127
128 # K itself is a face of K, so unless we were given a set S that
129 # isn't a subset of K, the candidates list will be nonempty.
130 if len(candidates) == 0:
131 raise ValueError('S is not a subset of the cone')
132 else:
133 return face_lattice.sorted(candidates)[0]
134
135
136 def dual_face(K,F):
137 r"""
138 Return the dual face of ``F`` with respect to the cone ``K``.
139
140 OUTPUT:
141
142 A face of ``K.dual()``.
143
144 REFERENCES:
145
146 .. [Tam] Bit-Shun Tam. On the duality operator of a convex cone. Linear
147 Algebra and its Applications, 64:33-56, 1985, doi:10.1016/0024-3795(85)
148 90265-4.
149
150 SETUP::
151
152 sage: from mjo.cone.faces import (dual_face, face_generated_by)
153
154 EXAMPLES:
155
156 The dual face of the first standard basis vector in three dimensions
157 is the face generated by the other two standard basis vectors::
158
159 sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)])
160 sage: F = Cone([(1,0,0)])
161 sage: dual_face(K,F).rays()
162 M(0, 0, 1),
163 M(0, 1, 0)
164 in 3-d lattice M
165
166 TESTS:
167
168 The dual face of ``K`` with respect to itself should be the
169 lineality space of its dual [Tam]_::
170
171 sage: set_random_seed()
172 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
173 sage: K_dual = K.dual()
174 sage: lKd_gens = [ dir*l for dir in [1,-1] for l in K_dual.lines() ]
175 sage: linspace_K_dual = Cone(lKd_gens, K_dual.lattice())
176 sage: dual_face(K,K).is_equivalent(linspace_K_dual)
177 True
178
179 If ``K`` is proper, then the dual face of its trivial face is the
180 dual of ``K`` [Tam]_::
181
182 sage: set_random_seed()
183 sage: K = random_cone(max_ambient_dim=8,
184 ....: max_rays=10,
185 ....: strictly_convex=True,
186 ....: solid=True)
187 sage: L = K.lattice()
188 sage: trivial_face = Cone([L.zero()], L)
189 sage: dual_face(K,trivial_face).is_equivalent(K.dual())
190 True
191
192 The dual of the cone of ``K`` at ``y`` is the dual face of the face
193 of ``K`` generated by ``y`` ([Tam]_ Corollary 3.2)::
194
195 sage: set_random_seed()
196 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
197 sage: y = K.random_element()
198 sage: S = [y]
199 sage: phi_y = face_generated_by(K,S)
200 sage: points_cone_gens = list(K.rays()) + [-z for z in phi_y.rays()]
201 sage: points_cone = Cone(points_cone_gens, K.lattice())
202 sage: points_cone.dual().is_equivalent(dual_face(K, phi_y))
203 True
204
205 Since all faces of a polyhedral cone are exposed, the dual face of a
206 dual face should be the original face [HilgertHofmannLawson]_::
207
208 sage: set_random_seed()
209 sage: def check_prop(K,F):
210 ....: return dual_face(K.dual(), dual_face(K,F)).is_equivalent(F)
211 sage: K = random_cone(max_ambient_dim=8, max_rays=10)
212 sage: all([check_prop(K,F) for F in K.face_lattice()])
213 True
214
215 """
216 # Ensure that F is actually a face of K before continuing.
217 if not F.is_face_of(K):
218 raise ValueError("%s is not a face of %s" % (F,K))
219
220 span_F = Cone([c*g for c in [1,-1] for g in F], F.lattice())
221 return K.dual().intersection(span_F.dual())