第 08 章

尾界、大数定律与概率方法

从 Markov 不等式出发,用平方技巧证明 Chebyshev 不等式,再由它推出弱大数定律;随后把尾界用于随机算法的错误率与赌博破产,并用「期望小于 1 就有正概率成功」证明 van der Waerden 数的下界。

Tail bounds, the law of large numbers and the probabilistic method

Markov's inequality gives a first bound from non-negativity alone; a squaring trick yields Chebyshev, which proves the weak law of large numbers. We apply these to the error rate of randomized algorithms and to gambler's ruin, then use 'expectation below one implies positive probability of success' to prove a lower bound for van der Waerden numbers.

首发于 2025.12.18中 / EN
系统课程probabilitytail-boundsconcentrationprobabilistic-method
语言
字号
目录
篇内目录

本讲要解决的问题

期望告诉你随机变量「平均」是多少,却不告诉你它有多容易偏离平均值。一个随机变量可以以极小概率取一个极大的值,把期望抬得很高,而绝大多数时候都贴近 00。

尾界要回答的是:随机变量离期望很远,概率有多大? 本讲按「用到的信息越来越多」这条线索推进:

用到的信息工具尾部衰减
非负 + 期望Markov1/C1/C
期望 + 方差Chebyshev1/C21/C^2
独立同分布弱大数定律概率 →0\to0
相互独立 + 全部矩Chernoff(下一讲)指数衰减

时间轴

时间内容
0:00回顾概率基础;尾界的动机
2:55Markov 不等式与证明
7:45非负性用在哪;反例
8:51Markov 的推论形式
10:36身高例子
15:40Chebyshev 不等式与证明
22:41身高的第二个例子
24:47弱大数定律的陈述
30:29证明:期望、方差与 Chebyshev
36:41赌博与破产
42:24随机算法的重复与错误率
50:42成对独立已经足够
51:55Chernoff 预告
56:48概率方法与 Ramsey 理论
1:08:20van der Waerden 定理与下界

Markov 不等式

定理。 设 X≥0X\ge0,则对任意 C>0C>0,

P(X≥C)≤E[X]C.\mathbb P(X\ge C)\le\frac{\mathbb E[X]}{C}.

证明。 用全期望公式,按事件 {X≥C}\{X\ge C\} 及其补集拆开:

E[X]=E[X∣X≥C]P(X≥C)+E[X∣X<C]P(X<C).\mathbb E[X] =\mathbb E\big[X\mid X\ge C\big]\mathbb P(X\ge C) +\mathbb E\big[X\mid X<C\big]\mathbb P(X<C).

第一项中,给定 X≥CX\ge C 时 XX 至少是 CC,故条件期望至少为 CC;第二项中 X≥0X\ge0,故条件期望非负。于是

E[X]≥C⋅P(X≥C),\mathbb E[X]\ge C\cdot\mathbb P(X\ge C),

两边除以 CC 即得。□\square

非负性用在哪里

只用在了「丢掉第二项」这一步。若 XX 可以取负值,E[X∣X<C]\mathbb E[X\mid X<C] 可能为负,丢掉它就不再是下界,不等式不成立。

反例:X=1X=1 与 X=−1X=-1 各以 1/21/2 的概率取值,则 E[X]=0\mathbb E[X]=0。取 C=1C=1,则

P(X≥1)=12>0=E[X]C.\mathbb P(X\ge1)=\tfrac12>0=\frac{\mathbb E[X]}{C}.

界彻底失效。期望为 00 时右边没有任何约束力。

推论形式

令 C′=C/E[X]C'=C/\mathbb E[X],即取 C=C′E[X]C=C'\mathbb E[X]:

P(X≥C′ E[X])≤1C′.\mathbb P\big(X\ge C'\,\mathbb E[X]\big)\le\frac{1}{C'}.

最常用的是 C′=2C'=2:非负随机变量超过其期望两倍的概率不超过 1/21/2。

身高例子

美国成年男性平均身高约 6969 英寸。于是

P(X≥2×69=138 英寸)≤12.\mathbb P(X\ge2\times69=138\text{ 英寸})\le\frac12 .

138138 英寸约合 1111 英尺 66 英寸。这个界在数学上正确,却没有实际意义——Markov 只用了期望,信息太少。身高例子贯穿全讲,用来衡量每个新工具进步了多少。

Chebyshev 不等式

定理。 对任意随机变量 XX(不要求非负),

P(∣X−E[X]∣≥C)≤Var⁡(X)C2.\mathbb P\big(|X-\mathbb E[X]|\ge C\big)\le\frac{\operatorname{Var}(X)}{C^2}.

证明。 两个技巧。

第一步:两个事件相同,因此概率相等。

∣X−E[X]∣≥C  ⟺  (X−E[X])2≥C2.|X-\mathbb E[X]|\ge C \iff \big(X-\mathbb E[X]\big)^2\ge C^2 .

第二步:制造一个非负随机变量,好使用 Markov。令

Y=(X−E[X])2≥0.Y=\big(X-\mathbb E[X]\big)^2\ge0 .

对 YY 用 Markov,阈值取 C2C^2:

P(Y≥C2)≤E[Y]C2=Var⁡(X)C2.\mathbb P(Y\ge C^2)\le\frac{\mathbb E[Y]}{C^2} =\frac{\operatorname{Var}(X)}{C^2}.

左边正是第一步的事件,证毕。□\square

推论形式

设 σ(X)=Var⁡(X)\sigma(X)=\sqrt{\operatorname{Var}(X)} 为标准差。取 C=cσ(X)C=c\sigma(X):

P(∣X−E[X]∣≥cσ(X))≤1c2.\mathbb P\big(|X-\mathbb E[X]|\ge c\sigma(X)\big)\le\frac{1}{c^2}.

c=2c=2 时:偏离两个标准差的概率不超过 1/41/4。

身高的第二个例子

已知男性身高标准差约 2.72.7 英寸,则 69+2×2.7=74.469+2\times2.7=74.4 英寸(约 66 英尺 2.42.4 英寸)以上(或对称地,以下)的概率不超过 1/41/4。

这个界仍然不紧,但至少不是「1111 英尺 66 英寸」这种荒谬结论。信息越多,界越紧——这是全讲的主题。

弱大数定律

陈述

固定 ε>0\varepsilon>0。设 X1,…,XnX_1,\dots,X_n 是某随机变量 XX 的独立同分布副本,E[X]=C\mathbb E[X]=C,方差有限。令

Sn=1n∑i=1nXi.S_n=\frac{1}{n}\sum_{i=1}^{n}X_i .

则

lim⁡n→∞P(∣Sn−C∣≥ε)=0.\lim_{n\to\infty}\mathbb P\big(|S_n-C|\ge\varepsilon\big)=0 .

量词顺序很重要:先固定精度 ε\varepsilon(例如民调误差 0.010.01),再找足够大的 nn。结论说「存在足够大的 nn 使概率任意小」,而不是「对所有 nn 都小」。

证明

第一步,估计均值。由线性期望,

E[Sn]=1n∑i=1nE[Xi]=C.\mathbb E[S_n]=\frac1n\sum_{i=1}^{n}\mathbb E[X_i]=C .

SnS_n 是 CC 的无偏估计。

第二步,估计方差——这是全证的关键。缩放一个随机变量时,方差乘以缩放的平方:

Var⁡(Sn)=1n2Var⁡(∑i=1nXi).\operatorname{Var}(S_n)=\frac{1}{n^2}\operatorname{Var}\Big(\sum_{i=1}^{n}X_i\Big).

这里必须用独立性:独立随机变量之和的方差等于方差之和。于是

Var⁡(∑i=1nXi)=∑i=1nVar⁡(Xi)=n σ2,\operatorname{Var}\Big(\sum_{i=1}^{n}X_i\Big)=\sum_{i=1}^{n}\operatorname{Var}(X_i)=n\,\sigma^2, Var⁡(Sn)=nσ2n2=σ2n.\operatorname{Var}(S_n)=\frac{n\sigma^2}{n^2}=\frac{\sigma^2}{n}.

第三步,用 Chebyshev:

P(∣Sn−C∣≥ε)≤Var⁡(Sn)ε2=σ2nε2→n→∞0.\mathbb P\big(|S_n-C|\ge\varepsilon\big) \le\frac{\operatorname{Var}(S_n)}{\varepsilon^2} =\frac{\sigma^2}{n\varepsilon^2}\xrightarrow[n\to\infty]{}0 .

定量版本

证明顺带给出了具体的 nn:要让失败概率不超过 δ\delta,只需

n≥σ2δ ε2.n\ge\frac{\sigma^2}{\delta\,\varepsilon^2}.

精度要求缩小 kk 倍,样本量要增加 k2k^2 倍。例如误差从 0.050.05 降到 0.010.01(缩小 55 倍),样本量要增加到 2525 倍。

赌博与破产

以掷骰子的 craps 为例,押注接近五五开,庄家优势(house edge)约 0.01410.0141。设每局赢 \1的概率为的概率为p,输,输 $1的概率为的概率为1-p$,则

(1−p)−p=0.0141⟹p=0.4929.(1-p)-p=0.0141 \Longrightarrow p=0.4929 .

每局的期望收益是

1⋅p+(−1)⋅(1−p)=2p−1=−0.0142<0.1\cdot p+(-1)\cdot(1-p)=2p-1=-0.0142<0 .

由弱大数定律,局数 nn 很大时,平均每局收益以概率 11 逼近 −0.0142-0.0142。累计收益约为 −0.0142n-0.0142n,随 nn 线性下降。

