TODO

  • Ganz an Anfang eine kurze Einfuehrung: Was ist Polymake ueberhaupt? Was kann es, was kann es nicht?
  • Am Ende vielleicht noch eine FAQ einfuegen, die kleinere Fragen klaert. Erstmal eine Liste mit Fragen anlegen, beantworten koennen wir sie dann spaeter noch…
  • Wo kann man Hilfe zu Polymake bekommen? Gibt's schon Foren/Mailinglisten?
  • Bilder in den Teil zur Visualisierung hinzufuegen.
  • Wir muessen noch was ueber Applications schreiben.

Introduction

polymake is a software system for analyzing convex polytopes. It was written by Ewgenij Gawrilow, Michael Joswig and many other contributors. In this tutorial we assume that you already installed the software. If you have trouble installing polymake, please read the manual on how to install it from source code.

To start polymake you need to open a terminal on your system. In the following the command prompt of the shell will be denoted by %. To run polymake simply type

% polymake

and hit return. You will be greeted with the following message:

Welcome to polymake version 2.9.9, released on November 05, 2010
Copyright (c) 1997-2010
Ewgenij Gawrilow, Michael Joswig (TU Darmstadt)
http://www.polymake.de

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:
cddlib, javaview, jreality, lrslib, nauty, povray
For more details:  show_credits;
polytope > 

Now polymake is ready for use and waits for you to enter commands. In our example its command prompt (very last line of output above) says

polytope >

which indicates that you are using the application polytope. But do not worry about applications for now, we will come back to them later. First we will look at a simple example.

Constructing the 3-Simplex

A polytope in Rd can be described either as the convex hull of finitely many points or the bounded intersection of finitely many halfspaces. Let us construct a 3-simplex with the vertices (0,0,0), (1,0,0), (0,1,0), and (0,0,1). At first we need to create a new object of type Polytope<Rational>. To access it later we store it in the variable $p.

polytope > $p = new Polytope<Rational>();

As for now, this object does not contain any information at all. We can enter the vertices either as

polytope > $p->POINTS=<<".";
polytope (2)> 1 0 0 0
polytope (3)> 1 1 0 0
polytope (4)> 1 0 1 0
polytope (5)> 1 0 0 1
polytope (6)> .

or we can enter them all at once row by row.

polytope > $p->POINTS=[[1,0,0,0],[1,1,0,0],[1,0,1,0],[1,0,0,1]];

Here we only need one command line to enter all of the points. This way of entering points might be a little easier, especially since it is more convenient to correct typos. There is yet another option of entering points. You can assign points directly when defining the new object:

$p = new Polytope<Rational>(POINTS=>[[1,0,0,0],[1,1,0,0],[1,0,1,0],[1,0,0,1]]);

No matter how you enter the points, you probably noticed that the coordinates are preceded by an additional 1 in the first column. The leading 1 coordinate means homogenization. This way polymake can deal with unbounded polyhedra in a very convenient way

Now that we generated a 3-simplex via a vertex description, we can start asking polymake about its properties. One can access a property via the operator. To get a quick overview over all available properties just type in print $p→ and press the tab key. This normally prints out a very long list which is a little confusing. If you already know or you can guess with which letter a certain property starts, then you can also enter the letter and use the tab key to get a listing of all the properties that start with that given letter only. Anyway, here is a list that shows you how to compute a few standard properties of polytopes. Keeping in mind that we deal with the 3-simplex none of polymake's answers should be surprising.

Polytope bounded? Yes!

polytope > print $p->BOUNDED;
1

Polytope cubical? No!

polytope > print $p->CUBICAL;
0

Facet-defining hyperplanes (aka H-representation):

polytope > print $p->FACETS;
1 -1 -1 -1
0 1 0 0
0 0 1 0
0 0 0 1

Every line of this matrix represents one inequality in a way that 0 is smaller or equals the scalar product of the line with (1,x,y,z). For example the first line stands for the inequality x+y+z≤1, the last one stands for 0≤z.

Therefore the number of facets is 4.

polytope > print $p->N_FACETS;
4

Compute the f-vector:

polytope > print $p->F_VECTOR;
4 6 4

