### Navigation

- index
- modules |
- next |
- previous |
- Combinatorial Geometry »

# H(yperplane) and V(ertex) representation objects for polyhedra

class `sage.geometry.polyhedron.representation.``Equation`(polyhedron_parent)

  Bases: `sage.geometry.polyhedron.representation.Hrepresentation`

  A linear equation of the polyhedron. That is, the polyhedron is strictly smaller-dimensional than the ambient space, and contained in this hyperplane. Inherits from `Hrepresentation`.

  `contains`(Vobj)

    Tests whether the hyperplane defined by the equation contains the given vertex/ray/line.

    EXAMPLES:

        sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]])
        sage: v = p.vertex_generator().next()
        sage: v
        A vertex at (0, 0, 0)
        sage: a = p.equation_generator().next()
        sage: a
        An equation (0, 0, 1) x + 0 == 0
        sage: a.contains(v)
        True

  `interior_contains`(Vobj)

    Tests whether the interior of the halfspace (excluding its boundary) defined by the inequality contains the given vertex/ray/line.

    NOTE:

    Returns False for any equation.

    EXAMPLES:

        sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]])
        sage: v = p.vertex_generator().next()
        sage: v
        A vertex at (0, 0, 0)
        sage: a = p.equation_generator().next()
        sage: a
        An equation (0, 0, 1) x + 0 == 0
        sage: a.interior_contains(v)
        False

  `is_equation`()

    Tests if this object is an equation. By construction, it must be.

    TESTS:

        sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]])
        sage: a = p.equation_generator().next()
        sage: a.is_equation()
        True

  `type`()

    Returns the type (equation/inequality/vertex/ray/line) as an integer.

    OUTPUT:

    Integer. One of `PolyhedronRepresentation.INEQUALITY`, `.EQUATION`, `.VERTEX`, `.RAY`, or `.LINE`.

    EXAMPLES:

        sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]])
        sage: repr_obj = p.equation_generator().next()
        sage: repr_obj.type()
        1
        sage: repr_obj.type() == repr_obj.INEQUALITY
        False
        sage: repr_obj.type() == repr_obj.EQUATION
        True
        sage: repr_obj.type() == repr_obj.VERTEX
        False
        sage: repr_obj.type() == repr_obj.RAY
        False
        sage: repr_obj.type() == repr_obj.LINE
        False

