Software For Enumerative and Analytic Combinatorics
Software For Enumerative and Analytic Combinatorics
Andrew MacFie
Thursday 26
th
April, 2012
Honours project (MATH 4905) Advisors: Daniel Panario and Brett Stevens
Abstract
We survey some general-purpose symbolic software packages that implement algorithms from enumerative and analytic combinatorics. Software for the following areas is covered: basic combinatorial objects, symbolic combinatorics, Plya theory, combinatorial species, and asymptotics. We describe the capabilities that the packages oer as well as some of the algorithms used, and provide links to original documentation. Most of the packages are freely downloadable from the web. Keywords: software, package, symbolic computation, combinatorics, counting, enumeration.
Note: In this project, to refer to webpages we place URL links in footnotes, and for all other types of referent we use standard endnote references.
Contents
1 Introduction 2 Enumerative and analytic combinatorics
2.1 Counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 2.1.2 2.1.3 2.2
3 4
4 4 5 6 7
Exact vs. asymptotic counting . . . . . . . . . . . . . . . . . . . . . . Generating functions vs. their coecients . . . . . . . . . . . . . . . . Bijective combinatorics vs. manipulatorics . . . . . . . . . . . . . . .
Enumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7 9
9 9 9 10 10 11 13
Combinat (Maple)
Combinatorial Object Server . . . . . . . . . . . . . . . . . . . . . . . . . . . Combinatorica: basic combinatorial objects . . . . . . . . . . . . . . . . . . . Sage: basic combinatorial objects . . . . . . . . . . . . . . . . . . . . . . . .
5 Symbolic combinatorics
5.1 Mathematical background 5.1.1 5.1.2 5.1.3 5.2 5.3 5.4 Labeled classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . Unlabeled classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Multiple parameters
14
14 15 16 17 18 19 20
Combstruct
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6 Plya theory
6.1 6.2 6.3 6.4 6.5 6.6 Mathematical background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A note on Plya theory packages COCO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Combinatorica: Plya theory . . . . . . . . . . . . . . . . . . . . . . . . . . . GraphEnumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . PermGroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
22
22 26 26 26 28 29
7 Combinatorial species
7.1 7.2 7.3 Mathematical background 7.1.1 Weighted species . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Aldor-Combinat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sage: combinatorial species
30
30 33 35 36
8 Asymptotics
8.1 Mathematical background 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.3 8.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . Asymptotic scales and series . . . . . . . . . . . . . . . . . . . . . . . Singularity analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . Saddle-point asymptotics . . . . . . . . . . . . . . . . . . . . . . . . . Power series coecients and the radius of convergence . . . . . . . . .
38
38 38 39 39 40 40 41 42
43 44 47
47 47
Introduction
1
posted to his website in 1999, Doron Zeilberger challenged mathemati-
In an opinion article
cians to rethink the role of computers in mathematics. Everything that we can prove today will soon be provable, faster and better, by computers, he says, then gives the following advice: The real work of us mathematicians, from now until, roughly, fty years from now, when computers won't need us anymore, is to make the transition from human-centric math to machine-centric math as smooth and ecient as possible. . . . We could be much more useful than we are now, if, instead of proving yet another theorem, we would start teaching the computer everything we know, so that it would have a headstart. . . . Once you learned to PROGRAM (rather than just use) Maple (or, if you insist Mathematica, etc.), you should immediately get to the business of transcribing your math-knowledge into Maple. If futurist Ray Kurzweil's predictions for articial intelligence progress are to be believed, Zeilberger's suggestions will turn out to be sound. (However, utilitarians would urge us to consider the risks such technology would present.
3 4
those who use mathematics, given the rise of computers, can ask themselves if they are failing to capitalize on a productive division of labor between man and machine. It is no 67 longer necessary to spend three years of Sundays factoring the Mersenne number 2 1, like F. N. Cole did in the 1900s [18], and neither is it necessary to use error-prone pen and paper methods to perform an ever-growing set of mathematical procedures. To illustrate this statement, this project examines symbolic computation (a.k.a. computer algebra) software packages for enumerative and algebraic combinatorics. We start, in Section 2, with an overview of the elds of enumerative and analytic combinatorics. Then we go into more detail on the scope of the project in Section 3. In Sections 48 we cover packages relating to basic combinatorial objects, symbolic combinatorics, Plya theory, combinatorial species, and asymptotics. Finally, we oer concluding observations and remarks in Section 9.
1 2 3 4
Welcome to the elds of enumerative and analytic combinatorics, a.k.a. combinatorial and asymptotic enumeration! In order to completely cover what mathematicians think of when they think of these elds (and to avoid saying enumerative or combinatorial), we break up our discussion into two parts which we call
counting,
Counting, the oldest mathematical subject [16], is enumeration in the mathematical sense: the study of the cardinalities of nite sets. addition rule [1]: The most basic principle of counting is the
Proposition 1
(Addition rule)
Elements of the body of work on counting can be roughly categorized based on three criteria: whether they deal with exact or asymptotic results, whether they speak in terms of generating functions or their coecients, and whether they make use of bijections or manipulations.
2.1.1 Exact vs. asymptotic counting Notation 1. Boldface symbols refer to (possibly terminating) 1-based sequences, i.e. a = (a1 , a2 , . . . ).
(S, p, N ) comprising a countable set S of objects, a sequence p = (p1 , p2 , . . . ) of functions pi : S Z0 , and a set N of sequences n for which p1 (n) = {s S : p1 (s) = n1 , p2 (s) = n2 , . . . } S is nite. The problem is 1 to answer the question For n N , how many objects does the set p (n) contain? The
Generally, counting problems involve a triple denition of an
exact answer
Example 1. If Sn is a permutation, then let cj () be the number of cycles of with size j . The signature of is c() = (c1 (), c2 (), . . . ). Let S be the set of all permutations, and for s S , let p(s) be the signature of s. Let n 1 and let n = ([j = n])j0 . Then |p1 (n)| = (n1)!. The expression (n1)! immediately suggests a polynomial-time algorithm to compute |p1 (n)|.
5
http://planetmath.org/encyclopedia/Combinatorics.html
(|p (n)|)nN ,
satises [16].
Exact 1
answers
can
be
classied
by
ansatz,
meaning
the
form
of
the
sequence
reccurence relation it
Exact answers are not the end of the story, however, partly because of applications to the analysis of algorithms.
p = (p) and N = ((0), (1), (2), . . . ), an asymptotic 1 answer is a relation between f : n |p (n)| and simple functions, which holds as n . Often the simple functions come from the logarithmico-exponential class L of Hardy [17, 20], and the relation is f (n) g(n) as n , where g L. A more substantial relation
In the single-parameter case, i.e. is a full asymptotic series [10]:
Denition 1. Given a sequence of functions g with gk+1 (n) = o(gk (n)) as n for all k, and real numbers c1 , c2 , . . ., the statement
f (n) c g(n) = c1 g1 (n) + c2 g2 (n) + c3 g3 (n) +
is called an
asymptotic series
f (n) = O(g1 (n)) f (n) = c1 g1 (n) + O(g2 (n)) f (n) = c1 g1 (n) + c2 g2 (n) + O(g3 (n)) f (n) = c1 g1 (n) + c2 g2 (n) + c3 g3 (n) + O(g4 (n))
. . .
(as n .)
An asymptotic answer in the multiple-parameter case is more complicated; it generally involves (possibly just some moments of ) a continuous approximation to a discrete probability distribution as one parameter approaches innity, or an asymptotic relation which holds as one or more parameters approach innity at various rates.
function
of
(S, p, N ), let f : N Z0 be dened f (n) = |p1 (n)|. A (type u) generating S with z = (z1 , z2 , . . . ) marking p is the element of the ring Q[[z]] F (z) =
n 0
f (n)u(n)z n ,
where
exponential Example 2. Let F (z) be the ordinary generating function for words of length n on the alphabet [1..k], with zj marking the number of occurrences of j, 1 j k. We have
n 0,
and we call it an
n n z n = z1 1 z2 2 .
We call
F (z)
generating function i u(n) = 1 for all 1 generating function i u(n) = (n1 !) for all n 0. an
ordinary
F (z) = (z1 + z2 + + zk )n .
5
To dene convergence of sequences of generating functions, the norm on formal power series used in this project is dened for
f (z) = 0
as
f (z) = 2k ,
and with
where
k = max j Z0 : i [0..j], [z i ]f (z, z, . . . ) = 0 , F (z) instead of working directly , and extracting f (n) exactly from a suently simple
In addition, there are very widely applicable theorems for obtaining the asymptotics of
from
F (z)
Since generating functions are heavily used in both the exact and
asymptotic worlds, Wilf says in his book [38], To omit the analytical (i.e. asymptotic) parts of [counting with generating functions] . . . is like listening to a stereo broadcast of, say, Beethoven's Ninth Symphony, using only the left audio channel. The full beauty of the subject of generating functions emerges only from tuning in on both channels: the discrete and the continuous.
Example 3. A partition is called odd if all its parts are odd and it is called distinct if all its parts are distinct. Let f (n) and g(n) be the number of odd and distinct partitions of size n respectively, and let us dene the ordinary generating functions F (z) = n0 f (n)z n and G(z) = n0 g(n)z n . Since
G(z) = = = (1 + z n )
n0
1 z 2n 1 zn n0
n0 (1 n0 (1 z 2n )
1 = 1 z 2n+1 n0
z 2n ) 2n+1 ) n0 (1 z
= F (z),
we have [z n ]G(z) = [z n ]F (z), and thus f (n) = g(n), for all n 0. There is also a bijective proof of this fact, due to Glaisher [16], which we sketch. The function from distinct partitions
6
http://web.mit.edu/~qchu/Public/TopicsInGF.pdf
6
to odd partitions is dened as follows: Given a distinct partition, write each of its parts as 2r s, where s is odd, and replace each by 2r copies of s. This function is invertible, with inverse computable as follows: Take an odd part a which occurs m times, and write m in base 2, i.e. m = (sk s1 )2 , then replace the m copies of a by the k parts 2s1 a, . . . , 2sk a.
Arguably, manipulations are not combinatorics, hence the name manipulatorics. and other elds are blurry. Usually, bijections are used to give exact answers, but bijections can also be used in the context of asymptotics, as described in [4], for example. Standard textbooks for the eld of counting include [6, 9, 13, 34, 35]. Indeed, here the borders between algebra, analysis, combinatorics, the analysis of algorithms,
2.2
Enumeration
algorithms
that
generate
the
elements of nite sets. Various types of enumeration problems can be proposed for a given
(S, p, N );
the most common ones are ranking and unranking, random generation,
exhaustive listing, and iteration, which we dene in that order below. 1 1 We call an of p (n) S a bijection between p (n) and the integers 1 [1..|p (n)|]. A algorithm computes this bijection and an algorithm
ordering ranking
unranking
and an algorithm is required to take as input n N 1 and return a random variate drawn from p (n) according to the distribution. Unranking algorithms can be used for random generation, since an integer can be generated at random and then unranked to give a random object. An
p1 (n).
exhaustive listing
n N and returns a list of all elements in p1 (n) are well dened, a brute force
algorithm is trivial, and the problem lies in designing an ecient algorithm. 1 is the problem of, given n N and an object s p (n), generating the next 1 object s in a certain ordering of p (n). It is related to the problem of exhaustive listing
Iteration
since any iteration algorithm immediately leads to an exhaustive listing algorithm, and more 1 importantly, nding a particular ordering of p (n) often leads to the most ecient exhaustive listing algorithms. If one employs an iteration algorithm repeatedly, in an exhaustive listing algorithm, one aims for an ordering that takes constant amortized time for each iteration. A
Gray code
small way and thus is perfect for exhaustive listing through iteration.
In this project we focus on general-purpose software of wide interest to mathematicians, mathematics students, and perhaps those outside the eld. Many packages have been cre-
ated for solving particular counting and enumeration problems, such as Lara Pudwell's enumeration schemes packages , Donald Knuth's OBDD outside the scope of this project. There are some relatively general-purpose packages which did not make it into the project but should to be mentioned for completeness, though: The Mathematica package Omega implements MacMahon's Partition Analysis called LinDiophantus
of bipartite graphs, and many of Zeilberger's numerous Maple packages ; such packages are
10
11
12
and Mathematica
13
14
, and the
regexpcount package from the INRIA Algorithms Group translates in the other direction method, an innite-matrix generalization of the transfer matrix method.
15
and Zeilberger has written a number of packages related to the umbral transfer matrix
16
This project excludes some software related to the intersection of algebraic and enumerative combinatorics, and all software related to power series summation and manipulation. General-purpose software is currently skewed towards manipulations, away from bijections. Indeed, one would not expect complicated bijections such as the proofs of Theorem 1 in [30] (balanced trees and rooted triangulations) or Theorem 4.34 in [8] (indecomposable 1342-avoiding
n-permutations
and
(0, 1)-trees
on
bijective avor as possible. (Ultimately all computations may be considered manipulations, but we refer to a qualitative dierence in mathematical content.) Finally, we note that plenty of basic algorithms from combinatorics, as well as advanced algorithms from the symbolic computation literature, have not been implemented in a published package. (Actually, whether or not an algorithm has been implemented in a published package has a fuzzy value. For example, some have been implemented, published, but are now gone, while others have been published and are available, but are written in obscure languages that are unfamiliar or dicult to obtain compilers for. The sentence is true even in the loosest sense, however.)
7 8 9 10 11 12 13 14 15 16
http://faculty.valpo.edu/lpudwell/maple.html http://www-cs-staff.stanford.edu/~knuth/programs.html http://www.math.rutgers.edu/~zeilberg/programs.html http://www.risc.jku.at/research/combinat/software/Omega/index.php http://www.math.rutgers.edu/~zeilberg/tokhniot/LinDiophantus http://www-irma.u-strasbg.fr/~guoniu/software/omega.html http://www.risc.jku.at/research/combinat/software/GenOmega/index.php http://www.risc.jku.at/research/combinat/software/RLangGFun/index.php http://algo.inria.fr/libraries/libraries.html#regexpcount http://www.math.rutgers.edu/~zeilberg/programs.html
4
4.1
Algorithmically counting and enumerating the basic objects of combinatorics like graphs, trees, set partitions, integer partitions, integer compositions, subsets, and permutations is implemented in various packages and discussed in various books [23, 24, 26, 27, 37] (and many papers). As an example, [33] describes over 30 permutation generation algorithms published as of 1977. A complete comparison of the enumeration algorithms implemented in the packages in this project could be its own project. For the packages mentioned in this project that For more However, in the rest of this subsection we enumerate basic objects, we do not give full details on the algorithms used. information, see the packages' documentation.
provide some examples of two general concepts, rst mentioned in Section 2.2, which guide the discovery of enumeration algorithms: orderings and Gray codes.
4.1.1 Orderings
Many combinatorial objects can be ordered lexicographically.
order, applies when the objects can be represented as words over an ordered alphabet.
w = w1 w2 wn and v = v1 v2 vn are words then, in lexicographic order, then w < v i w1 < v1 or there is some k [1..n 1] such that wj = vj for 1 j k and wk+1 < vk+1 .
Permutations are a clear example of a case where this order applies, and iterating through permutations in lexicographic order is an easy exercise, see [11] for a solution.
Co-lexicographic order,
Another order,
a.k.a.
and
are words,
w w
reverses
rev(w) rev(w )
rev
cool-lex order,
copies of
1,
k -subsets
010
or
011,
such prex exists. Then cyclically shift it one position to the right. Since the shifted portion of the string consists of at most four contiguous runs of
0's
and
1's,
word can be generated by transposing only one or two pairs of bits. Thus cool-lex order for
k -subsets
is a Gray code.
standard
Say we want
Gn of subsets of a size-n set, and suppose we already have a Gray Gn1 of subsets of the last n 1 elements of the set. Concatenate Gn1 with a reversed copy of Gn1 with the rst element of the set added to each subset. Then all subsets dier
17
http://planetmath.org/encyclopedia/DictionaryOrder.html
9
by one from their neighbors, including the center, where the subsets are identical except for the rst element.
4.2
Combinat (Maple)
httpXGGwwwFmplesoftFomGsupportGhelpGwpleGviewFspxcpthaomint
The combinat package, which is distributed with Maple, has routines for counting, listing, randomly generating, and ranking and unranking basic combinatorial objects such as permutations, compositions.
18
k -subsets,
Like Combinatorica and unlike Sage and the Combinatorial Object Server,
combinat does not oer a wide range of restrictions that can be placed on the objects. As mentioned in Section 5.2, most of the functionality of the combinat package is also covered by Combstruct. Most types of objects can only be enumerated in a single ordering, but unrestricted subsets (in binary word form) can be listed in Gray code order with the
gryode
function.
4.3
httpXGGtheoryFsFuviFGosFhtml
The Combinatorial Object Server (COS) is a website that runs on the University of Victoria's domain. It has a web interface for easily specifying a set of basic combinatorial objects and viewing an exhaustive listing of all objects in the set (see Figure 1 on page 12). Objects available include permutations, derangements, involutions, subsets, set partitions, trees, necklaces, and unlabeled graphs. On each type of object, there is a set of restrictions that can be placed. Integer partitions, for example, can be restricted by largest part, and whether the parts must be odd, distinct, or odd and distinct.
k -subsets,
unrestricted
18
http://www.maplesoft.com/support/help/Maple/view.aspx?path=combinat
10
There is also a wide variety of output formats for the objects. Permutations, for example, can be printed in one line notation, cycle notation, permutation matrix form, standard Young tableau form and more. The order of output can sometimes be specied, too. Combinations, for example, can be shown in Gray code, lexicographic, co-lexicographic, cool-lex, transposition, or adjacent transposition orders.
4.4
httpXGGwwwFsFuiowFeduG~srirmGgomintoriGxewgomintoriFm
httpXGGwwwFsFsunysFeduG~skienGomintoriG
Combinatorica is a Mathematica package for discrete mathematics. In development since 1990, it includes over 450 functions in the areas of Plya theory, permutations and algebraic combinatorics, basic combinatorial objects, graph algorithms, and graph plotting. A book was written by the package authors [27], which is the denitive source of information on Combinatorica. The Combinatorica package has been included with releases of Mathematica since Mathematica version 4.2, although some of Combinatorica's functionality has recently been redone and built into the Mathematica kernel in Mathematica 8. For information on Mathematica as a programming language, see the Appendix. Combinatorica has support for counting and enumeration with permutations, and graphs.
k -subsets,
unrestricted subsets, integer partitions, integer compositions, set partitions, Young tableaus For each type of object, Combinatorica generally oers rules for counting, iteration and listing in one or two orderings, and random generation. Combinatorica does not provide as many ways to specify restrictions on the objects as COS or Sage.
Example 5. The function qrygodeusets exhaustively lists all subsets of a set in standard reected Gray code order:
snIXa qrygodeusets{ID PD QD R} yutIXa {{}D{R}D{QDR}D{Q}D{PDQ}D{PDQDR}D{PDR}D{P}D{IDP}D{IDPDR}D {IDPDQDR}D{IDPDQ}D{IDQ}D{IDQDR}D{IDR}D{I}}
One may wonder if such a Gray code is unique, and one can nd this out by rst noticing that Gray codes for the subsets of a size-n set are in bijection with Hamiltonian paths in the n-dimensional hypercube. Combinatorica includes a database of common graphs, including ryperuen, and also has the rmiltoningyle rule which replaces rmiltoningylegrphD ell with a list of all Hamiltonian cycles in grph. So to nd out if the Gray code order above is unique, one can nd the length of the list of Hamiltonian paths in the 4-dimensional hypercube:
11
12
It is denitely not! The number of Hamiltonian cycles in an n-dimensional hypercube is not known, even asymptotically [37].
4.5 Sage: basic combinatorial objects
19 20
21
inumertedets22 .
integer partitions, permutations, ordered and unordered set partitions, words and subwords) all belong to the category
inumertedets
rdinlity@A list@A
nth
object in an ordering,
e,
in an ordering,
19 20 21 22
13
7.
Of course, each class of combinatorial object built in to the system may also implement many more methods. Many classes allow restrictions to be specied, but only the default ordering is available.
Example 6. The rtitions@A static method is called to construct an object representing a set of integer partitions specied by its arguments.23 For example, rtitions@RA returns all integer partitions of 4, while rtitions@RD mxprtaPA returns all partitions of 4 with maximum part size 2:
rtitions@RD mxprtaPAFrdinlity@A Q sgeX rtitions@RD mxprtaPAFlist@A PD PD PD ID ID ID ID ID I sgeX rtitions@RD mxprtaPAFrndomelement@A PDP
Sage also provides several implementations of counting functions, separate from the
inumertedets
category.
24
number of set partitions, and ordered and unordered integer partitions, and the set-theoretic counting functions for number of subsets, arrangements, derangements and permutations of a multiset.
5
5.1
Let
Symbolic combinatorics
Mathematical background
S
<2> be a set of objects, with a parameter p = (p). We dene a new set S = S S, <2> <2> <2> with parameter p = (p ), where p ((s1 , s2 )) = p(s1 ) + p(s2 ) for all s1 , s2 S . Let 1 <2> f (n) = |p (n)|, f (n) = |(p<2> )1 (n)|. Then if F (z) is the ordinary generating function
F (z) =
n0
and
f (n)z n ,
F <2> (z)
F <2> (z) =
n0
we have, simply,
f <2> (n)z n ,
http://sagemath.org/doc/reference/sage/combinat/partition.html http://sagemath.org/doc/reference/sage/combinat/combinat.html
14
It turns out that many other correspondences exist between the structure of a set of objects and its generating function. This project includes sections for two frameworks that develop this idea:
symbolic is
25
Denition 2. A combinatorial class is a countable set on which a parameter called dened, such that the number of elements of any given size n 0 is nite.
If
is denoted
in
by
An ,
||. We an = |An |.
denote the
Denition 3. The
counting sequence
labeled.
5.1.1 Unlabeled classes The word class in this section Denition 4. The (ordinary) formal power series
thought of as a set of objects made up of nodes without unique labels (think graphs). This will become rigorous as we proceed. generating function
A(z) =
n0
an z n .
Denition 5. A (k-ary) combinatorial construction is a function that maps combinatorial classes B<1> , B<2> , . . . , B<k> to a new class A = (B<1> , B<2> , . . . , B<k> ). The combinatorial construction is admissible i the counting sequence of A only depends on the counting sequences of the arguments B<1> , B<2> , . . . , B<k> .
If a construction functions such that
operator
on generating
sum
26
of two classes
and
is written
A+B
union
25 26
http://en.wikipedia.org/wiki/Symbolic_combinatorics http://en.wikipedia.org/wiki/Disjoint_union
15
2. The
product
B,
AB AB
and
with size dened additively. This is the construction used above, where we
A(z)B(z).
0.
Seq(A) is the set of all nite sequences of elements in A, with size dened additively. The generating function for Seq(A) is
For a class
sequence
A,
construction
Seq
the value
1 + A(z) + A(z)2 + =
1 . 1 A(z)
The basic combinatorial constructions can be modied ( For example, we can x length at least Let
k,
of even size from one class and an element of odd size from another, etc.
0,
neutral object,
and let
of size
1,
called an
where each i ( ) represents an expression built from the A's using the (possibly restricted) basic admissible constructions, as well as the classes E and Z . Example 7. Let T be the class of nonempty unlabeled plane trees, with the size of a tree being the number of nodes. Then T satises the specication
T = Z Seq(T ),
since an object in T is a single root with a sequence of subtrees. This specication implies T (z) = z(1 T (z))1 , and thus T (z) = 1 1 1 4z . 2
labeled,
of size
n,
each of its
indivisible
components is labeled with a unique integer from the set class with one neutral object element
[1..n].
such classes begins with a dierent denition for the elementary classes: Again, let
be the
of size
1,
labeled atom.
0,
above if we dene some useful constructions on labeled classes. There is indeed a set of admissible constructions for labeled classes that is analogous to that for the unlabeled case. The sum of two classes is dened the same as for unlabeled classes, but for the others, we rst need to dene the product of two labeled objects:
16
Denition 7. Given two labeled objects, and , the labeled product is the set of all pairs ( , ) where and are relabeled versions of and such that order is perserved in the relabelings and each number in [1..|| + ||] appears as a label in either or .
This concept leads to the denition of the product, sequence, set and cycle constructions, the rst of which we dene here; the rest can be found in [13]. The product of labeled classes
and
is the set
A B=
A,B
with size dened additively.
( ),
As with the unlabeled case, the usefulness of dening a labeled class in terms of a specication comes from the fact that labeled constructions correspond to relatively simple operators on generating functions exponenential generating functions in the labeled case.
Denition 8. The (exponential) generating fuction of a labeled class A with z marking size is the formal power series n
A(z) =
n0
For example, the generating function for
an
is
z . n!
A B
A(z)B(z).
Example 8. We dene a labeled binary tree as a labeled tree in which every internal node has two children. Let B be the labeled class representing such trees. Since an object in B is either a node with no children or a node with two children, we have
B =Z +Z B B,
E = { },
-atomic
, we can redene the original elementary classes so | | = ( ) = 0, and Z = {}, where || = 1, () = 0, and dene a new class P = {}, where || = 0, () = 1. Size is the only parameter with respect to
where
which a structure is labeled or unlabeled (and the only parameter which may be marked by a variable with a factorial below it in the generating function for the class), so those words can still be used unambiguously to refer to a class with more than one parameter. All constructions for labeled and unlabeled classes discussed so far have dened size additively, e.g. the size of an object is the sum of the sizes of its components. All of these constructions can be dened on multi-parameter classes with non-size parameters dened additively, just like size. The generating function equations they correspond to are the same as the single-parameter ones, except the generating functions may be multivariate (with a dierent variable marking each parameter).
17
Example 9. Let A be a single-parameter unlabeled combinatorial class. One can dene a new class, B, consisting of sequences of elements of A, with size and an additional parameter such that () is the number of elements of A in , for all B . Then B = Seq(P A), and, if u marks , A(z, u) = (1 uB(z))1 .
For more details, and for information on constructions where additional parameters are not dened additively, see [13]. Given a labeled or unlabeled class random variable distribution. If
Xn to be an u marks in
An
A(z, u),
5.2
Combstruct
27
and Maplesoft
httpXGGwwwFmplesoftFomGsupportGhelpGwpleGviewFspxcpthaomstrut
Combstruct is a Maple package originally developed by the INRIA Algorithms Group which is now distributed with the most recently released version of Maple, Maple 16. Its functionality has changed over time, but today, it includes the capabilities of ALAS from LUO (Section 5.4) along with the ability to enumerate, both randomly and exhaustively, the objects of a given size from a specied combinatorial class. Combstruct also extends ALAS by supporting translation from multiple-parameter specications to mulivariate generating functions. Combstruct can also count, randomly and exhaustively enumerate, and iterate through a small set of built-in, predened structures. of the functionality of Maple's combinat In fact, Combstruct provides most
28
structures, but with syntax that is unied with that for working with classes of objects dened by the user by combinatorial specications. We elaborate on these areas of functionality in the rest of this section. Combstruct allows the user to create labeled or unlabeled single-parameter combinatorial specications, and augment the specications with additional parameters separately. To
27 28
http://algo.inria.fr/index.html http://www.maplesoft.com/support/help/Maple/view.aspx?path=combinat
18
and
product, set, powerset, sequence, cycle and substitution. The constructions set, powerset, sequence and cycle can be restricted by an inequality or equality relation on the number of components allowed in the objects. It is possible, of course, to dene a great many types of basic combinatorial object, as well as more complicated objects, with such specications. The
gfeqns
sponding to a well-dened single-parameter specication (see Denition 10), and attempts to return explicit expressions for the generating functions. The returns the initial values of the counting sequences of the classes.
gfseries command
gfsolve
Example 10. We create a specication intreespe for labeled binary trees, where f is the class of labeled binary trees and is the atomic class:
bintreespe Xa {fanion@D rod@D fD fAAD aetom }X
(The nion construction is the same as sum.) Then we use gfsolve to get the generation functions:
bgfsolve@intreespeD leledD zA f@zA a E@IGPAB@EICsqrt@IERBzPAAGzD @zA a z
Combstruct's
A,
and an
drw command takes a single-parameter specication, the name of a class integer n 0 and returns a object chosen at random from the set An according
to the uniform distribution. For information on the algorithms used, see the documentation. To add additional parameters to a single-parameter specication, Combstruct allows the user to use an attribute grammar (see the documentation and [25] for more information on attribute grammars; also, note that it is also possible to augment single-parameter specications in Combstruct using a more limited method based on dening and using new atomic classes as described in the Mathematical background). The cation and attribute grammar. The multidimensional sequences. The
gfeqns
gfseries command returns the initial values of the gfmomentsolve command takes an integer k 0 and a <i> set of equations over n multivariate generating functions A (z, u), 1 i n and attempts k <i> to return explicit expressions for Du A (z, u)|u=1 , 1 i n.
A number of in-depth examples of Combstruct in action are available at the INRIA Algorithms Group's website
29
5.3
httpXGGlgoFinriFfrGlirriesG5down
29
http://algo.inria.fr/libraries/autocomb/
19
30
31
The Encyclopedia of Combinatorial Structures started out as a Maple package written by Stphanie Petit as part of the INRIA Algorithm Group's algolib and in 2009 a web interface for it was created by Alexis Darrasse and Frdric Chyzak at
frGenylopediGintroFhtml.
httpXGGlgoFinriF
The Encyclopedia is a database of counting sequences of speciable combinatorial structures. For each sequence in the database, the following elds, if available, are either computed or stored: 1. Name 2. Combinatorial specication, in Combstruct syntax 3. Initial values, obtained with Combstruct's
ount
4. Generating function, obtained with Combstruct's gfsolve 5. A linear reccurrence relation, if applicable, obtained with gfun's
diffeqtore
6. A closed-form expression, obtained with either
Maple's
rtpolytooeff
7. Dominant asymptotic term as
computed by gdev's
equivlent
8. Description of combinatorial structure 9. References, such as entry in Sloane's Encyclopedia of Integer Sequences
32
(Note that gfun is the name of a Maple package developed by the INRIA Algorithms Group, for more information, see
33
5.4
httpXGGwwwFloriFfrG~zimmermGsoftwreGluoPFIFtrFgz
34
httpXGGlgoFinriFfrGlirriesGlirriesFhtml5luo
30 31 32 33 34
LUO is a software project started in the late 1980s designed to automatically analyze algorithms. It is no longer heavily used; most of its functionality is available in Combstruct and the
equivlent
command in gdev.
35
capabilities related to enumerative and analytic combinatorics, omitting a discussion of its capabilities for algorithm analyis. LUO is made up of two modules: the algebraic analyzer (ALAS) and the analytic analyzer (ANANAS). ALAS takes as input a combinatorial specication, either labeled or unlabeled, and outputs a system of equations over generating functions for the classes in the specication. Then an intermediate process attempts to solve the equations explicitly; if successful, it passes the solutions to ANANAS. ANANAS then employs a routine (which became
equivlent
the coecients. ALAS is described in further detail below, and ANANAS is described in Section 8.3 Ocial documentation for LUO comes in the form of a main article discussing the algorithms used, but not the code [14], a cookbook containing a summary of [14] and a selection of examples of algorithms being analyzed [15], and some notes on the code and usage of ALAS, including a reference for writing programs in the syntax that the system can analyze, and examples of ALAS in action [39]. As mentioned above, ALAS, written by Paul Zimmermann, is a tool for translating specications to systems of equations over generating functions. That is, the user supplies a list of
equations
i ( )
A's
and
Z.
Denition 9. The valuation of a class A<i> is the minimum size of an object in A<i> built according to the specication. Denition 10. A combinatorial specication is well dened i it satises the two properties 1. each class has nite valuation, and
2. for each class A<i> and n 0, the number of objects of size n in A<i> built according to the specication is nite.
Since there is nothing preventing the user from supplying a non-well dened specication, it would be nice if the well-denedness of a specication could be checked programmaticly and indeed it can and ALAS does this. See [14] for details.
35
http://algo.inria.fr/salvy/index.html
21
Once ALAS veries that the specication is well-dened, it proceeds to generate the corresponding equations over generating functions using simple replacement rules. values of the counting sequences. The following theorem is proved in [14]: These generating function equations can then be used to (among other things) compute initial
Theorem 1. The number of arithmetic operations necessary for computing all the counting sequences associated with all classes A<i> up to size n is O(rn2 ).
6
6.1
Plya theory
Mathematical background
Plya theory is the study of counting symmetric objects, which makes use of group theory and generating functions. It was originally developed by John Redeld, then refounded by George Plya, who used it to count chemical compounds, among other objects, and after whom the central theorem (Theorem 2 on page 24) is named.
Denition 11. An action of a group H on a set X is a homomorphism : H S(X) from H to the symmetric group on X.
In this section, the groups we work with are assumed to be the images of group actions on nite sets, i.e. permutation groups. Let relation
Dene an equivalence
on
by
xy
The set of equivalence classes of Elements of element
i
X/G
is
orbits
x
under
under
X/G. G, and
the
orbit
of an element
and is denoted by
G(x).
The
stabilizer Gx
xX
of an
xX
Gx = {g G : g(x) = x}.
Our rst lemmas bring counting into the picture:
Proof.
f : G X dened g g(x). Then there is a bijection between the image of f , which is G(x), and the set of left cosets of Gx , which has cardinality |G|/|Gx |, given by h(x) hGx for all h(x) G(x).
For any consider the mapping
x X,
Proof.
x(g) =
gG gG xX
[g(x) = x] [g(x) = x]
xX gG
= =
xX
=
xX
= |G|
xX
= |G|
AX/G
= |G| = |G||X/G|
1 |A|
Denition 12. A graph automorphism of a graph G = (V, E) is a bijection : V V such that {((v1 ), (v2 ))|(v1 , v2 ) E} = E . The set of all automorphisms of G forms a group, aut(G). Example 11. Say we are given a labeled graph G, and we would like to nd the number of relabelings (bijections on the vertex set) that yield distinct graphs. Let X be set of all relabelings, and let be the induced action of aut(G) on X , i.e. if X and g aut(G), then (g)() = (g(1 ), g(2 ), . . . ). Then the number of such relabelings, which is the number of isomorphic graphs on the same vertex set, is |X/(aut(G))|. (The packages nauty36 , saucy37 and bliss38 , as well as some of the packages in this section, can compute the automorphism group of a graph. The code that nauty uses is also included in GRAPE.39 )
We now begin working up to the central theorem of Plya theory: a generalization of Lemma 2 for counting weighted colorings of an object.
Denition 13. Let g G be a permutation, and let c(g) be the signature of g. Then the cycle index of g is the formal monomial
z(g; s) = sc(g) .
36 37 38 39
The cycle index of the whole permutation group G is the terminating formal power series
Z(G; s) =
Let
= {1 , 2 , . . . } be a countable set of colors, each of which has a non-negative 1 weight w(i ), such that w (n) is nite for all n 0. We dene the color-counting generating
function
a(t) =
n0
where
an tn ,
total weight
of a coloring
f F
is
The
g (f (f g 1 )),
and let the coloring-counting generating function be
b(t) =
n0
where
bn tn , F
with total weight
bn
(G)
on
n.
Lemma 3. Say |X| = m. Then the generating function for functions from X to xed by a permutation (g) with total weight marked by t is
z(g; a(t), a(t2 ), . . . , a(tm )). (g) i it is constant on the cycles of g . So a function xed by (g) is specied by, for each i, a mapping between each cycle of size i and . For each i c (g) cycle size i, these mappings have generating function a(t ) i since there are ci (g) cycles of size i and each color of weight k contributes a function of weight ki that is constant on the i-cycle. The overall generating function is thus
A function is xed by
Proof.
a(t)c1 (g) a(t2 )c2 (g) a(tm ) = z(g; a(t), a(t2 ), . . . , a(tm )).
Theorem 2
Proof.
Example 12. A necklace of size n is a cycle of colored beads that can be ipped over or rotated and still be considered the same object. In this example, we count black and white necklaces of size 4 with a given number of black beads. We can use as our set X = {1, 2, 3, 4},
24
Figure 2: The six necklaces with four beads and two colors.
vertices.
and use as our permutation group on X the dihedral group D4 with 8 elements. We can let weight be the number of black beads, so that a(t) = 1 + t. Since D4 has cycle index
Z(D4 ; s1 , s2 , s3 , s4 ) = s4 + 2s2 s2 + 3s2 + 2s4 1 1 2 , 8
we have
From this generating function, we can also read o that there are 6 necklaces of size 4 with (at most) two colors of bead, as shown in Figure 2, taken from MathWorld40 . Example 13. Suppose we would like to know the number of unlabeled graphs with 3 vertices and k edges, 0 k 3, up to isomorphism. Plya's enumeration theorem can be used if we represent unlabeled graphs with 3 vertices as 2-colorings of the set E of all 3 possible edges, 2 where the color black represents an edge and the color white represents no edge. Total weight of a coloring equals the number of black edges, so our color-counting generating function is a(t) = 1 + t. The group of permutations on E that we need to quotient out is isomorphic to S3 , the symmetric group on the three vertices. The group S3 has cycle index
Z(S3 ; s1 , s2 , s3 ) = s3 + 3s1 s2 + 2s3 1 , 3!
thus
b(t) = Z(S3 ; 1 + t, 1 + t2 , 1 + t3 ) = 1 + t + t2 + t3 ,
and we see that there is exactly one graph, up to isomorphism, with 3 vertices and k edges, 0 k 3. Each of these is shown in Figure 3.
For more information on Plya theory, a more general version of Theorem 2, and many more examples, see [6, 29]
41
40 41
http://mathworld.wolfram.com/Necklace.html http://en.wikipedia.org/wiki/P%C3%B3lya_enumeration_theorem
25
6.2
Our goal in this section is to describe packages designed for Plya theory-type counting, rather than general computational group theory. GAP, Magma, Maple, Mathematica, and Sage. In the words of the authors of Combinatorica, Our aim in introducting permutation groups into Combinatorica is primarily for solving combinatorial enumeration problems. We make no attempt to eciently represent permutation groups or to solve many of the standard computational problems in group theory. [27]
6.3
COCO
Download:
httpXGGwwwFwinFtueFnlG~eGftpdosGmthGooGooEIFPFtrFgz
COCO is a package for doing computations with permutation groups which was designed to investigate graphs [22].
coherent congurations,
COCO includes routines for, among other things, nding the automorphism
group of an edgecolored complete graph and, given a base set and a permutation group on that set, computing the induced permutation group on a set of combinatorial structures over the base set. For more information, see its documentation and [22].
6.4
httpXGGwwwFsFuiowFeduG~srirmGgomintoriGxewgomintoriFm
httpXGGwwwFsFsunysFeduG~skienGomintoriG
Combinatorica has Plya-theoretic functionality that integrates with the rest of its capabilities, such as basic combinatorial objects, a description of which, along with an overview of the Combinatorica package can be found in Section 4.4. Combinatorica has built-in rules representing the symmetric, cyclic, dihedral and alternating groups, as well as the ability to create groups from other groups or simply from a set of permutations. Combinatorica can compute the automorphism group of a graph. The rules
yrits
and
yritepresenttives
optionally how the group acts on the set (the default action being the identity map), and return the set of orbits and representatives of those orbits, respectively.
Example 14. The yritepresenttives rule can be used to list all distinct necklaces of size 4 with 2 colors. To do so, we evaluate the rule with the group hihedrlqroupR, which is D4 , and the set of words of length 4 over the letters R and B :
snIXa yritepresenttiveshihedrlqroupRD trings{D f}D R
26
yutIXa {{DDD}D{fDfDfDf}D{fDfDfD}D{fDfDD}D{fDDfD}D{fDDD}}
The rule
gives the cycle index of a permutation group. Combinatorica comes with special rules for cycle index of symmetric, alternating, cyclic
gylesndex. For Plya's enumeration theorem, we have the rule yritsnventory, which takes the cycle index G(Z; s) of a group G and a list (w1 , w2 , . . . , wm ) of expressions and returns 2 G(Z; m wi , m wi , . . . ). i=1 i=1
and dihedral groups which work much faster than
Example 15. Letting G = D4 and setting w1 = 1, w2 = t, we can obtain the generating function for 2-colored necklaces of size 4:
snPXa dihedrlqroupgylesndex a hihedrlqroupsndexRD xY olorinumertor a {ID t}Y snQXa yritsnventorydihedrlqroupgylesndexD xD olorinumertor yutQXa I C t C P tP C tQ C tR
It turns out that Combinatorica has a built-in rule for this type of result:
snRXa xekleolynomilRD olorinumertorD hihedrl yutRXa I C t C P tP C tQ C tR
Example 16. As our last example of Combinatorica in action, we count the number of unlabeled graphs with 3 vertices. To apply Plya's theorem, we dene the set of all 2-subsets of [1..3], representing all 3 edges: 2
snSXa set a uusetsngeQD P yutSXa {{IDP}D{IDQ}D{PDQ}}
The group of permutations to quotient out is the set containing each permutation of set obtainable by applying a permutation g S3 to each 2-set in set. Combinatorica has the rule uusetqroup to create such a group:
snT Xa group a uusetqroupymmetriqroupQD setY
We stated above that this group is isomorphic to S3 . We can prove this with the Combinatorica rule wultiplitionle, which takes a set and an operation and gives the group multiplication table of the group they form:
snU Xa wultiplitionleymmetriqroupQD ermute GG leporm
27
yutUGGleforma
I P Q R S T
P I R Q T S
Q S I T P R
R T P S I Q R T P S I Q
S Q T I R P S Q T I R P
T R S P Q I T R S P Q I
ermute GG leporm
In order to apply Plya's enumeration theorem, we use gylesndex to compute the cycle index of group:
snW Xa ylesndex a gylesndexgroupD x yutW Xa xIQGT C xI xPGP C xQGQ
We did not actually have to do all this to nd the total number, since Combinatorica includes the rules xumeryfqrphs and vistqrphs to count and list all nonisomorphic graphs with a given number of vertices.
snII Xa xumeryfqrphsQ yutII Xa R
6.5 GraphEnumeration
httpXGGwwwFmthFrutgersFeduG~zeilergGtokhniotGqrphinumertion
httpXGGwwwFmthFrutgersFeduG~zeilergGmmrimGmmrimhtmlGqiFhtml
28
This Maple package implements the Plya-theoretic methods of [19] to solve various counting problems of the following type: How many nonisomorphic graphs are there with vertices,
P? k -hyper-graphs
according to edges,
The types of graphs that GraphEnumeration counts include unlabeled connected graphs according to the number of edges, unlabeled regular unlabeled rooted trees, unlabeled trees, all (connected or general) unlabeled simple graphs with a given degree sequence, and all (connected or general) unlabeled multi-graphs with a given degree sequence.
6.6
PermGroup
httpXGGwwwFrisFjkuFtGreserhGomintGsoftwreGermqroupG
PermGroup is a Mathematica package for permutation groups, group actions and counting. Documentation is scant, but like Combinatorica, PermGroup has built-in rules for the most commonly used permutation groups, methods for creating custom groups, and ways to use them to solve counting problems involving symmetry. Schreier-Sims algorithm PermGroup implements the
42
of PermGroup's functionality, for more details consult the documentation and code.
Example 17. To obtain the generating function for 2-colored necklaces of length 4 with t marking the number of black beads, we can use the hihedrlqroupgsoly rule which returns the cycle index for the dihedral group.
snI Xa hihedrlqroupgsolyRD x yutI Xa IGR @xIP xP C xPPA C IGV @xIR C xPP C P xRA
Example 18. To obtain the generating function for unlabeled graphs with 3 vertices, we rst dene the set of all 2-subsets of [1..3], representing all 3 edges: 2
42
http://en.wikipedia.org/wiki/Schreier-Sims_algorithm
29
Again, the group we really need is the induced group of sQ on grphsQ. PermGroup can give this to us with the rnsformqroup rule:
snT Xa gQ a rnsformqroupsQD grphsQD iretetionY
Now we could compute the cycle index polynomial of gQ and substitute in 1 + tn as above, but PermGroup oers the olyinumertion rule to save some work. The expression olyinumertiongroupD xD list evaluates to the cycle index of group in xID xPD FFF with xi replaced with otllisti.
snU Xa ixpndolyinumertiongQD xD {ID t} yutU Xa I C t C tP C tQ
7
7.1
Combinatorial species
Mathematical background
43
is a theoretical framework
The theory of combinatorial species, the most fruitful unifying concept in enumerative combinatorics of this quarter-century according to Zeilberger, generating functions can be described. While the theory of species and symbolic combinatorics (the subject of Section 5) have a lot in common, one of the important dierences is that in the theory of species, labeled and unlabeled objects are explicitly connected through Plya theory. Martin Rubey, co-author of the Aldor-Combinat package described in the next section, said in 2008: Combstruct and MuPAD-Combinat really had usability as primary goal. As one consequence, they do not implement species, but rather combinatorial classes, that is, collections of objects with a size function. The main drawback of that method is that you cannot treat labelled and unlabelled objects uniformly, there is no such concept as an isomorphism type, which, in my opinion, is the main strength of (ordinary) species. in the language of which a great diversity of families of combinatorial objects and their
44
43 44
http://www.math.rutgers.edu/~zeilberg/khaver.html http://www.mail-archive.com/[email protected]/msg00503.html
30
Connections between symbolic combinatorics and Plya theory have been made [13]
45
, but
they are not as central to the theory as they are in species. The article [28] is self-contained and can be used as a dictionary between the theory of species and the symbolic method of Flajolet and Sedgewick. We begin with the denition of a species:
The functions F [] must satisfy the following properties: 1. for each pair of bijections : U V and : V W ,
F [ ] = F [ ] F [],
is a group of permutations on
U,
is a
to
F [U ].
F [U ; H].
Denition 15. An element s F [U ] is called an F -structure on U , or alternatively a structure of species F on U . The function F [] is called the transport of F -structures along .
s F [U ], we |F [U ]| = |F [V ]|.
If use the notation
to denote
F [](s). E
Note that
|U | = |V |
implies
Whereas in symbolic combinatorics we had the classes the most elementary species are the
and
Z , in combinatorial species,
E[U ] =
and the
|U | = 0, otherwise,
45
http://www.mathematik.uni-stuttgart.de/~riedelmo/papers/collier.pdf
31
Denition 16. Consider two F -structures s1 F [U ] and s2 F [V ]. A bijection : U V is called an isomorphism of s1 to s2 i s2 = s1 . If there is such a bijection, we write s1 s2 and we say these two structures have the same isomorphism type. The isomorphism types of a species are isomorphism classes and thus equivalence classes. An F -structure s F [U ] on a set U can be referred to as a labeled structure, whereas an isomorphism type of F -structures can be referred to unlabeled structure.
Attentive readers will be detecting a whi of Plya theory by now, which will become stronger as we dene the generating functions associated with a species.
F (z) =
n0
f (n)
zn , n!
where f (n) = |F [[1..n]]|. Denition 18. Denote by T (Fn ) the quotient set F [[1..n]]/F [[1..n]; Sn ] of unlabeled F structures on [1..n]. Then the isomorphism type generating function of a species F is the formal power series
F (z) = f (n)z n ,
n0
is a permutation, let
x()
Denition 19. Let Sn denote the group of permutations of [1..n]. Then the generating function of a species F is the formal power series
ZF (z) =
n0
cycle index
ZF (z, 0, 0, . . . ) =
n0
=
n0
=
n0
32
2. Now,
ZF (z, z 2 , z 3 , . . . ) =
n0
=
n0
1 x(F [])z n n! S
n
of the action of
Sn
on
F [[1..n]]
n0
1 x(F [])z n = n! S
n
n0
1 n! n! |G|
x(F [])z n
x(F [])G
=
n0
1 x( )z n |G| G f (n)z n ,
=
n0
Denition 20. Let F and G be two species. An isomorphism of F to G is a family of bijections bU : F [U ] G[U ] which satises the following condition: for any bijection : U V between two nite sets and any F -structure s F [U ], we must have bU (s) = bV ( s). The two species are then said to be isomorphic and we write F = G.
As with combinatorial classes from symbolic combinatorics, there is a set of operations on species which have corresponding operations on their generating functions (all three types). These operations include addition, multiplication, composition, dierentiation, pointing, cartesian product, and functorial composition, just as in symbolic combinatorics. For more information on these, and all other parts of the theory of species, see the 457-page book devoted to the subject [6]. The species analogs of combinatorial specications are systems of equations, which can be created using the operators just mentioned and the notion of equality from Denition 20.
weighting function w : F [U ] R[t] maps objects in F [U ] to monomials in t over a R C, and an R[t]-weighted set is a pair (S, w), where w : S R[t] is a weighting
S.
For such a pair
function on
(S, w),
let
|S|w =
sS
w(s).
1. the rst of which maps each nite set U to an R[t]-weighted set (F [U ], wU ) such that |F [U ]|wU converges, and 2. the second of which maps each bijection : U V to a function
F [] : (F [U ], wU ) (F [V ], wV ),
that preserves weights. The functions F [] must satisfy the following properties: 1. for each pair of bijections : U V and : V W ,
F [ ] = F [ ] F [],
Denition 22. Let F be a weighted species, with weight functions wn : F [[1..n]] R[t], for n 0. Then the exponential generating function of F is
Fw (z) =
n0
|F [[1..n]]|wn
zn ; n!
|T (Fn )|w z n ,
where T (Fn ) is dened as in Denition 18; and the cycle index generating function of F is
ZFw (z) =
n0
1 n!
Example 19. Let L1 be the species of linear orders resricted to sets of at least one element; let S be the singleton species with weight 1; and let W be the singleton species with weight q. Then the species T of ordered trees with number of internal nodes marked by q satises
T = S + W (L1 T )
where + is addition (the species analog of sum), is multiplication (the analog of product), and is composition (the analog of substitution).
Two notable packages for species, Darwin [5, 7], and Devmol [2] have been described in the literature, but no longer exist.
34
7.2
Aldor-Combinat
httpsXGGportlFrisFjkuFtGwemersGhemmekeGldorGomint
A project which started in 2006, Aldor-Combinat is an unnished package primarily for working with species, which is based on MuPAD-Combinat's implementation of symbolic combinatorics. It is written in the Aldor language to be used with the Axiom algebra system. details of the package, but it is designed to be read by Aldor developers. model to organize its functionality.
46
computer
47
Like Sage uses for basic combinatorial objects, Aldor-Combinat uses a category-theoretic All species in Aldor-Combinat are objects in the
gomintorilpeies
tial generating series, isomorphism type generating series, cycle index generating series, a listing of structures, and a listing of isomorphism types. Aldor-Combinat has the following species predened: empty set, set, singleton, linear order, cycle, permutation, and set partition (whose isomorphism types are integer partitions).
Example 20. We can compute the initial coecients of the exponential generating function of the singleton species:
v aa sntegerY i aa imptyetpeies vY gseX yrdinryqenertingeries Xa genertingeries 6 iY import from sntegerY leX vist snteger Xa oeffiient@gseD nA for n in HFFQY
This assigns ID HD HD H to le. We can compute something similar for the singleton species:
w aa sntegerY aa ingletonpeies wY gssX ixponentilqenertingeries Xa genertingeries 6 Y import from sntegerY lsX vist snteger Xa oeffiient@gssD nA for n in HFFQY
n 0,
the if
species F restricted to n by
Fn [U ] =
46 47
F [U ]
|U | = n, otherwise,
http://axiom-developer.org/ http://www.risc.jku.at/people/hemmecke/AldorCombinat/combinat.html
35
U.
estritedpeies,
which is useful for dening other species. Species may be dened implicitly or explicitly with the following operations: addition, multiplication, composition, and functorial composition.
7.3
Download: Website:
httpXGGwwwFsgemthForgGdownlodFhtml httpXGGsgemthForgGdoGrefereneGomintGspeiesFhtml
For information on Sage's basic
combinatorial objects functionality and an overview Sage as a CAS, see Section 5.4. Sage's capabilities for working with combinatorial species, which began development around 2008, are based on those in Aldor-Combinat (covered in the previous section). project roadmap describes future plans for the project. and subset species. Also, the the restriction to
48
ghrteristipeies@nA method returns the characteristic species on n, which yields one object on sets of size n, and no objects on any other set (i.e. n
of the set species
Sage oers built-in classes representing the cycle, partition, permutation, linear-order, set,
X,
dened
X[U ] = U ).
We list all structures of on the empty set and the set {1, 2}:
sgeX {} sgeX iFstrutures@AFlist@A iFstrutures@IDPAFlist@A
Since the empty set species is isomorphic to the characteristic species on 0, we get identical output using ghrteristipeies@HA:
sgeX sgeX {} sgeX
48
http://trac.sagemath.org/sage_trac/ticket/10662
36
sgeX gHFgenertingseries@AFoeffiients@RA ID HD HD H
The operations on species of addition, multiplication, composition, and functorial composition are supported. Species can be dened explicitly or implicitly (define). Each species object When species are created, a weight can be specied, as well as a restriction on the size of the set.
fFstrutures@setA is set, fFisotypes@setA is the set of equivalence classes of f structures (isomorphism types) on the set set, yleindexseries@A is the cycle index series, genertingseries@A is the exponential series, and isotypegenertingseries@A
implements a number of useful methods: the set of
f-structures
on the set
Example 22. We wish to count unlabeled ordered trees by total number of nodes and number of internal nodes. To achieve this, we begin by assigning a weight of 1 to the leaves and q to internal nodes, which are each singleton species:
sgeX sgeX sgeX q a 9q9Fgen@A lef a speiesFingletonpeies@A internlnode a speiesFingletonpeies@weightaqA
Now we dene a species representing the trees, dened as lef C internlnodeBv@A, where v is the species of linear orders restricted to sets of size 1 or greater:
sgeX sgeX sgeX v a speiesFvineryrderpeies@minaIA a speiesFgomintorilpeies@A Fdefine@lef C internlnodeBv@AA
All that remains, since the trees are unlabeled, is to compute the coecients of the isomorphism type generating function:
sgeX Fisotypegenertingseries@AFoeffiients@TA HD ID qD qP C qD qQ C QBqP C qD qR C TBqQ C TBqP C q
37
Further examples may be found in a Sage species demo by Mike Hansen, one of the developers.
49
8
8.1
Asymptotics
Mathematical background
8.1.1 Asymptotic scales and series Denition 23. Let P be an open set and let L be a limit point of P . Let SP be a set of functions from P to C. Then the set SP is an asymptotic scale at L i for every pair of dierent functions 1 , 2 SP , the limit of 1 (x)/2 (x) as x L is either 0 or +. Example 23. If P = Z0 {}, L = , then an asymptotic scale is SP = {n 1, n n, n n2 , . . . }.
The following denition, which comes from [32] (as does the previous denition), generalizes Denition 1 for terminating series:
Denition 24. Let SP be an asymptotic scale at L and let f be a complex valued function on P . Then f is said to admit a terminating asymptotic series at L i there exists a sequence (a1 , . . . , an ) of complex numbers and a sequence (1 , . . . , n ) of elements of SP such that
i
i {1, . . . , n}, SP :
aj j (x) = o((x)) as x L.
k
z Example 24. With P, L, and SL dened as in Example 23, let fk (n) = [z n ] (1z)k be the number of integer compositions of n with k parts. Then a terminating asymptotic series for k(k1) 1 fk (n) at L consists of the complex numbers (k1)! , 2(k1)! and functions (n nk1 , n nk2 ) since
fk (n) =
Various CASes oer support for generating and working with asymptotic series expansions, including Maple, Mathematica, Maxima, and MATLAB's Symbolic Math Toolbox (the current product containing the code of MuPAD) of implementations of special interest.
50
49 50
http://sage.math.washington.edu/home/mhansen/CombinatorialSpeciesDemo.html http://www.mathworks.com/help/toolbox/mupad/stdlib/asympt.html
38
formal
Theorem 4 (Singularity analysis). Fix the range of Arg to be [, ). Let F C (C; 0) be a function analytic in a domain
D = z : |z| s1 , | Arg(z s)| > , 2
where s, s1 > s, and are three positive real numbers. Assume that, with (u) = u log u and {0, 1, 2, . . . }, we have /
F (z) 1 1 z/s
as z s in D.
(n) . n()
2b(r(n)) where r(n) is the smallest positive root of r(n)F (r(n))/F (r(n)) = n and b(r) = rDr (rF (r)).
Useful information on which functions are H-admissible is given by the following theorem (also from [21]):
H-admissible functions for which the following theorem holds: Theorem 5. If F is a function dened around the origin by F (z) = H-admissible, then F (r(n)) f (n) , as n n
r(n)
n0
f (n)z n and F is
Theorem 6. The following are three properties of H-admissible functions. 1. Let and 1 be positive real numbers, and let 2 and 3 be real numbers. Then F dened by
F (z) = exp 1 (1 z) 1 1 log z 1z
2
2 log z
1 1 log z 1z
is H-admissible.
39
2. If F and G are H-admissible, and P is a polynomial function with real coecients and positive leading coecient, then exp(F ), F +G, F +P, P (F ), and P F are H-admissible. 3. If P is a polynomial function such that P (z) cannot be written as P (Q(z k )) for any polynomial function Q and k > 1, then exp(P ) is H-admissible.
The saddle-point method are discussed in further detail in [13].
8.1.4 Power series coecients and the radius of convergence Notation 2 (from [13]). Given a sequence (a0 , a1 , a2 , . . . ) of rational numbers and r [0, ], we write
an rn
i where 1/ = 0, 1/0 = .
Proposition 2. Given a sequence (a0 , a1 , a2 , . . . ) of rational numbers and r [0, ], we have an r i an rn c(n), where lim sup |c(n)|1/n = 1. In other words fn r i 1/r is the radius of convergence of n n0 an z . Denition 25. Given a function F with Maclaurin series expansion F (z) = n0 f (n)z n having radius of convergence r, with a nite set of singularities at distance r from the origin, the dominant directions of F is the set where
[, ) and F is singular at rei .
8.2
Gdev
httpXGGlgoFinriFfrGlirriesG5down httpXGGlgoFinriFfrGlirriesG5gdev
51
Gdev is a package for computing asymptotic expressions for functions and generating function coecients, which, except for the
51 52
http://algo.inria.fr/salvy/index.html http://algo.inria.fr/salvy/index.html
40
Many packages provide routines for computing Taylor expansions, but the capabilities of gdev's function
gdev
gdev
takes a function given by an explicit expression and, automatically choosing the asymptotic scale to use, nds an asymptotic expansion around a point, which ends with a big O term. The function
equivlent,
originally in ANANAS from LUO, extracts an asymptotic See the next section for more information on the
expression for the coecients of an explictly given generating function using singularity analysis or the saddle-point method. underlying algorithm.
8.3
httpXGGwwwFloriFfrG~zimmermGsoftwreGluoPFIFtrFgz
httpXGGlgoFinriFfrGlirriesGlirriesFhtml5luo
section covers ANANAS, the component of LUO for extracting asymptotic
information from generating functions. To nd out about LUO's other component, ALAS, and how ANANAS ts in to the LUO system, see Section 5.4. Once ALAS produces a system of equations for Bruno Salvy. Not all explicit expressions can be handled by ANANAS, however in particular, not all expressions produced by ALAS.
an attempt to
1 , E(F ) = exp(F ). 1F ANANAS can handle some functions not in E , but for the rest of this section, we only consider ANANAS's behavior on functions in E , since the documentation focuses on this Q(F ) = 1 , 1F L(F ) = log
case. The set
Denition 26. The set E of functions is the set of generating functions corresponding to labeled classes dened by well-dened explicit specications. That is, the functions containing the monomial functions z 1 and z z , and closed under the operations {+, , Q, L, E}, where
logarithmic
Eentire
F EAL
EAL
i
algebraic-
0<r<
R, k Z0 F (z)
such that, as
z r .
ANANAS determines which subset of some functions from as complete as for algorithm used
ingly. For the details of the steps involved in this choice, see [14]. ANANAS is able to handle
Eother ,
Eentire and Eother using the saddle-point method, but the coverage is not EAL , where singularity analysis is very eective. We briey describe the for the class EAL ; for information on what ANANAS does with Eentire and EAL ,
ANANAS performs the algorithm Equivalent:
see [14].
Given a function in
of
if F
of
then
F
around
F,
else
3.2 Apply singularity analysis 4.1 Apply a singularity-analysis style result for functions with more than one dominant
singularity
end if
Step
Algorithm 2 Radius Require: F is an expression corresponding to a function in EAL if F is a polynomial then else if F
then return
exp(G)
or
matches is
then then
G g(x) = 1 G2 G2 then Radius on G1 and G2
or
Q(G)
L(G)
G1 + G2
8.4
MultiSeries
httpXGGlgoFinriFfrGlirriesG5down
42
httpXGGwwwFmplesoftFomGsupportGhelpGwpleGviewFspxcpthawultieries
Originally developed by Bruno Salvy at the INRIA Algorithms Group and now built into Maple releases, the MultiSeries Maple package provides functionality for computing asymptotic series expansions that superseeds that provided in gdev, the subject of Section 8.2. MultiSeries contains the function special cases of
multiseries that cover the same functionality of core Maple functions: sympt, series, limit, and tylor. According to the Maple documentation, the simplest use of the package is by overriding the standard sympt, series, limit using with. The
corresponding MultiSeries functions are often more powerful than the default ones, but require more computational time. (Presumably The the variable
multiseries,
gdev,
and four
multiseries function can take as arguments an expression expr, the limit point , x in the expression tending to , and the truncation order n. It returns, like gdev, an asymptotic expansion of expr as x tends to ending in a big O term, in terms of
an asymptotic scale automatically chosen. It is also possible to specify some extra options such as choosing the path of approach, and there is support for choosing the asymptotic scale used.
tylor
53
Conclusions
First, recall that we started this project with the claim that [it is no longer] necessary
to use error-prone pen and paper methods to perform an ever-growing set of mathematical procedures. Indeed, the packages in this project cover a lot of ground, and much of the progress is recent, but there is massive potential for more work both with mathematical algorithms that have been implemented and those that have not. Note that there are few packages available for any one CAS/programming language. The average mathematician cannot be expected to be familiar with more than one system, if any. There is therefore a need for projects to be ported to systems without those capabilities, preferably the big three CASes: Maple, Mathematica and Sage. Next, future package-writers can note that not all of the packages in this project come with sucient documentation for all uses. documentation should be available: To be maximally helpful, two forms of one for mere users, and one for developers or other
people interested in the implementation details. Users want to know what the package can do and how to do those things. Developers wishing to port or extend the software want to know the algorithms and code used.
53
http://www.maplesoft.com/support/help/Maple/view.aspx?path=MultiSeries%2fmultiseries
43
Lastly, as casual observations, we can say that learning how to use a package can be a good way to learn a mathematical concept or increase one's understanding, and also that these packages are for the most part not huge collaborative eorts often there is only one author, sometimes two. Writing symbolic packages is not trivial, since it requires skills from multiple disciplines, namely mathematics, computer science, and software engineering. However, it is clear that the future of the eld is bright, and the global project to replace pen and paper, and ultimately more and more of the problem solving, theorem proving and question answering now done only by human mathematicians will continue to progress and advance signicantly in the years to come.
References
[1] T. Andreescu and Z. Feng.
gies.
A path to combinatorics for undergraduates: counting strateSm. Lothar. Combin., 49:Art. B49z, 34, 2002/04.
Computing the molecular expansion of species
[2] P. Auger, G. Labelle, and P. Leroux. with the Maple package Devmol. [3] F. Baader and T. Nipkow. Cambridge, 1998.
A, 38(1):9698, 1985.
[5] F. Bergeron and G. Cartier. Darwin: Computer algebra and enumerative combinatorics.
STACS 88,
volume 294 of
Combinatorial species and tree-like structures, volume 67 of Encyclopedia of Mathematics and its Applications. Cambridge University
Press, Cambridge, 1998. Translated from the 1994 French original by Margaret Readdy, With a foreword by Gian-Carlo Rota. [7] F. Bergeron and C. Pichet. Darwin, a system designed for the study of enumerative
in Computer Science, pages 444445. Springer Berlin / Heidelberg, 1985. Combinatorics of permutations. Advanced combinatorics.
(Boca Raton). Chapman & Hall/CRC, Boca Raton, FL, 2004. Richard Stanley.
EUROCAL '85,
volume 204 of
Lecture Notes
[8] M. Bna.
[9] L. Comtet.
44
third edition, 1981. [11] E.W. Dijkstra. tion. [12] P. Flajolet and A. Odlyzko. Singularity analysis of generating functions.
A discipline of programming.
SIAM J.
Analytic combinatorics.
Lambda-Upsilon-Omega :
an assistant
algorithms analyzer. Rapport de recherche RR-0876, INRIA, 1988. [15] P. Flajolet, P. Zimmermann, and B. Salvy. Lambda-Upsilon-Omega the 1989 cookbook. Rapport de recherche RR-1073, INRIA, 1989. [16] T. Gowers, J. Barrow-Green, and I. Leader, editors.
ematics.
Concrete mathematics.
Publishing Company, Reading, MA, second edition, 1994. A foundation for computer
[18] N.T. Gridgeman. The search for perfect numbers. 1963. [19] F. Harary and E.M. Palmer. [20] G.H. Hardy.
18(334):8588,
Graphical enumeration.
Mathematics and Mathematical Physics, No. 12. [21] W.K. Hayman. A generalisation of Stirling's formula. 95, 1956. [22] M. Klin, S. Reichard, and A. Woldar. algebra experimentation. In pages 67112. Springer, Berlin, 2009. [23] D.E. Knuth. Siamese combinatorial objects via computer
Jersey: Addison-Wesley, 2011. Combinatorial Algorithms, Part 1. [24] D.L. Kreher and D.R. Stinson.
and search.
45
[25] M. Mishna.
Adv. in Appl.
Combinatorial algorithms.
Brace Jovanovich Publishers], New York, second edition, 1978. calculators, Computer Science and Applied Mathematics. [27] S. Pemmaraju and S. Skiena.
Cambridge Univer-
sity Press, Cambridge, 2003. Combinatorics and graph theory with Mathematica. [28] C. Pivoteau, B. Salvy, and M. Soria. Algorithms for combinatorial systems. Technical report, arXiv, 2011. 58 pages. [29] G. Plya and R. C. Read.
compounds.
German by Dorothee Aeppli. [30] D. Poulalhon and G. Schaeer. Optimal coding and sampling of triangulations.
[31] F. Ruskey and A. Williams. Generating combinations by prex shifts. In Berlin, 2005. [32] B. Salvy. Examples of automatic asymptotic expansions. 1991. [33] R. Sedgewick. Permutation generation methods. [34] R.P. Stanley.
combinatorics, volume 3595 of Lecture Notes in Comput. Sci., pages 570576. Springer, SIGSAM Bull., 25:417, April
Computing and
Enumerative combinatorics. Vol. 1, volume 49 of Cambridge Studies in Advanced Mathematics. Cambridge University Press, Cambridge, 1997. With a foreword Enumerative combinatorics. Vol. 2, volume 62 of Cambridge Studies in Advanced Mathematics. Cambridge University Press, Cambridge, 1999. With a foreword The Mathematica Guidebook: Programming with CD-ROM.
Springer-Verlag
by Gian-Carlo Rota, Corrected reprint of the 1986 original. [35] R.P. Stanley.
New York, Inc., Secaucus, NJ, USA, 1st edition, 2002. [37] H.S. Wilf.
Combinatorial algorithms: an update, volume 55 of CBMS-NSF Regional Conference Series in Applied Mathematics. Society for Industrial and Applied Mathematics (SIAM), Philadelphia, PA, 1989.
[39] P. Zimmermann. ALAS : Un systeme d'analyse algebrique. Rapport de recherche RR0968, INRIA, 1989.
46
Appendix
Maple 16
Maple is a modern commercial CAS whose development began in 1980 by the Symbolic Computation Group at the University of Waterloo, and, since 1988, has been developed and sold by Waterloo Maple Inc., a.k.a. Maplesoft. The most recent version as of time of writing is Maple 16, released in 2012.
Mathematica 8
Mathematica, another modern commercial CAS, is developed by Wolfram Research. It began as a project called Symbolic Manipulation Program created by Stephen Wolfram around 1979 at Caltech, and then after Wolfram Research was founded in 1987, was renamed Mathematica. Version 1.0 of Mathematica was released in 1988; the most recent release was Mathematica 8, in 2010. Mathematica is a Turing complete
evaluated
by Mathematica, it searches through a sequence of stored pattern-replacement When a rule's pattern matches a
rules (in which form Mathematica's mathematical routines exist) looking for a match between a pattern and a subexpression of the expression. is evaluated. subexpression, that subexpression is replaced according to the rule, and the new expression For more on term rewriting systems, see [3], and for more on Mathematica programming, see its documentation and [36].
47