Ticket #11634: trac_11634_ppl_backend.patch

File trac_11634_ppl_backend.patch, 78.1 KB (added by vbraun, 9 years ago)

Updated patch

  • doc/en/reference/geometry.rst

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1324332031 0
    # Node ID aeff9c999869ae9e3bb13a033767fd1c8ad3e45e
    # Parent  4e52af5c379ffc90f76a77f64a1323fa2dffd1bb
    Trac 11634: Implement PPL backend
    
    diff --git a/doc/en/reference/geometry.rst b/doc/en/reference/geometry.rst
    a b  
    2626   sage/geometry/polyhedron/base_QQ
    2727   sage/geometry/polyhedron/base_RDF
    2828   sage/geometry/polyhedron/backend_cdd
     29   sage/geometry/polyhedron/backend_ppl
    2930   sage/geometry/polyhedron/cdd_file_format
    3031
    3132   sage/geometry/triangulation/point_configuration
  • sage/geometry/cone.py

    diff --git a/sage/geometry/cone.py b/sage/geometry/cone.py
    a b  
    11881188            sage: c = Cone([(1,0), (1,1), (0,1)])
    11891189            sage: c._PPL_cone()
    11901190            A 2-dimensional polyhedron in QQ^2 defined as
    1191             the convex hull of 1 point, 2 rays.
     1191            the convex hull of 1 point, 2 rays
    11921192            sage: c._PPL_cone().minimized_generators()
    11931193            Generator_System {point(0/1, 0/1), ray(0, 1), ray(1, 0)}
    11941194            sage: c._PPL_cone().minimized_constraints()
     
    12001200       
    12011201            sage: Cone([(0,0)])._PPL_cone()
    12021202            A 0-dimensional polyhedron in QQ^2
    1203             defined as the convex hull of 1 point.
     1203            defined as the convex hull of 1 point
    12041204            sage: Cone([], lattice=ToricLattice(2))._PPL_cone()
    12051205            A 0-dimensional polyhedron in QQ^2
    1206             defined as the convex hull of 1 point.
     1206            defined as the convex hull of 1 point
    12071207        """
    12081208        if "_PPL_C_Polyhedron" not in self.__dict__:
    12091209            gs = Generator_System(
  • sage/geometry/integral_points.pyx

    diff --git a/sage/geometry/integral_points.pyx b/sage/geometry/integral_points.pyx
    a b  
    257257
    258258        sage: simplex = Polyhedron([(1,2,3,5), (2,3,7,5), (-2,-3,-11,5)])
    259259        sage: simplex_points(simplex.Vrepresentation())
    260         ((-2, -3, -11, 5), (0, 0, -2, 5), (1, 2, 3, 5), (2, 3, 7, 5))
     260        ((2, 3, 7, 5), (0, 0, -2, 5), (-2, -3, -11, 5), (1, 2, 3, 5))
    261261
    262262        sage: simplex_points([(2,3,7)])
    263263        ((2, 3, 7),)
     
    793793        sage: P_QQ = Polyhedron(identity_matrix(3).columns() + [(-2, -1,-1)], base_ring=QQ)
    794794        sage: ieq = InequalityCollection(P_QQ, Permutation([1,2,3]), [0]*3,[1]*3); ieq
    795795        The collection of inequalities
     796        integer: (3, -2, -2) x + 2 >= 0
     797        integer: (-1, 4, -1) x + 1 >= 0
     798        integer: (-1, -1, 4) x + 1 >= 0
    796799        integer: (-1, -1, -1) x + 1 >= 0
    797         integer: (-1, -1, 4) x + 1 >= 0
    798         integer: (-1, 4, -1) x + 1 >= 0
    799         integer: (3, -2, -2) x + 2 >= 0
    800800
    801801        sage: P_RR = Polyhedron(identity_matrix(2).columns() + [(-2.7, -1)], base_ring=RDF)
    802802        sage: InequalityCollection(P_RR, Permutation([1,2]), [0]*2, [1]*2)
     
    10191019            sage: iec = InequalityCollection(P_QQ, Permutation([1,2,3]), [0]*3,[1]*3)
    10201020            sage: iec
    10211021            The collection of inequalities
     1022            integer: (3, -2, -2) x + 2 >= 0
     1023            integer: (-1, 4, -1) x + 1 >= 0
     1024            integer: (-1, -1, 4) x + 1 >= 0
    10221025            integer: (-1, -1, -1) x + 1 >= 0
    1023             integer: (-1, -1, 4) x + 1 >= 0
    1024             integer: (-1, 4, -1) x + 1 >= 0
    1025             integer: (3, -2, -2) x + 2 >= 0
    10261026            sage: iec.swap_ineq_to_front(3)
    10271027            sage: iec
    10281028            The collection of inequalities
     1029            integer: (-1, -1, -1) x + 1 >= 0
    10291030            integer: (3, -2, -2) x + 2 >= 0
    1030             integer: (-1, -1, -1) x + 1 >= 0
     1031            integer: (-1, 4, -1) x + 1 >= 0
    10311032            integer: (-1, -1, 4) x + 1 >= 0
    1032             integer: (-1, 4, -1) x + 1 >= 0
    10331033        """
    10341034        i_th_entry = self.ineqs_int.pop(i)
    10351035        self.ineqs_int.insert(0, i_th_entry)
  • sage/geometry/polyhedra.py

    diff --git a/sage/geometry/polyhedra.py b/sage/geometry/polyhedra.py
    a b  
    11from sage.misc.misc import deprecation
    2 deprecation('The module sage.geometry.polyhedra has been removed.',
     2deprecation('The module sage.geometry.polyhedra has been removed, use sage.geometry.polyhedron instead.',
    33            'Sage Version 4.8')
    44from polyhedron.all import *
  • sage/geometry/polyhedron/backend_cdd.py

    diff --git a/sage/geometry/polyhedron/backend_cdd.py b/sage/geometry/polyhedron/backend_cdd.py
    a b  
    139139        TESTS::
    140140       
    141141            sage: p = Polyhedron(vertices = [[0,0,0],[1,0,0],[0,1,0],[0,0,1]], backend='cddr')
    142             sage: from sage.geometry.polyhedron.cdd_representation import cdd_Vrepresentation
     142            sage: from sage.geometry.polyhedron.cdd_file_format import cdd_Vrepresentation
    143143            sage: s = cdd_Vrepresentation('rational', [[0,0,1],[0,1,0],[1,0,0]], [], [])
    144144            sage: p._init_from_cdd_input(s)
    145145            sage: p.dim()
     
    163163
    164164        TESTS::
    165165 
    166             sage: from sage.geometry.polyhedron.cdd_representation import cdd_Vrepresentation
     166            sage: from sage.geometry.polyhedron.cdd_file_format import cdd_Vrepresentation
    167167            sage: s = cdd_Vrepresentation('rational',[[0,0],[1,0],[0,1],[1,1]], [], [])
    168168            sage: from subprocess import Popen, PIPE
    169169            sage: cdd_proc = Popen(['cdd_both_reps_gmp', '--all'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
  • new file sage/geometry/polyhedron/backend_ppl.py

    diff --git a/sage/geometry/polyhedron/backend_ppl.py b/sage/geometry/polyhedron/backend_ppl.py
    new file mode 100644
    - +  
     1"""
     2The PPL (Parma Polyhedra Library) backend for polyhedral computations
     3"""
     4
     5from sage.rings.all import ZZ, QQ
     6from sage.rings.arith import lcm
     7from sage.misc.functional import denominator
     8from sage.matrix.constructor import matrix
     9from sage.libs.ppl import (
     10    C_Polyhedron, Constraint_System, Generator_System,
     11    Variable, Linear_Expression,
     12    line, ray, point )
     13
     14from base_QQ import Polyhedron_QQ
     15from representation import (
     16    PolyhedronRepresentation,
     17    Hrepresentation,
     18    Inequality, Equation,
     19    Vrepresentation,
     20    Vertex, Ray, Line )
     21
     22
     23
     24#########################################################################
     25class Polyhedron_QQ_ppl(Polyhedron_QQ):
     26    """
     27    Polyhedra over `\QQ` with ppl
     28
     29    INPUT:
     30
     31    - ``ambient_dim`` -- integer. The dimension of the ambient space.
     32
     33    - ``Vrep`` -- a list ``[vertices, rays, lines]``.
     34       
     35    - ``Hrep`` -- a list ``[ieqs, eqns]``.
     36
     37    EXAMPLES::
     38
     39        sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], rays=[(1,1)], lines=[], backend='ppl')
     40        sage: TestSuite(p).run()
     41    """
     42
     43    def _init_from_Vrepresentation(self, ambient_dim, vertices, rays, lines, minimize=True):
     44        """
     45        Construct polyhedron from V-representation data.
     46
     47        INPUT:
     48
     49        - ``ambient_dim`` -- integer. The dimension of the ambient space.
     50       
     51        - ``vertices`` -- list of point. Each point can be specified
     52           as any iterable container of
     53           :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
     54       
     55        - ``rays`` -- list of rays. Each ray can be specified as any
     56          iterable container of
     57          :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
     58       
     59        - ``lines`` -- list of lines. Each line can be specified as
     60          any iterable container of
     61          :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
     62
     63        EXAMPLES::
     64
     65            sage: p = Polyhedron(backend='ppl')
     66            sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_QQ_ppl
     67            sage: Polyhedron_QQ_ppl._init_from_Vrepresentation(p, 2, [], [], [])
     68        """
     69        gs = Generator_System()
     70        if vertices is None: vertices = []
     71        for v in vertices:
     72            d = lcm([denominator(v_i) for v_i in v])
     73            dv = [ ZZ(d*v_i) for v_i in v ]
     74            gs.insert(point(Linear_Expression(dv, 0), d))
     75        if rays is None: rays = []
     76        for r in rays:
     77            d = lcm([denominator(r_i) for r_i in r])
     78            dr = [ ZZ(d*r_i) for r_i in r ]
     79            gs.insert(ray(Linear_Expression(dr, 0)))
     80        if lines is None: lines = []
     81        for l in lines:
     82            d = lcm([denominator(l_i) for l_i in l])
     83            dl = [ ZZ(d*l_i) for l_i in l ]
     84            gs.insert(line(Linear_Expression(dl, 0)))
     85        self._ppl_polyhedron = C_Polyhedron(gs)
     86        self._init_Vrepresentation_from_ppl(minimize)
     87        self._init_Hrepresentation_from_ppl(minimize)
     88
     89
     90    def _init_from_Hrepresentation(self, ambient_dim, ieqs, eqns, minimize=True):
     91        """
     92        Construct polyhedron from H-representation data.
     93
     94        INPUT:
     95
     96        - ``ambient_dim`` -- integer. The dimension of the ambient space.
     97       
     98        - ``ieqs`` -- list of inequalities. Each line can be specified
     99          as any iterable container of
     100          :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
     101
     102        - ``eqns`` -- list of equalities. Each line can be specified
     103          as any iterable container of
     104          :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
     105
     106        EXAMPLES::
     107
     108            sage: p = Polyhedron(backend='ppl')
     109            sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_QQ_ppl
     110            sage: Polyhedron_QQ_ppl._init_from_Hrepresentation(p, 2, [], [])
     111        """
     112        cs = Constraint_System()
     113        if ieqs is None: ieqs = []
     114        for ieq in ieqs:
     115            d = lcm([denominator(ieq_i) for ieq_i in ieq])
     116            dieq = [ ZZ(d*ieq_i) for ieq_i in ieq ]
     117            b = dieq[0]
     118            A = dieq[1:]
     119            cs.insert(Linear_Expression(A, b) >= 0)
     120        if eqns is None: eqns = []
     121        for eqn in eqns:
     122            d = lcm([denominator(eqn_i) for eqn_i in eqn])
     123            deqn = [ ZZ(d*eqn_i) for eqn_i in eqn ]
     124            b = deqn[0]
     125            A = deqn[1:]
     126            cs.insert(Linear_Expression(A, b) == 0)
     127        self._ppl_polyhedron = C_Polyhedron(cs)
     128        self._init_Vrepresentation_from_ppl(minimize)
     129        self._init_Hrepresentation_from_ppl(minimize)
     130
     131       
     132    def _init_Vrepresentation_from_ppl(self, minimize):
     133        """
     134        Create the Vrepresentation objects from the ppl polyhedron.
     135       
     136        EXAMPLES::
     137
     138            sage: p = Polyhedron(vertices=[(0,1/2),(2,0),(4,5/6)],
     139            ...                  backend='ppl')  # indirect doctest
     140            sage: p.Hrepresentation()
     141            (An inequality (1, 4) x - 2 >= 0,
     142             An inequality (1, -12) x + 6 >= 0,
     143             An inequality (-5, 12) x + 10 >= 0)
     144            sage: p._ppl_polyhedron.minimized_constraints()
     145            Constraint_System {x0+4*x1-2>=0, x0-12*x1+6>=0, -5*x0+12*x1+10>=0}
     146            sage: p.Vrepresentation()
     147            (A vertex at (0, 1/2), A vertex at (2, 0), A vertex at (4, 5/6))
     148            sage: p._ppl_polyhedron.minimized_generators()
     149            Generator_System {point(0/2, 1/2), point(2/1, 0/1), point(24/6, 5/6)}
     150        """
     151        self._Vrepresentation = []
     152        gs = self._ppl_polyhedron.minimized_generators()
     153        for g in gs:
     154            if g.is_point():
     155                d = g.divisor()
     156                Vertex(self, [x/d for x in g.coefficients()])
     157            elif g.is_ray():
     158                Ray(self, g.coefficients())
     159            elif g.is_line():
     160                Line(self, g.coefficients())
     161            else:
     162                assert False
     163        self._Vrepresentation = tuple(self._Vrepresentation)
     164       
     165
     166    def _init_Hrepresentation_from_ppl(self, minimize):
     167        """
     168        Create the Vrepresentation objects from the ppl polyhedron.
     169       
     170        EXAMPLES::
     171
     172            sage: p = Polyhedron(vertices=[(0,1/2),(2,0),(4,5/6)],
     173            ...                  backend='ppl')  # indirect doctest
     174            sage: p.Hrepresentation()
     175            (An inequality (1, 4) x - 2 >= 0,
     176             An inequality (1, -12) x + 6 >= 0,
     177             An inequality (-5, 12) x + 10 >= 0)
     178            sage: p._ppl_polyhedron.minimized_constraints()
     179            Constraint_System {x0+4*x1-2>=0, x0-12*x1+6>=0, -5*x0+12*x1+10>=0}
     180            sage: p.Vrepresentation()
     181            (A vertex at (0, 1/2), A vertex at (2, 0), A vertex at (4, 5/6))
     182            sage: p._ppl_polyhedron.minimized_generators()
     183            Generator_System {point(0/2, 1/2), point(2/1, 0/1), point(24/6, 5/6)}
     184        """
     185        self._Hrepresentation = []
     186        cs = self._ppl_polyhedron.minimized_constraints()
     187        for c in cs:
     188            if c.is_inequality():
     189                Inequality(self, (c.inhomogeneous_term(),) + c.coefficients())
     190            elif c.is_equality():
     191                Equation(self, (c.inhomogeneous_term(),) + c.coefficients())
     192        self._Hrepresentation = tuple(self._Hrepresentation)
     193       
     194
     195    def _init_empty_polyhedron(self, ambient_dim):
     196        """
     197        Initializes an empty polyhedron.
     198
     199        INPUT:
     200
     201        - ``ambient_dim`` -- integer. The dimension of the ambient space.
     202
     203        TESTS::
     204
     205            sage: empty = Polyhedron(backend='ppl'); empty
     206            The empty polyhedron in QQ^0
     207            sage: empty.Vrepresentation()
     208            ()
     209            sage: empty.Hrepresentation()
     210            (An equation -1 == 0,)
     211            sage: Polyhedron(vertices = [], backend='ppl')
     212            The empty polyhedron in QQ^0
     213            sage: Polyhedron(backend='ppl')._init_empty_polyhedron(0)
     214        """
     215        super(Polyhedron_QQ_ppl, self)._init_empty_polyhedron(ambient_dim)
     216        self._ppl_polyhedron = C_Polyhedron(ambient_dim, 'empty')
     217
     218
  • sage/geometry/polyhedron/base.py

    diff --git a/sage/geometry/polyhedron/base.py b/sage/geometry/polyhedron/base.py
    a b  
    580580            H-representation
    581581            begin
    582582             4 3 rational
     583             1 1 0
    583584             1 0 1
    584              1 1 0
     585             1 -1 0
    585586             1 0 -1
    586              1 -1 0
    587587            end
    588588        """
    589         from cdd_representation import cdd_Hrepresentation
     589        from cdd_file_format import cdd_Hrepresentation
    590590        try:
    591591            cdd_type = self._cdd_type
    592592        except AttributeError:
     
    614614            V-representation
    615615            begin
    616616             4 3 rational
     617             1 0 0
     618             1 0 1
     619             1 1 0
    617620             1 1 1
    618              1 0 0
    619              1 1 0
    620              1 0 1
    621621            end
    622622        """
    623         from cdd_representation import cdd_Vrepresentation
     623        from cdd_file_format import cdd_Vrepresentation
    624624        try:
    625625            cdd_type = self._cdd_type
    626626        except AttributeError:
     
    761761       
    762762            sage: p = polytopes.n_cube(3)
    763763            sage: p.Hrepresentation(0)
    764             An inequality (0, 0, 1) x + 1 >= 0
     764            An inequality (0, 0, -1) x + 1 >= 0
    765765            sage: p.Hrepresentation(0) == p.Hrepresentation() [0]
    766766            True
    767767        """
     
    780780       
    781781            sage: p = polytopes.n_cube(3)
    782782            sage: p.Hrep_generator().next()
    783             An inequality (0, 0, 1) x + 1 >= 0
     783            An inequality (0, 0, -1) x + 1 >= 0
    784784        """
    785785        for H in self.Hrepresentation():
    786786            yield H
     
    826826
    827827            sage: p = polytopes.n_simplex(4)
    828828            sage: p.Vrepresentation(0)
    829             A vertex at (0, 0, 0, -44721/50000)
     829            A vertex at (-7071/10000, 1633/4000, 7217/25000, 22361/100000)
    830830            sage: p.Vrepresentation(0) == p.Vrepresentation() [0]
    831831            True
    832832        """
     
    882882
    883883        .. NOTE::
    884884
    885             Instead of working with face indices, you can use the
    886             H-representation objects directly (see example).
     885            Instead of working with face indices, it is recommended
     886            that you use the H-representation objects directly (see
     887            example).
    887888
    888889        EXAMPLES::
    889890
    890891            sage: p = polytopes.permutahedron(4)
    891892            sage: p.facial_adjacencies()[0:3]
    892             [[0, [1, 2, 12, 13]], [1, [0, 2, 3, 6, 8, 13]], [2, [0, 1, 3, 4, 7, 12]]]
     893            [[0, [1, 2, 5, 10, 12, 13]], [1, [0, 2, 5, 7, 9, 11]], [2, [0, 1, 10, 11]]]
    893894            sage: f0 = p.Hrepresentation(0)
    894895            sage: f0.index() == 0
    895896            True
     
    913914       
    914915        .. NOTE::
    915916
    916             Instead of working with face/vertex indices, you can use
    917             the H-representation/V-representation objects directly
    918             (see examples).
     917            Instead of working with face/vertex indices, it is
     918            recommended that you use the
     919            H-representation/V-representation objects directly (see
     920            examples). Or use :meth:`incidence_matrix`.
    919921
    920922        OUTPUT:
    921923
     
    927929
    928930            sage: p = Polyhedron(vertices = [[5,0,0],[0,5,0],[5,5,0],[0,0,0],[2,2,5]])
    929931            sage: p.facial_incidences()
    930             [[0, [1, 3, 4]],
    931             [1, [0, 3, 4]],
    932             [2, [0, 2, 4]],
    933             [3, [1, 2, 4]],
    934             [4, [0, 1, 2, 3]]]
     932            [[0, [0, 1, 3, 4]],
     933             [1, [0, 1, 2]],
     934             [2, [0, 2, 3]],
     935             [3, [2, 3, 4]],
     936             [4, [1, 2, 4]]]
     937
    935938            sage: f0 = p.Hrepresentation(0)
    936939            sage: f0.index() == 0
    937940            True
    938941            sage: f0_incidences = [f0.index(), [v.index() for v in f0.incident()]]
    939942            sage: p.facial_incidences()[0] == f0_incidences
    940943            True
     944
     945            sage: p.incidence_matrix().column(0)
     946            (1, 1, 0, 1, 1)
     947            sage: p.incidence_matrix().column(1)
     948            (1, 1, 1, 0, 0)
     949            sage: p.incidence_matrix().column(2)
     950            (1, 0, 1, 1, 0)
     951            sage: p.incidence_matrix().column(3)
     952            (0, 0, 1, 1, 1)
     953            sage: p.incidence_matrix().column(4)
     954            (0, 1, 1, 0, 1)
    941955        """
    942956        try:
    943957            return self._facial_incidences
     
    10011015
    10021016            sage: p = polytopes.n_simplex(3)
    10031017            sage: p.vertex_incidences()
    1004             [[0, [0, 1, 3]], [1, [0, 2, 3]], [2, [1, 2, 3]], [3, [0, 1, 2]]]
     1018            [[0, [0, 1, 2]], [1, [0, 1, 3]], [2, [0, 2, 3]], [3, [1, 2, 3]]]
    10051019            sage: v0 = p.Vrepresentation(0)
    10061020            sage: v0.index() == 0
    10071021            True
     
    10311045
    10321046            sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[1,1]])
    10331047            sage: for v in triangle.inequality_generator(): print(v)
     1048            An inequality (1, 1) x - 1 >= 0
     1049            An inequality (0, -1) x + 1 >= 0
    10341050            An inequality (-1, 0) x + 1 >= 0
    1035             An inequality (0, -1) x + 1 >= 0
    1036             An inequality (1, 1) x - 1 >= 0
    10371051            sage: [ v for v in triangle.inequality_generator() ]
    1038             [An inequality (-1, 0) x + 1 >= 0,
    1039              An inequality (0, -1) x + 1 >= 0,
    1040              An inequality (1, 1) x - 1 >= 0]
     1052            [An inequality (1, 1) x - 1 >= 0,
     1053             An inequality (0, -1) x + 1 >= 0, 
     1054             An inequality (-1, 0) x + 1 >= 0]
    10411055            sage: [ [v.A(), v.b()] for v in triangle.inequality_generator() ]
    1042             [[(-1, 0), 1], [(0, -1), 1], [(1, 1), -1]]
     1056            [[(1, 1), -1], [(0, -1), 1], [(-1, 0), 1]]
    10431057        """
    10441058        for H in self.Hrepresentation():
    10451059            if H.is_inequality():
     
    10601074
    10611075            sage: p = Polyhedron(vertices = [[0,0,0],[0,0,1],[0,1,0],[1,0,0],[2,2,2]])
    10621076            sage: p.inequalities()[0:3]
    1063             [[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0]]
     1077            [[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
    10641078            sage: p3 = Polyhedron(vertices = permutations([1,2,3,4]))
    10651079            sage: ieqs = p3.inequalities()
    10661080            sage: ieqs[0]
    1067             [-1, 0, 0, 1, 0]
     1081            [-6, 0, 1, 1, 1]
    10681082            sage: ieqs[-1]
    1069             [4, -1, 0, 0, 0]
     1083            [-3, 0, 1, 0, 1]
    10701084            sage: ieqs == [list(x) for x in p3.inequality_generator()]
    10711085            True
    10721086        """
     
    11641178
    11651179            sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[1,1]])
    11661180            sage: triangle.vertices()
    1167             [[1, 0], [0, 1], [1, 1]]
    1168             sage: a_simplex = Polyhedron(ieqs = [[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1]], eqns = [[1,-1,-1,-1,-1]])
     1181            [[0, 1], [1, 0], [1, 1]]
     1182            sage: a_simplex = Polyhedron(ieqs = [
     1183            ...            [0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1]
     1184            ...        ], eqns = [[1,-1,-1,-1,-1]])
    11691185            sage: a_simplex.vertices()
    1170             [[0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]]
     1186            [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
    11711187            sage: a_simplex.vertices() == [list(v) for v in a_simplex.vertex_generator()]
    11721188            True
    11731189        """
     
    11861202
    11871203            sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[1,1]])
    11881204            sage: for v in triangle.vertex_generator(): print(v)
     1205            A vertex at (0, 1)
    11891206            A vertex at (1, 0)
    1190             A vertex at (0, 1)
    11911207            A vertex at (1, 1)
    11921208            sage: v_gen = triangle.vertex_generator()   
    11931209            sage: v_gen.next()   # the first vertex
    1194             A vertex at (1, 0)
     1210            A vertex at (0, 1)
    11951211            sage: v_gen.next()   # the second vertex 
    1196             A vertex at (0, 1)
     1212            A vertex at (1, 0)
    11971213            sage: v_gen.next()   # the third vertex
    11981214            A vertex at (1, 1)
    11991215            sage: try: v_gen.next()   # there are only three vertices
     
    12021218            sage: type(v_gen)
    12031219            <type 'generator'>
    12041220            sage: [ v for v in triangle.vertex_generator() ]
    1205             [A vertex at (1, 0), A vertex at (0, 1), A vertex at (1, 1)]
    1206 
     1221            [A vertex at (0, 1), A vertex at (1, 0), A vertex at (1, 1)]
    12071222        """
    12081223        for V in self.Vrepresentation():
    12091224            if V.is_vertex():
     
    13061321
    13071322            sage: p = Polyhedron(vertices=[[1,0],[0,1]], rays=[[1,0],[0,1]])
    13081323            sage: [ e for e in p.bounded_edges() ]
    1309             [(A vertex at (1, 0), A vertex at (0, 1))]
     1324            [(A vertex at (0, 1), A vertex at (1, 0))]
    13101325            sage: for e in p.bounded_edges(): print e
    1311             (A vertex at (1, 0), A vertex at (0, 1))
     1326            (A vertex at (0, 1), A vertex at (1, 0))
    13121327        """
    13131328        obj = self.Vrepresentation()
    13141329        edges = []
     
    13201335                yield (obj[i], obj[j])
    13211336
    13221337
     1338    @cached_method
     1339    def ambient_space(self):
     1340        r"""
     1341        Return the ambient vector space.
     1342       
     1343        OUTPUT:
     1344       
     1345        A free module over the base ring of dimension :meth:`ambient_dim`.
     1346       
     1347        EXAMPLES::
     1348
     1349            sage: poly_test = Polyhedron(vertices = [[1,0,0,0],[0,1,0,0]])
     1350            sage: poly_test.ambient_space()
     1351            Vector space of dimension 4 over Rational Field
     1352        """
     1353        from sage.modules.free_module import VectorSpace
     1354        return VectorSpace(self.base_ring(), self.ambient_dim())
     1355
     1356    Vrepresentation_space = ambient_space
     1357
     1358    @cached_method
     1359    def Hrepresentation_space(self):
     1360        r"""
     1361        Return the linear space containing the H-representation vectors.
     1362
     1363        OUTPUT:
     1364       
     1365        A free module over the base ring of dimension :meth:`ambient_dim` + 1.
     1366       
     1367        EXAMPLES::
     1368       
     1369            sage: poly_test = Polyhedron(vertices = [[1,0,0,0],[0,1,0,0]])
     1370            sage: poly_test.ambient_space()
     1371            Vector space of dimension 4 over Rational Field
     1372        """
     1373        from sage.modules.free_module import VectorSpace
     1374        return VectorSpace(self.base_ring(), self.ambient_dim()+1)
     1375
     1376
    13231377    def ambient_dim(self):
    13241378        r"""
    13251379        Return the dimension of the ambient space.
     
    14181472       
    14191473            sage: p = polytopes.cuboctahedron()
    14201474            sage: p.incidence_matrix()   
    1421             [0 0 1 0 0 1 0 0 1 1 0 0 0 0]
    1422             [0 0 0 1 0 0 0 0 0 1 1 0 1 0]
    1423             [0 1 1 0 0 0 0 0 1 0 0 0 0 1]
    1424             [0 0 0 0 0 0 0 0 0 0 1 1 1 1]
    1425             [1 1 0 0 0 0 0 0 0 0 0 1 0 1]
    1426             [0 0 0 0 0 0 0 0 1 1 1 0 0 1]
    1427             [1 0 0 0 0 0 0 1 0 0 0 1 1 0]
    1428             [1 1 1 0 0 0 1 0 0 0 0 0 0 0]
    1429             [1 0 0 0 1 0 1 1 0 0 0 0 0 0]
    1430             [0 0 0 1 1 0 0 1 0 0 0 0 1 0]
    1431             [0 0 0 1 1 1 0 0 0 1 0 0 0 0]
    1432             [0 0 1 0 1 1 1 0 0 0 0 0 0 0]
     1475            [0 0 1 1 0 1 0 0 0 0 1 0 0 0]
     1476            [0 0 0 1 0 0 1 0 1 0 1 0 0 0]
     1477            [0 0 1 1 1 0 0 1 0 0 0 0 0 0]
     1478            [1 0 0 1 1 0 1 0 0 0 0 0 0 0]
     1479            [0 0 0 0 0 1 0 0 1 1 1 0 0 0]
     1480            [0 0 1 0 0 1 0 1 0 0 0 1 0 0]
     1481            [1 0 0 0 0 0 1 0 1 0 0 0 1 0]
     1482            [1 0 0 0 1 0 0 1 0 0 0 0 0 1]
     1483            [0 1 0 0 0 1 0 0 0 1 0 1 0 0]
     1484            [0 1 0 0 0 0 0 0 1 1 0 0 1 0]
     1485            [0 1 0 0 0 0 0 1 0 0 0 1 0 1]
     1486            [1 1 0 0 0 0 0 0 0 0 0 0 1 1]
    14331487            sage: v = p.Vrepresentation(0)
    14341488            sage: v                         
    1435             A vertex at (0, -1/2, -1/2)
     1489            A vertex at (-1/2, -1/2, 0)
    14361490            sage: h = p.Hrepresentation(2)
    14371491            sage: h
    1438             An inequality (0, 2, 0) x + 1 >= 0
    1439             sage: h.eval(v)        # evaluation (0, 2, 0) * (0, -1/2, -1/2) + 1
     1492            An inequality (1, 1, -1) x + 1 >= 0
     1493            sage: h.eval(v)        # evaluation (1, 1, -1) * (-1/2, -1/2, 0) + 1
    14401494            0
    14411495            sage: h*v              # same as h.eval(v)
    14421496            0
     
    17481802        EXAMPLES::
    17491803
    17501804            sage: cube = polytopes.n_cube(3)
    1751             sage: triangulation = cube.triangulate(engine='internal') # to make doctest independent of TOPCOM
     1805            sage: triangulation = cube.triangulate(
     1806            ...      engine='internal') # to make doctest independent of TOPCOM
    17521807            sage: triangulation
    1753             (<0,1,2,4>, <1,2,3,4>, <1,3,4,5>, <2,3,4,6>, <3,4,5,6>, <3,5,6,7>)
     1808            (<0,1,2,7>, <0,1,4,7>, <0,2,4,7>, <1,2,3,7>, <1,4,5,7>, <2,4,6,7>)
    17541809            sage: simplex_indices = triangulation[0]; simplex_indices
    1755             (0, 1, 2, 4)
     1810            (0, 1, 2, 7)
    17561811            sage: simplex_vertices = [ cube.Vrepresentation(i) for i in simplex_indices ]
    17571812            sage: simplex_vertices
    1758             [A vertex at (1, 1, 1), A vertex at (-1, 1, 1),
    1759              A vertex at (1, -1, 1), A vertex at (1, 1, -1)]
     1813            [A vertex at (-1, -1, -1), A vertex at (-1, -1, 1),
     1814             A vertex at (-1, 1, -1), A vertex at (1, 1, 1)]
    17601815            sage: Polyhedron(simplex_vertices)
    17611816            A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
    17621817        """
     
    17851840
    17861841        If the figure is already composed of triangles, then all is well::
    17871842
    1788             sage: Polyhedron(vertices = [[5,0,0],[0,5,0],[5,5,0],[2,2,5]]).triangulated_facial_incidences()
     1843            sage: Polyhedron(vertices = [[5,0,0],[0,5,0],[5,5,0],[2,2,5]]
     1844            ...             ).triangulated_facial_incidences()
    17891845            doctest:...: DeprecationWarning: (Since Sage Version 4.7.1)
    17901846            This method is deprecated. Use triangulate() instead.
    1791             [[0, [0, 2, 3]], [1, [0, 1, 2]], [2, [1, 2, 3]], [3, [0, 1, 3]]]
     1847            [[0, [0, 1, 2]], [1, [0, 1, 3]], [2, [0, 2, 3]], [3, [1, 2, 3]]]
    17921848                             
    17931849        Otherwise some faces get split up to triangles::
    17941850
    1795             p = polytopes.regular_polygon(5)
    1796             sage: Polyhedron(vertices = [[2,0,0],[4,1,0],[0,5,0],[5,5,0],[1,1,0],[0,0,1]]).triangulated_facial_incidences()
    1797             [[0, [0, 1, 5]], [1, [0, 4, 5]], [2, [2, 4, 5]], [3, [2, 3, 5]], [4, [1, 3, 5]], [5, [0, 1, 4]], [5, [1, 4, 3]], [5, [4, 3, 2]]]
     1851            sage: Polyhedron(vertices = [[2,0,0],[4,1,0],[0,5,0],[5,5,0],
     1852            ...       [1,1,0],[0,0,1]]).triangulated_facial_incidences()
     1853            doctest:...: DeprecationWarning: (Since Sage Version 4.7.1)
     1854            This method is deprecated. Use triangulate() instead.
     1855            [[0, [1, 2, 5]], [0, [2, 5, 3]], [0, [5, 3, 4]], [1, [0, 1, 2]],
     1856             [2, [0, 2, 3]], [3, [0, 3, 4]], [4, [0, 4, 5]], [5, [0, 1, 5]]]
    17981857        """
    17991858        from sage.misc.misc import deprecation
    18001859        deprecation('This method is deprecated. Use triangulate() instead.', 'Sage Version 4.7.1')
     
    21942253            sage: square.face_lattice()
    21952254            Finite poset containing 10 elements
    21962255            sage: list(_)
    2197             [<>, <0>, <1>, <2>, <3>, <2,3>, <1,3>, <0,1>, <0,2>, <0,1,2,3>]
     2256            [<>, <0>, <1>, <2>, <3>, <0,1>, <0,2>, <2,3>, <1,3>, <0,1,2,3>]
    21982257            sage: poset_element = _[6]
    21992258            sage: a_face = poset_element.element
    22002259            sage: a_face
    2201             <1,3>
     2260            <0,2>
    22022261            sage: a_face.dim()
    22032262            1
    22042263            sage: set(a_face.ambient_Vrepresentation()) == \
    2205             ...   set([square.Vrepresentation(1), square.Vrepresentation(3)])
     2264            ...   set([square.Vrepresentation(0), square.Vrepresentation(2)])
    22062265            True
    22072266            sage: a_face.ambient_Vrepresentation()
    2208             (A vertex at (-1, 1), A vertex at (-1, -1))
     2267            (A vertex at (-1, -1), A vertex at (1, -1))
    22092268            sage: a_face.ambient_Hrepresentation()
    2210             (An inequality (1, 0) x + 1 >= 0,)
     2269            (An inequality (0, 1) x + 1 >= 0,)
    22112270           
    22122271        A more complicated example::
    22132272
     
    22262285
    22272286        TESTS::
    22282287
    2229             sage: c5_20 = Polyhedron(vertices = [[i,i^2,i^3,i^4,i^5] for i in range(1,21)]) # not tested - very long time
    2230             sage: c5_20_fl = c5_20.face_lattice() # not tested - very long time
    2231             sage: [len(x) for x in c5_20_fl.level_sets()] # not tested - very long time
     2288            sage: c5_20 = Polyhedron(vertices = [[i,i^2,i^3,i^4,i^5]
     2289            ...       for i in range(1,21)])
     2290            sage: c5_20_fl = c5_20.face_lattice() # long time
     2291            sage: [len(x) for x in c5_20_fl.level_sets()] # long time
    22322292            [1, 20, 190, 580, 680, 272, 1]
    22332293            sage: polytopes.n_cube(2).face_lattice().plot()
    22342294            sage: level_sets = polytopes.cross_polytope(2).face_lattice().level_sets()
     
    22382298        Various degenerate polyhedra::
    22392299
    22402300            sage: Polyhedron(vertices=[[0,0,0],[1,0,0],[0,1,0]]).face_lattice().level_sets()
    2241             [[<>], [<0>, <1>, <2>], [<0,1>, <1,2>, <0,2>], [<0,1,2>]]
     2301            [[<>], [<0>, <1>, <2>], [<0,1>, <0,2>, <1,2>], [<0,1,2>]]
    22422302            sage: Polyhedron(vertices=[(1,0,0),(0,1,0)], rays=[(0,0,1)]).face_lattice().level_sets()
    22432303            [[<>], [<1>, <2>], [<0,1>, <0,2>, <1,2>], [<0,1,2>]]
    22442304            sage: Polyhedron(rays=[(1,0,0),(0,1,0)], vertices=[(0,0,1)]).face_lattice().level_sets()
    2245             [[<>], [<2>], [<1,2>, <0,2>], [<0,1,2>]]
     2305            [[<>], [<0>], [<0,1>, <0,2>], [<0,1,2>]]
    22462306            sage: Polyhedron(rays=[(1,0),(0,1)], vertices=[(0,0)]).face_lattice().level_sets()
    2247             [[<>], [<2>], [<1,2>, <0,2>], [<0,1,2>]]
     2307            [[<>], [<0>], [<0,1>, <0,2>], [<0,1,2>]]
    22482308            sage: Polyhedron(vertices=[(1,),(0,)]).face_lattice().level_sets()
    22492309            [[<>], [<0>, <1>], [<0,1>]]
    22502310            sage: Polyhedron(vertices=[(1,0,0),(0,1,0)], lines=[(0,0,1)]).face_lattice().level_sets()
     
    22532313            [[<>], [<0,1>]]
    22542314            sage: Polyhedron(lines=[(1,0),(0,1)], vertices=[(0,0)]).face_lattice().level_sets()
    22552315            [[<>], [<0,1,2>]]
    2256             sage: Polyhedron(lines=[(1,0)], rays=[(0,1)], vertices=[(0,0)]).face_lattice().level_sets()
    2257             [[<>], [<0,2>], [<0,1,2>]]
     2316            sage: Polyhedron(lines=[(1,0)], rays=[(0,1)], vertices=[(0,0)])\
     2317            ...       .face_lattice().level_sets()
     2318            [[<>], [<0,1>], [<0,1,2>]]
    22582319            sage: Polyhedron(vertices=[(0,)], lines=[(1,)]).face_lattice().level_sets()
    22592320            [[<>], [<0,1>]]
    22602321            sage: Polyhedron(lines=[(1,0)], vertices=[(0,0)]).face_lattice().level_sets()
     
    23922453            sage: egyptian_pyramid.n_vertices()
    23932454            5
    23942455            sage: for v in egyptian_pyramid.vertex_generator(): print v
    2395             A vertex at (0, 1, 1)
     2456            A vertex at (0, -1, -1)
    23962457            A vertex at (0, -1, 1)
    23972458            A vertex at (0, 1, -1)
    2398             A vertex at (0, -1, -1)
     2459            A vertex at (0, 1, 1)
    23992460            A vertex at (1, 0, 0)
    24002461        """
    24012462        new_verts = \
     
    24172478            8
    24182479            sage: q = [list(v) for v in cross_poly_4d.vertex_generator()]
    24192480            sage: q
    2420             [[0, 0, 0, 1],
    2421              [0, 0, 1, 0],
    2422              [0, 1, 0, 0],
    2423              [0, 0, 0, -1],
    2424              [0, 0, -1, 0],
    2425              [0, -1, 0, 0],
    2426              [1, 0, 0, 0],
    2427              [-1, 0, 0, 0]]
     2481            [[-1, 0, 0, 0],
     2482             [0, -1, 0, 0],
     2483             [0, 0, -1, 0],
     2484             [0, 0, 0, -1], 
     2485             [0, 0, 0, 1],
     2486             [0, 0, 1, 0],
     2487             [0, 1, 0, 0],
     2488             [1, 0, 0, 0]]
    24282489       
    24292490        Now check that bipyramids of cross-polytopes are cross-polytopes::
    24302491
     
    25322593            sage: schlegel_edge_indices = sch_proj.lines
    25332594            sage: schlegel_edges = [sch_proj.coordinates_of(x) for x in schlegel_edge_indices]
    25342595            sage: len([x for x in schlegel_edges if x[0][0] > 0])
    2535             8
     2596            4
    25362597        """
    25372598        proj = self.projection()
    25382599        if projection_dir == None:
     
    28562917            sage: lp = P.lattice_polytope(); lp
    28572918            A lattice polytope: 2-dimensional, 4 vertices.
    28582919            sage: lp.vertices()
    2859             [ 1  0 -1  0]
    2860             [ 0  1  0 -1]
     2920            [-1  0  0  1]
     2921            [ 0 -1  1  0]
    28612922
    28622923        Here is a polyhedron with non-integral vertices::
    28632924
     
    28712932            sage: lp = P.lattice_polytope(True); lp
    28722933            A lattice polytope: 2-dimensional, 5 vertices.
    28732934            sage: lp.vertices()
    2874             [ 0  1  1 -1  0]
    2875             [ 1  0  1  0 -1]
     2935            [-1  0  0  1  1]
     2936            [ 0 -1  1  0  1]
    28762937        """
    28772938        if not self.is_compact():
    28782939            raise NotImplementedError, 'Only compact lattice polytopes are allowed.'
     
    29292990        EXAMPLES::
    29302991       
    29312992            sage: Polyhedron(vertices=[(-1,-1),(1,0),(1,1),(0,1)])._integral_points_PALP()
    2932             [(-1, -1), (1, 0), (1, 1), (0, 1), (0, 0)]
     2993            [(-1, -1), (0, 1), (1, 0), (1, 1), (0, 0)]
    29332994            sage: Polyhedron(vertices=[(-1/2,-1/2),(1,0),(1,1),(0,1)]).lattice_polytope(True).points()
    2934             [ 0 -1 -1  1  1  0  0]
    2935             [-1  0 -1  0  1  1  0]
     2995            [ 0 -1 -1  0  1  1  0]
     2996            [-1  0 -1  1  0  1  0]
    29362997            sage: Polyhedron(vertices=[(-1/2,-1/2),(1,0),(1,1),(0,1)])._integral_points_PALP()
    2937             [(1, 0), (1, 1), (0, 1), (0, 0)]
     2998            [(0, 1), (1, 0), (1, 1), (0, 0)]
    29382999        """
    29393000        if not self.is_compact():
    29403001            raise ValueError, 'Can only enumerate points in a compact polyhedron.'
     
    31633224        A ``self.dim()``-dimensional coordinate vector. It contains
    31643225        the coordinates of ``v`` in an arbitrary but fixed basis for
    31653226        the affine span of the polyhedron.
    3166 
     3227       
    31673228        EXAMPLES::
    31683229       
    31693230            sage: P = Polyhedron(rays=[(1,0,0),(0,1,0)])
    31703231            sage: P._affine_coordinates( (-1,-2,-3) )
    31713232            (-1, -2)
    31723233            sage: [ P._affine_coordinates(v) for v in P.Vrep_generator() ]
    3173             [(1, 0), (0, 1), (0, 0)]
     3234            [(0, 0), (0, 1), (1, 0)]
    31743235        """
    31753236        if '_affine_coordinates_pivots' not in self.__dict__:
    31763237            v_list = [ vector(v) for v in self.Vrepresentation() ]
     
    32743335
    32753336            sage: P = polytopes.cross_polytope(3)
    32763337            sage: AutP = P.restricted_automorphism_group();  AutP
    3277             Permutation Group with generators [(3,6), (2,3)(5,6), (2,5), (1,2)(4,5), (1,4)]
     3338            Permutation Group with generators [(3,4), (2,3)(4,5), (2,5), (1,2)(5,6), (1,6)]
    32783339            sage: P24 = polytopes.twenty_four_cell()
    32793340            sage: AutP24 = P24.restricted_automorphism_group()
    3280             sage: PermutationGroup([   # computed with sympow
    3281             ...    [(1,2),(3,4),(5,6),(7,8),(9,10),(11,12),(13,14),(15,16),(17,21)],
    3282             ...    [(1,5),(2,6),(3,7),(4,8),(9,13),(10,14),(11,15),(12,16),(19,23)],
    3283             ...    [(2,5),(4,7),(10,13),(12,15),(17,19),(21,23)],
    3284             ...    [(1,3),(2,4),(5,7),(6,8),(9,11),(10,12),(13,15),(14,16),(18,22)],
    3285             ...    [(3,5),(4,6),(11,13),(12,14),(18,19),(22,23)],
    3286             ...    [(1,9),(2,10),(3,11),(4,12),(5,13),(6,14),(7,15),(8,16),(20,24)],
    3287             ...    [(3,9),(4,10),(7,13),(8,14),(18,20),(22,24)],
    3288             ...    [(1,3,11,9),(2,4,12,10),(5,7,15,13),(6,8,16,14),(18,20,22,24)],
    3289             ...    [(3,9,5),(4,10,6),(7,11,13),(8,12,14),(18,20,19),(22,24,23)],
    3290             ...    [(1,5,7,15,11,9),(2,6,8,16,12,10),(3,13),(4,14),(18,20,23,22,24,19)],
    3291             ...    [(2,5,3,9),(4,13),(6,7,11,10),(8,15,12,14),(17,19,18,20),(21,23,22,24)],
    3292             ...    [(1,2,6,8,16,15,11,9),(3,10,5,4,14,7,12,13),(17,19,18,20,21,23,22,24)],
    3293             ...    [(1,12,20,16,5,24),(2,21,6,14,18,10),(3,22,7,15,17,11),(4,8,23,13,9,19)]
    3294             ...   ]) == AutP24           
     3341            sage: PermutationGroup([
     3342            ...     '(3,6)(4,7)(10,11)(14,15)(18,21)(19,22)',
     3343            ...     '(2,3)(7,8)(11,12)(13,14)(17,18)(22,23)',
     3344            ...     '(2,5)(3,10)(6,11)(8,17)(9,13)(12,16)(14,19)(15,22)(20,23)',
     3345            ...     '(2,10)(3,5)(6,12)(7,18)(9,14)(11,16)(13,19)(15,23)(20,22)',
     3346            ...     '(2,11)(3,12)(4,21)(5,6)(9,15)(10,16)(13,22)(14,23)(19,20)',
     3347            ...     '(1,2)(3,4)(6,7)(8,9)(12,13)(16,17)(18,19)(21,22)(23,24)',
     3348            ...     '(1,24)(2,13)(3,14)(5,9)(6,15)(10,19)(11,22)(12,23)(16,20)'
     3349            ...   ]) == AutP24
    32953350            True
    32963351
    32973352        Here is the quadrant example mentioned in the beginning::
    32983353
    32993354            sage: P = Polyhedron(rays=[(1,0),(0,1)])
    33003355            sage: P.Vrepresentation()
    3301             (A ray in the direction (1, 0), A ray in the direction (0, 1), A vertex at (0, 0))
     3356            (A vertex at (0, 0), A ray in the direction (0, 1), A ray in the direction (1, 0))
    33023357            sage: P.restricted_automorphism_group()
    3303             Permutation Group with generators [(1,2)]
     3358            Permutation Group with generators [(2,3)]
    33043359
    33053360        Also, the polyhedron need not be full-dimensional::
    33063361
     
    34513506        sage: from sage.geometry.polyhedron.base import PolyhedronFace_base
    34523507        sage: face = PolyhedronFace_base(octahedron, face_v_indices, face_h_indices)
    34533508        sage: face
    3454         <0,4,5>
     3509        <0,1,2>
    34553510        sage: face.dim()
    34563511        2
    34573512        sage: face.ambient_Hrepresentation()
    3458         (An inequality (1, 1, -1) x + 1 >= 0,)
     3513        (An inequality (1, 1, 1) x + 1 >= 0,)
    34593514        sage: face.ambient_Vrepresentation()
    3460         (A vertex at (0, 0, 1), A vertex at (0, -1, 0), A vertex at (-1, 0, 0))
     3515        (A vertex at (-1, 0, 0), A vertex at (0, -1, 0), A vertex at (0, 0, -1))
    34613516    """
    34623517
    34633518    def __init__(self, polyhedron, V_indices, H_indices):
     
    35193574            sage: for fl in square.face_lattice():
    35203575            ...       print fl.element.ambient_Hrepresentation()
    35213576            ...
    3522             (An inequality (0, 1) x + 1 >= 0, An inequality (1, 0) x + 1 >= 0,
    3523              An inequality (0, -1) x + 1 >= 0, An inequality (-1, 0) x + 1 >= 0)
    3524             (An inequality (0, -1) x + 1 >= 0, An inequality (-1, 0) x + 1 >= 0)
     3577            (An inequality (1, 0) x + 1 >= 0, An inequality (0, 1) x + 1 >= 0,
     3578             An inequality (-1, 0) x + 1 >= 0, An inequality (0, -1) x + 1 >= 0)
     3579            (An inequality (1, 0) x + 1 >= 0, An inequality (0, 1) x + 1 >= 0)
    35253580            (An inequality (1, 0) x + 1 >= 0, An inequality (0, -1) x + 1 >= 0)
    35263581            (An inequality (0, 1) x + 1 >= 0, An inequality (-1, 0) x + 1 >= 0)
    3527             (An inequality (0, 1) x + 1 >= 0, An inequality (1, 0) x + 1 >= 0)
     3582            (An inequality (-1, 0) x + 1 >= 0, An inequality (0, -1) x + 1 >= 0)
     3583            (An inequality (1, 0) x + 1 >= 0,)
    35283584            (An inequality (0, 1) x + 1 >= 0,)
    3529             (An inequality (1, 0) x + 1 >= 0,)
     3585            (An inequality (-1, 0) x + 1 >= 0,)
    35303586            (An inequality (0, -1) x + 1 >= 0,)
    3531             (An inequality (-1, 0) x + 1 >= 0,)
    35323587            ()
    35333588        """
    35343589        if index==None:
     
    35633618            ...       print fl.element.ambient_Vrepresentation()
    35643619            ...
    35653620            ()
    3566             (A vertex at (1, 1),)
     3621            (A vertex at (-1, -1),)
    35673622            (A vertex at (-1, 1),)
    35683623            (A vertex at (1, -1),)
    3569             (A vertex at (-1, -1),)
    3570             (A vertex at (1, -1), A vertex at (-1, -1))
    3571             (A vertex at (-1, 1), A vertex at (-1, -1))
    3572             (A vertex at (1, 1), A vertex at (-1, 1))
    3573             (A vertex at (1, 1), A vertex at (1, -1))
    3574             (A vertex at (1, 1), A vertex at (-1, 1), A vertex at (1, -1), A vertex at (-1, -1))
     3624            (A vertex at (1, 1),)
     3625            (A vertex at (-1, -1), A vertex at (-1, 1))
     3626            (A vertex at (-1, -1), A vertex at (1, -1))
     3627            (A vertex at (1, -1), A vertex at (1, 1))
     3628            (A vertex at (-1, 1), A vertex at (1, 1))
     3629            (A vertex at (-1, -1), A vertex at (-1, 1),
     3630             A vertex at (1, -1), A vertex at (1, 1))
    35753631        """
    35763632        if index==None:
    35773633            return self._ambient_Vrepresentation
     
    35973653            sage: face
    35983654            <0,2>
    35993655            sage: face.ambient_Hrepresentation()
    3600             (An inequality (1, -1, -1, -1) x + 1 >= 0,
    3601              An inequality (1, -1, 1, -1) x + 1 >= 0,
    3602              An inequality (-1, -1, 1, -1) x + 1 >= 0,
    3603              An inequality (-1, -1, -1, -1) x + 1 >= 0)
     3656            (An inequality (1, -1, 1, -1) x + 1 >= 0,
     3657             An inequality (1, 1, 1, 1) x + 1 >= 0,
     3658             An inequality (1, 1, 1, -1) x + 1 >= 0,
     3659             An inequality (1, -1, 1, 1) x + 1 >= 0)
    36043660            sage: face.n_ambient_Hrepresentation()
    36053661            4
    36063662        """
     
    36253681            sage: face
    36263682            <0,2>
    36273683            sage: face.ambient_Vrepresentation()
    3628             (A vertex at (0, 0, 0, 1), A vertex at (0, 1, 0, 0))
     3684            (A vertex at (-1, 0, 0, 0), A vertex at (0, 0, -1, 0))
    36293685            sage: face.n_ambient_Vrepresentation()
    36303686            2
    36313687        """
     
    36733729            sage: square = polytopes.n_cube(2)
    36743730            sage: a_face = list( square.face_lattice() )[8].element
    36753731            sage: a_face.__repr__()
    3676             '<0,2>'
     3732            '<1,3>'
    36773733        """
    36783734        s = '<'
    36793735        s += ','.join([ str(v.index()) for v in self.ambient_Vrepresentation() ])
  • 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 b  
    2929
    3030    EXAMPLES::
    3131
    32         sage: from sage.geometry.polyhedron.old import cdd_Vrepresentation
     32        sage: from sage.geometry.polyhedron.cdd_file_format import cdd_Vrepresentation
    3333        sage: print cdd_Vrepresentation('rational', [[0,0]], [[1,0]], [[0,1]])
    3434        V-representation
    3535        linearity 1 1
     
    7777
    7878    EXAMPLES::
    7979
    80         sage: from sage.geometry.polyhedron.old import cdd_Hrepresentation
     80        sage: from sage.geometry.polyhedron.cdd_file_format import cdd_Hrepresentation
    8181        sage: cdd_Hrepresentation('rational', None, [[0,1]])
    8282        'H-representation\nlinearity 1 1\nbegin\n 1 2 rational\n 0 1\nend\n'
    8383    """
  • sage/geometry/polyhedron/constructor.py

    diff --git a/sage/geometry/polyhedron/constructor.py b/sage/geometry/polyhedron/constructor.py
    a b  
    4242    A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 2 vertices and 2 rays
    4343    sage: v = trunc_quadr.vertex_generator().next()  # the first vertex in the internal enumeration
    4444    sage: v
    45     A vertex at (1, 0)
    46     sage: v()
    47     (1, 0)
     45    A vertex at (0, 1)
     46    sage: v.vector()
     47    (0, 1)
    4848    sage: list(v)
    49     [1, 0]
     49    [0, 1]
    5050    sage: len(v)
    5151    2
    5252    sage: v[0] + v[1]
     
    6161    A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 2 vertices and 2 rays
    6262    sage: r = trunc_quadr.ray_generator().next()
    6363    sage: r
    64     A ray in the direction (1, 0)
    65     sage: r()
    66     (1, 0)
     64    A ray in the direction (0, 1)
     65    sage: r.vector()
     66    (0, 1)
    6767    sage: [x for x in v.neighbors()]
    68     [A ray in the direction (1, 0), A vertex at (0, 1)]
     68    [A ray in the direction (0, 1), A ray in the direction (1, 0), A vertex at (1, 0)]
    6969
    7070Inequalities `A \vec{x} + b \geq 0` (and, similarly, equations) are
    7171specified by a list ``[b, A]``::
    7272
    7373    sage: Polyhedron(ieqs = [[0,1,0],[0,0,1],[1,-1,-1]]).Hrepresentation()
    74     (An inequality (1, 0) x + 0 >= 0,
    75      An inequality (0, 1) x + 0 >= 0,
    76      An inequality (-1, -1) x + 1 >= 0)
     74    (An inequality (-1, -1) x + 1 >= 0,
     75     An inequality (1, 0) x + 0 >= 0,
     76     An inequality (0, 1) x + 0 >= 0)
    7777
    7878See :func:`Polyhedron` for a detailed description of all possible ways
    7979to construct a polyhedron.
     
    153153
    154154    - ``backend`` -- string or ``None`` (default). The backend to use. Valid choices are
    155155
    156       * ``'cddr'``: cdd with rational coefficients
     156      * ``'cddr'``: cdd (:mod:`~sage.geometry.polyhedron.backend_cdd`)
     157        with rational coefficients
    157158
    158159      * ``'cddf'``: cdd with floating-point coefficients
    159160
     161      * ``'ppl'``: use ppl
     162        (:mod:`~sage.geometry.polyhedron.backend_ppl`) with `\QQ`
     163        coefficients.
     164
    160165    Some backends support further optional arguments:
    161166
    162167    - ``minimize`` -- boolean (default: ``True``). Whether to
     
    178183        sage: square_from_vertices = Polyhedron(vertices = [[1, 1], [1, -1], [-1, 1], [-1, -1]])
    179184        sage: square_from_ieqs = Polyhedron(ieqs = [[1, 0, 1], [1, 1, 0], [1, 0, -1], [1, -1, 0]])
    180185        sage: list(square_from_ieqs.vertex_generator())
    181         [A vertex at (1, -1),
    182          A vertex at (1, 1),
    183          A vertex at (-1, 1),
     186        [A vertex at (1, -1), 
     187         A vertex at (1, 1), 
     188         A vertex at (-1, 1), 
    184189         A vertex at (-1, -1)]
    185190        sage: list(square_from_vertices.inequality_generator())
    186         [An inequality (0, 1) x + 1 >= 0,
    187          An inequality (1, 0) x + 1 >= 0,
    188          An inequality (0, -1) x + 1 >= 0,
    189          An inequality (-1, 0) x + 1 >= 0]
     191        [An inequality (1, 0) x + 1 >= 0,
     192         An inequality (0, 1) x + 1 >= 0,
     193         An inequality (-1, 0) x + 1 >= 0,
     194         An inequality (0, -1) x + 1 >= 0]
    190195        sage: p = Polyhedron(vertices = [[1.1, 2.2], [3.3, 4.4]], base_ring=RDF)
    191196        sage: p.n_inequalities()
    192197        2
     
    223228        sage: P.dim()
    224229        5
    225230        sage: P.Vrepresentation()
    226         (A vertex at (0, 31/2, 31/2, 0, 0, 0), A vertex at (0, 31/2, 0, 0, 31/2, 0),
     231        (A vertex at (31, 0, 0, 0, 0, 0), A vertex at (0, 0, 0, 0, 0, 31),
    227232         A vertex at (0, 0, 0, 0, 31, 0), A vertex at (0, 0, 31/2, 0, 31/2, 0),
    228          A vertex at (0, 0, 0, 31/2, 31/2, 0), A vertex at (31, 0, 0, 0, 0, 0),
    229          A vertex at (0, 0, 0, 0, 0, 31))
     233         A vertex at (0, 31/2, 31/2, 0, 0, 0), A vertex at (0, 31/2, 0, 0, 31/2, 0),
     234         A vertex at (0, 0, 0, 31/2, 31/2, 0))
    230235
    231236    .. NOTE::
    232237   
     
    267272        ambient_dim = 0
    268273
    269274    if backend is not None:
     275        if backend=='ppl':
     276            from backend_ppl import Polyhedron_QQ_ppl
     277            return Polyhedron_QQ_ppl(ambient_dim, Vrep, Hrep, minimize=minimize)
    270278        if backend=='cddr':
    271279            from backend_cdd import Polyhedron_QQ_cdd
    272280            return Polyhedron_QQ_cdd(ambient_dim, Vrep, Hrep, verbose=verbose)
     
    275283            return Polyhedron_RDF_cdd(ambient_dim, Vrep, Hrep, verbose=verbose)
    276284
    277285    if base_ring is QQ:
    278         from backend_cdd import Polyhedron_QQ_cdd
    279         return Polyhedron_QQ_cdd(ambient_dim, Vrep, Hrep, verbose=verbose)
     286        from backend_ppl import Polyhedron_QQ_ppl
     287        return Polyhedron_QQ_ppl(ambient_dim, Vrep, Hrep, minimize=minimize)
    280288    elif base_ring is RDF:
    281289        from backend_cdd import Polyhedron_RDF_cdd
    282290        return Polyhedron_RDF_cdd(ambient_dim, Vrep, Hrep, verbose=verbose)
  • sage/geometry/polyhedron/library.py

    diff --git a/sage/geometry/polyhedron/library.py b/sage/geometry/polyhedron/library.py
    a b  
    396396            sage: p24 = polytopes.twenty_four_cell()
    397397            sage: v = p24.vertex_generator().next()
    398398            sage: for adj in v.neighbors(): print adj
    399             A vertex at (1/2, 1/2, 1/2, -1/2)
    400             A vertex at (1/2, 1/2, -1/2, 1/2)
    401             A vertex at (1/2, -1/2, 1/2, 1/2)
    402             A vertex at (-1/2, 1/2, 1/2, 1/2)
    403             A vertex at (0, 0, 0, 1)
    404             A vertex at (0, 0, 1, 0)
    405             A vertex at (0, 1, 0, 0)
    406             A vertex at (1, 0, 0, 0)
     399            A vertex at (-1/2, -1/2, -1/2, 1/2)
     400            A vertex at (-1/2, -1/2, 1/2, -1/2)
     401            A vertex at (-1, 0, 0, 0)
     402            A vertex at (-1/2, 1/2, -1/2, -1/2)
     403            A vertex at (0, -1, 0, 0)
     404            A vertex at (0, 0, -1, 0)
     405            A vertex at (0, 0, 0, -1)
     406            A vertex at (1/2, -1/2, -1/2, -1/2)
    407407        """
    408408        verts = []
    409409        q12 = QQ(1)/2
  • sage/geometry/polyhedron/plot.py

    diff --git a/sage/geometry/polyhedron/plot.py b/sage/geometry/polyhedron/plot.py
    a b  
    167167        sage: square = Polyhedron([[1,0],[-1,0],[0,1],[0,-1]])
    168168        sage: vertices = [v for v in square.vertex_generator()]
    169169        sage: vertices
    170         [A vertex at (1, 0),
     170        [A vertex at (-1, 0),
     171         A vertex at (0, -1),
     172         A vertex at (0, 1),
     173         A vertex at (1, 0)]
     174        sage: cyclic_sort_vertices_2d(vertices)
     175        [A vertex at (1, 0),
     176         A vertex at (0, -1),
    171177         A vertex at (-1, 0),
    172          A vertex at (0, 1),
    173          A vertex at (0, -1)]
    174         sage: cyclic_sort_vertices_2d(vertices)
    175         [A vertex at (0, -1),
    176          A vertex at (1, 0),
    177          A vertex at (0, 1),
    178          A vertex at (-1, 0)]
     178         A vertex at (0, 1)]
    179179    """
    180180    if len(Vlist)==0: return Vlist
    181181
     
    216216
    217217        sage: from sage.geometry.polyhedron.plot import ProjectionFuncStereographic
    218218        sage: cube = polytopes.n_cube(3).vertices()
    219         sage: proj = ProjectionFuncStereographic([1.1,1.1,1.1])
     219        sage: proj = ProjectionFuncStereographic([1.2, 3.4, 5.6])
    220220        sage: ppoints = [proj(vector(x)) for x in cube]
    221221        sage: ppoints[0]
    222         (0.0, 0.0)
     222        (-0.0486511..., 0.0859565...)
    223223    """
    224224    def __init__(self, projection_point):
    225225        """
     
    455455            sage: from sage.geometry.polyhedron.plot import ProjectionFuncStereographic
    456456            sage: pproj_stereo = pproj.__call__(proj = ProjectionFuncStereographic([1,2,3]))
    457457            sage: pproj_stereo.polygons[0]
    458             [8, 1, 3]
     458            [10, 4, 6]
    459459        """
    460460        self.transformed_coords = \
    461461            Sequence([proj(p) for p in self.coords])
     
    546546            sage: p = polytopes.n_cube(3)
    547547            sage: proj = p.projection()
    548548            sage: proj.coord_index_of(vector((1,1,1)))
    549             0
     549            7
    550550        """
    551551        try:
    552552            return self.coords.index(v)
     
    565565            sage: p = polytopes.n_cube(3)
    566566            sage: proj = p.projection()
    567567            sage: proj.coord_indices_of([vector((1,1,1)),vector((1,-1,1))])
    568             [0, 2]
     568            [7, 5]
    569569        """
    570570        return [self.coord_index_of(v) for v in v_list]
    571571       
     
    578578
    579579            sage: p = polytopes.n_simplex(4).projection()
    580580            sage: p.coordinates_of([1])
    581             [[0, 0, -43301/50000, 22361/100000]]
     581            [[0, -81649/100000, 7217/25000, 22361/100000]]
    582582        """
    583583        return [self.transformed_coords[i] for i in coord_index_list]
    584584
     
    779779            sage: proj.polygons = Sequence([])
    780780            sage: proj._init_solid_3d(p)
    781781            sage: proj.polygons
    782             [[3, 1, 2], [3, 0, 2], [3, 0, 1], [2, 0, 1]]
     782            [[2, 0, 1], [3, 0, 1], [3, 0, 2], [3, 1, 2]]
    783783        """
    784784        assert polyhedron.ambient_dim() == 3, "Requires polyhedron in 3d"
    785785
     
    920920            sage: cube_proj = cube.projection()
    921921            sage: wire = cube_proj.render_wireframe_3d()
    922922            sage: print wire.tachyon().split('\n')[77]  # for testing
    923             FCylinder base 1.0 -1.0 1.0 apex 1.0 1.0 1.0 rad 0.005 texture...
     923            FCylinder base -1.0 1.0 -1.0 apex -1.0 -1.0 -1.0 rad 0.005 texture...
    924924        """
    925925        wireframe = [];
    926926        for l in self.lines:
  • sage/geometry/polyhedron/representation.py

    diff --git a/sage/geometry/polyhedron/representation.py b/sage/geometry/polyhedron/representation.py
    a b  
    1313
    1414
    1515from sage.structure.sage_object import SageObject
     16from sage.structure.element import is_Vector
    1617from sage.rings.all import QQ, ZZ, RDF
    1718from sage.modules.free_module_element import vector
     19from sage.misc.all import cached_method
    1820
    1921
    2022
     
    5456       
    5557            sage: import sage.geometry.polyhedron.representation as P
    5658            sage: pr = P.PolyhedronRepresentation(Polyhedron(vertices = [[1,2,3]]), [1,2,3])
    57             sage: pr.vector()
     59            sage: tuple(pr)
    5860            (1, 2, 3)
    5961            sage: TestSuite(pr).run(skip='_test_pickling')
    6062        """
    61         self._representation_vector = vector(polyhedron.base_ring(), data);
    62         self._polyhedron = polyhedron;
     63        self._representation_data = tuple(data)
     64        self._polyhedron = polyhedron
    6365
    6466    def __len__(self):
    6567        """
     
    7274            sage: pr.__len__()
    7375            3
    7476        """
    75         return len(self._representation_vector)
     77        return len(self._representation_data)
    7678
    7779    def __getitem__(self, i):
    7880        """
     
    8587            sage: pr.__getitem__(1)
    8688            2
    8789        """
    88         return self._representation_vector[i]
     90        return self._representation_data[i]
    8991
    9092    def polyhedron(self):
    9193        """
     
    105107        Returns the vector representation of the representation
    106108        object. Shorthand for the vector() method.
    107109
     110        Note that the vector() method is only implemented in derived
     111        classes.
     112
    108113        TESTS::
    109114       
    110115            sage: import sage.geometry.polyhedron.representation as P
     116            sage: pr = Polyhedron(vertices = [[1,2,3]]).Vrepresentation(0)
     117            sage: pr.__call__()
     118            (1, 2, 3)
     119           
    111120            sage: pr = P.PolyhedronRepresentation(Polyhedron(vertices = [[1,2,3]]), [1,2,3])
    112121            sage: pr.__call__()
    113             (1, 2, 3)
     122            Traceback (most recent call last):
     123            ...
     124            AttributeError: 'PolyhedronRepresentation' object has no attribute 'vector'
    114125        """
    115         return self._representation_vector
    116 
    117     def vector(self):
    118         """
    119         Returns the vector representation of the representation object.
    120 
    121         NOTES:
    122        
    123           * For vertices/lines/rays this is a vector of length
    124             ``ambient_dim()``. For inequalities and equations this is
    125             a vector of length ``ambient_dim()+1``
    126 
    127         EXAMPLES::
    128 
    129             sage: s = polytopes.cuboctahedron()
    130             sage: v = s.vertex_generator().next()
    131             sage: v
    132             A vertex at (0, -1/2, -1/2)
    133             sage: v.vector()
    134             (0, -1/2, -1/2)
    135             sage: v()
    136             (0, -1/2, -1/2)
    137             sage: type(v())
    138             <type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
    139         """
    140         return self._representation_vector
     126        return self.vector()
    141127
    142128    def index(self):
    143129        """
     
    187173        self._index = len(polyhedron._Hrepresentation)
    188174        polyhedron._Hrepresentation.append(self)
    189175   
     176    @cached_method
     177    def vector(self):
     178        """
     179        Returns the vector representation of the H-representation object.
     180
     181        OUTPUT:
     182       
     183        A vector of length
     184        :meth:`~sage.geometry.polyhedron.base.Polyhedron_base.ambient_dim` + 1.
     185
     186        EXAMPLES::
     187
     188            sage: s = polytopes.cuboctahedron()
     189            sage: v = s.vertex_generator().next()
     190            sage: v
     191            A vertex at (-1/2, -1/2, 0)
     192            sage: v.vector()
     193            (-1/2, -1/2, 0)
     194            sage: v()
     195            (-1/2, -1/2, 0)
     196            sage: type(v())
     197            <type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
     198        """
     199        return self.polyhedron().Hrepresentation_space()(self._representation_data)
     200
    190201    def is_H(self):
    191202        """
    192203        Returns True if the object is part of a H-representation
     
    227238        """       
    228239        return False
    229240   
     241    @cached_method
    230242    def A(self):
    231243        r"""
    232244        Returns the coefficient vector `A` in `A\vec{x}+b`.
     
    234246        EXAMPLES::
    235247
    236248            sage: p = Polyhedron(ieqs = [[0,1,0],[0,0,1],[1,-1,0,],[1,0,-1]])
    237             sage: pH = p.Hrepresentation(0)
     249            sage: pH = p.Hrepresentation(2)
    238250            sage: pH.A()
    239251            (1, 0)
    240252        """
    241         return self._representation_vector[1:]
     253        return self.polyhedron().ambient_space()(self._representation_data[1:])
    242254
     255    @cached_method
    243256    def b(self):
    244257        r"""
    245258        Returns the constant `b` in `A\vec{x}+b`.
     
    247260        EXAMPLES::
    248261
    249262            sage: p = Polyhedron(ieqs = [[0,1,0],[0,0,1],[1,-1,0,],[1,0,-1]])
    250             sage: pH = p.Hrepresentation(0)
     263            sage: pH = p.Hrepresentation(2)
    251264            sage: pH.b()
    252265            0
    253266        """
    254         return self._representation_vector[0]
     267        return self._representation_data[0]
    255268
    256269    def neighbors(self):
    257270        """
     
    264277            sage: pH = p.Hrepresentation(0)
    265278            sage: a = list(pH.neighbors())
    266279            sage: a[0]
    267             An inequality (0, 1, 0) x + 0 >= 0
     280            An inequality (0, -1, 0) x + 1 >= 0
    268281            sage: list(a[0])
    269             [0, 0, 1, 0]
     282            [1, 0, -1, 0]
    270283        """
    271284        adjacency_matrix = self.polyhedron().facet_adjacency_matrix()
    272285        for x in self.polyhedron().Hrep_generator():
     
    279292
    280293        TESTS::
    281294
    282             sage: p = Polyhedron(ieqs = [[0,0,0,2],[0,0,1,0,],[0,10,0,0],[1,-1,0,0],[1,0,-1,0,],[1,0,0,-1]])
     295            sage: p = Polyhedron(ieqs = [[0,0,0,2],[0,0,1,0,],[0,10,0,0],
     296            ...       [1,-1,0,0],[1,0,-1,0,],[1,0,0,-1]])
    283297            sage: pH = p.Hrepresentation(0)
    284298            sage: a = list(pH.neighbors())
    285299            sage: b = list(pH.adjacent())
     
    294308
    295309        EXAMPLES::
    296310
    297             sage: p = Polyhedron(ieqs = [[0,0,0,1],[0,0,1,0,],[0,1,0,0],[1,-1,0,0],[1,0,-1,0,],[1,0,0,-1]])
     311            sage: p = Polyhedron(ieqs = [[0,0,0,1],[0,0,1,0,],[0,1,0,0],
     312            ...       [1,-1,0,0],[1,0,-1,0,],[1,0,0,-1]])
    298313            sage: pH = p.Hrepresentation(0)
    299314            sage: pH.is_incident(p.Vrepresentation(1))
    300315            True
     
    309324
    310325        EXAMPLES::
    311326
    312             sage: p = Polyhedron(ieqs = [[0,0,0,1],[0,0,1,0,],[0,1,0,0],[1,-1,0,0],[1,0,-1,0,],[1,0,0,-1]])
     327            sage: p = Polyhedron(ieqs = [[0,0,0,1],[0,0,1,0,],[0,1,0,0],
     328            ...        [1,-1,0,0],[1,0,-1,0,],[1,0,0,-1]])
    313329            sage: pH = p.Hrepresentation(0)
    314330            sage: pH*p.Vrepresentation(5)
    315331            1
     
    334350            sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[-1,-1]])
    335351            sage: ineq = triangle.inequality_generator().next()
    336352            sage: ineq
    337             An inequality (-1, -1) x + 1 >= 0
     353            An inequality (2, -1) x + 1 >= 0
    338354            sage: [ ineq.eval(v) for v in triangle.vertex_generator() ]
    339355            [0, 0, 3]
    340356            sage: [ ineq * v for v in triangle.vertex_generator() ]
     
    343359        If you pass a vector, it is assumed to be the coordinate vector of a point::
    344360           
    345361            sage: ineq.eval( vector(ZZ, [3,2]) )
    346             -4
     362            5
    347363        """
    348         try:
    349             return Vobj.evaluated_on(self)
    350         except AttributeError:
     364        if is_Vector(Vobj):
    351365            return self.A() * Vobj + self.b()
     366        return Vobj.evaluated_on(self)
     367        #return self.A() * Vobj.vector() + self.b()
    352368
    353369    def incident(self):
    354370        """
     
    360376            sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[-1,-1]])
    361377            sage: ineq = triangle.inequality_generator().next()
    362378            sage: ineq
    363             An inequality (-1, -1) x + 1 >= 0
     379            An inequality (2, -1) x + 1 >= 0
    364380            sage: [ v for v in ineq.incident()]
    365             [A vertex at (1, 0), A vertex at (0, 1)]
     381            [A vertex at (-1, -1), A vertex at (0, 1)]
    366382            sage: p = Polyhedron(vertices=[[0,0,0],[0,1,0],[0,0,1]], rays=[[1,-1,-1]])
    367383            sage: ineq = p.Hrepresentation(2)
    368384            sage: ineq
    369             An inequality (1, 1, 0) x + 0 >= 0
     385            An inequality (1, 0, 1) x + 0 >= 0
    370386            sage: [ x for x in ineq.incident() ] 
    371             [A ray in the direction (1, -1, -1),
    372              A vertex at (0, 0, 0),
    373              A vertex at (0, 0, 1)]
     387            [A vertex at (0, 0, 0),
     388             A vertex at (0, 1, 0),
     389             A ray in the direction (1, -1, -1)]
    374390        """
    375391        incidence_matrix = self.polyhedron().incidence_matrix()
    376392        for V in self.polyhedron().Vrep_generator():
     
    393409            sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]])
    394410            sage: a = p.inequality_generator().next()
    395411            sage: a
    396             An inequality (-1, 0, 0) x + 1 >= 0
     412            An inequality (-1, 1, 0) x + 0 >= 0
    397413            sage: TestSuite(a).run(skip='_test_pickling')
    398414        """
    399415        super(Inequality, self).__init__(polyhedron, data)
     
    451467            sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]])
    452468            sage: a = p.inequality_generator().next()
    453469            sage: a._repr_()
    454             'An inequality (-1, 0, 0) x + 1 >= 0'
     470            'An inequality (-1, 1, 0) x + 0 >= 0'
    455471            sage: Polyhedron(ieqs=[(1,-1),(-1,2)]).Hrepresentation()
    456472            (An inequality (-1) x + 1 >= 0, An inequality (2) x - 1 >= 0)
    457473            sage: Polyhedron(eqns=[(1,0)]).Hrepresentation()
    458             (An equation 1 == 0,)
     474            (An equation -1 == 0,)
    459475            sage: Polyhedron(eqns=[(-1,0)]).Hrepresentation()
    460476            (An equation -1 == 0,)
    461477        """
     
    486502            [True, True, True, True, True, True]
    487503            sage: p2 = 3*polytopes.n_cube(3)
    488504            sage: [i1.contains(q) for q in p2.vertex_generator()]
    489             [True, False, True, True, False, False, True, False]
     505            [True, False, False, False, True, True, True, False]
    490506        """
    491507        try:
    492508            if Vobj.is_vector(): # assume we were passed a point
     
    510526            sage: p = polytopes.cross_polytope(3)
    511527            sage: i1 = p.inequality_generator().next()
    512528            sage: [i1.interior_contains(q) for q in p.vertex_generator()]
    513             [True, False, True, False, True, False]
     529            [False, True, True, False, False, True]
    514530            sage: p2 = 3*polytopes.n_cube(3)
    515531            sage: [i1.interior_contains(q) for q in p2.vertex_generator()]
    516             [True, False, True, True, False, False, True, False]
     532            [True, False, False, False, True, True, True, False]
    517533
    518534        If you pass a vector, it is assumed to be the coordinate vector of a point::
    519535       
    520536            sage: P = Polyhedron(vertices=[[1,1],[1,-1],[-1,1],[-1,-1]])
    521537            sage: p = vector(ZZ, [1,0] )
    522538            sage: [ ieq.interior_contains(p) for ieq in P.inequality_generator() ]
    523             [True, True, True, False]
     539            [True, True, False, True]
    524540        """
    525541        try:
    526542            if Vobj.is_vector(): # assume we were passed a point
     
    698714        self._index = len(polyhedron._Vrepresentation)
    699715        polyhedron._Vrepresentation.append(self)
    700716
     717    @cached_method
     718    def vector(self):
     719        """
     720        Returns the vector representation of the V-representation object.
     721
     722        OUTPUT:
     723       
     724        A vector of length
     725        :meth:`~sage.geometry.polyhedron.base.Polyhedron_base.ambient_dim`.
     726
     727        EXAMPLES::
     728
     729            sage: s = polytopes.cuboctahedron()
     730            sage: v = s.vertex_generator().next()
     731            sage: v
     732            A vertex at (-1/2, -1/2, 0)
     733            sage: v.vector()
     734            (-1/2, -1/2, 0)
     735            sage: v()
     736            (-1/2, -1/2, 0)
     737            sage: type(v())
     738            <type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
     739        """
     740        return self.polyhedron().Vrepresentation_space()(self._representation_data)
     741
    701742    def is_V(self):
    702743        """
    703744        Returns True if the object is part of a V-representation
     
    778819             sage: p = Polyhedron(vertices = [[0,0],[1,0],[0,3],[1,4]])
    779820             sage: v = p.vertex_generator().next()
    780821             sage: v.neighbors().next()
    781              A vertex at (1, 0)
     822             A vertex at (0, 3)
    782823        """
    783824        adjacency_matrix = self.polyhedron().vertex_adjacency_matrix()
    784825        for x in self.polyhedron().Vrep_generator():
     
    809850            sage: p = polytopes.n_cube(3)
    810851            sage: h1 = p.inequality_generator().next()
    811852            sage: h1
    812             An inequality (0, 0, 1) x + 1 >= 0
     853            An inequality (0, 0, -1) x + 1 >= 0
    813854            sage: v1 = p.vertex_generator().next()
    814855            sage: v1
    815             A vertex at (1, 1, 1)
     856            A vertex at (-1, -1, -1)
    816857            sage: v1.is_incident(h1)
    817858            False
    818859        """
     
    842883            sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[-1,-1]])
    843884            sage: ineq = triangle.inequality_generator().next()
    844885            sage: ineq
    845             An inequality (-1, -1) x + 1 >= 0
     886            An inequality (2, -1) x + 1 >= 0
    846887            sage: [ v for v in ineq.incident()]
    847             [A vertex at (1, 0), A vertex at (0, 1)]
     888            [A vertex at (-1, -1), A vertex at (0, 1)]
    848889            sage: p = Polyhedron(vertices=[[0,0,0],[0,1,0],[0,0,1]], rays=[[1,-1,-1]])
    849890            sage: ineq = p.Hrepresentation(2)
    850891            sage: ineq
    851             An inequality (1, 1, 0) x + 0 >= 0
     892            An inequality (1, 0, 1) x + 0 >= 0
    852893            sage: [ x for x in ineq.incident() ] 
    853             [A ray in the direction (1, -1, -1),
    854              A vertex at (0, 0, 0),
    855              A vertex at (0, 0, 1)]
     894            [A vertex at (0, 0, 0),
     895             A vertex at (0, 1, 0),
     896             A ray in the direction (1, -1, -1)]
    856897        """
    857898        incidence_matrix = self.polyhedron().incidence_matrix()
    858899        for H in self.polyhedron().Hrep_generator():
     
    874915            sage: v1 = p.vertex_generator().next()
    875916            sage: v1
    876917            A vertex at (1, 0)
    877             sage: p._Vrepresentation = Sequence([])
    878             sage: v1.__init__(p,[1,2])
    879             sage: v1
    880             A vertex at (1, 2)
    881918            sage: TestSuite(v1).run(skip='_test_pickling')
    882919        """
    883920        super(Vertex, self).__init__(polyhedron, data)
     
    941978            sage: v.__repr__()
    942979            'A vertex at (1, 0)'
    943980        """
    944         return 'A vertex at ' + repr(self._representation_vector);
     981        return 'A vertex at ' + repr(self.vector());
    945982
    946983    def evaluated_on(self, Hobj):
    947984        r"""
     
    953990            sage: v = p.vertex_generator().next()
    954991            sage: h = p.inequality_generator().next()
    955992            sage: v
    956             A vertex at (1, 1, 1)
     993            A vertex at (-1, -1, -1)
    957994            sage: h
    958             An inequality (0, 0, 1) x + 1 >= 0
     995            An inequality (0, 0, -1) x + 1 >= 0
    959996            sage: v.evaluated_on(h)
    960997            2
    961998        """
    962         return Hobj.A() * self._representation_vector + Hobj.b()
     999        return Hobj.A() * self.vector() + Hobj.b()
    9631000
     1001    @cached_method
    9641002    def is_integral(self):
    9651003        r"""
    9661004        Return whether the coordinates of the vertex are all integral.
     
    9731011       
    9741012            sage: p = Polyhedron([(1/2,3,5), (0,0,0), (2,3,7)])
    9751013            sage: [ v.is_integral() for v in p.vertex_generator() ]
    976             [False, True, True]
     1014            [True, False, True]
    9771015        """
    978         return all(x in ZZ for x in self._representation_vector)
     1016        return all(x in ZZ for x in self._representation_data)
    9791017
    9801018
    9811019class Ray(Vrepresentation):
     
    9921030            sage: r1 = p.ray_generator().next()
    9931031            sage: r1
    9941032            A ray in the direction (0, 1)
    995             sage: p._Vrepresentation = Sequence([])
    996             sage: r1.__init__(p,[1,2])
    997             sage: p.ray_generator().next()
    998             A ray in the direction (1, 2)
    9991033            sage: TestSuite(r1).run(skip='_test_pickling')
    10001034        """
    10011035        super(Ray, self).__init__(polyhedron, data)
     
    10551089            sage: a._repr_()
    10561090            'A ray in the direction (0, 1)'
    10571091        """
    1058         return 'A ray in the direction ' + repr(self._representation_vector);
     1092        return 'A ray in the direction ' + repr(self.vector());
    10591093
    10601094    def evaluated_on(self, Hobj):
    10611095        r"""
     
    10671101            sage: a = p.ray_generator().next()
    10681102            sage: h = p.inequality_generator().next()
    10691103            sage: a.evaluated_on(h)
    1070             1
     1104            0
    10711105        """
    1072         return Hobj.A() * self._representation_vector
     1106        return Hobj.A() * self.vector()
    10731107
    10741108
    10751109class Line(Vrepresentation):
     
    11481182            sage: a.__repr__()
    11491183            'A line in the direction (0, 1, 0)'
    11501184        """
    1151         return 'A line in the direction ' + repr(self._representation_vector);
     1185        return 'A line in the direction ' + repr(self.vector());
    11521186
    11531187    def evaluated_on(self, Hobj):
    11541188        r"""
     
    11621196            sage: a.evaluated_on(h)
    11631197            0
    11641198        """
    1165         return Hobj.A() * self._representation_vector
     1199        return Hobj.A() * self.vector()
    11661200
    11671201
  • sage/geometry/triangulation/element.py

    diff --git a/sage/geometry/triangulation/element.py b/sage/geometry/triangulation/element.py
    a b  
    578578            sage: p = polytopes.cuboctahedron()
    579579            sage: sc = p.triangulate(engine='internal').simplicial_complex()
    580580            sage: sc   
    581             Simplicial complex with 12 vertices and 17 facets
     581            Simplicial complex with 12 vertices and 16 facets
    582582
    583583        Any convex set is contractable, so its reduced homology groups vanish::
    584584           
  • sage/geometry/triangulation/point_configuration.py

    diff --git a/sage/geometry/triangulation/point_configuration.py b/sage/geometry/triangulation/point_configuration.py
    a b  
    13321332            sage: p = PointConfiguration([[0,0],[1,0],[2,1],[1,2],[0,1]])
    13331333            sage: poly = p.secondary_polytope()
    13341334            sage: matrix(poly.vertices()).transpose()
    1335             [1 3 1 5 3]
    1336             [3 1 5 1 4]
    1337             [4 5 2 4 2]
    1338             [2 2 4 4 5]
    1339             [5 4 3 1 1]
     1335            [1 1 3 3 5]
     1336            [3 5 1 4 1]
     1337            [4 2 5 2 4]
     1338            [2 4 2 5 4]
     1339            [5 3 4 1 1]
    13401340            sage: poly.Vrepresentation()
    13411341            (A vertex at (1, 3, 4, 2, 5),
     1342             A vertex at (1, 5, 2, 4, 3),
    13421343             A vertex at (3, 1, 5, 2, 4),
    1343              A vertex at (1, 5, 2, 4, 3),
    1344              A vertex at (5, 1, 4, 4, 1),
    1345              A vertex at (3, 4, 2, 5, 1))
     1344             A vertex at (3, 4, 2, 5, 1),
     1345             A vertex at (5, 1, 4, 4, 1))
    13461346            sage: poly.Hrepresentation()
    1347             (An equation (1/2, 1, 1, 0, 0) x - 15/2 == 0,
    1348              An equation (-1, -1, 0, 1, 0) x + 2 == 0,
    1349              An equation (3/2, 1, 0, 0, 1) x - 19/2 == 0,
    1350              An inequality (-1, -2, 0, 0, 0) x + 11 >= 0,
    1351              An inequality (1, 0, 0, 0, 0) x - 1 >= 0,
    1352              An inequality (1, 1, 0, 0, 0) x - 4 >= 0,
    1353              An inequality (0, 1, 0, 0, 0) x - 1 >= 0,
    1354              An inequality (-3/2, -1, 0, 0, 0) x + 17/2 >= 0)
     1347            (An equation (0, 0, 1, 2, 1) x - 13 == 0,
     1348             An equation (1, 0, 0, 2, 2) x - 15 == 0,
     1349             An equation (0, 1, 0, -3, -2) x + 13 == 0,
     1350             An inequality (0, 0, 0, -1, -1) x + 7 >= 0,
     1351             An inequality (0, 0, 0, 1, 0) x - 2 >= 0,
     1352             An inequality (0, 0, 0, -2, -1) x + 11 >= 0,
     1353             An inequality (0, 0, 0, 0, 1) x - 1 >= 0,
     1354             An inequality (0, 0, 0, 3, 2) x - 14 >= 0)
    13551355        """
    13561356        from sage.geometry.polyhedron.constructor import Polyhedron
    13571357        #TODO: once restriction to regular triangulations is fixed,
  • sage/libs/ppl.pyx

    diff --git a/sage/libs/ppl.pyx b/sage/libs/ppl.pyx
    a b  
    116116
    117117    sage: basis = range(0,5)
    118118    sage: gs = [ tuple(coeff) for coeff in permutations(basis) ]
    119     sage: Polyhedron(vertices=gs)  # long time (3s on sage.math, 2011)
     119    sage: Polyhedron(vertices=gs, backend='cddr')  # long time (3s on sage.math, 2011)
    120120    A 4-dimensional polyhedron in QQ^5 defined as the convex hull of 120 vertices
    121121
    122122DIFFERENCES VS. C++
     
    129129
    130130* :class:`Polyhedron` and its subclasses as well as
    131131  :class:`Generator_System` and :class:`Constraint_System` can be set
    132   immutable via a ``set_immutable()` method. This is the analog of
     132  immutable via a ``set_immutable()`` method. This is the analog of
    133133  declaring a C++ instance ``const``. All other classes are immutable
    134134  by themselves.
    135135
  • sage/rings/polynomial/groebner_fan.py

    diff --git a/sage/rings/polynomial/groebner_fan.py b/sage/rings/polynomial/groebner_fan.py
    a b  
    10401040            sage: cone_data = Polyhedron(ieqs = g_cone_ieqs, eqns = [[1,-1,-1,-1,-1]])
    10411041            sage: cone_lines = gf._4d_to_3d(cone_data)
    10421042            sage: cone_lines
    1043             [[[-3/5, -1/3, -1/5], [-1/7, 3/7, 5/7]],
    1044             [[-3/5, -1/3, -1/5], [1, -1/3, 1/3]],
    1045             [[-3/5, -1/3, -1/5], [1, 1, -1]],
    1046             [[-1/7, 3/7, 5/7], [1, -1/3, 1/3]],
    1047             [[-1/7, 3/7, 5/7], [1, 1, -1]],
    1048             [[1, -1/3, 1/3], [1, 1, -1]]]
     1043            [[[1, 1, -1], [1, -1/3, 1/3]],
     1044            [[1, 1, -1], [-1/7, 3/7, 5/7]],
     1045            [[1, 1, -1], [-3/5, -1/3, -1/5]],
     1046            [[1, -1/3, 1/3], [-1/7, 3/7, 5/7]],
     1047            [[1, -1/3, 1/3], [-3/5, -1/3, -1/5]],
     1048            [[-1/7, 3/7, 5/7], [-3/5, -1/3, -1/5]]]
    10491049        """
    10501050        fpoints = polyhedral_data.vertices()
    10511051        tpoints = [self._embed_tetra(q) for q in fpoints]
  • sage/rings/polynomial/multi_polynomial.pyx

    diff --git a/sage/rings/polynomial/multi_polynomial.pyx b/sage/rings/polynomial/multi_polynomial.pyx
    a b  
    862862            sage: f = 1 + x*y + x^3 + y^3
    863863            sage: P = f.newton_polytope()
    864864            sage: P
    865             A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices.
     865            A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices
    866866            sage: P.is_simple()
    867867            True
    868868
     
    870870
    871871            sage: R.<x,y> = QQ[]
    872872            sage: R(0).newton_polytope()
    873             The empty polyhedron in QQ^0.
     873            The empty polyhedron in QQ^0
    874874            sage: R(1).newton_polytope()
    875             A 0-dimensional polyhedron in QQ^2 defined as the convex hull of 1 vertex.
     875            A 0-dimensional polyhedron in QQ^2 defined as the convex hull of 1 vertex
    876876           
    877877        """
    878878        from sage.geometry.polyhedron.constructor import Polyhedron
  • sage/schemes/generic/toric_divisor.py

    diff --git a/sage/schemes/generic/toric_divisor.py b/sage/schemes/generic/toric_divisor.py
    a b  
    12931293            sage: F2 = ToricVariety(fan,'u1, u2, u3, u4')
    12941294            sage: D = F2.divisor(3)
    12951295            sage: D.polyhedron().Vrepresentation()
    1296             (A vertex at (2, 1), A vertex at (0, 1), A vertex at (0, 0))
     1296            (A vertex at (0, 0), A vertex at (2, 1), A vertex at (0, 1))
    12971297            sage: Dprime = F2.divisor(1) + D
    12981298            sage: Dprime.polyhedron().Vrepresentation()
    12991299            (A vertex at (2, 1), A vertex at (0, 1), A vertex at (0, 0))
     
    13121312            sage: P_D
    13131313            A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 8 vertices
    13141314            sage: P_D.Vrepresentation()
    1315             (A vertex at (1, -1, 0), A vertex at (1, 1, 1),
    1316              A vertex at (1, -3, 1), A vertex at (-5, 1, 1),
    1317              A vertex at (-5, -3, 1), A vertex at (1, 1, -1/2),
    1318              A vertex at (1, 1/2, -1/2), A vertex at (-1, -1, 0))
     1315            (A vertex at (1, -1, 0), A vertex at (1, -3, 1),
     1316             A vertex at (1, 1, 1), A vertex at (-5, 1, 1),
     1317             A vertex at (1, 1, -1/2), A vertex at (1, 1/2, -1/2),
     1318             A vertex at (-1, -1, 0), A vertex at (-5, -3, 1))
    13191319            sage: P_D.Hrepresentation()
    13201320            (An inequality (-1, 0, 0) x + 1 >= 0, An inequality (0, -1, 0) x + 1 >= 0,
    1321              An inequality (0, 0, -1) x + 1 >= 0, An inequality (0, 1, 2) x + 1 >= 0,
    1322              An inequality (0, 1, 3) x + 1 >= 0, An inequality (1, 0, 4) x + 1 >= 0)
     1321             An inequality (0, 0, -1) x + 1 >= 0, An inequality (1, 0, 4) x + 1 >= 0,
     1322             An inequality (0, 1, 3) x + 1 >= 0, An inequality (0, 1, 2) x + 1 >= 0)
    13231323            sage: P_D.integral_points()
    13241324            ((-1, -1, 0), (0, -1, 0), (1, -1, 0), (-1, 0, 0), (0, 0, 0),
    13251325             (1, 0, 0), (-1, 1, 0), (0, 1, 0), (1, 1, 0), (-5, -3, 1),
     
    15881588            sage: supp
    15891589            A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 4 vertices
    15901590            sage: supp.Vrepresentation()
    1591             (A vertex at (-1, 1), A vertex at (0, 2), A vertex at (0, -1), A vertex at (3, -1))
     1591            (A vertex at (-1, 1), A vertex at (0, -1), A vertex at (3, -1), A vertex at (0, 2))
    15921592        """
    15931593        X = self.parent().scheme()
    15941594        fan = X.fan()