class `sage.geometry.polyhedron.representation.``Hrepresentation`(polyhedron_parent)

  Bases: `sage.geometry.polyhedron.representation.PolyhedronRepresentation`

  The internal base class for H-representation objects of a polyhedron. Inherits from `PolyhedronRepresentation`.

  `A`()

    Returns the coefficient vector \(A\) in \(A\vec{x}+b\).

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[0,1,0],[0,0,1],[1,-1,0,],[1,0,-1]])
        sage: pH = p.Hrepresentation(2)
        sage: pH.A()
        (1, 0)

  `adjacent`()

    Alias for neighbors().

    TESTS:

        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]])
        sage: pH = p.Hrepresentation(0)
        sage: a = list(pH.neighbors())
        sage: b = list(pH.adjacent())
        sage: a==b
        True

  `b`()

    Returns the constant \(b\) in \(A\vec{x}+b\).

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[0,1,0],[0,0,1],[1,-1,0,],[1,0,-1]])
        sage: pH = p.Hrepresentation(2)
        sage: pH.b()
        0

  `eval`(Vobj)

    Evaluates the left hand side \(A\vec{x}+b\) on the given vertex/ray/line.

    NOTES:

    > - Evaluating on a vertex returns \(A\vec{x}+b\)
    > - Evaluating on a ray returns \(A\vec{r}\). Only the sign or whether it is zero is meaningful.
    > - Evaluating on a line returns \(A\vec{l}\). Only whether it is zero or not is meaningful.

    EXAMPLES:

        sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[-1,-1]])
        sage: ineq = triangle.inequality_generator().next()
        sage: ineq
        An inequality (2, -1) x + 1 >= 0
        sage: [ ineq.eval(v) for v in triangle.vertex_generator() ]
        [0, 0, 3]
        sage: [ ineq * v for v in triangle.vertex_generator() ]
        [0, 0, 3]

    If you pass a vector, it is assumed to be the coordinate vector of a point:

        sage: ineq.eval( vector(ZZ, [3,2]) )
        5

  `incident`()

    Returns a generator for the incident H-representation objects, that is, the vertices/rays/lines satisfying the (in)equality.

    EXAMPLES:

        sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[-1,-1]])
        sage: ineq = triangle.inequality_generator().next()
        sage: ineq
        An inequality (2, -1) x + 1 >= 0
        sage: [ v for v in ineq.incident()]
        [A vertex at (-1, -1), A vertex at (0, 1)]
        sage: p = Polyhedron(vertices=[[0,0,0],[0,1,0],[0,0,1]], rays=[[1,-1,-1]])
        sage: ineq = p.Hrepresentation(2)
        sage: ineq
        An inequality (1, 0, 1) x + 0 >= 0
        sage: [ x for x in ineq.incident() ]
        [A vertex at (0, 0, 0),
         A vertex at (0, 1, 0),
         A ray in the direction (1, -1, -1)]

  `is_H`()

    Returns True if the object is part of a H-representation (inequality or equation).

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[0,1,0],[0,0,1],[1,-1,0,],[1,0,-1]])
        sage: pH = p.Hrepresentation(0)
        sage: pH.is_H()
        True

  `is_equation`()

    Returns True if the object is an equation of the H-representation.

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[0,1,0],[0,0,1],[1,-1,0,],[1,0,-1]], eqns = [[1,1,-1]])
        sage: pH = p.Hrepresentation(0)
        sage: pH.is_equation()
        True

  `is_incident`(Vobj)

    Returns whether the incidence matrix element (Vobj,self) == 1

    EXAMPLES:

        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]])
        sage: pH = p.Hrepresentation(0)
        sage: pH.is_incident(p.Vrepresentation(1))
        True
        sage: pH.is_incident(p.Vrepresentation(5))
        False

  `is_inequality`()

    Returns True if the object is an inequality of the H-representation.

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[0,1,0],[0,0,1],[1,-1,0,],[1,0,-1]])
        sage: pH = p.Hrepresentation(0)
        sage: pH.is_inequality()
        True

  `neighbors`()

    Iterate over the adjacent facets (i.e. inequalities/equations)

    EXAMPLES:

        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]])
        sage: pH = p.Hrepresentation(0)
        sage: a = list(pH.neighbors())
        sage: a[0]
        An inequality (0, -1, 0) x + 1 >= 0
        sage: list(a[0])
        [1, 0, -1, 0]

class `sage.geometry.polyhedron.representation.``Inequality`(polyhedron_parent)

  Bases: `sage.geometry.polyhedron.representation.Hrepresentation`

  A linear inequality (supporting hyperplane) of the polyhedron. Inherits from `Hrepresentation`.

  `contains`(Vobj)

    Tests whether the halfspace (including its boundary) defined by the inequality contains the given vertex/ray/line.

    EXAMPLES:

        sage: p = polytopes.cross_polytope(3)
        sage: i1 = p.inequality_generator().next()
        sage: [i1.contains(q) for q in p.vertex_generator()]
        [True, True, True, True, True, True]
        sage: p2 = 3*polytopes.n_cube(3)
        sage: [i1.contains(q) for q in p2.vertex_generator()]
        [True, False, False, False, True, True, True, False]

  `interior_contains`(Vobj)

    Tests whether the interior of the halfspace (excluding its boundary) defined by the inequality contains the given vertex/ray/line.

    EXAMPLES:

        sage: p = polytopes.cross_polytope(3)
        sage: i1 = p.inequality_generator().next()
        sage: [i1.interior_contains(q) for q in p.vertex_generator()]
        [False, True, True, False, False, True]
        sage: p2 = 3*polytopes.n_cube(3)
        sage: [i1.interior_contains(q) for q in p2.vertex_generator()]
        [True, False, False, False, True, True, True, False]

    If you pass a vector, it is assumed to be the coordinate vector of a point:

        sage: P = Polyhedron(vertices=[[1,1],[1,-1],[-1,1],[-1,-1]])
        sage: p = vector(ZZ, [1,0] )
        sage: [ ieq.interior_contains(p) for ieq in P.inequality_generator() ]
        [True, True, False, True]

  `is_inequality`()

    Returns True since this is, by construction, an inequality.

    EXAMPLES:

        sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]])
        sage: a = p.inequality_generator().next()
        sage: a.is_inequality()
        True

  `type`()

    Returns the type (equation/inequality/vertex/ray/line) as an integer.

    OUTPUT:

    Integer. One of `PolyhedronRepresentation.INEQUALITY`, `.EQUATION`, `.VERTEX`, `.RAY`, or `.LINE`.

    EXAMPLES:

        sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]])
        sage: repr_obj = p.inequality_generator().next()
        sage: repr_obj.type()
        0
        sage: repr_obj.type() == repr_obj.INEQUALITY
        True
        sage: repr_obj.type() == repr_obj.EQUATION
        False
        sage: repr_obj.type() == repr_obj.VERTEX
        False
        sage: repr_obj.type() == repr_obj.RAY
        False
        sage: repr_obj.type() == repr_obj.LINE
        False

