Interface to polymake - Interpreter Interfaces

Skip to content
Back to top
View this page
Edit this page

# Interface to polymake

polymake (https://polymake.org) is a mature open source package for research in polyhedral geometry and related fields, developed since 1997 by Ewgenij Gawrilow and Michael Joswig and various contributors.

polymake has been described in [GJ1997], [GJ2006], [JMP2009], [GJRW2010], [GHJ2016], and [AGHJLPR2017].

sage.interfaces.polymake.Polymake

  alias of `PolymakeJuPyMake`

class sage.interfaces.polymake.PolymakeAbstract(seed=None)

  Bases: `ExtraTabCompletion`, `Interface`

  Abstract interface to the polymake interpreter.

  This class should not be instantiated directly, but through its subclasses Polymake (Pexpect interface) or PolymakeJuPyMake (JuPyMake interface).

  EXAMPLES:

  Sage

      sage: from sage.interfaces.polymake import PolymakeAbstract, polymake_jupymake

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.polymake import PolymakeAbstract, polymake_jupymake

  We test the verbosity management with very early doctests because messages will not be repeated.

  Testing the JuPyMake interface:

  Sage

      sage: isinstance(polymake_jupymake, PolymakeAbstract)
      True
      sage: p = polymake_jupymake.rand_sphere(4, 20, seed=5)       # optional - jupymake
      sage: p                                             # optional - jupymake
      Random spherical polytope of dimension 4; seed=5...
      sage: set_verbose(3)
      sage: p.H_VECTOR                                    # optional - jupymake
      polymake: used package ppl
        The Parma Polyhedra Library ...
      1 16 40 16 1
      sage: set_verbose(0)
      sage: p.F_VECTOR                                    # optional - jupymake
      20 94 148 74

  [Python]

      >>> from sage.all import *
      >>> isinstance(polymake_jupymake, PolymakeAbstract)
      True
      >>> p = polymake_jupymake.rand_sphere(Integer(4), Integer(20), seed=Integer(5))       # optional - jupymake
      >>> p                                             # optional - jupymake
      Random spherical polytope of dimension 4; seed=5...
      >>> set_verbose(Integer(3))
      >>> p.H_VECTOR                                    # optional - jupymake
      polymake: used package ppl
        The Parma Polyhedra Library ...
      1 16 40 16 1
      >>> set_verbose(Integer(0))
      >>> p.F_VECTOR                                    # optional - jupymake
      20 94 148 74

  application(app)

    Change to a given polymake application.

    INPUT:

    - `app` – string; one of `'common'`, `'fulton'`, `'group'`, `'matroid'`, `'topaz'`, `'fan'`, `'graph'`, `'ideal'`, `'polytope'`, `'tropical'`

    EXAMPLES:

    We expose a computation that uses both the ‘polytope’ and the ‘fan’ application of polymake. Let us start by defining a polytope \(q\) in terms of inequalities. Polymake knows to compute the f- and h-vector and finds that the polytope is very ample:

    Sage

        sage: # optional - jupymake
        sage: q = polymake.new_object("Polytope", INEQUALITIES=[[5,-4,0,1],[-3,0,-4,1],[-2,1,0,0],[-4,4,4,-1],[0,0,1,0],[8,0,0,-1],[1,0,-1,0],[3,-1,0,0]])
        sage: q.H_VECTOR
        1 5 5 1
        sage: q.F_VECTOR
        8 14 8
        sage: q.VERY_AMPLE
        true

    Python

        >>> from sage.all import *
        >>> # optional - jupymake
        >>> q = polymake.new_object("Polytope", INEQUALITIES=[[Integer(5),-Integer(4),Integer(0),Integer(1)],[-Integer(3),Integer(0),-Integer(4),Integer(1)],[-Integer(2),Integer(1),Integer(0),Integer(0)],[-Integer(4),Integer(4),Integer(4),-Integer(1)],[Integer(0),Integer(0),Integer(1),Integer(0)],[Integer(8),Integer(0),Integer(0),-Integer(1)],[Integer(1),Integer(0),-Integer(1),Integer(0)],[Integer(3),-Integer(1),Integer(0),Integer(0)]])
        >>> q.H_VECTOR
        1 5 5 1
        >>> q.F_VECTOR
        8 14 8
        >>> q.VERY_AMPLE
        true

    In the application ‘fan’, polymake can now compute the normal fan of \(q\) and its (primitive) rays:

    Sage

        sage: # optional - jupymake
        sage: polymake.application('fan')
        sage: g = q.normal_fan()
        sage: g.RAYS
        -1 0 1/4
        0 -1 1/4
        1 0 0
        1 1 -1/4
        0 1 0
        0 0 -1
        0 -1 0
        -1 0 0
        sage: g.RAYS.primitive()
        -4 0 1
        0 -4 1
        1 0 0
        4 4 -1
        0 1 0
        0 0 -1
        0 -1 0
        -1 0 0

    [Python]

        >>> from sage.all import *
        >>> # optional - jupymake
        >>> polymake.application('fan')
        >>> g = q.normal_fan()
        >>> g.RAYS
        -1 0 1/4
        0 -1 1/4
        1 0 0
        1 1 -1/4
        0 1 0
        0 0 -1
        0 -1 0
        -1 0 0
        >>> g.RAYS.primitive()
        -4 0 1
        0 -4 1
        1 0 0
        4 4 -1
        0 1 0
        0 0 -1
        0 -1 0
        -1 0 0

    Note that the list of functions available by tab completion depends on the application.

  clear(var)

    Clear the variable named `var`.

    Note

    This is implicitly done when deleting an element in the interface.

  console()

    Raise an error, pointing to `interact()` and `polymake_console()`.

    EXAMPLES:

    Sage

        sage: polymake.console()
        Traceback (most recent call last):
        ...
        NotImplementedError: Please use polymake_console() function or the .interact() method

    Python

        >>> from sage.all import *
        >>> polymake.console()
        Traceback (most recent call last):
        ...
        NotImplementedError: Please use polymake_console() function or the .interact() method

  function_call(function, args=None, kwds=None)

    EXAMPLES:

    Sage

        sage: polymake.rand_sphere(4, 30, seed=15)           # optional - jupymake  # indirect doctest
        Random spherical polytope of dimension 4; seed=15...

    Python

        >>> from sage.all import *
        >>> polymake.rand_sphere(Integer(4), Integer(30), seed=Integer(15))           # optional - jupymake  # indirect doctest
        Random spherical polytope of dimension 4; seed=15...

  get(cmd)

    Return the string representation of an object in the polymake interface.

    EXAMPLES:

    Sage

        sage: polymake.get('cube(3)')                     # optional - jupymake
        'Polymake::polytope::Polytope__Rational=ARRAY(...)'

    Python

        >>> from sage.all import *
        >>> polymake.get('cube(3)')                     # optional - jupymake
        'Polymake::polytope::Polytope__Rational=ARRAY(...)'

    Note that the above string representation is what polymake provides. In our interface, we use what polymake calls a “description”:

    Sage

        sage: polymake('cube(3)')                         # optional - jupymake
        cube of dimension 3

    [Python]

        >>> from sage.all import *
        >>> polymake('cube(3)')                         # optional - jupymake
        cube of dimension 3

  help(topic, pager=True)

    Displays polymake’s help on a given topic, as a string.

    INPUT:

    - `topic` – string

    - `pager` – boolean (default: `True`); when `True`, display help, otherwise return as a string

    EXAMPLES:

    Sage

        sage: print(polymake.help('Polytope', pager=False))         # optional - jupymake # random
        objects/Polytope:
         Not necessarily bounded or unbounded polyhedron.
         Nonetheless, the name "Polytope" is used for two reasons:
         Firstly, combinatorially we always deal with polytopes; see the description of VERTICES_IN_FACETS for details.
         The second reason is historical.
         We use homogeneous coordinates, which is why Polytope is derived from Cone.
         Note that a pointed polyhedron is projectively equivalent to a polytope.
         Scalar is the numeric data type used for the coordinates.

    Python

        >>> from sage.all import *
        >>> print(polymake.help('Polytope', pager=False))         # optional - jupymake # random
        objects/Polytope:
         Not necessarily bounded or unbounded polyhedron.
         Nonetheless, the name "Polytope" is used for two reasons:
         Firstly, combinatorially we always deal with polytopes; see the description of VERTICES_IN_FACETS for details.
         The second reason is historical.
         We use homogeneous coordinates, which is why Polytope is derived from Cone.
         Note that a pointed polyhedron is projectively equivalent to a polytope.
         Scalar is the numeric data type used for the coordinates.

    In some cases, polymake expects user interaction to choose from different available help topics. In these cases, a warning is given, and the available help topics are displayed resp. printed, without user interaction:

    Sage

        sage: polymake.help('TRIANGULATION')                        # optional - jupymake # random
        doctest:warning
        ...
        UserWarning: Polymake expects user interaction. We abort and return the options that Polymake provides.
        There are 5 help topics matching 'TRIANGULATION':
        1: objects/Visualization/Visual::Polytope/methods/TRIANGULATION
        2: objects/Visualization/Visual::PointConfiguration/methods/TRIANGULATION
        3: objects/Cone/properties/Triangulation and volume/TRIANGULATION
        4: objects/PointConfiguration/properties/Triangulation and volume/TRIANGULATION
        5: objects/Polytope/properties/Triangulation and volume/TRIANGULATION

    [Python]

        >>> from sage.all import *
        >>> polymake.help('TRIANGULATION')                        # optional - jupymake # random
        doctest:warning
        ...
        UserWarning: Polymake expects user interaction. We abort and return the options that Polymake provides.
        There are 5 help topics matching 'TRIANGULATION':
        1: objects/Visualization/Visual::Polytope/methods/TRIANGULATION
        2: objects/Visualization/Visual::PointConfiguration/methods/TRIANGULATION
        3: objects/Cone/properties/Triangulation and volume/TRIANGULATION
        4: objects/PointConfiguration/properties/Triangulation and volume/TRIANGULATION
        5: objects/Polytope/properties/Triangulation and volume/TRIANGULATION

    If an unknown help topic is requested, a `PolymakeError` results:

    Sage

        sage: polymake.help('Triangulation')      # optional - jupymake
        Traceback (most recent call last):
        ...
        PolymakeError: unknown help topic 'Triangulation'

    Python

        >>> from sage.all import *
        >>> polymake.help('Triangulation')      # optional - jupymake
        Traceback (most recent call last):
        ...
        PolymakeError: unknown help topic 'Triangulation'

  new_object(name, *args, **kwds)

    Return a new instance of a given polymake type, with given positional or named arguments.

    INPUT:

    - `name` of a polymake class (potentially templated), as string.

    - further positional or named arguments, to be passed to the constructor.

    EXAMPLES:

    Sage

        sage: # optional - jupymake
        sage: q = polymake.new_object("Polytope<Rational>", INEQUALITIES=[[4,-4,0,1],[-4,0,-4,1],[-2,1,0,0],[-4,4,4,-1],[0,0,1,0],[8,0,0,-1]])
        sage: q.N_VERTICES
        4
        sage: q.BOUNDED
        true
        sage: q.VERTICES
        1 2 0 4
        1 3 0 8
        1 2 1 8
        1 3 1 8
        sage: q.full_typename()
        'Polytope<Rational>'

    Python

        >>> from sage.all import *
        >>> # optional - jupymake
        >>> q = polymake.new_object("Polytope<Rational>", INEQUALITIES=[[Integer(4),-Integer(4),Integer(0),Integer(1)],[-Integer(4),Integer(0),-Integer(4),Integer(1)],[-Integer(2),Integer(1),Integer(0),Integer(0)],[-Integer(4),Integer(4),Integer(4),-Integer(1)],[Integer(0),Integer(0),Integer(1),Integer(0)],[Integer(8),Integer(0),Integer(0),-Integer(1)]])
        >>> q.N_VERTICES
        4
        >>> q.BOUNDED
        true
        >>> q.VERTICES
        1 2 0 4
        1 3 0 8
        1 2 1 8
        1 3 1 8
        >>> q.full_typename()
        'Polytope<Rational>'

  set(var, value)

    Set the variable var to the given value.

    Eventually, `var` is a reference to `value`.

    Warning

    This method, although it doesn’t start with an underscore, is an internal method and not part of the interface. So, please do not try to call it explicitly. Instead, use the polymake interface as shown in the examples.

    REMARK:

    Polymake’s user language is Perl. In Perl, if one wants to assign the return value of a function to a variable, the syntax to do so depends on the type of the return value. While this is fine in compiled code, it seems quite awkward in user interaction.

    To make this polymake pexpect interface a bit more user friendly, we treat all variables as arrays. A scalar value (most typically a reference) is thus interpreted as the only item in an array of length one. It is, of course, possible to use the interface without knowing these details.

    EXAMPLES:

    Sage

        sage: c = polymake('cube(3)')                       # optional - jupymake # indirect doctest
        sage: d = polymake.cube(3)                          # optional - jupymake

    Python

        >>> from sage.all import *
        >>> c = polymake('cube(3)')                       # optional - jupymake # indirect doctest
        >>> d = polymake.cube(Integer(3))                          # optional - jupymake

    Equality is, for “big” objects such as polytopes, comparison by identity:

    Sage

        sage: c == d                                        # optional - jupymake
        False

    [Python]

        >>> from sage.all import *
        >>> c == d                                        # optional - jupymake
        False

    However, the list of vertices is equal:

    Sage

        sage: c.VERTICES == d.VERTICES                      # optional - jupymake
        True

    Python

        >>> from sage.all import *
        >>> c.VERTICES == d.VERTICES                      # optional - jupymake
        True

  version()

    Version of the polymake installation.

    EXAMPLES:

    Sage

        sage: polymake.version()               # optional - jupymake # random
        '4...'

    Python

        >>> from sage.all import *
        >>> polymake.version()               # optional - jupymake # random
        '4...'

class sage.interfaces.polymake.PolymakeElement(parent, value, is_name=False, name=None)

  Bases: `ExtraTabCompletion`, `InterfaceElement`

  Elements in the polymake interface.

  EXAMPLES:

  We support all “big” polymake types, Perl arrays of length different from one, and Perl scalars:

  Sage

      sage: p = polymake.rand_sphere(4, 20, seed=5)            # optional - jupymake
      sage: p.typename()                                      # optional - jupymake
      'Polytope'
      sage: p                                                 # optional - jupymake
      Random spherical polytope of dimension 4; seed=5...

  Python

      >>> from sage.all import *
      >>> p = polymake.rand_sphere(Integer(4), Integer(20), seed=Integer(5))            # optional - jupymake
      >>> p.typename()                                      # optional - jupymake
      'Polytope'
      >>> p                                                 # optional - jupymake
      Random spherical polytope of dimension 4; seed=5...

  Now, one can work with that element in Python syntax, for example:

  Sage

      sage: p.VERTICES[2][2]                                  # optional - jupymake
      1450479926727001/2251799813685248

  [Python]

      >>> from sage.all import *
      >>> p.VERTICES[Integer(2)][Integer(2)]                                  # optional - jupymake
      1450479926727001/2251799813685248

  full_typename()

    The name of the specialised type of this element.

    EXAMPLES:

    Sage

        sage: c = polymake.cube(4)          # optional - jupymake
        sage: c.full_typename()             # optional - jupymake
        'Polytope<Rational>'
        sage: c.VERTICES.full_typename()    # optional - jupymake
        'Matrix<Rational, NonSymmetric>'

    Python

        >>> from sage.all import *
        >>> c = polymake.cube(Integer(4))          # optional - jupymake
        >>> c.full_typename()             # optional - jupymake
        'Polytope<Rational>'
        >>> c.VERTICES.full_typename()    # optional - jupymake
        'Matrix<Rational, NonSymmetric>'

  get_member(attrname)

    Get a member/property of this element.

    Note

    Normally, it should be possible to just access the property in the usual Python syntax for attribute access. However, if that fails, one can request the member explicitly.

    EXAMPLES:

    Sage

        sage: p = polymake.rand_sphere(4, 20, seed=5)    # optional - jupymake

    Python

        >>> from sage.all import *
        >>> p = polymake.rand_sphere(Integer(4), Integer(20), seed=Integer(5))    # optional - jupymake

    Normally, a property would be accessed as follows:

    Sage

        sage: p.F_VECTOR                                # optional - jupymake
        20 94 148 74

    [Python]

        >>> from sage.all import *
        >>> p.F_VECTOR                                # optional - jupymake
        20 94 148 74

    However, explicit access is possible as well:

    Sage

        sage: p.get_member('F_VECTOR')                  # optional - jupymake
        20 94 148 74

    Python

        >>> from sage.all import *
        >>> p.get_member('F_VECTOR')                  # optional - jupymake
        20 94 148 74

    In some cases, the explicit access works better:

    Sage

        sage: p.type                                    # optional - jupymake
        Member function 'type' of Polymake::polytope::Polytope__Rational object
        sage: p.get_member('type')                      # optional - jupymake
        Polytope<Rational>[SAGE...]
        sage: p.get_member('type').get_member('name')   # optional - jupymake
        Polytope

    [Python]

        >>> from sage.all import *
        >>> p.type                                    # optional - jupymake
        Member function 'type' of Polymake::polytope::Polytope__Rational object
        >>> p.get_member('type')                      # optional - jupymake
        Polytope<Rational>[SAGE...]
        >>> p.get_member('type').get_member('name')   # optional - jupymake
        Polytope

    Note that in the last example calling the erroneously constructed member function `type` still works:

    Sage

        sage: p.type()                                  # optional - jupymake
        Polytope<Rational>[SAGE...]

    Python

        >>> from sage.all import *
        >>> p.type()                                  # optional - jupymake
        Polytope<Rational>[SAGE...]

  get_member_function(attrname)

    Request a member function of this element.

    Note

    It is not checked whether a member function with the given name exists.

    EXAMPLES:

    Sage

        sage: # optional - jupymake
        sage: c = polymake.cube(2)
        sage: c.contains
        Member function 'contains' of Polymake::polytope::Polytope__Rational object
        sage: V = polymake.new_object('Vector', [1,0,0])
        sage: V
        1 0 0
        sage: c.contains(V)
        true

    Python

        >>> from sage.all import *
        >>> # optional - jupymake
        >>> c = polymake.cube(Integer(2))
        >>> c.contains
        Member function 'contains' of Polymake::polytope::Polytope__Rational object
        >>> V = polymake.new_object('Vector', [Integer(1),Integer(0),Integer(0)])
        >>> V
        1 0 0
        >>> c.contains(V)
        true

    Whether a member function of the given name actually exists for that object will only be clear when calling it:

    Sage

        sage: c.get_member_function("foo")                          # optional - jupymake
        Member function 'foo' of Polymake::polytope::Polytope__Rational object
        sage: c.get_member_function("foo")()                        # optional - jupymake
        Traceback (most recent call last):
        ...
        TypeError: Can't locate object method "foo" via package "Polymake::polytope::Polytope__Rational"

    [Python]

        >>> from sage.all import *
        >>> c.get_member_function("foo")                          # optional - jupymake
        Member function 'foo' of Polymake::polytope::Polytope__Rational object
        >>> c.get_member_function("foo")()                        # optional - jupymake
        Traceback (most recent call last):
        ...
        TypeError: Can't locate object method "foo" via package "Polymake::polytope::Polytope__Rational"

  known_properties()

    List the names of properties that have been computed so far on this element.

    Note

    This is in many cases equivalent to use polymake’s `list_properties`, which returns a blank separated string representation of the list of properties. However, on some elements, `list_properties` would simply result in an error.

    EXAMPLES:

    Sage

        sage: c = polymake.cube(4)                      # optional - jupymake
        sage: c.known_properties()                      # optional - jupymake
        ['AFFINE_HULL',
         'BOUNDED',
         'CONE_AMBIENT_DIM',
         'CONE_DIM',
        ...
         'VERTICES_IN_FACETS']
        sage: c.list_properties()                       # optional - jupymake
        CONE_AMBIENT_DIM, CONE_DIM, FACETS, AFFINE_HULL, VERTICES_IN_FACETS,
        BOUNDED...

    Python

        >>> from sage.all import *
        >>> c = polymake.cube(Integer(4))                      # optional - jupymake
        >>> c.known_properties()                      # optional - jupymake
        ['AFFINE_HULL',
         'BOUNDED',
         'CONE_AMBIENT_DIM',
         'CONE_DIM',
        ...
         'VERTICES_IN_FACETS']
        >>> c.list_properties()                       # optional - jupymake
        CONE_AMBIENT_DIM, CONE_DIM, FACETS, AFFINE_HULL, VERTICES_IN_FACETS,
        BOUNDED...

    A computation can change the list of known properties:

    Sage

        sage: c.F_VECTOR                                # optional - jupymake
        16 32 24 8
        sage: c.known_properties()                      # optional - jupymake
        ['AFFINE_HULL',
         'BOUNDED',
         'COMBINATORIAL_DIM',
         'CONE_AMBIENT_DIM',
         'CONE_DIM',
        ...
         'VERTICES_IN_FACETS']

    [Python]

        >>> from sage.all import *
        >>> c.F_VECTOR                                # optional - jupymake
        16 32 24 8
        >>> c.known_properties()                      # optional - jupymake
        ['AFFINE_HULL',
         'BOUNDED',
         'COMBINATORIAL_DIM',
         'CONE_AMBIENT_DIM',
         'CONE_DIM',
        ...
         'VERTICES_IN_FACETS']

  qualified_typename()

    The qualified name of the type of this element.

    EXAMPLES:

    Sage

        sage: c = polymake.cube(4)              # optional - jupymake
        sage: c.qualified_typename()            # optional - jupymake
        'polytope::Polytope<Rational>'
        sage: c.VERTICES.qualified_typename()   # optional - jupymake
        'common::Matrix<Rational, NonSymmetric>'

    Python

        >>> from sage.all import *
        >>> c = polymake.cube(Integer(4))              # optional - jupymake
        >>> c.qualified_typename()            # optional - jupymake
        'polytope::Polytope<Rational>'
        >>> c.VERTICES.qualified_typename()   # optional - jupymake
        'common::Matrix<Rational, NonSymmetric>'

  typename()

    The name of the underlying base type of this element in polymake.

    EXAMPLES:

    Sage

        sage: c = polymake.cube(4)          # optional - jupymake
        sage: c.typename()                  # optional - jupymake
        'Polytope'
        sage: c.VERTICES.typename()         # optional - jupymake
        'Matrix'

    Python

        >>> from sage.all import *
        >>> c = polymake.cube(Integer(4))          # optional - jupymake
        >>> c.typename()                  # optional - jupymake
        'Polytope'
        >>> c.VERTICES.typename()         # optional - jupymake
        'Matrix'

  typeof()

    Return the type of a polymake “big” object, and its underlying Perl type.

    Note

    This is mainly for internal use.

    EXAMPLES:

    Sage

        sage: # optional - jupymake
        sage: p = polymake.rand_sphere(3, 13, seed=12)
        sage: p.typeof()
        ('Polymake::polytope::Polytope__Rational', 'ARRAY')
        sage: p.VERTICES.typeof()
        ('Polymake::common::Matrix_A_Rational_I_NonSymmetric_Z', 'ARRAY')
        sage: p.get_schedule('"F_VECTOR"').typeof()
        ('Polymake::Core::Scheduler::RuleChain', 'ARRAY')

    Python

        >>> from sage.all import *
        >>> # optional - jupymake
        >>> p = polymake.rand_sphere(Integer(3), Integer(13), seed=Integer(12))
        >>> p.typeof()
        ('Polymake::polytope::Polytope__Rational', 'ARRAY')
        >>> p.VERTICES.typeof()
        ('Polymake::common::Matrix_A_Rational_I_NonSymmetric_Z', 'ARRAY')
        >>> p.get_schedule('"F_VECTOR"').typeof()
        ('Polymake::Core::Scheduler::RuleChain', 'ARRAY')

    On “small” objects, it just returns empty strings:

    Sage

        sage: p.N_VERTICES.typeof()                                 # optional - jupymake
        ('', '')
        sage: p.list_properties().typeof()                          # optional - jupymake
        ('', '')

    [Python]

        >>> from sage.all import *
        >>> p.N_VERTICES.typeof()                                 # optional - jupymake
        ('', '')
        >>> p.list_properties().typeof()                          # optional - jupymake
        ('', '')

exception sage.interfaces.polymake.PolymakeError

  Bases: `RuntimeError`

  Raised if polymake yields an error message.

class sage.interfaces.polymake.PolymakeFunctionElement(obj, name, memberfunction=False)

  Bases: `InterfaceFunctionElement`

  A callable (function or member function) bound to a polymake element.

  EXAMPLES:

  Sage

      sage: # optional - jupymake
      sage: c = polymake.cube(2)
      sage: V = polymake.new_object('Vector', [1,0,0])
      sage: V
      1 0 0
      sage: c.contains
      Member function 'contains' of Polymake::polytope::Polytope__Rational object
      sage: c.contains(V)
      true

  Python

      >>> from sage.all import *
      >>> # optional - jupymake
      >>> c = polymake.cube(Integer(2))
      >>> V = polymake.new_object('Vector', [Integer(1),Integer(0),Integer(0)])
      >>> V
      1 0 0
      >>> c.contains
      Member function 'contains' of Polymake::polytope::Polytope__Rational object
      >>> c.contains(V)
      true

class sage.interfaces.polymake.PolymakeJuPyMake(seed=None, verbose=False)

  Bases: `PolymakeAbstract`

  Interface to the polymake interpreter using JuPyMake.

  In order to use this interface, you need to either install the optional polymake package for Sage, or install polymake system-wide on your computer; it is available from https://polymake.org. Also install the jupymake Python package.

  Type `polymake.[tab]` for a list of most functions available from your polymake install. Type `polymake.Function?` for polymake’s help about a given `Function`. Type `polymake(...)` to create a new polymake object, and `polymake.eval(...)` to run a string using polymake and get the result back as a string.

  EXAMPLES:

  Sage

      sage: from sage.interfaces.polymake import polymake_jupymake as polymake
      sage: type(polymake)
      <...sage.interfaces.polymake.PolymakeJuPyMake...
      sage: p = polymake.rand_sphere(4, 20, seed=5)       # optional - jupymake
      sage: p                                             # optional - jupymake
      Random spherical polytope of dimension 4; seed=5...
      sage: set_verbose(3)
      sage: p.H_VECTOR;                                   # optional - jupymake # random
      used package ppl
        The Parma Polyhedra Library ...
      sage: p.H_VECTOR                                    # optional - jupymake
      1 16 40 16 1
      sage: set_verbose(0)
      sage: p.F_VECTOR                                    # optional - jupymake
      20 94 148 74
      sage: print(p.F_VECTOR._sage_doc_())                # optional - jupymake # random
      property_types/Algebraic Types/Vector:
       A type for vectors with entries of type Element.

       You can perform algebraic operations such as addition or scalar multiplication.

       You can create a new Vector by entering its elements, e.g.:
          $v = new Vector<Int>(1,2,3);
       or
          $v = new Vector<Int>([1,2,3]);

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.polymake import polymake_jupymake as polymake
      >>> type(polymake)
      <...sage.interfaces.polymake.PolymakeJuPyMake...
      >>> p = polymake.rand_sphere(Integer(4), Integer(20), seed=Integer(5))       # optional - jupymake
      >>> p                                             # optional - jupymake
      Random spherical polytope of dimension 4; seed=5...
      >>> set_verbose(Integer(3))
      >>> p.H_VECTOR;                                   # optional - jupymake # random
      used package ppl
        The Parma Polyhedra Library ...
      >>> p.H_VECTOR                                    # optional - jupymake
      1 16 40 16 1
      >>> set_verbose(Integer(0))
      >>> p.F_VECTOR                                    # optional - jupymake
      20 94 148 74
      >>> print(p.F_VECTOR._sage_doc_())                # optional - jupymake # random
      property_types/Algebraic Types/Vector:
       A type for vectors with entries of type Element.

       You can perform algebraic operations such as addition or scalar multiplication.

       You can create a new Vector by entering its elements, e.g.:
          $v = new Vector<Int>(1,2,3);
       or
          $v = new Vector<Int>([1,2,3]);

  Python strings are translated to polymake (Perl) identifiers. To obtain Perl strings, use strings containing double-quote characters. Python dicts are translated to Perl hashes.

  Sage

      sage: # long time, optional - internet jupymake perl_mongodb
      sage: L = polymake.db_query({'"_id"': '"F.4D.0047"'},
      ....:                       db='"LatticePolytopes"',
      ....:                       collection='"SmoothReflexive"'); L
      BigObjectArray
      sage: len(L)
      1
      sage: P = L[0]
      sage: sorted(P.list_properties(), key=str)
      [..., LATTICE_POINTS_GENERATORS, ..., POINTED, ...]
      sage: P.F_VECTOR
      20 40 29 9

  [Python]

      >>> from sage.all import *
      >>> # long time, optional - internet jupymake perl_mongodb
      >>> L = polymake.db_query({'"_id"': '"F.4D.0047"'},
      ...                       db='"LatticePolytopes"',
      ...                       collection='"SmoothReflexive"'); L
      BigObjectArray
      >>> len(L)
      1
      >>> P = L[Integer(0)]
      >>> sorted(P.list_properties(), key=str)
      [..., LATTICE_POINTS_GENERATORS, ..., POINTED, ...]
      >>> P.F_VECTOR
      20 40 29 9

  eval(code, **kwds)

    Evaluate a command.

    INPUT:

    - `code` – a command (string) to be evaluated

    Different reaction types of polymake, including warnings, comments, errors, request for user interaction, and yielding a continuation prompt, are taken into account.

    EXAMPLES:

    Sage

        sage: from sage.interfaces.polymake import polymake_jupymake as polymake
        sage: p = polymake.cube(3)              # optional - jupymake  # indirect doctest

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.polymake import polymake_jupymake as polymake
        >>> p = polymake.cube(Integer(3))              # optional - jupymake  # indirect doctest

    Here we see that remarks printed by polymake are displayed if the verbosity is positive:

    Sage

        sage: set_verbose(1)
        sage: p.N_LATTICE_POINTS                # optional - jupymake # random
        used package latte
          LattE (Lattice point Enumeration) is a computer software dedicated to the
          problems of counting lattice points and integration inside convex polytopes.
          Copyright by Matthias Koeppe, Jesus A. De Loera and others.
          http://www.math.ucdavis.edu/~latte/
        27
        sage: set_verbose(0)

    [Python]

        >>> from sage.all import *
        >>> set_verbose(Integer(1))
        >>> p.N_LATTICE_POINTS                # optional - jupymake # random
        used package latte
          LattE (Lattice point Enumeration) is a computer software dedicated to the
          problems of counting lattice points and integration inside convex polytopes.
          Copyright by Matthias Koeppe, Jesus A. De Loera and others.
          http://www.math.ucdavis.edu/~latte/
        27
        >>> set_verbose(Integer(0))

    If polymake raises an error, the polymake interface raises a `PolymakeError`:

    Sage

        sage: polymake.eval('FOOBAR(3);')       # optional - jupymake
        Traceback (most recent call last):
        ...
        PolymakeError: Undefined subroutine &Polymake::User::FOOBAR called...

    Python

        >>> from sage.all import *
        >>> polymake.eval('FOOBAR(3);')       # optional - jupymake
        Traceback (most recent call last):
        ...
        PolymakeError: Undefined subroutine &Polymake::User::FOOBAR called...

    If a command is incomplete, then polymake returns a continuation prompt. In that case, we raise an error:

    Sage

        sage: polymake.eval('print 3')          # optional - jupymake
        Traceback (most recent call last):
        ...
        SyntaxError: Incomplete polymake command 'print 3'
        sage: polymake.eval('print 3;')         # optional - jupymake
        '3'

    [Python]

        >>> from sage.all import *
        >>> polymake.eval('print 3')          # optional - jupymake
        Traceback (most recent call last):
        ...
        SyntaxError: Incomplete polymake command 'print 3'
        >>> polymake.eval('print 3;')         # optional - jupymake
        '3'

    However, if the command contains line breaks but eventually is complete, no error is raised:

    Sage

        sage: print(polymake.eval('$tmp="abc";\nprint $tmp;'))  # optional - jupymake
        abc

    Python

        >>> from sage.all import *
        >>> print(polymake.eval('$tmp="abc";\nprint $tmp;'))  # optional - jupymake
        abc

    When requesting help, polymake sometimes expects the user to choose from a list. In that situation, we abort with a warning, and show the list from which the user can choose; we could demonstrate this using the `help()` method, but here we use an explicit code evaluation:

    Sage

        sage: print(polymake.eval('help "TRIANGULATION";'))     # optional - jupymake # random
        doctest:warning
        ...
        UserWarning: Polymake expects user interaction. We abort and return
        the options that Polymake provides.
        There are 5 help topics matching 'TRIANGULATION':
        1: objects/Cone/properties/Triangulation and volume/TRIANGULATION
        2: objects/Polytope/properties/Triangulation and volume/TRIANGULATION
        3: objects/Visualization/Visual::PointConfiguration/methods/TRIANGULATION
        4: objects/Visualization/Visual::Polytope/methods/TRIANGULATION
        5: objects/PointConfiguration/properties/Triangulation and volume/TRIANGULATION

    [Python]

        >>> from sage.all import *
        >>> print(polymake.eval('help "TRIANGULATION";'))     # optional - jupymake # random
        doctest:warning
        ...
        UserWarning: Polymake expects user interaction. We abort and return
        the options that Polymake provides.
        There are 5 help topics matching 'TRIANGULATION':
        1: objects/Cone/properties/Triangulation and volume/TRIANGULATION
        2: objects/Polytope/properties/Triangulation and volume/TRIANGULATION
        3: objects/Visualization/Visual::PointConfiguration/methods/TRIANGULATION
        4: objects/Visualization/Visual::Polytope/methods/TRIANGULATION
        5: objects/PointConfiguration/properties/Triangulation and volume/TRIANGULATION

    By default, we just wait until polymake returns a result. However, it is possible to explicitly set a timeout. The following usually does work in an interactive session and often in doc tests, too. However, sometimes it hangs, and therefore we remove it from the tests, for now:

    Sage

        sage: c = polymake.cube(15)             # optional - jupymake
        sage: polymake.eval('print {}->F_VECTOR;'.format(c.name()), timeout=1) # not tested # optional - jupymake
        Traceback (most recent call last):
        ...
        RuntimeError: Polymake fails to respond timely

    Python

        >>> from sage.all import *
        >>> c = polymake.cube(Integer(15))             # optional - jupymake
        >>> polymake.eval('print {}->F_VECTOR;'.format(c.name()), timeout=Integer(1)) # not tested # optional - jupymake
        Traceback (most recent call last):
        ...
        RuntimeError: Polymake fails to respond timely

    We verify that after the timeout, polymake is still able to give answers:

    Sage

        sage: c                                 # optional - jupymake
        cube of dimension 15
        sage: c.N_VERTICES                      # optional - jupymake
        32768

    [Python]

        >>> from sage.all import *
        >>> c                                 # optional - jupymake
        cube of dimension 15
        >>> c.N_VERTICES                      # optional - jupymake
        32768

    Note, however, that the recovery after a timeout is not perfect. It may happen that in some situation the interface collapses and thus polymake would automatically be restarted, thereby losing all data that have been computed before.

  is_running()

    Return `True` if `self` is currently running.

sage.interfaces.polymake.polymake_console(command='')

  Spawn a new polymake command-line session.

  EXAMPLES:

  Sage

      sage: from sage.interfaces.polymake import polymake_console
      sage: polymake_console()        # not tested
      Welcome to polymake version ...
      ...
      Ewgenij Gawrilow, Michael Joswig (TU Berlin)
      http://www.polymake.org

      This is free software licensed under GPL; see the source for copying conditions.
      There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

      Press F1 or enter 'help;' for basic instructions.

      Application polytope currently uses following third-party software packages:
      4ti2, bliss, cdd, latte, libnormaliz, lrs, permlib, ppl, sketch, sympol, threejs, tikz, topcom, tosimplex
      For more details:  show_credits;
      polytope >

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.polymake import polymake_console
      >>> polymake_console()        # not tested
      Welcome to polymake version ...
      ...
      Ewgenij Gawrilow, Michael Joswig (TU Berlin)
      http://www.polymake.org

      This is free software licensed under GPL; see the source for copying conditions.
      There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

      Press F1 or enter 'help;' for basic instructions.

      Application polytope currently uses following third-party software packages:
      4ti2, bliss, cdd, latte, libnormaliz, lrs, permlib, ppl, sketch, sympol, threejs, tikz, topcom, tosimplex
      For more details:  show_credits;
      polytope >

sage.interfaces.polymake.reduce_load_Polymake()

  Return the polymake interface object defined in `sage.interfaces.polymake`.

  EXAMPLES:

  Sage

      sage: from sage.interfaces.polymake import reduce_load_Polymake
      sage: reduce_load_Polymake()
      Polymake

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.polymake import reduce_load_Polymake
      >>> reduce_load_Polymake()
      Polymake