From f9d0571d553891281fd31949871e27e1f973a281 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 20 Sep 2015 15:44:57 -0400 Subject: [PATCH] Add the has_rearrangement_property() function for vectors. --- mjo/cone/rearrangement.py | 48 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/mjo/cone/rearrangement.py b/mjo/cone/rearrangement.py index 5da9b28..2cde638 100644 --- a/mjo/cone/rearrangement.py +++ b/mjo/cone/rearrangement.py @@ -6,7 +6,7 @@ from site import addsitedir addsitedir(abspath('../../')) from sage.all import * -from mjo.cone.cone import lyapunov_rank +from mjo.cone.cone import lyapunov_rank, random_element def rearrangement_cone(p,n): r""" @@ -94,3 +94,49 @@ def rearrangement_cone(p,n): V = VectorSpace(QQ, n) G = V.basis() + [ d(j) for j in range(n) ] return Cone(G) + + +def has_rearrangement_property(v, p): + r""" + Test if the vector ``v`` has the "rearrangement property." + + The rearrangement cone of order ``p`` in `n` dimensions has its + members vectors of length `n`. The "rearrangement property," + satisfied by its elements, is to have its smallest ``p`` components + sum to a nonnegative number. + + We believe that we have a description of the extreme vectors of the + rearrangement cone: see ``rearrangement_cone()``. This function is + used to test that conic combinations of those extreme vectors are in + fact elements of the rearrangement cone. We can't test all conic + combinations, obviously, but we can test a random one. + + To become more sure of the result, generate a bunch of vectors with + ``random_element()`` and test them with this function. + + INPUT: + + - ``v`` -- An element of a cone suspected of being the rearrangement + cone of order ``p``. + + - ``p`` -- The suspected order of the rearrangement cone. + + OUTPUT: + + If ``v`` has the rearrangement property (that is, if its smallest ``p`` + components sum to a nonnegative number), ``True`` is returned. Otherwise + ``False`` is returned. + + EXAMPLES: + + Every element of a rearrangement cone should have the property:: + + sage: for n in range(2,10): + ....: for p in range(1, n-1): + ....: K = rearrangement_cone(p,n) + ....: v = random_element(K) + ....: if not has_rearrangement_property(v,p): print v + + """ + components = sorted(v)[0:p] + return sum(components) >= 0 -- 2.44.2