]>
gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/cone.py
a7c16a520cbe19242398e176635ad3250e5c7671
3 def is_positive_on(L
,K
):
5 Determine whether or not ``L`` is positive on ``K``.
7 We say that ``L`` is positive on ``K`` if `L\left\lparen x
8 \right\rparen` belongs to ``K`` for all `x` in ``K``. This
9 property need only be checked for generators of ``K``.
13 - ``L`` -- A linear transformation or matrix.
15 - ``K`` -- A polyhedral closed convex cone.
19 ``True`` if it can be proven that ``L`` is positive on ``K``,
20 and ``False`` otherwise.
24 If this function returns ``True``, then ``L`` is positive
25 on ``K``. However, if ``False`` is returned, that could mean one
26 of two things. The first is that ``L`` is definitely not
27 positive on ``K``. The second is more of an "I don't know"
28 answer, returned (for example) if we cannot prove that an inner
29 product is nonnegative.
33 The identity is always positive in a nontrivial space::
35 sage: set_random_seed()
36 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=8)
37 sage: L = identity_matrix(K.lattice_dim())
38 sage: is_positive_on(L,K)
41 As is the "zero" transformation::
43 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=8)
44 sage: R = K.lattice().vector_space().base_ring()
45 sage: L = zero_matrix(R, K.lattice_dim())
46 sage: is_positive_on(L,K)
51 Everything in ``K.positive_operators_gens()`` should be
54 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=6)
55 sage: all([ is_positive_on(L,K)
56 ....: for L in K.positive_operators_gens() ])
58 sage: all([ is_positive_on(L.change_ring(SR),K)
59 ....: for L in K.positive_operators_gens() ])
63 if L
.base_ring().is_exact():
64 # This could potentially be extended to other types of ``K``...
65 return all([ L
*x
in K
for x
in K
])
66 elif L
.base_ring() is SR
:
67 # Fall back to inequality-checking when the entries of ``L``
69 return all([ s
*(L
*x
) >= 0 for x
in K
for s
in K
])
71 # The only inexact ring that we're willing to work with is SR,
72 # since it can still be exact when working with symbolic
73 # constants like pi and e.
74 raise ValueError('base ring of operator L is neither SR nor exact')
77 def is_cross_positive_on(L
,K
):
79 Determine whether or not ``L`` is cross-positive on ``K``.
81 We say that ``L`` is cross-positive on ``K`` if `\left\langle
82 L\left\lparenx\right\rparen,s\right\rangle \ge 0` for all pairs
83 `\left\langle x,s \right\rangle` in the complementarity set of
84 ``K``. This property need only be checked for generators of
89 - ``L`` -- A linear transformation or matrix.
91 - ``K`` -- A polyhedral closed convex cone.
95 ``True`` if it can be proven that ``L`` is cross-positive on ``K``,
96 and ``False`` otherwise.
100 If this function returns ``True``, then ``L`` is cross-positive
101 on ``K``. However, if ``False`` is returned, that could mean one
102 of two things. The first is that ``L`` is definitely not
103 cross-positive on ``K``. The second is more of an "I don't know"
104 answer, returned (for example) if we cannot prove that an inner
105 product is nonnegative.
109 The identity is always cross-positive in a nontrivial space::
111 sage: set_random_seed()
112 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=8)
113 sage: L = identity_matrix(K.lattice_dim())
114 sage: is_cross_positive_on(L,K)
117 As is the "zero" transformation::
119 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=8)
120 sage: R = K.lattice().vector_space().base_ring()
121 sage: L = zero_matrix(R, K.lattice_dim())
122 sage: is_cross_positive_on(L,K)
127 Everything in ``K.cross_positive_operators_gens()`` should be
128 cross-positive on ``K``::
130 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=6)
131 sage: all([ is_cross_positive_on(L,K)
132 ....: for L in K.cross_positive_operators_gens() ])
134 sage: all([ is_cross_positive_on(L.change_ring(SR),K)
135 ....: for L in K.cross_positive_operators_gens() ])
139 if L
.base_ring().is_exact() or L
.base_ring() is SR
:
140 return all([ s
*(L
*x
) >= 0
141 for (x
,s
) in K
.discrete_complementarity_set() ])
143 # The only inexact ring that we're willing to work with is SR,
144 # since it can still be exact when working with symbolic
145 # constants like pi and e.
146 raise ValueError('base ring of operator L is neither SR nor exact')
151 Determine whether or not ``L`` is a Z-operator on ``K``.
153 We say that ``L`` is a Z-operator on ``K`` if `\left\langle
154 L\left\lparenx\right\rparen,s\right\rangle \le 0` for all pairs
155 `\left\langle x,s \right\rangle` in the complementarity set of
156 ``K``. It is known that this property need only be
157 checked for generators of ``K`` and its dual.
159 A matrix is a Z-operator on ``K`` if and only if its negation is a
160 cross-positive operator on ``K``.
164 - ``L`` -- A linear transformation or matrix.
166 - ``K`` -- A polyhedral closed convex cone.
170 ``True`` if it can be proven that ``L`` is a Z-operator on ``K``,
171 and ``False`` otherwise.
175 If this function returns ``True``, then ``L`` is a Z-operator
176 on ``K``. However, if ``False`` is returned, that could mean one
177 of two things. The first is that ``L`` is definitely not
178 a Z-operator on ``K``. The second is more of an "I don't know"
179 answer, returned (for example) if we cannot prove that an inner
180 product is nonnegative.
184 The identity is always a Z-operator in a nontrivial space::
186 sage: set_random_seed()
187 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=8)
188 sage: L = identity_matrix(K.lattice_dim())
192 As is the "zero" transformation::
194 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=8)
195 sage: R = K.lattice().vector_space().base_ring()
196 sage: L = zero_matrix(R, K.lattice_dim())
202 Everything in ``K.Z_operators_gens()`` should be a Z-operator
205 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=6)
206 sage: all([ is_Z_on(L,K)
207 ....: for L in K.Z_operators_gens() ])
209 sage: all([ is_Z_on(L.change_ring(SR),K)
210 ....: for L in K.Z_operators_gens() ])
214 return is_cross_positive_on(-L
,K
)
217 def is_lyapunov_like_on(L
,K
):
219 Determine whether or not ``L`` is Lyapunov-like on ``K``.
221 We say that ``L`` is Lyapunov-like on ``K`` if `\left\langle
222 L\left\lparenx\right\rparen,s\right\rangle = 0` for all pairs
223 `\left\langle x,s \right\rangle` in the complementarity set of
224 ``K``. This property need only be checked for generators of
229 - ``L`` -- A linear transformation or matrix.
231 - ``K`` -- A polyhedral closed convex cone.
235 ``True`` if it can be proven that ``L`` is Lyapunov-like on ``K``,
236 and ``False`` otherwise.
240 If this function returns ``True``, then ``L`` is Lyapunov-like
241 on ``K``. However, if ``False`` is returned, that could mean one
242 of two things. The first is that ``L`` is definitely not
243 Lyapunov-like on ``K``. The second is more of an "I don't know"
244 answer, returned (for example) if we cannot prove that an inner
249 The identity is always Lyapunov-like in a nontrivial space::
251 sage: set_random_seed()
252 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=8)
253 sage: L = identity_matrix(K.lattice_dim())
254 sage: is_lyapunov_like_on(L,K)
257 As is the "zero" transformation::
259 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=8)
260 sage: R = K.lattice().vector_space().base_ring()
261 sage: L = zero_matrix(R, K.lattice_dim())
262 sage: is_lyapunov_like_on(L,K)
267 Everything in ``K.lyapunov_like_basis()`` should be Lyapunov-like
270 sage: K = random_cone(min_ambient_dim=1, max_ambient_dim=6)
271 sage: all([ is_lyapunov_like_on(L,K)
272 ....: for L in K.lyapunov_like_basis() ])
274 sage: all([ is_lyapunov_like_on(L.change_ring(SR),K)
275 ....: for L in K.lyapunov_like_basis() ])
279 if L
.base_ring().is_exact() or L
.base_ring() is SR
:
280 # The "fast method" of creating a vector space based on a
281 # ``lyapunov_like_basis`` is actually slower than this.
282 return all([ s
*(L
*x
) == 0
283 for (x
,s
) in K
.discrete_complementarity_set() ])
285 # The only inexact ring that we're willing to work with is SR,
286 # since it can still be exact when working with symbolic
287 # constants like pi and e.
288 raise ValueError('base ring of operator L is neither SR nor exact')
291 gens
= K
.lyapunov_like_basis()
292 L
= ToricLattice(K
.lattice_dim()**2)
293 return Cone([ g
.list() for g
in gens
], lattice
=L
, check
=False)
296 gens
= K
.cross_positive_operators_gens()
297 L
= ToricLattice(K
.lattice_dim()**2)
298 return Cone([ g
.list() for g
in gens
], lattice
=L
, check
=False)
301 gens
= K
.Z_operators_gens()
302 L
= ToricLattice(K
.lattice_dim()**2)
303 return Cone([ g
.list() for g
in gens
], lattice
=L
, check
=False)
305 def pi_cone(K1
, K2
=None):
308 gens
= K1
.positive_operators_gens(K2
)
309 L
= ToricLattice(K1
.lattice_dim()*K2
.lattice_dim())
310 return Cone([ g
.list() for g
in gens
], lattice
=L
, check
=False)