Elementary Counting

This chapter covers notes on basic counting.

The materials on this page restrict themselves to countable sets. We define a countable set as follows:

enumerability. Let S{S} be a set. Then S{S} is countably infinite if, and only if, #(S)=#(N).{\num{S} = \num{\nat}.}

Assignments

We begin by defining assignments, just to to make our discussion a bit more efficient.

assignment. Let A{A} and B{B} be sets. Then an assignment f:A↦B{f: A \mapsto B} is a set of pairs (a,b){(a,b)} where a∈A{a \in A} and b∈B,{b \in B,} resulting from the following condition: Every element of A{A} is paired with exactly one element of B.{B.} We write XY{^X Y} to denote the set of all assignments from X{X} to Y.{Y.}

example. Let A={ vanilla,chocolate,strawberry }.{A = \set{\tx{vanilla}, \tx{chocolate}, \tx{strawberry}}.} Let B={ waffle,cake,sugar }.{B = \set{\tx{waffle}, \tx{cake}, \tx{sugar}}.} Which of the following are assignments:

a={ (vanilla,Β waffle),(chocolate,Β cake),(strawberry,Β sugar) }b={ (vanilla,Β waffle),(vanilla,Β cake)(chocolate,Β cake),(strawberry,Β sugar) }c={ (vanilla,Β cake),(chocolate,Β cake),(strawberry,Β sugar) }d={ (chocolate,Β waffle),(strawberry,Β sugar) } \eqs{ a &= \set{\tx{(vanilla, waffle)}, \tx{(chocolate, cake)}, \tx{(strawberry, sugar)}} \\ b &= \set{\tx{(vanilla, waffle)}, \tx{(vanilla, cake)} \tx{(chocolate, cake)}, \tx{(strawberry, sugar)}} \\ c &= \set{\tx{(vanilla, cake)}, \tx{(chocolate, cake)}, \tx{(strawberry, sugar)}} \\ d &= \set{\tx{(chocolate, waffle)}, \tx{(strawberry, sugar)}} }

The set a{a} is an assignment, since every element of A{A} is assigned exactly one element of B.{B.} The set b{b} is not an assignment, since the element "vanilla" is assigned twice. The set c{c} is an assignment because every element of A{A} is assigned with exactly one element of B.{B.} The set d{d} is not an assignment, because not every element of A{A} is assigned with exactly one element of B.{B.}

An assignment is just another word for function, map, mapping, or transformation. We use the word assignment because function carries a lot of connotations β€” it conjures up mental images of input-output machines, f(x),{f(x),} the rule "can't divide by zero," R,{\reals,} pass-by-reference vs. pass-by-value, etc. None of these are "wrong," but they all cause unnecessary cognitive dissonance; that's the last thing we need when we're trying to count! The same reasons extend to the other words. Maps and mappings have specific meanings in other areas of mathematics, and transformation is almost exclusively used in geometry. Here, an assignment is just a set of pairs that look like (a,b),{(a,b),} where a∈A{a \in A} and b∈B,{b \in B,} resulting from a very specific rule: Every element of A{A} must be paired with exactly one element of B.{B.}

It's important to keep the nuances of assignments in mind to avoid common "gotchas." To do so, we can turn the definition into a logical formula. Suppose M{M} is an assignment from the sets A{A} to B.{B.} Then M{M} is an assignment only if the following is true:

(βˆ€a∈A.βˆ€b∈B.βˆ€c∈B.[(a,b)∈M]∧[(a,c)∈M]β‡’[b=c])∧(βˆ€a∈A.βˆƒb∈B.[(a,b)∈M]) (\forall a \in A. \forall b \in B. \forall c \in B. [(a,b) \in M] \land [(a,c) \in M] \nc [b = c]) \land (\forall a \in A. \exists b \in B. [(a,b) \in M])

Notice that this is a two part proposition. Let's break it down by letting a,b,c{a,b,c} be arbitrary elements. The first part says:

[(a,b)∈M∧(a,c)∈M]β‡’[b=c]. [(a,b) \in M \land (a,c) \in M] \nc [b = c].

If we have an (a,b){(a,b)} and an (a,c),{(a,c),} then it better be the case that b=c.{b = c.} The second part of the rule says:

[a∈A]β€…β€ŠβŸΉβ€…β€Š[b∈B∧(a,b)∈M]. [a \in A] \implies [b \in B \land (a,b) \in M].

Let's connect this to what we've seen so far. Given sets A{A} and B,{B,} their Cartesian product, AΓ—B,{A \times B,} contains all the possible pairs (a,b){(a,b)} where a∈A{a \in A} and b∈B.{b \in B.} This means that an assignment from A{A} to B{B} is really just a specific set of pairs. One where every a∈A{a \in A} is paired{\df{paired}} once.

  • paired(a)=1.{\df{paired}(a) = 1.}

Notice that this is entirely focused on the set A,{A,} the set whose elements we're pairing. It doesn't say anything about the b{b}s, other than existence. This leaves us with a few possibilities.

  • paired(b)≀1.{\df{paired}(b) \le 1.}
  • paired(b)=1.{\df{paired}(b) = 1.}
  • paired(b)β‰₯1.{\df{paired}(b) \ge 1.}

This leads to a few different types of assignments, to be discussed shortly.

Counting Assignments

Viewed logically, we can infer a few things. First, suppose we have two sets, A={ a,b,c },{A = \set{a,b,c},} and B={ x,y,z }.{B=\set{x,y,z}.} To count the number of possible pairs, we simply multiply the cardinality of A{A} by the cardinality of B.{B.} This gives us 3Γ—3=9{3 \times 3 = 9} possible pairs:

{(a,x)(a,y)(a,z)(b,x)(b,y)(b,z)(c,x)(c,y)(c,z)}. \lset{ \ax{ (a,x) & (a,y) & (a,z) \\ (b,x) & (b,y) & (b,z) \\ (c,x) & (c,y) & (c,z) \\ } }.

Asking for the number of possible pairs is a different question from asking for the number of certain combinations of pairs. If AΓ—B{A \times B} gives us the Cartesian product, then what might be the number of possible combinations? Well, if the Cartesian product has 9 pairs, then the number of possible combinations of pairs is 29=512.{2^9 = 512.} Not all of those combinations, however, are assignments, per our definition. Why? Because at least one of those combinations is:

{(a,x)(a,y)(a,z)(b,x)(b,y)(b,z)}. \lset{ \ax{ (a,x) & (a,y) & (a,z) \\ (b,x) & (b,y) & (b,z) \\ } }.

That's a combination without any c∈A{c \in A} at all, which violates the definition of an assignment. What we want to count is just the number of combinations where every element of A{A} is paired. Thus, for each n∈A,{n \in A,} n{n} can be paired with x,{x,} y,{y,} or z.{z.} This means that we have:

3Γ—3Γ—3=27 3 \times 3 \times 3 = 27

possible combinations of pairs.

number of possible assignments. Given the sets A{A} and B,{B,} the number of possible assignments, A{A} to B,{B,} denoted An,{A_n,} is given by:

An=#B#A A_n = \card{B}^{\card{A}}

where #B{\card{B}} is the number of elements in B,{B,} and #A{\card{A}} is the number of elements in A.{A.}

Injections