class `sage.geometry.polyhedron.representation.``Line`(polyhedron_parent)

  Bases: `sage.geometry.polyhedron.representation.Vrepresentation`

  A line (Minkowski summand \(\simeq\RR\)) of the polyhedron. Inherits from `Vrepresentation`.

  `evaluated_on`(Hobj)

    Returns \(A\vec{\ell}\)

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[1, 0, 0, 1],[1,1,0,0]])
        sage: a = p.line_generator().next()
        sage: h = p.inequality_generator().next()
        sage: a.evaluated_on(h)
        0

  `is_line`()

    Tests if the object is a line. By construction it must be.

    TESTS:

        sage: p = Polyhedron(ieqs = [[1, 0, 0, 1],[1,1,0,0]])
        sage: a = p.line_generator().next()
        sage: a.is_line()
        True

  `type`()

    Returns the type (equation/inequality/vertex/ray/line) as an integer.

    OUTPUT:

    Integer. One of `PolyhedronRepresentation.INEQUALITY`, `.EQUATION`, `.VERTEX`, `.RAY`, or `.LINE`.

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[1, 0, 0, 1],[1,1,0,0]])
        sage: repr_obj = p.line_generator().next()
        sage: repr_obj.type()
        4
        sage: repr_obj.type() == repr_obj.INEQUALITY
        False
        sage: repr_obj.type() == repr_obj.EQUATION
        False
        sage: repr_obj.type() == repr_obj.VERTEX
        False
        sage: repr_obj.type() == repr_obj.RAY
        False
        sage: repr_obj.type() == repr_obj.LINE
        True

class `sage.geometry.polyhedron.representation.``PolyhedronRepresentation`

  Bases: `sage.structure.sage_object.SageObject`

  The internal base class for all representation objects of `Polyhedron` (vertices/rays/lines and inequalites/equations)

  Note

  You should not (and cannot) instantiate it yourself. You can only obtain them from a Polyhedron() class.

  TESTS:

      sage: import sage.geometry.polyhedron.representation as P
      sage: P.PolyhedronRepresentation()
      <class 'sage.geometry.polyhedron.representation.PolyhedronRepresentation'>

  `count`(i)

    Count the number of occurrences of `i` in the coordinates.

    INPUT:

    - `i` – Anything.

    OUTPUT:

    Integer. The number of occurrences of `i` in the coordinates.

    EXAMPLES:

        sage: p = Polyhedron(vertices=[(0,1,1,2,1)])
        sage: v = p.Vrepresentation(0); v
        A vertex at (0, 1, 1, 2, 1)
        sage: v.count(1)
        3

  `index`()

    Returns an arbitrary but fixed number according to the internal storage order.

    NOTES:

    H-representation and V-representation objects are enumerated independently. That is, amongst all vertices/rays/lines there will be one with `index()==0`, and amongs all inequalities/equations there will be one with `index()==0`, unless the polyhedron is empty or spans the whole space.

    EXAMPLES:

        sage: s = Polyhedron(vertices=[[1],[-1]])
        sage: first_vertex = s.vertex_generator().next()
        sage: first_vertex.index()
        0
        sage: first_vertex == s.Vrepresentation(0)
        True

  `polyhedron`()

    Returns the underlying polyhedron.

    TESTS:

        sage: p = Polyhedron(vertices=[[1,2,3]])
        sage: v = p.Vrepresentation(0)
        sage: v.polyhedron()
        A 0-dimensional polyhedron in ZZ^3 defined as the convex hull of 1 vertex

  `vector`(base_ring=None)

    > Returns the vector representation of the H/V-representation object.

    > INPUT:

    > - `base_ring` – the base ring of the vector.

    > OUTPUT:

    > For a V-representation object, a vector of length `ambient_dim()`. For a H-representation object, a vector of length `ambient_dim()` + 1.

    > EXAMPLES:

    >     sage: s = polytopes.cuboctahedron()
    >     sage: v = s.vertex_generator().next()
    >     sage: v
    >     A vertex at (-1/2, -1/2, 0)
    >     sage: v.vector()
    >     (-1/2, -1/2, 0)
    >     sage: v()
    >     (-1/2, -1/2, 0)
    >     sage: type(v())
    >     <type 'sage.modules.vector_rational_dense.Vector_rational_dense'>

    Conversion to a different base ring can be forced with the optional argument:

        sage: v.vector(RDF)
        (-0.5, -0.5, 0.0)
        sage: vector(RDF, v)
        (-0.5, -0.5, 0.0)

