MVR4
I/UnrankKSubsets:6%%"rG%"nG%"kG6"F(F(@)529$""!1-%)binomialG6$9%9&F,-%'RETURNG6#
%2r~is~out~of~rangeG/F2F--F56#7"2F,-F06$,&F2"""!""F@F3-F56#-F"6%F,F?F3-F56#7$-%
#opG6#-F"6%,&F,F@F=FAF?,&F3F@FAF@F2F(F(6",
I*CountRuns:6$F&F'F(F(F(@)52F,F@2F2F@-F56#F-2F,F2FX/F,F@-F56#F@-F56#,&*&F2F@-FQ
6$,&F,F@FAF@F2F@F@*&,(F,F@F2FAF@F@F@-FQ6$F^oF?F@F@F(F(FP,
I/RankPartitions:6%%#ssGF&F'6#%(lastEltGF(F(C%@$/&F,Fgn,(F2F@F3FAF@F@FX>8$-%%no
psG6#F,@%/&F,6#F_pF@-F56#-Fco6%7#-FJ6#&F,6#;F@,&F_pF@FAF@F?FO-F56#,&-%0CountPar
titionsG6$F?FOF@-Fco6%-%$mapG6$:6#%"xGF(6$%)operatorG%&arrowGF(F^oF(F(F,,&F2F@F
3FAF3F@F(F(FP,
I1RandomPermCycles:FS6'%$rnoGF%%%eastG%%westG%#rnGF(F(@%Fen@%0F2F@F9-F56#7#F@C$
>F_p,$-%%randGF(#F@".++++++"@%2F_p*&-%(StirCycGFboF@-F\t6$F,F2FAC$>8&-FdrFbo-F5
6#7$-FJ6#FatF,C&>8(-Fes6#;F@F^o>8%-FjtF(>8'-FdrF]o-F56#-%'subsopG6$/F_uF,7$-FJ6
#Fbu&Fbu6#F_uF(F(FP,
I,IntegerPtns:FSF(F(F(@'5FUFZFX3Fen/F2F@Ffn-F56#,&-F_vFboF@-F_v6$,&F,F@F2FAF2F@
F(F(FP,
I2UnrankIntegerPtns:F$6#%#uuGF(F(@)5F+1-F_vF1F,F43Fdv/F3F@F^s2F,-F_vFgqC$>F_p-F
\w6%F,F?FO-F56#7$,&&F_pFgnF@F@F@-FJ6$;""#-FapFfpF_pC$>F_p-F\w6%,&F,F@FgwFAFcrF3
-F56#7$F`x-FJFfpF(F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deredPtnsGF1F\fl-F56#Fa_l-F56#-%0ListIntegerPtns
GF1F(F(FP,
I)RandRuns:FS6$FgrF^_lF(F(C%>F_p-Fes6#;F@-FQF^t>F_u-Fb_lF^t-F56#&F_u6#-F_pF(F(F
(FP,
I0CountPartitions:FSF(F(F(@'FbvFXFenFfn-F56#,&-FfqFboF@-FfqFjvF@F(F(FP,
I/RankPermCycles:Feo6%Ffam%#ttGF_wF(F(@'5/F3F2/F3F-FX/Fa]mF2-F56#-Fbdl6%-Fgu6$/
F2%%NULLGF,F?FOC(-%'memberG6%F2F,F_p>F_uF,>&F_uFfp&F_uF\dl>F_u7#-FJ6$;F@F?F_u>F
at-FbdlFf`m-F56#,(FatF@*&FaqF@-F\tF>F@F@-F\tFgqF@F(F(F(,
I&hello:F(F(F(F(CQ-%'lprintG6#%!G-F_anF(-%&printG6#%EThis~is~the~Maple~package~
"EastWest"G-Fdan6#%:Version~of~August~7,~1999GF^an-Fdan6#%YIt~accompanies~the~l
ecture~notes~"East~Side,~West~Side,"G-Fdan6#%0by~Herbert~WilfGF^anF^an-Fdan6#%h
nProgrammed~by~H.~Wilf~with~the~assistance~of~Joanna~NordlichtG-Fdan6#%]pBoth~t
he~notes~and~this~package~can~be~downloaded~from~<http://www.cis.upenn.edu>.GF^
anF^an-F_an6#%[r~This~package~performs~any~of~42~tasks,~namely:~any~one~of~six~
functions~on~any~of~seven~combinatorial~families.GFban-F_an6#%8~The~six~functio
ns~are:GFban-F_an6#%]o~~1.~Count~-~~returns~the~number~of~objects~of~the~specif
ied~size~G-F_an6#%T~~~~~~~~~~~~~~~~~Call:~~Count(family~number,~n,~k):G-F_an6#%
^o~~2.~List~~-~~returns~a~list~of~all~objects~of~the~specified~size,~G-F_an6#%e
n~~~~~~~~~~~~~~in~the~standard~encoding~for~the~family~~~~~G-F_an6#%S~~~~~~~~~~
~~~~~~~Call:~~List(family~number,~n,~k):G-F_an6#%\o~~3.~Random-~~returns~a~sing
le~object,~chosen~uniformly~at~randomG-F_an6#%in~~~~~~~~~~~~~~from~the~members~
of~the~family~of~the~given~sizeG-F_an6#%U~~~~~~~~~~~~~~~~~Call:~~Random(family~
number,~n,~k):G-F_an6#%]o~~4.~Rank~~-~~returns~the~rank~of~the~input~object~on~
the~list~of~G-F_an6#%do~~~~~~~~~~~~~~all~members~of~the~family~of~the~size~of~t
he~input~object~~G-F_an6#%\o~~~~~~~~~~~~~~~~~Call:~~Rank(family~number,~object~
to~be~ranked):G-F_an6#%[o~~5.~Unrank-~~returns~the~member~of~the~family~of~give
n~rank~in~G-F_an6#%\o~~~~~~~~~~~~~~the~list~of~all~members~of~the~family~of~giv
en~sizeG-F_an6#%en~~~~~~~~~~~~~~~~~Call:~~Unrank(family~number,~n,~k,~rank):G-F
_an6#%[o~~6.~Successor-~returns~the~object~that~immediately~follows~the~G-F_an6
#%\p~~~~~~~~~~~~~~given~object~on~the~list~of~all~members~of~the~family~of~give
n~sizeG-F_an6#%hn~~~~~~~~~~~~~~~~~Call:~~Successor(family~number,n,k,~object):G
F^an-F_an6#%V~The~seven~combinatorial~families/their~encodings~areGFban-F_an6#%
L~~1.~k-subsets~of~an~n-set/list~of~members~G-F_an6#%hn~~2.~permutations~of~n~l
etters~with~k~cycles/array~of~values~G-F_an6#%co~~3.~partitions~of~a~set~of~n~e
lements~with~k~classes/class~vector~arrayG-F_an6#%in~~4.~partitions~of~the~inte
ger~n~into~k~parts/array~of~parts~~G-F_an6#%\p~~5.~ordered~partitions~of~the~in
teger~n~into~k~nonnegative~parts/array~of~parts~G-F_an6#%in~~6.~permutations~of
~n~letters~with~k~runs~up/array~of~values~G-F_an6#%co~~7.~partitions~of~the~int
eger~n~whose~largest~part~is~k/array~of~parts~GF^anF^anFh]lF(F(F(,
I0ListOrderedPtns:FS6'F^\mF_\mFhrFirFdyF(F(C&>F_p:6#%"sGF(F`rF(7$F-Ff\mF(F(>F_u
:F]hnF(F`rF(7$,&F@F@F\pF@-FJ6$;FdxF`pF,F(F(@'Fdv-F56#7#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