When paired(b∈B)≀1,{\df{paired}(b \in B) \le 1,} then we have an injection. In other words, an assignment C:A↦B{C: A \mapsto B} where no b∈B{b \in B} is paired more than once. This means that a b∈B{b \in B} can either (1) not be paired, or (2) be paired exactly once.

injection. Let A{A} and B{B} be sets. Then an assignment r:A↦B{r: A \mapsto B} is an injection if, and only if, every b∈B{b \in B} is paired at most once under r.{r.}

In the British tradition, injections are also called one-to-one assignments. We one from a set X,{X,} to one from a set Y.{Y.}

Counting Injections

enumeration of injections. Given a set A={ a1,a2,…,an },{A = \set{a_1, a_2, \ldots, a_n},} and a set Y={ a1,a2…,am },{Y = \set{a_1, a_2 \ldots, a_m},} if n≀m,{n \le m,} then the number of injections from X{X} to Y{Y} is:

(m)(mβˆ’1)(mβˆ’2)…(mβˆ’n+1)!(mβˆ’n)!. \dfrac{(m)(m-1)(m-2) \ldots (m - n + 1)!}{(m-n)!}.

If m<n,{m \lt n,} then there are no injections from X{X} to Y.{Y.}

Surjection

When paired(b∈B)β‰₯1,{\df{paired}(b \in B) \ge 1,} then we have a surjection. I.e., an assignment C:A↦B{C: A \mapsto B} where no b∈B{b \in B} is left unpaired.

surjection. Let A{A} and B{B} be sets. Then an assignment r:A↦B{r: A \mapsto B} is a surjection if, and only if, every b∈B{b \in B} is paired at least once under r.{r.}

Surjections are also called onto assignments.

Bijection

A bijective assignment is one where every element of B{B} is paired exactly once β€” paired(b∈B)=1.{\df{paired}(b \in B) = 1.} That is, no elements are paired more than once, and no elements are left unpaired.

bijection. Let A{A} and B{B} be sets. Then an assignment r:A↦B{r: A \mapsto B} is a bijection if, and only if, r{r} is both an injection and a surjection.

Counting Bijections

enumeration of bijections. Let A{A} and B{B} be sets, both of cardinality n.{n.} Then there are n!{n!} bijections from X{X} to Y.{Y.}

The Truth Behind Counting

We went through the ordeal of defining assignments because there's a small fact that isn't emphasized very often in counting: Counting, fundamentally, is the act of assigning β€” more specifically, bijections β€” from the nonzero natural numbers to objects: 1 fish, 2 fish, (3, fish), (4, fish), (5, fish) ….{\ldots.}

Counting Elements

The most basic form of counting is to simply count the elements of a set. These rules provide the underlying foundation for subsequent rules.

Sum Rule

addition rule. Let A{A} and B{B} be countable, disjoint sets. Then #(AβˆͺB)=#(AβŠ”B)=#(A)+#(B).{\num{A \cup B} = \num{A \dup B} = \num{A} + \num{B}.}

The theorem above provides that the cardinality of the disjoin union of sets A{A} and B{B} is simply the cardinality of A{A} plus the cardinality of B.{B.} For example, given A={ a,b,c }{A = \set{a,b,c}} and B={ w,x,y,z },{B=\set{w,x,y,z},} we have AβŠ”B={ a,b,c,w,x,y,z }.{A \dup B = \set{a,b,c,w,x,y,z}.} Thus, #(AβˆͺB)=#(AβŠ”B)=7.{\num{A \cup B} = \num{A \dup B} = 7.} The disjoint union is equivalent to the symmetric difference of A{A} and B:{B:}

Aβ–³B=AβŠ”B=AβˆͺB A \dif B = A \dup B = A \cup B

Note that when we say addition rule, we are referring specifically to the addition rule of disjoint sets. The sum rule is as follows:

sum rule. Let A1,…,An{A_1, \ldots, A_n} be pairwise disjoint finite sets. Then

#⨆i=1nAi=#(A1βŠ”β€¦βŠ”Am)=#A1+…+#An. \card{\bdup_{i=1}^{n}A_i} = \card{(A_1 \dup \ldots \dup A_m)} = \card{A_1} + \ldots + \card{A_n}.

Difference Rule

The difference rule states that if some set TβŠ†S,{T \subseteq S,} then #(Sβˆ–T)=#Sβˆ’#T.{\card{(S \rid T)} = \card{S} - \card{T}.}

difference rule. Let S{S} and T{T} be finite sets, with TβŠ†S.{T \subseteq S.} Then #Sβˆ–T=#Sβˆ’#T.{\card{S \rid T} = \card{S} - \card{T}.}

Binary Union Rule

Suppose AβŠ”B=AβˆͺB.{A \dup B = A \cup B.} We'll just write AβˆͺB.{A \cup B.} The symmetric difference is defined as Aβ–³B=(Aβˆ–B)βˆͺ(Bβˆ–A).{A \dif B = (A \rid B) \cup (B \rid A).} Thus, we have:

AβˆͺB=(Aβˆ–B)βˆͺ(Bβˆ–A) A \cup B = (A \rid B) \cup (B \rid A)

There's nothing stopping us from including A∩B,{A \cap B,} since A∩B=βˆ…,{A \cap B = \nil,} and we know from the identity law that, given a set S,{S,} Sβˆͺβˆ…=S.{S \cup \nil = S.} Thus, we have:

AβˆͺB=(Aβˆ–B)βˆͺ(Bβˆ–A)βˆͺ(A∩B). A \cup B = (A \rid B) \cup (B \rid A) \cup (A \cap B).

Next, we can set A=(Aβˆ–B)βˆͺ(A∩B).{A = (A \rid B) \cup (A \cap B).} Again, this simply reduces to A=Aβˆͺβˆ…=A,{A = A \cup \nil = A,} since A∩B=βˆ…{A \cap B = \nil} implies that Aβˆ–B=A{A \rid B = A} by definition. Moreover, the fact that A∩B=βˆ…{A \cap B = \nil} implies that Aβˆ–B{A \rid B} and A∩B{A \cap B} are disjoint. Thus, we have:

#(A)=#(Aβˆ–B)+#(A∩B). \num{A} = \num{A \rid B} + \num{A \cap B}.

The same goes for B.{B.} We can express it as B=(Bβˆ–A)βˆͺ(A∩B),{B = (B \rid A) \cup (A \cap B),} since A∩B=βˆ….{A \cap B = \nil.} So, we again get:

#(B)=#(Bβˆ–A)+#(A∩B). \num{B} = \num{B \rid A} + \num{A \cap B}.

Earlier, we wrote:

AβˆͺB=(Aβˆ–B)βˆͺ(Bβˆ–A)βˆͺ(A∩B). A \cup B = (A \rid B) \cup (B \rid A) \cup (A \cap B).

So, we let's rewrite our findings we can substitute.

#(Aβˆ–B)=#(A)βˆ’#(A∩B)#(Bβˆ–A)=#(B)βˆ’#(A∩B). \eqs{ \num{A \rid B} &= \num{A} - \num{A \cap B} \\ \num{B \rid A} &= \num{B} - \num{A \cap B} }.

Substituting to obtain the cardinalities, we have:

