{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Intro to SnapPy \n",
    "###### SageDays 100\n",
    "###### 2019-07-23 Saul Schleimer\n",
    "\n",
    "SnapPy is maintained by Nathan Dunfield and Marc Culler.  For more details of all kinds (including development information) please see \n",
    "\n",
    "https://www.math.uic.edu/t3m/SnapPy/\n",
    "\n",
    "Start by installing SnapPy into Sage: for example use\n",
    "\n",
    "sage -pip install --user snappy\n",
    "\n",
    "Now start a notebook \n",
    "\n",
    "sage -n jupyter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import snappy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "(Now for some magic to get the GUI working on my machine. Your mileage may vary.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%gui tk"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's get the documentation on the main class in SnapPy."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "snappy.Manifold?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "W = snappy.Manifold() # draw the Whitehead link"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "W = snappy.Manifold('m129') # or just give one of its snappy names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "T = snappy.Manifold() # draw the trefoil"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "T = snappy.Manifold('3_1') # or give one of its snappy names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "W.solution_type() # snappy is happy with this one"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "T.solution_type() # but not this one"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "W.volume() # hyperbolic geometry!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "W.num_tetrahedra() # snappy represents all manifolds via a (pseudo)-triangulation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "W.tetrahedra_shapes() # where the tetrahedra have hyperbolic \"shapes\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are several routines in SnapPy that only work when running under Sage.\n",
    "For example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "W.alexander_polynomial() # algebra!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The trefoil T is not hyperbolic, but the algebra routines will still work."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "T.alexander_polynomial() "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\"W.browse()\" will open up a windo with lots of info.  \n",
    "If the GUI is not working for you try W.identify(), \n",
    "W.length_spectrum(2.5), and so on. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "W.browse()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "G = W.symmetry_group(); G"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "G.isometries() # tells us how the symmetries act on the cusps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "W.verify_hyperbolicity() # prove that W really is hyperbolic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "W.tetrahedra_field_gens?\n",
    "# instead of interval arithmetic, find the number field containing the shapes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "V = W.volume(verified=True); V # prove that the volume lies in an interval"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print V.parent(), '\\n', 'interval', V.endpoints(), '\\n', 'diameter', V.absolute_diameter()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "G = W.fundamental_group(); G"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "P = G.SL2C('ab'); print(P.n(16)); P.trace().n(16) \n",
    "# the representation of G into SL(2,C) coming from the hyperbolic structure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mu = G.peripheral_curves()[0][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "P = G.SL2C(mu); print(P.n(16)); P.trace().n(16) # peripheral so parabolic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "snappy.database_objects # databases shipped with snappy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "snappy.HTLinkExteriors?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "L = snappy.random_link(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "L.view() # switch the style to PL"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "SageMath 8.3",
   "language": "",
   "name": "sagemath"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
