Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 5095c2e

Browse files
author
Jonathan Kliem
committed
fix neighbors of Hrepresentatives
1 parent bdf4b23 commit 5095c2e

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

src/sage/geometry/polyhedron/base.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,14 +3060,14 @@ def normal_fan(self, direction='inner'):
30603060
r"""
30613061
Return the normal fan of a compact full-dimensional rational polyhedron.
30623062
3063-
This returns the inner normal fan of ``self``. For the outer normal fan,
3063+
This returns the inner normal fan of ``self``. For the outer normal fan,
30643064
use ``direction='outer'``.
30653065
30663066
INPUT:
30673067
3068-
- ``direction`` -- either ``'inner'`` (default) or ``'outer'``; if
3069-
set to ``'inner'``, use the inner normal vectors to span the cones of
3070-
the fan, if set to ``'outer'``, use the outer normal vectors.
3068+
- ``direction`` -- either ``'inner'`` (default) or ``'outer'``; if
3069+
set to ``'inner'``, use the inner normal vectors to span the cones of
3070+
the fan, if set to ``'outer'``, use the outer normal vectors.
30713071
30723072
OUTPUT:
30733073
@@ -4388,6 +4388,21 @@ def stack(self, face, position=None):
43884388
...
43894389
ValueError: the chosen position is too large
43904390
4391+
sage: s = polytopes.simplex(7)
4392+
sage: f = s.faces(3)[0]
4393+
sage: sf = s.stack(f); sf
4394+
A 7-dimensional polyhedron in QQ^8 defined as the convex hull of 9 vertices
4395+
sage: sf.vertices()
4396+
(A vertex at (-4, -4, -4, -4, 17/4, 17/4, 17/4, 17/4),
4397+
A vertex at (0, 0, 0, 0, 0, 0, 0, 1),
4398+
A vertex at (0, 0, 0, 0, 0, 0, 1, 0),
4399+
A vertex at (0, 0, 0, 0, 0, 1, 0, 0),
4400+
A vertex at (0, 0, 0, 0, 1, 0, 0, 0),
4401+
A vertex at (0, 0, 0, 1, 0, 0, 0, 0),
4402+
A vertex at (0, 0, 1, 0, 0, 0, 0, 0),
4403+
A vertex at (0, 1, 0, 0, 0, 0, 0, 0),
4404+
A vertex at (1, 0, 0, 0, 0, 0, 0, 0))
4405+
43914406
It is possible to stack on unbounded faces::
43924407
43934408
sage: Q = Polyhedron(vertices=[[0,1],[1,0]],rays=[[1,1]])
@@ -4430,9 +4445,9 @@ def stack(self, face, position=None):
44304445

44314446
# Taking all facets that contain the face
44324447
if face.dim() == self.dim() - 1:
4433-
face_star = set([face.ambient_Hrepresentation()[0]])
4448+
face_star = set([face.ambient_Hrepresentation()[-1]])
44344449
else:
4435-
face_star = set(facet for facet in self.Hrepresentation()
4450+
face_star = set(facet for facet in self.Hrepresentation() if facet.is_inequality()
44364451
if all(facet.contains(x) and not facet.interior_contains(x) for x in face_vertices))
44374452

44384453
neighboring_facets = set()

src/sage/geometry/polyhedron/representation.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ def neighbors(self):
449449
"""
450450
Iterate over the adjacent facets (i.e. inequalities/equations)
451451
452+
Only defined for inequalities.
453+
452454
EXAMPLES::
453455
454456
sage: p = Polyhedron(ieqs = [[0,0,0,1],[0,0,1,0,],[0,1,0,0],
@@ -459,11 +461,35 @@ def neighbors(self):
459461
An inequality (0, -1, 0) x + 1 >= 0
460462
sage: list(a[0])
461463
[1, 0, -1, 0]
464+
465+
TESTS:
466+
467+
Checking that it works for polyhedra with equations::
468+
469+
sage: P = polytopes.simplex()
470+
sage: F1 = P.Hrepresentation()[1]
471+
sage: list(F1.neighbors())
472+
[An inequality (0, 1, 0, 0) x + 0 >= 0,
473+
An inequality (0, 0, 1, 0) x + 0 >= 0,
474+
An inequality (0, 0, 0, 1) x + 0 >= 0]
475+
476+
Does not work for inequalities::
477+
478+
sage: F0 = P.Hrepresentation()[0]
479+
sage: list(F0.neighbors())
480+
Traceback (most recent call last):
481+
...
482+
AssertionError: must be inequality
462483
"""
484+
# The adjacency matrix does not include equations.
485+
n_eqs = self.polyhedron().n_equations()
486+
assert self.is_inequality(), "must be inequality"
487+
463488
adjacency_matrix = self.polyhedron().facet_adjacency_matrix()
464489
for x in self.polyhedron().Hrep_generator():
465-
if adjacency_matrix[self.index(), x.index()] == 1:
466-
yield x
490+
if not x.is_equation():
491+
if adjacency_matrix[self.index()-n_eqs, x.index()-n_eqs] == 1:
492+
yield x
467493

468494
def adjacent(self):
469495
"""
@@ -777,9 +803,9 @@ def outer_normal(self):
777803
Return the outer normal vector of ``self``.
778804
779805
OUTPUT:
780-
806+
781807
The normal vector directed away from the interior of the polyhedron.
782-
808+
783809
EXAMPLES::
784810
785811
sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]])

0 commit comments

Comments
 (0)