math-skill 1.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en-US.md +313 -0
- package/README.md +313 -278
- package/agents/math-critic.en.md +235 -0
- package/agents/math-critic.md +237 -203
- package/commands/abstraction.md +11 -34
- package/commands/algorithmic-thinking.md +11 -34
- package/commands/ask.md +18 -21
- package/commands/axiomatization.md +11 -34
- package/commands/causal-inference.md +11 -34
- package/commands/discrete-combinatorial.md +11 -34
- package/commands/game-theory.md +11 -34
- package/commands/induction-analogy.md +11 -34
- package/commands/information-theory.md +11 -34
- package/commands/logic-deduction.md +11 -34
- package/commands/modeling.md +11 -37
- package/commands/optimization.md +11 -33
- package/commands/probability-statistics.md +11 -36
- package/commands/symmetry-invariance.md +11 -34
- package/commands/topological-thinking.md +11 -33
- package/commands/transformation.md +11 -33
- package/knowledge-base/overview.en.md +228 -0
- package/knowledge-base/overview.md +230 -230
- package/package.json +73 -59
- package/references/agentic-workflow.en.md +53 -0
- package/references/agentic-workflow.md +55 -0
- package/references/books/abstract-algebra.md +124 -0
- package/references/books/algebraic-geometry-rising-sea.md +171 -0
- package/references/books/differential-geometry.md +140 -0
- package/references/books/matrix-analysis.md +146 -0
- package/references/books/micro-lie-theory.md +116 -0
- package/references/books/optimization-ml.md +164 -0
- package/references/books/smooth-manifolds.md +105 -0
- package/references/gpu-friendly-math.en.md +65 -0
- package/references/gpu-friendly-math.md +67 -0
- package/references/inspiration.en.md +113 -0
- package/{docs → references}/inspiration.md +2 -0
- package/skills/abstraction/SKILL.en.md +117 -0
- package/skills/abstraction/SKILL.md +121 -264
- package/skills/abstraction/original-texts.en.md +163 -0
- package/skills/algorithmic-thinking/SKILL.en.md +132 -0
- package/skills/algorithmic-thinking/SKILL.md +138 -371
- package/skills/algorithmic-thinking/original-texts.en.md +253 -0
- package/skills/axiomatization/SKILL.en.md +144 -0
- package/skills/axiomatization/SKILL.md +151 -213
- package/skills/axiomatization/original-texts.en.md +154 -0
- package/skills/causal-inference/SKILL.en.md +147 -0
- package/skills/causal-inference/SKILL.md +151 -374
- package/skills/causal-inference/original-texts.en.md +136 -0
- package/skills/discrete-combinatorial/SKILL.en.md +124 -0
- package/skills/discrete-combinatorial/SKILL.md +131 -286
- package/skills/discrete-combinatorial/original-texts.en.md +184 -0
- package/skills/game-theory/SKILL.en.md +117 -0
- package/skills/game-theory/SKILL.md +123 -318
- package/skills/game-theory/original-texts.en.md +131 -0
- package/skills/induction-analogy/SKILL.en.md +145 -0
- package/skills/induction-analogy/SKILL.md +152 -310
- package/skills/induction-analogy/original-texts.en.md +140 -0
- package/skills/information-theory/SKILL.en.md +134 -0
- package/skills/information-theory/SKILL.md +140 -242
- package/skills/information-theory/original-texts.en.md +127 -0
- package/skills/logic-deduction/SKILL.en.md +130 -0
- package/skills/logic-deduction/SKILL.md +135 -280
- package/skills/logic-deduction/original-texts.en.md +160 -0
- package/skills/math-research-activator/SKILL.en.md +132 -0
- package/skills/math-research-activator/SKILL.md +136 -0
- package/skills/math-research-activator/original-texts.en.md +105 -0
- package/skills/{meta-selector → math-research-activator}/original-texts.md +104 -104
- package/skills/modeling/SKILL.en.md +135 -0
- package/skills/modeling/SKILL.md +139 -318
- package/skills/modeling/original-texts.en.md +162 -0
- package/skills/optimization/SKILL.en.md +129 -0
- package/skills/optimization/SKILL.md +135 -292
- package/skills/optimization/original-texts.en.md +167 -0
- package/skills/probability-statistics/SKILL.en.md +146 -0
- package/skills/probability-statistics/SKILL.md +151 -312
- package/skills/probability-statistics/original-texts.en.md +191 -0
- package/skills/symmetry-invariance/SKILL.en.md +135 -0
- package/skills/symmetry-invariance/SKILL.md +139 -358
- package/skills/symmetry-invariance/original-texts.en.md +206 -0
- package/skills/topological-thinking/SKILL.en.md +124 -0
- package/skills/topological-thinking/SKILL.md +128 -273
- package/skills/topological-thinking/original-texts.en.md +134 -0
- package/skills/transformation/SKILL.en.md +120 -0
- package/skills/transformation/SKILL.md +124 -264
- package/skills/transformation/original-texts.en.md +204 -0
- package/docs/CLAUDE.md +0 -187
- package/skills/meta-selector/SKILL.md +0 -188
|
@@ -1,286 +1,131 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: discrete-combinatorial
|
|
3
|
-
description: |
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
>
|
|
15
|
-
>
|
|
16
|
-
>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
>
|
|
27
|
-
>
|
|
28
|
-
>
|
|
29
|
-
>
|
|
30
|
-
>
|
|
31
|
-
>
|
|
32
|
-
>
|
|
33
|
-
>
|
|
34
|
-
>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
###
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
### 第二步:应用基本计数原理 / Apply Basic Counting Principles
|
|
134
|
-
|
|
135
|
-
**科研模式**:
|
|
136
|
-
- **乘法原理 (Multiplication Principle)**:k 个独立选择 → k₁ × k₂ × ... × k_n 种结果。每步独立,总数相乘。
|
|
137
|
-
- **加法原理 (Addition Principle)**:互斥选项 → 总数相加。|A∪B| = |A| + |B|(当 A∩B = ∅)。
|
|
138
|
-
- **鸽巢原理 (Pigeonhole Principle)**:n > m 时碰撞不可避免。将 n 个物品放入 m 个盒子(n > m),则某盒子至少含 ⌈n/m⌉ 个物品。推广:将 kn+1 个物品放入 n 个盒子,则某盒子至少含 k+1 个物品。
|
|
139
|
-
|
|
140
|
-
应用要点:先判断选择是否独立(乘法)还是互斥(加法),再判断是否需要存在性结论(鸽巢)。
|
|
141
|
-
|
|
142
|
-
**生活模式**:粗略估计有多少种可能——"很多"还是"只有几种"?如果选项比需要分配的数量多,必然有选项被重复选择(鸽巢原理的生活版)。
|
|
143
|
-
|
|
144
|
-
**共通要点**:无论正式计算还是粗略估计,判断数量规模是决策的关键输入。
|
|
145
|
-
|
|
146
|
-
---
|
|
147
|
-
|
|
148
|
-
### 第三步:使用容斥原理 / Apply Inclusion-Exclusion
|
|
149
|
-
|
|
150
|
-
**科研模式**:
|
|
151
|
-
|
|
152
|
-
|A₁∪A₂∪...∪A_n| = Σ|A_i| − Σ|A_i∩A_j| + Σ|A_i∩A_j∩A_k| − ... ± |A₁∩...∩A_n|
|
|
153
|
-
|
|
154
|
-
容斥原理处理交集重叠的计数——直接相加会重复计算交集,容斥逐层修正。
|
|
155
|
-
|
|
156
|
-
**补集计数 (Complement counting)**:当直接计数困难时,计数补集。"不具有性质 P 的数量" = 全部 − "具有性质 P 的数量"。经典实例:错排数 D(n) = n! − C(n,1)(n−1)! + C(n,2)(n−2)! − ... ± C(n,n)·0!,即"所有元素都不在原位" = 全排列 − "至少一个在原位"。
|
|
157
|
-
|
|
158
|
-
**符号规则**:奇数个集合的交集取正号,偶数个集合的交集取负号。第 k 层贡献 = (−1)^{k+1} Σ|A_{i₁}∩...∩A_{i_k}|。
|
|
159
|
-
|
|
160
|
-
**生活模式**:有重叠的情况怎么算?——不是简单地相加,重叠部分要扣除。A或B的情况 = A的情况 + B的情况 − 同时是A和B的情况。
|
|
161
|
-
|
|
162
|
-
**共通要点**:重叠修正是一般性原则——不修正重叠就是错误估计。
|
|
163
|
-
|
|
164
|
-
---
|
|
165
|
-
|
|
166
|
-
### 第四步:构造生成函数 / Construct Generating Functions
|
|
167
|
-
|
|
168
|
-
**科研模式**:
|
|
169
|
-
- **常生成函数 (OGF)**:A(x) = Σa_n x^n。适用于无序选择、组合计数。系数 a_n 是第 n 项的计数。乘法:A(x)·C(x) 的系数 = Σa_i·c_{n−i}(组合两个独立的计数)。
|
|
170
|
-
- **指数生成函数 (EGF)**:B(x) = Σb_n x^n/n!。适用于有序选择、排列计数、有标号对象。乘法:B(x)·D(x) 的系数/n! = Σ(b_i/i!)·(d_{n−i}/(n−i)!)(排列两个有标号集合)。
|
|
171
|
-
|
|
172
|
-
经典实例:
|
|
173
|
-
- 分拆函数生成函数:P(x) = Σp(n)x^n = 1/((1−x)(1−x²)(1−x³)...),分拆 = 无限制地选择1、2、3、...的组合。
|
|
174
|
-
- Catalan 数生成函数:C(x) = ΣC_n x^n = (1−√(1−4x))/(2x),由递推 C_n = ΣC_i·C_{n−1−i} 得 C(x) = 1 + x·C(x)²。
|
|
175
|
-
|
|
176
|
-
**生活模式**:有没有一个系统的方法来追踪所有可能性?——用结构化的方式列出所有选项,而不是逐个枚举。
|
|
177
|
-
|
|
178
|
-
**共通要点**:结构化追踪优于随机枚举——这是组合效率的核心。
|
|
179
|
-
|
|
180
|
-
---
|
|
181
|
-
|
|
182
|
-
### 第五步:分析图结构 / Analyze Graph Structure
|
|
183
|
-
|
|
184
|
-
**科研模式**:
|
|
185
|
-
|
|
186
|
-
图 G = (V, E):顶点集 V,边集 E。
|
|
187
|
-
|
|
188
|
-
核心属性与分析:
|
|
189
|
-
- **顶点与边**:|V| 个顶点,|E| 条边;度数 deg(v);邻接矩阵、关联矩阵
|
|
190
|
-
- **路径与连通**:路径、回路、连通分量;最短路径(Dijkstra, Floyd-Warshall)
|
|
191
|
-
- **树与森林**:n 顶点的树恰有 n−1 条边;生成树(Kruskal, Prim 最小生成树);二叉树计数 C_n
|
|
192
|
-
- **平面图**:Euler 公式 V − E + F = 2(连通平面图);平面图必满足 E ≤ 3V − 6
|
|
193
|
-
- **着色**:色数 χ(G) = 最少颜色数使相邻顶点不同色;四色定理 χ(平面图) ≤ 4
|
|
194
|
-
- **匹配**:二分图匹配(Hall 婚姻定理);最大匹配、完美匹配;König 定理:二分图中最大匹配 = 最小顶点覆盖
|
|
195
|
-
- **环与割**:Euler 环(每边恰好一次 iff 连通且所有度数为偶);Hamilton 环(每顶点恰好一次,NP-complete)
|
|
196
|
-
|
|
197
|
-
**生活模式**:事物之间的关系是什么?——谁和谁连接,连接的方式是什么,整体的结构是什么样的?
|
|
198
|
-
|
|
199
|
-
**共通要点**:关系结构决定可行方案——理解连接方式是理解系统的前提。
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
### 第六步:发现递推与封闭公式 / Discover Recurrence and Closed Formula
|
|
204
|
-
|
|
205
|
-
**科研模式**:
|
|
206
|
-
- **递推关系 (Recurrence)**:Catalan 数 C_n = ΣC_i·C_{n−1−i},Fibonacci F_n = F_{n−1} + F_{n−2},错排 D_n = (n−1)(D_{n−1} + D_{n−2})
|
|
207
|
-
- **通过生成函数求解**:将递推乘以 x^n,对 n 求和,解出 A(x),再提取 a_n 的封闭公式。例如 Fibonacci:F(x) = x/(1−x−x²),部分分式分解得 F_n = (φ^n − ψ^n)/√5(φ = (1+√5)/2)。
|
|
208
|
-
- **直接公式**:当组合结构有清晰解释时可直接推导。C(n,k) = n!/(k!(n−k)!) 来自"n 选 k 无序"的计数;Catalan C_n = C(2n,n)/(n+1) 来自"合法括号序列"的组合论证。
|
|
209
|
-
|
|
210
|
-
**生活模式**:找到规律——如果知道前几步的结果,能否推导下一步?规律一旦找到就不需要逐个计算。
|
|
211
|
-
|
|
212
|
-
**共通要点**:规律发现是效率的来源——从已知推导未知优于逐个计算。
|
|
213
|
-
|
|
214
|
-
---
|
|
215
|
-
|
|
216
|
-
### 第七步:验证与推广 / Verify and Generalize
|
|
217
|
-
|
|
218
|
-
**科研模式**:
|
|
219
|
-
- **检查小案例**:n=0, 1, 2, 3 时公式是否给出正确计数?手动枚举验证。
|
|
220
|
-
- **验证公式计数正确**:公式的值是否等于实际枚举数?递推是否自洽?边界条件是否正确?
|
|
221
|
-
- **推广规律**:公式是否对所有 n 成立?是否可推广到更一般的参数?是否有更深的组合解释?
|
|
222
|
-
|
|
223
|
-
> **验证不是可选的——未经验证的计数公式是不可信的。** n=3 的手动枚举与公式的对比是最低验证要求。
|
|
224
|
-
|
|
225
|
-
**生活模式**:验证你的枚举是否完整——有没有遗漏的选项?结论能否推广到类似情况?
|
|
226
|
-
|
|
227
|
-
**共通要点**:验证是必须的——遗漏一个选项或一个规律反例就足以推翻整个推理。
|
|
228
|
-
|
|
229
|
-
## 常见错误 / Common Errors
|
|
230
|
-
|
|
231
|
-
| 错误 / Error | 数学批评 / Mathematical Critique | 正确做法 / Correct Approach | 标签 |
|
|
232
|
-
|---|---|---|---|
|
|
233
|
-
| 漏计与重计 (Under/Overcounting) | 漏计:遗漏约束的交互导致少计;重计:同一配置被多次计算 | 明确约束交互,用容斥修正重计,用补集计数修正漏计 | `[科研]` |
|
|
234
|
-
| 忽略约束条件的交互作用 | 约束不是独立的,交集的影响必须用容斥处理 | 用容斥原理:|A₁∪A₂| = |A₁| + |A₂| − |A₁∩A₂| | `[科研]` |
|
|
235
|
-
| 混淆排列与组合 | 排列计序 P(n,k) = n!/(n−k)!,组合不计序 C(n,k) = n!/(k!(n−k)!) | 先判断有序/无序,再选择公式 | `[通用]` |
|
|
236
|
-
| 错误使用容斥原理的符号 | 奇数层取正、偶数层取负,符号错误导致结果偏差 | 严格按 (−1)^{k+1} 规定符号:第 k 层交集取 (−1)^{k+1} | `[科研]` |
|
|
237
|
-
| 忽略生成函数的收敛域 | 生成函数作为形式幂级数可忽略收敛,但提取封闭公式需收敛域内操作 | 区分形式幂级数操作与解析操作;封闭公式提取需 x 在收敛域内 | `[科研]` |
|
|
238
|
-
| 混淆有标号与无标号计数 | 有标号用指数生成函数 Σb_n x^n/n!,无标号用常生成函数 Σa_n x^n | 有标号(排列/分布)→ EGF;无标号(组合/分拆)→ OGF | `[科研]` |
|
|
239
|
-
| 鸽巢原理使用不当 | 仅证明存在性,不构造具体实例;且需 n > m 条件才成立 | 确认 n > m 条件满足,结论为"至少一个"而非"恰好一个" | `[通用]` |
|
|
240
|
-
| 递推边界条件错误 | C₀ = 1(空结构计数为 1)而非 C₀ = 0;F₀ = 0, F₁ = 1 | 空结构 = 1(空排列、空组合各一种),检查 n=0,1 边界 | `[科研]` |
|
|
241
|
-
| 枚举遗漏 (Enumeration omission) | 列出选项时遗漏某些可能性,导致决策基础不完整 | 系统性枚举:按类别分组,检查每组是否完整 | `[生活]` |
|
|
242
|
-
| 忽略重叠情况 (Ignoring overlap) | 多个选项同时满足时简单相加,导致过度估计 | A或B的情况 = A的情况 + B的情况 − 重叠部分 | `[生活]` |
|
|
243
|
-
| 逐个尝试而非找规律 (Trial-by-trial instead of pattern) | 逐个检查所有选项而不是发现规律,效率低且易遗漏 | 先看前几步能否推导规律,有规律就不需要逐个计算 | `[生活]` |
|
|
244
|
-
|
|
245
|
-
## 操作规程 / Operating Procedure
|
|
246
|
-
|
|
247
|
-
当本 skill 被触发时,执行以下具体步骤:
|
|
248
|
-
|
|
249
|
-
**模式选择 / Mode Selector**:
|
|
250
|
-
- 若问题涉及正式计数、公式推导、存在性证明、生成函数 → **科研模式**
|
|
251
|
-
- 若问题涉及日常选择、有限选项枚举、规律发现、关系分析 → **生活模式**
|
|
252
|
-
|
|
253
|
-
---
|
|
254
|
-
|
|
255
|
-
### 科研模式输出格式 / Research Mode Output Format
|
|
256
|
-
|
|
257
|
-
1. **结构识别**:[结构]: [离散对象描述] — 明确计数对象、约束、分类
|
|
258
|
-
2. **计数类型**:[计数类型]: [排列/组合/分割/安排] — 判断有序/无序、有标号/无标号
|
|
259
|
-
3. **原理选择**:[原理]: [乘法/加法/鸽巢/容斥] — 说明选择理由
|
|
260
|
-
4. **生成函数**:[生成函数]: [公式] — 列出 GF 及其代数性质
|
|
261
|
-
5. **图结构**:[图结构]: [属性] — 顶点、边、连通性、着色等(如涉及)
|
|
262
|
-
6. **递推/公式**:[递推/公式]: [具体内容] — 递推关系及封闭公式
|
|
263
|
-
7. **验证**:[验证]: [小案例检查] — 至少 n=0,1,2,3 的手动枚举与公式对比
|
|
264
|
-
|
|
265
|
-
**输出必须包含以上 7 项,不得只输出分析性文字而不给出结论。**
|
|
266
|
-
|
|
267
|
-
---
|
|
268
|
-
|
|
269
|
-
### 生活模式输出格式 / Life Mode Output Format
|
|
270
|
-
|
|
271
|
-
1. **[问题类型]:[分类]** — 有限选择/排列/分配/关系
|
|
272
|
-
2. **[可能数量]:[粗略估计]** — 选项很多还是只有几种
|
|
273
|
-
3. **[系统性枚举]:[方法]** — 有没有遗漏
|
|
274
|
-
4. **[关系结构]:[分析]** — 事物之间的连接方式
|
|
275
|
-
5. **[规律发现]:[模式]** — 能否从已知推导未知
|
|
276
|
-
6. **[行动建议]:[步骤]** — 基于枚举和规律的结论
|
|
277
|
-
|
|
278
|
-
**输出必须包含以上 6 项,不得只输出分析性文字而不给出结论。**
|
|
279
|
-
|
|
280
|
-
## 与其他 skill 的关系 / Relations to Other Skills
|
|
281
|
-
|
|
282
|
-
- **归纳与类比**:组合规律由归纳发现——从枚举 {a_n} 的前几项归纳出递推,再类比到更一般结构
|
|
283
|
-
- **算法思想**:组合计数支撑复杂度分析——n! 排列、C(n,k) 组合是算法代价的估计基础
|
|
284
|
-
- **概率与统计**:组合是概率的计算基础——古典概率 P(A) = |A|/|Ω|,分母 |Ω| 和分子 |A| 都是组合计数
|
|
285
|
-
- **变换思想**:生成函数将计数变换为代数——序列 → 幂级数,递推 → 方程,计数 → 系数提取
|
|
286
|
-
- **公理化思想**:组合恒等式的严格证明——C(n,k) = C(n,n−k) 需代数证明或组合论证,不可仅凭直觉
|
|
1
|
+
---
|
|
2
|
+
name: discrete-combinatorial
|
|
3
|
+
description: |
|
|
4
|
+
触发:当需要计数、枚举、发现有限结构中的规律,或处理图论、组合结构、生成函数、递推关系;或为稀疏/路由/拓扑结构设计组合方案时调用。
|
|
5
|
+
English: Trigger when you need to count, enumerate, find patterns in finite structures, or handle graph theory, combinatorial structures, generating functions, recurrences; or design combinatorial schemes for sparse/routing/topological structures.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
> **语言路由**:若用户消息为英文,请读取并遵循同目录下的 `SKILL.en.md`,按其操作规程以英文输出;中文消息则继续使用本文件。
|
|
9
|
+
|
|
10
|
+
# 🧮 离散与组合思想 / Discrete & Combinatorial
|
|
11
|
+
|
|
12
|
+
> "计数是最古老的数学活动——有限对象蕴含无限规律。"
|
|
13
|
+
> "Counting is the oldest mathematical activity — finite objects harbor infinite patterns."
|
|
14
|
+
>
|
|
15
|
+
> —— 组合数学、图论、生成函数
|
|
16
|
+
> —— Combinatorics, Graph Theory, Generating Functions
|
|
17
|
+
|
|
18
|
+
## 核心原则 / Core Principle
|
|
19
|
+
|
|
20
|
+
**组合思想对有限结构进行系统计数、发现支配枚举的规律,并用生成函数等代数方法将计数问题变换为代数问题——有限的简单掌控无限的复杂。**
|
|
21
|
+
|
|
22
|
+
**Combinatorial thinking systematically counts finite structures, discovers patterns governing enumeration, and uses algebraic methods (generating functions) to recast counting as algebra — finite simplicity governing infinite complexity.**
|
|
23
|
+
|
|
24
|
+
> **数学形式化 / Mathematical Formalization**
|
|
25
|
+
>
|
|
26
|
+
> **鸽巢原理 (Pigeonhole Principle)**:n 个物品放入 m < n 个盒子,则某盒至少含 2 个;推广 kn+1 入 n 盒则某盒至少含 k+1。存在性证明利器——只证必然存在,不构造具体实例。
|
|
27
|
+
>
|
|
28
|
+
> **容斥原理 (Inclusion-Exclusion)**:|A₁∪...∪A_n| = Σ|A_i| − Σ|A_i∩A_j| + ... ± |A₁∩...∩A_n|;补集计数:"不具有 P" = 全部 − "具有 P"。
|
|
29
|
+
>
|
|
30
|
+
> **生成函数 (Generating Functions)**:常生成函数 OGF A(x)=Σa_n x^n(无序/组合,A·C 系数 = Σa_i·c_{n−i});指数生成函数 EGF B(x)=Σb_n x^n/n!(有序/有标号,B·D 系数/n! = Σ(b_i/i!)·(d_{n−i}/(n−i)!))。
|
|
31
|
+
>
|
|
32
|
+
> **Pólya 计数定理 (Pólya Enumeration)**:群 G 作用下的轨道计数 = (1/|G|)Σ_{g∈G}|Fix(g)|(Burnside 引理),用循环指标多项式刻画"旋转/翻转视为相同"的等价类着色计数。
|
|
33
|
+
>
|
|
34
|
+
> Euler 的洞察:将 1+2+3+... 的"发散级数"重新诠释为分拆计数的生成函数。
|
|
35
|
+
|
|
36
|
+
## GPU 友好性 / GPU-Friendliness(横切检查)
|
|
37
|
+
|
|
38
|
+
离散/组合结构常「美但不可算」——精确计数多为 #P 完备(着色计数、匹配计数),精确枚举 NP-hard(Hamilton 路、子集和),直接落 GPU 不可行。落 GPU 须过 `../../references/gpu-friendly-math.md` 八维门,改用可张量化的聚合与采样近似:
|
|
39
|
+
|
|
40
|
+
- **友好**:邻接矩阵幂迭代 A^k 计路径数(GEMM)、动态规划表批量并行、bitset packed 计数(popcount)、结构化稀疏图遍历。
|
|
41
|
+
- **可改造**:容斥/递推 → 半环聚合((min,+) / (max,+) / Boolean / 热带半环)张量化;精确计数 → 蒙特卡洛/重要性采样估计;枚举 → 分支定界剪枝 + 批量并行;离散选择 → Gumbel-softmax 松弛。
|
|
42
|
+
- **反模式**:精确全枚举(n! 爆炸)、串行回溯搜索、强串行 DP(长程依赖不可并行)、非结构化图随机访存——"美但不可算",须近似或松弛。
|
|
43
|
+
|
|
44
|
+
八维最低判定(正式术语):**张量化**看有限对象能否编码成矩阵/bitset/批量表;**GEMM 可映射**看递推能否半环矩阵化;**复杂度**明确 NP-hard/#P-hard 与近似界;**显存与 KV-Cache**检查枚举表、DP 表、邻接结构是否爆炸;**低精度稳定**看松弛采样和半环运算是否数值稳健;**并行与通信**看子问题是否独立或可斜扫描;**稀疏结构**只采用块/带状/规则图稀疏;**算子融合**看计数、mask、采样能否合并为少量 kernel。
|
|
45
|
+
|
|
46
|
+
> 配合 `../../references/books/abstract-algebra.md`(半环/有限域聚合)、`../../references/books/matrix-analysis.md`(邻接矩阵/谱图)。
|
|
47
|
+
|
|
48
|
+
## 不适用场景 / When NOT to Use
|
|
49
|
+
|
|
50
|
+
- **连续/分析性问题,无离散结构**——极限、微分、积分而非有限对象计数,属分析而非组合。
|
|
51
|
+
- **精确闭式公式可直接给出答案**——组合枚举是多余开销(如 n·(n−1) 直接代数运算)。
|
|
52
|
+
- **纯粹概率问题,无组合结构**——连续分布参数估计、贝叶斯更新不涉及有限集合计数,概率密度积分不是组合问题。
|
|
53
|
+
|
|
54
|
+
## 何时使用 / When to Use
|
|
55
|
+
|
|
56
|
+
- 需要计数配置数量(排列/选择/分配),答案是具体有限数而非 1 或无穷。
|
|
57
|
+
- 需通过鸽巢原理证存在性("必存在某对象具某性质")而不构造实例。
|
|
58
|
+
- 需发现枚举数列 {a_n} 的递推或封闭公式(如 Catalan C_n = (2n)!/(n!(n+1)!))。
|
|
59
|
+
- 需枚举满足约束的配置——按结构分类、按规则生成,非随机罗列。
|
|
60
|
+
- 需图/网络分析(连接、路径、匹配、着色、覆盖)——社交网络、调度、规划可化为图问题。
|
|
61
|
+
- 需求解递推关系求封闭公式或渐近行为——递推 → 生成函数 → 代数求解 → 提取系数。
|
|
62
|
+
- **为稀疏/路由/拓扑结构设计组合方案**——稀疏 attention 模式、路由表/拓扑排序、块结构化稀疏布局。
|
|
63
|
+
|
|
64
|
+
## 方法流程 / Method
|
|
65
|
+
|
|
66
|
+
### 第一步:识别离散结构与计数问题
|
|
67
|
+
明确**计数对象**(排列/组合/分拆/安排)、**目标**(总数/带约束子集/概率)、**约束**(互不相交、有序/无序、有标号/无标号)。分类:排列 P(n,k)=n!/(n−k)!;组合 C(n,k)=n!/(k!(n−k)!);分拆 p(n) 整数分拆、B(n) 集合分拆;安排(物品入位置)。
|
|
68
|
+
|
|
69
|
+
### 第二步:应用基本计数原理
|
|
70
|
+
- **乘法原理**:k 个独立选择 → k₁×k₂×...×k_n。
|
|
71
|
+
- **加法原理**:互斥选项 → |A∪B|=|A|+|B|(A∩B=∅)。
|
|
72
|
+
- **鸽巢原理**:n>m 碰撞不可避免,某盒至少 ⌈n/m⌉;推广 kn+1 入 n 盒则某盒至少含 k+1。
|
|
73
|
+
|
|
74
|
+
### 第三步:使用容斥原理
|
|
75
|
+
|A₁∪...∪A_n| = Σ|A_i| − Σ|A_i∩A_j| + Σ|A_i∩A_j∩A_k| − ... ± |A₁∩...∩A_n|。**补集计数**:"不具有 P" = 全部 − "具有 P";经典错排 D(n) = n! − C(n,1)(n−1)! + C(n,2)(n−2)! − ... ± C(n,n)·0!。**符号规则**:第 k 层贡献 = (−1)^{k+1} Σ|A_{i₁}∩...∩A_{i_k}|(奇层正、偶层负)。
|
|
76
|
+
|
|
77
|
+
### 第四步:构造生成函数
|
|
78
|
+
- **OGF**:A(x)=Σa_n x^n,无序/组合;A(x)·C(x) 系数 = Σa_i·c_{n−i}(组合两个独立计数)。
|
|
79
|
+
- **EGF**:B(x)=Σb_n x^n/n!,有序/排列/有标号;B(x)·D(x) 系数/n! = Σ(b_i/i!)·(d_{n−i}/(n−i)!)。
|
|
80
|
+
- 经典:分拆 P(x)=Σp(n)x^n = 1/((1−x)(1−x²)(1−x³)...);Catalan C(x)=ΣC_n x^n = (1−√(1−4x))/(2x),由 C_n=ΣC_i·C_{n−1−i} 得 C(x)=1+x·C(x)²。
|
|
81
|
+
|
|
82
|
+
### 第五步:分析图结构
|
|
83
|
+
图 G=(V,E),|V| 顶点、|E| 边。核心:度数 deg(v)、邻接/关联矩阵;路径/连通分量、最短路(Dijkstra、Floyd-Warshall);树恰 n−1 边、生成树(Kruskal/Prim)、二叉树计数 C_n;平面图 Euler 公式 V−E+F=2、E≤3V−6;色数 χ(G)、四色定理 χ(平面图)≤4;匹配(Hall 婚姻定理、König:二分图最大匹配=最小顶点覆盖);Euler 环(连通且全度数偶)、Hamilton 环(NP-complete)。
|
|
84
|
+
|
|
85
|
+
### 第六步:发现递推与封闭公式
|
|
86
|
+
- **递推**:Catalan C_n=ΣC_i·C_{n−1−i},Fibonacci F_n=F_{n−1}+F_{n−2},错排 D_n=(n−1)(D_{n−1}+D_{n−2})。
|
|
87
|
+
- **生成函数求解**:递推乘 x^n 求和 → 解 A(x) → 提取 a_n;Fibonacci F(x)=x/(1−x−x²),部分分式得 F_n=(φ^n−ψ^n)/√5(φ=(1+√5)/2)。
|
|
88
|
+
- **直接公式**:C(n,k)=n!/(k!(n−k)!)(n 选 k 无序);Catalan C_n=C(2n,n)/(n+1)(合法括号序列组合论证)。
|
|
89
|
+
|
|
90
|
+
### 第七步:验证与推广
|
|
91
|
+
检查小案例 n=0,1,2,3 手动枚举与公式对比;验证公式计数正确、递推自洽、边界条件无误(空结构计数为 1:C₀=1, F₀=0, F₁=1);推广至更一般参数或更深组合解释。
|
|
92
|
+
|
|
93
|
+
> **验证不是可选的——未经验证的计数公式不可信。** n=3 的手动枚举与公式对比是最低验证要求。
|
|
94
|
+
|
|
95
|
+
## 常见错误 / Common Errors
|
|
96
|
+
|
|
97
|
+
| 错误 / Error | 批评 / Critique | 正确做法 / Correct Approach |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| 漏计与重计 | 漏计:遗漏约束交互少计;重计:同配置多次计算 | 明确约束交互,容斥修正重计,补集修正漏计 |
|
|
100
|
+
| 忽略约束条件交互 | 约束非独立,交集须容斥处理 | 用容斥:并集 = 各集之和 − 交集 |
|
|
101
|
+
| 混淆排列与组合 | 排列计序 P(n,k)=n!/(n−k)!,组合不计序 C(n,k)=n!/(k!(n−k)!) | 先判有序/无序再选公式 |
|
|
102
|
+
| 错误使用容斥符号 | 奇层正、偶层负,符号错则结果偏差 | 严格按 (−1)^{k+1} 定符号 |
|
|
103
|
+
| 忽略生成函数收敛域 | 形式幂级数可忽略收敛,但提封闭公式须在收敛域内 | 区分形式操作与解析操作 |
|
|
104
|
+
| 混淆有标号/无标号 | 有标号用 EGF,无标号用 OGF | 排列/分布→EGF;组合/分拆→OGF |
|
|
105
|
+
| 鸽巢原理使用不当 | 仅证存在性不构造实例,需 n>m | 确认 n>m,结论为"至少一个"非"恰好一个" |
|
|
106
|
+
| 递推边界条件错误 | C₀=1 非 0;F₀=0, F₁=1 | 空结构=1,检查 n=0,1 边界 |
|
|
107
|
+
| GPU 不可算性 | 精确枚举/计数 #P 或 NP-hard 爆炸 | 改半环聚合/采样近似,过 GPU 八维门 |
|
|
108
|
+
|
|
109
|
+
## 操作规程 / Operating Procedure
|
|
110
|
+
|
|
111
|
+
当本 skill 被触发时,输出必须包含:
|
|
112
|
+
|
|
113
|
+
1. **结构识别**:`[结构]: [离散对象]` — 计数对象、约束、分类
|
|
114
|
+
2. **计数类型**:`[计数类型]: [排列/组合/分拆/安排]` — 有序/无序、有标号/无标号
|
|
115
|
+
3. **原理选择**:`[原理]: [乘法/加法/鸽巢/容斥]` — 选择理由
|
|
116
|
+
4. **生成函数**:`[生成函数]: [公式]` — GF 及代数性质(如涉及)
|
|
117
|
+
5. **图结构**:`[图结构]: [属性]` — 顶点/边/连通/着色(如涉及)
|
|
118
|
+
6. **递推/公式**:`[递推/公式]: [内容]` — 递推及封闭公式
|
|
119
|
+
7. **验证**:`[验证]: [小案例]` — 至少 n=0,1,2,3 手动枚举与公式对比
|
|
120
|
+
8. **[GPU 可行性]**(若用于算法/算子设计)— 精确计数/枚举是否 NP-hard/#P,能否半环聚合/张量化/采样近似,过八维门
|
|
121
|
+
|
|
122
|
+
**输出不得只给分析而无结论。**
|
|
123
|
+
|
|
124
|
+
## 与其他 skill 的关系 / Relations to Other Skills
|
|
125
|
+
|
|
126
|
+
- **归纳与类比**:组合规律由归纳发现——从 {a_n} 前几项归纳递推,再类比到更一般结构。
|
|
127
|
+
- **算法思想**:组合计数支撑复杂度分析——n!、C(n,k) 是算法代价估计基础。
|
|
128
|
+
- **概率与统计**:组合是概率的计算基础——古典概率 P(A)=|A|/|Ω|,分子分母皆组合计数。
|
|
129
|
+
- **变换思想**:生成函数将计数变换为代数——序列→幂级数,递推→方程,计数→系数提取。
|
|
130
|
+
- **公理化思想**:组合恒等式需严格证明——C(n,k)=C(n,n−k) 须代数或组合论证,不可仅凭直觉。
|
|
131
|
+
- **现代数学激活**:`../../references/books/abstract-algebra.md`(有限域/半环聚合、Burnside 计数)、`../../references/books/matrix-analysis.md`(邻接矩阵/谱图/传递矩阵)。
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Discrete & Combinatorial Thinking — Original Texts & Historical Context
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## 1. Pigeonhole Principle — Dirichlet (1834)
|
|
6
|
+
|
|
7
|
+
Peter Gustav Lejeune Dirichlet stated the pigeonhole principle in 1834 as the "Schubfachprinzip" (drawer principle), using it for existential proofs in number theory.
|
|
8
|
+
|
|
9
|
+
> "Wenn man n + 1 Objecte in n Facher distribuiert, so ist mindestens ein Fach mit zwei Objecten besetzt."
|
|
10
|
+
> — Dirichlet, 1834
|
|
11
|
+
|
|
12
|
+
**Core statement:**
|
|
13
|
+
- Basic form: if n items are placed into m boxes and n > m, then some box contains at least ⌈n/m⌉ items
|
|
14
|
+
- Generalized form: kn+1 items into n boxes → some box contains at least k+1 items
|
|
15
|
+
- Number theory application: for any real number α and integer N, there exists q ≤ N such that |qα − p| < 1/(N+1) (i.e., qα approximates an integer)
|
|
16
|
+
|
|
17
|
+
**Diophantine approximation:** Partition [0,1) into N+1 equal-length intervals ("boxes"), and consider the N+2 numbers {0, {α}, {2α}, ..., {(N+1)α}} ("items"). The pigeonhole principle guarantees that two must fall into the same interval, yielding |(q₁−q₂)α − ⌊(q₁−q₂)α⌋| < 1/(N+1). This is the standard pigeonhole proof of Dirichlet's approximation theorem.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 2. Euler's Generating Functions (1748)
|
|
22
|
+
|
|
23
|
+
Leonhard Euler pioneered the generating function method in **Introductio in analysin infinitorum** (1748) — transforming sequences into power series, and counting into algebraic operations.
|
|
24
|
+
|
|
25
|
+
> "If we ask how many ways a given number can be partitioned, we are led to a study of the generating function." — Euler, 1748
|
|
26
|
+
|
|
27
|
+
**Partition generating function:**
|
|
28
|
+
$$P(x) = \sum_{n=0}^{\infty} p(n) x^n = \prod_{k=1}^{\infty} \frac{1}{1-x^k}$$
|
|
29
|
+
- p(n) = the number of partitions of n into positive integers. p(5) = 7: {5, 4+1, 3+2, 3+1+1, 2+2+1, 2+1+1+1, 1+1+1+1+1}
|
|
30
|
+
- Product form: 1/(1−x^k) = 1+x^k+x^{2k}+... represents "taking 0, 1, 2, ... copies of k"; since each k is independent, the product encodes all combinations
|
|
31
|
+
|
|
32
|
+
**Pentagonal number theorem (Euler 1750):**
|
|
33
|
+
$$\prod_{k=1}^{\infty}(1-x^k) = \sum_{m=-\infty}^{\infty} (-1)^m x^{m(3m-1)/2}$$
|
|
34
|
+
- Generalized pentagonal numbers e_m = m(3m−1)/2: 0, 1, 2, 5, 7, 12, 15, 22, ...
|
|
35
|
+
- From P(x)·∏(1−x^k) = Σ(−1)^m x^{e_m}, one obtains the recurrence p(n) = p(n−1)+p(n−2)−p(n−5)−p(n−7)+...
|
|
36
|
+
- This is a classic example of a finite recurrence controlling an infinite sequence — the essence of combinatorial thinking
|
|
37
|
+
|
|
38
|
+
**Hardy-Ramanujan asymptotic formula (1918):**
|
|
39
|
+
$$p(n) \sim \frac{1}{4n\sqrt{3}} \exp\left(\pi\sqrt{\frac{2n}{3}}\right)$$
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 3. Catalan Numbers
|
|
44
|
+
|
|
45
|
+
**History:** Eugène Catalan (1838) studied the counting problem of nested parentheses, from which the Catalan numbers derive their name. However, Euler had already studied a related problem (polygon triangulation) in 1751.
|
|
46
|
+
|
|
47
|
+
**Definition and formula:**
|
|
48
|
+
$$C_n = \frac{1}{n+1}\binom{2n}{n} = \frac{(2n)!}{n!(n+1)!}$$
|
|
49
|
+
- Recurrence: C₀ = 1, C_n = ΣC_i·C_{n−1−i}
|
|
50
|
+
- Generating function: C(x) = ΣC_n x^n = (1−√(1−4x))/(2x), obtained by solving C(x) = 1 + x·C(x)²
|
|
51
|
+
|
|
52
|
+
**Combinatorial interpretations (60+):**
|
|
53
|
+
- **Binary trees**: the number of ordered binary trees with n nodes = C_n
|
|
54
|
+
- **Dyck paths**: lattice paths from (0,0) to (2n,0), with steps (+1,+1) or (+1,−1), never crossing above y=0
|
|
55
|
+
- **Parenthesizations**: the number of valid nestings of n pairs of parentheses = C_n
|
|
56
|
+
- **Ballot problem**: A receives n+1 votes, B receives n votes; the number of sequences in which A is always ahead of B = C_n (Bertrand 1887)
|
|
57
|
+
- **Polygon triangulation**: the number of distinct triangulations of an (n+2)-gon = C_n
|
|
58
|
+
|
|
59
|
+
First few terms: C₀=1, C₁=1, C₂=2, C₃=5, C₄=14, C₅=42, C₆=132
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 4. Ramsey Theory — Ramsey (1930)
|
|
64
|
+
|
|
65
|
+
Frank P. Ramsey proved in **"On a Problem of Formal Logic"** (1930) that sufficiently large systems necessarily contain some structure — a profound generalization of the pigeonhole principle.
|
|
66
|
+
|
|
67
|
+
> "In any sufficiently large system, complete disorder is impossible." — Cohen
|
|
68
|
+
|
|
69
|
+
**Ramsey numbers:**
|
|
70
|
+
$$R(s,t) = \min\{n : \text{every 2-coloring of the complete graph on } n \text{ vertices contains a red } K_s \text{ or a blue } K_t\}$$
|
|
71
|
+
|
|
72
|
+
**Known values:** R(3,3)=6 (at a party of 6 people, there must be 3 mutual acquaintances or 3 mutual strangers; proof: fix one person, among the remaining 5 at least 3 share the same relationship color by the pigeonhole principle; if any 2 of those 3 share that color they form a monochromatic triangle, otherwise those 3 form a triangle of the other color), R(4,4)=18, R(3,4)=9, R(3,5)=14.
|
|
73
|
+
|
|
74
|
+
**General bounds:** Erdős 1947 probabilistic method: R(k,k) > 2^{k/2}; upper bound R(k,k) ≤ 4^k. R(5,5) is unknown (43 ≤ R(5,5) ≤ 48). Erdős: "If aliens demanded R(5,5), we should marshal all our computers; if they demanded R(6,6), we should prepare for battle."
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 5. Graph Theory — Euler (1736)
|
|
79
|
+
|
|
80
|
+
**Seven Bridges of Königsberg (1736):**
|
|
81
|
+
|
|
82
|
+
Leonhard Euler, in **"Solutio problematis ad geometriam situs pertinentis"** (1736), solved the Königsberg bridge problem, founding graph theory.
|
|
83
|
+
|
|
84
|
+
> "The problem... is to find whether one can cross each of the seven bridges exactly once and return to the starting point." — Euler, 1736
|
|
85
|
+
|
|
86
|
+
**Euler circuit theorem:**
|
|
87
|
+
- A connected graph has an Euler circuit (a closed walk traversing every edge exactly once) if and only if all vertices have even degree
|
|
88
|
+
- The Königsberg graph: the 4 vertices have degrees 3, 3, 3, 5 (all odd), so no Euler circuit exists — the problem has no solution
|
|
89
|
+
|
|
90
|
+
**Euler's planar formula (1750):**
|
|
91
|
+
$$V - E + F = 2$$
|
|
92
|
+
- For any connected planar graph: the number of vertices V, edges E, and faces F satisfy this formula
|
|
93
|
+
- Corollaries: for a simple connected planar graph E ≤ 3V − 6; for a planar graph containing no K₃, E ≤ 2V − 4
|
|
94
|
+
|
|
95
|
+
**Matching theory:**
|
|
96
|
+
- König (1931): in a bipartite graph, the maximum matching size = the minimum vertex cover size (König's theorem)
|
|
97
|
+
- Hall's marriage theorem (1935): a bipartite graph G(X,Y) has a perfect matching from X to Y if and only if for every S ⊆ X, |N(S)| ≥ |S|
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 6. Pólya Enumeration Theorem (1937)
|
|
102
|
+
|
|
103
|
+
George Pólya, in his 1937 paper, provided a counting method under symmetry — the orbit counting theorem, the meeting point of combinatorial enumeration and group theory.
|
|
104
|
+
|
|
105
|
+
> "The number of distinct colorings is obtained by averaging over the group action." — Pólya, 1937
|
|
106
|
+
|
|
107
|
+
**Theorem statement:**
|
|
108
|
+
Let group G act on set X. The number of equivalence classes of k-colorings (number of orbits):
|
|
109
|
+
$$N = \frac{1}{|G|} \sum_{g \in G} k^{c(g)}$$
|
|
110
|
+
where c(g) = the number of cycles of the permutation g. Applications: chemical isomers, bead necklace patterns. Burnside's lemma (1897): N = (1/|G|)Σ|Fix(g)| is a special case of Pólya's theorem. Pólya generalized this to a weighted version: GF × cycle index = symmetric counting.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## 7. Inclusion-Exclusion Principle
|
|
115
|
+
|
|
116
|
+
**History:** da Vinci used inclusion-exclusion ideas to compute areas; Sylvester (1882) formalized the principle. Inclusion-exclusion handles overlapping intersections — direct addition double-counts intersections, requiring successive corrections.
|
|
117
|
+
|
|
118
|
+
Basic form: |A₁∪...∪A_n| = Σ|A_i| − Σ|A_i∩A_j| + ... ± |A₁∩...∩A_n|. Complement counting: "not having property P" = total − "having property P."
|
|
119
|
+
|
|
120
|
+
**Derangements:** D(n) = n! − C(n,1)(n−1)! + C(n,2)(n−2)! − ... = n!Σ(−1)^k/k! ≈ n!/e as n→∞. Probability form: P(A₁∪...∪A_n) = ΣP(A_i) − ΣP(A_i∩A_j) + ...
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 8. Recurrence Relations
|
|
125
|
+
|
|
126
|
+
**Fibonacci sequence:**
|
|
127
|
+
$$F_0 = 0, F_1 = 1, F_n = F_{n-1} + F_{n-2}$$
|
|
128
|
+
- Generating function: F(x) = ΣF_n x^n = x/(1−x−x²)
|
|
129
|
+
- Binet's formula: F_n = (φ^n − ψ^n)/√5, where φ = (1+√5)/2 ≈ 1.618 (the golden ratio)
|
|
130
|
+
|
|
131
|
+
**Tower of Hanoi:**
|
|
132
|
+
$$T_1 = 1, T_n = 2T_{n-1} + 1$$
|
|
133
|
+
- Solution: T_n = 2^n − 1. A tower of 64 disks requires 2^{64} − 1 ≈ 1.8×10^{19} moves
|
|
134
|
+
|
|
135
|
+
**Solving recurrences via generating functions:**
|
|
136
|
+
1. Multiply the recurrence by x^n, sum over n → obtain an equation for A(x)
|
|
137
|
+
2. Use initial conditions to solve for A(x) (algebraic or differential equation)
|
|
138
|
+
3. Extract a_n: partial fractions, Taylor expansion, or matching against known power series
|
|
139
|
+
|
|
140
|
+
**Catalan GF derivation:** C(x) = 1 + x·C(x)² → solve x·C² − C + 1 = 0 → C(x) = (1−√(1−4x))/(2x) → C_n = (1/(n+1))C(2n,n)
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## 9. Combinatorial Optimization
|
|
145
|
+
|
|
146
|
+
**Minimum spanning tree:**
|
|
147
|
+
- Kruskal (1956): greedily select edges in ascending order of weight, skipping those that form cycles, O(E log E)
|
|
148
|
+
- Prim (1957): expand from a single vertex, each time selecting the minimum-weight connecting edge, O(E log V) (with a priority queue)
|
|
149
|
+
|
|
150
|
+
**Max-flow min-cut:**
|
|
151
|
+
- Ford-Fulkerson (1956): augmenting path method, incrementally increasing flow until no augmenting path exists
|
|
152
|
+
- Max-flow min-cut theorem: the maximum flow value = the minimum cut capacity (the combinatorial manifestation of LP duality)
|
|
153
|
+
- Edmonds-Karp (1972): BFS selects the shortest augmenting path, guaranteeing O(VE²)
|
|
154
|
+
|
|
155
|
+
**Matching theory:**
|
|
156
|
+
- Hungarian algorithm (Kuhn 1955): O(V³) maximum weighted bipartite matching
|
|
157
|
+
- Edmonds' blossom algorithm (1965): maximum matching in general graphs, O(V³)
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## 10. The Twelvefold Way
|
|
162
|
+
|
|
163
|
+
Richard P. Stanley, in **Enumerative Combinatorics Vol. 1**, unified and classified the 12 fundamental counting problems of placing n balls into k boxes (2×2×3: balls labeled/unlabeled × boxes labeled/unlabeled × any/at most one/at least one):
|
|
164
|
+
|
|
165
|
+
| Balls | Boxes | Condition | Formula |
|
|
166
|
+
|---|---|---|---|
|
|
167
|
+
| distinct | distinct | any | k^n |
|
|
168
|
+
| identical | distinct | any | C(n+k−1, k−1) |
|
|
169
|
+
| distinct | identical | any | Σ S₂(n,i), i=1..k |
|
|
170
|
+
| identical | identical | any | p_k(n) (restricted partitions) |
|
|
171
|
+
| distinct | distinct | at most one ≤1 | P(k,n) = k!/(k−n)! |
|
|
172
|
+
| identical | distinct | at most one ≤1 | C(k,n) |
|
|
173
|
+
| distinct | identical | at most one ≤1 | 1 if n≤k, 0 otherwise |
|
|
174
|
+
| identical | identical | at most one ≤1 | 1 if n≤k, 0 otherwise |
|
|
175
|
+
| distinct | distinct | at least one ≥1 | k!·S₂(n,k) |
|
|
176
|
+
| identical | distinct | at least one ≥1 | C(n−1, k−1) |
|
|
177
|
+
| distinct | identical | at least one ≥1 | S₂(n,k) − S₂(n,k−1) |
|
|
178
|
+
| identical | identical | at least one ≥1 | p_k(n) − p_{k−1}(n) |
|
|
179
|
+
|
|
180
|
+
**Key insight:** The 2×2×3=12 fundamental counting problems cover the core scenarios in combinatorics. Use EGF for labeled objects, OGF for unlabeled objects. **Stirling numbers:** S₁(n,k) = the number of permutations of n elements with k cycles; S₂(n,k) = the number of ways to partition n elements into k non-empty subsets.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
*This file provides mathematical references and historical context for the discrete-combinatorial skill, covering core results from Euler to modern combinatorics.*
|