This means that the 3-simplex has 4 vertices, 6 edges and 4 facets which agrees with the number of vertices polymake counts:

 
polytope > print $p->N_VERTICES;
4

Polytope neighborly? Yes!

polytope > print $p->NEIGHBORLY;
1
polytope > print $p->SIMPLE;
1

Now we assume that we have given our simplex in terms of the inequalities 0≤x,y,z and x+y+z≤1 and see how we can assign this information to a new polytope.

polytope > $q = new Polytope<Rational>(INEQUALITIES=>[[0,1,0,0],[0,0,1,0],[0,0,0,1],[1,-1,-1,-1]]);

Of course, the aforementioned different ways of entering the data would have worked out as well.

The computation of the vertices of our polytope is now done as follows.

polytope > print $q->VERTICES;
1 0 0 1
1 0 1 0
1 1 0 0
1 0 0 0

This is just an exemplary calculation and completes our task, namely to convert V-representations and H-representations into one another.

As a matter of fact, polymake knows a bit about standard constructions of certain polytopes. So you will never actually have to type in your 3-simplex example. You can use the following command instead.

polytope > $p = simplex(3);

Basic Constructions

Now we want to see how we can construct a polytope without entering actual points but only by using the possibilities polymake offers us to construct from scratch. Our examples will be the icosahedron and the dodecahedron. The occuring calculations can easily be verified with some basic mathematics and/or by looking up the relevant formulas.

Important note: The following operations on polytopes are presented in order to give an illustrative example of how they are used. But be aware that it is usually not recommended to use irrational expressions like sqrt(5). The reason is that by default polymake uses a rational representation for any numerical value. This can explicitly be indicated by the keyword Rational as in Polytope<Rational> (see above). Thus polymake does not work with the exact irrational values, which can influence the combinatorial properties of the polytope heavily. As an example, consider the 3-cube where any slight perturbation of a single vertex yields a non-simple polytope.

Let us start by generating a (regular) pentagon.

polytope > $pentagon = n_gon(5,1/10*sqrt(50+10*sqrt(5)));

The second parameter gives us the radius of the circumscribing circle. In our example we choose it such that our pentagon has edges of length 1. This edge length determines the edge length of the icosahedron. As the center of the pentagon, polymake chooses the origin of its coordinate system.

The next step is to generate two pyramids that will to some extent serve as the “top” and the “bottom” of our icosahedron.

polytope > $bottom = pyramid($pentagon,-1/10*sqrt(50-10*sqrt(5)));

polytope > $top = pyramid($pentagon,1/10*sqrt(50-10*sqrt(5)));

The heights of the pyramids are chosen such that the triangles on its surface are equilateral. By using heights of different signs, we make sure that the two pyramids over the same pentagon are directed oppositely.

Since the pyramids still share the same base, we have to move them in the direction of their height.

polytope > $translated_bottom = translate($bottom,new Vector<Rational>(0,0,-1/4*sqrt(10+2*sqrt(5))+1/10*sqrt(50-10*sqrt(5))));

polytope > $translated_top = translate($top,new Vector<Rational>(0,0,1/4*sqrt(10+2*sqrt(5))-1/10*sqrt(50-10*sqrt(5))));

Observe how we create a new object of the type Vector<Rational> inside the translate-command. The length of the translation vector is determined by the difference of the radius of the circumsphere of our icosahedron and the height of our pyramids. We could basically achieve the same result by only moving one pyramid and doubling the translation vector. But this would also move the center of our final icosahedron away from the origin.

Before we are done, we need to rotate one of the pyramids (e.g. the top pyramid) by an angle of π/5.

polytope > $pi = Math::Trig::pi;

polytope > $m = new Matrix<Rational>([[1,0,0,0],[0,cos($pi/5),-sin($pi/5),0],[0,sin($pi/5),cos($pi/5),0],[0,0,0,1]]);

polytope > $rotated_top = transform($translated_top, $m);

The rotation is realized with an orthogonal transformation, determined by the given Matrix<Rational>. The value of π is gathered from the corresponding constant in Perl.

We can now define the icosahedron as the convex hull of the two pyramids we constructed:

polytope > $icosahedron = conv($translated_bottom,$rotated_top);

Now that we have an icosahedron it is very easy to construct its dual, the dodecahedron:

