<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://tcs.nju.edu.cn/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=172.21.0.0%2F16</id>
	<title>TCS Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://tcs.nju.edu.cn/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=172.21.0.0%2F16"/>
	<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Special:Contributions/172.21.0.0/16"/>
	<updated>2026-09-15T14:25:41Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4368</id>
		<title>Combinatorics (Fall 2010)/Duality, Matroid</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4368"/>
		<updated>2011-01-03T10:12:45Z</updated>

		<summary type="html">&lt;p&gt;172.21.9.33: /* LP duality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Duality ==&lt;br /&gt;
&lt;br /&gt;
Consider the following LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} &amp;amp;&amp;amp; 7x_1+x_2+5x_3\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6\\&lt;br /&gt;
&amp;amp;&amp;amp; x_1,x_2,x_3 &amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; be the value of the optimal solution. We want to estimate the upper and lower bound of &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; is the minimum over the feasible set, every feasible solution forms an upper bound for &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;. For example &amp;lt;math&amp;gt;\boldsymbol{x}=(2,1,3)&amp;lt;/math&amp;gt; is a feasible solution, thus &amp;lt;math&amp;gt;OPT\le 7\cdot 2+1+5\cdot 3=30&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For the lower bound, all feasible solution &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; satisfies the two constraints:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10,\\&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6.\\&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Since the &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; is restricted to be nonnegative, term-by-term comparison of coefficients shows that&lt;br /&gt;
:&amp;lt;math&amp;gt;7x_1+x_2+5x_3\ge(x_1-x_2+3x_3)+(5x_1-2x_2-x_3)\ge 16.&amp;lt;/math&amp;gt;&lt;br /&gt;
The idea behind this lower bound process is that we are finding suitable nonnegative multipliers (in the above case the multipliers are all 1s) for the constraints so that when we take their sum, the coefficient of each &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; in the sum is dominated by the coefficient in the objective function. It is important to ensure that the multipliers are nonnegative, so they do not reverse the direction of the constraint inequality.&lt;br /&gt;
&lt;br /&gt;
To find the best lower bound, we need to choose the multipliers in such a way that the sum is as large as possible. Interestingly, the problem of finding the best lower bound can be formulated as another LP:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} &amp;amp;&amp;amp; 10y_1+6y_2\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
y_1+5y_2 &amp;amp;\le 7\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
-y_1+2y_2 &amp;amp;\le 1\\&lt;br /&gt;
&amp;amp;&amp;amp;3y_1-y_2 &amp;amp;\le 5\\&lt;br /&gt;
&amp;amp;&amp;amp; y_1,y_2&amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;y_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;y_2&amp;lt;/math&amp;gt; were chosen to be nonnegative multipliers for the first and the second constraint, respectively. We call the first LP the &#039;&#039;&#039;primal program&#039;&#039;&#039; and the second LP the &#039;&#039;&#039;dual program&#039;&#039;&#039;. By definition, every feasible solution to the dual program gives a lower bound for the primal program.&lt;br /&gt;
&lt;br /&gt;
=== LP duality ===&lt;br /&gt;
Given an LP in canonical form, called the &#039;&#039;&#039;primal&#039;&#039;&#039; LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} &amp;amp;&amp;amp; \boldsymbol{c}^T\boldsymbol{x}\\&lt;br /&gt;
\text{subject to} &amp;amp;&amp;amp;&lt;br /&gt;
A\boldsymbol{x} &amp;amp;\ge\boldsymbol{b}\\&lt;br /&gt;
&amp;amp;&amp;amp; \boldsymbol{x} &amp;amp;\ge \boldsymbol{0}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the &#039;&#039;&#039;dual&#039;&#039;&#039; LP is defined as follows:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximum} &amp;amp;&amp;amp; \boldsymbol{b}^T\boldsymbol{y}\\&lt;br /&gt;
\text{subject to} &amp;amp;&amp;amp;&lt;br /&gt;
A^T\boldsymbol{y} &amp;amp;\ge\boldsymbol{c}\\&lt;br /&gt;
&amp;amp;&amp;amp; \boldsymbol{y} &amp;amp;\ge \boldsymbol{0}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;Surviving problem (diet problem)&lt;br /&gt;
Let us consider the surviving problem. Suppose we have &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; types of natural food, each containing up to &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; types of vitamins.  The &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;th food has &amp;lt;math&amp;gt;a_{ij}&amp;lt;/math&amp;gt; amount of vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, and the price of the &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;th food is &amp;lt;math&amp;gt;c_j&amp;lt;/math&amp;gt;. We need to consume &amp;lt;math&amp;gt;b_i&amp;lt;/math&amp;gt; amount of vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; for each &amp;lt;math&amp;gt;1\le i\le m&amp;lt;/math&amp;gt; to keep a good health. We want to minimize the total costs of food while keeping healthy. The problem can be formalized as the following LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} \quad&amp;amp; c_1x_1+c_2x_2+\cdots+c_nx_n\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} a_{i1}x_{1}+a_{i2}x_{2}+\cdots+a_{in}x_{n} &amp;amp;\le b_{i} &amp;amp;\quad&amp;amp; \forall 1\le i\le m\\&lt;br /&gt;
 x_{j}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall 1\le j\le n&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The dual LP is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; b_1y_1+b_2y_2+\cdots+b_ny_m\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} a_{1j}y_{1}+a_{2j}y_{2}+\cdots+a_{mj}y_{m} &amp;amp;\le c_{j} &amp;amp;\quad&amp;amp; \forall 1\le j\le n\\&lt;br /&gt;
 y_{i}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall 1\le i\le m&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The problem can be interpreted as follows: A food company produces &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; types of vitamin pills. The company wants to design a pricing system such that&lt;br /&gt;
* The vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; has a nonnegative price &amp;lt;math&amp;gt;y_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The price system should be competitive to any natural food. A costumer cannot replace the vitamins by any natural food and get a cheaper price, that is, &amp;lt;math&amp;gt;\sum_{i=1}^my_ja_{ij}\le c_j&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;1\le j\le n&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The company wants to find the maximal profit, assuming that the customer only buy exactly the necessary amount of vitamins (&amp;lt;math&amp;gt;b_i&amp;lt;/math&amp;gt; for vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
;Maximum flow problem&lt;br /&gt;
In the last lecture, we defined the maximum flow problem, whose LP is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; \sum_{v:(s,v)\in E}f_{sv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E}f_{uv}-\sum_{w:(v,w)\in E}f_{vw} &amp;amp;=0 &amp;amp;\quad&amp;amp; \forall v\in V\setminus\{s,t\}\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where directed graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; is the flow network, &amp;lt;math&amp;gt;s\in V&amp;lt;/math&amp;gt; is the source, &amp;lt;math&amp;gt;t\in V&amp;lt;/math&amp;gt; is the sink, and &amp;lt;math&amp;gt;c_{uv}&amp;lt;/math&amp;gt; is the capacity of directed edge &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We add a new edge from &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt;, and let the capacity be &amp;lt;math&amp;gt;c_{ts}=\infty&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;E&#039;&amp;lt;/math&amp;gt; be the new edge set. The LP for the max-flow problem can be rewritten as:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; f_{ts}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E&#039;}f_{uv}-\sum_{w:(v,w)\in E&#039;}f_{vw} &amp;amp;\le0 &amp;amp;\quad&amp;amp; \forall v\in V\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&#039;&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The second set of inequalities seem weaker than the original conservation constraint of flows, however, if this inequality holds at every node, then in fact it must be satisfied with equality at every node, thereby implying the flow conservation.&lt;br /&gt;
&lt;br /&gt;
To obtain the dual program we introduce variables &amp;lt;math&amp;gt;d_{uv}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;p_v&amp;lt;/math&amp;gt; corresponding to the two types of inequalities in the primal. The dual LP is:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} \quad&amp;amp; \sum_{(u,v)\in E}c_{uv}d_{uv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} d_{uv}-p_u+p_v &amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
p_s-p_t &amp;amp;\ge1 \\&lt;br /&gt;
 d_{uv} &amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
 p_v&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall v\in V&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
It is more helpful to consider its integer version:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} \quad&amp;amp; \sum_{(u,v)\in E}c_{uv}d_{uv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} d_{uv}-p_u+p_v &amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
p_s-p_t &amp;amp;\ge1 \\&lt;br /&gt;
 d_{uv} &amp;amp;\in\{0,1\} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
 p_v&amp;amp;\in\{0,1\} &amp;amp;\quad&amp;amp; \forall v\in V&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
In the last lecture, we know that the LP for max-flow is totally unimordular, so is this dual LP, therefore the optimal solutions to the integer program are the optimal solutions to the LP.&lt;br /&gt;
&lt;br /&gt;
The variables &amp;lt;math&amp;gt;p_v&amp;lt;/math&amp;gt; defines a bipartition of vertex set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;S=\{v\in V\mid p_v=1\}&amp;lt;/math&amp;gt;. The complement &amp;lt;math&amp;gt;\bar{S}=\{v\in V\mid p_v=1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For 0/1-valued variables, the only way to satisfy &amp;lt;math&amp;gt;p_s-p_t\ge1&amp;lt;/math&amp;gt; is to have &amp;lt;math&amp;gt;p_s=1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;p_t=0&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; is an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut.&lt;br /&gt;
&lt;br /&gt;
In an optimal solution, &amp;lt;math&amp;gt;d_{uv}=1&amp;lt;/math&amp;gt; if and only if &amp;lt;math&amp;gt;u\in S,v\in\bar{S}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt;. Therefore, the objective function of an optimal solution &amp;lt;math&amp;gt;\sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt; is the capacity of the minimum &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Duality theorems ===&lt;br /&gt;
&lt;br /&gt;
== Matroid ==&lt;br /&gt;
&lt;br /&gt;
=== Kruskal&#039;s greedy algorithm for MST ===&lt;br /&gt;
&lt;br /&gt;
=== Matroids ===&lt;br /&gt;
Let &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; be a finite set and &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; be a family of subsets of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;.  A member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;maximal&#039;&#039;&#039; if &amp;lt;math&amp;gt;S\cup\{x\}\not\in\mathcal{F}&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;x\in X\setminus S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\mathcal{F}_Y=\{S\in\mathcal{F}\mid S\subseteq Y\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;\mathcal{F}_Y&amp;lt;/math&amp;gt; is the restriction of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; over &amp;lt;math&amp;gt;2^Y\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:A set system &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;matroid&#039;&#039;&#039; if it satisfies:&lt;br /&gt;
:*(hereditary) if &amp;lt;math&amp;gt;T\subseteq S\in\mathcal{F}&amp;lt;/math&amp;gt; then &amp;lt;math&amp;gt;T\in\mathcal{F}&amp;lt;/math&amp;gt;;&lt;br /&gt;
:*(matroid property) for every &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, all maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; have the same &amp;lt;math&amp;gt;|S|&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Suppose &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is a matroid. Some matroid terminologies:&lt;br /&gt;
* Each member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;independent set&#039;&#039;&#039;.&lt;br /&gt;
* A maximal independent subset of a set &amp;lt;math&amp;gt;Y\subset X&amp;lt;/math&amp;gt;, i.e., a maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt;, is called a &#039;&#039;&#039;basis&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The size of the maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;rank&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;r(Y)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Graph matroids ====&lt;br /&gt;
&lt;br /&gt;
==== Linear matroids ====&lt;br /&gt;
&lt;br /&gt;
=== Greedy algorithms on weighted matroids ===&lt;br /&gt;
&lt;br /&gt;
=== Matroid intersections ===&lt;/div&gt;</summary>
		<author><name>172.21.9.33</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4367</id>
		<title>Combinatorics (Fall 2010)/Duality, Matroid</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4367"/>
		<updated>2011-01-03T09:34:42Z</updated>

		<summary type="html">&lt;p&gt;172.21.9.33: /* LP duality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Duality ==&lt;br /&gt;
&lt;br /&gt;
Consider the following LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} &amp;amp;&amp;amp; 7x_1+x_2+5x_3\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6\\&lt;br /&gt;
&amp;amp;&amp;amp; x_1,x_2,x_3 &amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; be the value of the optimal solution. We want to estimate the upper and lower bound of &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; is the minimum over the feasible set, every feasible solution forms an upper bound for &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;. For example &amp;lt;math&amp;gt;\boldsymbol{x}=(2,1,3)&amp;lt;/math&amp;gt; is a feasible solution, thus &amp;lt;math&amp;gt;OPT\le 7\cdot 2+1+5\cdot 3=30&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For the lower bound, all feasible solution &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; satisfies the two constraints:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10,\\&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6.\\&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Since the &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; is restricted to be nonnegative, term-by-term comparison of coefficients shows that&lt;br /&gt;
:&amp;lt;math&amp;gt;7x_1+x_2+5x_3\ge(x_1-x_2+3x_3)+(5x_1-2x_2-x_3)\ge 16.&amp;lt;/math&amp;gt;&lt;br /&gt;
The idea behind this lower bound process is that we are finding suitable nonnegative multipliers (in the above case the multipliers are all 1s) for the constraints so that when we take their sum, the coefficient of each &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; in the sum is dominated by the coefficient in the objective function. It is important to ensure that the multipliers are nonnegative, so they do not reverse the direction of the constraint inequality.&lt;br /&gt;
&lt;br /&gt;
To find the best lower bound, we need to choose the multipliers in such a way that the sum is as large as possible. Interestingly, the problem of finding the best lower bound can be formulated as another LP:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} &amp;amp;&amp;amp; 10y_1+6y_2\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
y_1+5y_2 &amp;amp;\le 7\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
-y_1+2y_2 &amp;amp;\le 1\\&lt;br /&gt;
&amp;amp;&amp;amp;3y_1-y_2 &amp;amp;\le 5\\&lt;br /&gt;
&amp;amp;&amp;amp; y_1,y_2&amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;y_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;y_2&amp;lt;/math&amp;gt; were chosen to be nonnegative multipliers for the first and the second constraint, respectively. We call the first LP the &#039;&#039;&#039;primal program&#039;&#039;&#039; and the second LP the &#039;&#039;&#039;dual program&#039;&#039;&#039;. By definition, every feasible solution to the dual program gives a lower bound for the primal program.&lt;br /&gt;
&lt;br /&gt;
=== LP duality ===&lt;br /&gt;
Given an LP in canonical form, called the &#039;&#039;&#039;primal&#039;&#039;&#039; LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} &amp;amp;&amp;amp; \boldsymbol{c}^T\boldsymbol{x}\\&lt;br /&gt;
\text{subject to} &amp;amp;&amp;amp;&lt;br /&gt;
A\boldsymbol{x} &amp;amp;\ge\boldsymbol{b}\\&lt;br /&gt;
&amp;amp;&amp;amp; \boldsymbol{x} &amp;amp;\ge \boldsymbol{0}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the &#039;&#039;&#039;dual&#039;&#039;&#039; LP is defined as follows:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximum} &amp;amp;&amp;amp; \boldsymbol{b}^T\boldsymbol{y}\\&lt;br /&gt;
\text{subject to} &amp;amp;&amp;amp;&lt;br /&gt;
A^T\boldsymbol{y} &amp;amp;\ge\boldsymbol{c}\\&lt;br /&gt;
&amp;amp;&amp;amp; \boldsymbol{y} &amp;amp;\ge \boldsymbol{0}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;Surviving problem (diet problem)&lt;br /&gt;
Let us consider the surviving problem. Suppose we have &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; types of natural food, each containing up to &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; types of vitamins.  The &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;th food has &amp;lt;math&amp;gt;a_{ij}&amp;lt;/math&amp;gt; amount of vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, and the price of the &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;th food is &amp;lt;math&amp;gt;c_j&amp;lt;/math&amp;gt;. We need to consume &amp;lt;math&amp;gt;b_i&amp;lt;/math&amp;gt; amount of vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; for each &amp;lt;math&amp;gt;1\le i\le m&amp;lt;/math&amp;gt; to keep a good health. We want to minimize the total costs of food while keeping healthy. The problem can be formalized as the following LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} \quad&amp;amp; c_1x_1+c_2x_2+\cdots+c_nx_n\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} a_{i1}x_{1}+a_{i2}x_{2}+\cdots+a_{in}x_{n} &amp;amp;\le b_{i} &amp;amp;\quad&amp;amp; \forall 1\le i\le m\\&lt;br /&gt;
 x_{j}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall 1\le j\le n&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The dual LP is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; b_1y_1+b_2y_2+\cdots+b_ny_m\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} a_{1j}y_{1}+a_{2j}y_{2}+\cdots+a_{mj}y_{m} &amp;amp;\le c_{j} &amp;amp;\quad&amp;amp; \forall 1\le j\le n\\&lt;br /&gt;
 y_{i}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall 1\le i\le m&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The problem can be interpreted as follows: A food company produces &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; types of vitamin pills. The company wants to design a pricing system such that&lt;br /&gt;
* The vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; has a nonnegative price &amp;lt;math&amp;gt;y_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The price system should be competitive to any natural food. A costumer cannot replace the vitamins by any natural food and get a cheaper price, that is, &amp;lt;math&amp;gt;\sum_{i=1}^my_ja_{ij}\le c_j&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;1\le j\le n&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The company wants to find the maximal profit, assuming that the customer only buy exactly the necessary amount of vitamins (&amp;lt;math&amp;gt;b_i&amp;lt;/math&amp;gt; for vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
;Maximum flow problem&lt;br /&gt;
In the last lecture, we defined the maximum flow problem, whose LP is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; \sum_{v:(s,v)\in E}f_{sv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E}f_{uv}-\sum_{w:(v,w)\in E}f_{vw} &amp;amp;=0 &amp;amp;\quad&amp;amp; \forall v\in V\setminus\{s,t\}\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Duality theorems ===&lt;br /&gt;
&lt;br /&gt;
== Matroid ==&lt;br /&gt;
&lt;br /&gt;
=== Kruskal&#039;s greedy algorithm for MST ===&lt;br /&gt;
&lt;br /&gt;
=== Matroids ===&lt;br /&gt;
Let &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; be a finite set and &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; be a family of subsets of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;.  A member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;maximal&#039;&#039;&#039; if &amp;lt;math&amp;gt;S\cup\{x\}\not\in\mathcal{F}&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;x\in X\setminus S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\mathcal{F}_Y=\{S\in\mathcal{F}\mid S\subseteq Y\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;\mathcal{F}_Y&amp;lt;/math&amp;gt; is the restriction of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; over &amp;lt;math&amp;gt;2^Y\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:A set system &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;matroid&#039;&#039;&#039; if it satisfies:&lt;br /&gt;
:*(hereditary) if &amp;lt;math&amp;gt;T\subseteq S\in\mathcal{F}&amp;lt;/math&amp;gt; then &amp;lt;math&amp;gt;T\in\mathcal{F}&amp;lt;/math&amp;gt;;&lt;br /&gt;
:*(matroid property) for every &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, all maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; have the same &amp;lt;math&amp;gt;|S|&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Suppose &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is a matroid. Some matroid terminologies:&lt;br /&gt;
* Each member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;independent set&#039;&#039;&#039;.&lt;br /&gt;
* A maximal independent subset of a set &amp;lt;math&amp;gt;Y\subset X&amp;lt;/math&amp;gt;, i.e., a maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt;, is called a &#039;&#039;&#039;basis&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The size of the maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;rank&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;r(Y)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Graph matroids ====&lt;br /&gt;
&lt;br /&gt;
==== Linear matroids ====&lt;br /&gt;
&lt;br /&gt;
=== Greedy algorithms on weighted matroids ===&lt;br /&gt;
&lt;br /&gt;
=== Matroid intersections ===&lt;/div&gt;</summary>
		<author><name>172.21.9.33</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4366</id>
		<title>Combinatorics (Fall 2010)/Duality, Matroid</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4366"/>
		<updated>2011-01-03T09:33:25Z</updated>

		<summary type="html">&lt;p&gt;172.21.9.33: /* LP duality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Duality ==&lt;br /&gt;
&lt;br /&gt;
Consider the following LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} &amp;amp;&amp;amp; 7x_1+x_2+5x_3\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6\\&lt;br /&gt;
&amp;amp;&amp;amp; x_1,x_2,x_3 &amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; be the value of the optimal solution. We want to estimate the upper and lower bound of &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; is the minimum over the feasible set, every feasible solution forms an upper bound for &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;. For example &amp;lt;math&amp;gt;\boldsymbol{x}=(2,1,3)&amp;lt;/math&amp;gt; is a feasible solution, thus &amp;lt;math&amp;gt;OPT\le 7\cdot 2+1+5\cdot 3=30&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For the lower bound, all feasible solution &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; satisfies the two constraints:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10,\\&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6.\\&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Since the &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; is restricted to be nonnegative, term-by-term comparison of coefficients shows that&lt;br /&gt;
:&amp;lt;math&amp;gt;7x_1+x_2+5x_3\ge(x_1-x_2+3x_3)+(5x_1-2x_2-x_3)\ge 16.&amp;lt;/math&amp;gt;&lt;br /&gt;
The idea behind this lower bound process is that we are finding suitable nonnegative multipliers (in the above case the multipliers are all 1s) for the constraints so that when we take their sum, the coefficient of each &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; in the sum is dominated by the coefficient in the objective function. It is important to ensure that the multipliers are nonnegative, so they do not reverse the direction of the constraint inequality.&lt;br /&gt;
&lt;br /&gt;
To find the best lower bound, we need to choose the multipliers in such a way that the sum is as large as possible. Interestingly, the problem of finding the best lower bound can be formulated as another LP:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} &amp;amp;&amp;amp; 10y_1+6y_2\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
y_1+5y_2 &amp;amp;\le 7\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
-y_1+2y_2 &amp;amp;\le 1\\&lt;br /&gt;
&amp;amp;&amp;amp;3y_1-y_2 &amp;amp;\le 5\\&lt;br /&gt;
&amp;amp;&amp;amp; y_1,y_2&amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;y_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;y_2&amp;lt;/math&amp;gt; were chosen to be nonnegative multipliers for the first and the second constraint, respectively. We call the first LP the &#039;&#039;&#039;primal program&#039;&#039;&#039; and the second LP the &#039;&#039;&#039;dual program&#039;&#039;&#039;. By definition, every feasible solution to the dual program gives a lower bound for the primal program.&lt;br /&gt;
&lt;br /&gt;
=== LP duality ===&lt;br /&gt;
Given an LP in canonical form, called the &#039;&#039;&#039;primal&#039;&#039;&#039; LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} &amp;amp;&amp;amp; \boldsymbol{c}^T\boldsymbol{x}\\&lt;br /&gt;
\text{subject to} &amp;amp;&amp;amp;&lt;br /&gt;
A\boldsymbol{x} &amp;amp;\ge\boldsymbol{b}\\&lt;br /&gt;
&amp;amp;&amp;amp; \boldsymbol{x} &amp;amp;\ge \boldsymbol{0}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the &#039;&#039;&#039;dual&#039;&#039;&#039; LP is defined as follows:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximum} &amp;amp;&amp;amp; \boldsymbol{b}^T\boldsymbol{y}\\&lt;br /&gt;
\text{subject to} &amp;amp;&amp;amp;&lt;br /&gt;
A^T\boldsymbol{y} &amp;amp;\ge\boldsymbol{c}\\&lt;br /&gt;
&amp;amp;&amp;amp; \boldsymbol{y} &amp;amp;\ge \boldsymbol{0}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;Surviving problem (diet problem)&lt;br /&gt;
Let us consider the surviving problem. Suppose we have &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; types of natural food, each containing up to &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; types of vitamins.  The &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;th food has &amp;lt;math&amp;gt;a_{ij}&amp;lt;/math&amp;gt; amount of vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, and the price of the &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;th food is &amp;lt;math&amp;gt;c_j&amp;lt;/math&amp;gt;. We need to consume &amp;lt;math&amp;gt;b_i&amp;lt;/math&amp;gt; amount of vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; for each &amp;lt;math&amp;gt;1\le i\le m&amp;lt;/math&amp;gt; to keep a good health. We want to minimize the total costs of food while keeping healthy. The problem can be formalized as the following LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} \quad&amp;amp; c_1x_1+c_2x_2+\cdots+c_nx_n\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} a_{i1}x_{1}+a_{i2}x_{2}+\cdots+a_{in}x_{n} &amp;amp;\le b_{i} &amp;amp;\quad&amp;amp; \forall 1\le i\le m\\&lt;br /&gt;
 x_{j}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall 1\le j\le n&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The dual LP is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; b_1y_1+b_2y_2+\cdots+b_ny_m\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} a_{1j}y_{1}+a_{2j}y_{2}+\cdots+a_{mj}y_{m} &amp;amp;\le c_{j} &amp;amp;\quad&amp;amp; \forall 1\le j\le n\\&lt;br /&gt;
 y_{i}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall 1\le i\le m&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The problem can be interpreted as follows: A food company produces &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; types of vitamin pills. The company wants to design a pricing system such that&lt;br /&gt;
* The vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; has a nonnegative price &amp;lt;math&amp;gt;y_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The price system should be competitive to any natural food. A costumer cannot replace the vitamins by any natural food and get a cheaper price, that is, &amp;lt;math&amp;gt;\sum_{i=1}^my_ja_{ij}\le c_j&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;1\le j\le n&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The company wants to find the maximal profit, assuming that the customer only buy exactly the necessary amount of vitamins (&amp;lt;math&amp;gt;b_i&amp;lt;/math&amp;gt; for vitamin &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
;Maximum flow problem&lt;br /&gt;
&lt;br /&gt;
=== Duality theorems ===&lt;br /&gt;
&lt;br /&gt;
== Matroid ==&lt;br /&gt;
&lt;br /&gt;
=== Kruskal&#039;s greedy algorithm for MST ===&lt;br /&gt;
&lt;br /&gt;
=== Matroids ===&lt;br /&gt;
Let &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; be a finite set and &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; be a family of subsets of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;.  A member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;maximal&#039;&#039;&#039; if &amp;lt;math&amp;gt;S\cup\{x\}\not\in\mathcal{F}&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;x\in X\setminus S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\mathcal{F}_Y=\{S\in\mathcal{F}\mid S\subseteq Y\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;\mathcal{F}_Y&amp;lt;/math&amp;gt; is the restriction of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; over &amp;lt;math&amp;gt;2^Y\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:A set system &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;matroid&#039;&#039;&#039; if it satisfies:&lt;br /&gt;
:*(hereditary) if &amp;lt;math&amp;gt;T\subseteq S\in\mathcal{F}&amp;lt;/math&amp;gt; then &amp;lt;math&amp;gt;T\in\mathcal{F}&amp;lt;/math&amp;gt;;&lt;br /&gt;
:*(matroid property) for every &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, all maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; have the same &amp;lt;math&amp;gt;|S|&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Suppose &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is a matroid. Some matroid terminologies:&lt;br /&gt;
* Each member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;independent set&#039;&#039;&#039;.&lt;br /&gt;
* A maximal independent subset of a set &amp;lt;math&amp;gt;Y\subset X&amp;lt;/math&amp;gt;, i.e., a maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt;, is called a &#039;&#039;&#039;basis&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The size of the maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;rank&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;r(Y)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Graph matroids ====&lt;br /&gt;
&lt;br /&gt;
==== Linear matroids ====&lt;br /&gt;
&lt;br /&gt;
=== Greedy algorithms on weighted matroids ===&lt;br /&gt;
&lt;br /&gt;
=== Matroid intersections ===&lt;/div&gt;</summary>
		<author><name>172.21.9.33</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4365</id>
		<title>Combinatorics (Fall 2010)/Duality, Matroid</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4365"/>
		<updated>2011-01-03T08:51:23Z</updated>

		<summary type="html">&lt;p&gt;172.21.9.33: /* LP duality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Duality ==&lt;br /&gt;
&lt;br /&gt;
Consider the following LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} &amp;amp;&amp;amp; 7x_1+x_2+5x_3\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6\\&lt;br /&gt;
&amp;amp;&amp;amp; x_1,x_2,x_3 &amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; be the value of the optimal solution. We want to estimate the upper and lower bound of &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; is the minimum over the feasible set, every feasible solution forms an upper bound for &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;. For example &amp;lt;math&amp;gt;\boldsymbol{x}=(2,1,3)&amp;lt;/math&amp;gt; is a feasible solution, thus &amp;lt;math&amp;gt;OPT\le 7\cdot 2+1+5\cdot 3=30&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For the lower bound, all feasible solution &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; satisfies the two constraints:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10,\\&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6.\\&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Since the &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; is restricted to be nonnegative, term-by-term comparison of coefficients shows that&lt;br /&gt;
:&amp;lt;math&amp;gt;7x_1+x_2+5x_3\ge(x_1-x_2+3x_3)+(5x_1-2x_2-x_3)\ge 16.&amp;lt;/math&amp;gt;&lt;br /&gt;
The idea behind this lower bound process is that we are finding suitable nonnegative multipliers (in the above case the multipliers are all 1s) for the constraints so that when we take their sum, the coefficient of each &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; in the sum is dominated by the coefficient in the objective function. It is important to ensure that the multipliers are nonnegative, so they do not reverse the direction of the constraint inequality.&lt;br /&gt;
&lt;br /&gt;
To find the best lower bound, we need to choose the multipliers in such a way that the sum is as large as possible. Interestingly, the problem of finding the best lower bound can be formulated as another LP:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} &amp;amp;&amp;amp; 10y_1+6y_2\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
y_1+5y_2 &amp;amp;\le 7\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
-y_1+2y_2 &amp;amp;\le 1\\&lt;br /&gt;
&amp;amp;&amp;amp;3y_1-y_2 &amp;amp;\le 5\\&lt;br /&gt;
&amp;amp;&amp;amp; y_1,y_2&amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;y_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;y_2&amp;lt;/math&amp;gt; were chosen to be nonnegative multipliers for the first and the second constraint, respectively. We call the first LP the &#039;&#039;&#039;primal program&#039;&#039;&#039; and the second LP the &#039;&#039;&#039;dual program&#039;&#039;&#039;. By definition, every feasible solution to the dual program gives a lower bound for the primal program.&lt;br /&gt;
&lt;br /&gt;
=== LP duality ===&lt;br /&gt;
Given an LP in canonical form, called the &#039;&#039;&#039;primal&#039;&#039;&#039; LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} &amp;amp;&amp;amp; \boldsymbol{c}^T\boldsymbol{x}\\&lt;br /&gt;
\text{subject to} &amp;amp;&amp;amp;&lt;br /&gt;
A\boldsymbol{x} &amp;amp;\ge\boldsymbol{b}\\&lt;br /&gt;
&amp;amp;&amp;amp; \boldsymbol{x} &amp;amp;\ge \boldsymbol{0}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the &#039;&#039;&#039;dual&#039;&#039;&#039; LP is defined as follows:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximum} &amp;amp;&amp;amp; \boldsymbol{b}^T\boldsymbol{y}\\&lt;br /&gt;
\text{subject to} &amp;amp;&amp;amp;&lt;br /&gt;
A^T\boldsymbol{y} &amp;amp;\ge\boldsymbol{c}\\&lt;br /&gt;
&amp;amp;&amp;amp; \boldsymbol{y} &amp;amp;\ge \boldsymbol{0}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Duality theorems ===&lt;br /&gt;
&lt;br /&gt;
== Matroid ==&lt;br /&gt;
&lt;br /&gt;
=== Kruskal&#039;s greedy algorithm for MST ===&lt;br /&gt;
&lt;br /&gt;
=== Matroids ===&lt;br /&gt;
Let &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; be a finite set and &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; be a family of subsets of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;.  A member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;maximal&#039;&#039;&#039; if &amp;lt;math&amp;gt;S\cup\{x\}\not\in\mathcal{F}&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;x\in X\setminus S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\mathcal{F}_Y=\{S\in\mathcal{F}\mid S\subseteq Y\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;\mathcal{F}_Y&amp;lt;/math&amp;gt; is the restriction of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; over &amp;lt;math&amp;gt;2^Y\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:A set system &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;matroid&#039;&#039;&#039; if it satisfies:&lt;br /&gt;
:*(hereditary) if &amp;lt;math&amp;gt;T\subseteq S\in\mathcal{F}&amp;lt;/math&amp;gt; then &amp;lt;math&amp;gt;T\in\mathcal{F}&amp;lt;/math&amp;gt;;&lt;br /&gt;
:*(matroid property) for every &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, all maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; have the same &amp;lt;math&amp;gt;|S|&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Suppose &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is a matroid. Some matroid terminologies:&lt;br /&gt;
* Each member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;independent set&#039;&#039;&#039;.&lt;br /&gt;
* A maximal independent subset of a set &amp;lt;math&amp;gt;Y\subset X&amp;lt;/math&amp;gt;, i.e., a maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt;, is called a &#039;&#039;&#039;basis&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The size of the maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;rank&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;r(Y)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Graph matroids ====&lt;br /&gt;
&lt;br /&gt;
==== Linear matroids ====&lt;br /&gt;
&lt;br /&gt;
=== Greedy algorithms on weighted matroids ===&lt;br /&gt;
&lt;br /&gt;
=== Matroid intersections ===&lt;/div&gt;</summary>
		<author><name>172.21.9.33</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4364</id>
		<title>Combinatorics (Fall 2010)/Duality, Matroid</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4364"/>
		<updated>2011-01-03T08:30:56Z</updated>

		<summary type="html">&lt;p&gt;172.21.9.33: /* Duality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Duality ==&lt;br /&gt;
&lt;br /&gt;
Consider the following LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} &amp;amp;&amp;amp; 7x_1+x_2+5x_3\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6\\&lt;br /&gt;
&amp;amp;&amp;amp; x_1,x_2,x_3 &amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; be the value of the optimal solution. We want to estimate the upper and lower bound of &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; is the minimum over the feasible set, every feasible solution forms an upper bound for &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;. For example &amp;lt;math&amp;gt;\boldsymbol{x}=(2,1,3)&amp;lt;/math&amp;gt; is a feasible solution, thus &amp;lt;math&amp;gt;OPT\le 7\cdot 2+1+5\cdot 3=30&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For the lower bound, all feasible solution &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; satisfies the two constraints:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10,\\&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6.\\&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Since the &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; is restricted to be nonnegative, term-by-term comparison of coefficients shows that&lt;br /&gt;
:&amp;lt;math&amp;gt;7x_1+x_2+5x_3\ge(x_1-x_2+3x_3)+(5x_1-2x_2-x_3)\ge 16.&amp;lt;/math&amp;gt;&lt;br /&gt;
The idea behind this lower bound process is that we are finding suitable nonnegative multipliers (in the above case the multipliers are all 1s) for the constraints so that when we take their sum, the coefficient of each &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; in the sum is dominated by the coefficient in the objective function. It is important to ensure that the multipliers are nonnegative, so they do not reverse the direction of the constraint inequality.&lt;br /&gt;
&lt;br /&gt;
To find the best lower bound, we need to choose the multipliers in such a way that the sum is as large as possible. Interestingly, the problem of finding the best lower bound can be formulated as another LP:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} &amp;amp;&amp;amp; 10y_1+6y_2\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
y_1+5y_2 &amp;amp;\le 7\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
-y_1+2y_2 &amp;amp;\le 1\\&lt;br /&gt;
&amp;amp;&amp;amp;3y_1-y_2 &amp;amp;\le 5\\&lt;br /&gt;
&amp;amp;&amp;amp; y_1,y_2&amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;y_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;y_2&amp;lt;/math&amp;gt; were chosen to be nonnegative multipliers for the first and the second constraint, respectively. We call the first LP the &#039;&#039;&#039;primal program&#039;&#039;&#039; and the second LP the &#039;&#039;&#039;dual program&#039;&#039;&#039;. By definition, every feasible solution to the dual program gives a lower bound for the primal program.&lt;br /&gt;
&lt;br /&gt;
=== LP duality ===&lt;br /&gt;
&lt;br /&gt;
=== Duality theorems ===&lt;br /&gt;
&lt;br /&gt;
== Matroid ==&lt;br /&gt;
&lt;br /&gt;
=== Kruskal&#039;s greedy algorithm for MST ===&lt;br /&gt;
&lt;br /&gt;
=== Matroids ===&lt;br /&gt;
Let &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; be a finite set and &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; be a family of subsets of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;.  A member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;maximal&#039;&#039;&#039; if &amp;lt;math&amp;gt;S\cup\{x\}\not\in\mathcal{F}&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;x\in X\setminus S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\mathcal{F}_Y=\{S\in\mathcal{F}\mid S\subseteq Y\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;\mathcal{F}_Y&amp;lt;/math&amp;gt; is the restriction of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; over &amp;lt;math&amp;gt;2^Y\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:A set system &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;matroid&#039;&#039;&#039; if it satisfies:&lt;br /&gt;
:*(hereditary) if &amp;lt;math&amp;gt;T\subseteq S\in\mathcal{F}&amp;lt;/math&amp;gt; then &amp;lt;math&amp;gt;T\in\mathcal{F}&amp;lt;/math&amp;gt;;&lt;br /&gt;
:*(matroid property) for every &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, all maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; have the same &amp;lt;math&amp;gt;|S|&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Suppose &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is a matroid. Some matroid terminologies:&lt;br /&gt;
* Each member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;independent set&#039;&#039;&#039;.&lt;br /&gt;
* A maximal independent subset of a set &amp;lt;math&amp;gt;Y\subset X&amp;lt;/math&amp;gt;, i.e., a maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt;, is called a &#039;&#039;&#039;basis&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The size of the maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;rank&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;r(Y)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Graph matroids ====&lt;br /&gt;
&lt;br /&gt;
==== Linear matroids ====&lt;br /&gt;
&lt;br /&gt;
=== Greedy algorithms on weighted matroids ===&lt;br /&gt;
&lt;br /&gt;
=== Matroid intersections ===&lt;/div&gt;</summary>
		<author><name>172.21.9.33</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4363</id>
		<title>Combinatorics (Fall 2010)/Duality, Matroid</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4363"/>
		<updated>2011-01-03T08:25:56Z</updated>

		<summary type="html">&lt;p&gt;172.21.9.33: /* Duality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Duality ==&lt;br /&gt;
&lt;br /&gt;
Consider the following LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{minimize} &amp;amp;&amp;amp; 7x_1+x_2+5x_3\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6\\&lt;br /&gt;
&amp;amp;&amp;amp; x_1,x_2,x_3 &amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; be the value of the optimal solution. We want to estimate the upper and lower bound of &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; is the minimum over the feasible set, every feasible solution forms an upper bound for &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt;. For example &amp;lt;math&amp;gt;\boldsymbol{x}=(2,1,3)&amp;lt;/math&amp;gt; is a feasible solution, thus &amp;lt;math&amp;gt;OPT\le 7\cdot 2+1+5\cdot 3=30&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For the lower bound, all feasible solution &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; satisfies the two constraints:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10,\\&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6.\\&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Since the &amp;lt;math&amp;gt;\boldsymbol{x}&amp;lt;/math&amp;gt; is restricted to be nonnegative, term-by-term comparison of coefficients shows that&lt;br /&gt;
:&amp;lt;math&amp;gt;7x_1+x_2+5x_3\ge(x_1-x_2+3x_3)+(5x_1-2x_2-x_3)\ge 16.&amp;lt;/math&amp;gt;&lt;br /&gt;
The idea behind this lower bound process is that we are finding suitable nonnegative multipliers (in the above case the multipliers are all 1s) for the constraints so that when we take their sum, the coefficient of each &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; in the sum is dominated by the coefficient in the objective function. It is important to ensure that the multipliers are nonnegative, so they do not reverse the direction of the constraint inequality.&lt;br /&gt;
&lt;br /&gt;
To choose the best lower bound, we need to choose the multipliers in such a way that the sum is as large as possible. Interestingly, the problem of finding the best lower bound can be formulated as another LP:&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} &amp;amp;&amp;amp; 10y_1+6y_2\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
y_1+5y_2 &amp;amp;\le 7\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
-y_1+2y_2 &amp;amp;\le 1\\&lt;br /&gt;
&amp;amp;&amp;amp;3y_1-y_2 &amp;amp;\le 5\\&lt;br /&gt;
&amp;amp;&amp;amp; y_1,y_2&amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;y_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;y_2&amp;lt;/math&amp;gt; were chosen to be nonnegative multipliers for the first and the second constraint, respectively. We call the first LP the &#039;&#039;&#039;primal program&#039;&#039;&#039; and the second LP the &#039;&#039;&#039;dual program&#039;&#039;&#039;. By definition, every feasible solution to the dual program gives a lower bound for the primal program.&lt;br /&gt;
&lt;br /&gt;
=== LP duality ===&lt;br /&gt;
&lt;br /&gt;
=== Duality theorems ===&lt;br /&gt;
&lt;br /&gt;
== Matroid ==&lt;br /&gt;
&lt;br /&gt;
=== Kruskal&#039;s greedy algorithm for MST ===&lt;br /&gt;
&lt;br /&gt;
=== Matroids ===&lt;br /&gt;
Let &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; be a finite set and &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; be a family of subsets of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;.  A member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;maximal&#039;&#039;&#039; if &amp;lt;math&amp;gt;S\cup\{x\}\not\in\mathcal{F}&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;x\in X\setminus S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\mathcal{F}_Y=\{S\in\mathcal{F}\mid S\subseteq Y\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;\mathcal{F}_Y&amp;lt;/math&amp;gt; is the restriction of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; over &amp;lt;math&amp;gt;2^Y\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:A set system &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;matroid&#039;&#039;&#039; if it satisfies:&lt;br /&gt;
:*(hereditary) if &amp;lt;math&amp;gt;T\subseteq S\in\mathcal{F}&amp;lt;/math&amp;gt; then &amp;lt;math&amp;gt;T\in\mathcal{F}&amp;lt;/math&amp;gt;;&lt;br /&gt;
:*(matroid property) for every &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, all maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; have the same &amp;lt;math&amp;gt;|S|&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Suppose &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is a matroid. Some matroid terminologies:&lt;br /&gt;
* Each member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;independent set&#039;&#039;&#039;.&lt;br /&gt;
* A maximal independent subset of a set &amp;lt;math&amp;gt;Y\subset X&amp;lt;/math&amp;gt;, i.e., a maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt;, is called a &#039;&#039;&#039;basis&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The size of the maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;rank&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;r(Y)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Graph matroids ====&lt;br /&gt;
&lt;br /&gt;
==== Linear matroids ====&lt;br /&gt;
&lt;br /&gt;
=== Greedy algorithms on weighted matroids ===&lt;br /&gt;
&lt;br /&gt;
=== Matroid intersections ===&lt;/div&gt;</summary>
		<author><name>172.21.9.33</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4362</id>
		<title>Combinatorics (Fall 2010)/Duality, Matroid</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4362"/>
		<updated>2011-01-03T07:48:01Z</updated>

		<summary type="html">&lt;p&gt;172.21.9.33: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Duality ==&lt;br /&gt;
&lt;br /&gt;
Consider the following LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} &amp;amp;&amp;amp; 7x_1+x_2+5x_3\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6\\&lt;br /&gt;
&amp;amp;&amp;amp; x_1,x_2,x_3 &amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; be the value of the optimal solution.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== LP duality ===&lt;br /&gt;
&lt;br /&gt;
=== Duality theorems ===&lt;br /&gt;
&lt;br /&gt;
== Matroid ==&lt;br /&gt;
&lt;br /&gt;
=== Kruskal&#039;s greedy algorithm for MST ===&lt;br /&gt;
&lt;br /&gt;
=== Matroids ===&lt;br /&gt;
Let &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; be a finite set and &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; be a family of subsets of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;.  A member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;maximal&#039;&#039;&#039; if &amp;lt;math&amp;gt;S\cup\{x\}\not\in\mathcal{F}&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;x\in X\setminus S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\mathcal{F}_Y=\{S\in\mathcal{F}\mid S\subseteq Y\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;\mathcal{F}_Y&amp;lt;/math&amp;gt; is the restriction of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; over &amp;lt;math&amp;gt;2^Y\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:A set system &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;matroid&#039;&#039;&#039; if it satisfies:&lt;br /&gt;
:*(hereditary) if &amp;lt;math&amp;gt;T\subseteq S\in\mathcal{F}&amp;lt;/math&amp;gt; then &amp;lt;math&amp;gt;T\in\mathcal{F}&amp;lt;/math&amp;gt;;&lt;br /&gt;
:*(matroid property) for every &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, all maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; have the same &amp;lt;math&amp;gt;|S|&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Suppose &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is a matroid. Some matroid terminologies:&lt;br /&gt;
* Each member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;independent set&#039;&#039;&#039;.&lt;br /&gt;
* A maximal independent subset of a set &amp;lt;math&amp;gt;Y\subset X&amp;lt;/math&amp;gt;, i.e., a maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt;, is called a &#039;&#039;&#039;basis&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The size of the maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;rank&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;r(Y)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Graph matroids ====&lt;br /&gt;
&lt;br /&gt;
==== Linear matroids ====&lt;br /&gt;
&lt;br /&gt;
=== Greedy algorithms on weighted matroids ===&lt;br /&gt;
&lt;br /&gt;
=== Matroid intersections ===&lt;/div&gt;</summary>
		<author><name>172.21.9.33</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4361</id>
		<title>Combinatorics (Fall 2010)/Duality, Matroid</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Duality,_Matroid&amp;diff=4361"/>
		<updated>2011-01-03T07:47:47Z</updated>

		<summary type="html">&lt;p&gt;172.21.9.33: /* Duality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Consider the following LP:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} &amp;amp;&amp;amp; 7x_1+x_2+5x_3\\&lt;br /&gt;
\text{subject to}  &amp;amp;&amp;amp;&lt;br /&gt;
x_1-x_2+3x_3 &amp;amp;\ge 10\\&lt;br /&gt;
 &amp;amp;&amp;amp;&lt;br /&gt;
5x_1-2x_2-x_3 &amp;amp;\ge 6\\&lt;br /&gt;
&amp;amp;&amp;amp; x_1,x_2,x_3 &amp;amp;\ge 0&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;OPT&amp;lt;/math&amp;gt; be the value of the optimal solution.&lt;br /&gt;
&lt;br /&gt;
== Duality ==&lt;br /&gt;
&lt;br /&gt;
=== LP duality ===&lt;br /&gt;
&lt;br /&gt;
=== Duality theorems ===&lt;br /&gt;
&lt;br /&gt;
== Matroid ==&lt;br /&gt;
&lt;br /&gt;
=== Kruskal&#039;s greedy algorithm for MST ===&lt;br /&gt;
&lt;br /&gt;
=== Matroids ===&lt;br /&gt;
Let &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; be a finite set and &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; be a family of subsets of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;.  A member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;maximal&#039;&#039;&#039; if &amp;lt;math&amp;gt;S\cup\{x\}\not\in\mathcal{F}&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;x\in X\setminus S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\mathcal{F}_Y=\{S\in\mathcal{F}\mid S\subseteq Y\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;\mathcal{F}_Y&amp;lt;/math&amp;gt; is the restriction of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; over &amp;lt;math&amp;gt;2^Y\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:A set system &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;matroid&#039;&#039;&#039; if it satisfies:&lt;br /&gt;
:*(hereditary) if &amp;lt;math&amp;gt;T\subseteq S\in\mathcal{F}&amp;lt;/math&amp;gt; then &amp;lt;math&amp;gt;T\in\mathcal{F}&amp;lt;/math&amp;gt;;&lt;br /&gt;
:*(matroid property) for every &amp;lt;math&amp;gt;Y\subseteq X&amp;lt;/math&amp;gt;, all maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; have the same &amp;lt;math&amp;gt;|S|&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Suppose &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is a matroid. Some matroid terminologies:&lt;br /&gt;
* Each member set &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;independent set&#039;&#039;&#039;.&lt;br /&gt;
* A maximal independent subset of a set &amp;lt;math&amp;gt;Y\subset X&amp;lt;/math&amp;gt;, i.e., a maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt;, is called a &#039;&#039;&#039;basis&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The size of the maximal &amp;lt;math&amp;gt;S\in\mathcal{F}_Y&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;rank&#039;&#039;&#039; of &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;r(Y)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Graph matroids ====&lt;br /&gt;
&lt;br /&gt;
==== Linear matroids ====&lt;br /&gt;
&lt;br /&gt;
=== Greedy algorithms on weighted matroids ===&lt;br /&gt;
&lt;br /&gt;
=== Matroid intersections ===&lt;/div&gt;</summary>
		<author><name>172.21.9.33</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4312</id>
		<title>Combinatorics (Fall 2010)/Flow and matching</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4312"/>
		<updated>2010-12-26T07:28:29Z</updated>

		<summary type="html">&lt;p&gt;172.21.5.190: /* Integrality of polytopes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Flow and Cut==&lt;br /&gt;
&lt;br /&gt;
=== Flows ===&lt;br /&gt;
An instance of the maximum flow problem consists of:&lt;br /&gt;
* a directed graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;;&lt;br /&gt;
* two distinguished vertices &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;source&#039;&#039;&#039;) and &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;sink&#039;&#039;&#039;), where the in-degree of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and the out-degree of &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; are both 0;&lt;br /&gt;
* the &#039;&#039;&#039;capacity function&#039;&#039;&#039;  &amp;lt;math&amp;gt;c:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; which associates each directed edge &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; a nonnegative real number &amp;lt;math&amp;gt;c_{uv}&amp;lt;/math&amp;gt; called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the edge.&lt;br /&gt;
&lt;br /&gt;
The quadruple &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow network&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A function &amp;lt;math&amp;gt;f:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow&#039;&#039;&#039; (to be specific an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow&#039;&#039;&#039;) in the network &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; if it satisfies:&lt;br /&gt;
* &#039;&#039;&#039;Capacity constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;f_{uv}\le c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Conservation constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;\sum_{u:(u,v)\in E}f_{uv}=\sum_{w:(v,w)\in E}f_{vw}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V\setminus\{s,t\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;value&#039;&#039;&#039; of the flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given a flow network, the maximum flow problem asks to find the flow of the maximum value.&lt;br /&gt;
&lt;br /&gt;
The maximum flow problem can be described as the following linear program.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; \sum_{v:(s,v)\in E}f_{sv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E}f_{uv}-\sum_{w:(v,w)\in E}f_{vw} &amp;amp;=0 &amp;amp;\quad&amp;amp; \forall v\in V\setminus\{s,t\}\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cuts ===&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;S\subset V&amp;lt;/math&amp;gt;. We call &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:The &#039;&#039;&#039;value&#039;&#039;&#039; of  the cut (also called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the cut) is defined as &amp;lt;math&amp;gt;\sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A fundamental fact in flow theory is that cuts always upper bound flows.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an arbitrary flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; be an arbitrary &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. Then&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}\le \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:that is, the value of any flow is no greater than the value of any cut.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|By the definition of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the conservation of flow, &lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{u\in S}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}+\sum_{u\in S\setminus\{s\}}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
On the other hand, summing flow over edges,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in S}\left(\sum_{u:(u,v)\in E}f_{uv}-\sum_{u:(v,u)\in E}f_{vu}\right)=\sum_{u\in S,v\in S\atop (u,v)\in E}\left(f_{uv}-f_{uv}\right)+\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\le\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}\le  \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}\,,&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Augmenting paths ===&lt;br /&gt;
{{Theorem|Definition (Augmenting path)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. An &#039;&#039;&#039;augmenting path to &amp;lt;math&amp;gt;u_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; is a sequence of distinct vertices &amp;lt;math&amp;gt;P=(u_0,u_1,\cdots, u_k)&amp;lt;/math&amp;gt;, such that &lt;br /&gt;
:* &amp;lt;math&amp;gt;u_0=s\,&amp;lt;/math&amp;gt;;&lt;br /&gt;
:and each pair of consecutive vertices &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; corresponds to either a &#039;&#039;&#039;forward edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; or a &#039;&#039;&#039;reverse edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;c(u_i,u_{i+1})\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a forward edge &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;gt;0\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a reverse edge &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
:If &amp;lt;math&amp;gt;u_k=t\,&amp;lt;/math&amp;gt;, we simply call &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; an &#039;&#039;&#039;augmenting path&#039;&#039;&#039;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Suppose there is an augmenting path &amp;lt;math&amp;gt;P=u_0u_1\cdots u_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;u_0=s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;u_k=t&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt; be a positive constant satisfying &lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le c(u_{i},u_{i+1})-f(u_i,u_{i+1})&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;;&lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le f(u_{i+1},u_i)&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the definition of augmenting path, we can always find such a positive &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Increase &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and decrease &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;. Denote the modified flow by &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;. It can be verified that &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; satisfies the capacity constraint and conservation constraint thus is still a valid flow. On the other hand, the value of the new flow &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&#039;=\epsilon+\sum_{v:(s,v)\in E}f_{sv}&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Therefore, the value of the flow can be &amp;quot;augmented&amp;quot; by adjusting the flow on the augmenting path. This immediately implies that if a flow is maximum, then there is no augmenting path. Surprisingly, the converse is also true, thus maximum flows are &amp;quot;characterized&amp;quot; by augmenting paths.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:A flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum if and only if there are no augmenting paths.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|We have already proved the &amp;quot;only if&amp;quot; direction above. Now we prove the &amp;quot;if&amp;quot; direction.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt;, and since there is no augmenting path &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defines an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. &lt;br /&gt;
&lt;br /&gt;
We claim that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
that is, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; approach the value of the cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defined above. By the above lemma, this will imply that the current flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum.&lt;br /&gt;
&lt;br /&gt;
To prove this claim, we first observe that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}&amp;lt;/math&amp;gt;.&lt;br /&gt;
This identity is implied by the flow conservation constraint, and holds for any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We then claim that &lt;br /&gt;
*&amp;lt;math&amp;gt;f_{uv}=c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u\in S,v\not\in S, (u,v)\in E&amp;lt;/math&amp;gt;; and &lt;br /&gt;
*&amp;lt;math&amp;gt;f_{vu}=0&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u\in S,v\not\in S, (v,u)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
If otherwise, then the augmenting path to &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; apending &amp;lt;math&amp;gt;uv&amp;lt;/math&amp;gt; becomes a new augmenting path to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, which contradicts that &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; includes all vertices to which there exist augmenting paths.&lt;br /&gt;
&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu} = \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
As discussed above, this proves the theorem.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The max-flow min-cut theorem ===&lt;br /&gt;
{{Theorem|Max-Flow Min-Cut Theorem|&lt;br /&gt;
:In a flow network, the maximum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow equals the minimum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow with maximum value, so there is no augmenting path.&lt;br /&gt;
&lt;br /&gt;
Again, let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. As proved above, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; forms an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, and&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
that is, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; equals the value of cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Since we know that all &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flows are not greater than any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; equals the minimum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Flow Integrality Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; be a flow network with integral capacity &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;. There exists an integral flow which is maximum.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an integral flow of maximum value. If there is an augmenting path, since both &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; are integral, a new flow can be constructed of value 1+the value of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, contradicting that &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum over all integral flows. Therefore, there is no augmenting path, which means that &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum over all flows, integral or not.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Unimodularity ==&lt;br /&gt;
&lt;br /&gt;
=== Integer Programming===&lt;br /&gt;
&lt;br /&gt;
=== Integrality of polytopes ===&lt;br /&gt;
A point in an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional space is integral if all its coordinates are integers. &lt;br /&gt;
&lt;br /&gt;
A polyhedron is said to be &#039;&#039;&#039;integral&#039;&#039;&#039; if all its vertices are integral.&lt;br /&gt;
&lt;br /&gt;
There always exists an optimal solution which is a vertex in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;. For integral &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;, all vertices are integral.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Hoffman 1974)|&lt;br /&gt;
: If a polyhedron &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is integral then for all integer vectors &amp;lt;math&amp;gt;\boldsymbol{c}&amp;lt;/math&amp;gt; there is an optimal solution to &amp;lt;math&amp;gt;\max\{\boldsymbol{c}^T\boldsymbol{x}\mid \boldsymbol{x}\in P\}&amp;lt;/math&amp;gt; which is integral.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Unimodularity and total unimodularity ===&lt;br /&gt;
{{Theorem|Definition (Unimodularity)|&lt;br /&gt;
:An &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; integer matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;unimodular&#039;&#039;&#039; if &amp;lt;math&amp;gt;\det(A)=\pm1&amp;lt;/math&amp;gt;.&lt;br /&gt;
:An &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;total unimodular&#039;&#039;&#039; if every square submatrix &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;\det(B)\in\{1,-1,0\}&amp;lt;/math&amp;gt;, that is, every square, nonsingular submatrix of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is unimodular.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix. &lt;br /&gt;
:If &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodualr, then for any integer vector &amp;lt;math&amp;gt;\boldsymbol{b}\in\mathbb{Z}^n&amp;lt;/math&amp;gt; the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; be a basis of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; be the corresponding coordinates in &amp;lt;math&amp;gt;\boldsymbol{b}&amp;lt;/math&amp;gt;. A basic solution is formed by &amp;lt;math&amp;gt;B^{-1}\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; and zeros. Since &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodular and &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; is a basis thus nonsingular, &amp;lt;math&amp;gt;\det(B)\in\{1,-1,0\}&amp;lt;/math&amp;gt;. By [http://en.wikipedia.org/wiki/Cramer&#039;s_rule Cramer&#039;s rule], &amp;lt;math&amp;gt;B^{-1}&amp;lt;/math&amp;gt; has integer entries, thus &amp;lt;math&amp;gt;B^{-1}\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; is integral. Therefore, any basic solution of &amp;lt;math&amp;gt;A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}&amp;lt;/math&amp;gt; is integral, which means the polyhedron  &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}} &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Hoffman-Kruskal 1956)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix. &lt;br /&gt;
:If &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodualr, then for any integer vector &amp;lt;math&amp;gt;\boldsymbol{b}\in\mathbb{Z}^n&amp;lt;/math&amp;gt; the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}\ge\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;A&#039;=\begin{bmatrix}A &amp;amp; -I\end{bmatrix}&amp;lt;/math&amp;gt;. We claim that &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; is also totally unimodular. Any square submatrix &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; can be written in the following form after permutation:&lt;br /&gt;
:&amp;lt;math&amp;gt;B=\begin{bmatrix}&lt;br /&gt;
C &amp;amp; 0\\&lt;br /&gt;
D &amp;amp; I&lt;br /&gt;
\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is a square submatrix of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;I&amp;lt;/math&amp;gt; is identity matrix. Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\det(B)=\det(C)\in\{1,-1,0\}&amp;lt;/math&amp;gt;,&lt;br /&gt;
thus &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; is totally unimodular.&lt;br /&gt;
&lt;br /&gt;
Add slack variables to transform the constraints to the standard form &amp;lt;math&amp;gt;A&#039;\boldsymbol{z}=\boldsymbol{b},\boldsymbol{z}\ge\boldsymbol{0}&amp;lt;/math&amp;gt;. The polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\mid A\boldsymbol{x}\ge\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral if the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{z}\mid A&#039;\boldsymbol{z}=\boldsymbol{b}, \boldsymbol{z}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral, which is implied by the total unimodularity of &amp;lt;math&amp;gt;A&#039;\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.5.190</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4311</id>
		<title>Combinatorics (Fall 2010)/Flow and matching</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4311"/>
		<updated>2010-12-26T07:10:55Z</updated>

		<summary type="html">&lt;p&gt;172.21.5.190: /* Cuts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Flow and Cut==&lt;br /&gt;
&lt;br /&gt;
=== Flows ===&lt;br /&gt;
An instance of the maximum flow problem consists of:&lt;br /&gt;
* a directed graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;;&lt;br /&gt;
* two distinguished vertices &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;source&#039;&#039;&#039;) and &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;sink&#039;&#039;&#039;), where the in-degree of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and the out-degree of &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; are both 0;&lt;br /&gt;
* the &#039;&#039;&#039;capacity function&#039;&#039;&#039;  &amp;lt;math&amp;gt;c:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; which associates each directed edge &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; a nonnegative real number &amp;lt;math&amp;gt;c_{uv}&amp;lt;/math&amp;gt; called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the edge.&lt;br /&gt;
&lt;br /&gt;
The quadruple &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow network&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A function &amp;lt;math&amp;gt;f:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow&#039;&#039;&#039; (to be specific an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow&#039;&#039;&#039;) in the network &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; if it satisfies:&lt;br /&gt;
* &#039;&#039;&#039;Capacity constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;f_{uv}\le c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Conservation constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;\sum_{u:(u,v)\in E}f_{uv}=\sum_{w:(v,w)\in E}f_{vw}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V\setminus\{s,t\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;value&#039;&#039;&#039; of the flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given a flow network, the maximum flow problem asks to find the flow of the maximum value.&lt;br /&gt;
&lt;br /&gt;
The maximum flow problem can be described as the following linear program.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; \sum_{v:(s,v)\in E}f_{sv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E}f_{uv}-\sum_{w:(v,w)\in E}f_{vw} &amp;amp;=0 &amp;amp;\quad&amp;amp; \forall v\in V\setminus\{s,t\}\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cuts ===&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;S\subset V&amp;lt;/math&amp;gt;. We call &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:The &#039;&#039;&#039;value&#039;&#039;&#039; of  the cut (also called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the cut) is defined as &amp;lt;math&amp;gt;\sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A fundamental fact in flow theory is that cuts always upper bound flows.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an arbitrary flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; be an arbitrary &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. Then&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}\le \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:that is, the value of any flow is no greater than the value of any cut.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|By the definition of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the conservation of flow, &lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{u\in S}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}+\sum_{u\in S\setminus\{s\}}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
On the other hand, summing flow over edges,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in S}\left(\sum_{u:(u,v)\in E}f_{uv}-\sum_{u:(v,u)\in E}f_{vu}\right)=\sum_{u\in S,v\in S\atop (u,v)\in E}\left(f_{uv}-f_{uv}\right)+\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\le\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}\le  \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}\,,&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Augmenting paths ===&lt;br /&gt;
{{Theorem|Definition (Augmenting path)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. An &#039;&#039;&#039;augmenting path to &amp;lt;math&amp;gt;u_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; is a sequence of distinct vertices &amp;lt;math&amp;gt;P=(u_0,u_1,\cdots, u_k)&amp;lt;/math&amp;gt;, such that &lt;br /&gt;
:* &amp;lt;math&amp;gt;u_0=s\,&amp;lt;/math&amp;gt;;&lt;br /&gt;
:and each pair of consecutive vertices &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; corresponds to either a &#039;&#039;&#039;forward edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; or a &#039;&#039;&#039;reverse edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;c(u_i,u_{i+1})\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a forward edge &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;gt;0\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a reverse edge &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
:If &amp;lt;math&amp;gt;u_k=t\,&amp;lt;/math&amp;gt;, we simply call &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; an &#039;&#039;&#039;augmenting path&#039;&#039;&#039;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Suppose there is an augmenting path &amp;lt;math&amp;gt;P=u_0u_1\cdots u_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;u_0=s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;u_k=t&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt; be a positive constant satisfying &lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le c(u_{i},u_{i+1})-f(u_i,u_{i+1})&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;;&lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le f(u_{i+1},u_i)&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the definition of augmenting path, we can always find such a positive &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Increase &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and decrease &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;. Denote the modified flow by &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;. It can be verified that &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; satisfies the capacity constraint and conservation constraint thus is still a valid flow. On the other hand, the value of the new flow &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&#039;=\epsilon+\sum_{v:(s,v)\in E}f_{sv}&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Therefore, the value of the flow can be &amp;quot;augmented&amp;quot; by adjusting the flow on the augmenting path. This immediately implies that if a flow is maximum, then there is no augmenting path. Surprisingly, the converse is also true, thus maximum flows are &amp;quot;characterized&amp;quot; by augmenting paths.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:A flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum if and only if there are no augmenting paths.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|We have already proved the &amp;quot;only if&amp;quot; direction above. Now we prove the &amp;quot;if&amp;quot; direction.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt;, and since there is no augmenting path &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defines an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. &lt;br /&gt;
&lt;br /&gt;
We claim that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
that is, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; approach the value of the cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defined above. By the above lemma, this will imply that the current flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum.&lt;br /&gt;
&lt;br /&gt;
To prove this claim, we first observe that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}&amp;lt;/math&amp;gt;.&lt;br /&gt;
This identity is implied by the flow conservation constraint, and holds for any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We then claim that &lt;br /&gt;
*&amp;lt;math&amp;gt;f_{uv}=c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u\in S,v\not\in S, (u,v)\in E&amp;lt;/math&amp;gt;; and &lt;br /&gt;
*&amp;lt;math&amp;gt;f_{vu}=0&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u\in S,v\not\in S, (v,u)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
If otherwise, then the augmenting path to &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; apending &amp;lt;math&amp;gt;uv&amp;lt;/math&amp;gt; becomes a new augmenting path to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, which contradicts that &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; includes all vertices to which there exist augmenting paths.&lt;br /&gt;
&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu} = \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
As discussed above, this proves the theorem.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The max-flow min-cut theorem ===&lt;br /&gt;
{{Theorem|Max-Flow Min-Cut Theorem|&lt;br /&gt;
:In a flow network, the maximum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow equals the minimum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow with maximum value, so there is no augmenting path.&lt;br /&gt;
&lt;br /&gt;
Again, let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. As proved above, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; forms an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, and&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
that is, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; equals the value of cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Since we know that all &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flows are not greater than any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; equals the minimum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Flow Integrality Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; be a flow network with integral capacity &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;. There exists an integral flow which is maximum.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an integral flow of maximum value. If there is an augmenting path, since both &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; are integral, a new flow can be constructed of value 1+the value of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, contradicting that &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum over all integral flows. Therefore, there is no augmenting path, which means that &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum over all flows, integral or not.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Unimodularity ==&lt;br /&gt;
&lt;br /&gt;
=== Integer Programming===&lt;br /&gt;
&lt;br /&gt;
=== Integrality of polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== Unimodularity and total unimodularity ===&lt;br /&gt;
{{Theorem|Definition (Unimodularity)|&lt;br /&gt;
:An &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; integer matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;unimodular&#039;&#039;&#039; if &amp;lt;math&amp;gt;\det(A)=\pm1&amp;lt;/math&amp;gt;.&lt;br /&gt;
:An &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;total unimodular&#039;&#039;&#039; if every square submatrix &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;\det(B)\in\{1,-1,0\}&amp;lt;/math&amp;gt;, that is, every square, nonsingular submatrix of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is unimodular.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix. &lt;br /&gt;
:If &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodualr, then for any integer vector &amp;lt;math&amp;gt;\boldsymbol{b}\in\mathbb{Z}^n&amp;lt;/math&amp;gt; the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; be a basis of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; be the corresponding coordinates in &amp;lt;math&amp;gt;\boldsymbol{b}&amp;lt;/math&amp;gt;. A basic solution is formed by &amp;lt;math&amp;gt;B^{-1}\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; and zeros. Since &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodular and &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; is a basis thus nonsingular, &amp;lt;math&amp;gt;\det(B)\in\{1,-1,0\}&amp;lt;/math&amp;gt;. By [http://en.wikipedia.org/wiki/Cramer&#039;s_rule Cramer&#039;s rule], &amp;lt;math&amp;gt;B^{-1}&amp;lt;/math&amp;gt; has integer entries, thus &amp;lt;math&amp;gt;B^{-1}\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; is integral. Therefore, any basic solution of &amp;lt;math&amp;gt;A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}&amp;lt;/math&amp;gt; is integral, which means the polyhedron  &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}} &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Hoffman-Kruskal 1956)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix. &lt;br /&gt;
:If &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodualr, then for any integer vector &amp;lt;math&amp;gt;\boldsymbol{b}\in\mathbb{Z}^n&amp;lt;/math&amp;gt; the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}\ge\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;A&#039;=\begin{bmatrix}A &amp;amp; -I\end{bmatrix}&amp;lt;/math&amp;gt;. We claim that &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; is also totally unimodular. Any square submatrix &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; can be written in the following form after permutation:&lt;br /&gt;
:&amp;lt;math&amp;gt;B=\begin{bmatrix}&lt;br /&gt;
C &amp;amp; 0\\&lt;br /&gt;
D &amp;amp; I&lt;br /&gt;
\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is a square submatrix of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;I&amp;lt;/math&amp;gt; is identity matrix. Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\det(B)=\det(C)\in\{1,-1,0\}&amp;lt;/math&amp;gt;,&lt;br /&gt;
thus &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; is totally unimodular.&lt;br /&gt;
&lt;br /&gt;
Add slack variables to transform the constraints to the standard form &amp;lt;math&amp;gt;A&#039;\boldsymbol{z}=\boldsymbol{b},\boldsymbol{z}\ge\boldsymbol{0}&amp;lt;/math&amp;gt;. The polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\mid A\boldsymbol{x}\ge\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral if the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{z}\mid A&#039;\boldsymbol{z}=\boldsymbol{b}, \boldsymbol{z}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral, which is implied by the total unimodularity of &amp;lt;math&amp;gt;A&#039;\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.5.190</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4310</id>
		<title>Combinatorics (Fall 2010)/Flow and matching</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4310"/>
		<updated>2010-12-26T07:09:55Z</updated>

		<summary type="html">&lt;p&gt;172.21.5.190: /* Integer Programmings */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Flow and Cut==&lt;br /&gt;
&lt;br /&gt;
=== Flows ===&lt;br /&gt;
An instance of the maximum flow problem consists of:&lt;br /&gt;
* a directed graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;;&lt;br /&gt;
* two distinguished vertices &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;source&#039;&#039;&#039;) and &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;sink&#039;&#039;&#039;), where the in-degree of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and the out-degree of &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; are both 0;&lt;br /&gt;
* the &#039;&#039;&#039;capacity function&#039;&#039;&#039;  &amp;lt;math&amp;gt;c:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; which associates each directed edge &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; a nonnegative real number &amp;lt;math&amp;gt;c_{uv}&amp;lt;/math&amp;gt; called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the edge.&lt;br /&gt;
&lt;br /&gt;
The quadruple &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow network&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A function &amp;lt;math&amp;gt;f:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow&#039;&#039;&#039; (to be specific an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow&#039;&#039;&#039;) in the network &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; if it satisfies:&lt;br /&gt;
* &#039;&#039;&#039;Capacity constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;f_{uv}\le c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Conservation constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;\sum_{u:(u,v)\in E}f_{uv}=\sum_{w:(v,w)\in E}f_{vw}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V\setminus\{s,t\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;value&#039;&#039;&#039; of the flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given a flow network, the maximum flow problem asks to find the flow of the maximum value.&lt;br /&gt;
&lt;br /&gt;
The maximum flow problem can be described as the following linear program.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; \sum_{v:(s,v)\in E}f_{sv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E}f_{uv}-\sum_{w:(v,w)\in E}f_{vw} &amp;amp;=0 &amp;amp;\quad&amp;amp; \forall v\in V\setminus\{s,t\}\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cuts ===&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;S\subset V&amp;lt;/math&amp;gt;. We call &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:The &#039;&#039;&#039;value&#039;&#039;&#039; of  the cut (also called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the cut) is defined as &amp;lt;math&amp;gt;\sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A fundamental fact in the theory of flow is that cuts always upper bound flows.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an arbitrary flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; be an arbitrary &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. Then&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}\le \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:that is, the value of any flow is no greater than the value of any cut.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|By the definition of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the conservation of flow, &lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{u\in S}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}+\sum_{u\in S\setminus\{s\}}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
On the other hand, summing flow over edges,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in S}\left(\sum_{u:(u,v)\in E}f_{uv}-\sum_{u:(v,u)\in E}f_{vu}\right)=\sum_{u\in S,v\in S\atop (u,v)\in E}\left(f_{uv}-f_{uv}\right)+\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\le\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}\le  \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}\,,&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Augmenting paths ===&lt;br /&gt;
{{Theorem|Definition (Augmenting path)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. An &#039;&#039;&#039;augmenting path to &amp;lt;math&amp;gt;u_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; is a sequence of distinct vertices &amp;lt;math&amp;gt;P=(u_0,u_1,\cdots, u_k)&amp;lt;/math&amp;gt;, such that &lt;br /&gt;
:* &amp;lt;math&amp;gt;u_0=s\,&amp;lt;/math&amp;gt;;&lt;br /&gt;
:and each pair of consecutive vertices &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; corresponds to either a &#039;&#039;&#039;forward edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; or a &#039;&#039;&#039;reverse edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;c(u_i,u_{i+1})\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a forward edge &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;gt;0\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a reverse edge &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
:If &amp;lt;math&amp;gt;u_k=t\,&amp;lt;/math&amp;gt;, we simply call &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; an &#039;&#039;&#039;augmenting path&#039;&#039;&#039;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Suppose there is an augmenting path &amp;lt;math&amp;gt;P=u_0u_1\cdots u_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;u_0=s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;u_k=t&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt; be a positive constant satisfying &lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le c(u_{i},u_{i+1})-f(u_i,u_{i+1})&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;;&lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le f(u_{i+1},u_i)&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the definition of augmenting path, we can always find such a positive &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Increase &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and decrease &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;. Denote the modified flow by &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;. It can be verified that &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; satisfies the capacity constraint and conservation constraint thus is still a valid flow. On the other hand, the value of the new flow &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&#039;=\epsilon+\sum_{v:(s,v)\in E}f_{sv}&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Therefore, the value of the flow can be &amp;quot;augmented&amp;quot; by adjusting the flow on the augmenting path. This immediately implies that if a flow is maximum, then there is no augmenting path. Surprisingly, the converse is also true, thus maximum flows are &amp;quot;characterized&amp;quot; by augmenting paths.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:A flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum if and only if there are no augmenting paths.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|We have already proved the &amp;quot;only if&amp;quot; direction above. Now we prove the &amp;quot;if&amp;quot; direction.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt;, and since there is no augmenting path &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defines an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. &lt;br /&gt;
&lt;br /&gt;
We claim that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
that is, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; approach the value of the cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defined above. By the above lemma, this will imply that the current flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum.&lt;br /&gt;
&lt;br /&gt;
To prove this claim, we first observe that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}&amp;lt;/math&amp;gt;.&lt;br /&gt;
This identity is implied by the flow conservation constraint, and holds for any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We then claim that &lt;br /&gt;
*&amp;lt;math&amp;gt;f_{uv}=c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u\in S,v\not\in S, (u,v)\in E&amp;lt;/math&amp;gt;; and &lt;br /&gt;
*&amp;lt;math&amp;gt;f_{vu}=0&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u\in S,v\not\in S, (v,u)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
If otherwise, then the augmenting path to &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; apending &amp;lt;math&amp;gt;uv&amp;lt;/math&amp;gt; becomes a new augmenting path to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, which contradicts that &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; includes all vertices to which there exist augmenting paths.&lt;br /&gt;
&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu} = \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
As discussed above, this proves the theorem.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The max-flow min-cut theorem ===&lt;br /&gt;
{{Theorem|Max-Flow Min-Cut Theorem|&lt;br /&gt;
:In a flow network, the maximum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow equals the minimum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow with maximum value, so there is no augmenting path.&lt;br /&gt;
&lt;br /&gt;
Again, let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. As proved above, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; forms an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, and&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
that is, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; equals the value of cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Since we know that all &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flows are not greater than any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; equals the minimum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Flow Integrality Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; be a flow network with integral capacity &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;. There exists an integral flow which is maximum.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an integral flow of maximum value. If there is an augmenting path, since both &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; are integral, a new flow can be constructed of value 1+the value of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, contradicting that &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum over all integral flows. Therefore, there is no augmenting path, which means that &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum over all flows, integral or not.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Unimodularity ==&lt;br /&gt;
&lt;br /&gt;
=== Integer Programming===&lt;br /&gt;
&lt;br /&gt;
=== Integrality of polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== Unimodularity and total unimodularity ===&lt;br /&gt;
{{Theorem|Definition (Unimodularity)|&lt;br /&gt;
:An &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; integer matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;unimodular&#039;&#039;&#039; if &amp;lt;math&amp;gt;\det(A)=\pm1&amp;lt;/math&amp;gt;.&lt;br /&gt;
:An &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;total unimodular&#039;&#039;&#039; if every square submatrix &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;\det(B)\in\{1,-1,0\}&amp;lt;/math&amp;gt;, that is, every square, nonsingular submatrix of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is unimodular.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix. &lt;br /&gt;
:If &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodualr, then for any integer vector &amp;lt;math&amp;gt;\boldsymbol{b}\in\mathbb{Z}^n&amp;lt;/math&amp;gt; the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; be a basis of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; be the corresponding coordinates in &amp;lt;math&amp;gt;\boldsymbol{b}&amp;lt;/math&amp;gt;. A basic solution is formed by &amp;lt;math&amp;gt;B^{-1}\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; and zeros. Since &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodular and &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; is a basis thus nonsingular, &amp;lt;math&amp;gt;\det(B)\in\{1,-1,0\}&amp;lt;/math&amp;gt;. By [http://en.wikipedia.org/wiki/Cramer&#039;s_rule Cramer&#039;s rule], &amp;lt;math&amp;gt;B^{-1}&amp;lt;/math&amp;gt; has integer entries, thus &amp;lt;math&amp;gt;B^{-1}\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; is integral. Therefore, any basic solution of &amp;lt;math&amp;gt;A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}&amp;lt;/math&amp;gt; is integral, which means the polyhedron  &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}} &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Hoffman-Kruskal 1956)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix. &lt;br /&gt;
:If &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodualr, then for any integer vector &amp;lt;math&amp;gt;\boldsymbol{b}\in\mathbb{Z}^n&amp;lt;/math&amp;gt; the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}\ge\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;A&#039;=\begin{bmatrix}A &amp;amp; -I\end{bmatrix}&amp;lt;/math&amp;gt;. We claim that &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; is also totally unimodular. Any square submatrix &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; can be written in the following form after permutation:&lt;br /&gt;
:&amp;lt;math&amp;gt;B=\begin{bmatrix}&lt;br /&gt;
C &amp;amp; 0\\&lt;br /&gt;
D &amp;amp; I&lt;br /&gt;
\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is a square submatrix of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;I&amp;lt;/math&amp;gt; is identity matrix. Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\det(B)=\det(C)\in\{1,-1,0\}&amp;lt;/math&amp;gt;,&lt;br /&gt;
thus &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; is totally unimodular.&lt;br /&gt;
&lt;br /&gt;
Add slack variables to transform the constraints to the standard form &amp;lt;math&amp;gt;A&#039;\boldsymbol{z}=\boldsymbol{b},\boldsymbol{z}\ge\boldsymbol{0}&amp;lt;/math&amp;gt;. The polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\mid A\boldsymbol{x}\ge\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral if the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{z}\mid A&#039;\boldsymbol{z}=\boldsymbol{b}, \boldsymbol{z}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral, which is implied by the total unimodularity of &amp;lt;math&amp;gt;A&#039;\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.5.190</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4309</id>
		<title>Combinatorics (Fall 2010)/Flow and matching</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4309"/>
		<updated>2010-12-26T07:04:57Z</updated>

		<summary type="html">&lt;p&gt;172.21.5.190: /* Unimodularity and total unimodularity */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Flow and Cut==&lt;br /&gt;
&lt;br /&gt;
=== Flows ===&lt;br /&gt;
An instance of the maximum flow problem consists of:&lt;br /&gt;
* a directed graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;;&lt;br /&gt;
* two distinguished vertices &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;source&#039;&#039;&#039;) and &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;sink&#039;&#039;&#039;), where the in-degree of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and the out-degree of &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; are both 0;&lt;br /&gt;
* the &#039;&#039;&#039;capacity function&#039;&#039;&#039;  &amp;lt;math&amp;gt;c:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; which associates each directed edge &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; a nonnegative real number &amp;lt;math&amp;gt;c_{uv}&amp;lt;/math&amp;gt; called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the edge.&lt;br /&gt;
&lt;br /&gt;
The quadruple &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow network&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A function &amp;lt;math&amp;gt;f:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow&#039;&#039;&#039; (to be specific an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow&#039;&#039;&#039;) in the network &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; if it satisfies:&lt;br /&gt;
* &#039;&#039;&#039;Capacity constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;f_{uv}\le c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Conservation constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;\sum_{u:(u,v)\in E}f_{uv}=\sum_{w:(v,w)\in E}f_{vw}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V\setminus\{s,t\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;value&#039;&#039;&#039; of the flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given a flow network, the maximum flow problem asks to find the flow of the maximum value.&lt;br /&gt;
&lt;br /&gt;
The maximum flow problem can be described as the following linear program.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; \sum_{v:(s,v)\in E}f_{sv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E}f_{uv}-\sum_{w:(v,w)\in E}f_{vw} &amp;amp;=0 &amp;amp;\quad&amp;amp; \forall v\in V\setminus\{s,t\}\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cuts ===&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;S\subset V&amp;lt;/math&amp;gt;. We call &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:The &#039;&#039;&#039;value&#039;&#039;&#039; of  the cut (also called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the cut) is defined as &amp;lt;math&amp;gt;\sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A fundamental fact in the theory of flow is that cuts always upper bound flows.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an arbitrary flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; be an arbitrary &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. Then&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}\le \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:that is, the value of any flow is no greater than the value of any cut.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|By the definition of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the conservation of flow, &lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{u\in S}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}+\sum_{u\in S\setminus\{s\}}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
On the other hand, summing flow over edges,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in S}\left(\sum_{u:(u,v)\in E}f_{uv}-\sum_{u:(v,u)\in E}f_{vu}\right)=\sum_{u\in S,v\in S\atop (u,v)\in E}\left(f_{uv}-f_{uv}\right)+\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\le\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}\le  \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}\,,&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Augmenting paths ===&lt;br /&gt;
{{Theorem|Definition (Augmenting path)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. An &#039;&#039;&#039;augmenting path to &amp;lt;math&amp;gt;u_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; is a sequence of distinct vertices &amp;lt;math&amp;gt;P=(u_0,u_1,\cdots, u_k)&amp;lt;/math&amp;gt;, such that &lt;br /&gt;
:* &amp;lt;math&amp;gt;u_0=s\,&amp;lt;/math&amp;gt;;&lt;br /&gt;
:and each pair of consecutive vertices &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; corresponds to either a &#039;&#039;&#039;forward edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; or a &#039;&#039;&#039;reverse edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;c(u_i,u_{i+1})\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a forward edge &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;gt;0\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a reverse edge &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
:If &amp;lt;math&amp;gt;u_k=t\,&amp;lt;/math&amp;gt;, we simply call &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; an &#039;&#039;&#039;augmenting path&#039;&#039;&#039;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Suppose there is an augmenting path &amp;lt;math&amp;gt;P=u_0u_1\cdots u_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;u_0=s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;u_k=t&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt; be a positive constant satisfying &lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le c(u_{i},u_{i+1})-f(u_i,u_{i+1})&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;;&lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le f(u_{i+1},u_i)&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the definition of augmenting path, we can always find such a positive &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Increase &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and decrease &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;. Denote the modified flow by &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;. It can be verified that &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; satisfies the capacity constraint and conservation constraint thus is still a valid flow. On the other hand, the value of the new flow &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&#039;=\epsilon+\sum_{v:(s,v)\in E}f_{sv}&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Therefore, the value of the flow can be &amp;quot;augmented&amp;quot; by adjusting the flow on the augmenting path. This immediately implies that if a flow is maximum, then there is no augmenting path. Surprisingly, the converse is also true, thus maximum flows are &amp;quot;characterized&amp;quot; by augmenting paths.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:A flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum if and only if there are no augmenting paths.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|We have already proved the &amp;quot;only if&amp;quot; direction above. Now we prove the &amp;quot;if&amp;quot; direction.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt;, and since there is no augmenting path &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defines an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. &lt;br /&gt;
&lt;br /&gt;
We claim that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
that is, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; approach the value of the cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defined above. By the above lemma, this will imply that the current flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum.&lt;br /&gt;
&lt;br /&gt;
To prove this claim, we first observe that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}&amp;lt;/math&amp;gt;.&lt;br /&gt;
This identity is implied by the flow conservation constraint, and holds for any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We then claim that &lt;br /&gt;
*&amp;lt;math&amp;gt;f_{uv}=c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u\in S,v\not\in S, (u,v)\in E&amp;lt;/math&amp;gt;; and &lt;br /&gt;
*&amp;lt;math&amp;gt;f_{vu}=0&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u\in S,v\not\in S, (v,u)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
If otherwise, then the augmenting path to &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; apending &amp;lt;math&amp;gt;uv&amp;lt;/math&amp;gt; becomes a new augmenting path to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, which contradicts that &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; includes all vertices to which there exist augmenting paths.&lt;br /&gt;
&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu} = \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
As discussed above, this proves the theorem.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The max-flow min-cut theorem ===&lt;br /&gt;
{{Theorem|Max-Flow Min-Cut Theorem|&lt;br /&gt;
:In a flow network, the maximum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow equals the minimum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow with maximum value, so there is no augmenting path.&lt;br /&gt;
&lt;br /&gt;
Again, let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. As proved above, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; forms an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, and&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
that is, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; equals the value of cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Since we know that all &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flows are not greater than any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; equals the minimum value of any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Flow Integrality Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; be a flow network with integral capacity &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;. There exists an integral flow which is maximum.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an integral flow of maximum value. If there is an augmenting path, since both &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; are integral, a new flow can be constructed of value 1+the value of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, contradicting that &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum over all integral flows. Therefore, there is no augmenting path, which means that &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum over all flows, integral or not.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Unimodularity ==&lt;br /&gt;
&lt;br /&gt;
=== Integer Programmings===&lt;br /&gt;
&lt;br /&gt;
=== Integrality of polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== Unimodularity and total unimodularity ===&lt;br /&gt;
{{Theorem|Definition (Unimodularity)|&lt;br /&gt;
:An &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; integer matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;unimodular&#039;&#039;&#039; if &amp;lt;math&amp;gt;\det(A)=\pm1&amp;lt;/math&amp;gt;.&lt;br /&gt;
:An &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;total unimodular&#039;&#039;&#039; if every square submatrix &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;\det(B)\in\{1,-1,0\}&amp;lt;/math&amp;gt;, that is, every square, nonsingular submatrix of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is unimodular.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix. &lt;br /&gt;
:If &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodualr, then for any integer vector &amp;lt;math&amp;gt;\boldsymbol{b}\in\mathbb{Z}^n&amp;lt;/math&amp;gt; the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; be a basis of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; be the corresponding coordinates in &amp;lt;math&amp;gt;\boldsymbol{b}&amp;lt;/math&amp;gt;. A basic solution is formed by &amp;lt;math&amp;gt;B^{-1}\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; and zeros. Since &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodular and &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; is a basis thus nonsingular, &amp;lt;math&amp;gt;\det(B)\in\{1,-1,0\}&amp;lt;/math&amp;gt;. By [http://en.wikipedia.org/wiki/Cramer&#039;s_rule Cramer&#039;s rule], &amp;lt;math&amp;gt;B^{-1}&amp;lt;/math&amp;gt; has integer entries, thus &amp;lt;math&amp;gt;B^{-1}\boldsymbol{b}&#039;&amp;lt;/math&amp;gt; is integral. Therefore, any basic solution of &amp;lt;math&amp;gt;A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}&amp;lt;/math&amp;gt; is integral, which means the polyhedron  &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}=\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}} &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Hoffman-Kruskal 1956)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; integer matrix. &lt;br /&gt;
:If &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is totally unimodualr, then for any integer vector &amp;lt;math&amp;gt;\boldsymbol{b}\in\mathbb{Z}^n&amp;lt;/math&amp;gt; the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\in\mathbb{R}^n\mid A\boldsymbol{x}\ge\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;A&#039;=\begin{bmatrix}A &amp;amp; -I\end{bmatrix}&amp;lt;/math&amp;gt;. We claim that &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; is also totally unimodular. Any square submatrix &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; can be written in the following form after permutation:&lt;br /&gt;
:&amp;lt;math&amp;gt;B=\begin{bmatrix}&lt;br /&gt;
C &amp;amp; 0\\&lt;br /&gt;
D &amp;amp; I&lt;br /&gt;
\end{bmatrix}&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; is a square submatrix of &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;I&amp;lt;/math&amp;gt; is identity matrix. Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\det(B)=\det(C)\in\{1,-1,0\}&amp;lt;/math&amp;gt;,&lt;br /&gt;
thus &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; is totally unimodular.&lt;br /&gt;
&lt;br /&gt;
Add slack variables to transform the constraints to the standard form &amp;lt;math&amp;gt;A&#039;\boldsymbol{z}=\boldsymbol{b},\boldsymbol{z}\ge\boldsymbol{0}&amp;lt;/math&amp;gt;. The polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{x}\mid A\boldsymbol{x}\ge\boldsymbol{b}, \boldsymbol{x}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral if the polyhedron &amp;lt;math&amp;gt;\{\boldsymbol{z}\mid A&#039;\boldsymbol{z}=\boldsymbol{b}, \boldsymbol{z}\ge \boldsymbol{0}\}&amp;lt;/math&amp;gt; is integral, which is implied by the total unimodularity of &amp;lt;math&amp;gt;A&#039;\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.5.190</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4291</id>
		<title>Combinatorics (Fall 2010)/Flow and matching</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4291"/>
		<updated>2010-12-24T12:43:13Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.81: /* The augmenting paths */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Flow ==&lt;br /&gt;
&lt;br /&gt;
=== The maximum flow problem ===&lt;br /&gt;
An instance of the maximum flow problem consists of:&lt;br /&gt;
* a directed graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;;&lt;br /&gt;
* two distinguished vertices &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;source&#039;&#039;&#039;) and &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;sink&#039;&#039;&#039;), where the in-degree of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and the out-degree of &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; are both 0;&lt;br /&gt;
* the &#039;&#039;&#039;capacity function&#039;&#039;&#039;  &amp;lt;math&amp;gt;c:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; which associates each directed edge &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; a nonnegative real number &amp;lt;math&amp;gt;c_{uv}&amp;lt;/math&amp;gt; called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the edge.&lt;br /&gt;
&lt;br /&gt;
The quadruple &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow network&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A function &amp;lt;math&amp;gt;f:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow&#039;&#039;&#039; (or an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow&#039;&#039;&#039;) in the network &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; if it satisfies:&lt;br /&gt;
* &#039;&#039;&#039;Capacity constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;f_{uv}\le c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Conservation constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;\sum_{u:(u,v)\in E}f_{uv}=\sum_{w:(v,w)\in E}f_{vw}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V\setminus\{s,t\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;value&#039;&#039;&#039; of the flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given a flow network, the maximum flow problem asks to find the flow of the maximum value.&lt;br /&gt;
&lt;br /&gt;
The maximum flow problem can be described as the following linear program.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; \sum_{v:(s,v)\in E}f_{sv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E}f_{uv}-\sum_{w:(v,w)\in E}f_{vw} &amp;amp;=0 &amp;amp;\quad&amp;amp; \forall v\in V\setminus\{s,t\}\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Cuts ===&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;S\subset V&amp;lt;/math&amp;gt;. We call &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:The &#039;&#039;&#039;value&#039;&#039;&#039; of  the cut (also called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the cut) is defined as &amp;lt;math&amp;gt;\sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A fundamental fact in the theory of flow is that cuts always upper bound flows.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an arbitrary flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; be an arbitrary &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. Then&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}\le \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:that is, the value of any flow is no greater than the value of any cut.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|By the definition of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the conservation of flow, &lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{u\in S}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}+\sum_{u\in S\setminus\{s\}}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
On the other hand, summing flow over edges,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in S}\left(\sum_{u:(u,v)\in E}f_{uv}-\sum_{u:(v,u)\in E}f_{vu}\right)=\sum_{u\in S,v\in S\atop (u,v)\in E}\left(f_{uv}-f_{uv}\right)+\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\le\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}\le  \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}\,,&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The augmenting paths ===&lt;br /&gt;
{{Theorem|Definition (Augmenting path)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. An &#039;&#039;&#039;augmenting path to &amp;lt;math&amp;gt;u_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; is a sequence of distinct vertices &amp;lt;math&amp;gt;P=(u_0,u_1,\cdots, u_k)&amp;lt;/math&amp;gt;, such that &lt;br /&gt;
:* &amp;lt;math&amp;gt;u_0=s\,&amp;lt;/math&amp;gt;;&lt;br /&gt;
:and each pair of consecutive vertices &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; corresponds to either a &#039;&#039;&#039;forward edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; or a &#039;&#039;&#039;reverse edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;c(u_i,u_{i+1})\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a forward edge &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;gt;0\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a reverse edge &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
:If &amp;lt;math&amp;gt;u_k=t\,&amp;lt;/math&amp;gt;, we simply call &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; an &#039;&#039;&#039;augmenting path&#039;&#039;&#039;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Suppose there is an augmenting path &amp;lt;math&amp;gt;P=u_0u_1\cdots u_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;u_0=s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;u_k=t&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt; be a positive constant satisfying &lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le c(u_{i},u_{i+1})-f(u_i,u_{i+1})&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;;&lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le f(u_{i+1},u_i)&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the definition of augmenting path, we can always find such a positive &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Increase &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and decrease &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;. Denote the modified flow by &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;. It is easy to see that &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; satisfies the capacity constraint and conservation constraint thus is still a valid flow. On the other hand, the value of the new flow &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&#039;=\epsilon+\sum_{v:(s,v)\in E}f_{sv}&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Therefore, the value of the flow can be &amp;quot;augmented&amp;quot; by adjusting the flow on the augmenting path. This immediately implies that if a flow is maximum, then there is no augmenting path. Surprisingly, the converse is also true, thus maximum flows are &amp;quot;characterized&amp;quot; by augmenting paths.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:A flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum if and only if there are no augmenting paths.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|We have already proved the &amp;quot;only if&amp;quot; direction above. Now we prove the &amp;quot;if&amp;quot; direction.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt;, and since there is no augmenting path &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defines an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. &lt;br /&gt;
&lt;br /&gt;
We claim that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
that is, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; approach the value of the cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defined above. By the above lemma, this will imply that the current flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum.&lt;br /&gt;
&lt;br /&gt;
To prove this claim, we first observe that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}&amp;lt;/math&amp;gt;.&lt;br /&gt;
This identity is implied by the flow conservation constraint, and holds for any &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We then claim that &lt;br /&gt;
*&amp;lt;math&amp;gt;f_{uv}=c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u\in S,v\not\in S, (u,v)\in E&amp;lt;/math&amp;gt;; and &lt;br /&gt;
*&amp;lt;math&amp;gt;f_{vu}=0&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u\in S,v\not\in S, (v,u)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
If otherwise, then the augmenting path to &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; apending &amp;lt;math&amp;gt;uv&amp;lt;/math&amp;gt; becomes a new augmenting path to &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, which contradicts that &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; includes all vertices to which there exist augmenting paths.&lt;br /&gt;
&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu} = \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
As discussed above, this proves the theorem.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The max-flow min-cut theorem ===&lt;br /&gt;
&lt;br /&gt;
== Unimodularity ==&lt;br /&gt;
&lt;br /&gt;
=== Integrality of polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== Unimodularity and total unimodularity ===&lt;/div&gt;</summary>
		<author><name>172.21.3.81</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4290</id>
		<title>Combinatorics (Fall 2010)/Flow and matching</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4290"/>
		<updated>2010-12-24T12:19:41Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.81: /* The augmenting paths */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Flow ==&lt;br /&gt;
&lt;br /&gt;
=== The maximum flow problem ===&lt;br /&gt;
An instance of the maximum flow problem consists of:&lt;br /&gt;
* a directed graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;;&lt;br /&gt;
* two distinguished vertices &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;source&#039;&#039;&#039;) and &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;sink&#039;&#039;&#039;), where the in-degree of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and the out-degree of &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; are both 0;&lt;br /&gt;
* the &#039;&#039;&#039;capacity function&#039;&#039;&#039;  &amp;lt;math&amp;gt;c:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; which associates each directed edge &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; a nonnegative real number &amp;lt;math&amp;gt;c_{uv}&amp;lt;/math&amp;gt; called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the edge.&lt;br /&gt;
&lt;br /&gt;
The quadruple &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow network&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A function &amp;lt;math&amp;gt;f:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow&#039;&#039;&#039; (or an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow&#039;&#039;&#039;) in the network &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; if it satisfies:&lt;br /&gt;
* &#039;&#039;&#039;Capacity constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;f_{uv}\le c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Conservation constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;\sum_{u:(u,v)\in E}f_{uv}=\sum_{w:(v,w)\in E}f_{vw}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V\setminus\{s,t\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;value&#039;&#039;&#039; of the flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given a flow network, the maximum flow problem asks to find the flow of the maximum value.&lt;br /&gt;
&lt;br /&gt;
The maximum flow problem can be described as the following linear program.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; \sum_{v:(s,v)\in E}f_{sv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E}f_{uv}-\sum_{w:(v,w)\in E}f_{vw} &amp;amp;=0 &amp;amp;\quad&amp;amp; \forall v\in V\setminus\{s,t\}\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Cuts ===&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;S\subset V&amp;lt;/math&amp;gt;. We call &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:The &#039;&#039;&#039;value&#039;&#039;&#039; of  the cut (also called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the cut) is defined as &amp;lt;math&amp;gt;\sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A fundamental fact in the theory of flow is that cuts always upper bound flows.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an arbitrary flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; be an arbitrary &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. Then&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}\le \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:that is, the value of any flow is no greater than the value of any cut.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|By the definition of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the conservation of flow, &lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{u\in S}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}+\sum_{u\in S\setminus\{s\}}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
On the other hand, summing flow over edges,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in S}\left(\sum_{u:(u,v)\in E}f_{uv}-\sum_{u:(v,u)\in E}f_{vu}\right)=\sum_{u\in S,v\in S\atop (u,v)\in E}\left(f_{uv}-f_{uv}\right)+\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\le\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}\le  \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}\,,&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The augmenting paths ===&lt;br /&gt;
{{Theorem|Definition (Augmenting path)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. An &#039;&#039;&#039;augmenting path to &amp;lt;math&amp;gt;u_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; is a sequence of distinct vertices &amp;lt;math&amp;gt;P=(u_0,u_1,\cdots, u_k)&amp;lt;/math&amp;gt;, such that &lt;br /&gt;
:* &amp;lt;math&amp;gt;u_0=s\,&amp;lt;/math&amp;gt;;&lt;br /&gt;
:and each pair of consecutive vertices &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; corresponds to either a &#039;&#039;&#039;forward edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; or a &#039;&#039;&#039;reverse edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;c(u_i,u_{i+1})\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a forward edge &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;gt;0\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a reverse edge &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
:If &amp;lt;math&amp;gt;u_k=t\,&amp;lt;/math&amp;gt;, we simply call &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; an &#039;&#039;&#039;augmenting path&#039;&#039;&#039;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Suppose there is an augmenting path &amp;lt;math&amp;gt;P=u_0u_1\cdots u_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;u_0=s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;u_k=t&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt; be a positive constant satisfying &lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le c(u_{i},u_{i+1})-f(u_i,u_{i+1})&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;;&lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le f(u_{i+1},u_i)&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the definition of augmenting path, we can always find such a positive &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Increase &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and decrease &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;. Denote the modified flow by &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;. It is easy to see that &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; satisfies the capacity constraint and conservation constraint thus is still a valid flow. On the other hand, the value of the new flow &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&#039;=\epsilon+\sum_{v:(s,v)\in E}f_{sv}&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Therefore, the value of the flow can be &amp;quot;augmented&amp;quot; by adjusting the flow on the augmenting path. This immediately implies that if a flow is maximum, then there is no augmenting path. Surprisingly, the converse is also true, thus maximum flows are &amp;quot;characterized&amp;quot; by augmenting paths.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:A flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum if and only if there are no augmenting paths.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|We have already proved the &amp;quot;only if&amp;quot; direction above. Now we prove the &amp;quot;if&amp;quot; direction.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt;, and since there is no augmenting path &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defines an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. &lt;br /&gt;
&lt;br /&gt;
We claim that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}= \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
that is, the value of flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; approach the value of the cut &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defined above. By the above lemma, this will imply that the current flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The max-flow min-cut theorem ===&lt;br /&gt;
&lt;br /&gt;
== Unimodularity ==&lt;br /&gt;
&lt;br /&gt;
=== Integrality of polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== Unimodularity and total unimodularity ===&lt;/div&gt;</summary>
		<author><name>172.21.3.81</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4289</id>
		<title>Combinatorics (Fall 2010)/Flow and matching</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4289"/>
		<updated>2010-12-24T12:06:22Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.81: /* The augmenting paths */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Flow ==&lt;br /&gt;
&lt;br /&gt;
=== The maximum flow problem ===&lt;br /&gt;
An instance of the maximum flow problem consists of:&lt;br /&gt;
* a directed graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;;&lt;br /&gt;
* two distinguished vertices &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;source&#039;&#039;&#039;) and &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;sink&#039;&#039;&#039;), where the in-degree of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and the out-degree of &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; are both 0;&lt;br /&gt;
* the &#039;&#039;&#039;capacity function&#039;&#039;&#039;  &amp;lt;math&amp;gt;c:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; which associates each directed edge &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; a nonnegative real number &amp;lt;math&amp;gt;c_{uv}&amp;lt;/math&amp;gt; called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the edge.&lt;br /&gt;
&lt;br /&gt;
The quadruple &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow network&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A function &amp;lt;math&amp;gt;f:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow&#039;&#039;&#039; (or an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow&#039;&#039;&#039;) in the network &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; if it satisfies:&lt;br /&gt;
* &#039;&#039;&#039;Capacity constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;f_{uv}\le c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Conservation constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;\sum_{u:(u,v)\in E}f_{uv}=\sum_{w:(v,w)\in E}f_{vw}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V\setminus\{s,t\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;value&#039;&#039;&#039; of the flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given a flow network, the maximum flow problem asks to find the flow of the maximum value.&lt;br /&gt;
&lt;br /&gt;
The maximum flow problem can be described as the following linear program.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; \sum_{v:(s,v)\in E}f_{sv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E}f_{uv}-\sum_{w:(v,w)\in E}f_{vw} &amp;amp;=0 &amp;amp;\quad&amp;amp; \forall v\in V\setminus\{s,t\}\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Cuts ===&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;S\subset V&amp;lt;/math&amp;gt;. We call &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:The &#039;&#039;&#039;value&#039;&#039;&#039; of  the cut (also called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the cut) is defined as &amp;lt;math&amp;gt;\sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A fundamental fact in the theory of flow is that cuts always upper bound flows.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an arbitrary flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; be an arbitrary &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. Then&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}\le \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:that is, the value of any flow is no greater than the value of any cut.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|By the definition of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the conservation of flow, &lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{u\in S}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}+\sum_{u\in S\setminus\{s\}}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
On the other hand, summing flow over edges,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in S}\left(\sum_{u:(u,v)\in E}f_{uv}-\sum_{u:(v,u)\in E}f_{vu}\right)=\sum_{u\in S,v\in S\atop (u,v)\in E}\left(f_{uv}-f_{uv}\right)+\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\le\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}\le  \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}\,,&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The augmenting paths ===&lt;br /&gt;
{{Theorem|Definition (Augmenting path)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. An &#039;&#039;&#039;augmenting path to &amp;lt;math&amp;gt;u_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; is a sequence of distinct vertices &amp;lt;math&amp;gt;P=(u_0,u_1,\cdots, u_k)&amp;lt;/math&amp;gt;, such that &lt;br /&gt;
:* &amp;lt;math&amp;gt;u_0=s\,&amp;lt;/math&amp;gt;;&lt;br /&gt;
:and each pair of consecutive vertices &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; corresponds to either a &#039;&#039;&#039;forward edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; or a &#039;&#039;&#039;reverse edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;c(u_i,u_{i+1})\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a forward edge &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;gt;0\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a reverse edge &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
:If &amp;lt;math&amp;gt;u_k=t\,&amp;lt;/math&amp;gt;, we simply call &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; an &#039;&#039;&#039;augmenting path&#039;&#039;&#039;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Suppose there is an augmenting path &amp;lt;math&amp;gt;P=u_0u_1\cdots u_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;u_0=s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;u_k=t&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt; be a positive constant satisfying &lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le c(u_{i},u_{i+1})-f(u_i,u_{i+1})&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;;&lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le f(u_{i+1},u_i)&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the definition of augmenting path, we can always find such a positive &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Increase &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and decrease &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;. Denote the modified flow by &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;. It is easy to see that &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; satisfies the capacity constraint and conservation constraint thus is still a valid flow. On the other hand, the value of the new flow &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&#039;=\epsilon+\sum_{v:(s,v)\in E}f_{sv}&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Therefore, the value of the flow can be &amp;quot;augmented&amp;quot; by adjusting the flow on the augmenting path. This immediately implies that if a flow is maximum, then there is no augmenting path. Surprisingly, the converse is also true, thus maximum flows are &amp;quot;characterized&amp;quot; by augmenting paths.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:A flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum if and only if there are no augmenting paths.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|We have already proved the &amp;quot;only if&amp;quot; direction above. Now we prove the &amp;quot;if&amp;quot; direction.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt;, and since there is no augmenting path &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; defines an &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The max-flow min-cut theorem ===&lt;br /&gt;
&lt;br /&gt;
== Unimodularity ==&lt;br /&gt;
&lt;br /&gt;
=== Integrality of polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== Unimodularity and total unimodularity ===&lt;/div&gt;</summary>
		<author><name>172.21.3.81</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4288</id>
		<title>Combinatorics (Fall 2010)/Flow and matching</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4288"/>
		<updated>2010-12-24T12:05:34Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.81: /* The augmenting paths */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Flow ==&lt;br /&gt;
&lt;br /&gt;
=== The maximum flow problem ===&lt;br /&gt;
An instance of the maximum flow problem consists of:&lt;br /&gt;
* a directed graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;;&lt;br /&gt;
* two distinguished vertices &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;source&#039;&#039;&#039;) and &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;sink&#039;&#039;&#039;), where the in-degree of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and the out-degree of &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; are both 0;&lt;br /&gt;
* the &#039;&#039;&#039;capacity function&#039;&#039;&#039;  &amp;lt;math&amp;gt;c:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; which associates each directed edge &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; a nonnegative real number &amp;lt;math&amp;gt;c_{uv}&amp;lt;/math&amp;gt; called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the edge.&lt;br /&gt;
&lt;br /&gt;
The quadruple &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow network&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A function &amp;lt;math&amp;gt;f:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow&#039;&#039;&#039; (or an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow&#039;&#039;&#039;) in the network &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; if it satisfies:&lt;br /&gt;
* &#039;&#039;&#039;Capacity constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;f_{uv}\le c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Conservation constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;\sum_{u:(u,v)\in E}f_{uv}=\sum_{w:(v,w)\in E}f_{vw}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V\setminus\{s,t\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;value&#039;&#039;&#039; of the flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given a flow network, the maximum flow problem asks to find the flow of the maximum value.&lt;br /&gt;
&lt;br /&gt;
The maximum flow problem can be described as the following linear program.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; \sum_{v:(s,v)\in E}f_{sv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E}f_{uv}-\sum_{w:(v,w)\in E}f_{vw} &amp;amp;=0 &amp;amp;\quad&amp;amp; \forall v\in V\setminus\{s,t\}\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Cuts ===&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;S\subset V&amp;lt;/math&amp;gt;. We call &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:The &#039;&#039;&#039;value&#039;&#039;&#039; of  the cut (also called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the cut) is defined as &amp;lt;math&amp;gt;\sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A fundamental fact in the theory of flow is that cuts always upper bound flows.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an arbitrary flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; be an arbitrary &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. Then&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}\le \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:that is, the value of any flow is no greater than the value of any cut.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|By the definition of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the conservation of flow, &lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{u\in S}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}+\sum_{u\in S\setminus\{s\}}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
On the other hand, summing flow over edges,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in S}\left(\sum_{u:(u,v)\in E}f_{uv}-\sum_{u:(v,u)\in E}f_{vu}\right)=\sum_{u\in S,v\in S\atop (u,v)\in E}\left(f_{uv}-f_{uv}\right)+\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\le\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}\le  \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}\,,&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The augmenting paths ===&lt;br /&gt;
{{Theorem|Definition (Augmenting path)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. An &#039;&#039;&#039;augmenting path to &amp;lt;math&amp;gt;u_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; is a sequence of distinct vertices &amp;lt;math&amp;gt;P=(u_0,u_1,\cdots, u_k)&amp;lt;/math&amp;gt;, such that &lt;br /&gt;
:* &amp;lt;math&amp;gt;u_0=s\,&amp;lt;/math&amp;gt;;&lt;br /&gt;
:and each pair of consecutive vertices &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; corresponds to either a &#039;&#039;&#039;forward edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; or a &#039;&#039;&#039;reverse edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;c(u_i,u_{i+1})\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a forward edge &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;gt;0\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a reverse edge &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
:If &amp;lt;math&amp;gt;u_k=t\,&amp;lt;/math&amp;gt;, we simply call &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; an &#039;&#039;&#039;augmenting path&#039;&#039;&#039;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Suppose there is an augmenting path &amp;lt;math&amp;gt;P=u_0u_1\cdots u_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;u_0=s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;u_k=t&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt; be a positive constant satisfying &lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le c(u_{i},u_{i+1})-f(u_i,u_{i+1})&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;;&lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le f(u_{i+1},u_i)&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the definition of augmenting path, we can always find such a positive &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Increase &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and decrease &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;. Denote the modified flow by &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;. It is easy to see that &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; satisfies the capacity constraint and conservation constraint thus is still a valid flow. On the other hand, the value of the new flow &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&#039;=\epsilon+\sum_{v:(s,v)\in E}f_{sv}&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Therefore, the value of the flow can be &amp;quot;augmented&amp;quot; by adjusting the flow on the augmenting path. This immediately implies that if a flow is maximum, then there is no augmenting path. Surprisingly, the converse is also true, thus maximum flows are &amp;quot;characterized&amp;quot; by augmenting paths.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:A flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum if and only if there are no augmenting paths.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|We have already proved the &amp;quot;only if&amp;quot; direction above. Now we prove the &amp;quot;if&amp;quot; direction.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{u\in V\mid \exists\text{an augmenting path to }u\}&amp;lt;/math&amp;gt;. Clearly &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt;, and since there is no augmenting path &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. Therefore, &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The max-flow min-cut theorem ===&lt;br /&gt;
&lt;br /&gt;
== Unimodularity ==&lt;br /&gt;
&lt;br /&gt;
=== Integrality of polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== Unimodularity and total unimodularity ===&lt;/div&gt;</summary>
		<author><name>172.21.3.81</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4287</id>
		<title>Combinatorics (Fall 2010)/Flow and matching</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Flow_and_matching&amp;diff=4287"/>
		<updated>2010-12-24T12:02:56Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.81: /* Cuts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Flow ==&lt;br /&gt;
&lt;br /&gt;
=== The maximum flow problem ===&lt;br /&gt;
An instance of the maximum flow problem consists of:&lt;br /&gt;
* a directed graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;;&lt;br /&gt;
* two distinguished vertices &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;source&#039;&#039;&#039;) and &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; (the &#039;&#039;&#039;sink&#039;&#039;&#039;), where the in-degree of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; and the out-degree of &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; are both 0;&lt;br /&gt;
* the &#039;&#039;&#039;capacity function&#039;&#039;&#039;  &amp;lt;math&amp;gt;c:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; which associates each directed edge &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; a nonnegative real number &amp;lt;math&amp;gt;c_{uv}&amp;lt;/math&amp;gt; called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the edge.&lt;br /&gt;
&lt;br /&gt;
The quadruple &amp;lt;math&amp;gt;(G,c,s,t)&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow network&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A function &amp;lt;math&amp;gt;f:E\rightarrow\mathbb{R}^+&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;flow&#039;&#039;&#039; (or an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; flow&#039;&#039;&#039;) in the network &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; if it satisfies:&lt;br /&gt;
* &#039;&#039;&#039;Capacity constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;f_{uv}\le c_{uv}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &#039;&#039;&#039;Conservation constraint:&#039;&#039;&#039; &amp;lt;math&amp;gt;\sum_{u:(u,v)\in E}f_{uv}=\sum_{w:(v,w)\in E}f_{vw}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V\setminus\{s,t\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;value&#039;&#039;&#039; of the flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Given a flow network, the maximum flow problem asks to find the flow of the maximum value.&lt;br /&gt;
&lt;br /&gt;
The maximum flow problem can be described as the following linear program.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{maximize} \quad&amp;amp; \sum_{v:(s,v)\in E}f_{sv}\\&lt;br /&gt;
\begin{align}&lt;br /&gt;
\text{subject to} \\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\\&lt;br /&gt;
\end{align}&lt;br /&gt;
\quad &amp;amp;&lt;br /&gt;
\begin{align} f_{uv}&amp;amp;\le c_{uv} &amp;amp;\quad&amp;amp; \forall (u,v)\in E\\&lt;br /&gt;
\sum_{u:(u,v)\in E}f_{uv}-\sum_{w:(v,w)\in E}f_{vw} &amp;amp;=0 &amp;amp;\quad&amp;amp; \forall v\in V\setminus\{s,t\}\\&lt;br /&gt;
 f_{uv}&amp;amp;\ge 0 &amp;amp;\quad&amp;amp; \forall (u,v)\in E&lt;br /&gt;
\end{align}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Cuts ===&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;S\subset V&amp;lt;/math&amp;gt;. We call &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; an &#039;&#039;&#039;&amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:The &#039;&#039;&#039;value&#039;&#039;&#039; of  the cut (also called the &#039;&#039;&#039;capacity&#039;&#039;&#039; of the cut) is defined as &amp;lt;math&amp;gt;\sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A fundamental fact in the theory of flow is that cuts always upper bound flows.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;(G(V,E),c,s,t)&amp;lt;/math&amp;gt; be a flow network. Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be an arbitrary flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;(S,\bar{S})&amp;lt;/math&amp;gt; be an arbitrary &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut. Then&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{v:(s,v)}f_{sv}\le \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:that is, the value of any flow is no greater than the value of any cut.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|By the definition of &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt;-&amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; cut, &amp;lt;math&amp;gt;s\in S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;t\not\in S&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the conservation of flow, &lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{u\in S}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}+\sum_{u\in S\setminus\{s\}}\left(\sum_{v:(u,v)\in E}f_{uv}-\sum_{v:(v,u)\in E}f_{vu}\right)=\sum_{v:(s,v)\in E}f_{sv}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
On the other hand, summing flow over edges,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in S}\left(\sum_{u:(u,v)\in E}f_{uv}-\sum_{u:(v,u)\in E}f_{vu}\right)=\sum_{u\in S,v\in S\atop (u,v)\in E}\left(f_{uv}-f_{uv}\right)+\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\,.&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}=\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}-\sum_{u\in S,v\not\in S\atop (v,u)\in E}f_{vu}\le\sum_{u\in S,v\not\in S\atop (u,v)\in E}f_{uv}\le  \sum_{u\in S,v\not\in S\atop (u,v)\in E}c_{uv}\,,&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The augmenting paths ===&lt;br /&gt;
{{Theorem|Definition (Augmenting path)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. An &#039;&#039;&#039;augmenting path to &amp;lt;math&amp;gt;u_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; is a sequence of distinct vertices &amp;lt;math&amp;gt;P=(u_0,u_1,\cdots, u_k)&amp;lt;/math&amp;gt;, such that &lt;br /&gt;
:* &amp;lt;math&amp;gt;u_0=s\,&amp;lt;/math&amp;gt;;&lt;br /&gt;
:and each pair of consecutive vertices &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; corresponds to either a &#039;&#039;&#039;forward edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; or a &#039;&#039;&#039;reverse edge&#039;&#039;&#039; &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;c(u_i,u_{i+1})\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a forward edge &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt;, and &lt;br /&gt;
:* &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;gt;0\,&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;u_{i}u_{i+1}\,&amp;lt;/math&amp;gt; corresponds to a reverse edge &amp;lt;math&amp;gt;(u_{i+1},u_{i})\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
:If &amp;lt;math&amp;gt;u_k=t\,&amp;lt;/math&amp;gt;, we simply call &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; an &#039;&#039;&#039;augmenting path&#039;&#039;&#039;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; be a flow in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Suppose there is an augmenting path &amp;lt;math&amp;gt;P=u_0u_1\cdots u_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;u_0=s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;u_k=t&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt; be a positive constant satisfying &lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le c(u_{i},u_{i+1})-f(u_i,u_{i+1})&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;;&lt;br /&gt;
*&amp;lt;math&amp;gt;\epsilon \le f(u_{i+1},u_i)&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the definition of augmenting path, we can always find such a positive &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Increase &amp;lt;math&amp;gt;f(u_i,u_{i+1})&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all forward edges &amp;lt;math&amp;gt;(u_{i},u_{i+1})\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and decrease &amp;lt;math&amp;gt;f(u_{i+1},u_i)&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; for all reverse edges &amp;lt;math&amp;gt;(u_{i+1},u_i)\in E&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt;. Denote the modified flow by &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;. It is easy to see that &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; satisfies the capacity constraint and conservation constraint thus is still a valid flow. On the other hand, the value of the new flow &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&#039;=\epsilon+\sum_{v:(s,v)\in E}f_{sv}&amp;gt;\sum_{v:(s,v)\in E}f_{sv}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Therefore, the value of the flow can be &amp;quot;augmented&amp;quot; by adjusting the flow on the augmenting path. This immediately implies that if a flow is maximum, then there is no augmenting path. Surprisingly, the converse is also true, thus maximum flows are &amp;quot;characterized&amp;quot; by augmenting paths.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:A flow &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is maximum if and only if there are no augmenting paths.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|We have already proved the &amp;quot;only if&amp;quot; direction above. Now we prove the &amp;quot;if&amp;quot; direction.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The max-flow min-cut theorem ===&lt;br /&gt;
&lt;br /&gt;
== Unimodularity ==&lt;br /&gt;
&lt;br /&gt;
=== Integrality of polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== Unimodularity and total unimodularity ===&lt;/div&gt;</summary>
		<author><name>172.21.3.81</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_set_theory&amp;diff=3808</id>
		<title>Combinatorics (Fall 2010)/Extremal set theory</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_set_theory&amp;diff=3808"/>
		<updated>2010-12-05T07:53:38Z</updated>

		<summary type="html">&lt;p&gt;172.21.15.93: /* First proof (shadows) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Sperner system ==&lt;br /&gt;
A set family &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; with the relation &amp;lt;math&amp;gt;\subseteq&amp;lt;/math&amp;gt; define a poset. Thus, a &#039;&#039;&#039;chain&#039;&#039;&#039; is a sequence &amp;lt;math&amp;gt;S_1\subseteq S_2\subseteq\cdots\subseteq S_k&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
A set family &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; is an &#039;&#039;&#039;antichain&#039;&#039;&#039; (also called a &#039;&#039;&#039;Sperner system&#039;&#039;&#039;) if for all &amp;lt;math&amp;gt;S,T\in\mathcal{F}&amp;lt;/math&amp;gt; that &amp;lt;math&amp;gt;S\neq T&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;S\not\subseteq T&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-uniform &amp;lt;math&amp;gt;{X\choose k}&amp;lt;/math&amp;gt; is an antichain. Let &amp;lt;math&amp;gt;n=|X|&amp;lt;/math&amp;gt;. The size of &amp;lt;math&amp;gt;{X\choose k}&amp;lt;/math&amp;gt; is maximized when &amp;lt;math&amp;gt;k=\lfloor n/2\rfloor&amp;lt;/math&amp;gt;. We wonder whether this is also the largest possible size of any antichain &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In 1928, Emanuel Sperner proved a theorem saying that it is indeed the largest possible antichain. This result, called Sperner&#039;s theorem today, initiated the studies of extremal set theory.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Sperner 1928)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;|X|=n&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is an antichain, then&lt;br /&gt;
::&amp;lt;math&amp;gt;|\mathcal{F}|\le{n\choose \lfloor n/2\rfloor}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== First proof (shadows)===&lt;br /&gt;
We first introduce the original proof by Sperner, which uses concepts called &#039;&#039;&#039;shadows&#039;&#039;&#039; and &#039;&#039;&#039;shades&#039;&#039;&#039; of set systems.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;|X|=n\,&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\mathcal{F}\subseteq {X\choose k}&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;k&amp;lt;n\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
:The &#039;&#039;&#039;shade&#039;&#039;&#039; of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is defined to be&lt;br /&gt;
::&amp;lt;math&amp;gt;\nabla\mathcal{F}=\left\{T\in {X\choose k+1}\,\,\bigg|\,\, \exists S\in\mathcal{F}\mbox{ such that } S\subset T\right\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Thus the shade &amp;lt;math&amp;gt;\nabla\mathcal{F}&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; consists of all subsets of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; which can be obtained by adding an element to a set in &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Similarly, the &#039;&#039;&#039;shadow&#039;&#039;&#039; of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is defined to be&lt;br /&gt;
::&amp;lt;math&amp;gt;\Delta\mathcal{F}=\left\{T\in {X\choose k-1}\,\,\bigg|\,\, \exists S\in\mathcal{F}\mbox{ such that } T\subset S\right\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Thus the shadow &amp;lt;math&amp;gt;\Delta\mathcal{F}&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; consists of all subsets of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; which can be obtained by removing an element from a set in &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Next lemma bounds the effects of shadows and shades on the sizes of set systems.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma (Sperner)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;|X|=n\,&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\mathcal{F}\subseteq {X\choose k}&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
&amp;amp;|\nabla\mathcal{F}|\ge\frac{n-k}{k+1}|\mathcal{F}| &amp;amp;\text{ if } k&amp;lt;n\\&lt;br /&gt;
&amp;amp;|\Delta\mathcal{F}|\ge\frac{k}{n-k+1}|\mathcal{F}| &amp;amp;\text{ if } k&amp;gt;0.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Proof|&lt;br /&gt;
The lemma is proved by double counting. We prove the inequality of &amp;lt;math&amp;gt;|\nabla\mathcal{F}|&amp;lt;/math&amp;gt;. Assume that &amp;lt;math&amp;gt;0\le k&amp;lt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Define&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathcal{R}=\{(S,T)\mid S\in\mathcal{F}, T\in\nabla\mathcal{F}, S\subset T\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
We estimate &amp;lt;math&amp;gt;|\mathcal{R}|&amp;lt;/math&amp;gt; in two ways. &lt;br /&gt;
&lt;br /&gt;
For each &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt;, there are &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; different &amp;lt;math&amp;gt;T\in\nabla\mathcal{F}&amp;lt;/math&amp;gt; that &amp;lt;math&amp;gt;S\subset T&amp;lt;/math&amp;gt;.&lt;br /&gt;
:&amp;lt;math&amp;gt;|\mathcal{R}|=(n-k)|\mathcal{F}|&amp;lt;/math&amp;gt;.&lt;br /&gt;
For each &amp;lt;math&amp;gt;T\in\nabla\mathcal{F}&amp;lt;/math&amp;gt;, there are &amp;lt;math&amp;gt;k+1&amp;lt;/math&amp;gt; ways to choose an &amp;lt;math&amp;gt;S\subset T&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|S|=k&amp;lt;/math&amp;gt;, some of which may not be in &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:&amp;lt;math&amp;gt;|\mathcal{R}|\le (k+1)|\nabla\mathcal{F}|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Altogether, we show that &amp;lt;math&amp;gt;|\nabla\mathcal{F}|\ge\frac{n-k}{k+1}|\mathcal{F}|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The inequality of &amp;lt;math&amp;gt;|\Delta\mathcal{F}|&amp;lt;/math&amp;gt; can be proved in the same way.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
An immediate corollary of the previous lemma is as follows.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition 1|&lt;br /&gt;
:If &amp;lt;math&amp;gt;k\le \frac{n-1}{2}&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;|\nabla\mathcal{F}|\ge|\mathcal{F}|&amp;lt;/math&amp;gt;.&lt;br /&gt;
:If &amp;lt;math&amp;gt;k\ge \frac{n-1}{2}&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;|\Delta\mathcal{F}|\ge|\mathcal{F}|&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The idea of Sperner&#039;s proof is pretty clear: &lt;br /&gt;
* we &amp;quot;push up&amp;quot; all the sets in &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; of size &amp;lt;math&amp;gt;&amp;lt;\frac{n-1}{2}&amp;lt;/math&amp;gt; replacing them by their shades; &lt;br /&gt;
* and also &amp;quot;push down&amp;quot; all the sets in &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; of size &amp;lt;math&amp;gt;\ge\frac{n+1}{2}&amp;lt;/math&amp;gt; replacing them by their shadows. &lt;br /&gt;
Repeat this process we end up with a set system &amp;lt;math&amp;gt;\mathcal{F}\subseteq{X\choose \lfloor n/2\rfloor}&amp;lt;/math&amp;gt;. We need to show that this process does not decrease the size of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition 2|&lt;br /&gt;
:Suppose that &amp;lt;math&amp;gt;\mathcal{F}\subseteq2^X&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;|X|=n&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;k_\min&amp;lt;/math&amp;gt; be the smallest &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; that &amp;lt;math&amp;gt;|\mathcal{F}_k|&amp;gt;0&amp;lt;/math&amp;gt;, and let&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\mathcal{F}&#039;=\begin{cases}&lt;br /&gt;
\mathcal{F}\setminus\mathcal{F}_k\cup \nabla\mathcal{F}_k &amp;amp; \mbox{if }k_\min&amp;lt;\frac{n-1}{2},\\&lt;br /&gt;
\mathcal{F} &amp;amp; \mbox{otherwise.}&lt;br /&gt;
\end{cases}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:Similarly, let &amp;lt;math&amp;gt;k_\max&amp;lt;/math&amp;gt; be the largest &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; that &amp;lt;math&amp;gt;|\mathcal{F}_k|&amp;gt;0&amp;lt;/math&amp;gt;, and let&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\mathcal{F}&#039;&#039;=\begin{cases}&lt;br /&gt;
\mathcal{F}\setminus\mathcal{F}_k\cup \Delta\mathcal{F}_k &amp;amp; \mbox{if }k_\max\ge\frac{n+1}{2},\\&lt;br /&gt;
\mathcal{F} &amp;amp; \mbox{otherwise.}&lt;br /&gt;
\end{cases}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
:If &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is an antichain, &amp;lt;math&amp;gt;\mathcal{F}&#039;&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\mathcal{F}&#039;&#039;&amp;lt;/math&amp;gt; are antichains, and we have &amp;lt;math&amp;gt;|\mathcal{F}&#039;|\ge|\mathcal{F}|&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|\mathcal{F}&#039;&#039;|\ge|\mathcal{F}|&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
We show that &amp;lt;math&amp;gt;\mathcal{F}&#039;&amp;lt;/math&amp;gt; is an antichain and &amp;lt;math&amp;gt;|\mathcal{F}&#039;|\ge|\mathcal{F}|&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
First, observe that &amp;lt;math&amp;gt;\nabla\mathcal{F}_k\cap\mathcal{F}=\emptyset&amp;lt;/math&amp;gt;, otherwise &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; cannot be an antichain, and due to Proposition 1, &amp;lt;math&amp;gt;|\nabla\mathcal{F}_k|\ge|\mathcal{F}_k|&amp;lt;/math&amp;gt; when &amp;lt;math&amp;gt;k\le \frac{n-1}{2}&amp;lt;/math&amp;gt;, so &amp;lt;math&amp;gt;|\mathcal{F}&#039;|=|\mathcal{F}|-|\mathcal{F}_k|+|\nabla\mathcal{F}_k|\ge |\mathcal{F}|&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Now we prove that &amp;lt;math&amp;gt;\mathcal{F}&#039;&amp;lt;/math&amp;gt; is an antichain . By contradiction, assume that there are &amp;lt;math&amp;gt;S, T\in \mathcal{F}&#039;&amp;lt;/math&amp;gt;, such that &amp;lt;math&amp;gt;S\subset T&amp;lt;/math&amp;gt;. One of the &amp;lt;math&amp;gt;S,T&amp;lt;/math&amp;gt; must be in &amp;lt;math&amp;gt;\nabla\mathcal{F}_k&amp;lt;/math&amp;gt;, or otherwise &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; cannot be an antichain. Recall that &amp;lt;math&amp;gt;k_\min&amp;lt;/math&amp;gt; is the smallest &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; that &amp;lt;math&amp;gt;|\mathcal{F}_k|&amp;gt;0&amp;lt;/math&amp;gt;, thus it must be &amp;lt;math&amp;gt;S\in \nabla\mathcal{F}_k&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;T\in\mathcal{F}&amp;lt;/math&amp;gt;. This implies that there is an &amp;lt;math&amp;gt;R\in \mathcal{F}_k\subseteq \mathcal{F}&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;R\subset S\subset T&amp;lt;/math&amp;gt;, which contradicts that &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is an antichain.&lt;br /&gt;
&lt;br /&gt;
The statement for &amp;lt;math&amp;gt;\mathcal{F}&#039;&#039;&amp;lt;/math&amp;gt; can be proved in the same way.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Applying the above process, we prove the Sperner&#039;s theorem.&lt;br /&gt;
{{Prooftitle|Proof of Sperner&#039;s theorem | (original proof of Sperner)&lt;br /&gt;
Let &amp;lt;math&amp;gt;\mathcal{F}_k=\{S\in\mathcal{F}\mid |S|=k\}&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;0\le k\le n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We change &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; as follows: &lt;br /&gt;
* for the smallest &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; that &amp;lt;math&amp;gt;|\mathcal{F}_k|&amp;gt;0&amp;lt;/math&amp;gt;, if &amp;lt;math&amp;gt;k&amp;lt;\frac{n-1}{2}&amp;lt;/math&amp;gt;, replace &amp;lt;math&amp;gt;\mathcal{F}_k&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\nabla\mathcal{F}_k&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Due to Proposition 2, this procedure preserves &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; as an antichain and does not decrease &amp;lt;math&amp;gt;|\mathcal{F}|&amp;lt;/math&amp;gt;. Repeat this procedure, until &amp;lt;math&amp;gt;|\mathcal{F}_k|=0&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;k&amp;lt;\frac{n-1}{2}&amp;lt;/math&amp;gt;, that is, there is no member set of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; has size less than &amp;lt;math&amp;gt;\frac{n-1}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We then define another symmetric procedure:&lt;br /&gt;
* for the largest &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; that &amp;lt;math&amp;gt;|\mathcal{F}_k|&amp;gt;0&amp;lt;/math&amp;gt;, if &amp;lt;math&amp;gt;k\ge\frac{n+1}{2}&amp;lt;/math&amp;gt;, replace &amp;lt;math&amp;gt;\mathcal{F}_k&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\Delta\mathcal{F}_k&amp;lt;/math&amp;gt;.&lt;br /&gt;
Also due to Proposition 2, this procedure preserves &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; as an antichain and does not decrease &amp;lt;math&amp;gt;|\mathcal{F}|&amp;lt;/math&amp;gt;. After repeatedly applying this procedure, &amp;lt;math&amp;gt;|\mathcal{F}_k|=0&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;k\ge\frac{n+1}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
The resulting &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;\mathcal{F}\subseteq{X\choose \lfloor n/2\rfloor}&amp;lt;/math&amp;gt;, and since &amp;lt;math&amp;gt;|\mathcal{F}|&amp;lt;/math&amp;gt; is never decreased, for the original &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt;, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;|\mathcal{F}|\le {n\choose \lfloor n/2\rfloor}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Second proof (counting)===&lt;br /&gt;
We now introduce an elegant proof due to Lubell. The proof uses a counting argument, and tells more information than just the size of the set system.&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Proof of Sperner&#039;s theorem | (Lubell 1966)&lt;br /&gt;
Let &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; be a permutation of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;. We say that an &amp;lt;math&amp;gt;S\subseteq X&amp;lt;/math&amp;gt; &#039;&#039;&#039;prefixes&#039;&#039;&#039; &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt;, if &amp;lt;math&amp;gt;S=\{\pi_1,\pi_2,\ldots, \pi_{|S|}\}&amp;lt;/math&amp;gt;, that is, &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is precisely the set of the first &amp;lt;math&amp;gt;|S|&amp;lt;/math&amp;gt; elements in the permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Fix an &amp;lt;math&amp;gt;S\subseteq X&amp;lt;/math&amp;gt;. It is easy to see that the number of permutations &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; prefixed by &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;|S|!(n-|S|)!&amp;lt;/math&amp;gt;.  Also, since &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is an antichain, no permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; can be prefixed by more than one members of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt;, otherwise one of the member sets must contain the other, which contradicts that &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is an antichain. Thus, the number of permutations &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; prefixed by some &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{S\in\mathcal{F}}|S|!(n-|S|)!&amp;lt;/math&amp;gt;,&lt;br /&gt;
which cannot be larger than the total number of permutations, &amp;lt;math&amp;gt;n!&amp;lt;/math&amp;gt;, therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{S\in\mathcal{F}}|S|!(n-|S|)!\le n!&amp;lt;/math&amp;gt;.&lt;br /&gt;
Dividing both sides by &amp;lt;math&amp;gt;n!&amp;lt;/math&amp;gt;, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{S\in\mathcal{F}}\frac{1}{{n\choose |S|}}=\sum_{S\in\mathcal{F}}\frac{|S|!(n-|S|)!}{n!}\le 1&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{n\choose |S|}\le {n\choose \lfloor n/2\rfloor}&amp;lt;/math&amp;gt;, so&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{S\in\mathcal{F}}\frac{1}{{n\choose |S|}}\ge \frac{|\mathcal{F}|}{{n\choose \lfloor n/2\rfloor}}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Combining this with the above inequality, we prove the Sperner&#039;s theorem.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== The LYM inequality ===&lt;br /&gt;
Lubell&#039;s proof proves the following inequality:&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{S\in\mathcal{F}}\frac{1}{{n\choose |S|}}\le 1&amp;lt;/math&amp;gt;&lt;br /&gt;
which is actually stronger than Sperner&#039;s original statement that &amp;lt;math&amp;gt;|\mathcal{F}|\le{n\choose \lfloor n/2\rfloor}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This inequality is independently discovered by Lubell-Yamamoto, Meschalkin, and Bollobás, and is called the LYM inequality today.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Lubell, Yamamoto 1954; Meschalkin 1963)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;|X|=n&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is an antichain, then&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{S\in\mathcal{F}}\frac{1}{{n\choose |S|}}\le 1&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
In Lubell&#039;s counting argument proves the LYM inequality, which implies the Sperner&#039;s theorem. Here we give another proof of the LYM inequality by the probabilistic method,  due to Noga Alon.&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof (the probabilistic method)| (Due to Alon.)&lt;br /&gt;
Let &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; be a uniformly random permutation of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;. Define a random maximal chain by&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathcal{C}_\pi=\{\{\pi_i\mid 1\le i\le k\}\mid 0\le k\le n\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
For any &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;X_S&amp;lt;/math&amp;gt; be the 0-1 random variable which indicates whether &amp;lt;math&amp;gt;S\in\mathcal{C}_\pi&amp;lt;/math&amp;gt;, that is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
X_S=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }S\in\mathcal{C}_\pi,\\&lt;br /&gt;
0 &amp;amp; \mbox{otherwise.}&lt;br /&gt;
\end{cases}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Note that for a uniformly random &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{C}_\pi&amp;lt;/math&amp;gt; has exact one member set of size &amp;lt;math&amp;gt;|S|&amp;lt;/math&amp;gt;, uniformly distributed over &amp;lt;math&amp;gt;{X\choose |S|}&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathbf{E}[X_S]=\Pr[S\in\mathcal{C}_\pi]=\frac{1}{{n\choose |S|}}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Let &amp;lt;math&amp;gt;X=\sum_{S\in\mathcal{F}}X_S&amp;lt;/math&amp;gt;. Note that &amp;lt;math&amp;gt;X=|\mathcal{F}\cap\mathcal{C}_\pi|&amp;lt;/math&amp;gt;. By the linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathbf{E}[X]=\sum_{S\in\mathcal{F}}\mathbf{E}[X_S]=\sum_{S\in\mathcal{F}}\frac{1}{{n\choose |S|}}&amp;lt;/math&amp;gt;.&lt;br /&gt;
On the other hand, since &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is an antichain, it can never intersect a chain at more than one elements, thus we always have &amp;lt;math&amp;gt;X=|\mathcal{F}\cap\mathcal{C}_\pi|\le 1&amp;lt;/math&amp;gt;. Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{S\in\mathcal{F}}\frac{1}{{n\choose |S|}}\le \mathbf{E}[X] \le 1&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The Sperner&#039;s theorem is an immediate consequence of the LYM inequality.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{S\in\mathcal{F}}\frac{1}{{n\choose |S|}}\le 1&amp;lt;/math&amp;gt; implies that &amp;lt;math&amp;gt;|\mathcal{F}|\le{n\choose \lfloor n/2\rfloor}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
It holds that &amp;lt;math&amp;gt;{n\choose k}\le {n\choose \lfloor n/2\rfloor}&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;1\ge \sum_{S\in\mathcal{F}}\frac{1}{{n\choose |S|}}\ge \frac{|\mathcal{F}|}{{n\choose \lfloor n/2\rfloor}}&amp;lt;/math&amp;gt;,&lt;br /&gt;
which implies that &amp;lt;math&amp;gt;|\mathcal{F}|\le {n\choose \lfloor n/2\rfloor}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Sunflowers ==&lt;br /&gt;
An set system is a &#039;&#039;&#039;sunflower&#039;&#039;&#039; if all its member sets intersect at the same set of elements.&lt;br /&gt;
{{Theorem|Definition (sunflower)|&lt;br /&gt;
: A set family &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;sunflower&#039;&#039;&#039; of size &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; with a &#039;&#039;&#039;core&#039;&#039;&#039; &amp;lt;math&amp;gt;C\subseteq X&amp;lt;/math&amp;gt; if &lt;br /&gt;
::&amp;lt;math&amp;gt;\forall S,T\in\mathcal{F}&amp;lt;/math&amp;gt; that &amp;lt;math&amp;gt;S\neq T&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;S\cap T=C&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
Note that we do not require the core to be nonempty, thus a family of disjoint sets is also a sunflower (with the core &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The next result due to Erdős and Rado, called the sunflower lemma, is a famous result in extremal set theory, and has some important applications in Boolean circuit complexity.&lt;br /&gt;
{{Theorem|Sunflower Lemma (Erdős-Rado)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\mathcal{F}\subseteq {X\choose k}&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;|\mathcal{F}|&amp;gt;k!(r-1)^k&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; contains a sunflower of size  &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
We proceed by induction on &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. For &amp;lt;math&amp;gt;k=1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{F}\subseteq{X\choose 1}&amp;lt;/math&amp;gt;, thus all sets in &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; are disjoint. And since &amp;lt;math&amp;gt;|\mathcal{F}|&amp;gt;r-1&amp;lt;/math&amp;gt;, we can choose &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; of these sets and form a sunflower.&lt;br /&gt;
&lt;br /&gt;
Now let &amp;lt;math&amp;gt;k\ge 2&amp;lt;/math&amp;gt; and assume the lemma holds for all smaller &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. Take a maximal family &amp;lt;math&amp;gt;\mathcal{G}\subseteq \mathcal{F}&amp;lt;/math&amp;gt; whose members are disjoint, i.e. for any &amp;lt;math&amp;gt;S,T\in \mathcal{G}&amp;lt;/math&amp;gt; that &amp;lt;math&amp;gt;S\neq T&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;S\cap T=\emptyset&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;|\mathcal{G}|\ge r&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; is a sunflower of size at least &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; and we are done.&lt;br /&gt;
&lt;br /&gt;
Assume that &amp;lt;math&amp;gt;|\mathcal{G}|\le r-1&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;Y=\bigcup_{S\in\mathcal{G}}S&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;|Y|=k|\mathcal{G}|\le k(r-1)&amp;lt;/math&amp;gt; (since all members of &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt;) are disjoint). We claim that &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; intersets all members of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt;, since if otherwise, there exists an &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;S\cap Y=\emptyset&amp;lt;/math&amp;gt;, then we can enlarge &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; by adding &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; into &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; and still have all members of &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; disjoint, which contradicts the assumption that &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; is the maximum of such families.&lt;br /&gt;
&lt;br /&gt;
By the pigeonhole principle, some elements &amp;lt;math&amp;gt;y\in Y&amp;lt;/math&amp;gt; must contained in at least&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{|\mathcal{F}|}{|Y|}&amp;gt;\frac{k!(r-1)^k}{k(r-1)}=(k-1)!(r-1)^{k-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
members of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt;. We delete this &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; from these sets and consider the family &lt;br /&gt;
:&amp;lt;math&amp;gt;\mathcal{H}=\{S\setminus\{y\}\mid S\in\mathcal{F}\wedge y\in S\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have &amp;lt;math&amp;gt;\mathcal{H}\subseteq {X\choose k-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|\mathcal{H}|&amp;gt;(k-1)!(r-1)^{k-1}&amp;lt;/math&amp;gt;, thus by the induction hypothesis, &amp;lt;math&amp;gt;\mathcal{H}&amp;lt;/math&amp;gt;contains a sunflower of size &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;. Adding &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; to the members of this sunflower, we get the desired sunflower in the original family &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==The Erdős–Ko–Rado Theorem ==&lt;br /&gt;
A set family &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^X&amp;lt;/math&amp;gt; is called &#039;&#039;&#039;intersecting&#039;&#039;&#039;, if for any &amp;lt;math&amp;gt;S,T\in\mathcal{F}&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;S\cap T\neq\emptyset&amp;lt;/math&amp;gt;. A natural question of extremal favor is: &amp;quot;how large can an intersecting family be?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Assume &amp;lt;math&amp;gt;|X|=n&amp;lt;/math&amp;gt;. When &amp;lt;math&amp;gt;n&amp;lt;2k&amp;lt;/math&amp;gt;, every pair of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; intersects. So the non-trivial case is when &amp;lt;math&amp;gt;n\le 2k&amp;lt;/math&amp;gt;. The famous Erdős–Ko–Rado theorem gives the largest possible cardinality of a nontrivially intersecting family. &lt;br /&gt;
&lt;br /&gt;
According to Erdős, the theorem itself was proved in 1938, but was not published until 23 years later.&lt;br /&gt;
{{Theorem|Erdős–Ko–Rado theorem (proved in 1938, published in 1961)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\mathcal{F}\subseteq {X\choose k}&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;|X|=n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n\ge 2k&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is intersecting, then&lt;br /&gt;
::&amp;lt;math&amp;gt;|\mathcal{F}|\le{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Katona&#039;s proof ===&lt;br /&gt;
We first introduce a proof discovered by Katona in 1972. The proof uses double counting.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; be a &#039;&#039;&#039;cyclic permutation&#039;&#039;&#039; of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;, that is, we think of assigning &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; in a circle and ignore the rotations of the circle. It is easy to see that there are &amp;lt;math&amp;gt;(n-1)!&amp;lt;/math&amp;gt; cyclic permutations of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set (each cyclic permutation corresponds to &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; permutations).&lt;br /&gt;
Let &lt;br /&gt;
:&amp;lt;math&amp;gt;\mathcal{G}_\pi=\{\{\pi_{(i+j)\bmod n}\mid j\in[k]\}\mid i\in [n]\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The next lemma states the following observation: in a circle of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; points, supposed &amp;lt;math&amp;gt;n\ge 2k&amp;lt;/math&amp;gt;, there can be at most &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; arcs, each consisting of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; points, such that every pair of arcs share at least one point.&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\mathcal{F}\subseteq {X\choose k}&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;|X|=n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n\ge 2k&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is intersecting, then for any cyclic permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;, it holds that &amp;lt;math&amp;gt;|\mathcal{G}_\pi\cap\mathcal{F}|\le k&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Fix a cyclic permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;A_i=\{\pi_{(i+j+n)\bmod n}\mid j\in[k]\}&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;\mathcal{G}_\pi&amp;lt;/math&amp;gt; can be written as &amp;lt;math&amp;gt;\mathcal{G}_\pi=\{A_i\mid i\in [n]\}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Suppose that &amp;lt;math&amp;gt;A_t\in\mathcal{F}&amp;lt;/math&amp;gt;. Since &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is intersecting, the only sets &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt; that can be in &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; other than &amp;lt;math&amp;gt;A_t&amp;lt;/math&amp;gt; itself are the &amp;lt;math&amp;gt;2k-2&amp;lt;/math&amp;gt; sets &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;t-(k-1)\le i\le t+k-1, i\neq t&amp;lt;/math&amp;gt;. We partition these sets into &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; pairs &amp;lt;math&amp;gt;\{A_i,A_{i+k}\}&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;t-(k-1)\le i\le t-1&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that for &amp;lt;math&amp;gt;n\ge 2k&amp;lt;/math&amp;gt;, it holds that &amp;lt;math&amp;gt;A_i\cap C_{i+k}=\emptyset&amp;lt;/math&amp;gt;. Since &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is intersecting, &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; can contain at most one set of each such pair. The lemma follows.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The Katona&#039;s proof of Erdős–Ko–Rado theorem is done by counting in two ways the pairs of member &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; and cyclic permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; which contain &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; as a continuous path on the circle (i.e., an arc).&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Katona&#039;s proof of Erdős–Ko–Rado theorem|(double counting)&lt;br /&gt;
Let &lt;br /&gt;
:&amp;lt;math&amp;gt;\mathcal{R}=\{(S,\pi)\mid \pi \text{ is a cyclic permutation of }X, \text{and }S\in\mathcal{F}\cap\mathcal{G}_\pi\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
We count &amp;lt;math&amp;gt;\mathcal{R}&amp;lt;/math&amp;gt; in two ways.&lt;br /&gt;
&lt;br /&gt;
First, due to the lemma, &amp;lt;math&amp;gt;|\mathcal{F}\cap\mathcal{G}_\pi|\le k&amp;lt;/math&amp;gt; for any cyclic permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt;. There are &amp;lt;math&amp;gt;(n-1)!&amp;lt;/math&amp;gt; cyclic permutations in total. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;|\mathcal{R}|=\sum_{\text{cyclic }\pi}|\mathcal{F}\cap\mathcal{G}_\pi|\le k(n-1)!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Next, for each &amp;lt;math&amp;gt;S\in\mathcal{F}&amp;lt;/math&amp;gt;, the number of cyclic permutations &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; in which &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is continuous is &amp;lt;math&amp;gt;|S|!(n-|S|)!=k!(n-k)!&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;|\mathcal{R}|=\sum_{S\in\mathcal{F}}k!(n-k)!=|\mathcal{F}|k!(n-k)!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Altogether, we have &lt;br /&gt;
:&amp;lt;math&amp;gt;|\mathcal{F}|\le\frac{k(n-1)!}{k!(n-k)!}=\frac{(n-1)!}{(k-1)!(n-k)!}={n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Erdős&#039; shifting technique ===&lt;br /&gt;
We now introduce the original proof of the Erdős–Ko–Rado theorem, which uses a technique called &#039;&#039;&#039;shifting&#039;&#039;&#039; (originally called &#039;&#039;&#039;compression&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Without loss of generality, we assume &amp;lt;math&amp;gt;X=[n]&amp;lt;/math&amp;gt;, and restate the Erdős–Ko–Rado theorem as follows.&lt;br /&gt;
{{Theorem|Erdős–Ko–Rado theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\mathcal{F}\subseteq {[n]\choose k}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n\ge 2k&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is intersecting, then &amp;lt;math&amp;gt;|\mathcal{F}|\le{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
We define a &#039;&#039;&#039;shift operator&#039;&#039;&#039; for the set family.&lt;br /&gt;
{{Theorem|Definition (shift operator)|&lt;br /&gt;
: Assume &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^{[n]}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;0\le i&amp;lt;j\le n-1&amp;lt;/math&amp;gt;. Define the &#039;&#039;&#039;&amp;lt;math&amp;gt;(i,j)&amp;lt;/math&amp;gt;-shift&#039;&#039;&#039; &amp;lt;math&amp;gt;S_{ij}&amp;lt;/math&amp;gt; as an operator on &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; as follows:&lt;br /&gt;
:*for each &amp;lt;math&amp;gt;T\in\mathcal{F}&amp;lt;/math&amp;gt;, write &amp;lt;math&amp;gt;T_{ij}=(T\setminus\{j\})\cup\{i\} &amp;lt;/math&amp;gt;, and let&lt;br /&gt;
::&amp;lt;math&amp;gt;S_{ij}(T)=&lt;br /&gt;
\begin{cases}&lt;br /&gt;
T_{ij} &amp;amp; \mbox{if }j\in T, i\not\in T, \mbox{ and }T_{ij} \not\in\mathcal{F},\\&lt;br /&gt;
T &amp;amp; \mbox{otherwise;}&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
:* let &amp;lt;math&amp;gt;S_{ij}(\mathcal{F})=\{S_{ij}(T)\mid T\in \mathcal{F}\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the following propositions of shifts.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
# &amp;lt;math&amp;gt;|S_{ij}(T)|=|T|\,&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|S_{ij}(\mathcal{F})|=\mathcal{F}&amp;lt;/math&amp;gt;;&lt;br /&gt;
# if &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is intersecting, then so is &amp;lt;math&amp;gt;S_{ij}(\mathcal{F})&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
(1) is immediate. Now we prove (2).&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;A,B\in\mathcal{F}&amp;lt;/math&amp;gt;. All the cases are easy to dealt with except when &amp;lt;math&amp;gt;A\cap B=\{j\}&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;i\in A&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;i\not\in B&amp;lt;/math&amp;gt;. Denote &amp;lt;math&amp;gt;A_{ij}=A\setminus\{j\}\cup\{i\}&amp;lt;/math&amp;gt;. It holds that &amp;lt;math&amp;gt;A_{ij}\cap B=(A\cap B)\setminus\{j\}=\emptyset&amp;lt;/math&amp;gt;. Since &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is intersecting, it must hold that &amp;lt;math&amp;gt;A_{ij}\not\in\mathcal{F}&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;S_{ij}(A)=A_{ij}&amp;lt;/math&amp;gt; and clearly &amp;lt;math&amp;gt;S_{ij}(B)=B_{ij}=B\setminus\{j\}\cup\{i\}&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;i\in S_{ij}(A)\cap S_{ij}(B)&amp;lt;/math&amp;gt; thus &amp;lt;math&amp;gt;S_{ij}(A)\cap S_{ij}(B)\neq \emptyset&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Repeatedly applying &amp;lt;math&amp;gt;S_{ij}(\mathcal{F})&amp;lt;/math&amp;gt; for any &amp;lt;math&amp;gt;0\le i&amp;lt;j\le n-1&amp;lt;/math&amp;gt;, since we only replace elements by smaller elements, eventually &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; will stop changing, that is, &amp;lt;math&amp;gt;S_{ij}(\mathcal{F})=\mathcal{F}&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;0\le i&amp;lt;j\le n-1&amp;lt;/math&amp;gt;. We call such an &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; &#039;&#039;&#039;shifted&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The idea behind the shifting technique is very natural: by applying shifting, all intersecting families are transformed to some &#039;&#039;special forms&#039;&#039;, and we only need to prove the theorem for these special form of intersecting families.&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Proof of Erdős-Ko-Rado theorem| (The original proof of Erdős-Ko-Rado by shifting)&lt;br /&gt;
By the above lemma, it is sufficient to prove the Erdős-Ko-Rado theorem holds for shifted &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt;. We assume that &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is shifted.&lt;br /&gt;
&lt;br /&gt;
First, it is trivial to see that the theorem holds for &amp;lt;math&amp;gt;k=1&amp;lt;/math&amp;gt; (no matter whether shifted).&lt;br /&gt;
&lt;br /&gt;
Next, we show that the theorem holds when &amp;lt;math&amp;gt;n=2k&amp;lt;/math&amp;gt;  (no matter whether shifted). For any &amp;lt;math&amp;gt;S\in{X\choose k}&amp;lt;/math&amp;gt;, both &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;X\setminus S&amp;lt;/math&amp;gt; are in &amp;lt;math&amp;gt;{X\choose k}&amp;lt;/math&amp;gt;, but at most one of them can be in &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;|\mathcal{F}|\le\frac{1}{2}{n\choose k}=\frac{n!}{2k!(n-k)!}=\frac{(n-1)!}{(k-1)!(n-k)!}={n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We then apply the induction on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. For &amp;lt;math&amp;gt;n&amp;gt; 2k&amp;lt;/math&amp;gt;, the induction hypothesis is stated as:&lt;br /&gt;
* the Erdős-Ko-Rado theorem holds for any smaller &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Define&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathcal{F}_0=\{S\in\mathcal{F}\mid n\not\in S\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\mathcal{F}_1=\{S\in\mathcal{F}\mid n\in S\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Clearly, &amp;lt;math&amp;gt;\mathcal{F}_0\subseteq{[n-1]\choose k}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\mathcal{F}_0&amp;lt;/math&amp;gt; is intersecting. Due to the induction hypothesis, &amp;lt;math&amp;gt;|\mathcal{F}_0|\le{n-2\choose k-1}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
In order to apply the induction, we let&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathcal{F}_1&#039;=\{S\setminus\{n\}\mid S\in\mathcal{F}_1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Clearly, &amp;lt;math&amp;gt;\mathcal{F}_1&#039;\subseteq{[n-1]\choose k-1}&amp;lt;/math&amp;gt;. If only it is also intersecting, we can apply the induction hypothesis, and indeed it is. To see this, by contradiction we assume that &amp;lt;math&amp;gt;\mathcal{F}_1&#039;&amp;lt;/math&amp;gt; is not intersecting. Then there must exist &amp;lt;math&amp;gt;A,B\in\mathcal{F}&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;A\cap B=\{n\}&amp;lt;/math&amp;gt;, which means that &amp;lt;math&amp;gt;|A\cup B|\le 2k-1&amp;lt;n-1&amp;lt;/math&amp;gt;. Thus, there is some &amp;lt;math&amp;gt;0\le i\le n-1&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;i\not\in A\cup B&amp;lt;/math&amp;gt;. Since &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is shifted, &amp;lt;math&amp;gt;A_{in}=A\setminus\{n\}\cup\{i\}\in\mathcal{F}&amp;lt;/math&amp;gt;. On the other hand it can be verified that &amp;lt;math&amp;gt;A_{in}\cap B=\emptyset&amp;lt;/math&amp;gt;, which contradicts that &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is intersecting. &lt;br /&gt;
&lt;br /&gt;
Thus, &amp;lt;math&amp;gt;\mathcal{F}_1&#039;\subseteq{[n-1]\choose k-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\mathcal{F}_1&#039;&amp;lt;/math&amp;gt; is intersecting. Due to the induction hypothesis, &amp;lt;math&amp;gt;|\mathcal{F}_1&#039;|\le{n-2\choose k-2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Combining these together,&lt;br /&gt;
:&amp;lt;math&amp;gt;|\mathcal{F}|=|\mathcal{F}_0|+|\mathcal{F}_1|=|\mathcal{F}_0|+|\mathcal{F}_1&#039;|\le {n-2\choose k-1}+{n-2\choose k-2}={n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
:(&#039;&#039;&#039;声明:&#039;&#039;&#039; 资料受版权保护, 仅用于教学.)&lt;br /&gt;
:(&#039;&#039;&#039;Disclaimer:&#039;&#039;&#039; The following copyrighted materials are meant for educational uses only.)&lt;br /&gt;
&lt;br /&gt;
* van Lin and Wilson. &#039;&#039;A course in combinatorics.&#039;&#039; Cambridge Press. Chapter 6.&lt;br /&gt;
* Aigner and Ziegler. &#039;&#039;Proofs from THE BOOK, 4th Edition.&#039;&#039; Springer-Verlag. [[media:PFTB_chap27.pdf| Chapter 27]].&lt;/div&gt;</summary>
		<author><name>172.21.15.93</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3518</id>
		<title>Combinatorics (Fall 2010)/Extremal graphs</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3518"/>
		<updated>2010-10-14T07:14:17Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.240: /* Erdős–Stone theorem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Extremal Graph Theory ==&lt;br /&gt;
&lt;br /&gt;
=== Mantel&#039;s theorem ===&lt;br /&gt;
We consider a typical extremal problem for graphs: the largest possible number of edges of &#039;&#039;&#039;triangle-free&#039;&#039;&#039; graphs, i.e. graphs contains no &amp;lt;math&amp;gt;K_3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Mantel 1907)|&lt;br /&gt;
:Suppose &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; is graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertice without triangles. Then &amp;lt;math&amp;gt;|E|\le\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (pigeonhole principle)|&lt;br /&gt;
We prove an equivalent theorem: Any &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|E|&amp;gt;\frac{n^2}{4}&amp;lt;/math&amp;gt; must have a triangle.&lt;br /&gt;
&lt;br /&gt;
Use induction on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The theorem holds trivially for &amp;lt;math&amp;gt;n\le 3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Induction hypothesis: assume the theorem hold for &amp;lt;math&amp;gt;|V|\le n-1&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices, without loss of generality, assume that &amp;lt;math&amp;gt;|E|=\frac{n^2}{4}+1&amp;lt;/math&amp;gt;, we will show that &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must contain a triangle. Take a &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; be the subgraph of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; induced by &amp;lt;math&amp;gt;V\setminus \{u,v\}&amp;lt;/math&amp;gt;. Clearly, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
:&#039;&#039;&#039;Case.1:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;&amp;gt;\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then by the induction hypothesis, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
:&#039;&#039;&#039;Case.2:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;\le\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then at least &amp;lt;math&amp;gt;\left(\frac{n^2}{4}+1\right)-\frac{(n-2)^2}{4}-1=n-1&amp;lt;/math&amp;gt; edges are between &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{u,v\}&amp;lt;/math&amp;gt;. By pigeonhole principle, there must be a vertex in &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; that is adjacent to both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
}} &lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (Cauchy-Schwarz inequality)|(Mantel&#039;s original proof)&lt;br /&gt;
For any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, no vertex can be a neighbor of both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, or otherwise there will be a triangle. Thus, for any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;d_u+d_v\le n&amp;lt;/math&amp;gt;. It follows that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)\le n|E|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Note that &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; appears exactly &amp;lt;math&amp;gt;d_v&amp;lt;/math&amp;gt; times in the sum, so that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)=\sum_{v\in V}d_v^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Applying Chauchy-Schwarz inequality,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
n|E|\ge\sum_{v\in V}d_v^2\ge\frac{\left(\sum_{v\in V}d_v\right)^2}{n}=\frac{4|E|^2}{n},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where the last equation is due to Euler&#039;s equality &amp;lt;math&amp;gt;\sum_{v\in V}d_v=2|E|&amp;lt;/math&amp;gt;. The theorem follows.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (inequality of the arithmetic and geometric mean)|&lt;br /&gt;
Assume that &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; vertices and is triangle-free.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be the largest independent set in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\alpha=|A|&amp;lt;/math&amp;gt;. &lt;br /&gt;
Since &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is triangle-free, for very vertex &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, all its neighbors must form an independent set, thus &amp;lt;math&amp;gt;d(v)\le \alpha&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Take &amp;lt;math&amp;gt;B=V\setminus A&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\beta=|B|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Since &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is an independent set, all edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; must have at least one endpoint in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;. Counting the edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; according to their endpoints in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;, we obtain &amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v&amp;lt;/math&amp;gt;. By the inequality of the arithmetic and geometric mean,&lt;br /&gt;
:&amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v\le\alpha\beta\le\left(\frac{\alpha+\beta}{2}\right)^2=\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Turán&#039;s theorem ===&lt;br /&gt;
{{Theorem|Theorem (Turán 1941)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a graph with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, &amp;lt;math&amp;gt;k\ge 2&amp;lt;/math&amp;gt;, then&lt;br /&gt;
::&amp;lt;math&amp;gt;|E|\le\frac{r-2}{2(r-1)}n^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (induction)|(Turán&#039;s original proof)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (weight shifting)|(due to Motzkin and Straus)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (the probabilistic method)|(due to Alon and Spencer)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Fourth proof.|&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with a maximum number of edges.&lt;br /&gt;
:&#039;&#039;&#039;Claim:&#039;&#039;&#039; &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; does not contain three vertices &amp;lt;math&amp;gt;u,v,w&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; but &amp;lt;math&amp;gt;uw\not\in E, vw\not\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
Suppose otherwise. There are two cases.&lt;br /&gt;
* &#039;&#039;&#039;Case.1:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;d(w)&amp;lt;d(v)&amp;lt;/math&amp;gt;. Without loss of generality, suppose that &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt;. We duplicate &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; by creating a new vertex &amp;lt;math&amp;gt;u&#039;&amp;lt;/math&amp;gt; which has exactly the same neighbors as &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; (but &amp;lt;math&amp;gt;uu&#039;&amp;lt;/math&amp;gt; is not an edge). Such duplication will not increase the clique size. We then remove &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;. The resulting graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is still &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free, and has &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices. The number of edges in &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+d(u)-d(w)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
:which contradicts the assumption that &amp;lt;math&amp;gt;|E(G)|&amp;lt;/math&amp;gt; is maximal.&lt;br /&gt;
* &#039;&#039;&#039;Case.2:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)\ge d(u)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;d(w)\ge d(v)&amp;lt;/math&amp;gt;. Duplicate &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; twice and delete &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. The new graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, and the number of edges is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+2d(w)-(d(u)+d(v)+1)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Contradiction again.&lt;br /&gt;
&lt;br /&gt;
The claim implies that &amp;lt;math&amp;gt;uv\not\in E&amp;lt;/math&amp;gt; defines an equivalence relation on vertices (to be more precise, it guarantees the transitivity of the relation, while the reflexivity and symmetry hold directly). Graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must be a complete multipartite graph &amp;lt;math&amp;gt;K_{n_1,n_2,\ldots,n_{r-1}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n_1+n_2+\cdots +n_{r-1}=n&amp;lt;/math&amp;gt;. Optimize the edge number, we have the Turán graph.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Erdős–Stone theorem ===&lt;br /&gt;
Let &amp;lt;math&amp;gt;K_s^r=K_{\underbrace{s,s,\cdots,s}_{r}}&amp;lt;/math&amp;gt; be the complete &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-partite graph with &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; vertices in each class, i.e., the Turán graph &amp;lt;math&amp;gt;T(rs,r)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Fundamental theorem of extremal graph theory (Erdős–Stone 1946)|&lt;br /&gt;
:For any integers &amp;lt;math&amp;gt;r\ge 2&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;s\ge 1&amp;lt;/math&amp;gt;, and any &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt;, if &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is sufficiently large then every graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices and with at least &amp;lt;math&amp;gt;\left(\frac{r-2}{2(r-1)}+\epsilon\right)n^2&amp;lt;/math&amp;gt; edges contains &amp;lt;math&amp;gt;K_{r,s}&amp;lt;/math&amp;gt; as a subgraph, i.e.,&lt;br /&gt;
:::&amp;lt;math&amp;gt;\mathrm{ex}(n,K_s^r)= \left(\frac{r-2}{2(r-1)}+o(1)\right)n^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Corollary|&lt;br /&gt;
:For every nonempty graph &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;\lim_{n\rightarrow\infty}\frac{\mathrm{ex}(n,H)}{{n\choose 2}}=\frac{\chi(H)-2}{\chi(H)-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Cycle Structures ==&lt;br /&gt;
=== Girth ===&lt;br /&gt;
&lt;br /&gt;
=== Hamiltonian cycle ===&lt;/div&gt;</summary>
		<author><name>172.21.1.240</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3517</id>
		<title>Combinatorics (Fall 2010)/Extremal graphs</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3517"/>
		<updated>2010-10-14T07:04:04Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.240: /* Erdős–Stone theorem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Extremal Graph Theory ==&lt;br /&gt;
&lt;br /&gt;
=== Mantel&#039;s theorem ===&lt;br /&gt;
We consider a typical extremal problem for graphs: the largest possible number of edges of &#039;&#039;&#039;triangle-free&#039;&#039;&#039; graphs, i.e. graphs contains no &amp;lt;math&amp;gt;K_3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Mantel 1907)|&lt;br /&gt;
:Suppose &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; is graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertice without triangles. Then &amp;lt;math&amp;gt;|E|\le\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (pigeonhole principle)|&lt;br /&gt;
We prove an equivalent theorem: Any &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|E|&amp;gt;\frac{n^2}{4}&amp;lt;/math&amp;gt; must have a triangle.&lt;br /&gt;
&lt;br /&gt;
Use induction on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The theorem holds trivially for &amp;lt;math&amp;gt;n\le 3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Induction hypothesis: assume the theorem hold for &amp;lt;math&amp;gt;|V|\le n-1&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices, without loss of generality, assume that &amp;lt;math&amp;gt;|E|=\frac{n^2}{4}+1&amp;lt;/math&amp;gt;, we will show that &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must contain a triangle. Take a &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; be the subgraph of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; induced by &amp;lt;math&amp;gt;V\setminus \{u,v\}&amp;lt;/math&amp;gt;. Clearly, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
:&#039;&#039;&#039;Case.1:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;&amp;gt;\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then by the induction hypothesis, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
:&#039;&#039;&#039;Case.2:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;\le\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then at least &amp;lt;math&amp;gt;\left(\frac{n^2}{4}+1\right)-\frac{(n-2)^2}{4}-1=n-1&amp;lt;/math&amp;gt; edges are between &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{u,v\}&amp;lt;/math&amp;gt;. By pigeonhole principle, there must be a vertex in &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; that is adjacent to both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
}} &lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (Cauchy-Schwarz inequality)|(Mantel&#039;s original proof)&lt;br /&gt;
For any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, no vertex can be a neighbor of both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, or otherwise there will be a triangle. Thus, for any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;d_u+d_v\le n&amp;lt;/math&amp;gt;. It follows that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)\le n|E|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Note that &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; appears exactly &amp;lt;math&amp;gt;d_v&amp;lt;/math&amp;gt; times in the sum, so that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)=\sum_{v\in V}d_v^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Applying Chauchy-Schwarz inequality,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
n|E|\ge\sum_{v\in V}d_v^2\ge\frac{\left(\sum_{v\in V}d_v\right)^2}{n}=\frac{4|E|^2}{n},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where the last equation is due to Euler&#039;s equality &amp;lt;math&amp;gt;\sum_{v\in V}d_v=2|E|&amp;lt;/math&amp;gt;. The theorem follows.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (inequality of the arithmetic and geometric mean)|&lt;br /&gt;
Assume that &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; vertices and is triangle-free.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be the largest independent set in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\alpha=|A|&amp;lt;/math&amp;gt;. &lt;br /&gt;
Since &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is triangle-free, for very vertex &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, all its neighbors must form an independent set, thus &amp;lt;math&amp;gt;d(v)\le \alpha&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Take &amp;lt;math&amp;gt;B=V\setminus A&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\beta=|B|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Since &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is an independent set, all edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; must have at least one endpoint in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;. Counting the edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; according to their endpoints in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;, we obtain &amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v&amp;lt;/math&amp;gt;. By the inequality of the arithmetic and geometric mean,&lt;br /&gt;
:&amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v\le\alpha\beta\le\left(\frac{\alpha+\beta}{2}\right)^2=\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Turán&#039;s theorem ===&lt;br /&gt;
{{Theorem|Theorem (Turán 1941)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a graph with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, &amp;lt;math&amp;gt;k\ge 2&amp;lt;/math&amp;gt;, then&lt;br /&gt;
::&amp;lt;math&amp;gt;|E|\le\frac{r-2}{2(r-1)}n^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (induction)|(Turán&#039;s original proof)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (weight shifting)|(due to Motzkin and Straus)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (the probabilistic method)|(due to Alon and Spencer)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Fourth proof.|&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with a maximum number of edges.&lt;br /&gt;
:&#039;&#039;&#039;Claim:&#039;&#039;&#039; &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; does not contain three vertices &amp;lt;math&amp;gt;u,v,w&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; but &amp;lt;math&amp;gt;uw\not\in E, vw\not\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
Suppose otherwise. There are two cases.&lt;br /&gt;
* &#039;&#039;&#039;Case.1:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;d(w)&amp;lt;d(v)&amp;lt;/math&amp;gt;. Without loss of generality, suppose that &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt;. We duplicate &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; by creating a new vertex &amp;lt;math&amp;gt;u&#039;&amp;lt;/math&amp;gt; which has exactly the same neighbors as &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; (but &amp;lt;math&amp;gt;uu&#039;&amp;lt;/math&amp;gt; is not an edge). Such duplication will not increase the clique size. We then remove &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;. The resulting graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is still &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free, and has &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices. The number of edges in &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+d(u)-d(w)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
:which contradicts the assumption that &amp;lt;math&amp;gt;|E(G)|&amp;lt;/math&amp;gt; is maximal.&lt;br /&gt;
* &#039;&#039;&#039;Case.2:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)\ge d(u)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;d(w)\ge d(v)&amp;lt;/math&amp;gt;. Duplicate &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; twice and delete &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. The new graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, and the number of edges is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+2d(w)-(d(u)+d(v)+1)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Contradiction again.&lt;br /&gt;
&lt;br /&gt;
The claim implies that &amp;lt;math&amp;gt;uv\not\in E&amp;lt;/math&amp;gt; defines an equivalence relation on vertices (to be more precise, it guarantees the transitivity of the relation, while the reflexivity and symmetry hold directly). Graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must be a complete multipartite graph &amp;lt;math&amp;gt;K_{n_1,n_2,\ldots,n_{r-1}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n_1+n_2+\cdots +n_{r-1}=n&amp;lt;/math&amp;gt;. Optimize the edge number, we have the Turán graph.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Erdős–Stone theorem ===&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Fundamental theorem of extremal graph theory (Erdős–Stone 1946)|&lt;br /&gt;
:For any integers &amp;lt;math&amp;gt;r\ge 2&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;s\ge 1&amp;lt;/math&amp;gt;, and any &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt;, if &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is sufficiently large then every graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices and with at least &amp;lt;math&amp;gt;\left(\frac{r-2}{2(r-1)}+\epsilon\right)n^2&amp;lt;/math&amp;gt; edges contains &amp;lt;math&amp;gt;K_{r,s}&amp;lt;/math&amp;gt; as a subgraph, i.e.,&lt;br /&gt;
:::&amp;lt;math&amp;gt;\mathrm{ex}(n,K_{r,s})= \left(\frac{r-2}{2(r-1)}+o(1)\right)n^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Corollary|&lt;br /&gt;
:For every nonempty graph &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;\lim_{n\rightarrow\infty}\frac{\mathrm{ex}(n,H)}{{n\choose 2}}=\frac{\chi(H)-2}{\chi(H)-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Cycle Structures ==&lt;br /&gt;
=== Girth ===&lt;br /&gt;
&lt;br /&gt;
=== Hamiltonian cycle ===&lt;/div&gt;</summary>
		<author><name>172.21.1.240</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3516</id>
		<title>Combinatorics (Fall 2010)/Extremal graphs</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3516"/>
		<updated>2010-10-14T07:00:05Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.240: /* Erdős–Stone theorem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Extremal Graph Theory ==&lt;br /&gt;
&lt;br /&gt;
=== Mantel&#039;s theorem ===&lt;br /&gt;
We consider a typical extremal problem for graphs: the largest possible number of edges of &#039;&#039;&#039;triangle-free&#039;&#039;&#039; graphs, i.e. graphs contains no &amp;lt;math&amp;gt;K_3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Mantel 1907)|&lt;br /&gt;
:Suppose &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; is graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertice without triangles. Then &amp;lt;math&amp;gt;|E|\le\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (pigeonhole principle)|&lt;br /&gt;
We prove an equivalent theorem: Any &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|E|&amp;gt;\frac{n^2}{4}&amp;lt;/math&amp;gt; must have a triangle.&lt;br /&gt;
&lt;br /&gt;
Use induction on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The theorem holds trivially for &amp;lt;math&amp;gt;n\le 3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Induction hypothesis: assume the theorem hold for &amp;lt;math&amp;gt;|V|\le n-1&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices, without loss of generality, assume that &amp;lt;math&amp;gt;|E|=\frac{n^2}{4}+1&amp;lt;/math&amp;gt;, we will show that &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must contain a triangle. Take a &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; be the subgraph of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; induced by &amp;lt;math&amp;gt;V\setminus \{u,v\}&amp;lt;/math&amp;gt;. Clearly, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
:&#039;&#039;&#039;Case.1:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;&amp;gt;\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then by the induction hypothesis, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
:&#039;&#039;&#039;Case.2:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;\le\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then at least &amp;lt;math&amp;gt;\left(\frac{n^2}{4}+1\right)-\frac{(n-2)^2}{4}-1=n-1&amp;lt;/math&amp;gt; edges are between &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{u,v\}&amp;lt;/math&amp;gt;. By pigeonhole principle, there must be a vertex in &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; that is adjacent to both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
}} &lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (Cauchy-Schwarz inequality)|(Mantel&#039;s original proof)&lt;br /&gt;
For any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, no vertex can be a neighbor of both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, or otherwise there will be a triangle. Thus, for any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;d_u+d_v\le n&amp;lt;/math&amp;gt;. It follows that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)\le n|E|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Note that &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; appears exactly &amp;lt;math&amp;gt;d_v&amp;lt;/math&amp;gt; times in the sum, so that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)=\sum_{v\in V}d_v^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Applying Chauchy-Schwarz inequality,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
n|E|\ge\sum_{v\in V}d_v^2\ge\frac{\left(\sum_{v\in V}d_v\right)^2}{n}=\frac{4|E|^2}{n},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where the last equation is due to Euler&#039;s equality &amp;lt;math&amp;gt;\sum_{v\in V}d_v=2|E|&amp;lt;/math&amp;gt;. The theorem follows.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (inequality of the arithmetic and geometric mean)|&lt;br /&gt;
Assume that &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; vertices and is triangle-free.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be the largest independent set in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\alpha=|A|&amp;lt;/math&amp;gt;. &lt;br /&gt;
Since &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is triangle-free, for very vertex &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, all its neighbors must form an independent set, thus &amp;lt;math&amp;gt;d(v)\le \alpha&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Take &amp;lt;math&amp;gt;B=V\setminus A&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\beta=|B|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Since &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is an independent set, all edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; must have at least one endpoint in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;. Counting the edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; according to their endpoints in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;, we obtain &amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v&amp;lt;/math&amp;gt;. By the inequality of the arithmetic and geometric mean,&lt;br /&gt;
:&amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v\le\alpha\beta\le\left(\frac{\alpha+\beta}{2}\right)^2=\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Turán&#039;s theorem ===&lt;br /&gt;
{{Theorem|Theorem (Turán 1941)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a graph with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, &amp;lt;math&amp;gt;k\ge 2&amp;lt;/math&amp;gt;, then&lt;br /&gt;
::&amp;lt;math&amp;gt;|E|\le\frac{r-2}{2(r-1)}n^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (induction)|(Turán&#039;s original proof)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (weight shifting)|(due to Motzkin and Straus)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (the probabilistic method)|(due to Alon and Spencer)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Fourth proof.|&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with a maximum number of edges.&lt;br /&gt;
:&#039;&#039;&#039;Claim:&#039;&#039;&#039; &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; does not contain three vertices &amp;lt;math&amp;gt;u,v,w&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; but &amp;lt;math&amp;gt;uw\not\in E, vw\not\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
Suppose otherwise. There are two cases.&lt;br /&gt;
* &#039;&#039;&#039;Case.1:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;d(w)&amp;lt;d(v)&amp;lt;/math&amp;gt;. Without loss of generality, suppose that &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt;. We duplicate &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; by creating a new vertex &amp;lt;math&amp;gt;u&#039;&amp;lt;/math&amp;gt; which has exactly the same neighbors as &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; (but &amp;lt;math&amp;gt;uu&#039;&amp;lt;/math&amp;gt; is not an edge). Such duplication will not increase the clique size. We then remove &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;. The resulting graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is still &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free, and has &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices. The number of edges in &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+d(u)-d(w)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
:which contradicts the assumption that &amp;lt;math&amp;gt;|E(G)|&amp;lt;/math&amp;gt; is maximal.&lt;br /&gt;
* &#039;&#039;&#039;Case.2:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)\ge d(u)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;d(w)\ge d(v)&amp;lt;/math&amp;gt;. Duplicate &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; twice and delete &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. The new graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, and the number of edges is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+2d(w)-(d(u)+d(v)+1)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Contradiction again.&lt;br /&gt;
&lt;br /&gt;
The claim implies that &amp;lt;math&amp;gt;uv\not\in E&amp;lt;/math&amp;gt; defines an equivalence relation on vertices (to be more precise, it guarantees the transitivity of the relation, while the reflexivity and symmetry hold directly). Graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must be a complete multipartite graph &amp;lt;math&amp;gt;K_{n_1,n_2,\ldots,n_{r-1}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n_1+n_2+\cdots +n_{r-1}=n&amp;lt;/math&amp;gt;. Optimize the edge number, we have the Turán graph.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Erdős–Stone theorem ===&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Fundamental theorem of extremal graph theory (Erdős–Stone 1946)|&lt;br /&gt;
:For any integers &amp;lt;math&amp;gt;r\ge 2&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;s\ge 1&amp;lt;/math&amp;gt;, and any &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt;, there exists an &amp;lt;math&amp;gt;N_0&amp;lt;/math&amp;gt; such that every graph with &amp;lt;math&amp;gt;n\ge N_0&amp;lt;/math&amp;gt; vertices and at least &amp;lt;math&amp;gt;\left(\frac{r-2}{2(r-1)}+\epsilon\right)n^2&amp;lt;/math&amp;gt; edges contains &amp;lt;math&amp;gt;K_{r,s}&amp;lt;/math&amp;gt; as a subgraph, i.e.,&lt;br /&gt;
:::&amp;lt;math&amp;gt;\mathrm{ex}(n,K_{r,s})= \left(\frac{r-2}{2(r-1)}+o(1)\right)n^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Corollary|&lt;br /&gt;
:For every nonempty graph &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;\lim_{n\rightarrow\infty}\frac{\mathrm{ex}(n,H)}{{n\choose 2}}=\frac{\chi(H)-2}{\chi(H)-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Cycle Structures ==&lt;br /&gt;
=== Girth ===&lt;br /&gt;
&lt;br /&gt;
=== Hamiltonian cycle ===&lt;/div&gt;</summary>
		<author><name>172.21.1.240</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3515</id>
		<title>Combinatorics (Fall 2010)/Extremal graphs</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3515"/>
		<updated>2010-10-14T06:59:33Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.240: /* Erdős–Stone theorem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Extremal Graph Theory ==&lt;br /&gt;
&lt;br /&gt;
=== Mantel&#039;s theorem ===&lt;br /&gt;
We consider a typical extremal problem for graphs: the largest possible number of edges of &#039;&#039;&#039;triangle-free&#039;&#039;&#039; graphs, i.e. graphs contains no &amp;lt;math&amp;gt;K_3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Mantel 1907)|&lt;br /&gt;
:Suppose &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; is graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertice without triangles. Then &amp;lt;math&amp;gt;|E|\le\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (pigeonhole principle)|&lt;br /&gt;
We prove an equivalent theorem: Any &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|E|&amp;gt;\frac{n^2}{4}&amp;lt;/math&amp;gt; must have a triangle.&lt;br /&gt;
&lt;br /&gt;
Use induction on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The theorem holds trivially for &amp;lt;math&amp;gt;n\le 3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Induction hypothesis: assume the theorem hold for &amp;lt;math&amp;gt;|V|\le n-1&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices, without loss of generality, assume that &amp;lt;math&amp;gt;|E|=\frac{n^2}{4}+1&amp;lt;/math&amp;gt;, we will show that &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must contain a triangle. Take a &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; be the subgraph of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; induced by &amp;lt;math&amp;gt;V\setminus \{u,v\}&amp;lt;/math&amp;gt;. Clearly, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
:&#039;&#039;&#039;Case.1:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;&amp;gt;\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then by the induction hypothesis, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
:&#039;&#039;&#039;Case.2:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;\le\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then at least &amp;lt;math&amp;gt;\left(\frac{n^2}{4}+1\right)-\frac{(n-2)^2}{4}-1=n-1&amp;lt;/math&amp;gt; edges are between &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{u,v\}&amp;lt;/math&amp;gt;. By pigeonhole principle, there must be a vertex in &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; that is adjacent to both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
}} &lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (Cauchy-Schwarz inequality)|(Mantel&#039;s original proof)&lt;br /&gt;
For any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, no vertex can be a neighbor of both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, or otherwise there will be a triangle. Thus, for any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;d_u+d_v\le n&amp;lt;/math&amp;gt;. It follows that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)\le n|E|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Note that &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; appears exactly &amp;lt;math&amp;gt;d_v&amp;lt;/math&amp;gt; times in the sum, so that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)=\sum_{v\in V}d_v^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Applying Chauchy-Schwarz inequality,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
n|E|\ge\sum_{v\in V}d_v^2\ge\frac{\left(\sum_{v\in V}d_v\right)^2}{n}=\frac{4|E|^2}{n},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where the last equation is due to Euler&#039;s equality &amp;lt;math&amp;gt;\sum_{v\in V}d_v=2|E|&amp;lt;/math&amp;gt;. The theorem follows.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (inequality of the arithmetic and geometric mean)|&lt;br /&gt;
Assume that &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; vertices and is triangle-free.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be the largest independent set in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\alpha=|A|&amp;lt;/math&amp;gt;. &lt;br /&gt;
Since &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is triangle-free, for very vertex &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, all its neighbors must form an independent set, thus &amp;lt;math&amp;gt;d(v)\le \alpha&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Take &amp;lt;math&amp;gt;B=V\setminus A&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\beta=|B|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Since &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is an independent set, all edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; must have at least one endpoint in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;. Counting the edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; according to their endpoints in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;, we obtain &amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v&amp;lt;/math&amp;gt;. By the inequality of the arithmetic and geometric mean,&lt;br /&gt;
:&amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v\le\alpha\beta\le\left(\frac{\alpha+\beta}{2}\right)^2=\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Turán&#039;s theorem ===&lt;br /&gt;
{{Theorem|Theorem (Turán 1941)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a graph with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, &amp;lt;math&amp;gt;k\ge 2&amp;lt;/math&amp;gt;, then&lt;br /&gt;
::&amp;lt;math&amp;gt;|E|\le\frac{r-2}{2(r-1)}n^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (induction)|(Turán&#039;s original proof)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (weight shifting)|(due to Motzkin and Straus)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (the probabilistic method)|(due to Alon and Spencer)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Fourth proof.|&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with a maximum number of edges.&lt;br /&gt;
:&#039;&#039;&#039;Claim:&#039;&#039;&#039; &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; does not contain three vertices &amp;lt;math&amp;gt;u,v,w&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; but &amp;lt;math&amp;gt;uw\not\in E, vw\not\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
Suppose otherwise. There are two cases.&lt;br /&gt;
* &#039;&#039;&#039;Case.1:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;d(w)&amp;lt;d(v)&amp;lt;/math&amp;gt;. Without loss of generality, suppose that &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt;. We duplicate &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; by creating a new vertex &amp;lt;math&amp;gt;u&#039;&amp;lt;/math&amp;gt; which has exactly the same neighbors as &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; (but &amp;lt;math&amp;gt;uu&#039;&amp;lt;/math&amp;gt; is not an edge). Such duplication will not increase the clique size. We then remove &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;. The resulting graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is still &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free, and has &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices. The number of edges in &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+d(u)-d(w)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
:which contradicts the assumption that &amp;lt;math&amp;gt;|E(G)|&amp;lt;/math&amp;gt; is maximal.&lt;br /&gt;
* &#039;&#039;&#039;Case.2:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)\ge d(u)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;d(w)\ge d(v)&amp;lt;/math&amp;gt;. Duplicate &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; twice and delete &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. The new graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, and the number of edges is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+2d(w)-(d(u)+d(v)+1)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Contradiction again.&lt;br /&gt;
&lt;br /&gt;
The claim implies that &amp;lt;math&amp;gt;uv\not\in E&amp;lt;/math&amp;gt; defines an equivalence relation on vertices (to be more precise, it guarantees the transitivity of the relation, while the reflexivity and symmetry hold directly). Graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must be a complete multipartite graph &amp;lt;math&amp;gt;K_{n_1,n_2,\ldots,n_{r-1}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n_1+n_2+\cdots +n_{r-1}=n&amp;lt;/math&amp;gt;. Optimize the edge number, we have the Turán graph.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Erdős–Stone theorem ===&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Fundamental theorem of extremal graph theory (Erdős–Stone 1946)|&lt;br /&gt;
:For any integers &amp;lt;math&amp;gt;r\ge 2&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;s\ge 1&amp;lt;/math&amp;gt;, and any &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt;, there exists an &amp;lt;math&amp;gt;N_0&amp;lt;/math&amp;gt; such that every graph with &amp;lt;math&amp;gt;n\ge N_0&amp;lt;/math&amp;gt; vertices and at least &amp;lt;math&amp;gt;\left(\frac{r-2}{2(r-1)}+\epsilon\right)n^2&amp;lt;/math&amp;gt; edges contains &amp;lt;math&amp;gt;K_{r,s}&amp;lt;/math&amp;gt; as a subgraph, i.e.,&lt;br /&gt;
:::&amp;lt;math&amp;gt;\mathrm{ex}(n,K_{s,r})= \left(\frac{r-2}{2(r-1)}+o(1)\right)n^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Corollary|&lt;br /&gt;
:For every nonempty graph &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;\lim_{n\rightarrow\infty}\frac{\mathrm{ex}(n,H)}{{n\choose 2}}=\frac{\chi(H)-2}{\chi(H)-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Cycle Structures ==&lt;br /&gt;
=== Girth ===&lt;br /&gt;
&lt;br /&gt;
=== Hamiltonian cycle ===&lt;/div&gt;</summary>
		<author><name>172.21.1.240</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3514</id>
		<title>Combinatorics (Fall 2010)/Extremal graphs</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3514"/>
		<updated>2010-10-14T06:58:37Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.240: /* Erdős–Stone theorem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Extremal Graph Theory ==&lt;br /&gt;
&lt;br /&gt;
=== Mantel&#039;s theorem ===&lt;br /&gt;
We consider a typical extremal problem for graphs: the largest possible number of edges of &#039;&#039;&#039;triangle-free&#039;&#039;&#039; graphs, i.e. graphs contains no &amp;lt;math&amp;gt;K_3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Mantel 1907)|&lt;br /&gt;
:Suppose &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; is graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertice without triangles. Then &amp;lt;math&amp;gt;|E|\le\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (pigeonhole principle)|&lt;br /&gt;
We prove an equivalent theorem: Any &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|E|&amp;gt;\frac{n^2}{4}&amp;lt;/math&amp;gt; must have a triangle.&lt;br /&gt;
&lt;br /&gt;
Use induction on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The theorem holds trivially for &amp;lt;math&amp;gt;n\le 3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Induction hypothesis: assume the theorem hold for &amp;lt;math&amp;gt;|V|\le n-1&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices, without loss of generality, assume that &amp;lt;math&amp;gt;|E|=\frac{n^2}{4}+1&amp;lt;/math&amp;gt;, we will show that &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must contain a triangle. Take a &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; be the subgraph of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; induced by &amp;lt;math&amp;gt;V\setminus \{u,v\}&amp;lt;/math&amp;gt;. Clearly, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
:&#039;&#039;&#039;Case.1:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;&amp;gt;\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then by the induction hypothesis, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
:&#039;&#039;&#039;Case.2:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;\le\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then at least &amp;lt;math&amp;gt;\left(\frac{n^2}{4}+1\right)-\frac{(n-2)^2}{4}-1=n-1&amp;lt;/math&amp;gt; edges are between &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{u,v\}&amp;lt;/math&amp;gt;. By pigeonhole principle, there must be a vertex in &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; that is adjacent to both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
}} &lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (Cauchy-Schwarz inequality)|(Mantel&#039;s original proof)&lt;br /&gt;
For any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, no vertex can be a neighbor of both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, or otherwise there will be a triangle. Thus, for any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;d_u+d_v\le n&amp;lt;/math&amp;gt;. It follows that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)\le n|E|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Note that &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; appears exactly &amp;lt;math&amp;gt;d_v&amp;lt;/math&amp;gt; times in the sum, so that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)=\sum_{v\in V}d_v^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Applying Chauchy-Schwarz inequality,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
n|E|\ge\sum_{v\in V}d_v^2\ge\frac{\left(\sum_{v\in V}d_v\right)^2}{n}=\frac{4|E|^2}{n},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where the last equation is due to Euler&#039;s equality &amp;lt;math&amp;gt;\sum_{v\in V}d_v=2|E|&amp;lt;/math&amp;gt;. The theorem follows.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (inequality of the arithmetic and geometric mean)|&lt;br /&gt;
Assume that &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; vertices and is triangle-free.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be the largest independent set in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\alpha=|A|&amp;lt;/math&amp;gt;. &lt;br /&gt;
Since &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is triangle-free, for very vertex &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, all its neighbors must form an independent set, thus &amp;lt;math&amp;gt;d(v)\le \alpha&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Take &amp;lt;math&amp;gt;B=V\setminus A&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\beta=|B|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Since &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is an independent set, all edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; must have at least one endpoint in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;. Counting the edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; according to their endpoints in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;, we obtain &amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v&amp;lt;/math&amp;gt;. By the inequality of the arithmetic and geometric mean,&lt;br /&gt;
:&amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v\le\alpha\beta\le\left(\frac{\alpha+\beta}{2}\right)^2=\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Turán&#039;s theorem ===&lt;br /&gt;
{{Theorem|Theorem (Turán 1941)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a graph with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, &amp;lt;math&amp;gt;k\ge 2&amp;lt;/math&amp;gt;, then&lt;br /&gt;
::&amp;lt;math&amp;gt;|E|\le\frac{r-2}{2(r-1)}n^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (induction)|(Turán&#039;s original proof)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (weight shifting)|(due to Motzkin and Straus)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (the probabilistic method)|(due to Alon and Spencer)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Fourth proof.|&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with a maximum number of edges.&lt;br /&gt;
:&#039;&#039;&#039;Claim:&#039;&#039;&#039; &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; does not contain three vertices &amp;lt;math&amp;gt;u,v,w&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; but &amp;lt;math&amp;gt;uw\not\in E, vw\not\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
Suppose otherwise. There are two cases.&lt;br /&gt;
* &#039;&#039;&#039;Case.1:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;d(w)&amp;lt;d(v)&amp;lt;/math&amp;gt;. Without loss of generality, suppose that &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt;. We duplicate &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; by creating a new vertex &amp;lt;math&amp;gt;u&#039;&amp;lt;/math&amp;gt; which has exactly the same neighbors as &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; (but &amp;lt;math&amp;gt;uu&#039;&amp;lt;/math&amp;gt; is not an edge). Such duplication will not increase the clique size. We then remove &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;. The resulting graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is still &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free, and has &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices. The number of edges in &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+d(u)-d(w)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
:which contradicts the assumption that &amp;lt;math&amp;gt;|E(G)|&amp;lt;/math&amp;gt; is maximal.&lt;br /&gt;
* &#039;&#039;&#039;Case.2:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)\ge d(u)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;d(w)\ge d(v)&amp;lt;/math&amp;gt;. Duplicate &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; twice and delete &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. The new graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, and the number of edges is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+2d(w)-(d(u)+d(v)+1)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Contradiction again.&lt;br /&gt;
&lt;br /&gt;
The claim implies that &amp;lt;math&amp;gt;uv\not\in E&amp;lt;/math&amp;gt; defines an equivalence relation on vertices (to be more precise, it guarantees the transitivity of the relation, while the reflexivity and symmetry hold directly). Graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must be a complete multipartite graph &amp;lt;math&amp;gt;K_{n_1,n_2,\ldots,n_{r-1}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n_1+n_2+\cdots +n_{r-1}=n&amp;lt;/math&amp;gt;. Optimize the edge number, we have the Turán graph.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Erdős–Stone theorem ===&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Fundamental theorem of extremal graph theory (Erdős–Stone 1946)|&lt;br /&gt;
:For any integers &amp;lt;math&amp;gt;r\ge 2&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;s\ge 1&amp;lt;/math&amp;gt;, and any &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt;, there exists an &amp;lt;math&amp;gt;N_0&amp;lt;/math&amp;gt; such that every graph with &amp;lt;math&amp;gt;n\ge N_0&amp;lt;/math&amp;gt; vertices and at least &amp;lt;math&amp;gt;\left(\frac{r-2}{2(r-1)}+\epsilon\right)n^2&amp;lt;/math&amp;gt; edges contains &amp;lt;math&amp;gt;K_{r,s}&amp;lt;/math&amp;gt; as a subgraph, i.e.,&lt;br /&gt;
:::&amp;lt;math&amp;gt;\mathrm{ex}(n,K_{s,r})\le \left(\frac{r-2}{2(r-1)}+o(1)\right)n^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Corollary|&lt;br /&gt;
:For every nonempty graph &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;\lim_{n\rightarrow\infty}\frac{\mathrm{ex}(n,H)}{{n\choose 2}}=\frac{\chi(H)-2}{\chi(H)-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Cycle Structures ==&lt;br /&gt;
=== Girth ===&lt;br /&gt;
&lt;br /&gt;
=== Hamiltonian cycle ===&lt;/div&gt;</summary>
		<author><name>172.21.1.240</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3513</id>
		<title>Combinatorics (Fall 2010)/Extremal graphs</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_graphs&amp;diff=3513"/>
		<updated>2010-10-14T06:50:52Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.240: /* Erdős–Stone theorem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Extremal Graph Theory ==&lt;br /&gt;
&lt;br /&gt;
=== Mantel&#039;s theorem ===&lt;br /&gt;
We consider a typical extremal problem for graphs: the largest possible number of edges of &#039;&#039;&#039;triangle-free&#039;&#039;&#039; graphs, i.e. graphs contains no &amp;lt;math&amp;gt;K_3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Mantel 1907)|&lt;br /&gt;
:Suppose &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; is graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertice without triangles. Then &amp;lt;math&amp;gt;|E|\le\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (pigeonhole principle)|&lt;br /&gt;
We prove an equivalent theorem: Any &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|E|&amp;gt;\frac{n^2}{4}&amp;lt;/math&amp;gt; must have a triangle.&lt;br /&gt;
&lt;br /&gt;
Use induction on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The theorem holds trivially for &amp;lt;math&amp;gt;n\le 3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Induction hypothesis: assume the theorem hold for &amp;lt;math&amp;gt;|V|\le n-1&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices, without loss of generality, assume that &amp;lt;math&amp;gt;|E|=\frac{n^2}{4}+1&amp;lt;/math&amp;gt;, we will show that &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must contain a triangle. Take a &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; be the subgraph of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; induced by &amp;lt;math&amp;gt;V\setminus \{u,v\}&amp;lt;/math&amp;gt;. Clearly, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
:&#039;&#039;&#039;Case.1:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;&amp;gt;\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then by the induction hypothesis, &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
:&#039;&#039;&#039;Case.2:&#039;&#039;&#039; If &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;\le\frac{(n-2)^2}{4}&amp;lt;/math&amp;gt; edges, then at least &amp;lt;math&amp;gt;\left(\frac{n^2}{4}+1\right)-\frac{(n-2)^2}{4}-1=n-1&amp;lt;/math&amp;gt; edges are between &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{u,v\}&amp;lt;/math&amp;gt;. By pigeonhole principle, there must be a vertex in &amp;lt;math&amp;gt;H&amp;lt;/math&amp;gt; that is adjacent to both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has a triangle.&lt;br /&gt;
}} &lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (Cauchy-Schwarz inequality)|(Mantel&#039;s original proof)&lt;br /&gt;
For any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, no vertex can be a neighbor of both &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, or otherwise there will be a triangle. Thus, for any edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;d_u+d_v\le n&amp;lt;/math&amp;gt;. It follows that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)\le n|E|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Note that &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; appears exactly &amp;lt;math&amp;gt;d_v&amp;lt;/math&amp;gt; times in the sum, so that&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{uv\in E}(d_u+d_v)=\sum_{v\in V}d_v^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Applying Chauchy-Schwarz inequality,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
n|E|\ge\sum_{v\in V}d_v^2\ge\frac{\left(\sum_{v\in V}d_v\right)^2}{n}=\frac{4|E|^2}{n},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where the last equation is due to Euler&#039;s equality &amp;lt;math&amp;gt;\sum_{v\in V}d_v=2|E|&amp;lt;/math&amp;gt;. The theorem follows.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (inequality of the arithmetic and geometric mean)|&lt;br /&gt;
Assume that &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; vertices and is triangle-free.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; be the largest independent set in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\alpha=|A|&amp;lt;/math&amp;gt;. &lt;br /&gt;
Since &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is triangle-free, for very vertex &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, all its neighbors must form an independent set, thus &amp;lt;math&amp;gt;d(v)\le \alpha&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Take &amp;lt;math&amp;gt;B=V\setminus A&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;\beta=|B|&amp;lt;/math&amp;gt;.&lt;br /&gt;
Since &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; is an independent set, all edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; must have at least one endpoint in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;. Counting the edges in &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; according to their endpoints in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;, we obtain &amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v&amp;lt;/math&amp;gt;. By the inequality of the arithmetic and geometric mean,&lt;br /&gt;
:&amp;lt;math&amp;gt;|E|\le\sum_{v\in B}d_v\le\alpha\beta\le\left(\frac{\alpha+\beta}{2}\right)^2=\frac{n^2}{4}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Turán&#039;s theorem ===&lt;br /&gt;
{{Theorem|Theorem (Turán 1941)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a graph with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, &amp;lt;math&amp;gt;k\ge 2&amp;lt;/math&amp;gt;, then&lt;br /&gt;
::&amp;lt;math&amp;gt;|E|\le\frac{r-2}{2(r-1)}n^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|First proof. (induction)|(Turán&#039;s original proof)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Second proof. (weight shifting)|(due to Motzkin and Straus)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Third proof. (the probabilistic method)|(due to Alon and Spencer)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Prooftitle|Fourth proof.|&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with a maximum number of edges.&lt;br /&gt;
:&#039;&#039;&#039;Claim:&#039;&#039;&#039; &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; does not contain three vertices &amp;lt;math&amp;gt;u,v,w&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; but &amp;lt;math&amp;gt;uw\not\in E, vw\not\in E&amp;lt;/math&amp;gt;.&lt;br /&gt;
Suppose otherwise. There are two cases.&lt;br /&gt;
* &#039;&#039;&#039;Case.1:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;d(w)&amp;lt;d(v)&amp;lt;/math&amp;gt;. Without loss of generality, suppose that &amp;lt;math&amp;gt;d(w)&amp;lt;d(u)&amp;lt;/math&amp;gt;. We duplicate &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; by creating a new vertex &amp;lt;math&amp;gt;u&#039;&amp;lt;/math&amp;gt; which has exactly the same neighbors as &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; (but &amp;lt;math&amp;gt;uu&#039;&amp;lt;/math&amp;gt; is not an edge). Such duplication will not increase the clique size. We then remove &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;. The resulting graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is still &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique-free, and has &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices. The number of edges in &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+d(u)-d(w)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
:which contradicts the assumption that &amp;lt;math&amp;gt;|E(G)|&amp;lt;/math&amp;gt; is maximal.&lt;br /&gt;
* &#039;&#039;&#039;Case.2:&#039;&#039;&#039; &amp;lt;math&amp;gt;d(w)\ge d(u)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;d(w)\ge d(v)&amp;lt;/math&amp;gt;. Duplicate &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; twice and delete &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;. The new graph &amp;lt;math&amp;gt;G&#039;&amp;lt;/math&amp;gt; has no &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;-clique, and the number of edges is&lt;br /&gt;
::&amp;lt;math&amp;gt;|E(G&#039;)|=|E(G)|+2d(w)-(d(u)+d(v)+1)&amp;gt;|E(G)|\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Contradiction again.&lt;br /&gt;
&lt;br /&gt;
The claim implies that &amp;lt;math&amp;gt;uv\not\in E&amp;lt;/math&amp;gt; defines an equivalence relation on vertices (to be more precise, it guarantees the transitivity of the relation, while the reflexivity and symmetry hold directly). Graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; must be a complete multipartite graph &amp;lt;math&amp;gt;K_{n_1,n_2,\ldots,n_{r-1}}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n_1+n_2+\cdots +n_{r-1}=n&amp;lt;/math&amp;gt;. Optimize the edge number, we have the Turán graph.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Erdős–Stone theorem ===&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Fundamental theorem of extremal graph theory (Erdős–Stone 1946)|&lt;br /&gt;
:For any &amp;lt;math&amp;gt;r\ge 2&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;s\ge 1&amp;lt;/math&amp;gt;, and every sufficiently large &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, every graph with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices and at least &amp;lt;math&amp;gt;\left(\frac{r-2}{2(r-1)}+\epsilon\right)n^2&amp;lt;/math&amp;gt; edges contains &amp;lt;math&amp;gt;K_{r,s}&amp;lt;/math&amp;gt; as a subgraph.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Corollary|&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Cycle Structures ==&lt;br /&gt;
=== Girth ===&lt;br /&gt;
&lt;br /&gt;
=== Hamiltonian cycle ===&lt;/div&gt;</summary>
		<author><name>172.21.1.240</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3030</id>
		<title>Combinatorics (Fall 2010)/Existence, the probabilistic method</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3030"/>
		<updated>2010-09-20T08:56:23Z</updated>

		<summary type="html">&lt;p&gt;172.21.6.120: /* Dirichlet&amp;#039;s theorem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting arguments ==&lt;br /&gt;
;Circuit complexity&lt;br /&gt;
&lt;br /&gt;
This is a fundamental problem in in Computer Science.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;boolean function&#039;&#039;&#039; is a function is the form &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, a boolean circuit is a directed acyclic graph. Nodes with indegree zero are input nodes, labeled &amp;lt;math&amp;gt;x_1, x_2, \ldots , x_n&amp;lt;/math&amp;gt;. A circuit has a unique node with outdegree zero, called the output node. Every other node is a gate. There are three types of gates: AND, OR (both with indegree two), and NOT (with indegree one).&lt;br /&gt;
&lt;br /&gt;
Computations in Turing machines can be simulated by circuits, and any boolean function in &#039;&#039;&#039;P&#039;&#039;&#039; can be computed by a circuit with polynomially many gates. Thus, if we can find a function in &#039;&#039;&#039;NP&#039;&#039;&#039; that cannot be computed by any circuit with polynomially many gates, then &#039;&#039;&#039;NP&#039;&#039;&#039;&amp;lt;math&amp;gt;\neq&amp;lt;/math&amp;gt;&#039;&#039;&#039;P&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The following theorem due to Shannon says that functions with exponentially large circuit complexity do exist.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem (Shannon 1949)|&lt;br /&gt;
:There is a boolean function &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt; with circuit complexity greater than &amp;lt;math&amp;gt;\frac{2^n}{3n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| &lt;br /&gt;
We first count the number of boolean functions &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;. There are &amp;lt;math&amp;gt;2^{2^n}&amp;lt;/math&amp;gt; boolean functions &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Then we count the number of boolean circuit with fixed number of gates.&lt;br /&gt;
Fix an integer &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt;, we count the number of circuits with &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; gates. By the [http://en.wikipedia.org/wiki/De_Morgan&#039;s_laws De Morgan&#039;s laws], we can assume that all NOTs are pushed back to the inputs. Each gate has one of the two types (AND or OR), and has two inputs. Each of the inputs to a gate is either a constant 0 or 1, an input variable &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt;, an inverted input variable &amp;lt;math&amp;gt;\neg x_i&amp;lt;/math&amp;gt;, or the output of another gate; thus, there are at most &amp;lt;math&amp;gt;2+2n+t-1&amp;lt;/math&amp;gt; possible gate inputs. It follows that the number of circuits with &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; gates is at most &amp;lt;math&amp;gt;2^t(t+2n+1)^{2t}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;t=2^n/3n&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{2^t(t+2n+1)^{2t}}{2^{2^n}}=o(1)&amp;lt;1,&amp;lt;/math&amp;gt;      thus, &amp;lt;math&amp;gt;2^t(t+2n+1)^{2t} &amp;lt; 2^{2^n}.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each boolean circuit computes one boolean function. Therefore, there must exist a boolean function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; which cannot be computed by any circuits with &amp;lt;math&amp;gt;2^n/3n&amp;lt;/math&amp;gt; gates.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Note that by Shannon&#039;s theorem, not only there exists a boolean function with exponentially large circuit complexity, but &#039;&#039;almost all&#039;&#039; boolean functions have exponentially large circuit complexity.&lt;br /&gt;
&lt;br /&gt;
=== Double counting ===&lt;br /&gt;
;Handshaking lemma&lt;br /&gt;
{{Theorem|Handshaking Lemma|&lt;br /&gt;
:At a party, the number of guests who shake hands an odd number of times is even.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
We model this scenario as an undirected graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; standing for the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; guests. There is an edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; shake hands. Let &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; be the degree of vertex &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, which represents the number of times that &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; shakes hand. The handshaking lemma states that in any undirected graph, the sum of odd degrees is even.&lt;br /&gt;
&lt;br /&gt;
The handshaking lemma is a direct consequence of the following lemma, which is proved by Euler in a 1736 paper that began the study of graph theory.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma (Euler 1736)|&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in V}d(v)=2|E|&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
We count the number of &#039;&#039;&#039;directed&#039;&#039;&#039; edges. A directed edge is an ordered pair &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;\{u,v\}\in E&amp;lt;/math&amp;gt;. There are two ways to count the directed edges.&lt;br /&gt;
&lt;br /&gt;
First, we can enumerate by edges. Pick every edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; and apply two directions &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;(v,u)&amp;lt;/math&amp;gt; to the edge. This gives us &amp;lt;math&amp;gt;2|E|&amp;lt;/math&amp;gt; directed edges.&lt;br /&gt;
&lt;br /&gt;
On the other hand, we can enumerate by vertices. Pick every vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt; and for each of its &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; neighbors, say &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt;, generate a directed edge &amp;lt;math&amp;gt;(v,u)&amp;lt;/math&amp;gt;. This gives us &amp;lt;math&amp;gt;\sum_{v\in V}d(v)&amp;lt;/math&amp;gt; directed edges.&lt;br /&gt;
&lt;br /&gt;
It is obvious that the two terms are equal, since we just count the same thing twice with different methods. The lemma follows.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The handshaking lemma is implied directly by the above lemma, since the sum of even degrees is even.&lt;br /&gt;
&lt;br /&gt;
;Cayley&#039;s formula&lt;br /&gt;
{{Theorem|Caylay&#039;s formula for trees|&lt;br /&gt;
: There are &amp;lt;math&amp;gt;n^{n-2}&amp;lt;/math&amp;gt; different trees on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; distinct vertices.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== The Pigeonhole Principle ==&lt;br /&gt;
&lt;br /&gt;
=== Monotonic subsequences ===&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Erdős-Szekeres 1935)|&lt;br /&gt;
:A sequence of more than &amp;lt;math&amp;gt;mn&amp;lt;/math&amp;gt; different real numbers must contain either an increasing subsequence of length &amp;lt;math&amp;gt;m+1&amp;lt;/math&amp;gt;, or a decreasing subsequence of length &amp;lt;math&amp;gt;n+1&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|(due to Seidenberg 1959)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Dirichlet&#039;s theorem ===&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Dirichlet 1879)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; be a real number. For any natural number &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, there is a rational number &amp;lt;math&amp;gt;\frac{p}{q}&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;1\le q\le n&amp;lt;/math&amp;gt; and &lt;br /&gt;
::&amp;lt;math&amp;gt;\left|x-\frac{p}{q}\right|&amp;lt;\frac{1}{nq}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== The Probabilistic Method ==&lt;br /&gt;
&lt;br /&gt;
Suppose we want prove the existence of mathematic objects with certain properties. One way to do so is to explicitly construct such an object. This kind of proofs can be interpreted as &#039;&#039;deterministic algorithms&#039;&#039; which find the object with desirable properties.&lt;br /&gt;
&lt;br /&gt;
The probabilistic method provides another way of proving the existence of objects: instead of explicitly constructing an object, we define a probability space of objects in which the probability is positive that a randomly selected object has the required property.&lt;br /&gt;
&lt;br /&gt;
The basic principle of the probabilistic method is very simple, and can be stated in intuitive ways:&lt;br /&gt;
*If an object chosen randomly from a universe satisfies a property with positive probability, then there must be an object in the universe that satisfies that property.&lt;br /&gt;
:For example, for a ball(the object) randomly chosen from a box(the universe) of balls, if the probability that the chosen ball is blue(the property) is &amp;gt;0, then there must be a blue ball in the box.&lt;br /&gt;
*Any random variable assumes at least one value that is no smaller than its expectation, and at least one value that is no greater than the expectation.&lt;br /&gt;
:For example, if we know the average height of the students in the class is &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;, then we know there is a students whose height is at least &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;, and there is a student whose height is at most &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Although the idea of  the probabilistic method is simple, it provides us a powerful tool for existential proof. In same cases, the proof itself is a &#039;&#039;randomized algorithm&#039;&#039;, and if we are lucky, the algorithm could be very efficient.&lt;br /&gt;
&lt;br /&gt;
=== Sampling ===&lt;br /&gt;
;Ramsey number&lt;br /&gt;
&lt;br /&gt;
Recall the Ramsey theorem which states that in a meeting of at least six people, there are either three people knowing each other or three people not knowing each other. In graph theoretical terms, this means that no matter how we color the edges of &amp;lt;math&amp;gt;K_6&amp;lt;/math&amp;gt; (the complete graph on six vertices), there must be a &#039;&#039;&#039;monochromatic&#039;&#039;&#039; &amp;lt;math&amp;gt;K_3&amp;lt;/math&amp;gt; (a triangle whose edges have the same color).&lt;br /&gt;
&lt;br /&gt;
Generally, the &#039;&#039;&#039;Ramsey number&#039;&#039;&#039; &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt; is the smallest integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; such that in any two-coloring of the edges of a complete graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; by red and blue, either there is a red &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; or there is a blue &amp;lt;math&amp;gt;K_\ell&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ramsey showed in 1929 that &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt; is finite for any &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;. It is extremely hard to compute the exact value of &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt;. Here we give a lower bound of &amp;lt;math&amp;gt;R(k,k)&amp;lt;/math&amp;gt; by the probabilistic method.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem (Erdős 1947)|&lt;br /&gt;
:If &amp;lt;math&amp;gt;{n\choose k}\cdot 2^{1-{k\choose 2}}&amp;lt;1&amp;lt;/math&amp;gt; then it is possible to color the edges of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; with two colors so that there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Consider a random two-coloring of edges of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; obtained as follows:&lt;br /&gt;
* For each edge of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt;, independently flip a fair coin to decide the color of the edge.&lt;br /&gt;
&lt;br /&gt;
For any fixed set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, let &amp;lt;math&amp;gt;\mathcal{E}_S&amp;lt;/math&amp;gt; be the event that the &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph induced by &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is monochromatic. There are &amp;lt;math&amp;gt;{k\choose 2}&amp;lt;/math&amp;gt; many edges in &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt;, therefore&lt;br /&gt;
:&amp;lt;math&amp;gt;\Pr[\mathcal{E}_S]=2\cdot 2^{-{k\choose 2}}=2^{1-{k\choose 2}}.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since there are &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; possible choices of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, by the union bound&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\Pr[\exists S, \mathcal{E}_S]\le {n\choose k}\cdot\Pr[\mathcal{E}_S]={n\choose k}\cdot 2^{1-{k\choose 2}}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Due to the assumption, &amp;lt;math&amp;gt;{n\choose k}\cdot 2^{1-{k\choose 2}}&amp;lt;1&amp;lt;/math&amp;gt;, thus there exists a two coloring that none of &amp;lt;math&amp;gt;\mathcal{E}_S&amp;lt;/math&amp;gt; occurs, which means  there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;k\ge 3&amp;lt;/math&amp;gt; and we take &amp;lt;math&amp;gt;n=\lfloor2^{k/2}\rfloor&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
{n\choose k}\cdot 2^{1-{k\choose 2}}&lt;br /&gt;
&amp;amp;&amp;lt;&lt;br /&gt;
\frac{n^k}{k!}\cdot\frac{2^{1+\frac{k}{2}}}{2^{k^2/2}}\\&lt;br /&gt;
&amp;amp;\le &lt;br /&gt;
\frac{2^{k^2/2}}{k!}\cdot\frac{2^{1+\frac{k}{2}}}{2^{k^2/2}}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{2^{1+\frac{k}{2}}}{k!}\\&lt;br /&gt;
&amp;amp;&amp;lt;1.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
By the above theorem, there exists a two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; that there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt;. Therefore, the Ramsey number &amp;lt;math&amp;gt;R(k,k)&amp;gt;\lfloor2^{k/2}\rfloor&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;k\ge 3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that for sufficiently large &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, if &amp;lt;math&amp;gt;n= \lfloor 2^{k/2}\rfloor&amp;lt;/math&amp;gt;, then the probability that there exists a monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; is bounded by&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
{n\choose k}\cdot 2^{1-{k\choose 2}}&lt;br /&gt;
&amp;lt;&lt;br /&gt;
\frac{2^{1+\frac{k}{2}}}{k!}&lt;br /&gt;
\ll 1,&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
which means that a random two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; is very likely not to contain a monochromatic  &amp;lt;math&amp;gt;K_{2\log n}&amp;lt;/math&amp;gt;. This gives us a very simple randomized algorithm for finding a two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; without monochromatic &amp;lt;math&amp;gt;K_{2\log n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Linearity of expectation ===&lt;br /&gt;
&lt;br /&gt;
;Maximum cut&lt;br /&gt;
&lt;br /&gt;
Given an undirected graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;, a set &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; of edges of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is disconnected after removing the edges in &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt;. We can represent a cut by &amp;lt;math&amp;gt;c(S,T)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;(S,T)&amp;lt;/math&amp;gt; is a bipartition of the vertex set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;c(S,T)=\{uv\in E\mid u\in S,v\in T\}&amp;lt;/math&amp;gt; is the set of edges crossing between &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We have seen how to compute min-cut: either by deterministic max-flow algorithm, or by Karger&#039;s randomized algorithm. On the other hand, max-cut is hard to compute, because it is &#039;&#039;&#039;NP-complete&#039;&#039;&#039;. Actually, the weighted version of max-cut is among the [http://en.wikipedia.org/wiki/Karp&#039;s_21_NP-complete_problems Karp&#039;s 21 NP-complete problems].&lt;br /&gt;
&lt;br /&gt;
We now show by the probabilistic method that a max-cut always has at least half the edges.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:Given an undirected graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges, there is a cut of size at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Enumerate the vertices in an arbitrary order. Partition the vertex set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; into two disjoint sets &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; as follows.&lt;br /&gt;
:For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;,&lt;br /&gt;
:* independently choose one of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; with equal probability, and let &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; join the chosen set.&lt;br /&gt;
&lt;br /&gt;
For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;X_v\in\{S,T\}&amp;lt;/math&amp;gt; be the random variable which represents the set that &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; joins. For each edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;Y_{uv}&amp;lt;/math&amp;gt; be the 0-1 random variable which indicates whether &amp;lt;math&amp;gt;uv&amp;lt;/math&amp;gt; crosses between &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;. Clearly,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\Pr[Y_{uv}=1]=\Pr[X_u\neq X_v]=\frac{1}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of &amp;lt;math&amp;gt;c(S,T)&amp;lt;/math&amp;gt; is given by &amp;lt;math&amp;gt;Y=\sum_{uv\in E}Y_{uv}&amp;lt;/math&amp;gt;. By the linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[Y]=\sum_{uv\in E}\mathbf{E}[Y_{uv}]=\sum_{uv\in E}\Pr[Y_{uv}=1]=\frac{m}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, there exist a bipartition &amp;lt;math&amp;gt;(S,T)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;|c(S,T)|\ge\frac{m}{2}&amp;lt;/math&amp;gt;, i.e. there exists a cut of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; which contains at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; edges.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;Maximum satisfiability&lt;br /&gt;
&lt;br /&gt;
Suppose that we have a number of boolean variables &amp;lt;math&amp;gt;x_1,x_2,\ldots,\in\{\mathrm{true},\mathrm{false}\}&amp;lt;/math&amp;gt;. A &#039;&#039;&#039;literal&#039;&#039;&#039; is either a variable &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; itself or its negation &amp;lt;math&amp;gt;\neg x_i&amp;lt;/math&amp;gt;. A logic expression is a &#039;&#039;&#039;conjunctive normal form (CNF)&#039;&#039;&#039; if it is written as the conjunction(AND) of a set of &#039;&#039;&#039;clauses&#039;&#039;&#039;, where each clause is a disjunction(OR) of literals. For example:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(x_1\vee \neg x_2 \vee \neg x_3)\wedge (\neg x_1\vee \neg x_3)\wedge (x_1\vee x_2\vee x_4)\wedge (x_4\vee \neg x_3)\wedge (x_4\vee \neg x_1).&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The satisfiability (SAT) problem ask whether the CNF is satisfiable, i.e. there exists an assignment of variables to the values of true and false so that all clauses are true. The maximum satisfiability (MAXSAT) is the optimization version of SAT, which ask for an assignment that the number of satisfied clauses is maximized.&lt;br /&gt;
&lt;br /&gt;
SAT is the first problem known to be &#039;&#039;&#039;NP-complete&#039;&#039;&#039; (the Cook-Levin theorem). MAXSAT is also &#039;&#039;&#039;NP-complete&#039;&#039;&#039;. We then see that there always exists a roughly good truth assignment which satisfies half the clauses.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:For any set of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; clauses, there is a truth assignment that satisfies at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; clauses.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| For each variable, independently assign a random value in &amp;lt;math&amp;gt;\{\mathrm{true},\mathrm{false}\}&amp;lt;/math&amp;gt; with equal probability. For the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;th clause, let &amp;lt;math&amp;gt;X_i&amp;lt;/math&amp;gt; be the random variable which indicates whether the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;th clause is satisfied. Suppose that there are &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; literals in the clause. The probability that the clause is satisfied is &lt;br /&gt;
:&amp;lt;math&amp;gt;\Pr[X_k=1]\ge(1-2^{-k})\ge\frac{1}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;X=\sum_{i=1}^m X_i&amp;lt;/math&amp;gt; be the number of satisfied clauses. By the linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[X]=\sum_{i=1}^{m}\mathbf{E}[X_i]\ge \frac{m}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, there exists an assignment such that at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; clauses are satisfied.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Alterations ===&lt;br /&gt;
;Independent sets&lt;br /&gt;
An independent set of a graph is a set of vertices with no edges between them. The following theorem gives a lower bound on the size of the largest independent set.&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges. Then &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has an independent set with at least &amp;lt;math&amp;gt;\frac{n^2}{4m}&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Let &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; be a set of vertices constructed as follows:&lt;br /&gt;
:For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;:&lt;br /&gt;
:* &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is included in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; independently with probability &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; to be determined.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;X=|S|&amp;lt;/math&amp;gt;. It is obvious that &amp;lt;math&amp;gt;\mathbf{E}[X]=np&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For each edge &amp;lt;math&amp;gt;e\in E&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;Y_{e}&amp;lt;/math&amp;gt; be the random variable which indicates whether both endpoints of &amp;lt;math&amp;gt;&amp;lt;/math&amp;gt; are in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[Y_{uv}]=\Pr[u\in S\wedge v\in S]=p^2.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Let &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; be the number of edges in the subgraph of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; induced by &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. It holds that &amp;lt;math&amp;gt;Y=\sum_{e\in E}Y_e&amp;lt;/math&amp;gt;. By linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathbf{E}[Y]=\sum_{e\in E}\mathbf{E}[Y_e]=mp^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that although &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is not necessary an independent set, it can be modified to one if for each edge &amp;lt;math&amp;gt;e&amp;lt;/math&amp;gt; of the induced subgraph &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, we delete one of the endpoint of &amp;lt;math&amp;gt;e&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; be the resulting set. It is obvious that &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; is an independent set since there is no edge left in the induced subgraph &amp;lt;math&amp;gt;G(S^*)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Since there are &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; edges in &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, there are at most &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; vertices in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; are deleted to make it become &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;|S^*|\ge X-Y&amp;lt;/math&amp;gt;. By linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[|S^*|]\ge\mathbf{E}[X-Y]=\mathbf{E}[X]-\mathbf{E}[Y]=np-mp^2.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The expectation is maximized when &amp;lt;math&amp;gt;p=\frac{n}{2m}&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[|S^*|]\ge n\cdot\frac{n}{2m}-m\left(\frac{n}{2m}\right)^2=\frac{n^2}{4m}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
There exists an independent set which contains at least &amp;lt;math&amp;gt;\frac{n^2}{4m}&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The proof actually propose a randomized algorithm for constructing large independent set:&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Algorithm|&lt;br /&gt;
Given a graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges, let &amp;lt;math&amp;gt;d=\frac{2m}{n}&amp;lt;/math&amp;gt; be the average degree.&lt;br /&gt;
#For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is included in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; independently with probability &amp;lt;math&amp;gt;\frac{1}{d}&amp;lt;/math&amp;gt;.&lt;br /&gt;
#For each remaining edge in the induced subgraph &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, remove one of the endpoints from &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; be the resulting set. We have shown that &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; is an independent set and &amp;lt;math&amp;gt;\mathbf{E}[|S^*|]\ge\frac{n^2}{4m}&amp;lt;/math&amp;gt;.&lt;/div&gt;</summary>
		<author><name>172.21.6.120</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3029</id>
		<title>Combinatorics (Fall 2010)/Existence, the probabilistic method</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3029"/>
		<updated>2010-09-20T08:54:33Z</updated>

		<summary type="html">&lt;p&gt;172.21.6.120: /* Monotonic subsequences */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting arguments ==&lt;br /&gt;
;Circuit complexity&lt;br /&gt;
&lt;br /&gt;
This is a fundamental problem in in Computer Science.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;boolean function&#039;&#039;&#039; is a function is the form &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, a boolean circuit is a directed acyclic graph. Nodes with indegree zero are input nodes, labeled &amp;lt;math&amp;gt;x_1, x_2, \ldots , x_n&amp;lt;/math&amp;gt;. A circuit has a unique node with outdegree zero, called the output node. Every other node is a gate. There are three types of gates: AND, OR (both with indegree two), and NOT (with indegree one).&lt;br /&gt;
&lt;br /&gt;
Computations in Turing machines can be simulated by circuits, and any boolean function in &#039;&#039;&#039;P&#039;&#039;&#039; can be computed by a circuit with polynomially many gates. Thus, if we can find a function in &#039;&#039;&#039;NP&#039;&#039;&#039; that cannot be computed by any circuit with polynomially many gates, then &#039;&#039;&#039;NP&#039;&#039;&#039;&amp;lt;math&amp;gt;\neq&amp;lt;/math&amp;gt;&#039;&#039;&#039;P&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The following theorem due to Shannon says that functions with exponentially large circuit complexity do exist.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem (Shannon 1949)|&lt;br /&gt;
:There is a boolean function &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt; with circuit complexity greater than &amp;lt;math&amp;gt;\frac{2^n}{3n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| &lt;br /&gt;
We first count the number of boolean functions &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;. There are &amp;lt;math&amp;gt;2^{2^n}&amp;lt;/math&amp;gt; boolean functions &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Then we count the number of boolean circuit with fixed number of gates.&lt;br /&gt;
Fix an integer &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt;, we count the number of circuits with &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; gates. By the [http://en.wikipedia.org/wiki/De_Morgan&#039;s_laws De Morgan&#039;s laws], we can assume that all NOTs are pushed back to the inputs. Each gate has one of the two types (AND or OR), and has two inputs. Each of the inputs to a gate is either a constant 0 or 1, an input variable &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt;, an inverted input variable &amp;lt;math&amp;gt;\neg x_i&amp;lt;/math&amp;gt;, or the output of another gate; thus, there are at most &amp;lt;math&amp;gt;2+2n+t-1&amp;lt;/math&amp;gt; possible gate inputs. It follows that the number of circuits with &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; gates is at most &amp;lt;math&amp;gt;2^t(t+2n+1)^{2t}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;t=2^n/3n&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{2^t(t+2n+1)^{2t}}{2^{2^n}}=o(1)&amp;lt;1,&amp;lt;/math&amp;gt;      thus, &amp;lt;math&amp;gt;2^t(t+2n+1)^{2t} &amp;lt; 2^{2^n}.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each boolean circuit computes one boolean function. Therefore, there must exist a boolean function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; which cannot be computed by any circuits with &amp;lt;math&amp;gt;2^n/3n&amp;lt;/math&amp;gt; gates.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Note that by Shannon&#039;s theorem, not only there exists a boolean function with exponentially large circuit complexity, but &#039;&#039;almost all&#039;&#039; boolean functions have exponentially large circuit complexity.&lt;br /&gt;
&lt;br /&gt;
=== Double counting ===&lt;br /&gt;
;Handshaking lemma&lt;br /&gt;
{{Theorem|Handshaking Lemma|&lt;br /&gt;
:At a party, the number of guests who shake hands an odd number of times is even.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
We model this scenario as an undirected graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; standing for the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; guests. There is an edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; shake hands. Let &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; be the degree of vertex &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, which represents the number of times that &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; shakes hand. The handshaking lemma states that in any undirected graph, the sum of odd degrees is even.&lt;br /&gt;
&lt;br /&gt;
The handshaking lemma is a direct consequence of the following lemma, which is proved by Euler in a 1736 paper that began the study of graph theory.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma (Euler 1736)|&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in V}d(v)=2|E|&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
We count the number of &#039;&#039;&#039;directed&#039;&#039;&#039; edges. A directed edge is an ordered pair &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;\{u,v\}\in E&amp;lt;/math&amp;gt;. There are two ways to count the directed edges.&lt;br /&gt;
&lt;br /&gt;
First, we can enumerate by edges. Pick every edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; and apply two directions &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;(v,u)&amp;lt;/math&amp;gt; to the edge. This gives us &amp;lt;math&amp;gt;2|E|&amp;lt;/math&amp;gt; directed edges.&lt;br /&gt;
&lt;br /&gt;
On the other hand, we can enumerate by vertices. Pick every vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt; and for each of its &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; neighbors, say &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt;, generate a directed edge &amp;lt;math&amp;gt;(v,u)&amp;lt;/math&amp;gt;. This gives us &amp;lt;math&amp;gt;\sum_{v\in V}d(v)&amp;lt;/math&amp;gt; directed edges.&lt;br /&gt;
&lt;br /&gt;
It is obvious that the two terms are equal, since we just count the same thing twice with different methods. The lemma follows.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The handshaking lemma is implied directly by the above lemma, since the sum of even degrees is even.&lt;br /&gt;
&lt;br /&gt;
;Cayley&#039;s formula&lt;br /&gt;
{{Theorem|Caylay&#039;s formula for trees|&lt;br /&gt;
: There are &amp;lt;math&amp;gt;n^{n-2}&amp;lt;/math&amp;gt; different trees on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; distinct vertices.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== The Pigeonhole Principle ==&lt;br /&gt;
&lt;br /&gt;
=== Monotonic subsequences ===&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Erdős-Szekeres 1935)|&lt;br /&gt;
:A sequence of more than &amp;lt;math&amp;gt;mn&amp;lt;/math&amp;gt; different real numbers must contain either an increasing subsequence of length &amp;lt;math&amp;gt;m+1&amp;lt;/math&amp;gt;, or a decreasing subsequence of length &amp;lt;math&amp;gt;n+1&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|(due to Seidenberg 1959)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Dirichlet&#039;s theorem ===&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Dirichlet 1879)|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; be a real number. For any natural number &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, there is a rational number &amp;lt;math&amp;gt;\frac{p}{q}&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;1\le q\le n&amp;lt;/math&amp;gt; and &lt;br /&gt;
::&amp;lt;math&amp;gt;\left|x-\frac{p}{q}\right|&amp;lt;\frac{1}{nq}\le\frac{1}{q^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== The Probabilistic Method ==&lt;br /&gt;
&lt;br /&gt;
Suppose we want prove the existence of mathematic objects with certain properties. One way to do so is to explicitly construct such an object. This kind of proofs can be interpreted as &#039;&#039;deterministic algorithms&#039;&#039; which find the object with desirable properties.&lt;br /&gt;
&lt;br /&gt;
The probabilistic method provides another way of proving the existence of objects: instead of explicitly constructing an object, we define a probability space of objects in which the probability is positive that a randomly selected object has the required property.&lt;br /&gt;
&lt;br /&gt;
The basic principle of the probabilistic method is very simple, and can be stated in intuitive ways:&lt;br /&gt;
*If an object chosen randomly from a universe satisfies a property with positive probability, then there must be an object in the universe that satisfies that property.&lt;br /&gt;
:For example, for a ball(the object) randomly chosen from a box(the universe) of balls, if the probability that the chosen ball is blue(the property) is &amp;gt;0, then there must be a blue ball in the box.&lt;br /&gt;
*Any random variable assumes at least one value that is no smaller than its expectation, and at least one value that is no greater than the expectation.&lt;br /&gt;
:For example, if we know the average height of the students in the class is &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;, then we know there is a students whose height is at least &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;, and there is a student whose height is at most &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Although the idea of  the probabilistic method is simple, it provides us a powerful tool for existential proof. In same cases, the proof itself is a &#039;&#039;randomized algorithm&#039;&#039;, and if we are lucky, the algorithm could be very efficient.&lt;br /&gt;
&lt;br /&gt;
=== Sampling ===&lt;br /&gt;
;Ramsey number&lt;br /&gt;
&lt;br /&gt;
Recall the Ramsey theorem which states that in a meeting of at least six people, there are either three people knowing each other or three people not knowing each other. In graph theoretical terms, this means that no matter how we color the edges of &amp;lt;math&amp;gt;K_6&amp;lt;/math&amp;gt; (the complete graph on six vertices), there must be a &#039;&#039;&#039;monochromatic&#039;&#039;&#039; &amp;lt;math&amp;gt;K_3&amp;lt;/math&amp;gt; (a triangle whose edges have the same color).&lt;br /&gt;
&lt;br /&gt;
Generally, the &#039;&#039;&#039;Ramsey number&#039;&#039;&#039; &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt; is the smallest integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; such that in any two-coloring of the edges of a complete graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; by red and blue, either there is a red &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; or there is a blue &amp;lt;math&amp;gt;K_\ell&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ramsey showed in 1929 that &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt; is finite for any &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;. It is extremely hard to compute the exact value of &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt;. Here we give a lower bound of &amp;lt;math&amp;gt;R(k,k)&amp;lt;/math&amp;gt; by the probabilistic method.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem (Erdős 1947)|&lt;br /&gt;
:If &amp;lt;math&amp;gt;{n\choose k}\cdot 2^{1-{k\choose 2}}&amp;lt;1&amp;lt;/math&amp;gt; then it is possible to color the edges of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; with two colors so that there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Consider a random two-coloring of edges of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; obtained as follows:&lt;br /&gt;
* For each edge of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt;, independently flip a fair coin to decide the color of the edge.&lt;br /&gt;
&lt;br /&gt;
For any fixed set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, let &amp;lt;math&amp;gt;\mathcal{E}_S&amp;lt;/math&amp;gt; be the event that the &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph induced by &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is monochromatic. There are &amp;lt;math&amp;gt;{k\choose 2}&amp;lt;/math&amp;gt; many edges in &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt;, therefore&lt;br /&gt;
:&amp;lt;math&amp;gt;\Pr[\mathcal{E}_S]=2\cdot 2^{-{k\choose 2}}=2^{1-{k\choose 2}}.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since there are &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; possible choices of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, by the union bound&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\Pr[\exists S, \mathcal{E}_S]\le {n\choose k}\cdot\Pr[\mathcal{E}_S]={n\choose k}\cdot 2^{1-{k\choose 2}}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Due to the assumption, &amp;lt;math&amp;gt;{n\choose k}\cdot 2^{1-{k\choose 2}}&amp;lt;1&amp;lt;/math&amp;gt;, thus there exists a two coloring that none of &amp;lt;math&amp;gt;\mathcal{E}_S&amp;lt;/math&amp;gt; occurs, which means  there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;k\ge 3&amp;lt;/math&amp;gt; and we take &amp;lt;math&amp;gt;n=\lfloor2^{k/2}\rfloor&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
{n\choose k}\cdot 2^{1-{k\choose 2}}&lt;br /&gt;
&amp;amp;&amp;lt;&lt;br /&gt;
\frac{n^k}{k!}\cdot\frac{2^{1+\frac{k}{2}}}{2^{k^2/2}}\\&lt;br /&gt;
&amp;amp;\le &lt;br /&gt;
\frac{2^{k^2/2}}{k!}\cdot\frac{2^{1+\frac{k}{2}}}{2^{k^2/2}}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{2^{1+\frac{k}{2}}}{k!}\\&lt;br /&gt;
&amp;amp;&amp;lt;1.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
By the above theorem, there exists a two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; that there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt;. Therefore, the Ramsey number &amp;lt;math&amp;gt;R(k,k)&amp;gt;\lfloor2^{k/2}\rfloor&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;k\ge 3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that for sufficiently large &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, if &amp;lt;math&amp;gt;n= \lfloor 2^{k/2}\rfloor&amp;lt;/math&amp;gt;, then the probability that there exists a monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; is bounded by&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
{n\choose k}\cdot 2^{1-{k\choose 2}}&lt;br /&gt;
&amp;lt;&lt;br /&gt;
\frac{2^{1+\frac{k}{2}}}{k!}&lt;br /&gt;
\ll 1,&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
which means that a random two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; is very likely not to contain a monochromatic  &amp;lt;math&amp;gt;K_{2\log n}&amp;lt;/math&amp;gt;. This gives us a very simple randomized algorithm for finding a two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; without monochromatic &amp;lt;math&amp;gt;K_{2\log n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Linearity of expectation ===&lt;br /&gt;
&lt;br /&gt;
;Maximum cut&lt;br /&gt;
&lt;br /&gt;
Given an undirected graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;, a set &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; of edges of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is disconnected after removing the edges in &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt;. We can represent a cut by &amp;lt;math&amp;gt;c(S,T)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;(S,T)&amp;lt;/math&amp;gt; is a bipartition of the vertex set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;c(S,T)=\{uv\in E\mid u\in S,v\in T\}&amp;lt;/math&amp;gt; is the set of edges crossing between &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We have seen how to compute min-cut: either by deterministic max-flow algorithm, or by Karger&#039;s randomized algorithm. On the other hand, max-cut is hard to compute, because it is &#039;&#039;&#039;NP-complete&#039;&#039;&#039;. Actually, the weighted version of max-cut is among the [http://en.wikipedia.org/wiki/Karp&#039;s_21_NP-complete_problems Karp&#039;s 21 NP-complete problems].&lt;br /&gt;
&lt;br /&gt;
We now show by the probabilistic method that a max-cut always has at least half the edges.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:Given an undirected graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges, there is a cut of size at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Enumerate the vertices in an arbitrary order. Partition the vertex set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; into two disjoint sets &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; as follows.&lt;br /&gt;
:For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;,&lt;br /&gt;
:* independently choose one of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; with equal probability, and let &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; join the chosen set.&lt;br /&gt;
&lt;br /&gt;
For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;X_v\in\{S,T\}&amp;lt;/math&amp;gt; be the random variable which represents the set that &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; joins. For each edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;Y_{uv}&amp;lt;/math&amp;gt; be the 0-1 random variable which indicates whether &amp;lt;math&amp;gt;uv&amp;lt;/math&amp;gt; crosses between &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;. Clearly,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\Pr[Y_{uv}=1]=\Pr[X_u\neq X_v]=\frac{1}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of &amp;lt;math&amp;gt;c(S,T)&amp;lt;/math&amp;gt; is given by &amp;lt;math&amp;gt;Y=\sum_{uv\in E}Y_{uv}&amp;lt;/math&amp;gt;. By the linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[Y]=\sum_{uv\in E}\mathbf{E}[Y_{uv}]=\sum_{uv\in E}\Pr[Y_{uv}=1]=\frac{m}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, there exist a bipartition &amp;lt;math&amp;gt;(S,T)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;|c(S,T)|\ge\frac{m}{2}&amp;lt;/math&amp;gt;, i.e. there exists a cut of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; which contains at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; edges.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;Maximum satisfiability&lt;br /&gt;
&lt;br /&gt;
Suppose that we have a number of boolean variables &amp;lt;math&amp;gt;x_1,x_2,\ldots,\in\{\mathrm{true},\mathrm{false}\}&amp;lt;/math&amp;gt;. A &#039;&#039;&#039;literal&#039;&#039;&#039; is either a variable &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; itself or its negation &amp;lt;math&amp;gt;\neg x_i&amp;lt;/math&amp;gt;. A logic expression is a &#039;&#039;&#039;conjunctive normal form (CNF)&#039;&#039;&#039; if it is written as the conjunction(AND) of a set of &#039;&#039;&#039;clauses&#039;&#039;&#039;, where each clause is a disjunction(OR) of literals. For example:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(x_1\vee \neg x_2 \vee \neg x_3)\wedge (\neg x_1\vee \neg x_3)\wedge (x_1\vee x_2\vee x_4)\wedge (x_4\vee \neg x_3)\wedge (x_4\vee \neg x_1).&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The satisfiability (SAT) problem ask whether the CNF is satisfiable, i.e. there exists an assignment of variables to the values of true and false so that all clauses are true. The maximum satisfiability (MAXSAT) is the optimization version of SAT, which ask for an assignment that the number of satisfied clauses is maximized.&lt;br /&gt;
&lt;br /&gt;
SAT is the first problem known to be &#039;&#039;&#039;NP-complete&#039;&#039;&#039; (the Cook-Levin theorem). MAXSAT is also &#039;&#039;&#039;NP-complete&#039;&#039;&#039;. We then see that there always exists a roughly good truth assignment which satisfies half the clauses.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:For any set of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; clauses, there is a truth assignment that satisfies at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; clauses.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| For each variable, independently assign a random value in &amp;lt;math&amp;gt;\{\mathrm{true},\mathrm{false}\}&amp;lt;/math&amp;gt; with equal probability. For the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;th clause, let &amp;lt;math&amp;gt;X_i&amp;lt;/math&amp;gt; be the random variable which indicates whether the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;th clause is satisfied. Suppose that there are &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; literals in the clause. The probability that the clause is satisfied is &lt;br /&gt;
:&amp;lt;math&amp;gt;\Pr[X_k=1]\ge(1-2^{-k})\ge\frac{1}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;X=\sum_{i=1}^m X_i&amp;lt;/math&amp;gt; be the number of satisfied clauses. By the linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[X]=\sum_{i=1}^{m}\mathbf{E}[X_i]\ge \frac{m}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, there exists an assignment such that at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; clauses are satisfied.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Alterations ===&lt;br /&gt;
;Independent sets&lt;br /&gt;
An independent set of a graph is a set of vertices with no edges between them. The following theorem gives a lower bound on the size of the largest independent set.&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges. Then &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has an independent set with at least &amp;lt;math&amp;gt;\frac{n^2}{4m}&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Let &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; be a set of vertices constructed as follows:&lt;br /&gt;
:For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;:&lt;br /&gt;
:* &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is included in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; independently with probability &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; to be determined.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;X=|S|&amp;lt;/math&amp;gt;. It is obvious that &amp;lt;math&amp;gt;\mathbf{E}[X]=np&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For each edge &amp;lt;math&amp;gt;e\in E&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;Y_{e}&amp;lt;/math&amp;gt; be the random variable which indicates whether both endpoints of &amp;lt;math&amp;gt;&amp;lt;/math&amp;gt; are in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[Y_{uv}]=\Pr[u\in S\wedge v\in S]=p^2.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Let &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; be the number of edges in the subgraph of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; induced by &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. It holds that &amp;lt;math&amp;gt;Y=\sum_{e\in E}Y_e&amp;lt;/math&amp;gt;. By linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathbf{E}[Y]=\sum_{e\in E}\mathbf{E}[Y_e]=mp^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that although &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is not necessary an independent set, it can be modified to one if for each edge &amp;lt;math&amp;gt;e&amp;lt;/math&amp;gt; of the induced subgraph &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, we delete one of the endpoint of &amp;lt;math&amp;gt;e&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; be the resulting set. It is obvious that &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; is an independent set since there is no edge left in the induced subgraph &amp;lt;math&amp;gt;G(S^*)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Since there are &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; edges in &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, there are at most &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; vertices in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; are deleted to make it become &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;|S^*|\ge X-Y&amp;lt;/math&amp;gt;. By linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[|S^*|]\ge\mathbf{E}[X-Y]=\mathbf{E}[X]-\mathbf{E}[Y]=np-mp^2.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The expectation is maximized when &amp;lt;math&amp;gt;p=\frac{n}{2m}&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[|S^*|]\ge n\cdot\frac{n}{2m}-m\left(\frac{n}{2m}\right)^2=\frac{n^2}{4m}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
There exists an independent set which contains at least &amp;lt;math&amp;gt;\frac{n^2}{4m}&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The proof actually propose a randomized algorithm for constructing large independent set:&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Algorithm|&lt;br /&gt;
Given a graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges, let &amp;lt;math&amp;gt;d=\frac{2m}{n}&amp;lt;/math&amp;gt; be the average degree.&lt;br /&gt;
#For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is included in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; independently with probability &amp;lt;math&amp;gt;\frac{1}{d}&amp;lt;/math&amp;gt;.&lt;br /&gt;
#For each remaining edge in the induced subgraph &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, remove one of the endpoints from &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; be the resulting set. We have shown that &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; is an independent set and &amp;lt;math&amp;gt;\mathbf{E}[|S^*|]\ge\frac{n^2}{4m}&amp;lt;/math&amp;gt;.&lt;/div&gt;</summary>
		<author><name>172.21.6.120</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3028</id>
		<title>Combinatorics (Fall 2010)/Existence, the probabilistic method</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3028"/>
		<updated>2010-09-20T06:20:28Z</updated>

		<summary type="html">&lt;p&gt;172.21.6.120: /* Monotonic subsequences */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting arguments ==&lt;br /&gt;
;Circuit complexity&lt;br /&gt;
&lt;br /&gt;
This is a fundamental problem in in Computer Science.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;boolean function&#039;&#039;&#039; is a function is the form &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, a boolean circuit is a directed acyclic graph. Nodes with indegree zero are input nodes, labeled &amp;lt;math&amp;gt;x_1, x_2, \ldots , x_n&amp;lt;/math&amp;gt;. A circuit has a unique node with outdegree zero, called the output node. Every other node is a gate. There are three types of gates: AND, OR (both with indegree two), and NOT (with indegree one).&lt;br /&gt;
&lt;br /&gt;
Computations in Turing machines can be simulated by circuits, and any boolean function in &#039;&#039;&#039;P&#039;&#039;&#039; can be computed by a circuit with polynomially many gates. Thus, if we can find a function in &#039;&#039;&#039;NP&#039;&#039;&#039; that cannot be computed by any circuit with polynomially many gates, then &#039;&#039;&#039;NP&#039;&#039;&#039;&amp;lt;math&amp;gt;\neq&amp;lt;/math&amp;gt;&#039;&#039;&#039;P&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The following theorem due to Shannon says that functions with exponentially large circuit complexity do exist.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem (Shannon 1949)|&lt;br /&gt;
:There is a boolean function &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt; with circuit complexity greater than &amp;lt;math&amp;gt;\frac{2^n}{3n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| &lt;br /&gt;
We first count the number of boolean functions &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;. There are &amp;lt;math&amp;gt;2^{2^n}&amp;lt;/math&amp;gt; boolean functions &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Then we count the number of boolean circuit with fixed number of gates.&lt;br /&gt;
Fix an integer &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt;, we count the number of circuits with &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; gates. By the [http://en.wikipedia.org/wiki/De_Morgan&#039;s_laws De Morgan&#039;s laws], we can assume that all NOTs are pushed back to the inputs. Each gate has one of the two types (AND or OR), and has two inputs. Each of the inputs to a gate is either a constant 0 or 1, an input variable &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt;, an inverted input variable &amp;lt;math&amp;gt;\neg x_i&amp;lt;/math&amp;gt;, or the output of another gate; thus, there are at most &amp;lt;math&amp;gt;2+2n+t-1&amp;lt;/math&amp;gt; possible gate inputs. It follows that the number of circuits with &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; gates is at most &amp;lt;math&amp;gt;2^t(t+2n+1)^{2t}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;t=2^n/3n&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{2^t(t+2n+1)^{2t}}{2^{2^n}}=o(1)&amp;lt;1,&amp;lt;/math&amp;gt;      thus, &amp;lt;math&amp;gt;2^t(t+2n+1)^{2t} &amp;lt; 2^{2^n}.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each boolean circuit computes one boolean function. Therefore, there must exist a boolean function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; which cannot be computed by any circuits with &amp;lt;math&amp;gt;2^n/3n&amp;lt;/math&amp;gt; gates.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Note that by Shannon&#039;s theorem, not only there exists a boolean function with exponentially large circuit complexity, but &#039;&#039;almost all&#039;&#039; boolean functions have exponentially large circuit complexity.&lt;br /&gt;
&lt;br /&gt;
=== Double counting ===&lt;br /&gt;
;Handshaking lemma&lt;br /&gt;
{{Theorem|Handshaking Lemma|&lt;br /&gt;
:At a party, the number of guests who shake hands an odd number of times is even.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
We model this scenario as an undirected graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|V|=n&amp;lt;/math&amp;gt; standing for the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; guests. There is an edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; shake hands. Let &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; be the degree of vertex &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;, which represents the number of times that &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; shakes hand. The handshaking lemma states that in any undirected graph, the sum of odd degrees is even.&lt;br /&gt;
&lt;br /&gt;
The handshaking lemma is a direct consequence of the following lemma, which is proved by Euler in a 1736 paper that began the study of graph theory.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma (Euler 1736)|&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{v\in V}d(v)=2|E|&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
We count the number of &#039;&#039;&#039;directed&#039;&#039;&#039; edges. A directed edge is an ordered pair &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;\{u,v\}\in E&amp;lt;/math&amp;gt;. There are two ways to count the directed edges.&lt;br /&gt;
&lt;br /&gt;
First, we can enumerate by edges. Pick every edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt; and apply two directions &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;(v,u)&amp;lt;/math&amp;gt; to the edge. This gives us &amp;lt;math&amp;gt;2|E|&amp;lt;/math&amp;gt; directed edges.&lt;br /&gt;
&lt;br /&gt;
On the other hand, we can enumerate by vertices. Pick every vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt; and for each of its &amp;lt;math&amp;gt;d(v)&amp;lt;/math&amp;gt; neighbors, say &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt;, generate a directed edge &amp;lt;math&amp;gt;(v,u)&amp;lt;/math&amp;gt;. This gives us &amp;lt;math&amp;gt;\sum_{v\in V}d(v)&amp;lt;/math&amp;gt; directed edges.&lt;br /&gt;
&lt;br /&gt;
It is obvious that the two terms are equal, since we just count the same thing twice with different methods. The lemma follows.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The handshaking lemma is implied directly by the above lemma, since the sum of even degrees is even.&lt;br /&gt;
&lt;br /&gt;
;Cayley&#039;s formula&lt;br /&gt;
{{Theorem|Caylay&#039;s formula for trees|&lt;br /&gt;
: There are &amp;lt;math&amp;gt;n^{n-2}&amp;lt;/math&amp;gt; different trees on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; distinct vertices.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== The Pigeonhole Principle ==&lt;br /&gt;
&lt;br /&gt;
=== Monotonic subsequences ===&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Erdős-Szekeres 1935)|&lt;br /&gt;
:A sequence of more than &amp;lt;math&amp;gt;mn&amp;lt;/math&amp;gt; different real numbers must contain either an increasing subsequence of length &amp;lt;math&amp;gt;m+1&amp;lt;/math&amp;gt;, or a decreasing subsequence of length &amp;lt;math&amp;gt;n+1&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|(due to Seidenberg 1959)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== The Probabilistic Method ==&lt;br /&gt;
&lt;br /&gt;
Suppose we want prove the existence of mathematic objects with certain properties. One way to do so is to explicitly construct such an object. This kind of proofs can be interpreted as &#039;&#039;deterministic algorithms&#039;&#039; which find the object with desirable properties.&lt;br /&gt;
&lt;br /&gt;
The probabilistic method provides another way of proving the existence of objects: instead of explicitly constructing an object, we define a probability space of objects in which the probability is positive that a randomly selected object has the required property.&lt;br /&gt;
&lt;br /&gt;
The basic principle of the probabilistic method is very simple, and can be stated in intuitive ways:&lt;br /&gt;
*If an object chosen randomly from a universe satisfies a property with positive probability, then there must be an object in the universe that satisfies that property.&lt;br /&gt;
:For example, for a ball(the object) randomly chosen from a box(the universe) of balls, if the probability that the chosen ball is blue(the property) is &amp;gt;0, then there must be a blue ball in the box.&lt;br /&gt;
*Any random variable assumes at least one value that is no smaller than its expectation, and at least one value that is no greater than the expectation.&lt;br /&gt;
:For example, if we know the average height of the students in the class is &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;, then we know there is a students whose height is at least &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;, and there is a student whose height is at most &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Although the idea of  the probabilistic method is simple, it provides us a powerful tool for existential proof. In same cases, the proof itself is a &#039;&#039;randomized algorithm&#039;&#039;, and if we are lucky, the algorithm could be very efficient.&lt;br /&gt;
&lt;br /&gt;
=== Sampling ===&lt;br /&gt;
;Ramsey number&lt;br /&gt;
&lt;br /&gt;
Recall the Ramsey theorem which states that in a meeting of at least six people, there are either three people knowing each other or three people not knowing each other. In graph theoretical terms, this means that no matter how we color the edges of &amp;lt;math&amp;gt;K_6&amp;lt;/math&amp;gt; (the complete graph on six vertices), there must be a &#039;&#039;&#039;monochromatic&#039;&#039;&#039; &amp;lt;math&amp;gt;K_3&amp;lt;/math&amp;gt; (a triangle whose edges have the same color).&lt;br /&gt;
&lt;br /&gt;
Generally, the &#039;&#039;&#039;Ramsey number&#039;&#039;&#039; &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt; is the smallest integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; such that in any two-coloring of the edges of a complete graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; by red and blue, either there is a red &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; or there is a blue &amp;lt;math&amp;gt;K_\ell&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ramsey showed in 1929 that &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt; is finite for any &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;. It is extremely hard to compute the exact value of &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt;. Here we give a lower bound of &amp;lt;math&amp;gt;R(k,k)&amp;lt;/math&amp;gt; by the probabilistic method.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem (Erdős 1947)|&lt;br /&gt;
:If &amp;lt;math&amp;gt;{n\choose k}\cdot 2^{1-{k\choose 2}}&amp;lt;1&amp;lt;/math&amp;gt; then it is possible to color the edges of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; with two colors so that there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Consider a random two-coloring of edges of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; obtained as follows:&lt;br /&gt;
* For each edge of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt;, independently flip a fair coin to decide the color of the edge.&lt;br /&gt;
&lt;br /&gt;
For any fixed set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, let &amp;lt;math&amp;gt;\mathcal{E}_S&amp;lt;/math&amp;gt; be the event that the &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph induced by &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is monochromatic. There are &amp;lt;math&amp;gt;{k\choose 2}&amp;lt;/math&amp;gt; many edges in &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt;, therefore&lt;br /&gt;
:&amp;lt;math&amp;gt;\Pr[\mathcal{E}_S]=2\cdot 2^{-{k\choose 2}}=2^{1-{k\choose 2}}.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since there are &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; possible choices of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, by the union bound&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\Pr[\exists S, \mathcal{E}_S]\le {n\choose k}\cdot\Pr[\mathcal{E}_S]={n\choose k}\cdot 2^{1-{k\choose 2}}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Due to the assumption, &amp;lt;math&amp;gt;{n\choose k}\cdot 2^{1-{k\choose 2}}&amp;lt;1&amp;lt;/math&amp;gt;, thus there exists a two coloring that none of &amp;lt;math&amp;gt;\mathcal{E}_S&amp;lt;/math&amp;gt; occurs, which means  there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;k\ge 3&amp;lt;/math&amp;gt; and we take &amp;lt;math&amp;gt;n=\lfloor2^{k/2}\rfloor&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
{n\choose k}\cdot 2^{1-{k\choose 2}}&lt;br /&gt;
&amp;amp;&amp;lt;&lt;br /&gt;
\frac{n^k}{k!}\cdot\frac{2^{1+\frac{k}{2}}}{2^{k^2/2}}\\&lt;br /&gt;
&amp;amp;\le &lt;br /&gt;
\frac{2^{k^2/2}}{k!}\cdot\frac{2^{1+\frac{k}{2}}}{2^{k^2/2}}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{2^{1+\frac{k}{2}}}{k!}\\&lt;br /&gt;
&amp;amp;&amp;lt;1.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
By the above theorem, there exists a two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; that there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt;. Therefore, the Ramsey number &amp;lt;math&amp;gt;R(k,k)&amp;gt;\lfloor2^{k/2}\rfloor&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;k\ge 3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that for sufficiently large &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, if &amp;lt;math&amp;gt;n= \lfloor 2^{k/2}\rfloor&amp;lt;/math&amp;gt;, then the probability that there exists a monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; is bounded by&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
{n\choose k}\cdot 2^{1-{k\choose 2}}&lt;br /&gt;
&amp;lt;&lt;br /&gt;
\frac{2^{1+\frac{k}{2}}}{k!}&lt;br /&gt;
\ll 1,&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
which means that a random two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; is very likely not to contain a monochromatic  &amp;lt;math&amp;gt;K_{2\log n}&amp;lt;/math&amp;gt;. This gives us a very simple randomized algorithm for finding a two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; without monochromatic &amp;lt;math&amp;gt;K_{2\log n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Linearity of expectation ===&lt;br /&gt;
&lt;br /&gt;
;Maximum cut&lt;br /&gt;
&lt;br /&gt;
Given an undirected graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;, a set &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; of edges of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is disconnected after removing the edges in &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt;. We can represent a cut by &amp;lt;math&amp;gt;c(S,T)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;(S,T)&amp;lt;/math&amp;gt; is a bipartition of the vertex set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;c(S,T)=\{uv\in E\mid u\in S,v\in T\}&amp;lt;/math&amp;gt; is the set of edges crossing between &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We have seen how to compute min-cut: either by deterministic max-flow algorithm, or by Karger&#039;s randomized algorithm. On the other hand, max-cut is hard to compute, because it is &#039;&#039;&#039;NP-complete&#039;&#039;&#039;. Actually, the weighted version of max-cut is among the [http://en.wikipedia.org/wiki/Karp&#039;s_21_NP-complete_problems Karp&#039;s 21 NP-complete problems].&lt;br /&gt;
&lt;br /&gt;
We now show by the probabilistic method that a max-cut always has at least half the edges.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:Given an undirected graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges, there is a cut of size at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Enumerate the vertices in an arbitrary order. Partition the vertex set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; into two disjoint sets &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; as follows.&lt;br /&gt;
:For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;,&lt;br /&gt;
:* independently choose one of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; with equal probability, and let &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; join the chosen set.&lt;br /&gt;
&lt;br /&gt;
For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;X_v\in\{S,T\}&amp;lt;/math&amp;gt; be the random variable which represents the set that &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; joins. For each edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;Y_{uv}&amp;lt;/math&amp;gt; be the 0-1 random variable which indicates whether &amp;lt;math&amp;gt;uv&amp;lt;/math&amp;gt; crosses between &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;. Clearly,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\Pr[Y_{uv}=1]=\Pr[X_u\neq X_v]=\frac{1}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of &amp;lt;math&amp;gt;c(S,T)&amp;lt;/math&amp;gt; is given by &amp;lt;math&amp;gt;Y=\sum_{uv\in E}Y_{uv}&amp;lt;/math&amp;gt;. By the linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[Y]=\sum_{uv\in E}\mathbf{E}[Y_{uv}]=\sum_{uv\in E}\Pr[Y_{uv}=1]=\frac{m}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, there exist a bipartition &amp;lt;math&amp;gt;(S,T)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;|c(S,T)|\ge\frac{m}{2}&amp;lt;/math&amp;gt;, i.e. there exists a cut of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; which contains at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; edges.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;Maximum satisfiability&lt;br /&gt;
&lt;br /&gt;
Suppose that we have a number of boolean variables &amp;lt;math&amp;gt;x_1,x_2,\ldots,\in\{\mathrm{true},\mathrm{false}\}&amp;lt;/math&amp;gt;. A &#039;&#039;&#039;literal&#039;&#039;&#039; is either a variable &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; itself or its negation &amp;lt;math&amp;gt;\neg x_i&amp;lt;/math&amp;gt;. A logic expression is a &#039;&#039;&#039;conjunctive normal form (CNF)&#039;&#039;&#039; if it is written as the conjunction(AND) of a set of &#039;&#039;&#039;clauses&#039;&#039;&#039;, where each clause is a disjunction(OR) of literals. For example:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(x_1\vee \neg x_2 \vee \neg x_3)\wedge (\neg x_1\vee \neg x_3)\wedge (x_1\vee x_2\vee x_4)\wedge (x_4\vee \neg x_3)\wedge (x_4\vee \neg x_1).&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The satisfiability (SAT) problem ask whether the CNF is satisfiable, i.e. there exists an assignment of variables to the values of true and false so that all clauses are true. The maximum satisfiability (MAXSAT) is the optimization version of SAT, which ask for an assignment that the number of satisfied clauses is maximized.&lt;br /&gt;
&lt;br /&gt;
SAT is the first problem known to be &#039;&#039;&#039;NP-complete&#039;&#039;&#039; (the Cook-Levin theorem). MAXSAT is also &#039;&#039;&#039;NP-complete&#039;&#039;&#039;. We then see that there always exists a roughly good truth assignment which satisfies half the clauses.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:For any set of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; clauses, there is a truth assignment that satisfies at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; clauses.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| For each variable, independently assign a random value in &amp;lt;math&amp;gt;\{\mathrm{true},\mathrm{false}\}&amp;lt;/math&amp;gt; with equal probability. For the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;th clause, let &amp;lt;math&amp;gt;X_i&amp;lt;/math&amp;gt; be the random variable which indicates whether the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;th clause is satisfied. Suppose that there are &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; literals in the clause. The probability that the clause is satisfied is &lt;br /&gt;
:&amp;lt;math&amp;gt;\Pr[X_k=1]\ge(1-2^{-k})\ge\frac{1}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;X=\sum_{i=1}^m X_i&amp;lt;/math&amp;gt; be the number of satisfied clauses. By the linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[X]=\sum_{i=1}^{m}\mathbf{E}[X_i]\ge \frac{m}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, there exists an assignment such that at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; clauses are satisfied.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Alterations ===&lt;br /&gt;
;Independent sets&lt;br /&gt;
An independent set of a graph is a set of vertices with no edges between them. The following theorem gives a lower bound on the size of the largest independent set.&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges. Then &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has an independent set with at least &amp;lt;math&amp;gt;\frac{n^2}{4m}&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Let &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; be a set of vertices constructed as follows:&lt;br /&gt;
:For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;:&lt;br /&gt;
:* &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is included in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; independently with probability &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; to be determined.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;X=|S|&amp;lt;/math&amp;gt;. It is obvious that &amp;lt;math&amp;gt;\mathbf{E}[X]=np&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For each edge &amp;lt;math&amp;gt;e\in E&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;Y_{e}&amp;lt;/math&amp;gt; be the random variable which indicates whether both endpoints of &amp;lt;math&amp;gt;&amp;lt;/math&amp;gt; are in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[Y_{uv}]=\Pr[u\in S\wedge v\in S]=p^2.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Let &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; be the number of edges in the subgraph of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; induced by &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. It holds that &amp;lt;math&amp;gt;Y=\sum_{e\in E}Y_e&amp;lt;/math&amp;gt;. By linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathbf{E}[Y]=\sum_{e\in E}\mathbf{E}[Y_e]=mp^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that although &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is not necessary an independent set, it can be modified to one if for each edge &amp;lt;math&amp;gt;e&amp;lt;/math&amp;gt; of the induced subgraph &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, we delete one of the endpoint of &amp;lt;math&amp;gt;e&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; be the resulting set. It is obvious that &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; is an independent set since there is no edge left in the induced subgraph &amp;lt;math&amp;gt;G(S^*)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Since there are &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; edges in &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, there are at most &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; vertices in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; are deleted to make it become &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;|S^*|\ge X-Y&amp;lt;/math&amp;gt;. By linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[|S^*|]\ge\mathbf{E}[X-Y]=\mathbf{E}[X]-\mathbf{E}[Y]=np-mp^2.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The expectation is maximized when &amp;lt;math&amp;gt;p=\frac{n}{2m}&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[|S^*|]\ge n\cdot\frac{n}{2m}-m\left(\frac{n}{2m}\right)^2=\frac{n^2}{4m}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
There exists an independent set which contains at least &amp;lt;math&amp;gt;\frac{n^2}{4m}&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The proof actually propose a randomized algorithm for constructing large independent set:&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Algorithm|&lt;br /&gt;
Given a graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges, let &amp;lt;math&amp;gt;d=\frac{2m}{n}&amp;lt;/math&amp;gt; be the average degree.&lt;br /&gt;
#For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is included in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; independently with probability &amp;lt;math&amp;gt;\frac{1}{d}&amp;lt;/math&amp;gt;.&lt;br /&gt;
#For each remaining edge in the induced subgraph &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, remove one of the endpoints from &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; be the resulting set. We have shown that &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; is an independent set and &amp;lt;math&amp;gt;\mathbf{E}[|S^*|]\ge\frac{n^2}{4m}&amp;lt;/math&amp;gt;.&lt;/div&gt;</summary>
		<author><name>172.21.6.120</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3022</id>
		<title>Combinatorics (Fall 2010)/Existence, the probabilistic method</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3022"/>
		<updated>2010-09-19T13:32:00Z</updated>

		<summary type="html">&lt;p&gt;172.21.8.48: /* Counting arguments */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting arguments ==&lt;br /&gt;
;Circuit complexity&lt;br /&gt;
&lt;br /&gt;
This is a fundamental problem in in Computer Science.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;boolean function&#039;&#039;&#039; is a function is the form &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, a boolean circuit is a directed acyclic graph. Nodes with indegree zero are input nodes, labeled &amp;lt;math&amp;gt;x_1, x_2, \ldots , x_n&amp;lt;/math&amp;gt;. A circuit has a unique node with outdegree zero, called the output node. Every other node is a gate. There are three types of gates: AND, OR (both with indegree two), and NOT (with indegree one).&lt;br /&gt;
&lt;br /&gt;
Computations in Turing machines can be simulated by circuits, and any boolean function in &#039;&#039;&#039;P&#039;&#039;&#039; can be computed by a circuit with polynomially many gates. Thus, if we can find a function in &#039;&#039;&#039;NP&#039;&#039;&#039; that cannot be computed by any circuit with polynomially many gates, then &#039;&#039;&#039;NP&#039;&#039;&#039;&amp;lt;math&amp;gt;\neq&amp;lt;/math&amp;gt;&#039;&#039;&#039;P&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The following theorem due to Shannon says that functions with exponentially large circuit complexity do exist.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem (Shannon 1949)|&lt;br /&gt;
:There is a boolean function &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt; with circuit complexity greater than &amp;lt;math&amp;gt;\frac{2^n}{3n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| &lt;br /&gt;
We first count the number of boolean functions &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;. There are &amp;lt;math&amp;gt;2^{2^n}&amp;lt;/math&amp;gt; boolean functions &amp;lt;math&amp;gt;f:\{0,1\}^n\rightarrow \{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Then we count the number of boolean circuit with fixed number of gates.&lt;br /&gt;
Fix an integer &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt;, we count the number of circuits with &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; gates. By the [http://en.wikipedia.org/wiki/De_Morgan&#039;s_laws De Morgan&#039;s laws], we can assume that all NOTs are pushed back to the inputs. Each gate has one of the two types (AND or OR), and has two inputs. Each of the inputs to a gate is either a constant 0 or 1, an input variable &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt;, an inverted input variable &amp;lt;math&amp;gt;\neg x_i&amp;lt;/math&amp;gt;, or the output of another gate; thus, there are at most &amp;lt;math&amp;gt;2+2n+t-1&amp;lt;/math&amp;gt; possible gate inputs. It follows that the number of circuits with &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; gates is at most &amp;lt;math&amp;gt;2^t(t+2n+1)^{2t}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
If &amp;lt;math&amp;gt;t=2^n/3n&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{2^t(t+2n+1)^{2t}}{2^{2^n}}=o(1)&amp;lt;1,&amp;lt;/math&amp;gt;      thus, &amp;lt;math&amp;gt;2^t(t+2n+1)^{2t} &amp;lt; 2^{2^n}.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each boolean circuit computes one boolean function. Therefore, there must exist a boolean function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; which cannot be computed by any circuits with &amp;lt;math&amp;gt;2^n/3n&amp;lt;/math&amp;gt; gates.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Note that by Shannon&#039;s theorem, not only there exists a boolean function with exponentially large circuit complexity, but &#039;&#039;almost all&#039;&#039; boolean functions have exponentially large circuit complexity.&lt;br /&gt;
&lt;br /&gt;
=== Double counting ===&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Handshaking Lemma|&lt;br /&gt;
:At a party, the number of guests who shake hands an odd number of times is even.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Caylay&#039;s formula for trees|&lt;br /&gt;
: There are &amp;lt;math&amp;gt;n^{n-2}&amp;lt;/math&amp;gt; different trees on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; distinct vertices.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== The Pigeonhole Principle ==&lt;br /&gt;
&lt;br /&gt;
== The Probabilistic Method ==&lt;br /&gt;
&lt;br /&gt;
Suppose we want prove the existence of mathematic objects with certain properties. One way to do so is to explicitly construct such an object. This kind of proofs can be interpreted as &#039;&#039;deterministic algorithms&#039;&#039; which find the object with desirable properties.&lt;br /&gt;
&lt;br /&gt;
The probabilistic method provides another way of proving the existence of objects: instead of explicitly constructing an object, we define a probability space of objects in which the probability is positive that a randomly selected object has the required property.&lt;br /&gt;
&lt;br /&gt;
The basic principle of the probabilistic method is very simple, and can be stated in intuitive ways:&lt;br /&gt;
*If an object chosen randomly from a universe satisfies a property with positive probability, then there must be an object in the universe that satisfies that property.&lt;br /&gt;
:For example, for a ball(the object) randomly chosen from a box(the universe) of balls, if the probability that the chosen ball is blue(the property) is &amp;gt;0, then there must be a blue ball in the box.&lt;br /&gt;
*Any random variable assumes at least one value that is no smaller than its expectation, and at least one value that is no greater than the expectation.&lt;br /&gt;
:For example, if we know the average height of the students in the class is &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;, then we know there is a students whose height is at least &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;, and there is a student whose height is at most &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Although the idea of  the probabilistic method is simple, it provides us a powerful tool for existential proof. In same cases, the proof itself is a &#039;&#039;randomized algorithm&#039;&#039;, and if we are lucky, the algorithm could be very efficient.&lt;br /&gt;
&lt;br /&gt;
=== Sampling ===&lt;br /&gt;
;Ramsey number&lt;br /&gt;
&lt;br /&gt;
Recall the Ramsey theorem which states that in a meeting of at least six people, there are either three people knowing each other or three people not knowing each other. In graph theoretical terms, this means that no matter how we color the edges of &amp;lt;math&amp;gt;K_6&amp;lt;/math&amp;gt; (the complete graph on six vertices), there must be a &#039;&#039;&#039;monochromatic&#039;&#039;&#039; &amp;lt;math&amp;gt;K_3&amp;lt;/math&amp;gt; (a triangle whose edges have the same color).&lt;br /&gt;
&lt;br /&gt;
Generally, the &#039;&#039;&#039;Ramsey number&#039;&#039;&#039; &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt; is the smallest integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; such that in any two-coloring of the edges of a complete graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; by red and blue, either there is a red &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; or there is a blue &amp;lt;math&amp;gt;K_\ell&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Ramsey showed in 1929 that &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt; is finite for any &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt;. It is extremely hard to compute the exact value of &amp;lt;math&amp;gt;R(k,\ell)&amp;lt;/math&amp;gt;. Here we give a lower bound of &amp;lt;math&amp;gt;R(k,k)&amp;lt;/math&amp;gt; by the probabilistic method.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem (Erdős 1947)|&lt;br /&gt;
:If &amp;lt;math&amp;gt;{n\choose k}\cdot 2^{1-{k\choose 2}}&amp;lt;1&amp;lt;/math&amp;gt; then it is possible to color the edges of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; with two colors so that there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Consider a random two-coloring of edges of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; obtained as follows:&lt;br /&gt;
* For each edge of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt;, independently flip a fair coin to decide the color of the edge.&lt;br /&gt;
&lt;br /&gt;
For any fixed set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, let &amp;lt;math&amp;gt;\mathcal{E}_S&amp;lt;/math&amp;gt; be the event that the &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph induced by &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is monochromatic. There are &amp;lt;math&amp;gt;{k\choose 2}&amp;lt;/math&amp;gt; many edges in &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt;, therefore&lt;br /&gt;
:&amp;lt;math&amp;gt;\Pr[\mathcal{E}_S]=2\cdot 2^{-{k\choose 2}}=2^{1-{k\choose 2}}.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since there are &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; possible choices of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, by the union bound&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\Pr[\exists S, \mathcal{E}_S]\le {n\choose k}\cdot\Pr[\mathcal{E}_S]={n\choose k}\cdot 2^{1-{k\choose 2}}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Due to the assumption, &amp;lt;math&amp;gt;{n\choose k}\cdot 2^{1-{k\choose 2}}&amp;lt;1&amp;lt;/math&amp;gt;, thus there exists a two coloring that none of &amp;lt;math&amp;gt;\mathcal{E}_S&amp;lt;/math&amp;gt; occurs, which means  there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; subgraph.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;k\ge 3&amp;lt;/math&amp;gt; and we take &amp;lt;math&amp;gt;n=\lfloor2^{k/2}\rfloor&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
{n\choose k}\cdot 2^{1-{k\choose 2}}&lt;br /&gt;
&amp;amp;&amp;lt;&lt;br /&gt;
\frac{n^k}{k!}\cdot\frac{2^{1+\frac{k}{2}}}{2^{k^2/2}}\\&lt;br /&gt;
&amp;amp;\le &lt;br /&gt;
\frac{2^{k^2/2}}{k!}\cdot\frac{2^{1+\frac{k}{2}}}{2^{k^2/2}}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{2^{1+\frac{k}{2}}}{k!}\\&lt;br /&gt;
&amp;amp;&amp;lt;1.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
By the above theorem, there exists a two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; that there is no monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt;. Therefore, the Ramsey number &amp;lt;math&amp;gt;R(k,k)&amp;gt;\lfloor2^{k/2}\rfloor&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;k\ge 3&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that for sufficiently large &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, if &amp;lt;math&amp;gt;n= \lfloor 2^{k/2}\rfloor&amp;lt;/math&amp;gt;, then the probability that there exists a monochromatic &amp;lt;math&amp;gt;K_k&amp;lt;/math&amp;gt; is bounded by&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
{n\choose k}\cdot 2^{1-{k\choose 2}}&lt;br /&gt;
&amp;lt;&lt;br /&gt;
\frac{2^{1+\frac{k}{2}}}{k!}&lt;br /&gt;
\ll 1,&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
which means that a random two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; is very likely not to contain a monochromatic  &amp;lt;math&amp;gt;K_{2\log n}&amp;lt;/math&amp;gt;. This gives us a very simple randomized algorithm for finding a two-coloring of &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt; without monochromatic &amp;lt;math&amp;gt;K_{2\log n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Linearity of expectation ===&lt;br /&gt;
&lt;br /&gt;
;Maximum cut&lt;br /&gt;
&lt;br /&gt;
Given an undirected graph &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt;, a set &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt; of edges of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;cut&#039;&#039;&#039; if &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; is disconnected after removing the edges in &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt;. We can represent a cut by &amp;lt;math&amp;gt;c(S,T)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;(S,T)&amp;lt;/math&amp;gt; is a bipartition of the vertex set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;c(S,T)=\{uv\in E\mid u\in S,v\in T\}&amp;lt;/math&amp;gt; is the set of edges crossing between &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We have seen how to compute min-cut: either by deterministic max-flow algorithm, or by Karger&#039;s randomized algorithm. On the other hand, max-cut is hard to compute, because it is &#039;&#039;&#039;NP-complete&#039;&#039;&#039;. Actually, the weighted version of max-cut is among the [http://en.wikipedia.org/wiki/Karp&#039;s_21_NP-complete_problems Karp&#039;s 21 NP-complete problems].&lt;br /&gt;
&lt;br /&gt;
We now show by the probabilistic method that a max-cut always has at least half the edges.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:Given an undirected graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges, there is a cut of size at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Enumerate the vertices in an arbitrary order. Partition the vertex set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; into two disjoint sets &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; as follows.&lt;br /&gt;
:For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;,&lt;br /&gt;
:* independently choose one of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; with equal probability, and let &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; join the chosen set.&lt;br /&gt;
&lt;br /&gt;
For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;X_v\in\{S,T\}&amp;lt;/math&amp;gt; be the random variable which represents the set that &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; joins. For each edge &amp;lt;math&amp;gt;uv\in E&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;Y_{uv}&amp;lt;/math&amp;gt; be the 0-1 random variable which indicates whether &amp;lt;math&amp;gt;uv&amp;lt;/math&amp;gt; crosses between &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt;. Clearly,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\Pr[Y_{uv}=1]=\Pr[X_u\neq X_v]=\frac{1}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of &amp;lt;math&amp;gt;c(S,T)&amp;lt;/math&amp;gt; is given by &amp;lt;math&amp;gt;Y=\sum_{uv\in E}Y_{uv}&amp;lt;/math&amp;gt;. By the linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[Y]=\sum_{uv\in E}\mathbf{E}[Y_{uv}]=\sum_{uv\in E}\Pr[Y_{uv}=1]=\frac{m}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, there exist a bipartition &amp;lt;math&amp;gt;(S,T)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;|c(S,T)|\ge\frac{m}{2}&amp;lt;/math&amp;gt;, i.e. there exists a cut of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; which contains at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; edges.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;Maximum satisfiability&lt;br /&gt;
&lt;br /&gt;
Suppose that we have a number of boolean variables &amp;lt;math&amp;gt;x_1,x_2,\ldots,\in\{\mathrm{true},\mathrm{false}\}&amp;lt;/math&amp;gt;. A &#039;&#039;&#039;literal&#039;&#039;&#039; is either a variable &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; itself or its negation &amp;lt;math&amp;gt;\neg x_i&amp;lt;/math&amp;gt;. A logic expression is a &#039;&#039;&#039;conjunctive normal form (CNF)&#039;&#039;&#039; if it is written as the conjunction(AND) of a set of &#039;&#039;&#039;clauses&#039;&#039;&#039;, where each clause is a disjunction(OR) of literals. For example:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(x_1\vee \neg x_2 \vee \neg x_3)\wedge (\neg x_1\vee \neg x_3)\wedge (x_1\vee x_2\vee x_4)\wedge (x_4\vee \neg x_3)\wedge (x_4\vee \neg x_1).&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The satisfiability (SAT) problem ask whether the CNF is satisfiable, i.e. there exists an assignment of variables to the values of true and false so that all clauses are true. The maximum satisfiability (MAXSAT) is the optimization version of SAT, which ask for an assignment that the number of satisfied clauses is maximized.&lt;br /&gt;
&lt;br /&gt;
SAT is the first problem known to be &#039;&#039;&#039;NP-complete&#039;&#039;&#039; (the Cook-Levin theorem). MAXSAT is also &#039;&#039;&#039;NP-complete&#039;&#039;&#039;. We then see that there always exists a roughly good truth assignment which satisfies half the clauses.&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:For any set of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; clauses, there is a truth assignment that satisfies at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; clauses.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| For each variable, independently assign a random value in &amp;lt;math&amp;gt;\{\mathrm{true},\mathrm{false}\}&amp;lt;/math&amp;gt; with equal probability. For the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;th clause, let &amp;lt;math&amp;gt;X_i&amp;lt;/math&amp;gt; be the random variable which indicates whether the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;th clause is satisfied. Suppose that there are &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; literals in the clause. The probability that the clause is satisfied is &lt;br /&gt;
:&amp;lt;math&amp;gt;\Pr[X_k=1]\ge(1-2^{-k})\ge\frac{1}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;X=\sum_{i=1}^m X_i&amp;lt;/math&amp;gt; be the number of satisfied clauses. By the linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[X]=\sum_{i=1}^{m}\mathbf{E}[X_i]\ge \frac{m}{2}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, there exists an assignment such that at least &amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt; clauses are satisfied.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Alterations ===&lt;br /&gt;
;Independent sets&lt;br /&gt;
An independent set of a graph is a set of vertices with no edges between them. The following theorem gives a lower bound on the size of the largest independent set.&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Theorem|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(V,E)&amp;lt;/math&amp;gt; be a graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges. Then &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has an independent set with at least &amp;lt;math&amp;gt;\frac{n^2}{4m}&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof| Let &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; be a set of vertices constructed as follows:&lt;br /&gt;
:For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;:&lt;br /&gt;
:* &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is included in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; independently with probability &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;,&lt;br /&gt;
&amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; to be determined.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;X=|S|&amp;lt;/math&amp;gt;. It is obvious that &amp;lt;math&amp;gt;\mathbf{E}[X]=np&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For each edge &amp;lt;math&amp;gt;e\in E&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;Y_{e}&amp;lt;/math&amp;gt; be the random variable which indicates whether both endpoints of &amp;lt;math&amp;gt;&amp;lt;/math&amp;gt; are in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[Y_{uv}]=\Pr[u\in S\wedge v\in S]=p^2.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Let &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; be the number of edges in the subgraph of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; induced by &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. It holds that &amp;lt;math&amp;gt;Y=\sum_{e\in E}Y_e&amp;lt;/math&amp;gt;. By linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;\mathbf{E}[Y]=\sum_{e\in E}\mathbf{E}[Y_e]=mp^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that although &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is not necessary an independent set, it can be modified to one if for each edge &amp;lt;math&amp;gt;e&amp;lt;/math&amp;gt; of the induced subgraph &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, we delete one of the endpoint of &amp;lt;math&amp;gt;e&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; be the resulting set. It is obvious that &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; is an independent set since there is no edge left in the induced subgraph &amp;lt;math&amp;gt;G(S^*)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Since there are &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; edges in &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, there are at most &amp;lt;math&amp;gt;Y&amp;lt;/math&amp;gt; vertices in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; are deleted to make it become &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;|S^*|\ge X-Y&amp;lt;/math&amp;gt;. By linearity of expectation,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[|S^*|]\ge\mathbf{E}[X-Y]=\mathbf{E}[X]-\mathbf{E}[Y]=np-mp^2.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The expectation is maximized when &amp;lt;math&amp;gt;p=\frac{n}{2m}&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\mathbf{E}[|S^*|]\ge n\cdot\frac{n}{2m}-m\left(\frac{n}{2m}\right)^2=\frac{n^2}{4m}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
There exists an independent set which contains at least &amp;lt;math&amp;gt;\frac{n^2}{4m}&amp;lt;/math&amp;gt; vertices.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The proof actually propose a randomized algorithm for constructing large independent set:&lt;br /&gt;
&lt;br /&gt;
{{Theorem&lt;br /&gt;
|Algorithm|&lt;br /&gt;
Given a graph on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices with &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; edges, let &amp;lt;math&amp;gt;d=\frac{2m}{n}&amp;lt;/math&amp;gt; be the average degree.&lt;br /&gt;
#For each vertex &amp;lt;math&amp;gt;v\in V&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is included in &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; independently with probability &amp;lt;math&amp;gt;\frac{1}{d}&amp;lt;/math&amp;gt;.&lt;br /&gt;
#For each remaining edge in the induced subgraph &amp;lt;math&amp;gt;G(S)&amp;lt;/math&amp;gt;, remove one of the endpoints from &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; be the resulting set. We have shown that &amp;lt;math&amp;gt;S^*&amp;lt;/math&amp;gt; is an independent set and &amp;lt;math&amp;gt;\mathbf{E}[|S^*|]\ge\frac{n^2}{4m}&amp;lt;/math&amp;gt;.&lt;/div&gt;</summary>
		<author><name>172.21.8.48</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Partitions,_sieve_methods&amp;diff=3002</id>
		<title>Combinatorics (Fall 2010)/Partitions, sieve methods</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Partitions,_sieve_methods&amp;diff=3002"/>
		<updated>2010-09-12T06:33:00Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.108: /* Reference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Partitions ==&lt;br /&gt;
We count the ways of partitioning &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &#039;&#039;identical&#039;&#039; objects into &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; &#039;&#039;unordered&#039;&#039; groups. This is equivalent to counting the ways partitioning a number &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; into &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; unordered parts.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partition&#039;&#039;&#039; of a number &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a multiset &amp;lt;math&amp;gt;\{x_1,x_2,\ldots,x_k\}&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;x_i\ge 1&amp;lt;/math&amp;gt; for every element &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We define &amp;lt;math&amp;gt;p_k(n)&amp;lt;/math&amp;gt; as the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example, number 7 has the following partitions:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
&amp;amp;\{7\}&lt;br /&gt;
&amp;amp; p_1(7)=1\\&lt;br /&gt;
&amp;amp;\{1,6\},\{2,5\},\{3,4\}&lt;br /&gt;
&amp;amp; p_2(7)=3\\&lt;br /&gt;
&amp;amp;\{1,1,5\}, \{1,2,4\}, \{1,3,3\}, \{2,2,3\} &lt;br /&gt;
&amp;amp; p_3(7)=4\\&lt;br /&gt;
&amp;amp;\{1,1,1,4\},\{1,1,2,3\}, \{1,2,2,2\}&lt;br /&gt;
&amp;amp; p_4(7)=3\\&lt;br /&gt;
&amp;amp;\{1,1,1,1,3\},\{1,1,1,2,2\}&lt;br /&gt;
&amp;amp; p_5(7)=2\\&lt;br /&gt;
&amp;amp;\{1,1,1,1,1,2\}&lt;br /&gt;
&amp;amp; p_6(7)=1\\&lt;br /&gt;
&amp;amp;\{1,1,1,1,1,1,1\}&lt;br /&gt;
&amp;amp; p_7(7)=1&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Equivalently, we can also define that A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partition of a number &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-tuple &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; with:&lt;br /&gt;
* &amp;lt;math&amp;gt;x_1\ge x_2\ge\cdots\ge x_k\ge 1&amp;lt;/math&amp;gt;;&lt;br /&gt;
* &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;p_k(n)&amp;lt;/math&amp;gt; the number of integral solutions to the above system.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;p(n)=\sum_{k=1}^n p_k(n)&amp;lt;/math&amp;gt; be the total number of partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The function &amp;lt;math&amp;gt;p(n)&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;partition number&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Counting &amp;lt;math&amp;gt;p_k(n)&amp;lt;/math&amp;gt;===&lt;br /&gt;
We now try to determine &amp;lt;math&amp;gt;p_k(n)&amp;lt;/math&amp;gt;. Unlike most problems we learned in the last lecture, &amp;lt;math&amp;gt;p_k(n)&amp;lt;/math&amp;gt; does not have a nice closed form formula. We now give a recurrence for &amp;lt;math&amp;gt;p_k(n)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:&amp;lt;math&amp;gt;p_k(n)=p_{k-1}(n-1)+p_k(n-k)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Suppose that &amp;lt;math&amp;gt;(x_1,\ldots,x_k)&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Note that it must hold that&lt;br /&gt;
:&amp;lt;math&amp;gt;x_1\ge x_2\ge \cdots \ge x_k\ge 1&amp;lt;/math&amp;gt;.&lt;br /&gt;
There are two cases: &amp;lt;math&amp;gt;x_k=1&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;x_k&amp;gt;1&amp;lt;/math&amp;gt;.&lt;br /&gt;
;Case 1.&lt;br /&gt;
:If &amp;lt;math&amp;gt;x_k=1&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;(x_1,\cdots,x_{k-1})&amp;lt;/math&amp;gt; is a distinct &amp;lt;math&amp;gt;(k-1)&amp;lt;/math&amp;gt;-partition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;. And every &amp;lt;math&amp;gt;(k-1)&amp;lt;/math&amp;gt;-partition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; can be obtained in this way. Thus the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in this case is &amp;lt;math&amp;gt;p_{k-1}(n-1)&amp;lt;/math&amp;gt;. &lt;br /&gt;
;Case 2.&lt;br /&gt;
:If &amp;lt;math&amp;gt;x_k&amp;gt;1&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;(x_1-1,\cdots,x_{k}-1)&amp;lt;/math&amp;gt; is a distinct &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partition of &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt;. And every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partition of &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; can be obtained in this way. Thus the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; in this case is &amp;lt;math&amp;gt;p_{k}(n-k)&amp;lt;/math&amp;gt;. &lt;br /&gt;
In conclusion, the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;p_{k-1}(n-1)+p_k(n-k)&amp;lt;/math&amp;gt;, i.e.&lt;br /&gt;
:&amp;lt;math&amp;gt;p_k(n)=p_{k-1}(n-1)+p_k(n-k)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Use the above recurrence, we can compute the &amp;lt;math&amp;gt;p_k(n)&amp;lt;/math&amp;gt;  for some decent &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; by computer simulation.&lt;br /&gt;
&lt;br /&gt;
If we are not restricted ourselves to the precise estimation of &amp;lt;math&amp;gt;p_k(n)&amp;lt;/math&amp;gt;, the next theorem gives an asymptotic estimation of &amp;lt;math&amp;gt;p_k(n)&amp;lt;/math&amp;gt;. Note that it only holds for &#039;&#039;&#039;constant&#039;&#039;&#039; &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, i.e. &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; does not depend on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
For any fixed &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;,&lt;br /&gt;
:&amp;lt;math&amp;gt;p_k(n)\sim\frac{n^{k-1}}{k!(k-1)!}&amp;lt;/math&amp;gt;,&lt;br /&gt;
as &amp;lt;math&amp;gt;n\rightarrow \infty&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Suppose that &amp;lt;math&amp;gt;(x_1,\ldots,x_k)&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1\ge x_2\ge \cdots \ge x_k\ge 1&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;k!&amp;lt;/math&amp;gt; permutations of &amp;lt;math&amp;gt;(x_1,\ldots,x_k)&amp;lt;/math&amp;gt; yield at most &amp;lt;math&amp;gt;k!&amp;lt;/math&amp;gt; many &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions (the &#039;&#039;ordered&#039;&#039; sum of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; positive integers). There are &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt; many &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, every one of which can be yielded in this way by permuting a partition. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;k!p_k(n)\ge{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;y_i=x_i+k-i&amp;lt;/math&amp;gt;. That is, &amp;lt;math&amp;gt;y_k=x_k, y_{k-1}=x_k+1, y_{k-2}=x_k+2,\ldots, y_{1}=x_k+k-1&amp;lt;/math&amp;gt;. Then, it holds that&lt;br /&gt;
* &amp;lt;math&amp;gt;y_1&amp;gt;y_2&amp;gt;\cdots&amp;gt;y_k\ge 1&amp;lt;/math&amp;gt;; and &lt;br /&gt;
* &amp;lt;math&amp;gt;y_1+y_2+\cdots+y_k=n+\frac{k(k-1)}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Each permutation of &amp;lt;math&amp;gt;(y_1,y_2,\ldots,y_k)&amp;lt;/math&amp;gt; yields a &#039;&#039;&#039;distinct&#039;&#039;&#039; &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n+\frac{k(k-1)}{2}&amp;lt;/math&amp;gt;, because all &amp;lt;math&amp;gt;y_i&amp;lt;/math&amp;gt; are distinct.&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;k!p_k(n)\le {n+\frac{k(k-1)}{2}-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Combining the two inequalities, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{{n-1\choose k-1}}{k!}\le p_k(n)\le \frac{{n+\frac{k(k-1)}{2}-1\choose k-1}}{k!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The theorem follows.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Ferrers diagram ===&lt;br /&gt;
A partition of a number &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be represented as a diagram of dots (or squares), called a &#039;&#039;&#039;Ferrers diagram&#039;&#039;&#039; (the square version of Ferrers diagram is also called a &#039;&#039;&#039;Young diagram&#039;&#039;&#039;, named after a structured called Young tableaux). &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; with that &amp;lt;math&amp;gt;x_1\ge x_2\ge \cdots x_k\ge 1&amp;lt;/math&amp;gt; be a partition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Its Ferrers diagram consists of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; rows, where the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;-th row contains &amp;lt;math&amp;gt;x_i&amp;lt;/math&amp;gt; dots (or squares).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
{|border=&amp;quot;0&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
{|border=&amp;quot;0&amp;quot;&lt;br /&gt;
|[[File:Chess xot45.svg|22px]]||[[File:Chess xot45.svg|22px]]||[[File:Chess xot45.svg|22px]]||[[File:Chess xot45.svg|22px]]||[[File:Chess xot45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess xot45.svg|22px]]||[[File:Chess xot45.svg|22px]]||[[File:Chess xot45.svg|22px]]||[[File:Chess xot45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess xot45.svg|22px]]||[[File:Chess xot45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess xot45.svg|22px]]&lt;br /&gt;
|}&lt;br /&gt;
|&lt;br /&gt;
[[File:Chess t45.svg|120px]]&lt;br /&gt;
|align=center|&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
|align=center|Ferrers diagram (&#039;&#039;dot version&#039;&#039;) of (5,4,2,1)||&lt;br /&gt;
|align=center|Ferrers diagram (&#039;&#039;square version&#039;&#039;) of (5,4,2,1)&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
;Conjugate partition&lt;br /&gt;
The partition we get by reading the Ferrers diagram by column instead of rows is called the &#039;&#039;&#039;conjugate&#039;&#039;&#039; of the original partition.&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&lt;br /&gt;
{|border=&amp;quot;0&amp;quot;&lt;br /&gt;
|align=center|&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]&lt;br /&gt;
|}&lt;br /&gt;
|&lt;br /&gt;
[[File:Chess t45.svg|120px]]&lt;br /&gt;
|align=center|&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]||[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]&lt;br /&gt;
|-&lt;br /&gt;
|[[File:Chess t45.svg|22px]]&lt;br /&gt;
|}&lt;br /&gt;
|-&lt;br /&gt;
|align=center|&amp;lt;math&amp;gt;(6,4,4,2,1)&amp;lt;/math&amp;gt;||&lt;br /&gt;
|align=center|conjugate: &amp;lt;math&amp;gt;(5,4,3,3,1,1)&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Clearly, &lt;br /&gt;
* different partitions cannot have the same conjugate, and &lt;br /&gt;
* every partition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is the conjugate of some partition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;,&lt;br /&gt;
so the conjugation mapping is a permutation on the set of partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This fact is very useful in proving theorems for partitions numbers.&lt;br /&gt;
&lt;br /&gt;
Some theorems of partitions can be easily proved by representing partitions in Ferrers diagrams.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
# The number of partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; which have largest summand &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, is &amp;lt;math&amp;gt;p_k(n)&amp;lt;/math&amp;gt;. &lt;br /&gt;
# The number of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; into &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; parts equals the number of partitions of &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; into at most &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; parts. Formally,&lt;br /&gt;
::&amp;lt;math&amp;gt;p_k(n)=\sum_{j=1}^k p_j(n-k)&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
# For every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partition, the conjugate partition has largest part &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. And vice versa.&lt;br /&gt;
# For a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, remove the leftmost cell of every row of the Ferrers diagram. Totally &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; cells are removed and the remaining diagram is a partition of &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; into at most &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; parts. And for a partition of &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; into at most &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; parts, add a cell to each of the &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; rows (including the empty ones). This will give us a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-partition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. It is easy to see the above mappings are 1-1 correspondences. Thus, the number of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; into &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; parts equals the number of partitions of &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; into at most &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; parts.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Principle of Inclusion-Exclusion ==&lt;br /&gt;
Let &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; be two finite sets. The cardinality of their union is&lt;br /&gt;
:&amp;lt;math&amp;gt;|A\cup B|=|A|+|B|-{\color{Blue}|A\cap B|}&amp;lt;/math&amp;gt;.&lt;br /&gt;
For three sets &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;C&amp;lt;/math&amp;gt;, the cardinality of the union of these three sets is computed as&lt;br /&gt;
:&amp;lt;math&amp;gt;|A\cup B\cup C|=|A|+|B|+|C|-{\color{Blue}|A\cap B|}-{\color{Blue}|A\cap C|}-{\color{Blue}|B\cap C|}+{\color{Red}|A\cap B\cap C|}&amp;lt;/math&amp;gt;.&lt;br /&gt;
This is illustrated by the following figure.&lt;br /&gt;
::[[Image:Inclusion-exclusion.png|200px|border|center]] &lt;br /&gt;
&lt;br /&gt;
Generally, the &#039;&#039;&#039;Principle of Inclusion-Exclusion&#039;&#039;&#039; states the rule for computing the union of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; finite sets &amp;lt;math&amp;gt;A_1,A_2,\ldots,A_n&amp;lt;/math&amp;gt;, such that&lt;br /&gt;
{{Equation|&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\left|\bigcup_{i=1}^nA_i\right|&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{I\subseteq\{1,\ldots,n\}}(-1)^{|I|-1}\left|\bigcap_{i\in I}A_i\right|.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
-----&lt;br /&gt;
&lt;br /&gt;
In combinatorial enumeration, the Principle of Inclusion-Exclusion is usually applied in its complement form.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;A_1,A_2,\ldots,A_n\subseteq U&amp;lt;/math&amp;gt; be subsets of some finite set &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. Here &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; is some universe of combinatorial objects, whose cardinality is easy to calculate (e.g. all strings, tuples, permutations), and each &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt; contains the objects with some specific property (e.g. a &amp;quot;pattern&amp;quot;) which we want to avoid. The problem is to count the number of objects without any of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; properties. We write &amp;lt;math&amp;gt;\bar{A_i}=U-A&amp;lt;/math&amp;gt;. The number of objects without any of the properties &amp;lt;math&amp;gt;A_1,A_2,\ldots,A_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
{{Equation|&lt;br /&gt;
&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\left|\bar{A_1}\cap\bar{A_2}\cap\cdots\cap\bar{A_n}\right|=\left|U-\bigcup_{i=1}^nA_i\right|&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
|U|-\sum_{I\subseteq\{1,\ldots,n\}}(-1)^{|I|}\left|\bigcap_{i\in I}A_i\right|.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
For an &amp;lt;math&amp;gt;I\subseteq\{1,2,\ldots,n\}&amp;lt;/math&amp;gt;, we denote&lt;br /&gt;
:&amp;lt;math&amp;gt;A_I=\bigcap_{i\in I}A_i&amp;lt;/math&amp;gt;&lt;br /&gt;
with the convention that &amp;lt;math&amp;gt;A_\emptyset=U&amp;lt;/math&amp;gt;. The above equation is stated as:&lt;br /&gt;
{{Theorem|Principle of Inclusion-Exclusion|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;A_1,A_2,\ldots,A_n&amp;lt;/math&amp;gt; be a family of subsets of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. Then the number of elements of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; which lie in none of the subsets &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt; is&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{I\subseteq\{1,\ldots, n\}}(-1)^{|I|}|A_I|&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S_k=\sum_{|I|=k}|A_I|\,&amp;lt;/math&amp;gt;. Conventionally, &amp;lt;math&amp;gt;S_0=|A_\emptyset|=|U|&amp;lt;/math&amp;gt;. The principle of inclusion-exclusion can be expressed as&lt;br /&gt;
{{Equation|&amp;lt;math&amp;gt;&lt;br /&gt;
S_0-S_1+S_2+\cdots+(-1)^nS_n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Surjections ===&lt;br /&gt;
In the twelvefold way, we discuss the counting problems incurred by the mappings &amp;lt;math&amp;gt;f:N\rightarrow M&amp;lt;/math&amp;gt;. The basic case is that elements from both &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; are distinguishable. In this case, it is easy to count the number of arbitrary mappings (which is &amp;lt;math&amp;gt;m^n&amp;lt;/math&amp;gt;) and the number of injective (one-to-one) mappings (which is &amp;lt;math&amp;gt;(m)_n&amp;lt;/math&amp;gt;), but the number of surjective is difficult. Here we apply the principle of inclusion-exclusion to count the number of surjective (onto) mappings.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:The number of surjective mappings from an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set to an &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-set is given by&lt;br /&gt;
::&amp;lt;math&amp;gt;\sum_{k=1}^m(-1)^{m-k}{m\choose k}k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;U=\{f:[n]\rightarrow[m]\}&amp;lt;/math&amp;gt; be the set of mappings from &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;|U|=m^n&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
For &amp;lt;math&amp;gt;i\in[m]&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt; be the set of mappings &amp;lt;math&amp;gt;f:[n]\rightarrow[m]&amp;lt;/math&amp;gt; that none of &amp;lt;math&amp;gt;j\in[n]&amp;lt;/math&amp;gt; is mapped to &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, i.e. &amp;lt;math&amp;gt;A_i=\{f:[n]\rightarrow[m]\setminus\{i\}\}&amp;lt;/math&amp;gt;, thus &amp;lt;math&amp;gt;|A_i|=(m-1)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
More generally, for &amp;lt;math&amp;gt;I\subseteq [m]&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;A_I=\bigcap_{i\in I}A_i&amp;lt;/math&amp;gt; contains the mappings &amp;lt;math&amp;gt;f:[n]\rightarrow[m]\setminus I&amp;lt;/math&amp;gt;. And &amp;lt;math&amp;gt;|A_I|=(m-|I|)^n\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
A mapping &amp;lt;math&amp;gt;f:[n]\rightarrow[m]&amp;lt;/math&amp;gt; is surjective if &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; lies in none of &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt;. By the principle of inclusion-exclusion, the number of surjective &amp;lt;math&amp;gt;f:[n]\rightarrow[m]&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{I\subseteq[m]}(-1)^{|I|}\left|A_I\right|=\sum_{I\subseteq[m]}(-1)^{|I|}(m-|I|)^n=\sum_{j=0}^m(-1)^j{m\choose j}(m-j)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Let &amp;lt;math&amp;gt;k=m-j&amp;lt;/math&amp;gt;. The theorem is proved.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Recall that, in the twelvefold way, we establish a relation between surjections and partitions.&lt;br /&gt;
&lt;br /&gt;
* Surjection to ordered partition:&lt;br /&gt;
:For a surjective &amp;lt;math&amp;gt;f:[n]\rightarrow[m]&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;(f^{-1}(0),f^{-1}(1),\ldots,f^{-1}(m-1))&amp;lt;/math&amp;gt; is an &#039;&#039;&#039;ordered partition&#039;&#039;&#039; of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Ordered partition to surjection:&lt;br /&gt;
:For an ordered &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-partition &amp;lt;math&amp;gt;(B_0,B_1,\ldots, B_{m-1})&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;, we can define a function &amp;lt;math&amp;gt;f:[n]\rightarrow[m]&amp;lt;/math&amp;gt; by letting &amp;lt;math&amp;gt;f(i)=j&amp;lt;/math&amp;gt; if and only if &amp;lt;math&amp;gt;i\in B_j&amp;lt;/math&amp;gt;. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is surjective since as a partition, none of &amp;lt;math&amp;gt;B_i&amp;lt;/math&amp;gt; is empty.&lt;br /&gt;
&lt;br /&gt;
Therefore, we have a one-to-one correspondence between surjective mappings from an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set to an &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-set and the ordered &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-partitions of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set.&lt;br /&gt;
&lt;br /&gt;
The Stirling number of the second kind &amp;lt;math&amp;gt;S(n,m)&amp;lt;/math&amp;gt; is the number of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-partitions of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. There are &amp;lt;math&amp;gt;m!&amp;lt;/math&amp;gt; ways to order an &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-partition, thus the number of surjective mappings &amp;lt;math&amp;gt;f:[n]\rightarrow[m]&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;m! S(n,m)&amp;lt;/math&amp;gt;. Combining with what we have proved for surjections, we give the following result for the Stirling number of the second kind.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:&amp;lt;math&amp;gt;S(n,m)=\frac{1}{m!}\sum_{k=1}^m(-1)^{m-k}{m\choose k}k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Derangements ===&lt;br /&gt;
We now count the number of bijections from a set to itself with no fixed points. This is the &#039;&#039;&#039;derangement problem&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For a permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;\{1,2,\ldots,n\}&amp;lt;/math&amp;gt;, a &#039;&#039;&#039;fixed point&#039;&#039;&#039; is such an &amp;lt;math&amp;gt;i\in\{1,2,\ldots,n\}&amp;lt;/math&amp;gt; that &amp;lt;math&amp;gt;\pi(i)=i&amp;lt;/math&amp;gt;.&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Derangement &#039;&#039;&#039;derangement&#039;&#039;&#039;] of &amp;lt;math&amp;gt;\{1,2,\ldots,n\}&amp;lt;/math&amp;gt; is a permutation of &amp;lt;math&amp;gt;\{1,2,\ldots,n\}&amp;lt;/math&amp;gt; that has no fixed points.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:The number of derangements of &amp;lt;math&amp;gt;\{1,2,\ldots,n\}&amp;lt;/math&amp;gt; given by&lt;br /&gt;
::&amp;lt;math&amp;gt;n!\sum_{k=0}^n\frac{(-1)^k}{k!}\approx \frac{n!}{\mathrm{e}}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be the set of all permutations of &amp;lt;math&amp;gt;\{1,2,\ldots,n\}&amp;lt;/math&amp;gt;. So &amp;lt;math&amp;gt;|U|=n!&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt; be the set of permutations with fixed point &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;; so &amp;lt;math&amp;gt;|A_i|=(n-1)!&amp;lt;/math&amp;gt;. More generally, for any &amp;lt;math&amp;gt;I\subseteq \{1,2,\ldots,n\}&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;A_I=\bigcap_{i\in I}A_i&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;|A_I|=(n-|I|)!&amp;lt;/math&amp;gt;, since permutations in &amp;lt;math&amp;gt;A_I&amp;lt;/math&amp;gt; fix every point in &amp;lt;math&amp;gt;I&amp;lt;/math&amp;gt; and permute the remaining points arbitrarily. A permutation is a derangement if and only if it lies in none of the sets &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt;. So the number of derangements is&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{I\subseteq\{1,2,\ldots,n\}}(-1)^{|I|}(n-|I|)!=\sum_{k=0}^n(-1)^k{n\choose k}(n-k)!=n!\sum_{k=0}^n\frac{(-1)^k}{k!}.&amp;lt;/math&amp;gt;&lt;br /&gt;
By Taylor&#039;s series,&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{\mathrm{e}}=\sum_{k=0}^\infty\frac{(-1)^k}{k!}=\sum_{k=0}^n\frac{(-1)^k}{k!}\pm o\left(\frac{1}{n!}\right)&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is not hard to see that &amp;lt;math&amp;gt;n!\sum_{k=0}^n\frac{(-1)^k}{k!}&amp;lt;/math&amp;gt; is the closest integer to &amp;lt;math&amp;gt;\frac{n!}{\mathrm{e}}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Therefore, there are about &amp;lt;math&amp;gt;\frac{1}{\mathrm{e}}&amp;lt;/math&amp;gt; fraction of all permutations with no fixed points.&lt;br /&gt;
&lt;br /&gt;
=== Permutations with restricted positions ===&lt;br /&gt;
We introduce a general theory of counting permutations with restricted positions. In the derangement problem, we count the number of permutations that &amp;lt;math&amp;gt;\pi(i)\neq i&amp;lt;/math&amp;gt;. We now generalize to the problem of counting permutations which avoid a set of arbitrarily specified positions. &lt;br /&gt;
&lt;br /&gt;
It is traditionally described using terminology from the game of chess. Let &amp;lt;math&amp;gt;B\subseteq \{1,\ldots,n\}\times \{1,\ldots,n\}&amp;lt;/math&amp;gt;, called a &#039;&#039;&#039;board&#039;&#039;&#039;.  As illustrated below, we can think of &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; as a chess board, with the positions in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; marked by &amp;quot;&amp;lt;math&amp;gt;\times&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
{{Chess diagram small&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|=&lt;br /&gt;
 8 |__|xx|xx|__|xx|__|__|xx|=&lt;br /&gt;
 7 |xx|__|__|xx|__|__|xx|__|=&lt;br /&gt;
 6 |xx|__|xx|xx|__|xx|xx|__|=&lt;br /&gt;
 5 |__|xx|__|__|xx|__|xx|__|=&lt;br /&gt;
 4 |xx|__|__|__|xx|xx|xx|__|=&lt;br /&gt;
 3 |__|xx|__|xx|__|__|__|xx|=&lt;br /&gt;
 2 |__|__|xx|__|xx|__|__|xx|=&lt;br /&gt;
 1 |xx|__|__|xx|__|xx|__|__|=&lt;br /&gt;
 a b c d e f g h&lt;br /&gt;
|&lt;br /&gt;
}}&lt;br /&gt;
For a permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;\{1,\ldots,n\}&amp;lt;/math&amp;gt;, define the &#039;&#039;&#039;graph&#039;&#039;&#039; &amp;lt;math&amp;gt;G_\pi(V,E)&amp;lt;/math&amp;gt; as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G_\pi &amp;amp;= \{(i,\pi(i))\mid i\in \{1,2,\ldots,n\}\}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
This can also be viewed as a set of marked positions on a chess board. Each row and each column has only one marked position, because &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; is a permutation. Thus, we can identify each &amp;lt;math&amp;gt;G_\pi&amp;lt;/math&amp;gt; as a placement of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; rooks (“城堡”，规则同中国象棋里的“车”) without attacking each other.&lt;br /&gt;
&lt;br /&gt;
For example, the following is the &amp;lt;math&amp;gt;G_\pi&amp;lt;/math&amp;gt; of such &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; that &amp;lt;math&amp;gt;\pi(i)=i&amp;lt;/math&amp;gt;.&lt;br /&gt;
{{Chess diagram small&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|=&lt;br /&gt;
 8 |rl|__|__|__|__|__|__|__|=&lt;br /&gt;
 7 |__|rl|__|__|__|__|__|__|=&lt;br /&gt;
 6 |__|__|rl|__|__|__|__|__|=&lt;br /&gt;
 5 |__|__|__|rl|__|__|__|__|=&lt;br /&gt;
 4 |__|__|__|__|rl|__|__|__|=&lt;br /&gt;
 3 |__|__|__|__|__|rl|__|__|=&lt;br /&gt;
 2 |__|__|__|__|__|__|rl|__|=&lt;br /&gt;
 1 |__|__|__|__|__|__|__|rl|=&lt;br /&gt;
 a b c d e f g h&lt;br /&gt;
|&lt;br /&gt;
}}&lt;br /&gt;
Now define&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
N_0 &amp;amp;= \left|\left\{\pi\mid B\cap G_\pi=\emptyset\right\}\right|\\&lt;br /&gt;
r_k &amp;amp;= \mbox{number of }k\mbox{-subsets of }B\mbox{ such that no two elements have a common coordinate}\\&lt;br /&gt;
&amp;amp;=\left|\left\{S\in{B\choose k} \,\bigg|\, \forall (i_1,j_1),(i_2,j_2)\in S, i_1\neq i_2, j_1\neq j_2 \right\}\right|&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Interpreted in chess game,&lt;br /&gt;
* &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;: a set of marked positions in an &amp;lt;math&amp;gt;[n]\times [n]&amp;lt;/math&amp;gt; chess board.&lt;br /&gt;
* &amp;lt;math&amp;gt;N_0&amp;lt;/math&amp;gt;: the number of ways of placing &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; non-attacking rooks on the chess board such that none of these rooks lie in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;: number of ways of placing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; non-attacking rooks on &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Our goal is to count &amp;lt;math&amp;gt;N_0&amp;lt;/math&amp;gt; in terms of &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;. This gives the number of permutations avoid all positions in a &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;N_0=\sum_{k=0}^n(-1)^kr_k(n-k)!&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
For each &amp;lt;math&amp;gt;i\in[n]&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;A_i=\{\pi\mid (i,\pi(i))\in B\}&amp;lt;/math&amp;gt; be the set of permutations &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; whose &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;-th position is in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;N_0&amp;lt;/math&amp;gt; is the number of permutations avoid all positions in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;. Thus, our goal is to count the number of permutations &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; in none of &amp;lt;math&amp;gt;A_i&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;i\in [n]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For each &amp;lt;math&amp;gt;I\subseteq [n]&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;A_I=\bigcap_{i\in I}A_i&amp;lt;/math&amp;gt;, which is the set of permutations &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;(i,\pi(i))\in B&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;i\in I&amp;lt;/math&amp;gt;. Due to the principle of inclusion-exclusion,&lt;br /&gt;
:&amp;lt;math&amp;gt;N_0=\sum_{I\subseteq [n]} (-1)^{|I|}|A_I|=\sum_{k=0}^n(-1)^k\sum_{I\in{[n]\choose k}}|A_I|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The next observation is that &lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{I\in{[n]\choose k}}|A_I|=r_k(n-k)!&amp;lt;/math&amp;gt;,&lt;br /&gt;
because we can count both sides by first placing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; non-attacking rooks on &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; and placing &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; additional non-attacking rooks on &amp;lt;math&amp;gt;[n]\times [n]&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;(n-k)!&amp;lt;/math&amp;gt; ways. &lt;br /&gt;
&lt;br /&gt;
Therefore,&lt;br /&gt;
:&amp;lt;math&amp;gt;N_0=\sum_{k=0}^n(-1)^kr_k(n-k)!&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
====Derangement problem====&lt;br /&gt;
We use the above general method to solve the derange problem again.&lt;br /&gt;
&lt;br /&gt;
Take &amp;lt;math&amp;gt;B=\{(1,1),(2,2),\ldots,(n,n)\}&amp;lt;/math&amp;gt; as the chess board.  A derangement &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; is a placement of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; non-attacking rooks such that none of them is in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;. &lt;br /&gt;
{{Chess diagram small&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|=&lt;br /&gt;
 8 |xx|__|__|__|__|__|__|__|=&lt;br /&gt;
 7 |__|xx|__|__|__|__|__|__|=&lt;br /&gt;
 6 |__|__|xx|__|__|__|__|__|=&lt;br /&gt;
 5 |__|__|__|xx|__|__|__|__|=&lt;br /&gt;
 4 |__|__|__|__|xx|__|__|__|=&lt;br /&gt;
 3 |__|__|__|__|__|xx|__|__|=&lt;br /&gt;
 2 |__|__|__|__|__|__|xx|__|=&lt;br /&gt;
 1 |__|__|__|__|__|__|__|xx|=&lt;br /&gt;
 a b c d e f g h&lt;br /&gt;
|&lt;br /&gt;
}}&lt;br /&gt;
Clearly, the number of ways of placing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; non-attacking rooks on &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;r_k={n\choose k}&amp;lt;/math&amp;gt;. We want to count &amp;lt;math&amp;gt;N_0&amp;lt;/math&amp;gt;, which gives the number of ways of placing &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; non-attacking rooks such that none of these rooks lie in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
By the above theorem&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
N_0=\sum_{k=0}^n(-1)^kr_k(n-k)!=\sum_{k=0}^n(-1)^k{n\choose k}(n-k)!=\sum_{k=0}^n(-1)^k\frac{n!}{k!}=n!\sum_{k=0}^n(-1)^k\frac{1}{k!}\approx\frac{n!}{e}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Problème des ménages====&lt;br /&gt;
Suppose that in a banquet, we want to seat &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; couples at a circular table, satisfying the following constraints:&lt;br /&gt;
* Men and women are in alternate places.&lt;br /&gt;
* No one sits next to his/her spouse.&lt;br /&gt;
&lt;br /&gt;
In how many ways can this be done?&lt;br /&gt;
&lt;br /&gt;
(For convenience, we assume that every seat at the table marked differently so that rotating the seats clockwise or anti-clockwise will end up with a &#039;&#039;&#039;different&#039;&#039;&#039; solution.)&lt;br /&gt;
&lt;br /&gt;
First, let the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; ladies find their seats. They may either sit at the odd numbered seats or even numbered seats, in either case, there are &amp;lt;math&amp;gt;n!&amp;lt;/math&amp;gt; different orders. Thus, there are &amp;lt;math&amp;gt;2(n!)&amp;lt;/math&amp;gt; ways to seat the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; ladies.&lt;br /&gt;
&lt;br /&gt;
After sitting the wives, we label the remaining &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; places clockwise as &amp;lt;math&amp;gt;0,1,\ldots, n-1&amp;lt;/math&amp;gt;. And a seating of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; husbands is given by a permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; defined as follows. Let &amp;lt;math&amp;gt;\pi(i)&amp;lt;/math&amp;gt; be the seat of the husband of he lady sitting at the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;-th place.&lt;br /&gt;
&lt;br /&gt;
It is easy to see that &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; satisfies that &amp;lt;math&amp;gt;\pi(i)\neq i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\pi(i)\not\equiv i+1\pmod n&amp;lt;/math&amp;gt;, and every permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; with these properties gives a feasible seating of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; husbands. Thus, we only need to count the number of permutations &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;\pi(i)\not\equiv i, i+1\pmod n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Take &amp;lt;math&amp;gt;B=\{(0,0),(1,1),\ldots,(n-1,n-1), (0,1),(1,2),\ldots,(n-2,n-1),(n-1,0)\}&amp;lt;/math&amp;gt; as the chess board.  A permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; which defines a way of seating the husbands, is a placement of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; non-attacking rooks such that none of them is in &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;. &lt;br /&gt;
{{Chess diagram small&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|=&lt;br /&gt;
 8 |xx|xx|__|__|__|__|__|__|=&lt;br /&gt;
 7 |__|xx|xx|__|__|__|__|__|=&lt;br /&gt;
 6 |__|__|xx|xx|__|__|__|__|=&lt;br /&gt;
 5 |__|__|__|xx|xx|__|__|__|=&lt;br /&gt;
 4 |__|__|__|__|xx|xx|__|__|=&lt;br /&gt;
 3 |__|__|__|__|__|xx|xx|__|=&lt;br /&gt;
 2 |__|__|__|__|__|__|xx|xx|=&lt;br /&gt;
 1 |xx|__|__|__|__|__|__|xx|=&lt;br /&gt;
 a b c d e f g h&lt;br /&gt;
|&lt;br /&gt;
}}&lt;br /&gt;
We need to compute &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;, the number of ways of placing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; non-attacking rooks on &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;. For our choice of &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; is the number of ways of choosing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; points, no two consecutive, from a collection of &amp;lt;math&amp;gt;2n&amp;lt;/math&amp;gt; points arranged in a circle.&lt;br /&gt;
&lt;br /&gt;
We first see how to do this in a &#039;&#039;line&#039;&#039;.&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:The number of ways of choosing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; &#039;&#039;non-consecutive&#039;&#039; objects from a collection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; objects arranged in a &#039;&#039;line&#039;&#039;, is &amp;lt;math&amp;gt;{m-k+1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
We draw a line of &amp;lt;math&amp;gt;m-k&amp;lt;/math&amp;gt; black points, and then insert &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; red points into the &amp;lt;math&amp;gt;m-k+1&amp;lt;/math&amp;gt; spaces between the black points (including the beginning and end).&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
&amp;amp;\sqcup \, \bullet \, \sqcup \, \bullet \, \sqcup \, \bullet \, \sqcup \, \bullet \, \sqcup \, \bullet \, \sqcup \, \bullet \, \sqcup \, \bullet \, \sqcup \\&lt;br /&gt;
&amp;amp;\qquad\qquad\qquad\quad\Downarrow\\&lt;br /&gt;
&amp;amp;\sqcup \, \bullet \,\, {\color{Red}\bullet} \, \bullet \,\, {\color{Red}\bullet} \, \bullet \, \sqcup \, \bullet \,\, {\color{Red}\bullet}\, \, \bullet \, \sqcup \, \bullet \, \sqcup \, \bullet \,\, {\color{Red}\bullet}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
This gives us a line of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; points, and the red points specifies the chosen objects, which are non-consecutive. The mapping is 1-1 correspondence.&lt;br /&gt;
There are &amp;lt;math&amp;gt;{m-k+1\choose k}&amp;lt;/math&amp;gt; ways of placing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; red points into &amp;lt;math&amp;gt;m-k+1&amp;lt;/math&amp;gt; spaces.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The problem of choosing non-consecutive objects in a circle can be reduced to the case that the objects are in a line.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:The number of ways of choosing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; &#039;&#039;non-consecutive&#039;&#039; objects from a collection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; objects arranged in a &#039;&#039;circle&#039;&#039;, is &amp;lt;math&amp;gt;\frac{m}{m-k}{m-k\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;f(m,k)&amp;lt;/math&amp;gt; be the desired number; and let &amp;lt;math&amp;gt;g(m,k)&amp;lt;/math&amp;gt; be the number of ways of choosing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; non-consecutive points from &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; points arranged in a circle, next coloring the &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; points red, and then coloring one of the uncolored point blue. &lt;br /&gt;
&lt;br /&gt;
Clearly, &amp;lt;math&amp;gt;g(m,k)=(m-k)f(m,k)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
But we can also compute &amp;lt;math&amp;gt;g(m,k)&amp;lt;/math&amp;gt; as follows:&lt;br /&gt;
* Choose one of the &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; points and color it blue. This gives us &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; ways.&lt;br /&gt;
* Cut the circle to make a line of &amp;lt;math&amp;gt;m-1&amp;lt;/math&amp;gt; points by removing the blue point.&lt;br /&gt;
* Choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; non-consecutive points from the line of &amp;lt;math&amp;gt;m-1&amp;lt;/math&amp;gt; points and color them red. This gives &amp;lt;math&amp;gt;{m-k\choose k}&amp;lt;/math&amp;gt; ways due to the previous lemma.&lt;br /&gt;
&lt;br /&gt;
Thus, &amp;lt;math&amp;gt;g(m,k)=m{m-k\choose k}&amp;lt;/math&amp;gt;. Therefore we have the desired number &amp;lt;math&amp;gt;f(m,k)=\frac{m}{m-k}{m-k\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
By the above lemma, we have that &amp;lt;math&amp;gt;r_k=\frac{2n}{2n-k}{2n-k\choose k}&amp;lt;/math&amp;gt;. Then apply the theorem of counting permutations with restricted positions,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
N_0=\sum_{k=0}^n(-1)^kr_k(n-k)!=\sum_{k=0}^n(-1)^k\frac{2n}{2n-k}{2n-k\choose k}(n-k)!.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This gives the number of ways of seating the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; husbands &#039;&#039;after the ladies are seated&#039;&#039;. Recall that there are &amp;lt;math&amp;gt;2n!&amp;lt;/math&amp;gt; ways of seating the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; ladies. Thus, the total number of ways of seating &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; couples as required by problème des ménages is &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
2n!\sum_{k=0}^n(-1)^k\frac{2n}{2n-k}{2n-k\choose k}(n-k)!.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== The Euler totient function === &lt;br /&gt;
Two integers &amp;lt;math&amp;gt;m, n&amp;lt;/math&amp;gt; are said to be &#039;&#039;&#039;relatively prime&#039;&#039;&#039; if their greatest common diviser &amp;lt;math&amp;gt;\mathrm{gcd}(m,n)=1&amp;lt;/math&amp;gt;. For a positive integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;\phi(n)&amp;lt;/math&amp;gt; be the number of positive integers from &amp;lt;math&amp;gt;\{1,2,\ldots,n\}&amp;lt;/math&amp;gt; that are relative prime to &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This function, called the Euler &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; function or &#039;&#039;&#039;the Euler totient function&#039;&#039;&#039;, is fundamental in number theory.&lt;br /&gt;
&lt;br /&gt;
We know derive a formula for this function by using the principle of inclusion-exclusion.&lt;br /&gt;
{{Theorem|Theorem (The Euler totient function)|&lt;br /&gt;
Suppose &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is divisible by precisely &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; different primes, denoted &amp;lt;math&amp;gt;p_1,\ldots,p_r&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;\phi(n)=n\prod_{i=1}^r\left(1-\frac{1}{p_i}\right)&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Let &amp;lt;math&amp;gt;U=\{1,2,\ldots,n\}&amp;lt;/math&amp;gt; be the universe. The number of positive integers from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; which is divisible by some &amp;lt;math&amp;gt;p_{i_1},p_{i_2},\ldots,p_{i_s}\in\{p_1,\ldots,p_r\}&amp;lt;/math&amp;gt;, is &amp;lt;math&amp;gt;\frac{n}{p_{i_1}p_{i_2}\cdots p_{i_s}}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\phi(n)&amp;lt;/math&amp;gt; is the number of integers from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; which is not divisible by any &amp;lt;math&amp;gt;p_1,\ldots,p_r&amp;lt;/math&amp;gt;.&lt;br /&gt;
By principle of inclusion-exclusion,&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\phi(n)&lt;br /&gt;
&amp;amp;=n+\sum_{k=1}^r(-1)^k\sum_{1\le i_1&amp;lt;i_2&amp;lt;\cdots &amp;lt;i_k\le n}\frac{n}{p_{i_1}p_{i_2}\cdots p_{i_k}}\\&lt;br /&gt;
&amp;amp;=n-\sum_{1\le i\le n}\frac{n}{p_i}+\sum_{1\le i&amp;lt;j\le n}\frac{n}{p_i p_j}-\sum_{1\le i&amp;lt;j&amp;lt;k\le n}\frac{n}{p_{i} p_{j} p_{k}}+\cdots + (-1)^r\frac{n}{p_{1}p_{2}\cdots p_{r}}\\&lt;br /&gt;
&amp;amp;=n\left(1-\sum_{1\le i\le n}\frac{1}{p_i}+\sum_{1\le i&amp;lt;j\le n}\frac{1}{p_i p_j}-\sum_{1\le i&amp;lt;j&amp;lt;k\le n}\frac{1}{p_{i} p_{j} p_{k}}+\cdots + (-1)^r\frac{1}{p_{1}p_{2}\cdots p_{r}}\right)\\&lt;br /&gt;
&amp;amp;=n\prod_{i=1}^n\left(1-\frac{1}{p_i}\right).&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* &#039;&#039;Stanley,&#039;&#039; Enumerative Combinatorics, Volume 1, Chapter 2.&lt;br /&gt;
* &#039;&#039;van Lin and Wilson&#039;&#039;, A course in combinatorics, Chapter 10, 15.&lt;/div&gt;</summary>
		<author><name>172.21.1.108</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3154</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3154"/>
		<updated>2010-09-12T06:32:36Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.108: /* Reference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Combinations ===&lt;br /&gt;
Suppose we wish to enumerate all subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. To construct a subset, we specifies for every element of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set whether the element is chosen or not. Let us denote the choice to omit an element by &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, and the choice to include it by &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt;. Using &amp;quot;&amp;lt;math&amp;gt;+&amp;lt;/math&amp;gt;&amp;quot; to represent &amp;quot;OR&amp;quot;, and using the multiplication to denote &amp;quot;AND&amp;quot;, the choices of subsets of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set are expressed as&lt;br /&gt;
:&amp;lt;math&amp;gt;\underbrace{(x_0+x_1)(x_0+x_1)\cdots (x_0+x_1)}_{n\mbox{ elements}}=(x_0+x_1)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example, when &amp;lt;math&amp;gt;n=3&amp;lt;/math&amp;gt;, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
(x_0+x_1)^3&lt;br /&gt;
&amp;amp;=x_0x_0x_0+x_0x_0x_1+x_0x_1x_0+x_0x_1x_1\\&lt;br /&gt;
&amp;amp;\quad +x_1x_0x_0+x_1x_0x_1+x_1x_1x_0+x_1x_1x_1&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
So it &amp;quot;generate&amp;quot; all subsets of the 3-set. Writing &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;(1+x)^3=1+3x+3x^2+x^3&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets of a 3-element set.&lt;br /&gt;
&lt;br /&gt;
In general, &amp;lt;math&amp;gt;(1+x)^n&amp;lt;/math&amp;gt; has the coefficients which are the number of subsets of fixed sizes of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set.&lt;br /&gt;
&lt;br /&gt;
-----&lt;br /&gt;
&lt;br /&gt;
Suppose that we have twelve balls: &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;3 red&amp;lt;/font&amp;gt;, &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;4 blue&amp;lt;/font&amp;gt;, and &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;5 green&amp;lt;/font&amp;gt;. Balls with the same color are indistinguishable.&lt;br /&gt;
&lt;br /&gt;
We want to determine the number of ways to select &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; balls from these twelve balls, for some &amp;lt;math&amp;gt;0\le k\le 12&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The generating function of this sequence is&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
&amp;amp;\quad {\color{Red}(1+x+x^2+x^3)}{\color{Blue}(1+x+x^2+x^3+x^4)}{\color{OliveGreen}(1+x+x^2+x^3+x^4+x^5)}\\&lt;br /&gt;
&amp;amp;=1+3x+6x^2+10x^3+14x^4+17x^5+18x^6+17x^7+14x^8+10x^9+6x^{10}+3x^{11}+x^{12}.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
The coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; gives the number of ways to select &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; balls.&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.&lt;br /&gt;
&lt;br /&gt;
The second and the forth steps need some non-trivial analytic techniques.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
=== Example: Quicksort ===&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* &#039;&#039;Graham, Knuth, and Patashnik&#039;&#039;, Concrete Mathematics: A Foundation for Computer Science, Chapter 7.&lt;br /&gt;
* &#039;&#039;Cameron&#039;&#039;, Combinatorics: Topics, Techniques, Algorithms, Chapter 4.&lt;br /&gt;
* &#039;&#039;van Lin and Wilson&#039;&#039;, A course in combinatorics, Chapter 14.&lt;/div&gt;</summary>
		<author><name>172.21.1.108</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3153</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3153"/>
		<updated>2010-09-12T06:32:05Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.108: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Combinations ===&lt;br /&gt;
Suppose we wish to enumerate all subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. To construct a subset, we specifies for every element of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set whether the element is chosen or not. Let us denote the choice to omit an element by &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, and the choice to include it by &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt;. Using &amp;quot;&amp;lt;math&amp;gt;+&amp;lt;/math&amp;gt;&amp;quot; to represent &amp;quot;OR&amp;quot;, and using the multiplication to denote &amp;quot;AND&amp;quot;, the choices of subsets of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set are expressed as&lt;br /&gt;
:&amp;lt;math&amp;gt;\underbrace{(x_0+x_1)(x_0+x_1)\cdots (x_0+x_1)}_{n\mbox{ elements}}=(x_0+x_1)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example, when &amp;lt;math&amp;gt;n=3&amp;lt;/math&amp;gt;, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
(x_0+x_1)^3&lt;br /&gt;
&amp;amp;=x_0x_0x_0+x_0x_0x_1+x_0x_1x_0+x_0x_1x_1\\&lt;br /&gt;
&amp;amp;\quad +x_1x_0x_0+x_1x_0x_1+x_1x_1x_0+x_1x_1x_1&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
So it &amp;quot;generate&amp;quot; all subsets of the 3-set. Writing &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;(1+x)^3=1+3x+3x^2+x^3&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets of a 3-element set.&lt;br /&gt;
&lt;br /&gt;
In general, &amp;lt;math&amp;gt;(1+x)^n&amp;lt;/math&amp;gt; has the coefficients which are the number of subsets of fixed sizes of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set.&lt;br /&gt;
&lt;br /&gt;
-----&lt;br /&gt;
&lt;br /&gt;
Suppose that we have twelve balls: &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;3 red&amp;lt;/font&amp;gt;, &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;4 blue&amp;lt;/font&amp;gt;, and &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;5 green&amp;lt;/font&amp;gt;. Balls with the same color are indistinguishable.&lt;br /&gt;
&lt;br /&gt;
We want to determine the number of ways to select &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; balls from these twelve balls, for some &amp;lt;math&amp;gt;0\le k\le 12&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The generating function of this sequence is&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
&amp;amp;\quad {\color{Red}(1+x+x^2+x^3)}{\color{Blue}(1+x+x^2+x^3+x^4)}{\color{OliveGreen}(1+x+x^2+x^3+x^4+x^5)}\\&lt;br /&gt;
&amp;amp;=1+3x+6x^2+10x^3+14x^4+17x^5+18x^6+17x^7+14x^8+10x^9+6x^{10}+3x^{11}+x^{12}.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
The coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; gives the number of ways to select &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; balls.&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.&lt;br /&gt;
&lt;br /&gt;
The second and the forth steps need some non-trivial analytic techniques.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
=== Example: Quicksort ===&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* &#039;&#039;Graham, Knuth, and Patashnik&#039;&#039;, Concrete Mathematics: A Foundation for Computer Science, Chapter 7.&lt;br /&gt;
* &#039;&#039;Cameron&#039;&#039;, Combinatorics: Topics, Techniques, Algorithms, Chapter 4.&lt;br /&gt;
* &amp;quot;van Lin and Wilson&amp;quot;, A course in combinatorics, Chapter 14.&lt;/div&gt;</summary>
		<author><name>172.21.1.108</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3152</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3152"/>
		<updated>2010-09-12T06:24:37Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.108: /* Combinations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Combinations ===&lt;br /&gt;
Suppose we wish to enumerate all subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. To construct a subset, we specifies for every element of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set whether the element is chosen or not. Let us denote the choice to omit an element by &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, and the choice to include it by &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt;. Using &amp;quot;&amp;lt;math&amp;gt;+&amp;lt;/math&amp;gt;&amp;quot; to represent &amp;quot;OR&amp;quot;, and using the multiplication to denote &amp;quot;AND&amp;quot;, the choices of subsets of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set are expressed as&lt;br /&gt;
:&amp;lt;math&amp;gt;\underbrace{(x_0+x_1)(x_0+x_1)\cdots (x_0+x_1)}_{n\mbox{ elements}}=(x_0+x_1)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example, when &amp;lt;math&amp;gt;n=3&amp;lt;/math&amp;gt;, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
(x_0+x_1)^3&lt;br /&gt;
&amp;amp;=x_0x_0x_0+x_0x_0x_1+x_0x_1x_0+x_0x_1x_1\\&lt;br /&gt;
&amp;amp;\quad +x_1x_0x_0+x_1x_0x_1+x_1x_1x_0+x_1x_1x_1&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
So it &amp;quot;generate&amp;quot; all subsets of the 3-set. Writing &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;(1+x)^3=1+3x+3x^2+x^3&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets of a 3-element set.&lt;br /&gt;
&lt;br /&gt;
In general, &amp;lt;math&amp;gt;(1+x)^n&amp;lt;/math&amp;gt; has the coefficients which are the number of subsets of fixed sizes of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set.&lt;br /&gt;
&lt;br /&gt;
-----&lt;br /&gt;
&lt;br /&gt;
Suppose that we have twelve balls: &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;3 red&amp;lt;/font&amp;gt;, &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;4 blue&amp;lt;/font&amp;gt;, and &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;5 green&amp;lt;/font&amp;gt;. Balls with the same color are indistinguishable.&lt;br /&gt;
&lt;br /&gt;
We want to determine the number of ways to select &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; balls from these twelve balls, for some &amp;lt;math&amp;gt;0\le k\le 12&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The generating function of this sequence is&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
&amp;amp;\quad {\color{Red}(1+x+x^2+x^3)}{\color{Blue}(1+x+x^2+x^3+x^4)}{\color{OliveGreen}(1+x+x^2+x^3+x^4+x^5)}\\&lt;br /&gt;
&amp;amp;=1+3x+6x^2+10x^3+14x^4+17x^5+18x^6+17x^7+14x^8+10x^9+6x^{10}+3x^{11}+x^{12}.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
The coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; gives the number of ways to select &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; balls.&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.&lt;br /&gt;
&lt;br /&gt;
The second and the forth steps need some non-trivial analytic techniques.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
=== Example: Quicksort ===&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.1.108</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3151</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3151"/>
		<updated>2010-09-12T06:19:53Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.108: /* Combinations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Combinations ===&lt;br /&gt;
Suppose we wish to enumerate all subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. To construct a subset, we specifies for every element of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set whether the element is chosen or not. Let us denote the choice to omit an element by &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt;, and the choice to include it by &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt;. Using &amp;quot;&amp;lt;math&amp;gt;+&amp;lt;/math&amp;gt;&amp;quot; to represent &amp;quot;OR&amp;quot;, and using the multiplication to denote &amp;quot;AND&amp;quot;, the choices of subsets of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set are expressed as&lt;br /&gt;
:&amp;lt;math&amp;gt;\underbrace{(x_0+x_1)(x_0+x_1)\cdots (x_0+x_1)}_{n\mbox{ elements}}=(x_0+x_1)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example, when &amp;lt;math&amp;gt;n=3&amp;lt;/math&amp;gt;, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
(x_0+x_1)^3&lt;br /&gt;
&amp;amp;=x_0x_0x_0+x_0x_0x_1+x_0x_1x_0+x_0x_1x_1\\&lt;br /&gt;
&amp;amp;\quad +x_1x_0x_0+x_1x_0x_1+x_1x_1x_0+x_1x_1x_1&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
So it &amp;quot;generate&amp;quot; all subsets of the 3-set. Writing &amp;lt;math&amp;gt;1&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;x_1&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;(1+x)^3=1+3x+3x^2+x^3&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets of a 3-element set.&lt;br /&gt;
&lt;br /&gt;
In general, &amp;lt;math&amp;gt;(1+x)^n&amp;lt;/math&amp;gt; has the coefficients which are the number of subsets of fixed sizes of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set.&lt;br /&gt;
&lt;br /&gt;
-----&lt;br /&gt;
&lt;br /&gt;
Suppose that we have twelve balls: &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;3 red&amp;lt;/font&amp;gt;, &amp;lt;font color=&amp;quot;blue&amp;quot;&amp;gt;4 blue&amp;lt;/font&amp;gt;, and &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;5 green&amp;lt;/font&amp;gt;. Balls with the same color are indistinguishable.&lt;br /&gt;
&lt;br /&gt;
We want to determine the number of ways to select &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; balls from these twelve balls, for some &amp;lt;math&amp;gt;0\le k\le 12&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;{\color{Red}(1+x+x^2+x^3)}{\color{Blue}(1+x+x^2+x^3+x^4)}{\color{OliveGreen}(1+x+x^2+x^3+x^4+x^5)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.&lt;br /&gt;
&lt;br /&gt;
The second and the forth steps need some non-trivial analytic techniques.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
=== Example: Quicksort ===&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.1.108</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3150</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3150"/>
		<updated>2010-09-12T02:52:32Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.108: /* Example: multisets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Combinations ===&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.&lt;br /&gt;
&lt;br /&gt;
The second and the forth steps need some non-trivial analytic techniques.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
=== Example: Quicksort ===&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.1.108</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3149</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3149"/>
		<updated>2010-09-12T02:52:17Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.108: /* Example: multisets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Combinations ===&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.&lt;br /&gt;
&lt;br /&gt;
The second and the forth steps need some non-trivial analytic techniques.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Example: Quicksort ===&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.1.108</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3148</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3148"/>
		<updated>2010-09-12T02:46:22Z</updated>

		<summary type="html">&lt;p&gt;172.21.1.108: /* Pólya&amp;#039;s problem of changing money */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Combinations ===&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.&lt;br /&gt;
&lt;br /&gt;
The second and the forth steps need some non-trivial analytic techniques.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.1.108</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3147</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3147"/>
		<updated>2010-09-12T02:19:06Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.5: /* Combinations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Combinations ===&lt;br /&gt;
&lt;br /&gt;
=== Pólya&#039;s problem of changing money ===&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.&lt;br /&gt;
&lt;br /&gt;
The second and the forth steps need some non-trivial analytic techniques.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.3.5</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3146</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3146"/>
		<updated>2010-09-12T02:18:48Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.5: /* Pólya&amp;#039;s problem of changing money */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Combinations ===&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.&lt;br /&gt;
&lt;br /&gt;
The second and the forth steps need some non-trivial analytic techniques.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.3.5</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3145</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3145"/>
		<updated>2010-09-12T01:42:03Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.5: /* Fibonacci numbers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Combinations ===&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.&lt;br /&gt;
&lt;br /&gt;
The second and the forth steps need some non-trivial analytic techniques.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
== Pólya&#039;s problem of changing money ==&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.3.5</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3144</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3144"/>
		<updated>2010-09-12T01:37:02Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.5: /* Solving recurrences */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The first step is usually established by combinatorial observations, or explicitly given by the problem. The third step is trivial.&lt;br /&gt;
&lt;br /&gt;
The second and the forth steps need some non-trivial analytic techniques.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
== Pólya&#039;s problem of changing money ==&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.3.5</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3143</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3143"/>
		<updated>2010-09-12T01:32:14Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.5: /* Solving recurrences */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
The following steps describe a general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;. In the case of Fibonacci sequence&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=a_{n-1}+a_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}(a_{n-1}+a_{n-2})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
== Pólya&#039;s problem of changing money ==&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.3.5</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3142</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3142"/>
		<updated>2010-09-12T01:24:04Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.5: /* Solving recurrences */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
In the above analysis of Fibonacci numbers, we apply the following general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;, such as&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=f(a_0,a_1,\ldots,a_{n-1})&amp;lt;/math&amp;gt;  for some function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}f(a_0,a_1,\ldots,a_{n-1})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
== Pólya&#039;s problem of changing money ==&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.3.5</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3141</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3141"/>
		<updated>2010-09-12T01:21:08Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.5: /* Fibonacci numbers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into two geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
In the above analysis of Fibonacci numbers, we apply the following general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;; that is, an equation expressing &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; in terms of other elements of the sequence, such as&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=f(a_0,a_1,\ldots,a_{n-1})&amp;lt;/math&amp;gt;  for some function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}f(a_0,a_1,\ldots,a_{n-1})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
== Pólya&#039;s problem of changing money ==&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.3.5</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3140</id>
		<title>Combinatorics (Fall 2010)/Generating functions</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3140"/>
		<updated>2010-09-12T01:20:45Z</updated>

		<summary type="html">&lt;p&gt;172.21.3.5: /* Fibonacci numbers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Generating Functions ==&lt;br /&gt;
In Stanley&#039;s magnificent book &#039;&#039;Enumerative Combinatorics&#039;&#039;, he comments the generating function as &amp;quot;the most useful but most difficult to understand method (for counting)&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The solution to a counting problem is usually represented as some &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; depending a parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Sometimes this &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is called a &#039;&#039;counting function&#039;&#039; as it is a function of the parameter &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.  &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; can also be treated as a infinite series:&lt;br /&gt;
:&amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;ordinary generating function (OGF)&#039;&#039;&#039; defined by &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
G(x)=\sum_{n\ge 0} a_nx^n.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So &amp;lt;math&amp;gt;G(x)=a_0+a_1x+a_2x^2+\cdots&amp;lt;/math&amp;gt;. An expression in this form is called a [http://en.wikipedia.org/wiki/Formal_power_series &#039;&#039;&#039;formal power series&#039;&#039;&#039;], and &amp;lt;math&amp;gt;a_0,a_1,a_2,\ldots&amp;lt;/math&amp;gt; is the sequence of &#039;&#039;&#039;coefficients&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Furthermore, the generating function can be expanded as&lt;br /&gt;
:G(x)=&amp;lt;math&amp;gt;(\underbrace{1+\cdots+1}_{a_0})+(\underbrace{x+\cdots+x}_{a_1})+(\underbrace{x^2+\cdots+x^2}_{a_2})+\cdots+(\underbrace{x^n+\cdots+x^n}_{a_n})+\cdots&amp;lt;/math&amp;gt;&lt;br /&gt;
so it indeed &amp;quot;generates&amp;quot; all the possible instances of the objects we want to count.&lt;br /&gt;
&lt;br /&gt;
Usually, we do not evaluate the generating function &amp;lt;math&amp;gt;GF(x)&amp;lt;/math&amp;gt; on any particular value. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; remains as a &#039;&#039;&#039;formal variable&#039;&#039;&#039; without assuming any value. The numbers that we want to count are the coefficients carried by the terms in the formal power series. So far the generating function is just another way to represent the sequence&lt;br /&gt;
:&amp;lt;math&amp;gt;(a_0,a_1,a_2,\ldots\ldots)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The true power of generating functions comes from the various algebraic operations that we can perform on these generating functions. We use an example to demonstrate this.&lt;br /&gt;
&lt;br /&gt;
=== Fibonacci numbers  ===&lt;br /&gt;
Consider the following counting problems.&lt;br /&gt;
* Count the number of ways that the nonnegative integer &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; can be written as a sum of ones and twos (in order).&lt;br /&gt;
: The problem asks for the number of compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with summands from &amp;lt;math&amp;gt;\{1,2\}&amp;lt;/math&amp;gt;. Formally, we are counting the number of tuples &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;k\le n&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_i\in\{1,2\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. We observe that a composition either starts with a 1, in which case the rest is a composition of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt;; or starts with a 2, in which case the rest is a composition of &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt;. So we have the recursion for &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; that&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Count the ways to completely cover a &amp;lt;math&amp;gt;2\times n&amp;lt;/math&amp;gt; rectangle with &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; dominos without any overlaps.&lt;br /&gt;
: Dominos are identical &amp;lt;math&amp;gt;2\times 1&amp;lt;/math&amp;gt; rectangles, so that only their orientations --- vertical or horizontal matter.&lt;br /&gt;
: Let &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; be the solution. It also holds that &amp;lt;math&amp;gt;F_n=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt;. The proof is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
In both problems, the solution is given by &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; which satisfies the following recursion.&lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\begin{cases}&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if }n\ge 2,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
0 &amp;amp; \mbox{if }n=0.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is called the [http://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number].&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
::&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; is the so-called [http://en.wikipedia.org/wiki/Golden_ratio golden ratio], a constant with some significance in mathematics and aesthetics.&lt;br /&gt;
&lt;br /&gt;
We now prove this theorem by using generating functions.&lt;br /&gt;
The ordinary generating function for the Fibonacci number &amp;lt;math&amp;gt;F_{n}&amp;lt;/math&amp;gt; is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}F_n x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
We have that &amp;lt;math&amp;gt;F_{n}=F_{n-1}+F_{n-2}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;n\ge 2&amp;lt;/math&amp;gt;, thus&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{align}&lt;br /&gt;
G(x) &lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}F_n x^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
x+\sum_{n\ge 2}(F_{n-1}+F_{n-2})x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For generating functions, there are general ways to generate &amp;lt;math&amp;gt;F_{n-1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F_{n-2}&amp;lt;/math&amp;gt;, or the coefficients with any smaller indices.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
xG(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+1}=\sum_{n\ge 1}F_{n-1} x^n=\sum_{n\ge 2}F_{n-1} x^n\\&lt;br /&gt;
x^2G(x)&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}F_n x^{n+2}=\sum_{n\ge 2}F_{n-2} x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we have&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=x+(x+x^2)G(x)\,&amp;lt;/math&amp;gt;,&lt;br /&gt;
hence&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
The value of &amp;lt;math&amp;gt;F_n&amp;lt;/math&amp;gt; is the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in the Taylor series for this formular, which is &amp;lt;math&amp;gt;\frac{G^{(n)}(0)}{n!}=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;. Although this expansion works in principle, the detailed calculus is rather painful.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
It is easier to expand the generating function by breaking it into several geometric series.&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\phi=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. It holds that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is easy to verify the above equation, but to deduce it, we need some (high school) calculation.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;3&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse;empty-cells:show;&amp;quot;&lt;br /&gt;
|&lt;br /&gt;
:{|&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;math&amp;gt;1-x-x^2&amp;lt;/math&amp;gt; has two roots &amp;lt;math&amp;gt;\frac{-1\pm\sqrt{5}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Denote that &amp;lt;math&amp;gt;\phi=\frac{2}{-1+\sqrt{5}}=\frac{1+\sqrt{5}}{2}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\hat{\phi}=\frac{2}{-1-\sqrt{5}}=\frac{1-\sqrt{5}}{2}&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;math&amp;gt;(1-x-x^2)=(1-\phi x)(1-\hat{\phi}x)&amp;lt;/math&amp;gt;, so we can write &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\frac{x}{1-x-x^2}&lt;br /&gt;
&amp;amp;=\frac{x}{(1-\phi x)(1-\hat{\phi} x)}\\&lt;br /&gt;
&amp;amp;=\frac{\alpha}{(1-\phi x)}+\frac{\beta}{(1-\hat{\phi} x)},&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; satisfying that&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{cases}&lt;br /&gt;
\alpha+\beta=0\\&lt;br /&gt;
\alpha\phi+\beta\hat{\phi}= -1.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Solving this we have that &amp;lt;math&amp;gt;\alpha=\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\beta=-\frac{1}{\sqrt{5}}&amp;lt;/math&amp;gt;. Thus,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{x}{1-x-x^2}=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
:&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known geometric expansion:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-z}=\sum_{n\ge 0}z^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; can be expanded as&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\phi x}-\frac{1}{\sqrt{5}}\cdot\frac{1}{1-\hat{\phi} x}\\&lt;br /&gt;
&amp;amp;=\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\phi x)^n-\frac{1}{\sqrt{5}}\sum_{n\ge 0}(\hat{\phi} x)^n\\&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)x^n.&lt;br /&gt;
\end{align}&amp;lt;/math&amp;gt;&lt;br /&gt;
So the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Fibonacci number is given by &lt;br /&gt;
:&amp;lt;math&amp;gt;F_n=\frac{1}{\sqrt{5}}\left(\phi^n-\hat{\phi}^n\right)=\frac{1}{\sqrt{5}}\left(\frac{1+\sqrt{5}}{2}\right)^n-\frac{1}{\sqrt{5}}\left(\frac{1-\sqrt{5}}{2}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Solving recurrences ==&lt;br /&gt;
In the above analysis of Fibonacci numbers, we apply the following general methodology of solving recurrences by generating functions.&lt;br /&gt;
:1. Give a recursion that computes &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;; that is, an equation expressing &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt; in terms of other elements of the sequence, such as&lt;br /&gt;
::&amp;lt;math&amp;gt;a_n=f(a_0,a_1,\ldots,a_{n-1})&amp;lt;/math&amp;gt;  for some function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2. Multiply both sides of the equation by &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; and sum over all &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. This gives the generating function&lt;br /&gt;
::&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}a_nx^n=\sum_{n\ge 0}f(a_0,a_1,\ldots,a_{n-1})x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: And manipulate the right hand side of the equation so that it becomes some other expression involving &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
:3. Solve the resulting equation to derive an explicit formula for &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
:4. Expand &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; into a power series and read off the coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt;, which is a closed form for &amp;lt;math&amp;gt;a_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Algebraic operations on generating functions ===&lt;br /&gt;
The second step in the above methodology is somehow tricky. It involves first applying the recurrence to the coefficients of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is easy; and then manipulating the resulting formal power series to express it in terms of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt;, which is more difficult (because it works backwards).&lt;br /&gt;
&lt;br /&gt;
We can apply several natural algebraic operations on the formal power series.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Generating function manipulation|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}g_nx^n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;F(x)=\sum_{n\ge 0}f_nx^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
x^k G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge k}g_{n-k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\frac{G(x)-\sum_{i=0}^{k-1}g_iz^i}{x^k}&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}g_{n+k}x^n, &amp;amp;\qquad (\mbox{integer }k\ge 0)\\&lt;br /&gt;
\alpha F(x)+\beta G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} (\alpha f_n+\beta g_n)x^n\\&lt;br /&gt;
F(x)G(x)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0}\sum_{k=0}^nf_kg_{n-k}x^n\\&lt;br /&gt;
G(cx)&lt;br /&gt;
&amp;amp;= \sum_{n\ge 0} c^ng_n x^n\\&lt;br /&gt;
G&#039;(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}(n+1)g_{n+1}x^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
When manipulating generating functions, these rules are applied backwards; that is, from the right-hand-side to the left-hand-side.&lt;br /&gt;
&lt;br /&gt;
=== Expanding generating functions ===&lt;br /&gt;
The last step of solving recurrences by generating function is expanding the closed form generating function &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; to evaluate its &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th coefficient. In principle, we can always use the [http://en.wikipedia.org/wiki/Taylor_series Taylor series]&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}\frac{G^{(n)}(0)}{n!}x^n&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;G^{(n)}(0)&amp;lt;/math&amp;gt; is the value of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; evaluated at &amp;lt;math&amp;gt;x=0&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some interesting special cases are very useful.&lt;br /&gt;
&lt;br /&gt;
====Geometric sequence====&lt;br /&gt;
In the example of Fibonacci numbers, we use the well known geometric series:&lt;br /&gt;
:&amp;lt;math&amp;gt;\frac{1}{1-x}=\sum_{n\ge 0}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is useful when we can express the generating function in the form of &amp;lt;math&amp;gt;G(x)=\frac{a_1}{1-b_1x}+\frac{a_2}{1-b_2x}+\cdots+\frac{a_k}{1-b_kx}&amp;lt;/math&amp;gt;. The coefficient of &amp;lt;math&amp;gt;x^n&amp;lt;/math&amp;gt; in such &amp;lt;math&amp;gt;G(x)&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;a_1b_1^n+a_2b_2^n+\cdots+a_kb_k^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
====Binomial theorem====&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-th derivative of &amp;lt;math&amp;gt;(1+x)^\alpha&amp;lt;/math&amp;gt; for some real &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)(1+x)^{\alpha-n}&amp;lt;/math&amp;gt;.&lt;br /&gt;
By Taylor series, we get a generalized version of the binomial theorem known as [http://en.wikipedia.org/wiki/Binomial_coefficient#Newton.27s_binomial_series &#039;&#039;&#039;Newton&#039;s formula&#039;&#039;&#039;]:&lt;br /&gt;
{{Theorem|Newton&#039;s formular (generalized binomial theorem)|&lt;br /&gt;
If &amp;lt;math&amp;gt;|x|&amp;lt;1&amp;lt;/math&amp;gt;, then&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^\alpha=\sum_{n\ge 0}{\alpha\choose n}x^{n}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;{\alpha\choose n}&amp;lt;/math&amp;gt; is the &#039;&#039;&#039;generalized binomial coefficient&#039;&#039;&#039; defined by &lt;br /&gt;
:&amp;lt;math&amp;gt;{\alpha\choose n}=\frac{\alpha(\alpha-1)(\alpha-2)\cdots(\alpha-n+1)}{n!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Example: multisets ===&lt;br /&gt;
In the last lecture we gave a combinatorial proof of the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Now we give a generating function approach to the problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set. We have&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x_1+x_1^2+\cdots)(1+x_2+x_2^2+\cdots)\cdots(1+x_n+x_n^2+\cdots)=\sum_{m:S\rightarrow\mathbb{N}} \prod_{x_i\in S}x_i^{m(x_i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where each &amp;lt;math&amp;gt;m:S\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; species a possible multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with multiplicity function &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let all &amp;lt;math&amp;gt;x_i=x&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1+x+x^2+\cdots)^n&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{m:S\rightarrow\mathbb{N}}x^{m(x_1)+\cdots+m(x_n)}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{\text{multiset }M\text{ on }S}x^{|M|}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{k\ge 0}\left({n\choose k}\right)x^k.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the the definition of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. Our task is to evaluate &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Due to the geometric sequence and the Newton&#039;s formula&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1+x+x^2+\cdots)^n=(1-x)^{-n}=\sum_{k\ge 0}{-n\choose k}(-x)^k.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\left({n\choose k}\right)=(-1)^k{-n\choose k}={n+k-1\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The last equation is due to the definition of the generalized binomial coefficient. We use an analytic (generating function) proof to get the same result of &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; as the combinatorial proof.&lt;br /&gt;
&lt;br /&gt;
== Pólya&#039;s problem of changing money ==&lt;br /&gt;
&lt;br /&gt;
== Catalan Number ==&lt;br /&gt;
We now introduce a class of counting problems, all with the same solution, called [http://en.wikipedia.org/wiki/Catalan_number &#039;&#039;&#039;Catalan number&#039;&#039;&#039;]. &lt;br /&gt;
&lt;br /&gt;
The &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;th Catalan number is denoted as &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
In Volume 2 of Stanley&#039;s &#039;&#039;Enumerative Combinatorics&#039;&#039;, a set of exercises describe 66 different interpretations of the Catalan numbers. We give a few examples, cited from Wikipedia.&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;Dyck words&#039;&#039;&#039; of length 2&#039;&#039;n&#039;&#039;. A Dyck word is a string consisting of &#039;&#039;n&#039;&#039; X&#039;s and &#039;&#039;n&#039;&#039; Y&#039;s such that no initial segment of the string has more Y&#039;s than X&#039;s (see also [http://en.wikipedia.org/wiki/Dyck_language Dyck language]). For example, the following are the Dyck words of length 6:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; XXXYYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXXYY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XYXYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYYXY &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; XXYXYY.&amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; counts the number of expressions containing &#039;&#039;n&#039;&#039; pairs of parentheses which are correctly matched:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;big&amp;gt; ((())) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()(()) &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; ()()() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (())() &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; (()()) &amp;lt;/big&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 factors can be completely parenthesized (or the number of ways of associating &#039;&#039;n&#039;&#039; applications of a &#039;&#039;&#039;binary operator&#039;&#039;&#039;). For &#039;&#039;n&#039;&#039; = 3, for example, we have the following five different parenthesizations of four factors:&lt;br /&gt;
&amp;lt;div class=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;math&amp;gt;((ab)c)d \quad (a(bc))d \quad(ab)(cd) \quad a((bc)d) \quad a(b(cd))&amp;lt;/math&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Successive applications of a binary operator can be represented in terms of a &#039;&#039;&#039;full binary tree&#039;&#039;&#039;. (A rooted binary tree is &#039;&#039;full&#039;&#039; if every vertex has either two children or no children.) It follows that &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of full binary trees with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;1 leaves:&lt;br /&gt;
[[Image:Catalan number binary tree example.png|center]] &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of &#039;&#039;&#039;monotonic paths&#039;&#039;&#039; along the edges of a grid with &#039;&#039;n&#039;&#039; × &#039;&#039;n&#039;&#039; square cells, which do not pass above the diagonal. A monotonic path is one which starts in the lower left corner, finishes in the upper right corner, and consists entirely of edges pointing rightwards or upwards. Counting such paths is equivalent to counting Dyck words: X stands for &amp;quot;move right&amp;quot; and Y stands for &amp;quot;move up&amp;quot;. The following diagrams show the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan number 4x4 grid example.svg.png|450px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of different ways a [http://en.wikipedia.org/wiki/Convex_polygon &#039;&#039;&#039;convex polygon&#039;&#039;&#039;] with &#039;&#039;n&#039;&#039;&amp;amp;nbsp;+&amp;amp;nbsp;2 sides can be cut into &#039;&#039;&#039;triangles&#039;&#039;&#039; by connecting vertices with straight lines. The following hexagons illustrate the case &#039;&#039;n&#039;&#039; = 4:&lt;br /&gt;
[[Image:Catalan-Hexagons-example.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of [http://en.wikipedia.org/wiki/Stack_(data_structure) &#039;&#039;&#039;stack&#039;&#039;&#039;]-sortable permutations of {1, ..., &#039;&#039;n&#039;&#039;}. A permutation &#039;&#039;w&#039;&#039; is called &#039;&#039;&#039;stack-sortable&#039;&#039;&#039; if &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;(1,&amp;amp;nbsp;...,&amp;amp;nbsp;&#039;&#039;n&#039;&#039;), where &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) is defined recursively as follows: write &#039;&#039;w&#039;&#039; =&amp;amp;nbsp;&#039;&#039;unv&#039;&#039; where &#039;&#039;n&#039;&#039; is the largest element in &#039;&#039;w&#039;&#039; and &#039;&#039;u&#039;&#039; and &#039;&#039;v&#039;&#039; are shorter sequences, and set &#039;&#039;S&#039;&#039;(&#039;&#039;w&#039;&#039;) =&amp;amp;nbsp;&#039;&#039;S&#039;&#039;(&#039;&#039;u&#039;&#039;)&#039;&#039;S&#039;&#039;(&#039;&#039;v&#039;&#039;)&#039;&#039;n&#039;&#039;, with &#039;&#039;S&#039;&#039; being the identity for one-element sequences. &lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;C&#039;&#039;&amp;lt;sub&amp;gt;&#039;&#039;n&#039;&#039;&amp;lt;/sub&amp;gt; is the number of ways to tile a stairstep shape of height &#039;&#039;n&#039;&#039; with &#039;&#039;n&#039;&#039; rectangles. The following figure illustrates the case &#039;&#039;n&#039;&#039;&amp;amp;nbsp;=&amp;amp;nbsp;4:&lt;br /&gt;
[[Image:Catalan stairsteps 4.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Recurrence relation for Catalan numbers|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;C_1=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n&amp;gt;1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=\sum_{i=1}^{n-1}C_iC_{n-i}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n&amp;lt;/math&amp;gt; be the generating function. Apply the product rule,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)^2=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n=\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
Due to the recurrence,&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\sum_{n\ge 0}C_nx^n=x+\sum_{n\ge 2}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=x+G(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving this, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Because &amp;lt;math&amp;gt;C_0=0&amp;lt;/math&amp;gt;, it must hold that &amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2}&amp;lt;/math&amp;gt;, or otherwise the constant term is not zero. Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, we have&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\frac{1-(1-4x)^{1/2}}{2}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-\frac{1}{2}\sum_{n\ge 0}{1/2\choose n}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Thus, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
C_n&lt;br /&gt;
&amp;amp;=-\frac{1}{2}{1/2\choose n}(-4)^n\\&lt;br /&gt;
&amp;amp;=-\frac{1}{2}\cdot\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-3)}{2}\cdot(-4)^n/n!\\&lt;br /&gt;
&amp;amp;=\frac{(2n-2)!}{(n-1)!n!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n}{2n-2\choose n-1}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So we prove the following closed form for Catalan number.&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;C_n=\frac{1}{n}{2n-2\choose n-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>172.21.3.5</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=%E5%A4%A7%E6%B0%94%E7%8E%AF%E6%B5%81_(Fall_2010)&amp;diff=3273</id>
		<title>大气环流 (Fall 2010)</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=%E5%A4%A7%E6%B0%94%E7%8E%AF%E6%B5%81_(Fall_2010)&amp;diff=3273"/>
		<updated>2010-09-07T06:50:02Z</updated>

		<summary type="html">&lt;p&gt;172.21.0.219: /* Assignments */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Infobox&lt;br /&gt;
|name         = Infobox&lt;br /&gt;
|bodystyle    = &lt;br /&gt;
|title        = 大气环流 &amp;lt;br&amp;gt;&lt;br /&gt;
General Circulation of the Atmosphere&lt;br /&gt;
|titlestyle   = &lt;br /&gt;
&lt;br /&gt;
|image        = [[File:zoo_2.jpg|border|150px]]&lt;br /&gt;
|imagestyle   = &lt;br /&gt;
|caption      = &lt;br /&gt;
|captionstyle = &lt;br /&gt;
|headerstyle  = background:#ccf;&lt;br /&gt;
|labelstyle   = background:#ddf;&lt;br /&gt;
|datastyle    = &lt;br /&gt;
&lt;br /&gt;
|header1 =Instructor&lt;br /&gt;
|label1  = &lt;br /&gt;
|data1   = &lt;br /&gt;
|header2 = &lt;br /&gt;
|label2  = &lt;br /&gt;
|data2   = 张洋&lt;br /&gt;
|header3 = &lt;br /&gt;
|label3  = Email&lt;br /&gt;
|data3   = yangzhang@nju.edu.cn yang.zhang.nju@gmail.com&lt;br /&gt;
|header4 =&lt;br /&gt;
|label4= office&lt;br /&gt;
|data4= 东南楼 334&lt;br /&gt;
|header5 = Class&lt;br /&gt;
|label5  = &lt;br /&gt;
|data5   = &lt;br /&gt;
|header6 =&lt;br /&gt;
|label6  = Class meetings&lt;br /&gt;
|data6   = 2 pm-4 pm, Wednesday, &amp;lt;br&amp;gt;馆I-103&lt;br /&gt;
|header7 =&lt;br /&gt;
|label7  = Place&lt;br /&gt;
|data7   = &lt;br /&gt;
|header8 =&lt;br /&gt;
|label8  = Office hours&lt;br /&gt;
|data8   = 4pm-5pm, Friday, &amp;lt;br&amp;gt;东南楼 334 &lt;br /&gt;
|header9 = Reference book&lt;br /&gt;
|label9  = &lt;br /&gt;
|data9   = &lt;br /&gt;
|header10 =&lt;br /&gt;
|label10  = &lt;br /&gt;
|data10   = {{Infobox&lt;br /&gt;
|name         = &lt;br /&gt;
|bodystyle  = &lt;br /&gt;
|title        = &lt;br /&gt;
|titlestyle   = &lt;br /&gt;
|image        = [[File:James-Circulating.jpg|border|100px]]&lt;br /&gt;
|imagestyle   = &lt;br /&gt;
|caption      = Introduction to Circulating Atmospheres, &amp;lt;br&amp;gt;&#039;&#039;I. James&#039;&#039;, Cambridge Press, 1995&lt;br /&gt;
|captionstyle = }}&lt;br /&gt;
|header11 =&lt;br /&gt;
|label11  = &lt;br /&gt;
|data11   = {{Infobox&lt;br /&gt;
|name         = &lt;br /&gt;
|bodystyle  = &lt;br /&gt;
|title        = &lt;br /&gt;
|titlestyle   = &lt;br /&gt;
|image        = [[File:Oort.jpg|border|100px]]&lt;br /&gt;
|imagestyle   = &lt;br /&gt;
|caption      =Physics of Climate, &#039;&#039;Peixoto, J. P.&#039;&#039; and &#039;&#039;A. H. Oort&#039;&#039;,  Springer-Verlag New York, 1992&lt;br /&gt;
|captionstyle = &lt;br /&gt;
}}&lt;br /&gt;
|header12 =&lt;br /&gt;
|label12  = &lt;br /&gt;
|data12   = {{Infobox&lt;br /&gt;
|name         = &lt;br /&gt;
|bodystyle  = &lt;br /&gt;
|title        = &lt;br /&gt;
|titlestyle   = &lt;br /&gt;
|image        = [[File:geoff.jpg|border|100px]]&lt;br /&gt;
|imagestyle   = &lt;br /&gt;
|caption      =Atmospheric and Oceanic Fluid Dynamics: Fundamentals and Large-scale Circulation, &#039;&#039;Vallis, G. K.&#039;&#039;, Cambridge University Press, 2006&lt;br /&gt;
|captionstyle = &lt;br /&gt;
}}&lt;br /&gt;
|belowstyle = background:#ddf;&lt;br /&gt;
|below = &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This is the page for the class &#039;&#039;General Circulation of the Atmosphere (大气环流)&#039;&#039; for the Fall 2010 semester. Students who take this class should check this page periodically for content updates and new announcements. &lt;br /&gt;
&lt;br /&gt;
= Announcement = &lt;br /&gt;
* 本学期大气环流课的上课时间已改为（1-18周）周三下午2-4pm，馆1-103. 【2010.9.4】&lt;br /&gt;
&lt;br /&gt;
= Course info =&lt;br /&gt;
* &#039;&#039;&#039;Instructor &#039;&#039;&#039;: 张洋，&lt;br /&gt;
:*office: 东南楼 334&lt;br /&gt;
:*email: yangzhang@nju.edu.cn, yang.zhang.nju@gmail.com&lt;br /&gt;
* &#039;&#039;&#039;Class meeting&#039;&#039;&#039;:  2 pm-4 pm, Wednesday, 馆I-103&lt;br /&gt;
* &#039;&#039;&#039;Office hour&#039;&#039;&#039;: 4-5pm, Friday; 东南楼 334&lt;br /&gt;
* &#039;&#039;&#039;Prerequisites&#039;&#039;&#039;: 动力气象，天气学，气候学&lt;br /&gt;
* &#039;&#039;&#039;Grading&#039;&#039;&#039;: 平时作业（60％）＋ 期末考试（40％）&lt;br /&gt;
本课程将大致布置5次作业，每次作业一二道题目左右。题目将选择每个课题最具有代表性、需要一定思维强度和动手能力的训练用题目,意在使学生通过顺利完成作业来建立环流系统的物理模型、以对课程内容得到深刻全面地理解和掌握。期末考试题目数量将会比平时作业多,覆盖面更广,但会比作业题目简单,只涉及对基本内容的掌握和对环流理论的直接应用。平时认真完成作业的学生,将不会在考试中遇到困难。&lt;br /&gt;
&lt;br /&gt;
= Course intro =&lt;br /&gt;
“大气环流”常指地球大气较大空间范围、较长时间尺度上的空气流动，及其对地球大气热量、动量、能量和水汽的全球输送。虽然从十七世纪起人们就开始研究大尺度的大气运动(如Hadley在1735年提出的信风理论)，但大气环流真正发展成为一门较完备的学科方向却是近半个世纪的事情。随着四五十年代探空资料等高空气象要素的取得，以及六十年代卫星等覆盖全球的观测资料的加入，大气环流的空间结构和时间变化开始被系统、全面地揭示。与此同时，大气环流的数值模拟，也开始成为研究大气环流的一个主要方法，并发展至今成为了解和预估未来气候变化的主要手段。随着观测和模拟手段的进步，大气环流的理论研究也在近三十年开始快速地发展，人们对各种环流系统的维持和变化有了更全面、更深刻、也更为现代的理解。&lt;br /&gt;
&lt;br /&gt;
现代的大气环流是大气动力学、天气学和气候学相结合的产物。大气环流，既是各种天气现象产生的背景流场，又是各种气候状态形成的动力机制。大气环流在低频、季节、年际、年代际等时间尺度的变化，不但会引起天气现象的变化，也影响着气候状态的形成。而在大气科学领域面临着诸如全球暖化、气候变化、环流异常等重大科学问题的今天，大气环流研究的重要性被推到了前所未有的高度,大气环流也成为活跃发展又充满挑战的学科方向。&lt;br /&gt;
&lt;br /&gt;
本课程将讲述在过去几十年里大气环流在观测、理论和模拟上取得的进展。希望学生借此课程能熟悉大气环流的基本分布和形态，掌握各主要环流系统的维持和变化机制，建立各环流系统形成的物理模型，了解现阶段的大气环流模式，知道大气环流方向有待解决的科学问题。&lt;br /&gt;
&lt;br /&gt;
作为一门课程，大气环流内容的讲述常可以有两条线索。一条是全球尺度上大气热量、动量、能量和水汽的分布与输送，Lorenz（1967）和 Peixoto and Oort（1992）是按此线索介绍大气环流的优秀教材；另一条线索，是各纬度、各区域内大气环流系统的形成、维持和变化机制，James（1995）和 Vallis（2006）是按此线索介绍大气环流的经典讲义。根据现阶段大气环流方向的研究特点，本课程的讲述将主要按照后一种方式来展开，并辅以介绍各环流系统对大气各要素场的输送。在介绍各环流系统时，本课程将以观测、理论和模拟为顺序，从各大气环流系统的观测事实入手，介绍大气环流系统的分布特征和时空变化特征；着重介绍关于环流系统的各种动力学模型和现阶段对环流系统的理解；辅以对环流系统模拟研究的介绍；最后通过三者的对比，讨论各环流系统有待研究的问题。&lt;br /&gt;
&lt;br /&gt;
= Syllabus =&lt;br /&gt;
本课程具体的内容安排如下：第一章为大气环流的概述，介绍大气环流发展的历史、包含的内容以及大气环流研究的常用观测资料和分析方法。第二章介绍大气环流产生的外部强迫：辐射强迫和下界面过程。第三至六章介绍大气环流中的各个环流系统及它们的动力机制。第七章详细介绍各复杂度的大气环流模式。第八章介绍大气环流领域现阶段最大的一个开放课题：全球暖化背景下的大气环流。这一章既是对前几章所介绍的大气环流理论的应用与检验，又是对未来大气环流研究方向的探讨。借此让学生熟悉并理解大气环流领域亟需解决的课题。具体课程安排和参考书目如下。&lt;br /&gt;
== Course schedule ==&lt;br /&gt;
*大气环流概述 (Introduction) （4课时）&lt;br /&gt;
*大气环流的外部强迫（3课时）&lt;br /&gt;
**辐射强迫 (Radiative forcing)&lt;br /&gt;
**下界面过程 (Surface boundaries)&lt;br /&gt;
*经向环流系统 (Zonally-averaged circulations)&lt;br /&gt;
**Hadley 环流（4课时）&lt;br /&gt;
**Ferrel 环流，急流，中纬度的波流相互作用（8课时）&lt;br /&gt;
*角动量、能量和水汽循环 (Angular momentum, energy and water vapor)（3课时）&lt;br /&gt;
*纬向环流系统（Non-zonal circulations）（6课时）&lt;br /&gt;
**Storm tracks&lt;br /&gt;
**Monsoon&lt;br /&gt;
**ENSO and Walker circulation&lt;br /&gt;
*不同复杂度的大气环流模式 (General circulation in a hierarchy of models)（3课时）&lt;br /&gt;
*全球暖化背景下的大气环流 (General circulation in the global warming scenario)（4课时）&lt;br /&gt;
&lt;br /&gt;
[[详细课程安排|点击此处看详细课程安排 (click for more)]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
*观测部分：Peixoto, J. P. and A. H. Oort, 1992: Physics of Climate. Springer-Verlag New York, Inc., 520 pp. 中文译本：气候物理学，1995，吴国雄、刘辉等译校，气象出版社。&lt;br /&gt;
*综合介绍：James, I., 1995: Introduction to circulating atmospheres. Cambridge University Press, 448 pp. &lt;br /&gt;
*理论部分：Vallis, G. K., 2006: Atmospheric and Oceanic Fluid Dynamics: Fundamentals and Large-scale Circulation. Cambridge University Press. 745 pp.&lt;br /&gt;
* [[其它参考书目|其它参考书目（点击看详情）]]&lt;br /&gt;
&lt;br /&gt;
= Course Slides =&lt;br /&gt;
*[2010.09.01] Course introduction ([[file:Course_intro.pdf]]) and Chapter1_1&lt;br /&gt;
&lt;br /&gt;
= Assignments =&lt;br /&gt;
# [[Reanalysis data and the earth&#039;s climatology]] [2010.9.8--2010.9.26]&lt;/div&gt;</summary>
		<author><name>172.21.0.219</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2475</id>
		<title>Randomized Algorithms (Spring 2010)/Approximate counting, linear programming</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2475"/>
		<updated>2010-05-24T19:54:53Z</updated>

		<summary type="html">&lt;p&gt;172.21.4.18: /* FPRAS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Complexity model ===&lt;br /&gt;
Recall the class &#039;&#039;&#039;NP&#039;&#039;&#039; of decision problems (the problems with &amp;quot;yes&amp;quot; or &amp;quot;no&amp;quot; answers). Formally, denoting by &amp;lt;math&amp;gt;\{0,1\}^*&amp;lt;/math&amp;gt; the set of all boolean strings of any lengths, a decision problem is a function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (NP)&#039;&#039;&#039;&lt;br /&gt;
:A function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\{0,1\}&amp;lt;/math&amp;gt; is in &#039;&#039;&#039;NP&#039;&#039;&#039; if there exist a polynomial &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and a poly-time algorithm &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; with boolean output such that for every &amp;lt;math&amp;gt;x\in\{0,1\}^*&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;f(x)=1 \Leftrightarrow \exists y\in\{0,1\}^{p(|x|)}, \mbox{such that } V(x,y)=1\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
Intuitively, the &#039;&#039;&#039;NP&#039;&#039;&#039; class contains all the decision problems such that the answer is &amp;quot;yes&amp;quot; if and only if there &#039;&#039;exists&#039;&#039; a &#039;&#039;&#039;certificate&#039;&#039;&#039; which can be verified in poly-time.&lt;br /&gt;
&lt;br /&gt;
In many contexts, we are interested not just in the &#039;&#039;existence&#039;&#039; of certificate but actually in counting the &#039;&#039;number&#039;&#039; of certificates. This leads to the definition of the class &#039;&#039;&#039;#P&#039;&#039;&#039; (pronounced &amp;quot;sharp p&amp;quot;). Only now the output of the function is a natural number.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (#P)&#039;&#039;&#039;&lt;br /&gt;
:A function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; is in &#039;&#039;&#039;#P&#039;&#039;&#039; if there exist a polynomial &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and a poly-time algorithm &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; with boolean output such that for every &amp;lt;math&amp;gt;x\in\{0,1\}^*&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;f(x)=\left|\left\{y\in\{0,1\}^{p(|x|)}\mid A(x,y)=1\right\}\right|&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
You may notice the similarity between the two definitions. The difference is that now &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt; does not just indicates the existence of a certificate, but gives the actual number of certificates.&lt;br /&gt;
&lt;br /&gt;
Why should we care about the number of &amp;quot;certificates&amp;quot; at all?&lt;br /&gt;
In combinatorics, a counting problem is usually formulated as counting the number of combinatorial objects with some particular structure, such as the number of trees, or Latin squares. The &#039;&#039;&#039;#P&#039;&#039;&#039; class contains the counting problems that the &amp;quot;structure&amp;quot; requirements are easy to check.&lt;br /&gt;
&lt;br /&gt;
;Examples of problems in #P&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;cycles: given as input a graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, count the number of cycles in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;SAT: given as input a boolean formula &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;, count the number of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The second example shows that the &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;P&#039;&#039;&#039; may be harder than &#039;&#039;&#039;NP&#039;&#039;&#039;, because we know that SAT (given a boolean formular, decide the existence of satisfying assignments) is &#039;&#039;&#039;NP-complete&#039;&#039;&#039;, and its counting version &amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;SAT now ask for the exact number of satisfying assignments.&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;FP&#039;&#039;&#039; contains all the functions &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; computable by poly-time algorithms. The classes &#039;&#039;&#039;FP&#039;&#039;&#039; and &#039;&#039;&#039;#P&#039;&#039;&#039; are the analogs of &#039;&#039;&#039;P&#039;&#039;&#039; and &#039;&#039;&#039;NP&#039;&#039;&#039; for counting problems.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;reduction&#039;&#039;&#039; from a problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to a problem &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is a mapping &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; which maps instances of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to instances of &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; such that for any instance &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;,&lt;br /&gt;
:&amp;lt;math&amp;gt;f(x)=g(\phi(x))&amp;lt;/math&amp;gt;.&lt;br /&gt;
In other words, &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; &amp;quot;reduces&amp;quot; the task of solving &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to the task of solving &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt;. A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is said to be &#039;&#039;&#039;poly-time reducible&#039;&#039;&#039; to the problem &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt;, if there exists a reduction &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is poly-time computable.&lt;br /&gt;
&lt;br /&gt;
A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-hard&#039;&#039;&#039; if every problem in &#039;&#039;&#039;#P&#039;&#039;&#039; is poly-time reducible to &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;. A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-complete&#039;&#039;&#039; if &amp;lt;math&amp;gt;f\in&amp;lt;/math&amp;gt;&#039;&#039;&#039;#P&#039;&#039;&#039; and &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. That is to say, &#039;&#039;&#039;#P-complete&#039;&#039;&#039; problems are the &amp;quot;hardest&amp;quot; problems in &#039;&#039;&#039;#P&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Generally, &#039;&#039;&#039;#P-complete&#039;&#039;&#039; problems are very hard, because if we can solve any of these problems in poly-time, then &#039;&#039;&#039;#P&#039;&#039;&#039;=&#039;&#039;&#039;FP&#039;&#039;&#039;, which implies that &#039;&#039;&#039;NP&#039;&#039;&#039;=&#039;&#039;&#039;P&#039;&#039;&#039;. On the other hand, we do not know whether &#039;&#039;&#039;NP&#039;&#039;&#039;=&#039;&#039;&#039;P&#039;&#039;&#039; could imply that &#039;&#039;&#039;#P&#039;&#039;&#039;=&#039;&#039;&#039;FP&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== FPRAS ===&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (FPRAS)&#039;&#039;&#039;&lt;br /&gt;
:A &#039;&#039;&#039;polynomial randomized approximation scheme (PRAS)&#039;&#039;&#039; for a problem &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{R}&amp;lt;/math&amp;gt; is a randomized algorithm &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; that takes an input instance &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; and a real number &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt;, and in time polynomial in &amp;lt;math&amp;gt;n=|x|&amp;lt;/math&amp;gt; returns &amp;lt;math&amp;gt;A(x)&amp;lt;/math&amp;gt; such that&lt;br /&gt;
:::&amp;lt;math&amp;gt;\Pr[(1-\epsilon)f(x)\le A(x)\le (1+\epsilon)f(x)]\ge\frac{3}{4}.&amp;lt;/math&amp;gt;&lt;br /&gt;
:A &#039;&#039;&#039;fully polynomial randomized approximation scheme (FPRAS)&#039;&#039;&#039; is a PRAS whose running time is polynomially in both &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;1/\epsilon&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The constant &amp;lt;math&amp;gt;\frac{3}{4}&amp;lt;/math&amp;gt; in the definition can be replaced by any constant in the range &amp;lt;math&amp;gt;(1/2,1)&amp;lt;/math&amp;gt; without changing the definition. In fact, it is usually more convenient to parameterize the FPRAS by the approximation error and the probability error.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (&amp;lt;math&amp;gt;(\epsilon,\delta)&amp;lt;/math&amp;gt;-FPRAS)&#039;&#039;&#039;&lt;br /&gt;
:An &#039;&#039;&#039;&amp;lt;math&amp;gt;(\epsilon,\delta)&amp;lt;/math&amp;gt;-FPRAS&#039;&#039;&#039; for a problem &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{R}&amp;lt;/math&amp;gt; is an FPRAS with &lt;br /&gt;
::&amp;lt;math&amp;gt;\Pr[(1-\epsilon)f(x)\le A(x)\le (1+\epsilon)f(x)]\ge 1-\delta,&amp;lt;/math&amp;gt;&lt;br /&gt;
:running in time polynomial of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\frac{1}{\epsilon}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;\log\frac{1}{\delta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Approximate Counting ==&lt;br /&gt;
Let us consider the following abstract problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be a finite set of known size, and let &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt;. We want to compute the size of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, namely &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We assume two devices:&lt;br /&gt;
* A &#039;&#039;&#039;uniform sampler&#039;&#039;&#039; &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;, which uniformly and independently samples a member of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; upon each calling.&lt;br /&gt;
* A &#039;&#039;&#039;membership oracle&#039;&#039;&#039; of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;. Given as the input an &amp;lt;math&amp;gt;x\in U&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{O}(x)&amp;lt;/math&amp;gt; indicates whether or not &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is a member of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Equipped by &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;, we can have the following Monte Carlo algorithm:&lt;br /&gt;
*Choose &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; independent samples from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; by the uniform sampler &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;, represented by the random variables &amp;lt;math&amp;gt;X_1,X_2,\ldots, X_N&amp;lt;/math&amp;gt;. &lt;br /&gt;
* Let &amp;lt;math&amp;gt;Y_i&amp;lt;/math&amp;gt; be the indicator random variable defined as &amp;lt;math&amp;gt;Y_i=\mathcal{O}(X_i)&amp;lt;/math&amp;gt;, namely, &amp;lt;math&amp;gt;Y_i&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;X_i\in G&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Define the estimator random variable&lt;br /&gt;
::&amp;lt;math&amp;gt;Z=\frac{|U|}{N}\sum_{i=1}^N Y_i.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is easy to see that &amp;lt;math&amp;gt;\mathbf{E}[Z]=|G|&amp;lt;/math&amp;gt; and we might hope that with high probability the value of &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt; is close to &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt;. Formally, &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt; is called an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation of &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; if&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1-\epsilon)|G|\le Z\le (1+\epsilon)|G|.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following theorem states that the probabilistic accuracy of the estimation depends on the number of samples and the ratio between &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|U|&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Theorem (estimator theorem)&#039;&#039;&#039;&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;. Then the Monte Carlo method yields an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation to &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; with probability at least &amp;lt;math&amp;gt;1-\delta&amp;lt;/math&amp;gt; provided&lt;br /&gt;
::&amp;lt;math&amp;gt;N\ge\frac{4}{\epsilon \alpha}\ln\frac{2}{\delta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;Proof&#039;&#039;&#039;: Use the Chernoff bound.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A counting algorithm for the set &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has to deal with the following three complications:&lt;br /&gt;
* Implement the membership oracle &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;. This is usually straightforward, or assumed by the model.&lt;br /&gt;
* Implement the uniform sampler &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;. As we have seen, this is usually approximated by random walks. How to design the random walk and bound its mixing rate is usually technical challenging, if possible at all.&lt;br /&gt;
* Deal with exponentially small &amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;. This requires us to cleverly choose the universe &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. Sometimes this needs some nontrivial ideas.&lt;br /&gt;
&lt;br /&gt;
=== Counting DNFs ===&lt;br /&gt;
A disjunctive normal form (DNF) formular is a disjunction (OR) of clauses, where each clause is a conjunction (AND) of literals. For example:&lt;br /&gt;
:&amp;lt;math&amp;gt;(x_1\wedge \overline{x_2}\wedge x_3)\vee(x_2\wedge x_4)\vee(\overline{x_1}\wedge x_3\wedge x_4)&amp;lt;/math&amp;gt;.&lt;br /&gt;
Note the difference from the conjunctive normal forms (CNF).&lt;br /&gt;
&lt;br /&gt;
Given a DNF formular &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; as the input, the problem is to count the number of satisfying assignments of &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. This problem is &#039;&#039;&#039;#P-complete&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Naively applying the Monte Carlo method will not give a good answer. Suppose that there are &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;U=\{\mathrm{true},\mathrm{false}\}^n&amp;lt;/math&amp;gt; be the set of all truth assignments of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;G=\{x\in U\mid \phi(x)=\mathrm{true}\}&amp;lt;/math&amp;gt; be the set of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. The straightforward use of Monte Carlo method samples &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; assignments from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and check how many of them satisfy &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. This algorithm fails when &amp;lt;math&amp;gt;|G|/|U|&amp;lt;/math&amp;gt; is exponentially small, namely, when exponentially small fraction of the assignments satisfy the input DNF formula. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;The union of sets problem&lt;br /&gt;
We reformulate the DNF counting problem in a more abstract framework, called the &#039;&#039;&#039;union of sets&#039;&#039;&#039; problem. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; be a finite universe. We are given &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; subsets &amp;lt;math&amp;gt;H_1,H_2,\ldots,H_m\subseteq V&amp;lt;/math&amp;gt;. The following assumptions hold:&lt;br /&gt;
*For all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;|H_i|&amp;lt;/math&amp;gt; is computable in poly-time.&lt;br /&gt;
*It is possible to sample uniformly from each individual &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
*For any &amp;lt;math&amp;gt;x\in V&amp;lt;/math&amp;gt;, it can be determined in poly-time whether &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The goal is to compute the size of &amp;lt;math&amp;gt;H=\bigcup_{i=1}^m H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
DNF counting can be interpreted in this general framework as follows. Suppose that the DNF formula &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is defined on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables, and &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; contains &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; clauses &amp;lt;math&amp;gt;C_1,C_2,\ldots,C_m&amp;lt;/math&amp;gt;, where clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;k_i&amp;lt;/math&amp;gt; literals. Without loss of generality, we assume that in each clause, each variable appears at most once.&lt;br /&gt;
* &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; is the set of all assignments.&lt;br /&gt;
*Each &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is the set of satisfying assignments for the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;-th clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; of the DNF formular &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. Then the union of sets &amp;lt;math&amp;gt;H=\bigcup_i H_i&amp;lt;/math&amp;gt; gives the set of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Each clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; is a conjunction (AND) of literals. It is not hard to see that &amp;lt;math&amp;gt;|H_i|=2^{n-k_i}&amp;lt;/math&amp;gt;, which is efficiently computable.&lt;br /&gt;
* Sampling from an &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is simple: we just fix the assignments of the &amp;lt;math&amp;gt;k_i&amp;lt;/math&amp;gt; literals of that clause, and sample uniformly and independently the rest &amp;lt;math&amp;gt;(n-k_i)&amp;lt;/math&amp;gt; variable assignments.&lt;br /&gt;
* For each assignment &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, it is easy to check whether it satisfies a clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt;, thus it is easy to determine whether &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
;The coverage algorithm&lt;br /&gt;
We now introduce the coverage algorithm for the union of sets problem.&lt;br /&gt;
&lt;br /&gt;
Consider the multiset &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; defined by&lt;br /&gt;
:&amp;lt;math&amp;gt;U=H_1\uplus H_2\uplus\cdots \uplus H_m&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\uplus&amp;lt;/math&amp;gt; denotes the multiset union. It is more convenient to define &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; as the set&lt;br /&gt;
:&amp;lt;math&amp;gt;U=\{(x,i)\mid x\in H_i\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
For each &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt;, there may be more than one instances of &amp;lt;math&amp;gt;(x,i)\in U&amp;lt;/math&amp;gt;. We can choose a unique representative among the multiple instances &amp;lt;math&amp;gt;(x,i)\in U&amp;lt;/math&amp;gt; for the same &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt;, by choosing the &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt; with the minimum &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, and form a set &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, &amp;lt;math&amp;gt;G=\{(x,i)\in U\mid \forall (x,j)\in U, j\le i\}&amp;lt;/math&amp;gt;. Every &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt; corresponds to a unique &amp;lt;math&amp;gt;(x,i)\in G&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the smallest among &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is obvious that &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt; and&lt;br /&gt;
:&amp;lt;math&amp;gt;|G|=|H|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, estimation of &amp;lt;math&amp;gt;|H|&amp;lt;/math&amp;gt; is reduced to estimation of &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; can have an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation with probability &amp;lt;math&amp;gt;(1-\delta)&amp;lt;/math&amp;gt; in poly-time, if we can uniformly sample from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|G|/|U|&amp;lt;/math&amp;gt; is suitably small.&lt;br /&gt;
&lt;br /&gt;
An uniform sample from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; can be implemented as follows:&lt;br /&gt;
* generate an &amp;lt;math&amp;gt;i\in\{1,2,\ldots,m\}&amp;lt;/math&amp;gt; with probability &amp;lt;math&amp;gt;\frac{|H_i|}{\sum_{i=1}^m|H_i|}&amp;lt;/math&amp;gt;;&lt;br /&gt;
* uniformly sample an &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;, and return &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is easy to see that this gives a uniform member of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. The above sampling procedure is poly-time because each &amp;lt;math&amp;gt;|H_i|&amp;lt;/math&amp;gt; can be computed in poly-time, and sampling uniformly from each &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is poly-time.&lt;br /&gt;
&lt;br /&gt;
We now only need to lower bound the ratio&lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We claim that &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha\ge\frac{1}{m}&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is easy to see this, because each &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt; has at most &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; instances of &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;, and we already know that &amp;lt;math&amp;gt;|G|=|H|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Due to the estimator theorem, this needs &amp;lt;math&amp;gt;\frac{4m}{\epsilon}\ln\frac{2}{\delta}&amp;lt;/math&amp;gt; uniform random samples from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This gives the coverage algorithm for the abstract problem of the union of sets. The DNF counting is a special case of it.&lt;br /&gt;
&lt;br /&gt;
=== Permanents and perfect matchings ===&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;U=\{u_1,u_2,\ldots,u_n\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;V=\{v_1,v_2,\ldots,v_n\}&amp;lt;/math&amp;gt;. Consider a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt;. An &amp;lt;math&amp;gt;M\subseteq E&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;perfect matching&#039;&#039;&#039; of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; if every vertex of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has exactly one edge in &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; adjacent to it.&lt;br /&gt;
&lt;br /&gt;
Given a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt;, we want to count the number of perfect matchings of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. This problem can be reduced to computing the &#039;&#039;&#039;permanent&#039;&#039;&#039; of a square matrix.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (permanent)&#039;&#039;&#039;&lt;br /&gt;
:Let &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix. The &#039;&#039;&#039;permanent&#039;&#039;&#039; of the matrix is defined as&lt;br /&gt;
::&amp;lt;math&amp;gt;\mathrm{per}(Q)=\sum_{\pi\in\mathbb{S}_n}\prod_{i=1}^n Q_{i,\pi(i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\mathbb{S}_n&amp;lt;/math&amp;gt; is the symmetric group of permutation of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If we multiply each term of the sum the sign of the permutation, then it gives us the determinant of the matrix, &lt;br /&gt;
:&amp;lt;math&amp;gt;\det(Q)=\sum_{\pi\in\mathbb{S}_n}\sgn(\pi)\prod_{i=1}^n Q_{i,\pi(i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\sgn(\pi)&amp;lt;/math&amp;gt;, the sign of a permutation, is either &amp;lt;math&amp;gt;-1&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;+1&amp;lt;/math&amp;gt;, according to whether the minimum number of pair-wise interchanges to achieve &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;(1,2,\ldots,n)&amp;lt;/math&amp;gt; is odd or even.&lt;br /&gt;
&lt;br /&gt;
Unlike the determinants, which are computable in poly-time, permanents are hard to compute, as permanents can be used to count the number of perfect matchings in a bipartite graph, which is &#039;&#039;&#039;#P-complete&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt; can be represented by an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; with 0-1 entries as follows:&lt;br /&gt;
* Each row of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; corresponds to a vertex in &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and each column of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; corresponds to a vertex in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;Q_{ij}=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }i\sim j,\\&lt;br /&gt;
0 &amp;amp; \mbox{otherwise}.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Note the subtle difference between the definition of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; and the adjacency matrix. &lt;br /&gt;
&lt;br /&gt;
Each perfect matching corresponds to a permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;(u,\pi(u))\in E&amp;lt;/math&amp;gt; for every &amp;lt;math&amp;gt;u\in U&amp;lt;/math&amp;gt;, which corresponds to a permutation &amp;lt;math&amp;gt;\pi\in\mathbb{S}_n&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;\prod_{i=1}^n Q_{i,\pi(i)}=1&amp;lt;/math&amp;gt;. It is than easy to see that &amp;lt;math&amp;gt;\mathrm{per}(Q)&amp;lt;/math&amp;gt; gives the number of perfect matchings in the bipartite graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is known that counting the number of perfect matchings in a bipartite graph is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. Since this problem can be reduced to computing the permanent, thus the problem of computing the permanents is also &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Now we show that with randomization, we can approximate the number of perfect matchings in a bipartite graph. In particular, we will give an FPRAS for counting the perfect matchings in a dense bipartite graph.&lt;br /&gt;
&lt;br /&gt;
==== The Jerrum-Sinclair algorithm ====&lt;br /&gt;
Fix a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\mathcal{M}_k&amp;lt;/math&amp;gt; be the set of matchings of size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;m_k=|\mathcal{M}_k|&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;\mathcal{M}_k&amp;lt;/math&amp;gt; is the set of perfect matchings in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and our goal is to compute &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;r_k=\frac{m_k}{m_{k-1}}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;m_k=m_{k-1}r_k&amp;lt;/math&amp;gt;,&lt;br /&gt;
which gives us a recursion to compute the &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt;, as&lt;br /&gt;
:&amp;lt;math&amp;gt;m_n=m_{1}\frac{m_2}{m_1}\cdot\frac{m_3}{m_2}\cdots\frac{m_n}{m_{n-1}}=m_1\prod_{k=2}^n r_k&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;m_1=|\mathcal{M}_1|&amp;lt;/math&amp;gt; is the number of matchings of size 1 in the bipartite graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, which is just the number of edges in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; can be computed once we know &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; can be estimated by sampling uniformly from the set &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;. The algorithm for estimating &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; is outlined as:&lt;br /&gt;
# For each &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;, have an FPRAS for computing the &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; by uniform sampling sufficiently many members from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt; as&lt;br /&gt;
::*uniformly sample &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; matching from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;, for some polynomially large &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;;&lt;br /&gt;
::* assuming that there are &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; sampled matchings of size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, return &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; as &amp;lt;math&amp;gt;r_k=\frac{X}{N-X}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2.  Compute &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; as &amp;lt;math&amp;gt;m_n=m_1\prod_{k=2}^n r_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;m_1=|E|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
There are several issues that we have to deal with in order to have a fully functional FPRAS for counting perfect matchings.&lt;br /&gt;
* By taking the product of &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&#039;s, the errors for individual &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&#039;s add up.&lt;br /&gt;
* In order to accurately estimate &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; by sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;, the ratio &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; should be within the range &amp;lt;math&amp;gt;\left[\frac{1}{\alpha},\alpha\right]&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; within polynomial of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Implement the uniform sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
;Estimator for each &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Accumulation of errors&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
; Near-uniform sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
In the last lecture, we have shown that by random walk, we can sample a near-uniform member of &amp;lt;math&amp;gt;\mathcal{M}_n\cup\mathcal{M}_{n-1}&amp;lt;/math&amp;gt; in poly-time.&lt;br /&gt;
&lt;br /&gt;
=== Volume estimation  ===&lt;br /&gt;
We consider the problem of computing the volume of a given [http://en.wikipedia.org/wiki/Convex_body convex body] &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions. &lt;br /&gt;
&lt;br /&gt;
We use &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; to denote the volume of the convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;. Abstractly, the problem is that given as input a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, return the &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We should be more specific about the input model. Since we allow an arbitrary convex body as input, it is not even clear how to describe the body. We assume that &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is described by means of a &#039;&#039;&#039;membership oracle&#039;&#039;&#039; &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;, such that  for a &#039;&#039;&#039;query&#039;&#039;&#039; of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{O}(x)&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;x\in K&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example, the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional convex body defined by the intersection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; half-spaces, which is the set of feasible solutions to a system of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; linear constraints, can be described as&lt;br /&gt;
:&amp;lt;math&amp;gt;A x\le \boldsymbol{b}&amp;lt;/math&amp;gt;,&lt;br /&gt;
for some &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector &amp;lt;math&amp;gt;b&amp;lt;/math&amp;gt;. For a query of an &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, the membership oracle &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt; just check whether &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For deterministic algorithms, there are negative news for this problem.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Theorem (Bárány-Füredi 1987)&#039;&#039;&#039;&lt;br /&gt;
:Suppose that a deterministic poly-time algorithm uses the membership oracle for a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, and generates an upper bound &amp;lt;math&amp;gt;\Upsilon_u\,&amp;lt;/math&amp;gt; and a lower bound &amp;lt;math&amp;gt;\Upsilon_\ell\,&amp;lt;/math&amp;gt; on the volume &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;. Then, there is a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and a constant &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; such that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{\Upsilon_u}{\Upsilon_\ell}\ge c\left(\frac{n}{\log n}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
That is said, with deterministic algorithms, we cannot even approximate the volume within a wildly loose range.&lt;br /&gt;
&lt;br /&gt;
Dyer-Frieze-Kannan come up with an idea of estimating the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; by sampling near-uniformly from convex sets. They reduce the problem of computing approximately the volume of convex bodies to this sampling problem and thus give the first FPRAS for the volume of convex bodies.&lt;br /&gt;
&lt;br /&gt;
For any convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, it encloses some &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional ball and is also enclosed by another ball with larger radius. We assume that the convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; encloses the unit ball around the origin, and is enclosed by a larger ball round the origin with polynomially large radius. Formally, we assume that&lt;br /&gt;
:&amp;lt;math&amp;gt;B(0,1)\subseteq K\subseteq B(0,n^c)&amp;lt;/math&amp;gt; for some constant &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;B(p,r)&amp;lt;/math&amp;gt; denotes a ball of radius &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; as center, i.e. &amp;lt;math&amp;gt;B(p,r)=\{x\mid \|x-p\|\le r \}&amp;lt;/math&amp;gt;. We can make this assumption because it is known that for any convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, there exists a linear transformation &amp;lt;math&amp;gt;\tau&amp;lt;/math&amp;gt; which can be found within poly-time such that &amp;lt;math&amp;gt;\tau K&amp;lt;/math&amp;gt; transforms the &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; to a convex body that satisfies the assumption, and preserves the ratio of the volumes of the balls to the convex body.&lt;br /&gt;
&lt;br /&gt;
The volumes of the balls are easy to compute. If only the ratio between the convex body and the ball which encloses it, is sufficiently large, then we can apply the Monte Carlo method to estimate &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; by uniformly sampling from the ball.&lt;br /&gt;
&lt;br /&gt;
However, in high-dimension, the ratio between the volume of a convex body and the volume of ball which encloses it, can be exponentially small. This is caused by the so called the &amp;quot;[http://en.wikipedia.org/wiki/Curse_of_dimensionality curse of dimensionality]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Instead of having an outer ball and an inner ball, we define a sequence of balls:&lt;br /&gt;
:&amp;lt;math&amp;gt;B_0=B(0,\lambda^0), B_1=B(0,\lambda^1), B_2=B(0,\lambda^2),\ldots, B_m=B(0,\lambda^m)&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\lambda=(1+\frac{1}{n})&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is the smallest positive integer such that &amp;lt;math&amp;gt;\lambda^m\ge n^c&amp;lt;/math&amp;gt;. Therefore, the inner ball &amp;lt;math&amp;gt;B(0,1)=B_0&amp;lt;/math&amp;gt;, the outer ball &amp;lt;math&amp;gt;B(0,n^c)\subseteq B_m&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is within polynomial of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. In fact, &amp;lt;math&amp;gt;m\approx cn\ln n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This sequence of balls naturally defines a sequence of convex bodies by intersections as &amp;lt;math&amp;gt;K_i=B_i\cap K&amp;lt;/math&amp;gt;. It is obvious that&lt;br /&gt;
:&amp;lt;math&amp;gt;B(0,1)=K_0\subseteq K_1\subseteq K_2\subseteq\cdots\subseteq K_m=K&amp;lt;/math&amp;gt;.&lt;br /&gt;
Balls are convex, and since the intersection of convex bodies is still convex, the sequence of &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt; is a sequence of convex bodies.&lt;br /&gt;
&lt;br /&gt;
We have the telescopic product:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\Upsilon(K_0)}{\Upsilon(K_1)}\cdot\frac{\Upsilon(K_1)}{\Upsilon(K_2)}\cdots\frac{\Upsilon(K_{m-1})}{\Upsilon(K_m)}=\frac{\Upsilon(K_0)}{\Upsilon(K_m)}=\frac{\Upsilon(B(0,1))}{\Upsilon(K)}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, the volume &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; can be computed as &lt;br /&gt;
:&amp;lt;math&amp;gt;\Upsilon(K)=\Upsilon(B(0,1))\cdot\prod_{i=1}^{m}\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The volume of unite ball &amp;lt;math&amp;gt;\Upsilon(B(0,1))\,&amp;lt;/math&amp;gt; can be precisely computed in poly-time. Each &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is computed by near-uniform sampling from &amp;lt;math&amp;gt;K_{i}&amp;lt;/math&amp;gt;, which encloses &amp;lt;math&amp;gt;K_{i-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Another observation is that the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is well-bounded. Recall that &amp;lt;math&amp;gt;K_i=B(0,\lambda^i)\cap K&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;\lambda=(1+\frac{1}{n})&amp;lt;/math&amp;gt;. It can be proved that in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, the volume of &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt; is at most &amp;lt;math&amp;gt;\lambda^n&amp;lt;/math&amp;gt; times the &amp;lt;math&amp;gt;K_{i-1}&amp;lt;/math&amp;gt;, thus the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is at most &amp;lt;math&amp;gt;\lambda^n=O(1)&amp;lt;/math&amp;gt;. By the estimator theorem, we can have an FPRAS for the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; if we can uniformly sample from &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Uniformly sampling from an arbitrary convex body is replaced by near-uniform sampling achieved by random walks. In the original walk of Dyer-Frieze-Kannan, they consider the random walk over &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional discrete grid points enclosed by &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, and prove that the walk is rapid mixing. This gives us the first FPRAS for volume estimation which runs in &amp;lt;math&amp;gt;\tilde{O}(n^{23})&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\tilde{O}(\cdot)&amp;lt;/math&amp;gt; ignores the polylogarithmic factors.&lt;br /&gt;
&lt;br /&gt;
The time bound was later improved by a series of works, each introducing some new ideas.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
| || complexity || new ingredient(s)&lt;br /&gt;
|-&lt;br /&gt;
| Dyer-Frieze-Kannan 1991 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{23}&amp;lt;/math&amp;gt; || everything&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Simonovits 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{16}&amp;lt;/math&amp;gt; || localization lemma&lt;br /&gt;
|-&lt;br /&gt;
| Applegate-Kannan 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{10}&amp;lt;/math&amp;gt; || logconcave sampling&lt;br /&gt;
|-&lt;br /&gt;
| Lovász 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{10}&amp;lt;/math&amp;gt; || ball walk&lt;br /&gt;
|-&lt;br /&gt;
| Dyer-Frieze 1991 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^8&amp;lt;/math&amp;gt; || better error analysis&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Simonovits 1993 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^7&amp;lt;/math&amp;gt; || many improvements&lt;br /&gt;
|-&lt;br /&gt;
| Kannan-Lovász-Simonovits 1997 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^5&amp;lt;/math&amp;gt; || isotropy, speedy walk&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Vempala 2003 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^4&amp;lt;/math&amp;gt; || simulated annealing, hit-and-run&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
(cited from &amp;quot;Geometric Random Walks: A Survey&amp;quot; by Santosh Vempala.)&lt;br /&gt;
&lt;br /&gt;
The current best upper bound is &amp;lt;math&amp;gt;\tilde{O}(n^4)&amp;lt;/math&amp;gt; due to Lovász and Vempala in 2003. It is conjectured that the optimal bound is &amp;lt;math&amp;gt;\Theta(n^3)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Linear Programming ==&lt;br /&gt;
Given a function &amp;lt;math&amp;gt;f:\mathbb{R}^n\rightarrow\mathbb{R}&amp;lt;/math&amp;gt; and a set &amp;lt;math&amp;gt;\mathcal{F}\subseteq\mathbb{R}^n&amp;lt;/math&amp;gt;, an &#039;&#039;&#039;optimization problem&#039;&#039;&#039; is the problem of finding an &amp;lt;math&amp;gt;x\in\mathcal{F}&amp;lt;/math&amp;gt; with the optimal (minimum) &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;. Formally, the problem can be expressed as:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize} &amp;amp; \quad f(x)\\&lt;br /&gt;
\mbox{subject to} &amp;amp;\quad  x\in\mathcal{F}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;x\in\mathcal{R}^n&amp;lt;/math&amp;gt; is a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. For the problem of maximizing a function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, we just minimizes &amp;lt;math&amp;gt;-f&amp;lt;/math&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
We call the function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; the &#039;&#039;&#039;objective function&#039;&#039;&#039; and call any &amp;lt;math&amp;gt;x\in\mathcal{F}&amp;lt;/math&amp;gt; a &#039;&#039;&#039;feasible solution&#039;&#039;&#039; of the problem. A feasible solution that minimizes &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;optimal solution&#039;&#039;&#039;. Our task is to find an optimal solution.&lt;br /&gt;
&lt;br /&gt;
The feasible set &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is usually given by a number of &#039;&#039;&#039;constraints&#039;&#039;&#039; &amp;lt;math&amp;gt;P_1,P_2,\ldots,P_m&amp;lt;/math&amp;gt;, which are predicates defined on &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. An &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is a feasible solution if it satisfies all the constraints. &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;linear programming (LP)&#039;&#039;&#039; problem is an optimization problem with a linear objective function subject to a number of linear constraints. Formally, an LP is a problem that can be expressed in the following form:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c_1x_1+c_2x_2+\cdots+c_nx_n\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad a_{11}x_1+a_{12}x_2+\cdots+a_{1n}x_n\le b_1\\&lt;br /&gt;
&amp;amp; \quad a_{21}x_1+a_{22}x_2+\cdots+a_{2n}x_n\le b_2\\&lt;br /&gt;
&amp;amp; \qquad\qquad \vdots\\&lt;br /&gt;
&amp;amp; \quad a_{m1}x_1+a_{m2}x_2+\cdots+a_{mn}x_n\le b_m\\&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;a_{ij}&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;c_j&amp;lt;/math&amp;gt; are constants and &amp;lt;math&amp;gt;x_j&amp;lt;/math&amp;gt; are variables. For maximization problem, or constraints given by &amp;quot;&amp;lt;math&amp;gt;\ge&amp;lt;/math&amp;gt;&amp;quot;, we can multiply  the coefficients by &amp;lt;math&amp;gt;-1&amp;lt;/math&amp;gt; and still write the LP in the above form. &lt;br /&gt;
&lt;br /&gt;
We can describe the programming in the vector form. Let &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;A=(a_{ij})&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; matrix of constant entries, &amp;lt;math&amp;gt;b=(b_1,\ldots,b_m)&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; constant entries, and &amp;lt;math&amp;gt;c=(c_1,\ldots,c_n)&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; constant entries. Then an LP is expressed as:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c^T x\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad Ax\le b&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
We call it the &#039;&#039;&#039;canonical form&#039;&#039;&#039; of linear programming.&lt;br /&gt;
&lt;br /&gt;
=== The geometry of LPs ===&lt;br /&gt;
For &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional space &amp;lt;math&amp;gt;\mathbb{R}^n&amp;lt;/math&amp;gt;, a linear constraint &amp;lt;math&amp;gt;ax\le b&amp;lt;/math&amp;gt; specifies a [http://en.wikipedia.org/wiki/Half-space halfspace]. The feasible set specified by &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; constraints together is an intersection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; halfspaces, thus, a [http://en.wikipedia.org/wiki/Convex_polytope convex polytope].&lt;br /&gt;
&lt;br /&gt;
The convex polytope is defined by &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The LP can be thought as given an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional polytope and a linear (affine) function &amp;lt;math&amp;gt;f:\mathbb{R}^n\rightarrow \mathbb{R}&amp;lt;/math&amp;gt;, looking for a point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; in the polytope with the smallest function value &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We can choose a number of constraints in the system &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, and make them hold with equality. This would define a subspace of &amp;lt;math&amp;gt;\mathbb{R}^n&amp;lt;/math&amp;gt;. In particular, if we choose &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; linearly independent constraints to form an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; submatrix &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; and the corresponding &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector &amp;lt;math&amp;gt;b&#039;&amp;lt;/math&amp;gt;, solving &amp;lt;math&amp;gt;A&#039;x=b&#039;&amp;lt;/math&amp;gt; would give us exactly one point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. If this &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is in the polytope, i.e. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; satisfies that &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, we call such &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; a &#039;&#039;&#039;vertex&#039;&#039;&#039; of the polytope &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;. In the context of LP, it is also called a &#039;&#039;&#039;basic feasible solution (&#039;&#039;bfs&#039;&#039;)&#039;&#039;&#039; of the LP.&lt;br /&gt;
&lt;br /&gt;
A key observation for LP is that there is a basic feasible solution which is optimal, i.e. the optimal solution is a vertex of the polytope.&lt;br /&gt;
&lt;br /&gt;
=== The simplex algorithms ===&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Simplex_algorithm simplex algorithm] by George Dantzig solves the linear programming by moving from vertex to vertex of the convex polytope, each time making some progress towards optimizing the objective function. Eventually the algorithm reaches a vertex which is a [http://en.wikipedia.org/wiki/Local_optimum local optimum]. In a convex set, a locally optimal point is also global optimal, thus the simplex algorithm returns an optimal solution in finite steps.&lt;br /&gt;
&lt;br /&gt;
The problem with the simplex algorithm is that in some bad polytopes, it takes the simplex algorithm exponentially many steps to reach the optimum. The simplex algorithm is actually a class of algorithms defined by various &#039;&#039;&#039;pivoting rules&#039;&#039;&#039;, which describe how to move locally from one vertex to another. The original pivoting rule proposed by Dantzig has an exponentially large worst-case time complexity (though works very good in practice). To-date, it is still unknown whether there exists any deterministic simplex algorithm with sub-exponential worst-case complexity.&lt;br /&gt;
&lt;br /&gt;
People have tried randomized pivoting rules, and there are some amazing progresses have been made:&lt;br /&gt;
* Kalai 1992: there is a randomized simplex algorithm with sub-exponential time complexity.&lt;br /&gt;
* Kelner-Spielman 2006: there is a polynomial time randomized simplex algorithm.&lt;br /&gt;
&lt;br /&gt;
Although we do not know whether there exists deterministic poly-time simplex algorithm, we do know that LP can be solved by deterministic poly-time algorithms, i.e. LP is in &#039;&#039;&#039;P&#039;&#039;&#039;. The following two algorithms use different ideas than the simplex algorithm, and are both in poly-time:&lt;br /&gt;
* The ellipsoid algorithm.&lt;br /&gt;
* Interior point methods.&lt;br /&gt;
Although these algorithms guarantee polynomial time complexity in the worst-case, their performances are worse than the simplex algorithms. However, the ideas of these algorithms can be used to solve more general mathematical programmings, such as [http://en.wikipedia.org/wiki/Convex_programming convex programmings].&lt;br /&gt;
&lt;br /&gt;
=== An LP solver via random walks ===&lt;br /&gt;
We discuss a new algorithm for solving LP which is based on random sampling, introduced by Bertsimas and Vempala in 2004. &lt;br /&gt;
&lt;br /&gt;
The problem of solving an LP can be reduced to that given a convex polytope &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, test whether the polytope is empty. We call this problem the &amp;quot;&#039;&#039;feasibility test&#039;&#039;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Suppose we have an LP:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c^T x\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad Ax\le b&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
To see this LP can be solved by feasibility testing, we treat the &amp;lt;math&amp;gt;c^Tx\le d&amp;lt;/math&amp;gt; for some parameter &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; as an additional constraint, and define a new polytope &amp;lt;math&amp;gt;A&#039;x\le b&#039;&amp;lt;/math&amp;gt;. The smallest &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; that the polytope &amp;lt;math&amp;gt;A&#039;x\le b&#039;&amp;lt;/math&amp;gt; is not empty is the optimal solution to the original LP. We can find this smallest &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; by binary search if we can efficiently test the emptiness of a convex polytope.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We assume that the convex polytope &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is contained in the axis-aligned cube of width &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; centered at the origin; further if &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is non-empty then it contains a cube of width &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;. The parameter &amp;lt;math&amp;gt;L&amp;lt;/math&amp;gt; is equal to &amp;lt;math&amp;gt;\log\frac{R}{r}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Algorithm&#039;&#039;&#039;: feasibility test &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Input&#039;&#039;&#039;: an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional convex polytope &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; defined by the system &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;: a point &amp;lt;math&amp;gt;x\in P&amp;lt;/math&amp;gt; in the polytope, or a guarantee that &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is empty.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; be the axis-aligned cube of side length &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; and center &amp;lt;math&amp;gt;z=\boldsymbol{0}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Repeat for &amp;lt;math&amp;gt;2nL&amp;lt;/math&amp;gt; times do:&lt;br /&gt;
:: If &amp;lt;math&amp;gt;Az\le b&amp;lt;/math&amp;gt;, return &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: Pick a constraint violated by &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;, say that &amp;lt;math&amp;gt;A_i z&amp;gt;b_i&amp;lt;/math&amp;gt;, and define the halfspace&lt;br /&gt;
:::&amp;lt;math&amp;gt;H=\{x\mid A_i x\le A_i z\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
::Set &amp;lt;math&amp;gt;K=K\cap H&amp;lt;/math&amp;gt;. Uniformly sample &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; random points &amp;lt;math&amp;gt;y^{(1)},y^{(2)},\ldots,y^{(N)}&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and let &lt;br /&gt;
:::&amp;lt;math&amp;gt;z=\frac{1}{N}\sum_{i=1}^Ny^{(i)}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Report &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is empty.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The number of samples required in each iteration, &amp;lt;math&amp;gt;N=O((\log m)^2)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is the number of linear constraints. &lt;br /&gt;
&lt;br /&gt;
It is easy to see that at any iteration, &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is a convex set, and &amp;lt;math&amp;gt;P\subseteq K&amp;lt;/math&amp;gt; for the current convex set &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The idea of the algorithm is based on computing the [http://en.wikipedia.org/wiki/Centroid centroid] of the convex set.  It is know that if we could compute the exact centroid in each iteration, then the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; drops by a constant factor &amp;lt;math&amp;gt;(1-1/e)&amp;lt;/math&amp;gt; in each iteration, thus reaches the smallest possible volume of a cube of width &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; within polynomial number of iterations. But, finding the centroid of a convex polytope, is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The idea behind the algorithm is that an approximate centroid can be computed using &amp;lt;math&amp;gt;N=O((\log m)^2)&amp;lt;/math&amp;gt; random points and the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is drops by a constant factor with high probability in each iteration with this choice of &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
The uniform sampling in &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is not easy. But since &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is also a convex polytope, we can approximate the uniform sampling by  near-uniform sampling from &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; by rapid mixing random walks. The random walks used here are similar to the ones used in the volume estimation of convex bodies. We could use the basic grid walk, or more advanced ball walk, or hit-and-run walk.&lt;br /&gt;
&lt;br /&gt;
With rapid mixing random walks, the resulting LP solver runs in poly-time.&lt;br /&gt;
&lt;br /&gt;
The details are omitted. You may check the following paper if interested:&lt;br /&gt;
* Bertsimas and Vempala, “&#039;&#039;Solving convex programs by random walks&#039;&#039;.” JACM 2004.&lt;/div&gt;</summary>
		<author><name>172.21.4.18</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2474</id>
		<title>Randomized Algorithms (Spring 2010)/Approximate counting, linear programming</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2474"/>
		<updated>2010-05-24T19:47:55Z</updated>

		<summary type="html">&lt;p&gt;172.21.4.18: /* FPRAS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Complexity model ===&lt;br /&gt;
Recall the class &#039;&#039;&#039;NP&#039;&#039;&#039; of decision problems (the problems with &amp;quot;yes&amp;quot; or &amp;quot;no&amp;quot; answers). Formally, denoting by &amp;lt;math&amp;gt;\{0,1\}^*&amp;lt;/math&amp;gt; the set of all boolean strings of any lengths, a decision problem is a function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (NP)&#039;&#039;&#039;&lt;br /&gt;
:A function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\{0,1\}&amp;lt;/math&amp;gt; is in &#039;&#039;&#039;NP&#039;&#039;&#039; if there exist a polynomial &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and a poly-time algorithm &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; with boolean output such that for every &amp;lt;math&amp;gt;x\in\{0,1\}^*&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;f(x)=1 \Leftrightarrow \exists y\in\{0,1\}^{p(|x|)}, \mbox{such that } V(x,y)=1\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
Intuitively, the &#039;&#039;&#039;NP&#039;&#039;&#039; class contains all the decision problems such that the answer is &amp;quot;yes&amp;quot; if and only if there &#039;&#039;exists&#039;&#039; a &#039;&#039;&#039;certificate&#039;&#039;&#039; which can be verified in poly-time.&lt;br /&gt;
&lt;br /&gt;
In many contexts, we are interested not just in the &#039;&#039;existence&#039;&#039; of certificate but actually in counting the &#039;&#039;number&#039;&#039; of certificates. This leads to the definition of the class &#039;&#039;&#039;#P&#039;&#039;&#039; (pronounced &amp;quot;sharp p&amp;quot;). Only now the output of the function is a natural number.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (#P)&#039;&#039;&#039;&lt;br /&gt;
:A function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; is in &#039;&#039;&#039;#P&#039;&#039;&#039; if there exist a polynomial &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and a poly-time algorithm &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; with boolean output such that for every &amp;lt;math&amp;gt;x\in\{0,1\}^*&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;f(x)=\left|\left\{y\in\{0,1\}^{p(|x|)}\mid A(x,y)=1\right\}\right|&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
You may notice the similarity between the two definitions. The difference is that now &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt; does not just indicates the existence of a certificate, but gives the actual number of certificates.&lt;br /&gt;
&lt;br /&gt;
Why should we care about the number of &amp;quot;certificates&amp;quot; at all?&lt;br /&gt;
In combinatorics, a counting problem is usually formulated as counting the number of combinatorial objects with some particular structure, such as the number of trees, or Latin squares. The &#039;&#039;&#039;#P&#039;&#039;&#039; class contains the counting problems that the &amp;quot;structure&amp;quot; requirements are easy to check.&lt;br /&gt;
&lt;br /&gt;
;Examples of problems in #P&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;cycles: given as input a graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, count the number of cycles in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;SAT: given as input a boolean formula &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;, count the number of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The second example shows that the &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;P&#039;&#039;&#039; may be harder than &#039;&#039;&#039;NP&#039;&#039;&#039;, because we know that SAT (given a boolean formular, decide the existence of satisfying assignments) is &#039;&#039;&#039;NP-complete&#039;&#039;&#039;, and its counting version &amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;SAT now ask for the exact number of satisfying assignments.&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;FP&#039;&#039;&#039; contains all the functions &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; computable by poly-time algorithms. The classes &#039;&#039;&#039;FP&#039;&#039;&#039; and &#039;&#039;&#039;#P&#039;&#039;&#039; are the analogs of &#039;&#039;&#039;P&#039;&#039;&#039; and &#039;&#039;&#039;NP&#039;&#039;&#039; for counting problems.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;reduction&#039;&#039;&#039; from a problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to a problem &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is a mapping &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; which maps instances of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to instances of &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; such that for any instance &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;,&lt;br /&gt;
:&amp;lt;math&amp;gt;f(x)=g(\phi(x))&amp;lt;/math&amp;gt;.&lt;br /&gt;
In other words, &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; &amp;quot;reduces&amp;quot; the task of solving &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to the task of solving &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt;. A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is said to be &#039;&#039;&#039;poly-time reducible&#039;&#039;&#039; to the problem &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt;, if there exists a reduction &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is poly-time computable.&lt;br /&gt;
&lt;br /&gt;
A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-hard&#039;&#039;&#039; if every problem in &#039;&#039;&#039;#P&#039;&#039;&#039; is poly-time reducible to &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;. A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-complete&#039;&#039;&#039; if &amp;lt;math&amp;gt;f\in&amp;lt;/math&amp;gt;&#039;&#039;&#039;#P&#039;&#039;&#039; and &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. That is to say, &#039;&#039;&#039;#P-complete&#039;&#039;&#039; problems are the &amp;quot;hardest&amp;quot; problems in &#039;&#039;&#039;#P&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Generally, &#039;&#039;&#039;#P-complete&#039;&#039;&#039; problems are very hard, because if we can solve any of these problems in poly-time, then &#039;&#039;&#039;#P&#039;&#039;&#039;=&#039;&#039;&#039;FP&#039;&#039;&#039;, which implies that &#039;&#039;&#039;NP&#039;&#039;&#039;=&#039;&#039;&#039;P&#039;&#039;&#039;. On the other hand, we do not know whether &#039;&#039;&#039;NP&#039;&#039;&#039;=&#039;&#039;&#039;P&#039;&#039;&#039; could imply that &#039;&#039;&#039;#P&#039;&#039;&#039;=&#039;&#039;&#039;FP&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== FPRAS ===&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (FPRAS)&#039;&#039;&#039;&lt;br /&gt;
:A &#039;&#039;&#039;polynomial randomized approximation scheme (PRAS)&#039;&#039;&#039; for a problem &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{R}&amp;lt;/math&amp;gt; is a randomized algorithm &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; that takes an input instance &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; and a real number &amp;lt;math&amp;gt;\epsilon&amp;gt;0&amp;lt;/math&amp;gt;, and in time polynomial in &amp;lt;math&amp;gt;n=|x|&amp;lt;/math&amp;gt; returns &amp;lt;math&amp;gt;A(x)&amp;lt;/math&amp;gt; such that&lt;br /&gt;
::&amp;lt;math&amp;gt;\Pr[(1-\epsilon)f(x)\le A(x)\le (1+\epsilon)f(x)]\ge\frac{3}{4}.&amp;lt;/math&amp;gt;&lt;br /&gt;
:A &#039;&#039;&#039;fully polynomial randomized approximation scheme (FPRAS)&#039;&#039;&#039; is a PRAS whose running time is polynomially in both &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;1/\epsilon&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Approximate Counting ==&lt;br /&gt;
Let us consider the following abstract problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be a finite set of known size, and let &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt;. We want to compute the size of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, namely &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We assume two devices:&lt;br /&gt;
* A &#039;&#039;&#039;uniform sampler&#039;&#039;&#039; &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;, which uniformly and independently samples a member of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; upon each calling.&lt;br /&gt;
* A &#039;&#039;&#039;membership oracle&#039;&#039;&#039; of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;. Given as the input an &amp;lt;math&amp;gt;x\in U&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{O}(x)&amp;lt;/math&amp;gt; indicates whether or not &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is a member of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Equipped by &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;, we can have the following Monte Carlo algorithm:&lt;br /&gt;
*Choose &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; independent samples from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; by the uniform sampler &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;, represented by the random variables &amp;lt;math&amp;gt;X_1,X_2,\ldots, X_N&amp;lt;/math&amp;gt;. &lt;br /&gt;
* Let &amp;lt;math&amp;gt;Y_i&amp;lt;/math&amp;gt; be the indicator random variable defined as &amp;lt;math&amp;gt;Y_i=\mathcal{O}(X_i)&amp;lt;/math&amp;gt;, namely, &amp;lt;math&amp;gt;Y_i&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;X_i\in G&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Define the estimator random variable&lt;br /&gt;
::&amp;lt;math&amp;gt;Z=\frac{|U|}{N}\sum_{i=1}^N Y_i.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is easy to see that &amp;lt;math&amp;gt;\mathbf{E}[Z]=|G|&amp;lt;/math&amp;gt; and we might hope that with high probability the value of &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt; is close to &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt;. Formally, &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt; is called an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation of &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; if&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1-\epsilon)|G|\le Z\le (1+\epsilon)|G|.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following theorem states that the probabilistic accuracy of the estimation depends on the number of samples and the ratio between &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|U|&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Theorem (estimator theorem)&#039;&#039;&#039;&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;. Then the Monte Carlo method yields an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation to &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; with probability at least &amp;lt;math&amp;gt;1-\delta&amp;lt;/math&amp;gt; provided&lt;br /&gt;
::&amp;lt;math&amp;gt;N\ge\frac{4}{\epsilon \alpha}\ln\frac{2}{\delta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;Proof&#039;&#039;&#039;: Use the Chernoff bound.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A counting algorithm for the set &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has to deal with the following three complications:&lt;br /&gt;
* Implement the membership oracle &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;. This is usually straightforward, or assumed by the model.&lt;br /&gt;
* Implement the uniform sampler &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;. As we have seen, this is usually approximated by random walks. How to design the random walk and bound its mixing rate is usually technical challenging, if possible at all.&lt;br /&gt;
* Deal with exponentially small &amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;. This requires us to cleverly choose the universe &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. Sometimes this needs some nontrivial ideas.&lt;br /&gt;
&lt;br /&gt;
=== Counting DNFs ===&lt;br /&gt;
A disjunctive normal form (DNF) formular is a disjunction (OR) of clauses, where each clause is a conjunction (AND) of literals. For example:&lt;br /&gt;
:&amp;lt;math&amp;gt;(x_1\wedge \overline{x_2}\wedge x_3)\vee(x_2\wedge x_4)\vee(\overline{x_1}\wedge x_3\wedge x_4)&amp;lt;/math&amp;gt;.&lt;br /&gt;
Note the difference from the conjunctive normal forms (CNF).&lt;br /&gt;
&lt;br /&gt;
Given a DNF formular &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; as the input, the problem is to count the number of satisfying assignments of &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. This problem is &#039;&#039;&#039;#P-complete&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Naively applying the Monte Carlo method will not give a good answer. Suppose that there are &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;U=\{\mathrm{true},\mathrm{false}\}^n&amp;lt;/math&amp;gt; be the set of all truth assignments of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;G=\{x\in U\mid \phi(x)=\mathrm{true}\}&amp;lt;/math&amp;gt; be the set of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. The straightforward use of Monte Carlo method samples &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; assignments from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and check how many of them satisfy &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. This algorithm fails when &amp;lt;math&amp;gt;|G|/|U|&amp;lt;/math&amp;gt; is exponentially small, namely, when exponentially small fraction of the assignments satisfy the input DNF formula. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;The union of sets problem&lt;br /&gt;
We reformulate the DNF counting problem in a more abstract framework, called the &#039;&#039;&#039;union of sets&#039;&#039;&#039; problem. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; be a finite universe. We are given &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; subsets &amp;lt;math&amp;gt;H_1,H_2,\ldots,H_m\subseteq V&amp;lt;/math&amp;gt;. The following assumptions hold:&lt;br /&gt;
*For all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;|H_i|&amp;lt;/math&amp;gt; is computable in poly-time.&lt;br /&gt;
*It is possible to sample uniformly from each individual &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
*For any &amp;lt;math&amp;gt;x\in V&amp;lt;/math&amp;gt;, it can be determined in poly-time whether &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The goal is to compute the size of &amp;lt;math&amp;gt;H=\bigcup_{i=1}^m H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
DNF counting can be interpreted in this general framework as follows. Suppose that the DNF formula &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is defined on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables, and &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; contains &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; clauses &amp;lt;math&amp;gt;C_1,C_2,\ldots,C_m&amp;lt;/math&amp;gt;, where clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;k_i&amp;lt;/math&amp;gt; literals. Without loss of generality, we assume that in each clause, each variable appears at most once.&lt;br /&gt;
* &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; is the set of all assignments.&lt;br /&gt;
*Each &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is the set of satisfying assignments for the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;-th clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; of the DNF formular &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. Then the union of sets &amp;lt;math&amp;gt;H=\bigcup_i H_i&amp;lt;/math&amp;gt; gives the set of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Each clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; is a conjunction (AND) of literals. It is not hard to see that &amp;lt;math&amp;gt;|H_i|=2^{n-k_i}&amp;lt;/math&amp;gt;, which is efficiently computable.&lt;br /&gt;
* Sampling from an &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is simple: we just fix the assignments of the &amp;lt;math&amp;gt;k_i&amp;lt;/math&amp;gt; literals of that clause, and sample uniformly and independently the rest &amp;lt;math&amp;gt;(n-k_i)&amp;lt;/math&amp;gt; variable assignments.&lt;br /&gt;
* For each assignment &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, it is easy to check whether it satisfies a clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt;, thus it is easy to determine whether &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
;The coverage algorithm&lt;br /&gt;
We now introduce the coverage algorithm for the union of sets problem.&lt;br /&gt;
&lt;br /&gt;
Consider the multiset &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; defined by&lt;br /&gt;
:&amp;lt;math&amp;gt;U=H_1\uplus H_2\uplus\cdots \uplus H_m&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\uplus&amp;lt;/math&amp;gt; denotes the multiset union. It is more convenient to define &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; as the set&lt;br /&gt;
:&amp;lt;math&amp;gt;U=\{(x,i)\mid x\in H_i\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
For each &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt;, there may be more than one instances of &amp;lt;math&amp;gt;(x,i)\in U&amp;lt;/math&amp;gt;. We can choose a unique representative among the multiple instances &amp;lt;math&amp;gt;(x,i)\in U&amp;lt;/math&amp;gt; for the same &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt;, by choosing the &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt; with the minimum &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, and form a set &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, &amp;lt;math&amp;gt;G=\{(x,i)\in U\mid \forall (x,j)\in U, j\le i\}&amp;lt;/math&amp;gt;. Every &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt; corresponds to a unique &amp;lt;math&amp;gt;(x,i)\in G&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the smallest among &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is obvious that &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt; and&lt;br /&gt;
:&amp;lt;math&amp;gt;|G|=|H|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, estimation of &amp;lt;math&amp;gt;|H|&amp;lt;/math&amp;gt; is reduced to estimation of &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; can have an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation with probability &amp;lt;math&amp;gt;(1-\delta)&amp;lt;/math&amp;gt; in poly-time, if we can uniformly sample from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|G|/|U|&amp;lt;/math&amp;gt; is suitably small.&lt;br /&gt;
&lt;br /&gt;
An uniform sample from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; can be implemented as follows:&lt;br /&gt;
* generate an &amp;lt;math&amp;gt;i\in\{1,2,\ldots,m\}&amp;lt;/math&amp;gt; with probability &amp;lt;math&amp;gt;\frac{|H_i|}{\sum_{i=1}^m|H_i|}&amp;lt;/math&amp;gt;;&lt;br /&gt;
* uniformly sample an &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;, and return &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is easy to see that this gives a uniform member of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. The above sampling procedure is poly-time because each &amp;lt;math&amp;gt;|H_i|&amp;lt;/math&amp;gt; can be computed in poly-time, and sampling uniformly from each &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is poly-time.&lt;br /&gt;
&lt;br /&gt;
We now only need to lower bound the ratio&lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We claim that &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha\ge\frac{1}{m}&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is easy to see this, because each &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt; has at most &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; instances of &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;, and we already know that &amp;lt;math&amp;gt;|G|=|H|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Due to the estimator theorem, this needs &amp;lt;math&amp;gt;\frac{4m}{\epsilon}\ln\frac{2}{\delta}&amp;lt;/math&amp;gt; uniform random samples from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This gives the coverage algorithm for the abstract problem of the union of sets. The DNF counting is a special case of it.&lt;br /&gt;
&lt;br /&gt;
=== Permanents and perfect matchings ===&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;U=\{u_1,u_2,\ldots,u_n\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;V=\{v_1,v_2,\ldots,v_n\}&amp;lt;/math&amp;gt;. Consider a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt;. An &amp;lt;math&amp;gt;M\subseteq E&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;perfect matching&#039;&#039;&#039; of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; if every vertex of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has exactly one edge in &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; adjacent to it.&lt;br /&gt;
&lt;br /&gt;
Given a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt;, we want to count the number of perfect matchings of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. This problem can be reduced to computing the &#039;&#039;&#039;permanent&#039;&#039;&#039; of a square matrix.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (permanent)&#039;&#039;&#039;&lt;br /&gt;
:Let &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix. The &#039;&#039;&#039;permanent&#039;&#039;&#039; of the matrix is defined as&lt;br /&gt;
::&amp;lt;math&amp;gt;\mathrm{per}(Q)=\sum_{\pi\in\mathbb{S}_n}\prod_{i=1}^n Q_{i,\pi(i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\mathbb{S}_n&amp;lt;/math&amp;gt; is the symmetric group of permutation of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If we multiply each term of the sum the sign of the permutation, then it gives us the determinant of the matrix, &lt;br /&gt;
:&amp;lt;math&amp;gt;\det(Q)=\sum_{\pi\in\mathbb{S}_n}\sgn(\pi)\prod_{i=1}^n Q_{i,\pi(i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\sgn(\pi)&amp;lt;/math&amp;gt;, the sign of a permutation, is either &amp;lt;math&amp;gt;-1&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;+1&amp;lt;/math&amp;gt;, according to whether the minimum number of pair-wise interchanges to achieve &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;(1,2,\ldots,n)&amp;lt;/math&amp;gt; is odd or even.&lt;br /&gt;
&lt;br /&gt;
Unlike the determinants, which are computable in poly-time, permanents are hard to compute, as permanents can be used to count the number of perfect matchings in a bipartite graph, which is &#039;&#039;&#039;#P-complete&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt; can be represented by an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; with 0-1 entries as follows:&lt;br /&gt;
* Each row of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; corresponds to a vertex in &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and each column of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; corresponds to a vertex in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;Q_{ij}=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }i\sim j,\\&lt;br /&gt;
0 &amp;amp; \mbox{otherwise}.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Note the subtle difference between the definition of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; and the adjacency matrix. &lt;br /&gt;
&lt;br /&gt;
Each perfect matching corresponds to a permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;(u,\pi(u))\in E&amp;lt;/math&amp;gt; for every &amp;lt;math&amp;gt;u\in U&amp;lt;/math&amp;gt;, which corresponds to a permutation &amp;lt;math&amp;gt;\pi\in\mathbb{S}_n&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;\prod_{i=1}^n Q_{i,\pi(i)}=1&amp;lt;/math&amp;gt;. It is than easy to see that &amp;lt;math&amp;gt;\mathrm{per}(Q)&amp;lt;/math&amp;gt; gives the number of perfect matchings in the bipartite graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is known that counting the number of perfect matchings in a bipartite graph is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. Since this problem can be reduced to computing the permanent, thus the problem of computing the permanents is also &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Now we show that with randomization, we can approximate the number of perfect matchings in a bipartite graph. In particular, we will give an FPRAS for counting the perfect matchings in a dense bipartite graph.&lt;br /&gt;
&lt;br /&gt;
==== The Jerrum-Sinclair algorithm ====&lt;br /&gt;
Fix a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\mathcal{M}_k&amp;lt;/math&amp;gt; be the set of matchings of size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;m_k=|\mathcal{M}_k|&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;\mathcal{M}_k&amp;lt;/math&amp;gt; is the set of perfect matchings in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and our goal is to compute &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;r_k=\frac{m_k}{m_{k-1}}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;m_k=m_{k-1}r_k&amp;lt;/math&amp;gt;,&lt;br /&gt;
which gives us a recursion to compute the &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt;, as&lt;br /&gt;
:&amp;lt;math&amp;gt;m_n=m_{1}\frac{m_2}{m_1}\cdot\frac{m_3}{m_2}\cdots\frac{m_n}{m_{n-1}}=m_1\prod_{k=2}^n r_k&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;m_1=|\mathcal{M}_1|&amp;lt;/math&amp;gt; is the number of matchings of size 1 in the bipartite graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, which is just the number of edges in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; can be computed once we know &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; can be estimated by sampling uniformly from the set &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;. The algorithm for estimating &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; is outlined as:&lt;br /&gt;
# For each &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;, have an FPRAS for computing the &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; by uniform sampling sufficiently many members from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt; as&lt;br /&gt;
::*uniformly sample &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; matching from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;, for some polynomially large &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;;&lt;br /&gt;
::* assuming that there are &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; sampled matchings of size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, return &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; as &amp;lt;math&amp;gt;r_k=\frac{X}{N-X}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2.  Compute &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; as &amp;lt;math&amp;gt;m_n=m_1\prod_{k=2}^n r_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;m_1=|E|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
There are several issues that we have to deal with in order to have a fully functional FPRAS for counting perfect matchings.&lt;br /&gt;
* By taking the product of &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&#039;s, the errors for individual &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&#039;s add up.&lt;br /&gt;
* In order to accurately estimate &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; by sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;, the ratio &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; should be within the range &amp;lt;math&amp;gt;\left[\frac{1}{\alpha},\alpha\right]&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; within polynomial of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Implement the uniform sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
;Estimator for each &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Accumulation of errors&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
; Near-uniform sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
In the last lecture, we have shown that by random walk, we can sample a near-uniform member of &amp;lt;math&amp;gt;\mathcal{M}_n\cup\mathcal{M}_{n-1}&amp;lt;/math&amp;gt; in poly-time.&lt;br /&gt;
&lt;br /&gt;
=== Volume estimation  ===&lt;br /&gt;
We consider the problem of computing the volume of a given [http://en.wikipedia.org/wiki/Convex_body convex body] &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions. &lt;br /&gt;
&lt;br /&gt;
We use &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; to denote the volume of the convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;. Abstractly, the problem is that given as input a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, return the &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We should be more specific about the input model. Since we allow an arbitrary convex body as input, it is not even clear how to describe the body. We assume that &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is described by means of a &#039;&#039;&#039;membership oracle&#039;&#039;&#039; &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;, such that  for a &#039;&#039;&#039;query&#039;&#039;&#039; of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{O}(x)&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;x\in K&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example, the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional convex body defined by the intersection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; half-spaces, which is the set of feasible solutions to a system of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; linear constraints, can be described as&lt;br /&gt;
:&amp;lt;math&amp;gt;A x\le \boldsymbol{b}&amp;lt;/math&amp;gt;,&lt;br /&gt;
for some &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector &amp;lt;math&amp;gt;b&amp;lt;/math&amp;gt;. For a query of an &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, the membership oracle &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt; just check whether &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For deterministic algorithms, there are negative news for this problem.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Theorem (Bárány-Füredi 1987)&#039;&#039;&#039;&lt;br /&gt;
:Suppose that a deterministic poly-time algorithm uses the membership oracle for a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, and generates an upper bound &amp;lt;math&amp;gt;\Upsilon_u\,&amp;lt;/math&amp;gt; and a lower bound &amp;lt;math&amp;gt;\Upsilon_\ell\,&amp;lt;/math&amp;gt; on the volume &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;. Then, there is a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and a constant &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; such that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{\Upsilon_u}{\Upsilon_\ell}\ge c\left(\frac{n}{\log n}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
That is said, with deterministic algorithms, we cannot even approximate the volume within a wildly loose range.&lt;br /&gt;
&lt;br /&gt;
Dyer-Frieze-Kannan come up with an idea of estimating the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; by sampling near-uniformly from convex sets. They reduce the problem of computing approximately the volume of convex bodies to this sampling problem and thus give the first FPRAS for the volume of convex bodies.&lt;br /&gt;
&lt;br /&gt;
For any convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, it encloses some &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional ball and is also enclosed by another ball with larger radius. We assume that the convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; encloses the unit ball around the origin, and is enclosed by a larger ball round the origin with polynomially large radius. Formally, we assume that&lt;br /&gt;
:&amp;lt;math&amp;gt;B(0,1)\subseteq K\subseteq B(0,n^c)&amp;lt;/math&amp;gt; for some constant &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;B(p,r)&amp;lt;/math&amp;gt; denotes a ball of radius &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; as center, i.e. &amp;lt;math&amp;gt;B(p,r)=\{x\mid \|x-p\|\le r \}&amp;lt;/math&amp;gt;. We can make this assumption because it is known that for any convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, there exists a linear transformation &amp;lt;math&amp;gt;\tau&amp;lt;/math&amp;gt; which can be found within poly-time such that &amp;lt;math&amp;gt;\tau K&amp;lt;/math&amp;gt; transforms the &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; to a convex body that satisfies the assumption, and preserves the ratio of the volumes of the balls to the convex body.&lt;br /&gt;
&lt;br /&gt;
The volumes of the balls are easy to compute. If only the ratio between the convex body and the ball which encloses it, is sufficiently large, then we can apply the Monte Carlo method to estimate &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; by uniformly sampling from the ball.&lt;br /&gt;
&lt;br /&gt;
However, in high-dimension, the ratio between the volume of a convex body and the volume of ball which encloses it, can be exponentially small. This is caused by the so called the &amp;quot;[http://en.wikipedia.org/wiki/Curse_of_dimensionality curse of dimensionality]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Instead of having an outer ball and an inner ball, we define a sequence of balls:&lt;br /&gt;
:&amp;lt;math&amp;gt;B_0=B(0,\lambda^0), B_1=B(0,\lambda^1), B_2=B(0,\lambda^2),\ldots, B_m=B(0,\lambda^m)&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\lambda=(1+\frac{1}{n})&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is the smallest positive integer such that &amp;lt;math&amp;gt;\lambda^m\ge n^c&amp;lt;/math&amp;gt;. Therefore, the inner ball &amp;lt;math&amp;gt;B(0,1)=B_0&amp;lt;/math&amp;gt;, the outer ball &amp;lt;math&amp;gt;B(0,n^c)\subseteq B_m&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is within polynomial of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. In fact, &amp;lt;math&amp;gt;m\approx cn\ln n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This sequence of balls naturally defines a sequence of convex bodies by intersections as &amp;lt;math&amp;gt;K_i=B_i\cap K&amp;lt;/math&amp;gt;. It is obvious that&lt;br /&gt;
:&amp;lt;math&amp;gt;B(0,1)=K_0\subseteq K_1\subseteq K_2\subseteq\cdots\subseteq K_m=K&amp;lt;/math&amp;gt;.&lt;br /&gt;
Balls are convex, and since the intersection of convex bodies is still convex, the sequence of &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt; is a sequence of convex bodies.&lt;br /&gt;
&lt;br /&gt;
We have the telescopic product:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\Upsilon(K_0)}{\Upsilon(K_1)}\cdot\frac{\Upsilon(K_1)}{\Upsilon(K_2)}\cdots\frac{\Upsilon(K_{m-1})}{\Upsilon(K_m)}=\frac{\Upsilon(K_0)}{\Upsilon(K_m)}=\frac{\Upsilon(B(0,1))}{\Upsilon(K)}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, the volume &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; can be computed as &lt;br /&gt;
:&amp;lt;math&amp;gt;\Upsilon(K)=\Upsilon(B(0,1))\cdot\prod_{i=1}^{m}\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The volume of unite ball &amp;lt;math&amp;gt;\Upsilon(B(0,1))\,&amp;lt;/math&amp;gt; can be precisely computed in poly-time. Each &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is computed by near-uniform sampling from &amp;lt;math&amp;gt;K_{i}&amp;lt;/math&amp;gt;, which encloses &amp;lt;math&amp;gt;K_{i-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Another observation is that the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is well-bounded. Recall that &amp;lt;math&amp;gt;K_i=B(0,\lambda^i)\cap K&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;\lambda=(1+\frac{1}{n})&amp;lt;/math&amp;gt;. It can be proved that in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, the volume of &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt; is at most &amp;lt;math&amp;gt;\lambda^n&amp;lt;/math&amp;gt; times the &amp;lt;math&amp;gt;K_{i-1}&amp;lt;/math&amp;gt;, thus the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is at most &amp;lt;math&amp;gt;\lambda^n=O(1)&amp;lt;/math&amp;gt;. By the estimator theorem, we can have an FPRAS for the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; if we can uniformly sample from &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Uniformly sampling from an arbitrary convex body is replaced by near-uniform sampling achieved by random walks. In the original walk of Dyer-Frieze-Kannan, they consider the random walk over &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional discrete grid points enclosed by &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, and prove that the walk is rapid mixing. This gives us the first FPRAS for volume estimation which runs in &amp;lt;math&amp;gt;\tilde{O}(n^{23})&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\tilde{O}(\cdot)&amp;lt;/math&amp;gt; ignores the polylogarithmic factors.&lt;br /&gt;
&lt;br /&gt;
The time bound was later improved by a series of works, each introducing some new ideas.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
| || complexity || new ingredient(s)&lt;br /&gt;
|-&lt;br /&gt;
| Dyer-Frieze-Kannan 1991 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{23}&amp;lt;/math&amp;gt; || everything&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Simonovits 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{16}&amp;lt;/math&amp;gt; || localization lemma&lt;br /&gt;
|-&lt;br /&gt;
| Applegate-Kannan 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{10}&amp;lt;/math&amp;gt; || logconcave sampling&lt;br /&gt;
|-&lt;br /&gt;
| Lovász 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{10}&amp;lt;/math&amp;gt; || ball walk&lt;br /&gt;
|-&lt;br /&gt;
| Dyer-Frieze 1991 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^8&amp;lt;/math&amp;gt; || better error analysis&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Simonovits 1993 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^7&amp;lt;/math&amp;gt; || many improvements&lt;br /&gt;
|-&lt;br /&gt;
| Kannan-Lovász-Simonovits 1997 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^5&amp;lt;/math&amp;gt; || isotropy, speedy walk&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Vempala 2003 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^4&amp;lt;/math&amp;gt; || simulated annealing, hit-and-run&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
(cited from &amp;quot;Geometric Random Walks: A Survey&amp;quot; by Santosh Vempala.)&lt;br /&gt;
&lt;br /&gt;
The current best upper bound is &amp;lt;math&amp;gt;\tilde{O}(n^4)&amp;lt;/math&amp;gt; due to Lovász and Vempala in 2003. It is conjectured that the optimal bound is &amp;lt;math&amp;gt;\Theta(n^3)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Linear Programming ==&lt;br /&gt;
Given a function &amp;lt;math&amp;gt;f:\mathbb{R}^n\rightarrow\mathbb{R}&amp;lt;/math&amp;gt; and a set &amp;lt;math&amp;gt;\mathcal{F}\subseteq\mathbb{R}^n&amp;lt;/math&amp;gt;, an &#039;&#039;&#039;optimization problem&#039;&#039;&#039; is the problem of finding an &amp;lt;math&amp;gt;x\in\mathcal{F}&amp;lt;/math&amp;gt; with the optimal (minimum) &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;. Formally, the problem can be expressed as:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize} &amp;amp; \quad f(x)\\&lt;br /&gt;
\mbox{subject to} &amp;amp;\quad  x\in\mathcal{F}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;x\in\mathcal{R}^n&amp;lt;/math&amp;gt; is a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. For the problem of maximizing a function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, we just minimizes &amp;lt;math&amp;gt;-f&amp;lt;/math&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
We call the function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; the &#039;&#039;&#039;objective function&#039;&#039;&#039; and call any &amp;lt;math&amp;gt;x\in\mathcal{F}&amp;lt;/math&amp;gt; a &#039;&#039;&#039;feasible solution&#039;&#039;&#039; of the problem. A feasible solution that minimizes &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;optimal solution&#039;&#039;&#039;. Our task is to find an optimal solution.&lt;br /&gt;
&lt;br /&gt;
The feasible set &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is usually given by a number of &#039;&#039;&#039;constraints&#039;&#039;&#039; &amp;lt;math&amp;gt;P_1,P_2,\ldots,P_m&amp;lt;/math&amp;gt;, which are predicates defined on &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. An &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is a feasible solution if it satisfies all the constraints. &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;linear programming (LP)&#039;&#039;&#039; problem is an optimization problem with a linear objective function subject to a number of linear constraints. Formally, an LP is a problem that can be expressed in the following form:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c_1x_1+c_2x_2+\cdots+c_nx_n\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad a_{11}x_1+a_{12}x_2+\cdots+a_{1n}x_n\le b_1\\&lt;br /&gt;
&amp;amp; \quad a_{21}x_1+a_{22}x_2+\cdots+a_{2n}x_n\le b_2\\&lt;br /&gt;
&amp;amp; \qquad\qquad \vdots\\&lt;br /&gt;
&amp;amp; \quad a_{m1}x_1+a_{m2}x_2+\cdots+a_{mn}x_n\le b_m\\&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;a_{ij}&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;c_j&amp;lt;/math&amp;gt; are constants and &amp;lt;math&amp;gt;x_j&amp;lt;/math&amp;gt; are variables. For maximization problem, or constraints given by &amp;quot;&amp;lt;math&amp;gt;\ge&amp;lt;/math&amp;gt;&amp;quot;, we can multiply  the coefficients by &amp;lt;math&amp;gt;-1&amp;lt;/math&amp;gt; and still write the LP in the above form. &lt;br /&gt;
&lt;br /&gt;
We can describe the programming in the vector form. Let &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;A=(a_{ij})&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; matrix of constant entries, &amp;lt;math&amp;gt;b=(b_1,\ldots,b_m)&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; constant entries, and &amp;lt;math&amp;gt;c=(c_1,\ldots,c_n)&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; constant entries. Then an LP is expressed as:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c^T x\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad Ax\le b&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
We call it the &#039;&#039;&#039;canonical form&#039;&#039;&#039; of linear programming.&lt;br /&gt;
&lt;br /&gt;
=== The geometry of LPs ===&lt;br /&gt;
For &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional space &amp;lt;math&amp;gt;\mathbb{R}^n&amp;lt;/math&amp;gt;, a linear constraint &amp;lt;math&amp;gt;ax\le b&amp;lt;/math&amp;gt; specifies a [http://en.wikipedia.org/wiki/Half-space halfspace]. The feasible set specified by &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; constraints together is an intersection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; halfspaces, thus, a [http://en.wikipedia.org/wiki/Convex_polytope convex polytope].&lt;br /&gt;
&lt;br /&gt;
The convex polytope is defined by &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The LP can be thought as given an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional polytope and a linear (affine) function &amp;lt;math&amp;gt;f:\mathbb{R}^n\rightarrow \mathbb{R}&amp;lt;/math&amp;gt;, looking for a point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; in the polytope with the smallest function value &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We can choose a number of constraints in the system &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, and make them hold with equality. This would define a subspace of &amp;lt;math&amp;gt;\mathbb{R}^n&amp;lt;/math&amp;gt;. In particular, if we choose &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; linearly independent constraints to form an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; submatrix &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; and the corresponding &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector &amp;lt;math&amp;gt;b&#039;&amp;lt;/math&amp;gt;, solving &amp;lt;math&amp;gt;A&#039;x=b&#039;&amp;lt;/math&amp;gt; would give us exactly one point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. If this &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is in the polytope, i.e. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; satisfies that &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, we call such &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; a &#039;&#039;&#039;vertex&#039;&#039;&#039; of the polytope &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;. In the context of LP, it is also called a &#039;&#039;&#039;basic feasible solution (&#039;&#039;bfs&#039;&#039;)&#039;&#039;&#039; of the LP.&lt;br /&gt;
&lt;br /&gt;
A key observation for LP is that there is a basic feasible solution which is optimal, i.e. the optimal solution is a vertex of the polytope.&lt;br /&gt;
&lt;br /&gt;
=== The simplex algorithms ===&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Simplex_algorithm simplex algorithm] by George Dantzig solves the linear programming by moving from vertex to vertex of the convex polytope, each time making some progress towards optimizing the objective function. Eventually the algorithm reaches a vertex which is a [http://en.wikipedia.org/wiki/Local_optimum local optimum]. In a convex set, a locally optimal point is also global optimal, thus the simplex algorithm returns an optimal solution in finite steps.&lt;br /&gt;
&lt;br /&gt;
The problem with the simplex algorithm is that in some bad polytopes, it takes the simplex algorithm exponentially many steps to reach the optimum. The simplex algorithm is actually a class of algorithms defined by various &#039;&#039;&#039;pivoting rules&#039;&#039;&#039;, which describe how to move locally from one vertex to another. The original pivoting rule proposed by Dantzig has an exponentially large worst-case time complexity (though works very good in practice). To-date, it is still unknown whether there exists any deterministic simplex algorithm with sub-exponential worst-case complexity.&lt;br /&gt;
&lt;br /&gt;
People have tried randomized pivoting rules, and there are some amazing progresses have been made:&lt;br /&gt;
* Kalai 1992: there is a randomized simplex algorithm with sub-exponential time complexity.&lt;br /&gt;
* Kelner-Spielman 2006: there is a polynomial time randomized simplex algorithm.&lt;br /&gt;
&lt;br /&gt;
Although we do not know whether there exists deterministic poly-time simplex algorithm, we do know that LP can be solved by deterministic poly-time algorithms, i.e. LP is in &#039;&#039;&#039;P&#039;&#039;&#039;. The following two algorithms use different ideas than the simplex algorithm, and are both in poly-time:&lt;br /&gt;
* The ellipsoid algorithm.&lt;br /&gt;
* Interior point methods.&lt;br /&gt;
Although these algorithms guarantee polynomial time complexity in the worst-case, their performances are worse than the simplex algorithms. However, the ideas of these algorithms can be used to solve more general mathematical programmings, such as [http://en.wikipedia.org/wiki/Convex_programming convex programmings].&lt;br /&gt;
&lt;br /&gt;
=== An LP solver via random walks ===&lt;br /&gt;
We discuss a new algorithm for solving LP which is based on random sampling, introduced by Bertsimas and Vempala in 2004. &lt;br /&gt;
&lt;br /&gt;
The problem of solving an LP can be reduced to that given a convex polytope &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, test whether the polytope is empty. We call this problem the &amp;quot;&#039;&#039;feasibility test&#039;&#039;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Suppose we have an LP:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c^T x\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad Ax\le b&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
To see this LP can be solved by feasibility testing, we treat the &amp;lt;math&amp;gt;c^Tx\le d&amp;lt;/math&amp;gt; for some parameter &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; as an additional constraint, and define a new polytope &amp;lt;math&amp;gt;A&#039;x\le b&#039;&amp;lt;/math&amp;gt;. The smallest &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; that the polytope &amp;lt;math&amp;gt;A&#039;x\le b&#039;&amp;lt;/math&amp;gt; is not empty is the optimal solution to the original LP. We can find this smallest &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; by binary search if we can efficiently test the emptiness of a convex polytope.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We assume that the convex polytope &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is contained in the axis-aligned cube of width &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; centered at the origin; further if &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is non-empty then it contains a cube of width &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;. The parameter &amp;lt;math&amp;gt;L&amp;lt;/math&amp;gt; is equal to &amp;lt;math&amp;gt;\log\frac{R}{r}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Algorithm&#039;&#039;&#039;: feasibility test &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Input&#039;&#039;&#039;: an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional convex polytope &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; defined by the system &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;: a point &amp;lt;math&amp;gt;x\in P&amp;lt;/math&amp;gt; in the polytope, or a guarantee that &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is empty.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; be the axis-aligned cube of side length &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; and center &amp;lt;math&amp;gt;z=\boldsymbol{0}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Repeat for &amp;lt;math&amp;gt;2nL&amp;lt;/math&amp;gt; times do:&lt;br /&gt;
:: If &amp;lt;math&amp;gt;Az\le b&amp;lt;/math&amp;gt;, return &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: Pick a constraint violated by &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;, say that &amp;lt;math&amp;gt;A_i z&amp;gt;b_i&amp;lt;/math&amp;gt;, and define the halfspace&lt;br /&gt;
:::&amp;lt;math&amp;gt;H=\{x\mid A_i x\le A_i z\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
::Set &amp;lt;math&amp;gt;K=K\cap H&amp;lt;/math&amp;gt;. Uniformly sample &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; random points &amp;lt;math&amp;gt;y^{(1)},y^{(2)},\ldots,y^{(N)}&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and let &lt;br /&gt;
:::&amp;lt;math&amp;gt;z=\frac{1}{N}\sum_{i=1}^Ny^{(i)}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Report &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is empty.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The number of samples required in each iteration, &amp;lt;math&amp;gt;N=O((\log m)^2)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is the number of linear constraints. &lt;br /&gt;
&lt;br /&gt;
It is easy to see that at any iteration, &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is a convex set, and &amp;lt;math&amp;gt;P\subseteq K&amp;lt;/math&amp;gt; for the current convex set &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The idea of the algorithm is based on computing the [http://en.wikipedia.org/wiki/Centroid centroid] of the convex set.  It is know that if we could compute the exact centroid in each iteration, then the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; drops by a constant factor &amp;lt;math&amp;gt;(1-1/e)&amp;lt;/math&amp;gt; in each iteration, thus reaches the smallest possible volume of a cube of width &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; within polynomial number of iterations. But, finding the centroid of a convex polytope, is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The idea behind the algorithm is that an approximate centroid can be computed using &amp;lt;math&amp;gt;N=O((\log m)^2)&amp;lt;/math&amp;gt; random points and the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is drops by a constant factor with high probability in each iteration with this choice of &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
The uniform sampling in &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is not easy. But since &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is also a convex polytope, we can approximate the uniform sampling by  near-uniform sampling from &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; by rapid mixing random walks. The random walks used here are similar to the ones used in the volume estimation of convex bodies. We could use the basic grid walk, or more advanced ball walk, or hit-and-run walk.&lt;br /&gt;
&lt;br /&gt;
With rapid mixing random walks, the resulting LP solver runs in poly-time.&lt;br /&gt;
&lt;br /&gt;
The details are omitted. You may check the following paper if interested:&lt;br /&gt;
* Bertsimas and Vempala, “&#039;&#039;Solving convex programs by random walks&#039;&#039;.” JACM 2004.&lt;/div&gt;</summary>
		<author><name>172.21.4.18</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2473</id>
		<title>Randomized Algorithms (Spring 2010)/Approximate counting, linear programming</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2473"/>
		<updated>2010-05-24T19:24:21Z</updated>

		<summary type="html">&lt;p&gt;172.21.4.18: /* Complexity model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Complexity model ===&lt;br /&gt;
Recall the class &#039;&#039;&#039;NP&#039;&#039;&#039; of decision problems (the problems with &amp;quot;yes&amp;quot; or &amp;quot;no&amp;quot; answers). Formally, denoting by &amp;lt;math&amp;gt;\{0,1\}^*&amp;lt;/math&amp;gt; the set of all boolean strings of any lengths, a decision problem is a function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (NP)&#039;&#039;&#039;&lt;br /&gt;
:A function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\{0,1\}&amp;lt;/math&amp;gt; is in &#039;&#039;&#039;NP&#039;&#039;&#039; if there exist a polynomial &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and a poly-time algorithm &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; with boolean output such that for every &amp;lt;math&amp;gt;x\in\{0,1\}^*&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;f(x)=1 \Leftrightarrow \exists y\in\{0,1\}^{p(|x|)}, \mbox{such that } V(x,y)=1\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
Intuitively, the &#039;&#039;&#039;NP&#039;&#039;&#039; class contains all the decision problems such that the answer is &amp;quot;yes&amp;quot; if and only if there &#039;&#039;exists&#039;&#039; a &#039;&#039;&#039;certificate&#039;&#039;&#039; which can be verified in poly-time.&lt;br /&gt;
&lt;br /&gt;
In many contexts, we are interested not just in the &#039;&#039;existence&#039;&#039; of certificate but actually in counting the &#039;&#039;number&#039;&#039; of certificates. This leads to the definition of the class &#039;&#039;&#039;#P&#039;&#039;&#039; (pronounced &amp;quot;sharp p&amp;quot;). Only now the output of the function is a natural number.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (#P)&#039;&#039;&#039;&lt;br /&gt;
:A function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; is in &#039;&#039;&#039;#P&#039;&#039;&#039; if there exist a polynomial &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and a poly-time algorithm &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; with boolean output such that for every &amp;lt;math&amp;gt;x\in\{0,1\}^*&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;f(x)=\left|\left\{y\in\{0,1\}^{p(|x|)}\mid A(x,y)=1\right\}\right|&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
You may notice the similarity between the two definitions. The difference is that now &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt; does not just indicates the existence of a certificate, but gives the actual number of certificates.&lt;br /&gt;
&lt;br /&gt;
Why should we care about the number of &amp;quot;certificates&amp;quot; at all?&lt;br /&gt;
In combinatorics, a counting problem is usually formulated as counting the number of combinatorial objects with some particular structure, such as the number of trees, or Latin squares. The &#039;&#039;&#039;#P&#039;&#039;&#039; class contains the counting problems that the &amp;quot;structure&amp;quot; requirements are easy to check.&lt;br /&gt;
&lt;br /&gt;
;Examples of problems in #P&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;cycles: given as input a graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, count the number of cycles in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;SAT: given as input a boolean formula &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;, count the number of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The second example shows that the &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;P&#039;&#039;&#039; may be harder than &#039;&#039;&#039;NP&#039;&#039;&#039;, because we know that SAT (given a boolean formular, decide the existence of satisfying assignments) is &#039;&#039;&#039;NP-complete&#039;&#039;&#039;, and its counting version &amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;SAT now ask for the exact number of satisfying assignments.&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;FP&#039;&#039;&#039; contains all the functions &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; computable by poly-time algorithms. The classes &#039;&#039;&#039;FP&#039;&#039;&#039; and &#039;&#039;&#039;#P&#039;&#039;&#039; are the analogs of &#039;&#039;&#039;P&#039;&#039;&#039; and &#039;&#039;&#039;NP&#039;&#039;&#039; for counting problems.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;reduction&#039;&#039;&#039; from a problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to a problem &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is a mapping &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; which maps instances of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to instances of &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; such that for any instance &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;,&lt;br /&gt;
:&amp;lt;math&amp;gt;f(x)=g(\phi(x))&amp;lt;/math&amp;gt;.&lt;br /&gt;
In other words, &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; &amp;quot;reduces&amp;quot; the task of solving &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to the task of solving &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt;. A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is said to be &#039;&#039;&#039;poly-time reducible&#039;&#039;&#039; to the problem &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt;, if there exists a reduction &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is poly-time computable.&lt;br /&gt;
&lt;br /&gt;
A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-hard&#039;&#039;&#039; if every problem in &#039;&#039;&#039;#P&#039;&#039;&#039; is poly-time reducible to &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;. A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-complete&#039;&#039;&#039; if &amp;lt;math&amp;gt;f\in&amp;lt;/math&amp;gt;&#039;&#039;&#039;#P&#039;&#039;&#039; and &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. That is to say, &#039;&#039;&#039;#P-complete&#039;&#039;&#039; problems are the &amp;quot;hardest&amp;quot; problems in &#039;&#039;&#039;#P&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Generally, &#039;&#039;&#039;#P-complete&#039;&#039;&#039; problems are very hard, because if we can solve any of these problems in poly-time, then &#039;&#039;&#039;#P&#039;&#039;&#039;=&#039;&#039;&#039;FP&#039;&#039;&#039;, which implies that &#039;&#039;&#039;NP&#039;&#039;&#039;=&#039;&#039;&#039;P&#039;&#039;&#039;. On the other hand, we do not know whether &#039;&#039;&#039;NP&#039;&#039;&#039;=&#039;&#039;&#039;P&#039;&#039;&#039; could imply that &#039;&#039;&#039;#P&#039;&#039;&#039;=&#039;&#039;&#039;FP&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== FPRAS ===&lt;br /&gt;
&lt;br /&gt;
== Approximate Counting ==&lt;br /&gt;
Let us consider the following abstract problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be a finite set of known size, and let &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt;. We want to compute the size of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, namely &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We assume two devices:&lt;br /&gt;
* A &#039;&#039;&#039;uniform sampler&#039;&#039;&#039; &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;, which uniformly and independently samples a member of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; upon each calling.&lt;br /&gt;
* A &#039;&#039;&#039;membership oracle&#039;&#039;&#039; of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;. Given as the input an &amp;lt;math&amp;gt;x\in U&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{O}(x)&amp;lt;/math&amp;gt; indicates whether or not &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is a member of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Equipped by &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;, we can have the following Monte Carlo algorithm:&lt;br /&gt;
*Choose &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; independent samples from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; by the uniform sampler &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;, represented by the random variables &amp;lt;math&amp;gt;X_1,X_2,\ldots, X_N&amp;lt;/math&amp;gt;. &lt;br /&gt;
* Let &amp;lt;math&amp;gt;Y_i&amp;lt;/math&amp;gt; be the indicator random variable defined as &amp;lt;math&amp;gt;Y_i=\mathcal{O}(X_i)&amp;lt;/math&amp;gt;, namely, &amp;lt;math&amp;gt;Y_i&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;X_i\in G&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Define the estimator random variable&lt;br /&gt;
::&amp;lt;math&amp;gt;Z=\frac{|U|}{N}\sum_{i=1}^N Y_i.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is easy to see that &amp;lt;math&amp;gt;\mathbf{E}[Z]=|G|&amp;lt;/math&amp;gt; and we might hope that with high probability the value of &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt; is close to &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt;. Formally, &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt; is called an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation of &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; if&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1-\epsilon)|G|\le Z\le (1+\epsilon)|G|.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following theorem states that the probabilistic accuracy of the estimation depends on the number of samples and the ratio between &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|U|&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Theorem (estimator theorem)&#039;&#039;&#039;&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;. Then the Monte Carlo method yields an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation to &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; with probability at least &amp;lt;math&amp;gt;1-\delta&amp;lt;/math&amp;gt; provided&lt;br /&gt;
::&amp;lt;math&amp;gt;N\ge\frac{4}{\epsilon \alpha}\ln\frac{2}{\delta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;Proof&#039;&#039;&#039;: Use the Chernoff bound.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A counting algorithm for the set &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has to deal with the following three complications:&lt;br /&gt;
* Implement the membership oracle &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;. This is usually straightforward, or assumed by the model.&lt;br /&gt;
* Implement the uniform sampler &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;. As we have seen, this is usually approximated by random walks. How to design the random walk and bound its mixing rate is usually technical challenging, if possible at all.&lt;br /&gt;
* Deal with exponentially small &amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;. This requires us to cleverly choose the universe &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. Sometimes this needs some nontrivial ideas.&lt;br /&gt;
&lt;br /&gt;
=== Counting DNFs ===&lt;br /&gt;
A disjunctive normal form (DNF) formular is a disjunction (OR) of clauses, where each clause is a conjunction (AND) of literals. For example:&lt;br /&gt;
:&amp;lt;math&amp;gt;(x_1\wedge \overline{x_2}\wedge x_3)\vee(x_2\wedge x_4)\vee(\overline{x_1}\wedge x_3\wedge x_4)&amp;lt;/math&amp;gt;.&lt;br /&gt;
Note the difference from the conjunctive normal forms (CNF).&lt;br /&gt;
&lt;br /&gt;
Given a DNF formular &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; as the input, the problem is to count the number of satisfying assignments of &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. This problem is &#039;&#039;&#039;#P-complete&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Naively applying the Monte Carlo method will not give a good answer. Suppose that there are &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;U=\{\mathrm{true},\mathrm{false}\}^n&amp;lt;/math&amp;gt; be the set of all truth assignments of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;G=\{x\in U\mid \phi(x)=\mathrm{true}\}&amp;lt;/math&amp;gt; be the set of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. The straightforward use of Monte Carlo method samples &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; assignments from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and check how many of them satisfy &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. This algorithm fails when &amp;lt;math&amp;gt;|G|/|U|&amp;lt;/math&amp;gt; is exponentially small, namely, when exponentially small fraction of the assignments satisfy the input DNF formula. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;The union of sets problem&lt;br /&gt;
We reformulate the DNF counting problem in a more abstract framework, called the &#039;&#039;&#039;union of sets&#039;&#039;&#039; problem. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; be a finite universe. We are given &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; subsets &amp;lt;math&amp;gt;H_1,H_2,\ldots,H_m\subseteq V&amp;lt;/math&amp;gt;. The following assumptions hold:&lt;br /&gt;
*For all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;|H_i|&amp;lt;/math&amp;gt; is computable in poly-time.&lt;br /&gt;
*It is possible to sample uniformly from each individual &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
*For any &amp;lt;math&amp;gt;x\in V&amp;lt;/math&amp;gt;, it can be determined in poly-time whether &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The goal is to compute the size of &amp;lt;math&amp;gt;H=\bigcup_{i=1}^m H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
DNF counting can be interpreted in this general framework as follows. Suppose that the DNF formula &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is defined on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables, and &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; contains &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; clauses &amp;lt;math&amp;gt;C_1,C_2,\ldots,C_m&amp;lt;/math&amp;gt;, where clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;k_i&amp;lt;/math&amp;gt; literals. Without loss of generality, we assume that in each clause, each variable appears at most once.&lt;br /&gt;
* &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; is the set of all assignments.&lt;br /&gt;
*Each &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is the set of satisfying assignments for the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;-th clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; of the DNF formular &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. Then the union of sets &amp;lt;math&amp;gt;H=\bigcup_i H_i&amp;lt;/math&amp;gt; gives the set of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Each clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; is a conjunction (AND) of literals. It is not hard to see that &amp;lt;math&amp;gt;|H_i|=2^{n-k_i}&amp;lt;/math&amp;gt;, which is efficiently computable.&lt;br /&gt;
* Sampling from an &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is simple: we just fix the assignments of the &amp;lt;math&amp;gt;k_i&amp;lt;/math&amp;gt; literals of that clause, and sample uniformly and independently the rest &amp;lt;math&amp;gt;(n-k_i)&amp;lt;/math&amp;gt; variable assignments.&lt;br /&gt;
* For each assignment &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, it is easy to check whether it satisfies a clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt;, thus it is easy to determine whether &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
;The coverage algorithm&lt;br /&gt;
We now introduce the coverage algorithm for the union of sets problem.&lt;br /&gt;
&lt;br /&gt;
Consider the multiset &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; defined by&lt;br /&gt;
:&amp;lt;math&amp;gt;U=H_1\uplus H_2\uplus\cdots \uplus H_m&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\uplus&amp;lt;/math&amp;gt; denotes the multiset union. It is more convenient to define &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; as the set&lt;br /&gt;
:&amp;lt;math&amp;gt;U=\{(x,i)\mid x\in H_i\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
For each &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt;, there may be more than one instances of &amp;lt;math&amp;gt;(x,i)\in U&amp;lt;/math&amp;gt;. We can choose a unique representative among the multiple instances &amp;lt;math&amp;gt;(x,i)\in U&amp;lt;/math&amp;gt; for the same &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt;, by choosing the &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt; with the minimum &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, and form a set &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, &amp;lt;math&amp;gt;G=\{(x,i)\in U\mid \forall (x,j)\in U, j\le i\}&amp;lt;/math&amp;gt;. Every &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt; corresponds to a unique &amp;lt;math&amp;gt;(x,i)\in G&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the smallest among &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is obvious that &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt; and&lt;br /&gt;
:&amp;lt;math&amp;gt;|G|=|H|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, estimation of &amp;lt;math&amp;gt;|H|&amp;lt;/math&amp;gt; is reduced to estimation of &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; can have an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation with probability &amp;lt;math&amp;gt;(1-\delta)&amp;lt;/math&amp;gt; in poly-time, if we can uniformly sample from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|G|/|U|&amp;lt;/math&amp;gt; is suitably small.&lt;br /&gt;
&lt;br /&gt;
An uniform sample from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; can be implemented as follows:&lt;br /&gt;
* generate an &amp;lt;math&amp;gt;i\in\{1,2,\ldots,m\}&amp;lt;/math&amp;gt; with probability &amp;lt;math&amp;gt;\frac{|H_i|}{\sum_{i=1}^m|H_i|}&amp;lt;/math&amp;gt;;&lt;br /&gt;
* uniformly sample an &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;, and return &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is easy to see that this gives a uniform member of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. The above sampling procedure is poly-time because each &amp;lt;math&amp;gt;|H_i|&amp;lt;/math&amp;gt; can be computed in poly-time, and sampling uniformly from each &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is poly-time.&lt;br /&gt;
&lt;br /&gt;
We now only need to lower bound the ratio&lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We claim that &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha\ge\frac{1}{m}&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is easy to see this, because each &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt; has at most &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; instances of &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;, and we already know that &amp;lt;math&amp;gt;|G|=|H|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Due to the estimator theorem, this needs &amp;lt;math&amp;gt;\frac{4m}{\epsilon}\ln\frac{2}{\delta}&amp;lt;/math&amp;gt; uniform random samples from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This gives the coverage algorithm for the abstract problem of the union of sets. The DNF counting is a special case of it.&lt;br /&gt;
&lt;br /&gt;
=== Permanents and perfect matchings ===&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;U=\{u_1,u_2,\ldots,u_n\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;V=\{v_1,v_2,\ldots,v_n\}&amp;lt;/math&amp;gt;. Consider a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt;. An &amp;lt;math&amp;gt;M\subseteq E&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;perfect matching&#039;&#039;&#039; of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; if every vertex of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has exactly one edge in &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; adjacent to it.&lt;br /&gt;
&lt;br /&gt;
Given a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt;, we want to count the number of perfect matchings of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. This problem can be reduced to computing the &#039;&#039;&#039;permanent&#039;&#039;&#039; of a square matrix.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (permanent)&#039;&#039;&#039;&lt;br /&gt;
:Let &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix. The &#039;&#039;&#039;permanent&#039;&#039;&#039; of the matrix is defined as&lt;br /&gt;
::&amp;lt;math&amp;gt;\mathrm{per}(Q)=\sum_{\pi\in\mathbb{S}_n}\prod_{i=1}^n Q_{i,\pi(i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\mathbb{S}_n&amp;lt;/math&amp;gt; is the symmetric group of permutation of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If we multiply each term of the sum the sign of the permutation, then it gives us the determinant of the matrix, &lt;br /&gt;
:&amp;lt;math&amp;gt;\det(Q)=\sum_{\pi\in\mathbb{S}_n}\sgn(\pi)\prod_{i=1}^n Q_{i,\pi(i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\sgn(\pi)&amp;lt;/math&amp;gt;, the sign of a permutation, is either &amp;lt;math&amp;gt;-1&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;+1&amp;lt;/math&amp;gt;, according to whether the minimum number of pair-wise interchanges to achieve &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;(1,2,\ldots,n)&amp;lt;/math&amp;gt; is odd or even.&lt;br /&gt;
&lt;br /&gt;
Unlike the determinants, which are computable in poly-time, permanents are hard to compute, as permanents can be used to count the number of perfect matchings in a bipartite graph, which is &#039;&#039;&#039;#P-complete&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt; can be represented by an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; with 0-1 entries as follows:&lt;br /&gt;
* Each row of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; corresponds to a vertex in &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and each column of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; corresponds to a vertex in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;Q_{ij}=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }i\sim j,\\&lt;br /&gt;
0 &amp;amp; \mbox{otherwise}.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Note the subtle difference between the definition of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; and the adjacency matrix. &lt;br /&gt;
&lt;br /&gt;
Each perfect matching corresponds to a permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;(u,\pi(u))\in E&amp;lt;/math&amp;gt; for every &amp;lt;math&amp;gt;u\in U&amp;lt;/math&amp;gt;, which corresponds to a permutation &amp;lt;math&amp;gt;\pi\in\mathbb{S}_n&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;\prod_{i=1}^n Q_{i,\pi(i)}=1&amp;lt;/math&amp;gt;. It is than easy to see that &amp;lt;math&amp;gt;\mathrm{per}(Q)&amp;lt;/math&amp;gt; gives the number of perfect matchings in the bipartite graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is known that counting the number of perfect matchings in a bipartite graph is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. Since this problem can be reduced to computing the permanent, thus the problem of computing the permanents is also &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Now we show that with randomization, we can approximate the number of perfect matchings in a bipartite graph. In particular, we will give an FPRAS for counting the perfect matchings in a dense bipartite graph.&lt;br /&gt;
&lt;br /&gt;
==== The Jerrum-Sinclair algorithm ====&lt;br /&gt;
Fix a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\mathcal{M}_k&amp;lt;/math&amp;gt; be the set of matchings of size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;m_k=|\mathcal{M}_k|&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;\mathcal{M}_k&amp;lt;/math&amp;gt; is the set of perfect matchings in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and our goal is to compute &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;r_k=\frac{m_k}{m_{k-1}}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;m_k=m_{k-1}r_k&amp;lt;/math&amp;gt;,&lt;br /&gt;
which gives us a recursion to compute the &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt;, as&lt;br /&gt;
:&amp;lt;math&amp;gt;m_n=m_{1}\frac{m_2}{m_1}\cdot\frac{m_3}{m_2}\cdots\frac{m_n}{m_{n-1}}=m_1\prod_{k=2}^n r_k&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;m_1=|\mathcal{M}_1|&amp;lt;/math&amp;gt; is the number of matchings of size 1 in the bipartite graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, which is just the number of edges in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; can be computed once we know &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; can be estimated by sampling uniformly from the set &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;. The algorithm for estimating &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; is outlined as:&lt;br /&gt;
# For each &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;, have an FPRAS for computing the &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; by uniform sampling sufficiently many members from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt; as&lt;br /&gt;
::*uniformly sample &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; matching from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;, for some polynomially large &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;;&lt;br /&gt;
::* assuming that there are &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; sampled matchings of size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, return &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; as &amp;lt;math&amp;gt;r_k=\frac{X}{N-X}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2.  Compute &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; as &amp;lt;math&amp;gt;m_n=m_1\prod_{k=2}^n r_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;m_1=|E|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
There are several issues that we have to deal with in order to have a fully functional FPRAS for counting perfect matchings.&lt;br /&gt;
* By taking the product of &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&#039;s, the errors for individual &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&#039;s add up.&lt;br /&gt;
* In order to accurately estimate &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; by sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;, the ratio &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; should be within the range &amp;lt;math&amp;gt;\left[\frac{1}{\alpha},\alpha\right]&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; within polynomial of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Implement the uniform sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
;Estimator for each &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Accumulation of errors&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
; Near-uniform sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
In the last lecture, we have shown that by random walk, we can sample a near-uniform member of &amp;lt;math&amp;gt;\mathcal{M}_n\cup\mathcal{M}_{n-1}&amp;lt;/math&amp;gt; in poly-time.&lt;br /&gt;
&lt;br /&gt;
=== Volume estimation  ===&lt;br /&gt;
We consider the problem of computing the volume of a given [http://en.wikipedia.org/wiki/Convex_body convex body] &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions. &lt;br /&gt;
&lt;br /&gt;
We use &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; to denote the volume of the convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;. Abstractly, the problem is that given as input a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, return the &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We should be more specific about the input model. Since we allow an arbitrary convex body as input, it is not even clear how to describe the body. We assume that &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is described by means of a &#039;&#039;&#039;membership oracle&#039;&#039;&#039; &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;, such that  for a &#039;&#039;&#039;query&#039;&#039;&#039; of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{O}(x)&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;x\in K&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example, the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional convex body defined by the intersection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; half-spaces, which is the set of feasible solutions to a system of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; linear constraints, can be described as&lt;br /&gt;
:&amp;lt;math&amp;gt;A x\le \boldsymbol{b}&amp;lt;/math&amp;gt;,&lt;br /&gt;
for some &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector &amp;lt;math&amp;gt;b&amp;lt;/math&amp;gt;. For a query of an &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, the membership oracle &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt; just check whether &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For deterministic algorithms, there are negative news for this problem.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Theorem (Bárány-Füredi 1987)&#039;&#039;&#039;&lt;br /&gt;
:Suppose that a deterministic poly-time algorithm uses the membership oracle for a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, and generates an upper bound &amp;lt;math&amp;gt;\Upsilon_u\,&amp;lt;/math&amp;gt; and a lower bound &amp;lt;math&amp;gt;\Upsilon_\ell\,&amp;lt;/math&amp;gt; on the volume &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;. Then, there is a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and a constant &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; such that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{\Upsilon_u}{\Upsilon_\ell}\ge c\left(\frac{n}{\log n}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
That is said, with deterministic algorithms, we cannot even approximate the volume within a wildly loose range.&lt;br /&gt;
&lt;br /&gt;
Dyer-Frieze-Kannan come up with an idea of estimating the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; by sampling near-uniformly from convex sets. They reduce the problem of computing approximately the volume of convex bodies to this sampling problem and thus give the first FPRAS for the volume of convex bodies.&lt;br /&gt;
&lt;br /&gt;
For any convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, it encloses some &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional ball and is also enclosed by another ball with larger radius. We assume that the convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; encloses the unit ball around the origin, and is enclosed by a larger ball round the origin with polynomially large radius. Formally, we assume that&lt;br /&gt;
:&amp;lt;math&amp;gt;B(0,1)\subseteq K\subseteq B(0,n^c)&amp;lt;/math&amp;gt; for some constant &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;B(p,r)&amp;lt;/math&amp;gt; denotes a ball of radius &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; as center, i.e. &amp;lt;math&amp;gt;B(p,r)=\{x\mid \|x-p\|\le r \}&amp;lt;/math&amp;gt;. We can make this assumption because it is known that for any convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, there exists a linear transformation &amp;lt;math&amp;gt;\tau&amp;lt;/math&amp;gt; which can be found within poly-time such that &amp;lt;math&amp;gt;\tau K&amp;lt;/math&amp;gt; transforms the &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; to a convex body that satisfies the assumption, and preserves the ratio of the volumes of the balls to the convex body.&lt;br /&gt;
&lt;br /&gt;
The volumes of the balls are easy to compute. If only the ratio between the convex body and the ball which encloses it, is sufficiently large, then we can apply the Monte Carlo method to estimate &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; by uniformly sampling from the ball.&lt;br /&gt;
&lt;br /&gt;
However, in high-dimension, the ratio between the volume of a convex body and the volume of ball which encloses it, can be exponentially small. This is caused by the so called the &amp;quot;[http://en.wikipedia.org/wiki/Curse_of_dimensionality curse of dimensionality]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Instead of having an outer ball and an inner ball, we define a sequence of balls:&lt;br /&gt;
:&amp;lt;math&amp;gt;B_0=B(0,\lambda^0), B_1=B(0,\lambda^1), B_2=B(0,\lambda^2),\ldots, B_m=B(0,\lambda^m)&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\lambda=(1+\frac{1}{n})&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is the smallest positive integer such that &amp;lt;math&amp;gt;\lambda^m\ge n^c&amp;lt;/math&amp;gt;. Therefore, the inner ball &amp;lt;math&amp;gt;B(0,1)=B_0&amp;lt;/math&amp;gt;, the outer ball &amp;lt;math&amp;gt;B(0,n^c)\subseteq B_m&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is within polynomial of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. In fact, &amp;lt;math&amp;gt;m\approx cn\ln n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This sequence of balls naturally defines a sequence of convex bodies by intersections as &amp;lt;math&amp;gt;K_i=B_i\cap K&amp;lt;/math&amp;gt;. It is obvious that&lt;br /&gt;
:&amp;lt;math&amp;gt;B(0,1)=K_0\subseteq K_1\subseteq K_2\subseteq\cdots\subseteq K_m=K&amp;lt;/math&amp;gt;.&lt;br /&gt;
Balls are convex, and since the intersection of convex bodies is still convex, the sequence of &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt; is a sequence of convex bodies.&lt;br /&gt;
&lt;br /&gt;
We have the telescopic product:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\Upsilon(K_0)}{\Upsilon(K_1)}\cdot\frac{\Upsilon(K_1)}{\Upsilon(K_2)}\cdots\frac{\Upsilon(K_{m-1})}{\Upsilon(K_m)}=\frac{\Upsilon(K_0)}{\Upsilon(K_m)}=\frac{\Upsilon(B(0,1))}{\Upsilon(K)}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, the volume &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; can be computed as &lt;br /&gt;
:&amp;lt;math&amp;gt;\Upsilon(K)=\Upsilon(B(0,1))\cdot\prod_{i=1}^{m}\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The volume of unite ball &amp;lt;math&amp;gt;\Upsilon(B(0,1))\,&amp;lt;/math&amp;gt; can be precisely computed in poly-time. Each &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is computed by near-uniform sampling from &amp;lt;math&amp;gt;K_{i}&amp;lt;/math&amp;gt;, which encloses &amp;lt;math&amp;gt;K_{i-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Another observation is that the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is well-bounded. Recall that &amp;lt;math&amp;gt;K_i=B(0,\lambda^i)\cap K&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;\lambda=(1+\frac{1}{n})&amp;lt;/math&amp;gt;. It can be proved that in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, the volume of &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt; is at most &amp;lt;math&amp;gt;\lambda^n&amp;lt;/math&amp;gt; times the &amp;lt;math&amp;gt;K_{i-1}&amp;lt;/math&amp;gt;, thus the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is at most &amp;lt;math&amp;gt;\lambda^n=O(1)&amp;lt;/math&amp;gt;. By the estimator theorem, we can have an FPRAS for the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; if we can uniformly sample from &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Uniformly sampling from an arbitrary convex body is replaced by near-uniform sampling achieved by random walks. In the original walk of Dyer-Frieze-Kannan, they consider the random walk over &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional discrete grid points enclosed by &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, and prove that the walk is rapid mixing. This gives us the first FPRAS for volume estimation which runs in &amp;lt;math&amp;gt;\tilde{O}(n^{23})&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\tilde{O}(\cdot)&amp;lt;/math&amp;gt; ignores the polylogarithmic factors.&lt;br /&gt;
&lt;br /&gt;
The time bound was later improved by a series of works, each introducing some new ideas.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
| || complexity || new ingredient(s)&lt;br /&gt;
|-&lt;br /&gt;
| Dyer-Frieze-Kannan 1991 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{23}&amp;lt;/math&amp;gt; || everything&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Simonovits 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{16}&amp;lt;/math&amp;gt; || localization lemma&lt;br /&gt;
|-&lt;br /&gt;
| Applegate-Kannan 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{10}&amp;lt;/math&amp;gt; || logconcave sampling&lt;br /&gt;
|-&lt;br /&gt;
| Lovász 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{10}&amp;lt;/math&amp;gt; || ball walk&lt;br /&gt;
|-&lt;br /&gt;
| Dyer-Frieze 1991 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^8&amp;lt;/math&amp;gt; || better error analysis&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Simonovits 1993 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^7&amp;lt;/math&amp;gt; || many improvements&lt;br /&gt;
|-&lt;br /&gt;
| Kannan-Lovász-Simonovits 1997 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^5&amp;lt;/math&amp;gt; || isotropy, speedy walk&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Vempala 2003 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^4&amp;lt;/math&amp;gt; || simulated annealing, hit-and-run&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
(cited from &amp;quot;Geometric Random Walks: A Survey&amp;quot; by Santosh Vempala.)&lt;br /&gt;
&lt;br /&gt;
The current best upper bound is &amp;lt;math&amp;gt;\tilde{O}(n^4)&amp;lt;/math&amp;gt; due to Lovász and Vempala in 2003. It is conjectured that the optimal bound is &amp;lt;math&amp;gt;\Theta(n^3)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Linear Programming ==&lt;br /&gt;
Given a function &amp;lt;math&amp;gt;f:\mathbb{R}^n\rightarrow\mathbb{R}&amp;lt;/math&amp;gt; and a set &amp;lt;math&amp;gt;\mathcal{F}\subseteq\mathbb{R}^n&amp;lt;/math&amp;gt;, an &#039;&#039;&#039;optimization problem&#039;&#039;&#039; is the problem of finding an &amp;lt;math&amp;gt;x\in\mathcal{F}&amp;lt;/math&amp;gt; with the optimal (minimum) &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;. Formally, the problem can be expressed as:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize} &amp;amp; \quad f(x)\\&lt;br /&gt;
\mbox{subject to} &amp;amp;\quad  x\in\mathcal{F}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;x\in\mathcal{R}^n&amp;lt;/math&amp;gt; is a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. For the problem of maximizing a function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, we just minimizes &amp;lt;math&amp;gt;-f&amp;lt;/math&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
We call the function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; the &#039;&#039;&#039;objective function&#039;&#039;&#039; and call any &amp;lt;math&amp;gt;x\in\mathcal{F}&amp;lt;/math&amp;gt; a &#039;&#039;&#039;feasible solution&#039;&#039;&#039; of the problem. A feasible solution that minimizes &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;optimal solution&#039;&#039;&#039;. Our task is to find an optimal solution.&lt;br /&gt;
&lt;br /&gt;
The feasible set &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is usually given by a number of &#039;&#039;&#039;constraints&#039;&#039;&#039; &amp;lt;math&amp;gt;P_1,P_2,\ldots,P_m&amp;lt;/math&amp;gt;, which are predicates defined on &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. An &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is a feasible solution if it satisfies all the constraints. &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;linear programming (LP)&#039;&#039;&#039; problem is an optimization problem with a linear objective function subject to a number of linear constraints. Formally, an LP is a problem that can be expressed in the following form:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c_1x_1+c_2x_2+\cdots+c_nx_n\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad a_{11}x_1+a_{12}x_2+\cdots+a_{1n}x_n\le b_1\\&lt;br /&gt;
&amp;amp; \quad a_{21}x_1+a_{22}x_2+\cdots+a_{2n}x_n\le b_2\\&lt;br /&gt;
&amp;amp; \qquad\qquad \vdots\\&lt;br /&gt;
&amp;amp; \quad a_{m1}x_1+a_{m2}x_2+\cdots+a_{mn}x_n\le b_m\\&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;a_{ij}&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;c_j&amp;lt;/math&amp;gt; are constants and &amp;lt;math&amp;gt;x_j&amp;lt;/math&amp;gt; are variables. For maximization problem, or constraints given by &amp;quot;&amp;lt;math&amp;gt;\ge&amp;lt;/math&amp;gt;&amp;quot;, we can multiply  the coefficients by &amp;lt;math&amp;gt;-1&amp;lt;/math&amp;gt; and still write the LP in the above form. &lt;br /&gt;
&lt;br /&gt;
We can describe the programming in the vector form. Let &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;A=(a_{ij})&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; matrix of constant entries, &amp;lt;math&amp;gt;b=(b_1,\ldots,b_m)&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; constant entries, and &amp;lt;math&amp;gt;c=(c_1,\ldots,c_n)&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; constant entries. Then an LP is expressed as:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c^T x\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad Ax\le b&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
We call it the &#039;&#039;&#039;canonical form&#039;&#039;&#039; of linear programming.&lt;br /&gt;
&lt;br /&gt;
=== The geometry of LPs ===&lt;br /&gt;
For &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional space &amp;lt;math&amp;gt;\mathbb{R}^n&amp;lt;/math&amp;gt;, a linear constraint &amp;lt;math&amp;gt;ax\le b&amp;lt;/math&amp;gt; specifies a [http://en.wikipedia.org/wiki/Half-space halfspace]. The feasible set specified by &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; constraints together is an intersection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; halfspaces, thus, a [http://en.wikipedia.org/wiki/Convex_polytope convex polytope].&lt;br /&gt;
&lt;br /&gt;
The convex polytope is defined by &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The LP can be thought as given an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional polytope and a linear (affine) function &amp;lt;math&amp;gt;f:\mathbb{R}^n\rightarrow \mathbb{R}&amp;lt;/math&amp;gt;, looking for a point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; in the polytope with the smallest function value &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We can choose a number of constraints in the system &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, and make them hold with equality. This would define a subspace of &amp;lt;math&amp;gt;\mathbb{R}^n&amp;lt;/math&amp;gt;. In particular, if we choose &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; linearly independent constraints to form an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; submatrix &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; and the corresponding &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector &amp;lt;math&amp;gt;b&#039;&amp;lt;/math&amp;gt;, solving &amp;lt;math&amp;gt;A&#039;x=b&#039;&amp;lt;/math&amp;gt; would give us exactly one point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. If this &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is in the polytope, i.e. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; satisfies that &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, we call such &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; a &#039;&#039;&#039;vertex&#039;&#039;&#039; of the polytope &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;. In the context of LP, it is also called a &#039;&#039;&#039;basic feasible solution (&#039;&#039;bfs&#039;&#039;)&#039;&#039;&#039; of the LP.&lt;br /&gt;
&lt;br /&gt;
A key observation for LP is that there is a basic feasible solution which is optimal, i.e. the optimal solution is a vertex of the polytope.&lt;br /&gt;
&lt;br /&gt;
=== The simplex algorithms ===&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Simplex_algorithm simplex algorithm] by George Dantzig solves the linear programming by moving from vertex to vertex of the convex polytope, each time making some progress towards optimizing the objective function. Eventually the algorithm reaches a vertex which is a [http://en.wikipedia.org/wiki/Local_optimum local optimum]. In a convex set, a locally optimal point is also global optimal, thus the simplex algorithm returns an optimal solution in finite steps.&lt;br /&gt;
&lt;br /&gt;
The problem with the simplex algorithm is that in some bad polytopes, it takes the simplex algorithm exponentially many steps to reach the optimum. The simplex algorithm is actually a class of algorithms defined by various &#039;&#039;&#039;pivoting rules&#039;&#039;&#039;, which describe how to move locally from one vertex to another. The original pivoting rule proposed by Dantzig has an exponentially large worst-case time complexity (though works very good in practice). To-date, it is still unknown whether there exists any deterministic simplex algorithm with sub-exponential worst-case complexity.&lt;br /&gt;
&lt;br /&gt;
People have tried randomized pivoting rules, and there are some amazing progresses have been made:&lt;br /&gt;
* Kalai 1992: there is a randomized simplex algorithm with sub-exponential time complexity.&lt;br /&gt;
* Kelner-Spielman 2006: there is a polynomial time randomized simplex algorithm.&lt;br /&gt;
&lt;br /&gt;
Although we do not know whether there exists deterministic poly-time simplex algorithm, we do know that LP can be solved by deterministic poly-time algorithms, i.e. LP is in &#039;&#039;&#039;P&#039;&#039;&#039;. The following two algorithms use different ideas than the simplex algorithm, and are both in poly-time:&lt;br /&gt;
* The ellipsoid algorithm.&lt;br /&gt;
* Interior point methods.&lt;br /&gt;
Although these algorithms guarantee polynomial time complexity in the worst-case, their performances are worse than the simplex algorithms. However, the ideas of these algorithms can be used to solve more general mathematical programmings, such as [http://en.wikipedia.org/wiki/Convex_programming convex programmings].&lt;br /&gt;
&lt;br /&gt;
=== An LP solver via random walks ===&lt;br /&gt;
We discuss a new algorithm for solving LP which is based on random sampling, introduced by Bertsimas and Vempala in 2004. &lt;br /&gt;
&lt;br /&gt;
The problem of solving an LP can be reduced to that given a convex polytope &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, test whether the polytope is empty. We call this problem the &amp;quot;&#039;&#039;feasibility test&#039;&#039;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Suppose we have an LP:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c^T x\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad Ax\le b&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
To see this LP can be solved by feasibility testing, we treat the &amp;lt;math&amp;gt;c^Tx\le d&amp;lt;/math&amp;gt; for some parameter &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; as an additional constraint, and define a new polytope &amp;lt;math&amp;gt;A&#039;x\le b&#039;&amp;lt;/math&amp;gt;. The smallest &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; that the polytope &amp;lt;math&amp;gt;A&#039;x\le b&#039;&amp;lt;/math&amp;gt; is not empty is the optimal solution to the original LP. We can find this smallest &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; by binary search if we can efficiently test the emptiness of a convex polytope.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We assume that the convex polytope &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is contained in the axis-aligned cube of width &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; centered at the origin; further if &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is non-empty then it contains a cube of width &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;. The parameter &amp;lt;math&amp;gt;L&amp;lt;/math&amp;gt; is equal to &amp;lt;math&amp;gt;\log\frac{R}{r}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Algorithm&#039;&#039;&#039;: feasibility test &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Input&#039;&#039;&#039;: an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional convex polytope &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; defined by the system &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;: a point &amp;lt;math&amp;gt;x\in P&amp;lt;/math&amp;gt; in the polytope, or a guarantee that &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is empty.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; be the axis-aligned cube of side length &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; and center &amp;lt;math&amp;gt;z=\boldsymbol{0}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Repeat for &amp;lt;math&amp;gt;2nL&amp;lt;/math&amp;gt; times do:&lt;br /&gt;
:: If &amp;lt;math&amp;gt;Az\le b&amp;lt;/math&amp;gt;, return &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: Pick a constraint violated by &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;, say that &amp;lt;math&amp;gt;A_i z&amp;gt;b_i&amp;lt;/math&amp;gt;, and define the halfspace&lt;br /&gt;
:::&amp;lt;math&amp;gt;H=\{x\mid A_i x\le A_i z\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
::Set &amp;lt;math&amp;gt;K=K\cap H&amp;lt;/math&amp;gt;. Uniformly sample &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; random points &amp;lt;math&amp;gt;y^{(1)},y^{(2)},\ldots,y^{(N)}&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and let &lt;br /&gt;
:::&amp;lt;math&amp;gt;z=\frac{1}{N}\sum_{i=1}^Ny^{(i)}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Report &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is empty.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The number of samples required in each iteration, &amp;lt;math&amp;gt;N=O((\log m)^2)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is the number of linear constraints. &lt;br /&gt;
&lt;br /&gt;
It is easy to see that at any iteration, &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is a convex set, and &amp;lt;math&amp;gt;P\subseteq K&amp;lt;/math&amp;gt; for the current convex set &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The idea of the algorithm is based on computing the [http://en.wikipedia.org/wiki/Centroid centroid] of the convex set.  It is know that if we could compute the exact centroid in each iteration, then the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; drops by a constant factor &amp;lt;math&amp;gt;(1-1/e)&amp;lt;/math&amp;gt; in each iteration, thus reaches the smallest possible volume of a cube of width &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; within polynomial number of iterations. But, finding the centroid of a convex polytope, is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The idea behind the algorithm is that an approximate centroid can be computed using &amp;lt;math&amp;gt;N=O((\log m)^2)&amp;lt;/math&amp;gt; random points and the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is drops by a constant factor with high probability in each iteration with this choice of &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
The uniform sampling in &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is not easy. But since &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is also a convex polytope, we can approximate the uniform sampling by  near-uniform sampling from &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; by rapid mixing random walks. The random walks used here are similar to the ones used in the volume estimation of convex bodies. We could use the basic grid walk, or more advanced ball walk, or hit-and-run walk.&lt;br /&gt;
&lt;br /&gt;
With rapid mixing random walks, the resulting LP solver runs in poly-time.&lt;br /&gt;
&lt;br /&gt;
The details are omitted. You may check the following paper if interested:&lt;br /&gt;
* Bertsimas and Vempala, “&#039;&#039;Solving convex programs by random walks&#039;&#039;.” JACM 2004.&lt;/div&gt;</summary>
		<author><name>172.21.4.18</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2472</id>
		<title>Randomized Algorithms (Spring 2010)/Approximate counting, linear programming</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2472"/>
		<updated>2010-05-24T19:21:31Z</updated>

		<summary type="html">&lt;p&gt;172.21.4.18: /* Complexity model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Complexity model ===&lt;br /&gt;
Recall the class &#039;&#039;&#039;NP&#039;&#039;&#039; of decision problems (the problems with &amp;quot;yes&amp;quot; or &amp;quot;no&amp;quot; answers). Formally, denoting by &amp;lt;math&amp;gt;\{0,1\}^*&amp;lt;/math&amp;gt; the set of all boolean strings of any lengths, a decision problem is a function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (NP)&#039;&#039;&#039;&lt;br /&gt;
:A function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\{0,1\}&amp;lt;/math&amp;gt; is in &#039;&#039;&#039;NP&#039;&#039;&#039; if there exist a polynomial &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and a poly-time algorithm &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; with boolean output such that for every &amp;lt;math&amp;gt;x\in\{0,1\}^*&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;f(x)=1 \Leftrightarrow \exists y\in\{0,1\}^{p(|x|)}, \mbox{such that } V(x,y)=1\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
Intuitively, the &#039;&#039;&#039;NP&#039;&#039;&#039; class contains all the decision problems such that the answer is &amp;quot;yes&amp;quot; if and only if there &#039;&#039;exists&#039;&#039; a &#039;&#039;&#039;certificate&#039;&#039;&#039; which can be verified in poly-time.&lt;br /&gt;
&lt;br /&gt;
In many contexts, we are interested not just in the &#039;&#039;existence&#039;&#039; of certificate but actually in counting the &#039;&#039;number&#039;&#039; of certificates. This leads to the definition of the class &#039;&#039;&#039;#P&#039;&#039;&#039; (pronounced &amp;quot;sharp p&amp;quot;). Only now the output of the function is a natural number.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (#P)&#039;&#039;&#039;&lt;br /&gt;
:A function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; is in &#039;&#039;&#039;#P&#039;&#039;&#039; if there exist a polynomial &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and a poly-time algorithm &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; with boolean output such that for every &amp;lt;math&amp;gt;x\in\{0,1\}^*&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;f(x)=\left|\left\{y\in\{0,1\}^{p(|x|)}\mid A(x,y)=1\right\}\right|&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
You may notice the similarity between the two definitions. The difference is that now &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt; does not just indicates the existence of a certificate, but gives the actual number of certificates.&lt;br /&gt;
&lt;br /&gt;
Why should we care about the number of &amp;quot;certificates&amp;quot; at all?&lt;br /&gt;
In combinatorics, a counting problem is usually formulated as counting the number of combinatorial objects with some particular structure, such as the number of trees, or Latin squares. The &#039;&#039;&#039;#P&#039;&#039;&#039; class contains the counting problems that the &amp;quot;structure&amp;quot; requirements are easy to check.&lt;br /&gt;
&lt;br /&gt;
;Examples of problems in #P&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;cycles: given as input a graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, count the number of cycles in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;SAT: given as input a boolean formula &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;, count the number of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The second example shows that the &#039;&#039;&#039;&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;P&#039;&#039;&#039; may be harder than &#039;&#039;&#039;NP&#039;&#039;&#039;, because we know that SAT (given a boolean formular, decide the existence of satisfying assignments) is &#039;&#039;&#039;NP-complete&#039;&#039;&#039;, and its counting version &amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;SAT now ask for the exact number of satisfying assignments.&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;FP&#039;&#039;&#039; contains all the functions &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; computable by poly-time algorithms. The classes &#039;&#039;&#039;FP&#039;&#039;&#039; and &#039;&#039;&#039;#P&#039;&#039;&#039; are the analogs of &#039;&#039;&#039;P&#039;&#039;&#039; and &#039;&#039;&#039;NP&#039;&#039;&#039; for counting problems.&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;reduction&#039;&#039;&#039; from a problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to a problem &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is a mapping &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; which maps instances of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to instances of &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; such that for any instance &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;,&lt;br /&gt;
:&amp;lt;math&amp;gt;f(x)=g(\phi(x))&amp;lt;/math&amp;gt;.&lt;br /&gt;
In other words, &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; &amp;quot;reduces&amp;quot; the task of solving &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to the task of solving &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt;. A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is said to be &#039;&#039;&#039;poly-time reducible&#039;&#039;&#039; to the problem &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt;, if there exists a reduction &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is poly-time computable.&lt;br /&gt;
&lt;br /&gt;
A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-hard&#039;&#039;&#039; if every problem in &#039;&#039;&#039;#P&#039;&#039;&#039; is poly-time reducible to &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;. A problem &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-complete&#039;&#039;&#039; if &amp;lt;math&amp;gt;f\in&amp;lt;/math&amp;gt;&#039;&#039;&#039;#P&#039;&#039;&#039; and &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. That is to say, &#039;&#039;&#039;#P-complete&#039;&#039;&#039; problems are the &amp;quot;hardest&amp;quot; problems in &#039;&#039;&#039;#P&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== FPRAS ===&lt;br /&gt;
&lt;br /&gt;
== Approximate Counting ==&lt;br /&gt;
Let us consider the following abstract problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be a finite set of known size, and let &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt;. We want to compute the size of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, namely &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We assume two devices:&lt;br /&gt;
* A &#039;&#039;&#039;uniform sampler&#039;&#039;&#039; &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;, which uniformly and independently samples a member of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; upon each calling.&lt;br /&gt;
* A &#039;&#039;&#039;membership oracle&#039;&#039;&#039; of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;. Given as the input an &amp;lt;math&amp;gt;x\in U&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{O}(x)&amp;lt;/math&amp;gt; indicates whether or not &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is a member of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Equipped by &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;, we can have the following Monte Carlo algorithm:&lt;br /&gt;
*Choose &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; independent samples from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; by the uniform sampler &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;, represented by the random variables &amp;lt;math&amp;gt;X_1,X_2,\ldots, X_N&amp;lt;/math&amp;gt;. &lt;br /&gt;
* Let &amp;lt;math&amp;gt;Y_i&amp;lt;/math&amp;gt; be the indicator random variable defined as &amp;lt;math&amp;gt;Y_i=\mathcal{O}(X_i)&amp;lt;/math&amp;gt;, namely, &amp;lt;math&amp;gt;Y_i&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;X_i\in G&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Define the estimator random variable&lt;br /&gt;
::&amp;lt;math&amp;gt;Z=\frac{|U|}{N}\sum_{i=1}^N Y_i.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is easy to see that &amp;lt;math&amp;gt;\mathbf{E}[Z]=|G|&amp;lt;/math&amp;gt; and we might hope that with high probability the value of &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt; is close to &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt;. Formally, &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt; is called an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation of &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; if&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1-\epsilon)|G|\le Z\le (1+\epsilon)|G|.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following theorem states that the probabilistic accuracy of the estimation depends on the number of samples and the ratio between &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|U|&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Theorem (estimator theorem)&#039;&#039;&#039;&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;. Then the Monte Carlo method yields an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation to &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; with probability at least &amp;lt;math&amp;gt;1-\delta&amp;lt;/math&amp;gt; provided&lt;br /&gt;
::&amp;lt;math&amp;gt;N\ge\frac{4}{\epsilon \alpha}\ln\frac{2}{\delta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;Proof&#039;&#039;&#039;: Use the Chernoff bound.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A counting algorithm for the set &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has to deal with the following three complications:&lt;br /&gt;
* Implement the membership oracle &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;. This is usually straightforward, or assumed by the model.&lt;br /&gt;
* Implement the uniform sampler &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;. As we have seen, this is usually approximated by random walks. How to design the random walk and bound its mixing rate is usually technical challenging, if possible at all.&lt;br /&gt;
* Deal with exponentially small &amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;. This requires us to cleverly choose the universe &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. Sometimes this needs some nontrivial ideas.&lt;br /&gt;
&lt;br /&gt;
=== Counting DNFs ===&lt;br /&gt;
A disjunctive normal form (DNF) formular is a disjunction (OR) of clauses, where each clause is a conjunction (AND) of literals. For example:&lt;br /&gt;
:&amp;lt;math&amp;gt;(x_1\wedge \overline{x_2}\wedge x_3)\vee(x_2\wedge x_4)\vee(\overline{x_1}\wedge x_3\wedge x_4)&amp;lt;/math&amp;gt;.&lt;br /&gt;
Note the difference from the conjunctive normal forms (CNF).&lt;br /&gt;
&lt;br /&gt;
Given a DNF formular &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; as the input, the problem is to count the number of satisfying assignments of &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. This problem is &#039;&#039;&#039;#P-complete&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Naively applying the Monte Carlo method will not give a good answer. Suppose that there are &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;U=\{\mathrm{true},\mathrm{false}\}^n&amp;lt;/math&amp;gt; be the set of all truth assignments of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;G=\{x\in U\mid \phi(x)=\mathrm{true}\}&amp;lt;/math&amp;gt; be the set of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. The straightforward use of Monte Carlo method samples &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; assignments from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and check how many of them satisfy &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. This algorithm fails when &amp;lt;math&amp;gt;|G|/|U|&amp;lt;/math&amp;gt; is exponentially small, namely, when exponentially small fraction of the assignments satisfy the input DNF formula. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;The union of sets problem&lt;br /&gt;
We reformulate the DNF counting problem in a more abstract framework, called the &#039;&#039;&#039;union of sets&#039;&#039;&#039; problem. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; be a finite universe. We are given &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; subsets &amp;lt;math&amp;gt;H_1,H_2,\ldots,H_m\subseteq V&amp;lt;/math&amp;gt;. The following assumptions hold:&lt;br /&gt;
*For all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;|H_i|&amp;lt;/math&amp;gt; is computable in poly-time.&lt;br /&gt;
*It is possible to sample uniformly from each individual &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
*For any &amp;lt;math&amp;gt;x\in V&amp;lt;/math&amp;gt;, it can be determined in poly-time whether &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The goal is to compute the size of &amp;lt;math&amp;gt;H=\bigcup_{i=1}^m H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
DNF counting can be interpreted in this general framework as follows. Suppose that the DNF formula &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is defined on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables, and &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; contains &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; clauses &amp;lt;math&amp;gt;C_1,C_2,\ldots,C_m&amp;lt;/math&amp;gt;, where clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;k_i&amp;lt;/math&amp;gt; literals. Without loss of generality, we assume that in each clause, each variable appears at most once.&lt;br /&gt;
* &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; is the set of all assignments.&lt;br /&gt;
*Each &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is the set of satisfying assignments for the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;-th clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; of the DNF formular &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. Then the union of sets &amp;lt;math&amp;gt;H=\bigcup_i H_i&amp;lt;/math&amp;gt; gives the set of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Each clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; is a conjunction (AND) of literals. It is not hard to see that &amp;lt;math&amp;gt;|H_i|=2^{n-k_i}&amp;lt;/math&amp;gt;, which is efficiently computable.&lt;br /&gt;
* Sampling from an &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is simple: we just fix the assignments of the &amp;lt;math&amp;gt;k_i&amp;lt;/math&amp;gt; literals of that clause, and sample uniformly and independently the rest &amp;lt;math&amp;gt;(n-k_i)&amp;lt;/math&amp;gt; variable assignments.&lt;br /&gt;
* For each assignment &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, it is easy to check whether it satisfies a clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt;, thus it is easy to determine whether &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
;The coverage algorithm&lt;br /&gt;
We now introduce the coverage algorithm for the union of sets problem.&lt;br /&gt;
&lt;br /&gt;
Consider the multiset &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; defined by&lt;br /&gt;
:&amp;lt;math&amp;gt;U=H_1\uplus H_2\uplus\cdots \uplus H_m&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\uplus&amp;lt;/math&amp;gt; denotes the multiset union. It is more convenient to define &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; as the set&lt;br /&gt;
:&amp;lt;math&amp;gt;U=\{(x,i)\mid x\in H_i\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
For each &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt;, there may be more than one instances of &amp;lt;math&amp;gt;(x,i)\in U&amp;lt;/math&amp;gt;. We can choose a unique representative among the multiple instances &amp;lt;math&amp;gt;(x,i)\in U&amp;lt;/math&amp;gt; for the same &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt;, by choosing the &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt; with the minimum &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, and form a set &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, &amp;lt;math&amp;gt;G=\{(x,i)\in U\mid \forall (x,j)\in U, j\le i\}&amp;lt;/math&amp;gt;. Every &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt; corresponds to a unique &amp;lt;math&amp;gt;(x,i)\in G&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the smallest among &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is obvious that &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt; and&lt;br /&gt;
:&amp;lt;math&amp;gt;|G|=|H|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, estimation of &amp;lt;math&amp;gt;|H|&amp;lt;/math&amp;gt; is reduced to estimation of &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; can have an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation with probability &amp;lt;math&amp;gt;(1-\delta)&amp;lt;/math&amp;gt; in poly-time, if we can uniformly sample from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|G|/|U|&amp;lt;/math&amp;gt; is suitably small.&lt;br /&gt;
&lt;br /&gt;
An uniform sample from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; can be implemented as follows:&lt;br /&gt;
* generate an &amp;lt;math&amp;gt;i\in\{1,2,\ldots,m\}&amp;lt;/math&amp;gt; with probability &amp;lt;math&amp;gt;\frac{|H_i|}{\sum_{i=1}^m|H_i|}&amp;lt;/math&amp;gt;;&lt;br /&gt;
* uniformly sample an &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;, and return &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is easy to see that this gives a uniform member of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. The above sampling procedure is poly-time because each &amp;lt;math&amp;gt;|H_i|&amp;lt;/math&amp;gt; can be computed in poly-time, and sampling uniformly from each &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is poly-time.&lt;br /&gt;
&lt;br /&gt;
We now only need to lower bound the ratio&lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We claim that &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha\ge\frac{1}{m}&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is easy to see this, because each &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt; has at most &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; instances of &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;, and we already know that &amp;lt;math&amp;gt;|G|=|H|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Due to the estimator theorem, this needs &amp;lt;math&amp;gt;\frac{4m}{\epsilon}\ln\frac{2}{\delta}&amp;lt;/math&amp;gt; uniform random samples from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This gives the coverage algorithm for the abstract problem of the union of sets. The DNF counting is a special case of it.&lt;br /&gt;
&lt;br /&gt;
=== Permanents and perfect matchings ===&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;U=\{u_1,u_2,\ldots,u_n\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;V=\{v_1,v_2,\ldots,v_n\}&amp;lt;/math&amp;gt;. Consider a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt;. An &amp;lt;math&amp;gt;M\subseteq E&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;perfect matching&#039;&#039;&#039; of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; if every vertex of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has exactly one edge in &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; adjacent to it.&lt;br /&gt;
&lt;br /&gt;
Given a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt;, we want to count the number of perfect matchings of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. This problem can be reduced to computing the &#039;&#039;&#039;permanent&#039;&#039;&#039; of a square matrix.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (permanent)&#039;&#039;&#039;&lt;br /&gt;
:Let &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix. The &#039;&#039;&#039;permanent&#039;&#039;&#039; of the matrix is defined as&lt;br /&gt;
::&amp;lt;math&amp;gt;\mathrm{per}(Q)=\sum_{\pi\in\mathbb{S}_n}\prod_{i=1}^n Q_{i,\pi(i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\mathbb{S}_n&amp;lt;/math&amp;gt; is the symmetric group of permutation of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If we multiply each term of the sum the sign of the permutation, then it gives us the determinant of the matrix, &lt;br /&gt;
:&amp;lt;math&amp;gt;\det(Q)=\sum_{\pi\in\mathbb{S}_n}\sgn(\pi)\prod_{i=1}^n Q_{i,\pi(i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\sgn(\pi)&amp;lt;/math&amp;gt;, the sign of a permutation, is either &amp;lt;math&amp;gt;-1&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;+1&amp;lt;/math&amp;gt;, according to whether the minimum number of pair-wise interchanges to achieve &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;(1,2,\ldots,n)&amp;lt;/math&amp;gt; is odd or even.&lt;br /&gt;
&lt;br /&gt;
Unlike the determinants, which are computable in poly-time, permanents are hard to compute, as permanents can be used to count the number of perfect matchings in a bipartite graph, which is &#039;&#039;&#039;#P-complete&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt; can be represented by an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; with 0-1 entries as follows:&lt;br /&gt;
* Each row of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; corresponds to a vertex in &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and each column of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; corresponds to a vertex in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;Q_{ij}=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }i\sim j,\\&lt;br /&gt;
0 &amp;amp; \mbox{otherwise}.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Note the subtle difference between the definition of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; and the adjacency matrix. &lt;br /&gt;
&lt;br /&gt;
Each perfect matching corresponds to a permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;(u,\pi(u))\in E&amp;lt;/math&amp;gt; for every &amp;lt;math&amp;gt;u\in U&amp;lt;/math&amp;gt;, which corresponds to a permutation &amp;lt;math&amp;gt;\pi\in\mathbb{S}_n&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;\prod_{i=1}^n Q_{i,\pi(i)}=1&amp;lt;/math&amp;gt;. It is than easy to see that &amp;lt;math&amp;gt;\mathrm{per}(Q)&amp;lt;/math&amp;gt; gives the number of perfect matchings in the bipartite graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is known that counting the number of perfect matchings in a bipartite graph is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. Since this problem can be reduced to computing the permanent, thus the problem of computing the permanents is also &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Now we show that with randomization, we can approximate the number of perfect matchings in a bipartite graph. In particular, we will give an FPRAS for counting the perfect matchings in a dense bipartite graph.&lt;br /&gt;
&lt;br /&gt;
==== The Jerrum-Sinclair algorithm ====&lt;br /&gt;
Fix a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\mathcal{M}_k&amp;lt;/math&amp;gt; be the set of matchings of size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;m_k=|\mathcal{M}_k|&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;\mathcal{M}_k&amp;lt;/math&amp;gt; is the set of perfect matchings in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and our goal is to compute &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;r_k=\frac{m_k}{m_{k-1}}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;m_k=m_{k-1}r_k&amp;lt;/math&amp;gt;,&lt;br /&gt;
which gives us a recursion to compute the &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt;, as&lt;br /&gt;
:&amp;lt;math&amp;gt;m_n=m_{1}\frac{m_2}{m_1}\cdot\frac{m_3}{m_2}\cdots\frac{m_n}{m_{n-1}}=m_1\prod_{k=2}^n r_k&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;m_1=|\mathcal{M}_1|&amp;lt;/math&amp;gt; is the number of matchings of size 1 in the bipartite graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, which is just the number of edges in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; can be computed once we know &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; can be estimated by sampling uniformly from the set &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;. The algorithm for estimating &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; is outlined as:&lt;br /&gt;
# For each &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;, have an FPRAS for computing the &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; by uniform sampling sufficiently many members from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt; as&lt;br /&gt;
::*uniformly sample &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; matching from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;, for some polynomially large &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;;&lt;br /&gt;
::* assuming that there are &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; sampled matchings of size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, return &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; as &amp;lt;math&amp;gt;r_k=\frac{X}{N-X}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2.  Compute &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; as &amp;lt;math&amp;gt;m_n=m_1\prod_{k=2}^n r_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;m_1=|E|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
There are several issues that we have to deal with in order to have a fully functional FPRAS for counting perfect matchings.&lt;br /&gt;
* By taking the product of &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&#039;s, the errors for individual &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&#039;s add up.&lt;br /&gt;
* In order to accurately estimate &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; by sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;, the ratio &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; should be within the range &amp;lt;math&amp;gt;\left[\frac{1}{\alpha},\alpha\right]&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; within polynomial of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Implement the uniform sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
;Estimator for each &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Accumulation of errors&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
; Near-uniform sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
In the last lecture, we have shown that by random walk, we can sample a near-uniform member of &amp;lt;math&amp;gt;\mathcal{M}_n\cup\mathcal{M}_{n-1}&amp;lt;/math&amp;gt; in poly-time.&lt;br /&gt;
&lt;br /&gt;
=== Volume estimation  ===&lt;br /&gt;
We consider the problem of computing the volume of a given [http://en.wikipedia.org/wiki/Convex_body convex body] &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions. &lt;br /&gt;
&lt;br /&gt;
We use &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; to denote the volume of the convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;. Abstractly, the problem is that given as input a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, return the &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We should be more specific about the input model. Since we allow an arbitrary convex body as input, it is not even clear how to describe the body. We assume that &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is described by means of a &#039;&#039;&#039;membership oracle&#039;&#039;&#039; &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;, such that  for a &#039;&#039;&#039;query&#039;&#039;&#039; of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{O}(x)&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;x\in K&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example, the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional convex body defined by the intersection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; half-spaces, which is the set of feasible solutions to a system of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; linear constraints, can be described as&lt;br /&gt;
:&amp;lt;math&amp;gt;A x\le \boldsymbol{b}&amp;lt;/math&amp;gt;,&lt;br /&gt;
for some &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector &amp;lt;math&amp;gt;b&amp;lt;/math&amp;gt;. For a query of an &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, the membership oracle &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt; just check whether &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For deterministic algorithms, there are negative news for this problem.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Theorem (Bárány-Füredi 1987)&#039;&#039;&#039;&lt;br /&gt;
:Suppose that a deterministic poly-time algorithm uses the membership oracle for a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, and generates an upper bound &amp;lt;math&amp;gt;\Upsilon_u\,&amp;lt;/math&amp;gt; and a lower bound &amp;lt;math&amp;gt;\Upsilon_\ell\,&amp;lt;/math&amp;gt; on the volume &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;. Then, there is a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and a constant &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; such that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{\Upsilon_u}{\Upsilon_\ell}\ge c\left(\frac{n}{\log n}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
That is said, with deterministic algorithms, we cannot even approximate the volume within a wildly loose range.&lt;br /&gt;
&lt;br /&gt;
Dyer-Frieze-Kannan come up with an idea of estimating the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; by sampling near-uniformly from convex sets. They reduce the problem of computing approximately the volume of convex bodies to this sampling problem and thus give the first FPRAS for the volume of convex bodies.&lt;br /&gt;
&lt;br /&gt;
For any convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, it encloses some &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional ball and is also enclosed by another ball with larger radius. We assume that the convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; encloses the unit ball around the origin, and is enclosed by a larger ball round the origin with polynomially large radius. Formally, we assume that&lt;br /&gt;
:&amp;lt;math&amp;gt;B(0,1)\subseteq K\subseteq B(0,n^c)&amp;lt;/math&amp;gt; for some constant &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;B(p,r)&amp;lt;/math&amp;gt; denotes a ball of radius &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; as center, i.e. &amp;lt;math&amp;gt;B(p,r)=\{x\mid \|x-p\|\le r \}&amp;lt;/math&amp;gt;. We can make this assumption because it is known that for any convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, there exists a linear transformation &amp;lt;math&amp;gt;\tau&amp;lt;/math&amp;gt; which can be found within poly-time such that &amp;lt;math&amp;gt;\tau K&amp;lt;/math&amp;gt; transforms the &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; to a convex body that satisfies the assumption, and preserves the ratio of the volumes of the balls to the convex body.&lt;br /&gt;
&lt;br /&gt;
The volumes of the balls are easy to compute. If only the ratio between the convex body and the ball which encloses it, is sufficiently large, then we can apply the Monte Carlo method to estimate &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; by uniformly sampling from the ball.&lt;br /&gt;
&lt;br /&gt;
However, in high-dimension, the ratio between the volume of a convex body and the volume of ball which encloses it, can be exponentially small. This is caused by the so called the &amp;quot;[http://en.wikipedia.org/wiki/Curse_of_dimensionality curse of dimensionality]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Instead of having an outer ball and an inner ball, we define a sequence of balls:&lt;br /&gt;
:&amp;lt;math&amp;gt;B_0=B(0,\lambda^0), B_1=B(0,\lambda^1), B_2=B(0,\lambda^2),\ldots, B_m=B(0,\lambda^m)&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\lambda=(1+\frac{1}{n})&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is the smallest positive integer such that &amp;lt;math&amp;gt;\lambda^m\ge n^c&amp;lt;/math&amp;gt;. Therefore, the inner ball &amp;lt;math&amp;gt;B(0,1)=B_0&amp;lt;/math&amp;gt;, the outer ball &amp;lt;math&amp;gt;B(0,n^c)\subseteq B_m&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is within polynomial of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. In fact, &amp;lt;math&amp;gt;m\approx cn\ln n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This sequence of balls naturally defines a sequence of convex bodies by intersections as &amp;lt;math&amp;gt;K_i=B_i\cap K&amp;lt;/math&amp;gt;. It is obvious that&lt;br /&gt;
:&amp;lt;math&amp;gt;B(0,1)=K_0\subseteq K_1\subseteq K_2\subseteq\cdots\subseteq K_m=K&amp;lt;/math&amp;gt;.&lt;br /&gt;
Balls are convex, and since the intersection of convex bodies is still convex, the sequence of &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt; is a sequence of convex bodies.&lt;br /&gt;
&lt;br /&gt;
We have the telescopic product:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\Upsilon(K_0)}{\Upsilon(K_1)}\cdot\frac{\Upsilon(K_1)}{\Upsilon(K_2)}\cdots\frac{\Upsilon(K_{m-1})}{\Upsilon(K_m)}=\frac{\Upsilon(K_0)}{\Upsilon(K_m)}=\frac{\Upsilon(B(0,1))}{\Upsilon(K)}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, the volume &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; can be computed as &lt;br /&gt;
:&amp;lt;math&amp;gt;\Upsilon(K)=\Upsilon(B(0,1))\cdot\prod_{i=1}^{m}\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The volume of unite ball &amp;lt;math&amp;gt;\Upsilon(B(0,1))\,&amp;lt;/math&amp;gt; can be precisely computed in poly-time. Each &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is computed by near-uniform sampling from &amp;lt;math&amp;gt;K_{i}&amp;lt;/math&amp;gt;, which encloses &amp;lt;math&amp;gt;K_{i-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Another observation is that the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is well-bounded. Recall that &amp;lt;math&amp;gt;K_i=B(0,\lambda^i)\cap K&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;\lambda=(1+\frac{1}{n})&amp;lt;/math&amp;gt;. It can be proved that in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, the volume of &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt; is at most &amp;lt;math&amp;gt;\lambda^n&amp;lt;/math&amp;gt; times the &amp;lt;math&amp;gt;K_{i-1}&amp;lt;/math&amp;gt;, thus the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is at most &amp;lt;math&amp;gt;\lambda^n=O(1)&amp;lt;/math&amp;gt;. By the estimator theorem, we can have an FPRAS for the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; if we can uniformly sample from &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Uniformly sampling from an arbitrary convex body is replaced by near-uniform sampling achieved by random walks. In the original walk of Dyer-Frieze-Kannan, they consider the random walk over &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional discrete grid points enclosed by &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, and prove that the walk is rapid mixing. This gives us the first FPRAS for volume estimation which runs in &amp;lt;math&amp;gt;\tilde{O}(n^{23})&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\tilde{O}(\cdot)&amp;lt;/math&amp;gt; ignores the polylogarithmic factors.&lt;br /&gt;
&lt;br /&gt;
The time bound was later improved by a series of works, each introducing some new ideas.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
| || complexity || new ingredient(s)&lt;br /&gt;
|-&lt;br /&gt;
| Dyer-Frieze-Kannan 1991 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{23}&amp;lt;/math&amp;gt; || everything&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Simonovits 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{16}&amp;lt;/math&amp;gt; || localization lemma&lt;br /&gt;
|-&lt;br /&gt;
| Applegate-Kannan 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{10}&amp;lt;/math&amp;gt; || logconcave sampling&lt;br /&gt;
|-&lt;br /&gt;
| Lovász 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{10}&amp;lt;/math&amp;gt; || ball walk&lt;br /&gt;
|-&lt;br /&gt;
| Dyer-Frieze 1991 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^8&amp;lt;/math&amp;gt; || better error analysis&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Simonovits 1993 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^7&amp;lt;/math&amp;gt; || many improvements&lt;br /&gt;
|-&lt;br /&gt;
| Kannan-Lovász-Simonovits 1997 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^5&amp;lt;/math&amp;gt; || isotropy, speedy walk&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Vempala 2003 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^4&amp;lt;/math&amp;gt; || simulated annealing, hit-and-run&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
(cited from &amp;quot;Geometric Random Walks: A Survey&amp;quot; by Santosh Vempala.)&lt;br /&gt;
&lt;br /&gt;
The current best upper bound is &amp;lt;math&amp;gt;\tilde{O}(n^4)&amp;lt;/math&amp;gt; due to Lovász and Vempala in 2003. It is conjectured that the optimal bound is &amp;lt;math&amp;gt;\Theta(n^3)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Linear Programming ==&lt;br /&gt;
Given a function &amp;lt;math&amp;gt;f:\mathbb{R}^n\rightarrow\mathbb{R}&amp;lt;/math&amp;gt; and a set &amp;lt;math&amp;gt;\mathcal{F}\subseteq\mathbb{R}^n&amp;lt;/math&amp;gt;, an &#039;&#039;&#039;optimization problem&#039;&#039;&#039; is the problem of finding an &amp;lt;math&amp;gt;x\in\mathcal{F}&amp;lt;/math&amp;gt; with the optimal (minimum) &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;. Formally, the problem can be expressed as:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize} &amp;amp; \quad f(x)\\&lt;br /&gt;
\mbox{subject to} &amp;amp;\quad  x\in\mathcal{F}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;x\in\mathcal{R}^n&amp;lt;/math&amp;gt; is a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. For the problem of maximizing a function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, we just minimizes &amp;lt;math&amp;gt;-f&amp;lt;/math&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
We call the function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; the &#039;&#039;&#039;objective function&#039;&#039;&#039; and call any &amp;lt;math&amp;gt;x\in\mathcal{F}&amp;lt;/math&amp;gt; a &#039;&#039;&#039;feasible solution&#039;&#039;&#039; of the problem. A feasible solution that minimizes &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;optimal solution&#039;&#039;&#039;. Our task is to find an optimal solution.&lt;br /&gt;
&lt;br /&gt;
The feasible set &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is usually given by a number of &#039;&#039;&#039;constraints&#039;&#039;&#039; &amp;lt;math&amp;gt;P_1,P_2,\ldots,P_m&amp;lt;/math&amp;gt;, which are predicates defined on &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. An &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is a feasible solution if it satisfies all the constraints. &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;linear programming (LP)&#039;&#039;&#039; problem is an optimization problem with a linear objective function subject to a number of linear constraints. Formally, an LP is a problem that can be expressed in the following form:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c_1x_1+c_2x_2+\cdots+c_nx_n\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad a_{11}x_1+a_{12}x_2+\cdots+a_{1n}x_n\le b_1\\&lt;br /&gt;
&amp;amp; \quad a_{21}x_1+a_{22}x_2+\cdots+a_{2n}x_n\le b_2\\&lt;br /&gt;
&amp;amp; \qquad\qquad \vdots\\&lt;br /&gt;
&amp;amp; \quad a_{m1}x_1+a_{m2}x_2+\cdots+a_{mn}x_n\le b_m\\&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;a_{ij}&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;c_j&amp;lt;/math&amp;gt; are constants and &amp;lt;math&amp;gt;x_j&amp;lt;/math&amp;gt; are variables. For maximization problem, or constraints given by &amp;quot;&amp;lt;math&amp;gt;\ge&amp;lt;/math&amp;gt;&amp;quot;, we can multiply  the coefficients by &amp;lt;math&amp;gt;-1&amp;lt;/math&amp;gt; and still write the LP in the above form. &lt;br /&gt;
&lt;br /&gt;
We can describe the programming in the vector form. Let &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;A=(a_{ij})&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; matrix of constant entries, &amp;lt;math&amp;gt;b=(b_1,\ldots,b_m)&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; constant entries, and &amp;lt;math&amp;gt;c=(c_1,\ldots,c_n)&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; constant entries. Then an LP is expressed as:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c^T x\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad Ax\le b&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
We call it the &#039;&#039;&#039;canonical form&#039;&#039;&#039; of linear programming.&lt;br /&gt;
&lt;br /&gt;
=== The geometry of LPs ===&lt;br /&gt;
For &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional space &amp;lt;math&amp;gt;\mathbb{R}^n&amp;lt;/math&amp;gt;, a linear constraint &amp;lt;math&amp;gt;ax\le b&amp;lt;/math&amp;gt; specifies a [http://en.wikipedia.org/wiki/Half-space halfspace]. The feasible set specified by &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; constraints together is an intersection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; halfspaces, thus, a [http://en.wikipedia.org/wiki/Convex_polytope convex polytope].&lt;br /&gt;
&lt;br /&gt;
The convex polytope is defined by &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The LP can be thought as given an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional polytope and a linear (affine) function &amp;lt;math&amp;gt;f:\mathbb{R}^n\rightarrow \mathbb{R}&amp;lt;/math&amp;gt;, looking for a point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; in the polytope with the smallest function value &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We can choose a number of constraints in the system &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, and make them hold with equality. This would define a subspace of &amp;lt;math&amp;gt;\mathbb{R}^n&amp;lt;/math&amp;gt;. In particular, if we choose &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; linearly independent constraints to form an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; submatrix &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; and the corresponding &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector &amp;lt;math&amp;gt;b&#039;&amp;lt;/math&amp;gt;, solving &amp;lt;math&amp;gt;A&#039;x=b&#039;&amp;lt;/math&amp;gt; would give us exactly one point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. If this &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is in the polytope, i.e. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; satisfies that &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, we call such &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; a &#039;&#039;&#039;vertex&#039;&#039;&#039; of the polytope &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;. In the context of LP, it is also called a &#039;&#039;&#039;basic feasible solution (&#039;&#039;bfs&#039;&#039;)&#039;&#039;&#039; of the LP.&lt;br /&gt;
&lt;br /&gt;
A key observation for LP is that there is a basic feasible solution which is optimal, i.e. the optimal solution is a vertex of the polytope.&lt;br /&gt;
&lt;br /&gt;
=== The simplex algorithms ===&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Simplex_algorithm simplex algorithm] by George Dantzig solves the linear programming by moving from vertex to vertex of the convex polytope, each time making some progress towards optimizing the objective function. Eventually the algorithm reaches a vertex which is a [http://en.wikipedia.org/wiki/Local_optimum local optimum]. In a convex set, a locally optimal point is also global optimal, thus the simplex algorithm returns an optimal solution in finite steps.&lt;br /&gt;
&lt;br /&gt;
The problem with the simplex algorithm is that in some bad polytopes, it takes the simplex algorithm exponentially many steps to reach the optimum. The simplex algorithm is actually a class of algorithms defined by various &#039;&#039;&#039;pivoting rules&#039;&#039;&#039;, which describe how to move locally from one vertex to another. The original pivoting rule proposed by Dantzig has an exponentially large worst-case time complexity (though works very good in practice). To-date, it is still unknown whether there exists any deterministic simplex algorithm with sub-exponential worst-case complexity.&lt;br /&gt;
&lt;br /&gt;
People have tried randomized pivoting rules, and there are some amazing progresses have been made:&lt;br /&gt;
* Kalai 1992: there is a randomized simplex algorithm with sub-exponential time complexity.&lt;br /&gt;
* Kelner-Spielman 2006: there is a polynomial time randomized simplex algorithm.&lt;br /&gt;
&lt;br /&gt;
Although we do not know whether there exists deterministic poly-time simplex algorithm, we do know that LP can be solved by deterministic poly-time algorithms, i.e. LP is in &#039;&#039;&#039;P&#039;&#039;&#039;. The following two algorithms use different ideas than the simplex algorithm, and are both in poly-time:&lt;br /&gt;
* The ellipsoid algorithm.&lt;br /&gt;
* Interior point methods.&lt;br /&gt;
Although these algorithms guarantee polynomial time complexity in the worst-case, their performances are worse than the simplex algorithms. However, the ideas of these algorithms can be used to solve more general mathematical programmings, such as [http://en.wikipedia.org/wiki/Convex_programming convex programmings].&lt;br /&gt;
&lt;br /&gt;
=== An LP solver via random walks ===&lt;br /&gt;
We discuss a new algorithm for solving LP which is based on random sampling, introduced by Bertsimas and Vempala in 2004. &lt;br /&gt;
&lt;br /&gt;
The problem of solving an LP can be reduced to that given a convex polytope &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, test whether the polytope is empty. We call this problem the &amp;quot;&#039;&#039;feasibility test&#039;&#039;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Suppose we have an LP:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c^T x\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad Ax\le b&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
To see this LP can be solved by feasibility testing, we treat the &amp;lt;math&amp;gt;c^Tx\le d&amp;lt;/math&amp;gt; for some parameter &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; as an additional constraint, and define a new polytope &amp;lt;math&amp;gt;A&#039;x\le b&#039;&amp;lt;/math&amp;gt;. The smallest &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; that the polytope &amp;lt;math&amp;gt;A&#039;x\le b&#039;&amp;lt;/math&amp;gt; is not empty is the optimal solution to the original LP. We can find this smallest &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; by binary search if we can efficiently test the emptiness of a convex polytope.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We assume that the convex polytope &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is contained in the axis-aligned cube of width &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; centered at the origin; further if &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is non-empty then it contains a cube of width &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;. The parameter &amp;lt;math&amp;gt;L&amp;lt;/math&amp;gt; is equal to &amp;lt;math&amp;gt;\log\frac{R}{r}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Algorithm&#039;&#039;&#039;: feasibility test &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Input&#039;&#039;&#039;: an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional convex polytope &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; defined by the system &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;: a point &amp;lt;math&amp;gt;x\in P&amp;lt;/math&amp;gt; in the polytope, or a guarantee that &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is empty.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; be the axis-aligned cube of side length &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; and center &amp;lt;math&amp;gt;z=\boldsymbol{0}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Repeat for &amp;lt;math&amp;gt;2nL&amp;lt;/math&amp;gt; times do:&lt;br /&gt;
:: If &amp;lt;math&amp;gt;Az\le b&amp;lt;/math&amp;gt;, return &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: Pick a constraint violated by &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;, say that &amp;lt;math&amp;gt;A_i z&amp;gt;b_i&amp;lt;/math&amp;gt;, and define the halfspace&lt;br /&gt;
:::&amp;lt;math&amp;gt;H=\{x\mid A_i x\le A_i z\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
::Set &amp;lt;math&amp;gt;K=K\cap H&amp;lt;/math&amp;gt;. Uniformly sample &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; random points &amp;lt;math&amp;gt;y^{(1)},y^{(2)},\ldots,y^{(N)}&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and let &lt;br /&gt;
:::&amp;lt;math&amp;gt;z=\frac{1}{N}\sum_{i=1}^Ny^{(i)}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Report &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is empty.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The number of samples required in each iteration, &amp;lt;math&amp;gt;N=O((\log m)^2)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is the number of linear constraints. &lt;br /&gt;
&lt;br /&gt;
It is easy to see that at any iteration, &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is a convex set, and &amp;lt;math&amp;gt;P\subseteq K&amp;lt;/math&amp;gt; for the current convex set &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The idea of the algorithm is based on computing the [http://en.wikipedia.org/wiki/Centroid centroid] of the convex set.  It is know that if we could compute the exact centroid in each iteration, then the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; drops by a constant factor &amp;lt;math&amp;gt;(1-1/e)&amp;lt;/math&amp;gt; in each iteration, thus reaches the smallest possible volume of a cube of width &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; within polynomial number of iterations. But, finding the centroid of a convex polytope, is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The idea behind the algorithm is that an approximate centroid can be computed using &amp;lt;math&amp;gt;N=O((\log m)^2)&amp;lt;/math&amp;gt; random points and the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is drops by a constant factor with high probability in each iteration with this choice of &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
The uniform sampling in &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is not easy. But since &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is also a convex polytope, we can approximate the uniform sampling by  near-uniform sampling from &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; by rapid mixing random walks. The random walks used here are similar to the ones used in the volume estimation of convex bodies. We could use the basic grid walk, or more advanced ball walk, or hit-and-run walk.&lt;br /&gt;
&lt;br /&gt;
With rapid mixing random walks, the resulting LP solver runs in poly-time.&lt;br /&gt;
&lt;br /&gt;
The details are omitted. You may check the following paper if interested:&lt;br /&gt;
* Bertsimas and Vempala, “&#039;&#039;Solving convex programs by random walks&#039;&#039;.” JACM 2004.&lt;/div&gt;</summary>
		<author><name>172.21.4.18</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2471</id>
		<title>Randomized Algorithms (Spring 2010)/Approximate counting, linear programming</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2471"/>
		<updated>2010-05-24T18:56:18Z</updated>

		<summary type="html">&lt;p&gt;172.21.4.18: /* Complexity model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Complexity model ===&lt;br /&gt;
Recall the class &#039;&#039;&#039;NP&#039;&#039;&#039; of decision problems (the problems with &amp;quot;yes&amp;quot; or &amp;quot;no&amp;quot; answers). Formally, denoting by &amp;lt;math&amp;gt;\{0,1\}^*&amp;lt;/math&amp;gt; the set of all boolean strings of any lengths, a decision problem is a function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\{0,1\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (NP)&#039;&#039;&#039;&lt;br /&gt;
:A function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\{0,1\}&amp;lt;/math&amp;gt; is in &#039;&#039;&#039;NP&#039;&#039;&#039; if there exist a polynomial &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and a poly-time algorithm &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; with boolean output such that for every &amp;lt;math&amp;gt;x\in\{0,1\}^*&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;f(x)=1 \Leftrightarrow \exists y\in\{0,1\}^{p(|x|)}, \mbox{such that } V(x,y)=1\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
Intuitively, the &#039;&#039;&#039;NP&#039;&#039;&#039; class contains all the decision problems such that the answer is &amp;quot;yes&amp;quot; if and only if there &#039;&#039;exists&#039;&#039; a &#039;&#039;&#039;certificate&#039;&#039;&#039; which can be verified in poly-time.&lt;br /&gt;
&lt;br /&gt;
In many contexts, we are interested not just in the &#039;&#039;existence&#039;&#039; of certificate but actually in counting the &#039;&#039;number&#039;&#039; of certificates. This leads to the definition of the class &#039;&#039;&#039;#P&#039;&#039;&#039; (pronounced &amp;quot;sharp p&amp;quot;). Only now the output of the function is a natural number.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (#P)&#039;&#039;&#039;&lt;br /&gt;
:A function &amp;lt;math&amp;gt;f:\{0,1\}^*\rightarrow\mathbb{N}&amp;lt;/math&amp;gt; is in &#039;&#039;&#039;#P&#039;&#039;&#039; if there exist a polynomial &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; and a poly-time algorithm &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; with boolean output such that for every &amp;lt;math&amp;gt;x\in\{0,1\}^*&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;f(x)=\left|\left\{y\in\{0,1\}^{p(|x|)}\mid A(x,y)=1\right\}\right|&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
You may notice the similarity between the two definitions. The difference is that now &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt; does not just indicates the existence of a certificate, but gives the actual number of certificates.&lt;br /&gt;
&lt;br /&gt;
;Examples&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;cycles: given as input a graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, count the number of cycles in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;SAT: given as input a boolean formula &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;, count the number of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== FPRAS ===&lt;br /&gt;
&lt;br /&gt;
== Approximate Counting ==&lt;br /&gt;
Let us consider the following abstract problem.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be a finite set of known size, and let &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt;. We want to compute the size of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, namely &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We assume two devices:&lt;br /&gt;
* A &#039;&#039;&#039;uniform sampler&#039;&#039;&#039; &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;, which uniformly and independently samples a member of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; upon each calling.&lt;br /&gt;
* A &#039;&#039;&#039;membership oracle&#039;&#039;&#039; of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, denoted &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;. Given as the input an &amp;lt;math&amp;gt;x\in U&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{O}(x)&amp;lt;/math&amp;gt; indicates whether or not &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is a member of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Equipped by &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt; and  &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;, we can have the following Monte Carlo algorithm:&lt;br /&gt;
*Choose &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; independent samples from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; by the uniform sampler &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;, represented by the random variables &amp;lt;math&amp;gt;X_1,X_2,\ldots, X_N&amp;lt;/math&amp;gt;. &lt;br /&gt;
* Let &amp;lt;math&amp;gt;Y_i&amp;lt;/math&amp;gt; be the indicator random variable defined as &amp;lt;math&amp;gt;Y_i=\mathcal{O}(X_i)&amp;lt;/math&amp;gt;, namely, &amp;lt;math&amp;gt;Y_i&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;X_i\in G&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Define the estimator random variable&lt;br /&gt;
::&amp;lt;math&amp;gt;Z=\frac{|U|}{N}\sum_{i=1}^N Y_i.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is easy to see that &amp;lt;math&amp;gt;\mathbf{E}[Z]=|G|&amp;lt;/math&amp;gt; and we might hope that with high probability the value of &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt; is close to &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt;. Formally, &amp;lt;math&amp;gt;Z&amp;lt;/math&amp;gt; is called an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation of &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; if&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
(1-\epsilon)|G|\le Z\le (1+\epsilon)|G|.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following theorem states that the probabilistic accuracy of the estimation depends on the number of samples and the ratio between &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|U|&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Theorem (estimator theorem)&#039;&#039;&#039;&lt;br /&gt;
:Let &amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;. Then the Monte Carlo method yields an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation to &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; with probability at least &amp;lt;math&amp;gt;1-\delta&amp;lt;/math&amp;gt; provided&lt;br /&gt;
::&amp;lt;math&amp;gt;N\ge\frac{4}{\epsilon \alpha}\ln\frac{2}{\delta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;Proof&#039;&#039;&#039;: Use the Chernoff bound.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\square&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A counting algorithm for the set &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has to deal with the following three complications:&lt;br /&gt;
* Implement the membership oracle &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;. This is usually straightforward, or assumed by the model.&lt;br /&gt;
* Implement the uniform sampler &amp;lt;math&amp;gt;\mathcal{U}&amp;lt;/math&amp;gt;. As we have seen, this is usually approximated by random walks. How to design the random walk and bound its mixing rate is usually technical challenging, if possible at all.&lt;br /&gt;
* Deal with exponentially small &amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;. This requires us to cleverly choose the universe &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. Sometimes this needs some nontrivial ideas.&lt;br /&gt;
&lt;br /&gt;
=== Counting DNFs ===&lt;br /&gt;
A disjunctive normal form (DNF) formular is a disjunction (OR) of clauses, where each clause is a conjunction (AND) of literals. For example:&lt;br /&gt;
:&amp;lt;math&amp;gt;(x_1\wedge \overline{x_2}\wedge x_3)\vee(x_2\wedge x_4)\vee(\overline{x_1}\wedge x_3\wedge x_4)&amp;lt;/math&amp;gt;.&lt;br /&gt;
Note the difference from the conjunctive normal forms (CNF).&lt;br /&gt;
&lt;br /&gt;
Given a DNF formular &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; as the input, the problem is to count the number of satisfying assignments of &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. This problem is &#039;&#039;&#039;#P-complete&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Naively applying the Monte Carlo method will not give a good answer. Suppose that there are &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;U=\{\mathrm{true},\mathrm{false}\}^n&amp;lt;/math&amp;gt; be the set of all truth assignments of the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;G=\{x\in U\mid \phi(x)=\mathrm{true}\}&amp;lt;/math&amp;gt; be the set of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. The straightforward use of Monte Carlo method samples &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; assignments from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and check how many of them satisfy &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. This algorithm fails when &amp;lt;math&amp;gt;|G|/|U|&amp;lt;/math&amp;gt; is exponentially small, namely, when exponentially small fraction of the assignments satisfy the input DNF formula. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;The union of sets problem&lt;br /&gt;
We reformulate the DNF counting problem in a more abstract framework, called the &#039;&#039;&#039;union of sets&#039;&#039;&#039; problem. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; be a finite universe. We are given &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; subsets &amp;lt;math&amp;gt;H_1,H_2,\ldots,H_m\subseteq V&amp;lt;/math&amp;gt;. The following assumptions hold:&lt;br /&gt;
*For all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;|H_i|&amp;lt;/math&amp;gt; is computable in poly-time.&lt;br /&gt;
*It is possible to sample uniformly from each individual &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
*For any &amp;lt;math&amp;gt;x\in V&amp;lt;/math&amp;gt;, it can be determined in poly-time whether &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The goal is to compute the size of &amp;lt;math&amp;gt;H=\bigcup_{i=1}^m H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
DNF counting can be interpreted in this general framework as follows. Suppose that the DNF formula &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is defined on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables, and &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; contains &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; clauses &amp;lt;math&amp;gt;C_1,C_2,\ldots,C_m&amp;lt;/math&amp;gt;, where clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; has &amp;lt;math&amp;gt;k_i&amp;lt;/math&amp;gt; literals. Without loss of generality, we assume that in each clause, each variable appears at most once.&lt;br /&gt;
* &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; is the set of all assignments.&lt;br /&gt;
*Each &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is the set of satisfying assignments for the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;-th clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; of the DNF formular &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;. Then the union of sets &amp;lt;math&amp;gt;H=\bigcup_i H_i&amp;lt;/math&amp;gt; gives the set of satisfying assignments for &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Each clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt; is a conjunction (AND) of literals. It is not hard to see that &amp;lt;math&amp;gt;|H_i|=2^{n-k_i}&amp;lt;/math&amp;gt;, which is efficiently computable.&lt;br /&gt;
* Sampling from an &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is simple: we just fix the assignments of the &amp;lt;math&amp;gt;k_i&amp;lt;/math&amp;gt; literals of that clause, and sample uniformly and independently the rest &amp;lt;math&amp;gt;(n-k_i)&amp;lt;/math&amp;gt; variable assignments.&lt;br /&gt;
* For each assignment &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, it is easy to check whether it satisfies a clause &amp;lt;math&amp;gt;C_i&amp;lt;/math&amp;gt;, thus it is easy to determine whether &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
;The coverage algorithm&lt;br /&gt;
We now introduce the coverage algorithm for the union of sets problem.&lt;br /&gt;
&lt;br /&gt;
Consider the multiset &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; defined by&lt;br /&gt;
:&amp;lt;math&amp;gt;U=H_1\uplus H_2\uplus\cdots \uplus H_m&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\uplus&amp;lt;/math&amp;gt; denotes the multiset union. It is more convenient to define &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; as the set&lt;br /&gt;
:&amp;lt;math&amp;gt;U=\{(x,i)\mid x\in H_i\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
For each &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt;, there may be more than one instances of &amp;lt;math&amp;gt;(x,i)\in U&amp;lt;/math&amp;gt;. We can choose a unique representative among the multiple instances &amp;lt;math&amp;gt;(x,i)\in U&amp;lt;/math&amp;gt; for the same &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt;, by choosing the &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt; with the minimum &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;, and form a set &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, &amp;lt;math&amp;gt;G=\{(x,i)\in U\mid \forall (x,j)\in U, j\le i\}&amp;lt;/math&amp;gt;. Every &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt; corresponds to a unique &amp;lt;math&amp;gt;(x,i)\in G&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is the smallest among &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is obvious that &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt; and&lt;br /&gt;
:&amp;lt;math&amp;gt;|G|=|H|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Therefore, estimation of &amp;lt;math&amp;gt;|H|&amp;lt;/math&amp;gt; is reduced to estimation of &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;G\subseteq U&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;|G|&amp;lt;/math&amp;gt; can have an &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt;-approximation with probability &amp;lt;math&amp;gt;(1-\delta)&amp;lt;/math&amp;gt; in poly-time, if we can uniformly sample from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;|G|/|U|&amp;lt;/math&amp;gt; is suitably small.&lt;br /&gt;
&lt;br /&gt;
An uniform sample from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; can be implemented as follows:&lt;br /&gt;
* generate an &amp;lt;math&amp;gt;i\in\{1,2,\ldots,m\}&amp;lt;/math&amp;gt; with probability &amp;lt;math&amp;gt;\frac{|H_i|}{\sum_{i=1}^m|H_i|}&amp;lt;/math&amp;gt;;&lt;br /&gt;
* uniformly sample an &amp;lt;math&amp;gt;x\in H_i&amp;lt;/math&amp;gt;, and return &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is easy to see that this gives a uniform member of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;. The above sampling procedure is poly-time because each &amp;lt;math&amp;gt;|H_i|&amp;lt;/math&amp;gt; can be computed in poly-time, and sampling uniformly from each &amp;lt;math&amp;gt;H_i&amp;lt;/math&amp;gt; is poly-time.&lt;br /&gt;
&lt;br /&gt;
We now only need to lower bound the ratio&lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha=\frac{|G|}{|U|}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We claim that &lt;br /&gt;
:&amp;lt;math&amp;gt;\alpha\ge\frac{1}{m}&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is easy to see this, because each &amp;lt;math&amp;gt;x\in H&amp;lt;/math&amp;gt; has at most &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; instances of &amp;lt;math&amp;gt;(x,i)&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;, and we already know that &amp;lt;math&amp;gt;|G|=|H|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Due to the estimator theorem, this needs &amp;lt;math&amp;gt;\frac{4m}{\epsilon}\ln\frac{2}{\delta}&amp;lt;/math&amp;gt; uniform random samples from &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This gives the coverage algorithm for the abstract problem of the union of sets. The DNF counting is a special case of it.&lt;br /&gt;
&lt;br /&gt;
=== Permanents and perfect matchings ===&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;U=\{u_1,u_2,\ldots,u_n\}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;V=\{v_1,v_2,\ldots,v_n\}&amp;lt;/math&amp;gt;. Consider a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt;. An &amp;lt;math&amp;gt;M\subseteq E&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;perfect matching&#039;&#039;&#039; of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; if every vertex of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt; has exactly one edge in &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; adjacent to it.&lt;br /&gt;
&lt;br /&gt;
Given a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt;, we want to count the number of perfect matchings of &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. This problem can be reduced to computing the &#039;&#039;&#039;permanent&#039;&#039;&#039; of a square matrix.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition (permanent)&#039;&#039;&#039;&lt;br /&gt;
:Let &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix. The &#039;&#039;&#039;permanent&#039;&#039;&#039; of the matrix is defined as&lt;br /&gt;
::&amp;lt;math&amp;gt;\mathrm{per}(Q)=\sum_{\pi\in\mathbb{S}_n}\prod_{i=1}^n Q_{i,\pi(i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
:where &amp;lt;math&amp;gt;\mathbb{S}_n&amp;lt;/math&amp;gt; is the symmetric group of permutation of size &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If we multiply each term of the sum the sign of the permutation, then it gives us the determinant of the matrix, &lt;br /&gt;
:&amp;lt;math&amp;gt;\det(Q)=\sum_{\pi\in\mathbb{S}_n}\sgn(\pi)\prod_{i=1}^n Q_{i,\pi(i)}&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\sgn(\pi)&amp;lt;/math&amp;gt;, the sign of a permutation, is either &amp;lt;math&amp;gt;-1&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;+1&amp;lt;/math&amp;gt;, according to whether the minimum number of pair-wise interchanges to achieve &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;(1,2,\ldots,n)&amp;lt;/math&amp;gt; is odd or even.&lt;br /&gt;
&lt;br /&gt;
Unlike the determinants, which are computable in poly-time, permanents are hard to compute, as permanents can be used to count the number of perfect matchings in a bipartite graph, which is &#039;&#039;&#039;#P-complete&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt; can be represented by an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; matrix &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; with 0-1 entries as follows:&lt;br /&gt;
* Each row of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; corresponds to a vertex in &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and each column of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; corresponds to a vertex in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;.&lt;br /&gt;
::&amp;lt;math&amp;gt;Q_{ij}=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }i\sim j,\\&lt;br /&gt;
0 &amp;amp; \mbox{otherwise}.&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
Note the subtle difference between the definition of &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt; and the adjacency matrix. &lt;br /&gt;
&lt;br /&gt;
Each perfect matching corresponds to a permutation &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;(u,\pi(u))\in E&amp;lt;/math&amp;gt; for every &amp;lt;math&amp;gt;u\in U&amp;lt;/math&amp;gt;, which corresponds to a permutation &amp;lt;math&amp;gt;\pi\in\mathbb{S}_n&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;\prod_{i=1}^n Q_{i,\pi(i)}=1&amp;lt;/math&amp;gt;. It is than easy to see that &amp;lt;math&amp;gt;\mathrm{per}(Q)&amp;lt;/math&amp;gt; gives the number of perfect matchings in the bipartite graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
It is known that counting the number of perfect matchings in a bipartite graph is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. Since this problem can be reduced to computing the permanent, thus the problem of computing the permanents is also &#039;&#039;&#039;#P-hard&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Now we show that with randomization, we can approximate the number of perfect matchings in a bipartite graph. In particular, we will give an FPRAS for counting the perfect matchings in a dense bipartite graph.&lt;br /&gt;
&lt;br /&gt;
==== The Jerrum-Sinclair algorithm ====&lt;br /&gt;
Fix a bipartite graph &amp;lt;math&amp;gt;G(U,V,E)&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|U|=|V|=n&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;\mathcal{M}_k&amp;lt;/math&amp;gt; be the set of matchings of size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and let &amp;lt;math&amp;gt;m_k=|\mathcal{M}_k|&amp;lt;/math&amp;gt;. Thus, &amp;lt;math&amp;gt;\mathcal{M}_k&amp;lt;/math&amp;gt; is the set of perfect matchings in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, and our goal is to compute &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;r_k=\frac{m_k}{m_{k-1}}&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;m_k=m_{k-1}r_k&amp;lt;/math&amp;gt;,&lt;br /&gt;
which gives us a recursion to compute the &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt;, as&lt;br /&gt;
:&amp;lt;math&amp;gt;m_n=m_{1}\frac{m_2}{m_1}\cdot\frac{m_3}{m_2}\cdots\frac{m_n}{m_{n-1}}=m_1\prod_{k=2}^n r_k&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;m_1=|\mathcal{M}_1|&amp;lt;/math&amp;gt; is the number of matchings of size 1 in the bipartite graph &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;, which is just the number of edges in &amp;lt;math&amp;gt;G&amp;lt;/math&amp;gt;. Therefore, &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; can be computed once we know &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; can be estimated by sampling uniformly from the set &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;. The algorithm for estimating &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; is outlined as:&lt;br /&gt;
# For each &amp;lt;math&amp;gt;1&amp;lt;k\le n&amp;lt;/math&amp;gt;, have an FPRAS for computing the &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; by uniform sampling sufficiently many members from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt; as&lt;br /&gt;
::*uniformly sample &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; matching from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;, for some polynomially large &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;;&lt;br /&gt;
::* assuming that there are &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; sampled matchings of size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, return &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; as &amp;lt;math&amp;gt;r_k=\frac{X}{N-X}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:2.  Compute &amp;lt;math&amp;gt;m_n&amp;lt;/math&amp;gt; as &amp;lt;math&amp;gt;m_n=m_1\prod_{k=2}^n r_k&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;m_1=|E|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
There are several issues that we have to deal with in order to have a fully functional FPRAS for counting perfect matchings.&lt;br /&gt;
* By taking the product of &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&#039;s, the errors for individual &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&#039;s add up.&lt;br /&gt;
* In order to accurately estimate &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; by sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;, the ratio &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt; should be within the range &amp;lt;math&amp;gt;\left[\frac{1}{\alpha},\alpha\right]&amp;lt;/math&amp;gt; for some &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; within polynomial of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Implement the uniform sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
;Estimator for each &amp;lt;math&amp;gt;r_k&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Accumulation of errors&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
; Near-uniform sampling from &amp;lt;math&amp;gt;\mathcal{M}_k\cup\mathcal{M}_{k-1}&amp;lt;/math&amp;gt;&lt;br /&gt;
In the last lecture, we have shown that by random walk, we can sample a near-uniform member of &amp;lt;math&amp;gt;\mathcal{M}_n\cup\mathcal{M}_{n-1}&amp;lt;/math&amp;gt; in poly-time.&lt;br /&gt;
&lt;br /&gt;
=== Volume estimation  ===&lt;br /&gt;
We consider the problem of computing the volume of a given [http://en.wikipedia.org/wiki/Convex_body convex body] &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions. &lt;br /&gt;
&lt;br /&gt;
We use &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; to denote the volume of the convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;. Abstractly, the problem is that given as input a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, return the &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We should be more specific about the input model. Since we allow an arbitrary convex body as input, it is not even clear how to describe the body. We assume that &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is described by means of a &#039;&#039;&#039;membership oracle&#039;&#039;&#039; &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt;, such that  for a &#039;&#039;&#039;query&#039;&#039;&#039; of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;\mathcal{O}(x)&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;x\in K&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For example, the &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional convex body defined by the intersection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; half-spaces, which is the set of feasible solutions to a system of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; linear constraints, can be described as&lt;br /&gt;
:&amp;lt;math&amp;gt;A x\le \boldsymbol{b}&amp;lt;/math&amp;gt;,&lt;br /&gt;
for some &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; matrix &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector &amp;lt;math&amp;gt;b&amp;lt;/math&amp;gt;. For a query of an &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, the membership oracle &amp;lt;math&amp;gt;\mathcal{O}&amp;lt;/math&amp;gt; just check whether &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For deterministic algorithms, there are negative news for this problem.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Theorem (Bárány-Füredi 1987)&#039;&#039;&#039;&lt;br /&gt;
:Suppose that a deterministic poly-time algorithm uses the membership oracle for a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, and generates an upper bound &amp;lt;math&amp;gt;\Upsilon_u\,&amp;lt;/math&amp;gt; and a lower bound &amp;lt;math&amp;gt;\Upsilon_\ell\,&amp;lt;/math&amp;gt; on the volume &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;. Then, there is a convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and a constant &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; such that&lt;br /&gt;
::&amp;lt;math&amp;gt;\frac{\Upsilon_u}{\Upsilon_\ell}\ge c\left(\frac{n}{\log n}\right)^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
That is said, with deterministic algorithms, we cannot even approximate the volume within a wildly loose range.&lt;br /&gt;
&lt;br /&gt;
Dyer-Frieze-Kannan come up with an idea of estimating the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; by sampling near-uniformly from convex sets. They reduce the problem of computing approximately the volume of convex bodies to this sampling problem and thus give the first FPRAS for the volume of convex bodies.&lt;br /&gt;
&lt;br /&gt;
For any convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, it encloses some &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional ball and is also enclosed by another ball with larger radius. We assume that the convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; encloses the unit ball around the origin, and is enclosed by a larger ball round the origin with polynomially large radius. Formally, we assume that&lt;br /&gt;
:&amp;lt;math&amp;gt;B(0,1)\subseteq K\subseteq B(0,n^c)&amp;lt;/math&amp;gt; for some constant &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;B(p,r)&amp;lt;/math&amp;gt; denotes a ball of radius &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; as center, i.e. &amp;lt;math&amp;gt;B(p,r)=\{x\mid \|x-p\|\le r \}&amp;lt;/math&amp;gt;. We can make this assumption because it is known that for any convex body &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, there exists a linear transformation &amp;lt;math&amp;gt;\tau&amp;lt;/math&amp;gt; which can be found within poly-time such that &amp;lt;math&amp;gt;\tau K&amp;lt;/math&amp;gt; transforms the &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; to a convex body that satisfies the assumption, and preserves the ratio of the volumes of the balls to the convex body.&lt;br /&gt;
&lt;br /&gt;
The volumes of the balls are easy to compute. If only the ratio between the convex body and the ball which encloses it, is sufficiently large, then we can apply the Monte Carlo method to estimate &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; by uniformly sampling from the ball.&lt;br /&gt;
&lt;br /&gt;
However, in high-dimension, the ratio between the volume of a convex body and the volume of ball which encloses it, can be exponentially small. This is caused by the so called the &amp;quot;[http://en.wikipedia.org/wiki/Curse_of_dimensionality curse of dimensionality]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Instead of having an outer ball and an inner ball, we define a sequence of balls:&lt;br /&gt;
:&amp;lt;math&amp;gt;B_0=B(0,\lambda^0), B_1=B(0,\lambda^1), B_2=B(0,\lambda^2),\ldots, B_m=B(0,\lambda^m)&amp;lt;/math&amp;gt;,&lt;br /&gt;
where &amp;lt;math&amp;gt;\lambda=(1+\frac{1}{n})&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is the smallest positive integer such that &amp;lt;math&amp;gt;\lambda^m\ge n^c&amp;lt;/math&amp;gt;. Therefore, the inner ball &amp;lt;math&amp;gt;B(0,1)=B_0&amp;lt;/math&amp;gt;, the outer ball &amp;lt;math&amp;gt;B(0,n^c)\subseteq B_m&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is within polynomial of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. In fact, &amp;lt;math&amp;gt;m\approx cn\ln n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This sequence of balls naturally defines a sequence of convex bodies by intersections as &amp;lt;math&amp;gt;K_i=B_i\cap K&amp;lt;/math&amp;gt;. It is obvious that&lt;br /&gt;
:&amp;lt;math&amp;gt;B(0,1)=K_0\subseteq K_1\subseteq K_2\subseteq\cdots\subseteq K_m=K&amp;lt;/math&amp;gt;.&lt;br /&gt;
Balls are convex, and since the intersection of convex bodies is still convex, the sequence of &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt; is a sequence of convex bodies.&lt;br /&gt;
&lt;br /&gt;
We have the telescopic product:&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\frac{\Upsilon(K_0)}{\Upsilon(K_1)}\cdot\frac{\Upsilon(K_1)}{\Upsilon(K_2)}\cdots\frac{\Upsilon(K_{m-1})}{\Upsilon(K_m)}=\frac{\Upsilon(K_0)}{\Upsilon(K_m)}=\frac{\Upsilon(B(0,1))}{\Upsilon(K)}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Therefore, the volume &amp;lt;math&amp;gt;\Upsilon(K)\,&amp;lt;/math&amp;gt; can be computed as &lt;br /&gt;
:&amp;lt;math&amp;gt;\Upsilon(K)=\Upsilon(B(0,1))\cdot\prod_{i=1}^{m}\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The volume of unite ball &amp;lt;math&amp;gt;\Upsilon(B(0,1))\,&amp;lt;/math&amp;gt; can be precisely computed in poly-time. Each &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is computed by near-uniform sampling from &amp;lt;math&amp;gt;K_{i}&amp;lt;/math&amp;gt;, which encloses &amp;lt;math&amp;gt;K_{i-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Another observation is that the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is well-bounded. Recall that &amp;lt;math&amp;gt;K_i=B(0,\lambda^i)\cap K&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;\lambda=(1+\frac{1}{n})&amp;lt;/math&amp;gt;. It can be proved that in &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; dimensions, the volume of &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt; is at most &amp;lt;math&amp;gt;\lambda^n&amp;lt;/math&amp;gt; times the &amp;lt;math&amp;gt;K_{i-1}&amp;lt;/math&amp;gt;, thus the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; is at most &amp;lt;math&amp;gt;\lambda^n=O(1)&amp;lt;/math&amp;gt;. By the estimator theorem, we can have an FPRAS for the ratio &amp;lt;math&amp;gt;\frac{\Upsilon(K_{i})}{\Upsilon(K_{i-1})}&amp;lt;/math&amp;gt; if we can uniformly sample from &amp;lt;math&amp;gt;K_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Uniformly sampling from an arbitrary convex body is replaced by near-uniform sampling achieved by random walks. In the original walk of Dyer-Frieze-Kannan, they consider the random walk over &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional discrete grid points enclosed by &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;, and prove that the walk is rapid mixing. This gives us the first FPRAS for volume estimation which runs in &amp;lt;math&amp;gt;\tilde{O}(n^{23})&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;\tilde{O}(\cdot)&amp;lt;/math&amp;gt; ignores the polylogarithmic factors.&lt;br /&gt;
&lt;br /&gt;
The time bound was later improved by a series of works, each introducing some new ideas.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
| || complexity || new ingredient(s)&lt;br /&gt;
|-&lt;br /&gt;
| Dyer-Frieze-Kannan 1991 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{23}&amp;lt;/math&amp;gt; || everything&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Simonovits 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{16}&amp;lt;/math&amp;gt; || localization lemma&lt;br /&gt;
|-&lt;br /&gt;
| Applegate-Kannan 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{10}&amp;lt;/math&amp;gt; || logconcave sampling&lt;br /&gt;
|-&lt;br /&gt;
| Lovász 1990 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^{10}&amp;lt;/math&amp;gt; || ball walk&lt;br /&gt;
|-&lt;br /&gt;
| Dyer-Frieze 1991 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^8&amp;lt;/math&amp;gt; || better error analysis&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Simonovits 1993 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^7&amp;lt;/math&amp;gt; || many improvements&lt;br /&gt;
|-&lt;br /&gt;
| Kannan-Lovász-Simonovits 1997 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^5&amp;lt;/math&amp;gt; || isotropy, speedy walk&lt;br /&gt;
|-&lt;br /&gt;
| Lovász-Vempala 2003 || align=&amp;quot;center&amp;quot; | &amp;lt;math&amp;gt;n^4&amp;lt;/math&amp;gt; || simulated annealing, hit-and-run&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
(cited from &amp;quot;Geometric Random Walks: A Survey&amp;quot; by Santosh Vempala.)&lt;br /&gt;
&lt;br /&gt;
The current best upper bound is &amp;lt;math&amp;gt;\tilde{O}(n^4)&amp;lt;/math&amp;gt; due to Lovász and Vempala in 2003. It is conjectured that the optimal bound is &amp;lt;math&amp;gt;\Theta(n^3)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Linear Programming ==&lt;br /&gt;
Given a function &amp;lt;math&amp;gt;f:\mathbb{R}^n\rightarrow\mathbb{R}&amp;lt;/math&amp;gt; and a set &amp;lt;math&amp;gt;\mathcal{F}\subseteq\mathbb{R}^n&amp;lt;/math&amp;gt;, an &#039;&#039;&#039;optimization problem&#039;&#039;&#039; is the problem of finding an &amp;lt;math&amp;gt;x\in\mathcal{F}&amp;lt;/math&amp;gt; with the optimal (minimum) &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;. Formally, the problem can be expressed as:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize} &amp;amp; \quad f(x)\\&lt;br /&gt;
\mbox{subject to} &amp;amp;\quad  x\in\mathcal{F}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;x\in\mathcal{R}^n&amp;lt;/math&amp;gt; is a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. For the problem of maximizing a function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt;, we just minimizes &amp;lt;math&amp;gt;-f&amp;lt;/math&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
We call the function &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; the &#039;&#039;&#039;objective function&#039;&#039;&#039; and call any &amp;lt;math&amp;gt;x\in\mathcal{F}&amp;lt;/math&amp;gt; a &#039;&#039;&#039;feasible solution&#039;&#039;&#039; of the problem. A feasible solution that minimizes &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt; is called an &#039;&#039;&#039;optimal solution&#039;&#039;&#039;. Our task is to find an optimal solution.&lt;br /&gt;
&lt;br /&gt;
The feasible set &amp;lt;math&amp;gt;\mathcal{F}&amp;lt;/math&amp;gt; is usually given by a number of &#039;&#039;&#039;constraints&#039;&#039;&#039; &amp;lt;math&amp;gt;P_1,P_2,\ldots,P_m&amp;lt;/math&amp;gt;, which are predicates defined on &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. An &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is a feasible solution if it satisfies all the constraints. &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;linear programming (LP)&#039;&#039;&#039; problem is an optimization problem with a linear objective function subject to a number of linear constraints. Formally, an LP is a problem that can be expressed in the following form:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c_1x_1+c_2x_2+\cdots+c_nx_n\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad a_{11}x_1+a_{12}x_2+\cdots+a_{1n}x_n\le b_1\\&lt;br /&gt;
&amp;amp; \quad a_{21}x_1+a_{22}x_2+\cdots+a_{2n}x_n\le b_2\\&lt;br /&gt;
&amp;amp; \qquad\qquad \vdots\\&lt;br /&gt;
&amp;amp; \quad a_{m1}x_1+a_{m2}x_2+\cdots+a_{mn}x_n\le b_m\\&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
where &amp;lt;math&amp;gt;a_{ij}&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;b_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;c_j&amp;lt;/math&amp;gt; are constants and &amp;lt;math&amp;gt;x_j&amp;lt;/math&amp;gt; are variables. For maximization problem, or constraints given by &amp;quot;&amp;lt;math&amp;gt;\ge&amp;lt;/math&amp;gt;&amp;quot;, we can multiply  the coefficients by &amp;lt;math&amp;gt;-1&amp;lt;/math&amp;gt; and still write the LP in the above form. &lt;br /&gt;
&lt;br /&gt;
We can describe the programming in the vector form. Let &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; variables. Let &amp;lt;math&amp;gt;A=(a_{ij})&amp;lt;/math&amp;gt; be an &amp;lt;math&amp;gt;m\times n&amp;lt;/math&amp;gt; matrix of constant entries, &amp;lt;math&amp;gt;b=(b_1,\ldots,b_m)&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; constant entries, and &amp;lt;math&amp;gt;c=(c_1,\ldots,c_n)&amp;lt;/math&amp;gt; be a vector of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; constant entries. Then an LP is expressed as:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c^T x\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad Ax\le b&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
We call it the &#039;&#039;&#039;canonical form&#039;&#039;&#039; of linear programming.&lt;br /&gt;
&lt;br /&gt;
=== The geometry of LPs ===&lt;br /&gt;
For &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional space &amp;lt;math&amp;gt;\mathbb{R}^n&amp;lt;/math&amp;gt;, a linear constraint &amp;lt;math&amp;gt;ax\le b&amp;lt;/math&amp;gt; specifies a [http://en.wikipedia.org/wiki/Half-space halfspace]. The feasible set specified by &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; constraints together is an intersection of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; halfspaces, thus, a [http://en.wikipedia.org/wiki/Convex_polytope convex polytope].&lt;br /&gt;
&lt;br /&gt;
The convex polytope is defined by &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The LP can be thought as given an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional polytope and a linear (affine) function &amp;lt;math&amp;gt;f:\mathbb{R}^n\rightarrow \mathbb{R}&amp;lt;/math&amp;gt;, looking for a point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; in the polytope with the smallest function value &amp;lt;math&amp;gt;f(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We can choose a number of constraints in the system &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, and make them hold with equality. This would define a subspace of &amp;lt;math&amp;gt;\mathbb{R}^n&amp;lt;/math&amp;gt;. In particular, if we choose &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; linearly independent constraints to form an &amp;lt;math&amp;gt;n\times n&amp;lt;/math&amp;gt; submatrix &amp;lt;math&amp;gt;A&#039;&amp;lt;/math&amp;gt; and the corresponding &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector &amp;lt;math&amp;gt;b&#039;&amp;lt;/math&amp;gt;, solving &amp;lt;math&amp;gt;A&#039;x=b&#039;&amp;lt;/math&amp;gt; would give us exactly one point &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. If this &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is in the polytope, i.e. &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; satisfies that &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, we call such &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; a &#039;&#039;&#039;vertex&#039;&#039;&#039; of the polytope &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;. In the context of LP, it is also called a &#039;&#039;&#039;basic feasible solution (&#039;&#039;bfs&#039;&#039;)&#039;&#039;&#039; of the LP.&lt;br /&gt;
&lt;br /&gt;
A key observation for LP is that there is a basic feasible solution which is optimal, i.e. the optimal solution is a vertex of the polytope.&lt;br /&gt;
&lt;br /&gt;
=== The simplex algorithms ===&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Simplex_algorithm simplex algorithm] by George Dantzig solves the linear programming by moving from vertex to vertex of the convex polytope, each time making some progress towards optimizing the objective function. Eventually the algorithm reaches a vertex which is a [http://en.wikipedia.org/wiki/Local_optimum local optimum]. In a convex set, a locally optimal point is also global optimal, thus the simplex algorithm returns an optimal solution in finite steps.&lt;br /&gt;
&lt;br /&gt;
The problem with the simplex algorithm is that in some bad polytopes, it takes the simplex algorithm exponentially many steps to reach the optimum. The simplex algorithm is actually a class of algorithms defined by various &#039;&#039;&#039;pivoting rules&#039;&#039;&#039;, which describe how to move locally from one vertex to another. The original pivoting rule proposed by Dantzig has an exponentially large worst-case time complexity (though works very good in practice). To-date, it is still unknown whether there exists any deterministic simplex algorithm with sub-exponential worst-case complexity.&lt;br /&gt;
&lt;br /&gt;
People have tried randomized pivoting rules, and there are some amazing progresses have been made:&lt;br /&gt;
* Kalai 1992: there is a randomized simplex algorithm with sub-exponential time complexity.&lt;br /&gt;
* Kelner-Spielman 2006: there is a polynomial time randomized simplex algorithm.&lt;br /&gt;
&lt;br /&gt;
Although we do not know whether there exists deterministic poly-time simplex algorithm, we do know that LP can be solved by deterministic poly-time algorithms, i.e. LP is in &#039;&#039;&#039;P&#039;&#039;&#039;. The following two algorithms use different ideas than the simplex algorithm, and are both in poly-time:&lt;br /&gt;
* The ellipsoid algorithm.&lt;br /&gt;
* Interior point methods.&lt;br /&gt;
Although these algorithms guarantee polynomial time complexity in the worst-case, their performances are worse than the simplex algorithms. However, the ideas of these algorithms can be used to solve more general mathematical programmings, such as [http://en.wikipedia.org/wiki/Convex_programming convex programmings].&lt;br /&gt;
&lt;br /&gt;
=== An LP solver via random walks ===&lt;br /&gt;
We discuss a new algorithm for solving LP which is based on random sampling, introduced by Bertsimas and Vempala in 2004. &lt;br /&gt;
&lt;br /&gt;
The problem of solving an LP can be reduced to that given a convex polytope &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;, test whether the polytope is empty. We call this problem the &amp;quot;&#039;&#039;feasibility test&#039;&#039;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Suppose we have an LP:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\mbox{minimize}  &amp;amp; \quad c^T x\\&lt;br /&gt;
\mbox{subject to} &amp;amp; \quad Ax\le b&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
To see this LP can be solved by feasibility testing, we treat the &amp;lt;math&amp;gt;c^Tx\le d&amp;lt;/math&amp;gt; for some parameter &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; as an additional constraint, and define a new polytope &amp;lt;math&amp;gt;A&#039;x\le b&#039;&amp;lt;/math&amp;gt;. The smallest &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; that the polytope &amp;lt;math&amp;gt;A&#039;x\le b&#039;&amp;lt;/math&amp;gt; is not empty is the optimal solution to the original LP. We can find this smallest &amp;lt;math&amp;gt;d&amp;lt;/math&amp;gt; by binary search if we can efficiently test the emptiness of a convex polytope.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We assume that the convex polytope &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is contained in the axis-aligned cube of width &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; centered at the origin; further if &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is non-empty then it contains a cube of width &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt;. The parameter &amp;lt;math&amp;gt;L&amp;lt;/math&amp;gt; is equal to &amp;lt;math&amp;gt;\log\frac{R}{r}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Algorithm&#039;&#039;&#039;: feasibility test &lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;&#039;Input&#039;&#039;&#039;: an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional convex polytope &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; defined by the system &amp;lt;math&amp;gt;Ax\le b&amp;lt;/math&amp;gt;.&lt;br /&gt;
&#039;&#039;&#039;Output&#039;&#039;&#039;: a point &amp;lt;math&amp;gt;x\in P&amp;lt;/math&amp;gt; in the polytope, or a guarantee that &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is empty.&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
:Let &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; be the axis-aligned cube of side length &amp;lt;math&amp;gt;R&amp;lt;/math&amp;gt; and center &amp;lt;math&amp;gt;z=\boldsymbol{0}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Repeat for &amp;lt;math&amp;gt;2nL&amp;lt;/math&amp;gt; times do:&lt;br /&gt;
:: If &amp;lt;math&amp;gt;Az\le b&amp;lt;/math&amp;gt;, return &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;.&lt;br /&gt;
:: Pick a constraint violated by &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;, say that &amp;lt;math&amp;gt;A_i z&amp;gt;b_i&amp;lt;/math&amp;gt;, and define the halfspace&lt;br /&gt;
:::&amp;lt;math&amp;gt;H=\{x\mid A_i x\le A_i z\}&amp;lt;/math&amp;gt;.&lt;br /&gt;
::Set &amp;lt;math&amp;gt;K=K\cap H&amp;lt;/math&amp;gt;. Uniformly sample &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; random points &amp;lt;math&amp;gt;y^{(1)},y^{(2)},\ldots,y^{(N)}&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and let &lt;br /&gt;
:::&amp;lt;math&amp;gt;z=\frac{1}{N}\sum_{i=1}^Ny^{(i)}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:Report &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; is empty.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The number of samples required in each iteration, &amp;lt;math&amp;gt;N=O((\log m)^2)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; is the number of linear constraints. &lt;br /&gt;
&lt;br /&gt;
It is easy to see that at any iteration, &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is a convex set, and &amp;lt;math&amp;gt;P\subseteq K&amp;lt;/math&amp;gt; for the current convex set &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The idea of the algorithm is based on computing the [http://en.wikipedia.org/wiki/Centroid centroid] of the convex set.  It is know that if we could compute the exact centroid in each iteration, then the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; drops by a constant factor &amp;lt;math&amp;gt;(1-1/e)&amp;lt;/math&amp;gt; in each iteration, thus reaches the smallest possible volume of a cube of width &amp;lt;math&amp;gt;r&amp;lt;/math&amp;gt; within polynomial number of iterations. But, finding the centroid of a convex polytope, is &#039;&#039;&#039;#P-hard&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The idea behind the algorithm is that an approximate centroid can be computed using &amp;lt;math&amp;gt;N=O((\log m)^2)&amp;lt;/math&amp;gt; random points and the volume of &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is drops by a constant factor with high probability in each iteration with this choice of &amp;lt;math&amp;gt;z&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
The uniform sampling in &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is not easy. But since &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; is also a convex polytope, we can approximate the uniform sampling by  near-uniform sampling from &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; by rapid mixing random walks. The random walks used here are similar to the ones used in the volume estimation of convex bodies. We could use the basic grid walk, or more advanced ball walk, or hit-and-run walk.&lt;br /&gt;
&lt;br /&gt;
With rapid mixing random walks, the resulting LP solver runs in poly-time.&lt;br /&gt;
&lt;br /&gt;
The details are omitted. You may check the following paper if interested:&lt;br /&gt;
* Bertsimas and Vempala, “&#039;&#039;Solving convex programs by random walks&#039;&#039;.” JACM 2004.&lt;/div&gt;</summary>
		<author><name>172.21.4.18</name></author>
	</entry>
</feed>