#(AβˆͺB)=#(Aβˆ–B)+#(Bβˆ–A)+#(A∩B)=(#(A)βˆ’#(A∩B))+(#(B)βˆ’#(A∩B))+#(A∩B)=#(A)βˆ’#(A∩B)+#(B)βˆ’#(A∩B)+#(A∩B)=#(A)βˆ’#(A∩B)+#(B)βˆ’#(A∩B)+#(A∩B)=#(A)+#(B)βˆ’#(A∩B). \eqs{ \num{A \cup B} &= \num{A \rid B} + \num{B \rid A} + \num{A \cap B} \\ &= (\num{A} - \num{A \cap B}) + (\num{B} - \num{A \cap B}) + \num{A \cap B} \\ &= \num{A} - \num{A \cap B} + \num{B} - \num{A \cap B} + \num{A \cap B} \\ &= \num{A} \sout{- \num{A \cap B}} + \num{B} - \num{A \cap B} \sout{+ \num{A \cap B}} \\ &= \num{A} + \num{B} - \num{A \cap B}. }

The result above is a bedrock of counting called the binary union rule.

binary union rule. Let A{A} and B{B} be finite sets. Then

#(AβˆͺB)=#(A)+#(B)βˆ’#(A∩B). \num{A \cup B} = \num{A} + \num{B} - \num{A \cap B}.

The inclusion-exclusion principle leads to a swathe of inferences with just a bit of algebra and set theory propositions.

cardinality rules. Let A{A} and B{B} be the only two subsets of a larger set U.{U.} Then the following propositions are true:

  1. #(AβˆͺB)=#(A)+#(B)βˆ’#(A∩B).{\num{A \cup B} = \num{A} + \num{B} - \num{A \cap B}.}
  2. #(AβˆͺB)+#(A∩B)=#(A)+#(B).{\num{A \cup B} + \num{A \cap B} = \num{A} + \num{B}.}
  3. #(A∩B)=#(A)+#(B)βˆ’#(AβˆͺB).{\num{A \cap B} = \num{A} + \num{B} - \num{A \cup B}.}
  4. #(A)=#(AβˆͺB)+#(A∩B)βˆ’#(B).{\num{A} = \num{A \cup B} + \num{A \cap B} - \num{B}.}
  5. #(B)=#(AβˆͺB)+#(A∩B)βˆ’#(A).{\num{B} = \num{A \cup B} + \num{A \cap B} - \num{A}.}

example. Let P{P} be a set and #P=12.{\card{P} = 12.} Each p∈P{p \in P} is also a member of the sets S{S} and F,{F,} where #S=8{\card{S} = 8} and #(S∩F)=5.{\card{(S \cap F)} = 5.} How many p{p} in F?{F?} Since #P=12,{\card{P}=12,} we have #({ p∈SβˆͺF:p∈P })=12.{\card{(\set{p \in S \cup F : p \in P})} = 12.} Since #S=8,{\card{S} = 8,} and #(S∩F)=5,{\card{(S \cap F)} = 5,} it follows that #(Sβˆ–S∩F)=8βˆ’5=3.{\card{(S \setminus S \cap F)} = 8 - 5 = 3.} Thus, there are 12βˆ’3=9{12-3 = 9} total p{p} in F{F} or S∩F,{S \cap F,} which means that there are 9{9} total p{p} in F.{F.}

example. Let C{C} be a set with #(C)=27.{\num{C} = 27.} C{C} contains two subsets, SβŠ‚C{S \are C} and KβŠ‚C,{K \are C,} not necessarily disjoint. #(S)=14.{\num{S} = 14.} #(K)=11.{\num{K} = 11.} #(Sβ€²βˆ©Kβ€²)=5.{\num{S' \cap K'} = 5.} What is #(S∩K)?{\num{S \cap K}?} From De Morgan's law, we know that Sβ€²βˆ©Kβ€²=(SβˆͺK)β€².{S' \cap K' = (S \cup K)'.} Thus, #((SβˆͺK)β€²)=5.{\num{(S \cup K)'} = 5.} Since #(C)=27,{\num{C} = 27,} we have #(SβˆͺK)+#((SβˆͺK)β€²)=27.{\num{S \cup K} + \num{(S \cup K)'} = 27.} Therefore, #(SβˆͺK)=27βˆ’5=22.{\num{S \cup K} = 27 - 5 = 22.} Since #(S)=14{\num{S} = 14} and #(K)=11,{\num{K}=11,} we have #(S)+#(K)=25.{\num{S} + \num{K} = 25.} Since #(SβˆͺK)=22,{\num{S \cup K} = 22,} it must be the case that #(S∩K)=25βˆ’22=3.{\num{S \cap K} = 25 - 22 = 3.}

Product Rule

The product rule tells us that if an event can occur in n{n} ways, and a second event can occur independently in k{k} ways, then the two events can occur in nk{nk} ways.

cardinality of cartesian product. Let S1,S2,…,Sk{S_1, S_2, \ldots, S_k} be finite sets with #Si=ni{\card{S_i} = n_i} given 1≀i≀k.{1 \le i \le k.} Then

#(S1Γ—S2×…×Sk)=n1Γ—n2Γ—n3…×nk. \card{(S_1 \times S_2 \times \ldots \times S_k)} = n_1 \times n_2 \times n_3 \ldots \times n_k.

example. A license plate consists of a digit followed by three uppercase letters, followed by four digits. How many possible plates? Here, a license plate is just a tuple from the Cartesian product:

S=DΓ—LΓ—LΓ—LΓ—DΓ—DΓ—D S = D \times L \times L \times L \times D \times D \times D

where D={ 0,1,2,…,8,9 },{D = \set{0,1,2,\ldots,8,9},} and S={ A,B,C,D,…,Z. }{S = \set{A,B,C,D,\ldots,Z.}} Thus, there are:

#S=10Γ—26Γ—26Γ—26Γ—10Γ—10Γ—10=175Β 760Β 000 \card{S} = 10 \times 26 \times 26 \times 26 \times 10 \times 10 \times 10 = 175~760~000

possible plates.

product rule. Let S{S} be a set. If there exists a bijection

f:{ 1,2,…,n1 }Γ—{ 1,2,…,n2 }×…×{ 1,2,…,nk }↣S, f: \set{1,2,\ldots,n_1} \times \set{1,2,\ldots,n_2} \times \ldots \times \set{1,2,\ldots,n_k} \bij S,

then #S=n1Γ—n2×…nk.{\card{S} = n_1 \times n_2 \times \ldots n_k.}

example. A fraternity name is a sequence of 2 or 3 uppercase Greek letters. How many possible names are there? There are 24 Greek uppercase letters. In the case of a 2-letter name, we have 24 choices for the first, and 24 choices for the second. In the case of a 3-letter name, we have 24 choices for the first, 24 choices for the second, and 24 choices for the third. It follows that there are: 242+243=14Β 400{24^2 + 24^3 = 14~400} possible names.

For many applications, it's also helpful to think of the product rule in terms of types: Given a set of objects, if the objects can be seperated into j{j} types, and each of those j{j} types can be seperated into k{k} different subtypes, then there are jβ‹…k{j \by k} different types.

Lists

A list is the most basic ordered collection. Some authors call them tuples, but we avoid using that term because in these notes, tuples are primitive objects, specifically nested sets, that exist independently of the natural numbers. I.e., tuples aren't "ordered" in the sense we're used to β€” there is no "first" or "second" in a tuple, because the natural numbers don't exist for them. See Set Theory Notes: Tuples. Accordingly, we use the term lists, since those can be created after constructing the natural numbers.