polytope > $dodecahedron = polarize($icosahedron);

Since we constructed the icosahedron in such a way that its center lies in the origin of the coordinate system, the polarized polytope is regular, just like we wanted to have it.

It may also be interesting to construct a truncated icosahedron (a soccer ball) from the icosahedron. The polytope can be constructed by cutting of each of the 12 vertices of the icosahedron such that one third of every edge is cut off.

polytope > $trunc_icosahedron = truncation($icosahedron, All, cutoff=>2/3);

The parameter All says that all vertices are going to be cut off and by the option cutoff you can specify the exact position of the hyperplane cutting off the vertices. The default value of cutoff is 1/2.

The truncated dodecahedron can be constructed in the same way:

polytope > $trunc_dodecahedron = truncation($dodecahedron, All, cutoff=>2/3);

Finally, after you invested some time into constructing a polytope, you can save it for the future.

polytope > save($icosahedron,"ico");

The second parameter determines the name of the file. If no suffix is given, .poly will be added. You can use relative paths from the current directory as well as absolute paths. You can even leave away the second parameter, polymake will then name the file after the variable.

To load a previously saved polytope, use the command

polytope > $p = load("icosahedron.poly");

By the way, even when you look for the right filename, you can use the tab completion.

Dealing with Graphs

Coming from polytopes the first situation in which a graph occurs is the vertex-edge graph of a polytope, which is like every other graph determined by its adjacency matrix

polytope > $c = cube(3);
polytope > print $c->GRAPH->ADJACENCY;
{1 2 4}
{0 3 5}
{0 3 6}
{1 2 7}
{0 5 6}
{1 4 7}
{2 4 7}
{3 5 6}

Apart from the adjacency matrix you can also explore a graph as a sequence of its edges:

print $c->GRAPH->EDGES;
{0 1}
{0 2}
{1 3}
{2 3}
{0 4}
{1 5}
{4 5}
{2 6}
{4 6}
{3 7}
{5 7}
{6 7}

Now, let us take a closer look at the graph of a cube:

Since the nodes of the graph correspond to the vertices of the cube and the edges of the graph correspond to the edges of the cube, it is no surprise that the graph of the cube has 8 nodes and 12 edges:

polytope > $c = cube(3);
polytope > print $c->GRAPH->N_NODES;
8
print $c->GRAPH->N_EDGES;
12

Of course the graph of the 3-cube, like the graph of every other polytope, has to be connected and since the 3-cube is a 3-dimensional polytope its graph is not only connected but 3-connected.

polytope > print $c->GRAPH->CONNECTED;
1
print $c->CONNECTIVITY;
3

In fact the graph of a n-dimensional polytope has to be n-connected, so for a 5-simplex polymake tells us correctly that its graph is 5-connected:

polytope > print simplex(5)->GRAPH->CONNECTIVITY;
5

Other properties of graphs one might be interested in are the degree of the nodes of a graph, which can be computed with the command NODE_DEGREES and the diameter of the graph:

print $c->GRAPH->NODE_DEGREES;
3 3 3 3 3 3 3 3
print $c->GRAPH->DIAMETER;
3

Of course it is also possible to visualize graphs (the algorithm for the visualization of graphs is based on the pseudo-physical model described in this paper).

$c->GRAPH->VISUAL;

In order to construct graphs which are not immutable, lets take a look at the type props::Graph. This refers to C++ class from the polymake Template Library named Graph, and this is where the data structure and most algorithms reside. It is possible to directly manipulate objects of this type, and these are not immutable, they can be changed. The following shows how one can create a 5-cycle. Calling the method edge creates an edge if it did not exist before. The output is the ordered list of neighbors per node.

polytope > $g=new props::Graph(5);                      
polytope > for (my $i=0; $i<5; ++$i) { $g->edge($i,($i+1)%5) };
polytope > print $g;
{1 4}               
{0 2}               
{1 3}               
{2 4}               
{0 3}               

If a graph has many nodes it is convenient to know which line of the output refers to which node. If an array of labels is given this could also be used instead of the numbers which are the default.

polytope > print rows_labeled($g);
0:1 4                             
1:0 2                             
2:1 3                             
3:2 4                             
4:0 3                             

There are other ways to change such a graph. Contracting the edge (x,y) where x is smaller than y implies that the node y is destroyed.

