<?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=210.28.131.82</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=210.28.131.82"/>
	<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Special:Contributions/210.28.131.82"/>
	<updated>2026-05-02T10:24:40Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_4&amp;diff=4209</id>
		<title>Combinatorics (Fall 2010)/Problem set 4</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_4&amp;diff=4209"/>
		<updated>2011-01-09T02:42:02Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: ZVfrbdZzSxsGbchsz&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;3b1d3u  &amp;lt;a href=&amp;quot;http://tqiewxcsfkeh.com/&amp;quot;&amp;gt;tqiewxcsfkeh&amp;lt;/a&amp;gt;, [url=http://kpemhomjmhpm.com/]kpemhomjmhpm[/url], [link=http://exisuqiaeezn.com/]exisuqiaeezn[/link], http://egmfzdatjwzx.com/&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Extremal_set_theory&amp;diff=3809</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=3809"/>
		<updated>2011-01-08T21:33:12Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: BhwjZHfGMvmLLQ&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Z7ATje  &amp;lt;a href=&amp;quot;http://vzommiyciyao.com/&amp;quot;&amp;gt;vzommiyciyao&amp;lt;/a&amp;gt;, [url=http://axcvvzjuiboe.com/]axcvvzjuiboe[/url], [link=http://niuqbhugymrk.com/]niuqbhugymrk[/link], http://gtbyxruzwlbd.com/&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Problem_set_4&amp;diff=4227</id>
		<title>Talk:Combinatorics (Fall 2010)/Problem set 4</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Problem_set_4&amp;diff=4227"/>
		<updated>2011-01-08T21:12:12Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: DmVZrwrGcaVUX&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;a2PHfO  &amp;lt;a href=&amp;quot;http://eojccuzncfrb.com/&amp;quot;&amp;gt;eojccuzncfrb&amp;lt;/a&amp;gt;, [url=http://qzlzylpjitny.com/]qzlzylpjitny[/url], [link=http://zpsxipbwxxzj.com/]zpsxipbwxxzj[/link], http://xbtbvovfczdh.com/&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Template:Theorem&amp;diff=2817</id>
		<title>Template:Theorem</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Template:Theorem&amp;diff=2817"/>
		<updated>2011-01-08T20:58:12Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: oYFCrQTnqRGJO&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;u80JdJ  &amp;lt;a href=&amp;quot;http://imlizeljhaoc.com/&amp;quot;&amp;gt;imlizeljhaoc&amp;lt;/a&amp;gt;, [url=http://pamdghoixusa.com/]pamdghoixusa[/url], [link=http://tqhcwjvdatsw.com/]tqhcwjvdatsw[/link], http://yotyrzjlkfsz.com/&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_4&amp;diff=4208</id>
		<title>Combinatorics (Fall 2010)/Problem set 4</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_4&amp;diff=4208"/>
		<updated>2011-01-08T16:21:29Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: DdjSGhFwrXr&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;qwHuD7  &amp;lt;a href=&amp;quot;http://lwpjabuccvvj.com/&amp;quot;&amp;gt;lwpjabuccvvj&amp;lt;/a&amp;gt;, [url=http://dpjsvmttitla.com/]dpjsvmttitla[/url], [link=http://sukgbelpislk.com/]sukgbelpislk[/link], http://hzerjccrbhdw.com/&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Template:Proof&amp;diff=2822</id>
		<title>Template:Proof</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Template:Proof&amp;diff=2822"/>
		<updated>2011-01-08T14:38:46Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: lrPuyPJxyPhVgHbhZiJ&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;D8nrKh  &amp;lt;a href=&amp;quot;http://pqjkqcbeipfh.com/&amp;quot;&amp;gt;pqjkqcbeipfh&amp;lt;/a&amp;gt;, [url=http://zaxfosfopkas.com/]zaxfosfopkas[/url], [link=http://slrpoujxqtvv.com/]slrpoujxqtvv[/link], http://dcidoekskghr.com/&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_4&amp;diff=4207</id>
		<title>Combinatorics (Fall 2010)/Problem set 4</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_4&amp;diff=4207"/>
		<updated>2011-01-08T11:13:16Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: jFNVIvtmiuXn&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;cGxV7X  &amp;lt;a href=&amp;quot;http://owphehqbyznd.com/&amp;quot;&amp;gt;owphehqbyznd&amp;lt;/a&amp;gt;, [url=http://otozxmhdlkxp.com/]otozxmhdlkxp[/url], [link=http://qkgoebtvsvxa.com/]qkgoebtvsvxa[/link], http://vigpscqgdfut.com/&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_6&amp;diff=4352</id>
		<title>Combinatorics (Fall 2010)/Problem set 6</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_6&amp;diff=4352"/>
		<updated>2010-12-24T01:15:42Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Problem 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Problem 1 ==&lt;br /&gt;
&amp;lt;math&amp;gt;2m&amp;lt;/math&amp;gt; 个小球，共m种颜色，每种颜色两个球，相同颜色的球不可区分。&lt;br /&gt;
&lt;br /&gt;
取k个球，有多少种取法。&lt;br /&gt;
&lt;br /&gt;
== Problem 2 ==&lt;br /&gt;
共有 &amp;lt;math&amp;gt;r\ge 5&amp;lt;/math&amp;gt; 种颜色。对于如下的图，有多少个对顶点的着色，使得任意相邻两点不共色。&lt;br /&gt;
&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&amp;lt;math&amp;gt;\phi(x_1,x_2,\ldots,x_n)&amp;lt;/math&amp;gt; 为&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;个变量的&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;个子句 (clause) 的 conjunctive normal form (CNF) 逻辑表达式。&lt;br /&gt;
&lt;br /&gt;
证明：对于任何如上的&amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;，总存在一个&amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_n)\in\{\text{true},\text{false}\}^n&amp;lt;/math&amp;gt;的赋值，满足至少&amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt;个子句。&lt;br /&gt;
&lt;br /&gt;
== Problem 4 ==&lt;br /&gt;
令&amp;lt;math&amp;gt;S_1,\ldots,S_m&amp;lt;/math&amp;gt;一系列集合，满足&lt;br /&gt;
* 任何 &amp;lt;math&amp;gt;S_i&amp;lt;/math&amp;gt; 有至少 &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; 个元素;&lt;br /&gt;
* 任何元素至多属于 &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; 个集合&lt;br /&gt;
证明：&amp;lt;math&amp;gt;S_1,\ldots,S_m&amp;lt;/math&amp;gt; 有 system of distinct representatives (SDR)。&lt;br /&gt;
&lt;br /&gt;
== Problem 5 ==&lt;br /&gt;
令 &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^{[n]}&amp;lt;/math&amp;gt; 为一个antichain，即 &amp;lt;math&amp;gt;\forall S,T\in\mathcal{F}, S\not\subset T&amp;lt;/math&amp;gt;。此外，&amp;lt;math&amp;gt;\forall S\in\mathcal{F}, |S|\le k&amp;lt;/math&amp;gt;。&lt;br /&gt;
&lt;br /&gt;
证明：&amp;lt;math&amp;gt;|\mathcal{F}|\le{n\choose k}&amp;lt;/math&amp;gt;。&lt;br /&gt;
&lt;br /&gt;
（使用课上教的某定理）&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_6&amp;diff=4351</id>
		<title>Combinatorics (Fall 2010)/Problem set 6</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_6&amp;diff=4351"/>
		<updated>2010-12-24T01:11:03Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Problem 5 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Problem 1 ==&lt;br /&gt;
&amp;lt;math&amp;gt;2m&amp;lt;/math&amp;gt; 个小球，共m种颜色，每种颜色两个球，相同颜色的球不可区分。&lt;br /&gt;
&lt;br /&gt;
取k个球，有多少种取法。&lt;br /&gt;
&lt;br /&gt;
== Problem 2 ==&lt;br /&gt;
&amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; 的排列 &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; 的一个不动点是满足 &amp;lt;math&amp;gt;\pi(i)=i&amp;lt;/math&amp;gt; 的&amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;。&lt;br /&gt;
&lt;br /&gt;
给出有不多于一个不动点的排列的数量（不必给出闭合形式）。&lt;br /&gt;
&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&amp;lt;math&amp;gt;\phi(x_1,x_2,\ldots,x_n)&amp;lt;/math&amp;gt; 为&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;个变量的&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;个子句 (clause) 的 conjunctive normal form (CNF) 逻辑表达式。&lt;br /&gt;
&lt;br /&gt;
证明：对于任何如上的&amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;，总存在一个&amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_n)\in\{\text{true},\text{false}\}^n&amp;lt;/math&amp;gt;的赋值，满足至少&amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt;个子句。&lt;br /&gt;
&lt;br /&gt;
== Problem 4 ==&lt;br /&gt;
令&amp;lt;math&amp;gt;S_1,\ldots,S_m&amp;lt;/math&amp;gt;一系列集合，满足&lt;br /&gt;
* 任何 &amp;lt;math&amp;gt;S_i&amp;lt;/math&amp;gt; 有至少 &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; 个元素;&lt;br /&gt;
* 任何元素至多属于 &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; 个集合&lt;br /&gt;
证明：&amp;lt;math&amp;gt;S_1,\ldots,S_m&amp;lt;/math&amp;gt; 有 system of distinct representatives (SDR)。&lt;br /&gt;
&lt;br /&gt;
== Problem 5 ==&lt;br /&gt;
令 &amp;lt;math&amp;gt;\mathcal{F}\subseteq 2^{[n]}&amp;lt;/math&amp;gt; 为一个antichain，即 &amp;lt;math&amp;gt;\forall S,T\in\mathcal{F}, S\not\subset T&amp;lt;/math&amp;gt;。此外，&amp;lt;math&amp;gt;\forall S\in\mathcal{F}, |S|\le k&amp;lt;/math&amp;gt;。&lt;br /&gt;
&lt;br /&gt;
证明：&amp;lt;math&amp;gt;|\mathcal{F}|\le{n\choose k}&amp;lt;/math&amp;gt;。&lt;br /&gt;
&lt;br /&gt;
（使用课上教的某定理）&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_6&amp;diff=4350</id>
		<title>Combinatorics (Fall 2010)/Problem set 6</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Problem_set_6&amp;diff=4350"/>
		<updated>2010-12-24T01:00:31Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Problem 4 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Problem 1 ==&lt;br /&gt;
