# Tutorial: Tropical arithmetics and tropical geometry

This tutorial showcases the main features of application tropical, such as

• Tropical arithmetics
• Tropical convex hull computations
• Tropical cycles and hypersurfaces.

To use the full palette of tools for tropical geometry, switch to the corresponding application by typing the following in the `polymake` shell:

`> application 'tropical';`

#### Disclaimer: Min or Max - you have to choose!

Most objects and data types related to tropical computations have a template parameter which tells it whether Min or Max is used as tropical addition. There is no default for this, so you have to choose!

#### Disclaimer 2: Newest version required

Most of the features described here only work in polymake version 3.0 or newer.

### Tropical arithmetics

You can create an element of the tropical semiring (over the rationals) simply by writing something like this:

```tropical > \$a = new TropicalNumber<Max>(4);
tropical > \$b = new TropicalNumber<Min>(4);
tropical > \$c = new TropicalNumber<Min>("inf");```

You can now do basic arithmetic - that is tropical addition and multiplication with these. Note that tropical numbers with different tropical additions don't mix!

```tropical > print \$a * \$a;
8
tropical > print \$b + \$c*\$b;
4
tropical > #print \$a + \$b; This won't work!```

Tropical vector/matrix arithmetics also work - you can even ask for the tropical determinant!

```tropical > \$m = new Matrix<TropicalNumber<Max> >([[0,1,2],[0,"-inf",3],[0,0,"-inf"]]);
tropical > \$v = new Vector<TropicalNumber<Max> >(1,1,2);
tropical > print \$m + \$m;
0 1 2
0 -inf 3
0 0 -inf
tropical > print \$m * \$v;
4 5 1
tropical > print tdet(\$m);
4```

Finally, you can also create tropical polynomials. This can be done with the special toTropicalPolynomial parser:

```tropical > \$q = toTropicalPolynomial("min(2a,b+c)");
tropical > print \$q;
x0^2 + x1*x2```

### Tropical convex hull computations