polytope > $g->delete_edge(0,1);
polytope > $g->contract_edge(2,3);
polytope > $g->squeeze();

However, most of our graph algorithms expect a graph with consecutively numbered nodes. The function squeeze takes care of a proper renumbering, but this takes linear time in the number of nodes.

polytope > print rows_labeled($g);
0:4
1:2
2:1 4
3:0 2

How do I iterate over the adjacent nodes to a given node?

foreach (@{$g->adjacent_nodes(0)}) {
   print "node number $_ is adjacent to node number 0\n";
}

It is also legal to copy all adjacent nodes to an array as in:

@x = @{$g->adjacent_nodes(0)};

Subsequently, the individial neighbors can be accessed at random, for instance, as $x[1]. However, for technical reasons too difficult to explain here, it is not legal to write $g→adjacent_nodes(0)→[1]! Usually it is preferred to avoid copying; so use constructions like foreach and map if possible.

Further Details

The next step after we gained a basic impression of the way polymake works is to get an idea of how perl comes into the game.

The language that the interactive version of polymake speaks is a dialect of Perl that we refer to as polymake/Perl. See www.perl.org for comprehensive Perl information. Note also that the ordinary Perl manual pages are particularly useful. This short section here cannot be a replacement for a thorough introduction to this language, but we want to focus on a few key points that are relevant to polymake.

As far as variables are concerned Perl distinguishes between scalar variables (which start by $), arrays (@), and hashes (%). polymake's object hierarchy is now completely reflected on the Perl side, and objects are referred to via references (hence they look like scalar variables at first sight). Properties of an object are dereferenced via the operator. An example. And, don't forget: commands are always terminated by a semicolon (or closing curly braces, provided that the syntax pattern fits).

polytope > $p = permutahedron(3);

polytope > print $p;
Polymake::polytope::Polytope__Rational=ARRAY(0x2f2f1c0)
polytope > print $p->N_FACETS;
14

This constructs a new object (here a 3-dimensional permutahedron) which is stored in the variable $p. The true nature of the object becomes visible if it is printed. In this case it is a polymake object from the application polytope, and it happens to be of type Polytope<Rational>. This last type is a valid polymake type name (defined in apps/polytope/rules/main.rules) which is not proper Perl syntax. But it is correct polymake/Perl syntax. Technically, $p is a reference to an array (but it should be never treated as an array unless you are deliberately trying to crash polymake). One of the many properties of a polytope is N_FACETS, the number of facets. This time it actually is a scalar variable. The types of the properties are determined in apps/polytope/rules/polytope_properties.rules.

Scalar properties can be used in arithmetic expressions right away.

polytope > $i = ($p->N_FACETS * $p->N_FACETS) * 15;

polytope > print $i;
2940

The property FACET_SIZES (which lists the number of vertices contained in each facet), for instance, is of polymake/Perl type Array<Int>. On the Perl side it can be treated as an ordinary reference to an array.

polytope > $fs = $p->FACET_SIZES;

polytope > print $fs;
6 4 6 4 6 4 4 6 6 6 4 6 4 6
polytope > print $fs->[0];
6

Copying this array and changing its first element works as follows.

polytope > @my_copy = @{$fs};

polytope > print "@my_copy";
6 4 6 4 6 4 4 6 6 6 4 6 4 6
polytope > $my_copy[0] = 100;

polytope > print "@my_copy";
100 4 6 4 6 4 4 6 6 6 4 6 4 6

Note that print @my_copy (that is, without the quotes) also works but does not add spaces between the entries. The reason why the command print $fs above works like print ”@{$fs}” is that special print handlers are implemented for the polymake/Perl objects.

A remark for the Perl experts: using my for local variables is often not a good idea since, for technical reasons, my is local for each single command line. This means that a variable declared my does not exist after the command line is executed.

polytope > my $c=cube(3); print $c->DIM;
3
polytope > my $c=cube(3);

polytope > print $c->DIM;

polymake:  ERROR: reference to an undeclared variable $c at input line 1.

Any property that we have once computed for a certain polytope will then be stored for later use. It is possible to print an overview of the properties that we already have computed. As an example, reconsider the aforementioned 3-simplex as we defined it by its 4 vertices.

 
polytope > print join(", ", $p->list_properties());
POINTS