class `sage.geometry.polyhedron.representation.``Ray`(polyhedron_parent)

  Bases: `sage.geometry.polyhedron.representation.Vrepresentation`

  A ray of the polyhedron. Inherits from `Vrepresentation`.

  `evaluated_on`(Hobj)

    Returns \(A\vec{r}\)

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[0,0,1],[0,1,0],[1,-1,0]])
        sage: a = p.ray_generator().next()
        sage: h = p.inequality_generator().next()
        sage: a.evaluated_on(h)
        0

  `is_ray`()

    Tests if this object is a ray. Always True by construction.

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[0,0,1],[0,1,0],[1,-1,0]])
        sage: a = p.ray_generator().next()
        sage: a.is_ray()
        True

  `type`()

    Returns the type (equation/inequality/vertex/ray/line) as an integer.

    OUTPUT:

    Integer. One of `PolyhedronRepresentation.INEQUALITY`, `.EQUATION`, `.VERTEX`, `.RAY`, or `.LINE`.

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[0,0,1],[0,1,0],[1,-1,0]])
        sage: repr_obj = p.ray_generator().next()
        sage: repr_obj.type()
        3
        sage: repr_obj.type() == repr_obj.INEQUALITY
        False
        sage: repr_obj.type() == repr_obj.EQUATION
        False
        sage: repr_obj.type() == repr_obj.VERTEX
        False
        sage: repr_obj.type() == repr_obj.RAY
        True
        sage: repr_obj.type() == repr_obj.LINE
        False

class `sage.geometry.polyhedron.representation.``Vertex`(polyhedron_parent)

  Bases: `sage.geometry.polyhedron.representation.Vrepresentation`

  A vertex of the polyhedron. Inherits from `Vrepresentation`.

  `evaluated_on`(Hobj)

    Returns \(A\vec{x}+b\)

    EXAMPLES:

        sage: p = polytopes.n_cube(3)
        sage: v = p.vertex_generator().next()
        sage: h = p.inequality_generator().next()
        sage: v
        A vertex at (-1, -1, -1)
        sage: h
        An inequality (0, 0, -1) x + 1 >= 0
        sage: v.evaluated_on(h)
        2

  `is_integral`()

    Return whether the coordinates of the vertex are all integral.

    OUTPUT:

    Boolean.

    EXAMPLES:

        sage: p = Polyhedron([(1/2,3,5), (0,0,0), (2,3,7)])
        sage: [ v.is_integral() for v in p.vertex_generator() ]
        [True, False, True]

  `is_vertex`()

    Tests if this object is a vertex. By construction it always is.

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[0,0,1],[0,1,0],[1,-1,0]])
        sage: a = p.vertex_generator().next()
        sage: a.is_vertex()
        True

  `type`()

    Returns the type (equation/inequality/vertex/ray/line) as an integer.

    OUTPUT:

    Integer. One of `PolyhedronRepresentation.INEQUALITY`, `.EQUATION`, `.VERTEX`, `.RAY`, or `.LINE`.

    EXAMPLES:

        sage: p = Polyhedron(vertices = [[0,0,0],[1,1,0],[1,2,0]])
        sage: repr_obj = p.vertex_generator().next()
        sage: repr_obj.type()
        2
        sage: repr_obj.type() == repr_obj.INEQUALITY
        False
        sage: repr_obj.type() == repr_obj.EQUATION
        False
        sage: repr_obj.type() == repr_obj.VERTEX
        True
        sage: repr_obj.type() == repr_obj.RAY
        False
        sage: repr_obj.type() == repr_obj.LINE
        False