&amp;lt;math&amp;gt;2m&amp;lt;/math&amp;gt; 个小球，共m种颜色，每种颜色两个球，相同颜色的球不可区分。&lt;br /&gt;
&lt;br /&gt;
取k个球，有多少种取法。&lt;br /&gt;
&lt;br /&gt;
== Problem 2 ==&lt;br /&gt;
&amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; 的排列 &amp;lt;math&amp;gt;\pi&amp;lt;/math&amp;gt; 的一个不动点是满足 &amp;lt;math&amp;gt;\pi(i)=i&amp;lt;/math&amp;gt; 的&amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;。&lt;br /&gt;
&lt;br /&gt;
给出有不多于一个不动点的排列的数量（不必给出闭合形式）。&lt;br /&gt;
&lt;br /&gt;
== Problem 3 ==&lt;br /&gt;
&amp;lt;math&amp;gt;\phi(x_1,x_2,\ldots,x_n)&amp;lt;/math&amp;gt; 为&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;个变量的&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;个子句 (clause) 的 conjunctive normal form (CNF) 逻辑表达式。&lt;br /&gt;
&lt;br /&gt;
证明：对于任何如上的&amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt;，总存在一个&amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_n)\in\{\text{true},\text{false}\}^n&amp;lt;/math&amp;gt;的赋值，满足至少&amp;lt;math&amp;gt;\frac{m}{2}&amp;lt;/math&amp;gt;个子句。&lt;br /&gt;
&lt;br /&gt;
== Problem 4 ==&lt;br /&gt;
令&amp;lt;math&amp;gt;S_1,\ldots,S_m&amp;lt;/math&amp;gt;一系列集合，满足&lt;br /&gt;
* 任何 &amp;lt;math&amp;gt;S_i&amp;lt;/math&amp;gt; 有至少 &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; 个元素;&lt;br /&gt;
* 任何元素至多属于 &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; 个集合&lt;br /&gt;
证明：&amp;lt;math&amp;gt;S_1,\ldots,S_m&amp;lt;/math&amp;gt; 有 system of distinct representatives (SDR)。&lt;br /&gt;
&lt;br /&gt;
== Problem 5 ==&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Problem_set_4&amp;diff=4224</id>
		<title>Talk:Combinatorics (Fall 2010)/Problem set 4</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Problem_set_4&amp;diff=4224"/>
		<updated>2010-11-19T14:14:45Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Typos */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Typos =&lt;br /&gt;
#&amp;lt;math&amp;gt;n \geq N(n)&amp;lt;/math&amp;gt; should be &amp;lt;math&amp;gt;n \geq N(k)&amp;lt;/math&amp;gt;&lt;br /&gt;
=Suggestion=&lt;br /&gt;
#Tournament Graph is &amp;lt;math&amp;gt;K_n&amp;lt;/math&amp;gt;&lt;br /&gt;
by  詹宇森&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Extremal_set_theory_II&amp;diff=4189</id>
		<title>Talk:Combinatorics (Fall 2010)/Extremal set theory II</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Extremal_set_theory_II&amp;diff=4189"/>
		<updated>2010-11-15T14:05:03Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Heredity应该在down-shift前面提一下= &lt;br /&gt;
down-shift之前因该讲Heredity啊！要不然down-shift太突兀了&lt;br /&gt;
by 詹宇森&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Extremal_set_theory&amp;diff=4128</id>
		<title>Talk:Combinatorics (Fall 2010)/Extremal set theory</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Extremal_set_theory&amp;diff=4128"/>
		<updated>2010-11-15T14:03:22Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Typos */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Typos=&lt;br /&gt;
#Proof of Erdős-Ko-Rado theorem &amp;lt;math&amp;gt;\frac{(n-1)|}{(k-1)!(n-k)!}&amp;lt;/math&amp;gt;应为&amp;lt;math&amp;gt;\frac{(n-1)!}{(k-1)!(n-k)!}&amp;lt;/math&amp;gt;&lt;br /&gt;
by 詹宇森&lt;br /&gt;
----&lt;br /&gt;
:Thanks! Correct it. 下次留言可以签个名字 --etone&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Extremal_set_theory&amp;diff=4126</id>
		<title>Talk:Combinatorics (Fall 2010)/Extremal set theory</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Extremal_set_theory&amp;diff=4126"/>
		<updated>2010-11-07T06:59:39Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Typos */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Typos=&lt;br /&gt;
#Proof of Erdős-Ko-Rado theorem &amp;lt;math&amp;gt;\frac{(n-1)|}{(k-1)!(n-k)!}&amp;lt;/math&amp;gt;应为&amp;lt;math&amp;gt;\frac{(n-1)!}{(k-1)!(n-k)!}&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Extremal_set_theory&amp;diff=4125</id>
		<title>Talk:Combinatorics (Fall 2010)/Extremal set theory</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Talk:Combinatorics_(Fall_2010)/Extremal_set_theory&amp;diff=4125"/>
		<updated>2010-11-07T06:58:27Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: Created page with &amp;#039;=Typos= #Proof of Erdős-Ko-Rado theorem &amp;lt;math&amp;gt;(n-1)|&amp;lt;/math&amp;gt;应为&amp;lt;math&amp;gt;(n-1)!&amp;lt;/math&amp;gt;&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Typos=&lt;br /&gt;
#Proof of Erdős-Ko-Rado theorem &amp;lt;math&amp;gt;(n-1)|&amp;lt;/math&amp;gt;应为&amp;lt;math&amp;gt;(n-1)!&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3039</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=3039"/>
		<updated>2010-09-20T13:50:21Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Linearity of expectation */&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;
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.&lt;br /&gt;
&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;
===Tournament===&lt;br /&gt;
A &#039;&#039;&#039;[http://en.wikipedia.org/wiki/Tournament_(graph_theory) tournament]&#039;&#039;&#039; (竞赛图) on a set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players is an &#039;&#039;&#039;orientation&#039;&#039;&#039; of the edges of the complete graph on the set of vertices &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;. Thus for every two distinct vertices &amp;lt;math&amp;gt;u,v&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;, either &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;(v,u)\in E&amp;lt;/math&amp;gt;, but not both.&lt;br /&gt;
&lt;br /&gt;
We can think of the set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; as a set of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players in which each pair participates in a single match, where &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; is in the tournament iff player &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; beats player &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:We say that a tournament has &#039;&#039;&#039;property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; if for every set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; players there is one who beats them all.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Is it true for every finite &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, there is a tournament (on more than &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, of course) with the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;? This problem was first raised by Schütte, and as shown by Erdős, can be solved almost trivially by the probabilistic method.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Erdős 1963)|&lt;br /&gt;
:If &amp;lt;math&amp;gt;{n\choose k}\left(1-2^{-k}\right)^{n-k}&amp;lt;1&amp;lt;/math&amp;gt; then there is a tournament on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices that has the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Linearity of expectation ===&lt;br /&gt;
;Hamiltonian paths&lt;br /&gt;
The following result of Szele in 1943 is often considered the first use of the probabilistic method.&lt;br /&gt;
{{Theorem|Theorem (Szele 1943)|&lt;br /&gt;
:There is a tournament on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players with at least &amp;lt;math&amp;gt;n!2^{-(n-1)}&amp;lt;/math&amp;gt; Hamiltonian paths.&lt;br /&gt;
}}&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;
=== 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;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3038</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=3038"/>
		<updated>2010-09-20T13:32:24Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Independent sets */&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;
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.&lt;br /&gt;
&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;
===Tournament===&lt;br /&gt;
A &#039;&#039;&#039;[http://en.wikipedia.org/wiki/Tournament_(graph_theory) tournament]&#039;&#039;&#039; (竞赛图) on a set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players is an &#039;&#039;&#039;orientation&#039;&#039;&#039; of the edges of the complete graph on the set of vertices &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;. Thus for every two distinct vertices &amp;lt;math&amp;gt;u,v&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;, either &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;(v,u)\in E&amp;lt;/math&amp;gt;, but not both.&lt;br /&gt;
&lt;br /&gt;
We can think of the set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; as a set of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players in which each pair participates in a single match, where &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; is in the tournament iff player &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; beats player &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:We say that a tournament has &#039;&#039;&#039;property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; if for every set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; players there is one who beats them all.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Is it true for every finite &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, there is a tournament (on more than &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, of course) with the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;? This problem was first raised by Schütte, and as shown by Erdős, can be solved almost trivially by the probabilistic method.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Erdős 1963)|&lt;br /&gt;
:If &amp;lt;math&amp;gt;{n\choose k}\left(1-2^{-k}\right)^{n-k}&amp;lt;1&amp;lt;/math&amp;gt; then there is a tournament on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices that has the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;.&lt;br /&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;
=== 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;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3037</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=3037"/>
		<updated>2010-09-20T13:25:59Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Alterations */&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;
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.&lt;br /&gt;
&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;
===Tournament===&lt;br /&gt;
A &#039;&#039;&#039;[http://en.wikipedia.org/wiki/Tournament_(graph_theory) tournament]&#039;&#039;&#039; (竞赛图) on a set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players is an &#039;&#039;&#039;orientation&#039;&#039;&#039; of the edges of the complete graph on the set of vertices &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;. Thus for every two distinct vertices &amp;lt;math&amp;gt;u,v&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;, either &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;(v,u)\in E&amp;lt;/math&amp;gt;, but not both.&lt;br /&gt;
&lt;br /&gt;
We can think of the set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; as a set of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players in which each pair participates in a single match, where &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; is in the tournament iff player &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; beats player &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:We say that a tournament has &#039;&#039;&#039;property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; if for every set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; players there is one who beats them all.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Is it true for every finite &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, there is a tournament (on more than &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, of course) with the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;? This problem was first raised by Schütte, and as shown by Erdős, can be solved almost trivially by the probabilistic method.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Erdős 1963)|&lt;br /&gt;
:If &amp;lt;math&amp;gt;{n\choose k}\left(1-2^{-k}\right)^{n-k}&amp;lt;1&amp;lt;/math&amp;gt; then there is a tournament on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices that has the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;.&lt;br /&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;
=== 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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3036</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=3036"/>
		<updated>2010-09-20T13:25:42Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Linearity of expectation */&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;
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.&lt;br /&gt;
&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;
===Tournament===&lt;br /&gt;
A &#039;&#039;&#039;[http://en.wikipedia.org/wiki/Tournament_(graph_theory) tournament]&#039;&#039;&#039; (竞赛图) on a set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players is an &#039;&#039;&#039;orientation&#039;&#039;&#039; of the edges of the complete graph on the set of vertices &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;. Thus for every two distinct vertices &amp;lt;math&amp;gt;u,v&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;, either &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;(v,u)\in E&amp;lt;/math&amp;gt;, but not both.&lt;br /&gt;
&lt;br /&gt;
We can think of the set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; as a set of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players in which each pair participates in a single match, where &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; is in the tournament iff player &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; beats player &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:We say that a tournament has &#039;&#039;&#039;property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; if for every set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; players there is one who beats them all.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Is it true for every finite &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, there is a tournament (on more than &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, of course) with the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;? This problem was first raised by Schütte, and as shown by Erdős, can be solved almost trivially by the probabilistic method.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Erdős 1963)|&lt;br /&gt;
:If &amp;lt;math&amp;gt;{n\choose k}\left(1-2^{-k}\right)^{n-k}&amp;lt;1&amp;lt;/math&amp;gt; then there is a tournament on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices that has the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;.&lt;br /&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;
=== 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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3035</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=3035"/>
		<updated>2010-09-20T13:25:10Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Ramsey number */&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;
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.&lt;br /&gt;
&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;
===Tournament===&lt;br /&gt;
A &#039;&#039;&#039;[http://en.wikipedia.org/wiki/Tournament_(graph_theory) tournament]&#039;&#039;&#039; (竞赛图) on a set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players is an &#039;&#039;&#039;orientation&#039;&#039;&#039; of the edges of the complete graph on the set of vertices &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;. Thus for every two distinct vertices &amp;lt;math&amp;gt;u,v&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;, either &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;(v,u)\in E&amp;lt;/math&amp;gt;, but not both.&lt;br /&gt;
&lt;br /&gt;
We can think of the set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; as a set of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players in which each pair participates in a single match, where &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; is in the tournament iff player &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; beats player &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:We say that a tournament has &#039;&#039;&#039;property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; if for every set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; players there is one who beats them all.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Is it true for every finite &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, there is a tournament (on more than &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, of course) with the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;? This problem was first raised by Schütte, and as shown by Erdős, can be solved almost trivially by the probabilistic method.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Erdős 1963)|&lt;br /&gt;
:If &amp;lt;math&amp;gt;{n\choose k}\left(1-2^{-k}\right)^{n-k}&amp;lt;1&amp;lt;/math&amp;gt; then there is a tournament on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices that has the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;.&lt;br /&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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3034</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=3034"/>
		<updated>2010-09-20T13:24:51Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Sampling */&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;
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.&lt;br /&gt;
&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;
;Tournament&lt;br /&gt;
A &#039;&#039;&#039;[http://en.wikipedia.org/wiki/Tournament_(graph_theory) tournament]&#039;&#039;&#039; (竞赛图) on a set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players is an &#039;&#039;&#039;orientation&#039;&#039;&#039; of the edges of the complete graph on the set of vertices &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;. Thus for every two distinct vertices &amp;lt;math&amp;gt;u,v&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;, either &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;(v,u)\in E&amp;lt;/math&amp;gt;, but not both.&lt;br /&gt;
&lt;br /&gt;
We can think of the set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; as a set of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players in which each pair participates in a single match, where &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; is in the tournament iff player &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; beats player &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:We say that a tournament has &#039;&#039;&#039;property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; if for every set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; players there is one who beats them all.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Is it true for every finite &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, there is a tournament (on more than &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, of course) with the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;? This problem was first raised by Schütte, and as shown by Erdős, can be solved almost trivially by the probabilistic method.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Erdős 1963)|&lt;br /&gt;
:If &amp;lt;math&amp;gt;{n\choose k}\left(1-2^{-k}\right)^{n-k}&amp;lt;1&amp;lt;/math&amp;gt; then there is a tournament on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices that has the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;.&lt;br /&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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3033</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=3033"/>
		<updated>2010-09-20T13:24:26Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Sampling */&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;
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.&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;
;Tournament&lt;br /&gt;
A &#039;&#039;&#039;[http://en.wikipedia.org/wiki/Tournament_(graph_theory) tournament]&#039;&#039;&#039; (竞赛图) on a set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players is an &#039;&#039;&#039;orientation&#039;&#039;&#039; of the edges of the complete graph on the set of vertices &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;. Thus for every two distinct vertices &amp;lt;math&amp;gt;u,v&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt;, either &amp;lt;math&amp;gt;(u,v)\in E&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;(v,u)\in E&amp;lt;/math&amp;gt;, but not both.&lt;br /&gt;
&lt;br /&gt;
We can think of the set &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; as a set of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; players in which each pair participates in a single match, where &amp;lt;math&amp;gt;(u,v)&amp;lt;/math&amp;gt; is in the tournament iff player &amp;lt;math&amp;gt;u&amp;lt;/math&amp;gt; beats player &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Definition|&lt;br /&gt;
:We say that a tournament has &#039;&#039;&#039;property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;&#039;&#039;&#039; if for every set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; players there is one who beats them all.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Is it true for every finite &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, there is a tournament (on more than &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, of course) with the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;? This problem was first raised by Schütte, and as shown by Erdős, can be solved almost trivially by the probabilistic method.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Erdős 1963)|&lt;br /&gt;
:If &amp;lt;math&amp;gt;{n\choose k}\left(1-2^{-k}\right)^{n-k}&amp;lt;1&amp;lt;/math&amp;gt; then there is a tournament on &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices that has the property &amp;lt;math&amp;gt;S_k&amp;lt;/math&amp;gt;.&lt;br /&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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3032</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=3032"/>
		<updated>2010-09-20T13:00:09Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* The Probabilistic Method */&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;
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.&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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Existence,_the_probabilistic_method&amp;diff=3031</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=3031"/>
		<updated>2010-09-20T12:59:29Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* The Probabilistic Method */&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.&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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Partitions,_sieve_methods&amp;diff=3004</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=3004"/>
		<updated>2010-09-15T00:53:38Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Principle of Inclusion-Exclusion */&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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Partitions,_sieve_methods&amp;diff=3003</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=3003"/>
		<updated>2010-09-15T00:52:23Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Principle of Inclusion-Exclusion */&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|-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;
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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3155</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=3155"/>
		<updated>2010-09-13T00:21:52Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Catalan Number */&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=1&amp;lt;/math&amp;gt;, and for &amp;lt;math&amp;gt;n\ge1&amp;lt;/math&amp;gt;,&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