Not very surprisingly, the only known thing about the polytope is the set of points of which it is the convex hull.

polytope > $p->FACETS;
polymake: used package cddlib
  Implementation of the double description method of Motzkin et al.
  Copyright by Komei Fukuda.
  http://www.ifor.math.ethz.ch/~fukuda/cdd_home/cdd.html


polytope > print join(", ", $p->list_properties());
POINTS, N_POINTS, FEASIBLE, BOUNDED, DIM, AMBIENT_DIM, FACETS, AFFINE_HULL

As we see, in order to compute the facets, there are many other values computed as well. We are now interested in the question, which operations have to be carried out in order to compute a certain property of our polytope.

polytope > $schedule = $p->get_schedule("VERTICES");

polytope > print join("\n",$schedule->list);
POINTS_IN_FACETS : POINTS, FACETS
sensitivity check for VertexPerm
VERTICES_IN_FACETS, VERTICES : POINTS_IN_FACETS, POINTS

More interestingly, the schedule for a given task can be applied to a polytope in order to perform the computation (without any output though). The beauty of this is that it can be applied to many similar polytopes thus saving time for computing the same sequence of rules again and again.

polytope > $schedule->apply($p);

polytope > print join(", ",$p->list_properties());
POINTS, N_POINTS, FEASIBLE, BOUNDED, DIM, AMBIENT_DIM, FACETS, AFFINE_HULL, VERTICES_IN_FACETS, VERTICES

Visualization of Polytopes

In this section we will show how to do visualization with polymake. To get a list of visualization methods available, use the built-in help system, e.g. to obtain the visualization possibilities for Polytopes in application 'polytope' type:

polytope > help 'objects/Polytope/methods/Visualization';
Subtopics of objects/Polytope/methods/Visualization:
GALE, SCHLEGEL, VISUAL, VISUAL_BOUNDED_GRAPH, VISUAL_DUAL, VISUAL_DUAL_FACE_LATTICE,
VISUAL_DUAL_GRAPH, VISUAL_FACE_LATTICE, VISUAL_GRAPH, VISUAL_TRIANGULATION_BOUNDARY

To visualize polytopes polymake uses jReality which is a Java based package designed for 3D-Visualization. The polytopes are visualized with the jReality viewer, which is an interactive application which lets you rotate, scale and translate your polytopes. The polytopes visualized with the jReality viewer can also be exported as images or Postscript files.

As a simple example we want to visualize the 3-cube

polytope > cube(3)->VISUAL;
polymake: used package jreality
  jReality is a visualization and sonification library focused on mathematical and scientific content.
  http://www.jreality.de

Now the jReality viewer visualizing the cube should open. By default you see your polytope in the “Viewer”-mode. Since in this mode the polytope you see looks quite different from how your polytope looks like if you export it (for example the labels of vertices and and facets are not visualized) you should switch to the “Soft-Viewer”-mode by pressing F2. To get back to the “Viewer”-Mode just press F1. Another good reason for switching to the “Soft-Viewer”-mode is that only in this mode you are able to export the polytopes as images (the other export possibilities also work in the other mode). After switching to the “Soft-Viewer”-mode the visualized cube should look like this:

You might want to change the name of the visualized object in the drawing. In order to do so, use the option Name

polytope > cube(3)->VISUAL(Name=>'cube');

Changing Colors and Other Properties

To change the appearance of a polytope one at first has to know that there are various ways to specify colors in polymake, i.e the color red may be given by

  • the String 'red', which will be looked up in rgb.txt to obtain the rgb values,
  • the String '1 0 0', which contains three decimal values in the interval [0,1] corresponding to the 'r g b'-values of the color,
  • the String '255 0 0', which contains three integer values in the interval [0,255] corresponding to the 'r g b'-values of the color,
  • an object new RGB(1,0,0) of polymake's RGB class.

To change the colors of vertices, edges and facets the properties VertexColor, EdgeColor and FacetColor are used. There are to different ways to change the color of the faces of a polytope. The following example shows how to specify one color for all the facets of the cube:

polytope > cube(3)->VISUAL(FacetColor=>'blue');