赌徒破产(gambler's ruin)的通俗表述:任何负期望的游戏,长期玩下去一定破产。直觉上你也许担心「万一运气特别好,一直赢呢」——大数定律说的正是:这种情形发生的概率趋于 00。

随机算法的失败概率

设随机算法 A\mathcal A 每次运行有 2/32/3 的概率给出正确答案,1/31/3 的概率出错。想知道「重复多少次,错误率才能降到可接受的水平」。

把第 ii 次运行的结果记为 Xi∈{0,1}X_i\in\{0,1\},Xi=1X_i=1 表示正确,E[Xi]=2/3\mathbb E[X_i]=2/3。取多数票,即看平均值 SnS_n 是否低于 1/21/2。失败意味着

∣Sn−23∣≥16.\Big|S_n-\tfrac23\Big|\ge\tfrac16 .

取 ε=1/9<16\varepsilon=1/9<\tfrac16,则失败事件包含在事件 {∣Sn−23∣≥ε}\{|S_n-\tfrac23|\ge\varepsilon\} 之中,所以对这个更大事件的上界也是失败概率的上界。

方差:

Var⁡(Xi)=23⋅13=29.\operatorname{Var}(X_i)=\tfrac23\cdot\tfrac13=\tfrac29 .

Chebyshev 给出

P(出错)≤2/9n⋅(1/9)2=2/9n/81=18n.\mathbb P(\text{出错})\le\frac{2/9}{n\cdot(1/9)^2}=\frac{2/9}{n/81}=\frac{18}{n}.

要让失败概率低于 10−1010^{-10},需要 n≈1.8×1011n\approx1.8\times10^{11} 次。这个数字在实际中不可接受——一台机器每秒跑十亿次也要跑几分钟到几小时。正是这个瓶颈促成了下一讲的 Chernoff 界:同样的目标只需 n=O(log⁡(1/δ))n=O(\log(1/\delta)) 次。

具体场景:素性测试

密码学中要判断一个大整数 qq 是否为素数。最好的算法是随机的,每次以 2/32/3 的概率给出正确答案。若把合数误判为素数,加密方案可能被攻破,代价是敏感信息泄露;因此需要失败概率低到 10−1010^{-10} 甚至 10−3010^{-30}。

用 Chebyshev 需要 101010^{10} 到 103010^{30} 次重复,不现实;Chernoff 把次数降到对数级,这才让随机素性测试成为工程上可用的方案。

成对独立已经够用

回看弱大数定律的证明,独立性只在方差相加这一步用到:

Var⁡(∑iXi)=∑iVar⁡(Xi)+2∑i<jCov⁡(Xi,Xj).\operatorname{Var}\Big(\sum_i X_i\Big)=\sum_i\operatorname{Var}(X_i)+2\sum_{i<j}\operatorname{Cov}(X_i,X_j).

只要每一对 Xi,XjX_i,X_j 独立,协方差全为 00,方差照样相加。成对独立就足够,不需要三元组、四元组的独立性。

这既是好消息(条件更弱),也是坏消息:Chebyshev 只用到二阶信息,因此给出的界偏松。下一讲的 Chernoff 界会用上「相互独立」这一更强条件,换取指数级的衰减。

Chernoff 界预告

设 X1,…,XnX_1,\dots,X_n 相互独立,Xi∈{0,1}X_i\in\{0,1\} 且 P(Xi=1)=pi\mathbb P(X_i=1)=p_i,令

X=∑i=1nXi,μ=E[X]=∑i=1npi.X=\sum_{i=1}^{n}X_i,\qquad \mu=\mathbb E[X]=\sum_{i=1}^{n}p_i .

则对 0<δ<10<\delta<1,

P(∣X−μ∣≥δμ)≤2e−μδ2/3.\mathbb P\big(|X-\mu|\ge\delta\mu\big)\le2e^{-\mu\delta^2/3}.

右边随 μ\mu(也就是随 nn)指数衰减,而不是 1/n1/n 这种多项式衰减。证明在下一讲。

概率方法

核心思想

要证明某类组合对象存在,不直接构造它,而是证明「随机选一个,以正概率满足要求」。

引理。 设 XX 是非负整数值随机变量,且 E[X]<1\mathbb E[X]<1。则 P(X=0)>0\mathbb P(X=0)>0。

证明。 由期望的定义并按 ii 拆项:

E[X]=∑i≥0i P(X=i)≥∑i≥1i P(X=i)≥∑i≥1P(X=i)=1−P(X=0).\mathbb E[X]=\sum_{i\ge0}i\,\mathbb P(X=i) \ge\sum_{i\ge1}i\,\mathbb P(X=i) \ge\sum_{i\ge1}\mathbb P(X=i) =1-\mathbb P(X=0).

于是 P(X=0)≥1−E[X]>0\mathbb P(X=0)\ge1-\mathbb E[X]>0。□\square

用法:让 XX 数「坏事件」的个数。只要坏事件的期望个数小于 11,就存在一个对象,一个坏事件都没有。

Ramsey:六人聚会

任意六个人中,必有三个人两两相识,或者三个人两两陌生。用图论说:对 K6K_6 的边任意染两色,必存在单色三角形。这就是 Ramsey 数 R(3,3)=6R(3,3)=6。

Ramsey 理论的一般形态是:足够大的对象中,某些有序子结构无法避免。课上还提到「圣经密码」——在《托拉》中按等距取字母能「找到」名人名字与日期;这其实是 Ramsey 现象的伪装,同样的「发现」在《战争与和平》的希伯来文译本里也能找到,并不具有统计显著性。

van der Waerden 定理

kk 项等差数列是形如

a, a+b, a+2b, …, a+(k−1)ba,\ a+b,\ a+2b,\ \dots,\ a+(k-1)b

的整数集合。

定理(van der Waerden)。 对任意 kk,存在 nn,使得把 1,2,…,n1,2,\dots,n 任意染成红蓝两色,都必然出现一个单色的 kk 项等差数列。

把最小的这样的 nn 记为 W(k)W(k)。已知 W(3)=9W(3)=9:11 到 88 可以染色避开三项等差,11 到 99 不行。

下面的染色(R 红、B 蓝)在 11 到 88 上避开了所有三项等差数列:

1,2,3,4,5,6,7,8  ⟼  R,R,B,B,R,R,B,B.1,2,3,4,5,6,7,8 \;\longmapsto\; R,R,B,B,R,R,B,B .

逐一检查公差 b=1,2,3b=1,2,3 的所有三项等差即可验证。而要证明 11 到 99 无法避免,需要穷举所有染色——这正是计算机暴力搜索的用武之地。

下界:随机染色

定理。 对任意 k≥2k\ge2,

W(k)≥k−1⋅2(k−1)/2.W(k)\ge\sqrt{k-1}\cdot2^{(k-1)/2}.

证明。 取 n<k−1⋅2(k−1)/2n<\sqrt{k-1}\cdot2^{(k-1)/2},对 [n][n] 做独立均匀的随机红蓝染色。设 XX 为单色 kk 项等差数列的个数。

对每一个具体的等差数列 Qa,bQ_{a,b},令 Ia,bI_{a,b} 为其单色指示变量。第一个元素颜色任意,其余 k−1k-1 个必须与它相同:

E[Ia,b]=P(Qa,b 单色)=22k=12k−1.\mathbb E[I_{a,b}]=\mathbb P(Q_{a,b}\text{ 单色})=\frac{2}{2^k}=\frac{1}{2^{k-1}}.

落在 [n][n] 内的等差数列个数:起点 a≤na\le n,公差 b≤nk−1b\le\dfrac{n}{k-1}(否则末项超过 nn),故至多

n⋅nk−1=n2k−1.n\cdot\frac{n}{k-1}=\frac{n^2}{k-1}.

由期望的线性性(不需要独立性):

E[X]≤n2k−1⋅12k−1.\mathbb E[X]\le\frac{n^2}{k-1}\cdot\frac{1}{2^{k-1}}.

当 n<k−1⋅2(k−1)/2n<\sqrt{k-1}\cdot2^{(k-1)/2} 时,

E[X]<(k−1)2k−1k−1⋅12k−1=1.\mathbb E[X]<\frac{(k-1)2^{k-1}}{k-1}\cdot\frac{1}{2^{k-1}}=1 .

由概率方法引理,P(X=0)>0\mathbb P(X=0)>0:存在一种染色,没有任何单色 kk 项等差数列。因此 W(k)>nW(k)>n,取下确界即得所述下界。□\square

这个证明的妙处在于:我们不知道那种染色长什么样,却知道它一定存在。概率方法把「构造」问题转化成了「算期望」问题。

本节结论

  • Markov:X≥0X\ge0 时 P(X≥C)≤E[X]/C\mathbb P(X\ge C)\le\mathbb E[X]/C;非负性用在丢掉第二项。
  • Chebyshev:P(∣X−EX∣≥C)≤Var⁡(X)/C2\mathbb P(|X-\mathbb E X|\ge C)\le\operatorname{Var}(X)/C^2;平方造出非负变量。
  • 弱大数定律:独立同分布、方差有限时,样本均值依概率收敛到期望;独立性用于方差相加。
  • 定量地,n≥σ2/(δε2)n\ge\sigma^2/(\delta\varepsilon^2);精度提高 kk 倍需要样本量提高 k2k^2 倍。
  • 负期望游戏长期必输(赌徒破产)。
  • 随机算法重复 nn 次,Chebyshev 给出 O(1/n)O(1/n) 的失败率,实际不够用。
  • 概率方法:E[X]<1\mathbb E[X]<1 且 XX 非负整数值 ⇒\Rightarrow 存在 X=0X=0 的对象。
  • van der Waerden:W(k)≥k−1 2(k−1)/2W(k)\ge\sqrt{k-1}\,2^{(k-1)/2},随机染色证明。

理解检验

1. Markov 不等式的证明中,非负性用在哪一步?构造一个去掉非负性后不等式失效的例子。

参考答案:全期望分解 E[X]=E[X∣X≥C]P(X≥C)+E[X∣X<C]P(X<C)\mathbb E[X]=\mathbb E[X\mid X\ge C]\mathbb P(X\ge C)+\mathbb E[X\mid X<C]\mathbb P(X<C) 之后,第一项至少是 CP(X≥C)C\mathbb P(X\ge C),第二项被直接丢掉——只有在 X≥0X\ge0 时第二项才非负,丢掉它才是「减小」。若 XX 可取负值,第二项可能为负,E[X]≥CP(X≥C)\mathbb E[X]\ge C\mathbb P(X\ge C) 不成立。反例:P(X=1)=P(X=−1)=1/2\mathbb P(X=1)=\mathbb P(X=-1)=1/2,E[X]=0\mathbb E[X]=0;取 C=1C=1,则 P(X≥1)=1/2\mathbb P(X\ge1)=1/2,而 E[X]/C=0\mathbb E[X]/C=0,不等式失效。

2. 完整写出 Chebyshev 的证明:事件等价是什么?新随机变量怎么定义?为什么可以用 Markov?

参考答案:事件 {∣X−EX∣≥C}\{|X-\mathbb E X|\ge C\} 与事件 {(X−EX)2≥C2}\{(X-\mathbb E X)^2\ge C^2\} 完全相同,因此概率相等。令 Y=(X−EX)2Y=(X-\mathbb E X)^2,它是平方,故 Y≥0Y\ge0,满足 Markov 的非负性要求。对 YY 在阈值 C2C^2 处用 Markov: P(Y≥C2)≤E[Y]/C2=Var⁡(X)/C2\mathbb P(Y\ge C^2)\le\mathbb E[Y]/C^2=\operatorname{Var}(X)/C^2。 而左边就是原事件的概率,证毕。

3. 弱大数定律的证明中,独立性用在哪一步?为什么成对独立就够?

参考答案:独立性只用在 Var⁡(∑iXi)=∑iVar⁡(Xi)\operatorname{Var}(\sum_i X_i)=\sum_i\operatorname{Var}(X_i) 这一步。一般地, Var⁡(∑iXi)=∑iVar⁡(Xi)+2∑i<jCov⁡(Xi,Xj)\operatorname{Var}(\sum_iX_i)=\sum_i\operatorname{Var}(X_i)+2\sum_{i<j}\operatorname{Cov}(X_i,X_j), 而成对独立保证每个 Cov⁡(Xi,Xj)=0\operatorname{Cov}(X_i,X_j)=0,于是方差仍然相加。因此只需要成对独立,不需要所有子集的相互独立。

4. 用 Chebyshev 估计「重复运行 2/3 正确率的算法 n 次、多数投票」的失败率,并算出达到 10−1010^{-10} 所需的 nn。

参考答案:XiX_i 为第 ii 次是否正确,Var⁡(Xi)=23⋅13=29\operatorname{Var}(X_i)=\frac23\cdot\frac13=\frac29。多数投票失败意味着 Sn<1/2S_n<1/2,即 ∣Sn−23∣>1/6|S_n-\frac23|>1/6。取 ε=19\varepsilon=\frac19,失败事件包含于 {∣Sn−23∣≥19}\{|S_n-\frac23|\ge\frac19\},Chebyshev 给出 P(失败)≤2/9n⋅(1/81)=18n\mathbb P(\text{失败})\le\frac{2/9}{n\cdot(1/81)}=\frac{18}{n}。 令 18/n≤10−1018/n\le10^{-10},得 n≥1.8×1011n\ge1.8\times10^{11},约 101110^{11} 量级,实践上不可行。

5. 证明概率方法引理:XX 非负整数值且 E[X]<1\mathbb E[X]<1,则 P(X=0)>0\mathbb P(X=0)>0。

参考答案: E[X]=∑i≥0iP(X=i)≥∑i≥1iP(X=i)≥∑i≥1P(X=i)=1−P(X=0)\mathbb E[X]=\sum_{i\ge0}i\mathbb P(X=i)\ge\sum_{i\ge1}i\mathbb P(X=i)\ge\sum_{i\ge1}\mathbb P(X=i)=1-\mathbb P(X=0)。 因此 P(X=0)≥1−E[X]>0\mathbb P(X=0)\ge1-\mathbb E[X]>0。直观上,若 X=0X=0 几乎不可能,XX 就几乎总是至少 11,期望不可能小于 11。

6. 用随机染色证明 van der Waerden 的下界,写出期望计算的每一步。

参考答案:取 n<k−1 2(k−1)/2n<\sqrt{k-1}\,2^{(k-1)/2},每个整数独立均匀染红或蓝。设 XX 为单色 kk 项等差数列的个数。对固定等差列,首项颜色有 22 种选择,其余 k−1k-1 项必须同色,故单色概率为 2/2k=2−(k−1)2/2^k=2^{-(k-1)}。落在 [n][n] 内的等差列个数至多 n⋅nk−1n\cdot\frac{n}{k-1}(起点至多 nn 种,公差至多 n/(k−1)n/(k-1) 种)。由线性期望, E[X]≤n2k−12−(k−1)<(k−1)2k−1k−12−(k−1)=1\mathbb E[X]\le\frac{n^2}{k-1}2^{-(k-1)}<\frac{(k-1)2^{k-1}}{k-1}2^{-(k-1)}=1。 由引理,存在一种染色使 X=0X=0,即无单色 kk 项等差列,故 W(k)>nW(k)>n。

7. 为什么 11 到 88 上的染色 RRBBRRBBRRBBRRBB 只证明了 W(3)≥9W(3)\ge9,而不是 W(3)=9W(3)=9?

参考答案:给出一个染色避开三项等差,只说明「n=8n=8 时存在坏染色」,即 W(3)>8W(3)>8,也就是 W(3)≥9W(3)\ge9。要证明 W(3)≤9W(3)\le9,必须证明 11 到 99 的每一种红蓝染色都含有单色三项等差——这是对 29=5122^9=512 种染色的穷举检验,无法用单个例子代替。

与前后课的关系

上一讲是生成函数;本讲回到概率,建立尾界的工具箱。下一讲证明 Chernoff 界,把尾部衰减从多项式提升到指数级,并说明为什么「相互独立」这个更强条件换来如此大的收益。

再往后依次进入模运算、群论与编码理论。概率方法本身会在后续单元反复出现——它是离散数学里证明「存在性」的标准武器。

What this lecture is for

Expectation tells you what a random variable averages, not how likely it is to drift away from that average. A variable may take a huge value with tiny probability, inflating the expectation while almost always staying near 00.

A tail bound answers: how likely is a random variable to be far from its expectation? The lecture is organised around using more and more information:

Information usedToolTail decay
Non-negativity and expectationMarkov1/C1/C
Expectation and varianceChebyshev1/C21/C^2
Independent, identically distributedWeak lawprobability →0\to0
Mutual independence, all momentsChernoff (next lecture)exponential

Timeline

TimeTopic
0:00Probability recap; why tail bounds
2:55Markov's inequality and proof
7:45Where non-negativity is used; a counterexample
8:51The corollary form of Markov
10:36The height example
15:40Chebyshev's inequality and proof
22:41A second height example
24:47Statement of the weak law
30:29Proof via expectation, variance and Chebyshev
36:41Gambling and ruin
42:24Repeating randomized algorithms
50:42Pairwise independence suffices
51:55Chernoff preview
56:48The probabilistic method and Ramsey theory
1:08:20van der Waerden's theorem and a lower bound

Markov's inequality

Theorem. If X≥0X\ge0, then for every C>0C>0,

P(X≥C)≤E[X]C.\mathbb P(X\ge C)\le\frac{\mathbb E[X]}{C}.

Proof. Split the expectation by the law of total expectation:

E[X]=E[X∣X≥C]P(X≥C)+E[X∣X<C]P(X<C).\mathbb E[X] =\mathbb E\big[X\mid X\ge C\big]\mathbb P(X\ge C) +\mathbb E\big[X\mid X<C\big]\mathbb P(X<C).

Given X≥CX\ge C, the conditional expectation is at least CC; given X<CX<C, non-negativity makes the conditional expectation at least 00. Hence

E[X]≥C⋅P(X≥C),\mathbb E[X]\ge C\cdot\mathbb P(X\ge C),

and dividing by CC completes the proof. □\square

Where non-negativity is used

Only in dropping the second term. If XX can be negative, E[X∣X<C]\mathbb E[X\mid X<C] may be negative, and discarding it is no longer a lower bound.

Counterexample: let X=1X=1 and X=−1X=-1 each with probability 1/21/2, so E[X]=0\mathbb E[X]=0. With C=1C=1,

P(X≥1)=12>0=E[X]C.\mathbb P(X\ge1)=\tfrac12>0=\frac{\mathbb E[X]}{C}.

The bound fails completely. When the expectation is zero the right side constrains nothing.

Corollary form

Put C′=C/E[X]C'=C/\mathbb E[X], i.e. C=C′E[X]C=C'\mathbb E[X]:

P(X≥C′ E[X])≤1C′.\mathbb P\big(X\ge C'\,\mathbb E[X]\big)\le\frac{1}{C'}.

The most quoted case is C′=2C'=2: a non-negative variable exceeds twice its expectation with probability at most 1/21/2.

The height example

The average US male height is about 6969 inches. Hence

P(X≥2×69=138 inches)≤12.\mathbb P(X\ge2\times69=138\text{ inches})\le\frac12 .

That is about 1111 feet 66 inches. The bound is mathematically correct but practically useless — Markov uses only the expectation. The height example runs through the lecture as a yardstick for each new tool.

Chebyshev's inequality

Theorem. For any random variable XX (non-negativity not required),

P(∣X−E[X]∣≥C)≤Var⁡(X)C2.\mathbb P\big(|X-\mathbb E[X]|\ge C\big)\le\frac{\operatorname{Var}(X)}{C^2}.

Proof. Two tricks.

First, the two events are the same, so their probabilities are equal:

∣X−E[X]∣≥C  ⟺  (X−E[X])2≥C2.|X-\mathbb E[X]|\ge C \iff \big(X-\mathbb E[X]\big)^2\ge C^2 .

Second, manufacture a non-negative variable so Markov applies. Let

Y=(X−E[X])2≥0.Y=\big(X-\mathbb E[X]\big)^2\ge0 .

Apply Markov to YY with threshold C2C^2:

P(Y≥C2)≤E[Y]C2=Var⁡(X)C2.\mathbb P(Y\ge C^2)\le\frac{\mathbb E[Y]}{C^2} =\frac{\operatorname{Var}(X)}{C^2}.

The left side is the event from step one. □\square

Corollary form

Let σ(X)=Var⁡(X)\sigma(X)=\sqrt{\operatorname{Var}(X)} be the standard deviation. Taking C=cσ(X)C=c\sigma(X),

P(∣X−E[X]∣≥cσ(X))≤1c2.\mathbb P\big(|X-\mathbb E[X]|\ge c\sigma(X)\big)\le\frac{1}{c^2}.

For c=2c=2: the probability of straying two standard deviations is at most 1/41/4.

The second height example

Male height has standard deviation about 2.72.7 inches, so the probability of exceeding 69+2×2.7=74.469+2\times2.7=74.4 inches (about 66 feet 2.42.4 inches), or symmetrically falling below, is at most 1/41/4.

Still loose, but no longer absurd — nothing like the 1111-foot-66 answer. More information yields tighter bounds, the theme of the lecture.

The weak law of large numbers

Statement

Fix ε>0\varepsilon>0. Let X1,…,XnX_1,\dots,X_n be independent copies of a random variable XX with E[X]=C\mathbb E[X]=C and finite variance, and let

Sn=1n∑i=1nXi.S_n=\frac{1}{n}\sum_{i=1}^{n}X_i .

Then

lim⁡n→∞P(∣Sn−C∣≥ε)=0.\lim_{n\to\infty}\mathbb P\big(|S_n-C|\ge\varepsilon\big)=0 .

The order of quantifiers matters: fix the accuracy ε\varepsilon first (say a polling error of 0.010.01), then find a large enough nn. The claim is not that the probability is small for every nn, but that a sufficiently large nn exists.

Proof

First, the mean. By linearity,

E[Sn]=1n∑i=1nE[Xi]=C.\mathbb E[S_n]=\frac1n\sum_{i=1}^{n}\mathbb E[X_i]=C .

So SnS_n is an unbiased estimator of CC.

Second, the variance — the heart of the proof. Scaling a random variable by a constant scales the variance by its square:

Var⁡(Sn)=1n2Var⁡(∑i=1nXi).\operatorname{Var}(S_n)=\frac{1}{n^2}\operatorname{Var}\Big(\sum_{i=1}^{n}X_i\Big).

Independence enters here: the variance of a sum of independent variables is the sum of the variances. Hence

Var⁡(∑i=1nXi)=∑i=1nVar⁡(Xi)=n σ2,\operatorname{Var}\Big(\sum_{i=1}^{n}X_i\Big)=\sum_{i=1}^{n}\operatorname{Var}(X_i)=n\,\sigma^2, Var⁡(Sn)=nσ2n2=σ2n.\operatorname{Var}(S_n)=\frac{n\sigma^2}{n^2}=\frac{\sigma^2}{n}.

Third, Chebyshev:

P(∣Sn−C∣≥ε)≤Var⁡(Sn)ε2=σ2nε2→n→∞0.\mathbb P\big(|S_n-C|\ge\varepsilon\big) \le\frac{\operatorname{Var}(S_n)}{\varepsilon^2} =\frac{\sigma^2}{n\varepsilon^2}\xrightarrow[n\to\infty]{}0 .

A quantitative version

The proof also yields a concrete sample size: to make the failure probability at most δ\delta, it suffices that

n≥σ2δ ε2.n\ge\frac{\sigma^2}{\delta\,\varepsilon^2}.

Cutting the error by a factor kk multiplies the sample size by k2k^2. Going from 0.050.05 to 0.010.01 (a factor of 55) needs 2525 times as many samples.

Gambling and ruin

In craps, the closest bet to even money has a house edge of about 0.01410.0141. Let each round win \1withprobabilitywith probabilitypandloseand lose$1$ otherwise. Then

(1−p)−p=0.0141⟹p=0.4929.(1-p)-p=0.0141 \Longrightarrow p=0.4929 .

The expected gain per round is

1⋅p+(−1)⋅(1−p)=2p−1=−0.0142<0.1\cdot p+(-1)\cdot(1-p)=2p-1=-0.0142<0 .

By the weak law, for large nn the average gain per round approaches −0.0142-0.0142 with probability 11, so cumulative winnings fall roughly linearly at −0.0142n-0.0142n.

Gambler's ruin, informally: a game with negative expectation eventually bankrupts you. One might hope for a lucky streak, but the law of large numbers says the probability of sustaining one vanishes.

Failure probability of randomized algorithms

Suppose a randomized algorithm A\mathcal A returns the correct answer with probability 2/32/3 and an incorrect one with probability 1/31/3. How many repetitions are needed to make the error rate acceptable?

Let Xi∈{0,1}X_i\in\{0,1\} indicate a correct run, so E[Xi]=2/3\mathbb E[X_i]=2/3. Take a majority vote, i.e. check whether the average SnS_n falls below 1/21/2. Failure implies

∣Sn−23∣≥16.\Big|S_n-\tfrac23\Big|\ge\tfrac16 .

Choose ε=1/9<16\varepsilon=1/9<\tfrac16; then the failure event is contained in {∣Sn−23∣≥ε}\{|S_n-\tfrac23|\ge\varepsilon\}, so a bound on the larger event bounds the failure probability. Since

Var⁡(Xi)=23⋅13=29,\operatorname{Var}(X_i)=\tfrac23\cdot\tfrac13=\tfrac29 ,

Chebyshev gives

P(failure)≤2/9n⋅(1/9)2=2/9n/81=18n.\mathbb P(\text{failure})\le\frac{2/9}{n\cdot(1/9)^2}=\frac{2/9}{n/81}=\frac{18}{n}.

To push the failure probability below 10−1010^{-10} requires n≈1.8×1011n\approx1.8\times10^{11} repetitions — impractical. This bottleneck motivates the Chernoff bound of the next lecture, which achieves the same target with n=O(log⁡(1/δ))n=O(\log(1/\delta)).

A concrete setting: primality testing

Cryptography needs to decide whether a large integer qq is prime. The best algorithms are randomized and answer correctly with probability 2/32/3. Mistaking a composite for a prime can break the scheme and leak sensitive data, so failure probabilities of 10−1010^{-10} or even 10−3010^{-30} are wanted.

Chebyshev demands 101010^{10} to 103010^{30} repetitions, which is hopeless; Chernoff reduces the count to a logarithmic factor, making randomized primality testing practical.

Pairwise independence suffices

Look back at the proof of the weak law. Independence is used only to add variances:

Var⁡(∑iXi)=∑iVar⁡(Xi)+2∑i<jCov⁡(Xi,Xj).\operatorname{Var}\Big(\sum_i X_i\Big)=\sum_i\operatorname{Var}(X_i)+2\sum_{i<j}\operatorname{Cov}(X_i,X_j).

If every pair is independent, all covariances vanish and the variances still add. Pairwise independence is enough; no triple or quadruple independence is needed.

That is both good news (a weaker hypothesis) and bad news (Chebyshev uses only second-order information, so the bound is loose). The Chernoff bound will use full mutual independence and buy exponential decay.

Chernoff preview

Let X1,…,XnX_1,\dots,X_n be mutually independent with Xi∈{0,1}X_i\in\{0,1\} and P(Xi=1)=pi\mathbb P(X_i=1)=p_i, and let

X=∑i=1nXi,μ=E[X]=∑i=1npi.X=\sum_{i=1}^{n}X_i,\qquad \mu=\mathbb E[X]=\sum_{i=1}^{n}p_i .

Then for 0<δ<10<\delta<1,

P(∣X−μ∣≥δμ)≤2e−μδ2/3.\mathbb P\big(|X-\mu|\ge\delta\mu\big)\le2e^{-\mu\delta^2/3}.

The right side decays exponentially in μ\mu (hence in nn), not polynomially like 1/n1/n. The proof is the subject of the next lecture.

The probabilistic method

The core idea

To prove that an object of a certain kind exists, do not construct it; prove that a random object satisfies the requirement with positive probability.

Lemma. Let XX be a non-negative integer-valued random variable with E[X]<1\mathbb E[X]<1. Then P(X=0)>0\mathbb P(X=0)>0.

Proof. By definition, grouping by the value of XX:

E[X]=∑i≥0i P(X=i)≥∑i≥1i P(X=i)≥∑i≥1P(X=i)=1−P(X=0).\mathbb E[X]=\sum_{i\ge0}i\,\mathbb P(X=i) \ge\sum_{i\ge1}i\,\mathbb P(X=i) \ge\sum_{i\ge1}\mathbb P(X=i) =1-\mathbb P(X=0).

So P(X=0)≥1−E[X]>0\mathbb P(X=0)\ge1-\mathbb E[X]>0. □\square

Usage: let XX count bad events. If the expected number of bad events is below 11, some object has none.

Ramsey: six people at a party

Among any six people, either three are pairwise acquainted or three are pairwise strangers. In graph language: in any two-colouring of the edges of K6K_6 there is a monochromatic triangle. This is the Ramsey number R(3,3)=6R(3,3)=6.

Ramsey theory in general: in a large enough object, certain ordered substructures cannot be avoided. The lecture also mentions the "Bible codes" — equally spaced letters in the Torah supposedly revealing names and dates. That is Ramsey theory in disguise: the same "discoveries" appear in a Hebrew translation of War and Peace and carry no statistical significance.

van der Waerden's theorem

A kk-term arithmetic progression is a set of integers

a, a+b, a+2b, …, a+(k−1)b.a,\ a+b,\ a+2b,\ \dots,\ a+(k-1)b .

Theorem (van der Waerden). For every kk there is an nn such that every red-blue colouring of 1,2,…,n1,2,\dots,n contains a monochromatic kk-term arithmetic progression.

Let W(k)W(k) be the least such nn. It is known that W(3)=9W(3)=9: 11 through 88 can be coloured to avoid three-term progressions, 11 through 99 cannot.

The following colouring (R red, B blue) avoids every three-term progression on 1,…,81,\dots,8:

1,2,3,4,5,6,7,8  ⟼  R,R,B,B,R,R,B,B.1,2,3,4,5,6,7,8 \;\longmapsto\; R,R,B,B,R,R,B,B .

One checks all progressions with common difference b=1,2,3b=1,2,3. Proving that 1,…,91,\dots,9 admits no such colouring requires exhaustive search over all colourings.

A lower bound by random colouring

Theorem. For every k≥2k\ge2,

W(k)≥k−1⋅2(k−1)/2.W(k)\ge\sqrt{k-1}\cdot2^{(k-1)/2}.

Proof. Take n<k−1⋅2(k−1)/2n<\sqrt{k-1}\cdot2^{(k-1)/2} and colour [n][n] independently and uniformly red or blue. Let XX count monochromatic kk-term progressions.

For a fixed progression Qa,bQ_{a,b}, let Ia,bI_{a,b} indicate that it is monochromatic. The first element may have either colour and the other k−1k-1 must match it:

E[Ia,b]=P(Qa,b monochromatic)=22k=12k−1.\mathbb E[I_{a,b}]=\mathbb P(Q_{a,b}\text{ monochromatic})=\frac{2}{2^k}=\frac{1}{2^{k-1}}.

The number of progressions inside [n][n]: the starting point satisfies a≤na\le n, and the common difference satisfies b≤nk−1b\le\dfrac{n}{k-1} (otherwise the last term exceeds nn). So there are at most

n⋅nk−1=n2k−1.n\cdot\frac{n}{k-1}=\frac{n^2}{k-1}.

By linearity of expectation (no independence needed),

E[X]≤n2k−1⋅12k−1.\mathbb E[X]\le\frac{n^2}{k-1}\cdot\frac{1}{2^{k-1}}.

For n<k−1⋅2(k−1)/2n<\sqrt{k-1}\cdot2^{(k-1)/2},

E[X]<(k−1)2k−1k−1⋅12k−1=1.\mathbb E[X]<\frac{(k-1)2^{k-1}}{k-1}\cdot\frac{1}{2^{k-1}}=1 .

The lemma then gives P(X=0)>0\mathbb P(X=0)>0: some colouring has no monochromatic kk-term progression. Hence W(k)>nW(k)>n, and taking the supremum over admissible nn yields the stated bound. □\square

The remarkable feature: we never learn what that colouring looks like, only that it must exist. The probabilistic method turns a construction problem into an expectation computation.

What this lecture establishes

  • Markov: for X≥0X\ge0, P(X≥C)≤E[X]/C\mathbb P(X\ge C)\le\mathbb E[X]/C; non-negativity is used to drop the second term.
  • Chebyshev: P(∣X−EX∣≥C)≤Var⁡(X)/C2\mathbb P(|X-\mathbb E X|\ge C)\le\operatorname{Var}(X)/C^2; squaring creates a non-negative variable.
  • Weak law: with i.i.d. finite-variance variables, the sample mean converges in probability to the expectation; independence is used to add variances.
  • Quantitatively n≥σ2/(δε2)n\ge\sigma^2/(\delta\varepsilon^2): a kk-fold accuracy gain costs k2k^2 times the samples.
  • Negative-expectation games ruin the player in the long run.
  • Repeating a randomized algorithm nn times, Chebyshev gives an O(1/n)O(1/n) failure rate — insufficient in practice.
  • Probabilistic method: if X≥0X\ge0 is integer-valued with E[X]<1\mathbb E[X]<1, some outcome has X=0X=0.
  • van der Waerden: W(k)≥k−1 2(k−1)/2W(k)\ge\sqrt{k-1}\,2^{(k-1)/2}, proved by random colouring.

Comprehension check

1. Where does the proof of Markov's inequality use non-negativity? Give a counterexample showing the inequality fails without it.

Reference answer: After the total-expectation split E[X]=E[X∣X≥C]P(X≥C)+E[X∣X<C]P(X<C)\mathbb E[X]=\mathbb E[X\mid X\ge C]\mathbb P(X\ge C)+\mathbb E[X\mid X<C]\mathbb P(X<C), the first term is at least CP(X≥C)C\mathbb P(X\ge C) and the second is discarded — discarding is only a lowering step when the second term is non-negative, which requires X≥0X\ge0. Without non-negativity the inequality E[X]≥CP(X≥C)\mathbb E[X]\ge C\mathbb P(X\ge C) can fail. Counterexample: P(X=1)=P(X=−1)=1/2\mathbb P(X=1)=\mathbb P(X=-1)=1/2, so E[X]=0\mathbb E[X]=0; with C=1C=1, P(X≥1)=1/2\mathbb P(X\ge1)=1/2 while E[X]/C=0\mathbb E[X]/C=0.

2. Write out the proof of Chebyshev: what is the event equivalence, what is the new variable, and why may Markov be applied?

Reference answer: The events {∣X−EX∣≥C}\{|X-\mathbb E X|\ge C\} and {(X−EX)2≥C2}\{(X-\mathbb E X)^2\ge C^2\} are identical, hence have equal probability. Set Y=(X−EX)2Y=(X-\mathbb E X)^2, which is a square and therefore non-negative, so Markov applies. Applying Markov to YY at threshold C2C^2, P(Y≥C2)≤E[Y]/C2=Var⁡(X)/C2\mathbb P(Y\ge C^2)\le\mathbb E[Y]/C^2=\operatorname{Var}(X)/C^2. The left side is the original event, completing the proof.

3. Where does the proof of the weak law use independence? Why is pairwise independence enough?

Reference answer: Independence is used only in Var⁡(∑iXi)=∑iVar⁡(Xi)\operatorname{Var}(\sum_iX_i)=\sum_i\operatorname{Var}(X_i). In general Var⁡(∑iXi)=∑iVar⁡(Xi)+2∑i<jCov⁡(Xi,Xj)\operatorname{Var}(\sum_iX_i)=\sum_i\operatorname{Var}(X_i)+2\sum_{i<j}\operatorname{Cov}(X_i,X_j), and pairwise independence makes every covariance zero, so variances still add. Triple or higher-order independence is never used.

4. Use Chebyshev to bound the failure probability of majority vote over nn runs of a 2/32/3-correct algorithm, and compute the nn needed for 10−1010^{-10}.

Reference answer: Let XiX_i indicate a correct run, so Var⁡(Xi)=23⋅13=29\operatorname{Var}(X_i)=\frac23\cdot\frac13=\frac29. Majority vote fails when Sn<1/2S_n<1/2, i.e. ∣Sn−23∣>1/6|S_n-\frac23|>1/6. Taking ε=19\varepsilon=\frac19, the failure event lies inside {∣Sn−23∣≥19}\{|S_n-\frac23|\ge\frac19\}, so Chebyshev gives P(failure)≤2/9n⋅(1/81)=18n\mathbb P(\text{failure})\le\frac{2/9}{n\cdot(1/81)}=\frac{18}{n}. Requiring 18/n≤10−1018/n\le10^{-10} gives n≥1.8×1011n\ge1.8\times10^{11} — impractical.

5. Prove the probabilistic-method lemma: if X≥0X\ge0 is integer-valued and E[X]<1\mathbb E[X]<1, then P(X=0)>0\mathbb P(X=0)>0.

Reference answer: E[X]=∑i≥0iP(X=i)≥∑i≥1iP(X=i)≥∑i≥1P(X=i)=1−P(X=0)\mathbb E[X]=\sum_{i\ge0}i\mathbb P(X=i)\ge\sum_{i\ge1}i\mathbb P(X=i)\ge\sum_{i\ge1}\mathbb P(X=i)=1-\mathbb P(X=0). Hence P(X=0)≥1−E[X]>0\mathbb P(X=0)\ge1-\mathbb E[X]>0. Intuitively, if X=0X=0 were almost impossible then XX would almost always be at least 11, and the expectation could not be below 11.

6. Prove the van der Waerden lower bound by random colouring, showing each step of the expectation computation.

Reference answer: Take n<k−1 2(k−1)/2n<\sqrt{k-1}\,2^{(k-1)/2} and colour each integer independently red or blue with probability 1/21/2. Let XX count monochromatic kk-term progressions. For a fixed progression, the first term has 22 colour choices and the remaining k−1k-1 must match, so the monochromatic probability is 2/2k=2−(k−1)2/2^k=2^{-(k-1)}. The number of progressions inside [n][n] is at most n⋅nk−1n\cdot\frac{n}{k-1} (at most nn starting points, at most n/(k−1)n/(k-1) common differences). Linearity of expectation gives E[X]≤n2k−12−(k−1)<(k−1)2k−1k−12−(k−1)=1\mathbb E[X]\le\frac{n^2}{k-1}2^{-(k-1)}<\frac{(k-1)2^{k-1}}{k-1}2^{-(k-1)}=1. The lemma then guarantees a colouring with X=0X=0, i.e. no monochromatic kk-term progression, so W(k)>nW(k)>n.

7. Why does the colouring RRBBRRBBRRBBRRBB on 11–88 prove only W(3)≥9W(3)\ge9, not W(3)=9W(3)=9?

Reference answer: Exhibiting one colouring without a three-term progression only shows that n=8n=8 is not enough, i.e. W(3)>8W(3)>8, hence W(3)≥9W(3)\ge9. To prove W(3)≤9W(3)\le9 one must show that every red-blue colouring of 1,…,91,\dots,9 contains a monochromatic three-term progression — a check over all 29=5122^9=512 colourings, which a single example cannot replace.

Relation to neighbouring lectures

The previous lecture concerned generating functions; this one returns to probability and builds the tail-bound toolkit. The next lecture proves the Chernoff bound, lifting tail decay from polynomial to exponential, and explains why the stronger hypothesis of mutual independence buys so much.

The course then moves to modular arithmetic, group theory and coding theory. The probabilistic method itself recurs throughout the remaining units — it is the standard tool for proving existence in discrete mathematics.

来源