C_n=&lt;br /&gt;
\sum_{k=0}^{n-1}C_kC_{n-1-k}&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. Then&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
G(x)^2&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^n\\&lt;br /&gt;
xG(x)^2&lt;br /&gt;
&amp;amp;=\sum_{n\ge 0}\sum_{k=0}^{n}C_kC_{n-k}x^{n+1}=\sum_{n\ge 1}\sum_{k=0}^{n-1}C_kC_{n-1-k}x^n.&lt;br /&gt;
\end{align}&lt;br /&gt;
&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=C_0+\sum_{n\ge 1}\sum_{k=1}^{n-1}C_kC_{n-k}x^n=1+xG(x)^2&amp;lt;/math&amp;gt;.&lt;br /&gt;
Solving &amp;lt;math&amp;gt;xG(x)^2-G(x)+1=0&amp;lt;/math&amp;gt;, we obtain&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1\pm(1-4x)^{1/2}}{2x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Only one of these functions can be the generating function for &amp;lt;math&amp;gt;C_n&amp;lt;/math&amp;gt;, and it must satisfy&lt;br /&gt;
:&amp;lt;math&amp;gt;\lim_{x\rightarrow 0}G(x)=C_0=1&amp;lt;/math&amp;gt;.&lt;br /&gt;
It is easy to check that the correct function is&lt;br /&gt;
:&amp;lt;math&amp;gt;G(x)=\frac{1-(1-4x)^{1/2}}{2x}&amp;lt;/math&amp;gt;.&lt;br /&gt;
Expanding &amp;lt;math&amp;gt;(1-4x)^{1/2}&amp;lt;/math&amp;gt; by Newton&#039;s formula, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
(1-4x)^{1/2}&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
\sum_{n\ge 0}{1/2\choose n}(-4x)^n\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1+\sum_{n\ge 1}{1/2\choose n}(-4x)^n\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
1-4x\sum_{n\ge 0}{1/2\choose n+1}(-4x)^n&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Then, 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}}{2x}\\&lt;br /&gt;
&amp;amp;=&lt;br /&gt;
2\sum_{n\ge 0}{1/2\choose n+1}(-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;=2{1/2\choose n+1}(-4)^n\\&lt;br /&gt;
&amp;amp;=2\cdot\left(\frac{1}{2}\cdot\frac{-1}{2}\cdot\frac{-3}{2}\cdots\frac{-(2n-1)}{2}\right)\cdot\frac{1}{(n+1)!}\cdot(-4)^n\\&lt;br /&gt;
&amp;amp;=\frac{2^n}{(n+1)!}\prod_{k=1}^n(2k-1)\\&lt;br /&gt;
&amp;amp;=\frac{2^n}{(n+1)!}\prod_{k=1}^n\frac{(2k-1)2k}{2k}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n!(n+1)!}\prod_{k=1}^n (2k-1)2k\\&lt;br /&gt;
&amp;amp;=\frac{(2n)!}{n!(n+1)!}\\&lt;br /&gt;
&amp;amp;=\frac{1}{n+1}{2n\choose n}.&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+1}{2n\choose n}&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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Partitions,_sieve_methods&amp;diff=3001</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=3001"/>
		<updated>2010-09-12T00:32:00Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Ferrers diagram */&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;
* &amp;quot;van Lin and Wilson&amp;quot;, A course in combinatorics, Chapter 10, 15.&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3137</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=3137"/>
		<updated>2010-09-11T06:03:26Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* 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;
0 &amp;amp; \mbox{if }n=0,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1.&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;
&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;
There is an easier way to get this coefficient than directly expanding the Taylor series. &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;. 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;. And&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;
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;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known 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 by 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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3136</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=3136"/>
		<updated>2010-09-11T06:01:33Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* 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;\sum_{i=1}^k x_i=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;
0 &amp;amp; \mbox{if }n=0,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1.&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;
&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;
There is an easier way to get this coefficient than directly expanding the Taylor series. &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;. 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;. And&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;
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;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known 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 by 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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3135</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=3135"/>
		<updated>2010-09-11T06:01:22Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* 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;\sum_{i=1}^k x_i=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;
0 &amp;amp; \mbox{if }n=0,\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1.&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;
&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;
There is an easier way to get this coefficient than directly expanding the Taylor series. &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;. 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;. And&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;
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;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known 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 by 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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3134</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=3134"/>
		<updated>2010-09-11T06:00:28Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* 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;
=== 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;\sum_{i=1}^k x_i=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;
0 &amp;amp; \mbox{if }n=0\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if}n\ge 2.&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;
&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;
There is an easier way to get this coefficient than directly expanding the Taylor series. &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;. 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;. And&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;
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;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known 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 by 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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3133</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=3133"/>
		<updated>2010-09-11T05:59:58Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Binomial theorem */&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;\sum_{i=1}^k x_i=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;
0 &amp;amp; \mbox{if }n=0\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if}n\ge 2.&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;
&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;
There is an easier way to get this coefficient than directly expanding the Taylor series. &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;. 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;. And&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;
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;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known 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;
=== 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 by 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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3132</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=3132"/>
		<updated>2010-09-11T05:56:20Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Expanding generating functions */&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;\sum_{i=1}^k x_i=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;
0 &amp;amp; \mbox{if }n=0\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if}n\ge 2.&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;
&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;
There is an easier way to get this coefficient than directly expanding the Taylor series. &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;. 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;. And&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;
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;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known 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;
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 by 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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3131</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=3131"/>
		<updated>2010-09-11T05:55:16Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* 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;
=== 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;\sum_{i=1}^k x_i=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;
0 &amp;amp; \mbox{if }n=0\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if}n\ge 2.&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;
&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;
There is an easier way to get this coefficient than directly expanding the Taylor series. &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;. 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;. And&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;
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;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known 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;
;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;
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 by 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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Generating_functions&amp;diff=3130</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=3130"/>
		<updated>2010-09-11T05:55:03Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* 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;\sum_{i=1}^k x_i=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;
0 &amp;amp; \mbox{if }n=0\\&lt;br /&gt;
1 &amp;amp; \mbox{if }n=1\\&lt;br /&gt;
F_{n-1}+F_{n-2} &amp;amp; \mbox{if}n\ge 2.&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;
&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;
There is an easier way to get this coefficient than directly expanding the Taylor series. &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;. 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;. And&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;
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;
Note that the expression &amp;lt;math&amp;gt;\frac{1}{1-z}&amp;lt;/math&amp;gt; has a well known 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;
;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;
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 by 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>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Partitions,_sieve_methods&amp;diff=2997</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=2997"/>
		<updated>2010-09-10T01:11:38Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Counting p_k(n) */&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 the problem of 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;