Of course the color of the edges and vertices can be changed in the same way.

In order to give the faces of a polytope different colors, these colors can be specified by an array which contains one color for each face:

polytope > cube(3)->VISUAL(FacetColor=>['blue','yellow','blue','yellow','blue','yellow']);

The thickness of the vertices and edges can be defined with the options VertexThickness and EdgeThickness by a rational number greater or equals 0, while '1' is the default value.

polytope > cube(3)->VISUAL(VertexThickness=>'3');

The options VertexThickness and EdgeThickness can also be used to remove the vertices or edges of a polytope. In order to so, just set the thickness to zero. Another way to remove the vertices, edges and also facets of the Polytope is the option VertexStyle (EdgeStyle or FacetStyle). Setting this option to 'hidden' removes the vertices, edges or facets and in the case of vertices and facets also their labels.

cube(3)->VISUAL(FacetStyle =>'hidden');

The thickness of edges and vertices can also be changes using jReality. After visualizing your polytope just press Ctrl+1 to increase the size of the vertices and Alt+1 to decrease it. To change the thickness of the edges use Ctrl+2 and Alt+2.

Like the colors of vertices and facets the labels of them can be changed by specifying an array containing the labels for each of the vertices or facets. So, to define the facet-labels of the 3-cube an array with the six labels as entries is needed:

polytope > cube(3)->VISUAL(FacetLabels=>['one','two','three','four','five','six']);

Again the options FacetLabel and VertexLabel can be used to remove the labels of facets or vertices by setting this options to 'hidden', which is in the most cases the default behavior of this options.

The transparency of the facets of a polytope is a rational number between 0 and 1 which can be changed with the option FacetTransparency. The following command visualizes a 3-cube which facets are 50% transparent:

polytope > cube(3)->VISUAL(FacetTransparency=>0.5);

Visualizing Schlegel Diagrams

If you try to visualize a 4-dimensional polytope, polymake automatically constructs a Schlegel diagram of that polytope. A Schlegel diagram is a projection of the edges and vertices of a polytope onto an arbitrary facet of that polytope. So, the dimension of the Schlegel diagram is always one dimension lower than the dimension of the polytope. There a different ways to visualize the Schlegel diagram of a polytope with polymake. If you want to visualize the Schlegel diagram of a 4-dimensional polytope, you can just use VISUAL. To visualize the Schlegel diagram of a polytope of dimension 3 or lower both of the following commands can be used (of course you can also use this commands for 4 dimensional polytopes):

polytope > cube(3) -> SCHLEGEL;
polytope > cube(3) -> SCHLEGEL_DIAGRAM -> VISUAL;

The appearance of a Schlegel diagram can be changes like the appearance of polytopes.

Another attribute of Schlegel diagrams which can be changed is the facet of the polytope on which the edges and vertices are projected to construct the Schlegel diagram

With the following two commands you get two different looking Schlegel diagrams of a prism over a 2-simplex, the first one projected on a triangular facet, the second one projected on one of the rectangular facets.

polytope > prism(simplex(2))-> SCHLEGEL(FACET=>1);
polytope > prism(simplex(2))-> SCHLEGEL(FACET=>3);

If the facet on which the Schlegel diagram is projected is not specified, polymake always projects on the facet identified with the number zero.

polymake can also visualize the construction of a Schlegel diagram of 3-dimensional Polytopes:

polytope > simplex(3)->SCHLEGEL->CONSTRUCTION;
polymake: used package cddlib
  Implementation of the double description method of Motzkin et al.
  Copyright by Komei Fukuda.
  http://www.ifor.math.ethz.ch/~fukuda/cdd_home/cdd.html

There also are two ways to change the position of the viewpoint of the projection that creates the Schlegel diagram. With the option FACET_POINT the intersection of the view ray with a facet can be specified. In order to get a nice visualization of the Schlegel diagram the facet on which the Schlegel diagram is projected should be the same than the facet on which lies the intersection point specified with the option FACET_POINT. In the following example you see two Schlegel diagrams of a 3-cube, which were projected onto the facet on the hyperplane z = −1. The first with an intersection point in the middle of the facet, the second with an intersection point which is not in the middle.

