COMPUTER PROGRAMMING
PRE-FASCICLE 3B
A DRAFT OF SECTIONS 7.2.1.4{5:
GENERATING ALL PARTITIONS
DONALD E.KNUTH StanfordUniversity
ADDISON{WESLEY
6
77
RandomHouse,1986),opyright 1986byVikramSeth
Internetpagehttp://www-s-faulty .st an fo rd .e du/ ~k nu th /t ao p. ht ml ontains
urrent informationaboutthisbookandrelatedbooks.
Seealsohttp://www-s-faulty. sta nf or d. ed u/~ kn ut h/ sg b.h tm lforinformation
aboutTheStanfordGraphBase,inludingdownloadablesoftwarefordealingwiththe
graphsusedinmanyoftheexamplesinChapter7.
Seealsohttp://www-s-faulty. sta nf or d. ed u/~ kn ut h/ mm ixw ar e. ht ml fordown-
loadablesoftwaretosimulatetheMMIXomputer.
Copyright
2004byAddison{Wesley
Allrightsreserved.Nopartofthispubliationmaybereprodued,storedinaretrieval
system,ortransmitted,inanyform, orby anymeans,eletroni, mehanial,photo-
opying, reording, or otherwise, without the prior onsent of the publisher, exept
that the oÆial eletroni le may be used to print single opies for personal (not
ommerial)use.
Zerothprinting(revision15),31Marh2005
Quhena word fales tobedivyded at theendofa lyne,
thepartition must bemade at theendof asyllab.
|ALEXANDERHUME,Orthographie :::oftheBritanTongue (.1620)
This booklet ontains draft material that I'm irulating to experts in the
eld, in hopes that they an help remove its most egregious errors before too
many other people see it. I am also, however, posting it on the Internet for
ourageous and/or random readers who don't mind the risk of reading a few
pagesthathavenotyetreahedaverymaturestate. Beware: Thismaterialhas
notyetbeenproofreadasthoroughlyasthemanusriptsofVolumes1,2,and3
were at the time of theirrst printings. And those arefully-hekedvolumes,
alas,were subsequentlyfoundtoontainthousandsofmistakes.
Giventhisaveat, Ihopethatmyerrorsthistime willnotbesonumerous
and/orobtrusivethatyouwillbedisouragedfromreadingthematerialarefully.
Ididtrytomakeitbothinterestingandauthoritative,asfarasitgoes. Butthe
eldissovast,Iannothopetohavesurroundeditenoughtoorralitompletely.
ThereforeIbegyoutoletmeknowaboutanydeieniesyoudisover.
To put the material in ontext, this pre-fasile ontains Setions 7.2.1.4
and7.2.1.5 ofa long,long hapter onombinatorialalgorithms. Chapter7 will
eventuallyllthreevolumes(namelyVolumes4A, 4B,and 4C),assuming that
I'mabletoremainhealthy. Itwillbeginwithashortreviewofgraphtheory,with
emphasis onsome highlights ofsigniantgraphs inThe Stanford GraphBase,
from whih I will be drawing many examples. Then omes Setion 7.1, whih
deals withthetopi of bitwisemanipulations. (Idrafted about60pagesabout
that subjet in 1977, but those pages need extensive revision; meanwhile I've
deided to work forawhile on the material that followsit, so that I an get a
betterfeelforhowmuhtout.) Setion7.2isaboutgeneratingallpossibilities,
and it begins with Setion 7.2.1: Generating Basi Combinatorial Patterns|
whih, in turn, begins with Setion 7.2.1.1, \Generating all n-tuples," Setion
7.2.1.2,\Generatingallpermutations,"andSetion7.2.1.3,\Generatingallom-
binations." (Readersofthepresentbookletshould havealreadylookedatthose
setions,draftsofwhihareavailableasPre-Fasiles2A,2B,and3A.)Thestage
isnowsetforthemainontentsofthisbooklet,Setion7.2.1.4: \Generatingall
partitions,"andSetion7.2.1.5: \Generatingallsetpartitions." Thenwillome
Setion 7.2.1.6 (abouttrees), et. Setion 7.2.2will dealwith baktrakingin
general. Andso itwillgoon,ifallgoeswell;anoutlineof theentireChapter 7
asurrentlyenvisagedappearsonthetaop webpagethatisitedonpageii.
Even the apparently lowly topi of partition generation turns out to be
surprisinglyrih, withtiesto Setions 1.2.5,1.2.6, 1.2.9,1.2.10, 1.2.11.2, 1.3.3,
2.3.3,2.3.4.2, 2.3.4.4, 2.3.4.5, 3.3.2, 3.3.3,3.4.1,4.5.4, 4.6.2,4.7, 5,5.1.1, 5.1.2,
5.1.3,5.1.4, 5.2.2,5.2.3, and5.2.5of therstthree volumes. I stronglybelieve
in building up a rm foundation, so I have disussed this topi muh more
thoroughlythan I will beable to dowith material that is neweror less basi.
Indeed,thetheoryofpartitionsisoneoftheniesthaptersinallofmathematis.
Tomysurprise,Iameupwith154exerises,eventhough|believeitornot|
Ihadtoeliminatequiteabitoftheinterestingmaterialthatappearsinmyles.
Someofthethingspresentedarenew,tothebestofmyknowledge,although
I will not be at all surprised to learn that my own little \disoveries" have
been disovered before. Please look, for example, at the exerises that I've
lassed as researh problems (rated with diÆulty level 46 or higher), namely
exerises 7.2.1.4{51, 62, 63, 71, and 7.2.1.5{18, 66, 74, 77; I've also impliitly
posed additional unsolved questions intheanswers to exerises 7.2.1.4{48and
69. Arethoseproblemsstillopen? Pleaseletmeknowifyouknowofasolution
toanyoftheseintriguingquestions. Andofourseifnosolutionisknowntoday
but you do makeprogress on any of them in the future, I hope you'll let me
know.
I urgently need your help also with respet to some exerises that I made
upasIwaspreparingthismaterial. Iertainlydon'tliketogetreditforthings
thathavealreadybeenpublishedbyothers, andmostoftheseresultsarequite
natural \fruits" that were just waiting to be \pluked." Therefore please tell
meifyouknow whoI should haveredited,with respetto the ideas foundin
exerises 7.2.1.4{20,27, 48, 49, 50, 56; 7.2.1.5{2, 6, 8,9, 25, 26, 35, 38(e), 47,
50,52,56,and/or76.
Ishallhappilypayander'sfeeof$2.56foreaherrorinthisdraftwhenitis
rstreportedtome,whetherthaterrorbetypographial,tehnial,orhistorial.
ThesamerewardholdsforitemsthatIforgottoputintheindex. Andvaluable
suggestions forimprovementsto the text areworth 32/eah. (Furthermore, if
younda bettersolutiontoanexerise,I'llatuallyrewardyouwithimmortal
gloryinsteadofmeremoney,bypublishingyournameintheeventualbook: )
Cross referenes to yet-unwritten material sometimes appear as `00'; this
impossiblevalueisaplaeholderfortheatualnumberstobesuppliedlater.
Happyreading!
Stanford,California D.E.K.
14February2004
7.2.1.4. Generatingallpartitions. RihardStanley'smagnientbookEnu-
merative Combinatoris (1986) begins by disussing The Twelvefold Way, a
223arrayofbasiombinatorialproblemsthatarisefrequentlyinpratie
(seeTable1). AlltwelveofStanley'sbasi problemsan bedesribedinterms
ofthewaysthat a givennumberof ballsan beplaedinto a given number of
urns. Forexample,thereareninewaystoput2ballsinto3urnsiftheballsand
urnsarelabeled:
A B C 1 2
A B C 1 2
A B C
1 2
A B C 1 2
A B C 1 2
A B C 1 2
A B C 1 2
A B C 1 2
A B C 1 2
(Theorder of balls within an urn is ignored.) But if the balls are unlabeled,
someofthese arrangementsareindistinguishable,soonlysixdierentwaysare
possible:
A B C A B C A B C A B C A B C A B C
: (1)
Iftheurns are unlabeled,arrangementslike 1 2
and 1 2
are essentially
thesame,heneonlytwoof theoriginal ninearrangementsaredistinguishable.
And if we have three labeled balls, the only distint ways to plae them into
threeunlabeledurns are
1 2 3
1 2
3 1
3
2 1 2
3
1 2 3
: (2)
Finally,ifneitherballsnorurnsarelabeled,thesevepossibilitiesreduetoonly
three:
: (3)
TheTwelvefoldWayonsidersallarrangementsthatarepossiblewhenballsand
urnsarelabeledorunlabeled,andwhentheurnsmayoptionallyberequiredto
ontainat leastone balloratmostoneball.
Table1
THE TWELVEFOLD WAY
ballsperurn unrestrited 1 1
nlabeledballs,
mlabeledurns
n-tuples
ofmthings
n-permutations
ofmthings
partitionsoff1;:::;ng
intomorderedparts
nunlabeledballs,
mlabeledurns
n-multiombinations
ofmthings
n-ombinations
ofmthings
ompositionsofn
intomparts
nlabeledballs,
munlabeledurns
partitionsoff1;:::;ng
intomparts
npigeons
intomholes
partitionsoff1;:::;ng
intomparts
nunlabeledballs,
munlabeledurns
partitionsofn
intomparts
npigeons
intomholes
partitionsofn
intomparts
We've learned about n-tuples, permutations, ombinations, and omposi-
tionsinprevioussetionsofthishapter;andtwoofthetwelveentriesinTable1
are trivial (namely the ones related to \pigeons"). So we an omplete our
study of lassial ombinatorial mathematis by learning about the remaining
veentriesinthetable,whih allinvolvepartitions.
Letus beginbyaknowledgingthat theword \partition"
has numerous meaningsin mathematis.
Anytime adivisionofsomeobjet intosubobjetsis undertaken,
theword partition is likelyto pop up.
|GEORGE ANDREWS,The TheoryofPartitions (1976)
Two quite dierentoneptsshare thesame name: Thepartitions of aset
are the ways to subdivideit into disjoint subsets; thus (2) illustrates the ve
partitionsoff1;2;3g,namely
f1;2;3g; f1;2gf3g; f1;3gf2g; f1gf2;3g; f1gf2gf3g: (4)
And the partitions of an integer are the waysto write it as a sum of positive
integers,disregardingorder;thus(3)illustratesthethreepartitionsof3,namely
3; 2+1; 1+1+1: (5)
Weshallfollowtheommonpratieofreferringtointeger partitionsassimply
\partitions," without any qualifying adjetive; the other kind will be alled
\set partitions" in what follows, to make the distintion lear. Both kinds of
partitionsareimportant,sowe'llstudyeahofthem inturn.
Generating all partitions of an integer. A partition of n an bedened
formally as a sequene of nonnegative integers a
1 a
2
suh that n =
a
1 +a
2
+; for example, one partition of 7 has a
1
= a
2
= 3, a
3
= 1, and
a
4
=a
5
==0. Thenumberofnonzerotermsisalledthenumberofparts,
and the zero terms are usually suppressed. Thus we write 7 = 3+3+1, or
simply331tosavespaewhentheontextislear.
Thesimplestwaytogenerateallpartitions,andoneofthefastest,istovisit
theminreverselexiographiorder,startingwith`n'andendingwith`11:::1'.
For example,thepartitionsof8 are
8;71;62;611;53;521;5111;44;431;422;4211;41111; 332;3311;
3221;32111;311111;2222;22211; 221111;2111111;11111111;
(6)
whenlistedinthisorder.
If a partitionisn't all 1s, it ends with (x+1) followedby zero or more 1s,
for some x 1; therefore the next smallest partition in lexiographi order
isobtainedbyreplaingthesuÆx(x+1)1:::1 byx:::xr forsomeappropriate
remainderrx. TheproessisquiteeÆientifwekeeptrakofthelargestsub-
sriptqsuhthata
q
6=1,assuggestedbyJ.K.S.MKay[CACM 13(1970),52℄:
Algorithm P(Partitions inreverselexiographi order). Thisalgorithmgen-
erates allpartitions a
1 a
2
a
m
1 with a
1 +a
2
++a
m
=nand
1mn,assumingthatn1.
P1.[Initialize.℄ Seta
0
0andm 1.
P2.[Storethenalpart.℄ Seta
m
nandq m [n=1℄.
P3.[Visit.℄ Visitthepartitiona
1 a
2 :::a
m
. ThengotoP5ifa
q 6=2.
P4.[Change2to1+1.℄ Seta
q
1,q q 1,m m+1,a
m
1,andreturn
toP3.
P5.[Dereasea
q
.℄ Terminatethealgorithmifq=0. Otherwisesetx a
q 1,
a
q
x,n m q+1,andm q+1.
P6.[Copy xifneessary.℄ Ifnx,returnto stepP2. Otherwiseset a
m x,
m m+1,n n x,andrepeatthisstep.
Notiethattheoperationofgoingfromonepartitiontothenextispartiularly
easyifa2ispresent;thenstepP4simplyhangestherightmost2toa1andap-
pendsanother1attheright. Thishappysituationis,fortunately,themostom-
monase. Forexample,nearly79%ofallpartitionsontaina2 whenn=100.
Anothersimplealgorithmisavailablewhenwewanttogenerateallpartitions
of n into a xed number of parts. The followingmethod, whih was featured
inC. F. Hindenburg's 18th-entury dissertation [Innitinomii Dignitatum Ex-
ponentis Indeterminati (Gottingen, 1779),73{91℄, visits thepartitions inolex
order,namelyinlexiographiorderofthereetedsequenea
m :::a
2 a
1 :
Algorithm H (Partitions intom parts). Thisalgorithm generatesallinteger
m-tuplesa
1 :::a
m
suhthata
1
a
m
1anda
1
++a
m
=n,assuming
thatnm2.
H1.[Initialize.℄ Set a
1
n m+1 and a
j
1 for 1 < j m. Also set
a
m+1 1.
H2.[Visit.℄ Visitthepartitiona
1 :::a
m
. Thengoto H4ifa
2 a
1 1.
H3.[Tweaka
1 anda
2 .℄ Seta
1 a
1 1,a
2 a
2
+1,and returnto H2.
H4.[Findj.℄ Setj 3ands a
1 +a
2
1.Then,ifa
j a
1
1,sets s+a
j ,
j j+1,andrepeatuntila
j
<a
1
1. (Nows=a
1
++a
j 1 1.)
H5.[Inrease a
j
.℄ Terminate if j > m. Otherwise set x a
j +1, a
j x,
j j 1.
H6.[Tweak a
1 :::a
j
.℄ While j > 1, set a
j
x, s s x, and j j 1.
Finallyseta
1
sandreturnto H2.
Forexample,whenn=11andm=4thesuessivepartitionsvisitedare
8111; 7211; 6311; 5411; 6221; 5321;4421; 4331; 5222; 4322; 3332: (7)
Thebasiideaisthatolexordergoesfromonepartitiona
1 :::a
m
tothenextby
ndingthesmallestjsuhthata
j
anbeinreasedwithouthanginga
j+1 :::a
m .
Thenewpartitiona 0
1 :::a
0
m
willhavea 0
1
a 0
j
=a
j
+1anda 0
1
++a 0
j
=
a
1
++a
j
, and these onditions are ahievable if and only if a
j
< a
1 1.
Furthermore, thesmallestsuh partitiona 0
1 :::a
0
m
inolexorder hasa 0
2
==
a 0
j
=a
j +1.
Step H3handles thesimpleasej =2, whih is byfarthe mostommon.
And indeed,the value of j almost always turns out to bequite small; we will
provelaterthatthetotalrunningtimeofAlgorithmHisatmostasmallonstant
timesthenumberofpartitionsvisited,plusO(m).
Otherrepresentationsofpartitions. We'vedenedapartitionasasequene
ofnonnegativeintegersa
1 a
2
::: with a
1 a
2
and a
1 +a
2
+=n, but
weanalsoregarditasann-tupleofnonnegativeintegers
1
2 :::
n
suhthat
1 +2
2
++n
n
= n: (8)
Here
j
isthe numberof times theinteger j appears inthesequene a
1 a
2 :::;
forexample,thepartition331orrespondsto theounts
1
=1,
2
=0,
3
=2,
4
=
5
=
6
=
7
=0. Thenumberofpartsisthen
1 +
2
++
n
. Aproedure
analogoustoAlgorithmPanreadilybedevisedtogeneratepartitionsinpart-
ountform;seeexerise5.
We have alreadyseen the part-ount representation impliitly informulas
likeEq. 1.2.9{(38),whihexpressesthesymmetrifuntion
h
n
=
X
Nd
n d
2 d
1 1
x
d1 x
d2 :::x
dn
(9)
as
X
1
;
2
;::: ;
n 0
1 +2
2 ++n
n
=n S
1
1
1
1
1
! S
2
2
2
2
2
!
S n
n
n
n
n
!
; (10)
where S
j
is the symmetri funtion x j
1 +x
j
2
++x j
N
. The sum in (9) is
essentially taken over all n-multiombinations of N, while the sum in (10) is
takenoverallpartitionsofn. Thus,forexample,h
3
= 1
6 S
3
1 +
1
2 S
1 S
2 +
1
3 S
3 ,and
whenN =2wehave
x 3
+x 2
y+xy 2
+y 3
= 1
6 (x+y)
3
+ 1
2
(x+y)(x 2
+y 2
)+ 1
3 (x
3
+y 3
):
Other sums over partitions appear in exerises 1.2.5{21, 1.2.9{10, 1.2.9{11,
1.2.10{12,et.;forthisreasonpartitionsareofentralimportaneinthestudyof
symmetrifuntions,a lassoffuntionsthatpervadesmathematisingeneral.
[Chapter 7 of Rihard Stanley's Enumerative Combinatoris 2 (1999) is an
exellentintrodutiontoadvanedaspetsofsymmetrifuntiontheory.℄
Partitions an be visualized in an appealing way by onsidering an array
of ndots, having a
1
dots inthetop rowand a
2
inthe nextrow,et. Suh an
arrangementof dots is alledthe Ferrers diagram of thepartition, inhonor of
N.M.Ferrers[seePhilosophialMag.5(1853),199{202℄;andthelargestsquare
subarray ofdotsthatitontainsisalledtheDurfee square,afterW.P. Durfee
[see Johns Hopkins Univ. Cirular 2 (Deember 1882), 23℄. For example, the
Ferrersdiagram of8887211isshownwithits44 DurfeesquareinFig.28(a).
(a)8887211 (b)75444443
Fig.28. TheFerrers
diagramsandDurfee
squaresoftwoonju-
gatepartitions.
The Durfee square ontains k 2
dots when k is the largest subsript suh that
a
k
k;wemayallkthetrae ofthepartition.
If is any partition a
1 a
2
:::, its onjugate T
= b
1 b
2
::: is obtained by
transposing the rows and olumns of the orresponding Ferrers diagram. For
example, Fig. 28(b) shows that (8887211) T
= 75444443. When = T
we
obviouslyhave= T
;thepartition hasa
1
partsandhasb
1
parts. Indeed,
there'sasimplerelationbetweenthepart-ountrepresentation
1 :::
n
ofand
theonjugatepartitionb
1 b
2
:::,namely
b
j b
j+1
=
j
forallj1. (11)
Thisrelationmakesiteasytoomputetheonjugateofa givenpartition,orto
writeitdownbyinspetion(seeexerise6).
Thenotionofonjugationoftenexplainspropertiesofpartitionsthatwould
otherwisebequitemysterious. Forexample,nowthatweknowthedenitionof
T
,wean easilysee that thevalueofj 1 instepH5of AlgorithmH isjust
theseond-smallestpart of the onjugatepartition(a
1 :::a
m )
T
. Therefore the
averageamountofworkthatneedstobedoneinstepsH4andH6isessentially
proportionaltotheaveragesizeoftheseond-smallestpartofarandompartition
whoselargestpartism. Andwewill seebelowthat theseond-smallestpart is
almostalwaysquitesmall.
Moreover, Algorithm H produespartitions inlexiographi order of their
onjugates. For example,therespetiveonjugatesof(7)are
41111111; 4211111; 422111; 42221; 431111;
43211; 4322; 4331; 44111; 4421; 443; (12)
theseare thepartitionsof n=11 withlargest part 4. Onewayto generateall
partitionsofnistostartwiththetrivialpartition`n',thenrunAlgorithmHfor
m=2, 3,:::, n inturn; this proess yields all inlexiographi order of T
(seeexerise 7). ThusAlgorithmHanberegardedasa dualofAlgorithmP.
There is at least one more useful way to represent partitions, alled the
rimrepresentation. Suppose wereplaethedots ofaFerrersdiagrambyboxes,
therebyobtaininga tableau shapeas wedidin Setion 5.1.4; forexample, the
partition8887211ofFig.28(a)beomes
: (13)
Theright-handboundaryofthisshapeanberegardedasapathfromthelower
leftornertotheupperrightornerofannnsquare,andweknowfromTable
7.2.1.3{1that suha pathorrespondstoan(n;n)-ombination.
Forexample,(13)orrespondsto the70-bit string
0:::01001011111010001:::1 = 0 28
1 1
0 2
1 1
0 1
1 5
0 1
1 1
0 3
1 27
; (14)
whereweplaeenough0satthebeginningand1sattheendtomakeexatlynof
eah. The0srepresentupwardstepsofthepath,andthe1srepresentrightward
steps. It is easy to see that the bit string dened in this way has exatly n
inversions; onversely, every permutation ofthe multisetfn0; n1gthat has
exatlyn inversions orresponds to a partitionof n. When thepartitionhas t
dierentparts,itsbitstringanbewrittenintheform
0 n q
1 q
2 q
t
1 p
1
0 q
1
1 p
2
0 q
2
:::1 p
t
0 q
t
1 n p
1 p
2 p
t
; (15)
wheretheexponentsp
j andq
j
arepositiveintegers. Thenthepartition'sstan-
dardrepresentation is
a
1 a
2
::: = (p
1
++p
t )
q
t
(p
1
++p
t 1 )
q
t 1
:::(p
1 )
q
1
; (16)
namely(1+1+5+1) 3
(1+1+5) 1
(1+1) 1
(1) 2
=8887211 inourexample.
The number ofpartitions. Inspiredbya questionthatwas posedto himby
PhilippNaudein1740,LeonhardEulerwrotetwofundamentalpapersinwhih
he ounted partitions of various kinds by studying their generating funtions
[Commentarii Aademi Sientiarum Petropolitan 13 (1741), 64{93; Novi
Comment.Aad.Si. Pet.3(1750),125{169℄. Heobservedthat theoeÆient
ofz n
intheinniteprodut
(1+z+z 2
++z j
+)(1+z 2
+z 4
++z 2k
+)(1+z 3
+z 6
++z 3l
+):::
isthenumberofnonnegativeintegersolutionstotheequationj+ 2k+ 3l+ =n;
and1+z m
+z 2m
+ is1=(1 z m
). Thereforeifwewrite
P(z) = 1
Y
m=1 1
1 z m
= 1
X
n=0 p(n)z
n
; (17)
thenumberofpartitions ofnis p(n). ThisfuntionP(z)turns outtohavean
amazingnumberofsubtlemathematialproperties.
For example, Euler disovered that massive anellation ours when the
denominatorofP(z)ismultipliedout:
(1 z)(1 z 2
)(1 z 3
)::: =1 z z 2
+z 5
+z 7
z 12
z 15
+z 22
+z 26
= X
1<n<1 ( 1)
n
z (3n
2
+n)=2
: (18)
A ombinatorial proof of this remarkableidentity, based on Ferrers diagrams,
appearsinexerise5.1.1{14;weanalsoproveitbysettingu=zandv=z 2
in
theevenmore remarkableidentityofJaobi,
1
Y
k=1 (1 u
k
v k 1
)(1 u k 1
v k
)(1 u k
v k
) = 1
X
n= 1 ( 1)
n
u (
n
2 )
v (
n
2 )
; (19)
beause the left-hand side beomes Q
1
k=1 (1 z
3k 2
)(1 z 3k 1
)(1 z 3k
); see
exerise5.1.1{20. Euler'sidentity(18)impliesthatthepartitionnumberssatisfy
thereurrene
p(n)=p(n 1)+p(n 2) p(n 5) p(n 7)+p(n 12)+p(n 15) ; (20)
from whih wean ompute their values more rapidly than by performing the
powerseriesalulationsin(17):
n = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
p(n)= 1 1 2 3 5 7 11 15 22 30 42 56 77 101 135 176
We know from Setion 1.2.8 that solutions to the Fibonai reurrene
f(n)=f(n 1)+f(n 2) growexponentially,with f(n)=( n
)when f(0)
andf(1)arepositive. Theadditionalterms` p(n 5) p(n 7)'in(20)havea
dampeningeetonpartitionnumbers, however;infat,ifwewere tostop the
reurrenethere,theresultingsequenewouldosillatebetweenpositiveandneg-
ativevalues. Furtherterms`+p(n 12)+p(n 15)'reinstateexponentialgrowth.
Theatualgrowthrateofp(n)turnsouttobeoforderA p
n
=nforaertain
onstantA. Forexample,exerise33provesdiretlythatp(n)growsatleastas
fastas e 2
p
n
=n. Andone fairlyeasy wayto obtain a deent upper bound is to
takelogarithmsin(17),
lnP(z) = 1
X
m=1 ln
1
1 z m
= 1
X
m=1 1
X
n=1 z
mn
n
; (21)
andthentolookat thebehaviornear z=1 bysettingz=e t
:
lnP(e t
)= X
m;n1 e
mnt
n
= X
n1 1
n 1
e tn
1
<
X
n1 1
n 2
t
= (2)
t
: (22)
Consequently,sinep(n)p(n+1)<p(n+2)< ande t
>1,wehave
p(n)
1 e t
<
1
X
k=0 p(k)e
(n k)t
= e nt
P(e t
) < e
nt+(2)=t
(23)
forallt>0. Settingt= p
(2)=ngives
p(n) < Ce 2C
p
n
= p
n; whereC= p
(2)== p
6. (24)
We an obtain more aurate information about the size of lnP(e t
) by
using Euler's summation formula (Setion 1.2.11.2)or Mellin transforms(Se-
tion5.2.2);seeexerise25. Butthemethodswehaveseensofararen'tpowerful
enough to dedue thepreise behavior of P(e t
), so itis time for us to add a
newweapontoourarsenaloftehniques.
Euler'sgeneratingfuntionP(z)isideallysuitedtothePoissonsummation
formula [J.
Eole Royale Polytehnique 12 (1823), 404{509, x63℄, aording to
whih
1
X
n= 1
f(n+) = lim
M!1 M
X
m= M e
2mi Z
1
1 e
2miy
f(y)dy; (25)
whenever f is a \well-behaved" funtion. This formula is based on the fat
thattheleft-handsideisaperiodifuntionof,andtheright-handsideisthe
expansionofthatfuntionasaFourierseries. Thefuntionf issuÆientlynie
if,forexample, R
1
1
f(y)
dy<1andeither
i) f(n+) is an analyti funtion of the omplex variable in the region
j=jfor some >0 and0 <1,and theleft-handside onverges
uniformlyinthatretangle;or
ii) f()= 1
2 lim
!0
f( )+f(+)
=g() h()for allreal numbers,
where gandharemonotoneinreasingand g(1), h(1)arenite.
[SeePeterHenrii,AppliedandComputationalComplexAnalysis2(NewYork:
Wiley,1977),Theorem10.6.2.℄ Poisson'sformulaisnotapanaeaforsummation
problemsof every kind; butwhen itdoesapplytheresultsan bespetaular,
aswewillsee.
Let us multiply Euler's formula (18) by z 1=24
in order to \omplete the
square":
z 1=24
P(z)
= 1
X
n= 1 ( 1)
n
z 3
2 (n+
1
6 )
2
: (26)
Thenforallt>0wehavee t=24
=P(e t
)= P
1
n= 1
f(n),where
f(y) = e 3
2 t(y+
1
6 )
2
osy; (27)
andthisfuntionf qualiesforPoisson'ssummationformulaunderbothofthe
riteria(i)and(ii)statedabove. Thereforeweantrytointegratee 2miy
f(y),
andform=0theresultis
Z
1
1
f(y)dy = r
2t e
2
=6t
: (28)
To thiswemustadd
1
X
m=1 Z
1
1 (e
2miy
+e 2miy
)f(y)dy = 2 1
X
m=1 Z
1
1
f(y)os2mydy; (29)
againthe integralturns outto bedoable. And theresults (seeexerise 27) t
togetherquitebeautifully,giving
e t=24
P(e t
)
= r
2
t 1
X
n= 1 ( 1)
n
e 6
2
(n+
1
6 )
2
=t
= r
2
t e
2
=6t
P(e 4
2
=t
)
: (30)
Surprise! WehaveprovedanotherremarkablefataboutP(z):
TheoremD. Thegeneratingfuntion(17)forpartitionssatisesthefuntional
relation
lnP(e t
) = (2)
t +
1
2 ln
t
2 t
24
+lnP(e 4
2
=t
) (31)
when<t>0.
Thistheorem was disovered byRihardDedekind[Crelle 83 (1877),265{292,
x6℄, whowrote() for thefuntionz 1=24
=P(z)when z =e 2i
; his proof was
basedonamuhmoreompliatedtheoryofelliptifuntions. Notiethatwhen
tis asmall positivenumber,lnP(e 4
2
=t
)is extremely tiny;forexample, when
t = 0:1 we have exp( 4 2
=t) 3:510 172
. Therefore Theorem D tells us
essentiallyeverythingweneedtoknowaboutthevalueofP(z)whenzisnear1.
G.H.Hardyand S.Ramanujanused thisknowledgeto deduetheasymp-
totibehaviorofp(n)forlargen,andtheirworkwasextendedmanyyearslater
by Hans Rademaher, who disovered a seriesthat is notonlyasymptoti but
onvergent [Pro. London Math. So. (2) 17 (1918), 75{115; 43 (1937), 241{
254℄. TheHardy{Ramanujan{Rademaherformulaforp(n)issurelyone ofthe
mostastonishingidentitieseverdisovered;itstatesthat
p(n) =
2 5=4
3 3=4
(n 1=24) 3=4
1
X
k=1 A
k (n)
k I
3=2 r
2
3
k p
n 1=24
: (32)
HereI
3=2
denotesthemodiedspherialBesselfuntion
I
3=2 (z) =
z
2
3=2 1
X
k=0 1
(k+5=2) (z
2
=4) k
k!
= r
2z
oshz
z
sinhz
z 2
; (33)
andtheoeÆientA
k
(n)isdened bytheformula
A
k (n) =
k 1
X
h=0
[h?k℄exp
2i
(h;k;0)
24
nh
k
(34)
where(h;k;0)istheDedekindsumdened inEq.3.3.3{(16). Wehave
A
1
(n)=1; A
2
(n)=( 1) n
; A
3
(n)=2os
(24n+1)
18
; (35)
andingeneralA
k
(n)liesbetween kandk.
A proof of (32) would take us far aeld, but the basi idea is to use the
\saddlepointmethod"disussedinSetion7.2.1.5. Thetermfork=1isderived
fromthebehavior ofP(z) whenz isnear 1;and thenexttermisderivedfrom
thebehavior when z isnear 1,where a transformationsimilar to(31)an be
applied. Ingeneral,thekthtermof(32)takesaountofthewayP(z)behaves
when z approahes e 2ih=k
for irreduible frations h=k with denominator k;
every kth root of unityis a pole ofeah of thefators 1=(1 z k
),1=(1 z 2k
),
1=(1 z 3k
),::: intheinniteprodutforP(z).
Theleadingtermof(32)anbesimpliedgreatly,ifwemerelywantarough
approximation:
p(n) = e
p
2n=3
4n p
3
1+O(n 1=2
)
: (36)
Or,ifwehoosetoretaina fewmoredetails,
p(n) = e
p
2n 0
=3
4n 0
p
3
1 1
r
3
2n 0
1+O e
p
n=6
; n 0
=n 1
24
: (37)
For example,p(100)hastheexatvalue190,569,292;formula(36)tellsus that
p(100)1:99310 8
, while(37)givesthefarbetterestimate190,568,944.783.
AndrewOdlyzkohasobservedthat,whennislarge,theHardy{Ramanujan{
Rademaherformulaatuallygivesanear-optimumwaytoomputethepreise
value of p(n), beause the arithmeti operations an be arried out in nearly
O logp(n)
=O(n 1=2
)steps. Therst fewterms of(32) givethemain ontri-
bution;thentheseriessettlesdowntotermsthatareoforderk 3=2
andusually
of orderk 2
. Furthermore, abouthalfof the oeÆientsA
k
(n) turn outto be
zero (see exerise 28). For example, when n = 10 6
, the terms for k = 1, 2,
and 3 are 1:4710 1107
, 1:2310 550
, and 1:2310 364
, respetively. The
sumof therst250 termsis 1471684986:::73818:01,whilethe truevalueis
1471684986:::73818; and123ofthose250termsarezero.
The number of parts. It isonvenienttointroduethenotation
n
m
(38)
forthenumberofpartitionsofnthathaveexatlymparts. Thenthereurrene
n
m
=
n 1
m 1
+
n m
m
(39)
holdsforallintegersmandn,beause
n 1
m 1
ountsthepartitionswhosesmallest
partis1and
n m
m
ountstheothers. (Ifthesmallestpartis2ormore,wean
subtrat1fromeahpartandgetapartitionofn mintomparts.) Bysimilar
reasoningweanonludethat
m+n
m
isthenumberofpartitionsofnintoatmost
mparts, namelyinto mnonnegativesummands. Wealsoknow,byonsidering
Ferrers diagrams, that
n
m
is the numberof partitions of n whose largest part
ism. Thus
n
m
isa goodnumbertoknow. Theboundaryonditions
n
0
=Æ
n0
and
n
m
=0 form<0 orn<0 (40)
makeit easyto tabulate
n
m
for smallvaluesof theparameters,and weobtain
anarrayof numbersanalogous tothefamiliartrianglesfor n
m
,
n
m
,
n
m , and
n
m
thatwe'veseen before; seeTable2. Thegeneratingfuntionis
X
n
n
m
z n
=
z m
(1 z)(1 z 2
):::(1 z m
)
: (41)
Table2
PARTITION NUMBERS
n
n
0
n
1
n
2
n
3
n
4
n
5
n
6
n
7
n
8
n
9
n
10
n
11
0 1 0 0 0 0 0 0 0 0 0 0 0
1 0 1 0 0 0 0 0 0 0 0 0 0
2 0 1 1 0 0 0 0 0 0 0 0 0
3 0 1 1 1 0 0 0 0 0 0 0 0
4 0 1 2 1 1 0 0 0 0 0 0 0
5 0 1 2 2 1 1 0 0 0 0 0 0
6 0 1 3 3 2 1 1 0 0 0 0 0
7 0 1 3 4 3 2 1 1 0 0 0 0
8 0 1 4 5 5 3 2 1 1 0 0 0
9 0 1 4 7 6 5 3 2 1 1 0 0
10 0 1 5 8 9 7 5 3 2 1 1 0
11 0 1 5 10 11 10 7 5 3 2 1 1
Almostallpartitions ofnhave( p
nlogn)parts. This fat,disovered by
P.Erd}osandJ.Lehner[DukeMath.J.8(1941),335{345℄,hasaveryinstrutive
proof:
TheoremE. LetC== p
6andm= 1
2C p
nlnn+x p
n+O(1). Then
1
p(n)
m+n
m
= F(x) 1+O(n 1=2+
)
(42)
forall>0 andallxed xasn!1,where
F(x) = e e
Cx
=C
: (43)
This funtionF(x) approahes 0 quite rapidly when x! 1, and it rapidly
inreasesto1 when x!+1; so it isa probabilitydistributionfuntion. Fig-
ure29(b)showsthattheorrespondingdensityfuntionf(x)=F 0
(x)islargely
onentratedintheregion 2x4. Thevaluesof
n
m
=
m+n
m
m 1+n
m 1
are
showninFig.29(a)foromparisonwhenn=100;inthisase 1
2C p
nlnn18.
Proof. Wewill usethe fatthat
m+n
m
isthe number ofpartitions of nwhose
largestpartism. Then,bytheprinipleofinlusionandexlusion,Eq.1.3.3{
(29),wehave
m+n
m
=p(n) X
j>m
p(n j)+
X
j2>j1>m p(n j
1 j
2 )
X
j3>j2>j1>m p(n j
1 j
2 j
3 )+;
beausep(n j
1
j
r
)isthenumberofpartitionsofnthatuseeahofthe
partsfj
1
;:::;j
r
g atleastone. Letus writethisas
1
p(n)
m+n
m
=1
1 +
2
3
+;
r
= X
jr> >j1>m p(n j
1
j
r )
p(n)
: (44)
a)
100
m
:
0 8 18 28 38 48 58
m
b)f(x):
2 1 0 1 2 3 4
x
Fig.29. Partitionsofnwithmparts,when(a)n=100;(b)n!1. (SeeTheoremE.)
In order to evaluate
r
we need to have a good estimate of the ratio
p(n t)=p(n). Andwe're inluk,beauseEq.(36)impliesthat
p(n t)
p(n)
=exp 2C p
n t ln(n t)+O (n t) 1=2
2C p
n+lnn
=exp Ctn 1=2
+O(n 1=2+2
)
if0tn 1=2+
: (45)
Furthermore, if t n 1=2+
we have p(n t)=p(n) p(n n 1=2+
)=p(n)
exp( Cn
),avaluethatisasymptotiallysmallerthananypowerofn. Therefore
wemaysafelyusetheapproximation
p(n t)
p(n)
t
; =exp( Cn
1=2
); (46)
forallvaluesoft0. Forexample,wehave
1
= X
j>m
p(n j)
p(n)
=
m+1
1
1+O(n 1=2+2
)
+ X
nj>n 1=2+
p(n j)
p(n)
= e
Cx
C
1+O(n 1=2+2
)
+O(ne Cn
);
beause =(1 )=n 1=2
=C+O(1) and m
=n 1=2
e Cx
. A similarargument
(seeexerise36)provesthat,ifr=O(logn),
r
= e
Crx
C r
r!
1+O(n 1=2+2
)
+O(e n
=2
): (47)
Finally|andthisisawonderfulpropertyoftheinlusion-exlusionprini-
pleingeneral|thepartialsums of(44)always\braket"thetruevalue,inthe
sensethat
1
1 +
2
2r 1
1
p(n)
m+n
m
1
1 +
2
2r 1 +
2r (48)
forallr. (Seeexerise37.) When2r isnearlnnandnislarge,theterm
2r is
extremelytiny;thereforeweobtain(42),exeptwith2inplaeof.
0
n 2 n
p
n
2 p
n
Fig.30. Temperley'surve(49)forthe
limitingshapeofarandompartition.
TheoremEtellsusthatthelargestpartofarandompartitionalmostalways
is 1
2C p
nlnn+O(
p
n),and whenn isreasonably largetheotherparts tendto
be preditable as well. Suppose, for example, that we take all the partitions
of25andsuperimposetheirFerrersdiagrams,hanging dots toboxes asinthe
rimrepresentation. Whih ellsareoupied mostoften? Figure 30shows the
result: A random partition tends to have a typial shape that approahes a
limitingurveasn!1.
H. N. V. Temperley [Pro. Cambridge Philos. So. 48 (1952), 683{697℄
gaveheuristireasonsto believethatmostpartsa
k
ofa largerandompartition
a
1 :::a
m
willsatisfytheapproximatelaw
e Ck=
p
n
+e Cak=
p
n
1; (49)
andhisformulahassubsequentlybeenveriedinastrongform. Forexample,a
theoremofBorisPittel[AdvanesinApplied Math.18 (1997),432{488℄ allows
usto onludethat the trae ofa random partitionisalmost always ln2
C p
n
0:54 p
n,inaordane with(49), withan errorof atmost O(
p
nlnn) 1=2
; thus
about29% ofalltheFerrersdots tendtolieintheDurfee square.
If, ontheother hand, welookonly atpartitions of nwith mparts, where
misxed,thelimitingshapeisratherdierent: Almostallsuhpartitionshave
a
k
n
m ln
m
k
; (50)
ifmis reasonably large. Figure 31illustrates theasen=50,m =5. Infat,
thesame limit holds whenm growswith n, but at a slowerratethan p
n[see
VershikandYakubovih,MosowMath.J.1(2001),457{468℄.
0
n=m 2n=m
m
Fig.31. Thelimitingshape(50)whentherearemparts.
Therimrepresentationofpartitionsgivesusfurtherinformationaboutpar-
titionsthataredoublybounded,inthesensethatwenotonlyrestritthenumber
of parts but also the size of eah part. A partitionthat has at mostm parts,
eah of size at mostl, tsinsidean mlbox. Allsuh partitions orrespond
topermutationsofthemultisetfm0;l1gthat haveexatlyninversions,and
wehavestudied theinversionsofmultisetpermutations inexerise5.1.2{16. In
partiular, that exerise derivesa nonobvious formula for the number of ways
ninversions anhappen:
Theorem C. Thenumberofpartitions of nthat have nomore thanm parts
andnopartlargerthanlis
[z n
℄
l+m
m
z
= [z n
℄ (1 z
l +1
)
(1 z)
(1 z l +2
)
(1 z 2
) :::
(1 z l +m
)
(1 z m
)
: (51)
This resultis due to A. Cauhy, Comptes Rendus Aad.Si. 17 (Paris,1843),
523{531. Notiethatwhenl!1thenumeratorbeomessimply1. Aninterest-
ingombinatorialproofofamoregeneralresultappearsinexerise39below.
Analysis of the algorithms. Now we know more than enough about the
quantitativeaspets of partitions to deduethebehavior of AlgorithmP quite
preisely. Supposesteps P1,:::,P6ofthatalgorithmareexeutedrespetively
T
1
(n),:::,T
6
(n)times. WeobviouslyhaveT
1
(n)=1andT
3
(n)=p(n);further-
moreKirhho'slawtellsusthatT
2 (n)=T
5
(n)andT
4 (n)+T
5
(n)=T
3
(n). We
gettostepP4oneforeahpartitionthatontainsa2;andthisislearlyp(n 2).
Thus the onlypossiblemystery about therunning timeof Algorithm P is
the number of times we must perform step P6, whih loops bak to itself. A
moment'sthought, however,reveals that the algorithmstoresa value2 into
thearraya
1 a
2
::: only insteps P2 andP6; and every suh valueis eventually
dereasedby1,eitherinstepP4orstepP5. Therefore
T 00
2
(n) + T
6
(n) = p(n) 1; (52)
whereT 00
2
(n)isthenumberoftimesstepP2setsa
m
toavalue2. LetT
2 (n)=
T 0
2 (n)+T
00
2
(n),sothatT 0
2
(n)isthenumberoftimesstepP2setsa
m
1. Then
T 0
2 (n)+T
4
(n)isthenumberofpartitions thatendin1,hene
T 0
2
(n) + T
4
(n)=p(n 1): (53)
Aha! We'vefoundenoughequationstodeterminealloftherequiredquantities:
T
1
(n);:::;T
6 (n)
=
1; p(n) p(n 2); p(n); p(n 2); p(n) p(n 2); p(n 1) 1
: (54)
Andfrom theasymptotisofp(n)wealsoknowtheaverageamount ofompu-
tationperpartition:
T
1 (n)
p(n)
;:::; T
6 (n)
p(n)
=
0;
2C
p
n
;1;1 2C
p
n
; 2C
p
n
;1 C
p
n
+ O
1
n
; (55)
where C = = p
6 1:283. (See exerise 45.) The total number of memory
aessesperpartitionthereforeomestoonly4 3C=
p
n+O(1=n).
Whoeverwantstogo about generatingallpartitions
not onlyimmerses himself inimmense labor,
but also must takepains tokeep fullyattentive,
so as not to be grossly deeived.
| LEONHARDEULER, De Partitione Numerorum (1750)
AlgorithmHismorediÆulttoanalyze,butweanatleastproveadeent
upperboundonitsrunningtime. Thekeyquantityisthevalueofj,thesmallest
subsript for whih a
j
<a
1
1. The suessivevalues of j when m = 4 and
n= 11 are (2;2;2;3;2;2;3;4;2;3;5), and we haveobserved that j = b
l 1 +1
whenb
1 :::b
l
istheonjugatepartition(a
1 :::a
m )
T
. (See(7)and(12).) StepH3
singlesouttheasej=2,beausethisaseisnotonlythemostommon,it is
alsoespeiallyeasytohandle.
Let
m
(n)betheaumulatedtotalvalueofj 1,summed overallof the
n
m
partitionsgeneratedbyAlgorithmH.Forexample,
4
(11)=1+1+1+2+
1+1+2+3+1+2+4 =19. Wean regard
m (n)=
n
m
as a good indiation
oftherunningtimeperpartition,beausethetimeto perform themostostly
steps,H4and H6,isroughlyproportionaltoj 2. This ratio
m (n)=
n
m
is not
bounded, beause
m
(m)=mwhile
m
m
=1. Butthefollowingtheorem shows
thatAlgorithmHiseÆientnonetheless:
TheoremH. Theostmeasure
m
(n)forAlgorithmHisat most3
n
m
+m.
Proof. We an readily verify that
m
(n)satises the same reurrene as
n
m
,
namely
m
(n) =
m 1
(n 1) +
m
(n m); form;n1; (56)
ifweartiially dene
m
(n)=1when1n<m; see(39). Buttheboundary
onditionsarenowdierent:
m
(0)=[m>0℄;
0
(n)=0: (57)
Table3showshow
m
(n)behaveswhenmandnaresmall.
To provethetheorem,wewill atuallyproveastrongerresult,
m
(n) 3
n
m
+2m n 1 fornm2. (58)
Exerise 50 shows that this inequality holds when m n 2m, so theproof
willbeompleteifweanproveitwhenn>2m. Inthelatterasewehave
m (n)=
1
(n m)+
2
(n m)+
3
(n m)++
m
(n m)
1+ 3
n m
2
+3 n+m
+ 3
n m
3
+5 n+m
+
+ 3
n m
m
+2m 1 n+m
=3
n m
1
+3
n m
2
++3
n m
m
3+m 2
(m 1)(n m)
=3
n
m
+2m 2
m (m 1)n 3
byindution;and2m 2
m (m 1)n 32m n 1beausen2m+1.
Table3
COSTS IN ALGORITHM H
n 0(n) 1(n) 2(n) 3(n) 4(n) 5(n) 6(n) 7(n) 8(n) 9(n) 10(n) 11(n)
0 0 1 1 1 1 1 1 1 1 1 1 1
1 0 1 1 1 1 1 1 1 1 1 1 1
2 0 1 2 1 1 1 1 1 1 1 1 1
3 0 1 2 3 1 1 1 1 1 1 1 1
4 0 1 3 3 4 1 1 1 1 1 1 1
5 0 1 3 4 4 5 1 1 1 1 1 1
6 0 1 4 6 5 5 6 1 1 1 1 1
7 0 1 4 7 7 6 6 7 1 1 1 1
8 0 1 5 8 11 8 7 7 8 1 1 1
9 0 1 5 11 12 12 9 8 8 9 1 1
10 0 1 6 12 16 17 13 10 9 9 10 1
11 0 1 6 14 19 21 18 14 11 10 10 11
*A Gray ode for partitions. Whenpartitions are generated inpart-ount
form
1 :::
n
as inexerise5,atmostfourofthe
j
valueshangeat eahstep.
Butwemightprefertominimizethehangestotheindividualparts,generating
partitions insuh a waythat thesuessor ofa
1 a
2 :::a
n
isalwaysobtainedby
simplysettinga
j a
j
+1anda
k a
k
1forsomejandk,asinthe\revolving
door"algorithmsofSetion 7.2.1.3. It turnsoutthatthis isalwayspossible;in
fat,thereisauniquewaytodoitwhenn=6:
111111; 21111; 3111; 2211; 222;321; 33; 42; 411;51; 6: (59)
And ingeneral, the
m+n
m
partitions of n into at most m parts an always be
generatedbyasuitableGraypath.
Notiethat ! isanallowabletransition fromone partitiontoanother
if and only ifweget the Ferrersdiagram for by moving just one dot inthe
Ferrers diagram for . Therefore T
!
T
is also an allowable transition. It
followsthatevery Grayodeforpartitionsintoatmostmparts orrespondsto
aGrayodeforpartitionsintopartsthatdonotexeedm. Weshallworkwith
thelatteronstraint.
The totalnumberof Gray odes forpartitions is vast: There are52 when
n=7, and652 whenn =8;there are 298,896 whenn =9,and 2,291,100,484
whenn=10. Butnoreallysimpleonstrutionisknown. Thereasonisprobably
thata fewpartitionshaveonlytwoneighbors,namelythepartitionsd n=d
when
1<d<nanddisadivisorofn. Suhpartitionsmustbepreededandfollowed
byf(d+ 1)d n=d 2
(d 1);d n=d 1
(d 1)1g, andthisrequirementseemsto ruleout
anysimplereursiveapproah.
CarlaD.Savage[J.Algorithms10(1989),577{595℄foundawaytosurmount
thediÆultieswithonlyamodestamountofomplexity. Let
(m;n) =
bn=m
z }| {
m m ::: m (nmodm) (60)
be the lexiographially largest partition of n with parts m; our goal will
be to onstrutreursively dened Graypaths L(m;n)and M(m;n) from the
partition1 n
to (m;n),where L(m;n)runs through allpartitions whoseparts
areboundedbymwhileM(m;n)runsthroughthosepartitionsandafewmore:
M(m;n) also inludes partitions whose largest part is m+1, provided that
theother parts are all stritly less than m. For example, L(3;8) is 11111111,
2111111,311111,221111,22211,2222,3221,32111, 3311,332,whileM(3;8)is
11111111;2111111; 221111;22211; 2222;3221;
3311; 32111; 311111; 41111; 4211; 422; 332; (61)
the additional partitions starting with 4 will give us \wiggle room" in other
partsof thereursion. Wewill dene L(m;n)forall n0, but M(m;n) only
forn>2m.
Thefollowingonstrution, illustratedfor m=5 to simplifythe notation,
almost works:
L(5)= 8
<
: L(3)
4L(1) R
5L(1) 9
=
;
ifn7;
8
>
>
>
>
>
<
>
>
>
>
>
: L(3)
4L(2) R
5L(2)
431
44
53 9
>
>
>
>
>
=
>
>
>
>
>
;
ifn=8;
8
<
: M(4)
54L(4) R
55L(5) 9
=
;
ifn9;
(62)
M(5)= 8
>
>
>
<
>
>
>
: L(4)
5L(4) R
6L(3)
64L(1) R
55L(1) 9
>
>
>
=
>
>
>
;
if11n13;
8
>
>
>
<
>
>
>
: L(4)
5M(4) R
6L(4)
554L(4) R
555L(5) 9
>
>
>
=
>
>
>
;
ifn14. (63)
HeretheparameterninL(m;n)andM(m;n)hasbeenomittedbeauseitan
bededuedfromtheontext;eahLorM issupposedtogeneratepartitionsof
whateveramountremainsafter previouspartshavebeensubtrated. Thus, for
example,(63)speies that
M(5;14) = L(4;14); 5M(4;9) R
; 6L(4;8); 554L(4;0) R
; 555L(5; 1);
thesequene L(5; 1) isatuallyempty,andL(4;0) istheemptystring,so the
nalpartitionofM(5;14)is554=(5;14)asitshouldbe. ThenotationL(1)
standsforL(1;n)=L(n;n),theGraypathofallpartitionsofn,startingwith
1 n
andendingwithn 1
.
In general, L(m) and M(m) are dened for all m 3 by essentially the
same rules, ifwereplaethe digits 2,3, 4,5, and 6 in(62)and (63) by m 3,
m 2,m 1,m, andm+1,respetively. Therangesn7,n=8,n9beome
n2m 3,n=2m 2,n2m 1;theranges11n13andn14beome
2m+1 n3m 2 and n 3m 1. The sequenesL(0), L(1), L(2) have
obvious denitions beause the paths are unique when m 2. The sequene
M(2)is1 n
, 21 n 2
,31 n 3
,221 n 4
,2221 n 6
,:::,(2;n)forn5.
TheoremS. GraypathsL 0
(m;n)form;n0andM 0
(m;n)forn2m+15
existfor all partitions with theproperties desribed above, exept inthe ase
L 0
(4;6). Furthermore, L 0
and M 0
obey the mutual reursions (62) and (63)
exeptina fewases.
Proof. Wenotedabovethat (62)and (63)almost work; thereader mayverify
thattheonlyglithoursintheaseL(4;6),when(62)gives
L(4;6)=L(2;6); 3L(1;3) R
; 4L(1;2); 321; 33; 42
=111111; 21111; 2211; 222; 3111; 411; 321; 33; 42: (64)
If m >4, we're OK beause thetransition from theend of L(m 2;2m 2) to
thebeginningof(m 1)L(m 3;m 1) R
isfrom(m 2)(m 2)2to(m 1)(m 3)2.
ThereisnosatisfatorypathL(4;6),beauseallGrayodesthrough thosenine
partitionsmustendwitheither411,33,3111,222,or2211.
In order to neutralize this anomaly we need to path the denitions of
L(m;n) and M(m;n) at eight plaes where the \buggy subroutine" L(4;6) is
invoked. Onesimplewayistomakethefollowingdenitions:
L 0
(4;6)=111111;21111;3111;411;321;33;42;
L 0
(3;5)=11111;2111;221;311;32:
(65)
Thus,weomit222and2211fromL(4;6);wealsoreprogramL(3;5)sothat2111
isadjaent to221. Thenexerise 60shows thatit isalwayseasy to\splie in"
thetwo partitionsthataremissing fromL(4;6).
EXERCISES
x 1. [M21℄ GiveformulasforthetotalnumberofpossibilitiesineahproblemofThe
Twelvefold Way. For example, the numberof n-tuples ofm things is m n
. (Use the
notation (38)when appropriate, and be areful to make your formulas orret even
whenm=0orn=0.)
x 2. [20℄ ShowthatasmallhangetostepH1yieldsanalgorithmthatwillgenerate
allpartitionsofnintoatmost mparts.
3. [M17℄ A partition a
1
++a
m
of n into m partsa
1
a
m
is optimally
balaned ifjai ajj1for1i;jm. Provethatthereisexatlyonesuhpartition,
whenevern m1,and givea simpleformula that expressesthe jth part aj as a
funtionofj,m,andn.
4. [M22℄ (GideonEhrlih, 1974.) What is the lexiographiallysmallestpartition
ofninwhihallpartsarer? Forexample,whenn=19andr=5theansweris766.
x 5. [23℄ Designanalgorithmthatgeneratesallpartitionsofninthepart-ountform
1 :::
n
of (8). Generate them inolex order, namely inthe lexiographiorder of
n:::1, whih is equivalent to lexiographi order of the orresponding partitions
a
1 a
2
:::. ForeÆieny,maintainalsoatableoflinksl
0 l
1 :::l
n
sothat,ifthedistint
valuesofkforwhihk>0arek1<<kt,wehave
l0=k1; lk
1
=k2; :::; lk
t 1
=kt; lk
t
=0:
(Thusthe partition331wouldbe represented by 1:::7 =1020000, l0 =1, l1 =3,
andl
3
=0;theotherlinksl
2 ,l
4 ,l
5 ,l
7
anbesettoanyonvenientvalues.)
6. [20℄ Designanalgorithmtoomputeb
1 b
2
::: =(a
1 a
2
:::) ,givena
1 a
2 :::.
7. [M20℄ Supposea
1 :::a
n and a
0
1 :::a
0
n
arepartitionsofnwitha
1
a
n 0
anda 0
1
a 0
n
0,and lettheir respetiveonjugates beb
1 :::b
n
=(a
1 :::a
n )
T
,
b 0
1 :::b
0
n
=(a 0
1 :::a
0
n )
T
. Showthatb
1 :::b
n
<b 0
1 :::b
0
n
ifandonlyifa
n :::a
1
<a 0
n :::a
0
1 .
8. [15℄ When(p1:::pt;q1:::qt)is therimrepresentationofapartitiona1a2::: as
in(15)and(16),whatistheonjugatepartition(a
1 a
2 :::)
T
=b
1 b
2 :::?
9. [22℄ Ifa
1 a
2 :::a
m andb
1 b
2 :::b
m
=(a
1 a
2 :::a
m )
T
areonjugatepartitions,show
thatthemultisetsfa1+1;a2+2;:::;am+mgandfb1+1;b2+2;:::;bm+mgareequal.
10. [21℄ Twosimplekindsofbinarytreesaresometimeshelpfulforreasoningabout
partitions: (a)a tree that inludes all partitionsof allintegers, and (b) atree that
inludesallpartitionsofagivenintegern,illustratedhereforn=8:
1
11 2
111 21 3
1111 211 22 31 4
11111 2111221 311 32 41 5
11111111
2111111
221111 311111
22211 32111 41111
2222 32213311 4211 5111
332 422 431 521 611
44 53 62 71
8
(a) (b)
Deduethegeneralrulesunderlyingtheseonstrutions. Whatorderoftreetraversal
orrespondstolexiographiorderofthepartitions?
11. [M22℄ Howmanywaysare theretopay oneeuro,usingoinsworth 1,2,5,10,
20,50,and/or100ents? Whatifyouareallowedtouseatmosttwoofeahoin?
x12 . [M21℄ (L. Euler, 1750.) Use generating funtions to prove that the numberof
waystopartition n intodistint parts isthe numberofwaystopartition ninto odd
parts.Forexample,5=4+1=3+2; 5=3+1+1=1+1+1+1+1.
[Note: Thenexttwoexerisesuseombinatorialtehniquestoproveextensionsof
thisfamoustheorem.℄
x13 . [M22℄ (F.Franklin,1882.) Find aone-to-oneorrespondene betweenpartitions
ofnthathaveexatlykpartsrepeated morethanoneandpartitionsofnthathave
exatlykevenparts. (Theasek=0orrespondstoEuler'sresult.)
x14 . [M28℄ (J. J.Sylvester, 1882.) Find aone-to-oneorrespondene between parti-
tionsof n into distint partsa
1
>a
2
>>a
m
thathaveexatly k \gaps"where
aj > aj+1+1, and partitionsof n into odd parts that have exatly k+1 dierent
values. (Forexample,whenk=0thisonstrutionprovesthatthenumberofwaysto
writenasasumofonseutiveintegersisthenumberofodddivisorsofn.)
15. [M20℄ (J.J.Sylvester.) Findageneratingfuntionforthenumberofpartitions
thatare self-onjugate(namely,partitionssuhthat= T
).
16. [M21℄ Findthegeneratingfuntionforpartitionsoftraek,andsumitonkto
obtainanontrivialidentity.
17. [M26℄ A joint partition of n is a pair of sequenes (a
1
;:::;a
r
; b
1
;:::;b
s ) of
positiveintegersforwhihwehave
a
1
a
r
; b
1
>>b
s
; and a
1
++a
r +b
1
++b
s
=n:
Thusitisanordinarypartitionifs=0,andapartitionintodistintpartsifr=0.
a) Find asimpleformula forthegeneratingfuntion P
u r+s
v s
z n
,summedoverall
jointpartitionsofnwithrordinarypartsa
i
andsdistintpartsb
j .
b) Similarly,ndasimpleformulafor P
v s
z n
whenthesumisoveralljointpartitions
thathaveexatlyr+s=ttotalparts,giventhevalueoft.
) Whatidentitydoyoudedue?
x18 . [M23℄ (Doron Zeilberger.) Show that there is a one-to-oneorrespondene be-
tweenpairsofintegersequenes(a
1
;a
2
;:::;a
r
; b
1
;b
2
;:::;b
s
)suhthat
a
1 a
2
a
r
; b
1
>b
2
>>b
s
;
andpairsofintegersequenes(
1
;
2
;:::;
r+s
; d
1
;d
2
;:::;d
r+s
)suhthat
12 r+s; dj2f0;1g for1jr+s;
relatedbythemultisetequations
fa
1
;a
2
;:::;a
r g=f
j jd
j
=0g and fb
1
;b
2
;:::;b
s g=f
j
+r+s jjd
j
=1g:
Consequentlyweobtaintheinterestingidentity
X
a
1 a
r
>0
b
1
>>b
s
>0 u
r+s
v s
z a
1 ++a
r +b
1 ++b
s
= X
1
t
>0
d1;:::;dt2f0;1g u t
v d
1 ++d
t
z
1 ++
t +(t 1)d
1 ++d
t 1
:
19. [M21℄ (E.Heine,1847.) Provethefour-parameteridentity
1
Y
m=1
(1 wxz m
)(1 wyz m
)
(1 wz m
)(1 wxyz m
)
= 1
X
k=0 w
k
(x 1)(x z):::(x z k 1
)(y 1)(y z):::(y z k 1
)z k
(1 z)(1 z 2
):::(1 z k
)(1 wz)(1 wz 2
):::(1 wz k
) .
Hint: Carryoutthesumovereitherkorlintheformula
X
k;l0 u
k
v l
z kl
(z az)(z az 2
):::(z az k
)
(1 z)(1 z 2
):::(1 z k
)
(z bz)(z bz 2
):::(z bz l
)
(1 z)(1 z 2
):::(1 z l
)
andonsiderthesimpliationsthatourwhen b=auz.
x20 . [M21℄ Approximatelyhowlongdoesittaketoompute atableof thepartition
numbersp(n)for1nN,usingEuler'sreurrene(20)?
21. [M21℄ (L.Euler.) Letq(n)bethenumberofpartitionsintodistintparts. What
isagoodwaytoomputeq(n)ifyoualreadyknowthevaluesofp(1),:::,p(n)?
22. [HM21℄ (L. Euler.) Let (n) be the sumof allpositive divisors of thepositive
integern. Thus,(n)=n+1when nis prime,and(n)anbe signiantlylarger
thannwhennishighlyomposite.Provethat,inspiteofthisratherhaotibehavior,
(n)satisesalmostthesamereurrene(20)asthepartitionnumbers:
(n)=(n 1)+(n 2) (n 5) (n 7)+(n 12)+(n 15)
forn1,exeptthatwhenatermontherightis`(0)'thevalue`n'isusedinstead.
For example, (11) = 1+11 = (10)+(9) (6) (4) = 18+13 12 7;
(12)=1+2+3+4+6+12=(11)+(10) (7) (5)+12=12+18 8 6+12.
23. [HM25℄ UseJaobi's tripleprodutidentity (19)to prove another formula that
hedisovered:
1
Y
k=1 (1 z
k
) 3
= 1 3z+5z 3
7z 6
+9z 10
= 1
X
n=0 ( 1)
n
(2n+1)z (
n+1
2 )
:
24. [M26℄ (S.Ramanujan,1919.) LetA(z)= Q
1
k=1 (1 z
k
) 4
.
a) Provethat[z n
℄A(z)isamultipleof5whennmod5=4.
b) Prove that [z n
℄A(z)B(z) 5
has the sameproperty, if B is any power series with
integeroeÆients.
) Thereforep(n)isamultipleof5whennmod5=4.
25. [HM27℄ Improveon(22)byusing(a)Euler'ssummationformulaand(b) Mellin
transformsto estimate lnP(e t
). Hint: The dilogarithm funtion Li
2
(x) = x=1 2
+
x 2
=2 2
+x 3
=3 2
+ satisesLi2(x)+Li2(1 x)=(2) (lnx)ln(1 x).
26. [HM22℄ Inexerises5.2.2{44and5.2.2{51westudiedtwowaystoprovethat
1
X
k=1 e
k 2
=n
= 1
2 (
p
n 1)+O(n M
) forallM>0.
ShowthatPoisson'ssummationformulagivesamuhstrongerresult.
27. [HM23℄ Evaluate(29)andompletethealulationsleadingtoTheoremD.
28. [HM42℄ (D.H. Lehmer.) Show that theHardy{Ramanujan{Rademaher oeÆ-
ientsA
k
(n)denedin(34)havethefollowingremarkableproperties:
a) Ifkisodd,thenA
2k
(km+4n+(k 2
1)=8)=A
2 (m)A
k (n).
b) Ifpisprime,p e
>2,andk?2p,then
Ap e
k(k 2
m+p 2e
n (k 2
+p 2e
1)=24) = ( 1) [p
e
=4℄
Ap
e(m)Ak(n):
Inthis formula k 2
+p 2e
1 is a multiple of 24 ifp or k is divisible by 2 or 3;
otherwisedivisionby24shouldbedonemodulop e
k.
) Ifpisprime,j Ap e(n)j
<2 [p>2℄
p e=2
.
d) Ifp isprime,A
p e
(n)6=0ifand onlyif1 24nis aquadrati residuemodulo p
andeithere=1or24nmodp6=1.
e) TheprobabilitythatAk(n)=0,whenk isdivisiblebyexatlytprimes5and
nisarandominteger,isapproximately1 2 t
.
x29 . [M16℄ Generalizing(41),evaluatethesum P
a1a2am1 z
a
1
1 z
a
2
2 :::z
am
m .
30. [M17℄ Findlosedformsforthesums
(a) X
k0
n km
m 1
and (b) X
k0
n
m k
(whiharenite,beausethetermsbeingsummedarezerowhenk islarge).
31. [M24℄ (A.DeMorgan, 1843.) Show that
n
2
=bn=2 and
n
3
=b(n 2
+6)=12;
ndasimilarformulafor
n
4
.
32. [M15℄ Provethat
n
m
p(n m)forallm;n0. Whendoesequalityhold?
33. [HM20℄ Usethefatthatthereareexatly n 1
m 1
ompositions ofnintomparts,
Eq.7.2.1.3{(9),toprovealowerboundon
n
m
. Thensetm=b p
ntoobtainanele-
mentarylowerboundonp(n).
x34 . [HM21℄ Showthat
n m(m 1)=2
m
isthenumberofpartitionsofninto mdistint
parts. Consequently
n
m
= n
m 1
m!(m 1)!
1+O
m 3
n
whenmn 1=3
.
35. [HM21℄ In the Erd}os{Lehner probability distribution (43), what value of x is
(a)mostprobable?(b)themedian? ()themean?(d)Whatisthestandarddeviation?
36. [HM24℄ Provethekeyestimate(47)thatisneededinTheoremE.
37. [M22℄ Prove the inlusion-exlusion braketing lemma (48), by analyzing how
manytimesapartitionthathasexatlyqdierentpartsexeedingmisountedinthe
rthpartialsum.
38. [M20℄ What isthegenerating funtionforthepartitionsofn thathaveexatly
mparts,andlargestpartl?
x39 . [M25℄ (F.Franklin.) GeneralizingTheoremC,showthat,for0km,
[z n
℄ (1 z
l+1
):::(1 z l+k
)
(1 z)(1 z 2
):::(1 z m
)
isthenumberofpartitionsa
1 a
2
::: ofnintomorfewerpartswiththepropertythat
a1ak+1+l.
40. [M22℄ (A.Cauhy.) Whatisthegeneratingfuntionforpartitionsintomparts,
alldistint andlessthanl?
41. [HM42℄ Extend the Hardy{Ramanujan{Rademaher formula (32) to obtain a
onvergentseriesforpartitionsofnintoatmostmparts,withnopartexeedingl.
42. [HM42℄ Find the limiting shape, analogous to (49), forrandom partitions of n
intoatmost p
nparts,withnopartexeeding' p
n,assumingthat'>1.
43. [M21℄ Givennandk,howmanypartitionsofnhavea1>a2 >>ak?
x44 . [M22℄ Howmanypartitionsofnhavetheirtwosmallestpartsequal?
45. [HM21℄ Computetheasymptotivalueofp(n 1)=p(n),withrelativeerrorO(n 2
).
46. [M20℄ Inthetext'sanalysisofAlgorithmP,whihislarger,T 0
2 (n)orT
00
2 (n)?
x47 . [HM22℄ (A. Nijenhuis and H. S. Wilf, 1975.) The following simple algorithm,
based ona tableof the partition numbers p(0), p(1),:::,p(n), generates a random
partitionofnusingthepart-ountrepresentation1:::nof(8).Provethatitprodues
eahpartitionwithequalprobability.
N1.[Initialize.℄ Setm nand1:::n 0:::0.
N2.[Done?℄ Terminateifm=0.
N3.[Generate.℄ GeneratearandomintegerM intherange0M <mp(m).
N4.[Choose parts.℄ Set s 0. Then for j = 1, 2, :::, n and fork = 1, 2,
:::,bm=j,repeatedlysets s+kp(m jk)untils>M.
N5.[Update.℄ Set
k
k
+j,m m jk,andreturntoN2.
Hint: StepN4,whihisbasedontheidentity
m
X
j=1 bm=j
X
k=1
kp(m jk) = mp(m);
hooseseahpartiularpairofvalues(j;k)withprobabilitykp(m jk)=(mp(m)).
48. [HM40℄ Analyzetherunningtimeofthealgorithminthepreviousexerise.
x49 . [HM26℄ (a)WhatisthegeneratingfuntionF(z)forthesumofthesmallestparts
ofallpartitionsofn? (Theseriesbeginsz+3z 2
+5z 3
+9z 4
+12z 5
+.)
(b)Findtheasymptotivalueof[z n
℄F(z),withrelativeerrorO(n 1
).
50. [HM33℄ Let(m)=m(2m)inthereurrene(56),(57).
a) Provethatm(m+k)=m k+(k)for0km.
b) Consequently(58)holdsformn2mif(m)<3p(m)forallm.
) Showthat(m) misthesumoftheseond-smallestpartsofallpartitionsofm.
d) Findaone-to-oneorrespondenebetweenallpartitionsofnwithseond-smallest
partkandallpartitionsofnumbersnwithsmallestpartk+1.
e) Desribethegeneratingfuntion P
m0 (m)z
m
.
f) Conludethat(m)<3p(m)forallm0.
51. [M46℄ MakeadetailedanalysisofAlgorithmH.
x52 . [M21℄ Whatis themillionthpartition generatedbyAlgorithmP whenn =64?
Hint: p(64)=1741630=1000000+
77
13
+
60
10
+
47
8
+
35
5
+
27
3
+
22
2
+
18
1
+
15
0
.
x53 . [M21℄ Whatis the millionthpartitiongenerated by AlgorithmH when m=32
andn=100? Hint: 999999=
80
12
+
66
11
+
50
7
+
41
6
+
33
5
+
26
4
+
21
4
.
x54 . [M30℄ Thepartition=a1a2::: issaidtomajorize thepartition=b1b2:::,
writtenor,ifa
1
++a
k b
1
++b
k
forallk0.
a) Trueorfalse:implies(lexiographially).
b) Trueorfalse:implies T
T
.
) Showthat any twopartitionsofn have agreatestlowerbound ^ suhthat
andifandonlyif^. Explainhowtoompute^.
d) Similarly,explainhowtoomputealeastupperbound_suhthatand
ifandonlyif_.
e) Ifhaslpartsandhasmparts,howmanypartsdo^and_ have?
f) Trueor false: If hasdistint partsand hasdistint parts,thenso do^
and_.
x55 . [M37℄ Continuingthe previous exerise, say that overs if , 6=,
and implies=or=. For example,Fig.32illustrates theovering
relationsbetweenpartitionsof12.
a) Let us write if = a
1 a
2
::: and = b
1 b
2
::: are partitions for whih
b
k
=a
k
[k=l℄+[k=l+1℄forallk1andsomel1.Provethatovers
ifandonlyifor T
T
.
b) Show that there is an easy way to tell if overs by looking at the rim
representationsofand.
) Letn= n
2
2
+ n
1
1
wheren2>n10. Showthatnopartitionofnoversmore
thann
2
2partitions.
d) Saythat thepartition isminimal ifthereisnopartitionwith. Prove
thatisminimalifandonlyif T
hasdistintparts.
e) Suppose=
0
1
k
and= 0
0
0
1
0
k
0,where
k and
0
k 0
areminimalpartitions. Provethatk=k 0
and
k
= 0
k 0
.
f) Explainhowtoomputethelexiographiallysmallestpartitionintodistintparts
thatmajorizesagivenpartition.
g) Desriben,thelexiographiallysmallestpartitionofnintodistintparts.What
isthelengthofallpathsn 1
=
0
1
T
n
?