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

Commit

Permalink
fixed more doctests involving order
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Feb 24, 2020
1 parent b2b544e commit 6ca4267
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 52 deletions.
70 changes: 35 additions & 35 deletions src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ Construction::
Obtaining edges and ridges::
sage: C.edges()[:2]
((A vertex at (1, 1, 1, -1), A vertex at (1, 1, 1, 1)),
(A vertex at (1, 1, -1, 1), A vertex at (1, 1, 1, 1)))
((A vertex at (-1, -1, -1, 1), A vertex at (-1, -1, -1, -1)),
(A vertex at (-1, 1, -1, -1), A vertex at (-1, -1, -1, -1)))
sage: C.edges(names=False)[:2]
((14, 15), (13, 15))
((14, 15), (10, 15))
sage: C.ridges()[:2]
((An inequality (0, 0, 1, 0) x + 1 >= 0,
An inequality (0, 0, 0, 1) x + 1 >= 0),
(An inequality (0, 1, 0, 0) x + 1 >= 0,
An inequality (0, 0, 0, 1) x + 1 >= 0))
An inequality (0, 1, 0, 0) x + 1 >= 0),
(An inequality (0, 0, 0, 1) x + 1 >= 0,
An inequality (0, 1, 0, 0) x + 1 >= 0))
sage: C.ridges(names=False)[:2]
((6, 7), (5, 7))
Expand Down Expand Up @@ -817,37 +817,37 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: P = polytopes.cube()
sage: C = CombinatorialPolyhedron(P)
sage: C.facets()
((A vertex at (-1, -1, 1),
A vertex at (-1, 1, 1),
A vertex at (1, -1, 1),
A vertex at (1, 1, 1)),
(A vertex at (-1, 1, -1),
A vertex at (-1, 1, 1),
((A vertex at (1, -1, -1),
A vertex at (1, 1, -1),
A vertex at (1, 1, 1)),
(A vertex at (1, -1, -1),
A vertex at (1, 1, 1),
A vertex at (1, -1, 1)),
(A vertex at (1, 1, -1),
A vertex at (1, 1, 1),
A vertex at (-1, 1, -1),
A vertex at (-1, 1, 1)),
(A vertex at (1, 1, 1),
A vertex at (1, -1, 1),
A vertex at (1, 1, -1),
A vertex at (1, 1, 1)),
(A vertex at (-1, -1, -1),
A vertex at (-1, -1, 1),
A vertex at (-1, 1, -1),
A vertex at (-1, 1, 1)),
(A vertex at (-1, -1, -1),
(A vertex at (-1, -1, 1),
A vertex at (-1, -1, -1),
A vertex at (-1, 1, -1),
A vertex at (1, -1, -1),
A vertex at (1, 1, -1)),
(A vertex at (-1, -1, -1),
A vertex at (-1, 1, 1)),
(A vertex at (1, -1, -1),
A vertex at (1, 1, -1),
A vertex at (-1, -1, -1),
A vertex at (-1, 1, -1)),
(A vertex at (1, -1, -1),
A vertex at (1, -1, 1),
A vertex at (-1, -1, 1),
A vertex at (1, -1, -1),
A vertex at (1, -1, 1)))
A vertex at (-1, -1, -1)))
sage: C.facets(names=False)
((1, 3, 5, 7),
(2, 3, 6, 7),
((0, 1, 2, 3),
(1, 2, 6, 7),
(2, 3, 4, 7),
(4, 5, 6, 7),
(0, 1, 2, 3),
(0, 2, 4, 6),
(0, 1, 4, 5))
(0, 1, 5, 6),
(0, 3, 4, 5))
"""
if unlikely(self.dimension() == 0):
# Special attention for this trivial case.
Expand Down Expand Up @@ -889,14 +889,14 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: P = polytopes.cube()
sage: C = P.combinatorial_polyhedron()
sage: C.incidence_matrix()
[1 0 0 0 1 1]
[1 1 0 0 1 0]
[1 1 1 0 0 0]
[1 0 1 0 0 1]
[0 0 1 1 0 1]
[0 0 0 1 1 1]
[1 0 0 1 0 1]
[0 1 0 1 1 0]
[1 1 0 1 0 0]
[0 0 1 0 1 1]
[1 0 1 0 0 1]
[0 1 1 0 1 0]
[1 1 1 0 0 0]
[0 1 1 1 0 0]
sage: P.incidence_matrix() == C.incidence_matrix()
True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ cdef class FaceIterator(SageObject):
(1,),
(0,),
(3, 4),
(2, 4),
(1, 4),
(0, 4),
(1, 3, 4),
(1, 2, 4),
(0, 1, 4),
(2, 3),
(1, 3),
(0, 3),
(0, 1, 3),
(1, 2, 3),
(1, 2),
(0, 2),
(0, 1, 2),
Expand Down Expand Up @@ -294,22 +294,22 @@ cdef class FaceIterator(SageObject):
(1,),
(0,),
(6, 7),
(5, 7),
(3, 7),
(4, 7),
(2, 7),
(4, 5, 6, 7),
(2, 3, 6, 7),
(1, 3, 5, 7),
(4, 6),
(2, 6),
(0, 2, 4, 6),
(1, 2, 6, 7),
(2, 3, 4, 7),
(5, 6),
(1, 6),
(0, 1, 5, 6),
(4, 5),
(1, 5),
(0, 1, 4, 5),
(0, 4),
(0, 5),
(0, 3, 4, 5),
(3, 4),
(2, 3),
(1, 3),
(0, 3),
(0, 1, 2, 3),
(0, 2),
(1, 2),
(0, 1)]
sage: it = C.face_iter(dual=False)
Expand Down
30 changes: 29 additions & 1 deletion src/sage/geometry/polyhedron/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -2807,8 +2807,29 @@ def hypercube(self, dim, intervals=None, backend=None):
Traceback (most recent call last):
...
ValueError: the only allowed string is 'zero_one'
Check that we set up the hypercube correctly::
sage: ls = [randint(-100,100) for _ in range(4)]
sage: intervals = [[x, x+randint(1,50)] for x in ls]
sage: ls = [randint(-100,100) for _ in range(4)]
sage: intervals = [[x, x+randint(1,50)] for x in ls]
sage: P = polytopes.hypercube(4, intervals, backend='field')
sage: P1 = polytopes.hypercube(4, intervals, backend='ppl')
sage: assert P == P1
Check that coercion for input invervals is handled correctly::
sage: P = polytopes.hypercube(2, [[1/2, 2], [0, 1]])
sage: P = polytopes.hypercube(2, [[1/2, 2], [0, 1.0]])
sage: P = polytopes.hypercube(2, [[1/2, 2], [0, AA(2).sqrt()]])
sage: P = polytopes.hypercube(2, [[1/2, 2], [0, 1.0]], backend='ppl')
Traceback (most recent call last):
...
ValueError: specified backend ppl cannot handle the intervals
"""
parent = Polyhedra(ZZ, dim, backend=backend)
convert = False

# Preparing the inequalities:
# If the intervals are (a_1,b_1), ..., (a_dim, b_dim),
Expand Down Expand Up @@ -2836,14 +2857,21 @@ def hypercube(self, dim, intervals=None, backend=None):
if not all(a < b for a,b in intervals):
raise ValueError("each interval must be a pair `(a, b)` with `a < b`")
parent = parent.base_extend(sum(a + b for a,b in intervals))
if parent.base_ring() not in (ZZ, QQ):
convert = True
if backend and parent.backend() is not backend:
# If the parent changed backends, but a backend was specified,
# the specified backend cannot handle the intervals.
raise ValueError("specified backend {} cannot handle the intervals".format(backend))

cp = list(itertools.product(*intervals))
for i in range(dim):
ieqs[i][0] = intervals[i][1] # An inequality -x_i + b_i >= 0
ieqs[i+dim][0] = -intervals[i][0] # An inequality x_i - a_i >= 0

else:
raise ValueError("the dimension of the hypercube must match the number of intervals")
return parent.element_class(parent, [cp, [], []], [ieqs, []], Vrep_minimal=True, Hrep_minimal=True )
return parent([cp, [], []], [ieqs, []], convert=convert, Vrep_minimal=True, Hrep_minimal=True )

def cube(self, intervals=None, backend=None):
r"""
Expand Down

0 comments on commit 6ca4267

Please sign in to comment.