]>
gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/cone.py
aeec0c90b5f582c8ba858d4b616fff191fb6d529
2 from sage
.geometry
.cone
import is_Cone
4 def is_positive_on(L
,K
):
6 Determine whether or not ``L`` is positive on ``K``.
8 We say that ``L`` is positive on a closed convex cone ``K`` if
9 `L\left\lparen x \right\rparen` belongs to ``K`` for all `x` in
10 ``K``. This property need only be checked for generators of ``K``.
12 To reliably check whether or not ``L`` is positive, its base ring
13 must be either exact (for example, the rationals) or ``SR``. An
14 exact ring is more reliable, but in some cases a matrix whose
15 entries contain symbolic constants like ``e`` and ``pi`` will work.
19 - ``L`` -- A matrix over either an exact ring or ``SR``.
21 - ``K`` -- A polyhedral closed convex cone.
25 If the base ring of ``L`` is exact, then ``True`` will be returned if
26 and only if ``L`` is positive on ``K``.
28 If the base ring of ``L`` is ``SR``, then the situation is more
31 - ``True`` will be returned if it can be proven that ``L``
33 - ``False`` will be returned if it can be proven that ``L``
34 is not positive on ``K``.
35 - ``False`` will also be returned if we can't decide; specifically
36 if we arrive at a symbolic inequality that cannot be resolved.
40 :func:`is_cross_positive_on`,
41 :func:`is_Z_operator_on`,
42 :func:`is_lyapunov_like_on`
46 Nonnegative matrices are positive operators on the nonnegative
49 sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)])
50 sage: L = random_matrix(QQ,3).apply_map(abs)
51 sage: is_positive_on(L,K)
56 The identity operator is always positive::
58 sage: set_random_seed()
59 sage: K = random_cone(max_ambient_dim=8)
60 sage: L = identity_matrix(K.lattice_dim())
61 sage: is_positive_on(L,K)
64 The "zero" operator is always positive::
66 sage: K = random_cone(max_ambient_dim=8)
67 sage: R = K.lattice().vector_space().base_ring()
68 sage: L = zero_matrix(R, K.lattice_dim())
69 sage: is_positive_on(L,K)
72 Everything in ``K.positive_operators_gens()`` should be
75 sage: K = random_cone(max_ambient_dim=5)
76 sage: all([ is_positive_on(L,K) # long time
77 ....: for L in K.positive_operators_gens() ]) # long time
79 sage: all([ is_positive_on(L.change_ring(SR),K) # long time
80 ....: for L in K.positive_operators_gens() ]) # long time
83 Technically we could test this, but for now only closed convex cones
84 are supported as our ``K`` argument::
86 sage: K = [ vector([1,2,3]), vector([5,-1,7]) ]
87 sage: L = identity_matrix(3)
88 sage: is_positive_on(L,K)
89 Traceback (most recent call last):
91 TypeError: K must be a Cone.
93 We can't give reliable answers over inexact rings::
95 sage: K = Cone([(1,2,3), (4,5,6)])
96 sage: L = identity_matrix(RR,3)
97 sage: is_positive_on(L,K)
98 Traceback (most recent call last):
100 ValueError: The base ring of L is neither SR nor exact.
105 raise TypeError('K must be a Cone.')
106 if not L
.base_ring().is_exact() and not L
.base_ring() is SR
:
107 raise ValueError('The base ring of L is neither SR nor exact.')
109 if L
.base_ring().is_exact():
110 # This should be way faster than computing the dual and
111 # checking a bunch of inequalities, but it doesn't work if
112 # ``L*x`` is symbolic. For example, ``e in Cone([(1,)])``
113 # is true, but returns ``False``.
114 return all([ L
*x
in K
for x
in K
])
116 # Fall back to inequality-checking when the entries of ``L``
118 return all([ s
*(L
*x
) >= 0 for x
in K
for s
in K
.dual() ])
121 def is_cross_positive_on(L
,K
):
123 Determine whether or not ``L`` is cross-positive on ``K``.
125 We say that ``L`` is cross-positive on a closed convex cone``K`` if
126 `\left\langle L\left\lparenx\right\rparen,s\right\rangle \ge 0` for
127 all pairs `\left\langle x,s \right\rangle` in the complementarity
128 set of ``K``. This property need only be checked for generators of
131 To reliably check whether or not ``L`` is cross-positive, its base
132 ring must be either exact (for example, the rationals) or ``SR``. An
133 exact ring is more reliable, but in some cases a matrix whose
134 entries contain symbolic constants like ``e`` and ``pi`` will work.
138 - ``L`` -- A matrix over either an exact ring or ``SR``.
140 - ``K`` -- A polyhedral closed convex cone.
144 If the base ring of ``L`` is exact, then ``True`` will be returned if
145 and only if ``L`` is cross-positive on ``K``.
147 If the base ring of ``L`` is ``SR``, then the situation is more
150 - ``True`` will be returned if it can be proven that ``L``
151 is cross-positive on ``K``.
152 - ``False`` will be returned if it can be proven that ``L``
153 is not cross-positive on ``K``.
154 - ``False`` will also be returned if we can't decide; specifically
155 if we arrive at a symbolic inequality that cannot be resolved.
159 :func:`is_positive_on`,
160 :func:`is_Z_operator_on`,
161 :func:`is_lyapunov_like_on`
165 The identity operator is always cross-positive::
167 sage: set_random_seed()
168 sage: K = random_cone(max_ambient_dim=8)
169 sage: L = identity_matrix(K.lattice_dim())
170 sage: is_cross_positive_on(L,K)
173 The "zero" operator is always cross-positive::
175 sage: K = random_cone(max_ambient_dim=8)
176 sage: R = K.lattice().vector_space().base_ring()
177 sage: L = zero_matrix(R, K.lattice_dim())
178 sage: is_cross_positive_on(L,K)
183 Everything in ``K.cross_positive_operators_gens()`` should be
184 cross-positive on ``K``::
186 sage: K = random_cone(max_ambient_dim=5)
187 sage: all([ is_cross_positive_on(L,K) # long time
188 ....: for L in K.cross_positive_operators_gens() ]) # long time
190 sage: all([ is_cross_positive_on(L.change_ring(SR),K) # long time
191 ....: for L in K.cross_positive_operators_gens() ]) # long time
194 Technically we could test this, but for now only closed convex cones
195 are supported as our ``K`` argument::
197 sage: L = identity_matrix(3)
198 sage: K = [ vector([8,2,-8]), vector([5,-5,7]) ]
199 sage: is_cross_positive_on(L,K)
200 Traceback (most recent call last):
202 TypeError: K must be a Cone.
204 We can't give reliable answers over inexact rings::
206 sage: K = Cone([(1,2,3), (4,5,6)])
207 sage: L = identity_matrix(RR,3)
208 sage: is_cross_positive_on(L,K)
209 Traceback (most recent call last):
211 ValueError: The base ring of L is neither SR nor exact.
215 raise TypeError('K must be a Cone.')
216 if not L
.base_ring().is_exact() and not L
.base_ring() is SR
:
217 raise ValueError('The base ring of L is neither SR nor exact.')
219 return all([ s
*(L
*x
) >= 0
220 for (x
,s
) in K
.discrete_complementarity_set() ])
222 def is_Z_operator_on(L
,K
):
224 Determine whether or not ``L`` is a Z-operator on ``K``.
226 We say that ``L`` is a Z-operator on a closed convex cone``K`` if
227 `\left\langle L\left\lparenx\right\rparen,s\right\rangle \le 0` for
228 all pairs `\left\langle x,s \right\rangle` in the complementarity
229 set of ``K``. It is known that this property need only be checked
230 for generators of ``K`` and its dual.
232 A matrix is a Z-operator on ``K`` if and only if its negation is a
233 cross-positive operator on ``K``.
235 To reliably check whether or not ``L`` is a Z operator, its base
236 ring must be either exact (for example, the rationals) or ``SR``. An
237 exact ring is more reliable, but in some cases a matrix whose
238 entries contain symbolic constants like ``e`` and ``pi`` will work.
242 - ``L`` -- A matrix over either an exact ring or ``SR``.
244 - ``K`` -- A polyhedral closed convex cone.
248 If the base ring of ``L`` is exact, then ``True`` will be returned if
249 and only if ``L`` is a Z-operator on ``K``.
251 If the base ring of ``L`` is ``SR``, then the situation is more
254 - ``True`` will be returned if it can be proven that ``L``
255 is a Z-operator on ``K``.
256 - ``False`` will be returned if it can be proven that ``L``
257 is not a Z-operator on ``K``.
258 - ``False`` will also be returned if we can't decide; specifically
259 if we arrive at a symbolic inequality that cannot be resolved.
263 :func:`is_positive_on`,
264 :func:`is_cross_positive_on`,
265 :func:`is_lyapunov_like_on`
269 The identity operator is always a Z-operator::
271 sage: set_random_seed()
272 sage: K = random_cone(max_ambient_dim=8)
273 sage: L = identity_matrix(K.lattice_dim())
274 sage: is_Z_operator_on(L,K)
277 The "zero" operator is always a Z-operator::
279 sage: K = random_cone(max_ambient_dim=8)
280 sage: R = K.lattice().vector_space().base_ring()
281 sage: L = zero_matrix(R, K.lattice_dim())
282 sage: is_Z_operator_on(L,K)
287 Everything in ``K.Z_operators_gens()`` should be a Z-operator
290 sage: K = random_cone(max_ambient_dim=5)
291 sage: all([ is_Z_operator_on(L,K) # long time
292 ....: for L in K.Z_operators_gens() ]) # long time
294 sage: all([ is_Z_operator_on(L.change_ring(SR),K) # long time
295 ....: for L in K.Z_operators_gens() ]) # long time
298 Technically we could test this, but for now only closed convex cones
299 are supported as our ``K`` argument::
301 sage: L = identity_matrix(3)
302 sage: K = [ vector([-4,20,3]), vector([1,-5,2]) ]
303 sage: is_Z_operator_on(L,K)
304 Traceback (most recent call last):
306 TypeError: K must be a Cone.
309 We can't give reliable answers over inexact rings::
311 sage: K = Cone([(1,2,3), (4,5,6)])
312 sage: L = identity_matrix(RR,3)
313 sage: is_Z_operator_on(L,K)
314 Traceback (most recent call last):
316 ValueError: The base ring of L is neither SR nor exact.
319 return is_cross_positive_on(-L
,K
)
322 def is_lyapunov_like_on(L
,K
):
324 Determine whether or not ``L`` is Lyapunov-like on ``K``.
326 We say that ``L`` is Lyapunov-like on a closed convex cone ``K`` if
327 `\left\langle L\left\lparenx\right\rparen,s\right\rangle = 0` for
328 all pairs `\left\langle x,s \right\rangle` in the complementarity
329 set of ``K``. This property need only be checked for generators of
332 An operator is Lyapunov-like on ``K`` if and only if both the
333 operator itself and its negation are cross-positive on ``K``.
335 To reliably check whether or not ``L`` is Lyapunov-like, its base
336 ring must be either exact (for example, the rationals) or ``SR``. An
337 exact ring is more reliable, but in some cases a matrix whose
338 entries contain symbolic constants like ``e`` and ``pi`` will work.
342 - ``L`` -- A matrix over either an exact ring or ``SR``.
344 - ``K`` -- A polyhedral closed convex cone.
348 If the base ring of ``L`` is exact, then ``True`` will be returned if
349 and only if ``L`` is Lyapunov-like on ``K``.
351 If the base ring of ``L`` is ``SR``, then the situation is more
354 - ``True`` will be returned if it can be proven that ``L``
355 is Lyapunov-like on ``K``.
356 - ``False`` will be returned if it can be proven that ``L``
357 is not Lyapunov-like on ``K``.
358 - ``False`` will also be returned if we can't decide; specifically
359 if we arrive at a symbolic inequality that cannot be resolved.
363 :func:`is_positive_on`,
364 :func:`is_cross_positive_on`,
365 :func:`is_Z_operator_on`
369 Diagonal matrices are Lyapunov-like operators on the nonnegative
372 sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)])
373 sage: L = diagonal_matrix(random_vector(QQ,3))
374 sage: is_lyapunov_like_on(L,K)
379 The identity operator is always Lyapunov-like::
381 sage: set_random_seed()
382 sage: K = random_cone(max_ambient_dim=8)
383 sage: L = identity_matrix(K.lattice_dim())
384 sage: is_lyapunov_like_on(L,K)
387 The "zero" operator is always Lyapunov-like::
389 sage: K = random_cone(max_ambient_dim=8)
390 sage: R = K.lattice().vector_space().base_ring()
391 sage: L = zero_matrix(R, K.lattice_dim())
392 sage: is_lyapunov_like_on(L,K)
395 Everything in ``K.lyapunov_like_basis()`` should be Lyapunov-like
398 sage: K = random_cone(max_ambient_dim=5)
399 sage: all([ is_lyapunov_like_on(L,K) # long time
400 ....: for L in K.lyapunov_like_basis() ]) # long time
402 sage: all([ is_lyapunov_like_on(L.change_ring(SR),K) # long time
403 ....: for L in K.lyapunov_like_basis() ]) # long time
406 Technically we could test this, but for now only closed convex cones
407 are supported as our ``K`` argument::
409 sage: L = identity_matrix(3)
410 sage: K = [ vector([2,2,-1]), vector([5,4,-3]) ]
411 sage: is_lyapunov_like_on(L,K)
412 Traceback (most recent call last):
414 TypeError: K must be a Cone.
416 We can't give reliable answers over inexact rings::
418 sage: K = Cone([(1,2,3), (4,5,6)])
419 sage: L = identity_matrix(RR,3)
420 sage: is_lyapunov_like_on(L,K)
421 Traceback (most recent call last):
423 ValueError: The base ring of L is neither SR nor exact.
427 raise TypeError('K must be a Cone.')
428 if not L
.base_ring().is_exact() and not L
.base_ring() is SR
:
429 raise ValueError('The base ring of L is neither SR nor exact.')
431 return all([ s
*(L
*x
) == 0
432 for (x
,s
) in K
.discrete_complementarity_set() ])
436 gens
= K
.lyapunov_like_basis()
437 L
= ToricLattice(K
.lattice_dim()**2)
438 return Cone([ g
.list() for g
in gens
], lattice
=L
, check
=False)
441 gens
= K
.cross_positive_operators_gens()
442 L
= ToricLattice(K
.lattice_dim()**2)
443 return Cone([ g
.list() for g
in gens
], lattice
=L
, check
=False)
446 gens
= K
.Z_operators_gens()
447 L
= ToricLattice(K
.lattice_dim()**2)
448 return Cone([ g
.list() for g
in gens
], lattice
=L
, check
=False)
450 def pi_cone(K1
, K2
=None):
453 gens
= K1
.positive_operators_gens(K2
)
454 L
= ToricLattice(K1
.lattice_dim()*K2
.lattice_dim())
455 return Cone([ g
.list() for g
in gens
], lattice
=L
, check
=False)