polytope > cube(3) -> SCHLEGEL(FACET=>5, FACET_POINT=>[1,0,0,-1]);
polytope > cube(3) -> SCHLEGEL(FACET=>5, FACET_POINT=>[1,0.3,0.3,-1]);

The other way to change the viewpoint of the projection is, to use the option INNER_POINT to set a point inside the polytope which lies on the view ray.

Visualizing the Face Lattice

The faces of a polytope form a graded lattice, its face lattice. The face lattice is formed by the faces of the polytope partially ordered by inclusion.

There are two ways to visualize the face lattice of a polytope:

polytope > simplex(3) -> VISUAL_FACE_LATTICE;
polytope > simplex(3) -> HASSE_DIAGRAM->VISUAL;

The labels of the Hasse diagram can be changed with the option AtomLabels. The labels of the atoms have to be inserted in an array where each entry of the array corresponds to an atom. The following command visualizes the Hasse diagram of a 3-simplex, with labels a,b,c,d.

simplex(3) -> HASSE_DIAGRAM->VISUAL(AtomLabels=>[’a’,’b’,’c’,’d’]);

With the option ArrowStyle the appearance of the arrows between the nodes of the diagram can be changed. By default this arrows are just undirected lines between the node (ArrowLine is set to '0'). With the value '1' you get arrows pointing in the direction of the maximal element of the lattice and with the value '-1' you get arrows pointing towards the minimal element.

Rendering Polytopes with POV-Ray

If you need some well rendered pictures of your polytope you should try out POV-Ray.

Use the command

polytope > povray(cube(3)->VISUAL, File=>'cube.pov');
polymake: used package povray
  Persistence of Vision Ray tracer, a tool for creating 3-d photo-realistic images.
  http://www.povray.org

to create the file cube.pov which contains the 3-cube encoded in the POV-Ray scene description language.

To render the image, type

% povray cube.pov

into the command shell. This should generate a new file named cube.png.

Maybe this image does not fulfill your expectations for a nice visualization of your polytope. Therefore there are several possibilities to adjust the output.

If you open the file cube.pov with a text editor of your choice you will find the first line spelling something similar to

#include "/usr/share/polymake/povray/polymake-scene.pov"

Within the file polymake-scene.pov some basic configuration for any polytope that is visualized with polymake and POV-Ray is done. The most important paragraphs to be changed for our purpose are the last two ones, namely camera and plane.

To adjust the camera, the interesting (and quite self-explanatory) parameters are location and look_at. Typically it is a good idea to choose the location of the camera somewhere outside of the polytope next to the face that should be in front. For the parameter look_at choose some point in the center of the polytope. Keep in mind, that - no matter where the points lie within the polymake-universe - your polytope is always scaled and moved in POV-Ray such that it lies within the cube with the vertices <-1,-1,-1> and <1,1,1>.

The paragraph starting with plane is used to create a plane that works as a “floor” that can also be regarded as the background. Without thisp lane the space around the polytope would be simply black. To change the color of the plane, modify the first three entries of the rgbf-vector with values between 0 and 1.

A good way to get your own .ini-file with rendering-modifications for POV-Ray is copying the original one from /etc/povray/<version> into your workspace. If you do not touch the filename, POV-Ray will automatically use the new one instead of the original one. The default settings are suitable while you are drafting since they provide a good performance.

For the final version you should change the width and height of the output image on the one hand, and activate anti-aliasing on the other hand. The latter task is easily done by modifying the appropriate line to

Antialias=on

(or by adding it, if it does not exist). To weigh up rendering performance and output quality against one another use the parameter Antialias_Threshold. Valid values are between 0.0 (low performance, high quality) and 3.0 (good performance, no antialiasing).

Many settings concerning the look of particular faces can be arranged by using attributes of the VISUAL-command (see above). But in most cases the details can be modified in the cube.pov more easily.

The cube.pov contains three blocks to define the faces of the polytope (i.e. each one for vertices, edges and facets), any of which is followed by the determination of its texture. The first three entries of the rgb(t) vectors define the color of the corresponding surface.

The settings for the texture include some settings from the polymake-scene.pov. In particular, one gets smoother edges by removing the line finish { F_MetalC } from polymake-scene.pov.