The basic object for tropical convex hull computations is `Polytope` (Careful: If you're not in application tropical, be sure to use the namespace identifier `tropical::Polytope` to distinguish it from the `polytope::Polytope`).

A tropical polytope should always be created via `POINTS` (i.e. not `VERTICES`), since they determine the combinatorial structure. The following creates a tropical line segment in the tropical projective plane. Note that the point (0,1,1) is not a vertex, as it is in the tropical convex hull of the other two points. However, it does play a role when computing the corresponding subdivision of the tropical projective torus into covector cells (see the note below to understand the different coordinates):

```tropical > \$c = new Polytope<Min>(POINTS=>[[0,0,0],[0,1,1],[0,2,1]]);
tropical > print \$c->VERTICES;
0 0 0
0 2 1
tropical > print rows_labeled(\$c->PSEUDOVERTICES);
0:0 0 1 1
1:0 0 -1 0
2:0 0 0 -1
3:1 0 0 0
4:1 0 1 1
5:1 0 2 1
tropical > print \$c->MAXIMAL_COVECTOR_CELLS; #Sets of PSEUDOVERTICES. They are maximal cells of the induced subdivision of the torus.
{0 1 4}
{0 2 5}
{0 4 5}
{1 2 3}
{1 3 4}
{2 3 4}
{2 4 5}
tropical > print \$c->POLYTOPE_MAXIMAL_COVECTOR_CELLS;
{3 4}
{4 5}
tropical > \$c->VISUAL_SUBDIVISION;```

In case you're just interested in either the subdivision of the full torus, or the polyhedral structure of the tropical polytope, the following will give you those structures as `fan::PolyhedralComplex` objects in affine coordinates:

```tropical > \$t = \$c->torus_subdivision_as_complex;
tropical > \$p = \$c->polytope_subdivision_as_complex;
tropical > print \$p->VERTICES;
1 0 0
1 1 1
1 2 1
tropical > print \$p->MAXIMAL_POLYTOPES;
{0 1}
{1 2}```

Note that by default, the affine chart is {x_0 = 0}. You can choose any chart {x_i = 0} by passing i as an argument to `.._subdivision_as_complex`.

Polymake computes the full subdivision of both the torus and the polytope as a `CovectorLattice`, which is just a `FaceLattice` with an additional map that attaches to each cell in the subdivision its covector. For more details on this data structure see the reference documentation. You can visualize the covector lattice with

```tropical > \$c->TORUS_COVECTOR_DECOMPOSITION->VISUAL;
tropical > \$c->POLYTOPE_COVECTOR_DECOMPOSITION->VISUAL;```

Each node in the lattice is a cell of the subdivision. The top row describes the vertices and rays of the subdivision. The bottom row is the covector of that cell with respect to the `POINTS`.

### Tropical cycles

The main object here is `Cycle`, which represents a weighted and balanced, rational pure polyhedral complex in the tropical projective torus (see the note below, if you're confused by coordinates in the following examples).

A tropical cycle can be created, like a `PolyhedralComplex`, by specifying its vertices and maximal cells (and possibly a lineality space). The only additional data are the weights on the maximal cells.

`tropical > \$x = new Cycle<Max>(PROJECTIVE_VERTICES=>[[1,0,0,0],[0,-1,0,0],[0,0,-1,0],[0,0,0,-1]],MAXIMAL_POLYTOPES=>[[0,1],[0,2],[0,3]],WEIGHTS=>[1,1,1]);`

This creates the standard tropical (max-)line in the plane. There are two caveats to observe here:

1. The use of `POINTS` and `INPUT_POLYTOPES` is strongly discouraged. `WEIGHTS` always refer to `MAXIMAL_POLYTOPES` and the order of the latter can be different from the order in `INPUT_POLYTOPES`.
2. You can also define a cycle using `VERTICES` instead of `PROJECTIVE_VERTICES`. However, in that case all vertices have to be normalized such that the second coordinate (i.e. the one after the leading 0/1, see note) is 0. I.e. in the above example, the point (0,-1,0,0) would have to be replaced by (0,0,1,1).

Entering projective coordinates can be a little tedious, since it usually just means adding a zero in front of your affine coordinates. There is a convenience function that does this for you. The following creates the excact same cycle as above:

`tropical > \$x = new Cycle<Max>(VERTICES=>thomog([[1,0,0],[0,1,1],[0,-1,0],[0,0,-1]]),MAXIMAL_POLYTOPES=>[[0,1],[0,2],[0,3]],WEIGHTS=>[1,1,1]);`

One can now ask for basic properties of the cycle, e.g., if it's balanced:

```tropical > print is_balanced(\$x);
1```

#### Hypersurfaces

Most of the time you probably won't want to input your tropical cycle directly as above. Polymake has a special data type `Hypersurface` for hypersurfaces of homogeneous tropical polynomials. The following creates the standard tropical min-line in the plane:

```tropical > \$H = new Hypersurface<Min>(POLYNOMIAL=>toTropicalPolynomial("min(a,b,c)"));
tropical > print \$H->VERTICES;
0 0 -1 -1
0 0 1 0
0 0 0 1
1 0 0 0
tropical > print \$H->MAXIMAL_POLYTOPES;
{2 3}
{1 3}
{0 3}
tropical > print \$H->WEIGHTS;
1 1 1```

#### Tropical intersection theory (and much more): a-tint

As of version 2.15-beta3, polymake comes bundled with the extension a-tint by Simon Hampe, which specializes in (but is not limited to) tropical intersection theory. You can find a non-comprehensive list of features here and a user manual and some basic tutorials on this page.

### A note on coordinates

Coordinates of tropical cones and cycles all live in tropical projective space, i.e. TPn-1 = (Tn \ 0) / (1,..,1), where T is the tropical semiring R union +/- infinity. Every element of projective space has a unique representative such that its first non-tropical-zero entry is 0 and polymake will usually normalize your input to this form.

When describing polyhedral complexes in tropical projective space, polymake uses vectors in TPn-1, but with an additional 1 or 0 in front, indicating whether it is a vertex or a ray (see also the page on homogeneous coordinates).