math-skill 2.1.0 → 3.0.1

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.
Files changed (244) hide show
  1. package/README.en-US.md +165 -198
  2. package/README.md +165 -198
  3. package/agents/math-critic.en.md +28 -26
  4. package/agents/math-critic.md +33 -33
  5. package/commands/ask.en.md +10 -0
  6. package/commands/ask.md +3 -10
  7. package/design-patterns/attention/equivariant-attention.en.md +72 -0
  8. package/design-patterns/attention/equivariant-attention.md +72 -0
  9. package/design-patterns/attention/geometry-aware-attention.en.md +73 -0
  10. package/design-patterns/attention/geometry-aware-attention.md +72 -0
  11. package/design-patterns/attention/information-bottleneck-attention.en.md +72 -0
  12. package/design-patterns/attention/information-bottleneck-attention.md +72 -0
  13. package/design-patterns/attention/projection-attention.en.md +68 -0
  14. package/design-patterns/attention/projection-attention.md +68 -0
  15. package/design-patterns/attention/spectral-attention.en.md +71 -0
  16. package/design-patterns/attention/spectral-attention.md +71 -0
  17. package/design-patterns/compression/leverage-score-selection.en.md +71 -0
  18. package/design-patterns/compression/leverage-score-selection.md +71 -0
  19. package/design-patterns/compression/low-rank-kv-cache.en.md +60 -0
  20. package/design-patterns/compression/low-rank-kv-cache.md +60 -0
  21. package/design-patterns/compression/spectral-token-pruning.en.md +61 -0
  22. package/design-patterns/compression/spectral-token-pruning.md +61 -0
  23. package/design-patterns/compression/topology-preserving-compression.en.md +64 -0
  24. package/design-patterns/compression/topology-preserving-compression.md +64 -0
  25. package/design-patterns/loss/constraint-penalty.en.md +67 -0
  26. package/design-patterns/loss/constraint-penalty.md +78 -0
  27. package/design-patterns/loss/contrastive-loss.en.md +59 -0
  28. package/design-patterns/loss/contrastive-loss.md +68 -0
  29. package/design-patterns/loss/information-bottleneck-loss.en.md +69 -0
  30. package/design-patterns/loss/information-bottleneck-loss.md +74 -0
  31. package/design-patterns/loss/orthogonality-loss.en.md +56 -0
  32. package/design-patterns/loss/orthogonality-loss.md +60 -0
  33. package/design-patterns/loss/variational-loss.en.md +61 -0
  34. package/design-patterns/loss/variational-loss.md +71 -0
  35. package/design-patterns/representation/equivariant-split.en.md +87 -0
  36. package/design-patterns/representation/equivariant-split.md +89 -0
  37. package/design-patterns/representation/manifold-representation.en.md +85 -0
  38. package/design-patterns/representation/manifold-representation.md +87 -0
  39. package/design-patterns/representation/shared-private-decomposition.en.md +84 -0
  40. package/design-patterns/representation/shared-private-decomposition.md +86 -0
  41. package/design-patterns/representation/subspace-alignment.en.md +90 -0
  42. package/design-patterns/representation/subspace-alignment.md +92 -0
  43. package/design-patterns/routing/graph-routing.en.md +79 -0
  44. package/design-patterns/routing/graph-routing.md +81 -0
  45. package/design-patterns/routing/moe-routing.en.md +85 -0
  46. package/design-patterns/routing/moe-routing.md +87 -0
  47. package/design-patterns/routing/optimal-transport-routing.en.md +68 -0
  48. package/design-patterns/routing/optimal-transport-routing.md +72 -0
  49. package/design-patterns/routing/spectral-clustering-routing.en.md +88 -0
  50. package/design-patterns/routing/spectral-clustering-routing.md +90 -0
  51. package/knowledge-base/differential-geometry/connection.en.md +51 -0
  52. package/knowledge-base/differential-geometry/connection.md +51 -0
  53. package/knowledge-base/differential-geometry/curvature.en.md +49 -0
  54. package/knowledge-base/differential-geometry/curvature.md +49 -0
  55. package/knowledge-base/differential-geometry/geodesic.en.md +51 -0
  56. package/knowledge-base/differential-geometry/geodesic.md +51 -0
  57. package/knowledge-base/differential-geometry/manifold.en.md +47 -0
  58. package/knowledge-base/differential-geometry/manifold.md +47 -0
  59. package/knowledge-base/differential-geometry/metric-tensor.en.md +50 -0
  60. package/knowledge-base/differential-geometry/metric-tensor.md +50 -0
  61. package/knowledge-base/differential-geometry/tangent-space.en.md +48 -0
  62. package/knowledge-base/differential-geometry/tangent-space.md +48 -0
  63. package/knowledge-base/information-geometry/fisher-metric.en.md +56 -0
  64. package/knowledge-base/information-geometry/fisher-metric.md +56 -0
  65. package/knowledge-base/information-geometry/natural-gradient.en.md +54 -0
  66. package/knowledge-base/information-geometry/natural-gradient.md +54 -0
  67. package/knowledge-base/lie-theory/equivariance.en.md +54 -0
  68. package/knowledge-base/lie-theory/equivariance.md +54 -0
  69. package/knowledge-base/lie-theory/group-action.en.md +51 -0
  70. package/knowledge-base/lie-theory/group-action.md +51 -0
  71. package/knowledge-base/lie-theory/lie-algebra.en.md +51 -0
  72. package/knowledge-base/lie-theory/lie-algebra.md +51 -0
  73. package/knowledge-base/lie-theory/lie-group.en.md +51 -0
  74. package/knowledge-base/lie-theory/lie-group.md +51 -0
  75. package/knowledge-base/lie-theory/representation.en.md +52 -0
  76. package/knowledge-base/lie-theory/representation.md +52 -0
  77. package/knowledge-base/matrix-analysis/low-rank-approximation.en.md +49 -0
  78. package/knowledge-base/matrix-analysis/low-rank-approximation.md +49 -0
  79. package/knowledge-base/matrix-analysis/matrix-perturbation.en.md +49 -0
  80. package/knowledge-base/matrix-analysis/matrix-perturbation.md +49 -0
  81. package/knowledge-base/matrix-analysis/positive-semidefinite.en.md +50 -0
  82. package/knowledge-base/matrix-analysis/positive-semidefinite.md +50 -0
  83. package/knowledge-base/matrix-analysis/projection.en.md +47 -0
  84. package/knowledge-base/matrix-analysis/projection.md +47 -0
  85. package/knowledge-base/matrix-analysis/spectral-decomposition.en.md +48 -0
  86. package/knowledge-base/matrix-analysis/spectral-decomposition.md +48 -0
  87. package/knowledge-base/optimization/constrained-optimization.en.md +53 -0
  88. package/knowledge-base/optimization/constrained-optimization.md +53 -0
  89. package/knowledge-base/optimization/convex-optimization.en.md +50 -0
  90. package/knowledge-base/optimization/convex-optimization.md +50 -0
  91. package/knowledge-base/optimization/lagrangian-duality.en.md +50 -0
  92. package/knowledge-base/optimization/lagrangian-duality.md +50 -0
  93. package/knowledge-base/optimization/proximal-method.en.md +52 -0
  94. package/knowledge-base/optimization/proximal-method.md +52 -0
  95. package/knowledge-base/optimization/riemannian-optimization.en.md +51 -0
  96. package/knowledge-base/optimization/riemannian-optimization.md +51 -0
  97. package/knowledge-base/overview.en.md +29 -218
  98. package/knowledge-base/overview.md +29 -220
  99. package/knowledge-base/probability/concentration-inequality.en.md +45 -0
  100. package/knowledge-base/probability/concentration-inequality.md +45 -0
  101. package/knowledge-base/probability/entropy.en.md +47 -0
  102. package/knowledge-base/probability/entropy.md +47 -0
  103. package/knowledge-base/probability/fisher-information.en.md +48 -0
  104. package/knowledge-base/probability/fisher-information.md +48 -0
  105. package/knowledge-base/probability/information-bottleneck.en.md +49 -0
  106. package/knowledge-base/probability/information-bottleneck.md +49 -0
  107. package/knowledge-base/probability/kl-divergence.en.md +51 -0
  108. package/knowledge-base/probability/kl-divergence.md +51 -0
  109. package/knowledge-base/topology/euler-characteristic.en.md +54 -0
  110. package/knowledge-base/topology/euler-characteristic.md +54 -0
  111. package/knowledge-base/topology/fundamental-group.en.md +52 -0
  112. package/knowledge-base/topology/fundamental-group.md +52 -0
  113. package/knowledge-base/topology/persistent-homology.en.md +54 -0
  114. package/knowledge-base/topology/persistent-homology.md +54 -0
  115. package/lenses/algorithmic.en.md +49 -0
  116. package/lenses/algorithmic.md +49 -0
  117. package/lenses/axiomatization.en.md +48 -0
  118. package/lenses/axiomatization.md +48 -0
  119. package/lenses/categorical.en.md +48 -0
  120. package/lenses/categorical.md +48 -0
  121. package/lenses/causal.en.md +49 -0
  122. package/lenses/causal.md +49 -0
  123. package/lenses/duality.en.md +47 -0
  124. package/lenses/duality.md +47 -0
  125. package/lenses/game.en.md +50 -0
  126. package/lenses/game.md +50 -0
  127. package/lenses/geometric.en.md +53 -0
  128. package/lenses/geometric.md +53 -0
  129. package/lenses/local-to-global.en.md +52 -0
  130. package/lenses/local-to-global.md +52 -0
  131. package/lenses/perturbation.en.md +51 -0
  132. package/lenses/perturbation.md +51 -0
  133. package/lenses/probabilistic.en.md +48 -0
  134. package/lenses/probabilistic.md +48 -0
  135. package/lenses/projection.en.md +50 -0
  136. package/lenses/projection.md +50 -0
  137. package/lenses/spectral.en.md +52 -0
  138. package/lenses/spectral.md +52 -0
  139. package/lenses/symmetry.en.md +49 -0
  140. package/lenses/symmetry.md +49 -0
  141. package/lenses/topological.en.md +48 -0
  142. package/lenses/topological.md +48 -0
  143. package/lenses/variational.en.md +48 -0
  144. package/lenses/variational.md +48 -0
  145. package/package.json +9 -3
  146. package/references/agentic-workflow.en.md +1 -1
  147. package/references/agentic-workflow.md +1 -1
  148. package/references/books/abstract-algebra.en.md +124 -0
  149. package/references/books/abstract-algebra.md +22 -22
  150. package/references/books/algebraic-geometry-rising-sea.en.md +171 -0
  151. package/references/books/algebraic-geometry-rising-sea.md +11 -11
  152. package/references/books/differential-geometry.en.md +140 -0
  153. package/references/books/differential-geometry.md +19 -19
  154. package/references/books/matrix-analysis.en.md +146 -0
  155. package/references/books/matrix-analysis.md +10 -10
  156. package/references/books/micro-lie-theory.en.md +116 -0
  157. package/references/books/micro-lie-theory.md +17 -17
  158. package/references/books/optimization-ml.en.md +163 -0
  159. package/references/books/optimization-ml.md +7 -8
  160. package/references/books/smooth-manifolds.en.md +105 -0
  161. package/references/books/smooth-manifolds.md +14 -14
  162. package/references/gpu-friendly-math.en.md +23 -10
  163. package/references/gpu-friendly-math.md +17 -4
  164. package/references/inspiration.en.md +1 -1
  165. package/references/inspiration.md +2 -2
  166. package/skills/math-research-activator/SKILL.en.md +195 -114
  167. package/skills/math-research-activator/SKILL.md +194 -119
  168. package/skills/math-research-activator/original-texts.en.md +9 -9
  169. package/skills/math-research-activator/original-texts.md +11 -11
  170. package/commands/abstraction.md +0 -11
  171. package/commands/algorithmic-thinking.md +0 -11
  172. package/commands/axiomatization.md +0 -11
  173. package/commands/causal-inference.md +0 -11
  174. package/commands/discrete-combinatorial.md +0 -11
  175. package/commands/game-theory.md +0 -11
  176. package/commands/induction-analogy.md +0 -11
  177. package/commands/information-theory.md +0 -11
  178. package/commands/logic-deduction.md +0 -11
  179. package/commands/modeling.md +0 -11
  180. package/commands/optimization.md +0 -11
  181. package/commands/probability-statistics.md +0 -11
  182. package/commands/symmetry-invariance.md +0 -11
  183. package/commands/topological-thinking.md +0 -11
  184. package/commands/transformation.md +0 -11
  185. package/skills/abstraction/SKILL.en.md +0 -117
  186. package/skills/abstraction/SKILL.md +0 -121
  187. package/skills/abstraction/original-texts.en.md +0 -163
  188. package/skills/abstraction/original-texts.md +0 -175
  189. package/skills/algorithmic-thinking/SKILL.en.md +0 -132
  190. package/skills/algorithmic-thinking/SKILL.md +0 -138
  191. package/skills/algorithmic-thinking/original-texts.en.md +0 -253
  192. package/skills/algorithmic-thinking/original-texts.md +0 -256
  193. package/skills/axiomatization/SKILL.en.md +0 -144
  194. package/skills/axiomatization/SKILL.md +0 -151
  195. package/skills/axiomatization/original-texts.en.md +0 -154
  196. package/skills/axiomatization/original-texts.md +0 -160
  197. package/skills/causal-inference/SKILL.en.md +0 -147
  198. package/skills/causal-inference/SKILL.md +0 -151
  199. package/skills/causal-inference/original-texts.en.md +0 -136
  200. package/skills/causal-inference/original-texts.md +0 -167
  201. package/skills/discrete-combinatorial/SKILL.en.md +0 -124
  202. package/skills/discrete-combinatorial/SKILL.md +0 -131
  203. package/skills/discrete-combinatorial/original-texts.en.md +0 -184
  204. package/skills/discrete-combinatorial/original-texts.md +0 -185
  205. package/skills/game-theory/SKILL.en.md +0 -117
  206. package/skills/game-theory/SKILL.md +0 -123
  207. package/skills/game-theory/original-texts.en.md +0 -131
  208. package/skills/game-theory/original-texts.md +0 -131
  209. package/skills/induction-analogy/SKILL.en.md +0 -145
  210. package/skills/induction-analogy/SKILL.md +0 -152
  211. package/skills/induction-analogy/original-texts.en.md +0 -140
  212. package/skills/induction-analogy/original-texts.md +0 -154
  213. package/skills/information-theory/SKILL.en.md +0 -134
  214. package/skills/information-theory/SKILL.md +0 -140
  215. package/skills/information-theory/original-texts.en.md +0 -127
  216. package/skills/information-theory/original-texts.md +0 -127
  217. package/skills/logic-deduction/SKILL.en.md +0 -130
  218. package/skills/logic-deduction/SKILL.md +0 -135
  219. package/skills/logic-deduction/original-texts.en.md +0 -160
  220. package/skills/logic-deduction/original-texts.md +0 -173
  221. package/skills/modeling/SKILL.en.md +0 -135
  222. package/skills/modeling/SKILL.md +0 -139
  223. package/skills/modeling/original-texts.en.md +0 -162
  224. package/skills/modeling/original-texts.md +0 -165
  225. package/skills/optimization/SKILL.en.md +0 -129
  226. package/skills/optimization/SKILL.md +0 -135
  227. package/skills/optimization/original-texts.en.md +0 -167
  228. package/skills/optimization/original-texts.md +0 -168
  229. package/skills/probability-statistics/SKILL.en.md +0 -146
  230. package/skills/probability-statistics/SKILL.md +0 -151
  231. package/skills/probability-statistics/original-texts.en.md +0 -191
  232. package/skills/probability-statistics/original-texts.md +0 -193
  233. package/skills/symmetry-invariance/SKILL.en.md +0 -135
  234. package/skills/symmetry-invariance/SKILL.md +0 -139
  235. package/skills/symmetry-invariance/original-texts.en.md +0 -206
  236. package/skills/symmetry-invariance/original-texts.md +0 -221
  237. package/skills/topological-thinking/SKILL.en.md +0 -124
  238. package/skills/topological-thinking/SKILL.md +0 -128
  239. package/skills/topological-thinking/original-texts.en.md +0 -134
  240. package/skills/topological-thinking/original-texts.md +0 -164
  241. package/skills/transformation/SKILL.en.md +0 -120
  242. package/skills/transformation/SKILL.md +0 -124
  243. package/skills/transformation/original-texts.en.md +0 -204
  244. package/skills/transformation/original-texts.md +0 -216