class `sage.geometry.polyhedron.representation.``Vrepresentation`(polyhedron_parent)

  Bases: `sage.geometry.polyhedron.representation.PolyhedronRepresentation`

  The base class for V-representation objects of a polyhedron. Inherits from `PolyhedronRepresentation`.

  `adjacent`()

    Alias for neighbors().

    TESTS:

        sage: p = Polyhedron(vertices = [[0,0],[1,0],[0,3],[1,4]])
        sage: v = p.vertex_generator().next()
        sage: a = v.neighbors().next()
        sage: b = v.adjacent().next()
        sage: a==b
        True

  `incident`()

    Returns a generator for the equations/inequalities that are satisfied on the given vertex/ray/line.

    EXAMPLES:

        sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[-1,-1]])
        sage: ineq = triangle.inequality_generator().next()
        sage: ineq
        An inequality (2, -1) x + 1 >= 0
        sage: [ v for v in ineq.incident()]
        [A vertex at (-1, -1), A vertex at (0, 1)]
        sage: p = Polyhedron(vertices=[[0,0,0],[0,1,0],[0,0,1]], rays=[[1,-1,-1]])
        sage: ineq = p.Hrepresentation(2)
        sage: ineq
        An inequality (1, 0, 1) x + 0 >= 0
        sage: [ x for x in ineq.incident() ]
        [A vertex at (0, 0, 0),
         A vertex at (0, 1, 0),
         A ray in the direction (1, -1, -1)]

  `is_V`()

    Returns True if the object is part of a V-representation (a vertex, ray, or line).

    EXAMPLES:

        sage: p = Polyhedron(vertices = [[0,0],[1,0],[0,3],[1,3]])
        sage: v = p.vertex_generator().next()
        sage: v.is_V()
        True

  `is_incident`(Hobj)

    Returns whether the incidence matrix element (self,Hobj) == 1

    EXAMPLES:

        sage: p = polytopes.n_cube(3)
        sage: h1 = p.inequality_generator().next()
        sage: h1
        An inequality (0, 0, -1) x + 1 >= 0
        sage: v1 = p.vertex_generator().next()
        sage: v1
        A vertex at (-1, -1, -1)
        sage: v1.is_incident(h1)
        False

  `is_line`()

    Returns True if the object is a line of the V-representation. This method is over-ridden by the corresponding method in the derived class Line.

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[1, 0, 0, 0, 1], [1, 1, 0, 0, 0], [1, 0, 1, 0, 0]])
        sage: line1 = p.line_generator().next()
        sage: line1.is_line()
        True
        sage: v1 = p.vertex_generator().next()
        sage: v1.is_line()
        False

  `is_ray`()

    Returns True if the object is a ray of the V-representation. This method is over-ridden by the corresponding method in the derived class Ray.

    EXAMPLES:

        sage: p = Polyhedron(ieqs = [[1, 0, 0, 0, 1], [1, 1, 0, 0, 0], [1, 0, 1, 0, 0]])
        sage: r1 = p.ray_generator().next()
        sage: r1.is_ray()
        True
        sage: v1 = p.vertex_generator().next()
        sage: v1
        A vertex at (-1, -1, 0, -1)
        sage: v1.is_ray()
        False

  `is_vertex`()

    Returns True if the object is a vertex of the V-representation. This method is over-ridden by the corresponding method in the derived class Vertex.

    EXAMPLES:

        sage: p = Polyhedron(vertices = [[0,0],[1,0],[0,3],[1,3]])
        sage: v = p.vertex_generator().next()
        sage: v.is_vertex()
        True
        sage: p = Polyhedron(ieqs = [[1, 0, 0, 0, 1], [1, 1, 0, 0, 0], [1, 0, 1, 0, 0]])
        sage: r1 = p.ray_generator().next()
        sage: r1.is_vertex()
        False

  `neighbors`()

    Returns a generator for the adjacent vertices/rays/lines.

    EXAMPLES:

        sage: p = Polyhedron(vertices = [[0,0],[1,0],[0,3],[1,4]])
        sage: v = p.vertex_generator().next()
        sage: v.neighbors().next()
        A vertex at (0, 3)

### Navigation

- index
- modules |
- next |
- previous |
- Combinatorial Geometry »