<s>
In	O
combinatorics	O
,	O
the	O
twelvefold	B-Algorithm
way	I-Algorithm
is	O
a	O
systematic	O
classification	O
of	O
12	O
related	O
enumerative	O
problems	O
concerning	O
two	O
finite	O
sets	O
,	O
which	O
include	O
the	O
classical	O
problems	O
of	O
counting	O
permutations	B-Algorithm
,	O
combinations	O
,	O
multisets	B-Language
,	O
and	O
partitions	O
either	O
of	O
a	O
set	O
or	O
of	O
a	O
number	O
.	O
</s>
<s>
Let	O
and	O
be	O
the	O
cardinality	B-Application
of	O
the	O
sets	O
.	O
</s>
<s>
is	O
surjective	B-Algorithm
:	O
for	O
each	O
in	O
there	O
must	O
be	O
at	O
least	O
one	O
in	O
such	O
that	O
,	O
thus	O
each	O
will	O
occur	O
at	O
least	O
once	O
in	O
the	O
image	O
of	O
.	O
</s>
<s>
(	O
The	O
condition	O
"	O
is	O
bijective	B-Algorithm
"	O
is	O
only	O
an	O
option	O
when	O
;	O
but	O
then	O
it	O
is	O
equivalent	O
to	O
both	O
"	O
is	O
injective	O
"	O
and	O
"	O
is	O
surjective	B-Algorithm
"	O
.	O
)	O
</s>
<s>
equality	O
up	O
to	O
a	O
permutation	B-Algorithm
of	O
;	O
</s>
<s>
equality	O
up	O
to	O
a	O
permutation	B-Algorithm
of	O
;	O
</s>
<s>
equality	O
up	O
to	O
permutations	B-Algorithm
of	O
and	O
.	O
</s>
<s>
Counting	O
n-permutations	O
(	O
i.e.	O
,	O
partial	B-Algorithm
permutations	I-Algorithm
or	O
sequences	B-Algorithm
without	I-Algorithm
repetition	I-Algorithm
)	O
of	O
X	O
is	O
equivalent	O
to	O
counting	O
injective	O
functions	O
.	O
</s>
<s>
Counting	O
n-combinations	O
of	O
X	O
is	O
equivalent	O
to	O
counting	O
injective	O
functions	O
up	O
to	O
permutations	B-Algorithm
of	O
N	O
.	O
</s>
<s>
Counting	O
permutations	B-Algorithm
of	O
the	O
set	O
X	O
is	O
equivalent	O
to	O
counting	O
injective	O
functions	O
when	O
n	O
=	O
x	O
,	O
and	O
also	O
to	O
counting	O
surjective	B-Algorithm
functions	I-Algorithm
when	O
.	O
</s>
<s>
Counting	O
multisets	B-Language
of	O
size	O
n	O
(	O
also	O
known	O
as	O
n-combinations	O
with	O
repetitions	O
)	O
of	O
elements	O
in	O
X	O
is	O
equivalent	O
to	O
counting	O
all	O
functions	O
up	O
to	O
permutations	B-Algorithm
of	O
N	O
.	O
</s>
<s>
Counting	O
partitions	O
of	O
the	O
set	O
N	O
into	O
x	O
subsets	O
is	O
equivalent	O
to	O
counting	O
all	O
surjective	B-Algorithm
functions	I-Algorithm
up	O
to	O
permutations	B-Algorithm
of	O
X	O
.	O
</s>
<s>
Counting	O
compositions	O
of	O
the	O
number	O
n	O
into	O
x	O
parts	O
is	O
equivalent	O
to	O
counting	O
all	O
surjective	B-Algorithm
functions	I-Algorithm
up	O
to	O
permutations	B-Algorithm
of	O
N	O
.	O
</s>
<s>
The	O
various	O
problems	O
in	O
the	O
twelvefold	B-Algorithm
way	I-Algorithm
may	O
be	O
considered	O
from	O
different	O
points	O
of	O
view	O
.	O
</s>
<s>
Traditionally	O
many	O
of	O
the	O
problems	O
in	O
the	O
twelvefold	B-Algorithm
way	I-Algorithm
have	O
been	O
formulated	O
in	O
terms	O
of	O
placing	O
balls	O
in	O
boxes	O
(	O
or	O
some	O
similar	O
visualization	O
)	O
instead	O
of	O
defining	O
functions	O
.	O
</s>
<s>
Requiring	O
in	O
addition	O
ƒ	O
to	O
be	O
injective	O
means	O
forbidding	O
to	O
put	O
more	O
than	O
one	O
ball	O
in	O
any	O
one	O
box	O
,	O
while	O
requiring	O
ƒ	O
to	O
be	O
surjective	B-Algorithm
means	O
insisting	O
that	O
every	O
box	O
contain	O
at	O
least	O
one	O
ball	O
.	O
</s>
<s>
Counting	O
modulo	O
permutations	B-Algorithm
of	O
N	O
or	O
X	O
is	O
reflected	O
by	O
calling	O
the	O
balls	O
or	O
the	O
boxes	O
,	O
respectively	O
,	O
"	O
indistinguishable	O
"	O
.	O
</s>
<s>
This	O
possibility	O
of	O
transformation	O
is	O
formalized	O
by	O
the	O
action	O
by	O
permutations	B-Algorithm
.	O
</s>
<s>
From	O
the	O
perspective	O
of	O
sampling	O
,	O
the	O
column	O
labeled	O
"	O
Surjective	B-Algorithm
f	O
"	O
is	O
somewhat	O
strange	O
:	O
Essentially	O
,	O
we	O
keep	O
sampling	O
with	O
replacement	O
until	O
we	O
've	O
chosen	O
each	O
item	O
at	O
least	O
once	O
.	O
</s>
<s>
Note	O
that	O
in	O
all	O
"	O
surjective	B-Algorithm
"	O
cases	O
,	O
the	O
number	O
of	O
sets	O
of	O
choices	O
is	O
zero	O
unless	O
.	O
</s>
<s>
The	O
labelling	O
and	O
selection	O
points	O
of	O
view	O
are	O
not	O
well	O
compatible	O
with	O
permutation	B-Algorithm
of	O
the	O
elements	O
of	O
X	O
,	O
since	O
this	O
changes	O
the	O
labels	O
or	O
the	O
selection	O
;	O
on	O
the	O
other	O
hand	O
the	O
grouping	O
point	O
of	O
view	O
does	O
not	O
give	O
complete	O
information	O
about	O
the	O
configuration	O
unless	O
the	O
elements	O
of	O
X	O
may	O
be	O
freely	O
permuted	O
.	O
</s>
<s>
Without	O
the	O
requirement	O
,	O
one	O
and	O
the	O
same	O
element	O
of	O
X	O
may	O
occur	O
multiple	O
times	O
in	O
the	O
selection	O
,	O
and	O
the	O
result	O
is	O
a	O
multiset	B-Language
of	O
size	O
n	O
of	O
elements	O
from	O
X	O
,	O
also	O
called	O
an	O
n-multicombination	O
or	O
n-combination	O
with	O
repetition	O
.	O
</s>
<s>
The	O
requirement	O
that	O
ƒ	O
be	O
surjective	B-Algorithm
,	O
from	O
the	O
viewpoint	O
of	O
labelling	O
elements	O
of	O
N	O
,	O
means	O
that	O
every	O
label	O
is	O
to	O
be	O
used	O
at	O
least	O
once	O
;	O
from	O
the	O
viewpoint	O
of	O
selection	O
from	O
X	O
,	O
it	O
means	O
that	O
every	O
element	O
of	O
X	O
must	O
be	O
included	O
in	O
the	O
selection	O
at	O
least	O
once	O
.	O
</s>
<s>
Labelling	O
with	O
surjection	B-Algorithm
is	O
equivalent	O
to	O
a	O
grouping	O
of	O
elements	O
of	O
N	O
followed	O
by	O
labeling	O
each	O
group	O
by	O
an	O
element	O
of	O
X	O
,	O
and	O
is	O
accordingly	O
somewhat	O
more	O
complicated	O
to	O
describe	O
mathematically	O
.	O
</s>
<s>
When	O
viewing	O
ƒ	O
as	O
a	O
grouping	O
of	O
the	O
elements	O
of	O
N	O
(	O
which	O
assumes	O
one	O
identifies	O
under	O
permutations	B-Algorithm
of	O
X	O
)	O
,	O
requiring	O
ƒ	O
to	O
be	O
surjective	B-Algorithm
means	O
the	O
number	O
of	O
groups	O
must	O
be	O
exactly	O
x	O
.	O
</s>
<s>
When	O
in	O
addition	O
one	O
identifies	O
under	O
permutations	B-Algorithm
of	O
N	O
,	O
this	O
amounts	O
to	O
forgetting	O
the	O
groups	O
themselves	O
but	O
retaining	O
only	O
their	O
sizes	O
.	O
</s>
<s>
These	O
sizes	O
moreover	O
do	O
not	O
come	O
in	O
any	O
definite	O
order	O
,	O
while	O
the	O
same	O
size	O
may	O
occur	O
more	O
than	O
once	O
;	O
one	O
may	O
choose	O
to	O
arrange	O
them	O
into	O
a	O
weakly	O
decreasing	O
list	O
of	O
numbers	O
,	O
whose	O
sum	O
is	O
the	O
number	O
n	O
.	O
This	O
gives	O
the	O
combinatorial	O
notion	O
of	O
a	O
partition	O
of	O
the	O
numbern	O
,	O
into	O
exactly	O
x	O
(	O
for	O
surjective	B-Algorithm
ƒ	O
)	O
or	O
at	O
most	O
x	O
(	O
for	O
arbitrary	O
ƒ	O
)	O
parts	O
.	O
</s>
<s>
Formulas	O
for	O
the	O
different	O
cases	O
of	O
the	O
twelvefold	B-Algorithm
way	I-Algorithm
are	O
summarized	O
in	O
the	O
following	O
table	O
;	O
each	O
table	O
entry	O
links	O
to	O
a	O
subsection	O
below	O
explaining	O
the	O
formula	O
.	O
</s>
<s>
Surjective	B-Algorithm
f	O
After	O
we	O
choose	O
an	O
item	O
,	O
we	O
put	O
it	O
back	O
,	O
so	O
we	O
might	O
choose	O
it	O
again	O
—	O
but	O
at	O
the	O
end	O
,	O
we	O
have	O
to	O
end	O
up	O
having	O
chosen	O
each	O
item	O
at	O
least	O
once	O
.	O
</s>
<s>
This	O
case	O
is	O
equivalent	O
to	O
counting	O
sequences	O
of	O
n	O
distinct	O
elements	O
of	O
X	O
,	O
also	O
called	O
n-permutations	O
of	O
X	O
,	O
or	O
sequences	B-Algorithm
without	I-Algorithm
repetitions	I-Algorithm
;	O
again	O
this	O
sequence	O
is	O
formed	O
by	O
the	O
n	O
images	O
of	O
the	O
elements	O
of	O
N	O
.	O
This	O
case	O
differs	O
from	O
the	O
one	O
of	O
unrestricted	O
sequences	O
in	O
that	O
there	O
is	O
one	O
choice	O
fewer	O
for	O
the	O
second	O
element	O
,	O
two	O
fewer	O
for	O
the	O
third	O
element	O
,	O
and	O
so	O
on	O
.	O
</s>
<s>
This	O
case	O
is	O
equivalent	O
to	O
counting	O
subsets	O
with	O
n	O
elements	O
of	O
X	O
,	O
also	O
called	O
n-combinations	O
of	O
X	O
:	O
among	O
the	O
sequences	O
of	O
n	O
distinct	O
elements	O
of	O
X	O
,	O
those	O
that	O
differ	O
only	O
in	O
the	O
order	O
of	O
their	O
terms	O
are	O
identified	O
by	O
permutations	B-Algorithm
of	O
N	O
.	O
Since	O
in	O
all	O
cases	O
this	O
groups	O
together	O
exactly	O
n	O
!	O
</s>
<s>
This	O
case	O
is	O
equivalent	O
to	O
counting	O
multisets	B-Language
with	O
n	O
elements	O
from	O
X	O
(	O
also	O
called	O
n-multicombinations	O
)	O
.	O
</s>
<s>
The	O
reason	O
is	O
that	O
for	O
each	O
element	O
of	O
X	O
it	O
is	O
determined	O
how	O
many	O
elements	O
of	O
N	O
are	O
mapped	O
to	O
it	O
by	O
f	O
,	O
while	O
two	O
functions	O
that	O
give	O
the	O
same	O
such	O
"	O
multiplicities	O
"	O
to	O
each	O
element	O
of	O
X	O
can	O
always	O
be	O
transformed	O
into	O
another	O
by	O
a	O
permutation	B-Algorithm
of	O
N	O
.	O
The	O
formula	O
counting	O
all	O
functions	O
is	O
not	O
useful	O
here	O
,	O
because	O
the	O
number	O
of	O
them	O
grouped	O
together	O
by	O
permutations	B-Algorithm
of	O
N	O
varies	O
from	O
one	O
function	O
to	O
another	O
.	O
</s>
<s>
This	O
case	O
is	O
equivalent	O
to	O
counting	O
multisets	B-Language
with	O
n	O
elements	O
from	O
X	O
,	O
for	O
which	O
each	O
element	O
of	O
X	O
occurs	O
at	O
least	O
once	O
.	O
</s>
<s>
The	O
correspondence	O
between	O
functions	O
and	O
multisets	B-Language
is	O
the	O
same	O
as	O
in	O
the	O
previous	O
case	O
,	O
and	O
the	O
surjectivity	B-Algorithm
requirement	O
means	O
that	O
all	O
multiplicities	O
are	O
at	O
least	O
one	O
.	O
</s>
<s>
Note	O
that	O
when	O
n	O
x	O
there	O
are	O
no	O
surjective	B-Algorithm
functions	I-Algorithm
at	O
all	O
(	O
a	O
kind	O
of	O
"	O
empty	O
pigeonhole	O
"	O
principle	O
)	O
;	O
this	O
is	O
taken	O
into	O
account	O
in	O
the	O
formula	O
,	O
by	O
the	O
convention	O
that	O
binomial	O
coefficients	O
are	O
always	O
0	O
if	O
the	O
lower	O
index	O
is	O
negative	O
.	O
</s>
<s>
The	O
form	O
of	O
the	O
result	O
suggests	O
looking	O
for	O
a	O
manner	O
to	O
associate	O
a	O
class	O
of	O
surjective	B-Algorithm
functions	I-Algorithm
directly	O
to	O
a	O
subset	O
of	O
elements	O
chosen	O
from	O
a	O
total	O
of	O
,	O
which	O
can	O
be	O
done	O
as	O
follows	O
.	O
</s>
<s>
First	O
choose	O
a	O
total	O
ordering	O
of	O
the	O
sets	O
N	O
and	O
X	O
,	O
and	O
note	O
that	O
by	O
applying	O
a	O
suitable	O
permutation	B-Algorithm
of	O
N	O
,	O
every	O
surjective	B-Algorithm
function	I-Algorithm
can	O
be	O
transformed	O
into	O
a	O
unique	O
weakly	O
increasing	O
(	O
and	O
of	O
course	O
still	O
surjective	B-Algorithm
)	O
function	O
.	O
</s>
<s>
If	O
one	O
connects	O
the	O
elements	O
of	O
N	O
in	O
order	O
by	O
arcs	O
into	O
a	O
linear	O
graph	O
,	O
then	O
choosing	O
any	O
subset	O
of	O
arcs	O
and	O
removing	O
the	O
rest	O
,	O
one	O
obtains	O
a	O
graph	O
with	O
x	O
connected	O
components	O
,	O
and	O
by	O
sending	O
these	O
to	O
the	O
successive	O
elements	O
of	O
X	O
,	O
one	O
obtains	O
a	O
weakly	O
increasing	O
surjective	B-Algorithm
function	I-Algorithm
;	O
also	O
the	O
sizes	O
of	O
the	O
connected	O
components	O
give	O
a	O
composition	O
of	O
n	O
into	O
x	O
parts	O
.	O
</s>
<s>
In	O
this	O
case	O
we	O
consider	O
sequences	O
of	O
n	O
distinct	O
elements	O
from	O
X	O
,	O
but	O
identify	O
those	O
obtained	O
from	O
one	O
another	O
by	O
applying	O
to	O
each	O
element	O
a	O
permutation	B-Algorithm
of	O
X	O
.	O
</s>
<s>
It	O
is	O
easy	O
to	O
see	O
that	O
two	O
different	O
such	O
sequences	O
can	O
always	O
be	O
identified	O
:	O
the	O
permutation	B-Algorithm
must	O
map	O
term	O
i	O
of	O
the	O
first	O
sequence	O
to	O
term	O
i	O
of	O
the	O
second	O
sequence	O
,	O
and	O
since	O
no	O
value	O
occurs	O
twice	O
in	O
either	O
sequence	O
these	O
requirements	O
do	O
not	O
contradict	O
each	O
other	O
;	O
it	O
remains	O
to	O
map	O
the	O
elements	O
not	O
occurring	O
in	O
the	O
first	O
sequence	O
bijectively	O
to	O
those	O
not	O
occurring	O
in	O
the	O
second	O
sequence	O
in	O
an	O
arbitrary	O
way	O
.	O
</s>
<s>
This	O
case	O
is	O
reduced	O
to	O
the	O
previous	O
one	O
:	O
since	O
all	O
sequences	O
of	O
n	O
distinct	O
elements	O
from	O
X	O
can	O
already	O
be	O
transformed	O
into	O
each	O
other	O
by	O
applying	O
a	O
permutation	B-Algorithm
of	O
X	O
to	O
each	O
of	O
their	O
terms	O
,	O
also	O
allowing	O
reordering	O
of	O
the	O
terms	O
does	O
not	O
give	O
any	O
new	O
identifications	O
;	O
the	O
number	O
remains	O
.	O
</s>
<s>
Indeed	O
,	O
for	O
any	O
surjective	B-Algorithm
function	I-Algorithm
,	O
the	O
relation	O
of	O
having	O
the	O
same	O
image	O
under	O
f	O
is	O
such	O
an	O
equivalence	O
relation	O
,	O
and	O
it	O
does	O
not	O
change	O
when	O
a	O
permutation	B-Algorithm
of	O
X	O
is	O
subsequently	O
applied	O
;	O
conversely	O
one	O
can	O
turn	O
such	O
an	O
equivalence	O
relation	O
into	O
a	O
surjective	B-Algorithm
function	I-Algorithm
by	O
assigning	O
the	O
elements	O
of	O
X	O
in	O
some	O
manner	O
to	O
the	O
x	O
equivalence	O
classes	O
.	O
</s>
<s>
For	O
each	O
surjective	B-Algorithm
function	I-Algorithm
,	O
its	O
orbit	O
under	O
permutations	B-Algorithm
of	O
X	O
has	O
x	O
!	O
</s>
<s>
elements	O
,	O
since	O
composition	O
(	O
on	O
the	O
left	O
)	O
with	O
two	O
distinct	O
permutations	B-Algorithm
of	O
X	O
never	O
gives	O
the	O
same	O
function	O
on	O
N	O
(	O
the	O
permutations	B-Algorithm
must	O
differ	O
at	O
some	O
element	O
of	O
X	O
,	O
which	O
can	O
always	O
be	O
written	O
as	O
f(i )	O
for	O
some	O
i	O
N	O
,	O
and	O
the	O
compositions	O
will	O
then	O
differ	O
at	O
i	O
)	O
.	O
</s>
<s>
This	O
case	O
is	O
like	O
the	O
corresponding	O
one	O
for	O
surjective	B-Algorithm
functions	I-Algorithm
,	O
but	O
some	O
elements	O
of	O
x	O
might	O
not	O
correspond	O
to	O
any	O
equivalence	O
class	O
at	O
all	O
(	O
since	O
one	O
considers	O
functions	O
up	O
to	O
a	O
permutation	B-Algorithm
of	O
X	O
,	O
it	O
does	O
not	O
matter	O
which	O
elements	O
are	O
concerned	O
,	O
just	O
how	O
many	O
)	O
.	O
</s>
<s>
Compared	O
to	O
the	O
case	O
of	O
counting	O
surjective	B-Algorithm
functions	I-Algorithm
up	O
to	O
permutations	B-Algorithm
of	O
X	O
only	O
(	O
)	O
,	O
one	O
only	O
retains	O
the	O
sizes	O
of	O
the	O
equivalence	O
classes	O
that	O
the	O
function	O
partitions	O
N	O
into	O
(	O
including	O
the	O
multiplicity	O
of	O
each	O
size	O
)	O
,	O
since	O
two	O
equivalence	O
relations	O
can	O
be	O
transformed	O
into	O
one	O
another	O
by	O
a	O
permutation	B-Algorithm
of	O
N	O
if	O
and	O
only	O
if	O
the	O
sizes	O
of	O
their	O
classes	O
match	O
.	O
</s>
<s>
By	O
adding	O
1	O
to	O
each	O
of	O
the	O
x	O
parts	O
,	O
one	O
obtains	O
a	O
partition	O
of	O
into	O
x	O
nonzero	O
parts	O
,	O
and	O
this	O
correspondence	O
is	O
bijective	B-Algorithm
;	O
hence	O
the	O
expression	O
given	O
can	O
be	O
simplified	O
by	O
writing	O
it	O
as	O
.	O
</s>
<s>
For	O
every	O
set	O
X	O
there	O
is	O
exactly	O
one	O
function	O
from	O
the	O
empty	O
set	O
to	O
X	O
(	O
there	O
are	O
no	O
values	O
of	O
this	O
function	O
to	O
specify	O
)	O
,	O
which	O
is	O
always	O
injective	O
,	O
but	O
never	O
surjective	B-Algorithm
unless	O
X	O
is	O
(	O
also	O
)	O
empty	O
.	O
</s>
<s>
When	O
there	O
are	O
no	O
injective	O
functions	O
,	O
and	O
if	O
there	O
are	O
no	O
surjective	B-Algorithm
functions	I-Algorithm
.	O
</s>
<s>
In	O
particular	O
in	O
the	O
case	O
of	O
counting	O
multisets	B-Language
with	O
n	O
elements	O
taken	O
from	O
X	O
,	O
the	O
given	O
expression	O
is	O
equivalent	O
in	O
most	O
cases	O
to	O
,	O
but	O
the	O
latter	O
expression	O
would	O
give	O
0	O
for	O
the	O
case	O
(	O
by	O
the	O
usual	O
convention	O
that	O
binomial	O
coefficients	O
with	O
a	O
negative	O
lower	O
index	O
are	O
always	O
0	O
)	O
.	O
</s>
<s>
We	O
can	O
generalize	O
further	O
by	O
allowing	O
other	O
groups	O
of	O
permutations	B-Algorithm
to	O
act	O
on	O
N	O
and	O
X	O
.	O
</s>
<s>
If	O
G	O
is	O
a	O
group	O
of	O
permutations	B-Algorithm
of	O
N	O
,	O
and	O
H	O
is	O
a	O
group	O
of	O
permutations	B-Algorithm
of	O
X	O
,	O
then	O
we	O
count	O
equivalence	O
classes	O
of	O
functions	O
.	O
</s>
<s>
This	O
extension	O
leads	O
to	O
notions	O
such	O
as	O
cyclic	B-Algorithm
and	O
dihedral	B-Algorithm
permutations	B-Algorithm
,	O
as	O
well	O
as	O
cyclic	B-Algorithm
and	O
dihedral	B-Algorithm
partitions	O
of	O
numbers	O
and	O
sets	O
.	O
</s>
