# Ticket #11763: trac_11763_remove_trailing_whitespace.patch

File trac_11763_remove_trailing_whitespace.patch, 54.7 KB (added by vbraun, 7 years ago)

Updated patch

• ## sage/geometry/polyhedron/backend_cdd.py

# HG changeset patch
# User Volker Braun <vbraun@stp.dias.ie>
# Date 1350906371 -3600
# Node ID 47a1e13855a20fa53cfb5951003f23851dfea3b8
Trac #11763: remove trailing whitespace

diff --git a/sage/geometry/polyhedron/backend_cdd.py b/sage/geometry/polyhedron/backend_cdd.py
 a - vertices -- list of point. Each point can be specified as any iterable container of :meth:~sage.geometry.polyhedron.base.base_ring elements. - rays -- list of rays. Each ray can be specified as any iterable container of :meth:~sage.geometry.polyhedron.base.base_ring elements. - lines -- list of lines. Each line can be specified as any iterable container of :meth:~sage.geometry.polyhedron.base.base_ring elements. computed during initialization. EXAMPLES:: sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], backend='cdd', base_ring=QQ) sage: '_H_adjacency_matrix' in p.__dict__ False computed during initialization. EXAMPLES:: sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], backend='cdd', base_ring=QQ) sage: '_V_adjacency_matrix' in p.__dict__ False and initialize ourselves with the output. TESTS:: sage: p = Polyhedron(vertices = [[0,0,0],[1,0,0],[0,1,0],[0,0,1]], backend='cdd', base_ring=QQ) sage: from sage.geometry.polyhedron.cdd_file_format import cdd_Vrepresentation sage: s = cdd_Vrepresentation('rational', [[0,0,1],[0,1,0],[1,0,0]], [], []) Initialize ourselves with the output from cdd. TESTS:: sage: from sage.geometry.polyhedron.cdd_file_format import cdd_Vrepresentation sage: s = cdd_Vrepresentation('rational',[[0,0],[1,0],[0,1],[1,1]], [], []) sage: from subprocess import Popen, PIPE parent._make_Vertex(self, [0] * self.ambient_dim()) self._Vrepresentation = tuple(self._Vrepresentation) expect_in_cddout('end') if find_in_cddout('H-representation'): self._Hrepresentation = [] equations = cdd_linearities() l = cddout.pop(0).split() assert l[2] == ':', "Not a line of the adjacency data?" return [int(i)-1 for i in l[3:]] if find_in_cddout('Vertex graph'): n = len(self._Vrepresentation); if suppressed_vertex: self._V_adjacency_matrix[n-1,i] = 1 self._V_adjacency_matrix.set_immutable() expect_in_cddout('end') if find_in_cddout('Facet graph'): n = len(self._Hrepresentation); self._H_adjacency_matrix = matrix(ZZ, n, n, 0) :class:~sage.geometry.polyhedron.parent.Polyhedra. - Vrep -- a list [vertices, rays, lines] or None. - Hrep -- a list [ieqs, eqns] or None. EXAMPLES:: data. TESTS:: sage: p = Polyhedron(backend='cdd', base_ring=QQ) sage: type(p) sage: TestSuite(p).run() """ Polyhedron_cdd.__init__(self, parent, Vrep, Hrep, **kwds) ######################################################################### class Polyhedron_RDF_cdd(Polyhedron_cdd, Polyhedron_RDF): - ambient_dim -- integer. The dimension of the ambient space. - Vrep -- a list [vertices, rays, lines] or None. - Hrep -- a list [ieqs, eqns] or None. EXAMPLES:: A 2-dimensional polyhedron in RDF^2 defined as the convex hull of 3 vertices """ _cdd_type = 'real' _cdd_executable = 'cdd_both_reps' def __init__(self, parent, Vrep, Hrep, **kwds): data. TESTS:: sage: p = Polyhedron(backend='cdd', base_ring=RDF) sage: type(p) sage: TestSuite(p).run() """ Polyhedron_cdd.__init__(self, parent, Vrep, Hrep, **kwds)
• ## sage/geometry/polyhedron/backend_ppl.py

diff --git a/sage/geometry/polyhedron/backend_ppl.py b/sage/geometry/polyhedron/backend_ppl.py
 a INPUT: - Vrep -- a list [vertices, rays, lines] or None. - Hrep -- a list [ieqs, eqns] or None. EXAMPLES:: - vertices -- list of point. Each point can be specified as any iterable container of :meth:~sage.geometry.polyhedron.base.base_ring elements. - rays -- list of rays. Each ray can be specified as any iterable container of :meth:~sage.geometry.polyhedron.base.base_ring elements. - lines -- list of lines. Each line can be specified as any iterable container of :meth:~sage.geometry.polyhedron.base.base_ring elements. Construct polyhedron from H-representation data. INPUT: - ieqs -- list of inequalities. Each line can be specified as any iterable container of :meth:~sage.geometry.polyhedron.base.base_ring elements. def _init_Vrepresentation_from_ppl(self, minimize): """ Create the Vrepresentation objects from the ppl polyhedron. EXAMPLES:: sage: p = Polyhedron(vertices=[(0,1/2),(2,0),(4,5/6)],
• ## sage/geometry/polyhedron/base.py

diff --git a/sage/geometry/polyhedron/base.py b/sage/geometry/polyhedron/base.py
 a - Vrep -- a list [vertices, rays, lines] or None. The V-representation of the polyhedron. If None, the polyhedron is determined by the H-representation. - Hrep -- a list [ieqs, eqns] or None. The H-representation of the polyhedron. If None, the polyhedron is determined by the V-representation. - vertices -- list of point. Each point can be specified as any iterable container of :meth:~sage.geometry.polyhedron.base.base_ring elements. - rays -- list of rays. Each ray can be specified as any iterable container of :meth:~sage.geometry.polyhedron.base.base_ring elements. - lines -- list of lines. Each line can be specified as any iterable container of :meth:~sage.geometry.polyhedron.base.base_ring elements. computed during initialization. EXAMPLES:: sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)]) sage: p._facet_adjacency_matrix() [0 1 1] computed during initialization. EXAMPLES:: sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)]) sage: p._vertex_adjacency_matrix() [0 1 1] Return a graphical representation. INPUT: - **kwds -- optional keyword parameters. See :func:render_2d, :func:render_3d, :func:render_4d desc += repr(self.n_vertices()) if self.n_vertices()==1: desc += ' vertex' else:                    desc += ' vertices' if self.n_rays()>0: if self.n_lines()>0: desc += ", " else:                desc += " and " desc += repr(self.n_rays()) if self.n_rays()==1: desc += ' ray' else:                desc += ' rays' if self.n_lines()>0: if self.n_rays()>0: desc += ", " else:               desc += " and " """ Write the vertices/rays/lines data of the polyhedron in cdd's V-representation format. OUTPUT: A string. If you save the output to filename.ext then you can either an inequality or a equation. INPUT: - index -- either an integer or None. OUTPUT: The optional argument is an index in 0...n_Hrepresentations(). If present, the H-representation object at the given index will be returned. Without an argument, returns the list of all H-representation objects. EXAMPLES:: sage: p = polytopes.n_cube(3) sage: p.Hrepresentation(0) An inequality (0, 0, -1) x + 1 >= 0 return self._Hrepresentation else: return self._Hrepresentation[index] def Hrep_generator(self): """ (inequalities or equations). EXAMPLES:: sage: p = polytopes.n_cube(3) sage: p.Hrep_generator().next() An inequality (0, 0, -1) x + 1 >= 0 either a vertex, a ray, or a line. INPUT: - index -- either an integer or None. OUTPUT: The optional argument is an index in 0...n_Vrepresentation(). If present, the V-representation object at the given index will be returned. Without an def facial_incidences(self): """ Return the face-vertex incidences in the form [f_i, [v_{i_0}, v_{i_1},\dots ,v_{i_2}]]. .. NOTE:: Instead of working with face/vertex indices, it is def vertex_incidences(self): """ Return the vertex-face incidences in the form [v_i, [f_{i_0}, f_{i_1},\dots ,f_{i_2}]]. .. NOTE:: Instead of working with face/vertex indices, you can use polyhedron. OUTPUT: A generator of the inequality Hrepresentation objects. EXAMPLES:: Return a list of inequalities as coefficient lists. .. NOTE:: It is recommended to use :meth:inequalities or :meth:inequality_generator instead to iterate over the list of :class:Inequality objects. Deprecated. Alias for inequalities() EXAMPLES:: sage: p3 = Polyhedron(vertices = permutations([1,2,3,4])) sage: p3.ieqs() == p3.inequalities() doctest:...: DeprecationWarning: the equation b = a1*x1 + a2*x2 + ... + an*xn. .. NOTE:: It is recommended to use :meth:equations or :meth:equation_generator() instead to iterate over the list of Return a list of vertices of the polyhedron. .. NOTE:: It is recommended to use :meth:vertex_generator instead to iterate over the list of :class:Vertex objects. True """ return [list(x) for x in self.vertex_generator()] def vertex_generator(self): """ Return a generator for the vertices of the polyhedron. Return the coordinates of the vertices as the columns of a matrix. INPUT: - base_ring -- A ring or None (default). The base ring of the returned matrix. If not specified, the base ring of the polyhedron is used. Return a list of rays as coefficient lists. .. NOTE:: It is recommended to use :meth:rays or :meth:ray_generator instead to iterate over the list of :class:Ray objects. as a list of coordinates rather than as a Hrepresentation object. .. NOTE:: It is recommended to use :meth:line_generator instead to iterate over the list of :class:Line objects. True """ return [list(x) for x in self.line_generator()] def bounded_edges(self): """ Return the bounded edges (excluding rays and lines). OUTPUT: A generator for pairs of vertices, one pair per edge. def Vrepresentation_space(self): r""" Return the ambient vector space. OUTPUT: A free module over the base ring of dimension :meth:ambient_dim. EXAMPLES:: sage: poly_test = Polyhedron(vertices = [[1,0,0,0],[0,1,0,0]]) Return the linear space containing the H-representation vectors. OUTPUT: A free module over the base ring of dimension :meth:ambient_dim + 1. EXAMPLES:: sage: poly_test = Polyhedron(vertices = [[1,0,0,0],[0,1,0,0]]) sage: poly_test.Hrepresentation_space() Ambient free module of rank 5 over the principal ideal domain Integer Ring 4 """ return self.parent().ambient_dim() def dim(self): """ Return the dimension of the polyhedron. :meth:Vrepresentation EXAMPLES:: sage: p = polytopes.cuboctahedron() sage: p.incidence_matrix() [0 0 1 1 0 1 0 0 0 0 1 0 0 0] distance measure. EXAMPLES:: sage: p = polytopes.n_cube(4) sage: p.radius() 2 sage: p2 = p.prism() sage: p2.gale_transform() [(1, 0), (0, 1), (-1, -1), (-1, 0), (0, -1), (1, 1)] REFERENCES: Lectures in Geometric Combinatorics, R.R.Thomas, 2006, AMS Press. - fine -- boolean (default: False). Whether the triangulations must be fine, that is, make use of all points of the configuration. - regular -- boolean or None (default: None). Whether the triangulations must be regular. A regular triangulation is one that is induced by a piecewise-linear convex support function. In other words, the shadows of the faces of a polyhedron in one higher dimension. * True: Only regular triangulations. * False: Only non-regular triangulations. :class:~sage.geometry.triangulation.point_configuration.Triangulation. The indices in the triangulation correspond to the :meth:Vrepresentation objects. EXAMPLES:: sage: cube = polytopes.n_cube(3) This method is deprecated. Use self.Hrepresentation(i).incident() instead. See http://trac.sagemath.org/11763 for details. [[0, [0, 1, 2]], [1, [0, 1, 3]], [2, [0, 2, 3]], [3, [1, 2, 3]]] Otherwise some faces get split up to triangles:: sage: Polyhedron(vertices = [[2,0,0],[4,1,0],[0,5,0],[5,5,0], r""" Return a new polyhedron formed from two points on each edge between two vertices. INPUT: - cut_frac -- integer. how deeply to cut into the edge. Default is \frac{1}{3}. OUTPUT: A Polyhedron object, truncated as described above. EXAMPLES:: sage: cube = polytopes.n_cube(3) face. OUTPUT: A new :class:PolyhedronFace_base instance. It is not checked whether the input data actually defines a face. Return the face-lattice poset. OUTPUT: A :class:~sage.combinat.posets.posets.FinitePoset. Elements are given as :class:~sage.geometry.polyhedron.PolyhedronFace_base. * Lines are removed before calling :func:Hasse_diagram_from_incidences, and then added back to each face V-representation except for the "empty face". * Equations are removed before calling :func:Hasse_diagram_from_incidences, and then added back to each face H-representation. (A vertex at (-1, -1), A vertex at (1, -1)) sage: a_face.ambient_Hrepresentation() (An inequality (0, 1) x + 1 >= 0,) A more complicated example:: sage: c5_10 = Polyhedron(vertices = [[i,i^2,i^3,i^4,i^5] for i in range(1,11)]) sage: c5_10_fl = c5_10.face_lattice() sage: [len(x) for x in c5_10_fl.level_sets()] [1, 10, 45, 100, 105, 42, 1] Note that if the polyhedron contains lines then there is a dimension gap between the empty face and the first non-empty face in the face lattice:: REFERENCES: ..  [KP2002] Volker Kaibel and Marc E. Pfetsch, "Computing the Face Lattice of a Polytope from its Vertex-Facet Incidences", Computational Geometry: Theory and Applications, Volume Hindex_to_coatom = [None] * self.n_Hrepresentation() for i in range(0,len(coatom_to_Hindex)): Hindex_to_coatom[ coatom_to_Hindex[i] ] = i atom_to_Vindex = [ v.index() for v in self.Vrep_generator() if not v.is_line() ] Vindex_to_atom = [None] * self.n_Vrepresentation() for i in range(0,len(atom_to_Vindex)): Vindex_to_atom[ atom_to_Vindex[i] ] = i atoms_incidences   = [ tuple([ Hindex_to_coatom[h.index()] for h in v.incident() if h.is_inequality() ]) for v in self.Vrepresentation() if not v.is_line() ] coatoms_incidences = [ tuple([ Vindex_to_atom[v.index()] for v in h.incident() if not v.is_line() ]) for h in self.Hrepresentation() if h.is_inequality() ] atoms_vertices = [ Vindex_to_atom[v.index()] for v in self.vertex_generator() ] equations = [ e.index() for e in self.equation_generator() ] lines     = [ l.index() for l in self.line_generator() ] Return the f-vector. OUTPUT: Returns a vector whose i-th entry is the number of i-dimensional faces of the polytope. [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]] Now check that bipyramids of cross-polytopes are cross-polytopes:: sage: q2 = [list(v) for v in polytopes.cross_polytope(4).vertex_generator()] projection_dir = [sum([vertices[f0[i]][j]/len(f0) for i in range(len(f0))]) for j in range(self.ambient_dim())] return proj.schlegel(projection_direction = projection_dir, height = height) def lrs_volume(self, verbose = False): """ Computes the volume of a polytope. 2.0 REFERENCES: David Avis's lrs program. """ if is_package_installed('lrs') != True: Boolean. EXAMPLES:: sage: P = Polyhedron(vertices=[[1,1],[1,-1],[0,0]]) sage: P.contains( [1,0] ) True True sage: ray.contains(['hello', 'kitty'])   # no common ring for coordinates False The empty polyhedron needs extra care, see trac #10238:: sage: empty = Polyhedron(); empty if len(p)!=self.ambient_dim(): return False for H in self.Hrep_generator(): if not H.contains(p): return False :meth:relative_interior_contains. INPUT: - point -- coordinates of a point. OUTPUT: True or False. EXAMPLES:: sage: P = Polyhedron(vertices=[[0,0],[1,1],[1,-1]]) sage: P.contains( [1,0] ) True if len(p)!=self.ambient_dim(): return False for H in self.Hrep_generator(): if not H.interior_contains(p): return False See also :meth:contains and :meth:interior_contains. INPUT: - point -- coordinates of a point. OUTPUT: True or False. EXAMPLES:: sage: P = Polyhedron(vertices=[(1,0), (-1,0)]) sage: P.contains( (0,0) ) True if len(p)!=self.ambient_dim(): return False for eq in self.equation_generator(): if not eq.contains(p): return False def is_simplex(self): r""" Return whether the polyhedron is a simplex. EXAMPLES:: sage: Polyhedron([(0,0,0), (1,0,0), (0,1,0)]).is_simplex() def is_lattice_polytope(self): r""" Return whether the polyhedron is a lattice polytope. OUTPUT: True if the polyhedron is compact and has only integral vertices, False otherwise. EXAMPLES:: sage: polytopes.cross_polytope(3).is_lattice_polytope() True sage: polytopes.regular_polygon(5).is_lattice_polytope() if self.base_ring() is ZZ: return True return all(v.is_integral() for v in self.vertex_generator()) @cached_method def lattice_polytope(self, envelope=False): r""" Return an encompassing lattice polytope. INPUT: - envelope -- boolean (default: False). If the is returned. EXAMPLES: First, a polyhedron with integral vertices:: sage: P = Polyhedron( vertices = [(1, 0), (0, 1), (-1, 0), (0, -1)]) This method is for testing purposes and will eventually be removed. OUTPUT: The list of integral points in the polyhedron. If the polyhedron is not compact, a ValueError is raised. EXAMPLES:: sage: Polyhedron(vertices=[(-1,-1),(1,0),(1,1),(0,1)])._integral_points_PALP() [(-1, -1), (0, 1), (1, 0), (1, 1), (0, 0)] sage: Polyhedron(vertices=[(-1/2,-1/2),(1,0),(1,1),(0,1)]).lattice_polytope(True).points() - integral -- Boolean (default: False). Whether to only allow integral coordinates in the bounding box. OUTPUT: A pair of tuples (box_min, box_max) where box_min are box_max.append(max_coord) box_min.append(min_coord) return (tuple(box_min), tuple(box_max)) def integral_points(self, threshold=100000): r""" Return the integral points in the polyhedron. algorith as long as the bounding box is smaller than this. OUTPUT: The list of integral points in the polyhedron. If the polyhedron is not compact, a ValueError is raised. EXAMPLES:: sage: Polyhedron(vertices=[(-1,-1),(1,0),(1,1),(0,1)]).integral_points() ((-1, -1), (0, 0), (0, 1), (1, 0), (1, 1)) points.update(new_points) # assert all(self.contains(p) for p in points)   # slow return tuple(points) @cached_method def combinatorial_automorphism_group(self): """ chosen to be shifted by +1. That is, i in the permutation group corresponds to the V-representation object self.Vrepresentation(i-1). EXAMPLES:: sage: quadrangle = Polyhedron(vertices=[(0,0),(1,0),(0,1),(2,3)]) sage: quadrangle.combinatorial_automorphism_group() Permutation Group with generators [(2,3), (1,2)(3,4)] def _affine_coordinates(self, Vrep_object): r""" Return affine coordinates for a V-representation object. INPUT: - v -- a V-representation object or any iterable A self.dim()-dimensional coordinate vector. It contains the coordinates of v in an arbitrary but fixed basis for the affine span of the polyhedron. EXAMPLES:: sage: P = Polyhedron(rays=[(1,0,0),(0,1,0)]) sage: P._affine_coordinates( (-1,-2,-3) ) (-1, -2) v_list = [ v - origin for v in v_list ] coordinates = matrix(v_list) self._affine_coordinates_pivots = coordinates.pivots() v = list(Vrep_object) if len(v) != self.ambient_dim(): raise ValueError('Incorrect dimension: '+str(v)) return vector(self.base_ring(), [ v[i] for i in self._affine_coordinates_pivots ]) @cached_method def restricted_automorphism_group(self): r""" generators with line generators. For example, take the first quadrant .. MATH:: Q = \Big\{ (x,y) \Big| x\geq 0,\; y\geq0 \Big\} \subset \QQ^2 Then the linear automorphism group is .. MATH:: \mathrm{Aut}(Q) = A :class:PermutationGroup that is isomorphic to the restricted automorphism group is returned. Note that in Sage, permutation groups always act on positive integers while self.Vrepresentation() is indexed by nonnegative integers. The indexing of the permutation group is Floating-point computations are supported with a simple fuzzy zero implementation:: sage: P = Polyhedron(vertices=[(1.0/3.0,0,0),(0,1.0/3.0,0),(0,0,1.0/3.0)], base_ring=RDF) sage: P.restricted_automorphism_group() Permutation Group with generators [(2,3), (1,2)] class PolyhedronFace_base(Polyhedron_base): r""" A face of a polyhedron. This class is for use in :meth:~sage.geometry.polyhedron.base.Polyhedron_base.face_lattice. - H_indices -- list of integers. The indices of the H-representation objects of the ambient polyhedron that are saturated on the face. TESTS:: sage: from sage.geometry.polyhedron.base import PolyhedronFace_base r""" Return the H-representation objects of the ambient polytope defining the face. INPUT: - index -- optional. Either an integer or None (default). OUTPUT: If the optional argument is not present, a tuple of H-representation objects. Each entry is either an inequality or an equation. index-th element of the tuple is returned. EXAMPLES:: sage: square = polytopes.n_cube(2) sage: for fl in square.face_lattice(): ...       print fl.element.ambient_Hrepresentation() return self._ambient_Hrepresentation else: return self._ambient_Hrepresentation[index] def ambient_Vrepresentation(self, index=None): r""" Return the V-representation objects of the ambient polytope defining the face. INPUT: - index -- optional. Either an integer or None (default). OUTPUT: If the optional argument is not present, a tuple of V-representation objects. Each entry is either a vertex, a ray, or a line. If the optional integer index is specified, the index-th element of the tuple is returned. EXAMPLES:: sage: square = polytopes.n_cube(2) sage: for fl in square.face_lattice(): ...       print fl.element.ambient_Vrepresentation() def dim(self): """ Return the dimension of the face. OUTPUT: Integer. EXAMPLES:: sage: fl = polytopes.dodecahedron().face_lattice()
