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

Commit

Permalink
fixed doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Feb 24, 2020
1 parent f9958f3 commit b2b544e
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 71 deletions.
92 changes: 49 additions & 43 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ def Hrepresentation(self, index=None):
sage: p = polytopes.hypercube(3)
sage: p.Hrepresentation(0)
An inequality (0, 0, -1) x + 1 >= 0
An inequality (-1, 0, 0) x + 1 >= 0
sage: p.Hrepresentation(0) == p.Hrepresentation() [0]
True
"""
Expand Down Expand Up @@ -1522,7 +1522,7 @@ def Hrepresentation_str(self, separator='\n', latex=False, style='>=', align=Non
sage: c = polytopes.cube()
sage: c.Hrepresentation_str(separator=', ', style='positive')
'1 >= x2, 1 >= x1, 1 >= x0, x0 + 1 >= 0, x2 + 1 >= 0, x1 + 1 >= 0'
'1 >= x0, 1 >= x1, 1 >= x2, x0 + 1 >= 0, x2 + 1 >= 0, x1 + 1 >= 0'
"""
pretty_hs = [h.repr_pretty(split=True, latex=latex, style=style, **kwds) for h in self.Hrepresentation()]
shift = any(pretty_h[2].startswith('-') for pretty_h in pretty_hs)
Expand Down Expand Up @@ -1574,7 +1574,7 @@ def Hrep_generator(self):
sage: p = polytopes.hypercube(3)
sage: next(p.Hrep_generator())
An inequality (0, 0, -1) x + 1 >= 0
An inequality (-1, 0, 0) x + 1 >= 0
"""
for H in self.Hrepresentation():
yield H
Expand Down Expand Up @@ -3246,14 +3246,14 @@ def is_prism(self, certificate=False):
True
sage: P.is_prism(certificate=True)
(True,
[[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: Q = polytopes.cyclic_polytope(3,8)
sage: Q.is_prism()
False
Expand Down Expand Up @@ -3653,13 +3653,15 @@ def triangulate(self, engine='auto', connected=True, fine=False, regular=None, s
sage: triangulation = cube.triangulate(
....: engine='internal') # to make doctest independent of TOPCOM
sage: triangulation
(<0,1,2,7>, <0,1,4,7>, <0,2,4,7>, <1,2,3,7>, <1,4,5,7>, <2,4,6,7>)
(<0,1,2,7>, <0,1,5,7>, <0,2,3,7>, <0,3,4,7>, <0,4,5,7>, <1,5,6,7>)
sage: simplex_indices = triangulation[0]; simplex_indices
(0, 1, 2, 7)
sage: simplex_vertices = [ cube.Vrepresentation(i) for i in simplex_indices ]
sage: simplex_vertices
[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: Polyhedron(simplex_vertices)
A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 4 vertices
Expand Down Expand Up @@ -4773,13 +4775,13 @@ def face_truncation(self, face, linear_coefficients=None, cut_frac=None):
sage: edge_trunc.f_vector()
(1, 10, 15, 7, 1)
sage: tuple(f.ambient_V_indices() for f in edge_trunc.faces(2))
((0, 4, 5, 6),
(0, 1, 6, 7),
(5, 6, 7, 8, 9),
(3, 4, 5, 9),
(1, 2, 7, 8),
(2, 3, 8, 9),
(0, 1, 2, 3, 4))
((0, 5, 6, 7),
(1, 4, 5, 6, 8),
(6, 7, 8, 9),
(0, 2, 3, 7, 9),
(1, 2, 8, 9),
(0, 3, 4, 5),
(1, 2, 3, 4))
sage: face_trunc = Cube.face_truncation(Cube.faces(2)[2])
sage: face_trunc.vertices()
(A vertex at (1, -1, -1),
Expand Down Expand Up @@ -5753,23 +5755,27 @@ def faces(self, face_dimension):
sage: p = polytopes.hypercube(4)
sage: list(f.ambient_V_indices() for f in p.faces(3))
[(0, 2, 4, 6, 8, 10, 12, 14),
(0, 1, 4, 5, 8, 9, 12, 13),
(0, 1, 2, 3, 8, 9, 10, 11),
(0, 1, 2, 3, 4, 5, 6, 7),
(1, 3, 5, 7, 9, 11, 13, 15),
(2, 3, 6, 7, 10, 11, 14, 15),
(4, 5, 6, 7, 12, 13, 14, 15),
(8, 9, 10, 11, 12, 13, 14, 15)]
[(0, 5, 6, 7, 8, 9, 14, 15),
(1, 4, 5, 6, 10, 13, 14, 15),
(1, 2, 6, 7, 8, 10, 11, 15),
(8, 9, 10, 11, 12, 13, 14, 15),
(0, 3, 4, 5, 9, 12, 13, 14),
(0, 2, 3, 7, 8, 9, 11, 12),
(1, 2, 3, 4, 10, 11, 12, 13),
(0, 1, 2, 3, 4, 5, 6, 7)]
sage: face = p.faces(3)[3]
sage: face.ambient_Hrepresentation()
(An inequality (1, 0, 0, 0) x + 1 >= 0,)
sage: face.vertices()
(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))
(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))
You can use the
:meth:`~sage.geometry.polyhedron.representation.PolyhedronRepresentation.index`
Expand All @@ -5779,19 +5785,19 @@ def faces(self, face_dimension):
sage: [get_idx(_) for _ in face.ambient_Hrepresentation()]
[4]
sage: [get_idx(_) for _ in face.ambient_Vrepresentation()]
[0, 1, 2, 3, 4, 5, 6, 7]
[8, 9, 10, 11, 12, 13, 14, 15]
sage: [ ([get_idx(_) for _ in face.ambient_Vrepresentation()],
....: [get_idx(_) for _ in face.ambient_Hrepresentation()])
....: for face in p.faces(3) ]
[([0, 2, 4, 6, 8, 10, 12, 14], [7]),
([0, 1, 4, 5, 8, 9, 12, 13], [6]),
([0, 1, 2, 3, 8, 9, 10, 11], [5]),
([0, 1, 2, 3, 4, 5, 6, 7], [4]),
([1, 3, 5, 7, 9, 11, 13, 15], [3]),
([2, 3, 6, 7, 10, 11, 14, 15], [2]),
([4, 5, 6, 7, 12, 13, 14, 15], [1]),
([8, 9, 10, 11, 12, 13, 14, 15], [0])]
[([0, 5, 6, 7, 8, 9, 14, 15], [7]),
([1, 4, 5, 6, 10, 13, 14, 15], [6]),
([1, 2, 6, 7, 8, 10, 11, 15], [5]),
([8, 9, 10, 11, 12, 13, 14, 15], [4]),
([0, 3, 4, 5, 9, 12, 13, 14], [3]),
([0, 2, 3, 7, 8, 9, 11, 12], [2]),
([1, 2, 3, 4, 10, 11, 12, 13], [1]),
([0, 1, 2, 3, 4, 5, 6, 7], [0])]
TESTS::
Expand Down Expand Up @@ -6262,7 +6268,7 @@ def one_point_suspension(self, vertex):
It works with a polyhedral face as well::
sage: vv = cube.faces(0)[0]
sage: vv = cube.faces(0)[1]
sage: ops_cube2 = cube.one_point_suspension(vv)
sage: ops_cube == ops_cube2
True
Expand Down Expand Up @@ -6438,7 +6444,7 @@ def schlegel_projection(self, projection_dir=None, height=1.1):
sage: schlegel_edge_indices = sch_proj.lines
sage: schlegel_edges = [sch_proj.coordinates_of(x) for x in schlegel_edge_indices]
sage: len([x for x in schlegel_edges if x[0][0] > 0])
4
5
"""
proj = self.projection()
if projection_dir is None:
Expand Down
10 changes: 5 additions & 5 deletions src/sage/geometry/polyhedron/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,12 @@ def ambient_V_indices(self):
sage: P = polytopes.cube()
sage: F = P.faces(2)
sage: [f.ambient_V_indices() for f in F]
[(0, 1, 4, 5),
(0, 2, 4, 6),
(0, 1, 2, 3),
[(0, 3, 4, 5),
(0, 1, 5, 6),
(4, 5, 6, 7),
(2, 3, 6, 7),
(1, 3, 5, 7)]
(2, 3, 4, 7),
(1, 2, 6, 7),
(0, 1, 2, 3)]
"""
return self._ambient_Vrepresentation_indices

Expand Down
20 changes: 10 additions & 10 deletions src/sage/geometry/polyhedron/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -2760,7 +2760,7 @@ def hypercube(self, dim, intervals=None, backend=None):
sage: z_cube = polytopes.hypercube(4,intervals = 'zero_one')
sage: z_cube.vertices()[0]
A vertex at (0, 0, 0, 0)
A vertex at (1, 0, 1, 1)
sage: z_cube.is_simple()
True
sage: z_cube.base_ring()
Expand Down Expand Up @@ -2835,7 +2835,7 @@ def hypercube(self, dim, intervals=None, backend=None):
elif len(intervals) == dim:
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(intervals)
parent = parent.base_extend(sum(a + b for a,b in intervals))
cp = list(itertools.product(*intervals))
for i in range(dim):
ieqs[i][0] = intervals[i][1] # An inequality -x_i + b_i >= 0
Expand Down Expand Up @@ -2894,14 +2894,14 @@ def cube(self, intervals=None, backend=None):
sage: cc = polytopes.cube(intervals ='zero_one')
sage: cc.vertices_list()
[[0, 0, 0],
[0, 0, 1],
[0, 1, 0],
[0, 1, 1],
[1, 0, 0],
[1, 0, 1],
[1, 1, 0],
[1, 1, 1]]
[[1, 0, 0],
[1, 1, 0],
[1, 1, 1],
[1, 0, 1],
[0, 0, 1],
[0, 0, 0],
[0, 1, 0],
[0, 1, 1]]
"""
return self.hypercube(3, backend=backend, intervals=intervals)