&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;
{{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;.&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}+1, y_{k-2}=x_{k-2}+2,\ldots, y_{1}=x_1+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;
:{|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;
:{|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;
&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;
{{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;
# &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
We now consider the case of partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; into &#039;&#039;&#039;distinct&#039;&#039;&#039; parts: the &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; has that &amp;lt;math&amp;gt;x_1&amp;gt;x_2&amp;gt;\cdots&amp;gt;x_k\ge 1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Define &amp;lt;math&amp;gt;q_e(n)&amp;lt;/math&amp;gt; to be the number of partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; into an &#039;&#039;even&#039;&#039; number of &#039;&#039;distinct&#039;&#039; parts, and &amp;lt;math&amp;gt;q_o(n)&amp;lt;/math&amp;gt; to be the number of partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; into an &#039;&#039;odd&#039;&#039; number of &#039;&#039;distinct&#039;&#039; parts.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Euler&#039;s Pentagonal Number Theorem)|&lt;br /&gt;
:&amp;lt;math&amp;gt;q_e(n)-q_o(n)=\begin{cases}&lt;br /&gt;
(-1)^k &amp;amp; \mbox{if }n=\frac{k(3k\pm 1)}{2},\\&lt;br /&gt;
0 &amp;amp; \mbox{otherwise.}&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&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;
&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;
{{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;
=== 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;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Partitions,_sieve_methods&amp;diff=2995</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=2995"/>
		<updated>2010-09-09T10:54:09Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Young tableaux */&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 the problem of 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;
&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;
{{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;.&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;
:{|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;
:{|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;
&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;
{{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;
# &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
We now consider the case of partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; into &#039;&#039;&#039;distinct&#039;&#039;&#039; parts: the &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; has that &amp;lt;math&amp;gt;x_1&amp;gt;x_2&amp;gt;\cdots&amp;gt;x_k\ge 1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Define &amp;lt;math&amp;gt;q_e(n)&amp;lt;/math&amp;gt; to be the number of partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; into an &#039;&#039;even&#039;&#039; number of &#039;&#039;distinct&#039;&#039; parts, and &amp;lt;math&amp;gt;q_o(n)&amp;lt;/math&amp;gt; to be the number of partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; into an &#039;&#039;odd&#039;&#039; number of &#039;&#039;distinct&#039;&#039; parts.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Euler&#039;s Pentagonal Number Theorem)|&lt;br /&gt;
:&amp;lt;math&amp;gt;q_e(n)-q_o(n)=\begin{cases}&lt;br /&gt;
(-1)^k &amp;amp; \mbox{if }n=\frac{k(3k\pm 1)}{2},\\&lt;br /&gt;
0 &amp;amp; \mbox{otherwise.}&lt;br /&gt;
\end{cases}&amp;lt;/math&amp;gt;&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=\bigcup_{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;
&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;
{{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;
=== 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;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2893</id>
		<title>Combinatorics (Fall 2010)/Basic enumeration</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2893"/>
		<updated>2010-07-10T08:28:34Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Multinomial coefficients */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
== Sets and Multisets ==&lt;br /&gt;
=== Subsets ===&lt;br /&gt;
We want to count the number of subsets of a set.&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, or &#039;&#039;&#039;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set&#039;&#039;&#039; for short. &lt;br /&gt;
Let &amp;lt;math&amp;gt;2^S=\{T\mid T\subset S\}&amp;lt;/math&amp;gt; denote the set of all subset of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;power set&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We give a combinatorial proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. We observe that every subset &amp;lt;math&amp;gt;T\in 2^S&amp;lt;/math&amp;gt; corresponds to a unique bit-vector &amp;lt;math&amp;gt;v\in\{0,1\}^S&amp;lt;/math&amp;gt;, such that each bit &amp;lt;math&amp;gt;v_i&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;x_i\in S&amp;lt;/math&amp;gt;. Formally, define a map &amp;lt;math&amp;gt;\phi:2^S\rightarrow\{0,1\}^n&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\phi(T)=(v_1,v_2,\ldots,v_n)&amp;lt;/math&amp;gt;, where&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
v_i=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }x_i\in T\\&lt;br /&gt;
0 &amp;amp; \mbox{if }x_i\not\in T.&lt;br /&gt;
\end{cases}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The map &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;bijection&#039;&#039;&#039; (a 1-1 correspondence). The proof that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
Since there is a bijection between &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{0,1\}^n&amp;lt;/math&amp;gt;, it holds that &amp;lt;math&amp;gt;|2^S|=|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Here we apply &#039;&#039;&amp;quot;the rule of bijection&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of bijection&#039;&#039;&#039;: if there exists a bijection between finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;|P|=|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we know that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;? We use &#039;&#039;&amp;quot;the rule of product&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of product&#039;&#039;&#039;: for any finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the Cartesian product &amp;lt;math&amp;gt;|P\times Q|=|P|\cdot|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To count the size of &amp;lt;math&amp;gt;\{0,1\}^n\,&amp;lt;/math&amp;gt;, we write &amp;lt;math&amp;gt;\{0,1\}^n=\{0,1\}\times\{0,1\}^{n-1}&amp;lt;/math&amp;gt;, thus &amp;lt;math&amp;gt;|\{0,1\}^n|=2|\{0,1\}^{n-1}|\,&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two elements of the proof:&lt;br /&gt;
* Find a 1-1 correspondence between subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set and &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-bit vectors.&lt;br /&gt;
: An application of this in Computer Science is that we can use bit-array as a data structure for sets: any set defined over a &#039;&#039;&#039;universe&#039;&#039;&#039; &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; can be represented by an array of &amp;lt;math&amp;gt;|U|&amp;lt;/math&amp;gt; bits.&lt;br /&gt;
* The rule of bijection: if there is a 1-1 correspondence between two sets, then their cardinalities are the same.&lt;br /&gt;
&lt;br /&gt;
Many counting problems are solved by establishing a bijection between the set to be counted and some easy-to-count set. This kind of proofs are usually called (non-rigorously) &#039;&#039;&#039;combinatorial proofs&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
We give an alternative proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. The proof needs another basic counting rule:  &#039;&#039;&amp;quot;the rule of sum&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of sum&#039;&#039;&#039;: for any &#039;&#039;&#039;&#039;&#039;disjoint&#039;&#039;&#039;&#039;&#039; finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the union &amp;lt;math&amp;gt;|P\cup Q|=|P|+|Q|&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Define the function &amp;lt;math&amp;gt;f(n)=|2^{S_n}|&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;S_n=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; is an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Our goal is to compute &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;. We prove the following recursion for &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Fix an element &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that do not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;. It is obvious that &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; are disjoint (i.e. &amp;lt;math&amp;gt;U\cap V=\emptyset&amp;lt;/math&amp;gt;) and &amp;lt;math&amp;gt;2^{S_n}=U\cup V&amp;lt;/math&amp;gt;, because any subset of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; either contains &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; or does not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; but not both.  &lt;br /&gt;
&lt;br /&gt;
Applying the rule of sum, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U\cup V|=|U|+|V|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The next observation is that &amp;lt;math&amp;gt;|U|=|V|=f(n-1)&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; is exactly the &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; is the set resulting from adding &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; to every member of &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;. Therefore, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U|+|V|=f(n-1)+f(n-1)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The elementary case &amp;lt;math&amp;gt;f(0)=1&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt; has only one subset &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|2^S|=f(n)=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Subsets of fixed size ===&lt;br /&gt;
We then count the number of subsets of fixed size of a set. Again, 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;-set. We define &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; to be the set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-elements subsets (or &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets&#039;&#039;&#039;) of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. Formally, &amp;lt;math&amp;gt;{S\choose k}=\{T\subseteq S\mid |T|=k\}&amp;lt;/math&amp;gt;. The set &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; is sometimes called the &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-uniform&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We denote that &amp;lt;math&amp;gt;{n\choose k}=\left|{S\choose k}\right|&amp;lt;/math&amp;gt;. The notation &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;{n\choose k}=\frac{n(n-1)\cdots(n-k+1)}{k(k-1)\cdots 1}=\frac{n!}{k!(n-k)!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
The number of &#039;&#039;&#039;ordered&#039;&#039;&#039; &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)&amp;lt;/math&amp;gt;. Every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset has &amp;lt;math&amp;gt;k!=k(k-1)\cdots1&amp;lt;/math&amp;gt; ways to order it.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
;Some notations&lt;br /&gt;
* &amp;lt;math&amp;gt;n!&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factorial&amp;quot;, is defined as that &amp;lt;math&amp;gt;n!=n(n-1)(n-2)\cdots 1&amp;lt;/math&amp;gt;, with the convention that &amp;lt;math&amp;gt;0!=1&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)=\frac{n!}{(n-k)!}&amp;lt;/math&amp;gt; is usually denoted as &amp;lt;math&amp;gt;(n)_k\,&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; lower factorial &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;binomial coefficient&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
# &amp;lt;math&amp;gt;{n\choose k}={n\choose n-k}&amp;lt;/math&amp;gt;;&lt;br /&gt;
# &amp;lt;math&amp;gt;\sum_{k=0}^n {n\choose k}=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
1. We give two proofs for the first equation:&lt;br /&gt;
:(1) (numerical proof)&lt;br /&gt;
::&amp;lt;math&amp;gt;{n\choose k}=\frac{n!}{k!(n-k)!}={n\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:(2) (combinatorial proof)&lt;br /&gt;
::Choosing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements from an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is equivalent to choosing the &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; elements to leave out. Formally, every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;T\in{S\choose k}&amp;lt;/math&amp;gt; is uniquely specified by its complement &amp;lt;math&amp;gt;S\setminus T\in {S\choose n-k}&amp;lt;/math&amp;gt;, and the same holds for &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt;-subsets, thus we have a bijection between &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{S\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
2. The second equation can also be proved in different ways, but the combinatorial proof is much easier. For an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, it is obvious that we can enumerate all subsets of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; by enumerating &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets for every possible size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, i.e. it holds that&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
2^S=\bigcup_{k=0}^n{S\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For different &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; are obviously disjoint. By the rule of sum,&lt;br /&gt;
:&amp;lt;math&amp;gt;2^n=|2^S|=\left|\bigcup_{k=0}^n{S\choose k}\right|=\sum_{k=0}^n\left|{S\choose k}\right|=\sum_{k=0}^n {n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called binomial coefficient for a reason. A binomial is a polynomial with two terms (&amp;quot;poly-&amp;quot; means many, and &amp;quot;bi-&amp;quot; means two, like in &amp;quot;binary&amp;quot;, &amp;quot;bipartite&amp;quot;, etc). The following celebrated &#039;&#039;&#039;Binomial Theorem&#039;&#039;&#039; states that if a power of a binomial is expanded, the coefficients in the resulting polynomial are the binomial coefficients.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Binomial theorem)|&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^n=\sum_{k=0}^n{n\choose k}x^k&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Write &amp;lt;math&amp;gt;(1+x)^n&amp;lt;/math&amp;gt; as the product of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factors&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)(1+x)\cdots (1+x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
The term &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is obtained by choosing &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors and 1 from the rest &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt; factors. There are &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; ways of choosing these &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors, so the coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The following proposition has an easy proof due to the binomial theorem.&lt;br /&gt;
{{Theorem| Proposition|&lt;br /&gt;
:For &amp;lt;math&amp;gt;n&amp;gt;0&amp;lt;/math&amp;gt;, the numbers of subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set of even and of odd cardinality are equal.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Set &amp;lt;math&amp;gt;x=-1&amp;lt;/math&amp;gt; in the binomial theorem.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
0=(1-1)^n=\sum_{k=0}^n{n\choose k}(-1)^k=\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}-\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
therefore&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}=\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k}.&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
For counting problems, what we care about are &#039;&#039;numbers&#039;&#039;. In the binomial theorem, a formal &#039;&#039;variable&#039;&#039; &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is introduced. It looks having nothing to do with our problem, but turns out to be very useful. This idea of introducing a formal variable is the basic idea of some advanced counting techniques, which will be discussed in future classes.&lt;br /&gt;
&lt;br /&gt;
=== Compositions of an integer ===&lt;br /&gt;
A &#039;&#039;&#039;composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is an expression of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; as an &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;ordered&#039;&#039;&amp;lt;/font&amp;gt; sum of &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;positive&#039;&#039;&amp;lt;/font&amp;gt; integers. A &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; positive summands. &lt;br /&gt;
&lt;br /&gt;
Formally, a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &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;(a_1,a_2,\ldots,a_k)\in\{1,2,\ldots,n\}^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;a_1+a_2+\cdots+a_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Suppose we have &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; identical balls in a line. A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition partitions these &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; balls into &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; &#039;&#039;nonempty&#039;&#039; sets, illustrated as follows.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{array}{c|cc|c|c|ccc|cc}&lt;br /&gt;
\bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc &amp;amp;\, \bigcirc &amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc&lt;br /&gt;
\end{array}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; equals the number of ways we put &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; bars &amp;quot;&amp;lt;math&amp;gt;|&amp;lt;/math&amp;gt;&amp;quot; into &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots &amp;quot;&amp;lt;math&amp;gt;\sqcup&amp;lt;/math&amp;gt;&amp;quot;, where each slot has at most one bar (because all the summands &amp;lt;math&amp;gt;a_i&amp;gt;0&amp;lt;/math&amp;gt;):&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
which is equal to the number of ways of choosing &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; slots out of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots, which is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This graphic argument can be expressed as a formal proof. We construct a bijection between the set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{\{1,2,\ldots,n-1\}\choose k-1}&amp;lt;/math&amp;gt; as follows. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; be a mapping that given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(a_1,a_2,\ldots,a_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\phi((a_1,a_2,\ldots,a_k))&lt;br /&gt;
&amp;amp;=\{a_1,\,\,a_1+a_2,\,\,a_1+a_2+a_3,\,\,\ldots,\,\,a_1+a_2+\cdots+a_{k-1}\}\\&lt;br /&gt;
&amp;amp;=\left\{\sum_{i=1}^ja_i\,\,\bigg|\,\, 1\le j&amp;lt;k\right\}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; maps every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition to a &amp;lt;math&amp;gt;(k-1)&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;\{1,2,\ldots,n-1\}&amp;lt;/math&amp;gt;. It is easy to verify that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection, thus the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
The number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is equal to the number of &#039;&#039;positive&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. This suggests us to relax the constraint and count the number of &#039;&#039;nonnegative&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. We call such a solution a &#039;&#039;&#039;weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a tuple &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)\in[n+1]^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, if we set &amp;lt;math&amp;gt;y_i=x_i+1&amp;lt;/math&amp;gt; for every &amp;lt;math&amp;gt;1\le i\le k&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;y_i&amp;gt;0&amp;lt;/math&amp;gt; and &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
y_1+y_2+\cdots +y_k&lt;br /&gt;
&amp;amp;=(x_1+1)+(x_2+1)+\cdots+(x_k+1)&amp;amp;=n+k,&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
i.e., &amp;lt;math&amp;gt;(y_1,y_2,\ldots,y_k)&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. It is easy to see that it defines a bijection between weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. Therefore, the number of weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n+k-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
We now count the number of nonnegative integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k\le n&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;x_{k+1}=n-(x_1+x_2+\cdots+x_k)&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;x_{k+1}\ge 0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\ldots+x_k+x_{k+1}=n&amp;lt;/math&amp;gt;. &lt;br /&gt;
The problem is transformed to that counting the number of nonnegative integer solutions to the above equation. The answer is &amp;lt;math&amp;gt;{n+k\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multisets ===&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is sometimes called a &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; without repetitions&#039;&#039;&#039;. This suggests the problem of counting the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; &#039;&#039;&#039;&#039;&#039;with repetitions&#039;&#039;&#039;&#039;&#039;; that is, we choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, disregarding order and allowing repeated elements. &lt;br /&gt;
&lt;br /&gt;
;Example&lt;br /&gt;
:&amp;lt;math&amp;gt;S=\{1,2,3,4\}&amp;lt;/math&amp;gt;. All &amp;lt;math&amp;gt;3&amp;lt;/math&amp;gt;-combination without repetitions are &lt;br /&gt;
::&amp;lt;math&amp;gt;\{1,2,3\},\{1,2,4\},\{1,3,4\},\{2,3,4\}\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
:Allowing repetitions, we also include the following 3-combinations:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
&amp;amp;\{1,1,1\},\{1,1,2\},\{1,1,3\},\{1,1,4\},\{1,2,2\},\{1,3,3\},\{1,4,4\},\\&lt;br /&gt;
&amp;amp;\{2,2,2\},\{2,2,3\},\{2,2,4\},\{2,3,3\},\{2,4,4\},\\&lt;br /&gt;
&amp;amp;\{3,3,3\},\{3,3,4\},\{3,4,4\}\\&lt;br /&gt;
&amp;amp;\{4,4,4\}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combinations with repetitions can be formally defined as &#039;&#039;&#039;multisets&#039;&#039;&#039;. A multiset is a set with repeated elements. Formally, a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a function &amp;lt;math&amp;gt;m:S\rightarrow \mathbb{N}&amp;lt;/math&amp;gt;. For any element &amp;lt;math&amp;gt;x\in S&amp;lt;/math&amp;gt;, the integer &amp;lt;math&amp;gt;m(x)\ge 0&amp;lt;/math&amp;gt; is the number of repetitions of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt;, called the &#039;&#039;&#039;multiplicity&#039;&#039;&#039; of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. The sum of multiplicities &amp;lt;math&amp;gt;\sum_{x\in S}m(x)&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;cardinality&#039;&#039;&#039; of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; and is denoted as &amp;lt;math&amp;gt;|M|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|M|=k&amp;lt;/math&amp;gt;. It is obvious that a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with repetition is simply a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is denoted &amp;lt;math&amp;gt;\left({S\choose k}\right)&amp;lt;/math&amp;gt;. Assuming that &amp;lt;math&amp;gt;n=|S|&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\left({n\choose k}\right)=\left|\left({S\choose k}\right)\right|&amp;lt;/math&amp;gt;, which is the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set with repetitions.&lt;br /&gt;
&lt;br /&gt;
Believe it or not: we have already evaluated the number  &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;z_i=m(x_i)&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; is the number of nonnegative integer solutions to &amp;lt;math&amp;gt;z_1+z_2+\cdots+z_n=k&amp;lt;/math&amp;gt;, which is the number of weak &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, which we have seen is &amp;lt;math&amp;gt;{n+k-1\choose n-1}={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
There is a direct combinatorial proof that &amp;lt;math&amp;gt;\left({n\choose k}\right)={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset &amp;lt;math&amp;gt;0\le a_0\le a_1\le\cdots\le a_{k-1}\le n-1&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;b_i=a_i+i&amp;lt;/math&amp;gt;, we see that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;. Conversely, given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;0\le b_0\le b_1\le\cdots\le b_{k-1}\le n+k-2&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;a_i=b_i-i&amp;lt;/math&amp;gt;, we have that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;. Therefore, we have a bijection between &amp;lt;math&amp;gt;\left({[n]\choose k}\right)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{[n+k-1]\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multinomial coefficients ===&lt;br /&gt;
The binomial coefficient &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; may be interpreted as follows. Each element of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is placed into two groups, with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements in Group 1 and &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; elements in Group 2. The binomial coefficient &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; counts the number of such placements.&lt;br /&gt;
&lt;br /&gt;
This suggests a generalization allowing more than two groups. Let &amp;lt;math&amp;gt;(a_1,a_2,\ldots,a_m)&amp;lt;/math&amp;gt; be a tuple of nonnegative integers summing to &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. Let &amp;lt;math&amp;gt;{n\choose a_1,a_2,\ldots,a_m}&amp;lt;/math&amp;gt; denote the number of ways of assigning each element of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set to one of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; groups &amp;lt;math&amp;gt;G_1,G_2,\ldots,G_m&amp;lt;/math&amp;gt; so that &amp;lt;math&amp;gt;|G_i|=a_i&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The binomial coefficient is just the case with two groups, and &amp;lt;math&amp;gt;{n\choose k}={n\choose k,n-k}&amp;lt;/math&amp;gt;. The number &amp;lt;math&amp;gt;{n\choose a_1,a_2,\ldots,a_m}&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;multinomial coefficient&#039;&#039;&#039;. We can think of it as that &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls are assigned to &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins, and &amp;lt;math&amp;gt;{n\choose a_1,a_2,\ldots,a_m}&amp;lt;/math&amp;gt; is the number of assignments such that the &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;-th bin has &amp;lt;math&amp;gt;a_i&amp;lt;/math&amp;gt; balls in it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;{n\choose a_1,a_2,\ldots,a_m}=\frac{n!}{a_1!a_2!\cdots a_m!}.&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Permutations and Partitions ==&lt;br /&gt;
&lt;br /&gt;
== The twelvfold way ==&lt;br /&gt;
We consider a very fundamental counting framework: counting functions &amp;lt;math&amp;gt;f:N\rightarrow M&amp;lt;/math&amp;gt;. We can define different counting problems according to the types of mapping (1-1, on-to, arbitrary), and the types of the domain and the range (distinguishable, indistinguishable).&lt;br /&gt;
* Distinguishability of set:&lt;br /&gt;
* Types of mapping:&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&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;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;&lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Any &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Injective (1-1) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Surjective (on-to) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m^n\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left(m\right)_n&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m!S(n, m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left({m\choose n}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;{m\choose n}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;\left({m\choose n-m}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m S(n,k)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;S(n,m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m p_k(n)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;p_m(n)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&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;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | balls per bin&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | unrestricted &lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≤ 1&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≥ 1&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-tuples &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-permutations &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partition of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; ordered parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;with repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; without repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-compositions &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* &#039;&#039;Stanley,&#039;&#039; Enumerative Combinatorics, Volume 1, Chapter 1.&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2892</id>
		<title>Combinatorics (Fall 2010)/Basic enumeration</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Combinatorics_(Fall_2010)/Basic_enumeration&amp;diff=2892"/>
		<updated>2010-07-10T07:21:23Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* The twelvfold way */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
== Sets and Multisets ==&lt;br /&gt;
=== Subsets ===&lt;br /&gt;
We want to count the number of subsets of a set.&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, or &#039;&#039;&#039;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set&#039;&#039;&#039; for short. &lt;br /&gt;
Let &amp;lt;math&amp;gt;2^S=\{T\mid T\subset S\}&amp;lt;/math&amp;gt; denote the set of all subset of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;power set&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We give a combinatorial proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. We observe that every subset &amp;lt;math&amp;gt;T\in 2^S&amp;lt;/math&amp;gt; corresponds to a unique bit-vector &amp;lt;math&amp;gt;v\in\{0,1\}^S&amp;lt;/math&amp;gt;, such that each bit &amp;lt;math&amp;gt;v_i&amp;lt;/math&amp;gt; indicates whether &amp;lt;math&amp;gt;x_i\in S&amp;lt;/math&amp;gt;. Formally, define a map &amp;lt;math&amp;gt;\phi:2^S\rightarrow\{0,1\}^n&amp;lt;/math&amp;gt; by &amp;lt;math&amp;gt;\phi(T)=(v_1,v_2,\ldots,v_n)&amp;lt;/math&amp;gt;, where&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
v_i=\begin{cases}&lt;br /&gt;
1 &amp;amp; \mbox{if }x_i\in T\\&lt;br /&gt;
0 &amp;amp; \mbox{if }x_i\not\in T.&lt;br /&gt;
\end{cases}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
The map &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a &#039;&#039;&#039;bijection&#039;&#039;&#039; (a 1-1 correspondence). The proof that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection is left as an exercise.&lt;br /&gt;
&lt;br /&gt;
Since there is a bijection between &amp;lt;math&amp;gt;2^S&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;\{0,1\}^n&amp;lt;/math&amp;gt;, it holds that &amp;lt;math&amp;gt;|2^S|=|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Here we apply &#039;&#039;&amp;quot;the rule of bijection&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of bijection&#039;&#039;&#039;: if there exists a bijection between finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;|P|=|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we know that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;? We use &#039;&#039;&amp;quot;the rule of product&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of product&#039;&#039;&#039;: for any finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the Cartesian product &amp;lt;math&amp;gt;|P\times Q|=|P|\cdot|Q|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To count the size of &amp;lt;math&amp;gt;\{0,1\}^n\,&amp;lt;/math&amp;gt;, we write &amp;lt;math&amp;gt;\{0,1\}^n=\{0,1\}\times\{0,1\}^{n-1}&amp;lt;/math&amp;gt;, thus &amp;lt;math&amp;gt;|\{0,1\}^n|=2|\{0,1\}^{n-1}|\,&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|\{0,1\}^n|=2^n\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two elements of the proof:&lt;br /&gt;
* Find a 1-1 correspondence between subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set and &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-bit vectors.&lt;br /&gt;
: An application of this in Computer Science is that we can use bit-array as a data structure for sets: any set defined over a &#039;&#039;&#039;universe&#039;&#039;&#039; &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; can be represented by an array of &amp;lt;math&amp;gt;|U|&amp;lt;/math&amp;gt; bits.&lt;br /&gt;
* The rule of bijection: if there is a 1-1 correspondence between two sets, then their cardinalities are the same.&lt;br /&gt;
&lt;br /&gt;
Many counting problems are solved by establishing a bijection between the set to be counted and some easy-to-count set. This kind of proofs are usually called (non-rigorously) &#039;&#039;&#039;combinatorial proofs&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
We give an alternative proof that &amp;lt;math&amp;gt;|2^S|=2^n&amp;lt;/math&amp;gt;. The proof needs another basic counting rule:  &#039;&#039;&amp;quot;the rule of sum&amp;quot;&#039;&#039;.&lt;br /&gt;
*&#039;&#039;&#039;The rule of sum&#039;&#039;&#039;: for any &#039;&#039;&#039;&#039;&#039;disjoint&#039;&#039;&#039;&#039;&#039; finite sets &amp;lt;math&amp;gt;P&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, the cardinality of the union &amp;lt;math&amp;gt;|P\cup Q|=|P|+|Q|&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Define the function &amp;lt;math&amp;gt;f(n)=|2^{S_n}|&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;S_n=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt; is an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set. Our goal is to compute &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;. We prove the following recursion for &amp;lt;math&amp;gt;f(n)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Lemma|&lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Fix an element &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; and let &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; be the set of subsets of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; that do not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt;. It is obvious that &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; are disjoint (i.e. &amp;lt;math&amp;gt;U\cap V=\emptyset&amp;lt;/math&amp;gt;) and &amp;lt;math&amp;gt;2^{S_n}=U\cup V&amp;lt;/math&amp;gt;, because any subset of &amp;lt;math&amp;gt;S_n&amp;lt;/math&amp;gt; either contains &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; or does not contain &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; but not both.  &lt;br /&gt;
&lt;br /&gt;
Applying the rule of sum, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U\cup V|=|U|+|V|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The next observation is that &amp;lt;math&amp;gt;|U|=|V|=f(n-1)&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; is exactly the &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;U&amp;lt;/math&amp;gt; is the set resulting from adding &amp;lt;math&amp;gt;x_n&amp;lt;/math&amp;gt; to every member of &amp;lt;math&amp;gt;2^{S_{n-1}}&amp;lt;/math&amp;gt;. Therefore, &lt;br /&gt;
:&amp;lt;math&amp;gt;f(n)=|U|+|V|=f(n-1)+f(n-1)=2f(n-1)\,&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
The elementary case &amp;lt;math&amp;gt;f(0)=1&amp;lt;/math&amp;gt;, because &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt; has only one subset &amp;lt;math&amp;gt;\emptyset&amp;lt;/math&amp;gt;. Solving the recursion, we have that &amp;lt;math&amp;gt;|2^S|=f(n)=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Subsets of fixed size ===&lt;br /&gt;
We then count the number of subsets of fixed size of a set. Again, 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;-set. We define &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; to be the set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-elements subsets (or &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets&#039;&#039;&#039;) of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;. Formally, &amp;lt;math&amp;gt;{S\choose k}=\{T\subseteq S\mid |T|=k\}&amp;lt;/math&amp;gt;. The set &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; is sometimes called the &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-uniform&#039;&#039;&#039; of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We denote that &amp;lt;math&amp;gt;{n\choose k}=\left|{S\choose k}\right|&amp;lt;/math&amp;gt;. The notation &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem|&lt;br /&gt;
:&amp;lt;math&amp;gt;{n\choose k}=\frac{n(n-1)\cdots(n-k+1)}{k(k-1)\cdots 1}=\frac{n!}{k!(n-k)!}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
The number of &#039;&#039;&#039;ordered&#039;&#039;&#039; &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)&amp;lt;/math&amp;gt;. Every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset has &amp;lt;math&amp;gt;k!=k(k-1)\cdots1&amp;lt;/math&amp;gt; ways to order it.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
;Some notations&lt;br /&gt;
* &amp;lt;math&amp;gt;n!&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factorial&amp;quot;, is defined as that &amp;lt;math&amp;gt;n!=n(n-1)(n-2)\cdots 1&amp;lt;/math&amp;gt;, with the convention that &amp;lt;math&amp;gt;0!=1&amp;lt;/math&amp;gt;.&lt;br /&gt;
* &amp;lt;math&amp;gt;n(n-1)\cdots(n-k+1)=\frac{n!}{(n-k)!}&amp;lt;/math&amp;gt; is usually denoted as &amp;lt;math&amp;gt;(n)_k\,&amp;lt;/math&amp;gt;, read &amp;quot;&amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; lower factorial &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called a &#039;&#039;&#039;binomial coefficient&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Proposition|&lt;br /&gt;
# &amp;lt;math&amp;gt;{n\choose k}={n\choose n-k}&amp;lt;/math&amp;gt;;&lt;br /&gt;
# &amp;lt;math&amp;gt;\sum_{k=0}^n {n\choose k}=2^n&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
1. We give two proofs for the first equation:&lt;br /&gt;
:(1) (numerical proof)&lt;br /&gt;
::&amp;lt;math&amp;gt;{n\choose k}=\frac{n!}{k!(n-k)!}={n\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
:(2) (combinatorial proof)&lt;br /&gt;
::Choosing &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements from an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set is equivalent to choosing the &amp;lt;math&amp;gt;n-k&amp;lt;/math&amp;gt; elements to leave out. Formally, every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;T\in{S\choose k}&amp;lt;/math&amp;gt; is uniquely specified by its complement &amp;lt;math&amp;gt;S\setminus T\in {S\choose n-k}&amp;lt;/math&amp;gt;, and the same holds for &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt;-subsets, thus we have a bijection between &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{S\choose n-k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
2. The second equation can also be proved in different ways, but the combinatorial proof is much easier. For an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-element set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, it is obvious that we can enumerate all subsets of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; by enumerating &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subsets for every possible size &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, i.e. it holds that&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
2^S=\bigcup_{k=0}^n{S\choose k}.&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
For different &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;{S\choose k}&amp;lt;/math&amp;gt; are obviously disjoint. By the rule of sum,&lt;br /&gt;
:&amp;lt;math&amp;gt;2^n=|2^S|=\left|\bigcup_{k=0}^n{S\choose k}\right|=\sum_{k=0}^n\left|{S\choose k}\right|=\sum_{k=0}^n {n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; is called binomial coefficient for a reason. A binomial is a polynomial with two terms (&amp;quot;poly-&amp;quot; means many, and &amp;quot;bi-&amp;quot; means two, like in &amp;quot;binary&amp;quot;, &amp;quot;bipartite&amp;quot;, etc). The following celebrated &#039;&#039;&#039;Binomial Theorem&#039;&#039;&#039; states that if a power of a binomial is expanded, the coefficients in the resulting polynomial are the binomial coefficients.&lt;br /&gt;
&lt;br /&gt;
{{Theorem|Theorem (Binomial theorem)|&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)^n=\sum_{k=0}^n{n\choose k}x^k&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Write &amp;lt;math&amp;gt;(1+x)^n&amp;lt;/math&amp;gt; as the product of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; factors&lt;br /&gt;
:&amp;lt;math&amp;gt;(1+x)(1+x)\cdots (1+x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
The term &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is obtained by choosing &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; from &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors and 1 from the rest &amp;lt;math&amp;gt;(n-k)&amp;lt;/math&amp;gt; factors. There are &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt; ways of choosing these &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; factors, so the coefficient of &amp;lt;math&amp;gt;x^k&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
The following proposition has an easy proof due to the binomial theorem.&lt;br /&gt;
{{Theorem| Proposition|&lt;br /&gt;
:For &amp;lt;math&amp;gt;n&amp;gt;0&amp;lt;/math&amp;gt;, the numbers of subsets of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set of even and of odd cardinality are equal.&lt;br /&gt;
}}&lt;br /&gt;
{{Proof|&lt;br /&gt;
Set &amp;lt;math&amp;gt;x=-1&amp;lt;/math&amp;gt; in the binomial theorem.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
0=(1-1)^n=\sum_{k=0}^n{n\choose k}(-1)^k=\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}-\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k},&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
therefore&lt;br /&gt;
:&amp;lt;math&amp;gt;\sum_{\overset{0\le k\le n}{k \text{ even}}}{n\choose k}=\sum_{\overset{0\le k\le n}{k \text{ odd}}}{n\choose k}.&amp;lt;/math&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
For counting problems, what we care about are &#039;&#039;numbers&#039;&#039;. In the binomial theorem, a formal &#039;&#039;variable&#039;&#039; &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; is introduced. It looks having nothing to do with our problem, but turns out to be very useful. This idea of introducing a formal variable is the basic idea of some advanced counting techniques, which will be discussed in future classes.&lt;br /&gt;
&lt;br /&gt;
=== Compositions of an integer ===&lt;br /&gt;
A &#039;&#039;&#039;composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is an expression of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; as an &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;ordered&#039;&#039;&amp;lt;/font&amp;gt; sum of &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&#039;&#039;positive&#039;&#039;&amp;lt;/font&amp;gt; integers. A &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; with exactly &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; positive summands. &lt;br /&gt;
&lt;br /&gt;
Formally, a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &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;(a_1,a_2,\ldots,a_k)\in\{1,2,\ldots,n\}^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;a_1+a_2+\cdots+a_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Suppose we have &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; identical balls in a line. A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition partitions these &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; balls into &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; &#039;&#039;nonempty&#039;&#039; sets, illustrated as follows.&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{array}{c|cc|c|c|ccc|cc}&lt;br /&gt;
\bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc &amp;amp;\, \bigcirc &amp;amp;\, \bigcirc \,&amp;amp;\, \bigcirc \,&amp;amp; \bigcirc&lt;br /&gt;
\end{array}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
So the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; equals the number of ways we put &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; bars &amp;quot;&amp;lt;math&amp;gt;|&amp;lt;/math&amp;gt;&amp;quot; into &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots &amp;quot;&amp;lt;math&amp;gt;\sqcup&amp;lt;/math&amp;gt;&amp;quot;, where each slot has at most one bar (because all the summands &amp;lt;math&amp;gt;a_i&amp;gt;0&amp;lt;/math&amp;gt;):&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc \sqcup \bigcirc&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
which is equal to the number of ways of choosing &amp;lt;math&amp;gt;k-1&amp;lt;/math&amp;gt; slots out of &amp;lt;math&amp;gt;n-1&amp;lt;/math&amp;gt; slots, which is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This graphic argument can be expressed as a formal proof. We construct a bijection between the set of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{\{1,2,\ldots,n-1\}\choose k-1}&amp;lt;/math&amp;gt; as follows. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; be a mapping that given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(a_1,a_2,\ldots,a_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
\phi((a_1,a_2,\ldots,a_k))&lt;br /&gt;
&amp;amp;=\{a_1,\,\,a_1+a_2,\,\,a_1+a_2+a_3,\,\,\ldots,\,\,a_1+a_2+\cdots+a_{k-1}\}\\&lt;br /&gt;
&amp;amp;=\left\{\sum_{i=1}^ja_i\,\,\bigg|\,\, 1\le j&amp;lt;k\right\}.&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; maps every &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition to a &amp;lt;math&amp;gt;(k-1)&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;\{1,2,\ldots,n-1\}&amp;lt;/math&amp;gt;. It is easy to verify that &amp;lt;math&amp;gt;\phi&amp;lt;/math&amp;gt; is a bijection, thus the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
The number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is equal to the number of &#039;&#039;positive&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. This suggests us to relax the constraint and count the number of &#039;&#039;nonnegative&#039;&#039; integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;. We call such a solution a &#039;&#039;&#039;weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition&#039;&#039;&#039; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Formally, a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a tuple &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)\in[n+1]^k&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k=n&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition &amp;lt;math&amp;gt;(x_1,x_2,\ldots,x_k)&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, if we set &amp;lt;math&amp;gt;y_i=x_i+1&amp;lt;/math&amp;gt; for every &amp;lt;math&amp;gt;1\le i\le k&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;y_i&amp;gt;0&amp;lt;/math&amp;gt; and &lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
y_1+y_2+\cdots +y_k&lt;br /&gt;
&amp;amp;=(x_1+1)+(x_2+1)+\cdots+(x_k+1)&amp;amp;=n+k,&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
i.e., &amp;lt;math&amp;gt;(y_1,y_2,\ldots,y_k)&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-composition of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. It is easy to see that it defines a bijection between weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n+k&amp;lt;/math&amp;gt;. Therefore, the number of weak &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;{n+k-1\choose k-1}&amp;lt;/math&amp;gt;.&lt;br /&gt;
----&lt;br /&gt;
We now count the number of nonnegative integer solutions to &amp;lt;math&amp;gt;x_1+x_2+\cdots+x_k\le n&amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;x_{k+1}=n-(x_1+x_2+\cdots+x_k)&amp;lt;/math&amp;gt;. Then &amp;lt;math&amp;gt;x_{k+1}\ge 0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;x_1+x_2+\ldots+x_k+x_{k+1}=n&amp;lt;/math&amp;gt;. &lt;br /&gt;
The problem is transformed to that counting the number of nonnegative integer solutions to the above equation. The answer is &amp;lt;math&amp;gt;{n+k\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multisets ===&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is sometimes called a &#039;&#039;&#039;&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; without repetitions&#039;&#039;&#039;. This suggests the problem of counting the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; &#039;&#039;&#039;&#039;&#039;with repetitions&#039;&#039;&#039;&#039;&#039;; that is, we choose &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; elements of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, disregarding order and allowing repeated elements. &lt;br /&gt;
&lt;br /&gt;
;Example&lt;br /&gt;
:&amp;lt;math&amp;gt;S=\{1,2,3,4\}&amp;lt;/math&amp;gt;. All &amp;lt;math&amp;gt;3&amp;lt;/math&amp;gt;-combination without repetitions are &lt;br /&gt;
::&amp;lt;math&amp;gt;\{1,2,3\},\{1,2,4\},\{1,3,4\},\{2,3,4\}\,&amp;lt;/math&amp;gt;. &lt;br /&gt;
:Allowing repetitions, we also include the following 3-combinations:&lt;br /&gt;
::&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{align}&lt;br /&gt;
&amp;amp;\{1,1,1\},\{1,1,2\},\{1,1,3\},\{1,1,4\},\{1,2,2\},\{1,3,3\},\{1,4,4\},\\&lt;br /&gt;
&amp;amp;\{2,2,2\},\{2,2,3\},\{2,2,4\},\{2,3,3\},\{2,4,4\},\\&lt;br /&gt;
&amp;amp;\{3,3,3\},\{3,3,4\},\{3,4,4\}\\&lt;br /&gt;
&amp;amp;\{4,4,4\}&lt;br /&gt;
\end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Combinations with repetitions can be formally defined as &#039;&#039;&#039;multisets&#039;&#039;&#039;. A multiset is a set with repeated elements. Formally, a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a function &amp;lt;math&amp;gt;m:S\rightarrow \mathbb{N}&amp;lt;/math&amp;gt;. For any element &amp;lt;math&amp;gt;x\in S&amp;lt;/math&amp;gt;, the integer &amp;lt;math&amp;gt;m(x)\ge 0&amp;lt;/math&amp;gt; is the number of repetitions of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; in &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt;, called the &#039;&#039;&#039;multiplicity&#039;&#039;&#039; of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;. The sum of multiplicities &amp;lt;math&amp;gt;\sum_{x\in S}m(x)&amp;lt;/math&amp;gt; is called the &#039;&#039;&#039;cardinality&#039;&#039;&#039; of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; and is denoted as &amp;lt;math&amp;gt;|M|&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on a set &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is a multiset &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;|M|=k&amp;lt;/math&amp;gt;. It is obvious that a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combination of &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; with repetition is simply a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The set of all &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multisets on &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt; is denoted &amp;lt;math&amp;gt;\left({S\choose k}\right)&amp;lt;/math&amp;gt;. Assuming that &amp;lt;math&amp;gt;n=|S|&amp;lt;/math&amp;gt;, denote &amp;lt;math&amp;gt;\left({n\choose k}\right)=\left|\left({S\choose k}\right)\right|&amp;lt;/math&amp;gt;, which is the number of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-combinations of an &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-set with repetitions.&lt;br /&gt;
&lt;br /&gt;
Believe it or not: we have already evaluated the number  &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt;. If &amp;lt;math&amp;gt;S=\{x_1,x_2,\ldots,x_n\}&amp;lt;/math&amp;gt;, let &amp;lt;math&amp;gt;z_i=m(x_i)&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;\left({n\choose k}\right)&amp;lt;/math&amp;gt; is the number of nonnegative integer solutions to &amp;lt;math&amp;gt;z_1+z_2+\cdots+z_n=k&amp;lt;/math&amp;gt;, which is the number of weak &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-compositions of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;, which we have seen is &amp;lt;math&amp;gt;{n+k-1\choose n-1}={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
There is a direct combinatorial proof that &amp;lt;math&amp;gt;\left({n\choose k}\right)={n+k-1\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset &amp;lt;math&amp;gt;0\le a_0\le a_1\le\cdots\le a_{k-1}\le n-1&amp;lt;/math&amp;gt; on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;b_i=a_i+i&amp;lt;/math&amp;gt;, we see that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;. Conversely, given a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-subset &amp;lt;math&amp;gt;0\le b_0\le b_1\le\cdots\le b_{k-1}\le n+k-2&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;[n+k-1]&amp;lt;/math&amp;gt;, then defining &amp;lt;math&amp;gt;a_i=b_i-i&amp;lt;/math&amp;gt;, we have that &amp;lt;math&amp;gt;\{b_0,b_1,\ldots,b_{k-1}\}&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;-multiset on &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt;. Therefore, we have a bijection between &amp;lt;math&amp;gt;\left({[n]\choose k}\right)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;{[n+k-1]\choose k}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Multinomial coefficients ===&lt;br /&gt;
&lt;br /&gt;
== Permutations and Partitions ==&lt;br /&gt;
&lt;br /&gt;
== The twelvfold way ==&lt;br /&gt;
We consider a very fundamental counting framework: counting functions &amp;lt;math&amp;gt;f:N\rightarrow M&amp;lt;/math&amp;gt;. We can define different counting problems according to the types of mapping (1-1, on-to, arbitrary), and the types of the domain and the range (distinguishable, indistinguishable).&lt;br /&gt;
* Distinguishability of set:&lt;br /&gt;
* Types of mapping:&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&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;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt;&lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Elements of &amp;lt;math&amp;gt;M&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Any &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Injective (1-1) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
!bgcolor=&amp;quot;#A7C1F2&amp;quot; | Surjective (on-to) &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m^n\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left(m\right)_n&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m!S(n, m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\left({m\choose n}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;{m\choose n}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;|&amp;lt;math&amp;gt;\left({m\choose n-m}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;distinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m S(n,k)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;S(n,m)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &#039;&#039;indistinguishable&#039;&#039;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\sum_{k=1}^m p_k(n)&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;\begin{cases}1 &amp;amp; \mbox{if }n\le m\\ 0&amp;amp; \mbox{if }n&amp;gt;m\end{cases}&amp;lt;/math&amp;gt;&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;p_m(n)\,&amp;lt;/math&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot;  cellspacing=&amp;quot;4&amp;quot; cellpadding=&amp;quot;10&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;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | balls per bin&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | unrestricted &lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≤ 1&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | ≥ 1&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-tuples &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-permutations &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; things&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partition of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; ordered parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; labeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;with repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-combinations of &amp;lt;math&amp;gt;[m]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt; without repetitions&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-compositions &amp;lt;br&amp;gt;of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; labeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;[n]&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|-&lt;br /&gt;
!align=&amp;quot;center&amp;quot; bgcolor=&amp;quot;#A7C1F2&amp;quot; | &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; unlabeled balls, &amp;lt;br&amp;gt;&amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; unlabeled bins&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;\le m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; pigeons &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; holes&lt;br /&gt;
|align=&amp;quot;center&amp;quot;| partitions of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; &amp;lt;br&amp;gt;into &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; parts&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
* &#039;&#039;Stanley,&#039;&#039; Enumerative Combinatorics, Volume 1, Chapter 1.&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Randomized_approximation_algorithms&amp;diff=2698</id>
		<title>Randomized Algorithms (Spring 2010)/Randomized approximation algorithms</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Randomized_approximation_algorithms&amp;diff=2698"/>
		<updated>2010-05-27T00:45:34Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Rounding LPs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Approximation Algorithms ==&lt;br /&gt;
&lt;br /&gt;
=== Coping with the NP-hardness ===&lt;br /&gt;
&lt;br /&gt;
=== Combinatorial approximation algorithms ===&lt;br /&gt;
&lt;br /&gt;
=== LP-based approximation algorithms ===&lt;br /&gt;
&lt;br /&gt;
== Randomized Rounding ==&lt;br /&gt;
&lt;br /&gt;
=== The integrality gap ===&lt;br /&gt;
&lt;br /&gt;
=== Randomized rounding ===&lt;br /&gt;
&lt;br /&gt;
=== Max-SAT ===&lt;br /&gt;
&lt;br /&gt;
=== Covering and Packing ===&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2428</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=2428"/>
		<updated>2010-05-21T17:08:11Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Volume estimation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Complexity model ===&lt;br /&gt;
&lt;br /&gt;
=== FPRAS ===&lt;br /&gt;
&lt;br /&gt;
== Approximate Counting ==&lt;br /&gt;
Let us consider the following formal 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;, &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.&lt;br /&gt;
&lt;br /&gt;
=== Permanents and perfect matchings ===&lt;br /&gt;
&lt;br /&gt;
=== Volume estimation  ===&lt;br /&gt;
&lt;br /&gt;
== Linear Programming ==&lt;br /&gt;
&lt;br /&gt;
=== LP and convex polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== The simplex algorithms ===&lt;br /&gt;
&lt;br /&gt;
=== An LP solver via random walks ===&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2427</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=2427"/>
		<updated>2010-05-21T16:44:30Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Counting DNFs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Complexity model ===&lt;br /&gt;
&lt;br /&gt;
=== FPRAS ===&lt;br /&gt;
&lt;br /&gt;
== Approximate Counting ==&lt;br /&gt;
Let us consider the following formal 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;, &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.&lt;br /&gt;
&lt;br /&gt;
=== Permanents and perfect matchings ===&lt;br /&gt;
&lt;br /&gt;
== Volume estimation  ==&lt;br /&gt;
&lt;br /&gt;
== Linear Programming ==&lt;br /&gt;
&lt;br /&gt;
=== LP and convex polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== The simplex algorithms ===&lt;br /&gt;
&lt;br /&gt;
=== An LP solver via random walks ===&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2426</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=2426"/>
		<updated>2010-05-21T15:30:59Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Approximate Counting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Complexity model ===&lt;br /&gt;
&lt;br /&gt;
=== FPRAS ===&lt;br /&gt;
&lt;br /&gt;
== Approximate Counting ==&lt;br /&gt;
Let us consider the following formal 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;, &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;
=== Permanents and perfect matchings ===&lt;br /&gt;
&lt;br /&gt;
== Volume estimation  ==&lt;br /&gt;
&lt;br /&gt;
== Linear Programming ==&lt;br /&gt;
&lt;br /&gt;
=== LP and convex polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== The simplex algorithms ===&lt;br /&gt;
&lt;br /&gt;
=== An LP solver via random walks ===&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2425</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=2425"/>
		<updated>2010-05-21T15:27:32Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Counting DNFs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Complexity model ===&lt;br /&gt;
&lt;br /&gt;
=== FPRAS ===&lt;br /&gt;
&lt;br /&gt;
== Approximate Counting ==&lt;br /&gt;
Let us consider the following formal 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;, &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.&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;
=== Permanents and perfect matchings ===&lt;br /&gt;
&lt;br /&gt;
== Volume estimation  ==&lt;br /&gt;
&lt;br /&gt;
== Linear Programming ==&lt;br /&gt;
&lt;br /&gt;
=== LP and convex polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== The simplex algorithms ===&lt;br /&gt;
&lt;br /&gt;
=== An LP solver via random walks ===&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Approximate_counting,_linear_programming&amp;diff=2424</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=2424"/>
		<updated>2010-05-21T14:17:14Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: /* Linear Programming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Counting Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Complexity model ===&lt;br /&gt;
&lt;br /&gt;
=== FPRAS ===&lt;br /&gt;
&lt;br /&gt;
== Approximate Counting ==&lt;br /&gt;
Let us consider the following formal 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;, &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.&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&lt;br /&gt;
:&amp;lt;math&amp;gt;|G|=|H|&amp;lt;/math&amp;gt;,&lt;br /&gt;
because there is an 1-1 correspondence between them.&lt;br /&gt;
&lt;br /&gt;
=== Permanents and perfect matchings ===&lt;br /&gt;
&lt;br /&gt;
== Volume estimation  ==&lt;br /&gt;
&lt;br /&gt;
== Linear Programming ==&lt;br /&gt;
&lt;br /&gt;
=== LP and convex polytopes ===&lt;br /&gt;
&lt;br /&gt;
=== The simplex algorithms ===&lt;br /&gt;
&lt;br /&gt;
=== An LP solver via random walks ===&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
	<entry>
		<id>https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Problem_Set_1&amp;diff=1695</id>
		<title>Randomized Algorithms (Spring 2010)/Problem Set 1</title>
		<link rel="alternate" type="text/html" href="https://tcs.nju.edu.cn/wiki/index.php?title=Randomized_Algorithms_(Spring_2010)/Problem_Set_1&amp;diff=1695"/>
		<updated>2010-03-28T12:55:37Z</updated>

		<summary type="html">&lt;p&gt;210.28.131.82: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
==Problem 1 (10 points)==&lt;br /&gt;
[MR]-1.1&lt;br /&gt;
&lt;br /&gt;
* Suppose that you are given a coin for which the probability of HEADS, say &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt;, is &#039;&#039;unknown&#039;&#039;. How can you use this coin to generate unbiased (i.e., &amp;lt;math&amp;gt;\Pr[\mathrm{HEADS}]=\Pr[\mathrm{TAILS}]=1/2&amp;lt;/math&amp;gt;) coin-flips? Give a scheme for which the expected number of flips of the biased coin for extracting one unbiased coin-flip is no more than &amp;lt;math&amp;gt;\frac{1}{p(1-p)}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
:(&#039;&#039;&#039;Hint&#039;&#039;&#039;: Consider two consecutive flips of the biased coin.)&lt;br /&gt;
&lt;br /&gt;
* (Bonus problem) Devise an extension of the scheme that extracts the largest possible number of independent, unbiased coin-flips from a given number of flips of the biased coin.&lt;br /&gt;
&lt;br /&gt;
==Problem 2 (10 points)==&lt;br /&gt;
The original Karger&#039;s algorithm returns a min-cut with probability &amp;lt;math&amp;gt;\ge\frac{2}{n(n-1)}&amp;lt;/math&amp;gt; after &amp;lt;math&amp;gt;n-2&amp;lt;/math&amp;gt; contractions.&lt;br /&gt;
We have seen that by running the original Karger&#039;s algorithm for multiple times, the probability of success can be improved. Consider the following variation. Starting with a graph with &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; vertices, first contract the graph down to &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices using Karger&#039;s algorithm. Make &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt; copies of the graph with &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; vertices, and now run Karger&#039;s algorithm independently on these &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt; copies. Return the smallest returned cut of these &amp;lt;math&amp;gt;\ell&amp;lt;/math&amp;gt; instances. &lt;br /&gt;
* What is the total number of contractions?&lt;br /&gt;
* What is the probability of finding a min-cut?&lt;br /&gt;
* Try to optimize the probability of success subject to the constraint of using no more than &amp;lt;math&amp;gt;2n&amp;lt;/math&amp;gt; contractions.&lt;br /&gt;
&lt;br /&gt;
==Problem 3 (10 points)==&lt;br /&gt;
Recall the following definitions:&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition 2:&#039;&#039;&#039; The class &#039;&#039;&#039;NP&#039;&#039;&#039; consists of all decision problems &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; that have a polynomial time deterministic algorithm &amp;lt;math&amp;gt;V&amp;lt;/math&amp;gt; such that for any input &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;,&lt;br /&gt;
:&amp;lt;math&amp;gt;f(x)=1&amp;lt;/math&amp;gt; if and only if &amp;lt;math&amp;gt;\exists y&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;V(x,y)=1&amp;lt;/math&amp;gt;, where the size of &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; is within polynomial of the size of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition 4:&#039;&#039;&#039; The class &#039;&#039;&#039;ZPP&#039;&#039;&#039; consists of all decision problems &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; that have a randomized algorithm &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; running in expected polynomial time for any input such that for any input &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;A(x)=f(x)&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&#039;&#039;&#039;Definition 5:&#039;&#039;&#039; The class &#039;&#039;&#039;RP&#039;&#039;&#039; consists of all decision problems &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; that have a randomized algorithm &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; running in worst-case polynomial time such that for any input &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt;,&lt;br /&gt;
*if &amp;lt;math&amp;gt;f(x)=1&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;\Pr[A(x)=1]\ge 1-1/2&amp;lt;/math&amp;gt;;&lt;br /&gt;
*if &amp;lt;math&amp;gt;f(x)=0&amp;lt;/math&amp;gt;, then &amp;lt;math&amp;gt;\Pr[A(x)=0]=1&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prove that &#039;&#039;&#039;ZPP&#039;&#039;&#039;&amp;lt;math&amp;gt;\subseteq&amp;lt;/math&amp;gt;&#039;&#039;&#039;NP&#039;&#039;&#039; and &#039;&#039;&#039;RP&#039;&#039;&#039;&amp;lt;math&amp;gt;\subseteq&amp;lt;/math&amp;gt;&#039;&#039;&#039;NP&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;&#039;Hint&#039;&#039;&#039;: Notice that a randomized algorithm &amp;lt;math&amp;gt;A&amp;lt;/math&amp;gt; on input &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; can be represented as a deterministic algorithm &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; with two inputs: &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; and a sequence &amp;lt;math&amp;gt;s&amp;lt;/math&amp;gt; of random bits.)&lt;br /&gt;
&lt;br /&gt;
==Problem 4 (10 points)==&lt;br /&gt;
A parallel computer consists of &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; processors and &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; memory modules. During a step, each processor sends a memory request to one of the memory modules, and each memory modul answer the request if it receives exactly one request. Note that a memory module may receive more than one requests. There are two schemes for dealing with conflicted memory requests:&lt;br /&gt;
# Upon receiving more than one requests, a memory module does not answer any request.&lt;br /&gt;
# Upon receiving more than one requests, a memory module answers one of the received requests.&lt;br /&gt;
Assuming that each processor sends a request to a memory module chosen uniformly and independently at random:&lt;br /&gt;
:(a) with the first scheme, what is the expected number of processors whose requests are answered?&lt;br /&gt;
:(b) with the second scheme, what is the expected number of processors whose requests are answered?&lt;br /&gt;
:(c) We upgrade the memory of the machine, so that a memory module that receives either one or two requests can answer its request(s); modules that receive more than two requests will answer two requests and discard the rest. What is the expected number of processors whose requests are answered?&lt;br /&gt;
&lt;br /&gt;
(You may assume the approximation &amp;lt;math&amp;gt;\left(1-\frac{1}{n}\right)^n\approx\frac{1}{e}&amp;lt;/math&amp;gt;.)&lt;/div&gt;</summary>
		<author><name>210.28.131.82</name></author>
	</entry>
</feed>