From 08ff39a270e90e6263339da12144ddd2bfc6f3f5 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 19 May 2015 15:09:02 -0400 Subject: [PATCH] Factor out the is_full_space() function. --- mjo/cone/cone.py | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/mjo/cone/cone.py b/mjo/cone/cone.py index 3b724a7..424a907 100644 --- a/mjo/cone/cone.py +++ b/mjo/cone/cone.py @@ -8,6 +8,47 @@ addsitedir(abspath('../../')) from sage.all import * +def is_full_space(K): + r""" + Return whether or not this cone is equal to its ambient vector space. + + OUTPUT: + + ``True`` if this cone is the entire vector space and ``False`` + otherwise. + + EXAMPLES: + + A ray in two dimensions is not equal to the entire space:: + + sage: K = Cone([(1,0)]) + sage: is_full_space(K) + False + + Neither is the nonnegative orthant:: + + sage: K = Cone([(1,0),(0,1)]) + sage: is_full_space(K) + False + + The right half-space contains a vector subspace, but it is still not + equal to the entire plane:: + + sage: K = Cone([(1,0),(-1,0),(0,1)]) + sage: is_full_space(K) + False + + But if we include nonnegative sums from both axes, then the resulting + cone is the entire two-dimensional space:: + + sage: K = Cone([(1,0),(-1,0),(0,1),(0,-1)]) + sage: is_full_space(K) + True + + """ + return K.linear_subspace() == K.lattice().vector_space() + + def random_cone(min_dim=0, max_dim=None, min_rays=0, max_rays=None): r""" Generate a random rational convex polyhedral cone. @@ -162,12 +203,6 @@ def random_cone(min_dim=0, max_dim=None, min_rays=0, max_rays=None): # ZZ.random_element() docs. return l + ZZ.random_element(u - l + 1) - def is_full_space(K): - r""" - Is this cone equivalent to the full ambient vector space? - """ - return K.lines().dim() == K.lattice_dim() - d = random_min_max(min_dim, max_dim) r = random_min_max(min_rays, max_rays) -- 2.44.2