list. Let A{A} be a finite set. Then a list is a finite sequence L=[a1,a2,a3,…,an]{L = [a_1, a_2, a_3, \ldots, a_n]} where each ai∈A{a_i \in A} and nβ‰₯0.{n \ge 0.} We say that n{n} is the length of L,{L,} and that two lists [a1,…,an]{[a_1,\ldots,a_n]} and [b1,…,bm]{[b_1,\ldots,b_m]} are equal if, and only if, n=m{n = m} and ai=bi{a_i = b_i} for each 1≀i≀k.{1 \le i \le k.}

list enumeration. Given a set A{A} with #A=n{\card{A} = n} and a list of length k,{k,} there nk{n^k} lists over A.{A.}

example. Let A{A} be the Latin alphabet { a,b,c,…,z,A,B,C,…,Z }.{\set{a,b,c,\ldots,z,A,B,C,\ldots,Z}.} Let D{D} be the set of digits { 0,1,2,3,4,5,6,7,8,9 }.{\set{0,1,2,3,4,5,6,7,8,9}.} How many possible strings of length 7 are there, such that: (1) The letter O{O} never appears, (2) the first character must be a digit, and (3) the remaining five can be a digit or letter, but not O.{O.} First, there are 26 letters in the Latin alphabet, each letter uppercase or lowercase. Because the string cannot contain the letter O,{O,} we have 25Γ—2=50{25 \times 2 = 50} possible letters. The first must be a digit, of which there are 10{10}. For each choice of the first, we have 50 choices for the second. Then we have 10+50=60{10 + 50 = 60} choices for the third, 60{60} choices for the fourth, 60{60} choices for the fifth, 60{60} choices for the sixth, and 60{60} choices for the seventh. This gives us: 10β‹…50β‹…605=388Β 800Β 000Β 000{10 \by 50 \by 60^5 = 388~800~000~000} possible strings.

example. How many three-digit positive integers are not multiples of 7? We first set the count's bounds. The smallest three-digit positive integer is 100. The largest three-digit positive integer is 999. We can find the smallest three digit multiple of seven by playing around with the integer quotient: ⌊100/7βŒ‹=104.{\floor{100/7} = 104.} 7 does not divide 103, so the smallest three-digit multiple of seven is 105=7β‹…15.{105=7 \by 15.} We can get the largest three-digit multiple of seven by multiplying 10:{10:} 105β‹…10=1050.{105 \by 10 = 1050.} This is out of range, so we subtract forty-nine: 1050βˆ’49=1001.{1050-49 = 1001.} This is still out of range, so we subtract seven: 1001βˆ’7=994.{1001-7=994.} Thus, the largest three-digit multiple of 7 is 994. So, our count must exclude 105,112,119,…,994.{105,112, 119, \ldots, 994.} Dividing each of these by 7,{7,} we get 15,16,17,…,142.{15,16,17,\ldots,142.} Thus, there are (142βˆ’15)+1=128{(142-15)+1 = 128} multiples of 7{7} from 100{100} to 999.{999.} Since there are (999βˆ’100)+1=900{(999-100)+1 = 900} three-digit numbers, subtracting the multiples of seven gives us: 900βˆ’128=772{900-128=772} three-digit integers that are not multiples of 7.

example. A diplomatic meeting consists of 4 American diplomats and 3 Chinese diplomats. In how many ways can they be seated in a row of 7 chairs, such that at least 2 American diplomats are next to each other? Because there are 7 diplomats total, there are 7!=5040{7! = 5040} possible arrangements. There is only one sequence to avoid: (a,c,a,c,a,c,a),{(a,c,a,c,a,c,a),} where a{a} is an American diplomat and c{c} is a Chinese diplomat. If the diplomats are seated in this bad sequence, then there are 4!{4!} seatings for the Americans, and 3!{3!} seatings for the Chinese. Thus, we have 4!β‹…3!=144.{4! \by 3! = 144.} ways to construct the bad sequence. It follows that there are 5040βˆ’144=4896{5040 - 144 = 4896} ways to seat the diplomats in a row of 7 chairs, such that at least 2 American diplomats are next to each other.

example. Let N{N} be the set of all 3-digit natural numbers with exactly one zero. What is #N?{\card{N}?} Consider how we construct 3-digit integers. The first digit can't be 0. So, we have 9 choices for the first. Now we have two more digits. We need exactly one zero, so it doesn't matter if it goes in the first or last, as long as the other place is not a 0. So, we have 9β‹…9β‹…2=162=#N.{9 \by 9 \by 2 = 162 = \card{N}.}

example. How many lists of the form [x1,x2,x3,…,x7]{[x_1,x_2,x_3,\ldots,x_7]} can be formed where: all xi{x_i} are integers with 0<xi<6{0 \lt x_i \lt 6} and no two adjacent xi{x_i} are equal. Once more, we construct. The interval tells us that we only have a set of 5{5} integers to work with. We have 5{5} choices for the first number. Then we have 4{4} choices for the second. We also have 4{4} choices for the third, since the requirement is placed on adjacency. Thus, we have: 5β‹…46=20Β 480{5 \by 4^6 = 20~480} possible sequences.

example. Let A{A} be a non-empty set and let B{B} be a non-empty set. How many 8-arrangements comprising 3 elements of A{A} and 5 elements of B{B} if the first and last must be an element of A?{A?} First, suppose a0{a_0} and a1{a_1} denote the two on the ends:

(a,βˆ…,βˆ…,βˆ…,βˆ…,βˆ…,βˆ…,a). (a, \nil, \nil, \nil, \nil, \nil, \nil, a).

There are 3 choices of an A{A} element for the first, followed by 2 choices of an A{A} element for the last: 3β‹…2=6.{3 \by 2 = 6.} This leaves us 6 elements to permute, so we have: 6β‹…6!=4320{6 \by 6! = 4320} possible 8-arrangements.

example. Let S{S} be a set with n(S)=4.{n(S)=4.} Let D{D} be a set with n(D)=3.{n(D)=3.} Given s∈S{s \in S} and d∈S,{d \in S,} how many 7-arrangements are there such that all three d{d} are adjacent? Here, it's helpful to construct a few arrangements:

(d,d,d,βˆ…,βˆ…,βˆ…,βˆ…)(βˆ…,d,d,d,βˆ…,βˆ…,βˆ…)(βˆ…,βˆ…,d,d,d,βˆ…,βˆ…)(βˆ…,βˆ…,βˆ…,d,d,d,βˆ…)(βˆ…,βˆ…,βˆ…,βˆ…,d,d,d) (d,d,d,\nil,\nil,\nil,\nil) \\ (\nil,d,d,d,\nil,\nil,\nil) \\ (\nil,\nil,d,d,d,\nil,\nil) \\ (\nil,\nil,\nil,d,d,d,\nil) \\ (\nil,\nil,\nil,\nil,d,d,d) \\

First, there are 3! ways to arrange the d{d} themselves. Thus, we have 6 possible arrangements for each of the arrangements above. Then there are 4! possible arrangements for the remaining s.{s.} Thus, we have 3!β‹…4!=144{3! \by 4! = 144} possible arrangements per arrangement: 144β‹…5=720{144 \by 5 = 720} possible arrangements.