Expand Down
8 changes: 4 additions & 4 deletions src/sage/geometry/polyhedron/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ProjectionFuncStereographic():
sage: cube = polytopes.hypercube(3).vertices()
sage: proj = ProjectionFuncStereographic([1.2, 3.4, 5.6])
sage: ppoints = [proj(vector(x)) for x in cube]
sage: ppoints[0]
sage: ppoints[5]
(-0.0486511..., 0.0859565...)
"""
def __init__(self, projection_point):
Expand Down Expand Up @@ -500,7 +500,7 @@ def coord_index_of(self, v):
sage: p = polytopes.hypercube(3)
sage: proj = p.projection()
sage: proj.coord_index_of(vector((1,1,1)))
7
2
"""
try:
return self.coords.index(v)
Expand All @@ -518,7 +518,7 @@ def coord_indices_of(self, v_list):
sage: p = polytopes.hypercube(3)
sage: proj = p.projection()
sage: proj.coord_indices_of([vector((1,1,1)),vector((1,-1,1))])
[7, 5]
[2, 3]
"""
return [self.coord_index_of(v) for v in v_list]

Expand Down Expand Up @@ -928,7 +928,7 @@ def render_wireframe_3d(self, **kwds):
sage: cube_proj = cube.projection()
sage: wire = cube_proj.render_wireframe_3d()
sage: print(wire.tachyon().split('\n')[77]) # for testing
FCylinder base -1.0 1.0 -1.0 apex -1.0 -1.0 -1.0 rad 0.005 texture...
FCylinder base 1.0 1.0 -1.0 apex 1.0 1.0 1.0 rad 0.005 texture...
"""
wireframe = []
for l in self.lines:
Expand Down
18 changes: 9 additions & 9 deletions src/sage/geometry/polyhedron/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def vector(self, base_ring=None):
sage: C = polytopes.cube()
sage: C.vertices()[0].vector()[0] = 3
sage: C.vertices()[0]
A vertex at (-1, -1, -1)
A vertex at (1, -1, -1)
"""
if (base_ring is None) or (base_ring is self._base_ring):
return copy(self._vector)
Expand Down Expand Up @@ -429,7 +429,7 @@ def A(self):
sage: C = polytopes.cube()
sage: C.inequalities()[0].A()[2] = 5
sage: C.inequalities()[0]
An inequality (0, 0, -1) x + 1 >= 0
An inequality (-1, 0, 0) x + 1 >= 0
"""
return copy(self._A)

