X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Fcone%2Fnonnegative_orthant.py;h=8c6f5b5686e234ad8a549fbac98f11a8c80ddb22;hb=f38e111cd026f1ecdab6dd2d2ed194a8745252a8;hp=c1163302b737b507db66cf344a644372e509227c;hpb=785d079a2f5faa5126685aea96d584c3fa9c3007;p=sage.d.git diff --git a/mjo/cone/nonnegative_orthant.py b/mjo/cone/nonnegative_orthant.py index c116330..8c6f5b5 100644 --- a/mjo/cone/nonnegative_orthant.py +++ b/mjo/cone/nonnegative_orthant.py @@ -1,11 +1,11 @@ -""" +r""" The nonnegative orthant in `\mathbb{Z}^{n}`. I'm sick and tired of typing it. """ from sage.all import * -def nonnegative_orthant(n): +def nonnegative_orthant(n, lattice=None): r""" The nonnegative orthant in ``n`` dimensions. @@ -13,12 +13,19 @@ def nonnegative_orthant(n): - ``n`` -- the dimension of the ambient space. + - ``lattice`` -- (default: ``None``) an ambient lattice of rank ``n`` + to be passed to the :func:`Cone` constructor. + OUTPUT: The convex cone having ``n`` standard basis vectors as its generators. Each generating ray will have the integer ring as its base ring. + If a ``lattice`` was specified, then the resulting cone will live in + that lattice unless its rank is incompatible with the dimension + ``n`` (in which case a ``ValueError`` is raised). + SETUP:: sage: from mjo.cone.nonnegative_orthant import nonnegative_orthant @@ -47,7 +54,28 @@ def nonnegative_orthant(n): sage: K.is_proper() True + If a ``lattice`` was given, it is actually used:: + + sage: L = ToricLattice(3, 'M') + sage: nonnegative_orthant(3, lattice=L) + 3-d cone in 3-d lattice M + + Unless the rank of the lattice disagrees with ``n``:: + + sage: L = ToricLattice(1, 'M') + sage: nonnegative_orthant(3, lattice=L) + Traceback (most recent call last): + ... + ValueError: lattice rank=1 and dimension n=3 are incompatible + """ + if lattice is None: + lattice = ToricLattice(n) + + if lattice.rank() != n: + raise ValueError('lattice rank=%d and dimension n=%d are incompatible' + % + (lattice.rank(), n)) + I = identity_matrix(ZZ,n) - lattice = ToricLattice(n) return Cone(I.rows(), lattice)