-
Notifications
You must be signed in to change notification settings - Fork 16
/
math239.tex
5435 lines (4626 loc) · 224 KB
/
math239.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[]{article}
\usepackage[margin = 1.5in]{geometry}
\setlength{\parindent}{0in}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{wasysym}
\usepackage{soul}
\usepackage[T1]{fontenc}
\usepackage{ae,aecompl}
\usepackage{tikz}
\usepackage[lined]{algorithm2e}
\usepackage{enumerate}
\usepackage[pdftex,
pdfauthor={Chris Thomson},
pdftitle={MATH 239: Introduction to Combinatorics},
pdfsubject={Lecture notes from MATH 239 at the University of Waterloo},
pdfkeywords={MATH 239, course notes, notes, Waterloo, University of Waterloo, combinatorics, mathematics, graph theory},
pdfproducer={LaTeX},
pdfcreator={pdflatex}]{hyperref}
\usepackage{cleveref}
\newtheorem*{theorem}{Theorem}
\newtheorem*{corollary}{Corollary}
\newtheorem*{proposition}{Proposition}
\theoremstyle{definition}
\newtheorem{problem}{Problem}[section]
\newtheorem*{defn}{Definition}
\newtheorem{ex}{Example}[section]
\newcommand{\union}{\cup}
\newcommand{\intersection}{\cap}
\setlength{\marginparwidth}{1.5in}
\newcommand{\lecture}[1]{\marginpar{{\footnotesize $\leftarrow$ \underline{#1}}}}
\DeclarePairedDelimiter{\set}{\lbrace}{\rbrace}
\crefname{ex}{Example}{Examples}
\crefname{proposition}{Proposition}{Propositions}
\definecolor{darkish-blue}{RGB}{25,103,185}
\hypersetup{
colorlinks,
citecolor=darkish-blue,
filecolor=darkish-blue,
linkcolor=darkish-blue,
urlcolor=darkish-blue
}
\tikzset{
dot/.style 2 args={circle,inner sep=2pt,fill,label=#1:{#2},name=#2},
rdot/.style 2 args={circle,inner sep=2pt,fill=red,label=#1:{#2},name=#2},
gdot/.style 2 args={circle,inner sep=2pt,fill=green,label=#1:{#2},name=#2},
bdot/.style 2 args={circle,inner sep=2pt,fill=blue,label=#1:{#2},name=#2}
}
\makeatletter
\def\blfootnote{\gdef\@thefnmark{}\@footnotetext}
\makeatother
\begin{document}
\let\ref\Cref
\title{\bf{MATH 239: Introduction to Combinatorics}}
\date{Winter 2013, University of Waterloo \\ \center Notes written from Bertrand Guenin's lectures.}
\author{Chris Thomson}
\blfootnote{I'd love to hear your feedback. Feel free to email me at \href{mailto:[email protected]}{[email protected]}.}
\blfootnote{See \href{http://cthomson.ca/notes}{cthomson.ca/notes} for updates.
\ifdefined\sha % Also, \commitDateTime should be defined.
Last modified: \commitDateTime{} ({\href{https://github.com/christhomson/lecture-notes/commit/\sha}{\sha}}).
\fi
}
\maketitle
\newpage
\tableofcontents
\newpage
\section{Introduction, Permutations, and Combinations} \lecture{January 7, 2013}
\subsection{Course Structure}
The grading scheme is \st{50\%} 55\% final, 30\% midterm, \st{10\% quizzes} 5\% participation marks (clicker questions), and 10\% assignments. There are \st{ten quizzes and} ten assignments. \st{The quizzes will not be announced in advance, and each quiz consists of a single clicker question}. Assignments are typically due on Friday mornings at 10 am. in the dropboxes outside of MC 4066. The midterm exam is scheduled for March 7, 2013, from 4:30 pm - 6:20 pm. There is no textbook for the course, but there are course notes available at Media.doc in MC, and they're \emph{highly} recommended.
\\ \\
MATH 239 is split into two parts: counting (weeks 1-5) and graph theory (weeks 6-12).
\\ \\
See the course syllabus for more information -- it's available on \href{https://learn.uwaterloo.ca/}{Waterloo LEARN}.
\subsection{Sample Counting Problems}
\begin{problem}
How many ways are there to cut a string of length 5 into parts of sizes 1 and 2?
\end{problem}
Here are a few example cuts:
\\ \\
\begin{tabular}{|c|c|c|c|c|}
\hline
1 & 2 & 3 & 4 & 5 \\
\hline
\end{tabular}
5 cuts: size 1, size 1, size 1, size 1, size 1.
\begin{tabular}{|c|c|c|c|c|}
\hline
1 & 1 & 2 & 2 & 3 \\
\hline
\end{tabular}
3 cuts: size 2, size 2, size 1.
\begin{tabular}{|c|c|c|c|c|}
\hline
1 & 2 & 2 & 3 & 3 \\
\hline
\end{tabular}
3 cuts: size 1, size 2, size 2.
\\ \\
This is a finite problem. You could count all of the possibilities manually in this case. However, this problem could be made more complicated to a point where manually counting all possibilities would become quite cumbersome, as is the case in the next problem.
\begin{problem}[Cuts]
How many ways are there to cut a string of size 372,694 into parts of sizes 3, 17, 24, and 96?
\end{problem}
\begin{defn}
A positive integer $n$ has a \textbf{composition} $(m_1, m_2, \ldots, m_k)$, where $m_1, \ldots, m_k$ are positive integers and where $n = m_1 + m_2 + \ldots + m_k$. $m_1, \ldots, m_k$ are the \textbf{parts} of the composition.
\end{defn}
Problem 1 could be rephrased as looking for the number of compositions of 5 where all parts are 1 or 2.
\begin{problem}
How many compositions of $n$ exist such that all parts are odd?
\end{problem}
\begin{problem}[Binary Strings]
Let $S = a_1, a_2, \ldots, a_n$ where $a_i \in \set{0, 1}$. How many strings $S$ exist?
\end{problem}
For each $a_i$, there is the choice between $0$ or $1$, and that choice is independent for each character of the string (for each $a_i$). So, there are $2^n$ binary strings of length $n$.
\begin{problem}
How many binary strings of size $n$ exist that do not include the substring $1100$?
\end{problem}
For example: $1010\underline{1100}101 \not \in S$.
\begin{problem}
How many binary strings of size $n$ exist such that there is no odd-length sequences of zeroes?
\end{problem}
For example: $1001001\underline{000}11 \not \in S$.
\begin{problem}[Recurrences]
How many times does a recursive function get called for a particular input $n$?
\end{problem}
\subsection{Sample Graph Theory Problems}
\begin{problem}
For any arbitrary map of regions, colour the regions such that no two touching boundaries do not have the same colour, with the least number of colours possible.
\end{problem}
The \textbf{four-colour theorem} states that you can always do this with four colours. It's also always possible to colour these regions with five colours. It's \emph{sometimes} possible to colour the regions with three or fewer colours, depending on the layout of the regions and their boundaries.
\subsection{Permutations and Combinations}
\subsubsection{Set Notation}
The usual set and sequence notation is used in this course. $(1, 2, 3)$ is a sequence (where order matters), and $\set{1, 2, 3}$ is a set (where order does not matter).
\\ \\
We will also be using one piece of notation you may not be familiar with: $[n] := \set{1, 2, \ldots, n}$.
\subsubsection{Permutations}
\begin{defn}
A \textbf{permutation} of $[n]$ is a rearrangement of the elements of $[n]$. The number of permutations of a set of $n$ objects is $n \times (n - 1) \times \ldots \times 1 = n!$.
\end{defn}
For example: the number of permutations of $6$ objects is $6 \times 5 \times 4 \times 3 \times 2 \times 1 = 6!$ permutations.
\\ \\
Why is this the case? Simple: there are $n$ choices for the first position, $(n - 1)$ choices for the second position, $(n - 2)$ choices for the third position, and so on, until there's $1$ choice for the $n$th position.
\begin{defn}
A \textbf{$k$-subset} is a subset of size $k$.
\end{defn}
\begin{problem}
How many $k$-subsets of $[n]$ exist?
\end{problem}
Let's consider a more specific case: how many 4-subsets of 6 are there? $\frac{6 \times 5 \times 4 \times 3}{4!}$.
\\ \\
For simplicity's sake, we will introduce notation for this, which we will refer to as a \textbf{combination}, denoted as
$\binom{n}{k} = \frac{n!}{k!(n-k)!}$ where $n, k \in \mathbb{Z} \ge 0$.
\begin{proposition}
There are $\binom{n}{k}$ $k$-subsets of $[n]$.
\end{proposition}
\subsubsection{Application: Binomial Theorem} \lecture{January 9, 2013}
\begin{align*}
(1 + x)^n = \sum_{k = 0}^{n} \binom{n}{k} x^k
\end{align*}
Why is this true?
\begin{align*}
(1 + x)^3 = \overbrace{(1 + x)}^1\overbrace{(1 + x)}^2\overbrace{(1 + x)}^3 = 1 + 3x + 3x^2 + x^3 = \binom{3}{0} + \binom{3}{1}x + \binom{3}{2}x^2 + \binom{3}{3}x^3
\end{align*}
\begin{proof}
\begin{align*}
(1 + x)^n = \overbrace{(1 + x)}^1 \overbrace{(1 + x)}^2 \cdots \overbrace{(1 + x)}^n
\end{align*}
In order to get $x^k$, we need to choose $x$ in $k$ of $\set{1, \ldots, n }$. There are $\binom{n}{k}$ ways of doing this.
\end{proof}
\section{Simple Tools for Counting}
\subsection{Partitioning}
Sets $S_1, S_2$ partition the set $S$ if $S = S_1 \union S_2$ and $S_1 \intersection S_2 = \emptyset$.
\begin{ex}
\begin{align*}
S &= [5] = \begin{cases}
S_1 = \set{1, 2 } \\
S_2 = \set{3, 4, 5}
\end{cases} \\
|S| &= |S_1| + |S_2|
\end{align*}
\end{ex}
\begin{proposition}
$\displaystyle 2^n = \sum_{k = 0}^{n} \binom{n}{k}$
\end{proposition}
\begin{proof}
We will discuss two proof methods.
\begin{enumerate}
\item \textbf{Algebraic proof}. Set $x = 1$ in the Binomial Theorem.
\item \textbf{Combinatorial proof}. We will count the left-hand side and the right-hand side in different ways to reach the same result.
Let $S$ be the set of subsets of $[n]$. $|S| = 2^n$, since for every element of $[n]$ we have two possibilities: include or don't include the element in $S$.
\underline{Aside}: suppose $n = 2$. Then $S = \set{\emptyset, \set{1}, \set{2}, \set{1, 2}}$.
Partition $S$ into $S_0, S_1, \ldots, S_n$, where $S_k$ is the set of $k$-subsets of $[n]$.
\begin{align*}
\underbrace{|S|}_{2^n} = \underbrace{|S_0|}_{\binom{n}{0}} + \underbrace{|S_1|}_{\binom{n}{1}} + \cdots + \underbrace{|S_n|}_{\binom{n}{n}}
\end{align*}
\qedhere
\end{enumerate}
\end{proof}
\begin{proposition}
$\displaystyle \binom{n}{k} = \binom{n - 1}{k} + \binom{n - 1}{k - 1}$
\end{proposition}
\begin{proof}
Let $S$ be the set of $k$-subsets of $[n]$. Then $|S| = \binom{n}{k}$. Partitioning $S$, let $S_1$ be the subsets of $S$ containing $n$, and let $S_2$ be the subsets of $S$ not containing $n$.
\\ \\
It's easy to see that $|S_1| = \binom{n - 1}{k - 1}$ ($n$ is already included in our choices) and $|S_2| = \binom{n - 1}{k}$. We now have $|S| = |S_1| + |S_2| = \binom{n - 1}{k - 1} + \binom{n - 1}{k}$.
\end{proof}
\subsection{Pascal's Triangle}
Pascal's Triangle is a triangle where each value is determined by the sum of its two direct parents. The uppermost value is 1.
\\ \\
\begin{center}
\begin{tabular}{rccccccccc}
$n = 0$:& & & & & 1\\\noalign{\smallskip\smallskip}
$n = 1$:& & & & 1 & & 1\\\noalign{\smallskip\smallskip}
$n = 2$:& & & 1 & & 2 & & 1\\\noalign{\smallskip\smallskip}
$n = 3$:& & 1 & & 3 & & 3 & & 1\\\noalign{\smallskip\smallskip}
$n = 4$:& 1 & & 4 & & 6 & & 4 & & 1\\\noalign{\smallskip\smallskip}
\end{tabular}
\end{center}
\begin{proposition}
$\displaystyle \binom{q + r}{q} = \sum_{i = 0}^{r} \binom{q + i - 1}{q - 1}$
\end{proposition}
For example: let $q = 3, r = 2$. Then we have: $\displaystyle \binom{5}{3} = \binom{2}{2} + \binom{3}{2} + \binom{4}{2}$.
\begin{proof}
Let $S$ be the set of $q$-subsets of $[q + r]$, so $|S| = \binom{q + r}{q}$. Partition $S$ such that $S_i$ is the set of $q$-subsets where the largest element is $q + i$ (where $i = 0, \ldots, r$).
\\ \\
We have: $|S| = |S_0| + |S_1| + \cdots + |S_r|$. Note that $|S_i| = \binom{q + i - 1}{q - 1}$. That gives us:
\begin{align*}
\underbrace{|S|}_{\binom{q + r}{q}} = \underbrace{\sum_{i = 0}^{r} |S_i|}_{\binom{q + i - 1}{q - 1}}
\end{align*}
\end{proof}
\subsection{Injections, Bijections, and Onto} \lecture{January 11, 2013}
Let's consider a function $f: S \to T$.
\begin{defn}
The function $f$ is an \textbf{injection} if for all $x_1, x_2 \in S, x_1 \ne x_2$ such that $f(x_1) \ne f(x_2)$. That is, no element in the codomain $T$ is the image of more than one element in $S$.
\end{defn}
\begin{defn}
The function $f$ is \textbf{onto} (or a \textbf{surjection}) if for all $y \in T$, there exists $x \in S$ such that $f(x) = y$. That is, all elements in the codomain $T$ are the image of an element in $S$. Multiple elements in $S$ can map to the same element in $T$.
\end{defn}
\begin{defn}
The function $f$ is a \textbf{bijection} if it is both injective and onto. That is, there is a one-to-one mapping between elements in $S$ and $T$, and vice versa.
\end{defn}
\begin{proposition}
If $S$ and $T$ are finite, $|S| = |T|$ if $f$ is bijective.
\end{proposition}
\begin{defn}
$g$ is the inverse of $f$ if:
\begin{enumerate}
\item For all $x \in S, g(f(x)) = x$.
\item For all $y \in T, f(g(y)) = y$.
\end{enumerate}
\end{defn}
In order to show that a function has a bijection, find the inverse function.
\subsection{Application: Binomial Coefficients}
\begin{proposition}
$\displaystyle \binom{n}{k} = \binom{n}{n - k}$
\end{proposition}
\begin{proof}
I will prove this proposition in a combinatorial proof using the bijection technique. We want to show that the cardinalities are the same.
\\ \\
Let $S_1$ be the set of $k$-subsets of $[n]$, so $|S_1| = \binom{n}{k}$, as shown earlier. Let $S_2$ be the set of $(n-k)$-subsets of $[n]$, so $|S_2| = \binom{n}{n - k}$. We need to show that $|S_1| = |S_2|$, so we need to show that there is a bijection between $S_1$ and $S_2$, $f: S_1 \to S_2$.
\\ \\
\underline{Aside}: suppose $n = 5$ and $k = 2$. Then, the bijection could be $\set{1, 3} \to \set{2, 4, 5}$ (the complement function).
\\ \\
The bijective function is $f(A) = [n]\backslash A$ (the complement function). Check: $f$ is its own inverse (let $g = f$).
\end{proof}
\section{Power Series and Generating Functions}
\subsection{Power Series}
\begin{defn}
Let $(a_0, a_1, \ldots)$ be a sequence of rational numbers. Then:
\begin{align*}
A(x) = \sum_{i \ge 0} a_i x^i
\end{align*}
This is called a \textbf{power series}.
\end{defn}
\begin{ex}
$a_i = 2^i \implies A(x) = 1 + 2x + 4x^2 + 8x^3 + \cdots$
\end{ex}
If the sequence is finite, it is just a polynomial.
\subsubsection{A General Counting Problem}
Let $S$ be the set of objects $\sigma$. Each object $\sigma$ has a weight $w(\sigma)$. We want to know how many objects of $S$ have some weight $k$.
\begin{ex}
Let $\sigma \subseteq [n], w(\sigma) = |\sigma|$. The question becomes: how many $k$-subsets of $[n]$?
\end{ex}
\begin{ex}
Let $\sigma$ be a set of coins (1\cent, 5\cent, 10\cent, 25\cent, \$1, \$2), and let $w(\sigma)$ be the total value of the coins in $\sigma$.
\\ \\
The question becomes: how many sets of coins have total value $k$? In other words, how many ways are there to give $k$ amount of change?
\end{ex}
\subsection{Generating Functions}
\begin{defn}
Given $S$ as the set of objects $\sigma$ and a weight function $w(\sigma)$:
\begin{align*}
\phi_S(x) = \sum_{\sigma \in S} x^{w(\sigma)}
\end{align*}
This is called the \textbf{generating function for S, w}.
\end{defn}
\begin{ex}
Let $S = \set{\sigma | \sigma \subseteq \set{1, 2, 3} }, w(\sigma) = |\sigma|$.
\begin{center}
\begin{tabular}{c|c|c}
$\sigma$ & $w(\sigma)$ & $x^{w(\sigma)}$ \\ \hline
$\emptyset$ & 0 & 1 \\
$\set{1}$ & 1 & x \\
$\set{2}$ & 1 & x \\
$\set{3}$ & 1 & x \\
$\set{1, 2}$ & 2 & $x^2$ \\
$\set{1, 3}$ & 2 & $x^2$ \\
$\set{2, 3}$ & 2 & $x^2$ \\
$\set{1, 2, 3}$ & 3 & $x^3$ \\
\end{tabular}
\end{center}
$\phi_S(x) = 1 + 3x + 3x^2 + x^3 = (1 + x)^3$ is the generating function. Notice that the coefficients of each term are the number of objects who have that the weight indicated by the exponent of the $x$ in that term.
\end{ex}
\textbf{Remember}: the generating function for $S$ with weights $w$ is $\phi_S(x) = \sum_{k \ge 0} a_k x^k$, where $a_k$ is the number of objects of size $k$ in $S$.
\begin{ex}
\lecture{January 14, 2013}
Let $S$ be the set of subsets of [n], and $w(\sigma) = |\sigma|$.
\begin{align*}
\phi_S(x) = \sum_{k \ge 0} \binom{n}{k} x^k = (1 + x)^n
\end{align*}
Note that $\binom{n}{k}$ is included because that's the number of $k$-subsets of $[n]$. $\phi_S(x) = (1 + x)^n$ by the binomial theorem.
\end{ex}
\begin{proposition}
Let $\phi_S(x)$ be the generating function for finite-size $S$ with weight $w$. Then:
\begin{enumerate}
\item $\phi_S(1) = |S|$
\item $\phi_S'(1) = $ sum of the weight of all the objects in $S$.
\end{enumerate}
Together, we get:
\begin{align*}
\frac{\phi_S'(1)}{\phi_S(1)} = \text{average weight of objects in } S
\end{align*}
\end{proposition}
Considering the previous example again, we know that $|S| = 2^n$ and the average weight is clearly $\frac{n}{2}$. We can verify that with this proposition.
\begin{align*}
\phi_S(x) = (1 + x)^n &\implies \phi_S(1) = (1 + 1)^n = 2^n \\
\phi_S'(x) = n(1 + x)^{n - 1} &\implies \phi_S'(1) = n2^{n - 1} \\
\text{average weight } &= \frac{\phi_S'(1)}{\phi_S(1)} = \frac{n2^{n - 1}}{2^n} = \frac{n}{2}
\end{align*}
We'll now prove this proposition more generally.
\begin{proof}
We will prove the two parts of the proposition separately. The average weight clearly follows from those two results.
\begin{enumerate}
\item
\begin{align*}
\phi_S(x) = \sum_{\sigma \in S} x^{w(\sigma)}
\end{align*}
Choose $x = 1$. Then $\phi_S(1) = \sum_{\sigma \in S} 1 = |S|$.
\item
\begin{align*}
\phi_S'(x) = \sum_{\sigma \in S} w(\sigma)x^{w(\sigma) - 1}
\end{align*}
Choose $x = 1$. Then $\phi_S'(1) = \sum_{\sigma \in S} w(\sigma) \cdot 1 = $ total weight of all objects in $S$.
\end{enumerate}
\end{proof}
In order to work further with generating functions, we'll first need to learn how to manipulate power series generally.
\subsection{Working With (Formal) Power Series}
For the following definitions, we will assume the following power series are defined:
\begin{align*}
A(x) &= a_0 + a_1x + a_2x^2 + \cdots \\
B(x) &= b_0 + b_1x + b_2x^2 + \cdots
\end{align*}
\begin{defn}
We define \textbf{addition of power series} as follows.
\begin{align*}
A(x) + B(x) := \sum_{n \ge 0} (a_n + b_n)x^n
\end{align*}
Note that this definition is consistent with the definition of addition for polynomials.
\end{defn}
\begin{defn}
We define \textbf{multiplication of power series} as follows.
\begin{align*}
A(x)B(x) := \sum_{n \ge 0} \left( \sum_{k = 0}^{n} a_k b_{n - k} \right) x^n
\end{align*}
\end{defn}
\begin{ex}
\begin{align*}
&(1 + x + x^2 + x^3 + \cdots)(1 - x) \\
&= 1 \cdot 1 + (1 \cdot -1 + 1 \cdot 1)x + (1 \cdot 1 + 1 \cdot -1)x^2 + \cdots \\
& = 1
\end{align*}
\end{ex}
\begin{defn}
$B(x)$ is the \textbf{inverse} of $A(x)$ if $A(x)B(x) = 1$ (alternatively, $B(x)A(x) = 1$).
\\ \\
We will use the notation $B(x) = \frac{1}{A(x)}$ to indicate that $B(x)$ is the inverse of $A(x)$, and vice versa.
\end{defn}
\begin{ex}
The inverse of $(1 + x + x^2 + \cdots)$ is $(1 - x)$, as shown in the previous example.
\end{ex}
\textbf{Question}: does every power series have an inverse? No. For example, $(x + x^2)$ does not have an inverse.
\begin{proof}
Suppose $(x + x^2)$ has an inverse. If $(x + x^2)$ has an inverse, there would exist constants $b_i$ such that
\begin{align*}
(x + x^2)(b_0 + b_1x + b_2x^2 + b_3x^3 + \cdots) = 1
\end{align*}
Clearly, this is impossible. In order to equal 1, $b_0$ must multiply by some constant term, however there is no other constant term. Therefore, our assumption was incorrect, meaning $(x + x^2)$ does not have an inverse.
\end{proof}
\textbf{Remark}: if a power series does not have a constant term then it has no inverse, and vice versa.
\begin{theorem}
If the constant term of $A(x)$ is non-zero, then $A(x)$ has an inverse, and we can find it.
\end{theorem}
\textbf{Notation}: given a power series $A(x)$, we say $[x^k]A(x)$ represents the coefficient of $x^k$.
\begin{ex}
Find the inverse of $1 - x + x^2 - x^3 + x^4 - \cdots$.
\begin{align*}
\underbrace{(1 - x + x^2 - x^3 + x^4 - \cdots)(b_0 + b_1x + b_2x^2 + \cdots)}_{(\star)} = 1
\end{align*}
\begin{align*}
[x^0](\star) = 1 \implies 1 \cdot b_0 = 1 &\implies b_0 = 1 \\
[x^1](\star) = 0 \implies 1 \cdot b_1 - 1 \cdot b_0 = 0 &\implies b_1 = b_0 = 1 \\
[x^2](\star) = 0 \implies 1 \cdot b_2 - 1 \cdot b_1 + 1 \cdot b_0 = 0 &\implies b_2 = b_1 - b_0 = 0
\end{align*}
Similarly, $b_3 = b_4 = \cdots = 0$. Thus, the inverse is $(1 + x)$.
\end{ex}
It's clear that the inverse for a power series is \textbf{unique}. We made no choices when determining the inverse, therefore it must be unique.
\subsubsection{Finding Inverses} \lecture{January 16, 2013}
Given:
\begin{align*}
A(x) = \sum_{n \ge 0} a_nx^n \text{ where } (a_0 \ne 0)
\end{align*}
We want to find:
\begin{align*}
B(x) = \sum_{n \ge 0} b_nx^n
\end{align*}
We'll start by finding $b_0$:
\begin{align*}
[x^0]A(x)B(x) = a_0b_0 = 1 \implies b_0 = \frac{1}{a_0}
\end{align*}
Notice that if we didn't have the restriction on $a_0$, we would've run into trouble here. Now, suppose you found $b_0, b_1, \ldots, b_{n - 1}$ for $n \ge 1$. Find $b_n$.
\begin{align*}
b_n = \frac{1}{a_0} \cdot (-a_1b_{n - 1} - a_2b_{n - 2} - \ldots - a_nb_0)
\end{align*}
\begin{proposition}
Let $A(x)$ and $P(x)$ be formal power series.
Suppose the constant for $A(x)$ is not 0. Then there exists a unique $B(x)$ such that $A(x)B(x) = P(x)$.
\end{proposition}
\textbf{Some useful formul\ae}:
\begin{align*}
\frac{1}{1 - x} = 1 + x + x^2 + x^3 + \cdots &\text{ since } 1 = (1 + x + x^2 + \cdots)(1 - x) \\
\frac{1 - x^{k+1}}{1-x} = 1 + x + x^2 + \cdots + x^k &\text{ since } 1 - x^{k+1} = (1 + x + x^2 + \cdots + x^k)(1-x)
\end{align*}
\subsubsection{Compositions}
\begin{defn}
Let $A(x)$ and $B(x)$ be formal power series defined by:
\begin{align*}
A(x) = \sum_{n \ge 0} a_n x^n \hspace{1cm} B(x) = \sum_{n \ge 0} b_n x^n
\end{align*}
We define the \textbf{composition} as:
\begin{align*}
A(B(x)) := \sum_{n \ge 0} a_n [B(x)]^n
\end{align*}
\end{defn}
\begin{ex}
Let $A(x) = 1 + x + x^2 + x^3 + \cdots$ and $B(x) = 2x$. Then the composition is $A(B(x)) = 1 + 2x + 4x^2 + 8x^3 + \cdots$.
\end{ex}
\textbf{Question}: is the composition of two formal power series a formal power series itself? No.
\begin{ex}
Suppose we pick $A(x) = 1 + x + x^2 + x^3 + \cdots$ and $B(x) = 1 + x$.
\\ \\
We have $A(B(x)) = 1 + (1 + x) + (1 + x)^2 + (1 + x)^3 + \cdots$. This cannot be a formal power series because a formal power series requires that all coefficients ($a_k$) need to be rational numbers, and in this case $a_0$ is infinite.
\end{ex}
\begin{ex}
Suppose we pick $A(x) = 1 + x + x^2 + x^3 + \cdots$ and $B(x) = x + x^2$.
\\ \\
We have $A(B(x)) = 1 + (x + x^2)^1 + (x + x^2)^2 + \cdots$. In order to show that this is a formal power series, we need to show that the coefficient of $x^k$ (which is $a_k$) is finite for all $k$.
\end{ex}
\begin{theorem}
Let $A(x)$ and $B(x)$ be formal power series, and $[x^0]B(x) = 0$ ($B(x)$'s constant is zero). Then $A(B(x))$ is a formal power series.
\end{theorem}
\underline{Aside}:
\begin{align*}
A(B(x)) = 1 + (\underbrace{x + x^2}_{x(1+x)})^1 + (\underbrace{x + x^2}_{x(1+x)})^2 + (\underbrace{x + x^2}_{x(1+x)})^3 + \cdots
\end{align*}
\begin{proof}
We need to show that for any fixed $k$, $[x^k]A(B(x))$ is finite.
\\ \\
Let $R(x)$ be such that $B(x) = xR(x)$. Then we have:
\begin{align*}
[x^k]A(B(x)) &= [x^k] \sum_{n \ge 0} a_n[B(x)]^n \\
&= [x^k] \sum_{n \ge 0} a_n x^n R(x) \\
&= [x^k] \sum_{n \ge 0}^{k} a_n x^n (R(x))^n
\end{align*}
We made the last sum finite because we're interested in the coefficient of $x^k$ only. Note that this last line shows we can determine the coefficient in a finite number of steps, since $k$ is finite.
\end{proof}
\begin{ex}
Let $y \mapsto x^2$ (I will call $x^2$, $y$).
\begin{align*}
\frac{1}{1 - x^2} = \frac{1}{1 - y} &= 1 + y + y^2 + y^3 + \cdots \\
&= 1 + x^2 + x^4 + x^6 + \cdots
\end{align*}
This is a composition with $A(x) = 1 + y + y^2 + \cdots$ and $B(x) = x^2$ (constant is zero). We were only allowed to do this because $[x^0]B(x) = 0$.
\end{ex}
\subsubsection{Cartesian Product}
\begin{defn}
Let $A$ and $B$ be sets. The \textbf{cartesian product} is defined as:
\begin{align*}
A \times B := \set{(a, b) \big| a \in A, b \in B }
\end{align*}
Note that $(a, b)$ is an ordered pair.
\end{defn}
\begin{ex}
Let $A = \set{1, 2, 3}$ and $B = \set{x, y}$. Then $A \times B = \set{(1, x), (2, x), (3, x), (1, y), (2, y), (3, y) }$.
\end{ex}
The cardinality of $A \times B$ is the product of the cardinalities of $A$ and $B$: $|A \times B| = |A||B|$.
\subsection{The Sum and Product Lemmas}
Let's consider a bin of two red marbles -- one large marble (denoted $R$), and one small marble (denoted $r$). We define $A$ to be the set of all selections of $\ge 1$ marbles. We know:
\begin{align*}
A &= \set{\set{r}, \set{R}, \set{r, R} } \\
w(\sigma) &= |\sigma| \\
\phi_A(x) &= x + x + x^2 = 2x + x^2
\end{align*}
Let's now consider a bin of green marbles -- two large marbles (denoted $G$). We define $B$ to be the set of all selections of $\ge 1$ marbles. We know:
\begin{align*}
B &= \set{\set{G}, \set{G, G} } \\
w(\sigma) &= |\sigma| \\
\phi_B(x) &= x + x^2
\end{align*}
\subsubsection{Sum Lemma}
Let $S = A \union B = \set{\set{r}, \set{R}, \set{r, R}, \set{G}, \set{G, G} }$, and note that $A \intersection B = \emptyset$. What is the generating function for $S$?
\begin{align*}
\phi_S(x) = \underbrace{(x + x + x^2)}_{\phi_A(x)} + \underbrace{(x + x^2)}_{\phi_B(x)}
\end{align*}
This works in general.
\begin{theorem}[Sum Lemma]
We have a set $S$ of objects with weight $w$. Let $A$ and $B$ be partitions of $S$. Then:
\begin{align*}
\phi_S(x) = \phi_A(x) + \phi_B(x)
\end{align*}
\end{theorem}
\begin{proof}
\begin{align*}
\phi_S(x) = \sum_{\sigma \in S} x^{w(\sigma)} = \underbrace{\sum_{\sigma \in A} x^{w(\sigma)}}_{\phi_A(x)} + \underbrace{\sum_{\sigma \in B} x^{w(\sigma)}}_{\phi_B(x)}
\end{align*}
\end{proof}
\subsubsection{Product Lemma} \lecture{January 18, 2013}
Let $S = A \times B = \set{(\set{r}, \set{G}), (\set{R}, \set{G}), (\set{r, R}, \set{G}), (\set{r}, \set{G, G}), (\set{R}, \set{G, G}), (\set{r, R}, \set{G, G}) }$. $S$ is the various ways of selecting marbles from both bins. Let $w(\sigma)$ be the number of marbles selected in total.
\\ \\
\textbf{Note}: you can think of a generating series as the sum of all objects' $x^{w(\sigma)}$, or you can think of it as the sum of all $a_k x^k$.
\begin{align*}
\phi_S(x) &= x^2 + x^2 + x^3 + x^3 + x^3 + x^4 \\
&= 2x^2 + 3x^3 + x^4 \\
&= (x + x + x^2)(x + x^2) \\
&= \phi_A(x) \cdot \phi_B(x)
\end{align*}
This works in general.
\\ \\
Each term in $\phi_A(x)$ corresponds to an object in $A$, and each term in $\phi_B(x)$ corresponds to an object in $B$. When you find the product, it automatically does the counting for you, due to exponentiation laws.
\begin{theorem}[Product Lemma]
Let $A$ be a set where objects have weight $\alpha$, and let $B$ be a set where objects have weight $\beta$. Let $S = A \times B$ be a set of all objects $(a, b) \in S$, where $w[(a, b)] = \alpha(a) + \beta(b)$. Then:
\begin{align*}
\phi_S(x) = \phi_A(x) \cdot \phi_B(x)
\end{align*}
\end{theorem}
\begin{proof}
\begin{align*}
\phi_S(x) &= \sum_{(a, b) \in S} x^{w[(a, b)]} \\
&= \sum_{(a, b) \in S} x^{\alpha(a) + \beta(b)} \\
&= \underbrace{\bigg[ \sum_{a \in A} x^{\alpha(a)} \bigg]}_{\phi_A(x)} \cdot \underbrace{\bigg[ \sum_{b \in B} x^{\beta(b)} \bigg]}_{\phi_B(x)}
\end{align*}
\end{proof}
\begin{ex}
Given integers $n \ge 0$ and $k \ge 0$, how many $k$-tuples $(m_1, m_2, \ldots, m_k)$ (where $m_i \ge 0, m_i \in \mathbb{Z}$) exist where $m_1 + m_2 + \ldots + m_k = n$?
\\ \\
Suppose $n = 3$ and $k = 2$. You'll have $(0, 3), (1, 2), (2, 1)$, and $(3, 0)$ \textendash{} four possibilities (notice order matters).
\\ \\
We have $\mathbb{N}_0 = \set{0, 1, 2, 3, \ldots }, w(a) = a$ (for $a \in \mathbb{N}_0$). Then:
\begin{align*}
\phi_{\mathbb{N}_0}(x) = \sum_{n \ge 0} a_n x^n = 1 + x + x^2 + x^3 + \ldots = \frac{1}{1-x}
\end{align*}
Now, let $S = \overbrace{\mathbb{N}_0 \times \mathbb{N}_0 \times \ldots \times \mathbb{N}_0}^{\mathbb{N}_0 \text{ appears } k \text{ times}}$. The objects in $S$ are sequences of form $(m_1, m_2, \ldots, m_k)$, where $m_i \ge 0, m_i \in \mathbb{Z}$. We define $w[(m_1, m_2, \ldots, m_k)] = m_1 + m_2 + \ldots + m_k$.
\begin{align*}
\phi_S(x) = [\phi_{\mathbb{N}_0}(x)]^k = \frac{1}{(1-x)^k} \text{ by the product lemma}
\end{align*}
Therefore, the number of $k$-tuples $(m_1, m_2, \ldots, m_k)$ (where $m_i \ge 0, m_i \in \mathbb{Z}$) where $m_1 + m_2 + \ldots + m_k = n$ is given by $[x^n]\frac{1}{(1 - x)^k}$. We cannot figure out this coefficient. Let's leave generating functions for now, and find a combinatorial proof for this.
\end{ex}
When you use the product lemma, you need to ensure:
\begin{enumerate}
\item Ensure it's used on something found by taking the cartesian product.
\item The weight is equal to the sum of the weights.
\end{enumerate}
\begin{ex}
Let $n = 5$ and $k = 3$. We have:
\begin{center}
(1, 2, 2): \textbullet{} | \textbullet{} \textbullet{} | \textbullet{} \textbullet{} \\
(2, 3, 0): \textbullet{} \textbullet{} | \textbullet{} \textbullet{} \textbullet{} |
\end{center}
We have $n$ dots and $k-1$ intervals, which gives us:
\begin{align*}
\binom{n + (k - 1)}{k - 1} = \binom{7}{2} \text{ (in this case) }
\end{align*}
We always want two bars because $k = 3$. In general, we always want $k - 1$ bars. We want $n$ dots. The combination above is formed by the need to place $k - 1$ bars among all of the positions.
\end{ex}
By combining the previous two examples, we have proven the following theorem.
\begin{theorem}[Theorem 1.6.5]
\begin{align*}
[x^n] \frac{1}{(1 - x)^k} = \binom{n + k - 1}{k - 1}
\end{align*}
\end{theorem}
\begin{defn}
Some integer $n$ has \textbf{composition} $(m_1, m_2, \ldots, m_k)$ if $m_1 + m_2 + \ldots + m_k = n$, where $m_i \ge 1, m_i \in \mathbb{Z}$. Note that the only difference from earlier is that $m_i \ge 1$ instead of $m_i \ge 0$.
\end{defn}
\begin{ex}
We have $\mathbb{N} = \set{1, 2, 3, \ldots }, w(a) = a$ (for $a \in \mathbb{N}$), which gives us:
\begin{align*}
\phi_{\mathbb{N}}(x) = x + x^2 + x^3 + \ldots = x(1 + x + x^2 + \ldots) = \frac{x}{1 - x}
\end{align*}
Note that $\phi_{\mathbb{N}}(x)$ is missing the object of size zero (the constant term).
\\ \\
Let $S = \overbrace{\mathbb{N} \times \mathbb{N} \times \ldots \times \mathbb{N}}^{k \text{ occurrences of } \mathbb{N} \text{ here}}$. We also define the weight as $w[(m_1, m_2, \ldots, m_k)] = m_1 + m_2 + \ldots + m_k$. Then:
\begin{align*}
\phi_S(x) = [\phi_{\mathbb{N}}(x)]^k = \frac{x^k}{(1 - x)^k}
\end{align*}
\lecture{January 21, 2013}
We're interested in finding $[x^n]x^k \frac{1}{(1 - x)^k}$.
\begin{align*}
[x^n]x^k \frac{1}{(1 - x)^k} &= [x^{n-k}] \frac{1}{(1 - x)^k} \\
&= \binom{(n - k) + k - 1}{k - 1} \\
&= \binom{n - 1}{k - 1}
\end{align*}
\end{ex}
\begin{ex}
We now want to know the number of compositions of $n$ (where $n \ge 1$) where we have an arbitrary number of parts. We have: $S = \mathbb{N} \union \mathbb{N}^2 \union \mathbb{N}^3 \union \mathbb{N}^4 \union \mathbb{N}^5 \union \ldots$. The weight function is the same as before \textendash{} the sum of the parts. That gives us:
\begin{align*}
\phi_S(x) = \sum_{k \ge 1} \phi_{\mathbb{N}^k}(x) = \sum_{k \ge 1} \bigg( \frac{x}{1 - x} \bigg)^k
\end{align*}
We want:
\begin{align*}
[x^n]\sum_{k \ge 1} \bigg( \frac{x}{1 - x} \bigg)^k
\end{align*}
Which is a composition of:
\begin{align*}
A(y) &= y + y^2 + y^3 + \ldots = y(1 + y + y^2 + \ldots) = \frac{y}{1 - y} \\
B(x) &= \frac{x}{1 - x}
\end{align*}
The composition is $A(B(x))$, but we need to be careful before using compositions. We can easily check that the constant of $B(x)$ is not zero, as required:
\begin{align*}
B(x) = \frac{x}{1 - x} = x(1 + x + x^2 + \ldots) \implies [x^0]B(x) = 0
\end{align*}
The composition is well-defined. So, we have:
\begin{align*}
\sum_{k \ge 1} \bigg( \frac{x}{1 - x} \bigg)^k = \frac{\frac{x}{1 - x}}{1 - \frac{x}{1 - x}} = \frac{x}{1 - 2x}
\end{align*}
We still need to figure out the coefficient $[x^n]\frac{x}{1 - 2x}$.
\begin{align}
[x^n] \frac{x}{1 - 2x} &= [x^{n - 1}] \frac{1}{1 - 2x} \\
&= [x^{n - 1}](1 + y + y^2 + \ldots) \\
&= [x^{n - 1}](1 + (2x) + (2x)^2 + \ldots) \\
&= 2^{n - 1}
\end{align}
(1) is a common, useful trick. We eliminate any instances of $x$ that are simply multiplied by something, by reducing the power of the coefficient we're looking for. (4) is true since every term is in the form $(2x)^k$.
\end{ex}
We might be able to avoid generating functions in some cases by using a combinatorial proof. Now, we'll look at an arbitrary, convoluted example where a combinatorial proof would not suffice. This aims to show that generating functions are solid and can apply in many more situations than combinatorial proofs.
\begin{ex}
We want to find the number of compositions of $n$ with $2k$ parts, where the first $k$ parts are $\le 5$ and the last $k$ parts are $\ge 3$.
\\ \\
A specific instance of this problem is when $n = 22$ and $k = 3$, we have:
\begin{align*}
(\underbrace{\dots}_{\le 5}&, \underbrace{\dots}_{\ge 3}) \\ \\
(\underbrace{1, 3, 5}_{\le 5}&, \underbrace{3, 6, 4}_{\ge 3})
\end{align*}
It's useful to think about what you're counting. In this case, you're counting the $k$-tuples, so this is the cartesian product of six sets (the first three being the set of positive integers $\le 5$ and the last three being the set of integers $\ge 3$).
\begin{align*}
\mathbb{N}_{\le 5} &= \set{1, 2, 3, 4, 5} \\
\mathbb{N}_{\ge 3} &= \set{3, 4, 5, \ldots}
\\ \\
S &= (\mathbb{N}_{\le 5})^k \times (\mathbb{N}_{\ge 3})^k
\end{align*}
The weight is the sum of the six individual numbers in the tuple, since $\mathbb{N}_{\le 5}$ and $\mathbb{N}_{\ge 3}$'s weights are both defined by $w(a) = a$, which gives us:
\begin{align*}
\phi_{\mathbb{N}_{\le 5}}(x) &= x + x^2 + x^3 + x^4 + x^5 \\
\phi_{\mathbb{N}_{\ge 3}}(x) &= x^3 + x^4 + x^5 + \ldots
\end{align*}
\lecture{January 23, 2013}
We can expand the generating functions $\phi_{\mathbb{N}_{\le 5}}(x)$ and $\phi_{\mathbb{N}_{\ge 3}}(x)$.
\begin{align*}
\phi_{\mathbb{N}_{\le 5}}(x) &= x + x^2 + x^3 + x^4 + x^5 \\
&= x(1 + x + x^2 + x^3 + x^4) \\
&= x \bigg( \frac{1 - x^5}{1 - x} \bigg)
\\ \\
\phi_{\mathbb{N}_{\ge 3}}(x) &= x^3 + x^4 + x^5 + \ldots \\
&= x^3(1 + x + x^2 + \ldots) \\
&= \frac{x^3}{1 - x}
\end{align*}
Now, we have $S = (\mathbb{N}_{\le 5})^k \times (\mathbb{N}_{\ge 3})^k$ with weight function $w[(a_1, \ldots, a_{2k})] = a_1 + a_2 + \ldots + a_{2k}$. By the product lemma, we get:
\begin{align*}
\phi_S(x) &= x^k \bigg(\frac{1 - x^5}{1 - x}\bigg)^k \bigg( \frac{x^3}{1 - x} \bigg)^k \\
&= x^{4k}(1 - x^5)^k (1-x)^{-2k}
\end{align*}
We're still interested in finding $[x^n]\phi_S(x)$. This becomes tedious, but the general idea is:
\begin{align*}
[x^n] \underbrace{x^{4k}}_{\text{collapse into } [x^n] \text{ to become } [x^{n - 4k}]} \cdot \underbrace{(1 - x^5)^k}_{\text{expand with binomial theorem}} \cdot \underbrace{(1 - x)^{-2k}}_{\text{ use formula } [x^n]\frac{1}{(1 - x)^k}}
\end{align*}
After much tedious work, you'll discover that the final result is:
\begin{align*}
[x^n] \phi_S(x) = \sum_{i = 0}^{\lfloor \frac{n - 4k}{5} \rfloor} (-1)^i \binom{k}{i} \binom{n - 5i - 2k - 1}{2k - 1}
\end{align*}
This couldn't have been found with a combinatorial proof. That's why generating functions are powerful \textendash{} they work even in convoluted situations like this one.
\end{ex}
\begin{ex}
We're interested in the number of compositions of $n$ where all parts are odd. There can be an arbitrary number of parts.
\\ \\
For example, with $n = 5$, the five solutions are:
\begin{align*}
\set{(1, 1, 1, 1, 1), (5), (3, 1, 1), (1, 3, 1), (1, 1, 3) }
\end{align*}
We'll define $n = 0$ to have a unique composition (), the empty tuple.
\\ \\
We have $\mathbb{N}_{\text{odd}} = \set{1, 3, 5, 7, \ldots}$, with its weight function defined to be $w(a) = a$ for any $a \in \mathbb{N}_{\text{odd}}$. That gives us its generating function:
\setcounter{equation}{0}
\begin{align}
\phi_{\mathbb{N}_{\text{odd}}}(x) &= x + x^3 + x^5 + x^7 + \ldots \\
&= x(1 + x^2 + x^4 + x^6 + \ldots) \\
&= x(1 + y + y^2 + y^3 + \ldots) \text{ where } y = x^2 \\
&= \frac{x}{1 - y} \\
&= \frac{x}{1 - x^2}
\end{align}
(3) is an acceptable composition because $x^2$ has a constant term of zero.
\\ \\
Now, we have that $\displaystyle S = () \bigcup_{k \ge 1} \mathbb{N}_{\text{odd}}^k$. By the sum and product lemmas, the generating function for $S$ is:
\setcounter{equation}{0}
\begin{align}
\phi_S(x) &= 1 + \sum_{k \ge 1} \phi_{\mathbb{N}_{\text{odd}}}^k(x) \\
&= 1 + \sum_{k \ge 1} \bigg( \frac{x}{1 - x^2} \bigg)^k \\
&= \sum_{k \ge 0} \bigg( \frac{x}{1 - x} \bigg)^k \\
&= 1 + z + z^2 + z^3 + \ldots \text{ where } z = \frac{x}{1 - x^2} \\
&= \frac{1}{1 - z} \\
&= \frac{1}{1 - \frac{x}{1 - x^2}} \\
&= \frac{1 - x^2}{1 - x - x^2}
\end{align}
(4) is a valid composition because $\frac{x}{1 - x^2}$ has a constant term of zero.
\\ \\
What is $[x^n] \frac{1 - x^2}{1 - x - x^2}$? (Don't think of assigning values to $x$. Just focus on canceling them out.)
\\ \\
\begin{align*}
\frac{1 - x^2}{1 - x - x^2} &= \sum_{n \ge 0} a_n x^n \\
1 - x^2 &= (1 - x - x^2)(a_0 + a_1x + a_2x^2 + \ldots) \\
&= a_0 + a_1x + a_2x^2 + a_3x^3 + \ldots - a_0x -a_1x^2 - a_2x^3 - a_3x^4 - \ldots -a_0x^2 - a_1x^3 - a_2x^4 - a_3x^5 - \ldots \\
&= a_0 + (a_1 - a_0)x + (a_2 - a_1 - a_0)x^2 + (a_3 - a_2 - a_1)x^3 + \ldots
\end{align*}
We know $a_0 = 1$ and $(a_1 - a_0) = 0$, and so on. We can express a recurrence relation for this.
\begin{align*}
a_0 &= 1 \\
a_1 - a_0 = 0 \implies a_1 &= 1 \\
a_2 - a_1 - a_0 = -1 \implies a_2 &= -1 + a_1 + a_0 = 1 \\
a_3 - a_2 - a_1 = 0 \implies a_3 &= a_1 + a_2 = 2 \\
a_4 &= a_3 + a_2 = 3 \\
a_5 &= a_4 + a_3 = 5 \\
\vdots&
\end{align*}
For all $n \ge 3$, we have that $a_n = a_{n - 1} + a_{n - 2}$. This defines the \textbf{fibonacci numbers}.
\end{ex}
\begin{defn}
The \textbf{golden ratio} is a pair of integers $a$ and $b$ such that $\frac{a + b}{a} = \frac{a}{b}$. It's a ratio that comes up in nature a lot, and is aesthetically pleasing.
\end{defn}
You can approximate the golden ratio with the Fibonacci numbers. $\frac{a_n}{a_{n - 1}}$ approaches the golden ratio as $n \to \infty$.
\begin{ex}
Let $S_n$ be the set of compositions into odd numbers of $n$. $|S_n| = |S_{n - 1}| + |S_{n - 2}|$ for $n \ge 2$. $S_n$ is partitioned by $S_{n - 1}$ and $S_{n - 2}$. Is there a bijection between $S_n$ and $S_{n - 1} \cup S_{n - 2}$?
\\ \\
Let's look at the case where $n = 5$. We have: \lecture{January 25, 2013}
\begin{align*}
\overbrace{\set{(1, 1, 1, 1, 1), (3, 1, 1), (1, 3, 1), (1, 1, 3), (5) }}^{S_n} \\
\set{\underbrace{(1, 1, 1, 1), (3, 1), (1, 3)}_{S_{n - 1}}, \underbrace{(1, 1, 1), (3)}_{S_{n - 2}} }
\end{align*}
Notice that each element in $S_{n - 1}$ and $S_{n - 2}$ can be obtained from $S_n$ by either removing the last element entirely, or by subtracting 2 from the last element. That's the bijection we're looking for, which we will now define more formally as $f : S_n \to S_{n - 1} \cup S_{n - 2}$:
\begin{align*}
f(a_1, \ldots, a_k) = \begin{cases}
(a_1, \ldots, a_{k - 1}) & a_k = 1 \\
(a_1, \ldots, a_{k - 2}) & a_k \ge 3
\end{cases}
\end{align*}
Note that $f(a_1, \ldots, a_k)$ is undefined for $1 < k < 3$, but that's okay because we're only interested in odd natural numbers.
\\ \\
We have to somehow show that $f$ actually is a bijection. We can do that by constructing its inverse. In our case, the inverse is simply providing an inverse procedure.
\\ \\
Therefore, $|S_n| = |S_{n - 1}| + |S_{n - 2}|$, which is a general property of bijections.
\end{ex}
\section{Binary Strings}
\begin{defn}
A \textbf{binary string} is a string composed of 0s and 1s. For example, $011001110011$ is a binary string.
\end{defn}
\begin{defn}
We define the operation of \textbf{concatenation of two binary strings} $a_1, a_2$ as $a_1 a_2$. For example, if $a_1 = 110$ and $a_2 = 011$, the concatenation $a_1 a_2 = 110011$.
\end{defn}
\begin{defn}
The \textbf{concatenation $\mathbf{AB}$ of two sets} ($A$ and $B$) of binary strings is defined as all possible strings formed as concatenations of one string from set $A$ followed by one string from set $B$. For example, if $A = \set{011, 11 }$ and $B = \set{10, 0}$, then $AB = \set{01110, 0110, 1110, 110 }$.
\end{defn}
\begin{defn}
Suppose $A$ is a set of strings. Then $A^k = \underbrace{AAAAA \ldots A}_{k \text{ times}}$.
\end{defn}
\begin{defn}
We define $A^\star = \set{\epsilon } \cup A \cup A^2 \cup A^3 \cup \ldots$, where $\epsilon$ represents the empty string.
\end{defn}
\begin{ex}
What is $\set{0, 1 }^\star$? It's the set of \emph{all} binary strings.
\end{ex}
\begin{ex}
What's $\set{0, 1 }^5$? $\set{0, 1 }^5 = \set{0, 1 } \set{0, 1 } \set{0, 1 } \set{0, 1 } \set{0, 1 }$. $\set{0, 1}^5$ is the set of all binary strings of length 5.
\end{ex}
\begin{ex}
Describe the set $S$ of all binary strings with no three consecutive 1s. For example: $a = 011000\underline{111}01001 \not \in S$, $b = 0\underline{111}10 \not \in S$, but $c = 0110010011011 \in S$. We aim to express $S$ using expression-$\star$ concatenation.
\\ \\
Let's take a second look at $c$.
\begin{align*}
c = \underbrace{0,110,0,10,0,110}_{(1)},\underbrace{11}_{(2)} \in S
\end{align*}
\begin{enumerate}
\item A sequence of at most two ones followed by zero, repeated: $\set{0, 10, 110 }^\star$
\item A sequence of zero, one, or two ones: $\set{\epsilon, 1, 11 }$.
\end{enumerate}
Therefore, $S = \set{0, 10, 110}^\star \set{\epsilon, 1, 11 }$. Note that $\epsilon$ is an element of $\set{\text{anything} }^\star$.
\end{ex}
\begin{defn}
A \textbf{block} in a binary string is equal to the maximum sequence of 0s or 1s.
\end{defn}
\begin{ex}
List all the blocks in the string $1100011110110101$.
\begin{align*}
\underbrace{11} \underbrace{000} \underbrace{1111} \underbrace{0} \underbrace{11} \underbrace{0} \underbrace{1} \underbrace{0} \underbrace{1}
\end{align*}
\end{ex}
\begin{ex}
Describe the set $S$ of strings with no blocks of length 2. For example, $a = 10\underline{11}000101 \not \in S$, but $b = 1110111000101000 \in S$.
\\ \\
Let's take another look at $b$.
\begin{align*}
b = \underbrace{111}_{(1)},\underbrace{0111,0001,01}_{(2)},\underbrace{000}_{(3)} \in S
\end{align*}
\begin{enumerate}
\item A sequence of ones, of any length other than length 2: $\set{\epsilon, 1, 111, 1111, 11111, \ldots }$.
\item A sequence of zeroes (of any non-zero length other than length 2), followed by a sequence of ones (of any non-zero length other than length 2), repeated: $[ \set{0, 000, 0000, \ldots } \set{1, 111, 1111, \ldots } ]^\star$.
\item A sequence of zeroes, of any length other than length 2: $\set{\epsilon, 0, 000, 0000, 00000, \ldots }$.
\end{enumerate}
It's important to note that $\set{1, 111, 1111, \ldots, 0, 000, 0000, \ldots }^\star$ does not work because you could pick two zeroes or two ones consecutively, which is not allowed. You have to be very careful that you don't generate strings that you don't want to generate.
\end{ex}
\subsection{Generating Functions for Strings}
We'd like to have something like the product lemma but for strings.