• ## sage/geometry/polyhedron/base_QQ.py

diff --git a/sage/geometry/polyhedron/base_QQ.py b/sage/geometry/polyhedron/base_QQ.py
 a Base class for Polyhedra over \QQ TESTS:: sage: p = Polyhedron([(0,0)], base_ring=QQ);  p A 0-dimensional polyhedron in QQ^2 defined as the convex hull of 1 vertex sage: TestSuite(p).run() def _is_zero(self, x): """ Test whether x is zero. INPUT: - x -- a number in the base ring. Boolean. EXAMPLES:: sage: p = Polyhedron([(0,0)], base_ring=QQ) sage: p._is_zero(0) True def _is_nonneg(self, x): """ Test whether x is nonnegative. INPUT: - x -- a number in the base ring. Boolean. EXAMPLES:: sage: p = Polyhedron([(0,0)], base_ring=QQ) sage: p._is_nonneg(1) True def _is_positive(self, x): """ Test whether x is positive. INPUT: - x -- a number in the base ring. Boolean. EXAMPLES:: sage: p = Polyhedron([(0,0)], base_ring=QQ) sage: p._is_positive(1) True
• ## sage/geometry/polyhedron/base_RDF.py

diff --git a/sage/geometry/polyhedron/base_RDF.py b/sage/geometry/polyhedron/base_RDF.py
 a Base class for polyhedra over RDF. TESTS:: sage: p = Polyhedron([(0,0)], base_ring=RDF);  p A 0-dimensional polyhedron in RDF^2 defined as the convex hull of 1 vertex sage: TestSuite(p).run() def _is_zero(self, x): """ Test whether x is zero. INPUT: - x -- a number in the base ring. Boolean. EXAMPLES:: sage: p = Polyhedron([(0,0)], base_ring=RDF) sage: p._is_zero(0) True def _is_nonneg(self, x): """ Test whether x is nonnegative. INPUT: - x -- a number in the base ring. Boolean. EXAMPLES:: sage: p = Polyhedron([(0,0)], base_ring=RDF) sage: p._is_nonneg(1) True def _is_positive(self, x): """ Test whether x is positive. INPUT: - x -- a number in the base ring. Boolean. EXAMPLES:: sage: p = Polyhedron([(0,0)], base_ring=RDF) sage: p._is_positive(1) True True """ return x>=-1e-6 _base_ring = RDF
• ## sage/geometry/polyhedron/cdd_file_format.py

diff --git a/sage/geometry/polyhedron/cdd_file_format.py b/sage/geometry/polyhedron/cdd_file_format.py
 a Return a string containing the V-representation in cddlib's ext format. NOTE: If there is no vertex given, then the origin will be implicitly added. You cannot write the empty V-representation (which cdd would refuse to process).
• ## sage/geometry/polyhedron/constructor.py

diff --git a/sage/geometry/polyhedron/constructor.py b/sage/geometry/polyhedron/constructor.py
 a polyhedron is then the Minkowski sum .. MATH:: P = \text{conv}\{v_1,\dots,v_k\} + \sum_{i=1}^m \RR_+ r_i + \sum_{j=1}^n \RR \ell_j where * v_1, \dots, v_k are a finite number of vertices, * r_1, \dots, r_m are generators of rays, * and \ell_1, \dots, \ell_n are generators of full lines. ######################################################################### any iterable container of base_ring elements. If rays or lines are specified but no vertices, the origin is taken to be the single vertex. - rays -- list of rays. Each ray can be specified as any iterable container of base_ring elements. - lines -- list of lines. Each line can be specified as any iterable container of base_ring elements. * The inequality e+b \geq c+d * The inequality e+c \geq b+d * The equation a+b+c+d+e+f = 31 :: sage: positive_coords = Polyhedron(ieqs=[ A vertex at (0, 0, 0, 31/2, 31/2, 0)) .. NOTE:: * Once constructed, a Polyhedron object is immutable. * Although the option field=RDF allows numerical data to be used, it might not give the right answer for degenerate got_Vrep = (len(vertices+rays+lines) > 0) got_Hrep = (len(ieqs+eqns) > 0) if got_Vrep and got_Hrep: raise ValueError('You cannot specify both H- and V-representation.') elif got_Vrep:
• ## sage/geometry/polyhedron/library.py

diff --git a/sage/geometry/polyhedron/library.py b/sage/geometry/polyhedron/library.py
 a """ A matrix of rational approximations to orthonormal vectors to (1,...,1). INPUT: - dim_n - the dimension of the vectors An internal utility function for constructing the Birkhoff polytopes. EXAMPLES:: sage: from sage.geometry.polyhedron.library import Polytopes sage: Polytopes._pfunc(1,2,permutations(3)[0]) 0 Return an icosahedron with edge length 1. INPUT: - base_ring -- Either QQ or RDF. OUTPUT: def dodecahedron(self, base_ring=QQ): """ Return a dodecahedron. INPUT: - base_ring -- Either QQ (in which case a rational approximation to the golden ratio is used) or RDF. - n -- the numbers (1,...,n) are permuted - project -- If False the polyhedron is left in dimension n. OUTPUT: A Polyhedron object representing the permutahedron. Return a cube in the given dimension INPUT: - dim_n -- integer. The dimension of the cube. OUTPUT: verts = verts + permutations([0 for i in range(dim_n-1)] + [-1]) return Polyhedron(vertices=verts) def parallelotope(self, generators): r""" Return the parallelotope spanned by the generators. INPUT: - generators -- an iterable of anything convertible to vector (for example, a list of vectors) such that the vectors all have the same dimension. parallelepiped (3 generators). EXAMPLES:: sage: polytopes.parallelotope([ (1,0), (0,1) ]) A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 4 vertices sage: polytopes.parallelotope([[1,2,3,4],[0,1,0,7],[3,1,0,2],[0,0,1,0]]) except TypeError: generators = [ vector(RDF,v) for v in generators ] base_ring = RDF from sage.combinat.combination import Combinations par =  [ 0*generators[0] ] par += [ sum(c) for c in Combinations(generators) if c!=[] ] return Polyhedron(vertices=par, base_ring=base_ring) polytopes = Polytopes()
