]> gitweb.michael.orlitzky.com - sage.d.git/blob - mjo/cone/nonnegative_orthant.py
mjo/cone: add the nonnegative_orthant module.
[sage.d.git] / mjo / cone / nonnegative_orthant.py
1 """
2 The nonnegative orthant in `\mathbb{Z}^{n}`. I'm sick and tired of
3 typing it.
4 """
5
6 from sage.all import *
7
8 def nonnegative_orthant(n):
9 r"""
10 The nonnegative orthant in ``n`` dimensions.
11
12 INPUT:
13
14 - ``n`` -- the dimension of the ambient space.
15
16 OUTPUT:
17
18 The convex cone having ``n`` standard basis vectors as its
19 generators. Each generating ray will have the integer ring as its
20 base ring.
21
22 SETUP::
23
24 sage: from mjo.cone.nonnegative_orthant import nonnegative_orthant
25
26 EXAMPLES::
27
28 sage: nonnegative_orthant(3).rays()
29 N(1, 0, 0),
30 N(0, 1, 0),
31 N(0, 0, 1)
32 in 3-d lattice N
33
34 TESTS:
35
36 We can construct the trivial cone as the nonnegative orthant in a
37 trivial vector space::
38
39 sage: nonnegative_orthant(0)
40 0-d cone in 0-d lattice N
41
42 The nonnegative orthant is a proper cone::
43
44 sage: set_random_seed()
45 sage: n = ZZ.random_element(10)
46 sage: K = nonnegative_orthant(n)
47 sage: K.is_proper()
48 True
49
50 """
51 I = identity_matrix(ZZ,n)
52 lattice = ToricLattice(n)
53 return Cone(I.rows(), lattice)