example. How many multiples of three are between 62 and 215? There are 51. First, we determine the smallest and largest multiple. We do so by testing the ends:

623=2023Β Β Β Β Β Β Β Β 2153=7123. {\dfrac{62}{3}} = 20 \frac{2}{3} ~~~~~~~~ {\dfrac{215}{3}} = {71 \frac{2}{3}}.

The smallest multiple is 21Γ—3=63,{21 \times 3 = 63,} and the largest multiple is 71Γ—2=213.{71 \times 2 = 213.} Thus, we have the subsequence

(63,66,69,…,213). (63,66,69,\ldots,213).

Dividing every term by 3, we get:

(63,66,69,…,213)3=21,22,23,…,71. \dfrac{(63,66,69,\ldots,213)}{3} = 21,22,23,\ldots,71.

That's a sequence we know how to count: 71βˆ’21+1=51.{71 - 21 + 1 = 51.}

Permutations

A permutation has a very specific meaning in mathematics:

permutation. Let S{S} be a set. Then a permutation p{p} of S{S} is a list where each element of S{S} appears exactly once. That is, a bijection p:[n]↣S.{p: [n] \bij S.}

permutation enumeration. Given #S=n,{\card{S} = n,} there are n!{n!} permutations over S.{S.}

example. Let A{A} be a set with #A=6.{\card{A} = 6.} Let B{B} be a set with #B=4.{\card{B} = 4.} Let C{C} be a set with #C=3.{\card{C} = 3.} Let D{D} be a set with #D=7.{\card{D} = 7.} How many possible sets are there, comprising of one element of A,{A,} one element of B,{B,} one element of C,{C,} and one element of D?{D?} We have 6 choices from A,{A,} and for each of those choices, 4 choices from B,{B,} and for each of those choices, 3 choices from C,{C,} and for each of those choices, 7 choices from D.{D.} Therefore, we have: 6β‹…4β‹…3β‹…7=504{6 \by 4 \by 3 \by 7 = 504} possible sets.

example. Let A{A} be a set with #4.{\card{4}.} How many ways are there to arrange all 4 elements? We have 4 choices for the first. But once we've placed an element. We have 3 choices for the second, since we've already places one element. Then we have 2 choices for the third. Then 1 choice for the last. Hence, there are 4β‹…3β‹…2β‹…1=24{4 \by 3 \by 2 \by 1 = 24} possible arrangements.

example. Let #S=20.{\card{S} = 20.} How many possible triples (a,b,c){(a,b,c)} are there, such that a,b,c∈S,{a,b,c \in S,} with aβ‰ bβ‰ c?{a \neq b \neq c?} There are 20 choices for a,{a,} 19 choices for b,{b,} and 18 choices for c.{c.} Thus, we have 20β‹…19β‹…18=6840{20 \by 19 \by 18 = 6840} possible triples.

example. Let S={ d,o,g }.{S = \set{d,o,g}.} How many permutations of S{S} elements are there? There are 3!=6{3! = 6} arrangements.

example. Let S={ b,a,l,l }.{S = \set{b,a,l,l}.} How many permutations of S{S} are there? If we simply computed 4!=24,{4!=24,} we would overcount. Consider the set of all such arrangements:

{bal1l2,bal2l1→ballbl2al1,bl1al2→blalbl1l2a,bl2l1a→bllaabl1l2,abl2l1→ablll1bal2,l2bal1→lball1bl2a,l2bl1a→lblaal1bl2,al2bl1→albll1abl2,l2abl1→labll1l2ba,l2l1ba→llbaal1l2b,al2l1b→allbl1al2b,l2al1b→lalbl1l2ab,l2l1ab→llab}. \lset{ \ax{ bal_1l_2, & bal_2l_1 & \rightarrow & ball & bl_2al_1, & bl_1al_2 & \rightarrow & blal \\ bl_1l_2a, & bl_2l_1a & \rightarrow & blla & abl_1l_2, & abl_2l_1 & \rightarrow & abll \\ l_1bal_2, & l_2bal_1 & \rightarrow & lbal & l_1bl_2a, & l_2bl_1a & \rightarrow & lbla \\ al_1bl_2, & al_2bl_1 & \rightarrow & albl & l_1abl_2, & l_2abl_1 & \rightarrow & labl \\ l_1l_2ba, & l_2l_1ba & \rightarrow & llba & al_1l_2b, & al_2l_1b & \rightarrow & allb \\ l_1al_2b, & l_2al_1b & \rightarrow & lalb & l_1l_2ab, & l_2l_1ab & \rightarrow & llab } }.

Because the ball{ball} appears exactly twice, we must divide by 2. There are 4!/2!=12{4!/2! = 12} possible permutations. The trick is to pretend that every element is different. Since every element is different, there 2!{2!} ways where ball{ball} occurs.

example. Let S={ t,a,t,t,e,r }.{S = \set{t,a,t,t,e,r}.} How many permutations of S{S} elements are there? Once more, we want to avoid overcounting. Because there t{t} is duplicated twice, there are 3!{3!} permutations that result in tatter. Thus, we again must divide: 6!/3!=120{6!/3! = 120} permutations.

example. Let S={ p,a,p,a }.{S = \set{p,a,p,a}.} How many permutations? Once more, we must correct for overcounting: 4!/(2!β‹…2!)=6{4!/(2! \by 2!) = 6} permutations. Because there are 2 p{p}s, there are 2!{2!} ways for p{p} to repeat. And for each of those ways, there are 2!{2!} ways for a{a} to repeat.

Partial Permutations

partial permutation. Let S{S} be a set. Then a partial permutation V{V} of S{S} is a list of a given length k{k} consisting of k{k} distinct elements of S.{S.}

partial permutation enumeration. Let S{S} be a set with #S=n.{\card{S}=n.} Then the number of k-permutations of length 0≀k≀n{0 \le k \le n} is

P(n,k)=n!(nβˆ’k)!=n(nβˆ’1)…(nβˆ’k+1). P(n,k) = \dfrac{n!}{(n - k)!} = n(n-1)\ldots(n-k+1).

Here's another formulation of this definition:

partial permutation enumeration. Let S{S} be a set with n{n} objects, and L{L} be a list with k{k} ordered slots. Then there are

n!(nβˆ’k)!=n(nβˆ’1)(nβˆ’2)…(nβˆ’k+1) \dfrac{n!}{(n-k)!} = n(n-1)(n-2)\ldots(n-k+1)

ways to fill the k{k} slots.

example. Let C{C} be a set with #C=n{\card{C} = n} and n∈Z+.{n \in \pint.} Let D{D} be a set with #D=r{\card{D} = r} and r≀n.{r \le n.} How many injective assignments are there from C{C} to D?{D?} There are nβˆ’0{n-0} choices for the first, nβˆ’1{n-1} choices for the second, nβˆ’2{n-2} choices for the third, …,{\ldots,} nβˆ’(rβˆ’1)=nβˆ’(r+1){n - (r - 1) = n - (r + 1)} choices for the last.

The example above is what we call an variation β€” a bijection from a set S{S} to some strict subset of S.{S.}

Consider the expression P(n,k)β‹…P(nβˆ’k,j){P(n,k) \by P(n-k,j)} where n,k,j∈Z{n,k,j \in \uint} with k≀n{k \le n} and j≀nβˆ’k.{j \le n - k.} With a little algebra, we can reduce this expression:

P(n,k)β‹…P(nβˆ’k,j)=n(nβˆ’k)!β‹…(nβˆ’k)!(nβˆ’kβˆ’j)!=n!(nβˆ’kβˆ’j)!=P(n,k+j). \eqs{ P(n,k) \by P(n-k,j) &= \dfrac{n}{(n-k)!} \by \dfrac{(n-k)!}{(n-k-j)!} \\[1em] &= \dfrac{n!}{(n-k-j)!} \\[1em] &= P(n,k+j). }

This is the formula for the number of permutations of size k,{k,} given a set of n{n} objects, multiplied by the number of permutations of size j{j} given nβˆ’k{n - k} objects.

example. Let A{A} be the set {1,2,3,4,…,23,24,25}{\lset{1,2,3,4,\ldots,23,24, 25}} with #A=25.{\card{A} = 25.} Suppose 4 elements are drawn to construct an arrangement (a,b,c,d).{(a,b,c,d).} First, how many possible arrangements are there if each element is excluded from A{A} after drawing? Second, how many possible arrangements are there if each element is not excluded from A{A} after drawing? The first part of this question imposes a bijection requirement: There are 25 choices for the first, 24 for the second, 23 for the third, and 22 for the fourth. This gives us:

25Γ—24Γ—23Γ—22=303Β 600 25 \times 24 \times 23 \times 22 = 303~600

possible arrangements. The second question throws the bijection requirement out. Now we have 254=390Β 625{25^4 = 390~625} possible arrangements. Notice that the parameters are different for the two questions. In elementary terms, the first question does not permit "replacement" (i.e., a bijection). The second question does (no bijection requirement).

example. An alphabet Ξ£{\Sigma} comprises 5 letters. Every valid string over Ξ£{\Sigma} has no more than 3 letters, but letters may be used more than once. How many possible strings are there? We can have 5 letters for the first, 5 letters for the second, and 5 letters for the third: 5β‹…5β‹…5=125{5 \by 5 \by 5 = 125} strings. That's a 3 letter string. We can also have a 2 letter string: 5Γ—5=25.{5 \times 5 = 25.} And we can also have a 1 letter string: 5.{5.} Thus, we have 125+25+5=155{125 + 25 + 5 = 155} possible strings over Ξ£.{\Sigma.}

example. How many pairs of (m,n){(m,n)} with m,n∈Z+{m,n \in \uint^+} satisfy the relation m2+n<22?{m^2 + n \lt 22?} Since m,n∈Z+,{m,n \in \uint^+,} it must be the case that 0<m2<22.{0 \lt m^2 \lt 22.} The only perfect squares between 0{0} and 22{22} are 1,2,3,4.{1,2,3,4.} If m=1,{m = 1,} then n<22βˆ’1=21.{n \lt 22 - 1 = 21.} So, there are 20{20} possible pairs when m=1.{m = 1.} If m=2,{m = 2,} then n<22βˆ’4=18.{n \lt 22 - 4 = 18.} There are 17{17} possible pairs when m=2.{m = 2.} If m=3,{m = 3,} then n<22βˆ’9=13,{n \lt 22-9=13,} so 12{12} pairs. If m=4,{m = 4,} then n<22βˆ’16=6.{n \lt 22-16=6.} There are 5{5} possible pairs. Hence, we have 21+18+13+16=54{21+18+13+16=54} possible pairs.

example. We're given the following grid:

∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘ \ax{ \circ & \circ & \circ & \circ & \circ \\ \circ & \circ & \circ & \circ & \circ \\ \circ & \circ & \circ & \circ & \circ \\ \circ & \circ & \circ & \circ & \circ \\ \circ & \circ & \circ & \circ & \circ \\ }

How many squares of any size can we form by connecting the dots? With 4 dots, we can make 1 square. With 6, we can make 2. With 8, we can make 3. With 10, we can make 4. This would comprise the first row, and there are 4 rows remaining. So, at a minimum, we have 4β‹…4=16{4 \by 4 = 16} squares. Those are 1Γ—1{1 \times 1} squares. We can also have 2Γ—2{2 \times 2} squares. That would give us 9{9} total. So, we now have 25{25} possible squares. We can also have a 3Γ—3{3 \times 3} square, of which there are 4{4} possibilities. Now we're up to 29{29} squares. Then, there's the 4Γ—4{4 \times 4} square, which is the whole square itself. This gives us 30{30} possible squares. We are, however, missing a case: Squares that are rotated. I.e., those squares whose sides are not parallel to the grid. Since a square's side lengths are all equal, we can determine the square's side lengths in terms of their diagonals, which, as Pythagoras tells us, is a2+b2.{\sqrt{a^2 + b^2}.}

a{a}b{b}sidenumber of squares
1{1}1{1}2{\sqrt{2}}9{9}
1{1}2{2}5{\sqrt{5}}8{8}
1{1}3{3}10{\sqrt{10}}1{1}
2{2}2{2}8{\sqrt{8}}2{2}

Therefore, there are 50{50} possible squares.

Combinations

example. A round-robin tournament consists of each player playing every other player exactly once. How many matches are held during an 8-person round-robin tennis tournament? This is a good example of a question that seems as if ordering matters, but really boils down to a combination.

example. Let S{S} be a set with #(C)=3.{\num{C}=3.} Let P{P} be a set with #(P)=4.{\num{P}=4.} How many many (s,p){(s,p)} are there, where s∈P{s \in P} and p∈P?{p \in P?} This is nothing more than the cardinality of the Cartesian product CΓ—B.{C \times B.} Thus, there are 3Γ—4=12{3 \times 4 = 12} pairs of (s,p).{(s,p).}

As simple as this example is, it generalizes many common counting problems. For example, given 3 interns and 10 managers, how many possible pairings are there? The first intern can be paired with any of the 10 managers, the second intern can be paired with any of the 10 managers, and the third intern can be paired with any of the 10 managers. This gives us 3Γ—10=30{3 \times 10 = 30} possible pairings.

example. Let A{A} be the set A={ a,b,c }.{A = \set{a,b,c}.} How many possible ways are there to combine a,{a,} b,{b,} and c?{c?} There are 8{8} possible ways: βˆ…,{\nil,} { a },{\set{a},} { b },{\set{b},} { c },{\set{c},} { a,b },{\set{a,b},} { b,c },{\set{b,c},} { a,c },{\set{a,c},} { a,b,c }.{\set{a,b,c}.}

Given some non-empty set A,{A,} we often want to ask: How many possible combinations of A{A}'s elements are there? For example, given a set A={ salty,sweet,sour },{A = \set{\text{salty}, \text{sweet}, \text{sour}},} how many possible ways are there to combine the elements?

To generate a combination C,{C,} for each element a∈A,{a \in A,} either a∈C{a \in C} or aβˆ‰C.{a \notin C.} This means means we have two possibilities for the first element, two possibilities for the second, two possibilities for the third, and so on. Thus, we have: 2n,{2^n,} where n{n} is the number of elements of the set in question. Thus, we have:

salty{\text{salty}}sweet{\text{sweet}}sour{\text{sour}}combination
000βˆ…{\nil}
100{ salty }{\set{\tx{salty}}}
010{ sweet }{\set{\tx{sweet}}}
001{ sour }{\set{\tx{sour}}}
110{ salty,sweet }{\set{\tx{salty}, \tx{sweet}}}
011{ sweet,sour }{\set{\tx{sweet}, \tx{sour}}}
101{ salty,sour }{\set{\tx{salty}, \tx{sour}}}
111{ salty,sweet,sour }{\set{\tx{salty}, \tx{sweet}, \tx{sour}}}

Notice that this gives us exactly 23=8{2^3 = 8} possible combinations. In effect, counting the number of combinations of a given set A{A} corresponds to the number of subsets of A,{A,} that is, how many subsets are in the power set of A?{A?}

number of subsets. Let S{S} be a set. Then the number of subsets of S{S} is 2∣S∣,{2^{\abs{S}},} where ∣S∣{\abs{S}} is the cardinality of S.{S.}

example. 4 candidates run for President and Vice President. How many possible pairs of (President, Vice President) (assuming no person can be both)? There are 4 choices for President. After we pick one, there are 3 choices for the second: 12 possible pairs.

Binomial Coefficients

example. How many ways can 2-seat committee be chosen from a group of 4 people (order of choosing irrelevant)? Start with a simple set: { a,b,c,d },{\set{a,b,c,d},} enumerating all possible sets:

{{ a,b }{ a,c }{ a,d }{ b,a }{ b,c }{ b,d }{ c,a }{ c,b }{ c,d }{ d,a }{ d,b }{ d,c }} \lset{ \eqs{ \set{a,b}\set{a,c}\set{a,d} \\ {\red{\set{b,a}}}\set{b,c}\set{b,d} \\ {\red{\set{c,a}}}{\red{\set{c,b}}}\set{c,d} \\ {\red{\set{d,a}}}{\red{\set{d,b}}}{\red{\set{d,c}}} \\ } }

Notice the duplicates in red. There are 6 possible ways.

example. In how many ways can three seats { a,b,c }{\set{a,b,c}} be taken given a group of 8 people? Again, if we simply permuted β€” (8)(7)(6)=210{(8)(7)(6) = 210} β€” we'd get an overcount. We know that the first permutation causes an overcount of 1. The second permutation causes an overcount of 2. The third permutation causes an overcount of 3. Thus, we have (8β‹…7β‹…6)/(1β‹…2β‹…3)=56{(8 \by 7 \by 6)/(1 \by 2 \by 3) = 56} ways.

Determining the maximum number of combinations is so widespread in mathematics that we have special notation for it. The last example can be expressed with any of the following expressions:

C(8,3)=56Β Β Β Β Β Β Β 8C3=56Β Β Β Β Β Β Β (83)=56 C(8,3) = 56 ~~~~~~~ _8 C _3 = 56 ~~~~~~~ \binom{8}{3} = 56

Each of the expressions above is read as "8 choose 3" or "8 pick 3." Is there a general formula for this computation? Recall that a permutation tells us how many ways we can arrange objects in order. Given n{n} objects, we have n{n} choices for index one, nβˆ’1{n-1} objects for index two, nβˆ’2{n-2} objects for index 3, all the way down to nβˆ’(rβˆ’1).{n-(r-1).} At each count, we pair an element with every other element. This results in r!{r!} duplicates, which means that we have:

n(nβˆ’1)(nβˆ’2)…(nβˆ’(rβˆ’1))r!. \dfrac{n(n-1)(n-2)\ldots(n-(r-1))}{r!}.

The numerator of this expression can be expressed another way:

n(nβˆ’1)(nβˆ’2)…(nβˆ’(rβˆ’1))=(n)(nβˆ’1)…(nβˆ’r+1)=(nβˆ’r)(nβˆ’rβˆ’1)…2…1(nβˆ’r)(nβˆ’rβˆ’1)…2…1=n!(nβˆ’r)! \eqs{ n(n-1)(n-2)\ldots(n-(r-1)) &= (n)(n-1)\ldots(n - r + 1) \\ &= \dfrac{(n-r)(n-r-1)\ldots 2 \ldots 1}{(n-r)(n-r-1)\ldots 2 \ldots 1} \\ &= \dfrac{n!}{(n-r)!} \\ }

This gives us:

(n)(nβˆ’1)(nβˆ’2)…(nβˆ’r+1)r!=n!(nβˆ’r)!r!=n!r!(nβˆ’r)! \eqs{ \dfrac{(n)(n-1)(n-2)\ldots(n-r+1)}{r!} &= \dfrac{\dfrac{n!}{(n-r)!}}{r!} \\ &= \dfrac{n!}{r!(n-r)!} }

That final expression is called the binomial coefficient.

binomial coefficient. Given k∈N{k \in \nat} and n∈N{n \in \nat} with 0≀k≀n,{0 \le k \le n,} the binomial coefficient of n{n} and k{k} is

(nk)=C(n,k)=n!k!(nβˆ’k)!, \binom{n}{k} = C(n,k) = \dfrac{n!}{k!(n-k)!},

which we read as "n{n} choose k.{k.}" If k<0{k \lt 0} or k>n,{k \gt n,} then we define (nk)=C(n,k)=0.{\binom{n}{k} = C(n,k) = 0.} For all nβ‰₯0{n \ge 0} and all k,{k,} (nk){\binom{n}{k}} is the number of k{k}-element subsets of an n{n}-element set.

example. In a state lottery, 48 balls are numbered 1 to 48, and 6 are chosen. How many different sets of winning numbers are there? This is a classic combination problem. We a set of 48, and we're asked to count how many subsets of size 6 we can make. So, we have (486)=48!/(6!)=12Β 271Β 512.{\binom{48}{6}=48!/(6!)=12~271~512.} As we can see, the odds of winning a state lottery β€” assuming all outcomes are equally likely β€” is very, very low.

Bitstrings

Consider the set of all binary digits, B={ 0,1 },{\bits = \set{0,1},} and a set S={ a,b,c }.{S = \set{a,b,c}.} One way we can count all of the possible subsets of S{S} is to establish a bijection f:S↣B3.{f: S \bij \bits^3.} The product B3{\bits^3} gives us the following strings:

{000100010001110101011111}.\lset{ \ax{ 000 & 100 & 010 & 001 \\ 110 & 101 & 011 & 111 \\ } }.

Now, we can count all of the possible subsets of S{S} mapping each element of S{S} to each string of B3.{\bits^3.} These mappings are displayed in the table below, where each β–‘{\ws} represents an empty position.

string
000{000}β–‘Β β–‘Β β–‘{\ws~\ws~\ws}βˆ…{\nil}
100{100}aΒ β–‘Β β–‘{a~\ws~\ws}a{a}
010{010}β–‘Β bΒ β–‘{\ws~b~\ws}b{b}
001{001}β–‘Β cΒ β–‘{\ws~c~\ws}c{c}
110{110}β–‘aΒ b{\ws a~b}ab{ab}
101{101}aΒ β–‘Β c{a~\ws~c}ac{ac}
011{011}β–‘Β bΒ c{\ws~b~c}bc{bc}
111{111}aΒ bΒ c{a~b~c}abc{abc}

This simply confirms that the number of possible subsets of a given set S{S} is 2n,{2^n,} where n{n} is the cardinality of S.{S.}

Compositions

Because the naturals are defined as sets, given two naturals n{n} and m{m} with m<n,{m \lt n,} we can break down n{n} into its elements (other naturals less than or equal to n{n}). Thus, the sequence (1,1,1,1){(1,1,1,1)} is another way to represent 4, and so is (1,3),{(1,3),} and so is (2,2),{(2,2),} as well as (1,1,2),{(1,1,2),} etc. Each of these sequences is called a composition of 4.{4.}

composition. Given an integer n,{n,} a composition of n{n} is a sequence t=t1,t2,…,tk,{t = t_1, t_2, \ldots, t_k,} where each ti{t_i} is a positive integer and βˆ‘i=1kti=t1+t2+…+tk=n,{\tsum{i=1}{k} t_i = t_1+t_2+\ldots+t_k = n,} with k∈Z+{k \in \pint} corresponding to the number of parts of t.{t.} We write comp[n]{\df{comp}[n]} to denote the set of all compositions of n.{n.}

composition count. For all integers n>0,{n \gt 0,} there are 2nβˆ’1{2^{n-1}} compositions of n.{n.}

Anagrams

What do β€œsilver”,{\string{silver},} β€œsliver”,{\string{sliver},} β€œlivers”,{\string{livers},} and β€œieslrv”{\string{ieslrv}} have in common? They consist entirely of the same elements. Each of these strings are anagrams of one another. The integer 172{172} has the anagrams 127{127}, 712,{712,} 721,{721,} 217,{217,} and 271.{271.}

anagram. Let { a1,a2,…,ak }{\set{a_1, a_2, \ldots, a_k}} be a list of distinct elements n1,n2,…,nk{n_1, n_2, \ldots, n_k} be natural numbers. An anagram is a list w=(w1,w2,…,wn){w = (w_1, w_2, \ldots, w_n)} formed by rearranging n1{n_1} copies of a1,{a_1,} n2{n_2} copies of a2,{a_2,} …,{\ldots,} nk{n_k} copies of ak,{a_k,} such that n=n1+n2+…nk.{n = n_1 + n_2 + \ldots n_k.} We denote the set of all anagrams of a given list w{w} with the notation anagram(a1n1,a2n2,a3n3,…,aknk).{\df{anagram}(a_1^{n_1}, a_2^{n_2}, a_3^{n_3}, \ldots, a_k^{n_k}).}

example. anagram(a1b2c1)={ abbc,abcb,acbb,cabb,cbab,cbba,bacb,babc,bcab,bbac,bbca,bcba }.{\df{anagram}(a^1b^2c^1)=\set{abbc,abcb,acbb, cabb,cbab,cbba, bacb,babc,bcab, bbac,bbca,bcba}.}

If we think about how an anagram is generated, this is simply a binomial coefficient. There are n!{n!} ways for the first position, (nβˆ’1)!{(n-1)!} factorials for the second, (nβˆ’2)!{(n-2)!} for the third, and so on, where n=n1+n2+n3+…+nk.{n = n_1 + n_2 + n_3 + \ldots + n_k.} As we saw with the binomial coefficient, we then correct for the overcount. Thus, we have:

4!(1!)(2!)(1!)=(4)(3)(2)(1)(2)=(4)(3)(2)(1)(2)=(4)(3)(1)=12\eqs{ \dfrac{4!}{(1!)(2!)(1!)} &= \dfrac{(4)(3)(2)(1)}{(2)} \\ &= \dfrac{(4)(3)\out{(2)}(1)}{\out{(2)}} \\ &= {(4)(3)(1)} \\ &= {12} \\ }

From the example above, we see that there are, in fact, 12 such anagrams.

anagram count. Given a1,…,ak{a_1, \ldots, a_k} distinct elements and n1,…,nk{n_1,\ldots,n_k} natural numbers with n=n1+…+nk,{n = n_1 + \ldots + n_k,} there are, at most,

#anagram(a1n1a2n2…aknk)=n!∏i=1kni!=n!(n1!)(n2!)…(nk!) \card{\df{anagram}(a_1^{n_1}a_2^{n_2}\ldots a_k^{n_k})} =\dfrac{n!}{\dprod{i=1}{k}n_i!} =\dfrac{n!}{(n_1!)(n_2!)\ldots(n_k!)}

anagrams.

Lattice Paths

Below are a few examples of lattice paths:

βˆ˜βˆ™βˆ™βˆ™βˆ™βˆ˜βˆ™βˆ˜βˆ˜βˆ™βˆ˜βˆ˜ \ax{ \circ & \bullet & \bullet \\ \bullet & \bullet & \circ \\ \bullet & \circ & \circ \\ \bullet & \circ & \circ \\ }
βˆ˜βˆ˜βˆ™βˆ˜βˆ™βˆ™βˆ˜βˆ™βˆ˜βˆ™βˆ™βˆ˜ \ax{ \circ & \circ & \bullet \\ \circ & \bullet & \bullet \\ \circ & \bullet & \circ \\ \bullet & \bullet & \circ \\ }
βˆ™βˆ™βˆ™βˆ™βˆ˜βˆ˜βˆ™βˆ˜βˆ˜βˆ™βˆ˜βˆ˜ \ax{ \bullet & \bullet & \bullet \\ \bullet & \circ & \circ \\ \bullet & \circ & \circ \\ \bullet & \circ & \circ \\ }

In short, they're dots marking the vertices along a path, where, at each vertex, we can only move right by 1, or up by 1. It's likely not apparent, but these paths are closely related to binomial coefficients.

lattice path. A lattice path is a sequence P=((x0,y0),(x1,y1),…,(xk,yk)),{P=((x_0,y0), (x_1,y_1), \ldots,(x_k,y_k)),} where each xi{x_i} and yi{y_i} is an integer, such that (xi,yi)=(xiβˆ’1+1,yiβˆ’1),{(x_i,y_i)=(x_{i-1} + 1, y_{i-1}),} or (xi,yi)=(xiβˆ’1,yiβˆ’1+1),{(x_i,y_i)=(x_{i-1},y_{i-1}+1),} for all i∈N:iβ‰₯1.{i \in \nat : i \ge 1.}

While lattice diagrams are helpful, it's often easier to express them as words. If we start at some point (a,b){(a,b)} we can denote the path to some other point (c,d){(c,d)} with the letters N{N} (north) and E{E} (east). For example, if we start at the bottom-left point for the the lattice path:

βˆ˜βˆ™βˆ™βˆ™βˆ™βˆ˜βˆ™βˆ˜βˆ˜βˆ™βˆ˜βˆ˜ \ax{ \circ & \bullet & \bullet \\ \bullet & \bullet & \circ \\ \bullet & \circ & \circ \\ \bullet & \circ & \circ \\ }

we may denote it as: NNENE.{NNENE.} Viewed this way, we can see that this is an alphabet with two letters. If we want a lattice path from (0,0){(0,0)} to (a,b),{(a,b),} we need a{a} of the E{E} steps and b{b} of the N{N} step. Which in turn means that there, at most, (a+ba,b){\binom{a+b}{a,b}} lattice paths to get from (0,0){(0,0)} to (a,b).{(a,b).}

lattice path count. For all a,b∈N,{a,b \in \nat,} there are

(a+ba,b)=(a+b)!a!b! \dbinom{a+b}{a,b} = \dfrac{(a+b)!}{a!b!}

lattice paths from (0,0){(0,0)} to (a,b).{(a,b).}