Expand Down Expand Up @@ -1105,12 +1105,12 @@ def is_incident(self, Hobj):
sage: p = polytopes.hypercube(3)
sage: h1 = next(p.inequality_generator())
sage: h1
An inequality (0, 0, -1) x + 1 >= 0
An inequality (-1, 0, 0) x + 1 >= 0
sage: v1 = next(p.vertex_generator())
sage: v1
A vertex at (-1, -1, -1)
A vertex at (1, -1, -1)
sage: v1.is_incident(h1)
False
True
"""
return self.polyhedron().incidence_matrix()[self.index(), Hobj.index()] == 1

Expand All @@ -1124,7 +1124,7 @@ def __mul__(self, Hobj):
sage: h1 = next(p.inequality_generator())
sage: v1 = next(p.vertex_generator())
sage: v1.__mul__(h1)
2
0
"""
return self.evaluated_on(Hobj)

Expand Down Expand Up @@ -1252,11 +1252,11 @@ def evaluated_on(self, Hobj):
sage: v = next(p.vertex_generator())
sage: h = next(p.inequality_generator())
sage: v
A vertex at (-1, -1, -1)
A vertex at (1, -1, -1)
sage: h
An inequality (0, 0, -1) x + 1 >= 0
An inequality (-1, 0, 0) x + 1 >= 0
sage: v.evaluated_on(h)
2
0
"""
return Hobj.A() * self.vector() + Hobj.b()

Expand Down

0 comments on commit b2b544e

Please sign in to comment.