Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
{LatticePolytopeClass, ConvexRationalPolyhedralCone._some_elements_: New
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Jun 21, 2021
1 parent e144389 commit bc26d4f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/sage/geometry/cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,27 @@ def _repr_(self):
result += " face of %s" % self.ambient()
return result

def _some_elements_(self):
r"""
Generate some points of ``self``.
EXAMPLE::
sage: K = cones.nonnegative_orthant(3)
sage: K.some_elements() # indirect doctest
[(0, 0, 0), (1/2, 0, 0), (1/4, 1/2, 0), (1/8, 1/4, 1/2)]
"""
V = self.ambient_vector_space()
r_iter = iter(self._rays)
p = V(0)
yield p
for i in range(5):
try:
p = (p + next(r_iter)) / 2
except StopIteration:
return
yield p

def _sort_faces(self, faces):
r"""
Return sorted (if necessary) ``faces`` as a tuple.
Expand Down
30 changes: 30 additions & 0 deletions src/sage/geometry/lattice_polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -3794,6 +3794,36 @@ def points(self, *args, **kwds):
else:
return self._points

def _some_elements_(self):
r"""
Generate some points of ``self`` as a convex polytope.
In contrast to :meth:`points`, these are not necessarily lattice points.
EXAMPLE::
sage: o = lattice_polytope.cross_polytope(3)
sage: o.some_elements() # indirect doctest
[(1, 0, 0),
(1/2, 1/2, 0),
(1/4, 1/4, 1/2),
(-3/8, 1/8, 1/4),
(-3/16, -7/16, 1/8),
(-3/32, -7/32, -7/16)]
"""
if not self._vertices:
return
V = self.ambient_vector_space()
v_iter = iter(self._vertices)
p = V(next(v_iter))
yield p
for i in range(5):
try:
p = (p + next(v_iter)) / 2
except StopIteration:
return
yield p

def polar(self):
r"""
Return the polar polytope, if this polytope is reflexive.
Expand Down

0 comments on commit bc26d4f

Please sign in to comment.