Repository navigation
Expand file tree
/
Copy pathnotes.tex
More file actions
239 lines (190 loc) · 5.77 KB
/
Copy pathnotes.tex
File metadata and controls
239 lines (190 loc) · 5.77 KB
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
\section*{Stirling Numbers of the First Kind}
\subsection*{Definition}
The \textbf{Stirling number of the first kind} $s(n,k)$ counts the number of permutations of $n$ distinct elements that decompose into exactly $k$ disjoint cycles:
\[
\boxed{
s(n,k) = \text{number of permutations of } n \text{ elements with exactly } k \text{ cycles.}
}
\]
These numbers may also be signed as $s(n,k) = (-1)^{n-k} |s(n,k)|$, where $|s(n,k)|$ counts the number of permutations regardless of sign.
\subsection*{Cycles in a permutation}
A \textbf{cycle} is a component of a permutation that maps elements among themselves in a circular fashion.
For example, in a permutation of $\{1,2,3,4\}$:
\[
\pi(1)=3,\ \pi(3)=1,\ \pi(2)=4,\ \pi(4)=2,
\]
we can write:
\[
\pi = (1\ 3)(2\ 4),
\]
which consists of two disjoint cycles: $(1\ 3)$ and $(2\ 4)$.
Thus, this permutation contributes to $s(4,2)$ since it has $2$ cycles.
\subsection*{Recurrence Relation}
The Stirling numbers of the first kind satisfy:
\[
\boxed{
s(n,k) = s(n-1,k-1) + (n-1)\,s(n-1,k)
}
\]
with base cases:
\[
s(0,0)=1, \quad s(n,0)=0 \ (n>0), \quad s(0,k)=0 \ (k>0).
\]
\paragraph{Interpretation.}
To build a permutation of $n$ elements:
\begin{itemize}
\item[(1)] The new element $n$ may form a new cycle by itself, contributing $s(n-1,k-1)$.
\item[(2)] Or it may be inserted into one of the existing $(n-1)$ positions in the cycles, contributing $(n-1)s(n-1,k)$.
\end{itemize}
\subsection*{Closed Form}
A closed expression using inclusion–exclusion is:
\[
\boxed{
s(n,k) = \frac{1}{k!} \sum_{j=0}^{k} (-1)^j \binom{n}{j} (k-j)^n.
}
\]
\subsection*{Example}
For $n=3$:
\[
\begin{aligned}
s(3,1) &= s(2,0) + 2s(2,1) = 0 + 2(1) = 2, \\
s(3,2) &= s(2,1) + 2s(2,2) = 1 + 2(1) = 3, \\
s(3,3) &= s(2,2) + 2s(2,3) = 1 + 0 = 1.
\end{aligned}
\]
\subsection*{Relation to Falling Factorials}
The falling factorial, also called the \textbf{lower factorial}, is defined as:
\[
(x)_k = x(x-1)(x-2)\cdots(x-k+1).
\]
Then, the Stirling numbers of the first kind appear in the expansion:
\[
(x)_n = \sum_{k=0}^{n} s(n,k)\,x^k,
\]
and conversely, the Stirling numbers of the second kind satisfy:
\[
x^n = \sum_{k=0}^{n} S(n,k)\,(x)_k.
\]
Thus, $s(n,k)$ and $S(n,k)$ form \textbf{inverse transformations} between the bases $\{x^k\}$ and $\{(x)_k\}$.
\subsection*{Difference Between Ordinary Powers and Falling Factorials}
\[
\begin{aligned}
x^k &= x \cdot x \cdot x \cdots x \quad (\text{k times}), \\
(x)_k &= x(x-1)(x-2)\cdots(x-k+1).
\end{aligned}
\]
\begin{center}
\begin{tabular}{c|c|c}
$k$ & $x^k$ & $(x)_k$ \\ \hline
0 & $1$ & $1$ \\
1 & $x$ & $x$ \\
2 & $x^2$ & $x^2 - x$ \\
3 & $x^3$ & $x^3 - 3x^2 + 2x$
\end{tabular}
\end{center}
\noindent
Hence, Stirling numbers of both kinds describe the conversion between these two polynomial forms:
\[
\boxed{
\begin{aligned}
x^n &= \sum_{k=0}^{n} S(n,k)\,(x)_k, \\
(x)_n &= \sum_{k=0}^{n} s(n,k)\,x^k.
\end{aligned}
}
\]
\section*{Stirling Numbers of the Second Kind}
\subsection*{Definition}
The \textbf{Stirling number of the second kind} $S(n,k)$ counts the number of ways to partition a set of $n$ distinct elements into $k$ non-empty, unlabeled subsets:
\[
\boxed{
S(n,k) = \text{number of ways to partition } \{1,2,\dots,n\} \text{ into } k \text{ non-empty subsets.}
}
\]
\subsection*{Recurrence Relation}
The Stirling numbers of the second kind satisfy:
\[
\boxed{
S(n,k) = S(n-1,k-1) + k\,S(n-1,k)
}
\]
with base cases:
\[
S(0,0)=1, \quad S(n,0)=0 \ (n>0), \quad S(0,k)=0 \ (k>0).
\]
\paragraph{Interpretation.}
To build a partition of $n$ elements:
\begin{itemize}
\item[(1)] The new element $n$ may form a new subset by itself, contributing $S(n-1,k-1)$.
\item[(2)] Or it may be added to one of the existing $k$ subsets, contributing $kS(n-1,k)$.
\end{itemize}
\subsection*{Closed Forms}
Two equivalent closed forms exist:
\[
\boxed{
S(n,k) = \frac{1}{k!} \sum_{j=0}^{k} (-1)^{k-j} \binom{k}{j} j^n
}
\]
and equivalently,
\[
\boxed{
S(n,k) = \frac{1}{k!} \sum_{j=0}^{k} (-1)^j \binom{k}{j} (k-j)^n.
}
\]
\subsection*{Relation to Bell Numbers}
The total number of partitions of a set of size $n$ (the $n$-th Bell number) is:
\[
B_n = \sum_{k=0}^{n} S(n,k).
\]
\section*{Lucas' Theorem}
\subsection*{General Statement}
Let $p$ be a prime number, and let $n,k \ge 0$ with base-$p$ expansions:
\[
n = n_0 + n_1p + n_2p^2 + \cdots + n_rp^r, \qquad
k = k_0 + k_1p + k_2p^2 + \cdots + k_rp^r,
\]
where $0 \le n_i, k_i < p$.
Then:
\[
\boxed{
\binom{n}{k} \equiv \prod_{i=0}^{r} \binom{n_i}{k_i} \pmod{p}.
}
\]
If any $k_i > n_i$, then $\binom{n_i}{k_i} = 0$, so the entire product is $0$.
\subsection*{Special Case: $p = 2$}
When $p = 2$, the digits $n_i, k_i \in \{0,1\}$ are the binary bits of $n$ and $k$:
\[
\binom{n}{k} \equiv \prod_{i=0}^{r} \binom{n_i}{k_i} \pmod{2}.
\]
Since $\binom{n_i}{k_i} \equiv 1 \pmod{2}$ if and only if $k_i \le n_i$, we have:
\[
\boxed{
\binom{n}{k} \text{ is odd } \iff k_i \le n_i \text{ for all bits } i.
}
\]
Equivalently, in bitwise form:
\[
\boxed{
\binom{n}{k} \text{ is odd } \iff (k \,\&\, \sim n) = 0
\iff (n \,\&\, k) = k.
}
\]
Thus, $\binom{n}{k}$ is odd if and only if $k$ is a \textbf{submask} of $n$ in binary.
\paragraph{Corollaries.}
\begin{itemize}
\item The parity pattern of Pascal's triangle (mod 2) forms the \textbf{Sierpiński triangle}.
\item $\binom{n}{k} \bmod 2 = 1$ exactly when $k$'s bits are contained in $n$'s bits.
\end{itemize}
\subsection*{Bitmask Relations}
Two equivalent bitwise characterizations of ``$k$ is a submask of $n$'':
\[
(k \,\&\, \sim n) = 0 \quad \Longleftrightarrow \quad (n \,\&\, k) = k.
\]
Both mean that every bit set in $k$ is also set in $n$.
\subsection*{Iterating Over Submasks in C++}
\textbf{Code pattern:}
\begin{verbatim}
for (int sub = mask; ; sub = (sub - 1) & mask) {
// use sub (it is a submask of mask)
if (sub == 0) break;
}
\end{verbatim}