• ## sage/geometry/polyhedron/misc.py

diff --git a/sage/geometry/polyhedron/misc.py b/sage/geometry/polyhedron/misc.py
 a INPUT: - l -- anything iterable. OUTPUT: String. length differs, ValueError is raised. Used to check arguments. OUTPUT: A tuple (number of entries, common length of the entries) EXAMPLES::
• ## sage/geometry/polyhedron/plot.py

diff --git a/sage/geometry/polyhedron/plot.py b/sage/geometry/polyhedron/plot.py
 a """ Return 2d rendering of the projection of a polyhedron into 2-dimensional ambient space. EXAMPLES:: sage: p1 = Polyhedron(vertices=[[1,1]], rays=[[1,1]]) sage: q1 = p1.projection() sage: p2 = Polyhedron(vertices=[[1,0], [0,1], [0,0]]) """ Return 3d rendering of a polyhedron projected into 3-dimensional ambient space. NOTE: This method, render_3d, is used in the show() method of a polyhedron if it is in 3 dimensions. EXAMPLES:: sage: p1 = Polyhedron(vertices=[[1,1,1]], rays=[[1,1,1]]) sage: p2 = Polyhedron(vertices=[[2,0,0], [0,2,0], [0,0,2]]) sage: p3 = Polyhedron(vertices=[[1,0,0], [0,1,0], [0,0,1]], rays=[[-1,-1,-1]]) sage: p1.projection().show() + p2.projection().show() + p3.projection().show() It correctly handles various degenerate cases:: sage: Polyhedron(lines=[[1,0,0],[0,1,0],[0,0,1]]).show()                              # whole space sage: Polyhedron(vertices=[[1,1,1]], rays=[[1,0,0]], lines=[[0,1,0],[0,0,1]]).show()  # half space sage: Polyhedron(vertices=[[1,1,1]], lines=[[0,1,0],[0,0,1]]).show()                  # R^2 in R^3 polyhedron projected into 3-dimensional space. NOTES: The show() method of Polyhedron() uses this to draw itself if the ambient dimension is 4. INPUT: - polyhedron -- A :mod:~sage.geometry.polyhedron.constructor.Polyhedron object. projection_direction= sets the projetion direction of the Schlegel projection. If it is not given, the center of a facet is used. EXAMPLES:: sage: poly = polytopes.twenty_four_cell() sage: poly A 4-dimensional polyhedron in QQ^4 defined as the convex hull of 24 vertices sage: poly.show(projection_direction=[2,5,11,17]) sage: type( poly.show() ) TESTS:: sage: from sage.geometry.polyhedron.plot import render_4d sage: p = polytopes.n_cube(4) sage: q = render_4d(p) def cyclic_sort_vertices_2d(Vlist): """ Return the vertices/rays in cyclic order if possible. NOTES: This works if and only if each vertex/ray is adjacent to exactly chain = [ Vlist.pop() ] result += chain return result ######################################################################### def projection_func_identity(x): """ self.projection_point = vector(projection_point) self.dim = self.projection_point.degree() pproj = vector(RDF,self.projection_point) self.psize = norm(pproj) if (self.psize).is_zero(): Action of the stereographic projection. INPUT: - x -- a vector or anything convertible to a vector. OUTPUT: def __init__(self, projection_direction, height = 1.1): """ Initializes the projection. EXAMPLES:: sage: from sage.geometry.polyhedron.plot import ProjectionFuncSchlegel - proj -- a projection function for the points NOTES: Once initialized, the polyhedral data is fixed. However, the projection can be changed later on. Sequence([proj(p) for p in self.coords]) self._init_dimension() return self def identity(self): """ Return the identity projection of the polyhedron. EXAMPLES:: sage: p = polytopes.icosahedron() sage: from sage.geometry.polyhedron.plot import Projection sage: pproj = Projection(p) Rteurn the stereographic projection. INPUT: - projection_point - The projection point. This must be distinct from the polyhedron's vertices. Default is (1,0,\dots,0) EXAMPLES:: sage: from sage.geometry.polyhedron.plot import Projection sage: proj = Projection(polytopes.buckyball())  #long time sage: proj                                      #long time if projection_point == None: projection_point = [1] + [0]*(self.polyhedron_ambient_dim-1) return self.__call__(ProjectionFuncStereographic(projection_point)) def schlegel(self, projection_direction=None, height = 1.1): """ the sphere. INPUT: - projection_direction - The direction of the Schlegel projection. By default, the vector consisting of the first n primes is chosen. if projection_direction == None: projection_direction = primes_first_n(self.polyhedron_ambient_dim) return self.__call__(ProjectionFuncSchlegel(projection_direction, height = height)) def coord_index_of(self, v): """ [7, 5] """ return [self.coord_index_of(v) for v in v_list] def coordinates_of(self, coord_index_list): """ except AttributeError: pass def _init_from_2d(self, polyhedron): """ Internal function: Initialize from 2d polyhedron. self.coord_index_of(l1[1]) ] ) self.arrows.append( [ self.coord_index_of(l2[0]), self.coord_index_of(l2[1]) ] ) def _init_area_2d(self, polyhedron): """ vertices = [v for v in polyhedron.Vrep_generator()] vertices = cyclic_sort_vertices_2d(vertices) coords = [] def adjacent_vertices(i): n = len(vertices) if vertices[(i-1) % n].is_vertex(): yield vertices[(i-1) % n] if vertices[(i+1) % n].is_vertex(): yield vertices[(i+1) % n] for i in range(len(vertices)): v = vertices[i] if v.is_vertex(): if v.is_ray(): for a in adjacent_vertices(i): coords.append(a() + v()) if polyhedron.n_lines() == 0: self.polygons.append( self.coord_indices_of(coords) ) return polygons = [] if polyhedron.n_lines() == 1: l1 = line1() l2 = line2() polygons = [ [v-l1-l2, v+l1-l2, v+l1+l2, v-l1+l2] ] polygons = [ self.coord_indices_of(p) for p in polygons ] self.polygons.extend(polygons) def _init_solid_3d(self, polyhedron): vertices = [v for v in facet_equation.incident()] vertices = cyclic_sort_vertices_2d(vertices) coords = [] def adjacent_vertices(i): n = len(vertices) if vertices[(i-1) % n].is_vertex(): yield vertices[(i-1) % n] if vertices[(i+1) % n].is_vertex(): yield vertices[(i+1) % n] for i in range(len(vertices)): v = vertices[i] if v.is_vertex(): assert len(coords)==2, "There must be two points." polygons.append( [ coords[0],coords[1], coords[1]+shift, coords[0]+shift ] ) if polyhedron.n_lines()==2: [line1, line2] = [l for l in polyhedron.line_generator()] l1 = line1() l2 = line2() for v in polyhedron.vertex_generator(): polygons.append( [v()-l1-l2, v()+l1-l2, v()+l1+l2, v()-l1+l2] ) self.polygons.extend( [self.coord_indices_of(p) for p in polygons] ) poly = [polygon2d(self.coordinates_of(p), **kwds) for p in self.polygons] return sum(poly) def render_vertices_3d(self, **kwds): """ Return the 3d rendering of the vertices. def render_solid_3d(self, **kwds): """ Return solid 3d rendering of a 3d polytope. EXAMPLES:: sage: p = polytopes.n_cube(3).projection() sage: p_solid = p.render_solid_3d(opacity = .7) sage: type(p_solid)
• ## sage/geometry/polyhedron/representation.py

diff --git a/sage/geometry/polyhedron/representation.py b/sage/geometry/polyhedron/representation.py
 a """ The internal base class for all representation objects of Polyhedron (vertices/rays/lines and inequalites/equations) .. note:: You should not (and cannot) instantiate it yourself. You can only obtain them from a Polyhedron() class. sage: P.PolyhedronRepresentation() """ # Numeric values for the output of the type() method INEQUALITY = 0 EQUATION = 1 VERTEX = 2 RAY = 3 LINE = 4 def __len__(self): """ Returns the length of the representation data. TESTS:: sage: p = Polyhedron(vertices=[[1,2,3]]) sage: v = p.Vrepresentation(0) sage: v.__len__() def __getitem__(self, i): """ Supports indexing. TESTS:: sage: p = Polyhedron(vertices=[[1,2,3]]) sage: v = p.Vrepresentation(0) sage: v.__getitem__(1) def polyhedron(self): """ Returns the underlying polyhedron. TESTS:: sage: p = Polyhedron(vertices=[[1,2,3]]) sage: v = p.Vrepresentation(0) sage: v.polyhedron() object. Shorthand for the vector() method. TESTS:: sage: p = Polyhedron(vertices=[[1,2,3]]) sage: v = p.Vrepresentation(0) sage: v.__call__() storage order. NOTES: H-representation and V-representation objects are enumerated independently. That is, amongst all vertices/rays/lines there will be one with index()==0, and amongs all unless the polyhedron is empty or spans the whole space. EXAMPLES:: sage: s = Polyhedron(vertices=[[1],[-1]]) sage: first_vertex = s.vertex_generator().next() sage: first_vertex.index() True """ return False def A(self): r""" Returns the coefficient vector A in A\vec{x}+b. r""" Evaluates the left hand side A\vec{x}+b on the given vertex/ray/line. NOTES: * Evaluating on a vertex returns A\vec{x}+b * Evaluating on a ray returns A\vec{r}. Only the sign or whether it is zero is meaningful. is zero or not is meaningful. EXAMPLES:: sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[-1,-1]]) sage: ineq = triangle.inequality_generator().next() sage: ineq [0, 0, 3] If you pass a vector, it is assumed to be the coordinate vector of a point:: sage: ineq.eval( vector(ZZ, [3,2]) ) 5 """ return self.polyhedron()._is_nonneg( self.eval(Vobj) ) except AttributeError: pass if Vobj.is_line(): return self.polyhedron()._is_zero( self.eval(Vobj) ) else: [True, False, False, False, True, True, True, False] If you pass a vector, it is assumed to be the coordinate vector of a point:: sage: P = Polyhedron(vertices=[[1,1],[1,-1],[-1,1],[-1,-1]]) sage: p = vector(ZZ, [1,0] ) sage: [ ieq.interior_contains(p) for ieq in P.inequality_generator() ] return self.polyhedron()._is_positive( self.eval(Vobj) ) except AttributeError: pass if Vobj.is_line(): return self.polyhedron()._is_zero( self.eval(Vobj) ) elif Vobj.is_vertex(): def _repr_(self): """ A string representation of this object. TESTS:: sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]]) the given vertex/ray/line. EXAMPLES:: sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]]) sage: v = p.vertex_generator().next() sage: v Initializes the PolyhedronRepresentation object. TESTS:: sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]]) sage: a = p.inequality_generator().next() sage: a Alias for neighbors(). TESTS:: sage: p = Polyhedron(vertices = [[0,0],[1,0],[0,3],[1,4]]) sage: v = p.vertex_generator().next() sage: a = v.neighbors().next() Boolean. EXAMPLES:: sage: p = Polyhedron([(1/2,3,5), (0,0,0), (2,3,7)]) sage: [ v.is_integral() for v in p.vertex_generator() ] [True, False, True] Returns A\vec{r} EXAMPLES:: sage: p = Polyhedron(ieqs = [[0,0,1],[0,1,0],[1,-1,0]]) sage: a = p.ray_generator().next() sage: h = p.inequality_generator().next() Tests if the object is a line.  By construction it must be. TESTS:: sage: p = Polyhedron(ieqs = [[1, 0, 0, 1],[1,1,0,0]]) sage: a = p.line_generator().next() sage: a.is_line() A string representation of the line. TESTS:: sage: p = Polyhedron(ieqs = [[1, 0, 0, 1],[1,1,0,0]]) sage: a = p.line_generator().next() sage: a.__repr__() def evaluated_on(self, Hobj): r""" Returns A\vec{\ell} EXAMPLES:: sage: p = Polyhedron(ieqs = [[1, 0, 0, 1],[1,1,0,0]]) sage: a = p.line_generator().next() sage: h = p.inequality_generator().next()