{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Tutorial for Lattice Polytopes\n",
    "\n",
    "This page gives a small introduction to lattice polytopes in `polymake`, some useful external software, and usage hints for it. For a list of methods and properties applicable to lattice polytopes see [here](tutorial/lattice_polytopes_doc). For an introduction to the `polymake` package see [here](tutorial/start). \n",
    "\n",
    "\n",
    "`polymake` always assumes that the lattice used to define a lattice polytope is the standard lattice Z<sup>d</sup>. Some rules also require that the polytope is full dimensional. There are user functions that transform a polytope sitting in some affine subspace of R<sup>d</sup> into a full dimensional polytope, either in the induced lattice or the lattice spanned by the vertices, see below. \n",
    "\n",
    "\n",
    "\n",
    "## Dependence on other Software\n",
    "\n",
    "For some computations `polymake` has no built-in commands and passes the computation to external software. Currently, polymake has an interface to the following packages that compute various properties of lattice polytopes.\n",
    "\n",
    "*  [libnormaliz](http://www.math.uos.de/normaliz/) by Winfried Bruns and Bogdan Ichim, bundled with polymake\n",
    "\n",
    "*  [4ti2](http://www.4ti2.de/) by the 4ti2 team\n",
    "\n",
    "*  [LattE macchiato](http://www.math.ucdavis.edu/~mkoeppe/latte/) by Matthias Köppe, building on `LattE`  by Jesus de Loera et. al.\n",
    "\n",
    "*  ([barvinok](http://freshmeat.net/projects/barvinok) by Sven Verdoolaege)\n",
    "\n",
    "Unless you want to deal with Hilbert bases of cones you don't need them. If you do, either the bundled extension `libnormaliz` or the external package `4ti2` suffices to do most computations with lattice polytopes. Computation of Gröbner bases currently requires `4ti2`. `LattE` only counts lattice points in a polytope and computes its Ehrhart polynomial, but may be faster on that than any other methods implemented. `barvinok` can be used to compute the number of lattice points and the  h<sup></sup>-polynomial. Access to barvinok is realized via an extension which has to be downloaded separately.\n",
    "\n",
    " For some of the commands in this tutorial you will need at least one of `bundled:libnormaliz` enabled  or `4ti2` installed on your machine. We'll remind you at the relevant places.\n",
    "\n",
    "\n",
    "\n",
    "## Lattice Points in Rational Polytopes\n",
    "\n",
    "We start by creating a rational polytope using one of `polymake`'s standard polytope constructions. We choose the 3-dimensional cube with coordinates +1 and -1. So we start `polymake` at the command line and assign a cube to the variable $p.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "$p=cube(3);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Suppose we want to know how many lattice points this cube contains. The answer is of course already known, as the cube has one relative interior integral point per non-empty face. So we expect to get the answer 27.\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "27"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<details>\n",
       "<summary>\n",
       "<pre><small>Click here for additional output</small></pre>\n",
       "</summary>\n",
       "<pre>\n",
       "polymake: used package latte\n",
       "  LattE (Lattice point Enumeration) is a computer software dedicated to the \n",
       "  problems of counting lattice points and integration inside convex polytopes.\n",
       "  Copyright by Matthias Koeppe, Jesus A. De Loera and others.\n",
       "  http://www.math.ucdavis.edu/~latte/\n",
       "\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print $p->N_LATTICE_POINTS;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To satisfy this request, `polymake` computes all properties necessary to call an external program that provides the number of lattice points. In this case, `polymake` has passed the request to `lattE`, which is shown by the credit message that appears before the answer. By default, credits for external software are shown when an external package is used for the first time. You can change this behavior using the variable `$Verbose::credits`. If you don't have a version of `LattE`, or if you have set different preferences, then `polymake` may choose one of the other programs. So the credit statement depends on your configuration.\n",
    "\n",
    "\n",
    "We can of course also ask `polymake` to compute the integral points for us. For our next computations we are only interested in the integral points in the interior of the cube, so we ask for\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 0 0 0\n"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<details>\n",
       "<summary>\n",
       "<pre><small>Click here for additional output</small></pre>\n",
       "</summary>\n",
       "<pre>\n",
       "polymake: used package libnormaliz\n",
       "  Normaliz is a tool for computations in affine monoids, vector configurations, lattice polytopes, and rational cones.\n",
       "  Copyright by Winfried Bruns, Bogdan Ichim, Christof Soeger.\n",
       "  http://www.math.uos.de/normaliz/\n",
       "\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print $p->INTERIOR_LATTICE_POINTS;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Internally, `polymake` computes the intersection of the polytope with the integer lattice, and then checks which of the points lies on a facet of $p. By default, `polymake` uses a project-and-lift algorithms to enumerate the lattice points. Note that our call to `LattE` above has only computed the number of integral points (which is done with an improved version of Barvinok's algorithm), so `polymake` really has to compute something here. If we had asked for `INTERIOR_LATTICE_POINTS` first, then `N_LATTICE_POINTS` would just have counted the rows of a matrix, which would have been much faster. So computation time can depend on the history. \n",
    "\n",
    "You can also ask for the HILBERT_BASIS, though in the case of a cube the result is not so exciting: \n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 -1 -1 -1\n",
       "1 -1 -1 0\n",
       "1 -1 -1 1\n",
       "1 -1 0 -1\n",
       "1 -1 0 0\n",
       "1 -1 0 1\n",
       "1 -1 1 -1\n",
       "1 -1 1 0\n",
       "1 -1 1 1\n",
       "1 0 -1 -1\n",
       "1 0 -1 0\n",
       "1 0 -1 1\n",
       "1 0 0 -1\n",
       "1 0 0 0\n",
       "1 0 0 1\n",
       "1 0 1 -1\n",
       "1 0 1 0\n",
       "1 0 1 1\n",
       "1 1 -1 -1\n",
       "1 1 -1 0\n",
       "1 1 -1 1\n",
       "1 1 0 -1\n",
       "1 1 0 0\n",
       "1 1 0 1\n",
       "1 1 1 -1\n",
       "1 1 1 0\n",
       "1 1 1 1\n"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->HILBERT_BASIS;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`polymake` has no native method to compute a Hilbert basis, so it has passed the computation to `4ti2`. The choice may vary, depending on what is installed on your computer (and configured for `polymake`). You can influence the choice with the appropriate `prefer` statement. \n",
    "\n",
    "Note that so far these commands also work for rational polytopes. \n",
    "\n",
    "## Lattice Polytopes\n",
    "\n",
    "Now we want to do some computations that don't make sense for polytopes that have non-integral vertex coordinates. We can let `polymake` check that our cube is indeed a polytope with integral vertices.\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->LATTICE;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A particularly interesting class of lattice polytopes is that of reflexive polytopes. A polytope is *reflexive* if its polar is agein alattice polytope. This implies in particular that the origin is the unique interior lattice point in the polytope. So, as we have seen above, our cube is a candidate. But this is not sufficient, so we have to do further checks.\n",
    "\n",
    "\n",
    "Reflexivity is a property that is not defined for polytopes with non-integral vertices. So if we ask for it in `polymake`, then `polymake` checks that the entered polytope is indeed a lattice polytope (i.e. it is **bounded** and has **integral vertices**). In that case the object will automatically get the specialization `Polytope::Lattice`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->REFLEXIVE;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lattice polytopes can be used to define toric varieties with an ample line bundle, and many properties of the variety are reflected by the polytope. here is an example: The toric variety defined by our cube is *smooth*, i.e. it is one of the *smooth toric Fano varieties*. In `polymake`, we can just ask for this property in the following way."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->SMOOTH;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "The number of integral points in the k-th dilate of a polytope is given by a polynomial of degree d in k. This is the famous *Ehrhart Theorem*. In `polymake` you can obtain the coefficients of this polynomial (starting with the constant coefficient).\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 6 12 8"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->EHRHART_POLYNOMIAL_COEFF;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`polymake` has passed this request to `LattE` or `normaliz`, but as we have used these programs already the credit message is suppressed (but if you save the cube to a file, then you will find it in there). Some coefficients of this polynomial have a geometric interpretation. E.g., the highest coefficient is the Euclidean volume of the polytope. \n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->VOLUME;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "By a theorem of Stanley, the generating function for the number of lattice points can be written as the quotient of a polynomial h<sup></sup>(t) by (1-t)<sup>d+1</sup>, and this polynomial has non-negative integral coefficients. \n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 23 23 1"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->H_STAR_VECTOR;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->LATTICE_DEGREE;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->LATTICE_CODEGREE;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In our case the coefficient vector is symmetric, as the polytope is reflexive. The *co-degree* of the polytope is d+1 minus the degree of the h<sup></sup>-polynomial. It is the smallest factor by which we have to dilate the polytope to obtain an interior integral point. In our case, this is 1, as the cube already has an integral point.\n",
    "\n",
    "\n",
    "We can obtain the volume of our polytope also from the `H_STAR_VECTOR`: Summing up the coefficients give the *lattice volume* of the polytope, which is d! times its Euclidean volume.\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "48"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->LATTICE_VOLUME;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Let us look at a different example: \n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "$q=new 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]]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "This actually defines a lattice polytope, which we can see from the list of vertices:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 3 0 8\n",
       "1 2 1 8\n",
       "1 3 1 8\n",
       "1 2 0 3\n",
       "1 3 0 7\n",
       "1 3 1 7\n",
       "1 2 1 7\n",
       "1 2 0 4\n"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<details>\n",
       "<summary>\n",
       "<pre><small>Click here for additional output</small></pre>\n",
       "</summary>\n",
       "<pre>\n",
       "polymake: used package ppl\n",
       "  The Parma Polyhedra Library (PPL): A C++ library for convex polyhedra\n",
       "  and other numerical abstractions.\n",
       "  http://www.cs.unipr.it/ppl/\n",
       "\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print $q->VERTICES;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`polymake` provides basically three methods for convex hull conversion, double description, reverse search, and beneath beyond. The first two are provided by the packages `cdd` and `lrs`, the last in internal. By default, `cdd` is chosen, and that is what was used above (they are bundled with `polymake`, you don't have to install them). A polytope Q is *normal* if every lattice point in the k-th dilate of Q is the sum of k lattice points in Q. You can check this property via\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "print $q->NORMAL;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "So our polytope is not normal. We can also find a point that violates the condition. Being normal is equivalent to the fact, that the Hilbert basis of the cone C(Q) obtained from Q by embedding the polytope at height one and the coning over it has all its generators in height one. The property HILBERT_BASIS computes these generators:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 2 0 3\n",
       "1 2 0 4\n",
       "1 2 1 7\n",
       "1 2 1 8\n",
       "1 3 0 7\n",
       "1 3 0 8\n",
       "1 3 1 7\n",
       "1 3 1 8\n",
       "2 5 1 13\n"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $q->HILBERT_BASIS;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The last row is the desired vector: [2,5,1,13] is a vector in 2*Q, but it is not a sum of lattice points in Q. The cone C(Q) corresponds to an affine toric variety, and the above tells us that this variety is not normal. Yet, it is very ample, as we can check with\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<details>\n",
       "<summary>\n",
       "<pre><small>Click here for additional output</small></pre>\n",
       "</summary>\n",
       "<pre>\n",
       "polymake: used package cdd\n",
       "  cddlib\n",
       "  Implementation of the double description method of Motzkin et al.\n",
       "  Copyright by Komei Fukuda.\n",
       "  http://www-oldurls.inf.ethz.ch/personal/fukudak/cdd_home/\n",
       "\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print $q->VERY_AMPLE;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now assume we are particularly interested in the third facet of Q. We can pick this via\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "$f=facet($q,2);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Recall that indexes in `polymake` start at 0, so the third facet has index 2. This is again a very ample polytope:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $f->VERY_AMPLE;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The result is no surprise, being very ample is inherited by faces. We could also be interested in the facet width of the polytope $f. This is the minimum over the maximal distance of a facet to any other vertex. `polymake` knows how to compute this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<details>\n",
       "<summary>\n",
       "<pre><small>Click here for additional output</small></pre>\n",
       "</summary>\n",
       "<pre>\n",
       "polymake:  WARNING: could not compute 'FACET_WIDTH' probably because of unsatisfied preconditions:\n",
       "precondition : FULL_DIM ( FACET_WIDTHS : VERTICES , FACETS , CONE_AMBIENT_DIM )\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print $f->FACET_WIDTH;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Almost. It tells you that it can only do this for a full dimensional polytope, i.e. for a polytope whose dimension coincides with the ambient dimension. This is not true for our facet: It lives in the same ambient space as $q, but has one dimension less. We can remedy this by applying the following:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$g=ambient_lattice_normalization($f);\n",
    "print $g->FACET_WIDTH;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The function `ambient_lattice_normalization` returns a full dimensional version of the polytope `$f` in the lattice induced by the intersection of the affine space of `$f` with Z^n. Now `$g` is full dimensional, and we can compute the facet width. Note that there is also a function which normalizes in the lattice spanned by the vertices of the polytope: `vertex_facet_normalization`. This can also be usefull for full dimensional polytopes. E.g. consider the cube we defined above. The sum of the entries of each vertex is odd, so the lattice spannd by the vertices is a sublattice of the integer lattice:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4) (0 1)\n",
       "1 1 0 0\n",
       "1 0 1 0\n",
       "1 1 1 0\n",
       "1 0 0 1\n",
       "1 1 0 1\n",
       "1 0 1 1\n",
       "1 1 1 1\n"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$cr=vertex_lattice_normalization($p);\n",
    "print $cr->VERTICES;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`$cr` is the same cube, but we have reduced the lattice. (The first line is a *sparse representation* of a vector: it has length 4, and the only non-zero entry is at position 0 and is 1 (note that indexes start at 0)).\n",
    "\n",
    "## Toric Varieties\n",
    "\n",
    "`polymake` has only few builtin functions to compute properties of the variety associated to a fan or lattice polytope. There are two extensions available that add more properties, both currently at an early stage:\n",
    "\n",
    "*  [Toric Varieties and Singular interface](https///github.com/lkastner) by Lars Kastner/Benjamin Lorenz\n",
    "\n",
    "*  [ToricVarieties-v0.3](http://www.mathematik.tu-darmstadt.de/~paffenholz/software.html) by Andreas Paffenholz. Defines a new property for toric varieties associated to a fan and divisors on that variety. \n",
    "\n",
    "Here we will do some computations that do not require one of the extensions. We start by defining a fan. We'll make our live easy and take the normal fan of our cube:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "application \"fan\";"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$f = normal_fan($p);\n",
    "print $f->SMOOTH_FAN;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With the last line we have verified that our fan defines a smooth toric variety. Note that switching the application is not strictly necessary, you can also prepend calls to functions and constructors with `fan::`. The fan object $f itself knows its type, and chooses available properties based on this. Any smooth variety is Gorenstein, so we expect the following:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $f->GORENSTEIN;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Similarly, we could check for Q-Gorensteinness with `Q_GORENSTEIN`. It is also a complete fan:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $f->COMPLETE;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "but currently there is little support to detect completeness in `polymake`. In our case it was already decided during construction, normal fans are complete. You can also check standard features of fans, like their rays. Let us do this for the normal fan of our other example:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1 0 1/4\n",
       "0 -1 1/4\n",
       "1 0 0\n",
       "1 1 -1/4\n",
       "0 1 0\n",
       "0 0 -1\n",
       "0 -1 0\n",
       "-1 0 0\n"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "$g=normal_fan($q);\n",
    "print $g->RAYS;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is not what we wanted. We would like to see the minimal lattice generators of the rays. We can fix this using\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-4 0 1\n",
       "0 -4 1\n",
       "1 0 0\n",
       "4 4 -1\n",
       "0 1 0\n",
       "0 0 -1\n",
       "0 -1 0\n",
       "-1 0 0\n"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print primitive($g->RAYS);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that the function `primitive` returns a copy of the argument, the RAYS as stored in the fan are unchanged. So you have to apply this function each time you need the primitive generators, or you store them in a new variable. The fan $g$ is not smooth, but still Gorenstein:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "print $g->SMOOTH_FAN;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $g->GORENSTEIN;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also access the maximal cones of the fan via\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{3 4 5 7}\n",
       "{2 3 5 6}\n",
       "{5 6 7}\n",
       "{0 1 2 4}\n",
       "{0 4 7}\n",
       "{0 1 6 7}\n",
       "{1 2 6}\n",
       "{2 3 4}\n"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $g->MAXIMAL_CONES;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The indices in these list refer to the list of rays. Sometimes you might be interested in the walls, i.e. the codimension 2 faces of the fan. Here is one way to get them \n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0:-1\n",
       "1:3 4 5 7\n",
       "2:2 3 5 6\n",
       "3:5 6 7\n",
       "4:0 1 2 4\n",
       "5:0 4 7\n",
       "6:0 1 6 7\n",
       "7:1 2 6\n",
       "8:2 3 4\n",
       "9:3 5\n",
       "10:5 7\n",
       "11:4 7\n",
       "12:3 4\n",
       "13:5 6\n",
       "14:2 6\n",
       "15:2 3\n",
       "16:6 7\n",
       "17:0 4\n",
       "18:0 1\n",
       "19:1 2\n",
       "20:2 4\n",
       "21:0 7\n",
       "22:1 6\n",
       "23:3\n",
       "24:5\n",
       "25:7\n",
       "26:4\n",
       "27:6\n",
       "28:2\n",
       "29:0\n",
       "30:1\n",
       "31:\n"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print rows_numbered($g->HASSE_DIAGRAM->FACES);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{23 24 25 26 27 28 29 30}"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $g->HASSE_DIAGRAM->nodes_of_dim($g->DIM-2);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "where the list of numbers given by the latter are the indices of the codimension 2 faces in the list of all faces given before. There is a more concise way to list those, using some simple perl programming:\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{3}{5}{7}{4}{6}{2}{0}{1}"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print map($g->HASSE_DIAGRAM->FACES->[$_], @{$g->HASSE_DIAGRAM->nodes_of_dim($g->DIM-2)});"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "\n",
    "## Visualization\n",
    "\n",
    "If the lattice polytope lives in R^2 or R^3, then we can visualize the polytope together with its lattice points. The picture below has been made with [`javaview`](http://www.javaview.de), but `polymake`'s standard visualization method is now `jreality`, which is bundled with `polymake`. \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n",
       "<svg height=\"841pt\" id=\"document\" viewBox=\"0 -615 575 615\" width=\"595pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "\t<title id=\"document_title\">p</title>\n",
       "\t<g>\n",
       "\t\t<polygon points=\"35,-578.5 35,-53.5 560,-53.5 560,-578.5 \" style=\"fill: rgb(); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t</g>\n",
       "\t<g />\n",
       "\t<g>\n",
       "\t\t<polygon points=\"35,-53.5 35,-53.5 35,-578.5 35,-578.5 \" style=\"fill: rgb(); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t\t<polygon points=\"560,-578.5 560,-53.5 560,-53.5 560,-578.5 \" style=\"fill: rgb(); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t\t<polygon points=\"560,-53.5 35,-53.5 35,-53.5 560,-53.5 \" style=\"fill: rgb(); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t\t<polygon points=\"35,-578.5 35,-578.5 560,-578.5 560,-578.5 \" style=\"fill: rgb(); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t\t<polygon points=\"35,-53.5 35,-578.5 560,-578.5 560,-53.5 \" style=\"fill: rgb(); fill-opacity: 1; stroke: rgb(0,0,0); stroke-width: 1\" />\n",
       "\t</g>\n",
       "\t<g />\n",
       "\t<circle cx=\"297.5\" cy=\"-316\" r=\"2\" style=\"fill: rgb(30,250,30)\" />\n",
       "\t<circle cx=\"35\" cy=\"-53.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"35\" cy=\"-53.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"35\" cy=\"-53.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"35\" cy=\"-316\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"35\" cy=\"-316\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"35\" cy=\"-316\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"35\" cy=\"-578.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"35\" cy=\"-578.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"35\" cy=\"-578.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-53.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-53.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-53.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-316\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-316\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-578.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-578.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"297.5\" cy=\"-578.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"560\" cy=\"-53.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"560\" cy=\"-53.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"560\" cy=\"-53.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"560\" cy=\"-316\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"560\" cy=\"-316\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"560\" cy=\"-316\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"560\" cy=\"-578.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"560\" cy=\"-578.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<circle cx=\"560\" cy=\"-578.5\" r=\"2\" style=\"fill: rgb(70,150,70)\" />\n",
       "\t<!--\n",
       "\tGenerated using the Perl SVG Module V2.82\n",
       "\tby Ronan Oger\n",
       "\tInfo: http://www.roitsystems.com/\n",
       "\t-->\n",
       "</svg"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<details>\n",
       "<summary>\n",
       "<pre><small>Click here for additional output</small></pre>\n",
       "</summary>\n",
       "<pre>\n",
       "polymake: used package SVG\n",
       "   Generated using the Perl SVG Module\n",
       "   by Ronan Oger\n",
       "\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "$p->VISUAL->LATTICE_COLORED;"
   ]
  },
  {
   "attachments": {
    "cube-in-lattice.gif": {
     "image/gif": "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"
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The output may look similar to the following. \n",
    "\n",
    "\n",
    "![{{:tutorial:cube-in-lattice.gif?298}}](attachment:cube-in-lattice.gif)\n",
    "\n",
    "The command `LATTICE_COLORED` sorted the lattice points into three classes before visualization: lattice points in the interior of the polytope, lattice points on the boundary, and vertices that are not in the lattice. These classes are then visualized with different colors (where we only see two in the above picture, as all vertices of the cube are in the lattice). If you don't need this distinction, `VISUAL->LATTICE` avoids the additional computations. \n",
    "\n",
    "## External Packages\n",
    "\n",
    "`polymake` can use `4ti2` and `lattE` via a file based interface and `libnormaliz >= 3.1.0` as library, (the file based interface to `normaliz` has been discontinued) for lattice computations and prints all available packages during startup. To tell `polymake` about a newly installed program run `%%polymake --reconfigure%%` or issue the command `reconfigure` during the interactive session.  polymake may ask you to confirm the paths to the binaries.\n",
    "\n",
    "    \n",
    "    Application polytope uses following third-party software (for details: help 'credits';)\n",
    "    4ti2, cddlib, latte, libnormaliz, lrslib, nauty\n",
    "\n",
    "\n",
    "The output at this position depends on the software available on your computer. To see each call to an external program you can either set the variable `$Verbose::external=1;` on the command line or  include the line `$Polymake::User::Verbose::external=1` in `~/.polymake/prefer.pl`. If you just want to see the credit message instead of the program call, set `$Verbose::credits=2` instead. If this is 1, then a credit is shown when a package is used for the first time, if 0, then all credits are suppressed (but you can find them in the file afterwards).\n",
    "\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "$Verbose::external=1;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 6 12 8"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print $p->EHRHART_POLYNOMIAL_COEFF;"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "You can ask `polymake` to prefer one package over another by setting `prefer \"program\";` where program is one of `_4ti2`, `latte` and `normaliz2`. Of course, the corresponding package needs to be installed on your computer.\n",
    "\n",
    "\n",
    "To prefer one program only for some computations you may append one of .integer_points, .hilbert, .ehrhartpoly for rules computing N_LATTICE_POINTS, LATTICE_POINTS, HILBERT_BASIS or EHRHART_POLYNOMIAL_COEFF. (Or `prefer_now` just for the next computation)\n",
    "\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<details>\n",
       "<summary>\n",
       "<pre><small>Click here for additional output</small></pre>\n",
       "</summary>\n",
       "<pre>\n",
       "polymake: running latte's count: cd /tmp/poly1567Taaaa0002; count  --ehrhart-polynomial input.ine\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print cube(2)->N_LATTICE_POINTS;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prefer_now \"libnormaliz\";\n",
    "print cube(2)->N_LATTICE_POINTS;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1 4 4"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<details>\n",
       "<summary>\n",
       "<pre><small>Click here for additional output</small></pre>\n",
       "</summary>\n",
       "<pre>\n",
       "polymake: running latte's count: cd /tmp/poly1567Taaaa0003; count  --ehrhart-polynomial input.ine\n",
       "</pre>\n",
       "</details>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print cube(2)->EHRHART_POLYNOMIAL_COEFF;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "polymake",
   "language": "polymake",
   "name": "polymake"
  },
  "language_info": {
   "codemirror_mode": "perl",
   "file_extension": ".pl",
   "mimetype": "text/x-polymake",
   "name": "polymake"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