A useful feature is transparency. There are two kinds of transparency within POV-Ray, namely filtering and non-filtering transparency. The former filters the light with the color of the transparent surface and thus normally yields a more natural result. The latter transmits the light unchanged (and is the one that polymake uses by default). To add transparency to the facets, replace the rgbt vector by an rgbf (which switches from non-filtered to filtered transparency) and set the value of the fourth entry to a value greater than zero.

Since POV-Ray is documented very well, you should have a look at its documentation, especially the chapters about the camera, output settings and textures.

Getting further help

Helpful Features of the Interactive Shell

Whenever you get stuck, one of the most powerful features is the TAB completion. After hitting the TAB-key, polymake tries to guess the command of your desire. If there are several appropriate possibilities, they will be listed below the input line. (Depending on your individual readline settings you might need to press TAB once again to see them all.) Since this only shows the commands as such, you may want to know somewhat more about them. Simply press F1 key, and you'll see the one-line help text reminding you of the proper argument order and available options. Pressing F1 once again (without moving the cursor in between) will deliver the complete description like this:

polytope > cube([F1][F1]
functions/Producing from scratch/cube:
cube(d; x_up, x_low) -> Polytope

 Produce a d-dimensional cube.
 Regular polytope corresponding to the Coxeter group of type B<sub>d-1</sub> = C<sub>d-1</sub>.

 The bounding hyperplanes are x<sub>i</sub> <= x_up and x<sub>i</sub> >= x_low.
 Default values: x_up=1, x_low=-x_up or 1 if x_up==0.

Arguments:
  Int d the dimension
  Rational x_up 
  Rational x_low 

Returns Polytope 

The same help text can be retrieved with a dedicated command help "cube".

Besides some information about what the function cube does, which arguments it expects etc., we see from the output that this help file is categorized under functions/Producing from scratch. This could give us the idea that there are further ways to construct polytopes from scratch, just like we did with the cube. Indeed, there are some of them:

polytope > help "functions/Producing from scratch/";
Subtopics of functions/Producing from scratch:
associahedron, birkhoff, create_24_cell, create_600_cell, cross, cube, cyclic, cyclic_caratheodory, dwarfed_cube,
dwarfed_product_polygons, goldfarb, hypersimplex, hypertruncated_cube, k_cyclic, knapsack, max_GC_rank, multiplex,
n_gon, neighborly_cubical, newton, permutahedron, pile, rand01, rand_box, rand_metric, rand_sphere,
rss_associahedron, signed_permutahedron, simplex, transportation

In general, command help accepts names of any functions, object types, or properties in quotation marks.

Applications

There are several different applications known to polymake. Each of the applications comprises a main object type, properties which describe an object of the type and a set of functions and rules. By default the application started with polymake is the application dealing with polytopes which is indicated by the command line prompt “polytope >”.

These are the other applications known to polymake:

  • common
  • graph
  • matroid
  • polytope
  • topaz
  • tropical

As an exception to the other applications the application common does not comprise an own main object type but it gathers functionality shared by all the other applications.

Of course there are connections between the applications. For example if you call

polytope > $p -> GRAPH

on a polytope $p, the property GRAPH of the polytope $p is of the object type Graph which is the main object type of the application “graph”.

In order to deal with graphs independent of polytopes you have to switch to the application graph applications “graph”:

polytope > application "graph";

Again the command line prompt “graph >” indicates that you are now using the application “graph” (you can switch to any other application like that).

Of course you can also use the main object type of one application while using another application. For example, to create a polytope while using the graph application the polytope has to be defined as follows:

graph > $p=new polytope::Polytope();

“polytope::” indicates that a Polytope is an object from the application “polytope”.

To start polymake with another application than “polytope”, for example with the application “matroid”, start polymake with the option -A matroid:

polymake -A matroid

A permanent change of the default application started with polymake can be made with:

polytope > set_custom $default_application = "matroid";

FAQ

  1. Warum muessen Daten manchmal so komisch eingegeben werden (z.B. POINTS=«”.”)? Und warum die 1 am Anfang?
  2. In welcher Reihenfolge werden Ecken bzw. Hyperebenen ausgegeben? In der Reihenfolge der Eingabe? Gibt's eine Normalform?

Links

tutorial/introduction.txt · Last modified: 2012/02/02 11:59 by paffenholz
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki