% Generated by Sphinx.
\def\sphinxdocclass{report}
\documentclass[letterpaper,10pt,english]{sphinxmanual}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{00A0}{\nobreakspace}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{times}
\usepackage[Bjarne]{fncychap}
\usepackage{longtable}
\usepackage{sphinx}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{amssymb}


\title{Sage Sandpiles Documentation}
\date{June 17, 2013}
\release{2.3}
\author{David Perkinson}
\newcommand{\sphinxlogo}{}
\renewcommand{\releasename}{Release}
\makeindex

\makeatletter
\def\PYG@reset{\let\PYG@it=\relax \let\PYG@bf=\relax%
    \let\PYG@ul=\relax \let\PYG@tc=\relax%
    \let\PYG@bc=\relax \let\PYG@ff=\relax}
\def\PYG@tok#1{\csname PYG@tok@#1\endcsname}
\def\PYG@toks#1+{\ifx\relax#1\empty\else%
    \PYG@tok{#1}\expandafter\PYG@toks\fi}
\def\PYG@do#1{\PYG@bc{\PYG@tc{\PYG@ul{%
    \PYG@it{\PYG@bf{\PYG@ff{#1}}}}}}}
\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+\PYG@do{#2}}

\expandafter\def\csname PYG@tok@gd\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
\expandafter\def\csname PYG@tok@gu\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
\expandafter\def\csname PYG@tok@gt\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
\expandafter\def\csname PYG@tok@gs\endcsname{\let\PYG@bf=\textbf}
\expandafter\def\csname PYG@tok@gr\endcsname{\def\PYG@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
\expandafter\def\csname PYG@tok@cm\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}}
\expandafter\def\csname PYG@tok@vg\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\expandafter\def\csname PYG@tok@m\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@mh\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@cs\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}\def\PYG@bc##1{\setlength{\fboxsep}{0pt}\colorbox[rgb]{1.00,0.94,0.94}{\strut ##1}}}
\expandafter\def\csname PYG@tok@ge\endcsname{\let\PYG@it=\textit}
\expandafter\def\csname PYG@tok@vc\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\expandafter\def\csname PYG@tok@il\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@go\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.20,0.20,0.20}{##1}}}
\expandafter\def\csname PYG@tok@cp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@gi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
\expandafter\def\csname PYG@tok@gh\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
\expandafter\def\csname PYG@tok@ni\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.84,0.33,0.22}{##1}}}
\expandafter\def\csname PYG@tok@nl\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.13,0.44}{##1}}}
\expandafter\def\csname PYG@tok@nn\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.05,0.52,0.71}{##1}}}
\expandafter\def\csname PYG@tok@no\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.38,0.68,0.84}{##1}}}
\expandafter\def\csname PYG@tok@na\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@nb\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@nc\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.05,0.52,0.71}{##1}}}
\expandafter\def\csname PYG@tok@nd\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.33,0.33,0.33}{##1}}}
\expandafter\def\csname PYG@tok@ne\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@nf\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.02,0.16,0.49}{##1}}}
\expandafter\def\csname PYG@tok@si\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.44,0.63,0.82}{##1}}}
\expandafter\def\csname PYG@tok@s2\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@vi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\expandafter\def\csname PYG@tok@nt\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.02,0.16,0.45}{##1}}}
\expandafter\def\csname PYG@tok@nv\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.38,0.84}{##1}}}
\expandafter\def\csname PYG@tok@s1\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@gp\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.78,0.36,0.04}{##1}}}
\expandafter\def\csname PYG@tok@sh\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@ow\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@sx\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.78,0.36,0.04}{##1}}}
\expandafter\def\csname PYG@tok@bp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@c1\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}}
\expandafter\def\csname PYG@tok@kc\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@c\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.50,0.56}{##1}}}
\expandafter\def\csname PYG@tok@mf\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@err\endcsname{\def\PYG@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}
\expandafter\def\csname PYG@tok@kd\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@ss\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.32,0.47,0.09}{##1}}}
\expandafter\def\csname PYG@tok@sr\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.14,0.33,0.53}{##1}}}
\expandafter\def\csname PYG@tok@mo\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@mi\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.13,0.50,0.31}{##1}}}
\expandafter\def\csname PYG@tok@kn\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@o\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PYG@tok@kr\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@s\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@kp\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@w\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
\expandafter\def\csname PYG@tok@kt\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.56,0.13,0.00}{##1}}}
\expandafter\def\csname PYG@tok@sc\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@sb\endcsname{\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@k\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.00,0.44,0.13}{##1}}}
\expandafter\def\csname PYG@tok@se\endcsname{\let\PYG@bf=\textbf\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}
\expandafter\def\csname PYG@tok@sd\endcsname{\let\PYG@it=\textit\def\PYG@tc##1{\textcolor[rgb]{0.25,0.44,0.63}{##1}}}

\def\PYGZbs{\char`\\}
\def\PYGZus{\char`\_}
\def\PYGZob{\char`\{}
\def\PYGZcb{\char`\}}
\def\PYGZca{\char`\^}
\def\PYGZam{\char`\&}
\def\PYGZlt{\char`\<}
\def\PYGZgt{\char`\>}
\def\PYGZsh{\char`\#}
\def\PYGZpc{\char`\%}
\def\PYGZdl{\char`\$}
\def\PYGZhy{\char`\-}
\def\PYGZsq{\char`\'}
\def\PYGZdq{\char`\"}
\def\PYGZti{\char`\~}
% for compatibility with earlier versions
\def\PYGZat{@}
\def\PYGZlb{[}
\def\PYGZrb{]}
\makeatother

\begin{document}

\maketitle
\tableofcontents
\phantomsection\label{sandpile::doc}


\emph{Author: David Perkinson, Reed College}


\chapter{Introduction}
\label{sandpile:introduction}\label{sandpile:abelian-sandpile-model}
These notes provide an introduction to Dhar's abelian sandpile model (ASM) and
to Sage Sandpiles, a collection of tools in Sage for doing sandpile
calculations.  For a more thorough introduction to the theory of the ASM, the
papers \emph{Chip-Firing and Rotor-Routing on Directed Graphs} {\hyperref[sandpile:h]{{[}H{]}}}, by Holroyd et
al. and \emph{Riemann-Roch and Abel-Jacobi Theory on a Finite Graph} by Baker and
Norine {\hyperref[sandpile:bn]{{[}BN{]}}} are recommended.

To describe the ASM, we start with a \emph{sandpile graph}: a directed multigraph
$\Gamma$ with a vertex $s$ that is accessible from every vertex (except
possibly $s$, itself).  By \emph{multigraph}, we mean that each edge of $\Gamma$ is
assigned a nonnegative integer weight.  To say $s$ is \emph{accessible} from some
vertex $v$ means that there is a sequence of directed edges starting at $v$ and
ending at $s$.  We call $s$ the \emph{sink} of the sandpile graph, even though it might have outgoing edges, for reasons that will be made clear in a moment.

We denoted the vertices of $\Gamma$ by $V$ and define $\tilde{V} = V\setminus\{s\}$.


\section{Configurations and divisors}
\label{sandpile:configurations-and-divisors}
A \emph{configuration} on $\Gamma$ is an element of $\mathbb{N}\tilde{V}$, i.e., the
assignment of a nonnegative integer to each nonsink vertex.  We think of each
integer as a number of grains of sand being placed at the corresponding
vertex.  A \emph{divisor} on $\Gamma$ is an element of $\mathbb{Z}V$, i.e., an
element in the free abelian group on \emph{all} of the vertices.  In the context of
divisors, it is sometimes useful to think of assigning dollars to each vertex,
with negative integers signifying a debt.


\section{Stabilization}
\label{sandpile:stabilization}
A configuration $c$ is \emph{stable} at a vertex $v\in\tilde{V}$ if
$c(v)<\mbox{out-degree}(v)$, and $c$ itself is stable if it is stable at each
nonsink vertex.  Otherwise, $c$ is \emph{unstable}.  If $c$ is unstable at $v$, the vertex $v$ can be \emph{fired}
(\emph{toppled}) by removing $\mbox{out-degree}(v)$ grains of sand from $v$ and
adding grains of sand to the neighbors of sand, determined by the weights of
the edges leaving $v$.

Despite our best intentions, we sometimes consider firing a stable vertex,
resulting in a configuration with a ``negative amount'' of sand at that vertex.
We may also \emph{reverse-firing} a vertex, absorbing sand from the vertex's
neighbors.

\textbf{Example.} Consider the graph:
\begin{figure}[htbp]
\centering
\capstart

\includegraphics{example1.png}
\caption{$\Gamma$}\end{figure}

All edges have weight $1$ except for the edge from vertex 1 to vertex 3,
which has weight $2$.  If we let $c=(5,0,1)$ with the indicated number of
grains of sand on vertices 1, 2, and 3, respectively, then only vertex 1,
whose out-degree is 4, is unstable.  Firing vertex 1 gives a new
configuration $c'=(1,1,3)$.  Here, $4$ grains have left vertex 1.  One of
these has gone to the sink vertex (and forgotten), one has gone to vertex 1,
and two have gone to vertex 2, since the edge from 1 to 2 has weight 2.
Vertex 3 in the new configuration is now unstable.  The Sage code for this
example follows.

\begin{Verbatim}[commandchars=\\\{\}]
sage: g = \PYGZob{}'sink':\PYGZob{}\PYGZcb{},
...        1:\PYGZob{}'sink':1, 2:1, 3:2\PYGZcb{},
...        2:\PYGZob{}1:1, 3:1\PYGZcb{},
...        3:\PYGZob{}1:1, 2:1\PYGZcb{}\PYGZcb{}
sage: S = Sandpile(g, 'sink')   \# create the sandpile
sage: S.show(edge\_labels=true)  \# display the graph

Create the configuration:

sage: c = SandpileConfig(S, \PYGZob{}1:5, 2:0, 3:1\PYGZcb{})
sage: S.out\_degree()
\PYGZob{}1: 4, 2: 2, 3: 2, 'sink': 0\PYGZcb{}

Fire vertex one:

sage: c.fire\_vertex(1)
\PYGZob{}1: 1, 2: 1, 3: 3\PYGZcb{}

The configuration is unchanged:

sage: c
\PYGZob{}1: 5, 2: 0, 3: 1\PYGZcb{}

Repeatedly fire vertices until the configuration becomes stable:

sage: c.stabilize()
\PYGZob{}1: 2, 2: 1, 3: 1\PYGZcb{}

Alternatives:

sage: \textasciitilde{}c             \# shorthand for c.stabilize()
\PYGZob{}1: 2, 2: 1, 3: 1\PYGZcb{}
sage: c.stabilize(with\_firing\_vector=true)
[\PYGZob{}1: 2, 2: 1, 3: 1\PYGZcb{}, \PYGZob{}1: 2, 2: 2, 3: 3\PYGZcb{}]
\end{Verbatim}

Since vertex 3 has become unstable after firing vertex 1, it can be fired,
which causes vertex 2 to become unstable, etc.  Repeated firings eventually
lead to a stable configuration.  The last line of the Sage code, above, is a
list, the first element of which is the resulting stable configuration,
$(2,1,1)$.  The second component records how many times each vertex fired in
the stabilization.


\bigskip\hrule{}\bigskip


Since the sink is accessible from each nonsink vertex and never fires, every
configuration will stabilize after a finite number of vertex-firings.  It is
not obvious, but the resulting stabilization is independent of the order in
which unstable vertices are fired.  Thus, each configuration stabilizes to a
unique stable configuration.


\section{Laplacian}
\label{sandpile:laplacian}
Fix an order on the vertices of $\Gamma$. The \emph{Laplacian} of $\Gamma$ is
\begin{gather}
\begin{split}L := D-A\end{split}\notag
\end{gather}
where $D$ is the diagonal matrix of out-degrees of the vertices and $A$ is the
adjacency matrix whose $(i,j)$-th entry is the weight of the edge from vertex
$i$ to vertex $j$, which we take to be $0$ if there is no edge.  The \emph{reduced
Laplacian}, $\tilde{L}$, is the submatrix of the Laplacian formed by removing
the row and column corresponding to the sink vertex.  Firing a vertex of a
configuration is the same as subtracting the corresponding row of the reduced
Laplacian.

\textbf{Example.} (Continued.)

\begin{Verbatim}[commandchars=\\\{\}]
sage: S.vertices()  \# the ordering of the vertices
[1, 2, 3, 'sink']
sage: S.laplacian()
[ 4 -1 -2 -1]
[-1  2 -1  0]
[-1 -1  2  0]
[ 0  0  0  0]
sage: S.reduced\_laplacian()
[ 4 -1 -2]
[-1  2 -1]
[-1 -1  2]

The configuration we considered previously:

sage: c = SandpileConfig(S, [5,0,1])
sage: c
\PYGZob{}1: 5, 2: 0, 3: 1\PYGZcb{}

Firing vertex 1 is the same as subtracting the
corresponding row from the reduced Laplacian:

sage: c.fire\_vertex(1).values()
[1, 1, 3]
sage: S.reduced\_laplacian()[0]
(4, -1, -2)
sage: vector([5,0,1]) - vector([4,-1,-2])
(1, 1, 3)
\end{Verbatim}


\section{Recurrent elements}
\label{sandpile:recurrent-elements}
Imagine an experiment in which grains of sand are dropped one-at-a-time onto a
graph, pausing to allow the configuration to stabilize between drops.  Some
configurations will only be seen once in this process.  For example, for most
graphs, once sand is dropped on the graph, no addition of sand+stabilization
will result in a graph empty of sand.  Other configurations---the so-called
\emph{recurrent configurations}---will be seen infinitely often as the process is
repeated indefinitely.

To be precise, a configuration $c$ is \emph{recurrent} if (i) it is stable, and (ii)
given any configuration $a$, there is a configuration $b$ such that
$c=\mbox{stab}(a+b)$, the stabilization of $a+b$.

The \emph{maximal-stable} configuration, denoted $c_{\mathrm{max}}$ is defined by
$c_{\mathrm{max}}(v)=\mbox{out-degree}(v)-1$ for all nonsink vertices $v$.  It is clear that $c_{\mathrm{max}}$ is recurrent.  Further, it is not hard to see that a configuration is recurrent if and only if it has the form $\mbox{stab}(a+c_{\mathrm{max}})$ for some configuration $a$.

\textbf{Example.} (Continued.)

\begin{Verbatim}[commandchars=\\\{\}]
sage: S.recurrents(verbose=false)
[[3, 1, 1], [2, 1, 1], [3, 1, 0]]
sage: c = SandpileConfig(S, [2,1,1])
sage: c
\PYGZob{}1: 2, 2: 1, 3: 1\PYGZcb{}
sage: c.is\_recurrent()
True
sage: S.max\_stable()
\PYGZob{}1: 3, 2: 1, 3: 1\PYGZcb{}

Adding any configuration to the max-stable configuration and stabilizing
yields a recurrent configuration.

sage: x = SandpileConfig(S, [1,0,0])
sage: x + S.max\_stable()
\PYGZob{}1: 4, 2: 1, 3: 1\PYGZcb{}

Use \& to add and stabilize:

sage: c = x \& S.max\_stable()
sage: c
\PYGZob{}1: 3, 2: 1, 3: 0\PYGZcb{}
sage: c.is\_recurrent()
True

Note the various ways of performing addition + stabilization:

sage: m = S.max\_stable()
sage: (x + m).stabilize() == \textasciitilde{}(x + m)
True
sage: (x + m).stabilize() == x \& m
True
\end{Verbatim}


\section{Burning Configuration}
\label{sandpile:burning-configuration}
A \emph{burning configuration} is a nonnegative integer-linear combination of the
rows of the reduced Laplacian matrix having nonnegative entries and such that
every vertex has a path from some vertex in its support.  The corresponding
\emph{burning script} gives the integer-linear combination needed to obtain the
burning configuration.  So if $b$ is the burning configuration, $\sigma$ is its
script, and $\tilde{L}$ is the reduced Laplacian, then $\sigma\,\tilde{L} = b$.
The \emph{minimal burning configuration} is the one with the minimal script (its
components are no larger than the components of any other script for a burning
configuration).

The following are equivalent for a configuration $c$ with burning
configuration $b$ having script $\sigma$:
\begin{itemize}
\item {} 
$c$ is recurrent;

\item {} 
$c+b$ stabilizes to $c$;

\item {} 
the firing vector for the stabilization of $c+b$ is $\sigma$.

\end{itemize}

The burning configuration and script are computed using a modified
version of Speer's script algorithm.  This is a generalization to
directed multigraphs of Dhar's burning algorithm.

\textbf{Example.}

\begin{Verbatim}[commandchars=\\\{\}]
sage: g = \PYGZob{}0:\PYGZob{}\PYGZcb{},1:\PYGZob{}0:1,3:1,4:1\PYGZcb{},2:\PYGZob{}0:1,3:1,5:1\PYGZcb{},
...        3:\PYGZob{}2:1,5:1\PYGZcb{},4:\PYGZob{}1:1,3:1\PYGZcb{},5:\PYGZob{}2:1,3:1\PYGZcb{}\PYGZcb{}
sage: G = Sandpile(g,0)
sage: G.burning\_config()
\PYGZob{}1: 2, 2: 0, 3: 1, 4: 1, 5: 0\PYGZcb{}
sage: G.burning\_config().values()
[2, 0, 1, 1, 0]
sage: G.burning\_script()
\PYGZob{}1: 1, 2: 3, 3: 5, 4: 1, 5: 4\PYGZcb{}
sage: G.burning\_script().values()
[1, 3, 5, 1, 4]
sage: matrix(G.burning\_script().values())*G.reduced\_laplacian()
[2 0 1 1 0]
\end{Verbatim}


\section{Sandpile group}
\label{sandpile:sandpile-group}
The collection of stable configurations forms a commutative monoid with
addition defined as ordinary addition followed by stabilization.  The identity
element is the all-zero configuration.  This monoid is a group
exactly when the underlying graph is a DAG (directed acyclic graph).

The recurrent elements form a submonoid which turns out to be a group.  This
group is called the \emph{sandpile group} for $\Gamma$, denoted
$\mathcal{S}(\Gamma)$.  Its identity element is usually not the all-zero
configuration (again, only in the case that $\Gamma$ is a DAG).  So finding the
identity element is an interesting problem.

Let $n=|V|-1$ and fix an ordering of the nonsink vertices. Let
$\mathcal{\tilde{L}}\subset\mathbb{Z}^n$ denote the column-span of
$\tilde{L}^t$, the transpose of the reduced Laplacian.  It is a theorem that
\begin{gather}
\begin{split}\mathcal{S}(\Gamma)\approx \mathbb{Z}^n/\mathcal{\tilde{L}}.\end{split}\notag
\end{gather}
Thus, the number of elements of the sandpile group is $\det{\tilde{L}}$, which
by the matrix-tree theorem is the number of weighted trees directed into the
sink.

\textbf{Example.} (Continued.)

\begin{Verbatim}[commandchars=\\\{\}]
sage: S.group\_order()
3
sage: S.invariant\_factors()
[1, 1, 3]
sage: S.reduced\_laplacian().dense\_matrix().smith\_form()
(
[1 0 0]  [ 0  0  1]  [3 1 4]
[0 1 0]  [ 1  0  0]  [4 1 6]
[0 0 3], [ 0  1 -1], [4 1 5]
)

Adding the identity to any recurrent configuration and stabilizing yields
the same recurrent configuration:

sage: S.identity()
\PYGZob{}1: 3, 2: 1, 3: 0\PYGZcb{}
sage: i = S.identity()
sage: m = S.max\_stable()
sage: i \& m == m
True
\end{Verbatim}


\section{Self-organized criticality}
\label{sandpile:self-organized-criticality}
The sandpile model was introduced by Bak, Tang, and Wiesenfeld in the paper,
\emph{Self-organized criticality: an explanation of 1/ƒ noise} {\hyperref[sandpile:btw]{{[}BTW{]}}}.  The term
\emph{self-organized criticality} has no precise definition, but can be
loosely taken to describe a system that naturally evolves to a state that is
barely stable and such that the instabilities are described by a power law.
In practice, \emph{self-organized criticality} is often taken to mean \emph{like the
sandpile model on a grid-graph}.  The grid graph is just a grid with an extra
sink vertex.  The vertices on the interior of each side have one edge to the
sink, and the corner vertices have an edge of weight $2$.  Thus, every nonsink
vertex has out-degree $4$.

Imagine repeatedly dropping grains of sand on and empty grid graph, allowing
the sandpile to stabilize in between.  At first there is little activity, but
as time goes on, the size and extent of the avalanche caused by a single grain
of sand becomes hard to predict.  Computer experiments---I do not think there
is a proof, yet---indicate that the distribution of avalanche sizes obeys a
power law with exponent -1.  In the example below, the size of an avalanche is
taken to be the sum of the number of times each vertex fires.

\textbf{Example (distribution of avalanche sizes).}

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = grid\_sandpile(10,10)
sage: m = S.max\_stable()
sage: a = []
sage: for i in range(10000):
...       m = m.add\_random()
...       m, f = m.stabilize(true)
...       a.append(sum(f.values()))
...
sage: p = list\_plot([[log(i+1),log(a.count(i))] for i in [0..max(a)] if a.count(i)])
sage: p.axes\_labels(['log(N)','log(D(N))'])
sage: p
\end{Verbatim}
\begin{figure}[htbp]
\centering
\capstart

\includegraphics{btw.png}
\caption{Distribution of avalanche sizes}\end{figure}

Note: In the above code, \code{m.stabilize(true)} returns a list consisting of the
stabilized configuration and the firing vector.  (Omitting \code{true} would give
just the stabilized configuration.)


\section{Divisors and Discrete Riemann surfaces}
\label{sandpile:discrete-riemann-surfaces}\label{sandpile:divisors-and-discrete-riemann-surfaces}
A reference for this section is \emph{Riemann-Roch and Abel-Jacobi theory on a finite
graph} {\hyperref[sandpile:bn]{{[}BN{]}}}.

A \emph{divisor} on $\Gamma$ is an element of the free abelian group on its
vertices, including the sink.  Suppose, as above, that the $n+1$ vertices of
$\Gamma$ have been ordered, and that $\mathcal{L}$ is the column span of the
transpose of the Laplacian.  A divisor is then identified with an element
$D\in\mathbb{Z}^{n+1}$ and two divisors are \emph{linearly equivalent} if they
differ by an element of $\mathcal{L}$.  A divisor $E$ is \emph{effective}, written
$E\geq0$, if $E(v)\geq0$ for each $v\in V$, i.e., if $E\in\mathbb{N}^{n+1}$.
The \emph{degree} of a divisor, $D$, is $deg(D) := \sum_{v\in V}D(v)$.   The
divisors of degree zero modulo linear equivalence form the \emph{Picard group}, or
\emph{Jacobian} of the graph. For an undirected graph, the Picard group is
isomorphic to the sandpile group.

The \emph{complete linear system} for a divisor $D$, denoted $|D|$, is the
collection of effective divisors linearly equivalent to $D.$


\subsection{Riemann-Roch}
\label{sandpile:riemann-roch}
To describe the Riemann-Roch theorem in this context, suppose that $\Gamma$ is
an undirected, unweighted graph. The \emph{dimension}, $r(D)$ of the linear system
$|D|$ is $-1$ if $|D|=\emptyset$ and otherwise is the greatest integer $s$ such
that $|D-E|\neq0$ for all effective divisors $E$ of degree $s$.  Define the
\emph{canonical divisor} by $K=\sum_{v\in V}(\deg(v)-2)v$ and the \emph{genus} by $g =
\#(E) - \#(V) + 1$.  The Riemann-Roch theorem says that for any divisor $D$,
\begin{gather}
\begin{split}r(D)-r(K-D)=\deg(D)+1-g.\end{split}\notag
\end{gather}
\textbf{Example.} (Some of the following calculations require the installation of {\hyperref[sandpile:installation]{\emph{4ti2}}}.)

\begin{Verbatim}[commandchars=\\\{\}]
sage: G = complete\_sandpile(5)  \# the sandpile on the complete graph with 5 vertices

The genus (num\_edges method counts each undirected edge twice):

sage: g = G.num\_edges()/2 - G.num\_verts() + 1

A divisor on the graph:

sage: D = SandpileDivisor(G, [1,2,2,0,2])

Verify the Riemann-Roch theorem:

sage: K = G.canonical\_divisor()
sage: D.r\_of\_D() - (K - D).r\_of\_D() == D.deg() + 1 - g \# optional - 4ti2
True

The effective divisors linearly equivalent to D:

sage: [E.values() for E in D.effective\_div()]  \# optional - 4ti2
[[0, 1, 1, 4, 1], [4, 0, 0, 3, 0], [1, 2, 2, 0, 2]]

The nonspecial divisors up to linear equivalence (divisors of degree
g-1 with empty linear systems)

sage: N = G.nonspecial\_divisors()
sage: [E.values() for E in N[:5]]   \# the first few
[[-1, 2, 1, 3, 0],
 [-1, 0, 3, 1, 2],
 [-1, 2, 0, 3, 1],
 [-1, 3, 1, 2, 0],
 [-1, 2, 0, 1, 3]]
sage: len(N)
24
sage: len(N) == G.h\_vector()[-1]
True
\end{Verbatim}


\subsection{Picturing linear systems}
\label{sandpile:picturing-linear-systems}
Fix a divisor $D$.  There are at least two natural graphs associated with
linear system associated with $D$.  First, consider the directed graph with
vertex set $|D|$ and with an edge from vertex $E$ to vertex $F$ if $F$ is
attained from $E$ by firing a single unstable vertex.

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(6),0)
sage: D = SandpileDivisor(S, [1,1,1,1,2,0])
sage: D.is\_alive()
True
sage: eff = D.effective\_div() \# optional - 4ti2
sage: firing\_graph(S,eff).show3d(edge\_size=.005,vertex\_size=0.01,iterations=500) \# optional - 4ti2
\end{Verbatim}
\begin{figure}[htbp]
\centering
\capstart

\includegraphics{C_6.png}
\caption{Complete linear system for (1,1,1,1,2,0) on $C_6$: single firings}\end{figure}

The second graph has the same set of vertices but with an edge from $E$ to $F$
if $F$ is obtained from $E$ by firing all unstable vertices of $E$.

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(6),0)
sage: D = SandpileDivisor(S, [1,1,1,1,2,0])
sage: eff = D.effective\_div()  \# optional - 4ti2
sage: parallel\_firing\_graph(S,eff).show3d(edge\_size=.005,vertex\_size=0.01,iterations=500) \# optional - 4ti2
\end{Verbatim}
\begin{figure}[htbp]
\centering
\capstart

\includegraphics{C_6-parallel.png}
\caption{Complete linear system for (1,1,1,1,2,0) on $C_6$: parallel firings}\end{figure}

Note that in each of the examples, above, starting at any divisor in the linear
system and following edges, one is eventually led into a cycle of length 6
(cycling the divisor (1,1,1,1,2,0)).  Thus, \code{D.alive()} returns \code{True}.  In
Sage, one would be able to rotate the above figures to get a better idea of the
structure.


\section{Algebraic geometry of sandpiles}
\label{sandpile:algebraic-geometry-of-sandpiles}

\subsection{Affine}
\label{sandpile:affine}
Let $n=|V|-1$, and fix an ordering on the nonsink vertices of $\Gamma$.  let
$\tilde{\mathcal{L}}\subset\mathbb{Z}^n$ denote the column-span of
$\tilde{L}^t$, the transpose of the reduced Laplacian.  Label vertex $i$ with the
indeterminate $x_i$, and let $\mathbb{C}[\Gamma_s] = \mathbb{C}[x_1,\dots,x_n]$.
(Here, $s$ denotes the sink vertex of $\Gamma$.) The \emph{sandpile ideal} or
\emph{toppling ideal}, first studied by Cori, Rossin, and Salvy {\hyperref[sandpile:crs]{{[}CRS{]}}} for undirected graphs, is the lattice ideal for $\tilde{\mathcal{L}}$:
\begin{gather}
\begin{split}I = I(\Gamma_s) := \{x^u-x^v: u-v\in
\tilde{\mathcal{L}}\}\subset\mathbb{C}[\Gamma_s],\end{split}\notag
\end{gather}
where $x^u := \prod_{i=1}^nx^{u_i}$ for $u\in\mathbb{Z}^n$.

For each $c\in\mathbb{Z}^n$ define $t(c) = x^{c^+} - x^{c^-}$ where
$c^+_i=\max\{c_i,0\}$ and $c^-=\max\{-c_i,0\}$ so that $c=c^+-c^-$.
Then, for each $\sigma\in\mathbb{Z}^n$, define $T(\sigma) =
t(\tilde{L}^t\sigma)$.  It then turns out that
\begin{gather}
\begin{split}I = (T(e_1),\dots,T(e_n),x^b-1)\end{split}\notag
\end{gather}
where $e_i$ is the $i$-th standard basis vector and $b$ is any burning
configuration.

The affine coordinate ring, $\mathbb{C}[\Gamma_s]/I,$ is isomorphic to the group
algebra of the sandpile group, $\mathbb{C}[\mathcal{S}(\Gamma)].$

The standard term-ordering on $\mathbb{C}[\Gamma_s]$ is graded reverse
lexigraphical order with $x_i>x_j$ if vertex $v_i$ is further from the sink than
vertex $v_j$. (There are choices to be made for vertices equidistant from the
sink). If $\sigma_b$ is the script for a burning configuration (not
necessarily minimal), then
\begin{gather}
\begin{split}\{T(\sigma): \sigma\leq\sigma_b\}\end{split}\notag
\end{gather}
is a Groebner basis for $I$.


\subsection{Projective}
\label{sandpile:projective}
Now let $\mathbb{C}[\Gamma]=\mathbb{C}[x_0,x_1,\dots,x_n]$, where $x_0$
corresponds to the sink vertex.  The \emph{homogeneous sandpile ideal}, denoted
$I^h$, is obtaining by homogenizing $I$ with respect to $x_0$.  Let $L$ be the
(full) Laplacian, and $\mathcal{L}\subset\mathbb{Z}^{n+1}$ be the column span of
its transpose, $L^t.$  Then $I^h$ is the lattice ideal for $\mathcal{L}$:
\begin{gather}
\begin{split}I^h = I^h(\Gamma) := \{x^u-x^v: u-v \in\mathcal{L}\}\subset\mathbb{C}[\Gamma].\end{split}\notag
\end{gather}
This ideal can be calculated by saturating the ideal
\begin{gather}
\begin{split}(T(e_i): i=0,\dots n)\end{split}\notag
\end{gather}
with respect to the product of the indeterminates: $\prod_{i=0}^nx_i$ (extending
the $T$ operator in the obvious way).  A Groebner basis with respect to the
degree lexicographic order describe above (with $x_0$ the smallest vertex), is
obtained by homogenizing each element of the Groebner basis for the
non-homogeneous sandpile ideal with respect to $x_0.$

\textbf{Example.}

\begin{Verbatim}[commandchars=\\\{\}]
sage: g = \PYGZob{}0:\PYGZob{}\PYGZcb{},1:\PYGZob{}0:1,3:1,4:1\PYGZcb{},2:\PYGZob{}0:1,3:1,5:1\PYGZcb{},
...        3:\PYGZob{}2:1,5:1\PYGZcb{},4:\PYGZob{}1:1,3:1\PYGZcb{},5:\PYGZob{}2:1,3:1\PYGZcb{}\PYGZcb{}
sage: S = Sandpile(g, 0)
sage: S.ring()
Multivariate Polynomial Ring in x5, x4, x3, x2, x1, x0 over Rational Field

The homogeneous sandpile ideal:

sage: S.ideal()
Ideal (x2 - x0, x3\textasciicircum{}2 - x5*x0, x5*x3 - x0\textasciicircum{}2, x4\textasciicircum{}2 - x3*x1, x5\textasciicircum{}2 - x3*x0,
x1\textasciicircum{}3 - x4*x3*x0, x4*x1\textasciicircum{}2 - x5*x0\textasciicircum{}2) of Multivariate Polynomial Ring
in x5, x4, x3, x2, x1, x0 over Rational Field

The generators of the ideal:

sage: S.ideal(true)
[x2 - x0,
 x3\textasciicircum{}2 - x5*x0,
 x5*x3 - x0\textasciicircum{}2,
 x4\textasciicircum{}2 - x3*x1,
 x5\textasciicircum{}2 - x3*x0,
 x1\textasciicircum{}3 - x4*x3*x0,
 x4*x1\textasciicircum{}2 - x5*x0\textasciicircum{}2]

Its resolution:

sage: S.resolution() \# long time
'R\textasciicircum{}1 \textless{}-- R\textasciicircum{}7 \textless{}-- R\textasciicircum{}19 \textless{}-- R\textasciicircum{}25 \textless{}-- R\textasciicircum{}16 \textless{}-- R\textasciicircum{}4'

and Betti table:

sage: S.betti() \# long time
           0     1     2     3     4     5
------------------------------------------
    0:     1     1     -     -     -     -
    1:     -     4     6     2     -     -
    2:     -     2     7     7     2     -
    3:     -     -     6    16    14     4
------------------------------------------
total:     1     7    19    25    16     4

The Hilbert function:

sage: S.hilbert\_function()
[1, 5, 11, 15]

and its first differences (which counts the number of superstable
configurations in each degree):

sage: S.h\_vector()
[1, 4, 6, 4]
sage: x = [i.deg() for i in S.superstables()]
sage: sorted(x)
[0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3]

The degree in which the Hilbert function equals the Hilbert polynomial, the
latter always being a constant in the case of a sandpile ideal:

sage: S.postulation()
3
\end{Verbatim}


\subsection{Zeros}
\label{sandpile:zeros}
The \emph{zero set} for the sandpile ideal $I$ is
\begin{gather}
\begin{split}Z(I) = \{p\in\mathbb{C}^n: f(p)=0\mbox{ for all $f\in I$}\},\end{split}\notag
\end{gather}
the set of simultaneous zeros of the polynomials in $I.$  Letting $S^1$ denote
the unit circle in the complex plane, $Z(I)$ is a finite
subgroup of $S^1\times\dots\times S^1\subset\mathbb{C}^n$, isomorphic to the
sandpile group.  The zero set is actually linearly isomorphic to a faithful representation of the sandpile group on $\mathbb{C}^n.$

\textbf{Example.} (Continued.)

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(\PYGZob{}0: \PYGZob{}\PYGZcb{}, 1: \PYGZob{}2: 2\PYGZcb{}, 2: \PYGZob{}0: 4, 1: 1\PYGZcb{}\PYGZcb{}, 0)
sage: S.ideal().gens()
[x1\textasciicircum{}2 - x2\textasciicircum{}2, x1*x2\textasciicircum{}3 - x0\textasciicircum{}4, x2\textasciicircum{}5 - x1*x0\textasciicircum{}4]

Approximation to the zero set (setting {}`{}`x\_0 = 1{}`{}`):

sage: S.solve()
[[-0.707107 + 0.707107*I, 0.707107 - 0.707107*I],
[-0.707107 - 0.707107*I, 0.707107 + 0.707107*I],
[-I, -I],
[I, I],
[0.707107 + 0.707107*I, -0.707107 - 0.707107*I],
[0.707107 - 0.707107*I, -0.707107 + 0.707107*I],
[1, 1],
[-1, -1]]
sage: len(\_) == S.group\_order()
True

The zeros are generated as a group by a single vector:

sage: S.points()
[[e\textasciicircum{}(1/4*I*pi), e\textasciicircum{}(-3/4*I*pi)]]
\end{Verbatim}


\subsection{Resolutions}
\label{sandpile:resolutions}
The homogeneous sandpile ideal, $I^h$, has a free resolution graded by the
divisors on $\Gamma$ modulo linear equivalence.  (See the section on
{\hyperref[sandpile:discrete-riemann-surfaces]{\emph{Discrete Riemann Surfaces}}} for the language of
divisors and linear equivalence.)  Let
$S=\mathbb{C}[\Gamma]=\mathbb{C}[x_0,\dots,x_n]$, as above, and let
$\mathfrak{S}$ denote the group of divisors modulo rational equivalence.  Then
$S$ is graded by $\mathfrak{S}$ by letting $\deg(x^c)= c\in\mathfrak{S}$ for
each monomial $x^c$.  The minimal free resolution of $I^h$ has the form
\begin{gather}
\begin{split} 0\leftarrow I^h
\leftarrow\oplus_{D\in\mathfrak{S}}S(-D)^{\beta_{0,D}}\leftarrow\oplus_{D\in\mathfrak{S}}S(-D)^{\beta_{1,D}}
\leftarrow\dots\leftarrow\oplus_{D\in\mathfrak{S}}S(-D)^{\beta_{r,D}}\leftarrow0.\end{split}\notag
\end{gather}
where the $\beta_{i,D}$ are the \emph{Betti numbers} for $I^h$.

For each divisor class $D\in\mathfrak{S}$, define a simplicial complex,
\begin{gather}
\begin{split}\Delta_D := \{I\subseteq\{0,\dots,n\}: I\subseteq\mbox{supp}(E)\mbox{ for some}\
E\in |D|\}.\end{split}\notag
\end{gather}
The Betti number $\beta_{i,D}$ equals the dimension over $\mathbb{C}$ of the
$i$-th reduced homology group of $\Delta_D$:
\begin{gather}
\begin{split}\beta_{i,D} = \dim_{\mathbb{C}}\tilde{H}_i(\Delta_D;\mathbb{C}).\end{split}\notag
\end{gather}
\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(\PYGZob{}0:\PYGZob{}\PYGZcb{},1:\PYGZob{}0: 1, 2: 1, 3: 4\PYGZcb{},2:\PYGZob{}3: 5\PYGZcb{},3:\PYGZob{}1: 1, 2: 1\PYGZcb{}\PYGZcb{},0)

Representatives of all divisor classes with nontrivial homology:

sage: p = S.betti\_complexes() \# optional - 4ti2
sage: p[0] \# optional - 4ti2
[\PYGZob{}0: -8, 1: 5, 2: 4, 3: 1\PYGZcb{},
 Simplicial complex with vertex set (0, 1, 2, 3) and facets \PYGZob{}(1, 2), (3,)\PYGZcb{}]

The homology associated with the first divisor in the list:

sage: D = p[0][0]  \# optional - 4ti2
sage: D.effective\_div() \# optional - 4ti2
[\PYGZob{}0: 0, 1: 1, 2: 1, 3: 0\PYGZcb{}, \PYGZob{}0: 0, 1: 0, 2: 0, 3: 2\PYGZcb{}]
sage: [E.support() for E in D.effective\_div()] \# optional - 4ti2
[[1, 2], [3]]
sage: D.Dcomplex() \# optional - 4ti2
Simplicial complex with vertex set (0, 1, 2, 3) and facets \PYGZob{}(1, 2), (3,)\PYGZcb{}
sage: D.Dcomplex().homology() \# optional - 4ti2
\PYGZob{}0: Z, 1: 0\PYGZcb{}


The minimal free resolution:

sage: S.resolution()
'R\textasciicircum{}1 \textless{}-- R\textasciicircum{}5 \textless{}-- R\textasciicircum{}5 \textless{}-- R\textasciicircum{}1'
sage: S.betti()
           0     1     2     3
------------------------------
    0:     1     -     -     -
    1:     -     5     5     -
    2:     -     -     -     1
------------------------------
total:     1     5     5     1
sage: len(p) \# optional - 4ti2
11

The degrees and ranks of the homology groups for each element of the list p
(compare with the Betti table, above):

sage: [[sum(d[0].values()),d[1].betti()] for d in p] \# optional - 4ti2
[[2, \PYGZob{}0: 2, 1: 0\PYGZcb{}],
[3, \PYGZob{}0: 1, 1: 1, 2: 0\PYGZcb{}],
[2, \PYGZob{}0: 2, 1: 0\PYGZcb{}],
[3, \PYGZob{}0: 1, 1: 1, 2: 0\PYGZcb{}],
[2, \PYGZob{}0: 2, 1: 0\PYGZcb{}],
[3, \PYGZob{}0: 1, 1: 1, 2: 0\PYGZcb{}],
[2, \PYGZob{}0: 2, 1: 0\PYGZcb{}],
[3, \PYGZob{}0: 1, 1: 1\PYGZcb{}],
[2, \PYGZob{}0: 2, 1: 0\PYGZcb{}],
[3, \PYGZob{}0: 1, 1: 1, 2: 0\PYGZcb{}],
[5, \PYGZob{}0: 1, 1: 0, 2: 1\PYGZcb{}]]
\end{Verbatim}


\subsection{Complete Intersections and Arithmetically Gorenstein toppling ideals}
\label{sandpile:complete-intersections-and-arithmetically-gorenstein-toppling-ideals}
NOTE: in the previous section note that the resolution always has length $n$ since
the ideal is Cohen-Macaulay.

To do.


\subsection{Betti numbers for undirected graphs}
\label{sandpile:betti-numbers-for-undirected-graphs}
To do.


\chapter{4ti2 installation}
\label{sandpile:ti2-installation}\label{sandpile:installation}
\begin{notice}{warning}{Warning:}
The methods for computing linear systems of divisors and their corresponding
simplicial complexes require the installation of 4ti2.
\end{notice}

To install 4ti2:
\begin{description}
\item[{Go to the \href{http://sagemath.org/download-packages.html}{Sage website} and}] \leavevmode
look for the \emph{precise name} of the 4ti2 package and install it according to
the instructions given there.  For instance, suppose the package is named
4ti2.p0.spkg.  Install the package with the following command from a UNIX shell
prompt:

\end{description}

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{sage} \PYG{o}{\PYGZhy{}}\PYG{n}{i} \PYG{l+m+mi}{4}\PYG{n}{ti2}\PYG{o}{.}\PYG{n}{p0}
\end{Verbatim}


\chapter{Usage}
\label{sandpile:usage}

\section{Initialization}
\label{sandpile:initialization}
There are three main classes for sandpile structures in Sage: \code{Sandpile},
\code{SandpileConfig}, and \code{SandpileDivisor}.  Initialization for \code{Sandpile}
has the form

\begin{Verbatim}[commandchars=\\\{\}]
\PYG{n}{sage}\PYG{p}{:} \PYG{n}{S} \PYG{o}{=} \PYG{n}{Sandpile}\PYG{p}{(}\PYG{n}{graph}\PYG{p}{,} \PYG{n}{sink}\PYG{p}{)}
\end{Verbatim}

where \code{graph} represents a graph and \code{sink} is the key for the sink
vertex.  There are four possible forms for \code{graph}:
\begin{enumerate}
\item {} 
a Python dictionary of dictionaries:

\begin{Verbatim}[commandchars=\\\{\}]
sage: g = \PYGZob{}0: \PYGZob{}\PYGZcb{}, 1: \PYGZob{}0: 1, 3: 1, 4: 1\PYGZcb{}, 2: \PYGZob{}0: 1, 3: 1, 5: 1\PYGZcb{},
...        3: \PYGZob{}2: 1, 5: 1\PYGZcb{}, 4: \PYGZob{}1: 1, 3: 1\PYGZcb{}, 5: \PYGZob{}2: 1, 3: 1\PYGZcb{}\PYGZcb{}
\end{Verbatim}

\end{enumerate}
\begin{figure}[htbp]
\centering
\capstart

\includegraphics{initial.png}
\caption{Graph from dictionary of dictionaries.}\end{figure}

Each key is the name of a vertex.  Next to each vertex name $v$ is a dictionary
consisting of pairs: \code{vertex: weight}.  Each pair represents a directed edge
emanating from $v$ and ending at \code{vertex} having (non-negative integer) weight
equal to \code{weight}.  Loops are allowed. In the example above, all of the weights are 1.
\begin{enumerate}
\setcounter{enumi}{1}
\item {} 
a Python dictionary of lists:

\begin{Verbatim}[commandchars=\\\{\}]
sage: g = \PYGZob{}0: [], 1: [0, 3, 4], 2: [0, 3, 5],
...        3: [2, 5], 4: [1, 3], 5: [2, 3]\PYGZcb{}
\end{Verbatim}

\end{enumerate}

This is a short-hand when all of the edge-weights are equal to 1.  The above
example is for the same displayed graph.
\begin{enumerate}
\setcounter{enumi}{2}
\item {} 
a Sage graph (of type \code{sage.graphs.graph.Graph}):

\begin{Verbatim}[commandchars=\\\{\}]
sage: g = graphs.CycleGraph(5)
sage: S = Sandpile(g, 0)
sage: type(g)
\textless{}class 'sage.graphs.graph.Graph'\textgreater{}
\end{Verbatim}

\end{enumerate}

To see the types of built-in graphs, type \code{graphs.}, including the period,
and hit TAB.
\begin{enumerate}
\setcounter{enumi}{3}
\item {} 
a Sage digraph:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(digraphs.RandomDirectedGNC(6), 0)
sage: S.show()
\end{Verbatim}

\end{enumerate}
\begin{figure}[htbp]
\centering
\capstart

\includegraphics{random.png}
\caption{A random graph.}\end{figure}

See
sage.graphs.graph\_generators for
more information on the Sage graph library and graph constructors.

Each of these four formats is preprocessed by the Sandpile class so that,
internally, the graph is represented by the dictionary of dictionaries format
first presented.  This internal format is returned by  \code{dict()}:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(\PYGZob{}0:[], 1:[0, 3, 4], 2:[0, 3, 5], 3: [2, 5], 4: [1, 3], 5: [2, 3]\PYGZcb{},0)
sage: S.dict()
\PYGZob{}0: \PYGZob{}\PYGZcb{},
 1: \PYGZob{}0: 1, 3: 1, 4: 1\PYGZcb{},
 2: \PYGZob{}0: 1, 3: 1, 5: 1\PYGZcb{},
 3: \PYGZob{}2: 1, 5: 1\PYGZcb{},
 4: \PYGZob{}1: 1, 3: 1\PYGZcb{},
 5: \PYGZob{}2: 1, 3: 1\PYGZcb{}\PYGZcb{}
\end{Verbatim}

\begin{notice}{note}{Note:}
The user is responsible for assuring that each vertex has a directed path
into the designated sink.  If the sink has out-edges, these will be ignored
for the purposes of sandpile calculations (but not calculations on divisors).
\end{notice}

Code for checking whether a given vertex is a sink:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(\PYGZob{}0:[], 1:[0, 3, 4], 2:[0, 3, 5], 3: [2, 5], 4: [1, 3], 5: [2, 3]\PYGZcb{},0)
sage: [S.distance(v,0) for v in S.vertices()] \# 0 is a sink
[0, 1, 1, 2, 2, 2]
sage: [S.distance(v,1) for v in S.vertices()] \# 1 is not a sink
[+Infinity, 0, +Infinity, +Infinity, 1, +Infinity]
\end{Verbatim}


\section{Methods}
\label{sandpile:methods}
Here are summaries of \code{Sandpile}, \code{SandpileConfig}, and \code{SandpileDivisor} methods
(functions).  Each summary is followed by a list of complete descriptions of
the methods.  There are many more methods available for a Sandpile, e.g.,
those inherited from the class DiGraph.  To see them all, enter
\code{dir(Sandpile)} or type \code{Sandpile.}, including the period, and hit TAB.


\subsection{Sandpile}
\label{sandpile:sandpile}
\textbf{Summary of methods.}
\begin{itemize}
\item {} 
{\hyperref[sandpile:all-k-config-k]{\emph{all\_k\_config(k)}}} --- The configuration with all values set to k.

\item {} 
{\hyperref[sandpile:all-k-div-k]{\emph{all\_k\_div(k)}}} --- The divisor with all values set to k.

\item {} 
{\hyperref[sandpile:betti-verbose-true]{\emph{betti(verbose=True)}}} --- The Betti table for the homogeneous sandpile ideal.

\item {} 
{\hyperref[sandpile:betti-complexes]{\emph{betti\_complexes()}}} --- The divisors with nonempty linear systems along with their simplicial complexes.

\item {} 
{\hyperref[sandpile:burning-config]{\emph{burning\_config()}}} --- A minimal burning configuration.

\item {} 
{\hyperref[sandpile:burning-script]{\emph{burning\_script()}}} --- A script for the minimal burning configuration.

\item {} 
{\hyperref[sandpile:canonical-divisor]{\emph{canonical\_divisor()}}} --- The canonical divisor (for undirected graphs).

\item {} 
{\hyperref[sandpile:dict]{\emph{dict()}}} --- A dictionary of dictionaries representing a directed graph.

\item {} 
{\hyperref[sandpile:groebner]{\emph{groebner()}}} --- Groebner basis for the homogeneous sandpile ideal with respect to the standard sandpile ordering.

\item {} 
{\hyperref[sandpile:group-order]{\emph{group\_order()}}} --- The size of the sandpile group.

\item {} 
{\hyperref[sandpile:h-vector]{\emph{h\_vector()}}} --- The first differences of the Hilbert function of the homogeneous sandpile ideal.

\item {} 
{\hyperref[sandpile:hilbert-function]{\emph{hilbert\_function()}}} --- The Hilbert function of the homogeneous sandpile ideal.

\item {} 
{\hyperref[sandpile:ideal-gens-false]{\emph{ideal(gens=False)}}} --- The saturated, homogeneous sandpile ideal.

\item {} 
{\hyperref[sandpile:identity]{\emph{identity()}}} --- The identity configuration.

\item {} 
{\hyperref[sandpile:in-degree-v-none]{\emph{in\_degree(v=None)}}} --- The in-degree of a vertex or a list of all in-degrees.

\item {} 
{\hyperref[sandpile:invariant-factors]{\emph{invariant\_factors()}}} --- The invariant factors of the sandpile group (a finite abelian group).

\item {} 
{\hyperref[sandpile:is-undirected]{\emph{is\_undirected()}}} --- \code{True} if \code{(u,v)} is and edge if and only if \code{(v,u)} is an edges, each edge with the same weight.

\item {} 
{\hyperref[sandpile:id6]{\emph{laplacian()}}} --- The Laplacian matrix of the graph.

\item {} 
{\hyperref[sandpile:max-stable]{\emph{max\_stable()}}} --- The maximal stable configuration.

\item {} 
{\hyperref[sandpile:max-stable-div]{\emph{max\_stable\_div()}}} --- The maximal stable divisor.

\item {} 
{\hyperref[sandpile:max-superstables-verbose-true]{\emph{max\_superstables(verbose=True)}}} --- The maximal superstable configurations.

\item {} 
{\hyperref[sandpile:min-recurrents-verbose-true]{\emph{min\_recurrents(verbose=True)}}} --- The minimal recurrent elements.

\item {} 
{\hyperref[sandpile:nonsink-vertices]{\emph{nonsink\_vertices()}}} --- The names of the nonsink vertices.

\item {} 
{\hyperref[sandpile:nonspecial-divisors-verbose-true]{\emph{nonspecial\_divisors(verbose=True)}}} --- The nonspecial divisors (only for undirected graphs).

\item {} 
{\hyperref[sandpile:num-edges]{\emph{num\_edges()}}} --- The number of edges.

\item {} 
{\hyperref[sandpile:num-verts]{\emph{num\_verts()}}} --- The number of vertices.

\item {} 
{\hyperref[sandpile:out-degree-v-none]{\emph{out\_degree(v=None)}}} --- The out-degree of a vertex or a list of all out-degrees.

\item {} 
{\hyperref[sandpile:points]{\emph{points()}}} --- Generators for the multiplicative group of zeros of the sandpile ideal.

\item {} 
{\hyperref[sandpile:postulation]{\emph{postulation()}}} --- The postulation number of the sandpile ideal.

\item {} 
{\hyperref[sandpile:recurrents-verbose-true]{\emph{recurrents(verbose=True)}}} --- The list of recurrent configurations.

\item {} 
{\hyperref[sandpile:reduced-laplacian]{\emph{reduced\_laplacian()}}} --- The reduced Laplacian matrix of the graph.

\item {} 
{\hyperref[sandpile:reorder-vertices]{\emph{reorder\_vertices()}}} --- Create a copy of the sandpile but with the vertices reordered.

\item {} 
{\hyperref[sandpile:resolution-verbose-false]{\emph{resolution(verbose=False)}}} --- The minimal free resolution of the homogeneous sandpile ideal.

\item {} 
{\hyperref[sandpile:ring]{\emph{ring()}}} --- The ring containing the homogeneous sandpile ideal.

\item {} 
{\hyperref[sandpile:show-kwds]{\emph{show(kwds)}}} --- Draws the graph.

\item {} 
{\hyperref[sandpile:show3d-kwds]{\emph{show3d(kwds)}}} --- Draws the graph.

\item {} 
{\hyperref[sandpile:sink]{\emph{sink()}}} --- The identifier for the sink vertex.

\item {} 
{\hyperref[sandpile:solve]{\emph{solve()}}} --- Approximations of the complex affine zeros of the sandpile ideal.

\item {} 
{\hyperref[sandpile:superstables-verbose-true]{\emph{superstables(verbose=True)}}} --- The list of superstable configurations.

\item {} 
{\hyperref[sandpile:symmetric-recurrents-orbits]{\emph{symmetric\_recurrents(orbits)}}} --- The list of symmetric recurrent configurations.

\item {} 
{\hyperref[sandpile:unsaturated-ideal]{\emph{unsaturated\_ideal()}}} --- The unsaturated, homogeneous sandpile ideal.

\item {} 
{\hyperref[sandpile:version]{\emph{version()}}} --- The version number of Sage Sandpiles.

\item {} 
{\hyperref[sandpile:vertices-key-none-boundary-first-false]{\emph{vertices(key=None, boundary\_first=False)}}} --- List of the vertices.

\item {} 
{\hyperref[sandpile:zero-config]{\emph{zero\_config()}}} --- The all-zero configuration.

\item {} 
{\hyperref[sandpile:zero-div]{\emph{zero\_div()}}} --- The all-zero divisor.

\end{itemize}


\bigskip\hrule{}\bigskip


\textbf{Complete descriptions of Sandpile methods.}

---
\phantomsection\label{sandpile:all-k-config-k}
\textbf{all\_k\_config(k)}
\begin{quote}

The configuration with all values set to k.

INPUT:

\code{k} - integer

OUTPUT:

SandpileConfig

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.all\_k\_config(7)
\PYGZob{}1: 7, 2: 7, 3: 7, 4: 7, 5: 7\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:all-k-div-k}
\textbf{all\_k\_div(k)}
\begin{quote}

The divisor with all values set to k.

INPUT:

\code{k} - integer

OUTPUT:

SandpileDivisor

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.all\_k\_div(7)
\PYGZob{}0: 7, 1: 7, 2: 7, 3: 7, 4: 7, 5: 7\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:betti-verbose-true}
\textbf{betti(verbose=True)}
\begin{quote}

Computes the Betti table for the homogeneous sandpile ideal.  If
\code{verbose} is \code{True}, it prints the standard Betti table,
otherwise, it returns a less formated table.

INPUT:

\code{verbose} (optional) - boolean

OUTPUT:

Betti numbers for the sandpile

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.betti() \# long time
           0     1     2     3     4     5
------------------------------------------
    0:     1     1     -     -     -     -
    1:     -     4     6     2     -     -
    2:     -     2     7     7     2     -
    3:     -     -     6    16    14     4
------------------------------------------
total:     1     7    19    25    16     4
sage: S.betti(False) \# long time
[1, 7, 19, 25, 16, 4]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:betti-complexes}
\textbf{betti\_complexes()}
\begin{quote}

A list of all the divisors with nonempty linear systems whose
corresponding simplicial complexes have nonzero homology in some
dimension.  Each such divisor is returned with its corresponding
simplicial complex.

INPUT:

None

OUTPUT:

list (of pairs {[}divisors, corresponding simplicial complex{]})

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(\PYGZob{}0:\PYGZob{}\PYGZcb{},1:\PYGZob{}0: 1, 2: 1, 3: 4\PYGZcb{},2:\PYGZob{}3: 5\PYGZcb{},3:\PYGZob{}1: 1, 2: 1\PYGZcb{}\PYGZcb{},0)
sage: p = S.betti\_complexes() \# optional - 4ti2
sage: p[0] \# optional - 4ti2
[\PYGZob{}0: -8, 1: 5, 2: 4, 3: 1\PYGZcb{},
 Simplicial complex with vertex set (0, 1, 2, 3) and facets \PYGZob{}(1, 2), (3,)\PYGZcb{}]
sage: S.resolution()
'R\textasciicircum{}1 \textless{}-- R\textasciicircum{}5 \textless{}-- R\textasciicircum{}5 \textless{}-- R\textasciicircum{}1'
sage: S.betti()
           0     1     2     3
------------------------------
    0:     1     -     -     -
    1:     -     5     5     -
    2:     -     -     -     1
------------------------------
total:     1     5     5     1
sage: len(p) \# optional - 4ti2
11
sage: p[0][1].homology() \# optional - 4ti2
\PYGZob{}0: Z, 1: 0\PYGZcb{}
sage: p[-1][1].homology() \# optional - 4ti2
\PYGZob{}0: 0, 1: 0, 2: Z\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:burning-config}
\textbf{burning\_config()}
\begin{quote}

A minimal burning configuration.

INPUT:

None

OUTPUT:

dict (configuration)

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: g = \PYGZob{}0:\PYGZob{}\PYGZcb{},1:\PYGZob{}0:1,3:1,4:1\PYGZcb{},2:\PYGZob{}0:1,3:1,5:1\PYGZcb{},\PYGZbs{}
           3:\PYGZob{}2:1,5:1\PYGZcb{},4:\PYGZob{}1:1,3:1\PYGZcb{},5:\PYGZob{}2:1,3:1\PYGZcb{}\PYGZcb{}
sage: S = Sandpile(g,0)
sage: S.burning\_config()
\PYGZob{}1: 2, 2: 0, 3: 1, 4: 1, 5: 0\PYGZcb{}
sage: S.burning\_config().values()
[2, 0, 1, 1, 0]
sage: S.burning\_script()
\PYGZob{}1: 1, 2: 3, 3: 5, 4: 1, 5: 4\PYGZcb{}
sage: script = S.burning\_script().values()
sage: script
[1, 3, 5, 1, 4]
sage: matrix(script)*S.reduced\_laplacian()
[2 0 1 1 0]
\end{Verbatim}

NOTES:

The burning configuration and script are computed using a modified
version of Speer's script algorithm.  This is a generalization to
directed multigraphs of Dhar's burning algorithm.

A \emph{burning configuration} is a nonnegative integer-linear
combination of the rows of the reduced Laplacian matrix having
nonnegative entries and such that every vertex has a path from some
vertex in its support.  The corresponding \emph{burning script} gives
the integer-linear combination needed to obtain the burning
configuration.  So if b is the burning configuration, sigma is its
script, and tilde\{L\} is the reduced Laplacian, then sigma *
tilde\{L\} = b.  The \emph{minimal burning configuration} is the one with
the minimal script (its components are no larger than the
components of any other script for a burning configuration).

The following are equivalent for a configuration c with burning
configuration b having script sigma:
\begin{itemize}
\item {} 
c is recurrent;

\item {} 
c+b stabilizes to c;

\item {} 
the firing vector for the stabilization of c+b is sigma.

\end{itemize}
\end{quote}

---
\phantomsection\label{sandpile:burning-script}
\textbf{burning\_script()}
\begin{quote}

A script for the minimal burning configuration.

INPUT:

None

OUTPUT:

dict

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: g = \PYGZob{}0:\PYGZob{}\PYGZcb{},1:\PYGZob{}0:1,3:1,4:1\PYGZcb{},2:\PYGZob{}0:1,3:1,5:1\PYGZcb{},\PYGZbs{}
3:\PYGZob{}2:1,5:1\PYGZcb{},4:\PYGZob{}1:1,3:1\PYGZcb{},5:\PYGZob{}2:1,3:1\PYGZcb{}\PYGZcb{}
sage: S = Sandpile(g,0)
sage: S.burning\_config()
\PYGZob{}1: 2, 2: 0, 3: 1, 4: 1, 5: 0\PYGZcb{}
sage: S.burning\_config().values()
[2, 0, 1, 1, 0]
sage: S.burning\_script()
\PYGZob{}1: 1, 2: 3, 3: 5, 4: 1, 5: 4\PYGZcb{}
sage: script = S.burning\_script().values()
sage: script
[1, 3, 5, 1, 4]
sage: matrix(script)*S.reduced\_laplacian()
[2 0 1 1 0]
\end{Verbatim}

NOTES:

The burning configuration and script are computed using a modified
version of Speer's script algorithm.  This is a generalization to
directed multigraphs of Dhar's burning algorithm.

A \emph{burning configuration} is a nonnegative integer-linear
combination of the rows of the reduced Laplacian matrix having
nonnegative entries and such that every vertex has a path from some
vertex in its support.  The corresponding \emph{burning script} gives
the integer-linear combination needed to obtain the burning
configuration. So if b is the burning configuration, s is its
script, and L\_\{mathrm\{red\}\} is the reduced Laplacian, then s *
L\_\{mathrm\{red\}\}= b.  The \emph{minimal burning configuration} is the
one with the minimal script (its components are no larger than the
components of any other script for a burning configuration).

The following are equivalent for a configuration c with burning
configuration b having script s:
\begin{itemize}
\item {} 
c is recurrent;

\item {} 
c+b stabilizes to c;

\item {} 
the firing vector for the stabilization of c+b is s.

\end{itemize}
\end{quote}

---
\phantomsection\label{sandpile:canonical-divisor}
\textbf{canonical\_divisor()}
\begin{quote}

The canonical divisor: the divisor \code{deg(v)-2} grains of sand on
each vertex.  Only for undirected graphs.

INPUT:

None

OUTPUT:

SandpileDivisor

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = complete\_sandpile(4)
sage: S.canonical\_divisor()
\PYGZob{}0: 1, 1: 1, 2: 1, 3: 1\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:dict}
\textbf{dict()}
\begin{quote}

A dictionary of dictionaries representing a directed graph.

INPUT:

None

OUTPUT:

dict

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: G = sandlib('generic')
sage: G.dict()
\PYGZob{}0: \PYGZob{}\PYGZcb{},
 1: \PYGZob{}0: 1, 3: 1, 4: 1\PYGZcb{},
 2: \PYGZob{}0: 1, 3: 1, 5: 1\PYGZcb{},
 3: \PYGZob{}2: 1, 5: 1\PYGZcb{},
 4: \PYGZob{}1: 1, 3: 1\PYGZcb{},
 5: \PYGZob{}2: 1, 3: 1\PYGZcb{}\PYGZcb{}
sage: G.sink()
0
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:groebner}
\textbf{groebner()}
\begin{quote}

A Groebner basis for the homogeneous sandpile ideal with respect to
the standard sandpile ordering (see \code{ring}).

INPUT:

None

OUTPUT:

Groebner basis

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.groebner()
[x4*x1\textasciicircum{}2 - x5*x0\textasciicircum{}2, x1\textasciicircum{}3 - x4*x3*x0, x5\textasciicircum{}2 - x3*x0, x4\textasciicircum{}2 - x3*x1, x5*x3 - x0\textasciicircum{}2,
x3\textasciicircum{}2 - x5*x0, x2 - x0]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:group-order}
\textbf{group\_order()}
\begin{quote}

The size of the sandpile group.

INPUT:

None

OUTPUT:

int

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.group\_order()
15
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:h-vector}
\textbf{h\_vector()}
\begin{quote}

The first differences of the Hilbert function of the homogeneous
sandpile ideal.  It lists the number of superstable configurations
in each degree.

INPUT:

None

OUTPUT:

list of nonnegative integers

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.hilbert\_function()
[1, 5, 11, 15]
sage: S.h\_vector()
[1, 4, 6, 4]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:hilbert-function}
\textbf{hilbert\_function()}
\begin{quote}

The Hilbert function of the homogeneous sandpile ideal.

INPUT:

None

OUTPUT:

list of nonnegative integers

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.hilbert\_function()
[1, 5, 11, 15]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:ideal-gens-false}
\textbf{ideal(gens=False)}
\begin{quote}

The saturated, homogeneous sandpile ideal (or its generators if
\code{gens=True}).

INPUT:

\code{verbose} (optional) - boolean

OUTPUT:

ideal or, optionally, the generators of an ideal

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.ideal()
Ideal (x2 - x0, x3\textasciicircum{}2 - x5*x0, x5*x3 - x0\textasciicircum{}2, x4\textasciicircum{}2 - x3*x1, x5\textasciicircum{}2 - x3*x0,
x1\textasciicircum{}3 - x4*x3*x0, x4*x1\textasciicircum{}2 - x5*x0\textasciicircum{}2) of Multivariate Polynomial Ring
in x5, x4, x3, x2, x1, x0 over Rational Field
sage: S.ideal(True)
[x2 - x0, x3\textasciicircum{}2 - x5*x0, x5*x3 - x0\textasciicircum{}2, x4\textasciicircum{}2 - x3*x1, x5\textasciicircum{}2 - x3*x0,
x1\textasciicircum{}3 - x4*x3*x0, x4*x1\textasciicircum{}2 - x5*x0\textasciicircum{}2]
sage: S.ideal().gens()  \# another way to get the generators
[x2 - x0, x3\textasciicircum{}2 - x5*x0, x5*x3 - x0\textasciicircum{}2, x4\textasciicircum{}2 - x3*x1, x5\textasciicircum{}2 - x3*x0,
x1\textasciicircum{}3 - x4*x3*x0, x4*x1\textasciicircum{}2 - x5*x0\textasciicircum{}2]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:identity}
\textbf{identity()}
\begin{quote}

The identity configuration.

INPUT:

None

OUTPUT:

dict (the identity configuration)

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: e = S.identity()
sage: x = e \& S.max\_stable()  \# stable addition
sage: x
\PYGZob{}1: 2, 2: 2, 3: 1, 4: 1, 5: 1\PYGZcb{}
sage: x == S.max\_stable()
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:in-degree-v-none}
\textbf{in\_degree(v=None)}
\begin{quote}

The in-degree of a vertex or a list of all in-degrees.

INPUT:

\code{v} - vertex name or None

OUTPUT:

integer or dict

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.in\_degree(2)
2
sage: S.in\_degree()
\PYGZob{}0: 2, 1: 1, 2: 2, 3: 4, 4: 1, 5: 2\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:invariant-factors}
\textbf{invariant\_factors()}
\begin{quote}

The invariant factors of the sandpile group (a finite abelian
group).

INPUT:

None

OUTPUT:

list of integers

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.invariant\_factors()
[1, 1, 1, 1, 15]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:is-undirected}
\textbf{is\_undirected()}
\begin{quote}

\code{True} if \code{(u,v)} is and edge if and only if \code{(v,u)} is an
edges, each edge with the same weight.

INPUT:

None

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: complete\_sandpile(4).is\_undirected()
True
sage: sandlib('gor').is\_undirected()
False
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:id6}
\textbf{laplacian()}
\begin{quote}

The Laplacian matrix of the graph.

INPUT:

None

OUTPUT:

matrix

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: G = sandlib('generic')
sage: G.laplacian()
[ 0  0  0  0  0  0]
[-1  3  0 -1 -1  0]
[-1  0  3 -1  0 -1]
[ 0  0 -1  2  0 -1]
[ 0 -1  0 -1  2  0]
[ 0  0 -1 -1  0  2]
\end{Verbatim}

NOTES:

The function \code{laplacian\_matrix} should be avoided.  It returns
the indegree version of the laplacian.
\end{quote}

---
\phantomsection\label{sandpile:max-stable}
\textbf{max\_stable()}
\begin{quote}

The maximal stable configuration.

INPUT:

None

OUTPUT:

SandpileConfig (the maximal stable configuration)

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.max\_stable()
\PYGZob{}1: 2, 2: 2, 3: 1, 4: 1, 5: 1\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:max-stable-div}
\textbf{max\_stable\_div()}
\begin{quote}

The maximal stable divisor.

INPUT:

SandpileDivisor

OUTPUT:

SandpileDivisor (the maximal stable divisor)

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.max\_stable\_div()
\PYGZob{}0: -1, 1: 2, 2: 2, 3: 1, 4: 1, 5: 1\PYGZcb{}
sage: S.out\_degree()
\PYGZob{}0: 0, 1: 3, 2: 3, 3: 2, 4: 2, 5: 2\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:max-superstables-verbose-true}
\textbf{max\_superstables(verbose=True)}
\begin{quote}

The maximal superstable configurations.  If the underlying graph is
undirected, these are the superstables of highest degree.  If
\code{verbose} is \code{False}, the configurations are converted to lists
of integers.

INPUT:

\code{verbose} (optional) - boolean

OUTPUT:

list (of maximal superstables)

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S=sandlib('riemann-roch2')
sage: S.max\_superstables()
[\PYGZob{}1: 1, 2: 1, 3: 1\PYGZcb{}, \PYGZob{}1: 0, 2: 0, 3: 2\PYGZcb{}]
sage: S.superstables(False)
[[0, 0, 0],
 [1, 0, 1],
 [1, 0, 0],
 [0, 1, 1],
 [0, 1, 0],
 [1, 1, 0],
 [0, 0, 1],
 [1, 1, 1],
 [0, 0, 2]]
sage: S.h\_vector()
[1, 3, 4, 1]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:min-recurrents-verbose-true}
\textbf{min\_recurrents(verbose=True)}
\begin{quote}

The minimal recurrent elements.  If the underlying graph is
undirected, these are the recurrent elements of least degree.  If
\code{verbose is {}`{}`False}, the configurations are converted to lists
of integers.

INPUT:

\code{verbose} (optional) - boolean

OUTPUT:

list of SandpileConfig

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S=sandlib('riemann-roch2')
sage: S.min\_recurrents()
[\PYGZob{}1: 0, 2: 0, 3: 1\PYGZcb{}, \PYGZob{}1: 1, 2: 1, 3: 0\PYGZcb{}]
sage: S.min\_recurrents(False)
[[0, 0, 1], [1, 1, 0]]
sage: S.recurrents(False)
[[1, 1, 2],
 [0, 1, 1],
 [0, 1, 2],
 [1, 0, 1],
 [1, 0, 2],
 [0, 0, 2],
 [1, 1, 1],
 [0, 0, 1],
 [1, 1, 0]]
sage: [i.deg() for i in S.recurrents()]
[4, 2, 3, 2, 3, 2, 3, 1, 2]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:nonsink-vertices}
\textbf{nonsink\_vertices()}
\begin{quote}

The names of the nonsink vertices.

INPUT:

None

OUTPUT:

None

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.nonsink\_vertices()
[1, 2, 3, 4, 5]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:nonspecial-divisors-verbose-true}
\textbf{nonspecial\_divisors(verbose=True)}
\begin{quote}

The nonspecial divisors: those divisors of degree \code{g-1} with
empty linear system.  The term is only defined for undirected
graphs. Here, \code{g = \textbar{}E\textbar{} - \textbar{}V\textbar{} + 1} is the genus of the graph.  If
\code{verbose} is \code{False}, the divisors are converted to lists of
integers.

INPUT:

\code{verbose} (optional) - boolean

OUTPUT:

list (of divisors)

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = complete\_sandpile(4)
sage: ns = S.nonspecial\_divisors() \# optional - 4ti2
sage: D = ns[0] \# optional - 4ti2
sage: D.values() \# optional - 4ti2
[-1, 1, 0, 2]
sage: D.deg() \# optional - 4ti2
2
sage: [i.effective\_div() for i in ns] \# optional - 4ti2
[[], [], [], [], [], []]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:num-edges}
\textbf{num\_edges()}
\begin{quote}

The number of edges.

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: G = graphs.PetersenGraph()
sage: G.size()
15
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:num-verts}
\textbf{num\_verts()}
\begin{quote}

The number of vertices. Note that len(G) returns the number
of vertices in G also.

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: G = graphs.PetersenGraph()
sage: G.order()
10

sage: G = graphs.TetrahedralGraph()
sage: len(G)
4
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:out-degree-v-none}
\textbf{out\_degree(v=None)}
\begin{quote}

The out-degree of a vertex or a list of all out-degrees.

INPUT:

\code{v} (optional) - vertex name

OUTPUT:

integer or dict

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.out\_degree(2)
3
sage: S.out\_degree()
\PYGZob{}0: 0, 1: 3, 2: 3, 3: 2, 4: 2, 5: 2\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:points}
\textbf{points()}
\begin{quote}

Generators for the multiplicative group of zeros of the sandpile
ideal.

INPUT:

None

OUTPUT:

list of complex numbers

EXAMPLES:

The sandpile group in this example is cyclic, and hence there is a
single generator for the group of solutions.

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.points()
[[e\textasciicircum{}(4/5*I*pi), 1, e\textasciicircum{}(2/3*I*pi), e\textasciicircum{}(-34/15*I*pi), e\textasciicircum{}(-2/3*I*pi)]]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:postulation}
\textbf{postulation()}
\begin{quote}

The postulation number of the sandpile ideal.  This is the largest
weight of a superstable configuration of the graph.

INPUT:

None

OUTPUT:

nonnegative integer

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.postulation()
3
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:recurrents-verbose-true}
\textbf{recurrents(verbose=True)}
\begin{quote}

The list of recurrent configurations. If \code{verbose} is \code{False},
the configurations are converted to lists of integers.

INPUT:

\code{verbose} (optional) - boolean

OUTPUT:

list (of recurrent configurations)

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.recurrents()
[\PYGZob{}1: 2, 2: 2, 3: 1, 4: 1, 5: 1\PYGZcb{}, \PYGZob{}1: 2, 2: 2, 3: 0, 4: 1, 5: 1\PYGZcb{},
\PYGZob{}1: 0, 2: 2, 3: 1, 4: 1, 5: 0\PYGZcb{}, \PYGZob{}1: 0, 2: 2, 3: 1, 4: 1, 5: 1\PYGZcb{},
\PYGZob{}1: 1, 2: 2, 3: 1, 4: 1, 5: 1\PYGZcb{}, \PYGZob{}1: 1, 2: 2, 3: 0, 4: 1, 5: 1\PYGZcb{},
\PYGZob{}1: 2, 2: 2, 3: 1, 4: 0, 5: 1\PYGZcb{}, \PYGZob{}1: 2, 2: 2, 3: 0, 4: 0, 5: 1\PYGZcb{},
\PYGZob{}1: 2, 2: 2, 3: 1, 4: 0, 5: 0\PYGZcb{}, \PYGZob{}1: 1, 2: 2, 3: 1, 4: 1, 5: 0\PYGZcb{},
\PYGZob{}1: 1, 2: 2, 3: 1, 4: 0, 5: 0\PYGZcb{}, \PYGZob{}1: 1, 2: 2, 3: 1, 4: 0, 5: 1\PYGZcb{},
\PYGZob{}1: 0, 2: 2, 3: 0, 4: 1, 5: 1\PYGZcb{}, \PYGZob{}1: 2, 2: 2, 3: 1, 4: 1, 5: 0\PYGZcb{},
\PYGZob{}1: 1, 2: 2, 3: 0, 4: 0, 5: 1\PYGZcb{}]
sage: S.recurrents(verbose=False)
[[2, 2, 1, 1, 1], [2, 2, 0, 1, 1], [0, 2, 1, 1, 0], [0, 2, 1, 1, 1],
[1, 2, 1, 1, 1], [1, 2, 0, 1, 1], [2, 2, 1, 0, 1], [2, 2, 0, 0, 1],
[2, 2, 1, 0, 0], [1, 2, 1, 1, 0], [1, 2, 1, 0, 0], [1, 2, 1, 0, 1],
[0, 2, 0, 1, 1], [2, 2, 1, 1, 0], [1, 2, 0, 0, 1]]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:reduced-laplacian}
\textbf{reduced\_laplacian()}
\begin{quote}

The reduced Laplacian matrix of the graph.

INPUT:

None

OUTPUT:

matrix

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: G = sandlib('generic')
sage: G.laplacian()
[ 0  0  0  0  0  0]
[-1  3  0 -1 -1  0]
[-1  0  3 -1  0 -1]
[ 0  0 -1  2  0 -1]
[ 0 -1  0 -1  2  0]
[ 0  0 -1 -1  0  2]
sage: G.reduced\_laplacian()
[ 3  0 -1 -1  0]
[ 0  3 -1  0 -1]
[ 0 -1  2  0 -1]
[-1  0 -1  2  0]
[ 0 -1 -1  0  2]
\end{Verbatim}

NOTES:

This is the Laplacian matrix with the row and column indexed by the
sink vertex removed.
\end{quote}

---
\phantomsection\label{sandpile:reorder-vertices}
\textbf{reorder\_vertices()}
\begin{quote}

Create a copy of the sandpile but with the vertices ordered
according to their distance from the sink, from greatest to least.

INPUT:

None

OUTPUT:

Sandpile

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('kite')
sage: S.dict()
\PYGZob{}0: \PYGZob{}\PYGZcb{}, 1: \PYGZob{}0: 1, 2: 1,
3: 1\PYGZcb{}, 2: \PYGZob{}1: 1, 3: 1, 4: 1\PYGZcb{}, 3: \PYGZob{}1: 1, 2: 1, 4: 1\PYGZcb{}, 4: \PYGZob{}2: 1,
3: 1\PYGZcb{}\PYGZcb{}
sage: T = S.reorder\_vertices()
sage: T.dict()
\PYGZob{}0: \PYGZob{}1: 1, 2: 1\PYGZcb{}, 1: \PYGZob{}0: 1, 2: 1, 3: 1\PYGZcb{}, 2: \PYGZob{}0: 1, 1: 1, 3: 1\PYGZcb{},
3: \PYGZob{}1: 1, 2: 1, 4: 1\PYGZcb{}, 4: \PYGZob{}\PYGZcb{}\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:resolution-verbose-false}
\textbf{resolution(verbose=False)}
\begin{quote}

This function computes a minimal free resolution of the homogeneous
sandpile ideal.  If \code{verbose} is \code{True}, then all of the
mappings are returned.  Otherwise, the resolution is summarized.

INPUT:

\code{verbose} (optional) - boolean

OUTPUT:

free resolution of the sandpile ideal

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('gor')
sage: S.resolution()
'R\textasciicircum{}1 \textless{}-- R\textasciicircum{}5 \textless{}-- R\textasciicircum{}5 \textless{}-- R\textasciicircum{}1'
sage: S.resolution(True)
[
[ x1\textasciicircum{}2 - x3*x0 x3*x1 - x2*x0  x3\textasciicircum{}2 - x2*x1  x2*x3 - x0\textasciicircum{}2  x2\textasciicircum{}2 - x1*x0],
[ x3  x2   0  x0   0]  [ x2\textasciicircum{}2 - x1*x0]
[-x1 -x3  x2   0 -x0]  [-x2*x3 + x0\textasciicircum{}2]
[ x0  x1   0  x2   0]  [-x3\textasciicircum{}2 + x2*x1]
[  0   0 -x1 -x3  x2]  [x3*x1 - x2*x0]
[  0   0  x0  x1 -x3], [ x1\textasciicircum{}2 - x3*x0]
]
sage: r = S.resolution(True)
sage: r[0]*r[1]
[0 0 0 0 0]
sage: r[1]*r[2]
[0]
[0]
[0]
[0]
[0]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:ring}
\textbf{ring()}
\begin{quote}

The ring containing the homogeneous sandpile ideal.

INPUT:

None

OUTPUT:

ring

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.ring()
Multivariate Polynomial Ring in x5, x4, x3, x2, x1, x0 over Rational Field
sage: S.ring().gens()
(x5, x4, x3, x2, x1, x0)
\end{Verbatim}

NOTES:

The indeterminate xi corresponds to the i-th vertex as listed my
the method \code{vertices}. The term-ordering is degrevlex with
indeterminates ordered according to their distance from the sink
(larger indeterminates are further from the sink).
\end{quote}

---
\phantomsection\label{sandpile:show-kwds}
\textbf{show(kwds)}
\begin{quote}

Draws the graph.

INPUT:

\code{kwds} - arguments passed to the show method for Graph or DiGraph

OUTPUT:

None

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.show()
sage: S.show(graph\_border=True, edge\_labels=True)
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:show3d-kwds}
\textbf{show3d(kwds)}
\begin{quote}

Draws the graph.

INPUT:

\code{kwds} - arguments passed to the show method for Graph or DiGraph

OUTPUT:

None

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.show3d()
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:sink}
\textbf{sink()}
\begin{quote}

The identifier for the sink vertex.

INPUT:

None

OUTPUT:

Object (name for the sink vertex)

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: G = sandlib('generic')
sage: G.sink()
0
sage: H = grid\_sandpile(2,2)
sage: H.sink()
'sink'
sage: type(H.sink())
\textless{}type 'str'\textgreater{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:solve}
\textbf{solve()}
\begin{quote}

Approximations of the complex affine zeros of the sandpile ideal.

INPUT:

None

OUTPUT:

list of complex numbers

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(\PYGZob{}0: \PYGZob{}\PYGZcb{}, 1: \PYGZob{}2: 2\PYGZcb{}, 2: \PYGZob{}0: 4, 1: 1\PYGZcb{}\PYGZcb{}, 0)
sage: S.solve()
[[-0.707107 + 0.707107*I, 0.707107 - 0.707107*I],
[-0.707107 - 0.707107*I, 0.707107 + 0.707107*I],
[-I, -I], [I, I], [0.707107 + 0.707107*I, -0.707107 - 0.707107*I],
[0.707107 - 0.707107*I, -0.707107 + 0.707107*I], [1, 1], [-1, -1]]
sage: len(\_)
8
sage: S.group\_order()
8
\end{Verbatim}

NOTES:

The solutions form a multiplicative group isomorphic to the
sandpile group.  Generators for this group are given exactly by
\code{points()}.
\end{quote}

---
\phantomsection\label{sandpile:superstables-verbose-true}
\textbf{superstables(verbose=True)}
\begin{quote}

The list of superstable configurations as dictionaries if
\code{verbose} is \code{True}, otherwise as lists of integers.  The
superstables are also known as G-parking functions.

INPUT:

\code{verbose} (optional) - boolean

OUTPUT:

list (of superstable elements)

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.superstables()
[\PYGZob{}1: 0, 2: 0, 3: 0, 4: 0, 5: 0\PYGZcb{},
 \PYGZob{}1: 0, 2: 0, 3: 1, 4: 0, 5: 0\PYGZcb{},
 \PYGZob{}1: 2, 2: 0, 3: 0, 4: 0, 5: 1\PYGZcb{},
 \PYGZob{}1: 2, 2: 0, 3: 0, 4: 0, 5: 0\PYGZcb{},
 \PYGZob{}1: 1, 2: 0, 3: 0, 4: 0, 5: 0\PYGZcb{},
 \PYGZob{}1: 1, 2: 0, 3: 1, 4: 0, 5: 0\PYGZcb{},
 \PYGZob{}1: 0, 2: 0, 3: 0, 4: 1, 5: 0\PYGZcb{},
 \PYGZob{}1: 0, 2: 0, 3: 1, 4: 1, 5: 0\PYGZcb{},
 \PYGZob{}1: 0, 2: 0, 3: 0, 4: 1, 5: 1\PYGZcb{},
 \PYGZob{}1: 1, 2: 0, 3: 0, 4: 0, 5: 1\PYGZcb{},
 \PYGZob{}1: 1, 2: 0, 3: 0, 4: 1, 5: 1\PYGZcb{},
 \PYGZob{}1: 1, 2: 0, 3: 0, 4: 1, 5: 0\PYGZcb{},
 \PYGZob{}1: 2, 2: 0, 3: 1, 4: 0, 5: 0\PYGZcb{},
 \PYGZob{}1: 0, 2: 0, 3: 0, 4: 0, 5: 1\PYGZcb{},
 \PYGZob{}1: 1, 2: 0, 3: 1, 4: 1, 5: 0\PYGZcb{}]
sage: S.superstables(False)
[[0, 0, 0, 0, 0],
 [0, 0, 1, 0, 0],
 [2, 0, 0, 0, 1],
 [2, 0, 0, 0, 0],
 [1, 0, 0, 0, 0],
 [1, 0, 1, 0, 0],
 [0, 0, 0, 1, 0],
 [0, 0, 1, 1, 0],
 [0, 0, 0, 1, 1],
 [1, 0, 0, 0, 1],
 [1, 0, 0, 1, 1],
 [1, 0, 0, 1, 0],
 [2, 0, 1, 0, 0],
 [0, 0, 0, 0, 1],
 [1, 0, 1, 1, 0]]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:symmetric-recurrents-orbits}
\textbf{symmetric\_recurrents(orbits)}
\begin{quote}

The list of symmetric recurrent configurations.

INPUT:

\code{orbits} - list of lists partitioning the vertices

OUTPUT:

list of recurrent configurations

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('kite')
sage: S.dict()
\PYGZob{}0: \PYGZob{}\PYGZcb{},
 1: \PYGZob{}0: 1, 2: 1, 3: 1\PYGZcb{},
 2: \PYGZob{}1: 1, 3: 1, 4: 1\PYGZcb{},
 3: \PYGZob{}1: 1, 2: 1, 4: 1\PYGZcb{},
 4: \PYGZob{}2: 1, 3: 1\PYGZcb{}\PYGZcb{}
sage: S.symmetric\_recurrents([[1],[2,3],[4]])
[\PYGZob{}1: 2, 2: 2, 3: 2, 4: 1\PYGZcb{}, \PYGZob{}1: 2, 2: 2, 3: 2, 4: 0\PYGZcb{}]
sage: S.recurrents()
[\PYGZob{}1: 2, 2: 2, 3: 2, 4: 1\PYGZcb{},
 \PYGZob{}1: 2, 2: 2, 3: 2, 4: 0\PYGZcb{},
 \PYGZob{}1: 2, 2: 1, 3: 2, 4: 0\PYGZcb{},
 \PYGZob{}1: 2, 2: 2, 3: 0, 4: 1\PYGZcb{},
 \PYGZob{}1: 2, 2: 0, 3: 2, 4: 1\PYGZcb{},
 \PYGZob{}1: 2, 2: 2, 3: 1, 4: 0\PYGZcb{},
 \PYGZob{}1: 2, 2: 1, 3: 2, 4: 1\PYGZcb{},
 \PYGZob{}1: 2, 2: 2, 3: 1, 4: 1\PYGZcb{}]
\end{Verbatim}

NOTES:

The user is responsible for ensuring that the list of orbits comes
from a group of symmetries of the underlying graph.
\end{quote}

---
\phantomsection\label{sandpile:unsaturated-ideal}
\textbf{unsaturated\_ideal()}
\begin{quote}

The unsaturated, homogeneous sandpile ideal.

INPUT:

None

OUTPUT:

ideal

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.unsaturated\_ideal().gens()
[x1\textasciicircum{}3 - x4*x3*x0, x2\textasciicircum{}3 - x5*x3*x0, x3\textasciicircum{}2 - x5*x2, x4\textasciicircum{}2 - x3*x1, x5\textasciicircum{}2 - x3*x2]
sage: S.ideal().gens()
[x2 - x0, x3\textasciicircum{}2 - x5*x0, x5*x3 - x0\textasciicircum{}2, x4\textasciicircum{}2 - x3*x1, x5\textasciicircum{}2 - x3*x0,
x1\textasciicircum{}3 - x4*x3*x0, x4*x1\textasciicircum{}2 - x5*x0\textasciicircum{}2]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:version}
\textbf{version()}
\begin{quote}

The version number of Sage Sandpiles.

INPUT:

None

OUTPUT:

string

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.version()
Sage Sandpiles Version 2.3
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:vertices-key-none-boundary-first-false}
\textbf{vertices(key=None, boundary\_first=False)}
\begin{quote}

A list of the vertices.

INPUT:
\begin{itemize}
\item {} 
\code{key} - default: \code{None} - a function that takes a vertex as
its one argument and returns a value that can be used for
comparisons in the sorting algorithm.

\item {} 
\code{boundary\_first} - default:  \code{False} - if \code{True}, return
the boundary vertices first.

\end{itemize}

OUTPUT:

The vertices of the list.

Warning: There is always an attempt to sort the list before returning the result. However, since any object may be a vertex, there is no guarantee that any two vertices will be comparable.  With default objects for vertices (all integers), or when all the vertices are of the same simple type, then there should not be a problem with how the vertices will be sorted. However, if you need to guarantee a total order for the sort, use the \code{key} argument, as illustrated in the examples below.

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: P = graphs.PetersenGraph()
sage: P.vertices()
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:zero-config}
\textbf{zero\_config()}
\begin{quote}

The all-zero configuration.

INPUT:

None

OUTPUT:

SandpileConfig

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.zero\_config()
\PYGZob{}1: 0, 2: 0, 3: 0, 4: 0, 5: 0\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:zero-div}
\textbf{zero\_div()}
\begin{quote}

The all-zero divisor.

INPUT:

None

OUTPUT:

SandpileDivisor

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.zero\_div()
\PYGZob{}0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0\PYGZcb{}
\end{Verbatim}
\end{quote}

---


\subsection{SandpileConfig}
\label{sandpile:sandpileconfig}
\textbf{Summary of methods.}
\begin{itemize}
\item {} 
{\hyperref[sandpile:id7]{\emph{+}}} --- Addition of configurations.

\item {} 
{\hyperref[sandpile:id8]{\emph{\&}}} --- The stabilization of the sum.

\item {} 
{\hyperref[sandpile:greater-equal]{\emph{greater-equal}}} --- \code{True} if every component of \code{self} is at least that of \code{other}.

\item {} 
{\hyperref[sandpile:greater]{\emph{greater}}} --- \code{True} if every component of \code{self} is at least that of \code{other} and the two configurations are not equal.

\item {} 
{\hyperref[sandpile:id9]{\emph{\textasciitilde{}}}} --- The stabilized configuration.

\item {} 
{\hyperref[sandpile:less-equal]{\emph{less-equal}}} --- \code{True} if every component of \code{self} is at most that of \code{other}.

\item {} 
{\hyperref[sandpile:less]{\emph{less}}} --- \code{True} if every component of \code{self} is at most that of \code{other} and the two configurations are not equal.

\item {} 
{\hyperref[sandpile:mul]{\emph{*}}} --- The recurrent element equivalent to the sum.

\item {} 
{\hyperref[sandpile:pow]{\emph{\textasciicircum{}}}} --- Exponentiation for the *-operator.

\item {} 
{\hyperref[sandpile:neg]{\emph{-}}} --- The additive inverse of the configuration.

\item {} 
{\hyperref[sandpile:id10]{\emph{-}}} --- Subtraction of configurations.

\item {} 
{\hyperref[sandpile:add-random]{\emph{add\_random()}}} --- Add one grain of sand to a random nonsink vertex.

\item {} 
{\hyperref[sandpile:deg]{\emph{deg()}}} --- The degree of the configuration.

\item {} 
{\hyperref[sandpile:dualize]{\emph{dualize()}}} --- The difference between the maximal stable configuration and the configuration.

\item {} 
{\hyperref[sandpile:equivalent-recurrent-with-firing-vector-false]{\emph{equivalent\_recurrent(with\_firing\_vector=False)}}} --- The equivalent recurrent configuration.

\item {} 
{\hyperref[sandpile:equivalent-superstable-with-firing-vector-false]{\emph{equivalent\_superstable(with\_firing\_vector=False)}}} --- The equivalent superstable configuration.

\item {} 
{\hyperref[sandpile:fire-script-sigma]{\emph{fire\_script(sigma)}}} --- Fire the script \code{sigma}, i.e., fire each vertex the indicated number of times.

\item {} 
{\hyperref[sandpile:fire-unstable]{\emph{fire\_unstable()}}} --- Fire all unstable vertices.

\item {} 
{\hyperref[sandpile:fire-vertex-v]{\emph{fire\_vertex(v)}}} --- Fire the vertex \code{v}.

\item {} 
{\hyperref[sandpile:is-recurrent]{\emph{is\_recurrent()}}} --- \code{True} if the configuration is recurrent.

\item {} 
{\hyperref[sandpile:is-stable]{\emph{is\_stable()}}} --- \code{True} if stable.

\item {} 
{\hyperref[sandpile:is-superstable]{\emph{is\_superstable()}}} --- \code{True} if \code{config} is superstable.

\item {} 
{\hyperref[sandpile:is-symmetric-orbits]{\emph{is\_symmetric(orbits)}}} --- Is the configuration constant over the vertices in each sublist of \code{orbits}?

\item {} 
{\hyperref[sandpile:order]{\emph{order()}}} --- The order of the recurrent element equivalent to \code{config}.

\item {} 
{\hyperref[sandpile:id11]{\emph{sandpile()}}} --- The configuration's underlying sandpile.

\item {} 
{\hyperref[sandpile:show-sink-true-colors-true-heights-false-directed-none-kwds]{\emph{show(sink=True,colors=True,heights=False,directed=None,kwds)}}} --- Show the configuration.

\item {} 
{\hyperref[sandpile:stabilize-with-firing-vector-false]{\emph{stabilize(with\_firing\_vector=False)}}} --- The stabilized configuration.  Optionally returns the corresponding firing vector.

\item {} 
{\hyperref[sandpile:support]{\emph{support()}}} --- Keys of the nonzero values of the dictionary.

\item {} 
{\hyperref[sandpile:unstable]{\emph{unstable()}}} --- List of the unstable vertices.

\item {} 
{\hyperref[sandpile:values]{\emph{values()}}} --- The values of the configuration as a list.

\end{itemize}


\bigskip\hrule{}\bigskip


\textbf{Complete descriptions of SandpileConfig methods.}

---
\phantomsection\label{sandpile:id7}
\textbf{+}
\begin{quote}

Addition of configurations.

INPUT:

\code{other} - SandpileConfig

OUTPUT:

sum of \code{self} and \code{other}

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: c = SandpileConfig(S, [1,2])
sage: d = SandpileConfig(S, [3,2])
sage: c + d
\PYGZob{}1: 4, 2: 4\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:id8}
\textbf{\&}
\begin{quote}

The stabilization of the sum.

INPUT:

\code{other} - SandpileConfig

OUTPUT:

SandpileConfig

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(4), 0)
sage: c = SandpileConfig(S, [1,0,0])
sage: c + c  \# ordinary addition
\PYGZob{}1: 2, 2: 0, 3: 0\PYGZcb{}
sage: c \& c  \# add and stabilize
\PYGZob{}1: 0, 2: 1, 3: 0\PYGZcb{}
sage: c*c  \# add and find equivalent recurrent
\PYGZob{}1: 1, 2: 1, 3: 1\PYGZcb{}
sage: \textasciitilde{}(c + c) == c \& c
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:greater-equal}
\textbf{\textgreater{}=}
\begin{quote}

\code{True} if every component of \code{self} is at least that of
\code{other}.

INPUT:

\code{other} - SandpileConfig

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: c = SandpileConfig(S, [1,2])
sage: d = SandpileConfig(S, [2,3])
sage: e = SandpileConfig(S, [2,0])
sage: c \textgreater{}= c
True
sage: d \textgreater{}= c
True
sage: c \textgreater{}= d
False
sage: e \textgreater{}= c
False
sage: c \textgreater{}= e
False
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:greater}
\textbf{\textgreater{}}
\begin{quote}

\code{True} if every component of \code{self} is at least that of
\code{other} and the two configurations are not equal.

INPUT:

\code{other} - SandpileConfig

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: c = SandpileConfig(S, [1,2])
sage: d = SandpileConfig(S, [1,3])
sage: c \textgreater{} c
False
sage: d \textgreater{} c
True
sage: c \textgreater{} d
False
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:id9}
\textbf{\textasciitilde{}}
\begin{quote}

The stabilized configuration.

INPUT:

None

OUTPUT:

\code{SandpileConfig}

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: c = S.max\_stable() + S.identity()
sage: \textasciitilde{}c
\PYGZob{}1: 2, 2: 2, 3: 1, 4: 1, 5: 1\PYGZcb{}
sage: \textasciitilde{}c == c.stabilize()
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:less-equal}
\textbf{\textless{}=}
\begin{quote}

\code{True} if every component of \code{self} is at most that of
\code{other}.

INPUT:

\code{other} - SandpileConfig

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: c = SandpileConfig(S, [1,2])
sage: d = SandpileConfig(S, [2,3])
sage: e = SandpileConfig(S, [2,0])
sage: c \textless{}= c
True
sage: c \textless{}= d
True
sage: d \textless{}= c
False
sage: c \textless{}= e
False
sage: e \textless{}= c
False
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:less}
\textbf{\textless{}}
\begin{quote}

\code{True} if every component of \code{self} is at most that of
\code{other} and the two configurations are not equal.

INPUT:

\code{other} - SandpileConfig

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: c = SandpileConfig(S, [1,2])
sage: d = SandpileConfig(S, [2,3])
sage: c \textless{} c
False
sage: c \textless{} d
True
sage: d \textless{} c
False
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:mul}
\textbf{*}
\begin{quote}

The recurrent element equivalent to the sum.

INPUT:

\code{other} - SandpileConfig

OUTPUT:

SandpileConfig

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(4), 0)
sage: c = SandpileConfig(S, [1,0,0])
sage: c + c  \# ordinary addition
\PYGZob{}1: 2, 2: 0, 3: 0\PYGZcb{}
sage: c \& c  \# add and stabilize
\PYGZob{}1: 0, 2: 1, 3: 0\PYGZcb{}
sage: c*c  \# add and find equivalent recurrent
\PYGZob{}1: 1, 2: 1, 3: 1\PYGZcb{}
sage: (c*c).is\_recurrent()
True
sage: c*(-c) == S.identity()
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:pow}
\textbf{\textasciicircum{}}
\begin{quote}

The recurrent element equivalent to the sum of the configuration
with itself \code{k} times.  If \code{k} is negative, do the same for the
negation of the configuration.  If \code{k} is zero, return the
identity of the sandpile group.

INPUT:

\code{k} - SandpileConfig

OUTPUT:

SandpileConfig

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(4), 0)
sage: c = SandpileConfig(S, [1,0,0])
sage: c\textasciicircum{}3
\PYGZob{}1: 1, 2: 1, 3: 0\PYGZcb{}
sage: (c + c + c) == c\textasciicircum{}3
False
sage: (c + c + c).equivalent\_recurrent() == c\textasciicircum{}3
True
sage: c\textasciicircum{}(-1)
\PYGZob{}1: 1, 2: 1, 3: 0\PYGZcb{}
sage: c\textasciicircum{}0 == S.identity()
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:neg}
\textbf{\_}
\begin{quote}

The additive inverse of the configuration.

INPUT:

None

OUTPUT:

SandpileConfig

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: c = SandpileConfig(S, [1,2])
sage: -c
\PYGZob{}1: -1, 2: -2\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:id10}
\textbf{-}
\begin{quote}

Subtraction of configurations.

INPUT:

\code{other} - SandpileConfig

OUTPUT:

sum of \code{self} and \code{other}

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: c = SandpileConfig(S, [1,2])
sage: d = SandpileConfig(S, [3,2])
sage: c - d
\PYGZob{}1: -2, 2: 0\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:add-random}
\textbf{add\_random()}
\begin{quote}

Add one grain of sand to a random nonsink vertex.

INPUT:

None

OUTPUT:

SandpileConfig

EXAMPLES:

We compute the `sizes' of the avalanches caused by adding random
grains of sand to the maximal stable configuration on a grid graph.
The function \code{stabilize()} returns the firing vector of the
stabilization, a dictionary whose values say how many times each
vertex fires in the stabilization.

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = grid\_sandpile(10,10)
sage: m = S.max\_stable()
sage: a = []
sage: for i in range(1000):
...       m = m.add\_random()
...       m, f = m.stabilize(True)
...       a.append(sum(f.values()))
...
sage: p = list\_plot([[log(i+1),log(a.count(i))] for i in [0..max(a)] if a.count(i)])
sage: p.axes\_labels(['log(N)','log(D(N))'])
sage: t = text("Distribution of avalanche sizes", (2,2), rgbcolor=(1,0,0))
sage: show(p+t,axes\_labels=['log(N)','log(D(N))'])
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:deg}
\textbf{deg()}
\begin{quote}

The degree of the configuration.

INPUT:

None

OUTPUT:

integer

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: c = SandpileConfig(S, [1,2])
sage: c.deg()
3
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:dualize}
\textbf{dualize()}
\begin{quote}

The difference between the maximal stable configuration and the
configuration.

INPUT:

None

OUTPUT:

SandpileConfig

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: c = SandpileConfig(S, [1,2])
sage: S.max\_stable()
\PYGZob{}1: 1, 2: 1\PYGZcb{}
sage: c.dualize()
\PYGZob{}1: 0, 2: -1\PYGZcb{}
sage: S.max\_stable() - c == c.dualize()
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:equivalent-recurrent-with-firing-vector-false}
\textbf{equivalent\_recurrent(with\_firing\_vector=False)}
\begin{quote}

The recurrent configuration equivalent to the given configuration.
Optionally returns the corresponding firing vector.

INPUT:

\code{with\_firing\_vector} (optional) -  boolean

OUTPUT:

\code{SandpileConfig} or \code{{[}SandpileConfig, firing\_vector{]}}

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: c = SandpileConfig(S, [0,0,0,0,0])
sage: c.equivalent\_recurrent() == S.identity()
True
sage: x = c.equivalent\_recurrent(True)
sage: r = vector([x[0][v] for v in S.nonsink\_vertices()])
sage: f = vector([x[1][v] for v in S.nonsink\_vertices()])
sage: cv = vector(c.values())
sage: r == cv - f*S.reduced\_laplacian()
True
\end{Verbatim}

NOTES:

Let L be the reduced laplacian, c the initial configuration, r the
returned configuration, and f the firing vector.  Then r = c -
f * L.
\end{quote}

---
\phantomsection\label{sandpile:equivalent-superstable-with-firing-vector-false}
\textbf{equivalent\_superstable(with\_firing\_vector=False)}
\begin{quote}

The equivalent superstable configuration. Optionally returns the
corresponding firing vector.

INPUT:

\code{with\_firing\_vector} (optional) - boolean

OUTPUT:

\code{SandpileConfig} or \code{{[}SandpileConfig, firing\_vector{]}}

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: m = S.max\_stable()
sage: m.equivalent\_superstable().is\_superstable()
True
sage: x = m.equivalent\_superstable(True)
sage: s = vector(x[0].values())
sage: f = vector(x[1].values())
sage: mv = vector(m.values())
sage: s == mv - f*S.reduced\_laplacian()
True
\end{Verbatim}

NOTES:

Let L be the reduced laplacian, c the initial configuration, s the
returned configuration, and f the firing vector.  Then s = c -
f * L.
\end{quote}

---
\phantomsection\label{sandpile:fire-script-sigma}
\textbf{fire\_script(sigma)}
\begin{quote}

Fire the script \code{sigma}, i.e., fire each vertex the indicated
number of times.

INPUT:

\code{sigma} - SandpileConfig or (list or dict representing a SandpileConfig)

OUTPUT:

SandpileConfig

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(4), 0)
sage: c = SandpileConfig(S, [1,2,3])
sage: c.unstable()
[2, 3]
sage: c.fire\_script(SandpileConfig(S,[0,1,1]))
\PYGZob{}1: 2, 2: 1, 3: 2\PYGZcb{}
sage: c.fire\_script(SandpileConfig(S,[2,0,0])) == c.fire\_vertex(1).fire\_vertex(1)
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:fire-unstable}
\textbf{fire\_unstable()}
\begin{quote}

Fire all unstable vertices.

INPUT:

None

OUTPUT:

SandpileConfig

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(4), 0)
sage: c = SandpileConfig(S, [1,2,3])
sage: c.fire\_unstable()
\PYGZob{}1: 2, 2: 1, 3: 2\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:fire-vertex-v}
\textbf{fire\_vertex(v)}
\begin{quote}

Fire the vertex \code{v}.

INPUT:

\code{v} - vertex

OUTPUT:

SandpileConfig

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: c = SandpileConfig(S, [1,2])
sage: c.fire\_vertex(2)
\PYGZob{}1: 2, 2: 0\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:is-recurrent}
\textbf{is\_recurrent()}
\begin{quote}

\code{True} if the configuration is recurrent.

INPUT:

None

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.identity().is\_recurrent()
True
sage: S.zero\_config().is\_recurrent()
False
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:is-stable}
\textbf{is\_stable()}
\begin{quote}

\code{True} if stable.

INPUT:

None

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.max\_stable().is\_stable()
True
sage: (S.max\_stable() + S.max\_stable()).is\_stable()
False
sage: (S.max\_stable() \& S.max\_stable()).is\_stable()
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:is-superstable}
\textbf{is\_superstable()}
\begin{quote}

\code{True} if \code{config} is superstable, i.e., whether its dual is
recurrent.

INPUT:

None

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.zero\_config().is\_superstable()
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:is-symmetric-orbits}
\textbf{is\_symmetric(orbits)}
\begin{quote}

This function checks if the values of the configuration are
constant over the vertices in each sublist of \code{orbits}.

INPUT:
\begin{quote}

\code{orbits} - list of lists of vertices
\end{quote}

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('kite')
sage: S.dict()
\PYGZob{}0: \PYGZob{}\PYGZcb{},
 1: \PYGZob{}0: 1, 2: 1, 3: 1\PYGZcb{},
 2: \PYGZob{}1: 1, 3: 1, 4: 1\PYGZcb{},
 3: \PYGZob{}1: 1, 2: 1, 4: 1\PYGZcb{},
 4: \PYGZob{}2: 1, 3: 1\PYGZcb{}\PYGZcb{}
sage: c = SandpileConfig(S, [1, 2, 2, 3])
sage: c.is\_symmetric([[2,3]])
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:order}
\textbf{order()}
\begin{quote}

The order of the recurrent element equivalent to \code{config}.

INPUT:

\code{config} - configuration

OUTPUT:

integer

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: [r.order() for r in S.recurrents()]
[3, 3, 5, 15, 15, 15, 5, 15, 15, 5, 15, 5, 15, 1, 15]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:id11}
\textbf{sandpile()}
\begin{quote}

The configuration's underlying sandpile.

INPUT:

None

OUTPUT:

Sandpile

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('genus2')
sage: c = S.identity()
sage: c.sandpile()
Digraph on 4 vertices
sage: c.sandpile() == S
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:show-sink-true-colors-true-heights-false-directed-none-kwds}
\textbf{show(sink=True,colors=True,heights=False,directed=None,kwds)}
\begin{quote}

Show the configuration.

INPUT:
\begin{itemize}
\item {} 
\code{sink} - whether to show the sink

\item {} 
\code{colors} - whether to color-code the amount of sand on each
vertex

\item {} 
\code{heights} - whether to label each vertex with the amount of
sand

\item {} 
\code{kwds} - arguments passed to the show method for Graph

\item {} 
\code{directed} - whether to draw directed edges

\end{itemize}

OUTPUT:

None

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S=sandlib('genus2')
sage: c=S.identity()
sage: S=sandlib('genus2')
sage: c=S.identity()
sage: c.show()
sage: c.show(directed=False)
sage: c.show(sink=False,colors=False,heights=True)
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:stabilize-with-firing-vector-false}
\textbf{stabilize(with\_firing\_vector=False)}
\begin{quote}

The stabilized configuration.  Optionally returns the corresponding
firing vector.

INPUT:

\code{with\_firing\_vector} (optional) -  boolean

OUTPUT:

\code{SandpileConfig} or \code{{[}SandpileConfig, firing\_vector{]}}

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: c = S.max\_stable() + S.identity()
sage: c.stabilize(True)
[\PYGZob{}1: 2, 2: 2, 3: 1, 4: 1, 5: 1\PYGZcb{}, \PYGZob{}1: 1, 2: 5, 3: 7, 4: 1, 5: 6\PYGZcb{}]
sage: S.max\_stable() \& S.identity()
\PYGZob{}1: 2, 2: 2, 3: 1, 4: 1, 5: 1\PYGZcb{}
sage: S.max\_stable() \& S.identity() == c.stabilize()
True
sage: \textasciitilde{}c
\PYGZob{}1: 2, 2: 2, 3: 1, 4: 1, 5: 1\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:support}
\textbf{support()}
\begin{quote}

The input is a dictionary of integers.  The output is a list of
keys of nonzero values of the dictionary.

INPUT:

None

OUTPUT:

list - support of the config

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: c = S.identity()
sage: c.values()
[2, 2, 1, 1, 0]
sage: c.support()
[1, 2, 3, 4]
sage: S.vertices()
[0, 1, 2, 3, 4, 5]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:unstable}
\textbf{unstable()}
\begin{quote}

List of the unstable vertices.

INPUT:

None

OUTPUT:

list of vertices

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(4), 0)
sage: c = SandpileConfig(S, [1,2,3])
sage: c.unstable()
[2, 3]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:values}
\textbf{values()}
\begin{quote}

The values of the configuration as a list, sorted in the order of
the vertices.

INPUT:

None

OUTPUT:

list of integers

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(\PYGZob{}'a':[1,'b'], 'b':[1,'a'], 1:['a']\PYGZcb{},'a')
sage: c = SandpileConfig(S, \PYGZob{}'b':1, 1:2\PYGZcb{})
sage: c
\PYGZob{}1: 2, 'b': 1\PYGZcb{}
sage: c.values()
[2, 1]
sage: S.nonsink\_vertices()
[1, 'b']
\end{Verbatim}
\end{quote}

---


\subsection{SandpileDivisor}
\label{sandpile:sandpiledivisor}
\textbf{Summary of methods.}
\begin{itemize}
\item {} 
{\hyperref[sandpile:divisor]{\emph{+}}} --- Addition of divisors.

\item {} 
{\hyperref[sandpile:greater-equal-divisor]{\emph{greater-equal}}} --- \code{True} if every component of \code{self} is at least that of \code{other}.

\item {} 
{\hyperref[sandpile:greater-divisor]{\emph{greater}}} --- \code{True} if every component of \code{self} is at least that of \code{other} and the two divisors are not equal.

\item {} 
{\hyperref[sandpile:less-equal-divisor]{\emph{less-equal}}} --- \code{True} if every component of \code{self} is at most that of \code{other}.

\item {} 
{\hyperref[sandpile:less-divisor]{\emph{less}}} --- \code{True} if every component of \code{self} is at most that of \code{other} and the two divisors are not equal.

\item {} 
{\hyperref[sandpile:neg-divisor]{\emph{-}}} --- The additive inverse of the divisor.

\item {} 
{\hyperref[sandpile:sub-divisor]{\emph{-}}} --- Subtraction of divisors.

\item {} 
{\hyperref[sandpile:add-random-divisor]{\emph{add\_random()}}} --- Add one grain of sand to a random vertex.

\item {} 
{\hyperref[sandpile:betti-divisor]{\emph{betti()}}} --- The Betti numbers for the simplicial complex associated with the divisor.

\item {} 
{\hyperref[sandpile:dcomplex]{\emph{Dcomplex()}}} --- The simplicial complex determined by the supports of the linearly equivalent effective divisors.

\item {} 
{\hyperref[sandpile:deg-divisor]{\emph{deg()}}} --- The degree of the divisor.

\item {} 
{\hyperref[sandpile:dualize-divisor]{\emph{dualize()}}} --- The difference between the maximal stable divisor and the divisor.

\item {} 
{\hyperref[sandpile:effective-div-verbose-true]{\emph{effective\_div(verbose=True)}}} --- All linearly equivalent effective divisors.

\item {} 
{\hyperref[sandpile:fire-script-sigma-divisor]{\emph{fire\_script(sigma)}}} --- Fire the script \code{sigma}, i.e., fire each vertex the indicated number of times.

\item {} 
{\hyperref[sandpile:fire-unstable-divisor]{\emph{fire\_unstable()}}} --- Fire all unstable vertices.

\item {} 
{\hyperref[sandpile:fire-vertex-v-divisor]{\emph{fire\_vertex(v)}}} --- Fire the vertex \code{v}.

\item {} 
{\hyperref[sandpile:is-alive-cycle-false]{\emph{is\_alive(cycle=False)}}} --- Will the divisor stabilize under repeated firings of all unstable vertices?

\item {} 
{\hyperref[sandpile:is-symmetric-orbits-divisor]{\emph{is\_symmetric(orbits)}}} --- Is the divisor constant over the vertices in each sublist of \code{orbits}?

\item {} 
{\hyperref[sandpile:linear-system]{\emph{linear\_system()}}} --- The complete linear system of a divisor.

\item {} 
{\hyperref[sandpile:r-of-d-verbose-false]{\emph{r\_of\_D(verbose=False)}}} --- Returns \code{r(D)}.

\item {} 
{\hyperref[sandpile:sandpile-divisor]{\emph{sandpile()}}} --- The divisor's underlying sandpile.

\item {} 
{\hyperref[sandpile:show-heights-true-directed-none-kwds-divisor]{\emph{show(heights=True,directed=None,kwds)}}} --- Show the divisor.

\item {} 
{\hyperref[sandpile:support-divisor]{\emph{support()}}} --- List of keys of the nonzero values of the divisor.

\item {} 
{\hyperref[sandpile:unstable-divisor]{\emph{unstable()}}} --- List of the unstable vertices.

\item {} 
{\hyperref[sandpile:values-divisor]{\emph{values()}}} --- The values of the divisor as a list, sorted in the order of the vertices.

\end{itemize}


\bigskip\hrule{}\bigskip


\textbf{Complete descriptions of SandpileDivisor methods.}

---
\phantomsection\label{sandpile:divisor}
\textbf{+}
\begin{quote}

Addition of divisors.

INPUT:

\code{other} - SandpileDivisor

OUTPUT:

sum of \code{self} and \code{other}

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: E = SandpileDivisor(S, [3,2,1])
sage: D + E
\PYGZob{}0: 4, 1: 4, 2: 4\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:greater-equal-divisor}
\textbf{\textgreater{}=}
\begin{quote}

\code{True} if every component of \code{self} is at least that of
\code{other}.

INPUT:

\code{other} - SandpileDivisor

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: E = SandpileDivisor(S, [2,3,4])
sage: F = SandpileDivisor(S, [2,0,4])
sage: D \textgreater{}= D
True
sage: E \textgreater{}= D
True
sage: D \textgreater{}= E
False
sage: F \textgreater{}= D
False
sage: D \textgreater{}= F
False
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:greater-divisor}
\textbf{\textgreater{}}
\begin{quote}

\code{True} if every component of \code{self} is at least that of
\code{other} and the two divisors are not equal.

INPUT:

\code{other} - SandpileDivisor

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: E = SandpileDivisor(S, [1,3,4])
sage: D \textgreater{} D
False
sage: E \textgreater{} D
True
sage: D \textgreater{} E
False
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:less-equal-divisor}
\textbf{\textless{}=}
\begin{quote}

\code{True} if every component of \code{self} is at most that of
\code{other}.

INPUT:

\code{other} - SandpileDivisor

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: E = SandpileDivisor(S, [2,3,4])
sage: F = SandpileDivisor(S, [2,0,4])
sage: D \textless{}= D
True
sage: D \textless{}= E
True
sage: E \textless{}= D
False
sage: D \textless{}= F
False
sage: F \textless{}= D
False
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:less-divisor}
\textbf{\textless{}}
\begin{quote}

\code{True} if every component of \code{self} is at most that of
\code{other} and the two divisors are not equal.

INPUT:

\code{other} - SandpileDivisor

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: E = SandpileDivisor(S, [2,3,4])
sage: D \textless{} D
False
sage: D \textless{} E
True
sage: E \textless{} D
False
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:neg-divisor}
\textbf{-}
\begin{quote}

The additive inverse of the divisor.

INPUT:

None

OUTPUT:

SandpileDivisor

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: -D
\PYGZob{}0: -1, 1: -2, 2: -3\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:sub-divisor}
\textbf{-}
\begin{quote}

Subtraction of divisors.

INPUT:

\code{other} - SandpileDivisor

OUTPUT:

Difference of \code{self} and \code{other}

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: E = SandpileDivisor(S, [3,2,1])
sage: D - E
\PYGZob{}0: -2, 1: 0, 2: 2\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:add-random-divisor}
\textbf{add\_random()}
\begin{quote}

Add one grain of sand to a random vertex.

INPUT:

None

OUTPUT:

SandpileDivisor

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: S.zero\_div().add\_random()  \#random
\PYGZob{}0: 0, 1: 0, 2: 0, 3: 1, 4: 0, 5: 0\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:betti-divisor}
\textbf{betti()}
\begin{quote}

The Betti numbers for the simplicial complex associated with the
divisor.

INPUT:

None

OUTPUT:

dictionary of integers

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [2,0,1])
sage: D.betti() \# optional - 4ti2
\PYGZob{}0: 1, 1: 1\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:dcomplex}
\textbf{Dcomplex()}
\begin{quote}

The simplicial complex determined by the supports of the linearly
equivalent effective divisors.

INPUT:

None

OUTPUT:

simplicial complex

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: p = SandpileDivisor(S, [0,1,2,0,0,1]).Dcomplex() \# optional - 4ti2
sage: p.homology() \# optional - 4ti2
\PYGZob{}0: 0, 1: Z x Z, 2: 0, 3: 0\PYGZcb{}
sage: p.f\_vector() \# optional - 4ti2
[1, 6, 15, 9, 1]
sage: p.betti() \# optional - 4ti2
\PYGZob{}0: 1, 1: 2, 2: 0, 3: 0\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:deg-divisor}
\textbf{deg()}
\begin{quote}

The degree of the divisor.

INPUT:

None

OUTPUT:

integer

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: D.deg()
6
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:dualize-divisor}
\textbf{dualize()}
\begin{quote}

The difference between the maximal stable divisor and the divisor.

INPUT:

None

OUTPUT:

SandpileDivisor

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: D.dualize()
\PYGZob{}0: 0, 1: -1, 2: -2\PYGZcb{}
sage: S.max\_stable\_div() - D == D.dualize()
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:effective-div-verbose-true}
\textbf{effective\_div(verbose=True)}
\begin{quote}

All linearly equivalent effective divisors.  If \code{verbose} is
\code{False}, the divisors are converted to lists of integers.

INPUT:

\code{verbose} (optional) - boolean

OUTPUT:

list (of divisors)

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: D = SandpileDivisor(S, [0,0,0,0,0,2]) \# optional - 4ti2
sage: D.effective\_div() \# optional - 4ti2
[\PYGZob{}0: 1, 1: 0, 2: 0, 3: 1, 4: 0, 5: 0\PYGZcb{},
 \PYGZob{}0: 0, 1: 0, 2: 1, 3: 1, 4: 0, 5: 0\PYGZcb{},
 \PYGZob{}0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 2\PYGZcb{}]
sage: D.effective\_div(False) \# optional - 4ti2
[[1, 0, 0, 1, 0, 0], [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 2]]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:fire-script-sigma-divisor}
\textbf{fire\_script(sigma)}
\begin{quote}

Fire the script \code{sigma}, i.e., fire each vertex the indicated
number of times.

INPUT:

\code{sigma} - SandpileDivisor or (list or dict representing a SandpileDivisor)

OUTPUT:

SandpileDivisor

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: D.unstable()
[1, 2]
sage: D.fire\_script([0,1,1])
\PYGZob{}0: 3, 1: 1, 2: 2\PYGZcb{}
sage: D.fire\_script(SandpileDivisor(S,[2,0,0])) == D.fire\_vertex(0).fire\_vertex(0)
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:fire-unstable-divisor}
\textbf{fire\_unstable()}
\begin{quote}

Fire all unstable vertices.

INPUT:

None

OUTPUT:

SandpileDivisor

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: D.fire\_unstable()
\PYGZob{}0: 3, 1: 1, 2: 2\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:fire-vertex-v-divisor}
\textbf{fire\_vertex(v)}
\begin{quote}

Fire the vertex \code{v}.

INPUT:

\code{v} - vertex

OUTPUT:

SandpileDivisor

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: D.fire\_vertex(1)
\PYGZob{}0: 2, 1: 0, 2: 4\PYGZcb{}
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:is-alive-cycle-false}
\textbf{is\_alive(cycle=False)}
\begin{quote}

Will the divisor stabilize under repeated firings of all unstable
vertices?  Optionally returns the resulting cycle.

INPUT:

\code{cycle} (optional) - boolean

OUTPUT:

boolean or optionally, a list of SandpileDivisors

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = complete\_sandpile(4)
sage: D = SandpileDivisor(S, \PYGZob{}0: 4, 1: 3, 2: 3, 3: 2\PYGZcb{})
sage: D.is\_alive()
True
sage: D.is\_alive(True)
[\PYGZob{}0: 4, 1: 3, 2: 3, 3: 2\PYGZcb{}, \PYGZob{}0: 3, 1: 2, 2: 2, 3: 5\PYGZcb{}, \PYGZob{}0: 1, 1: 4, 2: 4, 3: 3\PYGZcb{}]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:is-symmetric-orbits-divisor}
\textbf{is\_symmetric(orbits)}
\begin{quote}

This function checks if the values of the divisor are constant over
the vertices in each sublist of \code{orbits}.

INPUT:
\begin{itemize}
\item {} 
\code{orbits} - list of lists of vertices

\end{itemize}

OUTPUT:

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('kite')
sage: S.dict()
\PYGZob{}0: \PYGZob{}\PYGZcb{},
 1: \PYGZob{}0: 1, 2: 1, 3: 1\PYGZcb{},
 2: \PYGZob{}1: 1, 3: 1, 4: 1\PYGZcb{},
 3: \PYGZob{}1: 1, 2: 1, 4: 1\PYGZcb{},
 4: \PYGZob{}2: 1, 3: 1\PYGZcb{}\PYGZcb{}
sage: D = SandpileDivisor(S, [2,1, 2, 2, 3])
sage: D.is\_symmetric([[0,2,3]])
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:linear-system}
\textbf{linear\_system()}
\begin{quote}

The complete linear system of a divisor.

INPUT: None

OUTPUT:

dict - \code{\{num\_homog: int, homog:list, num\_inhomog:int,
inhomog:list\}}

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: D = SandpileDivisor(S, [0,0,0,0,0,2])
sage: D.linear\_system() \# optional - 4ti2
\PYGZob{}'inhomog': [[0, 0, -1, -1, 0, -2], [0, 0, 0, 0, 0, -1], [0, 0, 0, 0, 0, 0]],
'num\_inhomog': 3, 'num\_homog': 2, 'homog': [[1, 0, 0, 0, 0, 0],
[-1, 0, 0, 0, 0, 0]]\PYGZcb{}
\end{Verbatim}

NOTES:

If L is the Laplacian, an arbitrary v such that v * L\textgreater{}= -D has
the form v = w + t where w is in \code{inhomg} and t is in the integer
span of \code{homog} in the output of \code{linear\_system(D)}.

WARNING:

This method requires 4ti2.
\end{quote}

---
\phantomsection\label{sandpile:r-of-d-verbose-false}
\textbf{r\_of\_D(verbose=False)}
\begin{quote}

Returns \code{r(D)} and, if \code{verbose} is \code{True}, an effective
divisor \code{F} such that \code{\textbar{}D - F\textbar{}} is empty.

INPUT:

\code{verbose} (optional) - boolean

OUTPUT:

integer \code{r(D)} or tuple (integer \code{r(D)}, divisor \code{F})

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: D = SandpileDivisor(S, [0,0,0,0,0,4]) \# optional - 4ti2
sage: E = D.r\_of\_D(True) \# optional - 4ti2
sage: E \# optional - 4ti2
(1, \PYGZob{}0: 0, 1: 1, 2: 0, 3: 1, 4: 0, 5: 0\PYGZcb{})
sage: F = E[1] \# optional - 4ti2
sage: (D - F).values() \# optional - 4ti2
[0, -1, 0, -1, 0, 4]
sage: (D - F).effective\_div() \# optional - 4ti2
[]
sage: SandpileDivisor(S, [0,0,0,0,0,-4]).r\_of\_D(True) \# optional - 4ti2
(-1, \PYGZob{}0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: -4\PYGZcb{})
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:sandpile-divisor}
\textbf{sandpile()}
\begin{quote}

The divisor's underlying sandpile.

INPUT:

None

OUTPUT:

Sandpile

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('genus2')
sage: D = SandpileDivisor(S,[1,-2,0,3])
sage: D.sandpile()
Digraph on 4 vertices
sage: D.sandpile() == S
True
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:show-heights-true-directed-none-kwds-divisor}
\textbf{show(heights=True,directed=None,kwds)}
\begin{quote}

Show the divisor.

INPUT:
\begin{itemize}
\item {} 
\code{heights} - whether to label each vertex with the amount of
sand

\item {} 
\code{kwds} - arguments passed to the show method for Graph

\item {} 
\code{directed} - whether to draw directed edges

\end{itemize}

OUTPUT:

None

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('genus2')
sage: D = SandpileDivisor(S,[1,-2,0,2])
sage: D.show(graph\_border=True,vertex\_size=700,directed=False)
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:support-divisor}
\textbf{support()}
\begin{quote}

List of keys of the nonzero values of the divisor.

INPUT:

None

OUTPUT:

list - support of the divisor

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = sandlib('generic')
sage: c = S.identity()
sage: c.values()
[2, 2, 1, 1, 0]
sage: c.support()
[1, 2, 3, 4]
sage: S.vertices()
[0, 1, 2, 3, 4, 5]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:unstable-divisor}
\textbf{unstable()}
\begin{quote}

List of the unstable vertices.

INPUT:

None

OUTPUT:

list of vertices

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(3), 0)
sage: D = SandpileDivisor(S, [1,2,3])
sage: D.unstable()
[1, 2]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:values-divisor}
\textbf{values()}
\begin{quote}

The values of the divisor as a list, sorted in the order of the
vertices.

INPUT:

None

OUTPUT:

list of integers

boolean

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(\PYGZob{}'a':[1,'b'], 'b':[1,'a'], 1:['a']\PYGZcb{},'a')
sage: D = SandpileDivisor(S, \PYGZob{}'a':0, 'b':1, 1:2\PYGZcb{})
sage: D
\PYGZob{}'a': 0, 1: 2, 'b': 1\PYGZcb{}
sage: D.values()
[2, 0, 1]
sage: S.vertices()
[1, 'a', 'b']
\end{Verbatim}
\end{quote}


\subsection{Other}
\label{sandpile:other}\begin{itemize}
\item {} 
{\hyperref[sandpile:admissible-partitions-s-k]{\emph{admissible\_partitions(S, k)}}} ---
Partitions of the vertices into \code{k} parts, each of which is connected.

\item {} 
{\hyperref[sandpile:aztec-sandpile-n]{\emph{aztec\_sandpile(n)}}} --- The aztec diamond graph.

\item {} 
{\hyperref[sandpile:complete-sandpile-n]{\emph{complete\_sandpile(n)}}} --- Sandpile on the complete graph.

\item {} 
{\hyperref[sandpile:firing-graph-s-eff]{\emph{firing\_graph(S, eff)}}} --- The
firing graph.

\item {} 
{\hyperref[sandpile:firing-vector-s-d-e]{\emph{firing\_vector(S,D,E)}}} --- The firing vector
taking divisor \code{D} to divisor \code{E}.

\item {} 
{\hyperref[sandpile:glue-graphs-g-h-glue-g-glue-h]{\emph{glue\_graphs(g,h,glue\_g,glue\_h)}}} --- Glue two sandpiles
together.

\item {} 
{\hyperref[sandpile:grid-sandpile-m-n]{\emph{grid\_sandpile(m,n)}}} --- The $m\times n$ grid sandpile.

\item {} 
{\hyperref[sandpile:min-cycles-g-v]{\emph{min\_cycles(G,v)}}} --- The minimal length cycles in
the digraph \code{G} starting at vertex \code{v}.

\item {} 
{\hyperref[sandpile:parallel-firing-graph-s-eff]{\emph{parallel\_firing\_graph(S,eff)}}} --- The
parallel-firing graph.

\item {} 
{\hyperref[sandpile:partition-sandpile-s-p]{\emph{partition\_sandpile(S,p)}}} --- Sandpile formed
with vertices consisting of parts of an admissible partition.

\item {} 
{\hyperref[sandpile:random-digraph-num-verts-p-1-2-directed-true-weight-max-1]{\emph{random\_digraph(num\_verts,p=1/2,directed=True,weight\_max=1)}}} --- A
random directed graph.

\item {} 
{\hyperref[sandpile:random-dag-num-verts-p-1-2-weight-max-1]{\emph{random\_DAG(num\_verts,p=1/2,weight\_max=1)}}} --- A random directed acyclic graph.

\item {} 
{\hyperref[sandpile:random-tree-n-d]{\emph{random\_tree(n,d)}}} --- Random tree sandpile.

\item {} 
{\hyperref[sandpile:sandlib-selector-none]{\emph{sandlib(selector=None)}}} --- A collection of sandpiles.

\item {} 
{\hyperref[sandpile:triangle-sandpile-n]{\emph{triangle\_sandpile(n)}}} --- The triangle sandpile.

\item {} 
{\hyperref[sandpile:wilmes-algorithm-m]{\emph{wilmes\_algorithm(M)}}} --- Find matrix with the
same integer row span as \code{M} that is the reduced Laplacian of a digraph.

\end{itemize}


\bigskip\hrule{}\bigskip


\textbf{Complete descriptions of methods.}
\phantomsection\label{sandpile:admissible-partitions-s-k}
\textbf{admissible\_partitions(S, k)}
\begin{quote}

The partitions of the vertices of \code{S} into \code{k} parts,
each of which is connected.

INPUT:

\code{S} - Sandpile
\code{k} - integer

OUTPUT:

list of partitions

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(4), 0)
sage: P = [admissible\_partitions(S, i) for i in [2,3,4]]
sage: P
[[\PYGZob{}\PYGZob{}1, 2, 3\PYGZcb{}, \PYGZob{}0\PYGZcb{}\PYGZcb{},
  \PYGZob{}\PYGZob{}0, 2, 3\PYGZcb{}, \PYGZob{}1\PYGZcb{}\PYGZcb{},
  \PYGZob{}\PYGZob{}2\PYGZcb{}, \PYGZob{}0, 1, 3\PYGZcb{}\PYGZcb{},
  \PYGZob{}\PYGZob{}0, 1, 2\PYGZcb{}, \PYGZob{}3\PYGZcb{}\PYGZcb{},
  \PYGZob{}\PYGZob{}2, 3\PYGZcb{}, \PYGZob{}0, 1\PYGZcb{}\PYGZcb{},
  \PYGZob{}\PYGZob{}1, 2\PYGZcb{}, \PYGZob{}0, 3\PYGZcb{}\PYGZcb{}],
 [\PYGZob{}\PYGZob{}2, 3\PYGZcb{}, \PYGZob{}0\PYGZcb{}, \PYGZob{}1\PYGZcb{}\PYGZcb{},
  \PYGZob{}\PYGZob{}1, 2\PYGZcb{}, \PYGZob{}3\PYGZcb{}, \PYGZob{}0\PYGZcb{}\PYGZcb{},
  \PYGZob{}\PYGZob{}2\PYGZcb{}, \PYGZob{}0, 3\PYGZcb{}, \PYGZob{}1\PYGZcb{}\PYGZcb{},
  \PYGZob{}\PYGZob{}2\PYGZcb{}, \PYGZob{}3\PYGZcb{}, \PYGZob{}0, 1\PYGZcb{}\PYGZcb{}],
 [\PYGZob{}\PYGZob{}2\PYGZcb{}, \PYGZob{}3\PYGZcb{}, \PYGZob{}0\PYGZcb{}, \PYGZob{}1\PYGZcb{}\PYGZcb{}]]
sage: for p in P: \# long time
...    sum([partition\_sandpile(S, i).betti(verbose=false)[-1] for i in p]) \# long time
6
8
3
sage: S.betti()  \# long time
           0     1     2     3
------------------------------
    0:     1     -     -     -
    1:     -     6     8     3
------------------------------
total:     1     6     8     3
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:aztec-sandpile-n}
\textbf{aztec(n)}
\begin{quote}

The aztec diamond graph.

INPUT:

n - integer

OUTPUT:

dictionary for the aztec diamond graph

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: aztec\_sandpile(2)
\PYGZob{}'sink': \PYGZob{}(3/2, 1/2): 2, (-1/2, -3/2): 2, (-3/2, 1/2): 2, (1/2, 3/2): 2,
(1/2, -3/2): 2, (-3/2, -1/2): 2, (-1/2, 3/2): 2, (3/2, -1/2): 2\PYGZcb{},
(1/2, 3/2): \PYGZob{}(-1/2, 3/2): 1, (1/2, 1/2): 1, 'sink': 2\PYGZcb{}, (1/2, 1/2):
\PYGZob{}(1/2, -1/2): 1, (3/2, 1/2): 1, (1/2, 3/2): 1, (-1/2, 1/2): 1\PYGZcb{},
(-3/2, 1/2): \PYGZob{}(-3/2, -1/2): 1, 'sink': 2, (-1/2, 1/2): 1\PYGZcb{}, (-1/2, -1/2):
\PYGZob{}(-3/2, -1/2): 1, (1/2, -1/2): 1, (-1/2, -3/2): 1, (-1/2, 1/2): 1\PYGZcb{},
(-1/2, 1/2): \PYGZob{}(-3/2, 1/2): 1, (-1/2, -1/2): 1, (-1/2, 3/2): 1,
(1/2, 1/2): 1\PYGZcb{}, (-3/2, -1/2): \PYGZob{}(-3/2, 1/2): 1, (-1/2, -1/2): 1, 'sink': 2\PYGZcb{},
(3/2, 1/2): \PYGZob{}(1/2, 1/2): 1, (3/2, -1/2): 1, 'sink': 2\PYGZcb{}, (-1/2, 3/2):
\PYGZob{}(1/2, 3/2): 1, 'sink': 2, (-1/2, 1/2): 1\PYGZcb{}, (1/2, -3/2): \PYGZob{}(1/2, -1/2): 1,
(-1/2, -3/2): 1, 'sink': 2\PYGZcb{}, (3/2, -1/2): \PYGZob{}(3/2, 1/2): 1, (1/2, -1/2): 1,
'sink': 2\PYGZcb{}, (1/2, -1/2): \PYGZob{}(1/2, -3/2): 1, (-1/2, -1/2): 1, (1/2, 1/2): 1,
(3/2, -1/2): 1\PYGZcb{}, (-1/2, -3/2): \PYGZob{}(-1/2, -1/2): 1, 'sink': 2, (1/2, -3/2): 1\PYGZcb{}\PYGZcb{}
sage: Sandpile(aztec\_sandpile(2),'sink').group\_order()
4542720
\end{Verbatim}

NOTES:

This is the aztec diamond graph with a sink vertex added.  Boundary
vertices have edges to the sink so that each vertex has degree 4.
\end{quote}

---
\phantomsection\label{sandpile:complete-sandpile-n}
\textbf{complete\_sandpile(n)}
\begin{quote}

The sandpile on the complete graph with n vertices.

INPUT:

\code{n} - positive integer

OUTPUT:

Sandpile

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: K = complete\_sandpile(5)
sage: K.betti(verbose=False) \# long time
[1, 15, 50, 60, 24]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:firing-graph-s-eff}
\textbf{firing\_graph(S, eff)}
\begin{quote}

Creates a digraph with divisors as vertices and edges between two
divisors \code{D} and \code{E} if firing a single vertex in \code{D} gives
\code{E}.

INPUT:

\code{S} - sandpile
\code{eff} - list of divisors

OUTPUT:

DiGraph

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(6),0)
sage: D = SandpileDivisor(S, [1,1,1,1,2,0])
sage: eff = D.effective\_div() \# optional - 4ti2
sage: firing\_graph(S,eff).show3d(edge\_size=.005,vertex\_size=0.01) \# optional 4ti2
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:firing-vector-s-d-e}
\textbf{firing\_vector(S,D,E)}
\begin{quote}

If \code{D} and \code{E} are linearly equivalent divisors, find the firing vector
taking \code{D} to \code{E}.

INPUT:
\begin{itemize}
\item {} 
\code{S} -Sandpile

\item {} 
\code{D}, \code{E} - tuples (representing linearly equivalent divisors)

\end{itemize}

OUTPUT:

tuple (representing a firing vector from \code{D} to \code{E})

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = complete\_sandpile(4)
sage: D = SandpileDivisor(S, \PYGZob{}0: 0, 1: 0, 2: 8, 3: 0\PYGZcb{})
sage: E = SandpileDivisor(S, \PYGZob{}0: 2, 1: 2, 2: 2, 3: 2\PYGZcb{})
sage: v = firing\_vector(S, D, E)
sage: v
(0, 0, 2, 0)
sage: vector(D.values()) - S.laplacian()*vector(v) == vector(E.values())
True
\end{Verbatim}

The divisors must be linearly equivalent:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = complete\_sandpile(4)
sage: D = SandpileDivisor(S, \PYGZob{}0: 0, 1: 0, 2: 8, 3: 0\PYGZcb{})
sage: firing\_vector(S, D, S.zero\_div())
Error. Are the divisors linearly equivalent?
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:glue-graphs-g-h-glue-g-glue-h}
\textbf{glue\_graphs(g,h,glue\_g,glue\_h)}
\begin{quote}

Glue two graphs together.

INPUT:
\begin{itemize}
\item {} 
\code{g}, \code{h} - dictionaries for directed multigraphs

\item {} 
\code{glue\_h}, \code{glue\_g} - dictionaries for a vertex

\end{itemize}

OUTPUT:

dictionary for a directed multigraph

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: x = \PYGZob{}0: \PYGZob{}\PYGZcb{}, 1: \PYGZob{}0: 1\PYGZcb{}, 2: \PYGZob{}0: 1, 1: 1\PYGZcb{}, 3: \PYGZob{}0: 1, 1: 1, 2: 1\PYGZcb{}\PYGZcb{}
sage: y = \PYGZob{}0: \PYGZob{}\PYGZcb{}, 1: \PYGZob{}0: 2\PYGZcb{}, 2: \PYGZob{}1: 2\PYGZcb{}, 3: \PYGZob{}0: 1, 2: 1\PYGZcb{}\PYGZcb{}
sage: glue\_x = \PYGZob{}1: 1, 3: 2\PYGZcb{}
sage: glue\_y = \PYGZob{}0: 1, 1: 2, 3: 1\PYGZcb{}
sage: z = glue\_graphs(x,y,glue\_x,glue\_y)
sage: z
\PYGZob{}0: \PYGZob{}\PYGZcb{}, 'y2': \PYGZob{}'y1': 2\PYGZcb{}, 'y1': \PYGZob{}0: 2\PYGZcb{}, 'x2': \PYGZob{}'x0': 1, 'x1': 1\PYGZcb{},
'x3': \PYGZob{}'x2': 1, 'x0': 1, 'x1': 1\PYGZcb{}, 'y3': \PYGZob{}0: 1, 'y2': 1\PYGZcb{},
'x1': \PYGZob{}'x0': 1\PYGZcb{}, 'x0': \PYGZob{}0: 1, 'x3': 2, 'y3': 1, 'x1': 1, 'y1': 2\PYGZcb{}\PYGZcb{}
sage: S = Sandpile(z,0)
sage: S.h\_vector()
[1, 6, 17, 31, 41, 41, 31, 17, 6, 1]
sage: S.resolution() \# long time
'R\textasciicircum{}1 \textless{}-- R\textasciicircum{}7 \textless{}-- R\textasciicircum{}21 \textless{}-- R\textasciicircum{}35 \textless{}-- R\textasciicircum{}35 \textless{}-- R\textasciicircum{}21 \textless{}-- R\textasciicircum{}7 \textless{}-- R\textasciicircum{}1'
\end{Verbatim}

NOTES:

This method makes a dictionary for a graph by combining those for \code{g} and
\code{h}.  The sink of \code{g} is replaced by a vertex that is connected to the
vertices of \code{g} as specified by \code{glue\_g} the vertices of \code{h} as
specified in \code{glue\_h}.  The sink of the glued graph is $0$.

Both \code{glue\_g} and \code{glue\_h} are dictionaries with entries of the form
\code{v:w} where \code{v} is the vertex to be connected to and \code{w} is the weight
of the connecting edge.
\end{quote}

---
\phantomsection\label{sandpile:grid-sandpile-m-n}
\textbf{grid\_sandpile(m,n)}
\begin{quote}

The mxn grid sandpile.  Each nonsink vertex has degree 4.

INPUT:
\code{m}, \code{n} - positive integers

OUTPUT:
dictionary for a sandpile with sink named \code{sink}.

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: grid\_sandpile(3,4).dict()
\PYGZob{}(1, 2): \PYGZob{}(1, 1): 1, (1, 3): 1, 'sink': 1, (2, 2): 1\PYGZcb{},
(3, 2): \PYGZob{}(3, 3): 1, (3, 1): 1, 'sink': 1, (2, 2): 1\PYGZcb{},
(1, 3): \PYGZob{}(1, 2): 1, (2, 3): 1, 'sink': 1, (1, 4): 1\PYGZcb{},
(3, 3): \PYGZob{}(2, 3): 1, (3, 2): 1, (3, 4): 1, 'sink': 1\PYGZcb{},
(3, 1): \PYGZob{}(3, 2): 1, 'sink': 2, (2, 1): 1\PYGZcb{},
(1, 4): \PYGZob{}(1, 3): 1, (2, 4): 1, 'sink': 2\PYGZcb{},
(2, 4): \PYGZob{}(2, 3): 1, (3, 4): 1, 'sink': 1, (1, 4): 1\PYGZcb{},
(2, 3): \PYGZob{}(3, 3): 1, (1, 3): 1, (2, 4): 1, (2, 2): 1\PYGZcb{},
(2, 1): \PYGZob{}(1, 1): 1, (3, 1): 1, 'sink': 1, (2, 2): 1\PYGZcb{},
(2, 2): \PYGZob{}(1, 2): 1, (3, 2): 1, (2, 3): 1, (2, 1): 1\PYGZcb{},
(3, 4): \PYGZob{}(2, 4): 1, (3, 3): 1, 'sink': 2\PYGZcb{},
(1, 1): \PYGZob{}(1, 2): 1, 'sink': 2, (2, 1): 1\PYGZcb{},
'sink': \PYGZob{}\PYGZcb{}\PYGZcb{}
sage: grid\_sandpile(3,4).group\_order()
4140081
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:min-cycles-g-v}
\textbf{min\_cycles(G,v)}
\begin{quote}

Minimal length cycles in the digraph \code{G} starting at vertex \code{v}.

INPUT:

\code{G} - DiGraph
\code{v} - vertex of \code{G}

OUTPUT:

list of lists of vertices

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: T = sandlib('gor')
sage: [min\_cycles(T, i) for i in T.vertices()]
[[], [[1, 3]], [[2, 3, 1], [2, 3]], [[3, 1], [3, 2]]]
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:parallel-firing-graph-s-eff}
\textbf{parallel\_firing\_graph(S,eff)}
\begin{quote}

Creates a digraph with divisors as vertices and edges between two
divisors \code{D} and \code{E} if firing all unstable vertices in \code{D} gives
\code{E}.

INPUT:

\code{S} - Sandpile
\code{eff} - list of divisors

OUTPUT:

DiGraph

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(6),0)
sage: D = SandpileDivisor(S, [1,1,1,1,2,0])
sage: eff = D.effective\_div() \# optional - 4ti2
sage: parallel\_firing\_graph(S,eff).show3d(edge\_size=.005,vertex\_size=0.01) \# optional - 4ti2
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:partition-sandpile-s-p}
\textbf{partition\_sandpile(S,p)}
\begin{quote}

Each set of vertices in \code{p} is regarded as a single vertex, with and edge
between \code{A} and \code{B} if some element of \code{A} is connected by an edge
to  some element of \code{B} in \code{S}.

INPUT:

\code{S} - Sandpile
\code{p} - partition of the vertices of \code{S}

OUTPUT:

Sandpile

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = Sandpile(graphs.CycleGraph(4), 0)
sage: P = [admissible\_partitions(S, i) for i in [2,3,4]]
sage: for p in P:  \#long time
...       sum([partition\_sandpile(S, i).betti(verbose=false)[-1] for i in p]) \# long time
6
8
3
sage: S.betti() \# long time
           0     1     2     3
------------------------------
    0:     1     -     -     -
    1:     -     6     8     3
------------------------------
total:     1     6     8     3
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:random-digraph-num-verts-p-1-2-directed-true-weight-max-1}
\textbf{random\_digraph(num\_verts,p=1/2,directed=True,weight\_max=1)}
\begin{quote}

A random weighted digraph with a directed spanning tree rooted at $0$.  If
\code{directed = False}, the only difference is that if $(i,j,w)$ is an edge with
tail $i$, head $j$, and weight $w$, then $(j,i,w)$ appears also.  The result
is returned as a Sage digraph.

INPUT:
\begin{itemize}
\item {} 
\code{num\_verts} - number of vertices

\item {} 
\code{p} - probability edges occur

\item {} 
\code{directed} - True if directed

\item {} 
\code{weight\_max} - integer maximum for random weights

\end{itemize}

OUTPUT:

random graph

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: g = random\_digraph(6,0.2,True,3)
sage: S = Sandpile(g,0)
sage: S.show(edge\_labels=True)
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:random-dag-num-verts-p-1-2-weight-max-1}
\textbf{random\_DAG(num\_verts,p=1/2,weight\_max=1)}
\begin{quote}

Returns a random directed acyclic graph with \code{num\_verts} vertices.
The method starts with the sink vertex and adds vertices one at a time.
Each vertex is connected only to only previously defined vertices, and the
probability of each possible connection is given by the argument \code{p}.
The weight of an edge is a random integer between \code{1} and
\code{weight\_max}.

INPUT:
\begin{itemize}
\item {} 
\code{num\_verts} - positive integer

\item {} 
\code{p} - number between $0$ and $1$

\item {} 
\code{weight\_max} -- integer greater than $0$

\end{itemize}

OUTPUT:

directed acyclic graph with sink $0$

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: S = random\_DAG(5, 0.3)
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:random-tree-n-d}
\textbf{random\_tree(n,d)}
\begin{quote}

Returns a random undirected tree with \code{n} nodes, no node having
degree higher than \code{d}.

INPUT:

\code{n}, \code{d} - integers

OUTPUT:

Graph

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: T = random\_tree(15,3)
sage: T.show()
sage: S = Sandpile(T,0)
sage: U = S.reorder\_vertices()
sage: Graph(U).show()
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:sandlib-selector-none}
\textbf{sandlib(selector=None)}
\begin{quote}

The sandpile identified by \code{selector}.  If no argument is
given, a description of the sandpiles in the sandlib is printed.

INPUT:

\code{selector} - identifier or None

OUTPUT:

sandpile or description

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: sandlib()
  Sandpiles in the sandlib:
     kite : generic undirected graphs with 5 vertices
     generic : generic digraph with 6 vertices
     genus2 : Undirected graph of genus 2
     ci1 : complete intersection, non-DAG but  equivalent to a DAG
     riemann-roch1 : directed graph with postulation 9 and 3 maximal weight superstables
     riemann-roch2 : directed graph with a superstable not majorized by a maximal superstable
     gor : Gorenstein but not a complete intersection
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:triangle-sandpile-n}
\textbf{triangle(n)}
\begin{quote}

A triangular sandpile.  Each nonsink vertex has out-degree six.  The
vertices on the boundary of the triangle are connected to the sink.

INPUT:

\code{n} - int

OUTPUT:

Sandpile

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: T = triangle\_sandpile(5)
sage: T.group\_order()
135418115000
\end{Verbatim}
\end{quote}

---
\phantomsection\label{sandpile:wilmes-algorithm-m}
\textbf{wilmes\_algorithm(M)}
\begin{quote}

Computes an integer matrix \code{L} with the same integer row span as \code{M}
and such that \code{L} is the reduced laplacian of a directed multigraph.

INPUT:

\code{M} - square integer matrix of full rank

OUTPUT:

\code{L} - integer matrix

EXAMPLES:

\begin{Verbatim}[commandchars=\\\{\}]
sage: P = matrix([[2,3,-7,-3],[5,2,-5,5],[8,2,5,4],[-5,-9,6,6]])
sage: wilmes\_algorithm(P)
[ 1642   -13 -1627    -1]
[   -1  1980 -1582  -397]
[    0    -1  1650 -1649]
[    0     0 -1658  1658]
\end{Verbatim}

NOTES:

The algorithm is due to John Wilmes.
\end{quote}


\section{Help}
\label{sandpile:help}
Documentation for each method is available through the Sage online help system:

\begin{Verbatim}[commandchars=\\\{\}]
sage: SandpileConfig.fire\_vertex?
Base Class:     \textless{}type 'instancemethod'\textgreater{}
String Form:    \textless{}unbound method SandpileConfig.fire\_vertex\textgreater{}
Namespace:      Interactive
File:           /usr/local/sage-4.7/local/lib/python2.6/site-packages/sage/sandpiles/sandpile.py
Definition:     SandpileConfig.fire\_vertex(self, v)
Docstring:
       Fire the vertex {}`{}`v{}`{}`.

       INPUT:

       {}`{}`v{}`{}` - vertex

       OUTPUT:

       SandpileConfig

       EXAMPLES:

          sage: S = Sandpile(graphs.CycleGraph(3), 0)
          sage: c = SandpileConfig(S, [1,2])
          sage: c.fire\_vertex(2)
          \PYGZob{}1: 2, 2: 0\PYGZcb{}
\end{Verbatim}

\begin{notice}{note}{Note:}
An alternative to \code{SandpileConfig.fire\_vertex?} in the preceding code example
would be \code{c.fire\_vertex?}, if \code{c} is any SandpileConfig.
\end{notice}

General Sage documentation can be found at \href{http://sagemath.org/doc/}{http://sagemath.org/doc/}.


\chapter{Contact}
\label{sandpile:contact}
Please contact \href{mailto:davidp@reed.edu}{davidp@reed.edu} with questions, bug reports, and suggestions for
additional features and other improvements.

\begin{thebibliography}{BTW}
\bibitem[BN]{BN}{\phantomsection\label{sandpile:bn} 
Matthew Baker, Serguei Norine, \href{http://people.math.gatech.edu/~mbaker/papers.html}{Riemann-Roch and Abel-Jacobi Theory on a Finite Graph}, Advances in Mathematics 215 (2007), 766--788.
}
\bibitem[BTW]{BTW}{\phantomsection\label{sandpile:btw} 
Per Bak, Chao Tang and Kurt Wiesenfeld (1987). \emph{Self-organized criticality: an explanation of 1/ƒ noise}, Physical Review Letters 60: 381–384 \href{http://en.wikipedia.org/wiki/Bak-Tang-Wiesenfeld\_sandpile}{Wikipedia article}.
}
\bibitem[CRS]{CRS}{\phantomsection\label{sandpile:crs} 
Robert Cori, Dominique Rossin, and Bruno Salvy, \emph{Polynomial ideals for sandpiles and their Gröbner bases}, Theoretical Computer Science, 276 (2002) no. 1--2, 1--15.
}
\bibitem[H]{H}{\phantomsection\label{sandpile:h} 
Holroyd, Levine, Meszaros, Peres, Propp, Wilson, \href{http://front.math.ucdavis.edu/0801.3306}{Chip-Firing and Rotor-Routing on Directed Graphs}. The final version of this paper appears in \emph{In and out of Equilibrium II}, Eds. V. Sidoravicius, M. E. Vares, in the Series Progress in Probability, Birkhauser (2008).
}
\end{thebibliography}



\renewcommand{\indexname}{Index}
\printindex
\end{document}
