X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Fcone%2Ftests.py;h=550beb38744f1d399f492aa5d3ef2f7fcc23febb;hb=805b61b3751065f9c7d36280ce22d961d207553c;hp=b9dc2e064d771de1eb9bb02184a5d4d1df8ea319;hpb=af3e2ce56ad6561c5c9b1b6cf3df22d690550618;p=sage.d.git diff --git a/mjo/cone/tests.py b/mjo/cone/tests.py index b9dc2e0..550beb3 100644 --- a/mjo/cone/tests.py +++ b/mjo/cone/tests.py @@ -15,24 +15,103 @@ from sage.all import * # The double-import is needed to get the underscore methods. from mjo.cone.cone import * -from mjo.cone.cone import _basically_the_same, _rho +from mjo.cone.cone import _restrict_to_space # -# Tests for _rho. +# Tests for _restrict_to_space. # +def _look_isomorphic(K1, K2): + r""" + Test whether or not ``K1`` and ``K2`` look linearly isomorphic. + + This is a hack to get around the fact that it's difficult to tell + when two cones are linearly isomorphic. Instead, we check a list of + properties that should be preserved under linear isomorphism. + + OUTPUT: + + ``True`` if ``K1`` and ``K2`` look isomorphic, or ``False`` + if we can prove that they are not isomorphic. + + EXAMPLES: + + Any proper cone with three generators in `\mathbb{R}^{3}` is + isomorphic to the nonnegative orthant:: + + sage: K1 = Cone([(1,0,0), (0,1,0), (0,0,1)]) + sage: K2 = Cone([(1,2,3), (3, 18, 4), (66, 51, 0)]) + sage: _look_isomorphic(K1, K2) + True + + Negating a cone gives you an isomorphic cone:: + + sage: K = Cone([(0,2,-5), (-6, 2, 4), (0, 51, 0)]) + sage: _look_isomorphic(K, -K) + True + + TESTS: + + Any cone is isomorphic to itself:: + + sage: K = random_cone(max_ambient_dim = 8) + sage: _look_isomorphic(K, K) + True + + After applying an invertible matrix to the rows of a cone, the + result should is isomorphic to the cone we started with:: + + sage: K1 = random_cone(max_ambient_dim = 8) + sage: A = random_matrix(QQ, K1.lattice_dim(), algorithm='unimodular') + sage: K2 = Cone( [ A*r for r in K1.rays() ], lattice=K1.lattice()) + sage: _look_isomorphic(K1, K2) + True + + """ + if K1.lattice_dim() != K2.lattice_dim(): + return False + + if K1.nrays() != K2.nrays(): + return False + + if K1.dim() != K2.dim(): + return False + + if K1.lineality() != K2.lineality(): + return False + + if K1.is_solid() != K2.is_solid(): + return False + + if K1.is_strictly_convex() != K2.is_strictly_convex(): + return False + + if len(K1.lyapunov_like_basis()) != len(K2.lyapunov_like_basis()): + return False + + C_of_K1 = K1.discrete_complementarity_set() + C_of_K2 = K2.discrete_complementarity_set() + if len(C_of_K1) != len(C_of_K2): + return False + + if len(K1.facets()) != len(K2.facets()): + return False + + return True + + """ -Apply _rho according to our paper (to obtain our main result). Test all -four parameter combinations:: +Apply _restrict_to_space according to our paper (to obtain our main +result). Test all four parameter combinations:: sage: set_random_seed() sage: K = random_cone(max_ambient_dim = 8, ....: strictly_convex=False, ....: solid=False) - sage: K_S = _rho(K) - sage: K_SP = _rho(K_S.dual()).dual() + sage: K_S = _restrict_to_space(K, K.span()) + sage: K_SP = _restrict_to_space(K_S.dual(), K_S.dual().span()).dual() sage: K_SP.is_proper() True - sage: K_SP = _rho(K_S, K_S.dual()) + sage: K_SP = _restrict_to_space(K_S, K_S.dual().span()) sage: K_SP.is_proper() True @@ -42,11 +121,11 @@ four parameter combinations:: sage: K = random_cone(max_ambient_dim = 8, ....: strictly_convex=True, ....: solid=False) - sage: K_S = _rho(K) - sage: K_SP = _rho(K_S.dual()).dual() + sage: K_S = _restrict_to_space(K, K.span()) + sage: K_SP = _restrict_to_space(K_S.dual(), K_S.dual().span()).dual() sage: K_SP.is_proper() True - sage: K_SP = _rho(K_S, K_S.dual()) + sage: K_SP = _restrict_to_space(K_S, K_S.dual().span()) sage: K_SP.is_proper() True @@ -56,11 +135,11 @@ four parameter combinations:: sage: K = random_cone(max_ambient_dim = 8, ....: strictly_convex=False, ....: solid=True) - sage: K_S = _rho(K) - sage: K_SP = _rho(K_S.dual()).dual() + sage: K_S = _restrict_to_space(K, K.span()) + sage: K_SP = _restrict_to_space(K_S.dual(), K_S.dual().span()).dual() sage: K_SP.is_proper() True - sage: K_SP = _rho(K_S, K_S.dual()) + sage: K_SP = _restrict_to_space(K_S, K_S.dual().span()) sage: K_SP.is_proper() True @@ -70,11 +149,11 @@ four parameter combinations:: sage: K = random_cone(max_ambient_dim = 8, ....: strictly_convex=True, ....: solid=True) - sage: K_S = _rho(K) - sage: K_SP = _rho(K_S.dual()).dual() + sage: K_S = _restrict_to_space(K, K.span()) + sage: K_SP = _restrict_to_space(K_S.dual(), K_S.dual().span()).dual() sage: K_SP.is_proper() True - sage: K_SP = _rho(K_S, K_S.dual()) + sage: K_SP = _restrict_to_space(K_S, K_S.dual().span()) sage: K_SP.is_proper() True @@ -89,9 +168,9 @@ all parameter combinations:: ....: solid=False, ....: strictly_convex=False) sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice()) - sage: K_W_star = _rho(K, J).dual() - sage: K_star_W = _rho(K.dual(), J) - sage: _basically_the_same(K_W_star, K_star_W) + sage: K_W_star = _restrict_to_space(K, J.span()).dual() + sage: K_star_W = _restrict_to_space(K.dual(), J.span()) + sage: _look_isomorphic(K_W_star, K_star_W) True :: @@ -101,9 +180,9 @@ all parameter combinations:: ....: solid=True, ....: strictly_convex=False) sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice()) - sage: K_W_star = _rho(K, J).dual() - sage: K_star_W = _rho(K.dual(), J) - sage: _basically_the_same(K_W_star, K_star_W) + sage: K_W_star = _restrict_to_space(K, J.span()).dual() + sage: K_star_W = _restrict_to_space(K.dual(), J.span()) + sage: _look_isomorphic(K_W_star, K_star_W) True :: @@ -113,9 +192,9 @@ all parameter combinations:: ....: solid=False, ....: strictly_convex=True) sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice()) - sage: K_W_star = _rho(K, J).dual() - sage: K_star_W = _rho(K.dual(), J) - sage: _basically_the_same(K_W_star, K_star_W) + sage: K_W_star = _restrict_to_space(K, J.span()).dual() + sage: K_star_W = _restrict_to_space(K.dual(), J.span()) + sage: _look_isomorphic(K_W_star, K_star_W) True :: @@ -125,9 +204,9 @@ all parameter combinations:: ....: solid=True, ....: strictly_convex=True) sage: K = Cone(random_sublist(J.rays(), 0.5), lattice=J.lattice()) - sage: K_W_star = _rho(K, J).dual() - sage: K_star_W = _rho(K.dual(), J) - sage: _basically_the_same(K_W_star, K_star_W) + sage: K_W_star = _restrict_to_space(K, J.span()).dual() + sage: K_star_W = _restrict_to_space(K.dual(), J.span()) + sage: _look_isomorphic(K_W_star, K_star_W) True """ @@ -216,14 +295,14 @@ cone. Check all combinations of parameters:: sage: lyapunov_rank(K) == lyapunov_rank(K.dual()) True -The Lyapunov rank of a cone ``K`` is the dimension of ``LL(K)``. Check -all combinations of parameters:: +The Lyapunov rank of a cone ``K`` is the dimension of +``K.lyapunov_like_basis()``. Check all combinations of parameters:: sage: set_random_seed() sage: K = random_cone(max_ambient_dim=8, ....: strictly_convex=True, ....: solid=True) - sage: lyapunov_rank(K) == len(LL(K)) + sage: lyapunov_rank(K) == len(K.lyapunov_like_basis()) True :: @@ -232,7 +311,7 @@ all combinations of parameters:: sage: K = random_cone(max_ambient_dim=8, ....: strictly_convex=True, ....: solid=False) - sage: lyapunov_rank(K) == len(LL(K)) + sage: lyapunov_rank(K) == len(K.lyapunov_like_basis()) True :: @@ -241,7 +320,7 @@ all combinations of parameters:: sage: K = random_cone(max_ambient_dim=8, ....: strictly_convex=False, ....: solid=True) - sage: lyapunov_rank(K) == len(LL(K)) + sage: lyapunov_rank(K) == len(K.lyapunov_like_basis()) True :: @@ -250,7 +329,7 @@ all combinations of parameters:: sage: K = random_cone(max_ambient_dim=8, ....: strictly_convex=False, ....: solid=False) - sage: lyapunov_rank(K) == len(LL(K)) + sage: lyapunov_rank(K) == len(K.lyapunov_like_basis()) True """