]>
gitweb.michael.orlitzky.com - sage.d.git/blob - cone.py
baff1a7bbea4943206bc323040ef5d554d40ead4
1 # Sage doesn't load ~/.sage/init.sage during testing (sage -t), so we
2 # have to explicitly mangle our sitedir here so that "mjo.cone"
4 from os
.path
import abspath
5 from site
import addsitedir
6 addsitedir(abspath('../../'))
11 def _basically_the_same(K1
, K2
):
13 Test whether or not ``K1`` and ``K2`` are "basically the same."
15 This is a hack to get around the fact that it's difficult to tell
16 when two cones are linearly isomorphic. We have a proposition that
17 equates two cones, but represented over `\mathbb{Q}`, they are
18 merely linearly isomorphic (not equal). So rather than test for
19 equality, we test a list of properties that should be preserved
20 under an invertible linear transformation.
24 ``True`` if ``K1`` and ``K2`` are basically the same, and ``False``
29 Any proper cone with three generators in `\mathbb{R}^{3}` is
30 basically the same as the nonnegative orthant::
32 sage: K1 = Cone([(1,0,0), (0,1,0), (0,0,1)])
33 sage: K2 = Cone([(1,2,3), (3, 18, 4), (66, 51, 0)])
34 sage: _basically_the_same(K1, K2)
37 Negating a cone gives you another cone that is basically the same::
39 sage: K = Cone([(0,2,-5), (-6, 2, 4), (0, 51, 0)])
40 sage: _basically_the_same(K, -K)
45 Any cone is basically the same as itself::
47 sage: K = random_cone(max_dim = 8)
48 sage: _basically_the_same(K, K)
51 After applying an invertible matrix to the rows of a cone, the
52 result should be basically the same as the cone we started with::
54 sage: K1 = random_cone(max_dim = 8)
55 sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular')
56 sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice())
57 sage: _basically_the_same(K1, K2)
61 if K1
.lattice_dim() != K2
.lattice_dim():
64 if K1
.nrays() != K2
.nrays():
67 if K1
.dim() != K2
.dim():
70 if K1
.lineality() != K2
.lineality():
73 if K1
.is_solid() != K2
.is_solid():
76 if K1
.is_strictly_convex() != K2
.is_strictly_convex():
79 if len(LL(K1
)) != len(LL(K2
)):
82 C_of_K1
= discrete_complementarity_set(K1
)
83 C_of_K2
= discrete_complementarity_set(K2
)
84 if len(C_of_K1
) != len(C_of_K2
):
87 if len(K1
.facets()) != len(K2
.facets()):
96 Restrict ``K`` into its own span, or the span of another cone.
100 - ``K2`` -- another cone whose lattice has the same rank as this
105 A new cone in a sublattice.
109 sage: K = Cone([(1,)])
113 sage: K2 = Cone([(1,0)])
114 sage: _rho(K2).rays()
117 sage: K3 = Cone([(1,0,0)])
118 sage: _rho(K3).rays()
121 sage: _rho(K2) == _rho(K3)
126 The projected cone should always be solid::
128 sage: set_random_seed()
129 sage: K = random_cone(max_dim = 8)
134 And the resulting cone should live in a space having the same
135 dimension as the space we restricted it to::
137 sage: set_random_seed()
138 sage: K = random_cone(max_dim = 8)
139 sage: K_S = _rho(K, K.dual() )
140 sage: K_S.lattice_dim() == K.dual().dim()
143 This function should not affect the dimension of a cone::
145 sage: set_random_seed()
146 sage: K = random_cone(max_dim = 8)
147 sage: K.dim() == _rho(K).dim()
150 Nor should it affect the lineality of a cone::
152 sage: set_random_seed()
153 sage: K = random_cone(max_dim = 8)
154 sage: K.lineality() == _rho(K).lineality()
157 No matter which space we restrict to, the lineality should not
160 sage: set_random_seed()
161 sage: K = random_cone(max_dim = 8)
162 sage: K.lineality() >= _rho(K).lineality()
164 sage: K.lineality() >= _rho(K, K.dual()).lineality()
167 If we do this according to our paper, then the result is proper::
169 sage: set_random_seed()
170 sage: K = random_cone(max_dim = 8, strictly_convex=False, solid=False)
172 sage: K_SP = _rho(K_S.dual()).dual()
173 sage: K_SP.is_proper()
175 sage: K_SP = _rho(K_S, K_S.dual())
176 sage: K_SP.is_proper()
181 sage: set_random_seed()
182 sage: K = random_cone(max_dim = 8, strictly_convex=True, solid=False)
184 sage: K_SP = _rho(K_S.dual()).dual()
185 sage: K_SP.is_proper()
187 sage: K_SP = _rho(K_S, K_S.dual())
188 sage: K_SP.is_proper()
193 sage: set_random_seed()
194 sage: K = random_cone(max_dim = 8, strictly_convex=False, solid=True)
196 sage: K_SP = _rho(K_S.dual()).dual()
197 sage: K_SP.is_proper()
199 sage: K_SP = _rho(K_S, K_S.dual())
200 sage: K_SP.is_proper()
205 sage: set_random_seed()
206 sage: K = random_cone(max_dim = 8, strictly_convex=True, solid=True)
208 sage: K_SP = _rho(K_S.dual()).dual()
209 sage: K_SP.is_proper()
211 sage: K_SP = _rho(K_S, K_S.dual())
212 sage: K_SP.is_proper()
215 Test Proposition 7 in our paper concerning the duals and
216 restrictions. Generate a random cone, then create a subcone of
217 it. The operation of dual-taking should then commute with rho::
219 sage: set_random_seed()
220 sage: J = random_cone(max_dim = 8, solid=False, strictly_convex=False)
221 sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
222 sage: K_W_star = _rho(K, J).dual()
223 sage: K_star_W = _rho(K.dual(), J)
224 sage: _basically_the_same(K_W_star, K_star_W)
229 sage: set_random_seed()
230 sage: J = random_cone(max_dim = 8, solid=True, strictly_convex=False)
231 sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
232 sage: K_W_star = _rho(K, J).dual()
233 sage: K_star_W = _rho(K.dual(), J)
234 sage: _basically_the_same(K_W_star, K_star_W)
239 sage: set_random_seed()
240 sage: J = random_cone(max_dim = 8, solid=False, strictly_convex=True)
241 sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
242 sage: K_W_star = _rho(K, J).dual()
243 sage: K_star_W = _rho(K.dual(), J)
244 sage: _basically_the_same(K_W_star, K_star_W)
249 sage: set_random_seed()
250 sage: J = random_cone(max_dim = 8, solid=True, strictly_convex=True)
251 sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice())
252 sage: K_W_star = _rho(K, J).dual()
253 sage: K_star_W = _rho(K.dual(), J)
254 sage: _basically_the_same(K_W_star, K_star_W)
261 # First we project K onto the span of K2. This will explode if the
262 # rank of ``K2.lattice()`` doesn't match ours.
263 span_K2
= Cone(K2
.rays() + (-K2
).rays(), lattice
=K
.lattice())
264 K
= K
.intersection(span_K2
)
266 # Cheat a little to get the subspace span(K2). The paper uses the
267 # rays of K2 as a basis, but everything is invariant under linear
268 # isomorphism (i.e. a change of basis), and this is a little
270 W
= span_K2
.linear_subspace()
272 # We've already intersected K with the span of K2, so every
273 # generator of K should belong to W now.
274 W_rays
= [ W
.coordinate_vector(r
) for r
in K
.rays() ]
276 L
= ToricLattice(K2
.dim())
277 return Cone(W_rays
, lattice
=L
)
281 def discrete_complementarity_set(K
):
283 Compute the discrete complementarity set of this cone.
285 The complementarity set of a cone is the set of all orthogonal pairs
286 `(x,s)` such that `x` is in the cone, and `s` is in its dual. The
287 discrete complementarity set is a subset of the complementarity set
288 where `x` and `s` are required to be generators of their respective
291 For polyhedral cones, the discrete complementarity set is always
296 A list of pairs `(x,s)` such that,
298 * Both `x` and `s` are vectors (not rays).
299 * `x` is a generator of this cone.
300 * `s` is a generator of this cone's dual.
301 * `x` and `s` are orthogonal.
305 .. [Orlitzky/Gowda] M. Orlitzky and M. S. Gowda. The Lyapunov Rank of an
306 Improper Cone. Work in-progress.
310 The discrete complementarity set of the nonnegative orthant consists
311 of pairs of standard basis vectors::
313 sage: K = Cone([(1,0),(0,1)])
314 sage: discrete_complementarity_set(K)
315 [((1, 0), (0, 1)), ((0, 1), (1, 0))]
317 If the cone consists of a single ray, the second components of the
318 discrete complementarity set should generate the orthogonal
319 complement of that ray::
321 sage: K = Cone([(1,0)])
322 sage: discrete_complementarity_set(K)
323 [((1, 0), (0, 1)), ((1, 0), (0, -1))]
324 sage: K = Cone([(1,0,0)])
325 sage: discrete_complementarity_set(K)
326 [((1, 0, 0), (0, 1, 0)),
327 ((1, 0, 0), (0, -1, 0)),
328 ((1, 0, 0), (0, 0, 1)),
329 ((1, 0, 0), (0, 0, -1))]
331 When the cone is the entire space, its dual is the trivial cone, so
332 the discrete complementarity set is empty::
334 sage: K = Cone([(1,0),(-1,0),(0,1),(0,-1)])
335 sage: discrete_complementarity_set(K)
338 Likewise when this cone is trivial (its dual is the entire space)::
340 sage: L = ToricLattice(0)
341 sage: K = Cone([], ToricLattice(0))
342 sage: discrete_complementarity_set(K)
347 The complementarity set of the dual can be obtained by switching the
348 components of the complementarity set of the original cone::
350 sage: set_random_seed()
351 sage: K1 = random_cone(max_dim=6)
353 sage: expected = [(x,s) for (s,x) in discrete_complementarity_set(K2)]
354 sage: actual = discrete_complementarity_set(K1)
355 sage: sorted(actual) == sorted(expected)
358 The pairs in the discrete complementarity set are in fact
361 sage: set_random_seed()
362 sage: K = random_cone(max_dim=6)
363 sage: dcs = discrete_complementarity_set(K)
364 sage: sum([x.inner_product(s).abs() for (x,s) in dcs])
368 V
= K
.lattice().vector_space()
370 # Convert rays to vectors so that we can compute inner products.
371 xs
= [V(x
) for x
in K
.rays()]
373 # We also convert the generators of the dual cone so that we
374 # return pairs of vectors and not (vector, ray) pairs.
375 ss
= [V(s
) for s
in K
.dual().rays()]
377 return [(x
,s
) for x
in xs
for s
in ss
if x
.inner_product(s
) == 0]
382 Compute the space `\mathbf{LL}` of all Lyapunov-like transformations
387 A list of matrices forming a basis for the space of all
388 Lyapunov-like transformations on the given cone.
392 The trivial cone has no Lyapunov-like transformations::
394 sage: L = ToricLattice(0)
395 sage: K = Cone([], lattice=L)
399 The Lyapunov-like transformations on the nonnegative orthant are
400 simply diagonal matrices::
402 sage: K = Cone([(1,)])
406 sage: K = Cone([(1,0),(0,1)])
413 sage: K = Cone([(1,0,0),(0,1,0),(0,0,1)])
416 [1 0 0] [0 0 0] [0 0 0]
417 [0 0 0] [0 1 0] [0 0 0]
418 [0 0 0], [0 0 0], [0 0 1]
421 Only the identity matrix is Lyapunov-like on the `L^{3}_{1}` and
422 `L^{3}_{\infty}` cones [Rudolf et al.]_::
424 sage: L31 = Cone([(1,0,1), (0,-1,1), (-1,0,1), (0,1,1)])
432 sage: L3infty = Cone([(0,1,1), (1,0,1), (0,-1,1), (-1,0,1)])
440 If our cone is the entire space, then every transformation on it is
443 sage: K = Cone([(1,0), (-1,0), (0,1), (0,-1)])
444 sage: M = MatrixSpace(QQ,2)
445 sage: M.basis() == LL(K)
450 The inner product `\left< L\left(x\right), s \right>` is zero for
451 every pair `\left( x,s \right)` in the discrete complementarity set
454 sage: set_random_seed()
455 sage: K = random_cone(max_dim=8)
456 sage: C_of_K = discrete_complementarity_set(K)
457 sage: l = [ (L*x).inner_product(s) for (x,s) in C_of_K for L in LL(K) ]
458 sage: sum(map(abs, l))
461 The Lyapunov-like transformations on a cone and its dual are related
462 by transposition, but we're not guaranteed to compute transposed
463 elements of `LL\left( K \right)` as our basis for `LL\left( K^{*}
466 sage: set_random_seed()
467 sage: K = random_cone(max_dim=8)
468 sage: LL2 = [ L.transpose() for L in LL(K.dual()) ]
469 sage: V = VectorSpace( K.lattice().base_field(), K.lattice_dim()^2)
470 sage: LL1_vecs = [ V(m.list()) for m in LL(K) ]
471 sage: LL2_vecs = [ V(m.list()) for m in LL2 ]
472 sage: V.span(LL1_vecs) == V.span(LL2_vecs)
476 V
= K
.lattice().vector_space()
478 C_of_K
= discrete_complementarity_set(K
)
480 tensor_products
= [ s
.tensor_product(x
) for (x
,s
) in C_of_K
]
482 # Sage doesn't think matrices are vectors, so we have to convert
483 # our matrices to vectors explicitly before we can figure out how
484 # many are linearly-indepenedent.
486 # The space W has the same base ring as V, but dimension
487 # dim(V)^2. So it has the same dimension as the space of linear
488 # transformations on V. In other words, it's just the right size
489 # to create an isomorphism between it and our matrices.
490 W
= VectorSpace(V
.base_ring(), V
.dimension()**2)
492 # Turn our matrices into long vectors...
493 vectors
= [ W(m
.list()) for m
in tensor_products
]
495 # Vector space representation of Lyapunov-like matrices
496 # (i.e. vec(L) where L is Luapunov-like).
497 LL_vector
= W
.span(vectors
).complement()
499 # Now construct an ambient MatrixSpace in which to stick our
501 M
= MatrixSpace(V
.base_ring(), V
.dimension())
503 matrix_basis
= [ M(v
.list()) for v
in LL_vector
.basis() ]
509 def lyapunov_rank(K
):
511 Compute the Lyapunov (or bilinearity) rank of this cone.
513 The Lyapunov rank of a cone can be thought of in (mainly) two ways:
515 1. The dimension of the Lie algebra of the automorphism group of the
518 2. The dimension of the linear space of all Lyapunov-like
519 transformations on the cone.
523 A closed, convex polyhedral cone.
527 An integer representing the Lyapunov rank of the cone. If the
528 dimension of the ambient vector space is `n`, then the Lyapunov rank
529 will be between `1` and `n` inclusive; however a rank of `n-1` is
530 not possible (see the first reference).
534 In the references, the cones are always assumed to be proper. We
535 do not impose this restriction.
543 The codimension formula from the second reference is used. We find
544 all pairs `(x,s)` in the complementarity set of `K` such that `x`
545 and `s` are rays of our cone. It is known that these vectors are
546 sufficient to apply the codimension formula. Once we have all such
547 pairs, we "brute force" the codimension formula by finding all
548 linearly-independent `xs^{T}`.
552 .. [Gowda/Tao] M.S. Gowda and J. Tao. On the bilinearity rank of a proper
553 cone and Lyapunov-like transformations, Mathematical Programming, 147
556 .. [Orlitzky/Gowda] M. Orlitzky and M. S. Gowda. The Lyapunov Rank of an
557 Improper Cone. Work in-progress.
559 .. [Rudolf et al.] G. Rudolf, N. Noyan, D. Papp, and F. Alizadeh, Bilinear
560 optimality constraints for the cone of positive polynomials,
561 Mathematical Programming, Series B, 129 (2011) 5-31.
565 The nonnegative orthant in `\mathbb{R}^{n}` always has rank `n`
568 sage: positives = Cone([(1,)])
569 sage: lyapunov_rank(positives)
571 sage: quadrant = Cone([(1,0), (0,1)])
572 sage: lyapunov_rank(quadrant)
574 sage: octant = Cone([(1,0,0), (0,1,0), (0,0,1)])
575 sage: lyapunov_rank(octant)
578 The full space `\mathbb{R}^{n}` has Lyapunov rank `n^{2}`
581 sage: R5 = VectorSpace(QQ, 5)
582 sage: gs = R5.basis() + [ -r for r in R5.basis() ]
584 sage: lyapunov_rank(K)
587 The `L^{3}_{1}` cone is known to have a Lyapunov rank of one
590 sage: L31 = Cone([(1,0,1), (0,-1,1), (-1,0,1), (0,1,1)])
591 sage: lyapunov_rank(L31)
594 Likewise for the `L^{3}_{\infty}` cone [Rudolf et al.]_::
596 sage: L3infty = Cone([(0,1,1), (1,0,1), (0,-1,1), (-1,0,1)])
597 sage: lyapunov_rank(L3infty)
600 A single ray in `n` dimensions should have Lyapunov rank `n^{2} - n
601 + 1` [Orlitzky/Gowda]_::
603 sage: K = Cone([(1,0,0,0,0)])
604 sage: lyapunov_rank(K)
606 sage: K.lattice_dim()**2 - K.lattice_dim() + 1
609 A subspace (of dimension `m`) in `n` dimensions should have a
610 Lyapunov rank of `n^{2} - m\left(n - m)` [Orlitzky/Gowda]_::
612 sage: e1 = (1,0,0,0,0)
613 sage: neg_e1 = (-1,0,0,0,0)
614 sage: e2 = (0,1,0,0,0)
615 sage: neg_e2 = (0,-1,0,0,0)
616 sage: z = (0,0,0,0,0)
617 sage: K = Cone([e1, neg_e1, e2, neg_e2, z, z, z])
618 sage: lyapunov_rank(K)
620 sage: K.lattice_dim()**2 - K.dim()*K.codim()
623 The Lyapunov rank should be additive on a product of proper cones
626 sage: L31 = Cone([(1,0,1), (0,-1,1), (-1,0,1), (0,1,1)])
627 sage: octant = Cone([(1,0,0), (0,1,0), (0,0,1)])
628 sage: K = L31.cartesian_product(octant)
629 sage: lyapunov_rank(K) == lyapunov_rank(L31) + lyapunov_rank(octant)
632 Two isomorphic cones should have the same Lyapunov rank [Rudolf et al.]_.
633 The cone ``K`` in the following example is isomorphic to the nonnegative
634 octant in `\mathbb{R}^{3}`::
636 sage: K = Cone([(1,2,3), (-1,1,0), (1,0,6)])
637 sage: lyapunov_rank(K)
640 The dual cone `K^{*}` of ``K`` should have the same Lyapunov rank as ``K``
641 itself [Rudolf et al.]_::
643 sage: K = Cone([(2,2,4), (-1,9,0), (2,0,6)])
644 sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
649 The Lyapunov rank should be additive on a product of proper cones
652 sage: set_random_seed()
653 sage: K1 = random_cone(max_dim=8, strictly_convex=True, solid=True)
654 sage: K2 = random_cone(max_dim=8, strictly_convex=True, solid=True)
655 sage: K = K1.cartesian_product(K2)
656 sage: lyapunov_rank(K) == lyapunov_rank(K1) + lyapunov_rank(K2)
659 The Lyapunov rank is invariant under a linear isomorphism
662 sage: K1 = random_cone(max_dim = 8)
663 sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular')
664 sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice())
665 sage: lyapunov_rank(K1) == lyapunov_rank(K2)
668 Just to be sure, test a few more::
670 sage: K1 = random_cone(max_dim=8, strictly_convex=True, solid=True)
671 sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular')
672 sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice())
673 sage: lyapunov_rank(K1) == lyapunov_rank(K2)
678 sage: K1 = random_cone(max_dim=8, strictly_convex=True, solid=False)
679 sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular')
680 sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice())
681 sage: lyapunov_rank(K1) == lyapunov_rank(K2)
686 sage: K1 = random_cone(max_dim=8, strictly_convex=False, solid=True)
687 sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular')
688 sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice())
689 sage: lyapunov_rank(K1) == lyapunov_rank(K2)
694 sage: K1 = random_cone(max_dim=8, strictly_convex=False, solid=False)
695 sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular')
696 sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice())
697 sage: lyapunov_rank(K1) == lyapunov_rank(K2)
700 The dual cone `K^{*}` of ``K`` should have the same Lyapunov rank as ``K``
701 itself [Rudolf et al.]_::
703 sage: set_random_seed()
704 sage: K = random_cone(max_dim=8)
705 sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
708 Make sure we exercise the non-strictly-convex/non-solid case::
710 sage: set_random_seed()
711 sage: K = random_cone(max_dim=8, strictly_convex=False, solid=False)
712 sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
715 Let's check the other permutations as well, just to be sure::
717 sage: set_random_seed()
718 sage: K = random_cone(max_dim=8, strictly_convex=False, solid=True)
719 sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
724 sage: set_random_seed()
725 sage: K = random_cone(max_dim=8, strictly_convex=True, solid=False)
726 sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
731 sage: set_random_seed()
732 sage: K = random_cone(max_dim=8, strictly_convex=True, solid=True)
733 sage: lyapunov_rank(K) == lyapunov_rank(K.dual())
736 The Lyapunov rank of a proper polyhedral cone in `n` dimensions can
737 be any number between `1` and `n` inclusive, excluding `n-1`
738 [Gowda/Tao]_. By accident, the `n-1` restriction will hold for the
739 trivial cone in a trivial space as well. However, in zero dimensions,
740 the Lyapunov rank of the trivial cone will be zero::
742 sage: set_random_seed()
743 sage: K = random_cone(max_dim=8, strictly_convex=True, solid=True)
744 sage: b = lyapunov_rank(K)
745 sage: n = K.lattice_dim()
746 sage: (n == 0 or 1 <= b) and b <= n
751 In fact [Orlitzky/Gowda]_, no closed convex polyhedral cone can have
752 Lyapunov rank `n-1` in `n` dimensions::
754 sage: set_random_seed()
755 sage: K = random_cone(max_dim=8)
756 sage: b = lyapunov_rank(K)
757 sage: n = K.lattice_dim()
761 The calculation of the Lyapunov rank of an improper cone can be
762 reduced to that of a proper cone [Orlitzky/Gowda]_::
764 sage: set_random_seed()
765 sage: K = random_cone(max_dim=8)
766 sage: actual = lyapunov_rank(K)
768 sage: K_SP = _rho(K_S.dual()).dual()
769 sage: l = K.lineality()
771 sage: expected = lyapunov_rank(K_SP) + K.dim()*(l + c) + c**2
772 sage: actual == expected
775 The Lyapunov rank of a proper cone is just the dimension of ``LL(K)``::
777 sage: set_random_seed()
778 sage: K = random_cone(max_dim=8, strictly_convex=True, solid=True)
779 sage: lyapunov_rank(K) == len(LL(K))
782 In fact the same can be said of any cone. These additional tests
783 just increase our confidence that the reduction scheme works::
785 sage: set_random_seed()
786 sage: K = random_cone(max_dim=8, strictly_convex=True, solid=False)
787 sage: lyapunov_rank(K) == len(LL(K))
792 sage: set_random_seed()
793 sage: K = random_cone(max_dim=8, strictly_convex=False, solid=True)
794 sage: lyapunov_rank(K) == len(LL(K))
799 sage: set_random_seed()
800 sage: K = random_cone(max_dim=8, strictly_convex=False, solid=False)
801 sage: lyapunov_rank(K) == len(LL(K))
804 Test Theorem 3 in [Orlitzky/Gowda]_::
806 sage: set_random_seed()
807 sage: K = random_cone(max_dim=8, strictly_convex=True, solid=True)
808 sage: L = ToricLattice(K.lattice_dim() + 1)
809 sage: K = Cone([ r.list() + [0] for r in K.rays() ], lattice=L)
810 sage: lyapunov_rank(K) >= K.lattice_dim()
821 # K is not solid, restrict to its span.
825 beta
+= m
*(n
- m
) + (n
- m
)**2
828 # K is not pointed, restrict to the span of its dual. Uses a
829 # proposition from our paper, i.e. this is equivalent to K =
830 # _rho(K.dual()).dual().
831 K
= _rho(K
, K
.dual())