@@ -1,131 +0,0 @@
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`(邻接矩阵/谱图/传递矩阵)。
@@ -1,184 +0,0 @@
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.*
@@ -1,185 +0,0 @@
1
- # 离散与组合思想 — 原始文献与历史语境 / Discrete & Combinatorial Thinking — Original Texts & Historical Context
2
-
3
- ---
4
-
5
- ## 1. Pigeonhole Principle — Dirichlet (1834) / 鸽巢原理 — Dirichlet (1834)
6
-
7
- Peter Gustav Lejeune Dirichlet 在 1834 年以"Schubfachprinzip"(抽屉原理)阐述鸽巢原理,用于数论存在性证明。
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
- - 基本形式:若 n 物品放入 m 个盒子且 n > m,则某盒子含至少 ⌈n/m⌉ 个物品
14
- - 推广形式:kn+1 物品入 n 盒子 → 某盒至少含 k+1 个物品
15
- - 数论应用:对任意实数 α 和整数 N,存在 q ≤ N 使得 |qα − p| < 1/(N+1)(即 qα 逼近整数)
16
-
17
- **Diophantine 逼近 / Diophantine approximation:** 将 [0,1) 分为 N+1 个等长区间("盒子"),考虑 N+2 个数 {0, {α}, {2α}, ..., {(N+1)α}}("物品"),鸽巢保证必有两个落入同一区间,得 |(q₁−q₂)α − ⌊(q₁−q₂)α⌋| < 1/(N+1)。这是 Dirichlet 逼近定理的标准鸽巢证明。
18
-
19
- ---
20
-
21
- ## 2. Euler's Generating Functions (1748) / Euler 的生成函数 (1748)
22
-
23
- Leonhard Euler 在 **Introductio in analysin infinitorum** (1748) 中开创生成函数方法——序列变换为幂级数,计数变换为代数运算。
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 GF:**
28
- $$P(x) = \sum_{n=0}^{\infty} p(n) x^n = \prod_{k=1}^{\infty} \frac{1}{1-x^k}$$
29
- - p(n) = 将 n 分为正整数之和的分拆数。p(5) = 7:{5, 4+1, 3+2, 3+1+1, 2+2+1, 2+1+1+1, 1+1+1+1+1}
30
- - 乘积形式:1/(1−x^k) = 1+x^k+x^{2k}+... 表示"取 k 的 0,1,2,... 次",各 k 独立故乘积编码组合
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
- - 广义五角数 e_m = m(3m−1)/2:0, 1, 2, 5, 7, 12, 15, 22, ...
35
- - 由 P(x)·∏(1−x^k) = Σ(−1)^m x^{e_m},得递推 p(n) = p(n−1)+p(n−2)−p(n−5)−p(n−7)+...
36
- - 这是有限递推控制无限序列的经典实例——组合思想的精髓
37
-
38
- **Hardy-Ramanujan 渐近公式 (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 / Catalan 数
44
-
45
- **历史 / History:** Eugène Catalan (1838) 研究括号嵌套的计数问题,Catalan 数由此得名。但 Euler 早在 1751 年就研究过类似问题(多边形三角剖分)。
46
-
47
- **定义与公式 / Definition and formula:**
48
- $$C_n = \frac{1}{n+1}\binom{2n}{n} = \frac{(2n)!}{n!(n+1)!}$$
49
- - 递推:C₀ = 1, C_n = ΣC_i·C_{n−1−i}
50
- - 生成函数:C(x) = ΣC_n x^n = (1−√(1−4x))/(2x),由 C(x) = 1 + x·C(x)² 解得
51
-
52
- **组合解释(60+种) / Combinatorial interpretations (60+):**
53
- - **二叉树**:n 个节点的有序二叉树数 = C_n
54
- - **Dyck 路径**:从 (0,0) 到 (2n,0) 的格点路径,每步 (+1,+1) 或 (+1,−1),不越 y=0
55
- - **括号序列**:n 对括号的合法嵌套方式数 = C_n
56
- - **投票问题 (Ballot problem)**:A 得 n+1 票、B 得 n 票,A 全程领先 B 的序列数 = C_n(Bertrand 1887)
57
- - **多边形三角剖分**:n+2 边形的不同三角剖分数 = C_n
58
-
59
- 前几项:C₀=1, C₁=1, C₂=2, C₃=5, C₄=14, C₅=42, C₆=132
60
-
61
- ---
62
-
63
- ## 4. Ramsey Theory — Ramsey (1930) / Ramsey 理论 — Ramsey (1930)
64
-
65
- Frank P. Ramsey 在 **"On a Problem of Formal Logic"** (1930) 中证明:足够大的系统必存在某种结构——鸽巢原理的深刻推广。
66
-
67
- > "In any sufficiently large system, complete disorder is impossible." — Cohen
68
-
69
- **Ramsey 数 / Ramsey numbers:**
70
- $$R(s,t) = \min\{n : \text{任意 } n \text{ 阶 2-色完全图中必有红 } K_s \text{ 或蓝 } K_t\}$$
71
-
72
- **已知值:** R(3,3)=6(6人聚会必有3人互识或互不识;证明:固定一人,5人中至少3人同色关系(鸽巢),此3人中若2人同色则3人组,否则此3人构成另一色3人组), R(4,4)=18, R(3,4)=9, R(3,5)=14.
73
-
74
- **一般界:** Erdős 1947 概率方法: R(k,k) > 2^{k/2}; 上界 R(k,k) ≤ 4^k. R(5,5)未知(43≤R(5,5)≤48). Erdős:"外星人要R(5,5)就动员所有计算机;要R(6,6)就准备战斗。"
75
-
76
- ---
77
-
78
- ## 5. Graph Theory — Euler (1736) / 图论 — Euler (1736)
79
-
80
- **Königsberg 七桥问题 / Seven Bridges of Königsberg (1736):**
81
-
82
- Leonhard Euler 在 **"Solutio problematis ad geometriam situs pertinentis"** (1736) 解决柯尼斯堡七桥问题,开创图论。
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 环定理 / Euler circuit theorem:**
87
- - 连通图存在 Euler 环(经过每边恰好一次的闭路径)iff 所有顶点度数为偶数
88
- - 柯尼斯堡图:4 个顶点度数为 3, 3, 3, 5(均为奇数),故 Euler 环不存在——问题无解
89
-
90
- **Euler 平面图公式 / Euler's planar formula (1750):**
91
- $$V - E + F = 2$$
92
- - 对任意连通平面图:顶点数 V、边数 E、面数 F 满足此公式
93
- - 推论:简单连通平面图 E ≤ 3V − 6;不含 K₃ 的平面图 E ≤ 2V − 4
94
-
95
- **匹配理论 / Matching theory:**
96
- - König (1931):二分图中最大匹配数 = 最小顶点覆盖数(König 定理)
97
- - Hall 婚姻定理 (1935):二分图 G(X,Y) 有 X 到 Y 的完美匹配 iff 对任意 S ⊆ X,|N(S)| ≥ |S|
98
-
99
- ---
100
-
101
- ## 6. Pólya Enumeration Theorem (1937) / Pólya 计数定理 (1937)
102
-
103
- George Pólya 在 1937 年的论文中给出对称性下的计数方法——轨道计数定理,组合计数与群论的交汇点。
104
-
105
- > "The number of distinct colorings is obtained by averaging over the group action." — Pólya, 1937
106
-
107
- **定理陈述 / Theorem statement:**
108
- 设群 G 作用于集合 X,k-着色等价类数(轨道数):
109
- $$N = \frac{1}{|G|} \sum_{g \in G} k^{c(g)}$$
110
- c(g) = 置换 g 的循环数。应用: 化学异构体、珠串图案。Burnside 引理 (1897): N = (1/|G|)Σ|Fix(g)|,是 Pólya 特例。Pólya 推广为带权版本: GF × 循环指数 = 对称计数。
111
-
112
- ---
113
-
114
- ## 7. Inclusion-Exclusion Principle / 容斥原理
115
-
116
- **历史:** da Vinci 用容斥思想计算面积;Sylvester (1882) 形式化。容斥处理交集重叠——直接相加重计交集,需逐层修正。
117
-
118
- 基本形式: |A₁∪...∪A_n| = Σ|A_i| − Σ|A_i∩A_j| + ... ± |A₁∩...∩A_n|. 补集计数: "不具有P" = 全部 − "具有P".
119
-
120
- **错排数:** D(n) = n! − C(n,1)(n−1)! + C(n,2)(n−2)! − ... = n!Σ(−1)^k/k! ≈ n!/e (n→∞). 概率形式: P(A₁∪...∪A_n) = ΣP(A_i) − ΣP(A_i∩A_j) + ...
121
-
122
- ---
123
-
124
- ## 8. Recurrence Relations / 递推关系
125
-
126
- **Fibonacci 数列 / Fibonacci sequence:**
127
- $$F_0 = 0, F_1 = 1, F_n = F_{n-1} + F_{n-2}$$
128
- - 生成函数:F(x) = ΣF_n x^n = x/(1−x−x²)
129
- - Binet 公式:F_n = (φ^n − ψ^n)/√5,φ = (1+√5)/2 ≈ 1.618(黄金比)
130
-
131
- **汉诺塔 / Tower of Hanoi:**
132
- $$T_1 = 1, T_n = 2T_{n-1} + 1$$
133
- - 解:T_n = 2^n − 1。64 层需 2^{64} − 1 ≈ 1.8×10^{19} 步
134
-
135
- **GF 求解递推 / Solving recurrences via GF:**
136
- 1. 递推乘以 x^n,对 n 求和 → A(x) 的方程
137
- 2. 利用初始条件,解出 A(x)(代数/微分方程)
138
- 3. 提取 a_n:部分分式、Taylor 展开、幂级数对照
139
-
140
- **Catalan GF 推导:** C(x) = 1 + x·C(x)² → 解 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):按边权升序贪心选取不成环的边,O(E log E)
148
- - Prim (1957):从单点扩展,每次选最小权连接边,O(E log V)(优先队列)
149
-
150
- **最大流最小割 / Max-flow min-cut:**
151
- - Ford-Fulkerson (1956):增广路径法,流量逐步增加直至无增广路径
152
- - 最大流最小割定理:最大流值 = 最小割容量(LP 对偶性的组合表现)
153
- - Edmonds-Karp (1972):BFS 选最短增广路径,保证 O(VE²)
154
-
155
- **匹配理论 / Matching theory:**
156
- - Hungarian 算法 (Kuhn 1955):O(V³) 最大加权二分匹配
157
- - Edmonds 带花树算法 (1965):一般图最大匹配,O(V³)
158
-
159
- ---
160
-
161
- ## 10. The Twelvefold Way / 十二重道
162
-
163
- Richard P. Stanley 在 **Enumerative Combinatorics Vol. 1** 中统一分类 n球入k盒的12种基本计数(2×2×3: 球有标号/无标号 × 盒有标号/无标号 × 任意/至多1/至少1):
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)(受限分拆) |
171
- | 有标号 distinct | 有标号 distinct | 至多一个 ≤1 | P(k,n) = k!/(k−n)! |
172
- | 无标号 identical | 有标号 distinct | 至多一个 ≤1 | C(k,n) |
173
- | 有标号 distinct | 无标号 identical | 至多一个 ≤1 | 1 if n≤k, 0 else |
174
- | 无标号 identical | 无标号 identical | 至多一个 ≤1 | 1 if n≤k, 0 else |
175
- | 有标号 distinct | 有标号 distinct | 至少一个 ≥1 | k!·S₂(n,k) |
176
- | 无标号 identical | 有标号 distinct | 至至少一个 ≥1 | C(n−1, k−1) |
177
- | 有标号 distinct | 无标号 identical | 至少一个 ≥1 | S₂(n,k) − S₂(n,k−1) |
178
- | 无标号 identical | 无标号 identical | 至少一个 ≥1 | p_k(n) − p_{k−1}(n) |
179
-
180
- **关键洞察:** 2×2×3=12种基本计数覆盖组合数学核心场景。有标号用EGF,无标号用OGF。**Stirling数:** S₁(n,k)=n元素k循环排列数; S₂(n,k)=n元素k非空子集数。
181
-
182
- ---
183
-
184
- *本文件为离散与组合思想技能的数学参考与历史语境,涵盖从 Euler 到现代组合数学的核心成果。*
185
- *This file provides mathematical references and historical context for the discrete-combinatorial skill, covering core results from Euler to modern combinatorics.*
@@ -1,117 +0,0 @@
1
- ---
2
- name: game-theory
3
- description: |
4
- Trigger when optimal strategy depends on others' choices, needing Nash equilibrium computation, zero-sum/non-zero-sum analysis, mechanism design; or designing strategies for multi-agent systems, adversarial training, routing games.
5
- ---
6
-
7
- # 🎯 Game Theory
8
-
9
- > "Your optimal choice depends on others' choices — thinking must be interactive, not just deep."
10
- >
11
- > — Game Theory, Decision Theory, Mechanism Design
12
-
13
- ## Core Principle
14
-
15
- **Strategic interaction — your best action depends on what others do, and theirs depend on what you do. Nash equilibrium: strategy profile where no player benefits from unilateral deviation.**
16
-
17
- Key concepts: **Payoff Matrix**, **Dominant Strategy**, **Mixed Strategy**, **Pareto Optimality**. Classification dimensions: cooperative vs. non-cooperative, zero-sum vs. general-sum, simultaneous vs. sequential.
18
-
19
- > **Mathematical Formalization**
20
- >
21
- > Formal definition: $n$ players, each with strategy set $S_i$ and payoff function $u_i: S_1 \times \cdots \times S_n \to \mathbb{R}$.
22
- >
23
- > Nash equilibrium: strategy profile $s^* = (s_1^*, \ldots, s_n^*)$ satisfying $u_i(s^*) \geq u_i(s_i, s^*_{-i})$ for all $s_i \in S_i$ and all $i$, where $s^*_{-i}$ denotes the strategies of all players except $i$. Mixed-strategy Nash equilibrium: probability distribution $\sigma^*$ such that $u_i(\sigma^*) \geq u_i(s_i, \sigma^*_{-i})$.
24
- >
25
- > Dominant strategy: strict $u_i(s_i^*, s_{-i}) > u_i(s_i, s_{-i})$; weak dominance $\geq$ with at least one strict inequality.
26
- >
27
- > Zero-sum minimax: $\max_x \min_y f(x,y) = \min_y \max_x f(x,y)$.
28
-
29
- ## GPU-Friendliness (Cross-Cutting Check)
30
-
31
- Game-solving maps to GPU with widely varying capability; pass through the eight-dimensional gate in `../../references/gpu-friendly-math.md`:
32
-
33
- - **Matrix games / two-player zero-sum (minimax)**: Equivalent to linear programming (LP); payoff matrix operations are GEMM-compatible and batch-parallelizable — **friendly**.
34
- - **Mixed-strategy equilibrium computation**: Linear systems / indifference equations on the support; small-scale problems are batch-solvable; watch for sparsity and condition number at scale.
35
- - **Exact large-scale multi-agent equilibrium**: $n$-player Nash equilibrium is PPAD-complete; general case is **intractable** → **anti-pattern**; switch to approximate / learning-based methods (fictitious play, self-play, multi-agent RL, NFSP).
36
- - **Evolutionary / repeated game simulation**: Population and strategy batch updates are parallelizable; watch for inter-agent communication and synchronization overhead.
37
-
38
- Eight-dimensional minimum assessment (formal terms): **Tensorization** — whether players / strategies / rounds admit batched unfolding; **GEMM-mappability** — whether payoff matrices, minimax, LP / linear systems fall into matrix operations; **Complexity** — flag PPAD / combinatorial explosion risks for Nash / mechanism solving; **Memory and KV-Cache** — whether the strategy-state Cartesian product is compressible; **Low-precision stability** — whether equilibrium solving, LP, soft best-response have controlled condition numbers; **Parallelism and communication** — synchronization cost of multi-agent rollouts; **Sparse structure** — whether the interaction graph is structured; **Operator fusion** — whether payoff, mask, and best-response updates can be fused.
39
-
40
- > Use in conjunction with `../../references/books/optimization-ml.md` (duality / minimax, game learning algorithms) and `../../references/books/matrix-analysis.md` (matrix games, linear systems).
41
-
42
- ## When NOT to Use
43
-
44
- - **Single-agent decision problems with no interaction** — optimization thinking is more appropriate; no need to model others' strategic responses.
45
- - **Purely cooperative problems with no conflict of interest** — players' objectives are fully aligned; strategic analysis is unnecessary.
46
- - **Deterministic problems with no strategic uncertainty** — outcomes are uniquely determined by one's own actions; no reaction from others is involved.
47
- - **Outcomes determined purely by chance with no strategic choice** — no strategy sets to analyze; game theory does not apply.
48
-
49
- ## When to Use
50
-
51
- - Multiple decision-makers interact; each player's strategy affects others' payoffs; the optimal strategy depends on predicting others' responses.
52
- - Need to design incentive mechanisms so that self-interested behavior leads to socially optimal outcomes; predict equilibrium states under given rules.
53
- - Analyze pricing, entry, and exit in competitive markets; benefit allocation and threat points in negotiation / bargaining.
54
- - **Design strategies and equilibrium objectives for multi-agent systems, adversarial training (GAN / robust learning), and routing games.**
55
-
56
- ## Method
57
-
58
- ### Step 1: Identify Players and Strategies
59
- Define the fundamental elements of the game: players $N=\{1,\ldots,n\}$; strategy sets $S_i$; payoff functions $u_i: S_1\times\cdots\times S_n\to\mathbb{R}$; information structure (symmetric or not? incomplete information? sequential actions? communication possible?). The core task is identifying the "interaction structure" — whose choices affect whose outcomes. Missing a key player is the most common error.
60
-
61
- ### Step 2: Analyze the Game Type
62
- First classify: zero-sum / general-sum, simultaneous / sequential, cooperative / non-cooperative, complete / incomplete information. The type determines the method: zero-sum uses minimax / LP; sequential games use backward induction and subgame-perfect equilibrium; cooperative games use the Shapley value to allocate by marginal contribution:
63
- $$\phi_i(v)=\sum_{S\subseteq N\setminus\{i\}}\frac{|S|!(n-|S|-1)!}{n!}[v(S\cup\{i\})-v(S)]$$
64
- Misclassifying the type leads directly to applying the wrong equilibrium concept and solution method.
65
-
66
- ### Step 3: Construct the Payoff Matrix / Function
67
- For two-player games, use a payoff matrix with cells $(u_1,u_2)$; for $n$-player games, use $u_i(s_1,\ldots,s_n)$. Verify completeness: are any players or strategies missing? Do payoffs accurately reflect preferences? Are there externalities? Payoffs are the foundation of all analysis; inaccurate assessment biases everything downstream.
68
-
69
- ### Step 4: Search for Dominant Strategies
70
- Strict dominance: $u_i(s_i^*,s_{-i}) > u_i(s_i,s_{-i})$ for all $s_i\neq s_i^*$ and all $s_{-i}$; weak dominance: $\geq$ with at least one strict inequality. **Iterated elimination of dominated strategies** successively removes inferior strategies to shrink the strategy space. A dominant-strategy equilibrium is the strongest possible conclusion — no player has any incentive to deviate. If none exists, proceed to equilibrium analysis.
71
-
72
- ### Step 5: Compute Equilibria
73
- Select the method based on the game type from Step 2. Pure-strategy Nash: for each $s_{-i}$, find the best response $BR_i(s_{-i})$; intersections are equilibria. Mixed strategies: find probability distributions that make others indifferent, $u_j(s_j,\sigma^*_{-j})=u_j(s_j',\sigma^*_{-j})$ for all $s_j,s_j'\in S_j$. Zero-sum matrix games use minimax $\max_x\min_y f=\min_y\max_x f$; sequential games use backward induction; cooperative games output allocation schemes rather than standard Nash. For multiple equilibria, perform Pareto ranking and label optimal vs. inferior equilibria.
74
-
75
- ### Step 6: Check Equilibrium Stability
76
- Trembling-hand perfection (stable under small perturbations, excluding equilibria that rely on "opponents never make mistakes"); evolutionarily stable strategy ESS (resists invasion in repeated interactions); off-equilibrium-path incentives (in sequential games, whether there is motivation to honor commitments). Ask: is the equilibrium unique or multiple? Is it robust to small perturbations? Only stable equilibria constitute credible predictions.
77
-
78
- ### Step 7: Mechanism Design and Improvement
79
- If no good equilibrium exists, redesign the game: modify the payoff structure (incentives and penalties), add enforceable rules, introduce communication and reputation mechanisms, Vickrey auctions (truthful valuation reporting is a dominant strategy). Mechanism design formalization:
80
- $$\max\ \text{social welfare}\quad\text{s.t.}\quad\text{incentive compatibility + individual rationality}$$
81
- The revelation principle: any Bayesian game equilibrium can be implemented by a direct mechanism — truthful type reporting is an equilibrium. Mechanism design is the most practical branch — rather than lamenting non-cooperation, change the rules so that cooperation becomes the self-interested choice.
82
-
83
- ## Common Errors
84
-
85
- | Error | Critique | Correct Approach |
86
- |---|---|---|
87
- | Assuming others think the same way you do | Others have different payoff functions / rationality levels; $u_i\neq u_j$ | Explicitly specify each player's payoff function and beliefs |
88
- | Ignoring mixed strategies | Pure-strategy equilibria may not exist; mixed equilibria always exist (Nash, 1950) | Check whether mixed-strategy analysis is needed |
89
- | Confusing Nash equilibrium with Pareto optimality | Nash equilibrium can be Pareto-dominated (Prisoner's Dilemma); the two are independent | Separately annotate equilibrium properties and efficiency properties |
90
- | Ignoring information asymmetry | Incomplete-information equilibria differ fundamentally from complete-information ones | Distinguish Bayesian games from complete-information games |
91
- | Oversimplifying payoff structure | Omitting key payoff dimensions distorts the equilibrium | Systematically check complete payoffs for all players |
92
- | Ignoring repeated interaction dynamics | One-shot equilibria may change in repeated games (folk theorem) | Analyze subgame-perfect equilibria |
93
- | Intractable exact large-scale equilibrium | $n$-player Nash equilibrium is PPAD-complete; exact solutions are infeasible | Pass through the GPU eight-dimensional gate; switch to approximate / learning methods (self-play, MARL) |
94
-
95
- ## Operating Procedure
96
-
97
- When this skill is triggered, the output must include:
98
-
99
- 1. **[Players]**: All decision-makers and their types (rational / boundedly rational / unknown).
100
- 2. **[Strategy Sets]**: Available strategies for each player; label finite / infinite.
101
- 3. **[Payoff Matrix]**: Payoff values $(u_1,u_2,\ldots)$ for core strategy profiles, or payoff function form.
102
- 4. **[Game Type]**: Zero-sum / non-zero-sum / sequential / cooperative, with corresponding analytical method.
103
- 5. **[Equilibria]**: All applicable equilibria (pure strategy, mixed strategy, subgame-perfect, cooperative allocation, etc.); label multiple equilibria.
104
- 6. **[Stability]**: Trembling-hand perfection, evolutionary stability, off-equilibrium-path incentives.
105
- 7. **[Mechanism Recommendations]**: If equilibria are undesirable, propose mechanism design suggestions (modify payoffs, add rules, introduce reputation, etc.).
106
- 8. **[GPU Feasibility]**: Matrix games / minimax → LP is GEMM-compatible; large-scale multi-agent equilibria may be intractable → approximate / learning methods; pass through the eight-dimensional gate.
107
-
108
- **Output must not consist of analysis alone without conclusions.**
109
-
110
- ## Relations to Other Skills
111
-
112
- - **Optimization Thinking**: Nash equilibrium is mutual optimization — each player optimizes their own payoff subject to others' strategies; the equilibrium is the common solution to all optimization problems.
113
- - **Probability and Statistics**: Mixed strategies select actions via probability distributions; Bayesian games handle type uncertainty probabilistically; equilibria depend on expected payoffs.
114
- - **Information Theory Thinking**: Information asymmetry and signaling — in Spence signaling games, the information structure directly affects equilibrium existence and properties.
115
- - **Causal Inference Thinking**: Strategic choices causally affect others' payoffs; causal chains in strategic interaction are bidirectional.
116
- - **Algorithmic Thinking**: Nash equilibrium computation complexity (PPAD-complete), Lemke-Howson algorithm, evolutionary game simulation.
117
- - **Modern Mathematics Activation**: `../../references/books/optimization-ml.md` (duality / minimax, game learning algorithms), `../../references/books/matrix-analysis.md` (matrix games, linear algebraic structure of payoff matrices).